1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtmlWindow class for parsing & displaying HTML
4 // Author: Vaclav Slavik
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_HTMLWIN_H_
12 #define _WX_HTMLWIN_H_
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"
31 //--------------------------------------------------------------------------------
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 //--------------------------------------------------------------------------------
43 // item of history list
44 class WXDLLEXPORT HtmlHistoryItem
: public wxObject
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
;}
59 #undef WXDLLEXPORTLOCAL
60 #define WXDLLEXPORTLOCAL WXDLLEXPORT
61 // ?? Don't know why - but Allen Van Sickel reported it to fix problems with DLL
63 WX_DECLARE_OBJARRAY(HtmlHistoryItem
, HtmlHistoryArray
);
65 #undef WXDLLEXPORTLOCAL
66 #define WXDLLEXPORTLOCAL
69 class WXDLLEXPORT wxHtmlWindow
: public wxScrolledWindow
71 DECLARE_DYNAMIC_CLASS(wxHtmlWindow
)
74 wxHtmlWindow() : wxScrolledWindow() {};
75 wxHtmlWindow(wxWindow
*parent
, wxWindowID id
= -1,
76 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
77 long style
= wxHW_SCROLLBAR_AUTO
,
78 const wxString
& name
= "htmlWindow");
81 bool SetPage(const wxString
& source
);
82 // Set HTML page and display it. !! source is HTML document itself,
83 // it is NOT address/filename of HTML document. If you want to
84 // specify document location, use LoadPage() istead
85 // Return value : FALSE if an error occured, TRUE otherwise
87 bool LoadPage(const wxString
& location
);
88 // Load HTML page from given location. Location can be either
89 // a) /usr/wxGTK2/docs/html/wx.htm
90 // b) http://www.somewhere.uk/document.htm
91 // c) ftp://ftp.somesite.cz/pub/something.htm
92 // In case there is no prefix (http:,ftp:), the method
93 // will try to find it itself (1. local file, then http or ftp)
94 // After the page is loaded, the method calls SetPage() to display it.
95 // Note : you can also use path relative to previously loaded page
96 // Return value : same as SetPage
98 wxString
GetOpenedPage() const {return m_OpenedPage
;}
99 // Returns full location of opened page
101 void SetRelatedFrame(wxFrame
* frame
, const wxString
& format
);
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 wxFrame
* GetRelatedFrame() const {return m_RelatedFrame
;}
106 void SetRelatedStatusBar(int bar
);
107 // after(!) calling SetRelatedFrame, this sets statusbar slot where messages
108 // will be displayed. Default is -1 = no messages.
110 void SetFonts(wxString normal_face
, int normal_italic_mode
, wxString fixed_face
, int fixed_italic_mode
, int *sizes
);
111 // sets fonts to be used when displaying HTML page.
112 // *_italic_mode can be either wxSLANT or wxITALIC
114 void SetTitle(const wxString
& title
);
115 // Sets the title of the window
116 // (depending on the information passed to SetRelatedFrame() method)
118 void SetBorders(int b
) {m_Borders
= b
;}
119 // Sets space between text and window borders.
121 virtual void ReadCustomization(wxConfigBase
*cfg
, wxString path
= wxEmptyString
);
122 // saves custom settings into cfg config. it will use the path 'path'
123 // if given, otherwise it will save info into currently selected path.
124 // saved values : things set by SetFonts, SetBorders.
125 virtual void WriteCustomization(wxConfigBase
*cfg
, wxString path
= wxEmptyString
);
129 bool HistoryForward();
130 // Goes to previous/next page (in browsing history)
131 // Returns TRUE if successful, FALSE otherwise
135 wxHtmlContainerCell
* GetInternalRepresentation() const {return m_Cell
;}
136 // Returns pointer to conteiners/cells structure.
137 // It should be used ONLY when printing
139 static void AddFilter(wxHtmlFilter
*filter
);
142 virtual void OnLinkClicked(const wxString
& link
);
143 // called when users clicked on hypertext link. Default behavior is to
144 // call LoadPage(loc)
146 static void CleanUpStatics();
147 // cleans static variables
149 wxHtmlWinParser
*GetParser() const { return m_Parser
; }
150 // return a pointer to the parser.
153 bool ScrollToAnchor(const wxString
& anchor
);
154 // Scrolls to anchor of this name. (Anchor is #news
155 // or #features etc. it is part of address sometimes:
156 // http://www.ms.mff.cuni.cz/~vsla8348/wxhtml/index.html#news)
157 // Return value : TRUE if anchor exists, FALSE otherwise
160 // prepare layout (= fill m_PosX, m_PosY for fragments) based on actual size of
161 // window. This method also setup scrollbars
163 void OnDraw(wxDC
& dc
);
164 void OnSize(wxSizeEvent
& event
);
165 void OnMouseEvent(wxMouseEvent
& event
);
166 void OnIdle(wxIdleEvent
& event
);
167 void OnKeyDown(wxKeyEvent
& event
);
169 virtual wxHtmlFilter
*GetDefaultFilter() {return new wxHtmlFilterPlainText
;}
170 // returns new filter (will be stored into m_DefaultFilter variable)
174 wxHtmlContainerCell
*m_Cell
;
175 // This is pointer to the first cell in parsed data.
176 // (Note: the first cell is usually top one = all other cells are sub-cells of this one)
177 wxHtmlWinParser
*m_Parser
;
178 // parser which is used to parse HTML input.
179 // Each wxHtmlWindow has it's own parser because sharing one global
180 // parser would be problematic (because of reentrancy)
181 wxString m_OpenedPage
;
182 // contains name of actualy opened page or empty string if no page opened
183 wxString m_OpenedAnchor
;
184 // contains name of current anchor within m_OpenedPage
186 // class for opening files (file system)
188 wxFrame
*m_RelatedFrame
;
189 wxString m_TitleFormat
;
190 int m_RelatedStatusBar
;
191 // frame in which page title should be displayed & number of it's statusbar
192 // reserved for usage with this html window
195 // borders (free space between text and window borders)
196 // defaults to 10 pixels.
201 bool m_tmpMouseMoved
;
202 // a flag indicated if mouse moved
203 // (if TRUE we will try to change cursor in last call to OnIdle)
204 wxString m_tmpLastLink
;
205 // contains last link name
207 // if FALSE contents of the window is not redrawn
208 // (in order to avoid ugly bliking)
210 static wxList m_Filters
;
211 // list of HTML filters
212 static wxHtmlFilter
*m_DefaultFilter
;
213 // this filter is used when no filter is able to read some file
215 HtmlHistoryArray m_History
;
219 // if this FLAG is false, items are not added to history
222 DECLARE_EVENT_TABLE()
228 #endif // _WX_HTMLWIN_H_