1 /////////////////////////////////////////////////////////////////////////////
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_CORE wxColour
;
21 class WXDLLIMPEXP_HTML wxHtmlEntitiesParser
;
23 //-----------------------------------------------------------------------------
25 // - internal wxHTML class, do not use!
26 //-----------------------------------------------------------------------------
28 struct wxHtmlCacheItem
;
30 class WXDLLIMPEXP_HTML wxHtmlTagsCache
: public wxObject
32 DECLARE_DYNAMIC_CLASS(wxHtmlTagsCache
)
35 wxHtmlCacheItem
*m_Cache
;
40 wxHtmlTagsCache() : wxObject() {m_CacheSize
= 0; m_Cache
= NULL
;}
41 wxHtmlTagsCache(const wxString
& source
);
42 ~wxHtmlTagsCache() {free(m_Cache
);}
44 // Finds parameters for tag starting at at and fills the variables
45 void QueryTag(int at
, int* end1
, int* end2
);
47 DECLARE_NO_COPY_CLASS(wxHtmlTagsCache
)
51 //--------------------------------------------------------------------------------
53 // This represents single tag. It is used as internal structure
55 //--------------------------------------------------------------------------------
57 class WXDLLIMPEXP_HTML wxHtmlTag
: public wxObject
59 DECLARE_CLASS(wxHtmlTag
)
62 // constructs wxHtmlTag object based on HTML tag.
63 // The tag begins (with '<' character) at position pos in source
64 // end_pos is position where parsing ends (usually end of document)
65 wxHtmlTag(wxHtmlTag
*parent
,
66 const wxString
& source
, int pos
, int end_pos
,
67 wxHtmlTagsCache
*cache
,
68 wxHtmlEntitiesParser
*entParser
);
69 friend class wxHtmlParser
;
73 wxHtmlTag
*GetParent() const {return m_Parent
;}
74 wxHtmlTag
*GetFirstSibling() const;
75 wxHtmlTag
*GetLastSibling() const;
76 wxHtmlTag
*GetChildren() const { return m_FirstChild
; }
77 wxHtmlTag
*GetPreviousSibling() const { return m_Prev
; }
78 wxHtmlTag
*GetNextSibling() const {return m_Next
; }
79 // Return next tag, as if tree had been flattened
80 wxHtmlTag
*GetNextTag() const;
82 // Returns tag's name in uppercase.
83 inline wxString
GetName() const {return m_Name
;}
85 // Returns true if the tag has given parameter. Parameter
86 // should always be in uppercase.
87 // Example : <IMG SRC="test.jpg"> HasParam("SRC") returns true
88 bool HasParam(const wxString
& par
) const;
90 // Returns value of the param. Value is in uppercase unless it is
92 // Example : <P align=right> GetParam("ALIGN") returns (RIGHT)
93 // <P IMG SRC="WhaT.jpg"> GetParam("SRC") returns (WhaT.jpg)
94 // (or ("WhaT.jpg") if with_commas == true)
95 wxString
GetParam(const wxString
& par
, bool with_commas
= false) const;
97 // Convenience functions:
98 bool GetParamAsColour(const wxString
& par
, wxColour
*clr
) const;
99 bool GetParamAsInt(const wxString
& par
, int *clr
) const;
101 // Scans param like scanf() functions family does.
102 // Example : ScanParam("COLOR", "\"#%X\"", &clr);
103 // This is always with with_commas=false
104 // Returns number of scanned values
105 // (like sscanf() does)
106 // NOTE: unlike scanf family, this function only accepts
108 int ScanParam(const wxString
& par
, const wxChar
*format
, void *param
) const;
110 // Returns string containing all params.
111 wxString
GetAllParams() const;
113 // return true if this there is matching ending tag
114 inline bool HasEnding() const {return m_End1
>= 0;}
116 // returns beginning position of _internal_ block of text
117 // See explanation (returned value is marked with *):
118 // bla bla bla <MYTAG>* bla bla intenal text</MYTAG> bla bla
119 inline int GetBeginPos() const {return m_Begin
;}
120 // returns ending position of _internal_ block of text.
121 // bla bla bla <MYTAG> bla bla intenal text*</MYTAG> bla bla
122 inline int GetEndPos1() const {return m_End1
;}
123 // returns end position 2 :
124 // bla bla bla <MYTAG> bla bla internal text</MYTAG>* bla bla
125 inline int GetEndPos2() const {return m_End2
;}
129 int m_Begin
, m_End1
, m_End2
;
130 wxArrayString m_ParamNames
, m_ParamValues
;
132 // DOM tree relations:
135 wxHtmlTag
*m_FirstChild
, *m_LastChild
;
138 DECLARE_NO_COPY_CLASS(wxHtmlTag
)
147 #endif // _WX_HTMLTAG_H_