]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/html/winpars.h
renamed m_boxes to m_buttons because, well, it contains the radio buttons and not...
[wxWidgets.git] / include / wx / html / winpars.h
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: winpars.h
3// Purpose: wxHtmlWinParser class (parser to be used with wxHtmlWindow)
4// Author: Vaclav Slavik
5// RCS-ID: $Id$
6// Copyright: (c) 1999 Vaclav Slavik
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#ifndef _WX_WINPARS_H_
11#define _WX_WINPARS_H_
12
13#include "wx/defs.h"
14#if wxUSE_HTML
15
16#include "wx/module.h"
17#include "wx/font.h"
18#include "wx/html/htmlpars.h"
19#include "wx/html/htmlcell.h"
20#include "wx/encconv.h"
21
22class WXDLLIMPEXP_HTML wxHtmlWindow;
23class WXDLLIMPEXP_HTML wxHtmlWindowInterface;
24class WXDLLIMPEXP_HTML wxHtmlWinParser;
25class WXDLLIMPEXP_HTML wxHtmlWinTagHandler;
26class WXDLLIMPEXP_HTML wxHtmlTagsModule;
27
28
29//--------------------------------------------------------------------------------
30// wxHtmlWinParser
31// This class is derived from wxHtmlParser and its mail goal
32// is to parse HTML input so that it can be displayed in
33// wxHtmlWindow. It uses special wxHtmlWinTagHandler.
34//--------------------------------------------------------------------------------
35
36class WXDLLIMPEXP_HTML wxHtmlWinParser : public wxHtmlParser
37{
38 DECLARE_ABSTRACT_CLASS(wxHtmlWinParser)
39 friend class wxHtmlWindow;
40
41public:
42 wxHtmlWinParser(wxHtmlWindowInterface *wndIface = NULL);
43
44 ~wxHtmlWinParser();
45
46 virtual void InitParser(const wxString& source);
47 virtual void DoneParser();
48 virtual wxObject* GetProduct();
49
50 virtual wxFSFile *OpenURL(wxHtmlURLType type, const wxString& url) const;
51
52 // Set's the DC used for parsing. If SetDC() is not called,
53 // parsing won't proceed
54 virtual void SetDC(wxDC *dc, double pixel_scale = 1.0)
55 { m_DC = dc; m_PixelScale = pixel_scale; }
56
57 wxDC *GetDC() {return m_DC;}
58 double GetPixelScale() {return m_PixelScale;}
59 int GetCharHeight() const {return m_CharHeight;}
60 int GetCharWidth() const {return m_CharWidth;}
61
62 // NOTE : these functions do _not_ return _actual_
63 // height/width. They return h/w of default font
64 // for this DC. If you want actual values, call
65 // GetDC()->GetChar...()
66
67 // returns interface to the rendering window
68 wxHtmlWindowInterface *GetWindowInterface() {return m_windowInterface;}
69#if WXWIN_COMPATIBILITY_2_6
70 // deprecated, use GetWindowInterface()->GetHTMLWindow() instead
71 wxDEPRECATED( wxHtmlWindow *GetWindow() );
72#endif
73
74 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
75 void SetFonts(const wxString& normal_face, const wxString& fixed_face, const int *sizes = NULL);
76
77 // Sets font sizes to be relative to the given size or the system
78 // default size; use either specified or default font
79 void SetStandardFonts(int size = -1,
80 const wxString& normal_face = wxEmptyString,
81 const wxString& fixed_face = wxEmptyString);
82
83 // Adds tags module. see wxHtmlTagsModule for details.
84 static void AddModule(wxHtmlTagsModule *module);
85
86 static void RemoveModule(wxHtmlTagsModule *module);
87
88 // parsing-related methods. These methods are called by tag handlers:
89
90 // Returns pointer to actual container. Common use in tag handler is :
91 // m_WParser->GetContainer()->InsertCell(new ...);
92 wxHtmlContainerCell *GetContainer() const {return m_Container;}
93
94 // opens new container. This container is sub-container of opened
95 // container. Sets GetContainer to newly created container
96 // and returns it.
97 wxHtmlContainerCell *OpenContainer();
98
99 // works like OpenContainer except that new container is not created
100 // but c is used. You can use this to directly set actual container
101 wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
102
103 // closes the container and sets actual Container to upper-level
104 // container
105 wxHtmlContainerCell *CloseContainer();
106
107 int GetFontSize() const {return m_FontSize;}
108 void SetFontSize(int s);
109 int GetFontBold() const {return m_FontBold;}
110 void SetFontBold(int x) {m_FontBold = x;}
111 int GetFontItalic() const {return m_FontItalic;}
112 void SetFontItalic(int x) {m_FontItalic = x;}
113 int GetFontUnderlined() const {return m_FontUnderlined;}
114 void SetFontUnderlined(int x) {m_FontUnderlined = x;}
115 int GetFontFixed() const {return m_FontFixed;}
116 void SetFontFixed(int x) {m_FontFixed = x;}
117 wxString GetFontFace() const {return GetFontFixed() ? m_FontFaceFixed : m_FontFaceNormal;}
118 void SetFontFace(const wxString& face);
119
120 int GetAlign() const {return m_Align;}
121 void SetAlign(int a) {m_Align = a;}
122
123 wxHtmlScriptMode GetScriptMode() const { return m_ScriptMode; }
124 void SetScriptMode(wxHtmlScriptMode mode) { m_ScriptMode = mode; }
125 long GetScriptBaseline() const { return m_ScriptBaseline; }
126 void SetScriptBaseline(long base) { m_ScriptBaseline = base; }
127
128 const wxColour& GetLinkColor() const { return m_LinkColor; }
129 void SetLinkColor(const wxColour& clr) { m_LinkColor = clr; }
130 const wxColour& GetActualColor() const { return m_ActualColor; }
131 void SetActualColor(const wxColour& clr) { m_ActualColor = clr ;}
132 const wxHtmlLinkInfo& GetLink() const { return m_Link; }
133 void SetLink(const wxHtmlLinkInfo& link);
134
135 // applies current parser state (link, sub/supscript, ...) to given cell
136 void ApplyStateToCell(wxHtmlCell *cell);
137
138#if !wxUSE_UNICODE
139 void SetInputEncoding(wxFontEncoding enc);
140 wxFontEncoding GetInputEncoding() const { return m_InputEnc; }
141 wxFontEncoding GetOutputEncoding() const { return m_OutputEnc; }
142 wxEncodingConverter *GetEncodingConverter() const { return m_EncConv; }
143#endif
144
145 // creates font depending on m_Font* members.
146 virtual wxFont* CreateCurrentFont();
147
148protected:
149 virtual void AddText(const wxChar* txt);
150
151private:
152 void DoAddText(wxChar *temp, int& templen, wxChar nbsp);
153
154 bool m_tmpLastWasSpace;
155 wxChar *m_tmpStrBuf;
156 size_t m_tmpStrBufSize;
157 // temporary variables used by AddText
158 wxHtmlWindowInterface *m_windowInterface;
159 // window we're parsing for
160 double m_PixelScale;
161 wxDC *m_DC;
162 // Device Context we're parsing for
163 static wxList m_Modules;
164 // list of tags modules (see wxHtmlTagsModule for details)
165 // This list is used to initialize m_Handlers member.
166
167 wxHtmlContainerCell *m_Container;
168 // current container. See Open/CloseContainer for details.
169
170 int m_FontBold, m_FontItalic, m_FontUnderlined, m_FontFixed; // this is not true,false but 1,0, we need it for indexing
171 int m_FontSize; /* -2 to +4, 0 is default */
172 wxColour m_LinkColor;
173 wxColour m_ActualColor;
174 // basic font parameters.
175 wxHtmlLinkInfo m_Link;
176 // actual hypertext link or empty string
177 bool m_UseLink;
178 // true if m_Link is not empty
179 long m_CharHeight, m_CharWidth;
180 // average height of normal-sized text
181 int m_Align;
182 // actual alignment
183 wxHtmlScriptMode m_ScriptMode;
184 // current script mode (sub/sup/normal)
185 long m_ScriptBaseline;
186 // current sub/supscript base
187
188 wxFont* m_FontsTable[2][2][2][2][7];
189 wxString m_FontsFacesTable[2][2][2][2][7];
190#if !wxUSE_UNICODE
191 wxFontEncoding m_FontsEncTable[2][2][2][2][7];
192#endif
193 // table of loaded fonts. 1st four indexes are 0 or 1, depending on on/off
194 // state of these flags (from left to right):
195 // [bold][italic][underlined][fixed_size]
196 // last index is font size : from 0 to 6 (remapped from html sizes 1 to 7)
197 // Note : this table covers all possible combinations of fonts, but not
198 // all of them are used, so many items in table are usually NULL.
199 int m_FontsSizes[7];
200 wxString m_FontFaceFixed, m_FontFaceNormal;
201 // html font sizes and faces of fixed and proportional fonts
202
203#if !wxUSE_UNICODE
204 wxFontEncoding m_InputEnc, m_OutputEnc;
205 // I/O font encodings
206 wxEncodingConverter *m_EncConv;
207#endif
208
209 wxHtmlWordCell *m_lastWordCell;
210
211 DECLARE_NO_COPY_CLASS(wxHtmlWinParser)
212};
213
214
215
216
217
218
219//-----------------------------------------------------------------------------
220// wxHtmlWinTagHandler
221// This is basicly wxHtmlTagHandler except
222// it is extended with protected member m_Parser pointing to
223// the wxHtmlWinParser object
224//-----------------------------------------------------------------------------
225
226class WXDLLIMPEXP_HTML wxHtmlWinTagHandler : public wxHtmlTagHandler
227{
228 DECLARE_ABSTRACT_CLASS(wxHtmlWinTagHandler)
229
230public:
231 wxHtmlWinTagHandler() : wxHtmlTagHandler() {}
232
233 virtual void SetParser(wxHtmlParser *parser) {wxHtmlTagHandler::SetParser(parser); m_WParser = (wxHtmlWinParser*) parser;};
234
235protected:
236 wxHtmlWinParser *m_WParser; // same as m_Parser, but overcasted
237
238 DECLARE_NO_COPY_CLASS(wxHtmlWinTagHandler)
239};
240
241
242
243
244
245
246//----------------------------------------------------------------------------
247// wxHtmlTagsModule
248// This is basic of dynamic tag handlers binding.
249// The class provides methods for filling parser's handlers
250// hash table.
251// (See documentation for details)
252//----------------------------------------------------------------------------
253
254class WXDLLIMPEXP_HTML wxHtmlTagsModule : public wxModule
255{
256 DECLARE_DYNAMIC_CLASS(wxHtmlTagsModule)
257
258public:
259 wxHtmlTagsModule() : wxModule() {}
260
261 virtual bool OnInit();
262 virtual void OnExit();
263
264 // This is called by wxHtmlWinParser.
265 // The method must simply call parser->AddTagHandler(new
266 // <handler_class_name>); for each handler
267 virtual void FillHandlersTable(wxHtmlWinParser * WXUNUSED(parser)) { }
268};
269
270
271#endif
272
273#endif // _WX_WINPARS_H_