]> git.saurik.com Git - wxWidgets.git/blob - include/wx/html/htmltag.h
e92bb40eba41a3ece5fed7354dbe720d87ae43da
[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
31 {
32 private:
33 wxHtmlTagsCacheData *m_Cache;
34 size_t m_CachePos;
35
36 wxHtmlTagsCacheData& Cache() { return *m_Cache; }
37
38 public:
39 wxHtmlTagsCache() {m_Cache = NULL;}
40 wxHtmlTagsCache(const wxString& source);
41 virtual ~wxHtmlTagsCache();
42
43 // Finds parameters for tag starting at at and fills the variables
44 void QueryTag(int at, int* end1, int* end2);
45
46 DECLARE_NO_COPY_CLASS(wxHtmlTagsCache)
47 };
48
49
50 //--------------------------------------------------------------------------------
51 // wxHtmlTag
52 // This represents single tag. It is used as internal structure
53 // by wxHtmlParser.
54 //--------------------------------------------------------------------------------
55
56 class WXDLLIMPEXP_HTML wxHtmlTag
57 {
58 protected:
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)
62 wxHtmlTag(wxHtmlTag *parent,
63 const wxString& source, int pos, int end_pos,
64 wxHtmlTagsCache *cache,
65 wxHtmlEntitiesParser *entParser);
66 friend class wxHtmlParser;
67 public:
68 ~wxHtmlTag();
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;
78
79 // Returns tag's name in uppercase.
80 inline wxString GetName() const {return m_Name;}
81
82 // Returns true if the tag has given parameter. Parameter
83 // should always be in uppercase.
84 // Example : <IMG SRC="test.jpg"> HasParam("SRC") returns true
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)
91 // (or ("WhaT.jpg") if with_commas == true)
92 wxString GetParam(const wxString& par, bool with_commas = false) const;
93
94 // Convenience functions:
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.
99 // Example : ScanParam("COLOR", "\"#%X\"", &clr);
100 // This is always with with_commas=false
101 // Returns number of scanned values
102 // (like sscanf() does)
103 // NOTE: unlike scanf family, this function only accepts
104 // *one* parameter !
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;
107
108 // Returns string containing all params.
109 wxString GetAllParams() const;
110
111 // return true if this there is matching ending tag
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:
126 wxString m_Name;
127 int m_Begin, m_End1, m_End2;
128 wxArrayString m_ParamNames, m_ParamValues;
129
130 // DOM tree relations:
131 wxHtmlTag *m_Next;
132 wxHtmlTag *m_Prev;
133 wxHtmlTag *m_FirstChild, *m_LastChild;
134 wxHtmlTag *m_Parent;
135
136 DECLARE_NO_COPY_CLASS(wxHtmlTag)
137 };
138
139
140
141
142
143 #endif
144
145 #endif // _WX_HTMLTAG_H_
146