]>
Commit | Line | Data |
---|---|---|
5526e819 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: htmltag.h | |
3 | // Purpose: wxHtmlTag class (represents single tag) | |
4 | // Author: Vaclav Slavik | |
69941f05 | 5 | // RCS-ID: $Id$ |
5526e819 | 6 | // Copyright: (c) 1999 Vaclav Slavik |
65571936 | 7 | // Licence: wxWindows licence |
5526e819 VS |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
69941f05 VS |
10 | #ifndef _WX_HTMLTAG_H_ |
11 | #define _WX_HTMLTAG_H_ | |
5526e819 | 12 | |
5526e819 | 13 | #include "wx/defs.h" |
04dbb646 | 14 | |
5526e819 VS |
15 | #if wxUSE_HTML |
16 | ||
04dbb646 | 17 | #include "wx/object.h" |
360b63dd | 18 | #include "wx/arrstr.h" |
04dbb646 | 19 | |
b5dbe15d VS |
20 | class WXDLLIMPEXP_FWD_CORE wxColour; |
21 | class WXDLLIMPEXP_FWD_HTML wxHtmlEntitiesParser; | |
8bd72d90 | 22 | |
97494971 | 23 | //----------------------------------------------------------------------------- |
5526e819 | 24 | // wxHtmlTagsCache |
97494971 VS |
25 | // - internal wxHTML class, do not use! |
26 | //----------------------------------------------------------------------------- | |
5526e819 | 27 | |
4fe7567d | 28 | class wxHtmlTagsCacheData; |
5526e819 | 29 | |
7da48d49 | 30 | class WXDLLIMPEXP_HTML wxHtmlTagsCache |
5526e819 | 31 | { |
97494971 | 32 | private: |
4fe7567d VS |
33 | wxHtmlTagsCacheData *m_Cache; |
34 | size_t m_CachePos; | |
35 | ||
36 | wxHtmlTagsCacheData& Cache() { return *m_Cache; } | |
5526e819 | 37 | |
97494971 | 38 | public: |
4fe7567d | 39 | wxHtmlTagsCache() {m_Cache = NULL;} |
97494971 | 40 | wxHtmlTagsCache(const wxString& source); |
4fe7567d | 41 | virtual ~wxHtmlTagsCache(); |
5526e819 | 42 | |
97494971 VS |
43 | // Finds parameters for tag starting at at and fills the variables |
44 | void QueryTag(int at, int* end1, int* end2); | |
22f3361e VZ |
45 | |
46 | DECLARE_NO_COPY_CLASS(wxHtmlTagsCache) | |
5526e819 VS |
47 | }; |
48 | ||
49 | ||
5526e819 VS |
50 | //-------------------------------------------------------------------------------- |
51 | // wxHtmlTag | |
52 | // This represents single tag. It is used as internal structure | |
53 | // by wxHtmlParser. | |
54 | //-------------------------------------------------------------------------------- | |
55 | ||
7da48d49 | 56 | class WXDLLIMPEXP_HTML wxHtmlTag |
5526e819 | 57 | { |
6c62a62b | 58 | protected: |
97494971 VS |
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) | |
6c62a62b VS |
62 | wxHtmlTag(wxHtmlTag *parent, |
63 | const wxString& source, int pos, int end_pos, | |
8bd72d90 | 64 | wxHtmlTagsCache *cache, |
6c62a62b VS |
65 | wxHtmlEntitiesParser *entParser); |
66 | friend class wxHtmlParser; | |
67 | public: | |
7da48d49 | 68 | ~wxHtmlTag(); |
6c62a62b VS |
69 | |
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; | |
97494971 VS |
78 | |
79 | // Returns tag's name in uppercase. | |
80 | inline wxString GetName() const {return m_Name;} | |
81 | ||
6953da00 | 82 | // Returns true if the tag has given parameter. Parameter |
97494971 | 83 | // should always be in uppercase. |
6953da00 | 84 | // Example : <IMG SRC="test.jpg"> HasParam("SRC") returns true |
97494971 VS |
85 | bool HasParam(const wxString& par) const; |
86 | ||
87 | // Returns value of the param. Value is in uppercase unless it is | |
88 | // enclosed with " | |
89 | // Example : <P align=right> GetParam("ALIGN") returns (RIGHT) | |
90 | // <P IMG SRC="WhaT.jpg"> GetParam("SRC") returns (WhaT.jpg) | |
6953da00 WS |
91 | // (or ("WhaT.jpg") if with_commas == true) |
92 | wxString GetParam(const wxString& par, bool with_commas = false) const; | |
97494971 | 93 | |
04dbb646 | 94 | // Convenience functions: |
8bd72d90 VS |
95 | bool GetParamAsColour(const wxString& par, wxColour *clr) const; |
96 | bool GetParamAsInt(const wxString& par, int *clr) const; | |
97 | ||
98 | // Scans param like scanf() functions family does. | |
97494971 | 99 | // Example : ScanParam("COLOR", "\"#%X\"", &clr); |
6953da00 | 100 | // This is always with with_commas=false |
97494971 VS |
101 | // Returns number of scanned values |
102 | // (like sscanf() does) | |
103 | // NOTE: unlike scanf family, this function only accepts | |
104 | // *one* parameter ! | |
d7640339 VS |
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; | |
97494971 VS |
107 | |
108 | // Returns string containing all params. | |
8bd72d90 | 109 | wxString GetAllParams() const; |
97494971 | 110 | |
6953da00 | 111 | // return true if this there is matching ending tag |
97494971 VS |
112 | inline bool HasEnding() const {return m_End1 >= 0;} |
113 | ||
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;} | |
124 | ||
125 | private: | |
8bd72d90 | 126 | wxString m_Name; |
97494971 | 127 | int m_Begin, m_End1, m_End2; |
8bd72d90 | 128 | wxArrayString m_ParamNames, m_ParamValues; |
6c62a62b VS |
129 | |
130 | // DOM tree relations: | |
131 | wxHtmlTag *m_Next; | |
132 | wxHtmlTag *m_Prev; | |
133 | wxHtmlTag *m_FirstChild, *m_LastChild; | |
134 | wxHtmlTag *m_Parent; | |
22f3361e VZ |
135 | |
136 | DECLARE_NO_COPY_CLASS(wxHtmlTag) | |
69941f05 | 137 | }; |
5526e819 VS |
138 | |
139 | ||
140 | ||
141 | ||
5526e819 VS |
142 | |
143 | #endif | |
69941f05 VS |
144 | |
145 | #endif // _WX_HTMLTAG_H_ | |
146 |