]> git.saurik.com Git - wxWidgets.git/blame - include/wx/html/winpars.h
avoid a bug in Carbon headers
[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 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{
5526e819
VS
41 friend class wxHtmlWindow;
42
97494971 43public:
04db5c3f 44 wxHtmlWinParser(wxHtmlWindow *wnd = NULL);
97494971
VS
45 ~wxHtmlWinParser();
46
47 virtual void InitParser(const wxString& source);
48 virtual void DoneParser();
49 virtual wxObject* GetProduct();
50
6cc4e6b8 51 virtual wxFSFile *OpenURL(wxHtmlURLType type, const wxString& url) const;
04db5c3f 52
97494971
VS
53 // Set's the DC used for parsing. If SetDC() is not called,
54 // parsing won't proceed
19193a2c 55 virtual void SetDC(wxDC *dc, double pixel_scale = 1.0)
97494971
VS
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...()
19193a2c 67
97494971 68 // returns associated wxWindow
04db5c3f 69 wxHtmlWindow *GetWindow() {return m_Window;}
97494971 70
4eecf115
VS
71 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
72 void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes = NULL);
19193a2c 73
97494971
VS
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
2b5f62a0 120#if !wxUSE_UNICODE
97494971
VS
121 void SetInputEncoding(wxFontEncoding enc);
122 wxFontEncoding GetInputEncoding() const { return m_InputEnc; }
123 wxFontEncoding GetOutputEncoding() const { return m_OutputEnc; }
124 wxEncodingConverter *GetEncodingConverter() const { return m_EncConv; }
2b5f62a0 125#endif
97494971
VS
126
127 // creates font depending on m_Font* members.
128 virtual wxFont* CreateCurrentFont();
129
130protected:
6c62a62b 131 virtual void AddText(const wxChar* txt);
97494971
VS
132
133private:
134 bool m_tmpLastWasSpace;
6c62a62b
VS
135 wxChar *m_tmpStrBuf;
136 size_t m_tmpStrBufSize;
137 // temporary variables used by AddText
04db5c3f 138 wxHtmlWindow *m_Window;
97494971
VS
139 // window we're parsing for
140 double m_PixelScale;
141 wxDC *m_DC;
142 // Device Context we're parsing for
143 static wxList m_Modules;
144 // list of tags modules (see wxHtmlTagsModule for details)
145 // This list is used to initialize m_Handlers member.
146
147 wxHtmlContainerCell *m_Container;
ace0fab4 148 // current container. See Open/CloseContainer for details.
97494971
VS
149
150 int m_FontBold, m_FontItalic, m_FontUnderlined, m_FontFixed; // this is not TRUE,FALSE but 1,0, we need it for indexing
151 int m_FontSize; /* -2 to +4, 0 is default */
152 wxColour m_LinkColor;
153 wxColour m_ActualColor;
154 // basic font parameters.
155 wxHtmlLinkInfo m_Link;
156 // actual hypertext link or empty string
157 bool m_UseLink;
158 // TRUE if m_Link is not empty
159 long m_CharHeight, m_CharWidth;
160 // average height of normal-sized text
161 int m_Align;
162 // actual alignment
163
164 wxFont* m_FontsTable[2][2][2][2][7];
165 wxString m_FontsFacesTable[2][2][2][2][7];
2b5f62a0 166#if !wxUSE_UNICODE
97494971 167 wxFontEncoding m_FontsEncTable[2][2][2][2][7];
2b5f62a0 168#endif
97494971
VS
169 // table of loaded fonts. 1st four indexes are 0 or 1, depending on on/off
170 // state of these flags (from left to right):
171 // [bold][italic][underlined][fixed_size]
172 // last index is font size : from 0 to 6 (remapped from html sizes 1 to 7)
173 // Note : this table covers all possible combinations of fonts, but not
174 // all of them are used, so many items in table are usually NULL.
175 int m_FontsSizes[7];
176 wxString m_FontFaceFixed, m_FontFaceNormal;
177 // html font sizes and faces of fixed and proportional fonts
178
2b5f62a0 179#if !wxUSE_UNICODE
97494971
VS
180 wxFontEncoding m_InputEnc, m_OutputEnc;
181 // I/O font encodings
182 wxEncodingConverter *m_EncConv;
2b5f62a0 183#endif
8ba2f3ec
VS
184
185 wxHtmlWordCell *m_lastWordCell;
186
187 DECLARE_NO_COPY_CLASS(wxHtmlWinParser)
5526e819
VS
188};
189
190
191
192
193
194
8ba2f3ec 195//-----------------------------------------------------------------------------
5526e819
VS
196// wxHtmlWinTagHandler
197// This is basicly wxHtmlTagHandler except
198// it is extended with protected member m_Parser pointing to
199// the wxHtmlWinParser object
8ba2f3ec 200//-----------------------------------------------------------------------------
5526e819 201
6acba9a7 202class WXDLLIMPEXP_HTML wxHtmlWinTagHandler : public wxHtmlTagHandler
5526e819
VS
203{
204 DECLARE_ABSTRACT_CLASS(wxHtmlWinTagHandler)
205
97494971
VS
206public:
207 wxHtmlWinTagHandler() : wxHtmlTagHandler() {};
6e31e940 208
97494971 209 virtual void SetParser(wxHtmlParser *parser) {wxHtmlTagHandler::SetParser(parser); m_WParser = (wxHtmlWinParser*) parser;};
69941f05 210
97494971
VS
211protected:
212 wxHtmlWinParser *m_WParser; // same as m_Parser, but overcasted
22f3361e
VZ
213
214 DECLARE_NO_COPY_CLASS(wxHtmlWinTagHandler)
5526e819
VS
215};
216
217
218
219
220
221
8ba2f3ec 222//----------------------------------------------------------------------------
5526e819
VS
223// wxHtmlTagsModule
224// This is basic of dynamic tag handlers binding.
225// The class provides methods for filling parser's handlers
226// hash table.
227// (See documentation for details)
8ba2f3ec 228//----------------------------------------------------------------------------
5526e819 229
6acba9a7 230class WXDLLIMPEXP_HTML wxHtmlTagsModule : public wxModule
5526e819
VS
231{
232 DECLARE_DYNAMIC_CLASS(wxHtmlTagsModule)
233
97494971
VS
234public:
235 wxHtmlTagsModule() : wxModule() {};
5526e819 236
97494971
VS
237 virtual bool OnInit();
238 virtual void OnExit();
5526e819 239
97494971 240 // This is called by wxHtmlWinParser.
8ba2f3ec
VS
241 // The method must simply call parser->AddTagHandler(new
242 // <handler_class_name>); for each handler
97494971 243 virtual void FillHandlersTable(wxHtmlWinParser * WXUNUSED(parser)) { }
5526e819
VS
244};
245
246
69941f05 247#endif
5526e819 248
69941f05 249#endif // _WX_WINPARS_H_