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);
421 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
423 void wxPyHtmlWindow::OnLinkClicked(wxHtmlLinkInfo* link) {
424 bool doSave = wxPyRestoreThread();
425 if (m_myInst.findCallback("OnLinkClicked")) {
426 PyObject* obj = wxPyConstructObject(link, "wxHtmlLinkInfo");
427 m_myInst.callCallback(Py_BuildValue("(O)", obj));
430 wxHtmlWindow::OnLinkClicked(link);
431 wxPySaveThread(doSave);
433 void wxPyHtmlWindow::base_OnLinkClicked(wxHtmlLinkInfo* link) {
434 wxHtmlWindow::OnLinkClicked(link);
440 %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
442 wxPyHtmlWindow(wxWindow *parent, int id = -1,
443 wxPoint& pos = wxPyDefaultPosition,
444 wxSize& size = wxPyDefaultSize,
445 int flags=wxHW_SCROLLBAR_AUTO,
446 char* name = "htmlWindow");
448 void _setSelf(PyObject* self);
449 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
450 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
451 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
454 bool SetPage(const char* source);
455 bool LoadPage(const char* location);
456 wxString GetOpenedPage();
457 void SetRelatedFrame(wxFrame* frame, const char* format);
458 wxFrame* GetRelatedFrame();
459 void SetRelatedStatusBar(int bar);
460 void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
461 void SetTitle(const char* title);
462 void SetBorders(int b);
463 void ReadCustomization(wxConfigBase *cfg, char* path = "");
464 void WriteCustomization(wxConfigBase *cfg, char* path = "");
466 bool HistoryForward();
468 wxHtmlContainerCell* GetInternalRepresentation();
469 wxHtmlWinParser* GetParser();
472 void base_OnLinkClicked(wxHtmlLinkInfo* link);
473 void base_OnSetTitle(const char* title);
476 // Static methods are mapped to stand-alone functions
478 void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) {
479 wxHtmlWindow::AddFilter(filter);
484 //---------------------------------------------------------------------------
485 //---------------------------------------------------------------------------
488 class wxHtmlDCRenderer {
493 void SetDC(wxDC *dc, int maxwidth);
494 void SetSize(int width, int height);
495 void SetHtmlText(const wxString& html,
496 const wxString& basepath = wxEmptyString,
498 int Render(int x, int y, int from = 0, int dont_render = FALSE);
499 int GetTotalHeight();
500 // returns total height of the html document
501 // (compare Render's return value with this)
511 class wxHtmlPrintout : public wxPyPrintout {
513 wxHtmlPrintout(const char* title = "Printout");
516 void SetHtmlText(const wxString& html,
517 const wxString &basepath = wxEmptyString,
519 void SetHtmlFile(const wxString &htmlfile);
520 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
521 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
522 void SetMargins(float top = 25.2, float bottom = 25.2,
523 float left = 25.2, float right = 25.2,
529 class wxHtmlEasyPrinting {
531 wxHtmlEasyPrinting(const char* name = "Printing",
532 wxFrame *parent_frame = NULL);
533 ~wxHtmlEasyPrinting();
535 void PreviewFile(const wxString &htmlfile);
536 void PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
537 void PrintFile(const wxString &htmlfile);
538 void PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
541 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
542 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
544 wxPrintData *GetPrintData() {return m_PrintData;}
545 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
551 //---------------------------------------------------------------------------
552 //---------------------------------------------------------------------------
555 extern "C" SWIGEXPORT(void) inithtmlhelpc();
563 wxClassInfo::CleanUpClasses();
564 wxClassInfo::InitializeClasses();
566 // Until wxFileSystem is wrapped...
568 wxFileSystem::AddHandler(new wxZipFSHandler);
572 //----------------------------------------------------------------------
573 // And this gets appended to the shadow class file.
574 //----------------------------------------------------------------------
576 %pragma(python) include="_extras.py";
578 //---------------------------------------------------------------------------