1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtmlWindow class for parsing & displaying HTML
4 // Author: Vaclav Slavik
5 // Copyright: (c) 1999 Vaclav Slavik
6 // Licence: wxWindows Licence
7 /////////////////////////////////////////////////////////////////////////////
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>
29 //--------------------------------------------------------------------------------
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 //--------------------------------------------------------------------------------
41 // item of history list
42 class WXDLLEXPORT HtmlHistoryItem
: public wxObject
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
;}
57 #undef WXDLLEXPORTLOCAL
58 #define WXDLLEXPORTLOCAL WXDLLEXPORT
59 // ?? Don't know why - but Allen Van Sickel reported it to fix problems with DLL
61 WX_DECLARE_OBJARRAY(HtmlHistoryItem
, HtmlHistoryArray
);
63 #undef WXDLLEXPORTLOCAL
64 #define WXDLLEXPORTLOCAL
67 class WXDLLEXPORT wxHtmlWindow
: public wxScrolledWindow
69 DECLARE_DYNAMIC_CLASS(wxHtmlWindow
)
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
84 // class for opening files (file system)
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
93 // borders (free space between text and window borders)
94 // defaults to 10 pixels.
100 bool m_tmpMouseMoved
;
101 // a flag indicated if mouse moved
102 // (if TRUE we will try to change cursor in last call to OnIdle)
104 // if FALSE contents of the window is not redrawn
105 // (in order to avoid ugly bliking)
107 static wxList m_Filters
;
108 // list of HTML filters
109 static wxHtmlFilter
*m_DefaultFilter
;
110 // this filter is used when no filter is able to read some file
112 HtmlHistoryArray m_History
;
116 // if this FLAG is false, items are not added to history
119 wxHtmlWindow() : wxScrolledWindow() {};
120 wxHtmlWindow(wxWindow
*parent
, wxWindowID id
= -1,
121 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
122 long style
= wxHW_SCROLLBAR_AUTO
,
123 const wxString
& name
= "htmlWindow");
126 bool SetPage(const wxString
& source
);
127 // Set HTML page and display it. !! source is HTML document itself,
128 // it is NOT address/filename of HTML document. If you want to
129 // specify document location, use LoadPage() istead
130 // Return value : FALSE if an error occured, TRUE otherwise
132 bool LoadPage(const wxString
& location
);
133 // Load HTML page from given location. Location can be either
134 // a) /usr/wxGTK2/docs/html/wx.htm
135 // b) http://www.somewhere.uk/document.htm
136 // c) ftp://ftp.somesite.cz/pub/something.htm
137 // In case there is no prefix (http:,ftp:), the method
138 // will try to find it itself (1. local file, then http or ftp)
139 // After the page is loaded, the method calls SetPage() to display it.
140 // Note : you can also use path relative to previously loaded page
141 // Return value : same as SetPage
143 wxString
GetOpenedPage() const {return m_OpenedPage
;}
144 // Returns full location of opened page
146 void SetRelatedFrame(wxFrame
* frame
, const wxString
& format
);
147 // sets frame in which page title will be displayed. Format is format of
148 // frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s
149 wxFrame
* GetRelatedFrame() const {return m_RelatedFrame
;}
151 void SetRelatedStatusBar(int bar
);
152 // after(!) calling SetRelatedFrame, this sets statusbar slot where messages
153 // will be displayed. Default is -1 = no messages.
155 void SetFonts(wxString normal_face
, int normal_italic_mode
, wxString fixed_face
, int fixed_italic_mode
, int *sizes
);
156 // sets fonts to be used when displaying HTML page.
157 // *_italic_mode can be either wxSLANT or wxITALIC
159 void SetTitle(const wxString
& title
);
160 // Sets the title of the window
161 // (depending on the information passed to SetRelatedFrame() method)
163 void SetBorders(int b
) {m_Borders
= b
;}
164 // Sets space between text and window borders.
166 virtual void ReadCustomization(wxConfigBase
*cfg
, wxString path
= wxEmptyString
);
167 // saves custom settings into cfg config. it will use the path 'path'
168 // if given, otherwise it will save info into currently selected path.
169 // saved values : things set by SetFonts, SetBorders.
170 virtual void WriteCustomization(wxConfigBase
*cfg
, wxString path
= wxEmptyString
);
174 bool HistoryForward();
175 // Goes to previous/next page (in browsing history)
176 // Returns TRUE if successful, FALSE otherwise
180 wxHtmlContainerCell
* GetInternalRepresentation() const {return m_Cell
;}
181 // Returns pointer to conteiners/cells structure.
182 // It should be used ONLY when printing
184 static void AddFilter(wxHtmlFilter
*filter
);
187 virtual void OnLinkClicked(const wxString
& link
);
188 // called when users clicked on hypertext link. Default behavior is to
189 // call LoadPage(loc)
191 static void CleanUpStatics();
192 // cleans static variables
195 bool ScrollToAnchor(const wxString
& anchor
);
196 // Scrolls to anchor of this name. (Anchor is #news
197 // or #features etc. it is part of address sometimes:
198 // http://www.ms.mff.cuni.cz/~vsla8348/wxhtml/index.html#news)
199 // Return value : TRUE if anchor exists, FALSE otherwise
202 // prepare layout (= fill m_PosX, m_PosY for fragments) based on actual size of
203 // window. This method also setup scrollbars
205 void OnDraw(wxDC
& dc
);
206 void OnSize(wxSizeEvent
& event
);
207 void OnMouseEvent(wxMouseEvent
& event
);
208 void OnIdle(wxIdleEvent
& event
);
209 void OnKeyDown(wxKeyEvent
& event
);
211 virtual wxHtmlFilter
*GetDefaultFilter() {return new wxHtmlFilterPlainText
;}
212 // returns new filter (will be stored into m_DefaultFilter variable)
214 DECLARE_EVENT_TABLE()
219 #endif // __HTMLWIN_H__