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_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(int at
, int* end1
, int* end2
);
46 DECLARE_NO_COPY_CLASS(wxHtmlTagsCache
)
50 //--------------------------------------------------------------------------------
52 // This represents single tag. It is used as internal structure
54 //--------------------------------------------------------------------------------
56 class WXDLLIMPEXP_HTML wxHtmlTag
59 // constructs wxHtmlTag 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 wxHtmlTag(wxHtmlTag
*parent
,
63 const wxString
& source
, int pos
, int end_pos
,
64 wxHtmlTagsCache
*cache
,
65 wxHtmlEntitiesParser
*entParser
);
66 friend class wxHtmlParser
;
70 wxHtmlTag
*GetParent() const {return m_Parent
;}
71 wxHtmlTag
*GetFirstSibling() const;
72 wxHtmlTag
*GetLastSibling() const;
73 wxHtmlTag
*GetChildren() const { return m_FirstChild
; }
74 wxHtmlTag
*GetPreviousSibling() const { return m_Prev
; }
75 wxHtmlTag
*GetNextSibling() const {return m_Next
; }
76 // Return next tag, as if tree had been flattened
77 wxHtmlTag
*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 char *format
, void *param
) const;
106 int ScanParam(const wxString
& par
, const wchar_t *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 wxHtmlTag
*m_FirstChild
, *m_LastChild
;
136 DECLARE_NO_COPY_CLASS(wxHtmlTag
)
145 #endif // _WX_HTMLTAG_H_