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);
93 wxMouseEvent* GetEvent();
94 wxHtmlCell* GetHtmlCell();
97 //---------------------------------------------------------------------------
101 // Never need to create a new tag from Python...
102 //wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
105 bool HasParam(const wxString& par);
106 wxString GetParam(const wxString& par, int with_commas = FALSE);
108 // Can't do this one as-is, but GetParam should be enough...
109 //int ScanParam(const wxString& par, const char *format, void* param);
111 wxString GetAllParams();
120 //---------------------------------------------------------------------------
124 // wxHtmlParser(); This is an abstract base class...
126 void SetFS(wxFileSystem *fs);
127 wxFileSystem* GetFS();
128 wxObject* Parse(const wxString& source);
129 void InitParser(const wxString& source);
131 void DoParsing(int begin_pos, int end_pos);
132 // wxObject* GetProduct();
133 void AddTagHandler(wxHtmlTagHandler *handler);
134 wxString* GetSource();
135 void PushTagHandler(wxHtmlTagHandler* handler, wxString tags);
136 void PopTagHandler();
139 // void AddText(const char* txt) = 0;
140 // void AddTag(const wxHtmlTag& tag);
144 //---------------------------------------------------------------------------
146 class wxHtmlWinParser : public wxHtmlParser {
148 wxHtmlWinParser(wxWindow *wnd);
150 void SetDC(wxDC *dc);
154 wxWindow* GetWindow();
155 void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
157 wxHtmlContainerCell* GetContainer();
158 wxHtmlContainerCell* OpenContainer();
159 wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
160 wxHtmlContainerCell* CloseContainer();
163 void SetFontSize(int s);
165 void SetFontBold(int x);
167 void SetFontItalic(int x);
168 int GetFontUnderlined();
169 void SetFontUnderlined(int x);
171 void SetFontFixed(int x);
173 void SetAlign(int a);
174 const wxColour& GetLinkColor();
175 void SetLinkColor(const wxColour& clr);
176 const wxColour& GetActualColor();
177 void SetActualColor(const wxColour& clr);
178 void SetLink(const wxString& link);
179 wxFont* CreateCurrentFont();
180 wxHtmlLinkInfo GetLink();
186 //---------------------------------------------------------------------------
189 class wxPyHtmlTagHandler : public wxHtmlTagHandler {
191 wxPyHtmlTagHandler() : wxHtmlTagHandler() {};
193 wxHtmlParser* GetParser() { return m_Parser; }
194 void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); }
196 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
197 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
202 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
203 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
207 %name(wxHtmlTagHandler) class wxPyHtmlTagHandler {
209 wxPyHtmlTagHandler();
211 void _setSelf(PyObject* self);
212 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
214 void SetParser(wxHtmlParser *parser);
215 wxHtmlParser* GetParser();
216 void ParseInner(const wxHtmlTag& tag);
220 //---------------------------------------------------------------------------
223 class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
225 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
227 wxHtmlWinParser* GetParser() { return m_WParser; }
228 void ParseInner(const wxHtmlTag& tag)
229 { wxHtmlWinTagHandler::ParseInner(tag); }
231 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
232 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
237 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
238 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
242 %name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
244 wxPyHtmlWinTagHandler();
246 void _setSelf(PyObject* self);
247 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
249 void SetParser(wxHtmlParser *parser);
250 wxHtmlWinParser* GetParser();
251 void ParseInner(const wxHtmlTag& tag);
255 //---------------------------------------------------------------------------
259 class wxPyHtmlTagsModule : public wxHtmlTagsModule {
261 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
262 m_tagHandlerClass = thc;
263 Py_INCREF(m_tagHandlerClass);
264 RegisterModule(this);
265 wxHtmlWinParser::AddModule(this);
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);
277 void FillHandlersTable(wxHtmlWinParser *parser) {
278 // Wave our magic wand... (if it works it's a miracle! ;-)
280 // First, make a new instance of the tag handler
281 bool doSave = wxPyRestoreThread();
282 PyObject* arg = Py_BuildValue("()");
283 PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
285 wxPySaveThread(doSave);
287 // now figure out where it's C++ object is...
288 wxPyHtmlWinTagHandler* thPtr;
289 if (SWIG_GetPtrObj(obj, (void **)&thPtr, "_wxPyHtmlWinTagHandler_p"))
293 parser->AddTagHandler(thPtr);
300 PyObject* m_tagHandlerClass;
301 wxArrayPtrVoid m_objArray;
309 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
310 // Dynamically create a new wxModule. Refcounts tagHandlerClass
311 // and adds itself to the wxModules list and to the wxHtmlWinParser.
312 new wxPyHtmlTagsModule(tagHandlerClass);
317 //---------------------------------------------------------------------------
318 //---------------------------------------------------------------------------
329 wxHtmlLinkInfo* GetLink(int x = 0, int y = 0);
330 wxHtmlCell* GetNext();
331 wxHtmlContainerCell* GetParent();
332 void SetLink(const wxHtmlLinkInfo& link);
333 void SetNext(wxHtmlCell *cell);
334 void SetParent(wxHtmlContainerCell *p);
335 void SetPos(int x, int y);
337 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
338 void DrawInvisible(wxDC& dc, int x, int y);
339 const wxHtmlCell* Find(int condition, const void* param);
341 bool AdjustPagebreak(int * pagebreak);
342 void SetCanLiveOnPagebreak(bool can);
347 class wxHtmlContainerCell : public wxHtmlCell {
349 wxHtmlContainerCell(wxHtmlContainerCell *parent);
351 void InsertCell(wxHtmlCell *cell);
352 void SetAlignHor(int al);
354 void SetAlignVer(int al);
356 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
357 int GetIndent(int ind);
358 int GetIndentUnits(int ind);
359 void SetAlign(const wxHtmlTag& tag);
360 void SetWidthFloat(int w, int units);
361 %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
362 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
363 int GetMaxLineWidth();
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) {};
415 void OnLinkClicked(const wxHtmlLinkInfo& link);
416 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
418 DEC_PYCALLBACK__STRING(OnSetTitle);
423 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
425 void wxPyHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) {
426 bool doSave = wxPyRestoreThread();
427 if (m_myInst.findCallback("OnLinkClicked")) {
428 PyObject* obj = wxPyConstructObject((void*)&link, "wxHtmlLinkInfo");
429 m_myInst.callCallback(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 = wxPyDefaultPosition,
446 wxSize& size = wxPyDefaultSize,
447 int flags=wxHW_SCROLLBAR_AUTO,
448 char* name = "htmlWindow");
450 void _setSelf(PyObject* self);
451 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
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);
462 void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
463 void SetTitle(const char* title);
464 void SetBorders(int b);
465 void ReadCustomization(wxConfigBase *cfg, char* path = "");
466 void WriteCustomization(wxConfigBase *cfg, char* path = "");
468 bool HistoryForward();
470 wxHtmlContainerCell* GetInternalRepresentation();
471 wxHtmlWinParser* GetParser();
474 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
475 void base_OnSetTitle(const char* title);
478 // Static methods are mapped to stand-alone functions
480 void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) {
481 wxHtmlWindow::AddFilter(filter);
486 //---------------------------------------------------------------------------
487 //---------------------------------------------------------------------------
490 class wxHtmlDCRenderer {
495 void SetDC(wxDC *dc, int maxwidth);
496 void SetSize(int width, int height);
497 void SetHtmlText(const wxString& html,
498 const wxString& basepath = wxEmptyString,
500 int Render(int x, int y, int from = 0, int dont_render = FALSE);
501 int GetTotalHeight();
502 // returns total height of the html document
503 // (compare Render's return value with this)
513 class wxHtmlPrintout : public wxPyPrintout {
515 wxHtmlPrintout(const char* title = "Printout");
518 void SetHtmlText(const wxString& html,
519 const wxString &basepath = wxEmptyString,
521 void SetHtmlFile(const wxString &htmlfile);
522 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
523 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
524 void SetMargins(float top = 25.2, float bottom = 25.2,
525 float left = 25.2, float right = 25.2,
531 class wxHtmlEasyPrinting {
533 wxHtmlEasyPrinting(const char* name = "Printing",
534 wxFrame *parent_frame = NULL);
535 ~wxHtmlEasyPrinting();
537 void PreviewFile(const wxString &htmlfile);
538 void PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
539 void PrintFile(const wxString &htmlfile);
540 void PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
543 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
544 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
546 wxPrintData *GetPrintData() {return m_PrintData;}
547 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
553 //---------------------------------------------------------------------------
554 //---------------------------------------------------------------------------
557 extern "C" SWIGEXPORT(void) inithtmlhelpc();
565 wxClassInfo::CleanUpClasses();
566 wxClassInfo::InitializeClasses();
568 // Until wxFileSystem is wrapped...
570 wxFileSystem::AddHandler(new wxZipFSHandler);
574 //----------------------------------------------------------------------
575 // And this gets appended to the shadow class file.
576 //----------------------------------------------------------------------
578 %pragma(python) include="_extras.py";
580 //---------------------------------------------------------------------------