1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtmlTag class (represents single tag)
4 // Author: Vaclav Slavik
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_HTMLTAG_H_
12 #define _WX_HTMLTAG_H_
14 #if defined(__GNUG__) && !defined(__APPLE__)
15 #pragma interface "htmltag.h"
22 #include "wx/object.h"
23 #include "wx/arrstr.h"
25 class WXDLLIMPEXP_CORE wxColour
;
26 class WXDLLIMPEXP_HTML wxHtmlEntitiesParser
;
28 //-----------------------------------------------------------------------------
30 // - internal wxHTML class, do not use!
31 //-----------------------------------------------------------------------------
33 struct wxHtmlCacheItem
;
35 class WXDLLIMPEXP_HTML wxHtmlTagsCache
: public wxObject
37 DECLARE_DYNAMIC_CLASS(wxHtmlTagsCache
)
40 wxHtmlCacheItem
*m_Cache
;
45 wxHtmlTagsCache() : wxObject() {m_CacheSize
= 0; m_Cache
= NULL
;}
46 wxHtmlTagsCache(const wxString
& source
);
47 ~wxHtmlTagsCache() {free(m_Cache
);}
49 // Finds parameters for tag starting at at and fills the variables
50 void QueryTag(int at
, int* end1
, int* end2
);
52 DECLARE_NO_COPY_CLASS(wxHtmlTagsCache
)
56 //--------------------------------------------------------------------------------
58 // This represents single tag. It is used as internal structure
60 //--------------------------------------------------------------------------------
62 class WXDLLIMPEXP_HTML wxHtmlTag
: public wxObject
64 DECLARE_CLASS(wxHtmlTag
)
67 // constructs wxHtmlTag object based on HTML tag.
68 // The tag begins (with '<' character) at position pos in source
69 // end_pos is position where parsing ends (usually end of document)
70 wxHtmlTag(wxHtmlTag
*parent
,
71 const wxString
& source
, int pos
, int end_pos
,
72 wxHtmlTagsCache
*cache
,
73 wxHtmlEntitiesParser
*entParser
);
74 friend class wxHtmlParser
;
78 wxHtmlTag
*GetParent() const {return m_Parent
;}
79 wxHtmlTag
*GetFirstSibling() const;
80 wxHtmlTag
*GetLastSibling() const;
81 wxHtmlTag
*GetChildren() const { return m_FirstChild
; }
82 wxHtmlTag
*GetPreviousSibling() const { return m_Prev
; }
83 wxHtmlTag
*GetNextSibling() const {return m_Next
; }
84 // Return next tag, as if tree had been flattened
85 wxHtmlTag
*GetNextTag() const;
87 // Returns tag's name in uppercase.
88 inline wxString
GetName() const {return m_Name
;}
90 // Returns TRUE if the tag has given parameter. Parameter
91 // should always be in uppercase.
92 // Example : <IMG SRC="test.jpg"> HasParam("SRC") returns TRUE
93 bool HasParam(const wxString
& par
) const;
95 // Returns value of the param. Value is in uppercase unless it is
97 // Example : <P align=right> GetParam("ALIGN") returns (RIGHT)
98 // <P IMG SRC="WhaT.jpg"> GetParam("SRC") returns (WhaT.jpg)
99 // (or ("WhaT.jpg") if with_commas == TRUE)
100 wxString
GetParam(const wxString
& par
, bool with_commas
= FALSE
) const;
102 // Convenience functions:
103 bool GetParamAsColour(const wxString
& par
, wxColour
*clr
) const;
104 bool GetParamAsInt(const wxString
& par
, int *clr
) const;
106 // Scans param like scanf() functions family does.
107 // Example : ScanParam("COLOR", "\"#%X\"", &clr);
108 // This is always with with_commas=FALSE
109 // Returns number of scanned values
110 // (like sscanf() does)
111 // NOTE: unlike scanf family, this function only accepts
113 int ScanParam(const wxString
& par
, const wxChar
*format
, void *param
) const;
115 // Returns string containing all params.
116 wxString
GetAllParams() const;
118 #if WXWIN_COMPATIBILITY_2_2
119 // return TRUE if this is ending tag (</something>) or FALSE
120 // if it isn't (<something>)
121 inline bool IsEnding() const {return FALSE
;}
124 // return TRUE if this there is matching ending tag
125 inline bool HasEnding() const {return m_End1
>= 0;}
127 // returns beginning position of _internal_ block of text
128 // See explanation (returned value is marked with *):
129 // bla bla bla <MYTAG>* bla bla intenal text</MYTAG> bla bla
130 inline int GetBeginPos() const {return m_Begin
;}
131 // returns ending position of _internal_ block of text.
132 // bla bla bla <MYTAG> bla bla intenal text*</MYTAG> bla bla
133 inline int GetEndPos1() const {return m_End1
;}
134 // returns end position 2 :
135 // bla bla bla <MYTAG> bla bla internal text</MYTAG>* bla bla
136 inline int GetEndPos2() const {return m_End2
;}
140 int m_Begin
, m_End1
, m_End2
;
141 wxArrayString m_ParamNames
, m_ParamValues
;
143 // DOM tree relations:
146 wxHtmlTag
*m_FirstChild
, *m_LastChild
;
149 DECLARE_NO_COPY_CLASS(wxHtmlTag
)
158 #endif // _WX_HTMLTAG_H_