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