1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtmlWinParser class (parser to be used with wxHtmlWindow)
4 // Author: Vaclav Slavik
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_WINPARS_H_
11 #define _WX_WINPARS_H_
16 #include "wx/module.h"
18 #include "wx/html/htmlpars.h"
19 #include "wx/html/htmlcell.h"
20 #include "wx/encconv.h"
22 class WXDLLIMPEXP_HTML wxHtmlWindow
;
23 class WXDLLIMPEXP_HTML wxHtmlWinParser
;
24 class WXDLLIMPEXP_HTML wxHtmlWinTagHandler
;
25 class WXDLLIMPEXP_HTML wxHtmlTagsModule
;
27 //--------------------------------------------------------------------------------
29 // This class is derived from wxHtmlParser and its mail goal
30 // is to parse HTML input so that it can be displayed in
31 // wxHtmlWindow. It uses special wxHtmlWinTagHandler.
32 //--------------------------------------------------------------------------------
34 class WXDLLIMPEXP_HTML wxHtmlWinParser
: public wxHtmlParser
36 DECLARE_ABSTRACT_CLASS(wxHtmlWinParser
)
37 friend class wxHtmlWindow
;
40 wxHtmlWinParser(wxHtmlWindow
*wnd
= NULL
);
43 virtual void InitParser(const wxString
& source
);
44 virtual void DoneParser();
45 virtual wxObject
* GetProduct();
47 virtual wxFSFile
*OpenURL(wxHtmlURLType type
, const wxString
& url
) const;
49 // Set's the DC used for parsing. If SetDC() is not called,
50 // parsing won't proceed
51 virtual void SetDC(wxDC
*dc
, double pixel_scale
= 1.0)
52 { m_DC
= dc
; m_PixelScale
= pixel_scale
; }
54 wxDC
*GetDC() {return m_DC
;}
55 double GetPixelScale() {return m_PixelScale
;}
56 int GetCharHeight() const {return m_CharHeight
;}
57 int GetCharWidth() const {return m_CharWidth
;}
59 // NOTE : these functions do _not_ return _actual_
60 // height/width. They return h/w of default font
61 // for this DC. If you want actual values, call
62 // GetDC()->GetChar...()
64 // returns associated wxWindow
65 wxHtmlWindow
*GetWindow() {return m_Window
;}
67 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
68 void SetFonts(const wxString
& normal_face
, const wxString
& fixed_face
, const int *sizes
= NULL
);
70 // Sets font sizes to be relative to the given size or the system
71 // default size; use either specified or default font
72 void SetStandardFonts(int size
= -1,
73 const wxString
& normal_face
= wxEmptyString
,
74 const wxString
& fixed_face
= wxEmptyString
);
76 // Adds tags module. see wxHtmlTagsModule for details.
77 static void AddModule(wxHtmlTagsModule
*module);
79 static void RemoveModule(wxHtmlTagsModule
*module);
81 // parsing-related methods. These methods are called by tag handlers:
83 // Returns pointer to actual container. Common use in tag handler is :
84 // m_WParser->GetContainer()->InsertCell(new ...);
85 wxHtmlContainerCell
*GetContainer() const {return m_Container
;}
87 // opens new container. This container is sub-container of opened
88 // container. Sets GetContainer to newly created container
90 wxHtmlContainerCell
*OpenContainer();
92 // works like OpenContainer except that new container is not created
93 // but c is used. You can use this to directly set actual container
94 wxHtmlContainerCell
*SetContainer(wxHtmlContainerCell
*c
);
96 // closes the container and sets actual Container to upper-level
98 wxHtmlContainerCell
*CloseContainer();
100 int GetFontSize() const {return m_FontSize
;}
101 void SetFontSize(int s
);
102 int GetFontBold() const {return m_FontBold
;}
103 void SetFontBold(int x
) {m_FontBold
= x
;}
104 int GetFontItalic() const {return m_FontItalic
;}
105 void SetFontItalic(int x
) {m_FontItalic
= x
;}
106 int GetFontUnderlined() const {return m_FontUnderlined
;}
107 void SetFontUnderlined(int x
) {m_FontUnderlined
= x
;}
108 int GetFontFixed() const {return m_FontFixed
;}
109 void SetFontFixed(int x
) {m_FontFixed
= x
;}
110 wxString
GetFontFace() const {return GetFontFixed() ? m_FontFaceFixed
: m_FontFaceNormal
;}
111 void SetFontFace(const wxString
& face
);
113 int GetAlign() const {return m_Align
;}
114 void SetAlign(int a
) {m_Align
= a
;}
115 const wxColour
& GetLinkColor() const { return m_LinkColor
; }
116 void SetLinkColor(const wxColour
& clr
) { m_LinkColor
= clr
; }
117 const wxColour
& GetActualColor() const { return m_ActualColor
; }
118 void SetActualColor(const wxColour
& clr
) { m_ActualColor
= clr
;}
119 const wxHtmlLinkInfo
& GetLink() const { return m_Link
; }
120 void SetLink(const wxHtmlLinkInfo
& link
);
123 void SetInputEncoding(wxFontEncoding enc
);
124 wxFontEncoding
GetInputEncoding() const { return m_InputEnc
; }
125 wxFontEncoding
GetOutputEncoding() const { return m_OutputEnc
; }
126 wxEncodingConverter
*GetEncodingConverter() const { return m_EncConv
; }
129 // creates font depending on m_Font* members.
130 virtual wxFont
* CreateCurrentFont();
133 virtual void AddText(const wxChar
* txt
);
136 bool m_tmpLastWasSpace
;
138 size_t m_tmpStrBufSize
;
139 // temporary variables used by AddText
140 wxHtmlWindow
*m_Window
;
141 // window we're parsing for
144 // Device Context we're parsing for
145 static wxList m_Modules
;
146 // list of tags modules (see wxHtmlTagsModule for details)
147 // This list is used to initialize m_Handlers member.
149 wxHtmlContainerCell
*m_Container
;
150 // current container. See Open/CloseContainer for details.
152 int m_FontBold
, m_FontItalic
, m_FontUnderlined
, m_FontFixed
; // this is not true,false but 1,0, we need it for indexing
153 int m_FontSize
; /* -2 to +4, 0 is default */
154 wxColour m_LinkColor
;
155 wxColour m_ActualColor
;
156 // basic font parameters.
157 wxHtmlLinkInfo m_Link
;
158 // actual hypertext link or empty string
160 // true if m_Link is not empty
161 long m_CharHeight
, m_CharWidth
;
162 // average height of normal-sized text
166 wxFont
* m_FontsTable
[2][2][2][2][7];
167 wxString m_FontsFacesTable
[2][2][2][2][7];
169 wxFontEncoding m_FontsEncTable
[2][2][2][2][7];
171 // table of loaded fonts. 1st four indexes are 0 or 1, depending on on/off
172 // state of these flags (from left to right):
173 // [bold][italic][underlined][fixed_size]
174 // last index is font size : from 0 to 6 (remapped from html sizes 1 to 7)
175 // Note : this table covers all possible combinations of fonts, but not
176 // all of them are used, so many items in table are usually NULL.
178 wxString m_FontFaceFixed
, m_FontFaceNormal
;
179 // html font sizes and faces of fixed and proportional fonts
182 wxFontEncoding m_InputEnc
, m_OutputEnc
;
183 // I/O font encodings
184 wxEncodingConverter
*m_EncConv
;
187 wxHtmlWordCell
*m_lastWordCell
;
189 DECLARE_NO_COPY_CLASS(wxHtmlWinParser
)
197 //-----------------------------------------------------------------------------
198 // wxHtmlWinTagHandler
199 // This is basicly wxHtmlTagHandler except
200 // it is extended with protected member m_Parser pointing to
201 // the wxHtmlWinParser object
202 //-----------------------------------------------------------------------------
204 class WXDLLIMPEXP_HTML wxHtmlWinTagHandler
: public wxHtmlTagHandler
206 DECLARE_ABSTRACT_CLASS(wxHtmlWinTagHandler
)
209 wxHtmlWinTagHandler() : wxHtmlTagHandler() {}
211 virtual void SetParser(wxHtmlParser
*parser
) {wxHtmlTagHandler::SetParser(parser
); m_WParser
= (wxHtmlWinParser
*) parser
;};
214 wxHtmlWinParser
*m_WParser
; // same as m_Parser, but overcasted
216 DECLARE_NO_COPY_CLASS(wxHtmlWinTagHandler
)
224 //----------------------------------------------------------------------------
226 // This is basic of dynamic tag handlers binding.
227 // The class provides methods for filling parser's handlers
229 // (See documentation for details)
230 //----------------------------------------------------------------------------
232 class WXDLLIMPEXP_HTML wxHtmlTagsModule
: public wxModule
234 DECLARE_DYNAMIC_CLASS(wxHtmlTagsModule
)
237 wxHtmlTagsModule() : wxModule() {}
239 virtual bool OnInit();
240 virtual void OnExit();
242 // This is called by wxHtmlWinParser.
243 // The method must simply call parser->AddTagHandler(new
244 // <handler_class_name>); for each handler
245 virtual void FillHandlersTable(wxHtmlWinParser
* WXUNUSED(parser
)) { }
251 #endif // _WX_WINPARS_H_