1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG definitions of html classes
7 // Created: 25-nov-1998
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
18 #include <wx/html/htmlwin.h>
20 #include <wx/fs_zip.h>
21 #include <wx/fs_inet.h>
22 #include <wx/wfstream.h>
26 //---------------------------------------------------------------------------
29 %include my_typemaps.i
45 static wxString wxPyEmptyStr("");
46 static wxPoint wxPyDefaultPosition(wxDefaultPosition);
47 static wxSize wxPyDefaultSize(wxDefaultSize);
49 static PyThreadState* wxPyThreadState;
52 %pragma(python) code = "import wx,htmlhelper"
53 %pragma(python) code = "widget = htmlc"
57 static PyObject* mod_dict = NULL; // will be set by init
59 #include <wx/html/mod_templ.h>
61 TAG_HANDLER_BEGIN(PYTHONTAG, "PYTHON")
71 #ifdef WXP_WITH_THREAD
72 PyEval_RestoreThread(wxPyThreadState);
74 if (tag.HasParam("FLOAT"))
75 tag.ScanParam("FLOAT", "%i", &fl);
76 PyObject* pyfunc = PyDict_GetItemString(mod_dict, "WidgetStarter");
78 errmsg = "Could not find object WidgetStarter";
81 if (! PyCallable_Check(pyfunc)) {
82 errmsg = "WidgetStarter does not appear to be callable";
85 SWIG_MakePtr(pbuf, m_WParser->GetWindow(), "_wxHtmlWindow_p");
86 PyObject* arglist = Py_BuildValue("(s,s)", pbuf,
87 (const char*)tag.GetAllParams());
89 errmsg = "Failed making argument list";
92 PyObject* ret = PyEval_CallObject(pyfunc, arglist);
95 errmsg = "An error occured while calling WidgetStarter";
101 if (PyString_Check(ret)) {
102 char* thisc = PyString_AsString(ret);
103 SWIG_GetPtr(thisc, (void**)&wnd, "_wxWindow_p");
107 errmsg = "Could not make a wxWindow pointer from return ptr";
110 #ifdef WXP_WITH_THREAD
114 m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, fl));
118 /* we got out of the loop. Must be an error. Show a box stating it. */
120 #ifdef WXP_WITH_THREAD
124 wnd = new wxTextCtrl( m_WParser -> GetWindow(), -1,
125 errmsg, wxPoint(0,0),
126 wxSize(300, 100), wxTE_MULTILINE );
128 m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, 100));
132 TAG_HANDLER_END(PYTHONTAG)
134 TAGS_MODULE_BEGIN(PythonTag)
136 TAGS_MODULE_ADD(PYTHONTAG)
138 TAGS_MODULE_END(PythonTag)
140 // Note: see also the init function where we add the module!
144 //---------------------------------------------------------------------------
146 // item of history list
147 class HtmlHistoryItem
150 HtmlHistoryItem(const char* p, const char* a);
151 int GetPos() const {return m_Pos;}
152 void SetPos(int p) {m_Pos = p;}
153 const wxString& GetPage() const ;
154 const wxString& GetAnchor() const ;
157 class wxHtmlWindow : public wxScrolledWindow
160 wxHtmlWindow(wxWindow *parent, int id = -1,
161 const wxPoint& pos = wxPyDefaultPosition,
162 const wxSize& size = wxPyDefaultSize,
163 int flags=wxHW_SCROLLBAR_AUTO,
164 const char* name = "htmlWindow");
165 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
166 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
168 bool SetPage(const char* source);
169 // Set HTML page and display it. !! source is HTML document itself,
170 // it is NOT address/filename of HTML document. If you want to
171 // specify document location, use LoadPage() istead
172 // Return value : FALSE if an error occured, TRUE otherwise
174 bool LoadPage(const char* location);
175 // Load HTML page from given location. Location can be either
176 // a) /usr/wxGTK2/docs/html/wx.htm
177 // b) http://www.somewhere.uk/document.htm
178 // c) ftp://ftp.somesite.cz/pub/something.htm
179 // In case there is no prefix (http:,ftp:), the method
180 // will try to find it itself (1. local file, then http or ftp)
181 // After the page is loaded, the method calls SetPage() to display it.
182 // Note : you can also use path relative to previously loaded page
183 // Return value : same as SetPage
185 wxString GetOpenedPage() const {return m_OpenedPage;}
186 // Returns full location of opened page
188 void SetRelatedFrame(wxFrame* frame, const char* format);
189 // sets frame in which page title will be displayed. Format is format of
190 // frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s
191 wxFrame* GetRelatedFrame() const;
193 void SetRelatedStatusBar(int bar);
194 // after(!) calling SetRelatedFrame, this sets statusbar slot where messages
195 // will be displayed. Default is -1 = no messages.
197 void SetFonts(wxString normal_face, int normal_italic_mode, wxString fixed_face, int fixed_italic_mode, int *sizes);
198 // sets fonts to be used when displaying HTML page.
199 // *_italic_mode can be either wxSLANT or wxITALIC
201 void SetTitle(const char* title);
202 // Sets the title of the window
203 // (depending on the information passed to SetRelatedFrame() method)
205 void SetBorders(int b);
206 // Sets space between text and window borders.
208 //virtual void ReadCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
209 // saves custom settings into cfg config. it will use the path 'path'
210 // if given, otherwise it will save info into currently selected path.
211 // saved values : things set by SetFonts, SetBorders.
212 //virtual void WriteCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
216 bool HistoryForward();
217 // Goes to previous/next page (in browsing history)
218 // Returns TRUE if successful, FALSE otherwise
222 //wxHtmlContainerCell* GetInternalRepresentation() const;
223 // Returns pointer to conteiners/cells structure.
224 // It should be used ONLY when printing
226 //static void AddFilter(wxHtmlFilter *filter);
229 /* This function needs to be eventified! */
230 //virtual void OnLinkClicked(const char* link);
231 // called when users clicked on hypertext link. Default behavior is to
232 // call LoadPage(loc)
234 //static void CleanUpStatics();
235 // cleans static variables
247 wxID_HTML_SEARCHPAGE,
248 wxID_HTML_SEARCHTEXT,
249 wxID_HTML_SEARCHLIST,
250 wxID_HTML_SEARCHBUTTON
253 class wxHtmlHelpController : public wxEvtHandler
256 wxHtmlHelpController();
257 ~wxHtmlHelpController();
266 void SetTitleFormat(const wxString& format) {m_TitleFormat = format;}
267 // Sets format of title of the frame. Must contain exactly one "%s"
268 // (for title of displayed HTML page)
270 void SetTempDir(const wxString& path);
271 // Sets directory where temporary files are stored.
272 // These temp files are index & contents file in binary (much faster to read)
273 // form. These files are NOT deleted on program's exit.
275 bool AddBook(const wxString& book, bool show_wait_msg = FALSE);
276 // Adds new book. 'book' is location of .htb file (stands for "html book").
277 // See documentation for details on its format.
279 // If show_wait_msg == true then message window with "loading book..." is displayed
281 void Display(const wxString& x);
282 // Displays page x. If not found it will offect the user a choice of searching
284 // Looking for the page runs in these steps:
285 // 1. try to locate file named x (if x is for example "doc/howto.htm")
286 // 2. try to open starting page of book x
287 // 3. try to find x in contents (if x is for example "How To ...")
288 // 4. try to find x in index (if x is for example "How To ...")
289 // 5. offer searching and if the user agree, run KeywordSearch
290 %name(DisplayID) void Display(const int id);
291 // Alternative version that works with numeric ID.
292 // (uses extension to MS format, <param name="ID" value=id>, see docs)
294 void DisplayContents();
295 // Displays help window and focuses contents.
298 // Displays help window and focuses index.
300 bool KeywordSearch(const wxString& keyword);
301 // Searches for keyword. Returns TRUE and display page if found, return
303 // Syntax of keyword is Altavista-like:
304 // * words are separated by spaces
305 // (but "\"hello world\"" is only one world "hello world")
306 // * word may be pretended by + or -
307 // (+ : page must contain the word ; - : page can't contain the word)
308 // * if there is no + or - before the word, + is default
310 void UseConfig(wxConfigBase *config, const wxString& rootpath = wxEmptyString);
311 // Assigns config object to the controller. This config is then
312 // used in subsequent calls to Read/WriteCustomization of both help
313 // controller and it's wxHtmlWindow
315 void ReadCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
316 // saves custom settings into cfg config. it will use the path 'path'
317 // if given, otherwise it will save info into currently selected path.
318 // saved values : things set by SetFonts, SetBorders.
319 void WriteCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
323 class wxHtmlHelpSystem : public wxHtmlHelpController
326 wxHtmlHelpSystem() {};
327 ~wxHtmlHelpSystem() {};
329 bool AddBookParam(const wxString& title, const wxString& contfile,
330 const wxString& indexfile=wxEmptyString, const wxString& deftopic=wxEmptyString,
331 const wxString& path=wxEmptyString, bool show_wait_msg=FALSE);
332 // Alternative to AddBook(wxString& hhpfile)
333 wxToolBar* CreateToolBar(wxFrame* frame);
334 // creates a dockable toolbar for the frame, containing hide/show, back and forward buttons
335 wxTreeCtrl* CreateContentsTree(wxWindow* parent);
336 // creates a treecontrol with imagelist for books, folders etc and id wxID_HTML_TREECTRL
337 wxListBox* CreateIndexList(wxWindow* parent);
338 // creates a listbox with the right id
339 virtual void CreateHelpWindow();
340 // Slightly different version than in wxHtmlHelpController; uses helpers above
341 // Do nothing if the window already exists
342 void SetControls(wxFrame* frame, wxHtmlWindow* htmlwin,
343 wxTreeCtrl* contents=NULL, wxListBox* index=NULL,
344 wxListBox* searchlist=NULL);
345 // alternative for CreateHelpWindow(), sets frame, htmlwindow, contents tree, index
346 // listbox and searchlist listbox. If null, their functionality won't be used
348 // Some extra accessor functions
349 wxFrame* GetFrame() { return m_Frame; }
350 wxHtmlWindow* GetHtmlWindow() { return m_HtmlWin; }
351 wxTreeCtrl* GetContentsTree() { return m_ContentsBox; }
352 wxListBox* GetIndexList() { return m_IndexBox; }
353 wxListBox* GetSearchList() { return m_SearchList; }
354 wxImageList* GetContentsImageList() { return m_ContentsImageList; }
355 // public interface for wxHtmlHelpControllers handlers, so wxPython can call them
356 void OnToolbar(wxCommandEvent& event);
357 void OnContentsSel(wxTreeEvent& event) {wxHtmlHelpController::OnContentsSel(event);}
358 void OnIndexSel(wxCommandEvent& event) {wxHtmlHelpController::OnIndexSel(event);}
359 void OnSearchSel(wxCommandEvent& event) {wxHtmlHelpController::OnSearchSel(event);}
360 void OnSearch(wxCommandEvent& event) {wxHtmlHelpController::OnSearch(event);}
361 void OnCloseWindow(wxCloseEvent& event);
363 // some more protected functions that should be accessible from wxPython
365 void CreateContents() { if (!m_IndexBox) return; wxHtmlHelpController::CreateContents(); }
366 // Adds items to m_Contents tree control
367 void CreateIndex() { if (! m_ContentsBox) return; wxHtmlHelpController::CreateIndex(); }
368 // Adds items to m_IndexList
371 // just for fun, an Altavista-like search engine (the gems that Vaclav has hidden in wxHtml...)
372 // but not for wxMSW because it's not DLL exported
374 #ifdef THIS_IS_NOT_DEFINED_OKAY
378 wxSearchEngine() : wxObject() {m_Keyword = NULL;}
379 ~wxSearchEngine() {if (m_Keyword) free(m_Keyword);}
381 void LookFor(const wxString& keyword);
382 // Sets the keyword we will be searching for
384 bool Scan(wxInputStream *stream);
385 // Scans the stream for the keyword.
386 // Returns TRUE if the stream contains keyword, fALSE otherwise
388 bool ScanFile(const wxString& filename) {
389 if (filename.IsEmpty())
391 wxFileInputStream istr(filename);
392 return self->Scan(&istr);
398 //---------------------------------------------------------------------------
402 /* This is a bit cheesy. SWIG happens to call the dictionary d...
403 * I save it here, 'cause I don't know how to get it back later! */
405 wxPyThreadState = PyThreadState_Get();
406 wxClassInfo::CleanUpClasses();
407 wxClassInfo::InitializeClasses();
409 /* specifically add our python tag handler; it doesn't seem to
410 * happen by itself... */
411 wxHtmlWinParser::AddModule(new HTML_ModulePythonTag());
413 // Until wxFileSystem is wrapped...
415 wxFileSystem::AddHandler(new wxZipFSHandler);
419 //---------------------------------------------------------------------------