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