1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wx28HtmlTag class (represents single tag)
4 // Author: Vaclav Slavik
5 // Copyright: (c) 1999 Vaclav Slavik
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 #define _WX_HTMLTAG_H_
14 #include "wx/object.h"
15 #include "wx/arrstr.h"
18 class wx28HtmlEntitiesParser
;
20 //-----------------------------------------------------------------------------
22 // - internal wxHTML class, do not use!
23 //-----------------------------------------------------------------------------
25 struct wx28HtmlCacheItem
;
27 class wx28HtmlTagsCache
: public wxObject
29 DECLARE_DYNAMIC_CLASS(wx28HtmlTagsCache
)
32 wx28HtmlCacheItem
*m_Cache
;
37 wx28HtmlTagsCache() : wxObject() {m_CacheSize
= 0; m_Cache
= NULL
;}
38 wx28HtmlTagsCache(const wxString
& source
);
39 virtual ~wx28HtmlTagsCache() {free(m_Cache
);}
41 // Finds parameters for tag starting at at and fills the variables
42 void QueryTag(int at
, int* end1
, int* end2
);
44 DECLARE_NO_COPY_CLASS(wx28HtmlTagsCache
)
48 //--------------------------------------------------------------------------------
50 // This represents single tag. It is used as internal structure
52 //--------------------------------------------------------------------------------
54 class wx28HtmlTag
: public wxObject
56 DECLARE_CLASS(wx28HtmlTag
)
59 // constructs wx28HtmlTag object based on HTML tag.
60 // The tag begins (with '<' character) at position pos in source
61 // end_pos is position where parsing ends (usually end of document)
62 wx28HtmlTag(wx28HtmlTag
*parent
,
63 const wxString
& source
, int pos
, int end_pos
,
64 wx28HtmlTagsCache
*cache
,
65 wx28HtmlEntitiesParser
*entParser
);
66 friend class wx28HtmlParser
;
68 virtual ~wx28HtmlTag();
70 wx28HtmlTag
*GetParent() const {return m_Parent
;}
71 wx28HtmlTag
*GetFirstSibling() const;
72 wx28HtmlTag
*GetLastSibling() const;
73 wx28HtmlTag
*GetChildren() const { return m_FirstChild
; }
74 wx28HtmlTag
*GetPreviousSibling() const { return m_Prev
; }
75 wx28HtmlTag
*GetNextSibling() const {return m_Next
; }
76 // Return next tag, as if tree had been flattened
77 wx28HtmlTag
*GetNextTag() const;
79 // Returns tag's name in uppercase.
80 inline wxString
GetName() const {return m_Name
;}
82 // Returns true if the tag has given parameter. Parameter
83 // should always be in uppercase.
84 // Example : <IMG SRC="test.jpg"> HasParam("SRC") returns true
85 bool HasParam(const wxString
& par
) const;
87 // Returns value of the param. Value is in uppercase unless it is
89 // Example : <P align=right> GetParam("ALIGN") returns (RIGHT)
90 // <P IMG SRC="WhaT.jpg"> GetParam("SRC") returns (WhaT.jpg)
91 // (or ("WhaT.jpg") if with_commas == true)
92 wxString
GetParam(const wxString
& par
, bool with_commas
= false) const;
94 // Convenience functions:
95 bool GetParamAsColour(const wxString
& par
, wxColour
*clr
) const;
96 bool GetParamAsInt(const wxString
& par
, int *clr
) const;
98 // Scans param like scanf() functions family does.
99 // Example : ScanParam("COLOR", "\"#%X\"", &clr);
100 // This is always with with_commas=false
101 // Returns number of scanned values
102 // (like sscanf() does)
103 // NOTE: unlike scanf family, this function only accepts
105 int ScanParam(const wxString
& par
, const wxChar
*format
, void *param
) const;
107 // Returns string containing all params.
108 wxString
GetAllParams() const;
110 // return true if this there is matching ending tag
111 inline bool HasEnding() const {return m_End1
>= 0;}
113 // returns beginning position of _internal_ block of text
114 // See explanation (returned value is marked with *):
115 // bla bla bla <MYTAG>* bla bla intenal text</MYTAG> bla bla
116 inline int GetBeginPos() const {return m_Begin
;}
117 // returns ending position of _internal_ block of text.
118 // bla bla bla <MYTAG> bla bla intenal text*</MYTAG> bla bla
119 inline int GetEndPos1() const {return m_End1
;}
120 // returns end position 2 :
121 // bla bla bla <MYTAG> bla bla internal text</MYTAG>* bla bla
122 inline int GetEndPos2() const {return m_End2
;}
126 int m_Begin
, m_End1
, m_End2
;
127 wxArrayString m_ParamNames
, m_ParamValues
;
129 // DOM tree relations:
132 wx28HtmlTag
*m_FirstChild
, *m_LastChild
;
133 wx28HtmlTag
*m_Parent
;
135 DECLARE_NO_COPY_CLASS(wx28HtmlTag
)
140 #endif // _WX_HTMLTAG_H_