]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/modules/html/html.i
Added sh-bang
[wxWidgets.git] / utils / wxPython / modules / html / html.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: html.i
3 // Purpose: SWIG definitions of html classes
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 25-nov-1998
8 // RCS-ID: $Id$
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13
14 %module html
15
16 %{
17 #include "helpers.h"
18 #include <wx/html/htmlwin.h>
19 #include <wx/image.h>
20 #include <wx/fs_zip.h>
21 #include <wx/fs_inet.h>
22 #include <wx/wfstream.h>
23 #include "helpsys.h"
24 %}
25
26 //---------------------------------------------------------------------------
27
28 %include typemaps.i
29 %include my_typemaps.i
30
31 %extern wx.i
32 %extern windows.i
33 %extern _defs.i
34 %extern events.i
35 //%extern windows2.i
36 //%extern windows3.i
37 //%extern frames.i
38 //%extern misc.i
39 //%extern gdi.i
40 %extern controls.i
41 %extern controls2.i
42
43 %{
44 #ifdef __WXMSW__
45 static wxString wxPyEmptyStr("");
46 static wxPoint wxPyDefaultPosition(wxDefaultPosition);
47 static wxSize wxPyDefaultSize(wxDefaultSize);
48 #endif
49 static PyThreadState* wxPyThreadState;
50 %}
51
52 %pragma(python) code = "import wx,htmlhelper"
53 %pragma(python) code = "widget = htmlc"
54
55 %{
56
57 static PyObject* mod_dict = NULL; // will be set by init
58
59 #include <wx/html/mod_templ.h>
60
61 TAG_HANDLER_BEGIN(PYTHONTAG, "PYTHON")
62 TAG_HANDLER_PROC(tag)
63 {
64 wxWindow *wnd;
65 wxString errmsg;
66 char pbuf[256];
67
68 int fl = 0;
69
70 while (1) {
71 #ifdef WXP_WITH_THREAD
72 PyEval_RestoreThread(wxPyThreadState);
73 #endif
74 if (tag.HasParam("FLOAT"))
75 tag.ScanParam("FLOAT", "%i", &fl);
76 PyObject* pyfunc = PyDict_GetItemString(mod_dict, "WidgetStarter");
77 if (pyfunc == NULL) {
78 errmsg = "Could not find object WidgetStarter";
79 break;
80 }
81 if (! PyCallable_Check(pyfunc)) {
82 errmsg = "WidgetStarter does not appear to be callable";
83 break;
84 }
85 SWIG_MakePtr(pbuf, m_WParser->GetWindow(), "_wxHtmlWindow_p");
86 PyObject* arglist = Py_BuildValue("(s,s)", pbuf,
87 (const char*)tag.GetAllParams());
88 if (! arglist) {
89 errmsg = "Failed making argument list";
90 break;
91 }
92 PyObject* ret = PyEval_CallObject(pyfunc, arglist);
93 Py_DECREF(arglist);
94 if (ret == NULL) {
95 errmsg = "An error occured while calling WidgetStarter";
96 if (PyErr_Occurred())
97 PyErr_Print();
98 break;
99 }
100 wnd = NULL;
101 if (PyString_Check(ret)) {
102 char* thisc = PyString_AsString(ret);
103 SWIG_GetPtr(thisc, (void**)&wnd, "_wxWindow_p");
104 }
105 Py_DECREF(ret);
106 if (! wnd) {
107 errmsg = "Could not make a wxWindow pointer from return ptr";
108 break;
109 }
110 #ifdef WXP_WITH_THREAD
111 PyEval_SaveThread();
112 #endif
113 wnd -> Show(TRUE);
114 m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, fl));
115 return FALSE;
116 }
117
118 /* we got out of the loop. Must be an error. Show a box stating it. */
119
120 #ifdef WXP_WITH_THREAD
121 PyEval_SaveThread();
122 #endif
123
124 wnd = new wxTextCtrl( m_WParser -> GetWindow(), -1,
125 errmsg, wxPoint(0,0),
126 wxSize(300, 100), wxTE_MULTILINE );
127 wnd -> Show(TRUE);
128 m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, 100));
129 return FALSE;
130 }
131
132 TAG_HANDLER_END(PYTHONTAG)
133
134 TAGS_MODULE_BEGIN(PythonTag)
135
136 TAGS_MODULE_ADD(PYTHONTAG)
137
138 TAGS_MODULE_END(PythonTag)
139
140 // Note: see also the init function where we add the module!
141
142 %}
143
144 //---------------------------------------------------------------------------
145
146 // item of history list
147 class HtmlHistoryItem
148 {
149 public:
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 ;
155 };
156
157 class wxHtmlWindow : public wxScrolledWindow
158 {
159 public:
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)"
167
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
173
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
184
185 wxString GetOpenedPage() const {return m_OpenedPage;}
186 // Returns full location of opened page
187
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;
192
193 void SetRelatedStatusBar(int bar);
194 // after(!) calling SetRelatedFrame, this sets statusbar slot where messages
195 // will be displayed. Default is -1 = no messages.
196
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
200
201 void SetTitle(const char* title);
202 // Sets the title of the window
203 // (depending on the information passed to SetRelatedFrame() method)
204
205 void SetBorders(int b);
206 // Sets space between text and window borders.
207
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);
213 // ...
214
215 bool HistoryBack();
216 bool HistoryForward();
217 // Goes to previous/next page (in browsing history)
218 // Returns TRUE if successful, FALSE otherwise
219 void HistoryClear();
220 // Resets history
221
222 //wxHtmlContainerCell* GetInternalRepresentation() const;
223 // Returns pointer to conteiners/cells structure.
224 // It should be used ONLY when printing
225
226 //static void AddFilter(wxHtmlFilter *filter);
227 // Adds input filter
228
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)
233
234 //static void CleanUpStatics();
235 // cleans static variables
236
237 };
238
239 enum {
240 wxID_HTML_PANEL,
241 wxID_HTML_BACK,
242 wxID_HTML_FORWARD,
243 wxID_HTML_TREECTRL,
244 wxID_HTML_INDEXPAGE,
245 wxID_HTML_INDEXLIST,
246 wxID_HTML_NOTEBOOK,
247 wxID_HTML_SEARCHPAGE,
248 wxID_HTML_SEARCHTEXT,
249 wxID_HTML_SEARCHLIST,
250 wxID_HTML_SEARCHBUTTON
251 };
252
253 class wxHtmlHelpController : public wxEvtHandler
254 {
255 public:
256 wxHtmlHelpController();
257 ~wxHtmlHelpController();
258
259 // Images:
260 enum {
261 IMG_Book = 0,
262 IMG_Folder,
263 IMG_Page
264 };
265
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)
269
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.
274
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.
278 // Returns success.
279 // If show_wait_msg == true then message window with "loading book..." is displayed
280
281 void Display(const wxString& x);
282 // Displays page x. If not found it will offect the user a choice of searching
283 // books.
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)
293
294 void DisplayContents();
295 // Displays help window and focuses contents.
296
297 void DisplayIndex();
298 // Displays help window and focuses index.
299
300 bool KeywordSearch(const wxString& keyword);
301 // Searches for keyword. Returns TRUE and display page if found, return
302 // FALSE otherwise
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
309
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
314
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);
320 // ...
321 };
322
323 class wxHtmlHelpSystem : public wxHtmlHelpController
324 {
325 public:
326 wxHtmlHelpSystem() {};
327 ~wxHtmlHelpSystem() {};
328
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
347
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);
362
363 // some more protected functions that should be accessible from wxPython
364 void RefreshLists();
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
369 };
370
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
373 //#ifndef __WXMSW__
374 #ifdef THIS_IS_NOT_DEFINED_OKAY
375 class wxSearchEngine
376 {
377 public:
378 wxSearchEngine() : wxObject() {m_Keyword = NULL;}
379 ~wxSearchEngine() {if (m_Keyword) free(m_Keyword);}
380
381 void LookFor(const wxString& keyword);
382 // Sets the keyword we will be searching for
383
384 bool Scan(wxInputStream *stream);
385 // Scans the stream for the keyword.
386 // Returns TRUE if the stream contains keyword, fALSE otherwise
387 %addmethods {
388 bool ScanFile(const wxString& filename) {
389 if (filename.IsEmpty())
390 return false;
391 wxFileInputStream istr(filename);
392 return self->Scan(&istr);
393 }
394 }
395 };
396 #endif
397
398 //---------------------------------------------------------------------------
399
400 %init %{
401
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! */
404 mod_dict = d;
405 wxPyThreadState = PyThreadState_Get();
406 wxClassInfo::CleanUpClasses();
407 wxClassInfo::InitializeClasses();
408
409 /* specifically add our python tag handler; it doesn't seem to
410 * happen by itself... */
411 wxHtmlWinParser::AddModule(new HTML_ModulePythonTag());
412
413 // Until wxFileSystem is wrapped...
414 #if wxUSE_FS_ZIP
415 wxFileSystem::AddHandler(new wxZipFSHandler);
416 #endif
417 %}
418
419 //---------------------------------------------------------------------------