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"
17 class wx28HtmlEntitiesParser
;
19 //-----------------------------------------------------------------------------
21 // - internal wxHTML class, do not use!
22 //-----------------------------------------------------------------------------
24 struct wx28HtmlCacheItem
;
26 class wx28HtmlTagsCache
: public wxObject
28 DECLARE_DYNAMIC_CLASS(wx28HtmlTagsCache
)
31 wx28HtmlCacheItem
*m_Cache
;
36 wx28HtmlTagsCache() : wxObject() {m_CacheSize
= 0; m_Cache
= NULL
;}
37 wx28HtmlTagsCache(const wxString
& source
);
38 virtual ~wx28HtmlTagsCache() {free(m_Cache
);}
40 // Finds parameters for tag starting at at and fills the variables
41 void QueryTag(int at
, int* end1
, int* end2
);
43 DECLARE_NO_COPY_CLASS(wx28HtmlTagsCache
)
47 //--------------------------------------------------------------------------------
49 // This represents single tag. It is used as internal structure
51 //--------------------------------------------------------------------------------
53 class wx28HtmlTag
: public wxObject
55 DECLARE_CLASS(wx28HtmlTag
)
58 // constructs wx28HtmlTag object based on HTML tag.
59 // The tag begins (with '<' character) at position pos in source
60 // end_pos is position where parsing ends (usually end of document)
61 wx28HtmlTag(wx28HtmlTag
*parent
,
62 const wxString
& source
, int pos
, int end_pos
,
63 wx28HtmlTagsCache
*cache
,
64 wx28HtmlEntitiesParser
*entParser
);
65 friend class wx28HtmlParser
;
67 virtual ~wx28HtmlTag();
69 wx28HtmlTag
*GetParent() const {return m_Parent
;}
70 wx28HtmlTag
*GetFirstSibling() const;
71 wx28HtmlTag
*GetLastSibling() const;
72 wx28HtmlTag
*GetChildren() const { return m_FirstChild
; }
73 wx28HtmlTag
*GetPreviousSibling() const { return m_Prev
; }
74 wx28HtmlTag
*GetNextSibling() const {return m_Next
; }
75 // Return next tag, as if tree had been flattened
76 wx28HtmlTag
*GetNextTag() const;
78 // Returns tag's name in uppercase.
79 inline wxString
GetName() const {return m_Name
;}
81 // Returns true if the tag has given parameter. Parameter
82 // should always be in uppercase.
83 // Example : <IMG SRC="test.jpg"> HasParam("SRC") returns true
84 bool HasParam(const wxString
& par
) const;
86 // Returns value of the param. Value is in uppercase unless it is
88 // Example : <P align=right> GetParam("ALIGN") returns (RIGHT)
89 // <P IMG SRC="WhaT.jpg"> GetParam("SRC") returns (WhaT.jpg)
90 // (or ("WhaT.jpg") if with_commas == true)
91 wxString
GetParam(const wxString
& par
, bool with_commas
= false) const;
93 bool GetParamAsInt(const wxString
& par
, int *clr
) const;
95 // Scans param like scanf() functions family does.
96 // Example : ScanParam("COLOR", "\"#%X\"", &clr);
97 // This is always with with_commas=false
98 // Returns number of scanned values
99 // (like sscanf() does)
100 // NOTE: unlike scanf family, this function only accepts
102 int ScanParam(const wxString
& par
, const wxChar
*format
, void *param
) const;
104 // Returns string containing all params.
105 wxString
GetAllParams() const;
107 // return true if this there is matching ending tag
108 inline bool HasEnding() const {return m_End1
>= 0;}
110 // returns beginning position of _internal_ block of text
111 // See explanation (returned value is marked with *):
112 // bla bla bla <MYTAG>* bla bla intenal text</MYTAG> bla bla
113 inline int GetBeginPos() const {return m_Begin
;}
114 // returns ending position of _internal_ block of text.
115 // bla bla bla <MYTAG> bla bla intenal text*</MYTAG> bla bla
116 inline int GetEndPos1() const {return m_End1
;}
117 // returns end position 2 :
118 // bla bla bla <MYTAG> bla bla internal text</MYTAG>* bla bla
119 inline int GetEndPos2() const {return m_End2
;}
123 int m_Begin
, m_End1
, m_End2
;
124 wxArrayString m_ParamNames
, m_ParamValues
;
126 // DOM tree relations:
129 wx28HtmlTag
*m_FirstChild
, *m_LastChild
;
130 wx28HtmlTag
*m_Parent
;
132 DECLARE_NO_COPY_CLASS(wx28HtmlTag
)
137 #endif // _WX_HTMLTAG_H_