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();
86 void SetEvent(const wxMouseEvent *e);
87 void SetHtmlCell(const wxHtmlCell * e);
90 //---------------------------------------------------------------------------
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 //---------------------------------------------------------------------------
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 {
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 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
205 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
209 %name(wxHtmlTagHandler) class wxPyHtmlTagHandler {
211 wxPyHtmlTagHandler();
213 void _setSelf(PyObject* self, PyObject* _class);
214 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxHtmlTagHandler)"
216 void SetParser(wxHtmlParser *parser);
217 wxHtmlParser* GetParser();
218 void ParseInner(const wxHtmlTag& tag);
222 //---------------------------------------------------------------------------
225 class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
227 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
229 wxHtmlWinParser* GetParser() { return m_WParser; }
230 void ParseInner(const wxHtmlTag& tag)
231 { wxHtmlWinTagHandler::ParseInner(tag); }
233 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
234 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
239 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
240 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
244 %name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
246 wxPyHtmlWinTagHandler();
248 void _setSelf(PyObject* self, PyObject* _class);
249 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxHtmlWinTagHandler)"
251 void SetParser(wxHtmlParser *parser);
252 wxHtmlWinParser* GetParser();
253 void ParseInner(const wxHtmlTag& tag);
257 //---------------------------------------------------------------------------
261 class wxPyHtmlTagsModule : public wxHtmlTagsModule {
263 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
264 m_tagHandlerClass = thc;
265 Py_INCREF(m_tagHandlerClass);
266 RegisterModule(this);
267 wxHtmlWinParser::AddModule(this);
271 bool doSave = wxPyRestoreThread();
272 Py_DECREF(m_tagHandlerClass);
273 m_tagHandlerClass = NULL;
274 for (size_t x=0; x < m_objArray.GetCount(); x++) {
275 PyObject* obj = (PyObject*)m_objArray.Item(x);
278 wxPySaveThread(doSave);
281 void FillHandlersTable(wxHtmlWinParser *parser) {
282 // Wave our magic wand... (if it works it's a miracle! ;-)
284 // First, make a new instance of the tag handler
285 bool doSave = wxPyRestoreThread();
286 PyObject* arg = Py_BuildValue("()");
287 PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
289 wxPySaveThread(doSave);
291 // now figure out where it's C++ object is...
292 wxPyHtmlWinTagHandler* thPtr;
293 if (SWIG_GetPtrObj(obj, (void **)&thPtr, "_wxPyHtmlWinTagHandler_p"))
297 parser->AddTagHandler(thPtr);
304 PyObject* m_tagHandlerClass;
305 wxArrayPtrVoid m_objArray;
313 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
314 // Dynamically create a new wxModule. Refcounts tagHandlerClass
315 // and adds itself to the wxModules list and to the wxHtmlWinParser.
316 new wxPyHtmlTagsModule(tagHandlerClass);
321 //---------------------------------------------------------------------------
322 //---------------------------------------------------------------------------
333 wxHtmlLinkInfo* GetLink(int x = 0, int y = 0);
334 wxHtmlCell* GetNext();
335 wxHtmlContainerCell* GetParent();
336 void SetLink(const wxHtmlLinkInfo& link);
337 void SetNext(wxHtmlCell *cell);
338 void SetParent(wxHtmlContainerCell *p);
339 void SetPos(int x, int y);
341 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
342 void DrawInvisible(wxDC& dc, int x, int y);
343 const wxHtmlCell* Find(int condition, const void* param);
345 bool AdjustPagebreak(int * pagebreak);
346 void SetCanLiveOnPagebreak(bool can);
351 class wxHtmlContainerCell : public wxHtmlCell {
353 wxHtmlContainerCell(wxHtmlContainerCell *parent);
355 void InsertCell(wxHtmlCell *cell);
356 void SetAlignHor(int al);
358 void SetAlignVer(int al);
360 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
361 int GetIndent(int ind);
362 int GetIndentUnits(int ind);
363 void SetAlign(const wxHtmlTag& tag);
364 void SetWidthFloat(int w, int units);
365 %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
366 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
367 void SetBackgroundColour(const wxColour& clr);
368 void SetBorder(const wxColour& clr1, const wxColour& clr2);
369 wxHtmlCell* GetFirstCell();
374 class wxHtmlColourCell : public wxHtmlCell {
376 wxHtmlColourCell(wxColour clr, int flags = wxHTML_CLR_FOREGROUND);
382 class wxHtmlWidgetCell : public wxHtmlCell {
384 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
390 //---------------------------------------------------------------------------
391 //---------------------------------------------------------------------------
392 //---------------------------------------------------------------------------
395 class wxPyHtmlWindow : public wxHtmlWindow {
397 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
398 const wxPoint& pos = wxDefaultPosition,
399 const wxSize& size = wxDefaultSize,
400 long style = wxHW_SCROLLBAR_AUTO,
401 const wxString& name = "htmlWindow")
402 : wxHtmlWindow(parent, id, pos, size, style, name) {};
404 void OnLinkClicked(const wxHtmlLinkInfo& link);
405 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
407 DEC_PYCALLBACK__STRING(OnSetTitle);
412 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
414 void wxPyHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) {
415 bool doSave = wxPyRestoreThread();
416 if (wxPyCBH_findCallback(m_myInst, "OnLinkClicked")) {
417 PyObject* obj = wxPyConstructObject((void*)&link, "wxHtmlLinkInfo", 0);
418 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj));
422 wxHtmlWindow::OnLinkClicked(link);
423 wxPySaveThread(doSave);
425 void wxPyHtmlWindow::base_OnLinkClicked(const wxHtmlLinkInfo& link) {
426 wxHtmlWindow::OnLinkClicked(link);
432 %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
434 wxPyHtmlWindow(wxWindow *parent, int id = -1,
435 wxPoint& pos = wxDefaultPosition,
436 wxSize& size = wxDefaultSize,
437 int flags=wxHW_SCROLLBAR_AUTO,
438 char* name = "htmlWindow");
440 void _setSelf(PyObject* self, PyObject* _class);
441 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxHtmlWindow)"
442 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
443 %pragma(python) addtomethod = "__init__:#wx._StdOnScrollCallbacks(self)"
446 bool SetPage(const wxString& source);
447 bool LoadPage(const wxString& location);
448 wxString GetOpenedPage();
449 wxString GetOpenedAnchor();
450 wxString GetOpenedPageTitle();
452 void SetRelatedFrame(wxFrame* frame, const char* format);
453 wxFrame* GetRelatedFrame();
454 void SetRelatedStatusBar(int bar);
456 //void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
458 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes) {
459 int* temp = int_LIST_helper(sizes);
461 self->SetFonts(normal_face, fixed_face, temp);
467 void SetTitle(const wxString& title);
468 void SetBorders(int b);
469 void ReadCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
470 void WriteCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
472 bool HistoryForward();
473 bool HistoryCanBack();
474 bool HistoryCanForward();
476 wxHtmlContainerCell* GetInternalRepresentation();
477 wxHtmlWinParser* GetParser();
479 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
480 void base_OnSetTitle(const char* title);
483 // Static methods are mapped to stand-alone functions
485 void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) {
486 wxHtmlWindow::AddFilter(filter);
491 //---------------------------------------------------------------------------
492 //---------------------------------------------------------------------------
495 class wxHtmlDCRenderer {
500 void SetDC(wxDC *dc, int maxwidth);
501 void SetSize(int width, int height);
502 void SetHtmlText(const wxString& html,
503 const wxString& basepath = wxEmptyString,
505 int Render(int x, int y, int from = 0, int dont_render = FALSE);
506 int GetTotalHeight();
507 // returns total height of the html document
508 // (compare Render's return value with this)
518 class wxHtmlPrintout : public wxPyPrintout {
520 wxHtmlPrintout(const char* title = "Printout");
521 //~wxHtmlPrintout(); wxPrintPreview object takes ownership...
523 void SetHtmlText(const wxString& html,
524 const wxString &basepath = wxEmptyString,
526 void SetHtmlFile(const wxString &htmlfile);
527 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
528 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
529 void SetMargins(float top = 25.2, float bottom = 25.2,
530 float left = 25.2, float right = 25.2,
536 class wxHtmlEasyPrinting {
538 wxHtmlEasyPrinting(const char* name = "Printing",
539 wxFrame *parent_frame = NULL);
540 ~wxHtmlEasyPrinting();
542 void PreviewFile(const wxString &htmlfile);
543 void PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
544 void PrintFile(const wxString &htmlfile);
545 void PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
548 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
549 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
551 wxPrintData *GetPrintData() {return m_PrintData;}
552 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
558 //---------------------------------------------------------------------------
559 //---------------------------------------------------------------------------
562 extern "C" SWIGEXPORT(void) inithtmlhelpc();
570 wxClassInfo::CleanUpClasses();
571 wxClassInfo::InitializeClasses();
574 //----------------------------------------------------------------------
575 // And this gets appended to the shadow class file.
576 //----------------------------------------------------------------------
578 %pragma(python) include="_htmlextras.py";
580 //---------------------------------------------------------------------------