TGHtmlElement.cxx

Go to the documentation of this file.
00001 // $Id$
00002 // Author:  Valeriy Onuchin   03/05/2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2001, Rene Brun, Fons Rademakers and Reiner Rohlfs *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 /**************************************************************************
00013 
00014     HTML widget for xclass. Based on tkhtml 1.28
00015     Copyright (C) 1997-2000 D. Richard Hipp <drh@acm.org>
00016     Copyright (C) 2002-2003 Hector Peraza.
00017 
00018     This library is free software; you can redistribute it and/or
00019     modify it under the terms of the GNU Library General Public
00020     License as published by the Free Software Foundation; either
00021     version 2 of the License, or (at your option) any later version.
00022 
00023     This library is distributed in the hope that it will be useful,
00024     but WITHOUT ANY WARRANTY; without even the implied warranty of
00025     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00026     Library General Public License for more details.
00027 
00028     You should have received a copy of the GNU Library General Public
00029     License along with this library; if not, write to the Free
00030     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00031 
00032 **************************************************************************/
00033 
00034 #include <string.h>
00035 
00036 #include "TGHtml.h"
00037 #include "TImage.h"
00038 
00039 // TODO: make these TGHtml static members
00040 
00041 extern void HtmlTranslateEscapes(char *z);
00042 extern void ToLower(char *z);
00043 
00044 
00045 //______________________________________________________________________________
00046 TGHtmlElement::TGHtmlElement(int etype)
00047 {
00048    // HTML element constructor.
00049 
00050    fPNext = fPPrev = 0;
00051    fStyle.fFont = 0;
00052    fStyle.fColor = 0;
00053    fStyle.fSubscript = 0;
00054    fStyle.fAlign = 0;
00055    fStyle.fBgcolor = 0;
00056    fStyle.fExpbg = 0;
00057    fStyle.fFlags = 0;
00058    fType = etype;
00059    fFlags = 0;
00060    fCount = 0;
00061    fElId = 0;
00062    fOffs = 0;
00063 }
00064 
00065 //______________________________________________________________________________
00066 TGHtmlTextElement::TGHtmlTextElement(int size) : TGHtmlElement(Html_Text)
00067 {
00068    // HTML element constructor.
00069 
00070    fZText = new char[size + 1];
00071    fX = 0; fY = 0; fW = 0;
00072    fAscent = 0;
00073    fDescent = 0;
00074    fSpaceWidth = 0;
00075 }
00076 
00077 //______________________________________________________________________________
00078 TGHtmlTextElement::~TGHtmlTextElement()
00079 {
00080    // HTML element destructor.
00081 
00082    delete[] fZText;
00083 }
00084 
00085 //______________________________________________________________________________
00086 TGHtmlMarkupElement::TGHtmlMarkupElement(int type2, int argc, int arglen[], 
00087                                          char *av[]) : TGHtmlElement(type2)
00088 {
00089    // HTML mrkup element constructor.
00090 
00091    fCount = argc - 1;
00092 
00093    if (argc > 1) {
00094       fArgv = new char*[argc+1];
00095       for (int i = 1; i < argc; i++) {
00096          if (arglen) {
00097             fArgv[i-1] = new char[arglen[i]+1];
00098             //sprintf(fArgv[i-1], "%.*s", arglen[i], av[i]);
00099             strncpy(fArgv[i-1], av[i], arglen[i]);
00100             fArgv[i-1][arglen[i]] = 0;
00101             HtmlTranslateEscapes(fArgv[i-1]);
00102             if ((i & 1) == 1) ToLower(fArgv[i-1]);
00103          } else {
00104             fArgv[i-1] = StrDup(av[i]);
00105             HtmlTranslateEscapes(fArgv[i-1]);
00106             if ((i & 1) == 1) ToLower(fArgv[i-1]);
00107          }
00108       }
00109       fArgv[argc-1] = 0;
00110 
00111       // Following is just a flag that this is unmodified
00112       fArgv[argc] = (char *) fArgv;
00113 
00114    } else {
00115       fArgv = 0;
00116    }
00117 }
00118 
00119 //______________________________________________________________________________
00120 TGHtmlMarkupElement::~TGHtmlMarkupElement()
00121 {
00122    // HTML markup element destructor.
00123 
00124    if (fArgv) {
00125       for (int i = 0; i < fCount; ++i) delete [] fArgv[i];
00126       delete [] fArgv;
00127    }
00128 }
00129 
00130 //______________________________________________________________________________
00131 const char *TGHtmlMarkupElement::MarkupArg(const char *tag, const char *zDefault)
00132 {
00133    // Lookup an argument in the given markup with the name given.
00134    // Return a pointer to its value, or the given default
00135    // value if it doesn't appear.
00136 
00137    int i;
00138 
00139    for (i = 0; i < fCount; i += 2) {
00140       if (strcmp(fArgv[i], tag) == 0) return fArgv[i+1];
00141    }
00142    return zDefault;
00143 }
00144 
00145 //______________________________________________________________________________
00146 int TGHtmlMarkupElement::GetAlignment(int dflt)
00147 {
00148    // Return an alignment or justification flag associated with the
00149    // given markup. The given default value is returned if no alignment is
00150    // specified.
00151 
00152    const char *z = MarkupArg("align", 0);
00153    int rc = dflt;
00154 
00155    if (z) {
00156       if (strcasecmp(z, "left") == 0) {
00157          rc = ALIGN_Left;
00158       } else if (strcasecmp(z, "right") == 0) {
00159          rc = ALIGN_Right;
00160       } else if (strcasecmp(z, "center") == 0) {
00161          rc = ALIGN_Center;
00162       }
00163    }
00164 
00165    return rc;
00166 }
00167 
00168 //______________________________________________________________________________
00169 int TGHtmlMarkupElement::GetOrderedListType(int dflt)
00170 {
00171    // The "type" argument to the given element might describe the type
00172    // for an ordered list. Return the corresponding LI_TYPE_* entry
00173    // if this is the case, or the default value if it isn't.
00174    // (this and the following should be defined only for TGHtmlLi)
00175 
00176    const char *z = MarkupArg("type", 0);
00177    if (z) {
00178       switch (*z) {
00179          case 'A': dflt = LI_TYPE_Enum_A; break;
00180          case 'a': dflt = LI_TYPE_Enum_a; break;
00181          case '1': dflt = LI_TYPE_Enum_1; break;
00182          case 'I': dflt = LI_TYPE_Enum_I; break;
00183          case 'i': dflt = LI_TYPE_Enum_i; break;
00184          default:  break;
00185       }
00186    }
00187 
00188    return dflt;
00189 }
00190 
00191 //______________________________________________________________________________
00192 int TGHtmlMarkupElement::GetUnorderedListType(int dflt)
00193 {
00194    // The "type" argument to the given element might describe a type
00195    // for an unordered list.  Return the corresponding LI_TYPE entry
00196    // if this is the case, or the default value if it isn't.
00197 
00198    const char *z = MarkupArg("type", 0);
00199    if (z) {
00200       if (strcasecmp(z, "disc") == 0) {
00201          dflt = LI_TYPE_Bullet1;
00202       } else if (strcasecmp(z, "circle") == 0) {
00203          dflt = LI_TYPE_Bullet2;
00204       } else if (strcasecmp(z, "square") == 0) {
00205          dflt = LI_TYPE_Bullet3;
00206       }
00207    }
00208 
00209    return dflt;
00210 }
00211 
00212 //int TGHtmlMarkupElement::GetVerticalAlignment(int dflt);
00213 
00214 //______________________________________________________________________________
00215 TGHtmlTable::TGHtmlTable(int type2, int argc, int arglen[], char *argv2[]) :
00216    TGHtmlMarkupElement(type2, argc, arglen, argv2)
00217 {
00218    // HTML table element constructor.
00219 
00220    fBorderWidth = 0;
00221    fNCol = 0;
00222    fNRow = 0;
00223    fX = 0; fY = 0; fW = 0; fH = 0;
00224    fPEnd = 0;
00225    fBgImage = 0;
00226    fHasbg = 0;
00227    for (int i=0;i<=HTML_MAX_COLUMNS;++i) {
00228       fMinW[i] = fMaxW[i] = 0;
00229    }
00230 }
00231 
00232 //______________________________________________________________________________
00233 TGHtmlTable::~TGHtmlTable()
00234 {
00235    // HTML table element destructor.
00236 
00237    if (fBgImage) delete fBgImage;
00238 }
00239 
00240 //______________________________________________________________________________
00241 TGHtmlCell::TGHtmlCell(int type2, int argc, int arglen[], char *argv2[]) :
00242    TGHtmlMarkupElement(type2, argc, arglen, argv2)
00243 {
00244    // HTML cell element constructor.
00245 
00246    fRowspan = 0;
00247    fColspan = 0;
00248    fX = 0; fY = 0; fW = 0; fH = 0;
00249    fPTable = 0;
00250    fPRow = 0;
00251    fPEnd = 0;
00252    fBgImage = 0;
00253 }
00254 
00255 //______________________________________________________________________________
00256 TGHtmlCell::~TGHtmlCell()
00257 {
00258    // HTML cell element destructor.
00259 
00260    if (fBgImage) delete fBgImage;
00261 }
00262 
00263 //______________________________________________________________________________
00264 TGHtmlRef::TGHtmlRef(int type2, int argc, int arglen[], char *argv2[]) :
00265    TGHtmlMarkupElement(type2, argc, arglen, argv2)
00266 {
00267    // HTML ref element constructor.
00268 
00269    fPOther = 0;
00270    fBgImage = 0;
00271 }
00272 
00273 //______________________________________________________________________________
00274 TGHtmlRef::~TGHtmlRef()
00275 {
00276    // HTML ref element destructor.
00277 
00278    if (fBgImage) delete fBgImage;
00279 }
00280 
00281 //______________________________________________________________________________
00282 TGHtmlLi::TGHtmlLi(int type2, int argc, int arglen[], char *argv2[]) :
00283    TGHtmlMarkupElement(type2, argc, arglen, argv2)
00284 {
00285    // HTML li element constructor.
00286 
00287    fLtype = 0;
00288    fAscent = 0;
00289    fDescent = 0;
00290    fCnt = 0;
00291    fX = 0; fY = 0;
00292 }
00293 
00294 //______________________________________________________________________________
00295 TGHtmlListStart::TGHtmlListStart(int type2, int argc, int arglen[], char *argv2[]) :
00296    TGHtmlMarkupElement(type2, argc, arglen, argv2)
00297 {
00298    // HTML list start element constructor.
00299 
00300    fLtype = 0;
00301    fCompact = 0;
00302    fCnt = 0;
00303    fWidth = 0;
00304    fLPrev = 0;
00305 }
00306 
00307 //______________________________________________________________________________
00308 TGHtmlImageMarkup::TGHtmlImageMarkup(int type2, int argc,
00309                                      int arglen[], char *argv2[]) :
00310    TGHtmlMarkupElement(type2, argc, arglen, argv2)
00311 {
00312    // HTML image element constructor.
00313 
00314    fAlign = 0;
00315    fTextAscent = 0;
00316    fTextDescent = 0;
00317    fRedrawNeeded = 0;
00318    fX = 0; fY = 0; fW = 0; fH = 0;
00319    fAscent = 0;
00320    fDescent = 0;
00321    fZAlt = 0;
00322    fPImage = 0;
00323    fPMap = 0;
00324    fINext = 0;
00325 }
00326 
00327 //______________________________________________________________________________
00328 TGHtmlForm::TGHtmlForm(int type2, int argc, int arglen[], char *argv2[]) :
00329    TGHtmlMarkupElement(type2, argc, arglen, argv2)
00330 {
00331    // HTML form element constructor.
00332 
00333    fFormId = 0;
00334    fElements = 0;
00335    fHasctl = 0;
00336    fPFirst = 0;
00337    fPEnd = 0;
00338 }
00339 
00340 //______________________________________________________________________________
00341 TGHtmlHr::TGHtmlHr(int type2, int argc, int arglen[], char *argv2[]) :
00342    TGHtmlMarkupElement(type2, argc, arglen, argv2)
00343 {
00344    // HTML hr element constructor.
00345 
00346    fX = 0; fY = 0; fW = 0; fH = 0;
00347    fIs3D = 0;
00348 }
00349 
00350 //______________________________________________________________________________
00351 TGHtmlAnchor::TGHtmlAnchor(int type2, int argc, int arglen[], char *argv2[]) :
00352    TGHtmlMarkupElement(type2, argc, arglen, argv2)
00353 {
00354    // HTML anchor element constructor.
00355 
00356    fY = 0;
00357 }
00358 
00359 //______________________________________________________________________________
00360 TGHtmlScript::TGHtmlScript(int type2, int argc, int arglen[], char *argv2[]) :
00361    TGHtmlMarkupElement(type2, argc, arglen, argv2)
00362 {
00363    // HTML script element constructor.
00364 
00365    fNStart = -1;
00366    fNScript = 0;
00367 }
00368 
00369 //______________________________________________________________________________
00370 TGHtmlMapArea::TGHtmlMapArea(int type2, int argc, int arglen[], char *argv2[]) :
00371    TGHtmlMarkupElement(type2, argc, arglen, argv2)
00372 {
00373    // HTML map area constructor.
00374 
00375    fMType = 0;
00376    fCoords = 0;
00377    fNum = 0;
00378 }
00379 
00380 
00381 //----------------------------------------------------------------------
00382 
00383 #if 0
00384 TGHtmlBlock::TGHtmlBlock()
00385 {
00386    // HTML block element constructor.
00387 }
00388 
00389 TGHtmlBlock::~TGHtmlBlock()
00390 {
00391    // HTML block element destructor.
00392 }
00393 #endif
00394 
00395 //______________________________________________________________________________
00396 TGHtmlInput::TGHtmlInput(int type2, int argc, int arglen[], char *argv2[]) :
00397    TGHtmlMarkupElement(type2, argc, arglen, argv2)
00398 {
00399    // HTML input element constructor.
00400 
00401    fPForm = 0;
00402    fINext = 0;
00403    fFrame = 0;
00404    fHtml = 0;
00405    fPEnd = 0;
00406    fInpId = 0; fSubId = 0;
00407    fX = 0; fY = 0; fW = 0; fH = 0;
00408    fPadLeft = 0;
00409    fAlign = 0;
00410    fTextAscent = 0;
00411    fTextDescent = 0;
00412    fItype = 0;
00413    fSized = 0;
00414    fCnt = 0;
00415 }
00416 
00417 //______________________________________________________________________________
00418 void TGHtmlInput::Empty()
00419 {
00420    // Mark this element as being empty. It has no widget and doesn't appear on
00421    // the screen.
00422    //
00423    // This is called for HIDDEN inputs or when the corresponding widget is
00424    // not created.
00425 
00426    fFrame = NULL;
00427    fW = 0;
00428    fH = 0;
00429    fFlags &= ~HTML_Visible;
00430    fStyle.fFlags |= STY_Invisible;
00431    fSized = 1;
00432 }
00433 

Generated on Tue Jul 5 14:22:18 2011 for ROOT_528-00b_version by  doxygen 1.5.1