ROOT  6.06/09
Reference Guide
TGHtml.h
Go to the documentation of this file.
1 // $Id: TGHtml.h,v 1.1 2007/05/04 17:07:01 brun Exp $
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 #ifndef ROOT_TGHtml
35 #define ROOT_TGHtml
36 
37 #ifndef ROOT_TGView
38 #include "TGView.h"
39 #endif
40 
41 #ifndef ROOT_TGHtmlTokens
42 #include "TGHtmlTokens.h"
43 #endif
44 
45 class TGClient;
46 class TImage;
47 class TGFont;
48 class TGIdleHandler;
49 class THashTable;
50 class TTimer;
51 
52 //----------------------------------------------------------------------
53 
54 #define HTML_RELIEF_FLAT 0
55 #define HTML_RELIEF_SUNKEN 1
56 #define HTML_RELIEF_RAISED 2
57 
58 //#define TABLE_TRIM_BLANK 1
59 
60 // Debug must be turned on for testing to work.
61 //#define DEBUG
62 
63 #define CANT_HAPPEN \
64  fprintf(stderr, \
65  "Unplanned behavior in the HTML Widget in file %s line %d\n", \
66  __FILE__, __LINE__)
67 
68 #define UNTESTED \
69  fprintf(stderr, \
70  "Untested code executed in the HTML Widget in file %s line %d\n", \
71  __FILE__, __LINE__)
72 
73 // Sanity checking macros.
74 
75 #ifdef DEBUG
76 #define HtmlAssert(X) \
77  if(!(X)){ \
78  fprintf(stderr,"Assertion failed on line %d of %s\n",__LINE__,__FILE__); \
79  }
80 #define HtmlCantHappen \
81  fprintf(stderr,"Can't happen on line %d of %s\n",__LINE__,__FILE__);
82 #else
83 #define HtmlAssert(X)
84 #define HtmlCantHappen
85 #endif
86 
87 // Bitmasks for the HtmlTraceMask global variable
88 
89 #define HtmlTrace_Table1 0x00000001
90 #define HtmlTrace_Table2 0x00000002
91 #define HtmlTrace_Table3 0x00000004
92 #define HtmlTrace_Table4 0x00000008
93 #define HtmlTrace_Table5 0x00000010
94 #define HtmlTrace_Table6 0x00000020
95 #define HtmlTrace_GetLine 0x00000100
96 #define HtmlTrace_GetLine2 0x00000200
97 #define HtmlTrace_FixLine 0x00000400
98 #define HtmlTrace_BreakMarkup 0x00001000
99 #define HtmlTrace_Style 0x00002000
100 #define HtmlTrace_Input1 0x00004000
101 
102 // The TRACE macro is used to print internal information about the
103 // HTML layout engine during testing and debugging. The amount of
104 // information printed is governed by a global variable named
105 // HtmlTraceMask. If bits in the first argument to the TRACE macro
106 // match any bits in HtmlTraceMask variable, then the trace message
107 // is printed.
108 //
109 // All of this is completely disabled, of course, if the DEBUG macro
110 // is not defined.
111 
112 #ifdef DEBUG
113 extern int HtmlTraceMask;
114 extern int HtmlDepth;
115 # define TRACE_INDENT printf("%*s",HtmlDepth-3,"")
116 # define TRACE(Flag, Args) \
117  if( (Flag)&HtmlTraceMask ){ \
118  TRACE_INDENT; printf Args; fflush(stdout); \
119  }
120 # define TRACE_PUSH(Flag) if( (Flag)&HtmlTraceMask ){ HtmlDepth+=3; }
121 # define TRACE_POP(Flag) if( (Flag)&HtmlTraceMask ){ HtmlDepth-=3; }
122 #else
123 # define TRACE_INDENT
124 # define TRACE(Flag, Args)
125 # define TRACE_PUSH(Flag)
126 # define TRACE_POP(Flag)
127 #endif
128 
129 
130 //----------------------------------------------------------------------
131 
132 // Various data types. This code is designed to run on a modern cached
133 // architecture where the CPU runs a lot faster than the memory bus. Hence
134 // we try to pack as much data into as small a space as possible so that it
135 // is more likely to fit in cache. The extra CPU instruction or two needed
136 // to unpack the data is not normally an issue since we expect the speed of
137 // the memory bus to be the limiting factor.
138 
139 typedef unsigned char Html_u8_t; // 8-bit unsigned integer
140 typedef short Html_16_t; // 16-bit signed integer
141 typedef unsigned short Html_u16_t; // 16-bit unsigned integer
142 typedef int Html_32_t; // 32-bit signed integer
143 
144 // An instance of the following structure is used to record style
145 // information on each Html element.
146 
147 struct SHtmlStyle_t {
148  unsigned int fFont : 6; // Font to use for display
149  unsigned int fColor : 6; // Foreground color
150  signed int fSubscript : 4; // Positive for <sup>, negative for <sub>
151  unsigned int fAlign : 2; // Horizontal alignment
152  unsigned int fBgcolor : 6; // Background color
153  unsigned int fExpbg : 1; // Set to 1 if bgcolor explicitly set
154  unsigned int fFlags : 7; // the STY_ flags below
155 };
156 
157 
158 // We allow 8 different font families: Normal, Bold, Italic and Bold-Italic
159 // in either variable or constant width. Within each family there can be up
160 // to 7 font sizes from 1 (the smallest) up to 7 (the largest). Hence, the
161 // widget can use a maximum of 56 fonts. The ".font" field of the style is
162 // an integer between 0 and 55 which indicates which font to use.
163 
164 // HP: we further subdivide the .font field into two 3-bit subfields (size
165 // and family). That makes easier to manipulate the family field.
166 
167 #define N_FONT_FAMILY 8
168 #define N_FONT_SIZE 7
169 #define N_FONT 71
170 #define NormalFont(X) (X)
171 #define BoldFont(X) ((X) | 8)
172 #define ItalicFont(X) ((X) | 16)
173 #define CWFont(X) ((X) | 32)
174 #define FontSize(X) ((X) & 007)
175 #define FontFamily(X) ((X) & 070)
176 #define FONT_Any -1
177 #define FONT_Default 3
178 #define FontSwitch(Size, Bold, Italic, Cw) \
179  ((Size) | ((Bold+(Italic)*2+(Cw)*4) << 3))
180 
181 // Macros for manipulating the fontValid bitmap of an TGHtml object.
182 
183 #define FontIsValid(I) ((fFontValid[(I)>>3] & (1<<((I)&3)))!=0)
184 #define FontSetValid(I) (fFontValid[(I)>>3] |= (1<<((I)&3)))
185 #define FontClearValid(I) (fFontValid[(I)>>3] &= ~(1<<((I)&3)))
186 
187 
188 // Information about available colors.
189 //
190 // The widget will use at most N_COLOR colors. 4 of these colors are
191 // predefined. The rest are user selectable by options to various markups.
192 // (Ex: <font color=red>)
193 //
194 // All colors are stored in the apColor[] array of the main widget object.
195 // The ".color" field of the SHtmlStyle_t is an integer between 0 and
196 // N_COLOR-1 which indicates which of these colors to use.
197 
198 #define N_COLOR 32 // Total number of colors
199 
200 #define COLOR_Normal 0 // Index for normal color (black)
201 #define COLOR_Unvisited 1 // Index for unvisited hyperlinks
202 #define COLOR_Visited 2 // Color for visited hyperlinks
203 #define COLOR_Selection 3 // Background color for the selection
204 #define COLOR_Background 4 // Default background color
205 #define N_PREDEFINED_COLOR 5 // Number of predefined colors
206 
207 
208 // The "align" field of the style determines how text is justified
209 // horizontally. ALIGN_None means that the alignment is not specified.
210 // (It should probably default to ALIGN_Left in this case.)
211 
212 #define ALIGN_Left 1
213 #define ALIGN_Right 2
214 #define ALIGN_Center 3
215 #define ALIGN_None 0
216 
217 
218 // Possible value of the "flags" field of SHtmlStyle_t are shown below.
219 //
220 // STY_Preformatted If set, the current text occurred within
221 // <pre>..</pre>
222 //
223 // STY_StrikeThru Draw a solid line thru the middle of this text.
224 //
225 // STY_Underline This text should drawn with an underline.
226 //
227 // STY_NoBreak This text occurs within <nobr>..</nobr>
228 //
229 // STY_Anchor This text occurs within <a href=X>..</a>.
230 //
231 // STY_DT This text occurs within <dt>..</dt>.
232 //
233 // STY_Invisible This text should not appear in the main HTML
234 // window. (For example, it might be within
235 // <title>..</title> or <marquee>..</marquee>.)
236 
237 #define STY_Preformatted 0x001
238 #define STY_StrikeThru 0x002
239 #define STY_Underline 0x004
240 #define STY_NoBreak 0x008
241 #define STY_Anchor 0x010
242 #define STY_DT 0x020
243 #define STY_Invisible 0x040
244 #define STY_FontMask (STY_StrikeThru|STY_Underline)
245 
246 
247 //----------------------------------------------------------------------
248 // The first thing done with input HTML text is to parse it into
249 // TGHtmlElements. All sizing and layout is done using these elements.
250 
251 // Every element contains at least this much information:
252 
253 class TGHtmlElement : public TObject {
254 public:
255  TGHtmlElement(int etype = 0);
256 
257  virtual int IsMarkup() const { return (fType > Html_Block); }
258  virtual const char *MarkupArg(const char * /*tag*/, const char * /*zDefault*/) { return 0; }
259  virtual int GetAlignment(int dflt) { return dflt; }
260  virtual int GetOrderedListType(int dflt) { return dflt; }
261  virtual int GetUnorderedListType(int dflt) { return dflt; }
262  virtual int GetVerticalAlignment(int dflt) { return dflt; }
263 
264 public:
265  TGHtmlElement *fPNext; // Next input token in a list of them all
266  TGHtmlElement *fPPrev; // Previous token in a list of them all
267  SHtmlStyle_t fStyle; // The rendering style for this token
268  Html_u8_t fType; // The token type.
269  Html_u8_t fFlags; // The HTML_ flags below
270  Html_16_t fCount; // Various uses, depending on "type"
271  int fElId; // Unique identifier
272  int fOffs; // Offset within zText
273 };
274 
275 
276 // Bitmasks for the "flags" field of the TGHtmlElement
277 
278 #define HTML_Visible 0x01 // This element produces "ink"
279 #define HTML_NewLine 0x02 // type == Html_Space and ends with newline
280 #define HTML_Selected 0x04 // Some or all of this Html_Block is selected
281  // Used by Html_Block elements only.
282 
283 
284 // Each text element holds additional information as shown here. Notice that
285 // extra space is allocated so that zText[] will be large enough to hold the
286 // complete text of the element. X and y coordinates are relative to the
287 // virtual canvas. The y coordinate refers to the baseline.
288 
290 private:
291  TGHtmlTextElement(const TGHtmlTextElement&); // Not implemented.
292  TGHtmlTextElement &operator=(const TGHtmlTextElement&); // Not implemented.
293 
294 public:
295  TGHtmlTextElement(int size);
296  virtual ~TGHtmlTextElement();
297 
298  Html_32_t fY; // y coordinate where text should be rendered
299  Html_16_t fX; // x coordinate where text should be rendered
300  Html_16_t fW; // width of this token in pixels
301  Html_u8_t fAscent; // height above the baseline
302  Html_u8_t fDescent; // depth below the baseline
303  Html_u8_t fSpaceWidth; // Width of one space in the current font
304  char *fZText; // Text for this element. Null terminated
305 };
306 
307 
308 // Each space element is represented like this:
309 
311 public:
312  Html_16_t fW; // Width of a single space in current font
313  Html_u8_t fAscent; // height above the baseline
314  Html_u8_t fDescent; // depth below the baseline
315 
316 public:
317  TGHtmlSpaceElement() : TGHtmlElement(Html_Space), fW(0), fAscent(0), fDescent(0) {}
318 };
319 
320 // Most markup uses this class. Some markup extends this class with
321 // additional information, but most use it as is, at the very least.
322 //
323 // If the markup doesn't have arguments (the "count" field of
324 // TGHtmlElement is 0) then the extra "argv" field of this class
325 // is not allocated and should not be used.
326 
328 public:
329  TGHtmlMarkupElement(int type, int argc, int arglen[], char *argv[]);
330  virtual ~TGHtmlMarkupElement();
331 
332  virtual const char *MarkupArg(const char *tag, const char *zDefault);
333  virtual int GetAlignment(int dflt);
334  virtual int GetOrderedListType(int dflt);
335  virtual int GetUnorderedListType(int dflt);
336  virtual int GetVerticalAlignment(int dflt);
337 
338 public://protected:
339  char **fArgv;
340 };
341 
342 
343 // The maximum number of columns allowed in a table. Any columns beyond
344 // this number are ignored.
345 
346 #define HTML_MAX_COLUMNS 40
347 
348 
349 // This class is used for each <table> element.
350 //
351 // In the minW[] and maxW[] arrays, the [0] element is the overall
352 // minimum and maximum width, including cell padding, spacing and
353 // the "hspace". All other elements are the minimum and maximum
354 // width for the contents of individual cells without any spacing or
355 // padding.
356 
358 public:
359  TGHtmlTable(int type, int argc, int arglen[], char *argv[]);
360  ~TGHtmlTable();
361 
362 public:
363  Html_u8_t fBorderWidth; // Width of the border
364  Html_u8_t fNCol; // Number of columns
365  Html_u16_t fNRow; // Number of rows
366  Html_32_t fY; // top edge of table border
367  Html_32_t fH; // height of the table border
368  Html_16_t fX; // left edge of table border
369  Html_16_t fW; // width of the table border
370  int fMinW[HTML_MAX_COLUMNS+1]; // minimum width of each column
371  int fMaxW[HTML_MAX_COLUMNS+1]; // maximum width of each column
372  TGHtmlElement *fPEnd; // Pointer to the end tag element
373  TImage *fBgImage; // A background for the entire table
374  int fHasbg; // 1 if a table above has bgImage
375 };
376 
377 
378 // Each <td> or <th> markup is represented by an instance of the
379 // following class.
380 //
381 // Drawing for a cell is a sunken 3D border with the border width given
382 // by the borderWidth field in the associated <table> object.
383 
385 public:
386  TGHtmlCell(int type, int argc, int arglen[], char *argv[]);
387  ~TGHtmlCell();
388 
389 public:
390  Html_16_t fRowspan; // Number of rows spanned by this cell
391  Html_16_t fColspan; // Number of columns spanned by this cell
392  Html_16_t fX; // X coordinate of left edge of border
393  Html_16_t fW; // Width of the border
394  Html_32_t fY; // Y coordinate of top of border indentation
395  Html_32_t fH; // Height of the border
396  TGHtmlTable *fPTable; // Pointer back to the <table>
397  TGHtmlElement *fPRow; // Pointer back to the <tr>
398  TGHtmlElement *fPEnd; // Element that ends this cell
399  TImage *fBgImage; // Background for the cell
400 };
401 
402 
403 // This class is used for </table>, </td>, <tr>, </tr> and </th> elements.
404 // It points back to the <table> element that began the table. It is also
405 // used by </a> to point back to the original <a>. I'll probably think of
406 // other uses before all is said and done...
407 
409 public:
410  TGHtmlRef(int type, int argc, int arglen[], char *argv[]);
411  ~TGHtmlRef();
412 
413 public:
414  TGHtmlElement *fPOther; // Pointer to some other Html element
415  TImage *fBgImage; // A background for the entire row
416 };
417 
418 
419 // An instance of the following class is used to represent
420 // each <LI> markup.
421 
423 public:
424  TGHtmlLi(int type, int argc, int arglen[], char *argv[]);
425 
426 public:
427  Html_u8_t fLtype; // What type of list is this?
428  Html_u8_t fAscent; // height above the baseline
429  Html_u8_t fDescent; // depth below the baseline
430  Html_16_t fCnt; // Value for this element (if inside <OL>)
431  Html_16_t fX; // X coordinate of the bullet
432  Html_32_t fY; // Y coordinate of the bullet
433 };
434 
435 
436 // The ltype field of an TGHtmlLi or TGHtmlListStart object can take on
437 // any of the following values to indicate what type of bullet to draw.
438 // The value in TGHtmlLi will take precedence over the value in
439 // TGHtmlListStart if the two values differ.
440 
441 #define LI_TYPE_Undefined 0 // If in TGHtmlLi, use the TGHtmlListStart value
442 #define LI_TYPE_Bullet1 1 // A solid circle
443 #define LI_TYPE_Bullet2 2 // A hollow circle
444 #define LI_TYPE_Bullet3 3 // A hollow square
445 #define LI_TYPE_Enum_1 4 // Arabic numbers
446 #define LI_TYPE_Enum_A 5 // A, B, C, ...
447 #define LI_TYPE_Enum_a 6 // a, b, c, ...
448 #define LI_TYPE_Enum_I 7 // Capitalized roman numerals
449 #define LI_TYPE_Enum_i 8 // Lower-case roman numerals
450 
451 
452 // An instance of this class is used for <UL> or <OL> markup.
453 
455 public:
456  TGHtmlListStart(int type, int argc, int arglen[], char *argv[]);
457 
458 public:
459  Html_u8_t fLtype; // One of the LI_TYPE_ defines above
460  Html_u8_t fCompact; // True if the COMPACT flag is present
461  Html_u16_t fCnt; // Next value for <OL>
462  Html_u16_t fWidth; // How much space to allow for indentation
463  TGHtmlListStart *fLPrev; // Next higher level list, or NULL
464 };
465 
466 
467 #define HTML_MAP_RECT 1
468 #define HTML_MAP_CIRCLE 2
469 #define HTML_MAP_POLY 3
470 
472 public:
473  TGHtmlMapArea(int type, int argc, int arglen[], char *argv[]);
474 
475 public:
476  int fMType;
477  int *fCoords;
478  int fNum;
479 };
480 
481 
482 //----------------------------------------------------------------------
483 
484 // Structure to chain extension data onto.
485 
487  void *fExts;
488  int fTyp;
489  int fFlags;
491 };
492 
493 
494 //----------------------------------------------------------------------
495 
496 // Information about each image on the HTML widget is held in an instance
497 // of the following class. All images are held on a list attached to the
498 // main widget object.
499 //
500 // This class is NOT an element. The <IMG> element is represented by an
501 // TGHtmlImageMarkup object below. There is one TGHtmlImageMarkup for each
502 // <IMG> in the source HTML. There is one of these objects for each unique
503 // image loaded. (If two <IMG> specify the same image, there are still two
504 // TGHtmlImageMarkup objects but only one TGHtmlImage object that is shared
505 // between them.)
506 
507 class TGHtml;
508 class TGHtmlImageMarkup;
509 
510 class TGHtmlImage : public TObject {
511 private:
512  TGHtmlImage(const TGHtmlImage&); // Not implemented.
513  TGHtmlImage &operator=(const TGHtmlImage&); // Not implemented.
514 
515 public:
516  TGHtmlImage(TGHtml *htm, const char *url, const char *width,
517  const char *height);
518  virtual ~TGHtmlImage();
519 
520 public:
521  TGHtml *fHtml; // The owner of this image
522  TImage *fImage; // The image token
523  Html_32_t fW; // Requested width of this image (0 if none)
524  Html_32_t fH; // Requested height of this image (0 if none)
525  char *fZUrl; // The URL for this image.
526  char *fZWidth, *fZHeight; // Width and height in the <img> markup.
527  TGHtmlImage *fPNext; // Next image on the list
528  TGHtmlImageMarkup *fPList; // List of all <IMG> markups that use this
529  // same image
530  TTimer *fTimer; // for animations
531 };
532 
533 // Each <img> markup is represented by an instance of the following
534 // class.
535 //
536 // If pImage == 0, then we use the alternative text in zAlt.
537 
539 public:
540  TGHtmlImageMarkup(int type, int argc, int arglen[], char *argv[]);
541 
542 public:
543  Html_u8_t fAlign; // Alignment. See IMAGE_ALIGN_ defines below
544  Html_u8_t fTextAscent; // Ascent of text font in force at the <IMG>
545  Html_u8_t fTextDescent; // Descent of text font in force at the <IMG>
546  Html_u8_t fRedrawNeeded; // Need to redraw this image because the image
547  // content changed.
548  Html_16_t fH; // Actual height of the image
549  Html_16_t fW; // Actual width of the image
550  Html_16_t fAscent; // How far image extends above "y"
551  Html_16_t fDescent; // How far image extends below "y"
552  Html_16_t fX; // X coordinate of left edge of the image
553  Html_32_t fY; // Y coordinate of image baseline
554  const char *fZAlt; // Alternative text
555  TGHtmlImage *fPImage; // Corresponding TGHtmlImage object
556  TGHtmlElement *fPMap; // usemap
557  TGHtmlImageMarkup *fINext; // Next markup using the same TGHtmlImage object
558 };
559 
560 
561 // Allowed alignments for images. These represent the allowed arguments
562 // to the "align=" field of the <IMG> markup.
563 
564 #define IMAGE_ALIGN_Bottom 0
565 #define IMAGE_ALIGN_Middle 1
566 #define IMAGE_ALIGN_Top 2
567 #define IMAGE_ALIGN_TextTop 3
568 #define IMAGE_ALIGN_AbsMiddle 4
569 #define IMAGE_ALIGN_AbsBottom 5
570 #define IMAGE_ALIGN_Left 6
571 #define IMAGE_ALIGN_Right 7
572 
573 
574 // All kinds of form markup, including <INPUT>, <TEXTAREA> and <SELECT>
575 // are represented by instances of the following class.
576 //
577 // (later...) We also use this for the <APPLET> markup. That way,
578 // the window we create for an <APPLET> responds to the TGHtml::MapControls()
579 // and TGHtml::UnmapControls() function calls. For an <APPLET>, the
580 // pForm field is NULL. (Later still...) <EMBED> works just like
581 // <APPLET> so it uses this class too.
582 
583 class TGHtmlForm;
584 
586 public:
587  TGHtmlInput(int type, int argc, int arglen[], char *argv[]);
588 
589  void Empty();
590 
591 public:
592  TGHtmlForm *fPForm; // The <FORM> to which this belongs
593  TGHtmlInput *fINext; // Next element in a list of all input elements
594  TGFrame *fFrame; // The xclass window that implements this control
595  TGHtml *fHtml; // The HTML widget this control is attached to
596  TGHtmlElement *fPEnd; // End tag for <TEXTAREA>, etc.
597  Html_u16_t fInpId; // Unique id for this element
598  Html_u16_t fSubId; // For radio - an id, for select - option count
599  Html_32_t fY; // Baseline for this input element
600  Html_u16_t fX; // Left edge
601  Html_u16_t fW, fH; // Width and height of this control
602  Html_u8_t fPadLeft; // Extra padding on left side of the control
603  Html_u8_t fAlign; // One of the IMAGE_ALIGN_xxx types
604  Html_u8_t fTextAscent; // Ascent for the current font
605  Html_u8_t fTextDescent; // descent for the current font
606  Html_u8_t fItype; // What type of input is this?
607  Html_u8_t fSized; // True if this input has been sized already
608  Html_u16_t fCnt; // Used to derive widget name. 0 if no widget
609 };
610 
611 
612 // An input control can be one of the following types. See the
613 // comment about <APPLET> on the TGHtmlInput class insight into
614 // INPUT_TYPE_Applet.
615 
616 #define INPUT_TYPE_Unknown 0
617 #define INPUT_TYPE_Checkbox 1
618 #define INPUT_TYPE_File 2
619 #define INPUT_TYPE_Hidden 3
620 #define INPUT_TYPE_Image 4
621 #define INPUT_TYPE_Password 5
622 #define INPUT_TYPE_Radio 6
623 #define INPUT_TYPE_Reset 7
624 #define INPUT_TYPE_Select 8
625 #define INPUT_TYPE_Submit 9
626 #define INPUT_TYPE_Text 10
627 #define INPUT_TYPE_TextArea 11
628 #define INPUT_TYPE_Applet 12
629 #define INPUT_TYPE_Button 13
630 
631 
632 // There can be multiple <FORM> entries on a single HTML page.
633 // Each one must be given a unique number for identification purposes,
634 // and so we can generate unique state variable names for radiobuttons,
635 // checkbuttons, and entry boxes.
636 
638 public:
639  TGHtmlForm(int type, int argc, int arglen[], char *argv[]);
640 
641 public:
642  Html_u16_t fFormId; // Unique number assigned to this form
643  unsigned int fElements; // Number of elements
644  unsigned int fHasctl; // Has controls
645  TGHtmlElement *fPFirst; // First form element
646  TGHtmlElement *fPEnd; // Pointer to end tag element
647 };
648 
649 
650 // Information used by a <HR> markup
651 
653 public:
654  TGHtmlHr(int type, int argc, int arglen[], char *argv[]);
655 
656 public:
657  Html_32_t fY; // Baseline for this input element
658  Html_u16_t fX; // Left edge
659  Html_u16_t fW, fH; // Width and height of this control
660  Html_u8_t fIs3D; // Is it drawn 3D?
661 };
662 
663 
664 // Information used by a <A> markup
665 
667 public:
668  TGHtmlAnchor(int type, int argc, int arglen[], char *argv[]);
669 
670 public:
671  Html_32_t fY; // Top edge for this element
672 };
673 
674 
675 // Information about the <SCRIPT> markup. The parser treats <SCRIPT>
676 // specially. All text between <SCRIPT> and </SCRIPT> is captured and
677 // is indexed to by the nStart field of this class.
678 //
679 // The nStart field indexs to a spot in the zText field of the TGHtml object.
680 // The nScript field determines how long the script is.
681 
683 public:
684  TGHtmlScript(int type, int argc, int arglen[], char *argv[]);
685 
686 public:
687  int fNStart; // Start of the script (index into TGHtml::zText)
688  int fNScript; // Number of characters of text in zText holding
689  // the complete text of this script
690 };
691 
692 
693 // A block is a single unit of display information. This can be one or more
694 // text elements, or the border of table, or an image, etc.
695 //
696 // Blocks are used to improve display speed and to improve the speed of
697 // linear searchs through the token list. A single block will typically
698 // contain enough information to display a dozen or more Text and Space
699 // elements all with a single call to OXFont::DrawChars(). The blocks are
700 // linked together on their own list, so we can search them much faster than
701 // elements (since there are fewer of them.)
702 //
703 // Of course, you can construct pathological HTML that has as many Blocks as
704 // it has normal tokens. But you haven't lost anything. Using blocks just
705 // speeds things up in the common case.
706 //
707 // Much of the information needed for display is held in the original
708 // TGHtmlElement objects. "fPNext" points to the first object in the list
709 // which can be used to find the "style" "x" and "y".
710 //
711 // If n is zero, then "fPNext" might point to a special TGHtmlElement
712 // that defines some other kind of drawing, like <LI> or <IMG> or <INPUT>.
713 
714 class TGHtmlBlock : public TGHtmlElement {
715 public:
716  TGHtmlBlock();
717  virtual ~TGHtmlBlock();
718 
719 public:
720  char *fZ; // Space to hold text when n > 0
721  int fTop, fBottom; // Extremes of y coordinates
722  Html_u16_t fLeft, fRight; // Left and right boundry of this object
723  Html_u16_t fN; // Number of characters in z[]
724  TGHtmlBlock *fBPrev, *fBNext; // Linked list of all Blocks
725 };
726 
727 
728 // A stack of these structures is used to keep track of nested font and
729 // style changes. This allows us to easily revert to the previous style
730 // when we encounter and end-tag like </em> or </h3>.
731 //
732 // This stack is used to keep track of the current style while walking
733 // the list of elements. After all elements have been assigned a style,
734 // the information in this stack is no longer used.
735 
737  SHtmlStyleStack_t *fPNext; // Next style on the stack
738  int fType; // A markup that ends this style. Ex: Html_EndEM
739  SHtmlStyle_t fStyle; // The currently active style.
740 };
741 
742 
743 // A stack of the following structures is used to remember the
744 // left and right margins within a layout context.
745 
747  int fIndent; // Size of the current margin
748  int fBottom; // Y value at which this margin expires
749  int fTag; // Markup that will cancel this margin
750  SHtmlMargin_t *fPNext; // Previous margin
751 };
752 
753 
754 // How much space (in pixels) used for a single level of indentation due
755 // to a <UL> or <DL> or <BLOCKQUOTE>, etc.
756 
757 #define HTML_INDENT 36
758 
759 
760 //----------------------------------------------------------------------
761 
762 // A layout context holds all state information used by the layout engine.
763 
764 class TGHtmlLayoutContext : public TObject {
765 public:
767 
768  void LayoutBlock();
769  void Reset();
770 
771  void PopIndent();
772  void PushIndent();
773 
774 protected:
775  void PushMargin(SHtmlMargin_t **ppMargin, int indent, int bottom, int tag);
776  void PopOneMargin(SHtmlMargin_t **ppMargin);
777  void PopMargin(SHtmlMargin_t **ppMargin, int tag);
778  void PopExpiredMargins(SHtmlMargin_t **ppMarginStack, int y);
779  void ClearMarginStack(SHtmlMargin_t **ppMargin);
780 
782  int width, int minX, int *actualWidth);
783 
784  void FixAnchors(TGHtmlElement *p, TGHtmlElement *pEnd, int y);
785  int FixLine(TGHtmlElement *pStart, TGHtmlElement *pEnd,
786  int bottom, int width, int actualWidth, int leftMargin,
787  int *maxX);
788  void Paragraph(TGHtmlElement *p);
789  void ComputeMargins(int *pX, int *pY, int *pW);
790  void ClearObstacle(int mode);
792  int InWrapAround();
793  void WidenLine(int reqWidth, int *pX, int *pY, int *pW);
794 
796 
797 public:
798  TGHtml *fHtml; // The html widget undergoing layout
799  TGHtmlElement *fPStart; // Start of elements to layout
800  TGHtmlElement *fPEnd; // Stop when reaching this element
801  int fHeadRoom; // Extra space wanted above this line
802  int fTop; // Absolute top of drawing area
803  int fBottom; // Bottom of previous line
804  int fLeft, fRight; // Left and right extremes of drawing area
805  int fPageWidth; // Width of the layout field, including
806  // the margins
807  int fMaxX, fMaxY; // Maximum X and Y values of paint
808  SHtmlMargin_t *fLeftMargin; // Stack of left margins
809  SHtmlMargin_t *fRightMargin; // Stack of right margins
810 };
811 
812 
813 // With 28 different fonts and 16 colors, we could in principle have
814 // as many as 448 different GCs. But in practice, a single page of
815 // HTML will typically have much less than this. So we won't try to
816 // keep all GCs on hand. Instead, we'll keep around the most recently
817 // used GCs and allocate new ones as necessary.
818 //
819 // The following structure is used to build a cache of GCs in the
820 // main widget object.
821 
822 #define N_CACHE_GC 32
823 
824 struct GcCache_t {
825  GContext_t fGc; // The graphics context
826  Html_u8_t fFont; // Font used for this context
827  Html_u8_t fColor; // Color used for this context
828  Html_u8_t fIndex; // Index used for LRU replacement
829 };
830 
831 
832 // An SHtmlIndex_t is a reference to a particular character within a
833 // particular Text or Space token.
834 
835 struct SHtmlIndex_t {
836  TGHtmlElement *fP; // The token containing the character
837  int fI; // Index of the character
838 };
839 
840 
841 // Used by the tokenizer
842 
844  const char *fZName; // Name of a markup
845  Html_16_t fType; // Markup type code
846  Html_16_t fObjType; // Which kind of TGHtml... object to alocate
847  SHtmlTokenMap_t *fPCollide; // Hash table collision chain
848 };
849 
850 
851 // Markup element types to be allocated by the tokenizer.
852 // Do not confuse with .type field in TGHtmlElement
853 
854 #define O_HtmlMarkupElement 0
855 #define O_HtmlCell 1
856 #define O_HtmlTable 2
857 #define O_HtmlRef 3
858 #define O_HtmlLi 4
859 #define O_HtmlListStart 5
860 #define O_HtmlImageMarkup 6
861 #define O_HtmlInput 7
862 #define O_HtmlForm 8
863 #define O_HtmlHr 9
864 #define O_HtmlAnchor 10
865 #define O_HtmlScript 11
866 #define O_HtmlMapArea 12
867 
868 
869 //----------------------------------------------------------------------
870 
871 // The HTML widget. A derivate of TGView.
872 
873 class TGListBox;
874 class THashTable;
875 
876 class TGHtml : public TGView {
877 public:
878  TGHtml(const TGWindow *p, int w, int h, int id = -1);
879  virtual ~TGHtml();
880 
881  virtual Bool_t HandleFocusChange(Event_t *event);
882  virtual Bool_t HandleButton(Event_t *event);
883  virtual Bool_t HandleMotion(Event_t *event);
884 
886  virtual Bool_t HandleTimer(TTimer *timer);
887 
889 
890  virtual void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h);
891  virtual Bool_t ItemLayout();
892 
895 
896 public: // user commands
897 
898  int ParseText(char *text, const char *index = 0);
899 
900  void SetTableRelief(int relief);
901  int GetTableRelief() const { return fTableRelief; }
902 
903  void SetRuleRelief(int relief);
904  int GetRuleRelief() const { return fRuleRelief; }
905  int GetRulePadding() const { return fRulePadding; }
906 
907  void UnderlineLinks(int onoff);
908 
909  void SetBaseUri(const char *uri);
910  const char *GetBaseUri() const { return fZBase; }
911 
912  int GotoAnchor(const char *name);
913 
914 public: // reloadable methods
915 
916  // called when the widget is cleared
917  virtual void Clear(Option_t * = "");
918 
919  // User function to resolve URIs
920  virtual char *ResolveUri(const char *uri);
921 
922  // User function to get an image from a URL
923  virtual TImage *LoadImage(const char *uri, int w = 0, int h = 0) ;//
924  // { return 0; }
925 
926  // User function to tell if a hyperlink has already been visited
927  virtual int IsVisited(const char * /*url*/)
928  { return kFALSE; }
929 
930  // User function to process tokens of the given type
931  virtual int ProcessToken(TGHtmlElement * /*pElem*/, const char * /*name*/, int /*type*/)
932  { return kFALSE; }
933 
934  virtual TGFont *GetFont(int iFont);
935 
936  // The HTML parser will invoke the following methods from time
937  // to time to find out information it needs to complete formatting of
938  // the document.
939 
940  // Method for handling <frameset> markup
941  virtual int ProcessFrame()
942  { return kFALSE; }
943 
944  // Method to process applets
945  virtual TGFrame *ProcessApplet(TGHtmlInput * /*input*/)
946  { return 0; }
947 
948  // Called when parsing forms
949  virtual int FormCreate(TGHtmlForm * /*form*/, const char * /*zUrl*/, const char * /*args*/)
950  { return kFALSE; }
951 
952  // Called when user presses Submit
953  virtual int FormAction(TGHtmlForm * /*form*/, int /*id*/)
954  { return kFALSE; }
955 
956  // Invoked to find font names
957  virtual char *GetFontName()
958  { return 0; }
959 
960  // Invoked for each <SCRIPT> markup
961  virtual char *ProcessScript(TGHtmlScript * /*script*/)
962  { return 0; }
963 
964 public:
965  const char *GetText() const { return fZText; }
966 
967  int GetMarginWidth() { return fMargins.fL + fMargins.fR; }
968  int GetMarginHeight() { return fMargins.fT + fMargins.fB; }
969 
970  TGHtmlInput *GetInputElement(int x, int y);
971  const char *GetHref(int x, int y, const char **target = 0);
972 
974 
975  int InArea(TGHtmlMapArea *p, int left, int top, int x, int y);
976  TGHtmlElement *GetMap(const char *name);
977 
979  int ElementCoords(TGHtmlElement *p, int i, int pct, int *coords);
980 
981  TGHtmlElement *TableDimensions(TGHtmlTable *pStart, int lineWidth);
982  int CellSpacing(TGHtmlElement *pTable);
983  void MoveVertically(TGHtmlElement *p, TGHtmlElement *pLast, int dy);
984 
985  void PrintList(TGHtmlElement *first, TGHtmlElement *last);
986 
987  char *GetTokenName(TGHtmlElement *p);
988  char *DumpToken(TGHtmlElement *p);
989 
990  void EncodeText(TGString *str, const char *z);
991 
992 protected:
993  void HClear();
994  void ClearGcCache();
995  void ResetLayoutContext();
996  void Redraw();
997  void ComputeVirtualSize();
998 
999  void ScheduleRedraw();
1000 
1001  void RedrawArea(int left, int top, int right, int bottom);
1002  void RedrawBlock(TGHtmlBlock *p);
1003  void RedrawEverything();
1004  void RedrawText(int y);
1005 
1006  float ColorDistance(ColorStruct_t *pA, ColorStruct_t *pB);
1007  int IsDarkColor(ColorStruct_t *p);
1008  int IsLightColor(ColorStruct_t *p);
1009  int GetColorByName(const char *zColor);
1010  int GetDarkShadowColor(int iBgColor);
1011  int GetLightShadowColor(int iBgColor);
1012  int GetColorByValue(ColorStruct_t *pRef);
1013 
1014  void FlashCursor();
1015 
1016  GContext_t GetGC(int color, int font);
1017  GContext_t GetAnyGC();
1018 
1020  void ImageChanged(TGHtmlImage *image, int newWidth, int newHeight);
1022  int GetImageAt(int x, int y);
1023  const char *GetPctWidth(TGHtmlElement *p, char *opt, char *ret);
1024  void TableBgndImage(TGHtmlElement *p);
1025 
1027  void UnlinkAndFreeBlock(TGHtmlBlock *pBlock);
1028  void AppendBlock(TGHtmlElement *pToken, TGHtmlBlock *pBlock);
1029 
1030  void StringHW(const char *str, int *h, int *w);
1031  TGHtmlElement *MinMax(TGHtmlElement *p, int *pMin, int *pMax,
1032  int lineWidth, int hasbg);
1033 
1035  int x, int y);
1036  void DrawRect(Drawable_t drawable, TGHtmlElement *src,
1037  int x, int y, int w, int h, int depth, int relief);
1038  void BlockDraw(TGHtmlBlock *pBlock, Drawable_t wid,
1039  int left, int top,
1040  int width, int height, Pixmap_t pixmap);
1042  int left, int top,
1043  int right, int bottom);
1044  void DrawTableBgnd(int x, int y, int w, int h, Drawable_t d, TImage *image);
1045 
1047  void FormBlocks();
1048 
1049  void AppendElement(TGHtmlElement *pElem);
1050  int Tokenize();
1051  void AppToken(TGHtmlElement *pNew, TGHtmlElement *p, int offs);
1052  TGHtmlMarkupElement *MakeMarkupEntry(int objType, int type, int argc,
1053  int arglen[], char *argv[]);
1054  void TokenizerAppend(const char *text);
1056  char *zType, char *zArgs, int offs);
1057  SHtmlTokenMap_t *NameToPmap(char *zType);
1058  int NameToType(char *zType);
1059  const char *TypeToName(int type);
1060  int TextInsertCmd(int argc, char **argv);
1062 
1063  TGHtmlElement *TokenByIndex(int N, int flag);
1064  int TokenNumber(TGHtmlElement *p);
1065 
1066  void MaxIndex(TGHtmlElement *p, int *pIndex, int isLast);
1067  int IndexMod(TGHtmlElement **pp, int *ip, char *cp);
1068  void FindIndexInBlock(TGHtmlBlock *pBlock, int x,
1069  TGHtmlElement **ppToken, int *pIndex);
1070  void IndexToBlockIndex(SHtmlIndex_t sIndex,
1071  TGHtmlBlock **ppBlock, int *piIndex);
1072  int DecodeBaseIndex(const char *zBase,
1073  TGHtmlElement **ppToken, int *pIndex);
1074  int GetIndex(const char *zIndex, TGHtmlElement **ppToken, int *pIndex);
1075 
1076  void LayoutDoc();
1077 
1078  int MapControls();
1079  void UnmapControls();
1080  void DeleteControls();
1081  int ControlSize(TGHtmlInput *p);
1082  void SizeAndLink(TGFrame *frame, TGHtmlInput *pElem);
1083  int FormCount(TGHtmlInput *p, int radio);
1084  void AddFormInfo(TGHtmlElement *p);
1086  void AppendText(TGString *str, TGHtmlElement *pFirst, TGHtmlElement *pEnd);
1087 
1088  void UpdateSelection(int forceUpdate);
1089  void UpdateSelectionDisplay();
1090  void LostSelection();
1091  int SelectionSet(const char *startIx, const char *endIx);
1092  void UpdateInsert();
1093  int SetInsert(const char *insIx);
1094 
1095  const char *GetUid(const char *string);
1096  ColorStruct_t *AllocColor(const char *name);
1098  void FreeColor(ColorStruct_t *color);
1099 
1101  void PushStyleStack(int tag, SHtmlStyle_t style);
1102  SHtmlStyle_t PopStyleStack(int tag);
1103 
1104  void MakeInvisible(TGHtmlElement *p_first, TGHtmlElement *p_last);
1105  int GetLinkColor(const char *zURL);
1106  void AddStyle(TGHtmlElement *p);
1107  void Sizer();
1108 
1109  int NextMarkupType(TGHtmlElement *p);
1110 
1111  TGHtmlElement *AttrElem(const char *name, char *value);
1112 
1113 public:
1114  void AppendArglist(TGString *str, TGHtmlMarkupElement *pElem);
1117  TGString *TableText(TGHtmlTable *pTable, int flags);
1118 
1119  virtual void MouseOver(const char *uri) { Emit("MouseOver(const char *)",uri); } // *SIGNAL*
1120  virtual void MouseDown(const char *uri) { Emit("MouseDown(const char *)",uri); } // *SIGNAL*
1121  virtual void ButtonClicked(const char *name, const char *val); // *SIGNAL*
1122  virtual void SubmitClicked(const char *val); // *SIGNAL*
1123  virtual void CheckToggled(const char *name, Bool_t on, const char *val); // *SIGNAL*
1124  virtual void RadioChanged(const char *name, const char *val); // *SIGNAL*
1125  virtual void InputSelected(const char *name, const char *val); //*SIGNAL*
1126  virtual void SavePrimitive(std::ostream &out, Option_t * = "");
1127 
1128 protected:
1129  virtual void UpdateBackgroundStart();
1130 
1131 protected:
1132  TGHtmlElement *fPFirst; // First HTML token on a list of them all
1133  TGHtmlElement *fPLast; // Last HTML token on the list
1134  int fNToken; // Number of HTML tokens on the list.
1135  // Html_Block tokens don't count.
1136  TGHtmlElement *fLastSized; // Last HTML element that has been sized
1137  TGHtmlElement *fNextPlaced; // Next HTML element that needs to be
1138  // positioned on canvas.
1139  TGHtmlBlock *fFirstBlock; // List of all TGHtmlBlock tokens
1140  TGHtmlBlock *fLastBlock; // Last TGHtmlBlock in the list
1141  TGHtmlInput *fFirstInput; // First <INPUT> element
1142  TGHtmlInput *fLastInput; // Last <INPUT> element
1143  int fNInput; // The number of <INPUT> elements
1144  int fNForm; // The number of <FORM> elements
1145  int fVarId; // Used to construct a unique name for a
1146  // global array used by <INPUT> elements
1147  int fInputIdx; // Unique input index
1148  int fRadioIdx; // Unique radio index
1149 
1150  // Information about the selected region of text
1151 
1152  SHtmlIndex_t fSelBegin; // Start of the selection
1153  SHtmlIndex_t fSelEnd; // End of the selection
1154  TGHtmlBlock *fPSelStartBlock; // Block in which selection starts
1155  Html_16_t fSelStartIndex; // Index in pSelStartBlock of first selected
1156  // character
1157  Html_16_t fSelEndIndex; // Index of last selecte char in pSelEndBlock
1158  TGHtmlBlock *fPSelEndBlock; // Block in which selection ends
1159 
1160  // Information about the insertion cursor
1161 
1162  int fInsOnTime; // How long the cursor states one (millisec)
1163  int fInsOffTime; // How long it is off (milliseconds)
1164  int fInsStatus; // Is it visible?
1165  TTimer *fInsTimer; // Timer used to flash the insertion cursor
1166  SHtmlIndex_t fIns; // The insertion cursor position
1167  TGHtmlBlock *fPInsBlock; // The TGHtmlBlock containing the cursor
1168  int fInsIndex; // Index in pInsBlock of the cursor
1169 
1170  // The following fields hold state information used by the tokenizer.
1171 
1172  char *fZText; // Complete text of the unparsed HTML
1173  int fNText; // Number of characters in zText
1174  int fNAlloc; // Space allocated for zText
1175  int fNComplete; // How much of zText has actually been
1176  // converted into tokens
1177  int fICol; // The column in which zText[nComplete]
1178  // occurs. Used to resolve tabs in input
1179  int fIPlaintext; // If not zero, this is the token type that
1180  // caused us to go into plaintext mode. One
1181  // of Html_PLAINTEXT, Html_LISTING or
1182  // Html_XMP
1183  TGHtmlScript *fPScript; // <SCRIPT> currently being parsed
1184 
1186 
1187  // These fields hold state information used by the HtmlAddStyle routine.
1188  // We have to store this state information here since HtmlAddStyle
1189  // operates incrementally. This information must be carried from
1190  // one incremental execution to the next.
1191 
1192  SHtmlStyleStack_t *fStyleStack; // The style stack
1193  int fParaAlignment; // Justification associated with <p>
1194  int fRowAlignment; // Justification associated with <tr>
1195  int fAnchorFlags; // Style flags associated with <A>...</A>
1196  int fInDt; // Style flags associated with <DT>...</DT>
1197  int fInTr; // True if within <tr>..</tr>
1198  int fInTd; // True if within <td>..</td> or <th>..</th>
1199  TGHtmlAnchor *fAnchorStart; // Most recent <a href=...>
1200  TGHtmlForm *fFormStart; // Most recent <form>
1201  TGHtmlInput *fFormElemStart; // Most recent <textarea> or <select>
1202  TGHtmlInput *fFormElemLast; // Most recent <input>, <textarea> or <select>
1203  TGHtmlListStart *fInnerList; // The inner most <OL> or <UL>
1204  TGHtmlElement *fLoEndPtr; // How far AddStyle has gone to
1205  TGHtmlForm *fLoFormStart; // For AddStyle
1206 
1207  // These fields are used to hold the state of the layout engine.
1208  // Because the layout is incremental, this state must be held for
1209  // the life of the widget.
1210 
1212 
1213  // Information used when displaying the widget:
1214 
1215  int fHighlightWidth; // Width in pixels of highlight to draw
1216  // around widget when it has the focus.
1217  // <= 0 means don't draw a highlight.
1218  TGInsets fMargins; // document margins (separation between the
1219  // edge of the clip window and rendered HTML).
1220  ColorStruct_t *fHighlightBgColorPtr; // Color for drawing traversal highlight
1221  // area when highlight is off.
1222  ColorStruct_t *fHighlightColorPtr; // Color for drawing traversal highlight.
1223  TGFont *fAFont[N_FONT]; // Information about all screen fonts
1224  char fFontValid[(N_FONT+7)/8]; // If bit N%8 of work N/8 of this field is 0
1225  // if aFont[N] needs to be reallocated before
1226  // being used.
1227  ColorStruct_t *fApColor[N_COLOR]; // Information about all colors
1228  Long_t fColorUsed; // bit N is 1 if color N is in use. Only
1229  // applies to colors that aren't predefined
1230  int fIDark[N_COLOR]; // Dark 3D shadow of color K is iDark[K]
1231  int fILight[N_COLOR]; // Light 3D shadow of color K is iLight[K]
1232  ColorStruct_t *fBgColor; // Background color of the HTML document
1233  ColorStruct_t *fFgColor; // Color of normal text. apColor[0]
1234  ColorStruct_t *fNewLinkColor; // Color of unvisitied links. apColor[1]
1235  ColorStruct_t *fOldLinkColor; // Color of visitied links. apColor[2]
1236  ColorStruct_t *fSelectionColor; // Background color for selections
1237  GcCache_t fAGcCache[N_CACHE_GC]; // A cache of GCs for general use
1239  int fLastGC; // Index of recently used GC
1240  TGHtmlImage *fImageList; // A list of all images
1241  TImage *fBgImage; // Background image
1242 
1243  int fFormPadding; // Amount to pad form elements by
1244  int fOverrideFonts; // TRUE if we should override fonts
1245  int fOverrideColors; // TRUE if we should override colors
1246  int fUnderlineLinks; // TRUE if we should underline hyperlinks
1247  int fHasScript; // TRUE if we can do scripts for this page
1248  int fHasFrames; // TRUE if we can do frames for this page
1249  int fAddEndTags; // TRUE if we add /LI etc.
1250  int fTableBorderMin; // Force tables to have min border size
1251  int fVarind; // Index suffix for unique global var name
1252 
1253  // Information about the selection
1254 
1255  int fExportSelection; // True if the selection is automatically
1256  // exported to the clipboard
1257 
1258  // Miscellaneous information:
1259 
1260  int fTableRelief; // 3d effects on <TABLE>
1261  int fRuleRelief; // 3d effects on <HR>
1262  int fRulePadding; // extra pixels above and below <HR>
1263  const char *fZBase; // The base URI
1264  char *fZBaseHref; // zBase as modified by <BASE HREF=..> markup
1265  Cursor_t fCursor; // Current cursor for window, or None.
1266  int fMaxX, fMaxY; // Maximum extent of any "paint" that appears
1267  // on the virtual canvas. Used to compute
1268  // scrollbar positions.
1269  int fDirtyLeft, fDirtyTop; // Top left corner of region to redraw. These
1270  // are physical screen coordinates relative to
1271  // the clip win, not main window.
1272  int fDirtyRight, fDirtyBottom; // Bottom right corner of region to redraw
1273  int fFlags; // Various flags; see below for definitions.
1274  int fIdind;
1275  int fInParse; // Prevent update if parsing
1276  char *fZGoto; // Label to goto right after layout
1277 
1278  SHtmlExtensions_t *fExts; // Pointer to user extension data
1279 
1280  THashTable *fUidTable; // Hash table for some used string values
1281  // like color names, etc.
1282  const char *fLastUri; // Used in HandleMotion
1283  int fExiting; // True if the widget is being destroyed
1284 
1285  ClassDef(TGHtml, 0); // HTML widget
1286 };
1287 
1288 
1289 // Flag bits "flags" field of the Html widget:
1290 //
1291 // REDRAW_PENDING An idle handler has already been queued to
1292 // call the TGHtml::Redraw() method.
1293 //
1294 // GOT_FOCUS This widget currently has input focus.
1295 //
1296 // HSCROLL Horizontal scrollbar position needs to be
1297 // recomputed.
1298 //
1299 // VSCROLL Vertical scrollbar position needs to be
1300 // recomputed.
1301 //
1302 // RELAYOUT We need to reposition every element on the
1303 // virtual canvas. (This happens, for example,
1304 // when the size of the widget changes and we
1305 // need to recompute the line breaks.)
1306 //
1307 // RESIZE_ELEMENTS We need to recompute the size of every element.
1308 // This happens, for example, when the fonts
1309 // change.
1310 //
1311 // REDRAW_FOCUS We need to repaint the focus highlight border.
1312 //
1313 // REDRAW_TEXT Everything in the clipping window needs to be redrawn.
1314 //
1315 // STYLER_RUNNING There is a call to HtmlAddStyle() in process.
1316 // Used to prevent a recursive call to HtmlAddStyle().
1317 //
1318 // INSERT_FLASHING True if there is a timer scheduled that will toggle
1319 // the state of the insertion cursor.
1320 //
1321 // REDRAW_IMAGES One or more TGHtmlImageMarkup objects have their
1322 // redrawNeeded flag set.
1323 
1324 #define REDRAW_PENDING 0x000001
1325 #define GOT_FOCUS 0x000002
1326 #define HSCROLL 0x000004
1327 #define VSCROLL 0x000008
1328 #define RELAYOUT 0x000010
1329 #define RESIZE_ELEMENTS 0x000020
1330 #define REDRAW_FOCUS 0x000040
1331 #define REDRAW_TEXT 0x000080
1332 #define EXTEND_LAYOUT 0x000100
1333 #define STYLER_RUNNING 0x000200
1334 #define INSERT_FLASHING 0x000400
1335 #define REDRAW_IMAGES 0x000800
1336 #define ANIMATE_IMAGES 0x001000
1337 
1338 
1339 // Macros to set, clear or test bits of the "flags" field.
1340 
1341 #define HtmlHasFlag(A,F) (((A)->flags&(F))==(F))
1342 #define HtmlHasAnyFlag(A,F) (((A)->flags&(F))!=0)
1343 #define HtmlSetFlag(A,F) ((A)->flags|=(F))
1344 #define HtmlClearFlag(A,F) ((A)->flags&=~(F))
1345 
1346 
1347 // No coordinate is ever as big as this number
1348 
1349 #define LARGE_NUMBER 100000000
1350 
1351 
1352 // Default values for configuration options
1353 
1354 #define DEF_HTML_BG_COLOR DEF_FRAME_BG_COLOR
1355 #define DEF_HTML_BG_MONO DEF_FRAME_BG_MONO
1356 #define DEF_HTML_EXPORT_SEL 1
1357 #define DEF_HTML_FG DEF_BUTTON_FG
1358 #define DEF_HTML_HIGHLIGHT_BG DEF_BUTTON_HIGHLIGHT_BG
1359 #define DEF_HTML_HIGHLIGHT DEF_BUTTON_HIGHLIGHT
1360 #define DEF_HTML_HIGHLIGHT_WIDTH "0"
1361 #define DEF_HTML_INSERT_OFF_TIME 300
1362 #define DEF_HTML_INSERT_ON_TIME 600
1363 #define DEF_HTML_PADX (HTML_INDENT / 4)
1364 #define DEF_HTML_PADY (HTML_INDENT / 4)
1365 #define DEF_HTML_RELIEF "raised"
1366 #define DEF_HTML_SELECTION_COLOR "skyblue"
1367 #define DEF_HTML_TAKE_FOCUS "0"
1368 #define DEF_HTML_UNVISITED "blue2"
1369 #define DEF_HTML_VISITED "purple4"
1370 
1371 #ifdef NAVIGATOR_TABLES
1372 
1373 #define DEF_HTML_TABLE_BORDER "0"
1374 #define DEF_HTML_TABLE_CELLPADDING "2"
1375 #define DEF_HTML_TABLE_CELLSPACING "5"
1376 #define DEF_HTML_TABLE_BORDER_LIGHT_COLOR "gray80"
1377 #define DEF_HTML_TABLE_BORDER_DARK_COLOR "gray40"
1378 
1379 #endif // NAVIGATOR_TABLES
1380 
1381 
1382 //----------------------------------------------------------------------
1383 
1384 // Messages generated by the HTML widget
1385 /*
1386 class TGHtmlMessage : public OWidgetMessage {
1387 public:
1388  TGHtmlMessage(int t, int a, int i, const char *u, int rx, int ry) :
1389  OWidgetMessage(t, a, i) {
1390  uri = u;
1391  x_root = rx;
1392  y_root = ry;
1393  }
1394 
1395 public:
1396  const char *uri;
1397  //ORectangle bbox;
1398  int x_root, y_root;
1399 };
1400 */
1401 
1402 #endif // ROOT_TGHtml
Html_32_t fY
Definition: TGHtml.h:366
TGHtmlForm * fFormStart
Definition: TGHtml.h:1200
SHtmlIndex_t fSelBegin
Definition: TGHtml.h:1152
int fParaAlignment
Definition: TGHtml.h:1193
unsigned int fHasctl
Definition: TGHtml.h:644
TImage * fBgImage
Definition: TGHtml.h:399
int fDirtyBottom
Definition: TGHtml.h:1272
Long_t fColorUsed
Definition: TGHtml.h:1228
TGHtmlElement * GetLine(TGHtmlElement *pStart, TGHtmlElement *pEnd, int width, int minX, int *actualWidth)
This routine gathers as many tokens as will fit on one line.
virtual int FormCreate(TGHtmlForm *, const char *, const char *)
Definition: TGHtml.h:949
TGHtmlBlock * fPSelStartBlock
Definition: TGHtml.h:1154
int fILight[N_COLOR]
Definition: TGHtml.h:1231
char * fZHeight
Definition: TGHtml.h:526
virtual void InputSelected(const char *name, const char *val)
Emit Selected() signal.
Definition: TGHtml.cxx:1312
void UpdateInsert()
Recompute the position of the insertion cursor based on the position in fIns.
Definition: TGHtml.cxx:2023
TGString * TableText(TGHtmlTable *pTable, int flags)
Return text and images from a table as lists.
TGHtmlInput(int type, int argc, int arglen[], char *argv[])
HTML input element constructor.
Html_16_t fX
Definition: TGHtml.h:431
TGHtml * fHtml
Definition: TGHtml.h:798
Html_u16_t fNRow
Definition: TGHtml.h:365
void TokenizerAppend(const char *text)
Append text to the tokenizer engine.
int fRulePadding
Definition: TGHtml.h:1262
char * fZ
Definition: TGHtml.h:720
Html_u8_t fLtype
Definition: TGHtml.h:459
#define N_FONT
Definition: TGHtml.h:169
TImage * fBgImage
Definition: TGHtml.h:415
void RedrawBlock(TGHtmlBlock *p)
Redraw the TGHtmlBlock given.
Definition: TGHtml.cxx:852
int fExportSelection
Definition: TGHtml.h:1255
Html_u8_t fAscent
Definition: TGHtml.h:313
unsigned int fColor
Definition: TGHtml.h:149
TGHtmlElement * fP
Definition: TGHtml.h:836
Definition: TGView.h:49
TGHtmlListStart * fLPrev
Definition: TGHtml.h:463
void PrintList(TGHtmlElement *first, TGHtmlElement *last)
Print a list of tokens.
TGHtmlElement * fLoEndPtr
Definition: TGHtml.h:1204
SHtmlStyleStack_t * fStyleStack
Definition: TGHtml.h:1192
const char * fZBase
Definition: TGHtml.h:1263
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save a html widget as a C++ statement(s) on output stream out.
Definition: TGHtml.cxx:2061
int fTop
Definition: TGHtml.h:721
void Paragraph(TGHtmlElement *p)
Increase the headroom to create a paragraph break at the current token.
TGHtmlImageMarkup * fINext
Definition: TGHtml.h:557
int GotoAnchor(const char *name)
Go to anchor position.
Definition: TGHtml.cxx:447
virtual int ProcessFrame()
Definition: TGHtml.h:941
Html_16_t fAscent
Definition: TGHtml.h:550
int fHasbg
Definition: TGHtml.h:374
TGHtmlElement * fNextPlaced
Definition: TGHtml.h:1137
TGHtmlElement * AttrElem(const char *name, char *value)
Returns html element matching attribute name and value.
Definition: TGHtml.cxx:1846
Html_16_t fObjType
Definition: TGHtml.h:846
TGHtmlElement * fPOther
Definition: TGHtml.h:414
virtual void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h)
Draw region defined by [x,y] [w,h].
Definition: TGHtml.cxx:791
virtual int IsMarkup() const
Definition: TGHtml.h:257
void AppendText(TGString *str, TGHtmlElement *pFirst, TGHtmlElement *pEnd)
Append all text and space tokens between pStart and pEnd to the given TString.
Definition: TGHtmlForm.cxx:246
char * fZUrl
Definition: TGHtml.h:525
SHtmlTokenMap_t * NameToPmap(char *zType)
Returns token map matching zType name.
TGHtmlBlock * fPSelEndBlock
Definition: TGHtml.h:1158
TGHtmlMarkupElement(int type, int argc, int arglen[], char *argv[])
HTML mrkup element constructor.
const char Option_t
Definition: RtypesCore.h:62
Html_u16_t fRight
Definition: TGHtml.h:722
void UpdateSelectionDisplay()
The fPSelStartBlock and fPSelEndBlock values have been changed.
Definition: TGHtml.cxx:1920
void ResetLayoutContext()
Reset the main layout context in the main widget.
Definition: TGHtml.cxx:519
TGHtmlBlock * fLastBlock
Definition: TGHtml.h:1140
Html_32_t fY
Definition: TGHtml.h:599
int fInsOnTime
Definition: TGHtml.h:1162
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
void Sizer()
Compute the size of all elements in the widget.
Html_u16_t fSubId
Definition: TGHtml.h:598
void SizeAndLink(TGFrame *frame, TGHtmlInput *pElem)
'frame' is the child widget that is used to implement an input element.
Definition: TGHtmlForm.cxx:192
virtual void Clear(Option_t *="")
Erase all HTML from this widget and clear the screen.
Definition: TGHtml.cxx:296
TH1 * h
Definition: legend2.C:5
int NameToType(char *zType)
Convert a markup name into a type integer.
void LayoutBlock()
Do as much layout as possible on the block of text defined by the HtmlLayoutContext.
SHtmlTokenMap_t * fPCollide
Definition: TGHtml.h:847
void ClearObstacle(int mode)
Clear a wrap-around obstacle.
virtual void SubmitClicked(const char *val)
Emit SubmitClicked() signal.
Definition: TGHtml.cxx:1325
char * fZText
Definition: TGHtml.h:1172
TGHtmlBlock * fBPrev
Definition: TGHtml.h:724
Html_u8_t fIs3D
Definition: TGHtml.h:660
Handle_t Cursor_t
Definition: GuiTypes.h:35
virtual int GetUnorderedListType(int dflt)
Definition: TGHtml.h:261
TGHtmlBlock()
ctor.
Definition: TGHtmlDraw.cxx:46
int fInsStatus
Definition: TGHtml.h:1164
TGHtmlBlock * fPInsBlock
Definition: TGHtml.h:1167
virtual int GetVerticalAlignment(int dflt)
Definition: TGHtml.h:262
Html_u8_t fTextAscent
Definition: TGHtml.h:544
void MaxIndex(TGHtmlElement *p, int *pIndex, int isLast)
Find the maximum index for the given token.
Definition: TGHtmlIndex.cxx:97
void DrawTableBgnd(int x, int y, int w, int h, Drawable_t d, TImage *image)
Draw table background.
Definition: TGHtmlDraw.cxx:856
TGHtmlElement * fPLast
Definition: TGHtml.h:1133
void PushIndent()
Adjust (push) ident.
int fMaxW[HTML_MAX_COLUMNS+1]
Definition: TGHtml.h:371
#define N
int fRuleRelief
Definition: TGHtml.h:1261
int IndexMod(TGHtmlElement **pp, int *ip, char *cp)
Modify an index for both pointer and char +/-/=N.
Handle_t GContext_t
Definition: GuiTypes.h:39
SHtmlMargin_t * fLeftMargin
Definition: TGHtml.h:808
TGHtmlBlock * fFirstBlock
Definition: TGHtml.h:1139
int HtmlDepth
Definition: TGHtml.cxx:61
TGHtmlLayoutContext()
Html Layout Context constructor.
void LostSelection()
Clear selection.
Definition: TGHtml.cxx:1966
void DeleteControls()
Delete all input controls.
Definition: TGHtmlForm.cxx:103
TGHtmlImage * fImageList
Definition: TGHtml.h:1240
virtual TGFont * GetFont(int iFont)
The rendering and layout routines should call this routine in order to get a font structure...
Definition: TGHtml.cxx:1404
virtual void MouseDown(const char *uri)
Definition: TGHtml.h:1120
TGHtmlRef(int type, int argc, int arglen[], char *argv[])
HTML ref element constructor.
Html_16_t fX
Definition: TGHtml.h:392
int Int_t
Definition: RtypesCore.h:41
Bool_t HandleRadioButton(TGHtmlInput *p)
Handle radio button event.
Definition: TGHtml.cxx:1253
bool Bool_t
Definition: RtypesCore.h:59
TImage * fBgImage
Definition: TGHtml.h:373
unsigned int fExpbg
Definition: TGHtml.h:153
TGHtmlInput * fLastInput
Definition: TGHtml.h:1142
const Bool_t kFALSE
Definition: Rtypes.h:92
char fFontValid[(N_FONT+7)/8]
Definition: TGHtml.h:1224
unsigned int fElements
Definition: TGHtml.h:643
TGHtmlElement * MinMax(TGHtmlElement *p, int *pMin, int *pMax, int lineWidth, int hasbg)
Given a list of elements, compute the minimum and maximum width needed to render the list...
int fIDark[N_COLOR]
Definition: TGHtml.h:1230
void ScheduleRedraw()
Make sure that a call to the Redraw() routine has been queued.
Definition: TGHtml.cxx:748
Handle_t Drawable_t
Definition: GuiTypes.h:32
TGHtmlMarkupElement * MakeMarkupEntry(int objType, int type, int argc, int arglen[], char *argv[])
Make one markup entry.
void UnderlineLinks(int onoff)
Set/reset html links underline.
Definition: TGHtml.cxx:394
virtual ~TGHtmlTextElement()
HTML element destructor.
Html_u8_t fAlign
Definition: TGHtml.h:603
An abstract interface to image processing library.
Definition: TImage.h:45
int TextInsertCmd(int argc, char **argv)
Insert text into text token, or break token into two text tokens.
int fBottom
Definition: TGHtml.h:748
int fNToken
Definition: TGHtml.h:1134
void RedrawEverything()
Call this routine to force the entire widget to be redrawn.
Definition: TGHtml.cxx:863
GcCache_t fAGcCache[N_CACHE_GC]
Definition: TGHtml.h:1237
TGHtmlElement * TableLayout(TGHtmlTable *p)
Do all layout for a single table.
int fICol
Definition: TGHtml.h:1177
virtual int ProcessToken(TGHtmlElement *, const char *, int)
Definition: TGHtml.h:931
void AddFormInfo(TGHtmlElement *p)
Add the DOM control information for form elements.
Definition: TGHtmlForm.cxx:565
void AddSelectOptions(TGListBox *lb, TGHtmlElement *p, TGHtmlElement *pEnd)
The "p" argument points to a ,