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,
82 // enums for wxHtmlWindow::OnOpeningURL
83 enum wxHtmlOpeningStatus
97 //---------------------------------------------------------------------------
99 class wxHtmlLinkInfo : public wxObject {
101 wxHtmlLinkInfo(const wxString& href, const wxString& target = wxEmptyString);
103 wxString GetTarget();
104 wxMouseEvent* GetEvent();
105 wxHtmlCell* GetHtmlCell();
107 void SetEvent(const wxMouseEvent *e);
108 void SetHtmlCell(const wxHtmlCell * e);
111 //---------------------------------------------------------------------------
113 class wxHtmlTag : public wxObject {
115 // Never need to create a new tag from Python...
116 //wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
119 bool HasParam(const wxString& par);
120 wxString GetParam(const wxString& par, int with_commas = FALSE);
122 // Can't do this one as-is, but GetParam should be enough...
123 //int ScanParam(const wxString& par, const char *format, void* param);
125 wxString GetAllParams();
133 //---------------------------------------------------------------------------
135 class wxHtmlParser : public wxObject {
137 // wxHtmlParser(); This is an abstract base class...
139 void SetFS(wxFileSystem *fs);
140 wxFileSystem* GetFS();
141 wxObject* Parse(const wxString& source);
142 void InitParser(const wxString& source);
144 void DoParsing(int begin_pos, int end_pos);
145 // wxObject* GetProduct();
146 void AddTagHandler(wxHtmlTagHandler *handler);
147 wxString* GetSource();
148 void PushTagHandler(wxHtmlTagHandler* handler, wxString tags);
149 void PopTagHandler();
151 // virtual wxFSFile *OpenURL(wxHtmlURLType type, const wxString& url) const;
153 // void AddText(const char* txt) = 0;
154 // void AddTag(const wxHtmlTag& tag);
158 //---------------------------------------------------------------------------
160 class wxHtmlWinParser : public wxHtmlParser {
162 wxHtmlWinParser(wxHtmlWindow *wnd = NULL);
164 void SetDC(wxDC *dc);
168 wxHtmlWindow* GetWindow();
169 //void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
171 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes) {
172 int* temp = int_LIST_helper(sizes);
174 self->SetFonts(normal_face, fixed_face, temp);
180 wxHtmlContainerCell* GetContainer();
181 wxHtmlContainerCell* OpenContainer();
182 wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
183 wxHtmlContainerCell* CloseContainer();
186 void SetFontSize(int s);
188 void SetFontBold(int x);
190 void SetFontItalic(int x);
191 int GetFontUnderlined();
192 void SetFontUnderlined(int x);
194 void SetFontFixed(int x);
196 void SetAlign(int a);
197 wxColour GetLinkColor();
198 void SetLinkColor(const wxColour& clr);
199 wxColour GetActualColor();
200 void SetActualColor(const wxColour& clr);
201 void SetLink(const wxString& link);
202 wxFont* CreateCurrentFont();
203 wxHtmlLinkInfo GetLink();
209 //---------------------------------------------------------------------------
212 class wxPyHtmlTagHandler : public wxHtmlTagHandler {
213 DECLARE_DYNAMIC_CLASS(wxPyHtmlTagHandler);
215 wxPyHtmlTagHandler() : wxHtmlTagHandler() {};
217 wxHtmlParser* GetParser() { return m_Parser; }
218 void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); }
220 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
221 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
226 IMPLEMENT_DYNAMIC_CLASS(wxPyHtmlTagHandler, wxHtmlTagHandler);
228 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
229 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
233 %name(wxHtmlTagHandler) class wxPyHtmlTagHandler : public wxObject {
235 wxPyHtmlTagHandler();
237 void _setCallbackInfo(PyObject* self, PyObject* _class);
238 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxHtmlTagHandler)"
240 void SetParser(wxHtmlParser *parser);
241 wxHtmlParser* GetParser();
242 void ParseInner(const wxHtmlTag& tag);
246 //---------------------------------------------------------------------------
249 class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
250 DECLARE_DYNAMIC_CLASS(wxPyHtmlWinTagHandler);
252 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
254 wxHtmlWinParser* GetParser() { return m_WParser; }
255 void ParseInner(const wxHtmlTag& tag)
256 { wxHtmlWinTagHandler::ParseInner(tag); }
258 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
259 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
264 IMPLEMENT_DYNAMIC_CLASS( wxPyHtmlWinTagHandler, wxHtmlWinTagHandler);
266 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
267 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
271 %name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
273 wxPyHtmlWinTagHandler();
275 void _setCallbackInfo(PyObject* self, PyObject* _class);
276 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxHtmlWinTagHandler)"
278 void SetParser(wxHtmlParser *parser);
279 wxHtmlWinParser* GetParser();
280 void ParseInner(const wxHtmlTag& tag);
284 //---------------------------------------------------------------------------
288 class wxPyHtmlTagsModule : public wxHtmlTagsModule {
290 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
291 m_tagHandlerClass = thc;
292 Py_INCREF(m_tagHandlerClass);
293 RegisterModule(this);
294 wxHtmlWinParser::AddModule(this);
298 wxPyBeginBlockThreads();
299 Py_DECREF(m_tagHandlerClass);
300 m_tagHandlerClass = NULL;
301 for (size_t x=0; x < m_objArray.GetCount(); x++) {
302 PyObject* obj = (PyObject*)m_objArray.Item(x);
305 wxPyEndBlockThreads();
308 void FillHandlersTable(wxHtmlWinParser *parser) {
309 // Wave our magic wand... (if it works it's a miracle! ;-)
311 // First, make a new instance of the tag handler
312 wxPyBeginBlockThreads();
313 PyObject* arg = Py_BuildValue("()");
314 PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
316 wxPyEndBlockThreads();
318 // now figure out where it's C++ object is...
319 wxPyHtmlWinTagHandler* thPtr;
320 if (SWIG_GetPtrObj(obj, (void **)&thPtr, "_wxPyHtmlWinTagHandler_p"))
324 parser->AddTagHandler(thPtr);
331 PyObject* m_tagHandlerClass;
332 wxArrayPtrVoid m_objArray;
340 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
341 // Dynamically create a new wxModule. Refcounts tagHandlerClass
342 // and adds itself to the wxModules list and to the wxHtmlWinParser.
343 new wxPyHtmlTagsModule(tagHandlerClass);
348 //---------------------------------------------------------------------------
349 //---------------------------------------------------------------------------
351 class wxHtmlCell : public wxObject {
360 wxHtmlLinkInfo* GetLink(int x = 0, int y = 0);
361 wxHtmlCell* GetNext();
362 wxHtmlContainerCell* GetParent();
363 void SetLink(const wxHtmlLinkInfo& link);
364 void SetNext(wxHtmlCell *cell);
365 void SetParent(wxHtmlContainerCell *p);
366 void SetPos(int x, int y);
368 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
369 void DrawInvisible(wxDC& dc, int x, int y);
370 const wxHtmlCell* Find(int condition, const void* param);
372 bool AdjustPagebreak(int * pagebreak);
373 void SetCanLiveOnPagebreak(bool can);
378 class wxHtmlWordCell : public wxHtmlCell
381 wxHtmlWordCell(const wxString& word, wxDC& dc);
385 class wxHtmlContainerCell : public wxHtmlCell {
387 wxHtmlContainerCell(wxHtmlContainerCell *parent);
389 void InsertCell(wxHtmlCell *cell);
390 void SetAlignHor(int al);
392 void SetAlignVer(int al);
394 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
395 int GetIndent(int ind);
396 int GetIndentUnits(int ind);
397 void SetAlign(const wxHtmlTag& tag);
398 void SetWidthFloat(int w, int units);
399 %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
400 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
401 void SetBackgroundColour(const wxColour& clr);
402 void SetBorder(const wxColour& clr1, const wxColour& clr2);
403 wxHtmlCell* GetFirstCell();
408 class wxHtmlColourCell : public wxHtmlCell {
410 wxHtmlColourCell(wxColour clr, int flags = wxHTML_CLR_FOREGROUND);
415 class wxHtmlFontCell : public wxHtmlCell
418 wxHtmlFontCell(wxFont *font);
422 class wxHtmlWidgetCell : public wxHtmlCell {
424 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
430 //---------------------------------------------------------------------------
431 //---------------------------------------------------------------------------
432 //---------------------------------------------------------------------------
435 class wxPyHtmlWindow : public wxHtmlWindow {
436 DECLARE_ABSTRACT_CLASS(wxPyHtmlWindow);
438 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
439 const wxPoint& pos = wxDefaultPosition,
440 const wxSize& size = wxDefaultSize,
441 long style = wxHW_SCROLLBAR_AUTO,
442 const wxString& name = "htmlWindow")
443 : wxHtmlWindow(parent, id, pos, size, style, name) {};
444 wxPyHtmlWindow() : wxHtmlWindow() {};
446 void OnLinkClicked(const wxHtmlLinkInfo& link);
447 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
449 wxHtmlOpeningStatus OnOpeningURL(wxHtmlURLType type,
451 wxString *redirect) const;
453 DEC_PYCALLBACK__STRING(OnSetTitle);
454 DEC_PYCALLBACK__CELLINTINT(OnCellMouseHover);
455 DEC_PYCALLBACK__CELLINTINTME(OnCellClicked);
456 // DEC_PYCALLBACK_BOOL_STRING(OnOpeningURL);
460 IMPLEMENT_ABSTRACT_CLASS( wxPyHtmlWindow, wxHtmlWindow );
461 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
462 IMP_PYCALLBACK__CELLINTINT(wxPyHtmlWindow, wxHtmlWindow, OnCellMouseHover);
463 IMP_PYCALLBACK__CELLINTINTME(wxPyHtmlWindow, wxHtmlWindow, OnCellClicked);
464 // IMP_PYCALLBACK_BOOL_STRING(wxPyHtmlWindow, wxHtmlWindow, OnOpeningURL);
467 void wxPyHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) {
469 wxPyBeginBlockThreads();
470 if ((found = wxPyCBH_findCallback(m_myInst, "OnLinkClicked"))) {
471 PyObject* obj = wxPyConstructObject((void*)&link, "wxHtmlLinkInfo", 0);
472 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj));
475 wxPyEndBlockThreads();
477 wxHtmlWindow::OnLinkClicked(link);
479 void wxPyHtmlWindow::base_OnLinkClicked(const wxHtmlLinkInfo& link) {
480 wxHtmlWindow::OnLinkClicked(link);
484 wxHtmlOpeningStatus wxPyHtmlWindow::OnOpeningURL(wxHtmlURLType type,
486 wxString *redirect) const {
488 wxHtmlOpeningStatus rval;
489 wxPyBeginBlockThreads();
490 if ((found = wxPyCBH_findCallback(m_myInst, "OnOpeningURL"))) {
492 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(is)", type, url.c_str()));
493 if (PyString_Check(ro)
494 #if PYTHON_API_VERSION >= 1009
495 || PyUnicode_Check(ro)
498 PyObject* str = PyObject_Str(ro);
499 *redirect = PyString_AsString(str);
501 rval = wxHTML_REDIRECT;
504 PyObject* num = PyNumber_Int(ro);
505 rval = (wxHtmlOpeningStatus)PyInt_AsLong(num);
510 wxPyEndBlockThreads();
512 rval = wxHtmlWindow::OnOpeningURL(type, url, redirect);
521 %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
523 wxPyHtmlWindow(wxWindow *parent, int id = -1,
524 wxPoint& pos = wxDefaultPosition,
525 wxSize& size = wxDefaultSize,
526 int flags=wxHW_SCROLLBAR_AUTO,
527 char* name = "htmlWindow");
528 %name(wxPreHtmlWindow)wxPyHtmlWindow();
530 bool Create(wxWindow *parent, int id = -1,
531 wxPoint& pos = wxDefaultPosition,
532 wxSize& size = wxDefaultSize,
533 int flags=wxHW_SCROLLBAR_AUTO,
534 char* name = "htmlWindow");
537 void _setCallbackInfo(PyObject* self, PyObject* _class);
538 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxHtmlWindow)"
539 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
540 %pragma(python) addtomethod = "wxPreHtmlWindow:val._setOORInfo(val)"
542 bool SetPage(const wxString& source);
543 bool LoadPage(const wxString& location);
544 bool AppendToPage(const wxString& source);
545 wxString GetOpenedPage();
546 wxString GetOpenedAnchor();
547 wxString GetOpenedPageTitle();
549 void SetRelatedFrame(wxFrame* frame, const char* format);
550 wxFrame* GetRelatedFrame();
551 void SetRelatedStatusBar(int bar);
553 //void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
555 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes) {
556 int* temp = int_LIST_helper(sizes);
558 self->SetFonts(normal_face, fixed_face, temp);
564 void SetTitle(const wxString& title);
565 void SetBorders(int b);
566 void ReadCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
567 void WriteCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
569 bool HistoryForward();
570 bool HistoryCanBack();
571 bool HistoryCanForward();
573 wxHtmlContainerCell* GetInternalRepresentation();
574 wxHtmlWinParser* GetParser();
576 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
577 void base_OnSetTitle(const char* title);
578 void base_OnCellMouseHover(wxHtmlCell *cell, wxCoord x, wxCoord y);
579 void base_OnCellClicked(wxHtmlCell *cell,
580 wxCoord x, wxCoord y,
581 const wxMouseEvent& event);
584 // Static methods are mapped to stand-alone functions
586 void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) {
587 wxHtmlWindow::AddFilter(filter);
592 //---------------------------------------------------------------------------
593 //---------------------------------------------------------------------------
596 class wxHtmlDCRenderer : public wxObject {
601 void SetDC(wxDC *dc, int maxwidth);
602 void SetSize(int width, int height);
603 void SetHtmlText(const wxString& html,
604 const wxString& basepath = wxEmptyString,
606 int Render(int x, int y, int from = 0, int dont_render = FALSE);
607 int GetTotalHeight();
608 // returns total height of the html document
609 // (compare Render's return value with this)
619 class wxHtmlPrintout : public wxPyPrintout {
621 wxHtmlPrintout(const char* title = "Printout");
622 //~wxHtmlPrintout(); wxPrintPreview object takes ownership...
624 void SetHtmlText(const wxString& html,
625 const wxString &basepath = wxEmptyString,
627 void SetHtmlFile(const wxString &htmlfile);
628 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
629 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
630 void SetMargins(float top = 25.2, float bottom = 25.2,
631 float left = 25.2, float right = 25.2,
637 class wxHtmlEasyPrinting : public wxObject {
639 wxHtmlEasyPrinting(const char* name = "Printing",
640 wxFrame *parent_frame = NULL);
641 ~wxHtmlEasyPrinting();
643 void PreviewFile(const wxString &htmlfile);
644 void PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
645 void PrintFile(const wxString &htmlfile);
646 void PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
649 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
650 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
652 wxPrintData *GetPrintData() {return m_PrintData;}
653 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
659 //---------------------------------------------------------------------------
660 //---------------------------------------------------------------------------
663 extern "C" SWIGEXPORT(void) inithtmlhelpc();
671 wxClassInfo::CleanUpClasses();
672 wxClassInfo::InitializeClasses();
674 wxPyPtrTypeMap_Add("wxHtmlTagHandler", "wxPyHtmlTagHandler");
675 wxPyPtrTypeMap_Add("wxHtmlWinTagHandler", "wxPyHtmlWinTagHandler");
676 wxPyPtrTypeMap_Add("wxHtmlWindow", "wxPyHtmlWindow");
679 //----------------------------------------------------------------------
680 // And this gets appended to the shadow class file.
681 //----------------------------------------------------------------------
683 %pragma(python) include="_htmlextras.py";
685 //---------------------------------------------------------------------------