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);
94 wxMouseEvent* GetEvent();
95 wxHtmlCell* GetHtmlCell();
99 //---------------------------------------------------------------------------
103 // Never need to create a new tag from Python...
104 //wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
107 bool HasParam(const wxString& par);
108 wxString GetParam(const wxString& par, int with_commas = FALSE);
110 // Can't do this one as-is, but GetParam should be enough...
111 //int ScanParam(const wxString& par, const char *format, void* param);
113 wxString GetAllParams();
122 //---------------------------------------------------------------------------
126 // wxHtmlParser(); This is an abstract base class...
128 void SetFS(wxFileSystem *fs);
129 wxFileSystem* GetFS();
130 wxObject* Parse(const wxString& source);
131 void InitParser(const wxString& source);
133 void DoParsing(int begin_pos, int end_pos);
134 // wxObject* GetProduct();
135 void AddTagHandler(wxHtmlTagHandler *handler);
136 wxString* GetSource();
137 void PushTagHandler(wxHtmlTagHandler* handler, wxString tags);
138 void PopTagHandler();
141 // void AddText(const char* txt) = 0;
142 // void AddTag(const wxHtmlTag& tag);
146 //---------------------------------------------------------------------------
148 class wxHtmlWinParser : public wxHtmlParser {
150 wxHtmlWinParser(wxWindow *wnd);
152 void SetDC(wxDC *dc);
156 wxWindow* GetWindow();
157 void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
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);
214 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
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);
249 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
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 Py_DECREF(m_tagHandlerClass);
272 m_tagHandlerClass = NULL;
273 for (size_t x=0; x < m_objArray.GetCount(); x++) {
274 PyObject* obj = (PyObject*)m_objArray.Item(x);
279 void FillHandlersTable(wxHtmlWinParser *parser) {
280 // Wave our magic wand... (if it works it's a miracle! ;-)
282 // First, make a new instance of the tag handler
283 bool doSave = wxPyRestoreThread();
284 PyObject* arg = Py_BuildValue("()");
285 PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
287 wxPySaveThread(doSave);
289 // now figure out where it's C++ object is...
290 wxPyHtmlWinTagHandler* thPtr;
291 if (SWIG_GetPtrObj(obj, (void **)&thPtr, "_wxPyHtmlWinTagHandler_p"))
295 parser->AddTagHandler(thPtr);
302 PyObject* m_tagHandlerClass;
303 wxArrayPtrVoid m_objArray;
311 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
312 // Dynamically create a new wxModule. Refcounts tagHandlerClass
313 // and adds itself to the wxModules list and to the wxHtmlWinParser.
314 new wxPyHtmlTagsModule(tagHandlerClass);
319 //---------------------------------------------------------------------------
320 //---------------------------------------------------------------------------
331 wxHtmlLinkInfo* GetLink(int x = 0, int y = 0);
332 wxHtmlCell* GetNext();
333 wxHtmlContainerCell* GetParent();
334 void SetLink(const wxHtmlLinkInfo& link);
335 void SetNext(wxHtmlCell *cell);
336 void SetParent(wxHtmlContainerCell *p);
337 void SetPos(int x, int y);
339 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
340 void DrawInvisible(wxDC& dc, int x, int y);
341 const wxHtmlCell* Find(int condition, const void* param);
343 bool AdjustPagebreak(int * pagebreak);
344 void SetCanLiveOnPagebreak(bool can);
349 class wxHtmlContainerCell : public wxHtmlCell {
351 wxHtmlContainerCell(wxHtmlContainerCell *parent);
353 void InsertCell(wxHtmlCell *cell);
354 void SetAlignHor(int al);
356 void SetAlignVer(int al);
358 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
359 int GetIndent(int ind);
360 int GetIndentUnits(int ind);
361 void SetAlign(const wxHtmlTag& tag);
362 void SetWidthFloat(int w, int units);
363 %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
364 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
365 void SetBackgroundColour(const wxColour& clr);
366 void SetBorder(const wxColour& clr1, const wxColour& clr2);
367 wxHtmlCell* GetFirstCell();
372 class wxHtmlColourCell : public wxHtmlCell {
374 wxHtmlColourCell(wxColour clr, int flags = wxHTML_CLR_FOREGROUND);
380 class wxHtmlWidgetCell : public wxHtmlCell {
382 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
388 //---------------------------------------------------------------------------
389 //---------------------------------------------------------------------------
390 //---------------------------------------------------------------------------
392 // item of history list
393 class HtmlHistoryItem {
395 HtmlHistoryItem(const char* p, const char* a);
399 const wxString& GetPage();
400 const wxString& GetAnchor();
404 //---------------------------------------------------------------------------
406 class wxPyHtmlWindow : public wxHtmlWindow {
408 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
409 const wxPoint& pos = wxDefaultPosition,
410 const wxSize& size = wxDefaultSize,
411 long style = wxHW_SCROLLBAR_AUTO,
412 const wxString& name = "htmlWindow")
413 : wxHtmlWindow(parent, id, pos, size, style, name) {};
416 void OnLinkClicked(const wxHtmlLinkInfo& link);
417 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
419 void OnLinkClicked(wxHtmlLinkInfo* link);
420 void base_OnLinkClicked(wxHtmlLinkInfo* link);
423 DEC_PYCALLBACK__STRING(OnSetTitle);
428 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
431 void wxPyHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) {
433 void wxPyHtmlWindow::OnLinkClicked(wxHtmlLinkInfo* link) {
435 bool doSave = wxPyRestoreThread();
436 if (m_myInst.findCallback("OnLinkClicked")) {
438 PyObject* obj = wxPyConstructObject((void*)&link, "wxHtmlLinkInfo");
440 PyObject* obj = wxPyConstructObject(link, "wxHtmlLinkInfo");
442 m_myInst.callCallback(Py_BuildValue("(O)", obj));
445 wxHtmlWindow::OnLinkClicked(link);
446 wxPySaveThread(doSave);
449 void wxPyHtmlWindow::base_OnLinkClicked(const wxHtmlLinkInfo& link) {
451 void wxPyHtmlWindow::base_OnLinkClicked(wxHtmlLinkInfo* link) {
453 wxHtmlWindow::OnLinkClicked(link);
459 %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
461 wxPyHtmlWindow(wxWindow *parent, int id = -1,
462 wxPoint& pos = wxPyDefaultPosition,
463 wxSize& size = wxPyDefaultSize,
464 int flags=wxHW_SCROLLBAR_AUTO,
465 char* name = "htmlWindow");
467 void _setSelf(PyObject* self);
468 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
469 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
470 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
473 bool SetPage(const char* source);
474 bool LoadPage(const char* location);
475 wxString GetOpenedPage();
476 void SetRelatedFrame(wxFrame* frame, const char* format);
477 wxFrame* GetRelatedFrame();
478 void SetRelatedStatusBar(int bar);
479 void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
480 void SetTitle(const char* title);
481 void SetBorders(int b);
482 void ReadCustomization(wxConfigBase *cfg, char* path = "");
483 void WriteCustomization(wxConfigBase *cfg, char* path = "");
485 bool HistoryForward();
487 wxHtmlContainerCell* GetInternalRepresentation();
488 wxHtmlWinParser* GetParser();
491 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
493 void base_OnLinkClicked(wxHtmlLinkInfo* link);
495 void base_OnSetTitle(const char* title);
498 // Static methods are mapped to stand-alone functions
500 void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) {
501 wxHtmlWindow::AddFilter(filter);
506 //---------------------------------------------------------------------------
507 //---------------------------------------------------------------------------
510 class wxHtmlDCRenderer {
515 void SetDC(wxDC *dc, int maxwidth);
516 void SetSize(int width, int height);
517 void SetHtmlText(const wxString& html,
518 const wxString& basepath = wxEmptyString,
520 int Render(int x, int y, int from = 0, int dont_render = FALSE);
521 int GetTotalHeight();
522 // returns total height of the html document
523 // (compare Render's return value with this)
533 class wxHtmlPrintout : public wxPyPrintout {
535 wxHtmlPrintout(const char* title = "Printout");
538 void SetHtmlText(const wxString& html,
539 const wxString &basepath = wxEmptyString,
541 void SetHtmlFile(const wxString &htmlfile);
542 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
543 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
544 void SetMargins(float top = 25.2, float bottom = 25.2,
545 float left = 25.2, float right = 25.2,
551 class wxHtmlEasyPrinting {
553 wxHtmlEasyPrinting(const char* name = "Printing",
554 wxFrame *parent_frame = NULL);
555 ~wxHtmlEasyPrinting();
557 void PreviewFile(const wxString &htmlfile);
558 void PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
559 void PrintFile(const wxString &htmlfile);
560 void PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
563 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
564 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
566 wxPrintData *GetPrintData() {return m_PrintData;}
567 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
573 //---------------------------------------------------------------------------
574 //---------------------------------------------------------------------------
577 extern "C" SWIGEXPORT(void) inithtmlhelpc();
585 wxClassInfo::CleanUpClasses();
586 wxClassInfo::InitializeClasses();
588 // Until wxFileSystem is wrapped...
590 wxFileSystem::AddHandler(new wxZipFSHandler);
594 //----------------------------------------------------------------------
595 // And this gets appended to the shadow class file.
596 //----------------------------------------------------------------------
598 %pragma(python) include="_extras.py";
600 //---------------------------------------------------------------------------