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