]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/html/htmltag.h | |
3 | // Purpose: wxHtmlTag class (represents single tag) | |
4 | // Author: Vaclav Slavik | |
5 | // Copyright: (c) 1999 Vaclav Slavik | |
6 | // Licence: wxWindows licence | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | #ifndef _WX_HTMLTAG_H_ | |
10 | #define _WX_HTMLTAG_H_ | |
11 | ||
12 | #include "wx/defs.h" | |
13 | ||
14 | #if wxUSE_HTML | |
15 | ||
16 | #include "wx/object.h" | |
17 | #include "wx/arrstr.h" | |
18 | ||
19 | class WXDLLIMPEXP_FWD_CORE wxColour; | |
20 | class WXDLLIMPEXP_FWD_HTML wxHtmlEntitiesParser; | |
21 | ||
22 | //----------------------------------------------------------------------------- | |
23 | // wxHtmlTagsCache | |
24 | // - internal wxHTML class, do not use! | |
25 | //----------------------------------------------------------------------------- | |
26 | ||
27 | class wxHtmlTagsCacheData; | |
28 | ||
29 | class WXDLLIMPEXP_HTML wxHtmlTagsCache | |
30 | { | |
31 | private: | |
32 | wxHtmlTagsCacheData *m_Cache; | |
33 | int m_CachePos; | |
34 | ||
35 | wxHtmlTagsCacheData& Cache() { return *m_Cache; } | |
36 | ||
37 | public: | |
38 | wxHtmlTagsCache() {m_Cache = NULL;} | |
39 | wxHtmlTagsCache(const wxString& source); | |
40 | virtual ~wxHtmlTagsCache(); | |
41 | ||
42 | // Finds parameters for tag starting at at and fills the variables | |
43 | void QueryTag(const wxString::const_iterator& at, | |
44 | const wxString::const_iterator& inputEnd, | |
45 | wxString::const_iterator *end1, | |
46 | wxString::const_iterator *end2, | |
47 | bool *hasEnding); | |
48 | ||
49 | wxDECLARE_NO_COPY_CLASS(wxHtmlTagsCache); | |
50 | }; | |
51 | ||
52 | ||
53 | //-------------------------------------------------------------------------------- | |
54 | // wxHtmlTag | |
55 | // This represents single tag. It is used as internal structure | |
56 | // by wxHtmlParser. | |
57 | //-------------------------------------------------------------------------------- | |
58 | ||
59 | class WXDLLIMPEXP_HTML wxHtmlTag | |
60 | { | |
61 | protected: | |
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, | |
67 | const wxString::const_iterator& pos, | |
68 | const wxString::const_iterator& end_pos, | |
69 | wxHtmlTagsCache *cache, | |
70 | wxHtmlEntitiesParser *entParser); | |
71 | friend class wxHtmlParser; | |
72 | public: | |
73 | ~wxHtmlTag(); | |
74 | ||
75 | wxHtmlTag *GetParent() const {return m_Parent;} | |
76 | wxHtmlTag *GetFirstSibling() const; | |
77 | wxHtmlTag *GetLastSibling() const; | |
78 | wxHtmlTag *GetChildren() const { return m_FirstChild; } | |
79 | wxHtmlTag *GetPreviousSibling() const { return m_Prev; } | |
80 | wxHtmlTag *GetNextSibling() const {return m_Next; } | |
81 | // Return next tag, as if tree had been flattened | |
82 | wxHtmlTag *GetNextTag() const; | |
83 | ||
84 | // Returns tag's name in uppercase. | |
85 | inline wxString GetName() const {return m_Name;} | |
86 | ||
87 | // Returns true if the tag has given parameter. Parameter | |
88 | // should always be in uppercase. | |
89 | // Example : <IMG SRC="test.jpg"> HasParam("SRC") returns true | |
90 | bool HasParam(const wxString& par) const; | |
91 | ||
92 | // Returns value of the param. Value is in uppercase unless it is | |
93 | // enclosed with " | |
94 | // Example : <P align=right> GetParam("ALIGN") returns (RIGHT) | |
95 | // <P IMG SRC="WhaT.jpg"> GetParam("SRC") returns (WhaT.jpg) | |
96 | // (or ("WhaT.jpg") if with_quotes == true) | |
97 | wxString GetParam(const wxString& par, bool with_quotes = false) const; | |
98 | ||
99 | // Return true if the string could be parsed as an HTML colour and false | |
100 | // otherwise. | |
101 | static bool ParseAsColour(const wxString& str, wxColour *clr); | |
102 | ||
103 | // Convenience functions: | |
104 | bool GetParamAsString(const wxString& par, wxString *str) const; | |
105 | bool GetParamAsColour(const wxString& par, wxColour *clr) const; | |
106 | bool GetParamAsInt(const wxString& par, int *clr) const; | |
107 | bool GetParamAsIntOrPercent(const wxString& param, | |
108 | int* value, bool& isPercent) const; | |
109 | ||
110 | // Scans param like scanf() functions family does. | |
111 | // Example : ScanParam("COLOR", "\"#%X\"", &clr); | |
112 | // This is always with with_quotes=false | |
113 | // Returns number of scanned values | |
114 | // (like sscanf() does) | |
115 | // NOTE: unlike scanf family, this function only accepts | |
116 | // *one* parameter ! | |
117 | int ScanParam(const wxString& par, const char *format, void *param) const; | |
118 | int ScanParam(const wxString& par, const wchar_t *format, void *param) const; | |
119 | ||
120 | // Returns string containing all params. | |
121 | wxString GetAllParams() const; | |
122 | ||
123 | // return true if there is matching ending tag | |
124 | inline bool HasEnding() const {return m_hasEnding;} | |
125 | ||
126 | // returns beginning position of _internal_ block of text as iterator | |
127 | // into parser's source string (see wxHtmlParser::GetSource()) | |
128 | // See explanation (returned value is marked with *): | |
129 | // bla bla bla <MYTAG>* bla bla intenal text</MYTAG> bla bla | |
130 | wxString::const_iterator GetBeginIter() const | |
131 | { return m_Begin; } | |
132 | // returns ending position of _internal_ block of text as iterator | |
133 | // into parser's source string (see wxHtmlParser::GetSource()): | |
134 | // bla bla bla <MYTAG> bla bla intenal text*</MYTAG> bla bla | |
135 | wxString::const_iterator GetEndIter1() const { return m_End1; } | |
136 | // returns end position 2 as iterator | |
137 | // into parser's source string (see wxHtmlParser::GetSource()): | |
138 | // bla bla bla <MYTAG> bla bla internal text</MYTAG>* bla bla | |
139 | wxString::const_iterator GetEndIter2() const { return m_End2; } | |
140 | ||
141 | #if WXWIN_COMPATIBILITY_2_8 | |
142 | // use GetBeginIter(), GetEndIter1() and GetEndIter2() instead | |
143 | wxDEPRECATED( inline int GetBeginPos() const ); | |
144 | wxDEPRECATED( inline int GetEndPos1() const ); | |
145 | wxDEPRECATED( inline int GetEndPos2() const ); | |
146 | #endif // WXWIN_COMPATIBILITY_2_8 | |
147 | ||
148 | private: | |
149 | wxString m_Name; | |
150 | bool m_hasEnding; | |
151 | wxString::const_iterator m_Begin, m_End1, m_End2; | |
152 | wxArrayString m_ParamNames, m_ParamValues; | |
153 | #if WXWIN_COMPATIBILITY_2_8 | |
154 | wxString::const_iterator m_sourceStart; | |
155 | #endif | |
156 | ||
157 | // DOM tree relations: | |
158 | wxHtmlTag *m_Next; | |
159 | wxHtmlTag *m_Prev; | |
160 | wxHtmlTag *m_FirstChild, *m_LastChild; | |
161 | wxHtmlTag *m_Parent; | |
162 | ||
163 | wxDECLARE_NO_COPY_CLASS(wxHtmlTag); | |
164 | }; | |
165 | ||
166 | ||
167 | #if WXWIN_COMPATIBILITY_2_8 | |
168 | inline int wxHtmlTag::GetBeginPos() const { return int(m_Begin - m_sourceStart); } | |
169 | inline int wxHtmlTag::GetEndPos1() const { return int(m_End1 - m_sourceStart); } | |
170 | inline int wxHtmlTag::GetEndPos2() const { return int(m_End2 - m_sourceStart); } | |
171 | #endif // WXWIN_COMPATIBILITY_2_8 | |
172 | ||
173 | ||
174 | ||
175 | ||
176 | #endif // wxUSE_HTML | |
177 | ||
178 | #endif // _WX_HTMLTAG_H_ | |
179 |