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