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