1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        wx/html/htmltag.h 
   3 // Purpose:     wxHtmlTag class (represents single tag) 
   4 // Author:      Vaclav Slavik 
   6 // Copyright:   (c) 1999 Vaclav Slavik 
   7 // Licence:     wxWindows licence 
   8 ///////////////////////////////////////////////////////////////////////////// 
  10 #ifndef _WX_HTMLTAG_H_ 
  11 #define _WX_HTMLTAG_H_ 
  17 #include "wx/object.h" 
  18 #include "wx/arrstr.h" 
  20 class WXDLLIMPEXP_FWD_CORE wxColour
; 
  21 class WXDLLIMPEXP_FWD_HTML wxHtmlEntitiesParser
; 
  23 //----------------------------------------------------------------------------- 
  25 //          - internal wxHTML class, do not use! 
  26 //----------------------------------------------------------------------------- 
  28 class wxHtmlTagsCacheData
; 
  30 class WXDLLIMPEXP_HTML wxHtmlTagsCache
 
  33     wxHtmlTagsCacheData 
*m_Cache
; 
  36     wxHtmlTagsCacheData
& Cache() { return *m_Cache
; } 
  39     wxHtmlTagsCache() {m_Cache 
= NULL
;} 
  40     wxHtmlTagsCache(const wxString
& source
); 
  41     virtual ~wxHtmlTagsCache(); 
  43     // Finds parameters for tag starting at at and fills the variables 
  44     void QueryTag(const wxString::const_iterator
& at
, 
  45                   const wxString::const_iterator
& inputEnd
, 
  46                   wxString::const_iterator 
*end1
, 
  47                   wxString::const_iterator 
*end2
, 
  50     wxDECLARE_NO_COPY_CLASS(wxHtmlTagsCache
); 
  54 //-------------------------------------------------------------------------------- 
  56 //                  This represents single tag. It is used as internal structure 
  58 //-------------------------------------------------------------------------------- 
  60 class WXDLLIMPEXP_HTML wxHtmlTag
 
  63     // constructs wxHtmlTag object based on HTML tag. 
  64     // The tag begins (with '<' character) at position pos in source 
  65     // end_pos is position where parsing ends (usually end of document) 
  66     wxHtmlTag(wxHtmlTag 
*parent
, 
  67               const wxString 
*source
, 
  68               const wxString::const_iterator
& pos
, 
  69               const wxString::const_iterator
& end_pos
, 
  70               wxHtmlTagsCache 
*cache
, 
  71               wxHtmlEntitiesParser 
*entParser
); 
  72     friend class wxHtmlParser
; 
  76     wxHtmlTag 
*GetParent() const {return m_Parent
;} 
  77     wxHtmlTag 
*GetFirstSibling() const; 
  78     wxHtmlTag 
*GetLastSibling() const; 
  79     wxHtmlTag 
*GetChildren() const { return m_FirstChild
; } 
  80     wxHtmlTag 
*GetPreviousSibling() const { return m_Prev
; } 
  81     wxHtmlTag 
*GetNextSibling() const {return m_Next
; } 
  82     // Return next tag, as if tree had been flattened 
  83     wxHtmlTag 
*GetNextTag() const; 
  85     // Returns tag's name in uppercase. 
  86     inline wxString 
GetName() const {return m_Name
;} 
  88     // Returns true if the tag has given parameter. Parameter 
  89     // should always be in uppercase. 
  90     // Example : <IMG SRC="test.jpg"> HasParam("SRC") returns true 
  91     bool HasParam(const wxString
& par
) const; 
  93     // Returns value of the param. Value is in uppercase unless it is 
  95     // Example : <P align=right> GetParam("ALIGN") returns (RIGHT) 
  96     //           <P IMG SRC="WhaT.jpg"> GetParam("SRC") returns (WhaT.jpg) 
  97     //                           (or ("WhaT.jpg") if with_quotes == true) 
  98     wxString 
GetParam(const wxString
& par
, bool with_quotes 
= false) const; 
 100     // Return true if the string could be parsed as an HTML colour and false 
 102     static bool ParseAsColour(const wxString
& str
, wxColour 
*clr
); 
 104     // Convenience functions: 
 105     bool GetParamAsColour(const wxString
& par
, wxColour 
*clr
) const; 
 106     bool GetParamAsInt(const wxString
& par
, int *clr
) const; 
 108     // Scans param like scanf() functions family does. 
 109     // Example : ScanParam("COLOR", "\"#%X\"", &clr); 
 110     // This is always with with_quotes=false 
 111     // Returns number of scanned values 
 112     // (like sscanf() does) 
 113     // NOTE: unlike scanf family, this function only accepts 
 115     int ScanParam(const wxString
& par
, const char *format
, void *param
) const; 
 116     int ScanParam(const wxString
& par
, const wchar_t *format
, void *param
) const; 
 118     // Returns string containing all params. 
 119     wxString 
GetAllParams() const; 
 121     // return true if there is matching ending tag 
 122     inline bool HasEnding() const {return m_hasEnding
;} 
 124     // returns beginning position of _internal_ block of text as iterator 
 125     // into parser's source string (see wxHtmlParser::GetSource()) 
 126     // See explanation (returned value is marked with *): 
 127     // bla bla bla <MYTAG>* bla bla intenal text</MYTAG> bla bla 
 128     wxString::const_iterator 
GetBeginIter() const 
 130     // returns ending position of _internal_ block of text as iterator 
 131     // into parser's source string (see wxHtmlParser::GetSource()): 
 132     // bla bla bla <MYTAG> bla bla intenal text*</MYTAG> bla bla 
 133     wxString::const_iterator 
GetEndIter1() const { return m_End1
; } 
 134     // returns end position 2 as iterator 
 135     // into parser's source string (see wxHtmlParser::GetSource()): 
 136     // bla bla bla <MYTAG> bla bla internal text</MYTAG>* bla bla 
 137     wxString::const_iterator 
GetEndIter2() const { return m_End2
; } 
 139 #if WXWIN_COMPATIBILITY_2_8 
 140     // use GetBeginIter(), GetEndIter1() and GetEndIter2() instead 
 141     wxDEPRECATED( inline int GetBeginPos() const ); 
 142     wxDEPRECATED( inline int GetEndPos1() const ); 
 143     wxDEPRECATED( inline int GetEndPos2() const ); 
 144 #endif // WXWIN_COMPATIBILITY_2_8 
 149     wxString::const_iterator m_Begin
, m_End1
, m_End2
; 
 150     wxArrayString m_ParamNames
, m_ParamValues
; 
 151 #if WXWIN_COMPATIBILITY_2_8 
 152     wxString::const_iterator m_sourceStart
; 
 155     // DOM tree relations: 
 158     wxHtmlTag 
*m_FirstChild
, *m_LastChild
; 
 161     wxDECLARE_NO_COPY_CLASS(wxHtmlTag
); 
 165 #if WXWIN_COMPATIBILITY_2_8 
 166 inline int wxHtmlTag::GetBeginPos() const { return m_Begin 
- m_sourceStart
; } 
 167 inline int wxHtmlTag::GetEndPos1() const { return m_End1 
- m_sourceStart
; } 
 168 inline int wxHtmlTag::GetEndPos2() const { return m_End2 
- m_sourceStart
; } 
 169 #endif // WXWIN_COMPATIBILITY_2_8 
 176 #endif // _WX_HTMLTAG_H_