]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/html.i
reSWIGged
[wxWidgets.git] / wxPython / src / html.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: html.i
3 // Purpose: SWIG definitions of html classes
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 25-Nov-1998
8 // RCS-ID: $Id$
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 %define DOCSTRING
14 "Classes for a simple HTML rendering window, HTML Help Window, etc."
15 %enddef
16
17 %module(docstring=DOCSTRING) html
18
19 %{
20 #include "wx/wxPython/wxPython.h"
21 #include "wx/wxPython/pyclasses.h"
22 #include "wx/wxPython/pyistream.h"
23 #include "wx/wxPython/printfw.h"
24
25 #include <wx/html/htmlwin.h>
26 #include <wx/html/htmprint.h>
27 #include <wx/html/helpctrl.h>
28
29 %}
30
31
32 //---------------------------------------------------------------------------
33
34 %import windows.i
35 %pythoncode { wx = _core }
36 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
37
38 %include _html_rename.i
39
40
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"))
45
46
47 // TODO: Split this file into multiple %included files that coresponds to the
48 // wx/html include files (more or less.)
49
50 //---------------------------------------------------------------------------
51 //---------------------------------------------------------------------------
52 %newgroup
53
54
55 enum {
56 wxHTML_ALIGN_LEFT,
57 wxHTML_ALIGN_CENTER,
58 wxHTML_ALIGN_RIGHT,
59 wxHTML_ALIGN_BOTTOM,
60 wxHTML_ALIGN_TOP,
61
62 wxHTML_CLR_FOREGROUND,
63 wxHTML_CLR_BACKGROUND,
64
65 wxHTML_UNITS_PIXELS,
66 wxHTML_UNITS_PERCENT,
67
68 wxHTML_INDENT_LEFT,
69 wxHTML_INDENT_RIGHT,
70 wxHTML_INDENT_TOP,
71 wxHTML_INDENT_BOTTOM,
72
73 wxHTML_INDENT_HORIZONTAL,
74 wxHTML_INDENT_VERTICAL,
75 wxHTML_INDENT_ALL,
76
77 wxHTML_COND_ISANCHOR,
78 wxHTML_COND_ISIMAGEMAP,
79 wxHTML_COND_USER,
80
81
82 wxHTML_FONT_SIZE_1,
83 wxHTML_FONT_SIZE_2,
84 wxHTML_FONT_SIZE_3,
85 wxHTML_FONT_SIZE_4,
86 wxHTML_FONT_SIZE_5,
87 wxHTML_FONT_SIZE_6,
88 wxHTML_FONT_SIZE_7,
89 };
90
91
92 enum {
93 wxHW_SCROLLBAR_NEVER,
94 wxHW_SCROLLBAR_AUTO,
95 wxHW_NO_SELECTION,
96 wxHW_DEFAULT_STYLE,
97 };
98
99
100 // enums for wxHtmlWindow::OnOpeningURL
101 enum wxHtmlOpeningStatus
102 {
103 wxHTML_OPEN,
104 wxHTML_BLOCK,
105 wxHTML_REDIRECT
106 };
107
108 enum wxHtmlURLType
109 {
110 wxHTML_URL_PAGE,
111 wxHTML_URL_IMAGE,
112 wxHTML_URL_OTHER
113 };
114
115
116
117 //---------------------------------------------------------------------------
118
119 class wxHtmlLinkInfo : public wxObject {
120 public:
121 wxHtmlLinkInfo(const wxString& href, const wxString& target = wxPyEmptyString);
122 wxString GetHref();
123 wxString GetTarget();
124 wxMouseEvent* GetEvent();
125 wxHtmlCell* GetHtmlCell();
126
127 void SetEvent(const wxMouseEvent *e);
128 void SetHtmlCell(const wxHtmlCell * e);
129 };
130
131 //---------------------------------------------------------------------------
132
133 class wxHtmlTag : public wxObject {
134 public:
135 // Never need to create a new tag from Python...
136 //wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
137
138 wxString GetName();
139 bool HasParam(const wxString& par);
140 wxString GetParam(const wxString& par, int with_commas = False);
141
142 // Can't do this one as-is, but GetParam should be enough...
143 //int ScanParam(const wxString& par, const char *format, void* param);
144
145 wxString GetAllParams();
146 bool HasEnding();
147 int GetBeginPos();
148 int GetEndPos1();
149 int GetEndPos2();
150 };
151
152 //---------------------------------------------------------------------------
153
154 class wxHtmlParser : public wxObject {
155 public:
156 // wxHtmlParser(); This is an abstract base class...
157
158 void SetFS(wxFileSystem *fs);
159 wxFileSystem* GetFS();
160 wxObject* Parse(const wxString& source);
161 void InitParser(const wxString& source);
162 void DoneParser();
163 void DoParsing(int begin_pos, int end_pos);
164 void StopParsing();
165 // wxObject* GetProduct();
166
167 void AddTagHandler(wxHtmlTagHandler *handler);
168 wxString* GetSource();
169 void PushTagHandler(wxHtmlTagHandler* handler, wxString tags);
170 void PopTagHandler();
171
172 // virtual wxFSFile *OpenURL(wxHtmlURLType type, const wxString& url) const;
173
174 // void AddText(const char* txt) = 0;
175 // void AddTag(const wxHtmlTag& tag);
176 };
177
178
179 //---------------------------------------------------------------------------
180
181 class wxHtmlWinParser : public wxHtmlParser {
182 public:
183 wxHtmlWinParser(wxPyHtmlWindow *wnd = NULL);
184
185 void SetDC(wxDC *dc);
186 wxDC* GetDC();
187 int GetCharHeight();
188 int GetCharWidth();
189 wxPyHtmlWindow* GetWindow();
190
191 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
192 %extend {
193 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
194 int* temp = NULL;
195 if (sizes) temp = int_LIST_helper(sizes);
196 self->SetFonts(normal_face, fixed_face, temp);
197 if (temp)
198 delete [] temp;
199 }
200 }
201
202 wxHtmlContainerCell* GetContainer();
203 wxHtmlContainerCell* OpenContainer();
204 wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
205 wxHtmlContainerCell* CloseContainer();
206
207 int GetFontSize();
208 void SetFontSize(int s);
209 int GetFontBold();
210 void SetFontBold(int x);
211 int GetFontItalic();
212 void SetFontItalic(int x);
213 int GetFontUnderlined();
214 void SetFontUnderlined(int x);
215 int GetFontFixed();
216 void SetFontFixed(int x);
217 int GetAlign();
218 void SetAlign(int a);
219 wxColour GetLinkColor();
220 void SetLinkColor(const wxColour& clr);
221 wxColour GetActualColor();
222 void SetActualColor(const wxColour& clr);
223 void SetLink(const wxString& link);
224 wxFont* CreateCurrentFont();
225 wxHtmlLinkInfo GetLink();
226
227 };
228
229
230 //---------------------------------------------------------------------------
231
232 %{
233 class wxPyHtmlTagHandler : public wxHtmlTagHandler {
234 DECLARE_DYNAMIC_CLASS(wxPyHtmlTagHandler);
235 public:
236 wxPyHtmlTagHandler() : wxHtmlTagHandler() {};
237
238 wxHtmlParser* GetParser() { return m_Parser; }
239 void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); }
240
241 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
242 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
243
244 PYPRIVATE;
245 };
246
247 IMPLEMENT_DYNAMIC_CLASS(wxPyHtmlTagHandler, wxHtmlTagHandler);
248
249 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
250 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
251 %}
252
253
254 %name(HtmlTagHandler) class wxPyHtmlTagHandler : public wxObject {
255 public:
256 %pythonAppend wxPyHtmlTagHandler "self._setCallbackInfo(self, HtmlTagHandler)"
257 wxPyHtmlTagHandler();
258
259 void _setCallbackInfo(PyObject* self, PyObject* _class);
260
261 void SetParser(wxHtmlParser *parser);
262 wxHtmlParser* GetParser();
263 void ParseInner(const wxHtmlTag& tag);
264 };
265
266
267 //---------------------------------------------------------------------------
268
269 %{
270 class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
271 DECLARE_DYNAMIC_CLASS(wxPyHtmlWinTagHandler);
272 public:
273 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
274
275 wxHtmlWinParser* GetParser() { return m_WParser; }
276 void ParseInner(const wxHtmlTag& tag)
277 { wxHtmlWinTagHandler::ParseInner(tag); }
278
279 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
280 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
281
282 PYPRIVATE;
283 };
284
285 IMPLEMENT_DYNAMIC_CLASS( wxPyHtmlWinTagHandler, wxHtmlWinTagHandler);
286
287 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
288 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
289 %}
290
291
292 %name(HtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
293 public:
294 %pythonAppend wxPyHtmlWinTagHandler "self._setCallbackInfo(self, HtmlWinTagHandler)"
295 wxPyHtmlWinTagHandler();
296
297 void _setCallbackInfo(PyObject* self, PyObject* _class);
298
299 void SetParser(wxHtmlParser *parser);
300 wxHtmlWinParser* GetParser();
301 void ParseInner(const wxHtmlTag& tag);
302 };
303
304
305 //---------------------------------------------------------------------------
306
307 %{
308
309 class wxPyHtmlTagsModule : public wxHtmlTagsModule {
310 public:
311 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
312 m_tagHandlerClass = thc;
313 Py_INCREF(m_tagHandlerClass);
314 RegisterModule(this);
315 wxHtmlWinParser::AddModule(this);
316 }
317
318 void OnExit() {
319 bool blocked = wxPyBeginBlockThreads();
320 Py_DECREF(m_tagHandlerClass);
321 m_tagHandlerClass = NULL;
322 for (size_t x=0; x < m_objArray.GetCount(); x++) {
323 PyObject* obj = (PyObject*)m_objArray.Item(x);
324 Py_DECREF(obj);
325 }
326 wxPyEndBlockThreads(blocked);
327 };
328
329 void FillHandlersTable(wxHtmlWinParser *parser) {
330 // Wave our magic wand... (if it works it's a miracle! ;-)
331
332 // First, make a new instance of the tag handler
333 bool blocked = wxPyBeginBlockThreads();
334 PyObject* arg = PyTuple_New(0);
335 PyObject* obj = PyObject_CallObject(m_tagHandlerClass, arg);
336 Py_DECREF(arg);
337
338 // now figure out where it's C++ object is...
339 wxPyHtmlWinTagHandler* thPtr;
340 if (! wxPyConvertSwigPtr(obj, (void **)&thPtr, wxT("wxPyHtmlWinTagHandler"))) {
341 wxPyEndBlockThreads(blocked);
342 return;
343 }
344 wxPyEndBlockThreads(blocked);
345
346 // add it,
347 parser->AddTagHandler(thPtr);
348
349 // and track it.
350 m_objArray.Add(obj);
351 }
352
353 private:
354 PyObject* m_tagHandlerClass;
355 wxArrayPtrVoid m_objArray;
356
357 };
358 %}
359
360
361
362 %inline %{
363 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
364 // Dynamically create a new wxModule. Refcounts tagHandlerClass
365 // and adds itself to the wxModules list and to the wxHtmlWinParser.
366 new wxPyHtmlTagsModule(tagHandlerClass);
367 }
368 %}
369
370
371 //---------------------------------------------------------------------------
372 //---------------------------------------------------------------------------
373 %newgroup
374
375
376 // wxHtmlSelection is data holder with information about text selection.
377 // Selection is defined by two positions (beginning and end of the selection)
378 // and two leaf(!) cells at these positions.
379 class wxHtmlSelection
380 {
381 public:
382 wxHtmlSelection();
383 ~wxHtmlSelection();
384
385 void Set(const wxPoint& fromPos, const wxHtmlCell *fromCell,
386 const wxPoint& toPos, const wxHtmlCell *toCell);
387 %name(SetCells)void Set(const wxHtmlCell *fromCell, const wxHtmlCell *toCell);
388
389 const wxHtmlCell *GetFromCell() const;
390 const wxHtmlCell *GetToCell() const;
391
392 // these values are in absolute coordinates:
393 const wxPoint& GetFromPos() const;
394 const wxPoint& GetToPos() const;
395
396 // these are From/ToCell's private data
397 const wxPoint& GetFromPrivPos() const;
398 const wxPoint& GetToPrivPos() const;
399 void SetFromPrivPos(const wxPoint& pos);
400 void SetToPrivPos(const wxPoint& pos);
401 void ClearPrivPos();
402
403 const bool IsEmpty() const;
404
405 };
406
407
408 enum wxHtmlSelectionState
409 {
410 wxHTML_SEL_OUT, // currently rendered cell is outside the selection
411 wxHTML_SEL_IN, // ... is inside selection
412 wxHTML_SEL_CHANGING // ... is the cell on which selection state changes
413 };
414
415
416
417 // Selection state is passed to wxHtmlCell::Draw so that it can render itself
418 // differently e.g. when inside text selection or outside it.
419 class wxHtmlRenderingState
420 {
421 public:
422 wxHtmlRenderingState();
423 ~wxHtmlRenderingState();
424
425 void SetSelectionState(wxHtmlSelectionState s);
426 wxHtmlSelectionState GetSelectionState() const;
427
428 void SetFgColour(const wxColour& c);
429 const wxColour& GetFgColour() const;
430 void SetBgColour(const wxColour& c);
431 const wxColour& GetBgColour() const;
432 };
433
434
435
436 // HTML rendering customization. This class is used when rendering wxHtmlCells
437 // as a callback:
438 class wxHtmlRenderingStyle
439 {
440 public:
441 virtual wxColour GetSelectedTextColour(const wxColour& clr) = 0;
442 virtual wxColour GetSelectedTextBgColour(const wxColour& clr) = 0;
443 };
444
445 // Standard style:
446 class wxDefaultHtmlRenderingStyle : public wxHtmlRenderingStyle
447 {
448 public:
449 virtual wxColour GetSelectedTextColour(const wxColour& clr);
450 virtual wxColour GetSelectedTextBgColour(const wxColour& clr);
451 };
452
453
454
455 // Information given to cells when drawing them. Contains rendering state,
456 // selection information and rendering style object that can be used to
457 // customize the output.
458 class wxHtmlRenderingInfo
459 {
460 public:
461 wxHtmlRenderingInfo();
462 ~wxHtmlRenderingInfo();
463
464 void SetSelection(wxHtmlSelection *s);
465 wxHtmlSelection *GetSelection() const;
466
467 void SetStyle(wxHtmlRenderingStyle *style);
468 wxHtmlRenderingStyle& GetStyle();
469
470 wxHtmlRenderingState& GetState();
471 };
472
473 //---------------------------------------------------------------------------
474 %newgroup
475
476
477 enum
478 {
479 wxHTML_FIND_EXACT = 1,
480 wxHTML_FIND_NEAREST_BEFORE = 2,
481 wxHTML_FIND_NEAREST_AFTER = 4
482 };
483
484
485 class wxHtmlCell : public wxObject {
486 public:
487 wxHtmlCell();
488
489 int GetPosX();
490 int GetPosY();
491 int GetWidth();
492 int GetHeight();
493 int GetDescent();
494
495 // Returns the maximum possible length of the cell.
496 // Call Layout at least once before using GetMaxTotalWidth()
497 int GetMaxTotalWidth() const;
498
499 const wxString& GetId() const;
500 void SetId(const wxString& id);
501 wxHtmlLinkInfo* GetLink(int x = 0, int y = 0);
502 wxHtmlCell* GetNext();
503 wxHtmlContainerCell* GetParent();
504 wxHtmlCell* GetFirstChild() const;
505
506 // Returns cursor to be used when mouse is over the cell:
507 wxCursor GetCursor() const;
508
509 // Formatting cells are not visible on the screen, they only alter
510 // renderer's state.
511 bool IsFormattingCell() const;
512
513
514 void SetLink(const wxHtmlLinkInfo& link);
515 void SetNext(wxHtmlCell *cell);
516 void SetParent(wxHtmlContainerCell *p);
517 void SetPos(int x, int y);
518 void Layout(int w);
519 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
520 wxHtmlRenderingInfo& info);
521 void DrawInvisible(wxDC& dc, int x, int y,
522 wxHtmlRenderingInfo& info);
523 const wxHtmlCell* Find(int condition, const void* param);
524
525 bool AdjustPagebreak(int* INOUT);
526 void SetCanLiveOnPagebreak(bool can);
527
528 // Can the line be broken before this cell?
529 bool IsLinebreakAllowed() const;
530
531 // Returns True for simple == terminal cells, i.e. not composite ones.
532 // This if for internal usage only and may disappear in future versions!
533 bool IsTerminalCell() const;
534
535 // Find a cell inside this cell positioned at the given coordinates
536 // (relative to this's positions). Returns NULL if no such cell exists.
537 // The flag can be used to specify whether to look for terminal or
538 // nonterminal cells or both. In either case, returned cell is deepest
539 // cell in cells tree that contains [x,y].
540 wxHtmlCell *FindCellByPos(wxCoord x, wxCoord y,
541 unsigned flags = wxHTML_FIND_EXACT) const;
542
543 // Returns absolute position of the cell on HTML canvas
544 wxPoint GetAbsPos() const;
545
546 // Returns first (last) terminal cell inside this cell. It may return NULL,
547 // but it is rare -- only if there are no terminals in the tree.
548 wxHtmlCell *GetFirstTerminal() const ;
549 wxHtmlCell *GetLastTerminal() const ;
550
551 // Returns cell's depth, i.e. how far under the root cell it is
552 // (if it is the root, depth is 0)
553 unsigned GetDepth() const;
554
555 // Returns True if the cell appears before 'cell' in natural order of
556 // cells (= as they are read). If cell A is (grand)parent of cell B,
557 // then both A.IsBefore(B) and B.IsBefore(A) always return True.
558 bool IsBefore(wxHtmlCell *cell) const;
559
560 // Converts the cell into text representation. If sel != NULL then
561 // only part of the cell inside the selection is converted.
562 wxString ConvertToText(wxHtmlSelection *sel) const;
563 };
564
565
566 class wxHtmlWordCell : public wxHtmlCell
567 {
568 public:
569 wxHtmlWordCell(const wxString& word, wxDC& dc);
570 };
571
572
573 class wxHtmlContainerCell : public wxHtmlCell {
574 public:
575 wxHtmlContainerCell(wxHtmlContainerCell *parent);
576
577 void InsertCell(wxHtmlCell *cell);
578 void SetAlignHor(int al);
579 int GetAlignHor();
580 void SetAlignVer(int al);
581 int GetAlignVer();
582 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
583 int GetIndent(int ind);
584 int GetIndentUnits(int ind);
585 void SetAlign(const wxHtmlTag& tag);
586 void SetWidthFloat(int w, int units);
587 %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
588 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
589 void SetBackgroundColour(const wxColour& clr);
590 wxColour GetBackgroundColour();
591 void SetBorder(const wxColour& clr1, const wxColour& clr2);
592 wxHtmlCell* GetFirstChild();
593 %pragma(python) addtoclass = "GetFirstCell = GetFirstChild"
594 };
595
596
597
598 class wxHtmlColourCell : public wxHtmlCell {
599 public:
600 wxHtmlColourCell(wxColour clr, int flags = wxHTML_CLR_FOREGROUND);
601
602 };
603
604
605 class wxHtmlFontCell : public wxHtmlCell
606 {
607 public:
608 wxHtmlFontCell(wxFont *font);
609 };
610
611
612 class wxHtmlWidgetCell : public wxHtmlCell {
613 public:
614 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
615
616 };
617
618
619
620
621 //---------------------------------------------------------------------------
622 // wxHtmlFilter
623 //---------------------------------------------------------------------------
624 %newgroup
625
626
627 %{ // here's the C++ version
628 class wxPyHtmlFilter : public wxHtmlFilter {
629 DECLARE_ABSTRACT_CLASS(wxPyHtmlFilter);
630 public:
631 wxPyHtmlFilter() : wxHtmlFilter() {}
632
633 // returns True if this filter is able to open&read given file
634 virtual bool CanRead(const wxFSFile& file) const {
635 bool rval = False;
636 bool found;
637 bool blocked = wxPyBeginBlockThreads();
638 if ((found = wxPyCBH_findCallback(m_myInst, "CanRead"))) {
639 PyObject* obj = wxPyMake_wxObject((wxFSFile*)&file); // cast away const
640 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj));
641 Py_DECREF(obj);
642 }
643 wxPyEndBlockThreads(blocked);
644 return rval;
645 }
646
647
648 // Reads given file and returns HTML document.
649 // Returns empty string if opening failed
650 virtual wxString ReadFile(const wxFSFile& file) const {
651 wxString rval;
652 bool found;
653 bool blocked = wxPyBeginBlockThreads();
654 if ((found = wxPyCBH_findCallback(m_myInst, "ReadFile"))) {
655 PyObject* obj = wxPyMake_wxObject((wxFSFile*)&file); // cast away const
656 PyObject* ro;
657 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(O)", obj));
658 Py_DECREF(obj);
659 if (ro) {
660 rval = Py2wxString(ro);
661 Py_DECREF(ro);
662 }
663 }
664 wxPyEndBlockThreads(blocked);
665 return rval;
666 }
667
668 PYPRIVATE;
669 };
670
671 IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlFilter, wxHtmlFilter);
672 %}
673
674
675 // And now the version seen by SWIG
676
677 %name(HtmlFilter) class wxPyHtmlFilter : public wxObject {
678 public:
679 %pythonAppend wxPyHtmlFilter "self._setCallbackInfo(self, HtmlFilter)"
680 wxPyHtmlFilter();
681
682 void _setCallbackInfo(PyObject* self, PyObject* _class);
683 };
684
685
686 // TODO: wxHtmlFilterHTML
687
688
689 //---------------------------------------------------------------------------
690 // wxHtmlWindow
691 //---------------------------------------------------------------------------
692 %newgroup
693
694 %{
695 class wxPyHtmlWindow : public wxHtmlWindow {
696 DECLARE_ABSTRACT_CLASS(wxPyHtmlWindow);
697 public:
698 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
699 const wxPoint& pos = wxDefaultPosition,
700 const wxSize& size = wxDefaultSize,
701 long style = wxHW_DEFAULT_STYLE,
702 const wxString& name = wxPyHtmlWindowNameStr)
703 : wxHtmlWindow(parent, id, pos, size, style, name) {};
704 wxPyHtmlWindow() : wxHtmlWindow() {};
705
706 bool ScrollToAnchor(const wxString& anchor) {
707 return wxHtmlWindow::ScrollToAnchor(anchor);
708 }
709
710 bool HasAnchor(const wxString& anchor) {
711 const wxHtmlCell *c = m_Cell->Find(wxHTML_COND_ISANCHOR, &anchor);
712 return c!=NULL;
713 }
714
715 void OnLinkClicked(const wxHtmlLinkInfo& link);
716 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
717
718 wxHtmlOpeningStatus OnOpeningURL(wxHtmlURLType type,
719 const wxString& url,
720 wxString *redirect) const;
721
722 DEC_PYCALLBACK__STRING(OnSetTitle);
723 DEC_PYCALLBACK__CELLINTINT(OnCellMouseHover);
724 DEC_PYCALLBACK__CELLINTINTME(OnCellClicked);
725 PYPRIVATE;
726 };
727
728 IMPLEMENT_ABSTRACT_CLASS( wxPyHtmlWindow, wxHtmlWindow );
729 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
730 IMP_PYCALLBACK__CELLINTINT(wxPyHtmlWindow, wxHtmlWindow, OnCellMouseHover);
731 IMP_PYCALLBACK__CELLINTINTME(wxPyHtmlWindow, wxHtmlWindow, OnCellClicked);
732
733
734 void wxPyHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) {
735 bool found;
736 bool blocked = wxPyBeginBlockThreads();
737 if ((found = wxPyCBH_findCallback(m_myInst, "OnLinkClicked"))) {
738 PyObject* obj = wxPyConstructObject((void*)&link, wxT("wxHtmlLinkInfo"), 0);
739 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj));
740 Py_DECREF(obj);
741 }
742 wxPyEndBlockThreads(blocked);
743 if (! found)
744 wxHtmlWindow::OnLinkClicked(link);
745 }
746 void wxPyHtmlWindow::base_OnLinkClicked(const wxHtmlLinkInfo& link) {
747 wxHtmlWindow::OnLinkClicked(link);
748 }
749
750
751 wxHtmlOpeningStatus wxPyHtmlWindow::OnOpeningURL(wxHtmlURLType type,
752 const wxString& url,
753 wxString *redirect) const {
754 bool found;
755 wxHtmlOpeningStatus rval;
756 bool blocked = wxPyBeginBlockThreads();
757 if ((found = wxPyCBH_findCallback(m_myInst, "OnOpeningURL"))) {
758 PyObject* ro;
759 PyObject* s = wx2PyString(url);
760 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iO)", type, s));
761 Py_DECREF(s);
762 if (PyString_Check(ro)
763 #if PYTHON_API_VERSION >= 1009
764 || PyUnicode_Check(ro)
765 #endif
766 ) {
767 *redirect = Py2wxString(ro);
768 rval = wxHTML_REDIRECT;
769 }
770 else {
771 PyObject* num = PyNumber_Int(ro);
772 rval = (wxHtmlOpeningStatus)PyInt_AsLong(num);
773 Py_DECREF(num);
774 }
775 Py_DECREF(ro);
776 }
777 wxPyEndBlockThreads(blocked);
778 if (! found)
779 rval = wxHtmlWindow::OnOpeningURL(type, url, redirect);
780 return rval;
781 }
782
783
784 %}
785
786
787
788 %name(HtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
789 public:
790 %pythonAppend wxPyHtmlWindow "self._setCallbackInfo(self, HtmlWindow); self._setOORInfo(self)"
791 %pythonAppend wxPyHtmlWindow() ""
792
793 wxPyHtmlWindow(wxWindow *parent, int id = -1,
794 const wxPoint& pos = wxDefaultPosition,
795 const wxSize& size = wxDefaultSize,
796 int style=wxHW_DEFAULT_STYLE,
797 const wxString& name = wxPyHtmlWindowNameStr);
798 %name(PreHtmlWindow)wxPyHtmlWindow();
799
800 bool Create(wxWindow *parent, int id = -1,
801 const wxPoint& pos = wxDefaultPosition,
802 const wxSize& size = wxDefaultSize,
803 int style=wxHW_SCROLLBAR_AUTO,
804 const wxString& name = wxPyHtmlWindowNameStr);
805
806
807 void _setCallbackInfo(PyObject* self, PyObject* _class);
808
809
810 // Set HTML page and display it. !! source is HTML document itself,
811 // it is NOT address/filename of HTML document. If you want to
812 // specify document location, use LoadPage() istead
813 // Return value : False if an error occured, True otherwise
814 bool SetPage(const wxString& source);
815
816 // Load HTML page from given location. Location can be either
817 // a) /usr/wxGTK2/docs/html/wx.htm
818 // b) http://www.somewhere.uk/document.htm
819 // c) ftp://ftp.somesite.cz/pub/something.htm
820 // In case there is no prefix (http:,ftp:), the method
821 // will try to find it itself (1. local file, then http or ftp)
822 // After the page is loaded, the method calls SetPage() to display it.
823 // Note : you can also use path relative to previously loaded page
824 // Return value : same as SetPage
825 bool LoadPage(const wxString& location);
826
827 // Loads HTML page from file
828 bool LoadFile(const wxString& filename);
829
830 // Append to current page
831 bool AppendToPage(const wxString& source);
832
833 // Returns full location of opened page
834 wxString GetOpenedPage();
835
836 // Returns anchor within opened page
837 wxString GetOpenedAnchor();
838
839 // Returns <TITLE> of opened page or empty string otherwise
840 wxString GetOpenedPageTitle();
841
842 // Sets frame in which page title will be displayed. Format is format of
843 // frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s
844 void SetRelatedFrame(wxFrame* frame, const wxString& format);
845 wxFrame* GetRelatedFrame();
846
847 // After(!) calling SetRelatedFrame, this sets statusbar slot where messages
848 // will be displayed. Default is -1 = no messages.
849 void SetRelatedStatusBar(int bar);
850
851 // Sets fonts to be used when displaying HTML page.
852 %extend {
853 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
854 int* temp = NULL;
855 if (sizes) temp = int_LIST_helper(sizes);
856 self->SetFonts(normal_face, fixed_face, temp);
857 if (temp)
858 delete [] temp;
859 }
860 }
861
862 DocDeclStr(
863 void, SetTitle(const wxString& title),
864 "", "");
865
866 // Sets space between text and window borders.
867 void SetBorders(int b);
868
869 // Saves custom settings into cfg config. it will use the path 'path'
870 // if given, otherwise it will save info into currently selected path.
871 // saved values : things set by SetFonts, SetBorders.
872 void ReadCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
873 void WriteCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
874
875 // Goes to previous/next page (in browsing history)
876 // Returns True if successful, False otherwise
877 bool HistoryBack();
878 bool HistoryForward();
879 bool HistoryCanBack();
880 bool HistoryCanForward();
881
882 // Resets History
883 void HistoryClear();
884
885 // Returns pointer to conteiners/cells structure.
886 wxHtmlContainerCell* GetInternalRepresentation();
887
888 // Returns a pointer to the parser.
889 wxHtmlWinParser* GetParser();
890
891 bool ScrollToAnchor(const wxString& anchor);
892 bool HasAnchor(const wxString& anchor);
893
894 //Adds input filter
895 static void AddFilter(wxPyHtmlFilter *filter);
896
897 // Helper functions to select parts of page:
898 void SelectWord(const wxPoint& pos);
899 void SelectLine(const wxPoint& pos);
900 void SelectAll();
901
902
903 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
904 void base_OnSetTitle(const wxString& title);
905 void base_OnCellMouseHover(wxHtmlCell *cell, wxCoord x, wxCoord y);
906 void base_OnCellClicked(wxHtmlCell *cell,
907 wxCoord x, wxCoord y,
908 const wxMouseEvent& event);
909
910 static wxVisualAttributes
911 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
912 };
913
914
915
916
917 //---------------------------------------------------------------------------
918 //---------------------------------------------------------------------------
919 %newgroup
920
921
922 class wxHtmlDCRenderer : public wxObject {
923 public:
924 wxHtmlDCRenderer();
925 ~wxHtmlDCRenderer();
926
927 void SetDC(wxDC *dc, int maxwidth);
928 void SetSize(int width, int height);
929 void SetHtmlText(const wxString& html,
930 const wxString& basepath = wxPyEmptyString,
931 bool isdir = True);
932 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
933 %extend {
934 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
935 int* temp = NULL;
936 if (sizes) temp = int_LIST_helper(sizes);
937 self->SetFonts(normal_face, fixed_face, temp);
938 if (temp)
939 delete [] temp;
940 }
941 }
942 int Render(int x, int y, int from = 0, int dont_render = False, int to = INT_MAX,
943 //int *known_pagebreaks = NULL, int number_of_pages = 0
944 int* choices=NULL, int LCOUNT = 0
945 );
946 int GetTotalHeight();
947 // returns total height of the html document
948 // (compare Render's return value with this)
949 };
950
951
952 enum {
953 wxPAGE_ODD,
954 wxPAGE_EVEN,
955 wxPAGE_ALL
956 };
957
958
959 class wxHtmlPrintout : public wxPyPrintout {
960 public:
961 wxHtmlPrintout(const wxString& title = wxPyHtmlPrintoutTitleStr);
962 //~wxHtmlPrintout(); wxPrintPreview object takes ownership...
963
964 void SetHtmlText(const wxString& html,
965 const wxString &basepath = wxPyEmptyString,
966 bool isdir = True);
967 void SetHtmlFile(const wxString &htmlfile);
968 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
969 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
970
971 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
972 %extend {
973 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
974 int* temp = NULL;
975 if (sizes) temp = int_LIST_helper(sizes);
976 self->SetFonts(normal_face, fixed_face, temp);
977 if (temp)
978 delete [] temp;
979 }
980 }
981 void SetMargins(float top = 25.2, float bottom = 25.2,
982 float left = 25.2, float right = 25.2,
983 float spaces = 5);
984
985 // Adds input filter
986 static void AddFilter(wxHtmlFilter *filter);
987
988 // Cleanup
989 static void CleanUpStatics();
990 };
991
992
993
994 class wxHtmlEasyPrinting : public wxObject {
995 public:
996 wxHtmlEasyPrinting(const wxString& name = wxPyHtmlPrintingTitleStr,
997 wxWindow *parentWindow = NULL);
998 ~wxHtmlEasyPrinting();
999
1000 void PreviewFile(const wxString &htmlfile);
1001 void PreviewText(const wxString &htmltext, const wxString& basepath = wxPyEmptyString);
1002 void PrintFile(const wxString &htmlfile);
1003 void PrintText(const wxString &htmltext, const wxString& basepath = wxPyEmptyString);
1004 void PrinterSetup();
1005 void PageSetup();
1006 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
1007 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
1008
1009 %extend {
1010 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
1011 int* temp = NULL;
1012 if (sizes) temp = int_LIST_helper(sizes);
1013 self->SetFonts(normal_face, fixed_face, temp);
1014 if (temp)
1015 delete [] temp;
1016 }
1017 }
1018
1019 wxPrintData *GetPrintData() {return m_PrintData;}
1020 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
1021
1022 };
1023
1024
1025 //---------------------------------------------------------------------------
1026 //---------------------------------------------------------------------------
1027 %newgroup
1028
1029
1030 class wxHtmlBookRecord {
1031 public:
1032 wxHtmlBookRecord(const wxString& bookfile, const wxString& basepath,
1033 const wxString& title, const wxString& start);
1034
1035 wxString GetBookFile();
1036 wxString GetTitle();
1037 wxString GetStart();
1038 wxString GetBasePath();
1039
1040 void SetContentsRange(int start, int end);
1041 int GetContentsStart();
1042 int GetContentsEnd();
1043
1044 void SetTitle(const wxString& title);
1045 void SetBasePath(const wxString& path);
1046 void SetStart(const wxString& start);
1047
1048 wxString GetFullPath(const wxString &page) const;
1049 };
1050
1051 //---------------------------------------------------------------------------
1052
1053 struct wxHtmlContentsItem
1054 {
1055 %extend {
1056 int GetLevel() { return self->m_Level; }
1057 int GetID() { return self->m_ID; }
1058 wxString GetName() { return self->m_Name; }
1059 wxString GetPage() { return self->m_Page; }
1060 wxHtmlBookRecord* GetBook() { return self->m_Book; }
1061 }
1062 };
1063
1064 //---------------------------------------------------------------------------
1065
1066 class wxHtmlSearchStatus
1067 {
1068 public:
1069 //wxHtmlSearchStatus(wxHtmlHelpData* base, const wxString& keyword,
1070 // const wxString& book = wxPyEmptyString);
1071 bool Search();
1072 bool IsActive();
1073 int GetCurIndex();
1074 int GetMaxIndex();
1075 const wxString& GetName();
1076 wxHtmlContentsItem* GetContentsItem();
1077 };
1078
1079 //---------------------------------------------------------------------------
1080
1081 class wxHtmlHelpData {
1082 public:
1083 wxHtmlHelpData();
1084 ~wxHtmlHelpData();
1085
1086 void SetTempDir(const wxString& path);
1087 bool AddBook(const wxString& book);
1088 // bool AddBookParam(const wxString& title, const wxString& contfile,
1089 // const wxString& indexfile=wxPyEmptyString,
1090 // const wxString& deftopic=wxPyEmptyString,
1091 // const wxString& path=wxPyEmptyString);
1092
1093 wxString FindPageByName(const wxString& page);
1094 wxString FindPageById(int id);
1095
1096 // TODO: this one needs fixed...
1097 const wxHtmlBookRecArray& GetBookRecArray();
1098
1099 wxHtmlContentsItem* GetContents();
1100 int GetContentsCnt();
1101 wxHtmlContentsItem* GetIndex();
1102 int GetIndexCnt();
1103 };
1104
1105 //---------------------------------------------------------------------------
1106
1107 class wxHtmlHelpFrame : public wxFrame {
1108 public:
1109 %pythonAppend wxHtmlHelpFrame "self._setOORInfo(self)"
1110
1111 wxHtmlHelpFrame(wxWindow* parent, int wxWindowID,
1112 const wxString& title = wxPyEmptyString,
1113 int style = wxHF_DEFAULTSTYLE, wxHtmlHelpData* data = NULL);
1114
1115 wxHtmlHelpData* GetData();
1116 void SetTitleFormat(const wxString& format);
1117 void Display(const wxString& x);
1118 %name(DisplayID) void Display(int id);
1119 void DisplayContents();
1120 void DisplayIndex();
1121 bool KeywordSearch(const wxString& keyword);
1122 void UseConfig(wxConfigBase *config, const wxString& rootpath = wxPyEmptyString);
1123 void ReadCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
1124 void WriteCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
1125 };
1126
1127
1128 //---------------------------------------------------------------------------
1129
1130
1131 enum {
1132 wxHF_TOOLBAR,
1133 wxHF_FLATTOOLBAR,
1134 wxHF_CONTENTS,
1135 wxHF_INDEX,
1136 wxHF_SEARCH,
1137 wxHF_BOOKMARKS,
1138 wxHF_OPENFILES,
1139 wxHF_PRINT,
1140 wxHF_DEFAULTSTYLE,
1141 };
1142
1143
1144 class wxHtmlHelpController : public wxEvtHandler {
1145 public:
1146 %pythonAppend wxHtmlHelpController "self._setOORInfo(self)"
1147
1148 wxHtmlHelpController(int style = wxHF_DEFAULTSTYLE);
1149 ~wxHtmlHelpController();
1150
1151 void SetTitleFormat(const wxString& format);
1152 void SetTempDir(const wxString& path);
1153 bool AddBook(const wxString& book, int show_wait_msg = False);
1154 void Display(const wxString& x);
1155 %name(DisplayID) void Display(int id);
1156 void DisplayContents();
1157 void DisplayIndex();
1158 bool KeywordSearch(const wxString& keyword);
1159 void UseConfig(wxConfigBase *config, const wxString& rootpath = wxPyEmptyString);
1160 void ReadCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
1161 void WriteCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
1162 wxHtmlHelpFrame* GetFrame();
1163 };
1164
1165
1166
1167
1168 //---------------------------------------------------------------------------
1169 %init %{
1170 wxPyPtrTypeMap_Add("wxHtmlTagHandler", "wxPyHtmlTagHandler");
1171 wxPyPtrTypeMap_Add("wxHtmlWinTagHandler", "wxPyHtmlWinTagHandler");
1172 wxPyPtrTypeMap_Add("wxHtmlWindow", "wxPyHtmlWindow");
1173 wxPyPtrTypeMap_Add("wxHtmlFilter", "wxPyHtmlFilter");
1174 %}
1175 //---------------------------------------------------------------------------
1176 //---------------------------------------------------------------------------
1177
1178
1179