ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TGHtmlElement.cxx
Go to the documentation of this file.
1 // $Id$
2 // Author: Valeriy Onuchin 03/05/2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2001, Rene Brun, Fons Rademakers and Reiner Rohlfs *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /**************************************************************************
13 
14  HTML widget for xclass. Based on tkhtml 1.28
15  Copyright (C) 1997-2000 D. Richard Hipp <drh@acm.org>
16  Copyright (C) 2002-2003 Hector Peraza.
17 
18  This library is free software; you can redistribute it and/or
19  modify it under the terms of the GNU Library General Public
20  License as published by the Free Software Foundation; either
21  version 2 of the License, or (at your option) any later version.
22 
23  This library is distributed in the hope that it will be useful,
24  but WITHOUT ANY WARRANTY; without even the implied warranty of
25  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26  Library General Public License for more details.
27 
28  You should have received a copy of the GNU Library General Public
29  License along with this library; if not, write to the Free
30  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 
32 **************************************************************************/
33 
34 #include <string.h>
35 
36 #include "TGHtml.h"
37 #include "TImage.h"
38 
39 // TODO: make these TGHtml static members
40 
41 extern void HtmlTranslateEscapes(char *z);
42 extern void ToLower(char *z);
43 
44 
45 ////////////////////////////////////////////////////////////////////////////////
46 /// HTML element constructor.
47 
49 {
50  fPNext = fPPrev = 0;
51  fStyle.fFont = 0;
52  fStyle.fColor = 0;
53  fStyle.fSubscript = 0;
54  fStyle.fAlign = 0;
55  fStyle.fBgcolor = 0;
56  fStyle.fExpbg = 0;
57  fStyle.fFlags = 0;
58  fType = etype;
59  fFlags = 0;
60  fCount = 0;
61  fElId = 0;
62  fOffs = 0;
63 }
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 /// HTML element constructor.
67 
69 {
70  fZText = new char[size + 1];
71  fX = 0; fY = 0; fW = 0;
72  fAscent = 0;
73  fDescent = 0;
74  fSpaceWidth = 0;
75 }
76 
77 ////////////////////////////////////////////////////////////////////////////////
78 /// HTML element destructor.
79 
81 {
82  delete[] fZText;
83 }
84 
85 ////////////////////////////////////////////////////////////////////////////////
86 /// HTML mrkup element constructor.
87 
88 TGHtmlMarkupElement::TGHtmlMarkupElement(int type2, int argc, int arglen[],
89  char *av[]) : TGHtmlElement(type2)
90 {
91  fCount = argc - 1;
92 
93  if (argc > 1) {
94  fArgv = new char*[argc+1];
95  for (int i = 1; i < argc; i++) {
96  if (arglen) {
97  fArgv[i-1] = new char[arglen[i]+1];
98  //sprintf(fArgv[i-1], "%.*s", arglen[i], av[i]);
99  strncpy(fArgv[i-1], av[i], arglen[i]);
100  fArgv[i-1][arglen[i]] = 0;
102  if ((i & 1) == 1) ToLower(fArgv[i-1]);
103  } else {
104  fArgv[i-1] = StrDup(av[i]);
106  if ((i & 1) == 1) ToLower(fArgv[i-1]);
107  }
108  }
109  fArgv[argc-1] = 0;
110 
111  // Following is just a flag that this is unmodified
112  fArgv[argc] = (char *) fArgv;
113 
114  } else {
115  fArgv = 0;
116  }
117 }
118 
119 ////////////////////////////////////////////////////////////////////////////////
120 /// HTML markup element destructor.
121 
123 {
124  if (fArgv) {
125  for (int i = 0; i < fCount; ++i) delete [] fArgv[i];
126  delete [] fArgv;
127  }
128 }
129 
130 ////////////////////////////////////////////////////////////////////////////////
131 /// Lookup an argument in the given markup with the name given.
132 /// Return a pointer to its value, or the given default
133 /// value if it doesn't appear.
134 
135 const char *TGHtmlMarkupElement::MarkupArg(const char *tag, const char *zDefault)
136 {
137  int i;
138 
139  for (i = 0; i < fCount; i += 2) {
140  if (strcmp(fArgv[i], tag) == 0) return fArgv[i+1];
141  }
142  return zDefault;
143 }
144 
145 ////////////////////////////////////////////////////////////////////////////////
146 /// Return an alignment or justification flag associated with the
147 /// given markup. The given default value is returned if no alignment is
148 /// specified.
149 
151 {
152  const char *z = MarkupArg("align", 0);
153  int rc = dflt;
154 
155  if (z) {
156  if (strcasecmp(z, "left") == 0) {
157  rc = ALIGN_Left;
158  } else if (strcasecmp(z, "right") == 0) {
159  rc = ALIGN_Right;
160  } else if (strcasecmp(z, "center") == 0) {
161  rc = ALIGN_Center;
162  }
163  }
164 
165  return rc;
166 }
167 
168 ////////////////////////////////////////////////////////////////////////////////
169 /// The "type" argument to the given element might describe the type
170 /// for an ordered list. Return the corresponding LI_TYPE_* entry
171 /// if this is the case, or the default value if it isn't.
172 /// (this and the following should be defined only for TGHtmlLi)
173 
175 {
176  const char *z = MarkupArg("type", 0);
177  if (z) {
178  switch (*z) {
179  case 'A': dflt = LI_TYPE_Enum_A; break;
180  case 'a': dflt = LI_TYPE_Enum_a; break;
181  case '1': dflt = LI_TYPE_Enum_1; break;
182  case 'I': dflt = LI_TYPE_Enum_I; break;
183  case 'i': dflt = LI_TYPE_Enum_i; break;
184  default: break;
185  }
186  }
187 
188  return dflt;
189 }
190 
191 ////////////////////////////////////////////////////////////////////////////////
192 /// The "type" argument to the given element might describe a type
193 /// for an unordered list. Return the corresponding LI_TYPE entry
194 /// if this is the case, or the default value if it isn't.
195 
197 {
198  const char *z = MarkupArg("type", 0);
199  if (z) {
200  if (strcasecmp(z, "disc") == 0) {
201  dflt = LI_TYPE_Bullet1;
202  } else if (strcasecmp(z, "circle") == 0) {
203  dflt = LI_TYPE_Bullet2;
204  } else if (strcasecmp(z, "square") == 0) {
205  dflt = LI_TYPE_Bullet3;
206  }
207  }
208 
209  return dflt;
210 }
211 
212 //int TGHtmlMarkupElement::GetVerticalAlignment(int dflt);
213 
214 ////////////////////////////////////////////////////////////////////////////////
215 /// HTML table element constructor.
216 
217 TGHtmlTable::TGHtmlTable(int type2, int argc, int arglen[], char *argv2[]) :
218  TGHtmlMarkupElement(type2, argc, arglen, argv2)
219 {
220  fBorderWidth = 0;
221  fNCol = 0;
222  fNRow = 0;
223  fX = 0; fY = 0; fW = 0; fH = 0;
224  fPEnd = 0;
225  fBgImage = 0;
226  fHasbg = 0;
227  for (int i=0;i<=HTML_MAX_COLUMNS;++i) {
228  fMinW[i] = fMaxW[i] = 0;
229  }
230 }
231 
232 ////////////////////////////////////////////////////////////////////////////////
233 /// HTML table element destructor.
234 
236 {
237  if (fBgImage) delete fBgImage;
238 }
239 
240 ////////////////////////////////////////////////////////////////////////////////
241 /// HTML cell element constructor.
242 
243 TGHtmlCell::TGHtmlCell(int type2, int argc, int arglen[], char *argv2[]) :
244  TGHtmlMarkupElement(type2, argc, arglen, argv2)
245 {
246  fRowspan = 0;
247  fColspan = 0;
248  fX = 0; fY = 0; fW = 0; fH = 0;
249  fPTable = 0;
250  fPRow = 0;
251  fPEnd = 0;
252  fBgImage = 0;
253 }
254 
255 ////////////////////////////////////////////////////////////////////////////////
256 /// HTML cell element destructor.
257 
259 {
260  if (fBgImage) delete fBgImage;
261 }
262 
263 ////////////////////////////////////////////////////////////////////////////////
264 /// HTML ref element constructor.
265 
266 TGHtmlRef::TGHtmlRef(int type2, int argc, int arglen[], char *argv2[]) :
267  TGHtmlMarkupElement(type2, argc, arglen, argv2)
268 {
269  fPOther = 0;
270  fBgImage = 0;
271 }
272 
273 ////////////////////////////////////////////////////////////////////////////////
274 /// HTML ref element destructor.
275 
277 {
278  if (fBgImage) delete fBgImage;
279 }
280 
281 ////////////////////////////////////////////////////////////////////////////////
282 /// HTML li element constructor.
283 
284 TGHtmlLi::TGHtmlLi(int type2, int argc, int arglen[], char *argv2[]) :
285  TGHtmlMarkupElement(type2, argc, arglen, argv2)
286 {
287  fLtype = 0;
288  fAscent = 0;
289  fDescent = 0;
290  fCnt = 0;
291  fX = 0; fY = 0;
292 }
293 
294 ////////////////////////////////////////////////////////////////////////////////
295 /// HTML list start element constructor.
296 
297 TGHtmlListStart::TGHtmlListStart(int type2, int argc, int arglen[], char *argv2[]) :
298  TGHtmlMarkupElement(type2, argc, arglen, argv2)
299 {
300  fLtype = 0;
301  fCompact = 0;
302  fCnt = 0;
303  fWidth = 0;
304  fLPrev = 0;
305 }
306 
307 ////////////////////////////////////////////////////////////////////////////////
308 /// HTML image element constructor.
309 
311  int arglen[], char *argv2[]) :
312  TGHtmlMarkupElement(type2, argc, arglen, argv2)
313 {
314  fAlign = 0;
315  fTextAscent = 0;
316  fTextDescent = 0;
317  fRedrawNeeded = 0;
318  fX = 0; fY = 0; fW = 0; fH = 0;
319  fAscent = 0;
320  fDescent = 0;
321  fZAlt = 0;
322  fPImage = 0;
323  fPMap = 0;
324  fINext = 0;
325 }
326 
327 ////////////////////////////////////////////////////////////////////////////////
328 /// HTML form element constructor.
329 
330 TGHtmlForm::TGHtmlForm(int type2, int argc, int arglen[], char *argv2[]) :
331  TGHtmlMarkupElement(type2, argc, arglen, argv2)
332 {
333  fFormId = 0;
334  fElements = 0;
335  fHasctl = 0;
336  fPFirst = 0;
337  fPEnd = 0;
338 }
339 
340 ////////////////////////////////////////////////////////////////////////////////
341 /// HTML hr element constructor.
342 
343 TGHtmlHr::TGHtmlHr(int type2, int argc, int arglen[], char *argv2[]) :
344  TGHtmlMarkupElement(type2, argc, arglen, argv2)
345 {
346  fX = 0; fY = 0; fW = 0; fH = 0;
347  fIs3D = 0;
348 }
349 
350 ////////////////////////////////////////////////////////////////////////////////
351 /// HTML anchor element constructor.
352 
353 TGHtmlAnchor::TGHtmlAnchor(int type2, int argc, int arglen[], char *argv2[]) :
354  TGHtmlMarkupElement(type2, argc, arglen, argv2)
355 {
356  fY = 0;
357 }
358 
359 ////////////////////////////////////////////////////////////////////////////////
360 /// HTML script element constructor.
361 
362 TGHtmlScript::TGHtmlScript(int type2, int argc, int arglen[], char *argv2[]) :
363  TGHtmlMarkupElement(type2, argc, arglen, argv2)
364 {
365  fNStart = -1;
366  fNScript = 0;
367 }
368 
369 ////////////////////////////////////////////////////////////////////////////////
370 /// HTML map area constructor.
371 
372 TGHtmlMapArea::TGHtmlMapArea(int type2, int argc, int arglen[], char *argv2[]) :
373  TGHtmlMarkupElement(type2, argc, arglen, argv2)
374 {
375  fMType = 0;
376  fCoords = 0;
377  fNum = 0;
378 }
379 
380 
381 //----------------------------------------------------------------------
382 
383 #if 0
385 {
386  // HTML block element constructor.
387 }
388 
390 {
391  // HTML block element destructor.
392 }
393 #endif
394 
395 ////////////////////////////////////////////////////////////////////////////////
396 /// HTML input element constructor.
397 
398 TGHtmlInput::TGHtmlInput(int type2, int argc, int arglen[], char *argv2[]) :
399  TGHtmlMarkupElement(type2, argc, arglen, argv2)
400 {
401  fPForm = 0;
402  fINext = 0;
403  fFrame = 0;
404  fHtml = 0;
405  fPEnd = 0;
406  fInpId = 0; fSubId = 0;
407  fX = 0; fY = 0; fW = 0; fH = 0;
408  fPadLeft = 0;
409  fAlign = 0;
410  fTextAscent = 0;
411  fTextDescent = 0;
412  fItype = 0;
413  fSized = 0;
414  fCnt = 0;
415 }
416 
417 ////////////////////////////////////////////////////////////////////////////////
418 /// Mark this element as being empty. It has no widget and doesn't appear on
419 /// the screen.
420 ///
421 /// This is called for HIDDEN inputs or when the corresponding widget is
422 /// not created.
423 
425 {
426  fFrame = NULL;
427  fW = 0;
428  fH = 0;
429  fFlags &= ~HTML_Visible;
431  fSized = 1;
432 }
433 
Html_32_t fY
Definition: TGHtml.h:366
unsigned int fHasctl
Definition: TGHtml.h:644
TImage * fBgImage
Definition: TGHtml.h:399
void ToLower(char *z)
Convert a string to all lower-case letters.
TGHtmlInput(int type, int argc, int arglen[], char *argv[])
HTML input element constructor.
Html_16_t fX
Definition: TGHtml.h:431
Html_u16_t fNRow
Definition: TGHtml.h:365
Html_u8_t fLtype
Definition: TGHtml.h:459
TImage * fBgImage
Definition: TGHtml.h:415
#define ALIGN_Left
Definition: TGHtml.h:212
unsigned int fColor
Definition: TGHtml.h:149
TGHtmlListStart * fLPrev
Definition: TGHtml.h:463
TGHtmlImageMarkup * fINext
Definition: TGHtml.h:557
Html_16_t fAscent
Definition: TGHtml.h:550
int fHasbg
Definition: TGHtml.h:374
#define LI_TYPE_Enum_i
Definition: TGHtml.h:449
TGHtmlElement * fPOther
Definition: TGHtml.h:414
#define STY_Invisible
Definition: TGHtml.h:243
TGHtmlMarkupElement(int type, int argc, int arglen[], char *argv[])
HTML mrkup element constructor.
Html_32_t fY
Definition: TGHtml.h:599
TGHtmlTable(int type, int argc, int arglen[], char *argv[])
HTML table element constructor.
Html_16_t fX
Definition: TGHtml.h:552
Html_32_t fY
Definition: TGHtml.h:394
Html_u16_t fSubId
Definition: TGHtml.h:598
Html_u8_t fIs3D
Definition: TGHtml.h:660
#define LI_TYPE_Enum_A
Definition: TGHtml.h:446
TGHtmlBlock()
ctor.
Definition: TGHtmlDraw.cxx:46
#define ALIGN_Center
Definition: TGHtml.h:214
Html_u8_t fTextAscent
Definition: TGHtml.h:544
int fMaxW[HTML_MAX_COLUMNS+1]
Definition: TGHtml.h:371
#define HTML_Visible
Definition: TGHtml.h:278
TGHtmlRef(int type, int argc, int arglen[], char *argv[])
HTML ref element constructor.
Html_16_t fX
Definition: TGHtml.h:392
TImage * fBgImage
Definition: TGHtml.h:373
unsigned int fExpbg
Definition: TGHtml.h:153
unsigned int fElements
Definition: TGHtml.h:643
virtual ~TGHtmlTextElement()
HTML element destructor.
Html_u8_t fAlign
Definition: TGHtml.h:603
Html_32_t fY
Definition: TGHtml.h:671
Html_u8_t fLtype
Definition: TGHtml.h:427
TGHtmlMapArea(int type, int argc, int arglen[], char *argv[])
HTML map area constructor.
TGHtmlElement * fPEnd
Definition: TGHtml.h:646
Html_16_t fW
Definition: TGHtml.h:549
Html_16_t fColspan
Definition: TGHtml.h:391
Html_u8_t fCompact
Definition: TGHtml.h:460
TGHtmlElement * fPNext
Definition: TGHtml.h:265
Html_u8_t fSized
Definition: TGHtml.h:607
Html_u16_t fCnt
Definition: TGHtml.h:461
Html_u16_t fWidth
Definition: TGHtml.h:462
Html_32_t fH
Definition: TGHtml.h:367
Html_u8_t fBorderWidth
Definition: TGHtml.h:363
Html_32_t fY
Definition: TGHtml.h:657
Html_u8_t fNCol
Definition: TGHtml.h:364
unsigned int fBgcolor
Definition: TGHtml.h:152
TGHtmlElement * fPFirst
Definition: TGHtml.h:645
unsigned int fFont
Definition: TGHtml.h:148
Html_u16_t fW
Definition: TGHtml.h:659
int fNStart
Definition: TGHtml.h:687
Html_u8_t fAlign
Definition: TGHtml.h:543
TGHtmlForm(int type, int argc, int arglen[], char *argv[])
HTML form element constructor.
TGHtmlElement * fPPrev
Definition: TGHtml.h:266
Float_t z[5]
Definition: Ifit.C:16
#define LI_TYPE_Bullet3
Definition: TGHtml.h:444
Html_u8_t fRedrawNeeded
Definition: TGHtml.h:546
TGHtmlImage * fPImage
Definition: TGHtml.h:555
Html_16_t fX
Definition: TGHtml.h:299
Html_32_t fY
Definition: TGHtml.h:553
int fNScript
Definition: TGHtml.h:688
Html_u8_t fAscent
Definition: TGHtml.h:301
TGHtmlLi(int type, int argc, int arglen[], char *argv[])
HTML li element constructor.
SHtmlStyle_t fStyle
Definition: TGHtml.h:267
Html_32_t fH
Definition: TGHtml.h:395
#define LI_TYPE_Bullet1
Definition: TGHtml.h:442
Html_u16_t fW
Definition: TGHtml.h:601
Html_u8_t fPadLeft
Definition: TGHtml.h:602
#define LI_TYPE_Enum_a
Definition: TGHtml.h:447
#define LI_TYPE_Bullet2
Definition: TGHtml.h:443
virtual ~TGHtmlMarkupElement()
HTML markup element destructor.
Html_u8_t fTextDescent
Definition: TGHtml.h:545
Html_u16_t fCnt
Definition: TGHtml.h:608
Html_u16_t fX
Definition: TGHtml.h:600
TGHtmlTable * fPTable
Definition: TGHtml.h:396
Html_16_t fRowspan
Definition: TGHtml.h:390
char * fZText
Definition: TGHtml.h:304
Html_16_t fX
Definition: TGHtml.h:368
Html_u16_t fInpId
Definition: TGHtml.h:597
TGHtmlCell(int type, int argc, int arglen[], char *argv[])
HTML cell element constructor.
Html_u8_t fAscent
Definition: TGHtml.h:428
Html_u8_t fType
Definition: TGHtml.h:268
TGHtmlHr(int type, int argc, int arglen[], char *argv[])
HTML hr element constructor.
Html_u8_t fSpaceWidth
Definition: TGHtml.h:303
char * StrDup(const char *str)
Duplicate the string str.
Definition: TString.cxx:2500
Html_u16_t fH
Definition: TGHtml.h:659
unsigned int fFlags
Definition: TGHtml.h:154
virtual int GetUnorderedListType(int dflt)
The "type" argument to the given element might describe a type for an unordered list.
Html_u16_t fX
Definition: TGHtml.h:658
void HtmlTranslateEscapes(char *z)
Translate escape sequences in the string "z".
Html_16_t fCnt
Definition: TGHtml.h:430
#define LI_TYPE_Enum_1
Definition: TGHtml.h:445
TGHtmlForm * fPForm
Definition: TGHtml.h:592
Html_u8_t fItype
Definition: TGHtml.h:606
Html_16_t fH
Definition: TGHtml.h:548
TGHtmlElement * fPEnd
Definition: TGHtml.h:372
Html_u8_t fTextAscent
Definition: TGHtml.h:604
virtual int GetOrderedListType(int dflt)
The "type" argument to the given element might describe the type for an ordered list.
~TGHtmlCell()
HTML cell element destructor.
#define LI_TYPE_Enum_I
Definition: TGHtml.h:448
Html_16_t fW
Definition: TGHtml.h:300
#define HTML_MAX_COLUMNS
Definition: TGHtml.h:346
Html_16_t fW
Definition: TGHtml.h:393
TGHtmlAnchor(int type, int argc, int arglen[], char *argv[])
HTML anchor element constructor.
Html_u16_t fH
Definition: TGHtml.h:601
TGHtmlElement * fPMap
Definition: TGHtml.h:556
TGHtmlScript(int type, int argc, int arglen[], char *argv[])
HTML script element constructor.
TGFrame * fFrame
Definition: TGHtml.h:594
Html_32_t fY
Definition: TGHtml.h:432
Html_u8_t fDescent
Definition: TGHtml.h:429
~TGHtmlRef()
HTML ref element destructor.
int fMinW[HTML_MAX_COLUMNS+1]
Definition: TGHtml.h:370
TGHtmlElement * fPEnd
Definition: TGHtml.h:398
virtual ~TGHtmlBlock()
dtor.
Definition: TGHtmlDraw.cxx:59
Html_16_t fW
Definition: TGHtml.h:369
Html_16_t fCount
Definition: TGHtml.h:270
const char * fZAlt
Definition: TGHtml.h:554
Html_u8_t fTextDescent
Definition: TGHtml.h:605
TGHtmlInput * fINext
Definition: TGHtml.h:593
TGHtml * fHtml
Definition: TGHtml.h:595
#define NULL
Definition: Rtypes.h:82
#define ALIGN_Right
Definition: TGHtml.h:213
TGHtmlListStart(int type, int argc, int arglen[], char *argv[])
HTML list start element constructor.
int fMType
Definition: TGHtml.h:476
unsigned int fAlign
Definition: TGHtml.h:151
TGHtmlElement(int etype=0)
HTML element constructor.
TGHtmlElement * fPEnd
Definition: TGHtml.h:596
virtual const char * MarkupArg(const char *tag, const char *zDefault)
Lookup an argument in the given markup with the name given.
Html_32_t fY
Definition: TGHtml.h:298
Html_u16_t fFormId
Definition: TGHtml.h:642
signed int fSubscript
Definition: TGHtml.h:150
TGHtmlTextElement(const TGHtmlTextElement &)
void Empty()
Mark this element as being empty.
~TGHtmlTable()
HTML table element destructor.
TGHtmlElement * fPRow
Definition: TGHtml.h:397
Html_16_t fDescent
Definition: TGHtml.h:551
int * fCoords
Definition: TGHtml.h:477
virtual int GetAlignment(int dflt)
Return an alignment or justification flag associated with the given markup.
TGHtmlImageMarkup(int type, int argc, int arglen[], char *argv[])
HTML image element constructor.
Html_u8_t fFlags
Definition: TGHtml.h:269
Html_u8_t fDescent
Definition: TGHtml.h:302