]>
Commit | Line | Data |
---|---|---|
4b123bb9 HH |
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> | |
5ca24bf4 HH |
22 | #include <wx/wfstream.h> |
23 | #include "helpsys.h" | |
4b123bb9 HH |
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 | |
5ca24bf4 HH |
35 | %extern controls.i |
36 | %extern controls2.i | |
4b123bb9 | 37 | |
0f66a9f3 RD |
38 | %extern utils.i |
39 | ||
40 | //--------------------------------------------------------------------------- | |
41 | ||
4b123bb9 HH |
42 | %{ |
43 | #ifdef __WXMSW__ | |
0f66a9f3 RD |
44 | wxString wxPyEmptyStr(""); |
45 | wxPoint wxPyDefaultPosition(wxDefaultPosition); | |
46 | wxSize wxPyDefaultSize(wxDefaultSize); | |
4b123bb9 | 47 | #endif |
4b123bb9 HH |
48 | %} |
49 | ||
50 | %pragma(python) code = "import wx,htmlhelper" | |
51 | %pragma(python) code = "widget = htmlc" | |
52 | ||
53 | %{ | |
54 | ||
55 | static PyObject* mod_dict = NULL; // will be set by init | |
56 | ||
57 | #include <wx/html/mod_templ.h> | |
58 | ||
59 | TAG_HANDLER_BEGIN(PYTHONTAG, "PYTHON") | |
60 | TAG_HANDLER_PROC(tag) | |
61 | { | |
0f66a9f3 RD |
62 | wxWindow *wnd; |
63 | wxString errmsg; | |
64 | char pbuf[256]; | |
65 | ||
66 | int fl = 0; | |
67 | ||
68 | bool doSave = wxPyRestoreThread(); | |
69 | while (1) { | |
70 | if (tag.HasParam("FLOAT")) | |
71 | tag.ScanParam("FLOAT", "%i", &fl); | |
72 | PyObject* pyfunc = PyDict_GetItemString(mod_dict, "WidgetStarter"); | |
73 | if (pyfunc == NULL) { | |
74 | errmsg = "Could not find object WidgetStarter"; | |
75 | break; | |
76 | } | |
77 | if (! PyCallable_Check(pyfunc)) { | |
78 | errmsg = "WidgetStarter does not appear to be callable"; | |
79 | break; | |
80 | } | |
81 | SWIG_MakePtr(pbuf, m_WParser->GetWindow(), "_wxPyHtmlWindow_p"); | |
4b123bb9 | 82 | PyObject* arglist = Py_BuildValue("(s,s)", pbuf, |
0f66a9f3 RD |
83 | (const char*)tag.GetAllParams()); |
84 | if (! arglist) { | |
85 | errmsg = "Failed making argument list"; | |
86 | break; | |
87 | } | |
88 | PyObject* ret = PyEval_CallObject(pyfunc, arglist); | |
89 | Py_DECREF(arglist); | |
90 | if (ret == NULL) { | |
4b123bb9 | 91 | errmsg = "An error occured while calling WidgetStarter"; |
0f66a9f3 RD |
92 | if (PyErr_Occurred()) |
93 | PyErr_Print(); | |
94 | break; | |
95 | } | |
96 | wnd = NULL; | |
97 | if (PyString_Check(ret)) { | |
98 | char* thisc = PyString_AsString(ret); | |
99 | SWIG_GetPtr(thisc, (void**)&wnd, "_wxWindow_p"); | |
100 | } | |
101 | Py_DECREF(ret); | |
102 | if (! wnd) { | |
4b123bb9 | 103 | errmsg = "Could not make a wxWindow pointer from return ptr"; |
0f66a9f3 RD |
104 | break; |
105 | } | |
106 | wxPySaveThread(doSave); | |
107 | wnd -> Show(TRUE); | |
108 | m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, fl)); | |
109 | return FALSE; | |
110 | } | |
111 | ||
112 | wxPySaveThread(doSave); | |
113 | ||
114 | /* we got out of the loop. Must be an error. Show a box stating it. */ | |
4b123bb9 | 115 | wnd = new wxTextCtrl( m_WParser -> GetWindow(), -1, |
0f66a9f3 RD |
116 | errmsg, wxPoint(0,0), |
117 | wxSize(300, 100), wxTE_MULTILINE ); | |
118 | wnd -> Show(TRUE); | |
119 | m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, 100)); | |
4b123bb9 HH |
120 | return FALSE; |
121 | } | |
0f66a9f3 | 122 | |
4b123bb9 HH |
123 | TAG_HANDLER_END(PYTHONTAG) |
124 | ||
125 | TAGS_MODULE_BEGIN(PythonTag) | |
126 | ||
127 | TAGS_MODULE_ADD(PYTHONTAG) | |
0f66a9f3 | 128 | |
4b123bb9 HH |
129 | TAGS_MODULE_END(PythonTag) |
130 | ||
131 | // Note: see also the init function where we add the module! | |
132 | ||
133 | %} | |
134 | ||
0f66a9f3 RD |
135 | //--------------------------------------------------------------------------- |
136 | //--------------------------------------------------------------------------- | |
137 | ||
138 | class wxHtmlTag { | |
139 | public: | |
140 | // Never need to create a new tag... | |
141 | //wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache); | |
142 | ||
143 | wxString GetName(); | |
144 | bool HasParam(const wxString& par); | |
145 | wxString GetParam(const wxString& par, int with_commas = FALSE); | |
146 | ||
147 | // Can't do this one as-is, but GetParam should be enough... | |
148 | //int ScanParam(const wxString& par, const char *format, void* param); | |
149 | ||
150 | wxString GetAllParams(); | |
151 | bool IsEnding(); | |
152 | bool HasEnding(); | |
153 | int GetBeginPos(); | |
154 | int GetEndPos1(); | |
155 | int GetEndPos2(); | |
156 | }; | |
157 | ||
158 | ||
159 | //--------------------------------------------------------------------------- | |
160 | ||
161 | class wxHtmlParser { | |
162 | public: | |
163 | // wxHtmlParser(); This is an abstract base class... | |
164 | ||
165 | void SetFS(wxFileSystem *fs); | |
166 | wxFileSystem* GetFS(); | |
167 | wxObject* Parse(const wxString& source); | |
168 | void InitParser(const wxString& source); | |
169 | void DoneParser(); | |
170 | void DoParsing(int begin_pos, int end_pos); | |
171 | // wxObject* GetProduct(); | |
172 | void AddTagHandler(wxHtmlTagHandler *handler); | |
173 | wxString* GetSource(); | |
174 | ||
175 | ||
176 | // void AddText(const char* txt) = 0; | |
177 | // void AddTag(const wxHtmlTag& tag); | |
178 | }; | |
179 | ||
180 | ||
181 | //--------------------------------------------------------------------------- | |
182 | ||
183 | class wxHtmlWinParser : public wxHtmlParser { | |
184 | public: | |
185 | wxHtmlWinParser(wxWindow *wnd); | |
186 | ||
187 | void SetDC(wxDC *dc); | |
188 | wxDC* GetDC(); | |
189 | int GetCharHeight(); | |
190 | int GetCharWidth(); | |
191 | wxWindow* GetWindow(); | |
192 | void SetFonts(wxString normal_face, int normal_italic_mode, | |
193 | wxString fixed_face, int fixed_italic_mode, int *LIST); | |
194 | ||
195 | wxHtmlContainerCell* GetContainer(); | |
196 | wxHtmlContainerCell* OpenContainer(); | |
197 | wxHtmlContainerCell* CloseContainer(); | |
198 | int GetFontSize(); | |
199 | void SetFontSize(int s); | |
200 | int GetFontBold(); | |
201 | void SetFontBold(int x); | |
202 | int GetFontItalic(); | |
203 | void SetFontItalic(int x); | |
204 | int GetFontUnderlined(); | |
205 | void SetFontUnderlined(int x); | |
206 | int GetFontFixed(); | |
207 | void SetFontFixed(int x); | |
208 | int GetAlign(); | |
209 | void SetAlign(int a); | |
210 | const wxColour& GetLinkColor(); | |
211 | void SetLinkColor(const wxColour& clr); | |
212 | const wxColour& GetActualColor(); | |
213 | void SetActualColor(const wxColour& clr); | |
214 | const wxString& GetLink(); | |
215 | void SetLink(const wxString& link); | |
216 | wxFont* CreateCurrentFont(); | |
217 | }; | |
218 | ||
219 | ||
220 | ||
221 | //--------------------------------------------------------------------------- | |
222 | ||
223 | %{ | |
224 | class wxPyHtmlTagHandler : public wxHtmlTagHandler { | |
225 | public: | |
226 | wxPyHtmlTagHandler() : wxHtmlTagHandler() {}; | |
227 | ||
228 | wxHtmlParser* GetParser() { return m_Parser; } | |
229 | void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); } | |
230 | ||
231 | DEC_PYCALLBACK_STRING__pure(GetSupportedTags); | |
232 | DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag); | |
233 | ||
234 | PYPRIVATE; | |
235 | }; | |
236 | ||
237 | IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags); | |
238 | IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag); | |
239 | ||
240 | %} | |
241 | ||
242 | ||
243 | %name(wxHtmlTagHandler) class wxPyHtmlTagHandler { | |
244 | public: | |
245 | wxPyHtmlTagHandler(); | |
246 | ||
247 | void _setSelf(PyObject* self); | |
248 | %pragma(python) addtomethod = "__init__:self._setSelf(self)" | |
249 | ||
250 | void SetParser(wxHtmlParser *parser); | |
251 | wxHtmlParser* GetParser(); | |
252 | void ParseInner(const wxHtmlTag& tag); | |
253 | }; | |
254 | ||
255 | ||
256 | //--------------------------------------------------------------------------- | |
257 | ||
258 | %{ | |
259 | class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler { | |
260 | public: | |
261 | wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {}; | |
262 | ||
263 | wxHtmlWinParser* GetParser() { return m_WParser; } | |
264 | void ParseInner(const wxHtmlTag& tag) | |
265 | { wxHtmlWinTagHandler::ParseInner(tag); } | |
266 | ||
267 | DEC_PYCALLBACK_STRING__pure(GetSupportedTags); | |
268 | DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag); | |
269 | ||
270 | PYPRIVATE; | |
271 | }; | |
272 | ||
273 | IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags); | |
274 | IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag); | |
275 | ||
276 | %} | |
277 | ||
278 | ||
279 | %name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler { | |
280 | public: | |
281 | wxPyHtmlWinTagHandler(); | |
282 | ||
283 | void _setSelf(PyObject* self); | |
284 | %pragma(python) addtomethod = "__init__:self._setSelf(self)" | |
285 | ||
286 | void SetParser(wxHtmlParser *parser); | |
287 | wxHtmlWinParser* GetParser(); | |
288 | void ParseInner(const wxHtmlTag& tag); | |
289 | }; | |
290 | ||
291 | ||
292 | //--------------------------------------------------------------------------- | |
293 | ||
294 | %{ | |
295 | ||
296 | class wxPyHtmlTagsModule : public wxHtmlTagsModule { | |
297 | public: | |
298 | wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() { | |
299 | m_tagHandlerClass = thc; | |
300 | Py_INCREF(m_tagHandlerClass); | |
301 | RegisterModule(this); | |
302 | wxHtmlWinParser::AddModule(this); | |
303 | } | |
304 | ||
305 | void OnExit() { | |
306 | Py_DECREF(m_tagHandlerClass); | |
307 | m_tagHandlerClass = NULL; | |
308 | for (int x=0; x < m_objArray.GetCount(); x++) { | |
309 | PyObject* obj = (PyObject*)m_objArray.Item(x); | |
310 | Py_DECREF(obj); | |
311 | } | |
312 | }; | |
313 | ||
314 | void FillHandlersTable(wxHtmlWinParser *parser) { | |
315 | // Wave our magic wand... (if it works it's a miracle! ;-) | |
316 | ||
317 | // First, make a new instance of the tag handler | |
318 | PyObject* arg = Py_BuildValue("()"); | |
319 | PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL); | |
320 | Py_DECREF(arg); | |
321 | ||
322 | // now figure out where it's C++ object is... | |
323 | wxPyHtmlWinTagHandler* thPtr; | |
324 | if (SWIG_GetPtrObj(obj, (void **)&thPtr, "_wxPyHtmlWinTagHandler_p")) | |
325 | return; | |
326 | ||
327 | // add it, | |
328 | parser->AddTagHandler(thPtr); | |
329 | ||
330 | // and track it. | |
331 | m_objArray.Add(obj); | |
332 | } | |
333 | ||
334 | private: | |
335 | PyObject* m_tagHandlerClass; | |
336 | wxArrayPtrVoid m_objArray; | |
337 | ||
338 | }; | |
339 | %} | |
340 | ||
341 | ||
342 | ||
343 | %inline %{ | |
344 | void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) { | |
345 | // Dynamically create a new wxModule. Refcounts tagHandlerClass | |
346 | // and adds itself to the wxModules list and to the wxHtmlWinParser. | |
347 | new wxPyHtmlTagsModule(tagHandlerClass); | |
348 | } | |
349 | %} | |
350 | ||
351 | ||
352 | ||
353 | //--------------------------------------------------------------------------- | |
354 | //--------------------------------------------------------------------------- | |
4b123bb9 HH |
355 | //--------------------------------------------------------------------------- |
356 | ||
357 | // item of history list | |
0f66a9f3 RD |
358 | class HtmlHistoryItem { |
359 | public: | |
360 | HtmlHistoryItem(const char* p, const char* a); | |
361 | ||
362 | int GetPos(); | |
363 | void SetPos(int p); | |
364 | const wxString& GetPage(); | |
365 | const wxString& GetAnchor(); | |
4b123bb9 HH |
366 | }; |
367 | ||
0f66a9f3 RD |
368 | |
369 | //--------------------------------------------------------------------------- | |
370 | %{ | |
371 | class wxPyHtmlWindow : public wxHtmlWindow { | |
372 | public: | |
373 | wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1, | |
374 | const wxPoint& pos = wxDefaultPosition, | |
375 | const wxSize& size = wxDefaultSize, | |
376 | long style = wxHW_SCROLLBAR_AUTO, | |
377 | const wxString& name = "htmlWindow") | |
378 | : wxHtmlWindow(parent, id, pos, size, style, name) {}; | |
379 | ||
380 | DEC_PYCALLBACK__STRING(OnLinkClicked); | |
381 | ||
382 | PYPRIVATE; | |
383 | }; | |
384 | ||
385 | IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnLinkClicked); | |
386 | ||
387 | %} | |
388 | ||
389 | ||
390 | %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow { | |
391 | public: | |
392 | wxPyHtmlWindow(wxWindow *parent, int id = -1, | |
393 | wxPoint& pos = wxPyDefaultPosition, | |
394 | wxSize& size = wxPyDefaultSize, | |
395 | int flags=wxHW_SCROLLBAR_AUTO, | |
396 | char* name = "htmlWindow"); | |
397 | ||
398 | void _setSelf(PyObject* self); | |
399 | %pragma(python) addtomethod = "__init__:self._setSelf(self)" | |
400 | %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)" | |
401 | %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)" | |
402 | ||
403 | ||
404 | bool SetPage(const char* source); | |
4b123bb9 | 405 | // Set HTML page and display it. !! source is HTML document itself, |
0f66a9f3 | 406 | // it is NOT address/filename of HTML document. If you want to |
4b123bb9 HH |
407 | // specify document location, use LoadPage() istead |
408 | // Return value : FALSE if an error occured, TRUE otherwise | |
0f66a9f3 RD |
409 | |
410 | bool LoadPage(const char* location); | |
4b123bb9 HH |
411 | // Load HTML page from given location. Location can be either |
412 | // a) /usr/wxGTK2/docs/html/wx.htm | |
413 | // b) http://www.somewhere.uk/document.htm | |
414 | // c) ftp://ftp.somesite.cz/pub/something.htm | |
415 | // In case there is no prefix (http:,ftp:), the method | |
416 | // will try to find it itself (1. local file, then http or ftp) | |
417 | // After the page is loaded, the method calls SetPage() to display it. | |
418 | // Note : you can also use path relative to previously loaded page | |
419 | // Return value : same as SetPage | |
420 | ||
0f66a9f3 | 421 | wxString GetOpenedPage(); |
4b123bb9 | 422 | // Returns full location of opened page |
0f66a9f3 RD |
423 | |
424 | void SetRelatedFrame(wxFrame* frame, const char* format); | |
4b123bb9 | 425 | // sets frame in which page title will be displayed. Format is format of |
0f66a9f3 RD |
426 | // frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s |
427 | wxFrame* GetRelatedFrame(); | |
4b123bb9 | 428 | |
0f66a9f3 | 429 | void SetRelatedStatusBar(int bar); |
4b123bb9 HH |
430 | // after(!) calling SetRelatedFrame, this sets statusbar slot where messages |
431 | // will be displayed. Default is -1 = no messages. | |
432 | ||
0f66a9f3 RD |
433 | void SetFonts(wxString normal_face, int normal_italic_mode, |
434 | wxString fixed_face, int fixed_italic_mode, int *LIST); | |
4b123bb9 HH |
435 | // sets fonts to be used when displaying HTML page. |
436 | // *_italic_mode can be either wxSLANT or wxITALIC | |
437 | ||
0f66a9f3 | 438 | void SetTitle(const char* title); |
4b123bb9 HH |
439 | // Sets the title of the window |
440 | // (depending on the information passed to SetRelatedFrame() method) | |
441 | ||
0f66a9f3 | 442 | void SetBorders(int b); |
4b123bb9 HH |
443 | // Sets space between text and window borders. |
444 | ||
0f66a9f3 | 445 | void ReadCustomization(wxConfigBase *cfg, char* path = ""); |
4b123bb9 HH |
446 | // saves custom settings into cfg config. it will use the path 'path' |
447 | // if given, otherwise it will save info into currently selected path. | |
448 | // saved values : things set by SetFonts, SetBorders. | |
0f66a9f3 RD |
449 | |
450 | void WriteCustomization(wxConfigBase *cfg, char* path = ""); | |
4b123bb9 HH |
451 | // ... |
452 | ||
0f66a9f3 RD |
453 | bool HistoryBack(); |
454 | bool HistoryForward(); | |
4b123bb9 HH |
455 | // Goes to previous/next page (in browsing history) |
456 | // Returns TRUE if successful, FALSE otherwise | |
0f66a9f3 | 457 | void HistoryClear(); |
4b123bb9 HH |
458 | // Resets history |
459 | ||
a65c6e14 | 460 | wxHtmlContainerCell* GetInternalRepresentation(); |
4b123bb9 HH |
461 | // Returns pointer to conteiners/cells structure. |
462 | // It should be used ONLY when printing | |
463 | ||
4b123bb9 | 464 | |
0f66a9f3 | 465 | void base_OnLinkClicked(const char* link); |
4b123bb9 HH |
466 | // called when users clicked on hypertext link. Default behavior is to |
467 | // call LoadPage(loc) | |
4b123bb9 HH |
468 | |
469 | }; | |
470 | ||
0f66a9f3 RD |
471 | // Static methods are mapped to stand-alone functions |
472 | %inline %{ | |
473 | void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) { | |
474 | wxHtmlWindow::AddFilter(filter); | |
475 | } | |
476 | %} | |
5ca24bf4 | 477 | |
5ca24bf4 | 478 | |
0f66a9f3 RD |
479 | //--------------------------------------------------------------------------- |
480 | //--------------------------------------------------------------------------- | |
5ca24bf4 | 481 | |
0f66a9f3 RD |
482 | %{ |
483 | extern "C" SWIGEXPORT(void) inithtmlhelpc(); | |
484 | %} | |
4b123bb9 | 485 | |
4b123bb9 HH |
486 | |
487 | %init %{ | |
488 | ||
0f66a9f3 | 489 | /* This is a bit cheesy. SWIG happens to call the dictionary d... |
4b123bb9 HH |
490 | * I save it here, 'cause I don't know how to get it back later! */ |
491 | mod_dict = d; | |
0f66a9f3 RD |
492 | |
493 | //inithtmlhelpc(); | |
494 | ||
4b123bb9 HH |
495 | wxClassInfo::CleanUpClasses(); |
496 | wxClassInfo::InitializeClasses(); | |
497 | ||
498 | /* specifically add our python tag handler; it doesn't seem to | |
499 | * happen by itself... */ | |
500 | wxHtmlWinParser::AddModule(new HTML_ModulePythonTag()); | |
0f66a9f3 | 501 | |
4b123bb9 HH |
502 | // Until wxFileSystem is wrapped... |
503 | #if wxUSE_FS_ZIP | |
504 | wxFileSystem::AddHandler(new wxZipFSHandler); | |
505 | #endif | |
506 | %} | |
507 | ||
508 | //--------------------------------------------------------------------------- |