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();
113 //---------------------------------------------------------------------------
115 class wxHtmlParser : public wxObject {
117 // wxHtmlParser(); This is an abstract base class...
119 void SetFS(wxFileSystem *fs);
120 wxFileSystem* GetFS();
121 wxObject* Parse(const wxString& source);
122 void InitParser(const wxString& source);
124 void DoParsing(int begin_pos, int end_pos);
125 // wxObject* GetProduct();
126 void AddTagHandler(wxHtmlTagHandler *handler);
127 wxString* GetSource();
128 void PushTagHandler(wxHtmlTagHandler* handler, wxString tags);
129 void PopTagHandler();
132 // void AddText(const char* txt) = 0;
133 // void AddTag(const wxHtmlTag& tag);
137 //---------------------------------------------------------------------------
139 class wxHtmlWinParser : public wxHtmlParser {
141 wxHtmlWinParser(wxWindow *wnd);
143 void SetDC(wxDC *dc);
147 wxWindow* GetWindow();
148 //void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
150 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes) {
151 int* temp = int_LIST_helper(sizes);
153 self->SetFonts(normal_face, fixed_face, temp);
159 wxHtmlContainerCell* GetContainer();
160 wxHtmlContainerCell* OpenContainer();
161 wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
162 wxHtmlContainerCell* CloseContainer();
165 void SetFontSize(int s);
167 void SetFontBold(int x);
169 void SetFontItalic(int x);
170 int GetFontUnderlined();
171 void SetFontUnderlined(int x);
173 void SetFontFixed(int x);
175 void SetAlign(int a);
176 const wxColour& GetLinkColor();
177 void SetLinkColor(const wxColour& clr);
178 const wxColour& GetActualColor();
179 void SetActualColor(const wxColour& clr);
180 void SetLink(const wxString& link);
181 wxFont* CreateCurrentFont();
182 wxHtmlLinkInfo GetLink();
188 //---------------------------------------------------------------------------
191 class wxPyHtmlTagHandler : public wxHtmlTagHandler {
192 DECLARE_DYNAMIC_CLASS(wxPyHtmlTagHandler);
194 wxPyHtmlTagHandler() : wxHtmlTagHandler() {};
196 wxHtmlParser* GetParser() { return m_Parser; }
197 void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); }
199 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
200 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
205 IMPLEMENT_DYNAMIC_CLASS(wxPyHtmlTagHandler, wxHtmlTagHandler);
207 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
208 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
212 %name(wxHtmlTagHandler) class wxPyHtmlTagHandler : public wxObject {
214 wxPyHtmlTagHandler();
216 void _setSelf(PyObject* self, PyObject* _class);
217 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxHtmlTagHandler)"
219 void SetParser(wxHtmlParser *parser);
220 wxHtmlParser* GetParser();
221 void ParseInner(const wxHtmlTag& tag);
225 //---------------------------------------------------------------------------
228 class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
229 DECLARE_DYNAMIC_CLASS(wxPyHtmlWinTagHandler);
231 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
233 wxHtmlWinParser* GetParser() { return m_WParser; }
234 void ParseInner(const wxHtmlTag& tag)
235 { wxHtmlWinTagHandler::ParseInner(tag); }
237 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
238 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
243 IMPLEMENT_DYNAMIC_CLASS( wxPyHtmlWinTagHandler, wxHtmlWinTagHandler);
245 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
246 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
250 %name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
252 wxPyHtmlWinTagHandler();
254 void _setSelf(PyObject* self, PyObject* _class);
255 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxHtmlWinTagHandler)"
257 void SetParser(wxHtmlParser *parser);
258 wxHtmlWinParser* GetParser();
259 void ParseInner(const wxHtmlTag& tag);
263 //---------------------------------------------------------------------------
267 class wxPyHtmlTagsModule : public wxHtmlTagsModule {
269 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
270 m_tagHandlerClass = thc;
271 Py_INCREF(m_tagHandlerClass);
272 RegisterModule(this);
273 wxHtmlWinParser::AddModule(this);
277 bool doSave = wxPyRestoreThread();
278 Py_DECREF(m_tagHandlerClass);
279 m_tagHandlerClass = NULL;
280 for (size_t x=0; x < m_objArray.GetCount(); x++) {
281 PyObject* obj = (PyObject*)m_objArray.Item(x);
284 wxPySaveThread(doSave);
287 void FillHandlersTable(wxHtmlWinParser *parser) {
288 // Wave our magic wand... (if it works it's a miracle! ;-)
290 // First, make a new instance of the tag handler
291 bool doSave = wxPyRestoreThread();
292 PyObject* arg = Py_BuildValue("()");
293 PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
295 wxPySaveThread(doSave);
297 // now figure out where it's C++ object is...
298 wxPyHtmlWinTagHandler* thPtr;
299 if (SWIG_GetPtrObj(obj, (void **)&thPtr, "_wxPyHtmlWinTagHandler_p"))
303 parser->AddTagHandler(thPtr);
310 PyObject* m_tagHandlerClass;
311 wxArrayPtrVoid m_objArray;
319 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
320 // Dynamically create a new wxModule. Refcounts tagHandlerClass
321 // and adds itself to the wxModules list and to the wxHtmlWinParser.
322 new wxPyHtmlTagsModule(tagHandlerClass);
327 //---------------------------------------------------------------------------
328 //---------------------------------------------------------------------------
330 class wxHtmlCell : public wxObject {
339 wxHtmlLinkInfo* GetLink(int x = 0, int y = 0);
340 wxHtmlCell* GetNext();
341 wxHtmlContainerCell* GetParent();
342 void SetLink(const wxHtmlLinkInfo& link);
343 void SetNext(wxHtmlCell *cell);
344 void SetParent(wxHtmlContainerCell *p);
345 void SetPos(int x, int y);
347 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
348 void DrawInvisible(wxDC& dc, int x, int y);
349 const wxHtmlCell* Find(int condition, const void* param);
351 bool AdjustPagebreak(int * pagebreak);
352 void SetCanLiveOnPagebreak(bool can);
357 class wxHtmlWordCell : public wxHtmlCell
360 wxHtmlWordCell(const wxString& word, wxDC& dc);
364 class wxHtmlContainerCell : public wxHtmlCell {
366 wxHtmlContainerCell(wxHtmlContainerCell *parent);
368 void InsertCell(wxHtmlCell *cell);
369 void SetAlignHor(int al);
371 void SetAlignVer(int al);
373 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
374 int GetIndent(int ind);
375 int GetIndentUnits(int ind);
376 void SetAlign(const wxHtmlTag& tag);
377 void SetWidthFloat(int w, int units);
378 %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
379 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
380 void SetBackgroundColour(const wxColour& clr);
381 void SetBorder(const wxColour& clr1, const wxColour& clr2);
382 wxHtmlCell* GetFirstCell();
387 class wxHtmlColourCell : public wxHtmlCell {
389 wxHtmlColourCell(wxColour clr, int flags = wxHTML_CLR_FOREGROUND);
394 class wxHtmlFontCell : public wxHtmlCell
397 wxHtmlFontCell(wxFont *font);
401 class wxHtmlWidgetCell : public wxHtmlCell {
403 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
409 //---------------------------------------------------------------------------
410 //---------------------------------------------------------------------------
411 //---------------------------------------------------------------------------
414 class wxPyHtmlWindow : public wxHtmlWindow {
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);
431 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
433 void wxPyHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) {
434 bool doSave = wxPyRestoreThread();
435 if (wxPyCBH_findCallback(m_myInst, "OnLinkClicked")) {
436 PyObject* obj = wxPyConstructObject((void*)&link, "wxHtmlLinkInfo", 0);
437 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj));
441 wxHtmlWindow::OnLinkClicked(link);
442 wxPySaveThread(doSave);
444 void wxPyHtmlWindow::base_OnLinkClicked(const wxHtmlLinkInfo& link) {
445 wxHtmlWindow::OnLinkClicked(link);
451 %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
453 wxPyHtmlWindow(wxWindow *parent, int id = -1,
454 wxPoint& pos = wxDefaultPosition,
455 wxSize& size = wxDefaultSize,
456 int flags=wxHW_SCROLLBAR_AUTO,
457 char* name = "htmlWindow");
459 void _setSelf(PyObject* self, PyObject* _class);
460 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxHtmlWindow)"
461 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
462 %pragma(python) addtomethod = "__init__:#wx._StdOnScrollCallbacks(self)"
465 bool SetPage(const wxString& source);
466 bool LoadPage(const wxString& location);
467 wxString GetOpenedPage();
468 wxString GetOpenedAnchor();
469 wxString GetOpenedPageTitle();
471 void SetRelatedFrame(wxFrame* frame, const char* format);
472 wxFrame* GetRelatedFrame();
473 void SetRelatedStatusBar(int bar);
475 //void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
477 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes) {
478 int* temp = int_LIST_helper(sizes);
480 self->SetFonts(normal_face, fixed_face, temp);
486 void SetTitle(const wxString& title);
487 void SetBorders(int b);
488 void ReadCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
489 void WriteCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
491 bool HistoryForward();
492 bool HistoryCanBack();
493 bool HistoryCanForward();
495 wxHtmlContainerCell* GetInternalRepresentation();
496 wxHtmlWinParser* GetParser();
498 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
499 void base_OnSetTitle(const char* title);
502 // Static methods are mapped to stand-alone functions
504 void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) {
505 wxHtmlWindow::AddFilter(filter);
510 //---------------------------------------------------------------------------
511 //---------------------------------------------------------------------------
514 class wxHtmlDCRenderer : public wxObject {
519 void SetDC(wxDC *dc, int maxwidth);
520 void SetSize(int width, int height);
521 void SetHtmlText(const wxString& html,
522 const wxString& basepath = wxEmptyString,
524 int Render(int x, int y, int from = 0, int dont_render = FALSE);
525 int GetTotalHeight();
526 // returns total height of the html document
527 // (compare Render's return value with this)
537 class wxHtmlPrintout : public wxPyPrintout {
539 wxHtmlPrintout(const char* title = "Printout");
540 //~wxHtmlPrintout(); wxPrintPreview object takes ownership...
542 void SetHtmlText(const wxString& html,
543 const wxString &basepath = wxEmptyString,
545 void SetHtmlFile(const wxString &htmlfile);
546 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
547 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
548 void SetMargins(float top = 25.2, float bottom = 25.2,
549 float left = 25.2, float right = 25.2,
555 class wxHtmlEasyPrinting : public wxObject {
557 wxHtmlEasyPrinting(const char* name = "Printing",
558 wxFrame *parent_frame = NULL);
559 ~wxHtmlEasyPrinting();
561 void PreviewFile(const wxString &htmlfile);
562 void PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
563 void PrintFile(const wxString &htmlfile);
564 void PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
567 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
568 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
570 wxPrintData *GetPrintData() {return m_PrintData;}
571 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
577 //---------------------------------------------------------------------------
578 //---------------------------------------------------------------------------
581 extern "C" SWIGEXPORT(void) inithtmlhelpc();
589 wxClassInfo::CleanUpClasses();
590 wxClassInfo::InitializeClasses();
592 wxPyPtrTypeMap_Add("wxHtmlTagHandler", "wxPyHtmlTagHandler");
593 wxPyPtrTypeMap_Add("wxHtmlWinTagHandler", "wxPyHtmlWinTagHandler");
594 wxPyPtrTypeMap_Add("wxHtmlWindow", "wxPyHtmlWindow");
597 //----------------------------------------------------------------------
598 // And this gets appended to the shadow class file.
599 //----------------------------------------------------------------------
601 %pragma(python) include="_htmlextras.py";
603 //---------------------------------------------------------------------------