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