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 {
80 wxHtmlLinkInfo(const wxString& href, const wxString& target = wxEmptyString);
83 wxMouseEvent* GetEvent();
84 wxHtmlCell* GetHtmlCell();
87 //---------------------------------------------------------------------------
91 // Never need to create a new tag from Python...
92 //wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
95 bool HasParam(const wxString& par);
96 wxString GetParam(const wxString& par, int with_commas = FALSE);
98 // Can't do this one as-is, but GetParam should be enough...
99 //int ScanParam(const wxString& par, const char *format, void* param);
101 wxString GetAllParams();
110 //---------------------------------------------------------------------------
114 // wxHtmlParser(); This is an abstract base class...
116 void SetFS(wxFileSystem *fs);
117 wxFileSystem* GetFS();
118 wxObject* Parse(const wxString& source);
119 void InitParser(const wxString& source);
121 void DoParsing(int begin_pos, int end_pos);
122 // wxObject* GetProduct();
123 void AddTagHandler(wxHtmlTagHandler *handler);
124 wxString* GetSource();
125 void PushTagHandler(wxHtmlTagHandler* handler, wxString tags);
126 void PopTagHandler();
129 // void AddText(const char* txt) = 0;
130 // void AddTag(const wxHtmlTag& tag);
134 //---------------------------------------------------------------------------
136 class wxHtmlWinParser : public wxHtmlParser {
138 wxHtmlWinParser(wxWindow *wnd);
140 void SetDC(wxDC *dc);
144 wxWindow* GetWindow();
145 //void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
147 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes) {
148 int* temp = int_LIST_helper(sizes);
150 self->SetFonts(normal_face, fixed_face, temp);
156 wxHtmlContainerCell* GetContainer();
157 wxHtmlContainerCell* OpenContainer();
158 wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
159 wxHtmlContainerCell* CloseContainer();
162 void SetFontSize(int s);
164 void SetFontBold(int x);
166 void SetFontItalic(int x);
167 int GetFontUnderlined();
168 void SetFontUnderlined(int x);
170 void SetFontFixed(int x);
172 void SetAlign(int a);
173 const wxColour& GetLinkColor();
174 void SetLinkColor(const wxColour& clr);
175 const wxColour& GetActualColor();
176 void SetActualColor(const wxColour& clr);
177 void SetLink(const wxString& link);
178 wxFont* CreateCurrentFont();
179 wxHtmlLinkInfo GetLink();
185 //---------------------------------------------------------------------------
188 class wxPyHtmlTagHandler : public wxHtmlTagHandler {
190 wxPyHtmlTagHandler() : wxHtmlTagHandler() {};
192 wxHtmlParser* GetParser() { return m_Parser; }
193 void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); }
195 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
196 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
201 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
202 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
206 %name(wxHtmlTagHandler) class wxPyHtmlTagHandler {
208 wxPyHtmlTagHandler();
210 void _setSelf(PyObject* self, PyObject* _class);
211 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxHtmlTagHandler)"
213 void SetParser(wxHtmlParser *parser);
214 wxHtmlParser* GetParser();
215 void ParseInner(const wxHtmlTag& tag);
219 //---------------------------------------------------------------------------
222 class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
224 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
226 wxHtmlWinParser* GetParser() { return m_WParser; }
227 void ParseInner(const wxHtmlTag& tag)
228 { wxHtmlWinTagHandler::ParseInner(tag); }
230 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
231 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
236 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
237 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
241 %name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
243 wxPyHtmlWinTagHandler();
245 void _setSelf(PyObject* self, PyObject* _class);
246 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxHtmlWinTagHandler)"
248 void SetParser(wxHtmlParser *parser);
249 wxHtmlWinParser* GetParser();
250 void ParseInner(const wxHtmlTag& tag);
254 //---------------------------------------------------------------------------
258 class wxPyHtmlTagsModule : public wxHtmlTagsModule {
260 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
261 m_tagHandlerClass = thc;
262 Py_INCREF(m_tagHandlerClass);
263 RegisterModule(this);
264 wxHtmlWinParser::AddModule(this);
268 bool doSave = wxPyRestoreThread();
269 Py_DECREF(m_tagHandlerClass);
270 m_tagHandlerClass = NULL;
271 for (size_t x=0; x < m_objArray.GetCount(); x++) {
272 PyObject* obj = (PyObject*)m_objArray.Item(x);
275 wxPySaveThread(doSave);
278 void FillHandlersTable(wxHtmlWinParser *parser) {
279 // Wave our magic wand... (if it works it's a miracle! ;-)
281 // First, make a new instance of the tag handler
282 bool doSave = wxPyRestoreThread();
283 PyObject* arg = Py_BuildValue("()");
284 PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
286 wxPySaveThread(doSave);
288 // now figure out where it's C++ object is...
289 wxPyHtmlWinTagHandler* thPtr;
290 if (SWIG_GetPtrObj(obj, (void **)&thPtr, "_wxPyHtmlWinTagHandler_p"))
294 parser->AddTagHandler(thPtr);
301 PyObject* m_tagHandlerClass;
302 wxArrayPtrVoid m_objArray;
310 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
311 // Dynamically create a new wxModule. Refcounts tagHandlerClass
312 // and adds itself to the wxModules list and to the wxHtmlWinParser.
313 new wxPyHtmlTagsModule(tagHandlerClass);
318 //---------------------------------------------------------------------------
319 //---------------------------------------------------------------------------
330 wxHtmlLinkInfo* GetLink(int x = 0, int y = 0);
331 wxHtmlCell* GetNext();
332 wxHtmlContainerCell* GetParent();
333 void SetLink(const wxHtmlLinkInfo& link);
334 void SetNext(wxHtmlCell *cell);
335 void SetParent(wxHtmlContainerCell *p);
336 void SetPos(int x, int y);
338 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
339 void DrawInvisible(wxDC& dc, int x, int y);
340 const wxHtmlCell* Find(int condition, const void* param);
342 bool AdjustPagebreak(int * pagebreak);
343 void SetCanLiveOnPagebreak(bool can);
348 class wxHtmlContainerCell : public wxHtmlCell {
350 wxHtmlContainerCell(wxHtmlContainerCell *parent);
352 void InsertCell(wxHtmlCell *cell);
353 void SetAlignHor(int al);
355 void SetAlignVer(int al);
357 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
358 int GetIndent(int ind);
359 int GetIndentUnits(int ind);
360 void SetAlign(const wxHtmlTag& tag);
361 void SetWidthFloat(int w, int units);
362 %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
363 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
364 void SetBackgroundColour(const wxColour& clr);
365 void SetBorder(const wxColour& clr1, const wxColour& clr2);
366 wxHtmlCell* GetFirstCell();
371 class wxHtmlColourCell : public wxHtmlCell {
373 wxHtmlColourCell(wxColour clr, int flags = wxHTML_CLR_FOREGROUND);
379 class wxHtmlWidgetCell : public wxHtmlCell {
381 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
387 //---------------------------------------------------------------------------
388 //---------------------------------------------------------------------------
389 //---------------------------------------------------------------------------
391 // item of history list
392 class HtmlHistoryItem {
394 HtmlHistoryItem(const char* p, const char* a);
398 const wxString& GetPage();
399 const wxString& GetAnchor();
403 //---------------------------------------------------------------------------
405 class wxPyHtmlWindow : public wxHtmlWindow {
407 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
408 const wxPoint& pos = wxDefaultPosition,
409 const wxSize& size = wxDefaultSize,
410 long style = wxHW_SCROLLBAR_AUTO,
411 const wxString& name = "htmlWindow")
412 : wxHtmlWindow(parent, id, pos, size, style, name) {};
414 void OnLinkClicked(const wxHtmlLinkInfo& link);
415 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
417 DEC_PYCALLBACK__STRING(OnSetTitle);
422 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
424 void wxPyHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) {
425 bool doSave = wxPyRestoreThread();
426 if (wxPyCBH_findCallback(m_myInst, "OnLinkClicked")) {
427 PyObject* obj = wxPyConstructObject((void*)&link, "wxHtmlLinkInfo", 0);
428 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj));
432 wxHtmlWindow::OnLinkClicked(link);
433 wxPySaveThread(doSave);
435 void wxPyHtmlWindow::base_OnLinkClicked(const wxHtmlLinkInfo& link) {
436 wxHtmlWindow::OnLinkClicked(link);
442 %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
444 wxPyHtmlWindow(wxWindow *parent, int id = -1,
445 wxPoint& pos = wxDefaultPosition,
446 wxSize& size = wxDefaultSize,
447 int flags=wxHW_SCROLLBAR_AUTO,
448 char* name = "htmlWindow");
450 void _setSelf(PyObject* self, PyObject* _class);
451 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxHtmlWindow)"
452 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
453 %pragma(python) addtomethod = "__init__:#wx._StdOnScrollCallbacks(self)"
456 bool SetPage(const char* source);
457 bool LoadPage(const char* location);
458 wxString GetOpenedPage();
459 void SetRelatedFrame(wxFrame* frame, const char* format);
460 wxFrame* GetRelatedFrame();
461 void SetRelatedStatusBar(int bar);
463 //void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
465 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes) {
466 int* temp = int_LIST_helper(sizes);
468 self->SetFonts(normal_face, fixed_face, temp);
474 void SetTitle(const char* title);
475 void SetBorders(int b);
476 void ReadCustomization(wxConfigBase *cfg, char* path = "");
477 void WriteCustomization(wxConfigBase *cfg, char* path = "");
479 bool HistoryForward();
481 wxHtmlContainerCell* GetInternalRepresentation();
482 wxHtmlWinParser* GetParser();
484 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
485 void base_OnSetTitle(const char* title);
488 // Static methods are mapped to stand-alone functions
490 void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) {
491 wxHtmlWindow::AddFilter(filter);
496 //---------------------------------------------------------------------------
497 //---------------------------------------------------------------------------
500 class wxHtmlDCRenderer {
505 void SetDC(wxDC *dc, int maxwidth);
506 void SetSize(int width, int height);
507 void SetHtmlText(const wxString& html,
508 const wxString& basepath = wxEmptyString,
510 int Render(int x, int y, int from = 0, int dont_render = FALSE);
511 int GetTotalHeight();
512 // returns total height of the html document
513 // (compare Render's return value with this)
523 class wxHtmlPrintout : public wxPyPrintout {
525 wxHtmlPrintout(const char* title = "Printout");
528 void SetHtmlText(const wxString& html,
529 const wxString &basepath = wxEmptyString,
531 void SetHtmlFile(const wxString &htmlfile);
532 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
533 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
534 void SetMargins(float top = 25.2, float bottom = 25.2,
535 float left = 25.2, float right = 25.2,
541 class wxHtmlEasyPrinting {
543 wxHtmlEasyPrinting(const char* name = "Printing",
544 wxFrame *parent_frame = NULL);
545 ~wxHtmlEasyPrinting();
547 void PreviewFile(const wxString &htmlfile);
548 void PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
549 void PrintFile(const wxString &htmlfile);
550 void PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
553 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
554 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
556 wxPrintData *GetPrintData() {return m_PrintData;}
557 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
563 //---------------------------------------------------------------------------
564 //---------------------------------------------------------------------------
567 extern "C" SWIGEXPORT(void) inithtmlhelpc();
575 wxClassInfo::CleanUpClasses();
576 wxClassInfo::InitializeClasses();
579 //----------------------------------------------------------------------
580 // And this gets appended to the shadow class file.
581 //----------------------------------------------------------------------
583 %pragma(python) include="_htmlextras.py";
585 //---------------------------------------------------------------------------