1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG definitions of html classes
7 // Created: 25-Nov-1998
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
14 "Classes for a simple HTML rendering window, HTML Help Window, etc."
17 %module(package="wx", docstring=DOCSTRING) html
20 #include "wx/wxPython/wxPython.h"
21 #include "wx/wxPython/pyclasses.h"
22 #include "wx/wxPython/pyistream.h"
23 #include "wx/wxPython/printfw.h"
25 #include <wx/html/htmlwin.h>
26 #include <wx/html/htmprint.h>
27 #include <wx/html/helpctrl.h>
32 //---------------------------------------------------------------------------
35 %pythoncode { wx = _core }
36 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
38 %include _html_rename.i
41 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
42 MAKE_CONST_WXSTRING2(HtmlWindowNameStr, wxT("htmlWindow"))
43 MAKE_CONST_WXSTRING2(HtmlPrintoutTitleStr, wxT("Printout"))
44 MAKE_CONST_WXSTRING2(HtmlPrintingTitleStr, wxT("Printing"))
47 // TODO: Split this file into multiple %included files that coresponds to the
48 // wx/html include files (more or less.)
50 //---------------------------------------------------------------------------
51 //---------------------------------------------------------------------------
62 wxHTML_CLR_FOREGROUND,
63 wxHTML_CLR_BACKGROUND,
73 wxHTML_INDENT_HORIZONTAL,
74 wxHTML_INDENT_VERTICAL,
78 wxHTML_COND_ISIMAGEMAP,
100 // enums for wxHtmlWindow::OnOpeningURL
101 enum wxHtmlOpeningStatus
117 //---------------------------------------------------------------------------
119 class wxHtmlLinkInfo : public wxObject {
121 wxHtmlLinkInfo(const wxString& href, const wxString& target = wxPyEmptyString);
123 wxString GetTarget();
124 wxMouseEvent* GetEvent();
125 wxHtmlCell* GetHtmlCell();
127 void SetEvent(const wxMouseEvent *e);
128 void SetHtmlCell(const wxHtmlCell * e);
131 //---------------------------------------------------------------------------
133 class wxHtmlTag : public wxObject {
135 // Never need to create a new tag from Python...
136 //wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
139 bool HasParam(const wxString& par);
140 wxString GetParam(const wxString& par, int with_commas = False);
142 // Can't do this one as-is, but GetParam should be enough...
143 //int ScanParam(const wxString& par, const char *format, void* param);
145 wxString GetAllParams();
152 //---------------------------------------------------------------------------
154 class wxHtmlParser : public wxObject {
156 // wxHtmlParser(); This is an abstract base class...
158 void SetFS(wxFileSystem *fs);
159 wxFileSystem* GetFS();
160 wxObject* Parse(const wxString& source);
161 void InitParser(const wxString& source);
163 void DoParsing(int begin_pos, int end_pos);
165 // wxObject* GetProduct();
167 void AddTagHandler(wxHtmlTagHandler *handler);
168 wxString* GetSource();
169 void PushTagHandler(wxHtmlTagHandler* handler, wxString tags);
170 void PopTagHandler();
172 // virtual wxFSFile *OpenURL(wxHtmlURLType type, const wxString& url) const;
174 // void AddText(const char* txt) = 0;
175 // void AddTag(const wxHtmlTag& tag);
179 //---------------------------------------------------------------------------
181 class wxHtmlWinParser : public wxHtmlParser {
183 wxHtmlWinParser(wxPyHtmlWindow *wnd = NULL);
185 void SetDC(wxDC *dc);
189 wxPyHtmlWindow* GetWindow();
191 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
193 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
195 if (sizes) temp = int_LIST_helper(sizes);
196 self->SetFonts(normal_face, fixed_face, temp);
202 // Sets font sizes to be relative to the given size or the system default size
203 void NormalizeFontSizes(int size=-1);
205 wxHtmlContainerCell* GetContainer();
206 wxHtmlContainerCell* OpenContainer();
207 wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
208 wxHtmlContainerCell* CloseContainer();
211 void SetFontSize(int s);
213 void SetFontBold(int x);
215 void SetFontItalic(int x);
216 int GetFontUnderlined();
217 void SetFontUnderlined(int x);
219 void SetFontFixed(int x);
221 void SetAlign(int a);
222 wxColour GetLinkColor();
223 void SetLinkColor(const wxColour& clr);
224 wxColour GetActualColor();
225 void SetActualColor(const wxColour& clr);
226 void SetLink(const wxString& link);
227 wxFont* CreateCurrentFont();
228 wxHtmlLinkInfo GetLink();
233 //---------------------------------------------------------------------------
236 class wxPyHtmlTagHandler : public wxHtmlTagHandler {
237 DECLARE_DYNAMIC_CLASS(wxPyHtmlTagHandler);
239 wxPyHtmlTagHandler() : wxHtmlTagHandler() {};
241 wxHtmlParser* GetParser() { return m_Parser; }
242 void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); }
244 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
245 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
250 IMPLEMENT_DYNAMIC_CLASS(wxPyHtmlTagHandler, wxHtmlTagHandler);
252 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
253 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
257 %name(HtmlTagHandler) class wxPyHtmlTagHandler : public wxObject {
259 %pythonAppend wxPyHtmlTagHandler "self._setCallbackInfo(self, HtmlTagHandler)"
260 wxPyHtmlTagHandler();
262 void _setCallbackInfo(PyObject* self, PyObject* _class);
264 void SetParser(wxHtmlParser *parser);
265 wxHtmlParser* GetParser();
266 void ParseInner(const wxHtmlTag& tag);
270 //---------------------------------------------------------------------------
273 class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
274 DECLARE_DYNAMIC_CLASS(wxPyHtmlWinTagHandler);
276 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
278 wxHtmlWinParser* GetParser() { return m_WParser; }
279 void ParseInner(const wxHtmlTag& tag)
280 { wxHtmlWinTagHandler::ParseInner(tag); }
282 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
283 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
288 IMPLEMENT_DYNAMIC_CLASS( wxPyHtmlWinTagHandler, wxHtmlWinTagHandler);
290 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
291 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
295 %name(HtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
297 %pythonAppend wxPyHtmlWinTagHandler "self._setCallbackInfo(self, HtmlWinTagHandler)"
298 wxPyHtmlWinTagHandler();
300 void _setCallbackInfo(PyObject* self, PyObject* _class);
302 void SetParser(wxHtmlParser *parser);
303 wxHtmlWinParser* GetParser();
304 void ParseInner(const wxHtmlTag& tag);
308 //---------------------------------------------------------------------------
312 class wxPyHtmlTagsModule : public wxHtmlTagsModule {
314 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
315 m_tagHandlerClass = thc;
316 Py_INCREF(m_tagHandlerClass);
317 RegisterModule(this);
318 wxHtmlWinParser::AddModule(this);
322 bool blocked = wxPyBeginBlockThreads();
323 Py_DECREF(m_tagHandlerClass);
324 m_tagHandlerClass = NULL;
325 for (size_t x=0; x < m_objArray.GetCount(); x++) {
326 PyObject* obj = (PyObject*)m_objArray.Item(x);
329 wxPyEndBlockThreads(blocked);
332 void FillHandlersTable(wxHtmlWinParser *parser) {
333 // Wave our magic wand... (if it works it's a miracle! ;-)
335 // First, make a new instance of the tag handler
336 bool blocked = wxPyBeginBlockThreads();
337 PyObject* arg = PyTuple_New(0);
338 PyObject* obj = PyObject_CallObject(m_tagHandlerClass, arg);
341 // now figure out where it's C++ object is...
342 wxPyHtmlWinTagHandler* thPtr;
343 if (! wxPyConvertSwigPtr(obj, (void **)&thPtr, wxT("wxPyHtmlWinTagHandler"))) {
344 wxPyEndBlockThreads(blocked);
347 wxPyEndBlockThreads(blocked);
350 parser->AddTagHandler(thPtr);
357 PyObject* m_tagHandlerClass;
358 wxArrayPtrVoid m_objArray;
366 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
367 // Dynamically create a new wxModule. Refcounts tagHandlerClass
368 // and adds itself to the wxModules list and to the wxHtmlWinParser.
369 new wxPyHtmlTagsModule(tagHandlerClass);
374 //---------------------------------------------------------------------------
375 //---------------------------------------------------------------------------
379 // wxHtmlSelection is data holder with information about text selection.
380 // Selection is defined by two positions (beginning and end of the selection)
381 // and two leaf(!) cells at these positions.
382 class wxHtmlSelection
388 void Set(const wxPoint& fromPos, const wxHtmlCell *fromCell,
389 const wxPoint& toPos, const wxHtmlCell *toCell);
390 %name(SetCells)void Set(const wxHtmlCell *fromCell, const wxHtmlCell *toCell);
392 const wxHtmlCell *GetFromCell() const;
393 const wxHtmlCell *GetToCell() const;
395 // these values are in absolute coordinates:
396 const wxPoint& GetFromPos() const;
397 const wxPoint& GetToPos() const;
399 // these are From/ToCell's private data
400 const wxPoint& GetFromPrivPos() const;
401 const wxPoint& GetToPrivPos() const;
402 void SetFromPrivPos(const wxPoint& pos);
403 void SetToPrivPos(const wxPoint& pos);
406 const bool IsEmpty() const;
411 enum wxHtmlSelectionState
413 wxHTML_SEL_OUT, // currently rendered cell is outside the selection
414 wxHTML_SEL_IN, // ... is inside selection
415 wxHTML_SEL_CHANGING // ... is the cell on which selection state changes
420 // Selection state is passed to wxHtmlCell::Draw so that it can render itself
421 // differently e.g. when inside text selection or outside it.
422 class wxHtmlRenderingState
425 wxHtmlRenderingState();
426 ~wxHtmlRenderingState();
428 void SetSelectionState(wxHtmlSelectionState s);
429 wxHtmlSelectionState GetSelectionState() const;
431 void SetFgColour(const wxColour& c);
432 const wxColour& GetFgColour() const;
433 void SetBgColour(const wxColour& c);
434 const wxColour& GetBgColour() const;
439 // HTML rendering customization. This class is used when rendering wxHtmlCells
441 class wxHtmlRenderingStyle
444 virtual wxColour GetSelectedTextColour(const wxColour& clr) = 0;
445 virtual wxColour GetSelectedTextBgColour(const wxColour& clr) = 0;
449 class wxDefaultHtmlRenderingStyle : public wxHtmlRenderingStyle
452 virtual wxColour GetSelectedTextColour(const wxColour& clr);
453 virtual wxColour GetSelectedTextBgColour(const wxColour& clr);
458 // Information given to cells when drawing them. Contains rendering state,
459 // selection information and rendering style object that can be used to
460 // customize the output.
461 class wxHtmlRenderingInfo
464 wxHtmlRenderingInfo();
465 ~wxHtmlRenderingInfo();
467 void SetSelection(wxHtmlSelection *s);
468 wxHtmlSelection *GetSelection() const;
470 void SetStyle(wxHtmlRenderingStyle *style);
471 wxHtmlRenderingStyle& GetStyle();
473 wxHtmlRenderingState& GetState();
476 //---------------------------------------------------------------------------
482 wxHTML_FIND_EXACT = 1,
483 wxHTML_FIND_NEAREST_BEFORE = 2,
484 wxHTML_FIND_NEAREST_AFTER = 4
488 class wxHtmlCell : public wxObject {
498 // Returns the maximum possible length of the cell.
499 // Call Layout at least once before using GetMaxTotalWidth()
500 int GetMaxTotalWidth() const;
502 const wxString& GetId() const;
503 void SetId(const wxString& id);
504 wxHtmlLinkInfo* GetLink(int x = 0, int y = 0);
505 wxHtmlCell* GetNext();
506 wxHtmlContainerCell* GetParent();
507 wxHtmlCell* GetFirstChild() const;
509 // Returns cursor to be used when mouse is over the cell:
510 wxCursor GetCursor() const;
512 // Formatting cells are not visible on the screen, they only alter
514 bool IsFormattingCell() const;
517 void SetLink(const wxHtmlLinkInfo& link);
518 void SetNext(wxHtmlCell *cell);
519 void SetParent(wxHtmlContainerCell *p);
520 void SetPos(int x, int y);
522 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
523 wxHtmlRenderingInfo& info);
524 void DrawInvisible(wxDC& dc, int x, int y,
525 wxHtmlRenderingInfo& info);
526 const wxHtmlCell* Find(int condition, const void* param);
528 bool AdjustPagebreak(int* INOUT);
529 void SetCanLiveOnPagebreak(bool can);
531 // Can the line be broken before this cell?
532 bool IsLinebreakAllowed() const;
534 // Returns True for simple == terminal cells, i.e. not composite ones.
535 // This if for internal usage only and may disappear in future versions!
536 bool IsTerminalCell() const;
538 // Find a cell inside this cell positioned at the given coordinates
539 // (relative to this's positions). Returns NULL if no such cell exists.
540 // The flag can be used to specify whether to look for terminal or
541 // nonterminal cells or both. In either case, returned cell is deepest
542 // cell in cells tree that contains [x,y].
543 wxHtmlCell *FindCellByPos(wxCoord x, wxCoord y,
544 unsigned flags = wxHTML_FIND_EXACT) const;
546 // Returns absolute position of the cell on HTML canvas
547 wxPoint GetAbsPos() const;
549 // Returns first (last) terminal cell inside this cell. It may return NULL,
550 // but it is rare -- only if there are no terminals in the tree.
551 wxHtmlCell *GetFirstTerminal() const ;
552 wxHtmlCell *GetLastTerminal() const ;
554 // Returns cell's depth, i.e. how far under the root cell it is
555 // (if it is the root, depth is 0)
556 unsigned GetDepth() const;
558 // Returns True if the cell appears before 'cell' in natural order of
559 // cells (= as they are read). If cell A is (grand)parent of cell B,
560 // then both A.IsBefore(B) and B.IsBefore(A) always return True.
561 bool IsBefore(wxHtmlCell *cell) const;
563 // Converts the cell into text representation. If sel != NULL then
564 // only part of the cell inside the selection is converted.
565 wxString ConvertToText(wxHtmlSelection *sel) const;
569 class wxHtmlWordCell : public wxHtmlCell
572 wxHtmlWordCell(const wxString& word, wxDC& dc);
576 class wxHtmlContainerCell : public wxHtmlCell {
578 wxHtmlContainerCell(wxHtmlContainerCell *parent);
580 void InsertCell(wxHtmlCell *cell);
581 void SetAlignHor(int al);
583 void SetAlignVer(int al);
585 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
586 int GetIndent(int ind);
587 int GetIndentUnits(int ind);
588 void SetAlign(const wxHtmlTag& tag);
589 void SetWidthFloat(int w, int units);
590 %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
591 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
592 void SetBackgroundColour(const wxColour& clr);
593 wxColour GetBackgroundColour();
594 void SetBorder(const wxColour& clr1, const wxColour& clr2);
595 wxHtmlCell* GetFirstChild();
596 %pragma(python) addtoclass = "GetFirstCell = GetFirstChild"
601 class wxHtmlColourCell : public wxHtmlCell {
603 wxHtmlColourCell(wxColour clr, int flags = wxHTML_CLR_FOREGROUND);
608 class wxHtmlFontCell : public wxHtmlCell
611 wxHtmlFontCell(wxFont *font);
615 class wxHtmlWidgetCell : public wxHtmlCell {
617 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
624 //---------------------------------------------------------------------------
626 //---------------------------------------------------------------------------
630 %{ // here's the C++ version
631 class wxPyHtmlFilter : public wxHtmlFilter {
632 DECLARE_ABSTRACT_CLASS(wxPyHtmlFilter);
634 wxPyHtmlFilter() : wxHtmlFilter() {}
636 // returns True if this filter is able to open&read given file
637 virtual bool CanRead(const wxFSFile& file) const {
640 bool blocked = wxPyBeginBlockThreads();
641 if ((found = wxPyCBH_findCallback(m_myInst, "CanRead"))) {
642 PyObject* obj = wxPyMake_wxObject((wxFSFile*)&file,false); // cast away const
643 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj));
646 wxPyEndBlockThreads(blocked);
651 // Reads given file and returns HTML document.
652 // Returns empty string if opening failed
653 virtual wxString ReadFile(const wxFSFile& file) const {
656 bool blocked = wxPyBeginBlockThreads();
657 if ((found = wxPyCBH_findCallback(m_myInst, "ReadFile"))) {
658 PyObject* obj = wxPyMake_wxObject((wxFSFile*)&file,false); // cast away const
660 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(O)", obj));
663 rval = Py2wxString(ro);
667 wxPyEndBlockThreads(blocked);
674 IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlFilter, wxHtmlFilter);
678 // And now the version seen by SWIG
680 %name(HtmlFilter) class wxPyHtmlFilter : public wxObject {
682 %pythonAppend wxPyHtmlFilter "self._setCallbackInfo(self, HtmlFilter)"
685 void _setCallbackInfo(PyObject* self, PyObject* _class);
689 // TODO: wxHtmlFilterHTML
692 //---------------------------------------------------------------------------
694 //---------------------------------------------------------------------------
698 class wxPyHtmlWindow : public wxHtmlWindow {
699 DECLARE_ABSTRACT_CLASS(wxPyHtmlWindow);
701 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
702 const wxPoint& pos = wxDefaultPosition,
703 const wxSize& size = wxDefaultSize,
704 long style = wxHW_DEFAULT_STYLE,
705 const wxString& name = wxPyHtmlWindowNameStr)
706 : wxHtmlWindow(parent, id, pos, size, style, name) {};
707 wxPyHtmlWindow() : wxHtmlWindow() {};
709 bool ScrollToAnchor(const wxString& anchor) {
710 return wxHtmlWindow::ScrollToAnchor(anchor);
713 bool HasAnchor(const wxString& anchor) {
714 const wxHtmlCell *c = m_Cell->Find(wxHTML_COND_ISANCHOR, &anchor);
718 void OnLinkClicked(const wxHtmlLinkInfo& link);
719 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
721 wxHtmlOpeningStatus OnOpeningURL(wxHtmlURLType type,
723 wxString *redirect) const;
725 DEC_PYCALLBACK__STRING(OnSetTitle);
726 DEC_PYCALLBACK__CELLINTINT(OnCellMouseHover);
727 DEC_PYCALLBACK__CELLINTINTME(OnCellClicked);
731 IMPLEMENT_ABSTRACT_CLASS( wxPyHtmlWindow, wxHtmlWindow );
732 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
733 IMP_PYCALLBACK__CELLINTINT(wxPyHtmlWindow, wxHtmlWindow, OnCellMouseHover);
734 IMP_PYCALLBACK__CELLINTINTME(wxPyHtmlWindow, wxHtmlWindow, OnCellClicked);
737 void wxPyHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) {
739 bool blocked = wxPyBeginBlockThreads();
740 if ((found = wxPyCBH_findCallback(m_myInst, "OnLinkClicked"))) {
741 PyObject* obj = wxPyConstructObject((void*)&link, wxT("wxHtmlLinkInfo"), 0);
742 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj));
745 wxPyEndBlockThreads(blocked);
747 wxHtmlWindow::OnLinkClicked(link);
749 void wxPyHtmlWindow::base_OnLinkClicked(const wxHtmlLinkInfo& link) {
750 wxHtmlWindow::OnLinkClicked(link);
754 wxHtmlOpeningStatus wxPyHtmlWindow::OnOpeningURL(wxHtmlURLType type,
756 wxString *redirect) const {
758 wxHtmlOpeningStatus rval;
759 bool blocked = wxPyBeginBlockThreads();
760 if ((found = wxPyCBH_findCallback(m_myInst, "OnOpeningURL"))) {
762 PyObject* s = wx2PyString(url);
763 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iO)", type, s));
765 if (PyString_Check(ro)
766 #if PYTHON_API_VERSION >= 1009
767 || PyUnicode_Check(ro)
770 *redirect = Py2wxString(ro);
771 rval = wxHTML_REDIRECT;
774 PyObject* num = PyNumber_Int(ro);
775 rval = (wxHtmlOpeningStatus)PyInt_AsLong(num);
780 wxPyEndBlockThreads(blocked);
782 rval = wxHtmlWindow::OnOpeningURL(type, url, redirect);
791 MustHaveApp(wxPyHtmlWindow);
793 %name(HtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
795 %pythonAppend wxPyHtmlWindow "self._setCallbackInfo(self, HtmlWindow); self._setOORInfo(self)"
796 %pythonAppend wxPyHtmlWindow() ""
797 %typemap(out) wxPyHtmlWindow*; // turn off this typemap
799 wxPyHtmlWindow(wxWindow *parent, int id = -1,
800 const wxPoint& pos = wxDefaultPosition,
801 const wxSize& size = wxDefaultSize,
802 int style=wxHW_DEFAULT_STYLE,
803 const wxString& name = wxPyHtmlWindowNameStr);
804 %name(PreHtmlWindow)wxPyHtmlWindow();
806 // Turn it back on again
807 %typemap(out) wxPyHtmlWindow* { $result = wxPyMake_wxObject($1, $owner); }
809 bool Create(wxWindow *parent, int id = -1,
810 const wxPoint& pos = wxDefaultPosition,
811 const wxSize& size = wxDefaultSize,
812 int style=wxHW_SCROLLBAR_AUTO,
813 const wxString& name = wxPyHtmlWindowNameStr);
816 void _setCallbackInfo(PyObject* self, PyObject* _class);
819 // Set HTML page and display it. !! source is HTML document itself,
820 // it is NOT address/filename of HTML document. If you want to
821 // specify document location, use LoadPage() istead
822 // Return value : False if an error occured, True otherwise
823 bool SetPage(const wxString& source);
825 // Load HTML page from given location. Location can be either
826 // a) /usr/wxGTK2/docs/html/wx.htm
827 // b) http://www.somewhere.uk/document.htm
828 // c) ftp://ftp.somesite.cz/pub/something.htm
829 // In case there is no prefix (http:,ftp:), the method
830 // will try to find it itself (1. local file, then http or ftp)
831 // After the page is loaded, the method calls SetPage() to display it.
832 // Note : you can also use path relative to previously loaded page
833 // Return value : same as SetPage
834 bool LoadPage(const wxString& location);
836 // Loads HTML page from file
837 bool LoadFile(const wxString& filename);
839 // Append to current page
840 bool AppendToPage(const wxString& source);
842 // Returns full location of opened page
843 wxString GetOpenedPage();
845 // Returns anchor within opened page
846 wxString GetOpenedAnchor();
848 // Returns <TITLE> of opened page or empty string otherwise
849 wxString GetOpenedPageTitle();
851 // Sets frame in which page title will be displayed. Format is format of
852 // frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s
853 void SetRelatedFrame(wxFrame* frame, const wxString& format);
854 wxFrame* GetRelatedFrame();
856 // After(!) calling SetRelatedFrame, this sets statusbar slot where messages
857 // will be displayed. Default is -1 = no messages.
858 void SetRelatedStatusBar(int bar);
860 // Sets fonts to be used when displaying HTML page.
862 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
864 if (sizes) temp = int_LIST_helper(sizes);
865 self->SetFonts(normal_face, fixed_face, temp);
871 // Sets font sizes to be relative to the given size or the system default size
872 void NormalizeFontSizes(int size=-1);
875 void, SetTitle(const wxString& title),
878 // Sets space between text and window borders.
879 void SetBorders(int b);
881 // Saves custom settings into cfg config. it will use the path 'path'
882 // if given, otherwise it will save info into currently selected path.
883 // saved values : things set by SetFonts, SetBorders.
884 void ReadCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
885 void WriteCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
887 // Goes to previous/next page (in browsing history)
888 // Returns True if successful, False otherwise
890 bool HistoryForward();
891 bool HistoryCanBack();
892 bool HistoryCanForward();
897 // Returns pointer to conteiners/cells structure.
898 wxHtmlContainerCell* GetInternalRepresentation();
900 // Returns a pointer to the parser.
901 wxHtmlWinParser* GetParser();
903 bool ScrollToAnchor(const wxString& anchor);
904 bool HasAnchor(const wxString& anchor);
907 static void AddFilter(wxPyHtmlFilter *filter);
909 // Helper functions to select parts of page:
910 void SelectWord(const wxPoint& pos);
911 void SelectLine(const wxPoint& pos);
914 // Convert selection to text:
915 wxString SelectionToText();
917 // Converts current page to text:
920 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
921 void base_OnSetTitle(const wxString& title);
922 void base_OnCellMouseHover(wxHtmlCell *cell, wxCoord x, wxCoord y);
923 void base_OnCellClicked(wxHtmlCell *cell,
924 wxCoord x, wxCoord y,
925 const wxMouseEvent& event);
927 static wxVisualAttributes
928 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
934 //---------------------------------------------------------------------------
935 //---------------------------------------------------------------------------
939 MustHaveApp(wxHtmlDCRenderer);
941 class wxHtmlDCRenderer : public wxObject {
946 void SetDC(wxDC *dc, int maxwidth);
947 void SetSize(int width, int height);
948 void SetHtmlText(const wxString& html,
949 const wxString& basepath = wxPyEmptyString,
951 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
953 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
955 if (sizes) temp = int_LIST_helper(sizes);
956 self->SetFonts(normal_face, fixed_face, temp);
962 // Sets font sizes to be relative to the given size or the system default size
963 void NormalizeFontSizes(int size=-1);
965 int Render(int x, int y, int from = 0, int dont_render = False, int to = INT_MAX,
966 //int *known_pagebreaks = NULL, int number_of_pages = 0
967 int* choices=NULL, int LCOUNT = 0
969 int GetTotalHeight();
970 // returns total height of the html document
971 // (compare Render's return value with this)
982 MustHaveApp(wxHtmlPrintout);
984 class wxHtmlPrintout : public wxPyPrintout {
986 wxHtmlPrintout(const wxString& title = wxPyHtmlPrintoutTitleStr);
987 //~wxHtmlPrintout(); wxPrintPreview object takes ownership...
989 void SetHtmlText(const wxString& html,
990 const wxString &basepath = wxPyEmptyString,
992 void SetHtmlFile(const wxString &htmlfile);
993 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
994 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
996 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
998 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
1000 if (sizes) temp = int_LIST_helper(sizes);
1001 self->SetFonts(normal_face, fixed_face, temp);
1007 // Sets font sizes to be relative to the given size or the system default size
1008 void NormalizeFontSizes(int size=-1);
1010 void SetMargins(float top = 25.2, float bottom = 25.2,
1011 float left = 25.2, float right = 25.2,
1014 // Adds input filter
1015 static void AddFilter(wxHtmlFilter *filter);
1018 static void CleanUpStatics();
1023 MustHaveApp(wxHtmlEasyPrinting);
1025 class wxHtmlEasyPrinting : public wxObject {
1027 wxHtmlEasyPrinting(const wxString& name = wxPyHtmlPrintingTitleStr,
1028 wxWindow *parentWindow = NULL);
1029 ~wxHtmlEasyPrinting();
1031 void PreviewFile(const wxString &htmlfile);
1032 void PreviewText(const wxString &htmltext, const wxString& basepath = wxPyEmptyString);
1033 void PrintFile(const wxString &htmlfile);
1034 void PrintText(const wxString &htmltext, const wxString& basepath = wxPyEmptyString);
1035 void PrinterSetup();
1037 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
1038 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
1041 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
1043 if (sizes) temp = int_LIST_helper(sizes);
1044 self->SetFonts(normal_face, fixed_face, temp);
1050 // Sets font sizes to be relative to the given size or the system default size
1051 void NormalizeFontSizes(int size=-1);
1053 wxPrintData *GetPrintData() {return m_PrintData;}
1054 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
1059 //---------------------------------------------------------------------------
1060 //---------------------------------------------------------------------------
1064 class wxHtmlBookRecord {
1066 wxHtmlBookRecord(const wxString& bookfile, const wxString& basepath,
1067 const wxString& title, const wxString& start);
1069 wxString GetBookFile();
1070 wxString GetTitle();
1071 wxString GetStart();
1072 wxString GetBasePath();
1074 void SetContentsRange(int start, int end);
1075 int GetContentsStart();
1076 int GetContentsEnd();
1078 void SetTitle(const wxString& title);
1079 void SetBasePath(const wxString& path);
1080 void SetStart(const wxString& start);
1082 wxString GetFullPath(const wxString &page) const;
1085 //---------------------------------------------------------------------------
1087 struct wxHtmlContentsItem
1090 int GetLevel() { return self->m_Level; }
1091 int GetID() { return self->m_ID; }
1092 wxString GetName() { return self->m_Name; }
1093 wxString GetPage() { return self->m_Page; }
1094 wxHtmlBookRecord* GetBook() { return self->m_Book; }
1098 //---------------------------------------------------------------------------
1100 class wxHtmlSearchStatus
1103 //wxHtmlSearchStatus(wxHtmlHelpData* base, const wxString& keyword,
1104 // const wxString& book = wxPyEmptyString);
1109 const wxString& GetName();
1110 wxHtmlContentsItem* GetContentsItem();
1113 //---------------------------------------------------------------------------
1115 class wxHtmlHelpData {
1120 void SetTempDir(const wxString& path);
1121 bool AddBook(const wxString& book);
1122 // bool AddBookParam(const wxString& title, const wxString& contfile,
1123 // const wxString& indexfile=wxPyEmptyString,
1124 // const wxString& deftopic=wxPyEmptyString,
1125 // const wxString& path=wxPyEmptyString);
1127 wxString FindPageByName(const wxString& page);
1128 wxString FindPageById(int id);
1130 // TODO: this one needs fixed...
1131 const wxHtmlBookRecArray& GetBookRecArray();
1133 wxHtmlContentsItem* GetContents();
1134 int GetContentsCnt();
1135 wxHtmlContentsItem* GetIndex();
1139 //---------------------------------------------------------------------------
1141 MustHaveApp(wxHtmlHelpFrame);
1143 class wxHtmlHelpFrame : public wxFrame {
1145 %pythonAppend wxHtmlHelpFrame "self._setOORInfo(self)"
1147 wxHtmlHelpFrame(wxWindow* parent, int wxWindowID,
1148 const wxString& title = wxPyEmptyString,
1149 int style = wxHF_DEFAULTSTYLE, wxHtmlHelpData* data = NULL);
1151 wxHtmlHelpData* GetData();
1152 void SetTitleFormat(const wxString& format);
1153 void Display(const wxString& x);
1154 %name(DisplayID) void Display(int id);
1155 void DisplayContents();
1156 void DisplayIndex();
1157 bool KeywordSearch(const wxString& keyword);
1158 void UseConfig(wxConfigBase *config, const wxString& rootpath = wxPyEmptyString);
1159 void ReadCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
1160 void WriteCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
1164 //---------------------------------------------------------------------------
1180 MustHaveApp(wxHtmlHelpController);
1182 class wxHtmlHelpController : public wxEvtHandler {
1184 %pythonAppend wxHtmlHelpController "self._setOORInfo(self)"
1186 wxHtmlHelpController(int style = wxHF_DEFAULTSTYLE);
1187 ~wxHtmlHelpController();
1189 void SetTitleFormat(const wxString& format);
1190 void SetTempDir(const wxString& path);
1191 bool AddBook(const wxString& book, int show_wait_msg = False);
1192 void Display(const wxString& x);
1193 %name(DisplayID) void Display(int id);
1194 void DisplayContents();
1195 void DisplayIndex();
1196 bool KeywordSearch(const wxString& keyword);
1197 void UseConfig(wxConfigBase *config, const wxString& rootpath = wxPyEmptyString);
1198 void ReadCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
1199 void WriteCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
1200 wxHtmlHelpFrame* GetFrame();
1206 //---------------------------------------------------------------------------
1208 wxPyPtrTypeMap_Add("wxHtmlTagHandler", "wxPyHtmlTagHandler");
1209 wxPyPtrTypeMap_Add("wxHtmlWinTagHandler", "wxPyHtmlWinTagHandler");
1210 wxPyPtrTypeMap_Add("wxHtmlWindow", "wxPyHtmlWindow");
1211 wxPyPtrTypeMap_Add("wxHtmlFilter", "wxPyHtmlFilter");
1213 //---------------------------------------------------------------------------
1214 //---------------------------------------------------------------------------