Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files 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 
48 TGHtmlElement::TGHtmlElement(int etype)
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 
68 TGHtmlTextElement::TGHtmlTextElement(int size) : TGHtmlElement(Html_Text)
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 
80 TGHtmlTextElement::~TGHtmlTextElement()
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;
101  HtmlTranslateEscapes(fArgv[i-1]);
102  if ((i & 1) == 1) ToLower(fArgv[i-1]);
103  } else {
104  fArgv[i-1] = StrDup(av[i]);
105  HtmlTranslateEscapes(fArgv[i-1]);
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 
122 TGHtmlMarkupElement::~TGHtmlMarkupElement()
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 
150 int TGHtmlMarkupElement::GetAlignment(int dflt)
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 
174 int TGHtmlMarkupElement::GetOrderedListType(int dflt)
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 
196 int TGHtmlMarkupElement::GetUnorderedListType(int dflt)
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 
235 TGHtmlTable::~TGHtmlTable()
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 
258 TGHtmlCell::~TGHtmlCell()
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 
276 TGHtmlRef::~TGHtmlRef()
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 
310 TGHtmlImageMarkup::TGHtmlImageMarkup(int type2, int argc,
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
384 TGHtmlBlock::TGHtmlBlock()
385 {
386  // HTML block element constructor.
387 }
388 
389 TGHtmlBlock::~TGHtmlBlock()
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 
424 void TGHtmlInput::Empty()
425 {
426  fFrame = NULL;
427  fW = 0;
428  fH = 0;
429  fFlags &= ~HTML_Visible;
430  fStyle.fFlags |= STY_Invisible;
431  fSized = 1;
432 }
433