1. corrected some owner-drawn buttons bugs
[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
VS
6// Copyright: (c) 1999 Vaclav Slavik
7// Licence: wxWindows Licence
8/////////////////////////////////////////////////////////////////////////////
9
10
69941f05
VS
11#ifndef _WX_WINPARS_H_
12#define _WX_WINPARS_H_
5526e819
VS
13
14#ifdef __GNUG__
15#pragma interface
16#endif
17
18#include "wx/defs.h"
19#if wxUSE_HTML
20
69941f05
VS
21#include "wx/module.h"
22#include "wx/html/htmlpars.h"
23#include "wx/html/htmlcell.h"
5526e819
VS
24
25class wxHtmlWinParser;
26class wxHtmlWinTagHandler;
27class wxHtmlTagsModule;
28
29//--------------------------------------------------------------------------------
30// wxHtmlWinParser
31// This class is derived from wxHtmlParser and its mail goal
32// is to parse HTML input so that it can be displayed in
33// wxHtmlWindow. It uses special wxHtmlWinTagHandler.
34//--------------------------------------------------------------------------------
35
36class WXDLLEXPORT wxHtmlWinParser : public wxHtmlParser
37{
5526e819
VS
38 friend class wxHtmlWindow;
39
5526e819 40 public:
89966d5c 41 wxHtmlWinParser(wxWindow *wnd = NULL);
5526e819
VS
42
43 virtual void InitParser(const wxString& source);
44 virtual void DoneParser();
45 virtual wxObject* GetProduct();
46
edbd0635 47 virtual void SetDC(wxDC *dc, double pixel_scale = 1.0) {m_DC = dc; m_PixelScale = pixel_scale;}
5526e819
VS
48 // Set's the DC used for parsing. If SetDC() is not called,
49 // parsing won't proceed
50 wxDC *GetDC() {return m_DC;}
edbd0635 51 double GetPixelScale() {return m_PixelScale;}
5526e819
VS
52 int GetCharHeight() const {return m_CharHeight;}
53 int GetCharWidth() const {return m_CharWidth;}
54 // NOTE : these functions do _not_ return _actual_
55 // height/width. They return h/w of default font
56 // for this DC. If you want actual values, call
57 // GetDC() -> GetChar...()
58 wxWindow *GetWindow() {return m_Window;}
59 // returns associated wxWindow
60
89966d5c 61 void SetFonts(wxString normal_face, int normal_italic_mode, wxString fixed_face, int fixed_italic_mode, const int *sizes);
5526e819
VS
62 // sets fonts to be used when displaying HTML page.
63 // *_italic_mode can be either wxSLANT or wxITALIC
6e31e940 64
5526e819
VS
65 virtual wxList* GetTempData();
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) {m_FontSize = 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
96 int GetAlign() const {return m_Align;}
97 void SetAlign(int a) {m_Align = a;}
98 const wxColour& GetLinkColor() const {return m_LinkColor;}
99 void SetLinkColor(const wxColour& clr) {m_LinkColor = clr;}
100 const wxColour& GetActualColor() const {return m_ActualColor;}
101 void SetActualColor(const wxColour& clr) {m_ActualColor = clr;}
102 const wxString& GetLink() const {return m_Link;}
103 void SetLink(const wxString& link) {m_Link = link; m_UseLink = link.Length() > 0;}
104
105 virtual wxFont* CreateCurrentFont();
106 // creates font depending on m_Font* members.
107 // (note : it calls wxHtmlWindow's CreateCurrentFont...)
108
109 protected:
110 virtual void AddText(const char *txt);
111
112 private:
113 bool m_tmpLastWasSpace;
114 // temporary variable used by AddText
69941f05
VS
115 wxWindow *m_Window;
116 // window we're parsing for
edbd0635 117 double m_PixelScale;
69941f05
VS
118 wxDC *m_DC;
119 // Device Context we're parsing for
120 static wxList m_Modules;
121 // list of tags modules (see wxHtmlTagsModule for details)
122 // This list is used to initialize m_Handlers member.
123
124 wxHtmlContainerCell *m_Container;
125 // actual container. See Open/CloseContainer for details.
126
127 int m_FontBold, m_FontItalic, m_FontUnderlined, m_FontFixed; // this is not TRUE,FALSE but 1,0, we need it for indexing
128 int m_FontSize; /* -2 to +4, 0 is default */
129 wxColour m_LinkColor;
130 wxColour m_ActualColor;
131 // basic font parameters.
132 wxString m_Link;
133 // actual hypertext link or empty string
134 bool m_UseLink;
135 // TRUE if m_Link is not empty
136 long m_CharHeight, m_CharWidth;
137 // average height of normal-sized text
138 int m_Align;
139 // actual alignment
140
141 wxFont *m_FontsTable[2][2][2][2][7];
142 // table of loaded fonts. 1st four indexes are 0 or 1, depending on on/off
143 // state of these flags (from left to right):
144 // [bold][italic][underlined][fixed_size]
145 // last index is font size : from 0 to 7 (remapped from html sizes -2 to +4)
146 // Note : this table covers all possible combinations of fonts, but not
147 // all of them are used, so many items in table are usually NULL.
148 int m_FontsSizes[7];
149 wxString m_FontFaceFixed, m_FontFaceNormal;
150 int m_ItalicModeFixed, m_ItalicModeNormal;
151 // html font sizes and faces of fixed and proportional fonts
5526e819
VS
152};
153
154
155
156
157
158
159//--------------------------------------------------------------------------------
160// wxHtmlWinTagHandler
161// This is basicly wxHtmlTagHandler except
162// it is extended with protected member m_Parser pointing to
163// the wxHtmlWinParser object
164//--------------------------------------------------------------------------------
165
166class WXDLLEXPORT wxHtmlWinTagHandler : public wxHtmlTagHandler
167{
168 DECLARE_ABSTRACT_CLASS(wxHtmlWinTagHandler)
169
5526e819
VS
170 public:
171 wxHtmlWinTagHandler() : wxHtmlTagHandler() {};
6e31e940 172
5526e819 173 virtual void SetParser(wxHtmlParser *parser) {wxHtmlTagHandler::SetParser(parser); m_WParser = (wxHtmlWinParser*) parser;};
69941f05
VS
174
175 protected:
176 wxHtmlWinParser *m_WParser;
177 // same as m_Parser, but overcasted
5526e819
VS
178};
179
180
181
182
183
184
185//--------------------------------------------------------------------------------
186// wxHtmlTagsModule
187// This is basic of dynamic tag handlers binding.
188// The class provides methods for filling parser's handlers
189// hash table.
190// (See documentation for details)
191//--------------------------------------------------------------------------------
192
193class WXDLLEXPORT wxHtmlTagsModule : public wxModule
194{
195 DECLARE_DYNAMIC_CLASS(wxHtmlTagsModule)
196
197 public:
198 wxHtmlTagsModule() : wxModule() {};
199
200 virtual bool OnInit();
201 virtual void OnExit();
202
6e31e940 203 virtual void FillHandlersTable(wxHtmlWinParser * WXUNUSED(parser)) { }
5526e819
VS
204 // This is called by wxHtmlWinParser.
205 // The method must simply call parser->AddTagHandler(new <handler_class_name>);
206 // for each handler
207
208};
209
210
69941f05 211#endif
5526e819 212
69941f05 213#endif // _WX_WINPARS_H_
5526e819 214
5526e819
VS
215
216
217