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"
56 //---------------------------------------------------------------------------
65 wxHTML_CLR_FOREGROUND,
66 wxHTML_CLR_BACKGROUND,
76 wxHTML_INDENT_HORIZONTAL,
77 wxHTML_INDENT_VERTICAL,
81 wxHTML_COND_ISIMAGEMAP,
86 //---------------------------------------------------------------------------
88 class wxHtmlLinkInfo {
90 wxHtmlLinkInfo(const wxString& href, const wxString& target = wxEmptyString);
93 wxMouseEvent* GetEvent();
94 wxHtmlCell* GetHtmlCell();
97 //---------------------------------------------------------------------------
101 // Never need to create a new tag from Python...
102 //wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
105 bool HasParam(const wxString& par);
106 wxString GetParam(const wxString& par, int with_commas = FALSE);
108 // Can't do this one as-is, but GetParam should be enough...
109 //int ScanParam(const wxString& par, const char *format, void* param);
111 wxString GetAllParams();
120 //---------------------------------------------------------------------------
124 // wxHtmlParser(); This is an abstract base class...
126 void SetFS(wxFileSystem *fs);
127 wxFileSystem* GetFS();
128 wxObject* Parse(const wxString& source);
129 void InitParser(const wxString& source);
131 void DoParsing(int begin_pos, int end_pos);
132 // wxObject* GetProduct();
133 void AddTagHandler(wxHtmlTagHandler *handler);
134 wxString* GetSource();
135 void PushTagHandler(wxHtmlTagHandler* handler, wxString tags);
136 void PopTagHandler();
139 // void AddText(const char* txt) = 0;
140 // void AddTag(const wxHtmlTag& tag);
144 //---------------------------------------------------------------------------
146 class wxHtmlWinParser : public wxHtmlParser {
148 wxHtmlWinParser(wxWindow *wnd);
150 void SetDC(wxDC *dc);
154 wxWindow* GetWindow();
155 //void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
157 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes) {
158 int* temp = int_LIST_helper(sizes);
160 self->SetFonts(normal_face, fixed_face, temp);
166 wxHtmlContainerCell* GetContainer();
167 wxHtmlContainerCell* OpenContainer();
168 wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
169 wxHtmlContainerCell* CloseContainer();
172 void SetFontSize(int s);
174 void SetFontBold(int x);
176 void SetFontItalic(int x);
177 int GetFontUnderlined();
178 void SetFontUnderlined(int x);
180 void SetFontFixed(int x);
182 void SetAlign(int a);
183 const wxColour& GetLinkColor();
184 void SetLinkColor(const wxColour& clr);
185 const wxColour& GetActualColor();
186 void SetActualColor(const wxColour& clr);
187 void SetLink(const wxString& link);
188 wxFont* CreateCurrentFont();
189 wxHtmlLinkInfo GetLink();
195 //---------------------------------------------------------------------------
198 class wxPyHtmlTagHandler : public wxHtmlTagHandler {
200 wxPyHtmlTagHandler() : wxHtmlTagHandler() {};
202 wxHtmlParser* GetParser() { return m_Parser; }
203 void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); }
205 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
206 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
211 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
212 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
216 %name(wxHtmlTagHandler) class wxPyHtmlTagHandler {
218 wxPyHtmlTagHandler();
220 void _setSelf(PyObject* self, PyObject* _class);
221 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxHtmlTagHandler)"
223 void SetParser(wxHtmlParser *parser);
224 wxHtmlParser* GetParser();
225 void ParseInner(const wxHtmlTag& tag);
229 //---------------------------------------------------------------------------
232 class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
234 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
236 wxHtmlWinParser* GetParser() { return m_WParser; }
237 void ParseInner(const wxHtmlTag& tag)
238 { wxHtmlWinTagHandler::ParseInner(tag); }
240 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
241 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
246 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
247 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
251 %name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
253 wxPyHtmlWinTagHandler();
255 void _setSelf(PyObject* self, PyObject* _class);
256 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxHtmlWinTagHandler)"
258 void SetParser(wxHtmlParser *parser);
259 wxHtmlWinParser* GetParser();
260 void ParseInner(const wxHtmlTag& tag);
264 //---------------------------------------------------------------------------
268 class wxPyHtmlTagsModule : public wxHtmlTagsModule {
270 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
271 m_tagHandlerClass = thc;
272 Py_INCREF(m_tagHandlerClass);
273 RegisterModule(this);
274 wxHtmlWinParser::AddModule(this);
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);
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 bool doSave = wxPyRestoreThread();
291 PyObject* arg = Py_BuildValue("()");
292 PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
294 wxPySaveThread(doSave);
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 //---------------------------------------------------------------------------
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 wxHtmlContainerCell : public wxHtmlCell {
358 wxHtmlContainerCell(wxHtmlContainerCell *parent);
360 void InsertCell(wxHtmlCell *cell);
361 void SetAlignHor(int al);
363 void SetAlignVer(int al);
365 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
366 int GetIndent(int ind);
367 int GetIndentUnits(int ind);
368 void SetAlign(const wxHtmlTag& tag);
369 void SetWidthFloat(int w, int units);
370 %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
371 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
372 void SetBackgroundColour(const wxColour& clr);
373 void SetBorder(const wxColour& clr1, const wxColour& clr2);
374 wxHtmlCell* GetFirstCell();
379 class wxHtmlColourCell : public wxHtmlCell {
381 wxHtmlColourCell(wxColour clr, int flags = wxHTML_CLR_FOREGROUND);
387 class wxHtmlWidgetCell : public wxHtmlCell {
389 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
395 //---------------------------------------------------------------------------
396 //---------------------------------------------------------------------------
397 //---------------------------------------------------------------------------
399 // item of history list
400 class HtmlHistoryItem {
402 HtmlHistoryItem(const char* p, const char* a);
406 const wxString& GetPage();
407 const wxString& GetAnchor();
411 //---------------------------------------------------------------------------
413 class wxPyHtmlWindow : public wxHtmlWindow {
415 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
416 const wxPoint& pos = wxDefaultPosition,
417 const wxSize& size = wxDefaultSize,
418 long style = wxHW_SCROLLBAR_AUTO,
419 const wxString& name = "htmlWindow")
420 : wxHtmlWindow(parent, id, pos, size, style, name) {};
422 void OnLinkClicked(const wxHtmlLinkInfo& link);
423 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
425 DEC_PYCALLBACK__STRING(OnSetTitle);
430 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
432 void wxPyHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) {
433 bool doSave = wxPyRestoreThread();
434 if (m_myInst.findCallback("OnLinkClicked")) {
435 PyObject* obj = wxPyConstructObject((void*)&link, "wxHtmlLinkInfo");
436 m_myInst.callCallback(Py_BuildValue("(O)", obj));
439 wxHtmlWindow::OnLinkClicked(link);
440 wxPySaveThread(doSave);
442 void wxPyHtmlWindow::base_OnLinkClicked(const wxHtmlLinkInfo& link) {
443 wxHtmlWindow::OnLinkClicked(link);
449 %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
451 wxPyHtmlWindow(wxWindow *parent, int id = -1,
452 wxPoint& pos = wxPyDefaultPosition,
453 wxSize& size = wxPyDefaultSize,
454 int flags=wxHW_SCROLLBAR_AUTO,
455 char* name = "htmlWindow");
457 void _setSelf(PyObject* self, PyObject* _class);
458 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxHtmlWindow)"
459 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
460 %pragma(python) addtomethod = "__init__:#wx._StdOnScrollCallbacks(self)"
463 bool SetPage(const char* source);
464 bool LoadPage(const char* location);
465 wxString GetOpenedPage();
466 void SetRelatedFrame(wxFrame* frame, const char* format);
467 wxFrame* GetRelatedFrame();
468 void SetRelatedStatusBar(int bar);
470 //void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
472 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes) {
473 int* temp = int_LIST_helper(sizes);
475 self->SetFonts(normal_face, fixed_face, temp);
481 void SetTitle(const char* title);
482 void SetBorders(int b);
483 void ReadCustomization(wxConfigBase *cfg, char* path = "");
484 void WriteCustomization(wxConfigBase *cfg, char* path = "");
486 bool HistoryForward();
488 wxHtmlContainerCell* GetInternalRepresentation();
489 wxHtmlWinParser* GetParser();
491 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
492 void base_OnSetTitle(const char* title);
495 // Static methods are mapped to stand-alone functions
497 void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) {
498 wxHtmlWindow::AddFilter(filter);
503 //---------------------------------------------------------------------------
504 //---------------------------------------------------------------------------
507 class wxHtmlDCRenderer {
512 void SetDC(wxDC *dc, int maxwidth);
513 void SetSize(int width, int height);
514 void SetHtmlText(const wxString& html,
515 const wxString& basepath = wxEmptyString,
517 int Render(int x, int y, int from = 0, int dont_render = FALSE);
518 int GetTotalHeight();
519 // returns total height of the html document
520 // (compare Render's return value with this)
530 class wxHtmlPrintout : public wxPyPrintout {
532 wxHtmlPrintout(const char* title = "Printout");
535 void SetHtmlText(const wxString& html,
536 const wxString &basepath = wxEmptyString,
538 void SetHtmlFile(const wxString &htmlfile);
539 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
540 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
541 void SetMargins(float top = 25.2, float bottom = 25.2,
542 float left = 25.2, float right = 25.2,
548 class wxHtmlEasyPrinting {
550 wxHtmlEasyPrinting(const char* name = "Printing",
551 wxFrame *parent_frame = NULL);
552 ~wxHtmlEasyPrinting();
554 void PreviewFile(const wxString &htmlfile);
555 void PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
556 void PrintFile(const wxString &htmlfile);
557 void PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
560 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
561 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
563 wxPrintData *GetPrintData() {return m_PrintData;}
564 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
570 //---------------------------------------------------------------------------
571 //---------------------------------------------------------------------------
574 extern "C" SWIGEXPORT(void) inithtmlhelpc();
582 wxClassInfo::CleanUpClasses();
583 wxClassInfo::InitializeClasses();
585 // Until wxFileSystem is wrapped...
587 wxFileSystem::AddHandler(new wxZipFSHandler);
590 // wxFileSystem::AddHandler(new wxInternetFSHandler);
594 //----------------------------------------------------------------------
595 // And this gets appended to the shadow class file.
596 //----------------------------------------------------------------------
598 %pragma(python) include="_htmlextras.py";
600 //---------------------------------------------------------------------------