Logo ROOT   6.12/07
Reference Guide
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:362
unsigned int fHasctl
Definition: TGHtml.h:640
TImage * fBgImage
Definition: TGHtml.h:395
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:427
Html_u16_t fNRow
Definition: TGHtml.h:361
Html_u8_t fLtype
Definition: TGHtml.h:455
TImage * fBgImage
Definition: TGHtml.h:411
#define ALIGN_Left
Definition: TGHtml.h:208
unsigned int fColor
Definition: TGHtml.h:145
TGHtmlListStart * fLPrev
Definition: TGHtml.h:459
TGHtmlImageMarkup * fINext
Definition: TGHtml.h:553
Html_16_t fAscent
Definition: TGHtml.h:546
int fHasbg
Definition: TGHtml.h:370
#define LI_TYPE_Enum_i
Definition: TGHtml.h:445
TGHtmlElement * fPOther
Definition: TGHtml.h:410
#define STY_Invisible
Definition: TGHtml.h:239
TGHtmlMarkupElement(int type, int argc, int arglen[], char *argv[])
HTML mrkup element constructor.
Html_32_t fY
Definition: TGHtml.h:595
TGHtmlTable(int type, int argc, int arglen[], char *argv[])
HTML table element constructor.
Html_16_t fX
Definition: TGHtml.h:548
Html_32_t fY
Definition: TGHtml.h:390
Html_u16_t fSubId
Definition: TGHtml.h:594
Html_u8_t fIs3D
Definition: TGHtml.h:656
#define LI_TYPE_Enum_A
Definition: TGHtml.h:442
TGHtmlBlock()
ctor.
Definition: TGHtmlDraw.cxx:46
#define ALIGN_Center
Definition: TGHtml.h:210
Html_u8_t fTextAscent
Definition: TGHtml.h:540
int fMaxW[HTML_MAX_COLUMNS+1]
Definition: TGHtml.h:367
#define HTML_Visible
Definition: TGHtml.h:274
TGHtmlRef(int type, int argc, int arglen[], char *argv[])
HTML ref element constructor.
Html_16_t fX
Definition: TGHtml.h:388
TImage * fBgImage
Definition: TGHtml.h:369
unsigned int fExpbg
Definition: TGHtml.h:149
unsigned int fElements
Definition: TGHtml.h:639
virtual ~TGHtmlTextElement()
HTML element destructor.
Html_u8_t fAlign
Definition: TGHtml.h:599
Html_32_t fY
Definition: TGHtml.h:667
Html_u8_t fLtype
Definition: TGHtml.h:423
TGHtmlMapArea(int type, int argc, int arglen[], char *argv[])
HTML map area constructor.
TGHtmlElement * fPEnd
Definition: TGHtml.h:642
Html_16_t fW
Definition: TGHtml.h:545
Html_16_t fColspan
Definition: TGHtml.h:387
Html_u8_t fCompact
Definition: TGHtml.h:456
TGHtmlElement * fPNext
Definition: TGHtml.h:261
Html_u8_t fSized
Definition: TGHtml.h:603
Html_u16_t fCnt
Definition: TGHtml.h:457
Html_u16_t fWidth
Definition: TGHtml.h:458
Html_32_t fH
Definition: TGHtml.h:363
Html_u8_t fBorderWidth
Definition: TGHtml.h:359
Html_32_t fY
Definition: TGHtml.h:653
Html_u8_t fNCol
Definition: TGHtml.h:360
unsigned int fBgcolor
Definition: TGHtml.h:148
TGHtmlElement * fPFirst
Definition: TGHtml.h:641
unsigned int fFont
Definition: TGHtml.h:144
Html_u16_t fW
Definition: TGHtml.h:655
int fNStart
Definition: TGHtml.h:683
Html_u8_t fAlign
Definition: TGHtml.h:539
TGHtmlForm(int type, int argc, int arglen[], char *argv[])
HTML form element constructor.
TGHtmlElement * fPPrev
Definition: TGHtml.h:262
#define LI_TYPE_Bullet3
Definition: TGHtml.h:440
Html_u8_t fRedrawNeeded
Definition: TGHtml.h:542
TGHtmlImage * fPImage
Definition: TGHtml.h:551
Html_16_t fX
Definition: TGHtml.h:295
Html_32_t fY
Definition: TGHtml.h:549
int fNScript
Definition: TGHtml.h:684
Html_u8_t fAscent
Definition: TGHtml.h:297
TGHtmlLi(int type, int argc, int arglen[], char *argv[])
HTML li element constructor.
SHtmlStyle_t fStyle
Definition: TGHtml.h:263
Html_32_t fH
Definition: TGHtml.h:391
#define LI_TYPE_Bullet1
Definition: TGHtml.h:438
Html_u16_t fW
Definition: TGHtml.h:597
Html_u8_t fPadLeft
Definition: TGHtml.h:598
#define LI_TYPE_Enum_a
Definition: TGHtml.h:443
#define LI_TYPE_Bullet2
Definition: TGHtml.h:439
virtual ~TGHtmlMarkupElement()
HTML markup element destructor.
Html_u8_t fTextDescent
Definition: TGHtml.h:541
Html_u16_t fCnt
Definition: TGHtml.h:604
Html_u16_t fX
Definition: TGHtml.h:596
TGHtmlTable * fPTable
Definition: TGHtml.h:392
Html_16_t fRowspan
Definition: TGHtml.h:386
char * fZText
Definition: TGHtml.h:300
Html_16_t fX
Definition: TGHtml.h:364
Html_u16_t fInpId
Definition: TGHtml.h:593
TGHtmlCell(int type, int argc, int arglen[], char *argv[])
HTML cell element constructor.
Html_u8_t fAscent
Definition: TGHtml.h:424
Html_u8_t fType
Definition: TGHtml.h:264
TGHtmlHr(int type, int argc, int arglen[], char *argv[])
HTML hr element constructor.
Html_u8_t fSpaceWidth
Definition: TGHtml.h:299
char * StrDup(const char *str)
Duplicate the string str.
Definition: TString.cxx:2544
Html_u16_t fH
Definition: TGHtml.h:655
unsigned int fFlags
Definition: TGHtml.h:150
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:654
void HtmlTranslateEscapes(char *z)
Translate escape sequences in the string "z".
Html_16_t fCnt
Definition: TGHtml.h:426
#define LI_TYPE_Enum_1
Definition: TGHtml.h:441
TGHtmlForm * fPForm
Definition: TGHtml.h:588
Html_u8_t fItype
Definition: TGHtml.h:602
Html_16_t fH
Definition: TGHtml.h:544
TGHtmlElement * fPEnd
Definition: TGHtml.h:368
Html_u8_t fTextAscent
Definition: TGHtml.h:600
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:444
Html_16_t fW
Definition: TGHtml.h:296
#define HTML_MAX_COLUMNS
Definition: TGHtml.h:342
Html_16_t fW
Definition: TGHtml.h:389
TGHtmlAnchor(int type, int argc, int arglen[], char *argv[])
HTML anchor element constructor.
Html_u16_t fH
Definition: TGHtml.h:597
TGHtmlElement * fPMap
Definition: TGHtml.h:552
TGHtmlScript(int type, int argc, int arglen[], char *argv[])
HTML script element constructor.
TGFrame * fFrame
Definition: TGHtml.h:590
Html_32_t fY
Definition: TGHtml.h:428
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
Html_u8_t fDescent
Definition: TGHtml.h:425
~TGHtmlRef()
HTML ref element destructor.
int fMinW[HTML_MAX_COLUMNS+1]
Definition: TGHtml.h:366
TGHtmlElement * fPEnd
Definition: TGHtml.h:394
virtual ~TGHtmlBlock()
dtor.
Definition: TGHtmlDraw.cxx:59
Html_16_t fW
Definition: TGHtml.h:365
Html_16_t fCount
Definition: TGHtml.h:266
const char * fZAlt
Definition: TGHtml.h:550
Html_u8_t fTextDescent
Definition: TGHtml.h:601
TGHtmlInput * fINext
Definition: TGHtml.h:589
TGHtml * fHtml
Definition: TGHtml.h:591
#define ALIGN_Right
Definition: TGHtml.h:209
TGHtmlListStart(int type, int argc, int arglen[], char *argv[])
HTML list start element constructor.
int fMType
Definition: TGHtml.h:472
unsigned int fAlign
Definition: TGHtml.h:147
TGHtmlElement(int etype=0)
HTML element constructor.
TGHtmlElement * fPEnd
Definition: TGHtml.h:592
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:294
Html_u16_t fFormId
Definition: TGHtml.h:638
signed int fSubscript
Definition: TGHtml.h:146
TGHtmlTextElement(const TGHtmlTextElement &)
void Empty()
Mark this element as being empty.
~TGHtmlTable()
HTML table element destructor.
TGHtmlElement * fPRow
Definition: TGHtml.h:393
Html_16_t fDescent
Definition: TGHtml.h:547
int * fCoords
Definition: TGHtml.h:473
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:265
Html_u8_t fDescent
Definition: TGHtml.h:298