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