]> git.saurik.com Git - wxWidgets.git/blame - include/wx/html/winpars.h
fixes to static box borders calculations and significant code cleanup (finalizes...
[wxWidgets.git] / include / wx / html / winpars.h
CommitLineData
5526e819 1/////////////////////////////////////////////////////////////////////////////
69941f05 2// Name: winpars.h
5526e819
VS
3// Purpose: wxHtmlWinParser class (parser to be used with wxHtmlWindow)
4// Author: Vaclav Slavik
69941f05 5// RCS-ID: $Id$
5526e819 6// Copyright: (c) 1999 Vaclav Slavik
65571936 7// Licence: wxWindows licence
5526e819
VS
8/////////////////////////////////////////////////////////////////////////////
9
10
69941f05
VS
11#ifndef _WX_WINPARS_H_
12#define _WX_WINPARS_H_
5526e819 13
12028905 14#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
97494971 15#pragma interface "winpars.h"
5526e819
VS
16#endif
17
18#include "wx/defs.h"
19#if wxUSE_HTML
20
69941f05 21#include "wx/module.h"
b250d384 22#include "wx/font.h"
69941f05
VS
23#include "wx/html/htmlpars.h"
24#include "wx/html/htmlcell.h"
b250d384 25#include "wx/encconv.h"
5526e819 26
6acba9a7
VS
27class WXDLLIMPEXP_HTML wxHtmlWindow;
28class WXDLLIMPEXP_HTML wxHtmlWinParser;
29class WXDLLIMPEXP_HTML wxHtmlWinTagHandler;
30class WXDLLIMPEXP_HTML wxHtmlTagsModule;
5526e819
VS
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
6acba9a7 39class WXDLLIMPEXP_HTML wxHtmlWinParser : public wxHtmlParser
5526e819 40{
4f44ea36 41 DECLARE_ABSTRACT_CLASS(wxHtmlWinParser)
5526e819
VS
42 friend class wxHtmlWindow;
43
97494971 44public:
04db5c3f 45 wxHtmlWinParser(wxHtmlWindow *wnd = NULL);
97494971
VS
46 ~wxHtmlWinParser();
47
48 virtual void InitParser(const wxString& source);
49 virtual void DoneParser();
50 virtual wxObject* GetProduct();
51
6cc4e6b8 52 virtual wxFSFile *OpenURL(wxHtmlURLType type, const wxString& url) const;
04db5c3f 53
97494971
VS
54 // Set's the DC used for parsing. If SetDC() is not called,
55 // parsing won't proceed
19193a2c 56 virtual void SetDC(wxDC *dc, double pixel_scale = 1.0)
97494971
VS
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...()
19193a2c 68
97494971 69 // returns associated wxWindow
04db5c3f 70 wxHtmlWindow *GetWindow() {return m_Window;}
97494971 71
4eecf115
VS
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);
19193a2c 74
10e5c7ea
VS
75 // Sets font sizes to be relative to the given size or the system
76 // default size; use either specified or default font
77 void SetStandardFonts(int size = -1,
78 const wxString& normal_face = wxEmptyString,
79 const wxString& fixed_face = wxEmptyString);
6953da00 80
97494971
VS
81 // Adds tags module. see wxHtmlTagsModule for details.
82 static void AddModule(wxHtmlTagsModule *module);
83
84 static void RemoveModule(wxHtmlTagsModule *module);
85
86 // parsing-related methods. These methods are called by tag handlers:
87
88 // Returns pointer to actual container. Common use in tag handler is :
89 // m_WParser->GetContainer()->InsertCell(new ...);
90 wxHtmlContainerCell *GetContainer() const {return m_Container;}
91
92 // opens new container. This container is sub-container of opened
93 // container. Sets GetContainer to newly created container
94 // and returns it.
95 wxHtmlContainerCell *OpenContainer();
96
97 // works like OpenContainer except that new container is not created
98 // but c is used. You can use this to directly set actual container
99 wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
100
101 // closes the container and sets actual Container to upper-level
102 // container
103 wxHtmlContainerCell *CloseContainer();
104
105 int GetFontSize() const {return m_FontSize;}
106 void SetFontSize(int s);
107 int GetFontBold() const {return m_FontBold;}
108 void SetFontBold(int x) {m_FontBold = x;}
109 int GetFontItalic() const {return m_FontItalic;}
110 void SetFontItalic(int x) {m_FontItalic = x;}
111 int GetFontUnderlined() const {return m_FontUnderlined;}
112 void SetFontUnderlined(int x) {m_FontUnderlined = x;}
113 int GetFontFixed() const {return m_FontFixed;}
114 void SetFontFixed(int x) {m_FontFixed = x;}
115 wxString GetFontFace() const {return GetFontFixed() ? m_FontFaceFixed : m_FontFaceNormal;}
116 void SetFontFace(const wxString& face);
117
118 int GetAlign() const {return m_Align;}
119 void SetAlign(int a) {m_Align = a;}
120 const wxColour& GetLinkColor() const { return m_LinkColor; }
121 void SetLinkColor(const wxColour& clr) { m_LinkColor = clr; }
122 const wxColour& GetActualColor() const { return m_ActualColor; }
123 void SetActualColor(const wxColour& clr) { m_ActualColor = clr ;}
124 const wxHtmlLinkInfo& GetLink() const { return m_Link; }
125 void SetLink(const wxHtmlLinkInfo& link);
126
2b5f62a0 127#if !wxUSE_UNICODE
97494971
VS
128 void SetInputEncoding(wxFontEncoding enc);
129 wxFontEncoding GetInputEncoding() const { return m_InputEnc; }
130 wxFontEncoding GetOutputEncoding() const { return m_OutputEnc; }
131 wxEncodingConverter *GetEncodingConverter() const { return m_EncConv; }
2b5f62a0 132#endif
97494971
VS
133
134 // creates font depending on m_Font* members.
135 virtual wxFont* CreateCurrentFont();
136
137protected:
6c62a62b 138 virtual void AddText(const wxChar* txt);
97494971
VS
139
140private:
141 bool m_tmpLastWasSpace;
6c62a62b
VS
142 wxChar *m_tmpStrBuf;
143 size_t m_tmpStrBufSize;
144 // temporary variables used by AddText
04db5c3f 145 wxHtmlWindow *m_Window;
97494971
VS
146 // window we're parsing for
147 double m_PixelScale;
148 wxDC *m_DC;
149 // Device Context we're parsing for
150 static wxList m_Modules;
151 // list of tags modules (see wxHtmlTagsModule for details)
152 // This list is used to initialize m_Handlers member.
153
154 wxHtmlContainerCell *m_Container;
ace0fab4 155 // current container. See Open/CloseContainer for details.
97494971 156
6953da00 157 int m_FontBold, m_FontItalic, m_FontUnderlined, m_FontFixed; // this is not true,false but 1,0, we need it for indexing
97494971
VS
158 int m_FontSize; /* -2 to +4, 0 is default */
159 wxColour m_LinkColor;
160 wxColour m_ActualColor;
161 // basic font parameters.
162 wxHtmlLinkInfo m_Link;
163 // actual hypertext link or empty string
164 bool m_UseLink;
6953da00 165 // true if m_Link is not empty
97494971
VS
166 long m_CharHeight, m_CharWidth;
167 // average height of normal-sized text
168 int m_Align;
169 // actual alignment
170
171 wxFont* m_FontsTable[2][2][2][2][7];
172 wxString m_FontsFacesTable[2][2][2][2][7];
2b5f62a0 173#if !wxUSE_UNICODE
97494971 174 wxFontEncoding m_FontsEncTable[2][2][2][2][7];
2b5f62a0 175#endif
97494971
VS
176 // table of loaded fonts. 1st four indexes are 0 or 1, depending on on/off
177 // state of these flags (from left to right):
178 // [bold][italic][underlined][fixed_size]
179 // last index is font size : from 0 to 6 (remapped from html sizes 1 to 7)
180 // Note : this table covers all possible combinations of fonts, but not
181 // all of them are used, so many items in table are usually NULL.
182 int m_FontsSizes[7];
183 wxString m_FontFaceFixed, m_FontFaceNormal;
184 // html font sizes and faces of fixed and proportional fonts
185
2b5f62a0 186#if !wxUSE_UNICODE
97494971
VS
187 wxFontEncoding m_InputEnc, m_OutputEnc;
188 // I/O font encodings
189 wxEncodingConverter *m_EncConv;
2b5f62a0 190#endif
8ba2f3ec
VS
191
192 wxHtmlWordCell *m_lastWordCell;
6953da00 193
8ba2f3ec 194 DECLARE_NO_COPY_CLASS(wxHtmlWinParser)
5526e819
VS
195};
196
197
198
199
200
201
8ba2f3ec 202//-----------------------------------------------------------------------------
5526e819
VS
203// wxHtmlWinTagHandler
204// This is basicly wxHtmlTagHandler except
205// it is extended with protected member m_Parser pointing to
206// the wxHtmlWinParser object
8ba2f3ec 207//-----------------------------------------------------------------------------
5526e819 208
6acba9a7 209class WXDLLIMPEXP_HTML wxHtmlWinTagHandler : public wxHtmlTagHandler
5526e819
VS
210{
211 DECLARE_ABSTRACT_CLASS(wxHtmlWinTagHandler)
212
97494971 213public:
6fb99eb3 214 wxHtmlWinTagHandler() : wxHtmlTagHandler() {}
6e31e940 215
97494971 216 virtual void SetParser(wxHtmlParser *parser) {wxHtmlTagHandler::SetParser(parser); m_WParser = (wxHtmlWinParser*) parser;};
69941f05 217
97494971
VS
218protected:
219 wxHtmlWinParser *m_WParser; // same as m_Parser, but overcasted
22f3361e
VZ
220
221 DECLARE_NO_COPY_CLASS(wxHtmlWinTagHandler)
5526e819
VS
222};
223
224
225
226
227
228
8ba2f3ec 229//----------------------------------------------------------------------------
5526e819
VS
230// wxHtmlTagsModule
231// This is basic of dynamic tag handlers binding.
232// The class provides methods for filling parser's handlers
233// hash table.
234// (See documentation for details)
8ba2f3ec 235//----------------------------------------------------------------------------
5526e819 236
6acba9a7 237class WXDLLIMPEXP_HTML wxHtmlTagsModule : public wxModule
5526e819
VS
238{
239 DECLARE_DYNAMIC_CLASS(wxHtmlTagsModule)
240
97494971 241public:
6fb99eb3 242 wxHtmlTagsModule() : wxModule() {}
5526e819 243
97494971
VS
244 virtual bool OnInit();
245 virtual void OnExit();
5526e819 246
97494971 247 // This is called by wxHtmlWinParser.
8ba2f3ec
VS
248 // The method must simply call parser->AddTagHandler(new
249 // <handler_class_name>); for each handler
97494971 250 virtual void FillHandlersTable(wxHtmlWinParser * WXUNUSED(parser)) { }
5526e819
VS
251};
252
253
69941f05 254#endif
5526e819 255
69941f05 256#endif // _WX_WINPARS_H_