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);
95 //---------------------------------------------------------------------------
99 // Never need to create a new tag from Python...
100 //wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
103 bool HasParam(const wxString& par);
104 wxString GetParam(const wxString& par, int with_commas = FALSE);
106 // Can't do this one as-is, but GetParam should be enough...
107 //int ScanParam(const wxString& par, const char *format, void* param);
109 wxString GetAllParams();
118 //---------------------------------------------------------------------------
122 // wxHtmlParser(); This is an abstract base class...
124 void SetFS(wxFileSystem *fs);
125 wxFileSystem* GetFS();
126 wxObject* Parse(const wxString& source);
127 void InitParser(const wxString& source);
129 void DoParsing(int begin_pos, int end_pos);
130 // wxObject* GetProduct();
131 void AddTagHandler(wxHtmlTagHandler *handler);
132 wxString* GetSource();
133 void PushTagHandler(wxHtmlTagHandler* handler, wxString tags);
134 void PopTagHandler();
137 // void AddText(const char* txt) = 0;
138 // void AddTag(const wxHtmlTag& tag);
142 //---------------------------------------------------------------------------
144 class wxHtmlWinParser : public wxHtmlParser {
146 wxHtmlWinParser(wxWindow *wnd);
148 void SetDC(wxDC *dc);
152 wxWindow* GetWindow();
153 void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
155 wxHtmlContainerCell* GetContainer();
156 wxHtmlContainerCell* OpenContainer();
157 wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
158 wxHtmlContainerCell* CloseContainer();
161 void SetFontSize(int s);
163 void SetFontBold(int x);
165 void SetFontItalic(int x);
166 int GetFontUnderlined();
167 void SetFontUnderlined(int x);
169 void SetFontFixed(int x);
171 void SetAlign(int a);
172 const wxColour& GetLinkColor();
173 void SetLinkColor(const wxColour& clr);
174 const wxColour& GetActualColor();
175 void SetActualColor(const wxColour& clr);
176 void SetLink(const wxString& link);
177 wxFont* CreateCurrentFont();
178 wxHtmlLinkInfo GetLink();
184 //---------------------------------------------------------------------------
187 class wxPyHtmlTagHandler : public wxHtmlTagHandler {
189 wxPyHtmlTagHandler() : wxHtmlTagHandler() {};
191 wxHtmlParser* GetParser() { return m_Parser; }
192 void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); }
194 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
195 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
200 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
201 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
205 %name(wxHtmlTagHandler) class wxPyHtmlTagHandler {
207 wxPyHtmlTagHandler();
209 void _setSelf(PyObject* self);
210 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
212 void SetParser(wxHtmlParser *parser);
213 wxHtmlParser* GetParser();
214 void ParseInner(const wxHtmlTag& tag);
218 //---------------------------------------------------------------------------
221 class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
223 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
225 wxHtmlWinParser* GetParser() { return m_WParser; }
226 void ParseInner(const wxHtmlTag& tag)
227 { wxHtmlWinTagHandler::ParseInner(tag); }
229 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
230 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
235 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
236 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
240 %name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
242 wxPyHtmlWinTagHandler();
244 void _setSelf(PyObject* self);
245 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
247 void SetParser(wxHtmlParser *parser);
248 wxHtmlWinParser* GetParser();
249 void ParseInner(const wxHtmlTag& tag);
253 //---------------------------------------------------------------------------
257 class wxPyHtmlTagsModule : public wxHtmlTagsModule {
259 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
260 m_tagHandlerClass = thc;
261 Py_INCREF(m_tagHandlerClass);
262 RegisterModule(this);
263 wxHtmlWinParser::AddModule(this);
267 Py_DECREF(m_tagHandlerClass);
268 m_tagHandlerClass = NULL;
269 for (size_t x=0; x < m_objArray.GetCount(); x++) {
270 PyObject* obj = (PyObject*)m_objArray.Item(x);
275 void FillHandlersTable(wxHtmlWinParser *parser) {
276 // Wave our magic wand... (if it works it's a miracle! ;-)
278 // First, make a new instance of the tag handler
279 bool doSave = wxPyRestoreThread();
280 PyObject* arg = Py_BuildValue("()");
281 PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
283 wxPySaveThread(doSave);
285 // now figure out where it's C++ object is...
286 wxPyHtmlWinTagHandler* thPtr;
287 if (SWIG_GetPtrObj(obj, (void **)&thPtr, "_wxPyHtmlWinTagHandler_p"))
291 parser->AddTagHandler(thPtr);
298 PyObject* m_tagHandlerClass;
299 wxArrayPtrVoid m_objArray;
307 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
308 // Dynamically create a new wxModule. Refcounts tagHandlerClass
309 // and adds itself to the wxModules list and to the wxHtmlWinParser.
310 new wxPyHtmlTagsModule(tagHandlerClass);
315 //---------------------------------------------------------------------------
316 //---------------------------------------------------------------------------
327 wxHtmlLinkInfo* GetLink(int x = 0, int y = 0);
328 wxHtmlCell* GetNext();
329 wxHtmlContainerCell* GetParent();
330 void SetLink(const wxHtmlLinkInfo& link);
331 void SetNext(wxHtmlCell *cell);
332 void SetParent(wxHtmlContainerCell *p);
333 void SetPos(int x, int y);
335 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
336 void DrawInvisible(wxDC& dc, int x, int y);
337 const wxHtmlCell* Find(int condition, const void* param);
339 bool AdjustPagebreak(int * pagebreak);
340 void SetCanLiveOnPagebreak(bool can);
345 class wxHtmlContainerCell : public wxHtmlCell {
347 wxHtmlContainerCell(wxHtmlContainerCell *parent);
349 void InsertCell(wxHtmlCell *cell);
350 void SetAlignHor(int al);
352 void SetAlignVer(int al);
354 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
355 int GetIndent(int ind);
356 int GetIndentUnits(int ind);
357 void SetAlign(const wxHtmlTag& tag);
358 void SetWidthFloat(int w, int units);
359 %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
360 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
361 int GetMaxLineWidth();
362 void SetBackgroundColour(const wxColour& clr);
363 void SetBorder(const wxColour& clr1, const wxColour& clr2);
364 wxHtmlCell* GetFirstCell();
369 class wxHtmlColourCell : public wxHtmlCell {
371 wxHtmlColourCell(wxColour clr, int flags = wxHTML_CLR_FOREGROUND);
377 class wxHtmlWidgetCell : public wxHtmlCell {
379 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
385 //---------------------------------------------------------------------------
386 //---------------------------------------------------------------------------
387 //---------------------------------------------------------------------------
389 // item of history list
390 class HtmlHistoryItem {
392 HtmlHistoryItem(const char* p, const char* a);
396 const wxString& GetPage();
397 const wxString& GetAnchor();
401 //---------------------------------------------------------------------------
403 class wxPyHtmlWindow : public wxHtmlWindow {
405 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
406 const wxPoint& pos = wxDefaultPosition,
407 const wxSize& size = wxDefaultSize,
408 long style = wxHW_SCROLLBAR_AUTO,
409 const wxString& name = "htmlWindow")
410 : wxHtmlWindow(parent, id, pos, size, style, name) {};
413 void OnLinkClicked(wxHtmlLinkInfo* link);
414 void base_OnLinkClicked(wxHtmlLinkInfo* link);
416 DEC_PYCALLBACK__STRING(OnSetTitle);
420 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
422 void wxPyHtmlWindow::OnLinkClicked(wxHtmlLinkInfo* link) {
423 bool doSave = wxPyRestoreThread();
424 if (m_myInst.findCallback("OnLinkClicked")) {
425 PyObject* obj = wxPyConstructObject(link, "wxHtmlLinkInfo");
426 m_myInst.callCallback(Py_BuildValue("(O)", obj));
429 wxHtmlWindow::OnLinkClicked(link);
430 wxPySaveThread(doSave);
432 void wxPyHtmlWindow::base_OnLinkClicked(wxHtmlLinkInfo* link) {
433 wxHtmlWindow::OnLinkClicked(link);
438 %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
440 wxPyHtmlWindow(wxWindow *parent, int id = -1,
441 wxPoint& pos = wxPyDefaultPosition,
442 wxSize& size = wxPyDefaultSize,
443 int flags=wxHW_SCROLLBAR_AUTO,
444 char* name = "htmlWindow");
446 void _setSelf(PyObject* self);
447 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
448 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
449 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
452 bool SetPage(const char* source);
453 bool LoadPage(const char* location);
454 wxString GetOpenedPage();
455 void SetRelatedFrame(wxFrame* frame, const char* format);
456 wxFrame* GetRelatedFrame();
457 void SetRelatedStatusBar(int bar);
458 void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
459 void SetTitle(const char* title);
460 void SetBorders(int b);
461 void ReadCustomization(wxConfigBase *cfg, char* path = "");
462 void WriteCustomization(wxConfigBase *cfg, char* path = "");
464 bool HistoryForward();
466 wxHtmlContainerCell* GetInternalRepresentation();
467 wxHtmlWinParser* GetParser();
470 void base_OnSetTitle(const char* title);
473 // Static methods are mapped to stand-alone functions
475 void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) {
476 wxHtmlWindow::AddFilter(filter);
481 //---------------------------------------------------------------------------
482 //---------------------------------------------------------------------------
485 class wxHtmlDCRenderer {
490 void SetDC(wxDC *dc, int maxwidth);
491 void SetSize(int width, int height);
492 void SetHtmlText(const wxString& html,
493 const wxString& basepath = wxEmptyString,
495 int Render(int x, int y, int from = 0, int dont_render = FALSE);
496 int GetTotalHeight();
497 // returns total height of the html document
498 // (compare Render's return value with this)
508 class wxHtmlPrintout : public wxPyPrintout {
510 wxHtmlPrintout(const char* title = "Printout");
513 void SetHtmlText(const wxString& html,
514 const wxString &basepath = wxEmptyString,
516 void SetHtmlFile(const wxString &htmlfile);
517 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
518 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
519 void SetMargins(float top = 25.2, float bottom = 25.2,
520 float left = 25.2, float right = 25.2,
526 class wxHtmlEasyPrinting {
528 wxHtmlEasyPrinting(const char* name = "Printing",
529 wxFrame *parent_frame = NULL);
530 ~wxHtmlEasyPrinting();
532 void PreviewFile(const wxString &htmlfile);
533 void PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
534 void PrintFile(const wxString &htmlfile);
535 void PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
538 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
539 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
541 wxPrintData *GetPrintData() {return m_PrintData;}
542 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
548 //---------------------------------------------------------------------------
549 //---------------------------------------------------------------------------
552 extern "C" SWIGEXPORT(void) inithtmlhelpc();
560 wxClassInfo::CleanUpClasses();
561 wxClassInfo::InitializeClasses();
563 // Until wxFileSystem is wrapped...
565 wxFileSystem::AddHandler(new wxZipFSHandler);
569 //----------------------------------------------------------------------
570 // And this gets appended to the shadow class file.
571 //----------------------------------------------------------------------
573 %pragma(python) include="_extras.py";
575 //---------------------------------------------------------------------------