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