]> git.saurik.com Git - wxWidgets.git/blame - include/wx/html/htmltag.h
Don't define __STRICT_ANSI__, we should build both with and without it.
[wxWidgets.git] / include / wx / html / htmltag.h
CommitLineData
5526e819 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: wx/html/htmltag.h
5526e819
VS
3// Purpose: wxHtmlTag class (represents single tag)
4// Author: Vaclav Slavik
5// Copyright: (c) 1999 Vaclav Slavik
65571936 6// Licence: wxWindows licence
5526e819
VS
7/////////////////////////////////////////////////////////////////////////////
8
69941f05
VS
9#ifndef _WX_HTMLTAG_H_
10#define _WX_HTMLTAG_H_
5526e819 11
5526e819 12#include "wx/defs.h"
04dbb646 13
5526e819
VS
14#if wxUSE_HTML
15
04dbb646 16#include "wx/object.h"
360b63dd 17#include "wx/arrstr.h"
04dbb646 18
b5dbe15d
VS
19class WXDLLIMPEXP_FWD_CORE wxColour;
20class WXDLLIMPEXP_FWD_HTML wxHtmlEntitiesParser;
8bd72d90 21
97494971 22//-----------------------------------------------------------------------------
5526e819 23// wxHtmlTagsCache
97494971
VS
24// - internal wxHTML class, do not use!
25//-----------------------------------------------------------------------------
5526e819 26
4fe7567d 27class wxHtmlTagsCacheData;
5526e819 28
7da48d49 29class WXDLLIMPEXP_HTML wxHtmlTagsCache
5526e819 30{
97494971 31private:
4fe7567d 32 wxHtmlTagsCacheData *m_Cache;
b1a3a964 33 int m_CachePos;
4fe7567d
VS
34
35 wxHtmlTagsCacheData& Cache() { return *m_Cache; }
5526e819 36
97494971 37public:
4fe7567d 38 wxHtmlTagsCache() {m_Cache = NULL;}
97494971 39 wxHtmlTagsCache(const wxString& source);
4fe7567d 40 virtual ~wxHtmlTagsCache();
5526e819 41
97494971 42 // Finds parameters for tag starting at at and fills the variables
b1a3a964
VS
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);
22f3361e 48
c0c133e1 49 wxDECLARE_NO_COPY_CLASS(wxHtmlTagsCache);
5526e819
VS
50};
51
52
5526e819
VS
53//--------------------------------------------------------------------------------
54// wxHtmlTag
55// This represents single tag. It is used as internal structure
56// by wxHtmlParser.
57//--------------------------------------------------------------------------------
58
7da48d49 59class WXDLLIMPEXP_HTML wxHtmlTag
5526e819 60{
6c62a62b 61protected:
97494971
VS
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)
6c62a62b 65 wxHtmlTag(wxHtmlTag *parent,
b1a3a964
VS
66 const wxString *source,
67 const wxString::const_iterator& pos,
68 const wxString::const_iterator& end_pos,
8bd72d90 69 wxHtmlTagsCache *cache,
6c62a62b
VS
70 wxHtmlEntitiesParser *entParser);
71 friend class wxHtmlParser;
72public:
7da48d49 73 ~wxHtmlTag();
6c62a62b
VS
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;
97494971
VS
83
84 // Returns tag's name in uppercase.
85 inline wxString GetName() const {return m_Name;}
86
6953da00 87 // Returns true if the tag has given parameter. Parameter
97494971 88 // should always be in uppercase.
6953da00 89 // Example : <IMG SRC="test.jpg"> HasParam("SRC") returns true
97494971
VS
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)
614f9713
VS
96 // (or ("WhaT.jpg") if with_quotes == true)
97 wxString GetParam(const wxString& par, bool with_quotes = false) const;
97494971 98
f68e16c5
VZ
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
04dbb646 103 // Convenience functions:
8bd72d90
VS
104 bool GetParamAsColour(const wxString& par, wxColour *clr) const;
105 bool GetParamAsInt(const wxString& par, int *clr) const;
e0e4b2b0
VZ
106 bool GetParamAsIntOrPercent(const wxString& param,
107 int* value, bool& isPercent) const;
8bd72d90
VS
108
109 // Scans param like scanf() functions family does.
97494971 110 // Example : ScanParam("COLOR", "\"#%X\"", &clr);
614f9713 111 // This is always with with_quotes=false
97494971
VS
112 // Returns number of scanned values
113 // (like sscanf() does)
114 // NOTE: unlike scanf family, this function only accepts
115 // *one* parameter !
d7640339
VS
116 int ScanParam(const wxString& par, const char *format, void *param) const;
117 int ScanParam(const wxString& par, const wchar_t *format, void *param) const;
97494971
VS
118
119 // Returns string containing all params.
8bd72d90 120 wxString GetAllParams() const;
97494971 121
b1a3a964
VS
122 // return true if there is matching ending tag
123 inline bool HasEnding() const {return m_hasEnding;}
97494971 124
0e89a51a
VS
125 // returns beginning position of _internal_ block of text as iterator
126 // into parser's source string (see wxHtmlParser::GetSource())
97494971
VS
127 // See explanation (returned value is marked with *):
128 // bla bla bla <MYTAG>* bla bla intenal text</MYTAG> bla bla
b1a3a964
VS
129 wxString::const_iterator GetBeginIter() const
130 { return m_Begin; }
0e89a51a
VS
131 // returns ending position of _internal_ block of text as iterator
132 // into parser's source string (see wxHtmlParser::GetSource()):
97494971 133 // bla bla bla <MYTAG> bla bla intenal text*</MYTAG> bla bla
61679695 134 wxString::const_iterator GetEndIter1() const { return m_End1; }
0e89a51a
VS
135 // returns end position 2 as iterator
136 // into parser's source string (see wxHtmlParser::GetSource()):
97494971 137 // bla bla bla <MYTAG> bla bla internal text</MYTAG>* bla bla
61679695 138 wxString::const_iterator GetEndIter2() const { return m_End2; }
b1a3a964
VS
139
140#if WXWIN_COMPATIBILITY_2_8
0e89a51a 141 // use GetBeginIter(), GetEndIter1() and GetEndIter2() instead
b1a3a964
VS
142 wxDEPRECATED( inline int GetBeginPos() const );
143 wxDEPRECATED( inline int GetEndPos1() const );
144 wxDEPRECATED( inline int GetEndPos2() const );
145#endif // WXWIN_COMPATIBILITY_2_8
97494971
VS
146
147private:
8bd72d90 148 wxString m_Name;
b1a3a964
VS
149 bool m_hasEnding;
150 wxString::const_iterator m_Begin, m_End1, m_End2;
8bd72d90 151 wxArrayString m_ParamNames, m_ParamValues;
b1a3a964
VS
152#if WXWIN_COMPATIBILITY_2_8
153 wxString::const_iterator m_sourceStart;
154#endif
6c62a62b
VS
155
156 // DOM tree relations:
157 wxHtmlTag *m_Next;
158 wxHtmlTag *m_Prev;
159 wxHtmlTag *m_FirstChild, *m_LastChild;
160 wxHtmlTag *m_Parent;
22f3361e 161
c0c133e1 162 wxDECLARE_NO_COPY_CLASS(wxHtmlTag);
69941f05 163};
5526e819
VS
164
165
b1a3a964 166#if WXWIN_COMPATIBILITY_2_8
17473a77
VS
167inline int wxHtmlTag::GetBeginPos() const { return int(m_Begin - m_sourceStart); }
168inline int wxHtmlTag::GetEndPos1() const { return int(m_End1 - m_sourceStart); }
169inline int wxHtmlTag::GetEndPos2() const { return int(m_End2 - m_sourceStart); }
b1a3a964 170#endif // WXWIN_COMPATIBILITY_2_8
5526e819
VS
171
172
5526e819 173
b1a3a964
VS
174
175#endif // wxUSE_HTML
69941f05
VS
176
177#endif // _WX_HTMLTAG_H_
178