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>
19 #include <wx/html/htmprint.h>
21 #include <wx/fs_zip.h>
22 #include <wx/fs_inet.h>
23 #include <wx/wfstream.h>
28 //---------------------------------------------------------------------------
31 %include my_typemaps.i
43 //---------------------------------------------------------------------------
47 wxString wxPyEmptyStr("");
48 wxPoint wxPyDefaultPosition(wxDefaultPosition);
49 wxSize wxPyDefaultSize(wxDefaultSize);
53 %pragma(python) code = "import wx"
54 %pragma(python) code = "widget = htmlc"
59 static PyObject* mod_dict = NULL; // will be set by init
61 #include <wx/html/mod_templ.h>
63 TAG_HANDLER_BEGIN(PYTHONTAG, "PYTHON")
72 bool doSave = wxPyRestoreThread();
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(), "_wxPyHtmlWindow_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 wxPySaveThread(doSave);
112 m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, fl));
116 wxPySaveThread(doSave);
118 /* we got out of the loop. Must be an error. Show a box stating it. */
119 wnd = new wxTextCtrl( m_WParser -> GetWindow(), -1,
120 errmsg, wxPoint(0,0),
121 wxSize(300, 100), wxTE_MULTILINE );
123 m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, 100));
127 TAG_HANDLER_END(PYTHONTAG)
129 TAGS_MODULE_BEGIN(PythonTag)
131 TAGS_MODULE_ADD(PYTHONTAG)
133 TAGS_MODULE_END(PythonTag)
135 // Note: see also the init function where we add the module!
139 //---------------------------------------------------------------------------
148 wxHTML_CLR_FOREGROUND,
149 wxHTML_CLR_BACKGROUND,
152 wxHTML_UNITS_PERCENT,
157 wxHTML_INDENT_BOTTOM,
159 wxHTML_INDENT_HORIZONTAL,
160 wxHTML_INDENT_VERTICAL,
163 wxHTML_COND_ISANCHOR,
164 wxHTML_COND_ISIMAGEMAP,
169 //---------------------------------------------------------------------------
173 // Never need to create a new tag from Python...
174 //wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
177 bool HasParam(const wxString& par);
178 wxString GetParam(const wxString& par, int with_commas = FALSE);
180 // Can't do this one as-is, but GetParam should be enough...
181 //int ScanParam(const wxString& par, const char *format, void* param);
183 wxString GetAllParams();
192 //---------------------------------------------------------------------------
196 // wxHtmlParser(); This is an abstract base class...
198 void SetFS(wxFileSystem *fs);
199 wxFileSystem* GetFS();
200 wxObject* Parse(const wxString& source);
201 void InitParser(const wxString& source);
203 void DoParsing(int begin_pos, int end_pos);
204 // wxObject* GetProduct();
205 void AddTagHandler(wxHtmlTagHandler *handler);
206 wxString* GetSource();
207 void PushTagHandler(wxHtmlTagHandler* handler, wxString tags);
208 void PopTagHandler();
211 // void AddText(const char* txt) = 0;
212 // void AddTag(const wxHtmlTag& tag);
216 //---------------------------------------------------------------------------
218 class wxHtmlWinParser : public wxHtmlParser {
220 wxHtmlWinParser(wxWindow *wnd);
222 void SetDC(wxDC *dc);
226 wxWindow* GetWindow();
227 void SetFonts(wxString normal_face, int normal_italic_mode,
228 wxString fixed_face, int fixed_italic_mode, int *LIST);
230 wxHtmlContainerCell* GetContainer();
231 wxHtmlContainerCell* OpenContainer();
232 wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
233 wxHtmlContainerCell* CloseContainer();
236 void SetFontSize(int s);
238 void SetFontBold(int x);
240 void SetFontItalic(int x);
241 int GetFontUnderlined();
242 void SetFontUnderlined(int x);
244 void SetFontFixed(int x);
246 void SetAlign(int a);
247 const wxColour& GetLinkColor();
248 void SetLinkColor(const wxColour& clr);
249 const wxColour& GetActualColor();
250 void SetActualColor(const wxColour& clr);
251 const wxString& GetLink();
252 void SetLink(const wxString& link);
253 wxFont* CreateCurrentFont();
258 //---------------------------------------------------------------------------
261 class wxPyHtmlTagHandler : public wxHtmlTagHandler {
263 wxPyHtmlTagHandler() : wxHtmlTagHandler() {};
265 wxHtmlParser* GetParser() { return m_Parser; }
266 void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); }
268 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
269 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
274 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
275 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
279 %name(wxHtmlTagHandler) class wxPyHtmlTagHandler {
281 wxPyHtmlTagHandler();
283 void _setSelf(PyObject* self);
284 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
286 void SetParser(wxHtmlParser *parser);
287 wxHtmlParser* GetParser();
288 void ParseInner(const wxHtmlTag& tag);
292 //---------------------------------------------------------------------------
295 class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
297 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
299 wxHtmlWinParser* GetParser() { return m_WParser; }
300 void ParseInner(const wxHtmlTag& tag)
301 { wxHtmlWinTagHandler::ParseInner(tag); }
303 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
304 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
309 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
310 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
314 %name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
316 wxPyHtmlWinTagHandler();
318 void _setSelf(PyObject* self);
319 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
321 void SetParser(wxHtmlParser *parser);
322 wxHtmlWinParser* GetParser();
323 void ParseInner(const wxHtmlTag& tag);
327 //---------------------------------------------------------------------------
331 class wxPyHtmlTagsModule : public wxHtmlTagsModule {
333 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
334 m_tagHandlerClass = thc;
335 Py_INCREF(m_tagHandlerClass);
336 RegisterModule(this);
337 wxHtmlWinParser::AddModule(this);
341 Py_DECREF(m_tagHandlerClass);
342 m_tagHandlerClass = NULL;
343 for (size_t x=0; x < m_objArray.GetCount(); x++) {
344 PyObject* obj = (PyObject*)m_objArray.Item(x);
349 void FillHandlersTable(wxHtmlWinParser *parser) {
350 // Wave our magic wand... (if it works it's a miracle! ;-)
352 // First, make a new instance of the tag handler
353 bool doSave = wxPyRestoreThread();
354 PyObject* arg = Py_BuildValue("()");
355 PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
357 wxPySaveThread(doSave);
359 // now figure out where it's C++ object is...
360 wxPyHtmlWinTagHandler* thPtr;
361 if (SWIG_GetPtrObj(obj, (void **)&thPtr, "_wxPyHtmlWinTagHandler_p"))
365 parser->AddTagHandler(thPtr);
372 PyObject* m_tagHandlerClass;
373 wxArrayPtrVoid m_objArray;
381 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
382 // Dynamically create a new wxModule. Refcounts tagHandlerClass
383 // and adds itself to the wxModules list and to the wxHtmlWinParser.
384 new wxPyHtmlTagsModule(tagHandlerClass);
389 //---------------------------------------------------------------------------
390 //---------------------------------------------------------------------------
396 void SetParent(wxHtmlContainerCell *p);
397 wxHtmlContainerCell* GetParent();
403 wxString GetLink(int x = 0, int y = 0);
404 wxHtmlCell* GetNext();
405 void SetPos(int x, int y);
406 void SetLink(const wxString& link);
407 void SetNext(wxHtmlCell *cell);
409 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
410 void DrawInvisible(wxDC& dc, int x, int y);
411 const wxHtmlCell* Find(int condition, const void* param);
413 bool AdjustPagebreak(int * pagebreak);
414 void SetCanLiveOnPagebreak(bool can);
418 class wxHtmlContainerCell : public wxHtmlCell {
420 wxHtmlContainerCell(wxHtmlContainerCell *parent);
422 void InsertCell(wxHtmlCell *cell);
423 void SetAlignHor(int al);
425 void SetAlignVer(int al);
427 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
428 int GetIndent(int ind);
429 int GetIndentUnits(int ind);
430 void SetAlign(const wxHtmlTag& tag);
431 void SetWidthFloat(int w, int units);
432 %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
433 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
434 int GetMaxLineWidth();
435 void SetBackgroundColour(const wxColour& clr);
436 void SetBorder(const wxColour& clr1, const wxColour& clr2);
437 wxHtmlCell* GetFirstCell();
443 class wxHtmlWidgetCell : public wxHtmlCell {
445 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
451 //---------------------------------------------------------------------------
452 //---------------------------------------------------------------------------
453 //---------------------------------------------------------------------------
455 // item of history list
456 class HtmlHistoryItem {
458 HtmlHistoryItem(const char* p, const char* a);
462 const wxString& GetPage();
463 const wxString& GetAnchor();
467 //---------------------------------------------------------------------------
469 class wxPyHtmlWindow : public wxHtmlWindow {
471 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
472 const wxPoint& pos = wxDefaultPosition,
473 const wxSize& size = wxDefaultSize,
474 long style = wxHW_SCROLLBAR_AUTO,
475 const wxString& name = "htmlWindow")
476 : wxHtmlWindow(parent, id, pos, size, style, name) {};
478 DEC_PYCALLBACK__STRING(OnLinkClicked);
483 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnLinkClicked);
488 %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
490 wxPyHtmlWindow(wxWindow *parent, int id = -1,
491 wxPoint& pos = wxPyDefaultPosition,
492 wxSize& size = wxPyDefaultSize,
493 int flags=wxHW_SCROLLBAR_AUTO,
494 char* name = "htmlWindow");
496 void _setSelf(PyObject* self);
497 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
498 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
499 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
502 bool SetPage(const char* source);
503 bool LoadPage(const char* location);
504 wxString GetOpenedPage();
505 void SetRelatedFrame(wxFrame* frame, const char* format);
506 wxFrame* GetRelatedFrame();
507 void SetRelatedStatusBar(int bar);
508 void SetFonts(wxString normal_face, int normal_italic_mode,
509 wxString fixed_face, int fixed_italic_mode, int *LIST);
510 void SetTitle(const char* title);
511 void SetBorders(int b);
512 void ReadCustomization(wxConfigBase *cfg, char* path = "");
513 void WriteCustomization(wxConfigBase *cfg, char* path = "");
515 bool HistoryForward();
517 wxHtmlContainerCell* GetInternalRepresentation();
518 wxHtmlWinParser* GetParser();
521 void base_OnLinkClicked(const char* link);
524 // Static methods are mapped to stand-alone functions
526 void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) {
527 wxHtmlWindow::AddFilter(filter);
532 //---------------------------------------------------------------------------
533 //---------------------------------------------------------------------------
536 class wxHtmlDCRenderer {
541 void SetDC(wxDC *dc, int maxwidth);
542 void SetSize(int width, int height);
543 void SetHtmlText(const wxString& html,
544 const wxString& basepath = wxEmptyString,
546 int Render(int x, int y, int from = 0, int dont_render = FALSE);
547 int GetTotalHeight();
548 // returns total height of the html document
549 // (compare Render's return value with this)
559 class wxHtmlPrintout : public wxPyPrintout {
561 wxHtmlPrintout(const wxString& title = "Printout");
564 void SetHtmlText(const wxString& html,
565 const wxString &basepath = wxEmptyString,
567 void SetHtmlFile(const wxString &htmlfile);
568 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
569 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
570 void SetMargins(float top = 25.2, float bottom = 25.2,
571 float left = 25.2, float right = 25.2,
577 class wxHtmlEasyPrinting {
579 wxHtmlEasyPrinting(const wxString& name = "Printing",
580 wxFrame *parent_frame = NULL);
581 ~wxHtmlEasyPrinting();
583 void PreviewFile(const wxString &htmlfile);
584 void PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
585 void PrintFile(const wxString &htmlfile);
586 void PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
589 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
590 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
592 wxPrintData *GetPrintData() {return m_PrintData;}
593 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
599 //---------------------------------------------------------------------------
600 //---------------------------------------------------------------------------
603 extern "C" SWIGEXPORT(void) inithtmlhelpc();
610 /* This is a bit cheesy. SWIG happens to call the dictionary d...
611 * I save it here, 'cause I don't know how to get it back later! */
617 wxClassInfo::CleanUpClasses();
618 wxClassInfo::InitializeClasses();
621 /* specifically add our python tag handler; it doesn't seem to
622 * happen by itself... */
623 wxHtmlWinParser::AddModule(new HTML_ModulePythonTag());
626 // Until wxFileSystem is wrapped...
628 wxFileSystem::AddHandler(new wxZipFSHandler);
632 //----------------------------------------------------------------------
633 // And this gets appended to the shadow class file.
634 //----------------------------------------------------------------------
636 %pragma(python) include="_extras.py";
638 //---------------------------------------------------------------------------