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