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