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