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