Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TGHtml.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // $Id: TGHtml.h,v 1.1 2007/05/04 17:07:01 brun Exp $
0002 // Author:  Valeriy Onuchin   03/05/2007
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2021, Rene Brun, Fons Rademakers and Reiner Rohlfs *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 /**************************************************************************
0013 
0014     HTML widget for xclass. Based on tkhtml 1.28
0015     Copyright (C) 1997-2000 D. Richard Hipp <drh@acm.org>
0016     Copyright (C) 2002-2003 Hector Peraza.
0017 
0018     This library is free software; you can redistribute it and/or
0019     modify it under the terms of the GNU Library General Public
0020     License as published by the Free Software Foundation; either
0021     version 2 of the License, or (at your option) any later version.
0022 
0023     This library is distributed in the hope that it will be useful,
0024     but WITHOUT ANY WARRANTY; without even the implied warranty of
0025     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0026     Library General Public License for more details.
0027 
0028     You should have received a copy of the GNU Library General Public
0029     License along with this library; if not, write to the Free
0030     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
0031 
0032 **************************************************************************/
0033 
0034 #ifndef ROOT_TGHtml
0035 #define ROOT_TGHtml
0036 
0037 #include "TGView.h"
0038 
0039 #include "TGHtmlTokens.h"
0040 
0041 class TGClient;
0042 class TImage;
0043 class TGFont;
0044 class TGIdleHandler;
0045 class THashTable;
0046 class TTimer;
0047 class TGPopupMenu;
0048 
0049 //----------------------------------------------------------------------
0050 
0051 #define HTML_RELIEF_FLAT    0
0052 #define HTML_RELIEF_SUNKEN  1
0053 #define HTML_RELIEF_RAISED  2
0054 
0055 //#define TABLE_TRIM_BLANK 1
0056 
0057 // Debug must be turned on for testing to work.
0058 //#define DEBUG
0059 
0060 #define CANT_HAPPEN  \
0061   fprintf(stderr, \
0062           "Unplanned behavior in the HTML Widget in file %s line %d\n", \
0063           __FILE__, __LINE__)
0064 
0065 #define UNTESTED  \
0066   fprintf(stderr, \
0067           "Untested code executed in the HTML Widget in file %s line %d\n", \
0068           __FILE__, __LINE__)
0069 
0070 // Sanity checking macros.
0071 
0072 #ifdef DEBUG
0073 #define HtmlAssert(X) \
0074   if(!(X)){ \
0075     fprintf(stderr,"Assertion failed on line %d of %s\n",__LINE__,__FILE__); \
0076   }
0077 #define HtmlCantHappen \
0078   fprintf(stderr,"Can't happen on line %d of %s\n",__LINE__,__FILE__);
0079 #else
0080 #define HtmlAssert(X)
0081 #define HtmlCantHappen
0082 #endif
0083 
0084 // Bitmasks for the HtmlTraceMask global variable
0085 
0086 #define HtmlTrace_Table1       0x00000001
0087 #define HtmlTrace_Table2       0x00000002
0088 #define HtmlTrace_Table3       0x00000004
0089 #define HtmlTrace_Table4       0x00000008
0090 #define HtmlTrace_Table5       0x00000010
0091 #define HtmlTrace_Table6       0x00000020
0092 #define HtmlTrace_GetLine      0x00000100
0093 #define HtmlTrace_GetLine2     0x00000200
0094 #define HtmlTrace_FixLine      0x00000400
0095 #define HtmlTrace_BreakMarkup  0x00001000
0096 #define HtmlTrace_Style        0x00002000
0097 #define HtmlTrace_Input1       0x00004000
0098 
0099 // The TRACE macro is used to print internal information about the
0100 // HTML layout engine during testing and debugging. The amount of
0101 // information printed is governed by a global variable named
0102 // HtmlTraceMask. If bits in the first argument to the TRACE macro
0103 // match any bits in HtmlTraceMask variable, then the trace message
0104 // is printed.
0105 //
0106 // All of this is completely disabled, of course, if the DEBUG macro
0107 // is not defined.
0108 
0109 #ifdef DEBUG
0110 extern int HtmlTraceMask;
0111 extern int HtmlDepth;
0112 # define TRACE_INDENT  printf("%*s",HtmlDepth-3,"")
0113 # define TRACE(Flag, Args) \
0114     if( (Flag)&HtmlTraceMask ){ \
0115        TRACE_INDENT; printf Args; fflush(stdout); \
0116     }
0117 # define TRACE_PUSH(Flag)  if( (Flag)&HtmlTraceMask ){ HtmlDepth+=3; }
0118 # define TRACE_POP(Flag)   if( (Flag)&HtmlTraceMask ){ HtmlDepth-=3; }
0119 #else
0120 # define TRACE_INDENT
0121 # define TRACE(Flag, Args)
0122 # define TRACE_PUSH(Flag)
0123 # define TRACE_POP(Flag)
0124 #endif
0125 
0126 
0127 //----------------------------------------------------------------------
0128 
0129 // Various data types. This code is designed to run on a modern cached
0130 // architecture where the CPU runs a lot faster than the memory bus. Hence
0131 // we try to pack as much data into as small a space as possible so that it
0132 // is more likely to fit in cache. The extra CPU instruction or two needed
0133 // to unpack the data is not normally an issue since we expect the speed of
0134 // the memory bus to be the limiting factor.
0135 
0136 typedef unsigned char  Html_u8_t;      // 8-bit unsigned integer
0137 typedef short          Html_16_t;      // 16-bit signed integer
0138 typedef unsigned short Html_u16_t;     // 16-bit unsigned integer
0139 typedef int            Html_32_t;      // 32-bit signed integer
0140 
0141 // An instance of the following structure is used to record style
0142 // information on each Html element.
0143 
0144 struct SHtmlStyle_t {
0145   unsigned int fFont      : 6;      // Font to use for display
0146   unsigned int fColor     : 6;      // Foreground color
0147   signed int   fSubscript : 4;      // Positive for <sup>, negative for <sub>
0148   unsigned int fAlign     : 2;      // Horizontal alignment
0149   unsigned int fBgcolor   : 6;      // Background color
0150   unsigned int fExpbg     : 1;      // Set to 1 if bgcolor explicitly set
0151   unsigned int fFlags     : 7;      // the STY_ flags below
0152 };
0153 
0154 
0155 // We allow 8 different font families: Normal, Bold, Italic and Bold-Italic
0156 // in either variable or constant width. Within each family there can be up
0157 // to 7 font sizes from 1 (the smallest) up to 7 (the largest). Hence, the
0158 // widget can use a maximum of 56 fonts. The ".font" field of the style is
0159 // an integer between 0 and 55 which indicates which font to use.
0160 
0161 // HP: we further subdivide the .font field into two 3-bit subfields (size
0162 // and family). That makes easier to manipulate the family field.
0163 
0164 #define N_FONT_FAMILY     8
0165 #define N_FONT_SIZE       7
0166 #define N_FONT            71
0167 #define NormalFont(X)     (X)
0168 #define BoldFont(X)       ((X) | 8)
0169 #define ItalicFont(X)     ((X) | 16)
0170 #define CWFont(X)         ((X) | 32)
0171 #define FontSize(X)       ((X) & 007)
0172 #define FontFamily(X)     ((X) & 070)
0173 #define FONT_Any          -1
0174 #define FONT_Default      3
0175 #define FontSwitch(Size, Bold, Italic, Cw) \
0176                           ((Size) | ((Bold+(Italic)*2+(Cw)*4) << 3))
0177 
0178 // Macros for manipulating the fontValid bitmap of an TGHtml object.
0179 
0180 #define FontIsValid(I)     ((fFontValid[(I)>>3] &   (1<<((I)&3)))!=0)
0181 #define FontSetValid(I)     (fFontValid[(I)>>3] |=  (1<<((I)&3)))
0182 #define FontClearValid(I)   (fFontValid[(I)>>3] &= ~(1<<((I)&3)))
0183 
0184 
0185 // Information about available colors.
0186 //
0187 // The widget will use at most N_COLOR colors. 4 of these colors are
0188 // predefined. The rest are user selectable by options to various markups.
0189 // (Ex: <font color=red>)
0190 //
0191 // All colors are stored in the apColor[] array of the main widget object.
0192 // The ".color" field of the SHtmlStyle_t is an integer between 0 and
0193 // N_COLOR-1 which indicates which of these colors to use.
0194 
0195 #define N_COLOR             32      // Total number of colors
0196 
0197 #define COLOR_Normal         0      // Index for normal color (black)
0198 #define COLOR_Unvisited      1      // Index for unvisited hyperlinks
0199 #define COLOR_Visited        2      // Color for visited hyperlinks
0200 #define COLOR_Selection      3      // Background color for the selection
0201 #define COLOR_Background     4      // Default background color
0202 #define N_PREDEFINED_COLOR   5      // Number of predefined colors
0203 
0204 
0205 // The "align" field of the style determines how text is justified
0206 // horizontally. ALIGN_None means that the alignment is not specified.
0207 // (It should probably default to ALIGN_Left in this case.)
0208 
0209 #define ALIGN_Left   1
0210 #define ALIGN_Right  2
0211 #define ALIGN_Center 3
0212 #define ALIGN_None   0
0213 
0214 
0215 // Possible value of the "flags" field of SHtmlStyle_t are shown below.
0216 //
0217 //  STY_Preformatted       If set, the current text occurred within
0218 //                         <pre>..</pre>
0219 //
0220 //  STY_StrikeThru         Draw a solid line thru the middle of this text.
0221 //
0222 //  STY_Underline          This text should drawn with an underline.
0223 //
0224 //  STY_NoBreak            This text occurs within <nobr>..</nobr>
0225 //
0226 //  STY_Anchor             This text occurs within <a href=X>..</a>.
0227 //
0228 //  STY_DT                 This text occurs within <dt>..</dt>.
0229 //
0230 //  STY_Invisible          This text should not appear in the main HTML
0231 //                         window. (For example, it might be within
0232 //                         <title>..</title> or <marquee>..</marquee>.)
0233 
0234 #define STY_Preformatted    0x001
0235 #define STY_StrikeThru      0x002
0236 #define STY_Underline       0x004
0237 #define STY_NoBreak         0x008
0238 #define STY_Anchor          0x010
0239 #define STY_DT              0x020
0240 #define STY_Invisible       0x040
0241 #define STY_FontMask        (STY_StrikeThru|STY_Underline)
0242 
0243 
0244 //----------------------------------------------------------------------
0245 // The first thing done with input HTML text is to parse it into
0246 // TGHtmlElements. All sizing and layout is done using these elements.
0247 
0248 // Every element contains at least this much information:
0249 
0250 class TGHtmlElement : public TObject {
0251 public:
0252    TGHtmlElement(int etype = 0);
0253 
0254    virtual int  IsMarkup() const { return (fType > Html_Block); }
0255    virtual const char *MarkupArg(const char * /*tag*/, const char * /*zDefault*/) { return nullptr; }
0256    virtual int  GetAlignment(int dflt) { return dflt; }
0257    virtual int  GetOrderedListType(int dflt) { return dflt; }
0258    virtual int  GetUnorderedListType(int dflt) { return dflt; }
0259    virtual int  GetVerticalAlignment(int dflt) { return dflt; }
0260 
0261 public:
0262    TGHtmlElement *fPNext;        // Next input token in a list of them all
0263    TGHtmlElement *fPPrev;        // Previous token in a list of them all
0264    SHtmlStyle_t   fStyle;        // The rendering style for this token
0265    Html_u8_t      fType;         // The token type.
0266    Html_u8_t      fFlags;        // The HTML_ flags below
0267    Html_16_t      fCount;        // Various uses, depending on "type"
0268    int            fElId;         // Unique identifier
0269    int            fOffs;         // Offset within zText
0270 };
0271 
0272 
0273 // Bitmasks for the "flags" field of the TGHtmlElement
0274 
0275 #define HTML_Visible   0x01   // This element produces "ink"
0276 #define HTML_NewLine   0x02   // type == Html_Space and ends with newline
0277 #define HTML_Selected  0x04   // Some or all of this Html_Block is selected
0278                               // Used by Html_Block elements only.
0279 
0280 
0281 // Each text element holds additional information as shown here. Notice that
0282 // extra space is allocated so that zText[] will be large enough to hold the
0283 // complete text of the element. X and y coordinates are relative to the
0284 // virtual canvas. The y coordinate refers to the baseline.
0285 
0286 class TGHtmlTextElement : public TGHtmlElement {
0287 private:
0288    TGHtmlTextElement(const TGHtmlTextElement&) = delete;
0289    TGHtmlTextElement &operator=(const TGHtmlTextElement&) = delete;
0290 
0291 public:
0292    TGHtmlTextElement(int size);
0293    ~TGHtmlTextElement() override;
0294 
0295    Html_32_t    fY;                // y coordinate where text should be rendered
0296    Html_16_t    fX;                // x coordinate where text should be rendered
0297    Html_16_t    fW;                // width of this token in pixels
0298    Html_u8_t    fAscent;           // height above the baseline
0299    Html_u8_t    fDescent;          // depth below the baseline
0300    Html_u8_t    fSpaceWidth;       // Width of one space in the current font
0301    char        *fZText;            // Text for this element. Null terminated
0302 };
0303 
0304 
0305 // Each space element is represented like this:
0306 
0307 class TGHtmlSpaceElement : public TGHtmlElement {
0308 public:
0309    Html_16_t fW;                  // Width of a single space in current font
0310    Html_u8_t fAscent;             // height above the baseline
0311    Html_u8_t fDescent;            // depth below the baseline
0312 
0313 public:
0314    TGHtmlSpaceElement() : TGHtmlElement(Html_Space), fW(0), fAscent(0), fDescent(0) {}
0315 };
0316 
0317 // Most markup uses this class. Some markup extends this class with
0318 // additional information, but most use it as is, at the very least.
0319 //
0320 // If the markup doesn't have arguments (the "count" field of
0321 // TGHtmlElement is 0) then the extra "argv" field of this class
0322 // is not allocated and should not be used.
0323 
0324 class TGHtmlMarkupElement : public TGHtmlElement {
0325 public:
0326    TGHtmlMarkupElement(int type, int argc, int arglen[], char *argv[]);
0327    ~TGHtmlMarkupElement() override;
0328 
0329    const char *MarkupArg(const char *tag, const char *zDefault) override;
0330    int  GetAlignment(int dflt) override;
0331    int  GetOrderedListType(int dflt) override;
0332    int  GetUnorderedListType(int dflt) override;
0333    int  GetVerticalAlignment(int dflt) override;
0334 
0335 public://protected:
0336    char **fArgv;
0337 };
0338 
0339 
0340 // The maximum number of columns allowed in a table. Any columns beyond
0341 // this number are ignored.
0342 
0343 #define HTML_MAX_COLUMNS 40
0344 
0345 
0346 // This class is used for each <table> element.
0347 //
0348 // In the minW[] and maxW[] arrays, the [0] element is the overall
0349 // minimum and maximum width, including cell padding, spacing and
0350 // the "hspace". All other elements are the minimum and maximum
0351 // width for the contents of individual cells without any spacing or
0352 // padding.
0353 
0354 class TGHtmlTable : public TGHtmlMarkupElement {
0355 public:
0356    TGHtmlTable(int type, int argc, int arglen[], char *argv[]);
0357    ~TGHtmlTable() override;
0358 
0359 public:
0360    Html_u8_t      fBorderWidth;              // Width of the border
0361    Html_u8_t      fNCol;                     // Number of columns
0362    Html_u16_t     fNRow;                     // Number of rows
0363    Html_32_t      fY;                        // top edge of table border
0364    Html_32_t      fH;                        // height of the table border
0365    Html_16_t      fX;                        // left edge of table border
0366    Html_16_t      fW;                        // width of the table border
0367    int            fMinW[HTML_MAX_COLUMNS+1]; // minimum width of each column
0368    int            fMaxW[HTML_MAX_COLUMNS+1]; // maximum width of each column
0369    TGHtmlElement *fPEnd;                     // Pointer to the end tag element
0370    TImage        *fBgImage;                  // A background for the entire table
0371    int            fHasbg;                    // 1 if a table above has bgImage
0372 };
0373 
0374 
0375 // Each <td> or <th> markup is represented by an instance of the
0376 // following class.
0377 //
0378 // Drawing for a cell is a sunken 3D border with the border width given
0379 // by the borderWidth field in the associated <table> object.
0380 
0381 class TGHtmlCell : public TGHtmlMarkupElement {
0382 public:
0383    TGHtmlCell(int type, int argc, int arglen[], char *argv[]);
0384    ~TGHtmlCell() override;
0385 
0386 public:
0387    Html_16_t      fRowspan;      // Number of rows spanned by this cell
0388    Html_16_t      fColspan;      // Number of columns spanned by this cell
0389    Html_16_t      fX;            // X coordinate of left edge of border
0390    Html_16_t      fW;            // Width of the border
0391    Html_32_t      fY;            // Y coordinate of top of border indentation
0392    Html_32_t      fH;            // Height of the border
0393    TGHtmlTable   *fPTable;       // Pointer back to the <table>
0394    TGHtmlElement *fPRow;         // Pointer back to the <tr>
0395    TGHtmlElement *fPEnd;         // Element that ends this cell
0396    TImage        *fBgImage;      // Background for the cell
0397 };
0398 
0399 
0400 // This class is used for </table>, </td>, <tr>, </tr> and </th> elements.
0401 // It points back to the <table> element that began the table. It is also
0402 // used by </a> to point back to the original <a>. I'll probably think of
0403 // other uses before all is said and done...
0404 
0405 class TGHtmlRef : public TGHtmlMarkupElement {
0406 public:
0407    TGHtmlRef(int type, int argc, int arglen[], char *argv[]);
0408    ~TGHtmlRef() override;
0409 
0410 public:
0411    TGHtmlElement *fPOther;      // Pointer to some other Html element
0412    TImage        *fBgImage;     // A background for the entire row
0413 };
0414 
0415 
0416 // An instance of the following class is used to represent
0417 // each <LI> markup.
0418 
0419 class TGHtmlLi : public TGHtmlMarkupElement {
0420 public:
0421    TGHtmlLi(int type, int argc, int arglen[], char *argv[]);
0422 
0423 public:
0424    Html_u8_t fLtype;    // What type of list is this?
0425    Html_u8_t fAscent;   // height above the baseline
0426    Html_u8_t fDescent;  // depth below the baseline
0427    Html_16_t fCnt;      // Value for this element (if inside <OL>)
0428    Html_16_t fX;        // X coordinate of the bullet
0429    Html_32_t fY;        // Y coordinate of the bullet
0430 };
0431 
0432 
0433 // The ltype field of an TGHtmlLi or TGHtmlListStart object can take on
0434 // any of the following values to indicate what type of bullet to draw.
0435 // The value in TGHtmlLi will take precedence over the value in
0436 // TGHtmlListStart if the two values differ.
0437 
0438 #define LI_TYPE_Undefined 0     // If in TGHtmlLi, use the TGHtmlListStart value
0439 #define LI_TYPE_Bullet1   1     // A solid circle
0440 #define LI_TYPE_Bullet2   2     // A hollow circle
0441 #define LI_TYPE_Bullet3   3     // A hollow square
0442 #define LI_TYPE_Enum_1    4     // Arabic numbers
0443 #define LI_TYPE_Enum_A    5     // A, B, C, ...
0444 #define LI_TYPE_Enum_a    6     // a, b, c, ...
0445 #define LI_TYPE_Enum_I    7     // Capitalized roman numerals
0446 #define LI_TYPE_Enum_i    8     // Lower-case roman numerals
0447 
0448 
0449 // An instance of this class is used for <UL> or <OL> markup.
0450 
0451 class TGHtmlListStart : public TGHtmlMarkupElement {
0452 public:
0453    TGHtmlListStart(int type, int argc, int arglen[], char *argv[]);
0454 
0455 public:
0456    Html_u8_t         fLtype;     // One of the LI_TYPE_ defines above
0457    Html_u8_t         fCompact;   // True if the COMPACT flag is present
0458    Html_u16_t        fCnt;       // Next value for <OL>
0459    Html_u16_t        fWidth;     // How much space to allow for indentation
0460    TGHtmlListStart  *fLPrev;     // Next higher level list, or NULL
0461 };
0462 
0463 
0464 #define HTML_MAP_RECT    1
0465 #define HTML_MAP_CIRCLE  2
0466 #define HTML_MAP_POLY    3
0467 
0468 class TGHtmlMapArea : public TGHtmlMarkupElement {
0469 public:
0470    TGHtmlMapArea(int type, int argc, int arglen[], char *argv[]);
0471 
0472 public:
0473    int    fMType;
0474    int   *fCoords;
0475    int    fNum;
0476 };
0477 
0478 
0479 //----------------------------------------------------------------------
0480 
0481 // Structure to chain extension data onto.
0482 
0483 struct SHtmlExtensions_t {
0484    void              *fExts;
0485    int                fTyp;
0486    int                fFlags;
0487    SHtmlExtensions_t *fNext;
0488 };
0489 
0490 
0491 //----------------------------------------------------------------------
0492 
0493 // Information about each image on the HTML widget is held in an instance
0494 // of the following class. All images are held on a list attached to the
0495 // main widget object.
0496 //
0497 // This class is NOT an element. The <IMG> element is represented by an
0498 // TGHtmlImageMarkup object below. There is one TGHtmlImageMarkup for each
0499 // <IMG> in the source HTML. There is one of these objects for each unique
0500 // image loaded. (If two <IMG> specify the same image, there are still two
0501 // TGHtmlImageMarkup objects but only one TGHtmlImage object that is shared
0502 // between them.)
0503 
0504 class TGHtml;
0505 class TGHtmlImageMarkup;
0506 
0507 class TGHtmlImage : public TObject {
0508 private:
0509    TGHtmlImage(const TGHtmlImage&) = delete;
0510    TGHtmlImage &operator=(const TGHtmlImage&) = delete;
0511 
0512 public:
0513    TGHtmlImage(TGHtml *htm, const char *url, const char *width,
0514                const char *height);
0515    ~TGHtmlImage() override;
0516 
0517 public:
0518    TGHtml            *fHtml;              // The owner of this image
0519    TImage            *fImage;             // The image token
0520    Html_32_t          fW;                 // Requested width of this image (0 if none)
0521    Html_32_t          fH;                 // Requested height of this image (0 if none)
0522    char              *fZUrl;              // The URL for this image.
0523    char              *fZWidth, *fZHeight; // Width and height in the <img> markup.
0524    TGHtmlImage       *fPNext;             // Next image on the list
0525    TGHtmlImageMarkup *fPList;             // List of all <IMG> markups that use this
0526                                           // same image
0527    TTimer            *fTimer;             // for animations
0528 };
0529 
0530 // Each <img> markup is represented by an instance of the following
0531 // class.
0532 //
0533 // If pImage == 0, then we use the alternative text in zAlt.
0534 
0535 class TGHtmlImageMarkup : public TGHtmlMarkupElement {
0536 public:
0537    TGHtmlImageMarkup(int type, int argc, int arglen[], char *argv[]);
0538 
0539 public:
0540    Html_u8_t          fAlign;          // Alignment. See IMAGE_ALIGN_ defines below
0541    Html_u8_t          fTextAscent;     // Ascent of text font in force at the <IMG>
0542    Html_u8_t          fTextDescent;    // Descent of text font in force at the <IMG>
0543    Html_u8_t          fRedrawNeeded;   // Need to redraw this image because the image
0544                                        // content changed.
0545    Html_16_t          fH;              // Actual height of the image
0546    Html_16_t          fW;              // Actual width of the image
0547    Html_16_t          fAscent;         // How far image extends above "y"
0548    Html_16_t          fDescent;        // How far image extends below "y"
0549    Html_16_t          fX;              // X coordinate of left edge of the image
0550    Html_32_t          fY;              // Y coordinate of image baseline
0551    const char        *fZAlt;           // Alternative text
0552    TGHtmlImage       *fPImage;         // Corresponding TGHtmlImage object
0553    TGHtmlElement     *fPMap;           // usemap
0554    TGHtmlImageMarkup *fINext;          // Next markup using the same TGHtmlImage object
0555 };
0556 
0557 
0558 // Allowed alignments for images. These represent the allowed arguments
0559 // to the "align=" field of the <IMG> markup.
0560 
0561 #define IMAGE_ALIGN_Bottom        0
0562 #define IMAGE_ALIGN_Middle        1
0563 #define IMAGE_ALIGN_Top           2
0564 #define IMAGE_ALIGN_TextTop       3
0565 #define IMAGE_ALIGN_AbsMiddle     4
0566 #define IMAGE_ALIGN_AbsBottom     5
0567 #define IMAGE_ALIGN_Left          6
0568 #define IMAGE_ALIGN_Right         7
0569 
0570 
0571 // All kinds of form markup, including <INPUT>, <TEXTAREA> and <SELECT>
0572 // are represented by instances of the following class.
0573 //
0574 // (later...)  We also use this for the <APPLET> markup. That way,
0575 // the window we create for an <APPLET> responds to the TGHtml::MapControls()
0576 // and TGHtml::UnmapControls() function calls. For an <APPLET>, the
0577 // pForm field is NULL. (Later still...) <EMBED> works just like
0578 // <APPLET> so it uses this class too.
0579 
0580 class TGHtmlForm;
0581 
0582 class TGHtmlInput : public TGHtmlMarkupElement {
0583 public:
0584    TGHtmlInput(int type, int argc, int arglen[], char *argv[]);
0585 
0586    void Empty();
0587 
0588 public:
0589    TGHtmlForm     *fPForm;       // The <FORM> to which this belongs
0590    TGHtmlInput    *fINext;       // Next element in a list of all input elements
0591    TGFrame        *fFrame;       // The xclass window that implements this control
0592    TGHtml         *fHtml;        // The HTML widget this control is attached to
0593    TGHtmlElement  *fPEnd;        // End tag for <TEXTAREA>, etc.
0594    Html_u16_t      fInpId;       // Unique id for this element
0595    Html_u16_t      fSubId;       // For radio - an id, for select - option count
0596    Html_32_t       fY;           // Baseline for this input element
0597    Html_u16_t      fX;           // Left edge
0598    Html_u16_t      fW, fH;       // Width and height of this control
0599    Html_u8_t       fPadLeft;     // Extra padding on left side of the control
0600    Html_u8_t       fAlign;       // One of the IMAGE_ALIGN_xxx types
0601    Html_u8_t       fTextAscent;  // Ascent for the current font
0602    Html_u8_t       fTextDescent; // descent for the current font
0603    Html_u8_t       fItype;       // What type of input is this?
0604    Html_u8_t       fSized;       // True if this input has been sized already
0605    Html_u16_t      fCnt;         // Used to derive widget name. 0 if no widget
0606 };
0607 
0608 
0609 // An input control can be one of the following types. See the
0610 // comment about <APPLET> on the TGHtmlInput class insight into
0611 // INPUT_TYPE_Applet.
0612 
0613 #define INPUT_TYPE_Unknown      0
0614 #define INPUT_TYPE_Checkbox     1
0615 #define INPUT_TYPE_File         2
0616 #define INPUT_TYPE_Hidden       3
0617 #define INPUT_TYPE_Image        4
0618 #define INPUT_TYPE_Password     5
0619 #define INPUT_TYPE_Radio        6
0620 #define INPUT_TYPE_Reset        7
0621 #define INPUT_TYPE_Select       8
0622 #define INPUT_TYPE_Submit       9
0623 #define INPUT_TYPE_Text        10
0624 #define INPUT_TYPE_TextArea    11
0625 #define INPUT_TYPE_Applet      12
0626 #define INPUT_TYPE_Button      13
0627 
0628 
0629 // There can be multiple <FORM> entries on a single HTML page.
0630 // Each one must be given a unique number for identification purposes,
0631 // and so we can generate unique state variable names for radiobuttons,
0632 // checkbuttons, and entry boxes.
0633 
0634 class TGHtmlForm : public TGHtmlMarkupElement {
0635 public:
0636    TGHtmlForm(int type, int argc, int arglen[], char *argv[]);
0637 
0638 public:
0639    Html_u16_t     fFormId;    // Unique number assigned to this form
0640    unsigned int   fElements;  // Number of elements
0641    unsigned int   fHasctl;    // Has controls
0642    TGHtmlElement *fPFirst;    // First form element
0643    TGHtmlElement *fPEnd;      // Pointer to end tag element
0644 };
0645 
0646 
0647 // Information used by a <HR> markup
0648 
0649 class TGHtmlHr : public TGHtmlMarkupElement {
0650 public:
0651    TGHtmlHr(int type, int argc, int arglen[], char *argv[]);
0652 
0653 public:
0654    Html_32_t   fY;      // Baseline for this input element
0655    Html_u16_t  fX;      // Left edge
0656    Html_u16_t  fW, fH;  // Width and height of this control
0657    Html_u8_t   fIs3D;   // Is it drawn 3D?
0658 };
0659 
0660 
0661 // Information used by a <A> markup
0662 
0663 class TGHtmlAnchor : public TGHtmlMarkupElement {
0664 public:
0665    TGHtmlAnchor(int type, int argc, int arglen[], char *argv[]);
0666 
0667 public:
0668    Html_32_t  fY;   // Top edge for this element
0669 };
0670 
0671 
0672 // Information about the <SCRIPT> markup. The parser treats <SCRIPT>
0673 // specially. All text between <SCRIPT> and </SCRIPT> is captured and
0674 // is indexed to by the nStart field of this class.
0675 //
0676 // The nStart field indexs to a spot in the zText field of the TGHtml object.
0677 // The nScript field determines how long the script is.
0678 
0679 class TGHtmlScript : public TGHtmlMarkupElement {
0680 public:
0681    TGHtmlScript(int type, int argc, int arglen[], char *argv[]);
0682 
0683 public:
0684    int   fNStart;    // Start of the script (index into TGHtml::zText)
0685    int   fNScript;   // Number of characters of text in zText holding
0686                      // the complete text of this script
0687 };
0688 
0689 
0690 // A block is a single unit of display information. This can be one or more
0691 // text elements, or the border of table, or an image, etc.
0692 //
0693 // Blocks are used to improve display speed and to improve the speed of
0694 // linear searchs through the token list. A single block will typically
0695 // contain enough information to display a dozen or more Text and Space
0696 // elements all with a single call to OXFont::DrawChars(). The blocks are
0697 // linked together on their own list, so we can search them much faster than
0698 // elements (since there are fewer of them.)
0699 //
0700 // Of course, you can construct pathological HTML that has as many Blocks as
0701 // it has normal tokens. But you haven't lost anything. Using blocks just
0702 // speeds things up in the common case.
0703 //
0704 // Much of the information needed for display is held in the original
0705 // TGHtmlElement objects. "fPNext" points to the first object in the list
0706 // which can be used to find the "style" "x" and "y".
0707 //
0708 // If n is zero, then "fPNext" might point to a special TGHtmlElement
0709 // that defines some other kind of drawing, like <LI> or <IMG> or <INPUT>.
0710 
0711 class TGHtmlBlock : public TGHtmlElement {
0712 public:
0713    TGHtmlBlock();
0714    ~TGHtmlBlock() override;
0715 
0716 public:
0717    char        *fZ;                 // Space to hold text when n > 0
0718    int          fTop, fBottom;      // Extremes of y coordinates
0719    Html_u16_t   fLeft, fRight;      // Left and right boundry of this object
0720    Html_u16_t   fN;                 // Number of characters in z[]
0721    TGHtmlBlock *fBPrev, *fBNext;    // Linked list of all Blocks
0722 };
0723 
0724 
0725 // A stack of these structures is used to keep track of nested font and
0726 // style changes. This allows us to easily revert to the previous style
0727 // when we encounter and end-tag like </em> or </h3>.
0728 //
0729 // This stack is used to keep track of the current style while walking
0730 // the list of elements. After all elements have been assigned a style,
0731 // the information in this stack is no longer used.
0732 
0733 struct SHtmlStyleStack_t {
0734    SHtmlStyleStack_t *fPNext;   // Next style on the stack
0735    int                fType;    // A markup that ends this style. Ex: Html_EndEM
0736    SHtmlStyle_t       fStyle;   // The currently active style.
0737 };
0738 
0739 
0740 // A stack of the following structures is used to remember the
0741 // left and right margins within a layout context.
0742 
0743 struct SHtmlMargin_t {
0744    int            fIndent;    // Size of the current margin
0745    int            fBottom;    // Y value at which this margin expires
0746    int            fTag;       // Markup that will cancel this margin
0747    SHtmlMargin_t *fPNext;     // Previous margin
0748 };
0749 
0750 
0751 // How much space (in pixels) used for a single level of indentation due
0752 // to a <UL> or <DL> or <BLOCKQUOTE>, etc.
0753 
0754 #define HTML_INDENT 36
0755 
0756 
0757 //----------------------------------------------------------------------
0758 
0759 // A layout context holds all state information used by the layout engine.
0760 
0761 class TGHtmlLayoutContext : public TObject {
0762 public:
0763    TGHtmlLayoutContext();
0764 
0765    void LayoutBlock();
0766    void Reset();
0767 
0768    void PopIndent();
0769    void PushIndent();
0770 
0771 protected:
0772    void PushMargin(SHtmlMargin_t **ppMargin, int indent, int bottom, int tag);
0773    void PopOneMargin(SHtmlMargin_t **ppMargin);
0774    void PopMargin(SHtmlMargin_t **ppMargin, int tag);
0775    void PopExpiredMargins(SHtmlMargin_t **ppMarginStack, int y);
0776    void ClearMarginStack(SHtmlMargin_t **ppMargin);
0777 
0778    TGHtmlElement *GetLine(TGHtmlElement *pStart, TGHtmlElement *pEnd,
0779                           int width, int minX, int *actualWidth);
0780 
0781    void FixAnchors(TGHtmlElement *p, TGHtmlElement *pEnd, int y);
0782    int  FixLine(TGHtmlElement *pStart, TGHtmlElement *pEnd,
0783                 int bottom, int width, int actualWidth, int leftMargin,
0784                 int *maxX);
0785    void Paragraph(TGHtmlElement *p);
0786    void ComputeMargins(int *pX, int *pY, int *pW);
0787    void ClearObstacle(int mode);
0788    TGHtmlElement *DoBreakMarkup(TGHtmlElement *p);
0789    int  InWrapAround();
0790    void WidenLine(int reqWidth, int *pX, int *pY, int *pW);
0791 
0792    TGHtmlElement *TableLayout(TGHtmlTable *p);
0793 
0794 public:
0795    TGHtml           *fHtml;            // The html widget undergoing layout
0796    TGHtmlElement    *fPStart;          // Start of elements to layout
0797    TGHtmlElement    *fPEnd;            // Stop when reaching this element
0798    int               fHeadRoom;        // Extra space wanted above this line
0799    int               fTop;             // Absolute top of drawing area
0800    int               fBottom;          // Bottom of previous line
0801    int               fLeft, fRight;    // Left and right extremes of drawing area
0802    int               fPageWidth;       // Width of the layout field, including
0803                                        // the margins
0804    int               fMaxX, fMaxY;     // Maximum X and Y values of paint
0805    SHtmlMargin_t    *fLeftMargin;      // Stack of left margins
0806    SHtmlMargin_t    *fRightMargin;     // Stack of right margins
0807 };
0808 
0809 
0810 // With 28 different fonts and 16 colors, we could in principle have
0811 // as many as 448 different GCs. But in practice, a single page of
0812 // HTML will typically have much less than this. So we won't try to
0813 // keep all GCs on hand. Instead, we'll keep around the most recently
0814 // used GCs and allocate new ones as necessary.
0815 //
0816 // The following structure is used to build a cache of GCs in the
0817 // main widget object.
0818 
0819 #define N_CACHE_GC 32
0820 
0821 struct GcCache_t {
0822    GContext_t  fGc;        // The graphics context
0823    Html_u8_t   fFont;      // Font used for this context
0824    Html_u8_t   fColor;     // Color used for this context
0825    Html_u8_t   fIndex;     // Index used for LRU replacement
0826 };
0827 
0828 
0829 // An SHtmlIndex_t is a reference to a particular character within a
0830 // particular Text or Space token.
0831 
0832 struct SHtmlIndex_t {
0833    TGHtmlElement *fP;     // The token containing the character
0834    int            fI;     // Index of the character
0835 };
0836 
0837 
0838 // Used by the tokenizer
0839 
0840 struct SHtmlTokenMap_t {
0841    const char       *fZName;        // Name of a markup
0842    Html_16_t         fType;         // Markup type code
0843    Html_16_t         fObjType;      // Which kind of TGHtml... object to alocate
0844    SHtmlTokenMap_t  *fPCollide;     // Hash table collision chain
0845 };
0846 
0847 
0848 // Markup element types to be allocated by the tokenizer.
0849 // Do not confuse with .type field in TGHtmlElement
0850 
0851 #define O_HtmlMarkupElement   0
0852 #define O_HtmlCell            1
0853 #define O_HtmlTable           2
0854 #define O_HtmlRef             3
0855 #define O_HtmlLi              4
0856 #define O_HtmlListStart       5
0857 #define O_HtmlImageMarkup     6
0858 #define O_HtmlInput           7
0859 #define O_HtmlForm            8
0860 #define O_HtmlHr              9
0861 #define O_HtmlAnchor          10
0862 #define O_HtmlScript          11
0863 #define O_HtmlMapArea         12
0864 
0865 
0866 //----------------------------------------------------------------------
0867 
0868 // The HTML widget. A derivate of TGView.
0869 
0870 class TGListBox;
0871 class THashTable;
0872 
0873 class TGHtml : public TGView {
0874 public:
0875    TGHtml(const TGWindow *p, int w, int h, int id = -1);
0876    ~TGHtml() override;
0877 
0878    Bool_t HandleFocusChange(Event_t *event) override;
0879    Bool_t HandleButton(Event_t *event) override;
0880    Bool_t HandleMotion(Event_t *event) override;
0881 
0882    Bool_t HandleIdleEvent(TGIdleHandler *i) override;
0883    Bool_t HandleTimer(TTimer *timer) override;
0884 
0885    Bool_t ProcessMessage(Longptr_t, Longptr_t, Longptr_t) override;
0886 
0887    void   DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h) override;
0888    Bool_t ItemLayout() override;
0889 
0890    Bool_t         HandleHtmlInput(TGHtmlInput *pr, Event_t *event);
0891    Bool_t         HandleRadioButton(TGHtmlInput *p);
0892 
0893 public:   // user commands
0894 
0895    int  ParseText(char *text, const char *index = nullptr);
0896 
0897    void SetTableRelief(int relief);
0898    int  GetTableRelief() const { return fTableRelief; }
0899 
0900    void SetRuleRelief(int relief);
0901    int  GetRuleRelief() const { return fRuleRelief; }
0902    int  GetRulePadding() const { return fRulePadding; }
0903 
0904    void UnderlineLinks(int onoff);
0905 
0906    void SetBaseUri(const char *uri);
0907    const char *GetBaseUri() const { return fZBase; }
0908 
0909    int GotoAnchor(const char *name);
0910 
0911 public:   // reloadable methods
0912 
0913    // called when the widget is cleared
0914    void Clear(Option_t * = "") override;
0915 
0916    // User function to resolve URIs
0917    virtual char *ResolveUri(const char *uri);
0918 
0919    // User function to get an image from a URL
0920    virtual TImage *LoadImage(const char *uri, int w = 0, int h = 0) ;//
0921    //    { return 0; }
0922 
0923    // User function to tell if a hyperlink has already been visited
0924    virtual int IsVisited(const char * /*url*/)
0925       { return kFALSE; }
0926 
0927    // User function to process tokens of the given type
0928    virtual int ProcessToken(TGHtmlElement * /*pElem*/, const char * /*name*/, int /*type*/)
0929       { return kFALSE; }
0930 
0931    virtual TGFont *GetFont(int iFont);
0932 
0933    // The HTML parser will invoke the following methods from time
0934    // to time to find out information it needs to complete formatting of
0935    // the document.
0936 
0937    // Method for handling <frameset> markup
0938    virtual int ProcessFrame()
0939       { return kFALSE; }
0940 
0941    // Method to process applets
0942    virtual TGFrame *ProcessApplet(TGHtmlInput * /*input*/)
0943       { return nullptr; }
0944 
0945    // Called when parsing forms
0946    virtual int FormCreate(TGHtmlForm * /*form*/, const char * /*zUrl*/, const char * /*args*/)
0947       { return kFALSE; }
0948 
0949    // Called when user presses Submit
0950    virtual int FormAction(TGHtmlForm * /*form*/, int /*id*/)
0951       { return kFALSE; }
0952 
0953    // Invoked to find font names
0954    virtual char *GetFontName()
0955       { return nullptr; }
0956 
0957    // Invoked for each <SCRIPT> markup
0958    virtual char *ProcessScript(TGHtmlScript * /*script*/)
0959       { return nullptr; }
0960 
0961 public:
0962    const char *GetText() const { return fZText; }
0963 
0964    void HandleMenu(Int_t);
0965    void SaveFileAs();
0966 
0967    int GetMarginWidth() { return fMargins.fL + fMargins.fR; }
0968    int GetMarginHeight() { return fMargins.fT + fMargins.fB; }
0969 
0970    TGHtmlInput *GetInputElement(int x, int y);
0971    const char *GetHref(int x, int y, const char **target = nullptr);
0972 
0973    TGHtmlImage *GetImage(TGHtmlImageMarkup *p);
0974 
0975    int  InArea(TGHtmlMapArea *p, int left, int top, int x, int y);
0976    TGHtmlElement *GetMap(const char *name);
0977 
0978    void ResetBlocks() { fFirstBlock = fLastBlock = nullptr; }
0979    int  ElementCoords(TGHtmlElement *p, int i, int pct, int *coords);
0980 
0981    TGHtmlElement *TableDimensions(TGHtmlTable *pStart, int lineWidth);
0982    int  CellSpacing(TGHtmlElement *pTable);
0983    void MoveVertically(TGHtmlElement *p, TGHtmlElement *pLast, int dy);
0984 
0985    void PrintList(TGHtmlElement *first, TGHtmlElement *last);
0986 
0987    char *GetTokenName(TGHtmlElement *p);
0988    char *DumpToken(TGHtmlElement *p);
0989 
0990    void EncodeText(TGString *str, const char *z);
0991 
0992 protected:
0993    void HClear();
0994    void ClearGcCache();
0995    void ResetLayoutContext();
0996    void Redraw();
0997    void ComputeVirtualSize();
0998 
0999    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 
1019    void AnimateImage(TGHtmlImage *image);
1020    void ImageChanged(TGHtmlImage *image, int newWidth, int newHeight);
1021    int  GetImageAlignment(TGHtmlElement *p);
1022    int  GetImageAt(int x, int y);
1023    const char *GetPctWidth(TGHtmlElement *p, char *opt, char *ret);
1024    void TableBgndImage(TGHtmlElement *p);
1025 
1026    TGHtmlElement *FillOutBlock(TGHtmlBlock *p);
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 
1034    void DrawSelectionBackground(TGHtmlBlock *pBlock, Drawable_t Drawable_t,
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);
1041    void DrawImage(TGHtmlImageMarkup *image, Drawable_t wid,
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 
1046    TGHtmlElement *FindStartOfNextBlock(TGHtmlElement *p, int *pCnt);
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);
1055    TGHtmlElement *InsertToken(TGHtmlElement *pToken,
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);
1061    SHtmlTokenMap_t* GetMarkupMap(int n);
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);
1085    void AddSelectOptions(TGListBox *lb, TGHtmlElement *p, TGHtmlElement *pEnd);
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);
1097    ColorStruct_t *AllocColorByValue(ColorStruct_t *color);
1098    void FreeColor(ColorStruct_t *color);
1099 
1100    SHtmlStyle_t GetCurrentStyle();
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);
1115    TGHtmlElement *FindEndNest(TGHtmlElement *sp, int en, TGHtmlElement *lp);
1116    TGString *ListTokens(TGHtmlElement *p, TGHtmlElement *pEnd);
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    void SavePrimitive(std::ostream &out, Option_t * = "") override;
1127 
1128 protected:
1129    void UpdateBackgroundStart() override;
1130 
1131 protected:
1132    enum {
1133       kM_FILE_SAVEAS, kM_FILE_PRINT
1134    };
1135 
1136    TGHtmlElement *fPFirst;          // First HTML token on a list of them all
1137    TGHtmlElement *fPLast;           // Last HTML token on the list
1138    int            fNToken;          // Number of HTML tokens on the list.
1139                                     // Html_Block tokens don't count.
1140    TGHtmlElement *fLastSized;       // Last HTML element that has been sized
1141    TGHtmlElement *fNextPlaced;      // Next HTML element that needs to be
1142                                     // positioned on canvas.
1143    TGHtmlBlock   *fFirstBlock;      // List of all TGHtmlBlock tokens
1144    TGHtmlBlock   *fLastBlock;       // Last TGHtmlBlock in the list
1145    TGHtmlInput   *fFirstInput;      // First <INPUT> element
1146    TGHtmlInput   *fLastInput;       // Last <INPUT> element
1147    int            fNInput;          // The number of <INPUT> elements
1148    int            fNForm;           // The number of <FORM> elements
1149    int            fVarId;           // Used to construct a unique name for a
1150                                     // global array used by <INPUT> elements
1151    int            fInputIdx;        // Unique input index
1152    int            fRadioIdx;        // Unique radio index
1153 
1154    // Information about the selected region of text
1155 
1156    SHtmlIndex_t   fSelBegin;        // Start of the selection
1157    SHtmlIndex_t   fSelEnd;          // End of the selection
1158    TGHtmlBlock   *fPSelStartBlock;  // Block in which selection starts
1159    Html_16_t      fSelStartIndex;   // Index in pSelStartBlock of first selected
1160                                     // character
1161    Html_16_t      fSelEndIndex;     // Index of last selecte char in pSelEndBlock
1162    TGHtmlBlock   *fPSelEndBlock;    // Block in which selection ends
1163 
1164    // Information about the insertion cursor
1165 
1166    int            fInsOnTime;       // How long the cursor states one (millisec)
1167    int            fInsOffTime;      // How long it is off (milliseconds)
1168    int            fInsStatus;       // Is it visible?
1169    TTimer        *fInsTimer;        // Timer used to flash the insertion cursor
1170    SHtmlIndex_t   fIns;             // The insertion cursor position
1171    TGHtmlBlock   *fPInsBlock;       // The TGHtmlBlock containing the cursor
1172    int            fInsIndex;        // Index in pInsBlock of the cursor
1173 
1174    // The following fields hold state information used by the tokenizer.
1175 
1176    char          *fZText;           // Complete text of the unparsed HTML
1177    int            fNText;           // Number of characters in zText
1178    int            fNAlloc;          // Space allocated for zText
1179    int            fNComplete;       // How much of zText has actually been
1180                                     // converted into tokens
1181    int            fICol;            // The column in which zText[nComplete]
1182                                     // occurs. Used to resolve tabs in input
1183    int            fIPlaintext;      // If not zero, this is the token type that
1184                                     // caused us to go into plaintext mode. One
1185                                     // of Html_PLAINTEXT, Html_LISTING or
1186                                     // Html_XMP
1187    TGHtmlScript  *fPScript;         // <SCRIPT> currently being parsed
1188 
1189    TGIdleHandler *fIdle;
1190    TGPopupMenu   *fMenu;            // popup menu with user actions
1191 
1192    // These fields hold state information used by the HtmlAddStyle routine.
1193    // We have to store this state information here since HtmlAddStyle
1194    // operates incrementally. This information must be carried from
1195    // one incremental execution to the next.
1196 
1197    SHtmlStyleStack_t *fStyleStack;     // The style stack
1198    int               fParaAlignment;   // Justification associated with <p>
1199    int               fRowAlignment;    // Justification associated with <tr>
1200    int               fAnchorFlags;     // Style flags associated with <A>...</A>
1201    int               fInDt;            // Style flags associated with <DT>...</DT>
1202    int               fInTr;            // True if within <tr>..</tr>
1203    int               fInTd;            // True if within <td>..</td> or <th>..</th>
1204    TGHtmlAnchor     *fAnchorStart;     // Most recent <a href=...>
1205    TGHtmlForm       *fFormStart;       // Most recent <form>
1206    TGHtmlInput      *fFormElemStart;   // Most recent <textarea> or <select>
1207    TGHtmlInput      *fFormElemLast;    // Most recent <input>, <textarea> or <select>
1208    TGHtmlListStart  *fInnerList;       // The inner most <OL> or <UL>
1209    TGHtmlElement    *fLoEndPtr;        // How far AddStyle has gone to
1210    TGHtmlForm       *fLoFormStart;     // For AddStyle
1211 
1212    // These fields are used to hold the state of the layout engine.
1213    // Because the layout is incremental, this state must be held for
1214    // the life of the widget.
1215 
1216    TGHtmlLayoutContext fLayoutContext;
1217 
1218    // Information used when displaying the widget:
1219 
1220    int               fHighlightWidth;        // Width in pixels of highlight to draw
1221                                              // around widget when it has the focus.
1222                                              // <= 0 means don't draw a highlight.
1223    TGInsets          fMargins;               // document margins (separation between the
1224                                              // edge of the clip window and rendered HTML).
1225    ColorStruct_t    *fHighlightBgColorPtr;   // Color for drawing traversal highlight
1226                                              // area when highlight is off.
1227    ColorStruct_t    *fHighlightColorPtr;     // Color for drawing traversal highlight.
1228    TGFont           *fAFont[N_FONT];         // Information about all screen fonts
1229    char              fFontValid[(N_FONT+7)/8]; // If bit N%8 of work N/8 of this field is 0
1230                                              // if aFont[N] needs to be reallocated before
1231                                              // being used.
1232    ColorStruct_t    *fApColor[N_COLOR];      // Information about all colors
1233    Long_t            fColorUsed;             // bit N is 1 if color N is in use. Only
1234                                              // applies to colors that aren't predefined
1235    int               fIDark[N_COLOR];        // Dark 3D shadow of color K is iDark[K]
1236    int               fILight[N_COLOR];       // Light 3D shadow of color K is iLight[K]
1237    ColorStruct_t    *fBgColor;               // Background color of the HTML document
1238    ColorStruct_t    *fFgColor;               // Color of normal text. apColor[0]
1239    ColorStruct_t    *fNewLinkColor;          // Color of unvisitied links. apColor[1]
1240    ColorStruct_t    *fOldLinkColor;          // Color of visitied links. apColor[2]
1241    ColorStruct_t    *fSelectionColor;        // Background color for selections
1242    GcCache_t         fAGcCache[N_CACHE_GC];  // A cache of GCs for general use
1243    int               fGcNextToFree;
1244    int               fLastGC;                // Index of recently used GC
1245    TGHtmlImage      *fImageList;             // A list of all images
1246    TImage           *fBgImage;               // Background image
1247 
1248    int               fFormPadding;           // Amount to pad form elements by
1249    int               fOverrideFonts;         // TRUE if we should override fonts
1250    int               fOverrideColors;        // TRUE if we should override colors
1251    int               fUnderlineLinks;        // TRUE if we should underline hyperlinks
1252    int               fHasScript;             // TRUE if we can do scripts for this page
1253    int               fHasFrames;             // TRUE if we can do frames for this page
1254    int               fAddEndTags;            // TRUE if we add /LI etc.
1255    int               fTableBorderMin;        // Force tables to have min border size
1256    int               fVarind;                // Index suffix for unique global var name
1257 
1258    // Information about the selection
1259 
1260    int               fExportSelection;       // True if the selection is automatically
1261                                              // exported to the clipboard
1262 
1263    // Miscellaneous information:
1264 
1265    int               fTableRelief;           // 3d effects on <TABLE>
1266    int               fRuleRelief;            // 3d effects on <HR>
1267    int               fRulePadding;           // extra pixels above and below <HR>
1268    const char       *fZBase;                 // The base URI
1269    char             *fZBaseHref;             // zBase as modified by <BASE HREF=..> markup
1270    Cursor_t          fCursor;                // Current cursor for window, or None.
1271    int               fMaxX, fMaxY;           // Maximum extent of any "paint" that appears
1272                                              // on the virtual canvas. Used to compute
1273                                              // scrollbar positions.
1274    int               fDirtyLeft, fDirtyTop;  // Top left corner of region to redraw. These
1275                                              // are physical screen coordinates relative to
1276                                              // the clip win, not main window.
1277    int               fDirtyRight, fDirtyBottom;  // Bottom right corner of region to redraw
1278    int               fFlags;                 // Various flags; see below for definitions.
1279    int               fIdind;
1280    int               fInParse;               // Prevent update if parsing
1281    char             *fZGoto;                 // Label to goto right after layout
1282 
1283    SHtmlExtensions_t *fExts;                 // Pointer to user extension data
1284 
1285    THashTable       *fUidTable;              // Hash table for some used string values
1286                                              // like color names, etc.
1287    const char       *fLastUri;               // Used in HandleMotion
1288    int               fExiting;               // True if the widget is being destroyed
1289 
1290    ClassDefOverride(TGHtml, 0); // HTML widget
1291 };
1292 
1293 
1294 // Flag bits "flags" field of the Html widget:
1295 //
1296 // REDRAW_PENDING         An idle handler has already been queued to
1297 //                        call the TGHtml::Redraw() method.
1298 //
1299 // GOT_FOCUS              This widget currently has input focus.
1300 //
1301 // HSCROLL                Horizontal scrollbar position needs to be
1302 //                        recomputed.
1303 //
1304 // VSCROLL                Vertical scrollbar position needs to be
1305 //                        recomputed.
1306 //
1307 // RELAYOUT               We need to reposition every element on the
1308 //                        virtual canvas. (This happens, for example,
1309 //                        when the size of the widget changes and we
1310 //                        need to recompute the line breaks.)
1311 //
1312 // RESIZE_ELEMENTS        We need to recompute the size of every element.
1313 //                        This happens, for example, when the fonts
1314 //                        change.
1315 //
1316 // REDRAW_FOCUS           We need to repaint the focus highlight border.
1317 //
1318 // REDRAW_TEXT            Everything in the clipping window needs to be redrawn.
1319 //
1320 // STYLER_RUNNING         There is a call to HtmlAddStyle() in process.
1321 //                        Used to prevent a recursive call to HtmlAddStyle().
1322 //
1323 // INSERT_FLASHING        True if there is a timer scheduled that will toggle
1324 //                        the state of the insertion cursor.
1325 //
1326 // REDRAW_IMAGES          One or more TGHtmlImageMarkup objects have their
1327 //                        redrawNeeded flag set.
1328 
1329 #define REDRAW_PENDING       0x000001
1330 #define GOT_FOCUS            0x000002
1331 #define HSCROLL              0x000004
1332 #define VSCROLL              0x000008
1333 #define RELAYOUT             0x000010
1334 #define RESIZE_ELEMENTS      0x000020
1335 #define REDRAW_FOCUS         0x000040
1336 #define REDRAW_TEXT          0x000080
1337 #define EXTEND_LAYOUT        0x000100
1338 #define STYLER_RUNNING       0x000200
1339 #define INSERT_FLASHING      0x000400
1340 #define REDRAW_IMAGES        0x000800
1341 #define ANIMATE_IMAGES       0x001000
1342 
1343 
1344 // Macros to set, clear or test bits of the "flags" field.
1345 
1346 #define HtmlHasFlag(A,F)      (((A)->flags&(F))==(F))
1347 #define HtmlHasAnyFlag(A,F)   (((A)->flags&(F))!=0)
1348 #define HtmlSetFlag(A,F)      ((A)->flags|=(F))
1349 #define HtmlClearFlag(A,F)    ((A)->flags&=~(F))
1350 
1351 
1352 // No coordinate is ever as big as this number
1353 
1354 #define LARGE_NUMBER 100000000
1355 
1356 
1357 // Default values for configuration options
1358 
1359 #define DEF_HTML_BG_COLOR             DEF_FRAME_BG_COLOR
1360 #define DEF_HTML_BG_MONO              DEF_FRAME_BG_MONO
1361 #define DEF_HTML_EXPORT_SEL           1
1362 #define DEF_HTML_FG                   DEF_BUTTON_FG
1363 #define DEF_HTML_HIGHLIGHT_BG         DEF_BUTTON_HIGHLIGHT_BG
1364 #define DEF_HTML_HIGHLIGHT            DEF_BUTTON_HIGHLIGHT
1365 #define DEF_HTML_HIGHLIGHT_WIDTH      "0"
1366 #define DEF_HTML_INSERT_OFF_TIME      300
1367 #define DEF_HTML_INSERT_ON_TIME       600
1368 #define DEF_HTML_PADX                 (HTML_INDENT / 4)
1369 #define DEF_HTML_PADY                 (HTML_INDENT / 4)
1370 #define DEF_HTML_RELIEF               "raised"
1371 #define DEF_HTML_SELECTION_COLOR      "skyblue"
1372 #define DEF_HTML_TAKE_FOCUS           "0"
1373 #define DEF_HTML_UNVISITED            "blue2"
1374 #define DEF_HTML_VISITED              "purple4"
1375 
1376 #ifdef NAVIGATOR_TABLES
1377 
1378 #define DEF_HTML_TABLE_BORDER             "0"
1379 #define DEF_HTML_TABLE_CELLPADDING        "2"
1380 #define DEF_HTML_TABLE_CELLSPACING        "5"
1381 #define DEF_HTML_TABLE_BORDER_LIGHT_COLOR "gray80"
1382 #define DEF_HTML_TABLE_BORDER_DARK_COLOR  "gray40"
1383 
1384 #endif  // NAVIGATOR_TABLES
1385 
1386 
1387 //----------------------------------------------------------------------
1388 
1389 // Messages generated by the HTML widget
1390 /*
1391 class TGHtmlMessage : public OWidgetMessage {
1392 public:
1393   TGHtmlMessage(int t, int a, int i, const char *u, int rx, int ry) :
1394     OWidgetMessage(t, a, i) {
1395       uri = u;
1396       x_root = rx;
1397       y_root = ry;
1398     }
1399 
1400 public:
1401   const char *uri;
1402   //ORectangle bbox;
1403   int x_root, y_root;
1404 };
1405 */
1406 
1407 #endif  // ROOT_TGHtml