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
203 // default size; use either specified or default font
204 void SetStandardFonts(int size = -1,
205 const wxString& normal_face = wxPyEmptyString,
206 const wxString& fixed_face = wxPyEmptyString);
209 wxHtmlContainerCell* GetContainer();
210 wxHtmlContainerCell* OpenContainer();
211 wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
212 wxHtmlContainerCell* CloseContainer();
215 void SetFontSize(int s);
217 void SetFontBold(int x);
219 void SetFontItalic(int x);
220 int GetFontUnderlined();
221 void SetFontUnderlined(int x);
223 void SetFontFixed(int x);
225 void SetAlign(int a);
226 wxColour GetLinkColor();
227 void SetLinkColor(const wxColour& clr);
228 wxColour GetActualColor();
229 void SetActualColor(const wxColour& clr);
230 void SetLink(const wxString& link);
231 wxFont* CreateCurrentFont();
232 wxHtmlLinkInfo GetLink();
237 //---------------------------------------------------------------------------
240 class wxPyHtmlTagHandler : public wxHtmlTagHandler {
241 DECLARE_DYNAMIC_CLASS(wxPyHtmlTagHandler);
243 wxPyHtmlTagHandler() : wxHtmlTagHandler() {};
245 wxHtmlParser* GetParser() { return m_Parser; }
246 void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); }
248 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
249 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
254 IMPLEMENT_DYNAMIC_CLASS(wxPyHtmlTagHandler, wxHtmlTagHandler);
256 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
257 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
261 %rename(HtmlTagHandler) wxPyHtmlTagHandler;
262 class wxPyHtmlTagHandler : public wxObject {
264 %pythonAppend wxPyHtmlTagHandler "self._setCallbackInfo(self, HtmlTagHandler)"
265 wxPyHtmlTagHandler();
267 void _setCallbackInfo(PyObject* self, PyObject* _class);
269 void SetParser(wxHtmlParser *parser);
270 wxHtmlParser* GetParser();
271 void ParseInner(const wxHtmlTag& tag);
275 //---------------------------------------------------------------------------
278 class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
279 DECLARE_DYNAMIC_CLASS(wxPyHtmlWinTagHandler);
281 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
283 wxHtmlWinParser* GetParser() { return m_WParser; }
284 void ParseInner(const wxHtmlTag& tag)
285 { wxHtmlWinTagHandler::ParseInner(tag); }
287 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
288 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
293 IMPLEMENT_DYNAMIC_CLASS( wxPyHtmlWinTagHandler, wxHtmlWinTagHandler);
295 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
296 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
300 %rename(HtmlWinTagHandler) wxPyHtmlWinTagHandler;
301 class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
303 %pythonAppend wxPyHtmlWinTagHandler "self._setCallbackInfo(self, HtmlWinTagHandler)"
304 wxPyHtmlWinTagHandler();
306 void _setCallbackInfo(PyObject* self, PyObject* _class);
308 void SetParser(wxHtmlParser *parser);
309 wxHtmlWinParser* GetParser();
310 void ParseInner(const wxHtmlTag& tag);
314 //---------------------------------------------------------------------------
318 class wxPyHtmlTagsModule : public wxHtmlTagsModule {
320 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
321 m_tagHandlerClass = thc;
322 Py_INCREF(m_tagHandlerClass);
323 RegisterModule(this);
324 wxHtmlWinParser::AddModule(this);
328 bool blocked = wxPyBeginBlockThreads();
329 Py_DECREF(m_tagHandlerClass);
330 m_tagHandlerClass = NULL;
331 for (size_t x=0; x < m_objArray.GetCount(); x++) {
332 PyObject* obj = (PyObject*)m_objArray.Item(x);
335 wxPyEndBlockThreads(blocked);
338 void FillHandlersTable(wxHtmlWinParser *parser) {
339 // Wave our magic wand... (if it works it's a miracle! ;-)
341 // First, make a new instance of the tag handler
342 bool blocked = wxPyBeginBlockThreads();
343 PyObject* arg = PyTuple_New(0);
344 PyObject* obj = PyObject_CallObject(m_tagHandlerClass, arg);
347 // now figure out where it's C++ object is...
348 wxPyHtmlWinTagHandler* thPtr;
349 if (! wxPyConvertSwigPtr(obj, (void **)&thPtr, wxT("wxPyHtmlWinTagHandler"))) {
350 wxPyEndBlockThreads(blocked);
353 wxPyEndBlockThreads(blocked);
356 parser->AddTagHandler(thPtr);
363 PyObject* m_tagHandlerClass;
364 wxArrayPtrVoid m_objArray;
372 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
373 // Dynamically create a new wxModule. Refcounts tagHandlerClass
374 // and adds itself to the wxModules list and to the wxHtmlWinParser.
375 new wxPyHtmlTagsModule(tagHandlerClass);
380 //---------------------------------------------------------------------------
381 //---------------------------------------------------------------------------
385 // wxHtmlSelection is data holder with information about text selection.
386 // Selection is defined by two positions (beginning and end of the selection)
387 // and two leaf(!) cells at these positions.
388 class wxHtmlSelection
394 void Set(const wxPoint& fromPos, const wxHtmlCell *fromCell,
395 const wxPoint& toPos, const wxHtmlCell *toCell);
396 %Rename(SetCells, void, Set(const wxHtmlCell *fromCell, const wxHtmlCell *toCell));
398 const wxHtmlCell *GetFromCell() const;
399 const wxHtmlCell *GetToCell() const;
401 // these values are in absolute coordinates:
402 const wxPoint& GetFromPos() const;
403 const wxPoint& GetToPos() const;
405 // these are From/ToCell's private data
406 const wxPoint& GetFromPrivPos() const;
407 const wxPoint& GetToPrivPos() const;
408 void SetFromPrivPos(const wxPoint& pos);
409 void SetToPrivPos(const wxPoint& pos);
412 const bool IsEmpty() const;
417 enum wxHtmlSelectionState
419 wxHTML_SEL_OUT, // currently rendered cell is outside the selection
420 wxHTML_SEL_IN, // ... is inside selection
421 wxHTML_SEL_CHANGING // ... is the cell on which selection state changes
426 // Selection state is passed to wxHtmlCell::Draw so that it can render itself
427 // differently e.g. when inside text selection or outside it.
428 class wxHtmlRenderingState
431 wxHtmlRenderingState();
432 ~wxHtmlRenderingState();
434 void SetSelectionState(wxHtmlSelectionState s);
435 wxHtmlSelectionState GetSelectionState() const;
437 void SetFgColour(const wxColour& c);
438 const wxColour& GetFgColour() const;
439 void SetBgColour(const wxColour& c);
440 const wxColour& GetBgColour() const;
445 // HTML rendering customization. This class is used when rendering wxHtmlCells
447 class wxHtmlRenderingStyle
450 virtual wxColour GetSelectedTextColour(const wxColour& clr) = 0;
451 virtual wxColour GetSelectedTextBgColour(const wxColour& clr) = 0;
455 class wxDefaultHtmlRenderingStyle : public wxHtmlRenderingStyle
458 virtual wxColour GetSelectedTextColour(const wxColour& clr);
459 virtual wxColour GetSelectedTextBgColour(const wxColour& clr);
464 // Information given to cells when drawing them. Contains rendering state,
465 // selection information and rendering style object that can be used to
466 // customize the output.
467 class wxHtmlRenderingInfo
470 wxHtmlRenderingInfo();
471 ~wxHtmlRenderingInfo();
473 void SetSelection(wxHtmlSelection *s);
474 wxHtmlSelection *GetSelection() const;
476 void SetStyle(wxHtmlRenderingStyle *style);
477 wxHtmlRenderingStyle& GetStyle();
479 wxHtmlRenderingState& GetState();
482 //---------------------------------------------------------------------------
488 wxHTML_FIND_EXACT = 1,
489 wxHTML_FIND_NEAREST_BEFORE = 2,
490 wxHTML_FIND_NEAREST_AFTER = 4
494 class wxHtmlCell : public wxObject {
504 // Returns the maximum possible length of the cell.
505 // Call Layout at least once before using GetMaxTotalWidth()
506 int GetMaxTotalWidth() const;
508 const wxString& GetId() const;
509 void SetId(const wxString& id);
510 wxHtmlLinkInfo* GetLink(int x = 0, int y = 0);
511 wxHtmlCell* GetNext();
512 wxHtmlContainerCell* GetParent();
513 wxHtmlCell* GetFirstChild() const;
515 // Returns cursor to be used when mouse is over the cell:
516 wxCursor GetCursor() const;
518 // Formatting cells are not visible on the screen, they only alter
520 bool IsFormattingCell() const;
523 void SetLink(const wxHtmlLinkInfo& link);
524 void SetNext(wxHtmlCell *cell);
525 void SetParent(wxHtmlContainerCell *p);
526 void SetPos(int x, int y);
528 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
529 wxHtmlRenderingInfo& info);
530 void DrawInvisible(wxDC& dc, int x, int y,
531 wxHtmlRenderingInfo& info);
532 const wxHtmlCell* Find(int condition, const void* param);
534 bool AdjustPagebreak(int* INOUT);
535 void SetCanLiveOnPagebreak(bool can);
537 // Can the line be broken before this cell?
538 bool IsLinebreakAllowed() const;
540 // Returns True for simple == terminal cells, i.e. not composite ones.
541 // This if for internal usage only and may disappear in future versions!
542 bool IsTerminalCell() const;
544 // Find a cell inside this cell positioned at the given coordinates
545 // (relative to this's positions). Returns NULL if no such cell exists.
546 // The flag can be used to specify whether to look for terminal or
547 // nonterminal cells or both. In either case, returned cell is deepest
548 // cell in cells tree that contains [x,y].
549 wxHtmlCell *FindCellByPos(wxCoord x, wxCoord y,
550 unsigned flags = wxHTML_FIND_EXACT) const;
552 // Returns absolute position of the cell on HTML canvas
553 wxPoint GetAbsPos() const;
555 // Returns first (last) terminal cell inside this cell. It may return NULL,
556 // but it is rare -- only if there are no terminals in the tree.
557 wxHtmlCell *GetFirstTerminal() const ;
558 wxHtmlCell *GetLastTerminal() const ;
560 // Returns cell's depth, i.e. how far under the root cell it is
561 // (if it is the root, depth is 0)
562 unsigned GetDepth() const;
564 // Returns True if the cell appears before 'cell' in natural order of
565 // cells (= as they are read). If cell A is (grand)parent of cell B,
566 // then both A.IsBefore(B) and B.IsBefore(A) always return True.
567 bool IsBefore(wxHtmlCell *cell) const;
569 // Converts the cell into text representation. If sel != NULL then
570 // only part of the cell inside the selection is converted.
571 wxString ConvertToText(wxHtmlSelection *sel) const;
575 class wxHtmlWordCell : public wxHtmlCell
578 wxHtmlWordCell(const wxString& word, wxDC& dc);
582 class wxHtmlContainerCell : public wxHtmlCell {
584 wxHtmlContainerCell(wxHtmlContainerCell *parent);
586 void InsertCell(wxHtmlCell *cell);
587 void SetAlignHor(int al);
589 void SetAlignVer(int al);
591 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
592 int GetIndent(int ind);
593 int GetIndentUnits(int ind);
594 void SetAlign(const wxHtmlTag& tag);
595 void SetWidthFloat(int w, int units);
596 %Rename(SetWidthFloatFromTag, void, SetWidthFloat(const wxHtmlTag& tag));
597 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
598 void SetBackgroundColour(const wxColour& clr);
599 wxColour GetBackgroundColour();
600 void SetBorder(const wxColour& clr1, const wxColour& clr2);
601 wxHtmlCell* GetFirstChild();
602 %pragma(python) addtoclass = "GetFirstCell = GetFirstChild"
607 class wxHtmlColourCell : public wxHtmlCell {
609 wxHtmlColourCell(wxColour clr, int flags = wxHTML_CLR_FOREGROUND);
614 class wxHtmlFontCell : public wxHtmlCell
617 wxHtmlFontCell(wxFont *font);
621 class wxHtmlWidgetCell : public wxHtmlCell {
623 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
630 //---------------------------------------------------------------------------
632 //---------------------------------------------------------------------------
636 %{ // here's the C++ version
637 class wxPyHtmlFilter : public wxHtmlFilter {
638 DECLARE_ABSTRACT_CLASS(wxPyHtmlFilter);
640 wxPyHtmlFilter() : wxHtmlFilter() {}
642 // returns True if this filter is able to open&read given file
643 virtual bool CanRead(const wxFSFile& file) const {
646 bool blocked = wxPyBeginBlockThreads();
647 if ((found = wxPyCBH_findCallback(m_myInst, "CanRead"))) {
648 PyObject* obj = wxPyMake_wxObject((wxFSFile*)&file,false); // cast away const
649 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj));
652 wxPyEndBlockThreads(blocked);
657 // Reads given file and returns HTML document.
658 // Returns empty string if opening failed
659 virtual wxString ReadFile(const wxFSFile& file) const {
662 bool blocked = wxPyBeginBlockThreads();
663 if ((found = wxPyCBH_findCallback(m_myInst, "ReadFile"))) {
664 PyObject* obj = wxPyMake_wxObject((wxFSFile*)&file,false); // cast away const
666 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(O)", obj));
669 rval = Py2wxString(ro);
673 wxPyEndBlockThreads(blocked);
680 IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlFilter, wxHtmlFilter);
684 // And now the version seen by SWIG
686 %rename(HtmlFilter) wxPyHtmlFilter;
687 class wxPyHtmlFilter : public wxObject {
689 %pythonAppend wxPyHtmlFilter "self._setCallbackInfo(self, HtmlFilter)"
692 void _setCallbackInfo(PyObject* self, PyObject* _class);
696 // TODO: wxHtmlFilterHTML
699 //---------------------------------------------------------------------------
701 //---------------------------------------------------------------------------
705 class wxPyHtmlWindow : public wxHtmlWindow {
706 DECLARE_ABSTRACT_CLASS(wxPyHtmlWindow);
708 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
709 const wxPoint& pos = wxDefaultPosition,
710 const wxSize& size = wxDefaultSize,
711 long style = wxHW_DEFAULT_STYLE,
712 const wxString& name = wxPyHtmlWindowNameStr)
713 : wxHtmlWindow(parent, id, pos, size, style, name) {};
714 wxPyHtmlWindow() : wxHtmlWindow() {};
716 bool ScrollToAnchor(const wxString& anchor) {
717 return wxHtmlWindow::ScrollToAnchor(anchor);
720 bool HasAnchor(const wxString& anchor) {
721 const wxHtmlCell *c = m_Cell->Find(wxHTML_COND_ISANCHOR, &anchor);
725 void OnLinkClicked(const wxHtmlLinkInfo& link);
726 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
728 wxHtmlOpeningStatus OnOpeningURL(wxHtmlURLType type,
730 wxString *redirect) const;
732 DEC_PYCALLBACK__STRING(OnSetTitle);
733 DEC_PYCALLBACK__CELLINTINT(OnCellMouseHover);
734 DEC_PYCALLBACK__CELLINTINTME(OnCellClicked);
738 IMPLEMENT_ABSTRACT_CLASS( wxPyHtmlWindow, wxHtmlWindow );
739 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
740 IMP_PYCALLBACK__CELLINTINT(wxPyHtmlWindow, wxHtmlWindow, OnCellMouseHover);
741 IMP_PYCALLBACK__CELLINTINTME(wxPyHtmlWindow, wxHtmlWindow, OnCellClicked);
744 void wxPyHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) {
746 bool blocked = wxPyBeginBlockThreads();
747 if ((found = wxPyCBH_findCallback(m_myInst, "OnLinkClicked"))) {
748 PyObject* obj = wxPyConstructObject((void*)&link, wxT("wxHtmlLinkInfo"), 0);
749 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj));
752 wxPyEndBlockThreads(blocked);
754 wxHtmlWindow::OnLinkClicked(link);
756 void wxPyHtmlWindow::base_OnLinkClicked(const wxHtmlLinkInfo& link) {
757 wxHtmlWindow::OnLinkClicked(link);
761 wxHtmlOpeningStatus wxPyHtmlWindow::OnOpeningURL(wxHtmlURLType type,
763 wxString *redirect) const {
765 wxHtmlOpeningStatus rval;
766 bool blocked = wxPyBeginBlockThreads();
767 if ((found = wxPyCBH_findCallback(m_myInst, "OnOpeningURL"))) {
769 PyObject* s = wx2PyString(url);
770 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iO)", type, s));
772 if (PyString_Check(ro)
773 #if PYTHON_API_VERSION >= 1009
774 || PyUnicode_Check(ro)
777 *redirect = Py2wxString(ro);
778 rval = wxHTML_REDIRECT;
781 PyObject* num = PyNumber_Int(ro);
782 rval = (wxHtmlOpeningStatus)PyInt_AsLong(num);
787 wxPyEndBlockThreads(blocked);
789 rval = wxHtmlWindow::OnOpeningURL(type, url, redirect);
798 MustHaveApp(wxPyHtmlWindow);
800 %rename(HtmlWindow) wxPyHtmlWindow;
801 class wxPyHtmlWindow : public wxScrolledWindow {
803 %pythonAppend wxPyHtmlWindow "self._setCallbackInfo(self, HtmlWindow); self._setOORInfo(self)"
804 %pythonAppend wxPyHtmlWindow() ""
805 %typemap(out) wxPyHtmlWindow*; // turn off this typemap
807 wxPyHtmlWindow(wxWindow *parent, int id = -1,
808 const wxPoint& pos = wxDefaultPosition,
809 const wxSize& size = wxDefaultSize,
810 int style=wxHW_DEFAULT_STYLE,
811 const wxString& name = wxPyHtmlWindowNameStr);
812 %RenameCtor(PreHtmlWindow, wxPyHtmlWindow());
814 // Turn it back on again
815 %typemap(out) wxPyHtmlWindow* { $result = wxPyMake_wxObject($1, $owner); }
817 bool Create(wxWindow *parent, int id = -1,
818 const wxPoint& pos = wxDefaultPosition,
819 const wxSize& size = wxDefaultSize,
820 int style=wxHW_SCROLLBAR_AUTO,
821 const wxString& name = wxPyHtmlWindowNameStr);
824 void _setCallbackInfo(PyObject* self, PyObject* _class);
827 // Set HTML page and display it. !! source is HTML document itself,
828 // it is NOT address/filename of HTML document. If you want to
829 // specify document location, use LoadPage() istead
830 // Return value : False if an error occured, True otherwise
831 bool SetPage(const wxString& source);
833 // Load HTML page from given location. Location can be either
834 // a) /usr/wxGTK2/docs/html/wx.htm
835 // b) http://www.somewhere.uk/document.htm
836 // c) ftp://ftp.somesite.cz/pub/something.htm
837 // In case there is no prefix (http:,ftp:), the method
838 // will try to find it itself (1. local file, then http or ftp)
839 // After the page is loaded, the method calls SetPage() to display it.
840 // Note : you can also use path relative to previously loaded page
841 // Return value : same as SetPage
842 bool LoadPage(const wxString& location);
844 // Loads HTML page from file
845 bool LoadFile(const wxString& filename);
847 // Append to current page
848 bool AppendToPage(const wxString& source);
850 // Returns full location of opened page
851 wxString GetOpenedPage();
853 // Returns anchor within opened page
854 wxString GetOpenedAnchor();
856 // Returns <TITLE> of opened page or empty string otherwise
857 wxString GetOpenedPageTitle();
859 // Sets frame in which page title will be displayed. Format is format of
860 // frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s
861 void SetRelatedFrame(wxFrame* frame, const wxString& format);
862 wxFrame* GetRelatedFrame();
864 // After(!) calling SetRelatedFrame, this sets statusbar slot where messages
865 // will be displayed. Default is -1 = no messages.
866 void SetRelatedStatusBar(int bar);
868 // Sets fonts to be used when displaying HTML page.
870 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
872 if (sizes) temp = int_LIST_helper(sizes);
873 self->SetFonts(normal_face, fixed_face, temp);
879 // Sets font sizes to be relative to the given size or the system
880 // default size; use either specified or default font
881 void SetStandardFonts(int size = -1,
882 const wxString& normal_face = wxPyEmptyString,
883 const wxString& fixed_face = wxPyEmptyString);
886 void, SetTitle(const wxString& title),
889 // Sets space between text and window borders.
890 void SetBorders(int b);
892 // Saves custom settings into cfg config. it will use the path 'path'
893 // if given, otherwise it will save info into currently selected path.
894 // saved values : things set by SetFonts, SetBorders.
895 void ReadCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
896 void WriteCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
898 // Goes to previous/next page (in browsing history)
899 // Returns True if successful, False otherwise
901 bool HistoryForward();
902 bool HistoryCanBack();
903 bool HistoryCanForward();
908 // Returns pointer to conteiners/cells structure.
909 wxHtmlContainerCell* GetInternalRepresentation();
911 // Returns a pointer to the parser.
912 wxHtmlWinParser* GetParser();
914 bool ScrollToAnchor(const wxString& anchor);
915 bool HasAnchor(const wxString& anchor);
918 static void AddFilter(wxPyHtmlFilter *filter);
920 // Helper functions to select parts of page:
921 void SelectWord(const wxPoint& pos);
922 void SelectLine(const wxPoint& pos);
925 // Convert selection to text:
926 wxString SelectionToText();
928 // Converts current page to text:
931 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
932 void base_OnSetTitle(const wxString& title);
933 void base_OnCellMouseHover(wxHtmlCell *cell, wxCoord x, wxCoord y);
934 void base_OnCellClicked(wxHtmlCell *cell,
935 wxCoord x, wxCoord y,
936 const wxMouseEvent& event);
938 static wxVisualAttributes
939 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
945 //---------------------------------------------------------------------------
946 //---------------------------------------------------------------------------
950 MustHaveApp(wxHtmlDCRenderer);
952 class wxHtmlDCRenderer : public wxObject {
957 void SetDC(wxDC *dc, int maxwidth);
958 void SetSize(int width, int height);
959 void SetHtmlText(const wxString& html,
960 const wxString& basepath = wxPyEmptyString,
962 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
964 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
966 if (sizes) temp = int_LIST_helper(sizes);
967 self->SetFonts(normal_face, fixed_face, temp);
973 // Sets font sizes to be relative to the given size or the system
974 // default size; use either specified or default font
975 void SetStandardFonts(int size = -1,
976 const wxString& normal_face = wxPyEmptyString,
977 const wxString& fixed_face = wxPyEmptyString);
979 int Render(int x, int y, int from = 0, int dont_render = false, int maxHeight = INT_MAX,
980 //int *known_pagebreaks = NULL, int number_of_pages = 0
981 int* choices=NULL, int LCOUNT = 0
983 int GetTotalHeight();
984 // returns total height of the html document
985 // (compare Render's return value with this)
996 MustHaveApp(wxHtmlPrintout);
998 class wxHtmlPrintout : public wxPyPrintout {
1000 wxHtmlPrintout(const wxString& title = wxPyHtmlPrintoutTitleStr);
1001 //~wxHtmlPrintout(); wxPrintPreview object takes ownership...
1003 void SetHtmlText(const wxString& html,
1004 const wxString &basepath = wxPyEmptyString,
1006 void SetHtmlFile(const wxString &htmlfile);
1007 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
1008 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
1010 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
1012 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
1014 if (sizes) temp = int_LIST_helper(sizes);
1015 self->SetFonts(normal_face, fixed_face, temp);
1021 // Sets font sizes to be relative to the given size or the system
1022 // default size; use either specified or default font
1023 void SetStandardFonts(int size = -1,
1024 const wxString& normal_face = wxPyEmptyString,
1025 const wxString& fixed_face = wxPyEmptyString);
1027 void SetMargins(float top = 25.2, float bottom = 25.2,
1028 float left = 25.2, float right = 25.2,
1031 // Adds input filter
1032 static void AddFilter(wxHtmlFilter *filter);
1035 static void CleanUpStatics();
1040 MustHaveApp(wxHtmlEasyPrinting);
1042 class wxHtmlEasyPrinting : public wxObject {
1044 wxHtmlEasyPrinting(const wxString& name = wxPyHtmlPrintingTitleStr,
1045 wxWindow *parentWindow = NULL);
1046 ~wxHtmlEasyPrinting();
1048 void PreviewFile(const wxString &htmlfile);
1049 void PreviewText(const wxString &htmltext, const wxString& basepath = wxPyEmptyString);
1050 void PrintFile(const wxString &htmlfile);
1051 void PrintText(const wxString &htmltext, const wxString& basepath = wxPyEmptyString);
1052 // void PrinterSetup();
1054 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
1055 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
1058 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
1060 if (sizes) temp = int_LIST_helper(sizes);
1061 self->SetFonts(normal_face, fixed_face, temp);
1067 // Sets font sizes to be relative to the given size or the system
1068 // default size; use either specified or default font
1069 void SetStandardFonts(int size = -1,
1070 const wxString& normal_face = wxPyEmptyString,
1071 const wxString& fixed_face = wxPyEmptyString);
1073 wxPrintData *GetPrintData() {return m_PrintData;}
1074 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
1079 //---------------------------------------------------------------------------
1080 //---------------------------------------------------------------------------
1084 class wxHtmlBookRecord {
1086 wxHtmlBookRecord(const wxString& bookfile, const wxString& basepath,
1087 const wxString& title, const wxString& start);
1089 wxString GetBookFile();
1090 wxString GetTitle();
1091 wxString GetStart();
1092 wxString GetBasePath();
1094 void SetContentsRange(int start, int end);
1095 int GetContentsStart();
1096 int GetContentsEnd();
1098 void SetTitle(const wxString& title);
1099 void SetBasePath(const wxString& path);
1100 void SetStart(const wxString& start);
1102 wxString GetFullPath(const wxString &page) const;
1105 //---------------------------------------------------------------------------
1107 struct wxHtmlContentsItem
1110 int GetLevel() { return self->m_Level; }
1111 int GetID() { return self->m_ID; }
1112 wxString GetName() { return self->m_Name; }
1113 wxString GetPage() { return self->m_Page; }
1114 wxHtmlBookRecord* GetBook() { return self->m_Book; }
1118 //---------------------------------------------------------------------------
1120 class wxHtmlSearchStatus
1123 //wxHtmlSearchStatus(wxHtmlHelpData* base, const wxString& keyword,
1124 // const wxString& book = wxPyEmptyString);
1129 const wxString& GetName();
1130 wxHtmlContentsItem* GetContentsItem();
1133 //---------------------------------------------------------------------------
1135 class wxHtmlHelpData {
1140 void SetTempDir(const wxString& path);
1141 bool AddBook(const wxString& book);
1142 // bool AddBookParam(const wxString& title, const wxString& contfile,
1143 // const wxString& indexfile=wxPyEmptyString,
1144 // const wxString& deftopic=wxPyEmptyString,
1145 // const wxString& path=wxPyEmptyString);
1147 wxString FindPageByName(const wxString& page);
1148 wxString FindPageById(int id);
1150 // TODO: this one needs fixed...
1151 const wxHtmlBookRecArray& GetBookRecArray();
1153 wxHtmlContentsItem* GetContents();
1154 int GetContentsCnt();
1155 wxHtmlContentsItem* GetIndex();
1159 //---------------------------------------------------------------------------
1161 MustHaveApp(wxHtmlHelpFrame);
1163 class wxHtmlHelpFrame : public wxFrame {
1165 %pythonAppend wxHtmlHelpFrame "self._setOORInfo(self)"
1167 wxHtmlHelpFrame(wxWindow* parent, int wxWindowID,
1168 const wxString& title = wxPyEmptyString,
1169 int style = wxHF_DEFAULTSTYLE, wxHtmlHelpData* data = NULL);
1171 wxHtmlHelpData* GetData();
1172 void SetTitleFormat(const wxString& format);
1173 void Display(const wxString& x);
1174 %Rename(DisplayID, void, Display(int id));
1175 void DisplayContents();
1176 void DisplayIndex();
1177 bool KeywordSearch(const wxString& keyword);
1178 void UseConfig(wxConfigBase *config, const wxString& rootpath = wxPyEmptyString);
1179 void ReadCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
1180 void WriteCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
1184 //---------------------------------------------------------------------------
1200 MustHaveApp(wxHtmlHelpController);
1202 class wxHtmlHelpController : public wxObject // wxHelpControllerBase
1205 // %pythonAppend wxHtmlHelpController "self._setOORInfo(self)"
1207 wxHtmlHelpController(int style = wxHF_DEFAULTSTYLE);
1208 ~wxHtmlHelpController();
1210 void SetTitleFormat(const wxString& format);
1211 void SetTempDir(const wxString& path);
1212 bool AddBook(const wxString& book, int show_wait_msg = false);
1213 void Display(const wxString& x);
1214 %Rename(DisplayID, void, Display(int id));
1215 void DisplayContents();
1216 void DisplayIndex();
1217 bool KeywordSearch(const wxString& keyword);
1218 void UseConfig(wxConfigBase *config, const wxString& rootpath = wxPyEmptyString);
1219 void ReadCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
1220 void WriteCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
1221 wxHtmlHelpFrame* GetFrame();
1227 //---------------------------------------------------------------------------
1229 wxPyPtrTypeMap_Add("wxHtmlTagHandler", "wxPyHtmlTagHandler");
1230 wxPyPtrTypeMap_Add("wxHtmlWinTagHandler", "wxPyHtmlWinTagHandler");
1231 wxPyPtrTypeMap_Add("wxHtmlWindow", "wxPyHtmlWindow");
1232 wxPyPtrTypeMap_Add("wxHtmlFilter", "wxPyHtmlFilter");
1234 //---------------------------------------------------------------------------
1235 //---------------------------------------------------------------------------