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