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