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