]> git.saurik.com Git - wxWidgets.git/blame - include/wx/html/winpars.h
Added wxPGChoices::Copy(), tweaked related documentation
[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
69941f05
VS
10#ifndef _WX_WINPARS_H_
11#define _WX_WINPARS_H_
5526e819 12
5526e819
VS
13#include "wx/defs.h"
14#if wxUSE_HTML
15
69941f05 16#include "wx/module.h"
b250d384 17#include "wx/font.h"
69941f05
VS
18#include "wx/html/htmlpars.h"
19#include "wx/html/htmlcell.h"
b250d384 20#include "wx/encconv.h"
5526e819 21
b5dbe15d
VS
22class WXDLLIMPEXP_FWD_HTML wxHtmlWindow;
23class WXDLLIMPEXP_FWD_HTML wxHtmlWindowInterface;
24class WXDLLIMPEXP_FWD_HTML wxHtmlWinParser;
25class WXDLLIMPEXP_FWD_HTML wxHtmlWinTagHandler;
26class WXDLLIMPEXP_FWD_HTML wxHtmlTagsModule;
5526e819 27
bc55e31b 28
5526e819
VS
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
6acba9a7 36class WXDLLIMPEXP_HTML wxHtmlWinParser : public wxHtmlParser
5526e819 37{
4f44ea36 38 DECLARE_ABSTRACT_CLASS(wxHtmlWinParser)
5526e819
VS
39 friend class wxHtmlWindow;
40
97494971 41public:
bc55e31b
VS
42 wxHtmlWinParser(wxHtmlWindowInterface *wndIface = NULL);
43
d3c7fc99 44 virtual ~wxHtmlWinParser();
97494971
VS
45
46 virtual void InitParser(const wxString& source);
47 virtual void DoneParser();
48 virtual wxObject* GetProduct();
49
6cc4e6b8 50 virtual wxFSFile *OpenURL(wxHtmlURLType type, const wxString& url) const;
04db5c3f 51
97494971
VS
52 // Set's the DC used for parsing. If SetDC() is not called,
53 // parsing won't proceed
19193a2c 54 virtual void SetDC(wxDC *dc, double pixel_scale = 1.0)
97494971
VS
55 { m_DC = dc; m_PixelScale = pixel_scale; }
56
57 wxDC *GetDC() {return m_DC;}
58 double GetPixelScale() {return m_PixelScale;}
59 int GetCharHeight() const {return m_CharHeight;}
60 int GetCharWidth() const {return m_CharWidth;}
61
62 // NOTE : these functions do _not_ return _actual_
63 // height/width. They return h/w of default font
64 // for this DC. If you want actual values, call
65 // GetDC()->GetChar...()
19193a2c 66
968d6f46 67 // returns interface to the rendering window
bc55e31b
VS
68 wxHtmlWindowInterface *GetWindowInterface() {return m_windowInterface;}
69#if WXWIN_COMPATIBILITY_2_6
968d6f46 70 // deprecated, use GetWindowInterface()->GetHTMLWindow() instead
bc55e31b
VS
71 wxDEPRECATED( wxHtmlWindow *GetWindow() );
72#endif
97494971 73
4eecf115 74 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
fbfb8bcc 75 void SetFonts(const wxString& normal_face, const wxString& fixed_face, const int *sizes = NULL);
19193a2c 76
10e5c7ea
VS
77 // Sets font sizes to be relative to the given size or the system
78 // default size; use either specified or default font
79 void SetStandardFonts(int size = -1,
80 const wxString& normal_face = wxEmptyString,
81 const wxString& fixed_face = wxEmptyString);
6953da00 82
97494971
VS
83 // Adds tags module. see wxHtmlTagsModule for details.
84 static void AddModule(wxHtmlTagsModule *module);
85
86 static void RemoveModule(wxHtmlTagsModule *module);
87
88 // parsing-related methods. These methods are called by tag handlers:
89
90 // Returns pointer to actual container. Common use in tag handler is :
91 // m_WParser->GetContainer()->InsertCell(new ...);
92 wxHtmlContainerCell *GetContainer() const {return m_Container;}
93
94 // opens new container. This container is sub-container of opened
95 // container. Sets GetContainer to newly created container
96 // and returns it.
97 wxHtmlContainerCell *OpenContainer();
98
99 // works like OpenContainer except that new container is not created
100 // but c is used. You can use this to directly set actual container
101 wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
102
103 // closes the container and sets actual Container to upper-level
104 // container
105 wxHtmlContainerCell *CloseContainer();
106
107 int GetFontSize() const {return m_FontSize;}
108 void SetFontSize(int s);
109 int GetFontBold() const {return m_FontBold;}
110 void SetFontBold(int x) {m_FontBold = x;}
111 int GetFontItalic() const {return m_FontItalic;}
112 void SetFontItalic(int x) {m_FontItalic = x;}
113 int GetFontUnderlined() const {return m_FontUnderlined;}
114 void SetFontUnderlined(int x) {m_FontUnderlined = x;}
115 int GetFontFixed() const {return m_FontFixed;}
116 void SetFontFixed(int x) {m_FontFixed = x;}
117 wxString GetFontFace() const {return GetFontFixed() ? m_FontFaceFixed : m_FontFaceNormal;}
118 void SetFontFace(const wxString& face);
119
120 int GetAlign() const {return m_Align;}
121 void SetAlign(int a) {m_Align = a;}
3c115835
VS
122
123 wxHtmlScriptMode GetScriptMode() const { return m_ScriptMode; }
124 void SetScriptMode(wxHtmlScriptMode mode) { m_ScriptMode = mode; }
125 long GetScriptBaseline() const { return m_ScriptBaseline; }
126 void SetScriptBaseline(long base) { m_ScriptBaseline = base; }
127
97494971
VS
128 const wxColour& GetLinkColor() const { return m_LinkColor; }
129 void SetLinkColor(const wxColour& clr) { m_LinkColor = clr; }
130 const wxColour& GetActualColor() const { return m_ActualColor; }
131 void SetActualColor(const wxColour& clr) { m_ActualColor = clr ;}
132 const wxHtmlLinkInfo& GetLink() const { return m_Link; }
133 void SetLink(const wxHtmlLinkInfo& link);
134
3c115835
VS
135 // applies current parser state (link, sub/supscript, ...) to given cell
136 void ApplyStateToCell(wxHtmlCell *cell);
137
2b5f62a0 138#if !wxUSE_UNICODE
97494971
VS
139 void SetInputEncoding(wxFontEncoding enc);
140 wxFontEncoding GetInputEncoding() const { return m_InputEnc; }
141 wxFontEncoding GetOutputEncoding() const { return m_OutputEnc; }
142 wxEncodingConverter *GetEncodingConverter() const { return m_EncConv; }
2b5f62a0 143#endif
97494971
VS
144
145 // creates font depending on m_Font* members.
146 virtual wxFont* CreateCurrentFont();
147
6a603a10
VS
148 enum WhitespaceMode
149 {
150 Whitespace_Normal, // normal mode, collapse whitespace
151 Whitespace_Pre // inside <pre>, keep whitespace as-is
152 };
153
154 // change the current whitespace handling mode
155 void SetWhitespaceMode(WhitespaceMode mode) { m_whitespaceMode = mode; }
156 WhitespaceMode GetWhitespaceMode() const { return m_whitespaceMode; }
157
97494971 158protected:
5bce3e6f 159 virtual void AddText(const wxString& txt);
97494971
VS
160
161private:
6a603a10
VS
162 void FlushWordBuf(wxChar *temp, int& len);
163 void AddWord(wxHtmlWordCell *word);
164 void AddWord(const wxString& word)
165 { AddWord(new wxHtmlWordCell(word, *(GetDC()))); }
166 void AddPreBlock(const wxString& text);
97eac136 167
97494971 168 bool m_tmpLastWasSpace;
6c62a62b
VS
169 wxChar *m_tmpStrBuf;
170 size_t m_tmpStrBufSize;
171 // temporary variables used by AddText
bc55e31b 172 wxHtmlWindowInterface *m_windowInterface;
97494971
VS
173 // window we're parsing for
174 double m_PixelScale;
175 wxDC *m_DC;
176 // Device Context we're parsing for
177 static wxList m_Modules;
178 // list of tags modules (see wxHtmlTagsModule for details)
179 // This list is used to initialize m_Handlers member.
180
181 wxHtmlContainerCell *m_Container;
ace0fab4 182 // current container. See Open/CloseContainer for details.
97494971 183
6953da00 184 int m_FontBold, m_FontItalic, m_FontUnderlined, m_FontFixed; // this is not true,false but 1,0, we need it for indexing
97494971
VS
185 int m_FontSize; /* -2 to +4, 0 is default */
186 wxColour m_LinkColor;
187 wxColour m_ActualColor;
188 // basic font parameters.
189 wxHtmlLinkInfo m_Link;
190 // actual hypertext link or empty string
191 bool m_UseLink;
6953da00 192 // true if m_Link is not empty
97494971
VS
193 long m_CharHeight, m_CharWidth;
194 // average height of normal-sized text
195 int m_Align;
196 // actual alignment
3c115835
VS
197 wxHtmlScriptMode m_ScriptMode;
198 // current script mode (sub/sup/normal)
199 long m_ScriptBaseline;
200 // current sub/supscript base
97494971
VS
201
202 wxFont* m_FontsTable[2][2][2][2][7];
203 wxString m_FontsFacesTable[2][2][2][2][7];
2b5f62a0 204#if !wxUSE_UNICODE
97494971 205 wxFontEncoding m_FontsEncTable[2][2][2][2][7];
2b5f62a0 206#endif
97494971
VS
207 // table of loaded fonts. 1st four indexes are 0 or 1, depending on on/off
208 // state of these flags (from left to right):
209 // [bold][italic][underlined][fixed_size]
210 // last index is font size : from 0 to 6 (remapped from html sizes 1 to 7)
211 // Note : this table covers all possible combinations of fonts, but not
212 // all of them are used, so many items in table are usually NULL.
213 int m_FontsSizes[7];
214 wxString m_FontFaceFixed, m_FontFaceNormal;
215 // html font sizes and faces of fixed and proportional fonts
216
2b5f62a0 217#if !wxUSE_UNICODE
c7820964 218 wxChar m_nbsp;
97494971
VS
219 wxFontEncoding m_InputEnc, m_OutputEnc;
220 // I/O font encodings
221 wxEncodingConverter *m_EncConv;
2b5f62a0 222#endif
8ba2f3ec 223
6a603a10
VS
224 // current whitespace handling mode
225 WhitespaceMode m_whitespaceMode;
226
8ba2f3ec 227 wxHtmlWordCell *m_lastWordCell;
6953da00 228
6a603a10
VS
229 // current position on line, in num. of characters; used to properly
230 // expand TABs; only updated while inside <pre>
231 int m_posColumn;
232
8ba2f3ec 233 DECLARE_NO_COPY_CLASS(wxHtmlWinParser)
5526e819
VS
234};
235
236
237
238
239
240
8ba2f3ec 241//-----------------------------------------------------------------------------
5526e819
VS
242// wxHtmlWinTagHandler
243// This is basicly wxHtmlTagHandler except
244// it is extended with protected member m_Parser pointing to
245// the wxHtmlWinParser object
8ba2f3ec 246//-----------------------------------------------------------------------------
5526e819 247
6acba9a7 248class WXDLLIMPEXP_HTML wxHtmlWinTagHandler : public wxHtmlTagHandler
5526e819
VS
249{
250 DECLARE_ABSTRACT_CLASS(wxHtmlWinTagHandler)
251
97494971 252public:
6fb99eb3 253 wxHtmlWinTagHandler() : wxHtmlTagHandler() {}
6e31e940 254
47b378bd 255 virtual void SetParser(wxHtmlParser *parser) {wxHtmlTagHandler::SetParser(parser); m_WParser = (wxHtmlWinParser*) parser;}
69941f05 256
97494971
VS
257protected:
258 wxHtmlWinParser *m_WParser; // same as m_Parser, but overcasted
22f3361e
VZ
259
260 DECLARE_NO_COPY_CLASS(wxHtmlWinTagHandler)
5526e819
VS
261};
262
263
264
265
266
267
8ba2f3ec 268//----------------------------------------------------------------------------
5526e819
VS
269// wxHtmlTagsModule
270// This is basic of dynamic tag handlers binding.
271// The class provides methods for filling parser's handlers
272// hash table.
273// (See documentation for details)
8ba2f3ec 274//----------------------------------------------------------------------------
5526e819 275
6acba9a7 276class WXDLLIMPEXP_HTML wxHtmlTagsModule : public wxModule
5526e819
VS
277{
278 DECLARE_DYNAMIC_CLASS(wxHtmlTagsModule)
279
97494971 280public:
6fb99eb3 281 wxHtmlTagsModule() : wxModule() {}
5526e819 282
97494971
VS
283 virtual bool OnInit();
284 virtual void OnExit();
5526e819 285
97494971 286 // This is called by wxHtmlWinParser.
8ba2f3ec
VS
287 // The method must simply call parser->AddTagHandler(new
288 // <handler_class_name>); for each handler
97494971 289 virtual void FillHandlersTable(wxHtmlWinParser * WXUNUSED(parser)) { }
5526e819
VS
290};
291
292
69941f05 293#endif
5526e819 294
69941f05 295#endif // _WX_WINPARS_H_