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 %pragma(python) code = "import wx"
46 //---------------------------------------------------------------------------
55 wxHTML_CLR_FOREGROUND,
56 wxHTML_CLR_BACKGROUND,
66 wxHTML_INDENT_HORIZONTAL,
67 wxHTML_INDENT_VERTICAL,
71 wxHTML_COND_ISIMAGEMAP,
76 //---------------------------------------------------------------------------
78 class wxHtmlLinkInfo : public wxObject {
80 wxHtmlLinkInfo(const wxString& href, const wxString& target = wxEmptyString);
83 wxMouseEvent* GetEvent();
84 wxHtmlCell* GetHtmlCell();
86 void SetEvent(const wxMouseEvent *e);
87 void SetHtmlCell(const wxHtmlCell * e);
90 //---------------------------------------------------------------------------
92 class wxHtmlTag : public wxObject {
94 // Never need to create a new tag from Python...
95 //wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
98 bool HasParam(const wxString& par);
99 wxString GetParam(const wxString& par, int with_commas = FALSE);
101 // Can't do this one as-is, but GetParam should be enough...
102 //int ScanParam(const wxString& par, const char *format, void* param);
104 wxString GetAllParams();
112 //---------------------------------------------------------------------------
114 class wxHtmlParser : public wxObject {
116 // wxHtmlParser(); This is an abstract base class...
118 void SetFS(wxFileSystem *fs);
119 wxFileSystem* GetFS();
120 wxObject* Parse(const wxString& source);
121 void InitParser(const wxString& source);
123 void DoParsing(int begin_pos, int end_pos);
124 // wxObject* GetProduct();
125 void AddTagHandler(wxHtmlTagHandler *handler);
126 wxString* GetSource();
127 void PushTagHandler(wxHtmlTagHandler* handler, wxString tags);
128 void PopTagHandler();
130 // Returns TRUE if the parser is allowed to open given URL (may be forbidden
131 // for security reasons)
132 virtual bool CanOpenURL(const wxString& url) const { return TRUE; }
134 // void AddText(const char* txt) = 0;
135 // void AddTag(const wxHtmlTag& tag);
139 //---------------------------------------------------------------------------
141 class wxHtmlWinParser : public wxHtmlParser {
143 wxHtmlWinParser(wxHtmlWindow *wnd = NULL);
145 void SetDC(wxDC *dc);
149 wxHtmlWindow* GetWindow();
150 //void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
152 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes) {
153 int* temp = int_LIST_helper(sizes);
155 self->SetFonts(normal_face, fixed_face, temp);
161 wxHtmlContainerCell* GetContainer();
162 wxHtmlContainerCell* OpenContainer();
163 wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
164 wxHtmlContainerCell* CloseContainer();
167 void SetFontSize(int s);
169 void SetFontBold(int x);
171 void SetFontItalic(int x);
172 int GetFontUnderlined();
173 void SetFontUnderlined(int x);
175 void SetFontFixed(int x);
177 void SetAlign(int a);
178 wxColour GetLinkColor();
179 void SetLinkColor(const wxColour& clr);
180 wxColour GetActualColor();
181 void SetActualColor(const wxColour& clr);
182 void SetLink(const wxString& link);
183 wxFont* CreateCurrentFont();
184 wxHtmlLinkInfo GetLink();
190 //---------------------------------------------------------------------------
193 class wxPyHtmlTagHandler : public wxHtmlTagHandler {
194 DECLARE_DYNAMIC_CLASS(wxPyHtmlTagHandler);
196 wxPyHtmlTagHandler() : wxHtmlTagHandler() {};
198 wxHtmlParser* GetParser() { return m_Parser; }
199 void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); }
201 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
202 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
207 IMPLEMENT_DYNAMIC_CLASS(wxPyHtmlTagHandler, wxHtmlTagHandler);
209 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
210 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
214 %name(wxHtmlTagHandler) class wxPyHtmlTagHandler : public wxObject {
216 wxPyHtmlTagHandler();
218 void _setCallbackInfo(PyObject* self, PyObject* _class);
219 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxHtmlTagHandler)"
221 void SetParser(wxHtmlParser *parser);
222 wxHtmlParser* GetParser();
223 void ParseInner(const wxHtmlTag& tag);
227 //---------------------------------------------------------------------------
230 class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
231 DECLARE_DYNAMIC_CLASS(wxPyHtmlWinTagHandler);
233 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
235 wxHtmlWinParser* GetParser() { return m_WParser; }
236 void ParseInner(const wxHtmlTag& tag)
237 { wxHtmlWinTagHandler::ParseInner(tag); }
239 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
240 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
245 IMPLEMENT_DYNAMIC_CLASS( wxPyHtmlWinTagHandler, wxHtmlWinTagHandler);
247 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
248 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
252 %name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
254 wxPyHtmlWinTagHandler();
256 void _setCallbackInfo(PyObject* self, PyObject* _class);
257 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxHtmlWinTagHandler)"
259 void SetParser(wxHtmlParser *parser);
260 wxHtmlWinParser* GetParser();
261 void ParseInner(const wxHtmlTag& tag);
265 //---------------------------------------------------------------------------
269 class wxPyHtmlTagsModule : public wxHtmlTagsModule {
271 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
272 m_tagHandlerClass = thc;
273 Py_INCREF(m_tagHandlerClass);
274 RegisterModule(this);
275 wxHtmlWinParser::AddModule(this);
279 wxPyBeginBlockThreads();
280 Py_DECREF(m_tagHandlerClass);
281 m_tagHandlerClass = NULL;
282 for (size_t x=0; x < m_objArray.GetCount(); x++) {
283 PyObject* obj = (PyObject*)m_objArray.Item(x);
286 wxPyEndBlockThreads();
289 void FillHandlersTable(wxHtmlWinParser *parser) {
290 // Wave our magic wand... (if it works it's a miracle! ;-)
292 // First, make a new instance of the tag handler
293 wxPyBeginBlockThreads();
294 PyObject* arg = Py_BuildValue("()");
295 PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
297 wxPyEndBlockThreads();
299 // now figure out where it's C++ object is...
300 wxPyHtmlWinTagHandler* thPtr;
301 if (SWIG_GetPtrObj(obj, (void **)&thPtr, "_wxPyHtmlWinTagHandler_p"))
305 parser->AddTagHandler(thPtr);
312 PyObject* m_tagHandlerClass;
313 wxArrayPtrVoid m_objArray;
321 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
322 // Dynamically create a new wxModule. Refcounts tagHandlerClass
323 // and adds itself to the wxModules list and to the wxHtmlWinParser.
324 new wxPyHtmlTagsModule(tagHandlerClass);
329 //---------------------------------------------------------------------------
330 //---------------------------------------------------------------------------
332 class wxHtmlCell : public wxObject {
341 wxHtmlLinkInfo* GetLink(int x = 0, int y = 0);
342 wxHtmlCell* GetNext();
343 wxHtmlContainerCell* GetParent();
344 void SetLink(const wxHtmlLinkInfo& link);
345 void SetNext(wxHtmlCell *cell);
346 void SetParent(wxHtmlContainerCell *p);
347 void SetPos(int x, int y);
349 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
350 void DrawInvisible(wxDC& dc, int x, int y);
351 const wxHtmlCell* Find(int condition, const void* param);
353 bool AdjustPagebreak(int * pagebreak);
354 void SetCanLiveOnPagebreak(bool can);
359 class wxHtmlWordCell : public wxHtmlCell
362 wxHtmlWordCell(const wxString& word, wxDC& dc);
366 class wxHtmlContainerCell : public wxHtmlCell {
368 wxHtmlContainerCell(wxHtmlContainerCell *parent);
370 void InsertCell(wxHtmlCell *cell);
371 void SetAlignHor(int al);
373 void SetAlignVer(int al);
375 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
376 int GetIndent(int ind);
377 int GetIndentUnits(int ind);
378 void SetAlign(const wxHtmlTag& tag);
379 void SetWidthFloat(int w, int units);
380 %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
381 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
382 void SetBackgroundColour(const wxColour& clr);
383 void SetBorder(const wxColour& clr1, const wxColour& clr2);
384 wxHtmlCell* GetFirstCell();
389 class wxHtmlColourCell : public wxHtmlCell {
391 wxHtmlColourCell(wxColour clr, int flags = wxHTML_CLR_FOREGROUND);
396 class wxHtmlFontCell : public wxHtmlCell
399 wxHtmlFontCell(wxFont *font);
403 class wxHtmlWidgetCell : public wxHtmlCell {
405 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
411 //---------------------------------------------------------------------------
412 //---------------------------------------------------------------------------
413 //---------------------------------------------------------------------------
416 class wxPyHtmlWindow : public wxHtmlWindow {
417 DECLARE_ABSTRACT_CLASS(wxPyHtmlWindow);
419 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
420 const wxPoint& pos = wxDefaultPosition,
421 const wxSize& size = wxDefaultSize,
422 long style = wxHW_SCROLLBAR_AUTO,
423 const wxString& name = "htmlWindow")
424 : wxHtmlWindow(parent, id, pos, size, style, name) {};
425 wxPyHtmlWindow() : wxHtmlWindow() {};
427 void OnLinkClicked(const wxHtmlLinkInfo& link);
428 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
430 DEC_PYCALLBACK__STRING(OnSetTitle);
431 DEC_PYCALLBACK__CELLINTINT(OnCellMouseHover);
432 DEC_PYCALLBACK__CELLINTINTME(OnCellClicked);
433 DEC_PYCALLBACK_BOOL_STRING(OnOpeningURL);
437 IMPLEMENT_ABSTRACT_CLASS( wxPyHtmlWindow, wxHtmlWindow );
438 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
439 IMP_PYCALLBACK__CELLINTINT(wxPyHtmlWindow, wxHtmlWindow, OnCellMouseHover);
440 IMP_PYCALLBACK__CELLINTINTME(wxPyHtmlWindow, wxHtmlWindow, OnCellClicked);
441 IMP_PYCALLBACK_BOOL_STRING(wxPyHtmlWindow, wxHtmlWindow, OnOpeningURL);
444 void wxPyHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) {
446 wxPyBeginBlockThreads();
447 if ((found = wxPyCBH_findCallback(m_myInst, "OnLinkClicked"))) {
448 PyObject* obj = wxPyConstructObject((void*)&link, "wxHtmlLinkInfo", 0);
449 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj));
452 wxPyEndBlockThreads();
454 wxHtmlWindow::OnLinkClicked(link);
456 void wxPyHtmlWindow::base_OnLinkClicked(const wxHtmlLinkInfo& link) {
457 wxHtmlWindow::OnLinkClicked(link);
464 %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
466 wxPyHtmlWindow(wxWindow *parent, int id = -1,
467 wxPoint& pos = wxDefaultPosition,
468 wxSize& size = wxDefaultSize,
469 int flags=wxHW_SCROLLBAR_AUTO,
470 char* name = "htmlWindow");
471 %name(wxPreHtmlWindow)wxPyHtmlWindow();
473 bool Create(wxWindow *parent, int id = -1,
474 wxPoint& pos = wxDefaultPosition,
475 wxSize& size = wxDefaultSize,
476 int flags=wxHW_SCROLLBAR_AUTO,
477 char* name = "htmlWindow");
480 void _setCallbackInfo(PyObject* self, PyObject* _class);
481 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxHtmlWindow)"
482 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
483 %pragma(python) addtomethod = "wxPreHtmlWindow:val._setOORInfo(val)"
485 bool SetPage(const wxString& source);
486 bool LoadPage(const wxString& location);
487 bool AppendToPage(const wxString& source);
488 wxString GetOpenedPage();
489 wxString GetOpenedAnchor();
490 wxString GetOpenedPageTitle();
492 void SetRelatedFrame(wxFrame* frame, const char* format);
493 wxFrame* GetRelatedFrame();
494 void SetRelatedStatusBar(int bar);
496 //void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
498 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes) {
499 int* temp = int_LIST_helper(sizes);
501 self->SetFonts(normal_face, fixed_face, temp);
507 void SetTitle(const wxString& title);
508 void SetBorders(int b);
509 void ReadCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
510 void WriteCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
512 bool HistoryForward();
513 bool HistoryCanBack();
514 bool HistoryCanForward();
516 wxHtmlContainerCell* GetInternalRepresentation();
517 wxHtmlWinParser* GetParser();
519 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
520 void base_OnSetTitle(const char* title);
521 void base_OnCellMouseHover(wxHtmlCell *cell, wxCoord x, wxCoord y);
522 void base_OnCellClicked(wxHtmlCell *cell,
523 wxCoord x, wxCoord y,
524 const wxMouseEvent& event);
527 // Static methods are mapped to stand-alone functions
529 void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) {
530 wxHtmlWindow::AddFilter(filter);
535 //---------------------------------------------------------------------------
536 //---------------------------------------------------------------------------
539 class wxHtmlDCRenderer : public wxObject {
544 void SetDC(wxDC *dc, int maxwidth);
545 void SetSize(int width, int height);
546 void SetHtmlText(const wxString& html,
547 const wxString& basepath = wxEmptyString,
549 int Render(int x, int y, int from = 0, int dont_render = FALSE);
550 int GetTotalHeight();
551 // returns total height of the html document
552 // (compare Render's return value with this)
562 class wxHtmlPrintout : public wxPyPrintout {
564 wxHtmlPrintout(const char* title = "Printout");
565 //~wxHtmlPrintout(); wxPrintPreview object takes ownership...
567 void SetHtmlText(const wxString& html,
568 const wxString &basepath = wxEmptyString,
570 void SetHtmlFile(const wxString &htmlfile);
571 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
572 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
573 void SetMargins(float top = 25.2, float bottom = 25.2,
574 float left = 25.2, float right = 25.2,
580 class wxHtmlEasyPrinting : public wxObject {
582 wxHtmlEasyPrinting(const char* name = "Printing",
583 wxFrame *parent_frame = NULL);
584 ~wxHtmlEasyPrinting();
586 void PreviewFile(const wxString &htmlfile);
587 void PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
588 void PrintFile(const wxString &htmlfile);
589 void PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
592 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
593 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
595 wxPrintData *GetPrintData() {return m_PrintData;}
596 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
602 //---------------------------------------------------------------------------
603 //---------------------------------------------------------------------------
606 extern "C" SWIGEXPORT(void) inithtmlhelpc();
614 wxClassInfo::CleanUpClasses();
615 wxClassInfo::InitializeClasses();
617 wxPyPtrTypeMap_Add("wxHtmlTagHandler", "wxPyHtmlTagHandler");
618 wxPyPtrTypeMap_Add("wxHtmlWinTagHandler", "wxPyHtmlWinTagHandler");
619 wxPyPtrTypeMap_Add("wxHtmlWindow", "wxPyHtmlWindow");
622 //----------------------------------------------------------------------
623 // And this gets appended to the shadow class file.
624 //----------------------------------------------------------------------
626 %pragma(python) include="_htmlextras.py";
628 //---------------------------------------------------------------------------