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 /////////////////////////////////////////////////////////////////////////////
10 #ifndef __HTMLWINPARSER_H__
11 #define __HTMLWINPARSER_H__
20 #include <wx/module.h>
21 #include <wx/html/htmlparser.h>
22 #include <wx/html/htmlcell.h>
24 class wxHtmlWinParser
;
25 class wxHtmlWinTagHandler
;
26 class wxHtmlTagsModule
;
28 //--------------------------------------------------------------------------------
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 //--------------------------------------------------------------------------------
35 class WXDLLEXPORT wxHtmlWinParser
: public wxHtmlParser
37 DECLARE_DYNAMIC_CLASS(wxHtmlWinParser
)
39 friend class wxHtmlWindow
;
43 // window we're parsing for
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.
50 wxHtmlContainerCell
*m_Container
;
51 // actual container. See Open/CloseContainer for details.
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 */
56 wxColour m_ActualColor
;
57 // basic font parameters.
59 // actual hypertext link or empty string
61 // TRUE if m_Link is not empty
62 long m_CharHeight
, m_CharWidth
;
63 // average height of normal-sized text
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.
75 wxString m_FontFaceFixed
, m_FontFaceNormal
;
76 int m_ItalicModeFixed
, m_ItalicModeNormal
;
77 // html font sizes and faces of fixed and proportional fonts
80 wxHtmlWinParser() : wxHtmlParser() {wxHtmlWinParser(NULL
);}
81 wxHtmlWinParser(wxWindow
*wnd
);
83 virtual void InitParser(const wxString
& source
);
84 virtual void DoneParser();
85 virtual wxObject
* GetProduct();
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
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
104 virtual wxList
* GetTempData();
106 static void AddModule(wxHtmlTagsModule
*module);
107 // Adds tags module. see wxHtmlTagsModule for details.
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
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
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
;}
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;}
144 virtual wxFont
* CreateCurrentFont();
145 // creates font depending on m_Font* members.
146 // (note : it calls wxHtmlWindow's CreateCurrentFont...)
149 virtual void AddText(const char *txt
);
152 bool m_tmpLastWasSpace
;
153 // temporary variable used by AddText
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 //--------------------------------------------------------------------------------
168 class WXDLLEXPORT wxHtmlWinTagHandler
: public wxHtmlTagHandler
170 DECLARE_ABSTRACT_CLASS(wxHtmlWinTagHandler
)
173 wxHtmlWinParser
*m_WParser
;
174 // same as m_Parser, but overcasted
177 wxHtmlWinTagHandler() : wxHtmlTagHandler() {};
179 virtual void SetParser(wxHtmlParser
*parser
) {wxHtmlTagHandler::SetParser(parser
); m_WParser
= (wxHtmlWinParser
*) parser
;};
187 //--------------------------------------------------------------------------------
189 // This is basic of dynamic tag handlers binding.
190 // The class provides methods for filling parser's handlers
192 // (See documentation for details)
193 //--------------------------------------------------------------------------------
195 class WXDLLEXPORT wxHtmlTagsModule
: public wxModule
197 DECLARE_DYNAMIC_CLASS(wxHtmlTagsModule
)
200 wxHtmlTagsModule() : wxModule() {};
202 virtual bool OnInit();
203 virtual void OnExit();
205 virtual void FillHandlersTable(wxHtmlWinParser
*parser
) {}
206 // This is called by wxHtmlWinParser.
207 // The method must simply call parser->AddTagHandler(new <handler_class_name>);
214 #endif // __HTMLWINPARSER_H__