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