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();
131 // void AddText(const char* txt) = 0;
132 // void AddTag(const wxHtmlTag& tag);
136 //---------------------------------------------------------------------------
138 class wxHtmlWinParser : public wxHtmlParser {
140 wxHtmlWinParser(wxWindow *wnd);
142 void SetDC(wxDC *dc);
146 wxWindow* GetWindow();
147 //void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
149 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes) {
150 int* temp = int_LIST_helper(sizes);
152 self->SetFonts(normal_face, fixed_face, temp);
158 wxHtmlContainerCell* GetContainer();
159 wxHtmlContainerCell* OpenContainer();
160 wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
161 wxHtmlContainerCell* CloseContainer();
164 void SetFontSize(int s);
166 void SetFontBold(int x);
168 void SetFontItalic(int x);
169 int GetFontUnderlined();
170 void SetFontUnderlined(int x);
172 void SetFontFixed(int x);
174 void SetAlign(int a);
175 const wxColour& GetLinkColor();
176 void SetLinkColor(const wxColour& clr);
177 const wxColour& GetActualColor();
178 void SetActualColor(const wxColour& clr);
179 void SetLink(const wxString& link);
180 wxFont* CreateCurrentFont();
181 wxHtmlLinkInfo GetLink();
187 //---------------------------------------------------------------------------
190 class wxPyHtmlTagHandler : public wxHtmlTagHandler {
191 DECLARE_DYNAMIC_CLASS(wxPyHtmlTagHandler);
193 wxPyHtmlTagHandler() : wxHtmlTagHandler() {};
195 wxHtmlParser* GetParser() { return m_Parser; }
196 void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); }
198 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
199 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
204 IMPLEMENT_DYNAMIC_CLASS(wxPyHtmlTagHandler, wxHtmlTagHandler);
206 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
207 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
211 %name(wxHtmlTagHandler) class wxPyHtmlTagHandler : public wxObject {
213 wxPyHtmlTagHandler();
215 void _setCallbackInfo(PyObject* self, PyObject* _class);
216 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxHtmlTagHandler)"
218 void SetParser(wxHtmlParser *parser);
219 wxHtmlParser* GetParser();
220 void ParseInner(const wxHtmlTag& tag);
224 //---------------------------------------------------------------------------
227 class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
228 DECLARE_DYNAMIC_CLASS(wxPyHtmlWinTagHandler);
230 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
232 wxHtmlWinParser* GetParser() { return m_WParser; }
233 void ParseInner(const wxHtmlTag& tag)
234 { wxHtmlWinTagHandler::ParseInner(tag); }
236 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
237 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
242 IMPLEMENT_DYNAMIC_CLASS( wxPyHtmlWinTagHandler, wxHtmlWinTagHandler);
244 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
245 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
249 %name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
251 wxPyHtmlWinTagHandler();
253 void _setCallbackInfo(PyObject* self, PyObject* _class);
254 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxHtmlWinTagHandler)"
256 void SetParser(wxHtmlParser *parser);
257 wxHtmlWinParser* GetParser();
258 void ParseInner(const wxHtmlTag& tag);
262 //---------------------------------------------------------------------------
266 class wxPyHtmlTagsModule : public wxHtmlTagsModule {
268 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
269 m_tagHandlerClass = thc;
270 Py_INCREF(m_tagHandlerClass);
271 RegisterModule(this);
272 wxHtmlWinParser::AddModule(this);
276 wxPyTState* state = wxPyBeginBlockThreads();
277 Py_DECREF(m_tagHandlerClass);
278 m_tagHandlerClass = NULL;
279 for (size_t x=0; x < m_objArray.GetCount(); x++) {
280 PyObject* obj = (PyObject*)m_objArray.Item(x);
283 wxPyEndBlockThreads(state);
286 void FillHandlersTable(wxHtmlWinParser *parser) {
287 // Wave our magic wand... (if it works it's a miracle! ;-)
289 // First, make a new instance of the tag handler
290 wxPyTState* state = wxPyBeginBlockThreads();
291 PyObject* arg = Py_BuildValue("()");
292 PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
294 wxPyEndBlockThreads(state);
296 // now figure out where it's C++ object is...
297 wxPyHtmlWinTagHandler* thPtr;
298 if (SWIG_GetPtrObj(obj, (void **)&thPtr, "_wxPyHtmlWinTagHandler_p"))
302 parser->AddTagHandler(thPtr);
309 PyObject* m_tagHandlerClass;
310 wxArrayPtrVoid m_objArray;
318 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
319 // Dynamically create a new wxModule. Refcounts tagHandlerClass
320 // and adds itself to the wxModules list and to the wxHtmlWinParser.
321 new wxPyHtmlTagsModule(tagHandlerClass);
326 //---------------------------------------------------------------------------
327 //---------------------------------------------------------------------------
329 class wxHtmlCell : public wxObject {
338 wxHtmlLinkInfo* GetLink(int x = 0, int y = 0);
339 wxHtmlCell* GetNext();
340 wxHtmlContainerCell* GetParent();
341 void SetLink(const wxHtmlLinkInfo& link);
342 void SetNext(wxHtmlCell *cell);
343 void SetParent(wxHtmlContainerCell *p);
344 void SetPos(int x, int y);
346 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
347 void DrawInvisible(wxDC& dc, int x, int y);
348 const wxHtmlCell* Find(int condition, const void* param);
350 bool AdjustPagebreak(int * pagebreak);
351 void SetCanLiveOnPagebreak(bool can);
356 class wxHtmlWordCell : public wxHtmlCell
359 wxHtmlWordCell(const wxString& word, wxDC& dc);
363 class wxHtmlContainerCell : public wxHtmlCell {
365 wxHtmlContainerCell(wxHtmlContainerCell *parent);
367 void InsertCell(wxHtmlCell *cell);
368 void SetAlignHor(int al);
370 void SetAlignVer(int al);
372 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
373 int GetIndent(int ind);
374 int GetIndentUnits(int ind);
375 void SetAlign(const wxHtmlTag& tag);
376 void SetWidthFloat(int w, int units);
377 %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
378 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
379 void SetBackgroundColour(const wxColour& clr);
380 void SetBorder(const wxColour& clr1, const wxColour& clr2);
381 wxHtmlCell* GetFirstCell();
386 class wxHtmlColourCell : public wxHtmlCell {
388 wxHtmlColourCell(wxColour clr, int flags = wxHTML_CLR_FOREGROUND);
393 class wxHtmlFontCell : public wxHtmlCell
396 wxHtmlFontCell(wxFont *font);
400 class wxHtmlWidgetCell : public wxHtmlCell {
402 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
408 //---------------------------------------------------------------------------
409 //---------------------------------------------------------------------------
410 //---------------------------------------------------------------------------
413 class wxPyHtmlWindow : public wxHtmlWindow {
414 DECLARE_ABSTRACT_CLASS(wxPyHtmlWindow);
416 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
417 const wxPoint& pos = wxDefaultPosition,
418 const wxSize& size = wxDefaultSize,
419 long style = wxHW_SCROLLBAR_AUTO,
420 const wxString& name = "htmlWindow")
421 : wxHtmlWindow(parent, id, pos, size, style, name) {};
423 void OnLinkClicked(const wxHtmlLinkInfo& link);
424 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
426 DEC_PYCALLBACK__STRING(OnSetTitle);
427 DEC_PYCALLBACK__CELLINTINT(OnCellMouseHover);
428 DEC_PYCALLBACK__CELLINTINTME(OnCellClicked);
432 IMPLEMENT_ABSTRACT_CLASS( wxPyHtmlWindow, wxHtmlWindow );
433 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
434 IMP_PYCALLBACK__CELLINTINT(wxPyHtmlWindow, wxHtmlWindow, OnCellMouseHover);
435 IMP_PYCALLBACK__CELLINTINTME(wxPyHtmlWindow, wxHtmlWindow, OnCellClicked);
438 void wxPyHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) {
440 wxPyTState* state = wxPyBeginBlockThreads();
441 if ((found = wxPyCBH_findCallback(m_myInst, "OnLinkClicked"))) {
442 PyObject* obj = wxPyConstructObject((void*)&link, "wxHtmlLinkInfo", 0);
443 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj));
446 wxPyEndBlockThreads(state);
448 wxHtmlWindow::OnLinkClicked(link);
450 void wxPyHtmlWindow::base_OnLinkClicked(const wxHtmlLinkInfo& link) {
451 wxHtmlWindow::OnLinkClicked(link);
458 %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
460 wxPyHtmlWindow(wxWindow *parent, int id = -1,
461 wxPoint& pos = wxDefaultPosition,
462 wxSize& size = wxDefaultSize,
463 int flags=wxHW_SCROLLBAR_AUTO,
464 char* name = "htmlWindow");
466 void _setCallbackInfo(PyObject* self, PyObject* _class);
467 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxHtmlWindow)"
469 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
471 bool SetPage(const wxString& source);
472 bool LoadPage(const wxString& location);
473 wxString GetOpenedPage();
474 wxString GetOpenedAnchor();
475 wxString GetOpenedPageTitle();
477 void SetRelatedFrame(wxFrame* frame, const char* format);
478 wxFrame* GetRelatedFrame();
479 void SetRelatedStatusBar(int bar);
481 //void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
483 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes) {
484 int* temp = int_LIST_helper(sizes);
486 self->SetFonts(normal_face, fixed_face, temp);
492 void SetTitle(const wxString& title);
493 void SetBorders(int b);
494 void ReadCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
495 void WriteCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
497 bool HistoryForward();
498 bool HistoryCanBack();
499 bool HistoryCanForward();
501 wxHtmlContainerCell* GetInternalRepresentation();
502 wxHtmlWinParser* GetParser();
504 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
505 void base_OnSetTitle(const char* title);
506 void base_OnCellMouseHover(wxHtmlCell *cell, wxCoord x, wxCoord y);
507 void base_OnCellClicked(wxHtmlCell *cell,
508 wxCoord x, wxCoord y,
509 const wxMouseEvent& event);
512 // Static methods are mapped to stand-alone functions
514 void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) {
515 wxHtmlWindow::AddFilter(filter);
520 //---------------------------------------------------------------------------
521 //---------------------------------------------------------------------------
524 class wxHtmlDCRenderer : public wxObject {
529 void SetDC(wxDC *dc, int maxwidth);
530 void SetSize(int width, int height);
531 void SetHtmlText(const wxString& html,
532 const wxString& basepath = wxEmptyString,
534 int Render(int x, int y, int from = 0, int dont_render = FALSE);
535 int GetTotalHeight();
536 // returns total height of the html document
537 // (compare Render's return value with this)
547 class wxHtmlPrintout : public wxPyPrintout {
549 wxHtmlPrintout(const char* title = "Printout");
550 //~wxHtmlPrintout(); wxPrintPreview object takes ownership...
552 void SetHtmlText(const wxString& html,
553 const wxString &basepath = wxEmptyString,
555 void SetHtmlFile(const wxString &htmlfile);
556 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
557 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
558 void SetMargins(float top = 25.2, float bottom = 25.2,
559 float left = 25.2, float right = 25.2,
565 class wxHtmlEasyPrinting : public wxObject {
567 wxHtmlEasyPrinting(const char* name = "Printing",
568 wxFrame *parent_frame = NULL);
569 ~wxHtmlEasyPrinting();
571 void PreviewFile(const wxString &htmlfile);
572 void PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
573 void PrintFile(const wxString &htmlfile);
574 void PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
577 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
578 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
580 wxPrintData *GetPrintData() {return m_PrintData;}
581 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
587 //---------------------------------------------------------------------------
588 //---------------------------------------------------------------------------
591 extern "C" SWIGEXPORT(void) inithtmlhelpc();
599 wxClassInfo::CleanUpClasses();
600 wxClassInfo::InitializeClasses();
602 wxPyPtrTypeMap_Add("wxHtmlTagHandler", "wxPyHtmlTagHandler");
603 wxPyPtrTypeMap_Add("wxHtmlWinTagHandler", "wxPyHtmlWinTagHandler");
604 wxPyPtrTypeMap_Add("wxHtmlWindow", "wxPyHtmlWindow");
607 //----------------------------------------------------------------------
608 // And this gets appended to the shadow class file.
609 //----------------------------------------------------------------------
611 %pragma(python) include="_htmlextras.py";
613 //---------------------------------------------------------------------------