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 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_WINPARS_H_
12 #define _WX_WINPARS_H_
14 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
15 #pragma interface "winpars.h"
21 #include "wx/module.h"
23 #include "wx/html/htmlpars.h"
24 #include "wx/html/htmlcell.h"
25 #include "wx/encconv.h"
27 class WXDLLIMPEXP_HTML wxHtmlWindow
;
28 class WXDLLIMPEXP_HTML wxHtmlWinParser
;
29 class WXDLLIMPEXP_HTML wxHtmlWinTagHandler
;
30 class WXDLLIMPEXP_HTML wxHtmlTagsModule
;
32 //--------------------------------------------------------------------------------
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 //--------------------------------------------------------------------------------
39 class WXDLLIMPEXP_HTML wxHtmlWinParser
: public wxHtmlParser
41 DECLARE_ABSTRACT_CLASS(wxHtmlWinParser
)
42 friend class wxHtmlWindow
;
45 wxHtmlWinParser(wxHtmlWindow
*wnd
= NULL
);
48 virtual void InitParser(const wxString
& source
);
49 virtual void DoneParser();
50 virtual wxObject
* GetProduct();
52 virtual wxFSFile
*OpenURL(wxHtmlURLType type
, const wxString
& url
) const;
54 // Set's the DC used for parsing. If SetDC() is not called,
55 // parsing won't proceed
56 virtual void SetDC(wxDC
*dc
, double pixel_scale
= 1.0)
57 { m_DC
= dc
; m_PixelScale
= pixel_scale
; }
59 wxDC
*GetDC() {return m_DC
;}
60 double GetPixelScale() {return m_PixelScale
;}
61 int GetCharHeight() const {return m_CharHeight
;}
62 int GetCharWidth() const {return m_CharWidth
;}
64 // NOTE : these functions do _not_ return _actual_
65 // height/width. They return h/w of default font
66 // for this DC. If you want actual values, call
67 // GetDC()->GetChar...()
69 // returns associated wxWindow
70 wxHtmlWindow
*GetWindow() {return m_Window
;}
72 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
73 void SetFonts(wxString normal_face
, wxString fixed_face
, const int *sizes
= NULL
);
75 // Sets font sizes to be relative to the given size or the system default size
76 void NormalizeFontSizes(int size
=-1);
78 // Adds tags module. see wxHtmlTagsModule for details.
79 static void AddModule(wxHtmlTagsModule
*module);
81 static void RemoveModule(wxHtmlTagsModule
*module);
83 // parsing-related methods. These methods are called by tag handlers:
85 // Returns pointer to actual container. Common use in tag handler is :
86 // m_WParser->GetContainer()->InsertCell(new ...);
87 wxHtmlContainerCell
*GetContainer() const {return m_Container
;}
89 // opens new container. This container is sub-container of opened
90 // container. Sets GetContainer to newly created container
92 wxHtmlContainerCell
*OpenContainer();
94 // works like OpenContainer except that new container is not created
95 // but c is used. You can use this to directly set actual container
96 wxHtmlContainerCell
*SetContainer(wxHtmlContainerCell
*c
);
98 // closes the container and sets actual Container to upper-level
100 wxHtmlContainerCell
*CloseContainer();
102 int GetFontSize() const {return m_FontSize
;}
103 void SetFontSize(int s
);
104 int GetFontBold() const {return m_FontBold
;}
105 void SetFontBold(int x
) {m_FontBold
= x
;}
106 int GetFontItalic() const {return m_FontItalic
;}
107 void SetFontItalic(int x
) {m_FontItalic
= x
;}
108 int GetFontUnderlined() const {return m_FontUnderlined
;}
109 void SetFontUnderlined(int x
) {m_FontUnderlined
= x
;}
110 int GetFontFixed() const {return m_FontFixed
;}
111 void SetFontFixed(int x
) {m_FontFixed
= x
;}
112 wxString
GetFontFace() const {return GetFontFixed() ? m_FontFaceFixed
: m_FontFaceNormal
;}
113 void SetFontFace(const wxString
& face
);
115 int GetAlign() const {return m_Align
;}
116 void SetAlign(int a
) {m_Align
= a
;}
117 const wxColour
& GetLinkColor() const { return m_LinkColor
; }
118 void SetLinkColor(const wxColour
& clr
) { m_LinkColor
= clr
; }
119 const wxColour
& GetActualColor() const { return m_ActualColor
; }
120 void SetActualColor(const wxColour
& clr
) { m_ActualColor
= clr
;}
121 const wxHtmlLinkInfo
& GetLink() const { return m_Link
; }
122 void SetLink(const wxHtmlLinkInfo
& link
);
125 void SetInputEncoding(wxFontEncoding enc
);
126 wxFontEncoding
GetInputEncoding() const { return m_InputEnc
; }
127 wxFontEncoding
GetOutputEncoding() const { return m_OutputEnc
; }
128 wxEncodingConverter
*GetEncodingConverter() const { return m_EncConv
; }
131 // creates font depending on m_Font* members.
132 virtual wxFont
* CreateCurrentFont();
135 virtual void AddText(const wxChar
* txt
);
138 bool m_tmpLastWasSpace
;
140 size_t m_tmpStrBufSize
;
141 // temporary variables used by AddText
142 wxHtmlWindow
*m_Window
;
143 // window we're parsing for
146 // Device Context we're parsing for
147 static wxList m_Modules
;
148 // list of tags modules (see wxHtmlTagsModule for details)
149 // This list is used to initialize m_Handlers member.
151 wxHtmlContainerCell
*m_Container
;
152 // current container. See Open/CloseContainer for details.
154 int m_FontBold
, m_FontItalic
, m_FontUnderlined
, m_FontFixed
; // this is not TRUE,FALSE but 1,0, we need it for indexing
155 int m_FontSize
; /* -2 to +4, 0 is default */
156 wxColour m_LinkColor
;
157 wxColour m_ActualColor
;
158 // basic font parameters.
159 wxHtmlLinkInfo m_Link
;
160 // actual hypertext link or empty string
162 // TRUE if m_Link is not empty
163 long m_CharHeight
, m_CharWidth
;
164 // average height of normal-sized text
168 wxFont
* m_FontsTable
[2][2][2][2][7];
169 wxString m_FontsFacesTable
[2][2][2][2][7];
171 wxFontEncoding m_FontsEncTable
[2][2][2][2][7];
173 // table of loaded fonts. 1st four indexes are 0 or 1, depending on on/off
174 // state of these flags (from left to right):
175 // [bold][italic][underlined][fixed_size]
176 // last index is font size : from 0 to 6 (remapped from html sizes 1 to 7)
177 // Note : this table covers all possible combinations of fonts, but not
178 // all of them are used, so many items in table are usually NULL.
180 wxString m_FontFaceFixed
, m_FontFaceNormal
;
181 // html font sizes and faces of fixed and proportional fonts
184 wxFontEncoding m_InputEnc
, m_OutputEnc
;
185 // I/O font encodings
186 wxEncodingConverter
*m_EncConv
;
189 wxHtmlWordCell
*m_lastWordCell
;
191 DECLARE_NO_COPY_CLASS(wxHtmlWinParser
)
199 //-----------------------------------------------------------------------------
200 // wxHtmlWinTagHandler
201 // This is basicly wxHtmlTagHandler except
202 // it is extended with protected member m_Parser pointing to
203 // the wxHtmlWinParser object
204 //-----------------------------------------------------------------------------
206 class WXDLLIMPEXP_HTML wxHtmlWinTagHandler
: public wxHtmlTagHandler
208 DECLARE_ABSTRACT_CLASS(wxHtmlWinTagHandler
)
211 wxHtmlWinTagHandler() : wxHtmlTagHandler() {};
213 virtual void SetParser(wxHtmlParser
*parser
) {wxHtmlTagHandler::SetParser(parser
); m_WParser
= (wxHtmlWinParser
*) parser
;};
216 wxHtmlWinParser
*m_WParser
; // same as m_Parser, but overcasted
218 DECLARE_NO_COPY_CLASS(wxHtmlWinTagHandler
)
226 //----------------------------------------------------------------------------
228 // This is basic of dynamic tag handlers binding.
229 // The class provides methods for filling parser's handlers
231 // (See documentation for details)
232 //----------------------------------------------------------------------------
234 class WXDLLIMPEXP_HTML wxHtmlTagsModule
: public wxModule
236 DECLARE_DYNAMIC_CLASS(wxHtmlTagsModule
)
239 wxHtmlTagsModule() : wxModule() {};
241 virtual bool OnInit();
242 virtual void OnExit();
244 // This is called by wxHtmlWinParser.
245 // The method must simply call parser->AddTagHandler(new
246 // <handler_class_name>); for each handler
247 virtual void FillHandlersTable(wxHtmlWinParser
* WXUNUSED(parser
)) { }
253 #endif // _WX_WINPARS_H_