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