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