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