]> git.saurik.com Git - wxWidgets.git/blob - include/wx/html/htmlwin.h
virtual functionsignature corrected
[wxWidgets.git] / include / wx / html / htmlwin.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: htmlwin.h
3 // Purpose: wxHtmlWindow class for parsing & displaying HTML
4 // Author: Vaclav Slavik
5 // Copyright: (c) 1999 Vaclav Slavik
6 // Licence: wxWindows Licence
7 /////////////////////////////////////////////////////////////////////////////
8
9
10 #ifndef __HTMLWIN_H__
11 #define __HTMLWIN_H__
12
13 #ifdef __GNUG__
14 #pragma interface
15 #endif
16
17 #include "wx/defs.h"
18 #if wxUSE_HTML
19
20 #include <wx/window.h>
21 #include <wx/scrolwin.h>
22 #include <wx/config.h>
23 #include <wx/treectrl.h>
24 #include <wx/html/htmlwinparser.h>
25 #include <wx/html/htmlcell.h>
26 #include <wx/filesys.h>
27 #include <wx/html/htmlfilter.h>
28
29
30 //--------------------------------------------------------------------------------
31 // wxHtmlWindow
32 // (This is probably the only class you will directly use.)
33 // Purpose of this class is to display HTML page (either local
34 // file or downloaded via HTTP protocol) in a window. Width
35 // of window is constant - given in constructor - virtual height
36 // is changed dynamicly depending on page size.
37 // Once the window is created you can set it's content by calling
38 // SetPage(text) or LoadPage(filename).
39 //--------------------------------------------------------------------------------
40
41
42 // item of history list
43 class WXDLLEXPORT HtmlHistoryItem : public wxObject
44 {
45 private:
46 wxString m_Page;
47 wxString m_Anchor;
48 int m_Pos;
49
50 public:
51 HtmlHistoryItem(const wxString& p, const wxString& a) {m_Page = p, m_Anchor = a, m_Pos = 0;}
52 int GetPos() const {return m_Pos;}
53 void SetPos(int p) {m_Pos = p;}
54 const wxString& GetPage() const {return m_Page;}
55 const wxString& GetAnchor() const {return m_Anchor;}
56 };
57
58 #undef WXDLLEXPORTLOCAL
59 #define WXDLLEXPORTLOCAL WXDLLEXPORT
60 // ?? Don't know why - but Allen Van Sickel reported it to fix problems with DLL
61
62 WX_DECLARE_OBJARRAY(HtmlHistoryItem, HtmlHistoryArray);
63
64 #undef WXDLLEXPORTLOCAL
65 #define WXDLLEXPORTLOCAL
66
67
68 class WXDLLEXPORT wxHtmlWindow : public wxScrolledWindow
69 {
70 DECLARE_DYNAMIC_CLASS(wxHtmlWindow)
71
72 protected:
73 wxHtmlContainerCell *m_Cell;
74 // This is pointer to the first cell in parsed data.
75 // (Note: the first cell is usually top one = all other cells are sub-cells of this one)
76 wxHtmlWinParser *m_Parser;
77 // parser which is used to parse HTML input.
78 // Each wxHtmlWindow has it's own parser because sharing one global
79 // parser would be problematic (because of reentrancy)
80 wxString m_OpenedPage;
81 // contains name of actualy opened page or empty string if no page opened
82 wxString m_OpenedAnchor;
83 // contains name of current anchor within m_OpenedPage
84 wxFileSystem* m_FS;
85 // class for opening files (file system)
86
87 wxFrame *m_RelatedFrame;
88 wxString m_TitleFormat;
89 int m_RelatedStatusBar;
90 // frame in which page title should be displayed & number of it's statusbar
91 // reserved for usage with this html window
92
93 int m_Borders;
94 // borders (free space between text and window borders)
95 // defaults to 10 pixels.
96
97 int m_Style;
98
99
100 private:
101 bool m_tmpMouseMoved;
102 // a flag indicated if mouse moved
103 // (if TRUE we will try to change cursor in last call to OnIdle)
104 bool m_tmpCanDraw;
105 // if FALSE contents of the window is not redrawn
106 // (in order to avoid ugly bliking)
107
108 static wxList m_Filters;
109 // list of HTML filters
110 static wxHtmlFilter *m_DefaultFilter;
111 // this filter is used when no filter is able to read some file
112
113 HtmlHistoryArray m_History;
114 int m_HistoryPos;
115 // browser history
116 bool m_HistoryOn;
117 // if this FLAG is false, items are not added to history
118
119 public:
120 wxHtmlWindow() : wxScrolledWindow() {};
121 wxHtmlWindow(wxWindow *parent, wxWindowID id = -1,
122 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
123 long style = wxHW_SCROLLBAR_AUTO,
124 const wxString& name = "htmlWindow");
125 ~wxHtmlWindow();
126
127 bool SetPage(const wxString& source);
128 // Set HTML page and display it. !! source is HTML document itself,
129 // it is NOT address/filename of HTML document. If you want to
130 // specify document location, use LoadPage() istead
131 // Return value : FALSE if an error occured, TRUE otherwise
132
133 bool LoadPage(const wxString& location);
134 // Load HTML page from given location. Location can be either
135 // a) /usr/wxGTK2/docs/html/wx.htm
136 // b) http://www.somewhere.uk/document.htm
137 // c) ftp://ftp.somesite.cz/pub/something.htm
138 // In case there is no prefix (http:,ftp:), the method
139 // will try to find it itself (1. local file, then http or ftp)
140 // After the page is loaded, the method calls SetPage() to display it.
141 // Note : you can also use path relative to previously loaded page
142 // Return value : same as SetPage
143
144 wxString GetOpenedPage() const {return m_OpenedPage;}
145 // Returns full location of opened page
146
147 void SetRelatedFrame(wxFrame* frame, const wxString& format);
148 // sets frame in which page title will be displayed. Format is format of
149 // frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s
150 wxFrame* GetRelatedFrame() const {return m_RelatedFrame;}
151
152 void SetRelatedStatusBar(int bar);
153 // after(!) calling SetRelatedFrame, this sets statusbar slot where messages
154 // will be displayed. Default is -1 = no messages.
155
156 void SetFonts(wxString normal_face, int normal_italic_mode, wxString fixed_face, int fixed_italic_mode, int *sizes);
157 // sets fonts to be used when displaying HTML page.
158 // *_italic_mode can be either wxSLANT or wxITALIC
159
160 void SetTitle(const wxString& title);
161 // Sets the title of the window
162 // (depending on the information passed to SetRelatedFrame() method)
163
164 void SetBorders(int b) {m_Borders = b;}
165 // Sets space between text and window borders.
166
167 virtual void ReadCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
168 // saves custom settings into cfg config. it will use the path 'path'
169 // if given, otherwise it will save info into currently selected path.
170 // saved values : things set by SetFonts, SetBorders.
171 virtual void WriteCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
172 // ...
173
174 bool HistoryBack();
175 bool HistoryForward();
176 // Goes to previous/next page (in browsing history)
177 // Returns TRUE if successful, FALSE otherwise
178 void HistoryClear();
179 // Resets history
180
181 wxHtmlContainerCell* GetInternalRepresentation() const {return m_Cell;}
182 // Returns pointer to conteiners/cells structure.
183 // It should be used ONLY when printing
184
185 static void AddFilter(wxHtmlFilter *filter);
186 // Adds input filter
187
188 virtual void OnLinkClicked(const wxString& link);
189 // called when users clicked on hypertext link. Default behavior is to
190 // call LoadPage(loc)
191
192 static void CleanUpStatics();
193 // cleans static variables
194
195 wxHtmlWinParser *GetParser() const { return m_Parser; }
196 // return a pointer to the parser.
197
198 protected:
199 bool ScrollToAnchor(const wxString& anchor);
200 // Scrolls to anchor of this name. (Anchor is #news
201 // or #features etc. it is part of address sometimes:
202 // http://www.ms.mff.cuni.cz/~vsla8348/wxhtml/index.html#news)
203 // Return value : TRUE if anchor exists, FALSE otherwise
204
205 void CreateLayout();
206 // prepare layout (= fill m_PosX, m_PosY for fragments) based on actual size of
207 // window. This method also setup scrollbars
208
209 void OnDraw(wxDC& dc);
210 void OnSize(wxSizeEvent& event);
211 void OnMouseEvent(wxMouseEvent& event);
212 void OnIdle(wxIdleEvent& event);
213 void OnKeyDown(wxKeyEvent& event);
214
215 virtual wxHtmlFilter *GetDefaultFilter() {return new wxHtmlFilterPlainText;}
216 // returns new filter (will be stored into m_DefaultFilter variable)
217
218 DECLARE_EVENT_TABLE()
219 };
220
221
222
223 #endif // __HTMLWIN_H__
224
225 #endif
226
227
228