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 //---------------------------------------------------------------------------
90 // Never need to create a new tag from Python...
91 //wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
94 bool HasParam(const wxString& par);
95 wxString GetParam(const wxString& par, int with_commas = FALSE);
97 // Can't do this one as-is, but GetParam should be enough...
98 //int ScanParam(const wxString& par, const char *format, void* param);
100 wxString GetAllParams();
109 //---------------------------------------------------------------------------
113 // wxHtmlParser(); This is an abstract base class...
115 void SetFS(wxFileSystem *fs);
116 wxFileSystem* GetFS();
117 wxObject* Parse(const wxString& source);
118 void InitParser(const wxString& source);
120 void DoParsing(int begin_pos, int end_pos);
121 // wxObject* GetProduct();
122 void AddTagHandler(wxHtmlTagHandler *handler);
123 wxString* GetSource();
124 void PushTagHandler(wxHtmlTagHandler* handler, wxString tags);
125 void PopTagHandler();
128 // void AddText(const char* txt) = 0;
129 // void AddTag(const wxHtmlTag& tag);
133 //---------------------------------------------------------------------------
135 class wxHtmlWinParser : public wxHtmlParser {
137 wxHtmlWinParser(wxWindow *wnd);
139 void SetDC(wxDC *dc);
143 wxWindow* GetWindow();
144 void SetFonts(wxString normal_face, int normal_italic_mode,
145 wxString fixed_face, int fixed_italic_mode, int *LIST);
147 wxHtmlContainerCell* GetContainer();
148 wxHtmlContainerCell* OpenContainer();
149 wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
150 wxHtmlContainerCell* CloseContainer();
153 void SetFontSize(int s);
155 void SetFontBold(int x);
157 void SetFontItalic(int x);
158 int GetFontUnderlined();
159 void SetFontUnderlined(int x);
161 void SetFontFixed(int x);
163 void SetAlign(int a);
164 const wxColour& GetLinkColor();
165 void SetLinkColor(const wxColour& clr);
166 const wxColour& GetActualColor();
167 void SetActualColor(const wxColour& clr);
168 const wxString& GetLink();
169 void SetLink(const wxString& link);
170 wxFont* CreateCurrentFont();
175 //---------------------------------------------------------------------------
178 class wxPyHtmlTagHandler : public wxHtmlTagHandler {
180 wxPyHtmlTagHandler() : wxHtmlTagHandler() {};
182 wxHtmlParser* GetParser() { return m_Parser; }
183 void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); }
185 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
186 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
191 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
192 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
196 %name(wxHtmlTagHandler) class wxPyHtmlTagHandler {
198 wxPyHtmlTagHandler();
200 void _setSelf(PyObject* self);
201 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
203 void SetParser(wxHtmlParser *parser);
204 wxHtmlParser* GetParser();
205 void ParseInner(const wxHtmlTag& tag);
209 //---------------------------------------------------------------------------
212 class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
214 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
216 wxHtmlWinParser* GetParser() { return m_WParser; }
217 void ParseInner(const wxHtmlTag& tag)
218 { wxHtmlWinTagHandler::ParseInner(tag); }
220 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
221 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
226 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
227 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
231 %name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
233 wxPyHtmlWinTagHandler();
235 void _setSelf(PyObject* self);
236 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
238 void SetParser(wxHtmlParser *parser);
239 wxHtmlWinParser* GetParser();
240 void ParseInner(const wxHtmlTag& tag);
244 //---------------------------------------------------------------------------
248 class wxPyHtmlTagsModule : public wxHtmlTagsModule {
250 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
251 m_tagHandlerClass = thc;
252 Py_INCREF(m_tagHandlerClass);
253 RegisterModule(this);
254 wxHtmlWinParser::AddModule(this);
258 Py_DECREF(m_tagHandlerClass);
259 m_tagHandlerClass = NULL;
260 for (size_t x=0; x < m_objArray.GetCount(); x++) {
261 PyObject* obj = (PyObject*)m_objArray.Item(x);
266 void FillHandlersTable(wxHtmlWinParser *parser) {
267 // Wave our magic wand... (if it works it's a miracle! ;-)
269 // First, make a new instance of the tag handler
270 bool doSave = wxPyRestoreThread();
271 PyObject* arg = Py_BuildValue("()");
272 PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
274 wxPySaveThread(doSave);
276 // now figure out where it's C++ object is...
277 wxPyHtmlWinTagHandler* thPtr;
278 if (SWIG_GetPtrObj(obj, (void **)&thPtr, "_wxPyHtmlWinTagHandler_p"))
282 parser->AddTagHandler(thPtr);
289 PyObject* m_tagHandlerClass;
290 wxArrayPtrVoid m_objArray;
298 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
299 // Dynamically create a new wxModule. Refcounts tagHandlerClass
300 // and adds itself to the wxModules list and to the wxHtmlWinParser.
301 new wxPyHtmlTagsModule(tagHandlerClass);
306 //---------------------------------------------------------------------------
307 //---------------------------------------------------------------------------
313 void SetParent(wxHtmlContainerCell *p);
314 wxHtmlContainerCell* GetParent();
320 wxString GetLink(int x = 0, int y = 0);
321 wxHtmlCell* GetNext();
322 void SetPos(int x, int y);
323 void SetLink(const wxString& link);
324 void SetNext(wxHtmlCell *cell);
326 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
327 void DrawInvisible(wxDC& dc, int x, int y);
328 const wxHtmlCell* Find(int condition, const void* param);
330 bool AdjustPagebreak(int * pagebreak);
331 void SetCanLiveOnPagebreak(bool can);
335 class wxHtmlContainerCell : public wxHtmlCell {
337 wxHtmlContainerCell(wxHtmlContainerCell *parent);
339 void InsertCell(wxHtmlCell *cell);
340 void SetAlignHor(int al);
342 void SetAlignVer(int al);
344 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
345 int GetIndent(int ind);
346 int GetIndentUnits(int ind);
347 void SetAlign(const wxHtmlTag& tag);
348 void SetWidthFloat(int w, int units);
349 %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
350 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
351 int GetMaxLineWidth();
352 void SetBackgroundColour(const wxColour& clr);
353 void SetBorder(const wxColour& clr1, const wxColour& clr2);
354 wxHtmlCell* GetFirstCell();
360 class wxHtmlWidgetCell : public wxHtmlCell {
362 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
368 //---------------------------------------------------------------------------
369 //---------------------------------------------------------------------------
370 //---------------------------------------------------------------------------
372 // item of history list
373 class HtmlHistoryItem {
375 HtmlHistoryItem(const char* p, const char* a);
379 const wxString& GetPage();
380 const wxString& GetAnchor();
384 //---------------------------------------------------------------------------
386 class wxPyHtmlWindow : public wxHtmlWindow {
388 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
389 const wxPoint& pos = wxDefaultPosition,
390 const wxSize& size = wxDefaultSize,
391 long style = wxHW_SCROLLBAR_AUTO,
392 const wxString& name = "htmlWindow")
393 : wxHtmlWindow(parent, id, pos, size, style, name) {};
395 DEC_PYCALLBACK__STRING(OnLinkClicked);
400 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnLinkClicked);
405 %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
407 wxPyHtmlWindow(wxWindow *parent, int id = -1,
408 wxPoint& pos = wxPyDefaultPosition,
409 wxSize& size = wxPyDefaultSize,
410 int flags=wxHW_SCROLLBAR_AUTO,
411 char* name = "htmlWindow");
413 void _setSelf(PyObject* self);
414 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
415 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
416 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
419 bool SetPage(const char* source);
420 bool LoadPage(const char* location);
421 wxString GetOpenedPage();
422 void SetRelatedFrame(wxFrame* frame, const char* format);
423 wxFrame* GetRelatedFrame();
424 void SetRelatedStatusBar(int bar);
425 void SetFonts(wxString normal_face, int normal_italic_mode,
426 wxString fixed_face, int fixed_italic_mode, int *LIST);
427 void SetTitle(const char* title);
428 void SetBorders(int b);
429 void ReadCustomization(wxConfigBase *cfg, char* path = "");
430 void WriteCustomization(wxConfigBase *cfg, char* path = "");
432 bool HistoryForward();
434 wxHtmlContainerCell* GetInternalRepresentation();
435 wxHtmlWinParser* GetParser();
438 void base_OnLinkClicked(const char* link);
441 // Static methods are mapped to stand-alone functions
443 void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) {
444 wxHtmlWindow::AddFilter(filter);
449 //---------------------------------------------------------------------------
450 //---------------------------------------------------------------------------
453 class wxHtmlDCRenderer {
458 void SetDC(wxDC *dc, int maxwidth);
459 void SetSize(int width, int height);
460 void SetHtmlText(const wxString& html,
461 const wxString& basepath = wxEmptyString,
463 int Render(int x, int y, int from = 0, int dont_render = FALSE);
464 int GetTotalHeight();
465 // returns total height of the html document
466 // (compare Render's return value with this)
476 class wxHtmlPrintout : public wxPyPrintout {
478 wxHtmlPrintout(const char* title = "Printout");
481 void SetHtmlText(const wxString& html,
482 const wxString &basepath = wxEmptyString,
484 void SetHtmlFile(const wxString &htmlfile);
485 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
486 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
487 void SetMargins(float top = 25.2, float bottom = 25.2,
488 float left = 25.2, float right = 25.2,
494 class wxHtmlEasyPrinting {
496 wxHtmlEasyPrinting(const char* name = "Printing",
497 wxFrame *parent_frame = NULL);
498 ~wxHtmlEasyPrinting();
500 void PreviewFile(const wxString &htmlfile);
501 void PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
502 void PrintFile(const wxString &htmlfile);
503 void PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
506 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
507 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
509 wxPrintData *GetPrintData() {return m_PrintData;}
510 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
516 //---------------------------------------------------------------------------
517 //---------------------------------------------------------------------------
520 extern "C" SWIGEXPORT(void) inithtmlhelpc();
528 wxClassInfo::CleanUpClasses();
529 wxClassInfo::InitializeClasses();
531 // Until wxFileSystem is wrapped...
533 wxFileSystem::AddHandler(new wxZipFSHandler);
537 //----------------------------------------------------------------------
538 // And this gets appended to the shadow class file.
539 //----------------------------------------------------------------------
541 %pragma(python) include="_extras.py";
543 //---------------------------------------------------------------------------