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>
25 //---------------------------------------------------------------------------
28 %include my_typemaps.i
39 //---------------------------------------------------------------------------
43 wxString wxPyEmptyStr("");
44 wxPoint wxPyDefaultPosition(wxDefaultPosition);
45 wxSize wxPyDefaultSize(wxDefaultSize);
49 %pragma(python) code = "import wx"
50 %pragma(python) code = "widget = htmlc"
55 static PyObject* mod_dict = NULL; // will be set by init
57 #include <wx/html/mod_templ.h>
59 TAG_HANDLER_BEGIN(PYTHONTAG, "PYTHON")
68 bool doSave = wxPyRestoreThread();
70 if (tag.HasParam("FLOAT"))
71 tag.ScanParam("FLOAT", "%i", &fl);
72 PyObject* pyfunc = PyDict_GetItemString(mod_dict, "WidgetStarter");
74 errmsg = "Could not find object WidgetStarter";
77 if (! PyCallable_Check(pyfunc)) {
78 errmsg = "WidgetStarter does not appear to be callable";
81 SWIG_MakePtr(pbuf, m_WParser->GetWindow(), "_wxPyHtmlWindow_p");
82 PyObject* arglist = Py_BuildValue("(s,s)", pbuf,
83 (const char*)tag.GetAllParams());
85 errmsg = "Failed making argument list";
88 PyObject* ret = PyEval_CallObject(pyfunc, arglist);
91 errmsg = "An error occured while calling WidgetStarter";
97 if (PyString_Check(ret)) {
98 char* thisc = PyString_AsString(ret);
99 SWIG_GetPtr(thisc, (void**)&wnd, "_wxWindow_p");
103 errmsg = "Could not make a wxWindow pointer from return ptr";
106 wxPySaveThread(doSave);
108 m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, fl));
112 wxPySaveThread(doSave);
114 /* we got out of the loop. Must be an error. Show a box stating it. */
115 wnd = new wxTextCtrl( m_WParser -> GetWindow(), -1,
116 errmsg, wxPoint(0,0),
117 wxSize(300, 100), wxTE_MULTILINE );
119 m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, 100));
123 TAG_HANDLER_END(PYTHONTAG)
125 TAGS_MODULE_BEGIN(PythonTag)
127 TAGS_MODULE_ADD(PYTHONTAG)
129 TAGS_MODULE_END(PythonTag)
131 // Note: see also the init function where we add the module!
135 //---------------------------------------------------------------------------
155 HTML_INDENT_HORIZONTAL,
156 HTML_INDENT_VERTICAL,
160 HTML_COND_ISIMAGEMAP,
165 //---------------------------------------------------------------------------
169 // Never need to create a new tag from Python...
170 //wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
173 bool HasParam(const wxString& par);
174 wxString GetParam(const wxString& par, int with_commas = FALSE);
176 // Can't do this one as-is, but GetParam should be enough...
177 //int ScanParam(const wxString& par, const char *format, void* param);
179 wxString GetAllParams();
188 //---------------------------------------------------------------------------
192 // wxHtmlParser(); This is an abstract base class...
194 void SetFS(wxFileSystem *fs);
195 wxFileSystem* GetFS();
196 wxObject* Parse(const wxString& source);
197 void InitParser(const wxString& source);
199 void DoParsing(int begin_pos, int end_pos);
200 // wxObject* GetProduct();
201 void AddTagHandler(wxHtmlTagHandler *handler);
202 wxString* GetSource();
205 // void AddText(const char* txt) = 0;
206 // void AddTag(const wxHtmlTag& tag);
210 //---------------------------------------------------------------------------
212 class wxHtmlWinParser : public wxHtmlParser {
214 wxHtmlWinParser(wxWindow *wnd);
216 void SetDC(wxDC *dc);
220 wxWindow* GetWindow();
221 void SetFonts(wxString normal_face, int normal_italic_mode,
222 wxString fixed_face, int fixed_italic_mode, int *LIST);
224 wxHtmlContainerCell* GetContainer();
225 wxHtmlContainerCell* OpenContainer();
226 wxHtmlContainerCell* CloseContainer();
228 void SetFontSize(int s);
230 void SetFontBold(int x);
232 void SetFontItalic(int x);
233 int GetFontUnderlined();
234 void SetFontUnderlined(int x);
236 void SetFontFixed(int x);
238 void SetAlign(int a);
239 const wxColour& GetLinkColor();
240 void SetLinkColor(const wxColour& clr);
241 const wxColour& GetActualColor();
242 void SetActualColor(const wxColour& clr);
243 const wxString& GetLink();
244 void SetLink(const wxString& link);
245 wxFont* CreateCurrentFont();
250 //---------------------------------------------------------------------------
253 class wxPyHtmlTagHandler : public wxHtmlTagHandler {
255 wxPyHtmlTagHandler() : wxHtmlTagHandler() {};
257 wxHtmlParser* GetParser() { return m_Parser; }
258 void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); }
260 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
261 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
266 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
267 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
271 %name(wxHtmlTagHandler) class wxPyHtmlTagHandler {
273 wxPyHtmlTagHandler();
275 void _setSelf(PyObject* self);
276 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
278 void SetParser(wxHtmlParser *parser);
279 wxHtmlParser* GetParser();
280 void ParseInner(const wxHtmlTag& tag);
284 //---------------------------------------------------------------------------
287 class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
289 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
291 wxHtmlWinParser* GetParser() { return m_WParser; }
292 void ParseInner(const wxHtmlTag& tag)
293 { wxHtmlWinTagHandler::ParseInner(tag); }
295 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
296 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
301 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
302 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
306 %name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
308 wxPyHtmlWinTagHandler();
310 void _setSelf(PyObject* self);
311 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
313 void SetParser(wxHtmlParser *parser);
314 wxHtmlWinParser* GetParser();
315 void ParseInner(const wxHtmlTag& tag);
319 //---------------------------------------------------------------------------
323 class wxPyHtmlTagsModule : public wxHtmlTagsModule {
325 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
326 m_tagHandlerClass = thc;
327 Py_INCREF(m_tagHandlerClass);
328 RegisterModule(this);
329 wxHtmlWinParser::AddModule(this);
333 Py_DECREF(m_tagHandlerClass);
334 m_tagHandlerClass = NULL;
335 for (int x=0; x < m_objArray.GetCount(); x++) {
336 PyObject* obj = (PyObject*)m_objArray.Item(x);
341 void FillHandlersTable(wxHtmlWinParser *parser) {
342 // Wave our magic wand... (if it works it's a miracle! ;-)
344 // First, make a new instance of the tag handler
345 bool doSave = wxPyRestoreThread();
346 PyObject* arg = Py_BuildValue("()");
347 PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
349 wxPySaveThread(doSave);
351 // now figure out where it's C++ object is...
352 wxPyHtmlWinTagHandler* thPtr;
353 if (SWIG_GetPtrObj(obj, (void **)&thPtr, "_wxPyHtmlWinTagHandler_p"))
357 parser->AddTagHandler(thPtr);
364 PyObject* m_tagHandlerClass;
365 wxArrayPtrVoid m_objArray;
373 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
374 // Dynamically create a new wxModule. Refcounts tagHandlerClass
375 // and adds itself to the wxModules list and to the wxHtmlWinParser.
376 new wxPyHtmlTagsModule(tagHandlerClass);
380 //---------------------------------------------------------------------------
381 //---------------------------------------------------------------------------
387 void SetParent(wxHtmlContainerCell *p);
388 wxHtmlContainerCell* GetParent();
394 wxString GetLink(int x = 0, int y = 0);
395 wxHtmlCell* GetNext();
396 void SetPos(int x, int y);
397 void SetLink(const wxString& link);
398 void SetNext(wxHtmlCell *cell);
400 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
401 void DrawInvisible(wxDC& dc, int x, int y);
402 const wxHtmlCell* Find(int condition, const void* param);
406 class wxHtmlContainerCell : public wxHtmlCell {
408 wxHtmlContainerCell(wxHtmlContainerCell *parent);
410 void InsertCell(wxHtmlCell *cell);
411 void SetAlignHor(int al);
413 void SetAlignVer(int al);
415 void SetIndent(int i, int what, int units = HTML_UNITS_PIXELS);
416 int GetIndent(int ind);
417 int GetIndentUnits(int ind);
418 void SetAlign(const wxHtmlTag& tag);
419 void SetWidthFloat(int w, int units);
420 %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
421 void SetMinHeight(int h, int align = HTML_ALIGN_TOP);
422 int GetMaxLineWidth();
423 void SetBackgroundColour(const wxColour& clr);
424 void SetBorder(const wxColour& clr1, const wxColour& clr2);
425 wxHtmlCell* GetFirstCell();
431 class wxHtmlWidgetCell : public wxHtmlCell {
433 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
439 //---------------------------------------------------------------------------
440 //---------------------------------------------------------------------------
441 //---------------------------------------------------------------------------
443 // item of history list
444 class HtmlHistoryItem {
446 HtmlHistoryItem(const char* p, const char* a);
450 const wxString& GetPage();
451 const wxString& GetAnchor();
455 //---------------------------------------------------------------------------
457 class wxPyHtmlWindow : public wxHtmlWindow {
459 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
460 const wxPoint& pos = wxDefaultPosition,
461 const wxSize& size = wxDefaultSize,
462 long style = wxHW_SCROLLBAR_AUTO,
463 const wxString& name = "htmlWindow")
464 : wxHtmlWindow(parent, id, pos, size, style, name) {};
466 DEC_PYCALLBACK__STRING(OnLinkClicked);
471 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnLinkClicked);
476 %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
478 wxPyHtmlWindow(wxWindow *parent, int id = -1,
479 wxPoint& pos = wxPyDefaultPosition,
480 wxSize& size = wxPyDefaultSize,
481 int flags=wxHW_SCROLLBAR_AUTO,
482 char* name = "htmlWindow");
484 void _setSelf(PyObject* self);
485 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
486 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
487 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
490 bool SetPage(const char* source);
491 bool LoadPage(const char* location);
492 wxString GetOpenedPage();
493 void SetRelatedFrame(wxFrame* frame, const char* format);
494 wxFrame* GetRelatedFrame();
495 void SetRelatedStatusBar(int bar);
496 void SetFonts(wxString normal_face, int normal_italic_mode,
497 wxString fixed_face, int fixed_italic_mode, int *LIST);
498 void SetTitle(const char* title);
499 void SetBorders(int b);
500 void ReadCustomization(wxConfigBase *cfg, char* path = "");
501 void WriteCustomization(wxConfigBase *cfg, char* path = "");
503 bool HistoryForward();
505 wxHtmlContainerCell* GetInternalRepresentation();
506 wxHtmlWinParser* GetParser();
509 void base_OnLinkClicked(const char* link);
512 // Static methods are mapped to stand-alone functions
514 void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) {
515 wxHtmlWindow::AddFilter(filter);
520 //---------------------------------------------------------------------------
521 //---------------------------------------------------------------------------
524 extern "C" SWIGEXPORT(void) inithtmlhelpc();
531 /* This is a bit cheesy. SWIG happens to call the dictionary d...
532 * I save it here, 'cause I don't know how to get it back later! */
538 wxClassInfo::CleanUpClasses();
539 wxClassInfo::InitializeClasses();
542 /* specifically add our python tag handler; it doesn't seem to
543 * happen by itself... */
544 wxHtmlWinParser::AddModule(new HTML_ModulePythonTag());
547 // Until wxFileSystem is wrapped...
549 wxFileSystem::AddHandler(new wxZipFSHandler);
553 //----------------------------------------------------------------------
554 // And this gets appended to the shadow class file.
555 //----------------------------------------------------------------------
557 %pragma(python) include="_extras.py";
559 //---------------------------------------------------------------------------