]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/html.i
Use a panel
[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 bool blocked = 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(blocked);
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 bool blocked = 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(blocked);
338 return;
339 }
340 wxPyEndBlockThreads(blocked);
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
491 // Returns the maximum possible length of the cell.
492 // Call Layout at least once before using GetMaxTotalWidth()
493 int GetMaxTotalWidth() const;
494
495 const wxString& GetId() const;
496 void SetId(const wxString& id);
497 wxHtmlLinkInfo* GetLink(int x = 0, int y = 0);
498 wxHtmlCell* GetNext();
499 wxHtmlContainerCell* GetParent();
500 wxHtmlCell* GetFirstChild() const;
501
502 // Returns cursor to be used when mouse is over the cell:
503 wxCursor GetCursor() const;
504
505 // Formatting cells are not visible on the screen, they only alter
506 // renderer's state.
507 bool IsFormattingCell() const;
508
509
510 void SetLink(const wxHtmlLinkInfo& link);
511 void SetNext(wxHtmlCell *cell);
512 void SetParent(wxHtmlContainerCell *p);
513 void SetPos(int x, int y);
514 void Layout(int w);
515 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
516 wxHtmlRenderingInfo& info);
517 void DrawInvisible(wxDC& dc, int x, int y,
518 wxHtmlRenderingInfo& info);
519 const wxHtmlCell* Find(int condition, const void* param);
520
521 bool AdjustPagebreak(int* INOUT);
522 void SetCanLiveOnPagebreak(bool can);
523
524 // Can the line be broken before this cell?
525 bool IsLinebreakAllowed() const;
526
527 // Returns True for simple == terminal cells, i.e. not composite ones.
528 // This if for internal usage only and may disappear in future versions!
529 bool IsTerminalCell() const;
530
531 // Find a cell inside this cell positioned at the given coordinates
532 // (relative to this's positions). Returns NULL if no such cell exists.
533 // The flag can be used to specify whether to look for terminal or
534 // nonterminal cells or both. In either case, returned cell is deepest
535 // cell in cells tree that contains [x,y].
536 wxHtmlCell *FindCellByPos(wxCoord x, wxCoord y,
537 unsigned flags = wxHTML_FIND_EXACT) const;
538
539 // Returns absolute position of the cell on HTML canvas
540 wxPoint GetAbsPos() const;
541
542 // Returns first (last) terminal cell inside this cell. It may return NULL,
543 // but it is rare -- only if there are no terminals in the tree.
544 wxHtmlCell *GetFirstTerminal() const ;
545 wxHtmlCell *GetLastTerminal() const ;
546
547 // Returns cell's depth, i.e. how far under the root cell it is
548 // (if it is the root, depth is 0)
549 unsigned GetDepth() const;
550
551 // Returns True if the cell appears before 'cell' in natural order of
552 // cells (= as they are read). If cell A is (grand)parent of cell B,
553 // then both A.IsBefore(B) and B.IsBefore(A) always return True.
554 bool IsBefore(wxHtmlCell *cell) const;
555
556 // Converts the cell into text representation. If sel != NULL then
557 // only part of the cell inside the selection is converted.
558 wxString ConvertToText(wxHtmlSelection *sel) const;
559 };
560
561
562 class wxHtmlWordCell : public wxHtmlCell
563 {
564 public:
565 wxHtmlWordCell(const wxString& word, wxDC& dc);
566 };
567
568
569 class wxHtmlContainerCell : public wxHtmlCell {
570 public:
571 wxHtmlContainerCell(wxHtmlContainerCell *parent);
572
573 void InsertCell(wxHtmlCell *cell);
574 void SetAlignHor(int al);
575 int GetAlignHor();
576 void SetAlignVer(int al);
577 int GetAlignVer();
578 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
579 int GetIndent(int ind);
580 int GetIndentUnits(int ind);
581 void SetAlign(const wxHtmlTag& tag);
582 void SetWidthFloat(int w, int units);
583 %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
584 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
585 void SetBackgroundColour(const wxColour& clr);
586 wxColour GetBackgroundColour();
587 void SetBorder(const wxColour& clr1, const wxColour& clr2);
588 wxHtmlCell* GetFirstChild();
589 %pragma(python) addtoclass = "GetFirstCell = GetFirstChild"
590 };
591
592
593
594 class wxHtmlColourCell : public wxHtmlCell {
595 public:
596 wxHtmlColourCell(wxColour clr, int flags = wxHTML_CLR_FOREGROUND);
597
598 };
599
600
601 class wxHtmlFontCell : public wxHtmlCell
602 {
603 public:
604 wxHtmlFontCell(wxFont *font);
605 };
606
607
608 class wxHtmlWidgetCell : public wxHtmlCell {
609 public:
610 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
611
612 };
613
614
615
616
617 //---------------------------------------------------------------------------
618 // wxHtmlFilter
619 //---------------------------------------------------------------------------
620 %newgroup
621
622
623 %{ // here's the C++ version
624 class wxPyHtmlFilter : public wxHtmlFilter {
625 DECLARE_ABSTRACT_CLASS(wxPyHtmlFilter);
626 public:
627 wxPyHtmlFilter() : wxHtmlFilter() {}
628
629 // returns True if this filter is able to open&read given file
630 virtual bool CanRead(const wxFSFile& file) const {
631 bool rval = False;
632 bool found;
633 bool blocked = wxPyBeginBlockThreads();
634 if ((found = wxPyCBH_findCallback(m_myInst, "CanRead"))) {
635 PyObject* obj = wxPyMake_wxObject((wxFSFile*)&file); // cast away const
636 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj));
637 Py_DECREF(obj);
638 }
639 wxPyEndBlockThreads(blocked);
640 return rval;
641 }
642
643
644 // Reads given file and returns HTML document.
645 // Returns empty string if opening failed
646 virtual wxString ReadFile(const wxFSFile& file) const {
647 wxString rval;
648 bool found;
649 bool blocked = wxPyBeginBlockThreads();
650 if ((found = wxPyCBH_findCallback(m_myInst, "ReadFile"))) {
651 PyObject* obj = wxPyMake_wxObject((wxFSFile*)&file); // cast away const
652 PyObject* ro;
653 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(O)", obj));
654 Py_DECREF(obj);
655 if (ro) {
656 rval = Py2wxString(ro);
657 Py_DECREF(ro);
658 }
659 }
660 wxPyEndBlockThreads(blocked);
661 return rval;
662 }
663
664 PYPRIVATE;
665 };
666
667 IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlFilter, wxHtmlFilter);
668 %}
669
670
671 // And now the version seen by SWIG
672
673 %name(HtmlFilter) class wxPyHtmlFilter : public wxObject {
674 public:
675 %pythonAppend wxPyHtmlFilter "self._setCallbackInfo(self, HtmlFilter)"
676 wxPyHtmlFilter();
677
678 void _setCallbackInfo(PyObject* self, PyObject* _class);
679 };
680
681
682 // TODO: wxHtmlFilterHTML
683
684
685 //---------------------------------------------------------------------------
686 // wxHtmlWindow
687 //---------------------------------------------------------------------------
688 %newgroup
689
690 %{
691 class wxPyHtmlWindow : public wxHtmlWindow {
692 DECLARE_ABSTRACT_CLASS(wxPyHtmlWindow);
693 public:
694 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
695 const wxPoint& pos = wxDefaultPosition,
696 const wxSize& size = wxDefaultSize,
697 long style = wxHW_DEFAULT_STYLE,
698 const wxString& name = wxPyHtmlWindowNameStr)
699 : wxHtmlWindow(parent, id, pos, size, style, name) {};
700 wxPyHtmlWindow() : wxHtmlWindow() {};
701
702 bool ScrollToAnchor(const wxString& anchor) {
703 return wxHtmlWindow::ScrollToAnchor(anchor);
704 }
705
706 bool HasAnchor(const wxString& anchor) {
707 const wxHtmlCell *c = m_Cell->Find(wxHTML_COND_ISANCHOR, &anchor);
708 return c!=NULL;
709 }
710
711 void OnLinkClicked(const wxHtmlLinkInfo& link);
712 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
713
714 wxHtmlOpeningStatus OnOpeningURL(wxHtmlURLType type,
715 const wxString& url,
716 wxString *redirect) const;
717
718 DEC_PYCALLBACK__STRING(OnSetTitle);
719 DEC_PYCALLBACK__CELLINTINT(OnCellMouseHover);
720 DEC_PYCALLBACK__CELLINTINTME(OnCellClicked);
721 PYPRIVATE;
722 };
723
724 IMPLEMENT_ABSTRACT_CLASS( wxPyHtmlWindow, wxHtmlWindow );
725 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
726 IMP_PYCALLBACK__CELLINTINT(wxPyHtmlWindow, wxHtmlWindow, OnCellMouseHover);
727 IMP_PYCALLBACK__CELLINTINTME(wxPyHtmlWindow, wxHtmlWindow, OnCellClicked);
728
729
730 void wxPyHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) {
731 bool found;
732 bool blocked = wxPyBeginBlockThreads();
733 if ((found = wxPyCBH_findCallback(m_myInst, "OnLinkClicked"))) {
734 PyObject* obj = wxPyConstructObject((void*)&link, wxT("wxHtmlLinkInfo"), 0);
735 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj));
736 Py_DECREF(obj);
737 }
738 wxPyEndBlockThreads(blocked);
739 if (! found)
740 wxHtmlWindow::OnLinkClicked(link);
741 }
742 void wxPyHtmlWindow::base_OnLinkClicked(const wxHtmlLinkInfo& link) {
743 wxHtmlWindow::OnLinkClicked(link);
744 }
745
746
747 wxHtmlOpeningStatus wxPyHtmlWindow::OnOpeningURL(wxHtmlURLType type,
748 const wxString& url,
749 wxString *redirect) const {
750 bool found;
751 wxHtmlOpeningStatus rval;
752 bool blocked = wxPyBeginBlockThreads();
753 if ((found = wxPyCBH_findCallback(m_myInst, "OnOpeningURL"))) {
754 PyObject* ro;
755 PyObject* s = wx2PyString(url);
756 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iO)", type, s));
757 Py_DECREF(s);
758 if (PyString_Check(ro)
759 #if PYTHON_API_VERSION >= 1009
760 || PyUnicode_Check(ro)
761 #endif
762 ) {
763 *redirect = Py2wxString(ro);
764 rval = wxHTML_REDIRECT;
765 }
766 else {
767 PyObject* num = PyNumber_Int(ro);
768 rval = (wxHtmlOpeningStatus)PyInt_AsLong(num);
769 Py_DECREF(num);
770 }
771 Py_DECREF(ro);
772 }
773 wxPyEndBlockThreads(blocked);
774 if (! found)
775 rval = wxHtmlWindow::OnOpeningURL(type, url, redirect);
776 return rval;
777 }
778
779
780 %}
781
782
783
784 %name(HtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
785 public:
786 %pythonAppend wxPyHtmlWindow "self._setCallbackInfo(self, HtmlWindow); self._setOORInfo(self)"
787 %pythonAppend wxPyHtmlWindow() ""
788
789 wxPyHtmlWindow(wxWindow *parent, int id = -1,
790 const wxPoint& pos = wxDefaultPosition,
791 const wxSize& size = wxDefaultSize,
792 int style=wxHW_DEFAULT_STYLE,
793 const wxString& name = wxPyHtmlWindowNameStr);
794 %name(PreHtmlWindow)wxPyHtmlWindow();
795
796 bool Create(wxWindow *parent, int id = -1,
797 const wxPoint& pos = wxDefaultPosition,
798 const wxSize& size = wxDefaultSize,
799 int style=wxHW_SCROLLBAR_AUTO,
800 const wxString& name = wxPyHtmlWindowNameStr);
801
802
803 void _setCallbackInfo(PyObject* self, PyObject* _class);
804
805
806 // Set HTML page and display it. !! source is HTML document itself,
807 // it is NOT address/filename of HTML document. If you want to
808 // specify document location, use LoadPage() istead
809 // Return value : False if an error occured, True otherwise
810 bool SetPage(const wxString& source);
811
812 // Load HTML page from given location. Location can be either
813 // a) /usr/wxGTK2/docs/html/wx.htm
814 // b) http://www.somewhere.uk/document.htm
815 // c) ftp://ftp.somesite.cz/pub/something.htm
816 // In case there is no prefix (http:,ftp:), the method
817 // will try to find it itself (1. local file, then http or ftp)
818 // After the page is loaded, the method calls SetPage() to display it.
819 // Note : you can also use path relative to previously loaded page
820 // Return value : same as SetPage
821 bool LoadPage(const wxString& location);
822
823 // Loads HTML page from file
824 bool LoadFile(const wxString& filename);
825
826 // Append to current page
827 bool AppendToPage(const wxString& source);
828
829 // Returns full location of opened page
830 wxString GetOpenedPage();
831
832 // Returns anchor within opened page
833 wxString GetOpenedAnchor();
834
835 // Returns <TITLE> of opened page or empty string otherwise
836 wxString GetOpenedPageTitle();
837
838 // Sets frame in which page title will be displayed. Format is format of
839 // frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s
840 void SetRelatedFrame(wxFrame* frame, const wxString& format);
841 wxFrame* GetRelatedFrame();
842
843 // After(!) calling SetRelatedFrame, this sets statusbar slot where messages
844 // will be displayed. Default is -1 = no messages.
845 void SetRelatedStatusBar(int bar);
846
847 // Sets fonts to be used when displaying HTML page.
848 %extend {
849 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
850 int* temp = NULL;
851 if (sizes) temp = int_LIST_helper(sizes);
852 self->SetFonts(normal_face, fixed_face, temp);
853 if (temp)
854 delete [] temp;
855 }
856 }
857
858 DocDeclStr(
859 void, SetTitle(const wxString& title),
860 "");
861
862 // Sets space between text and window borders.
863 void SetBorders(int b);
864
865 // Saves custom settings into cfg config. it will use the path 'path'
866 // if given, otherwise it will save info into currently selected path.
867 // saved values : things set by SetFonts, SetBorders.
868 void ReadCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
869 void WriteCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
870
871 // Goes to previous/next page (in browsing history)
872 // Returns True if successful, False otherwise
873 bool HistoryBack();
874 bool HistoryForward();
875 bool HistoryCanBack();
876 bool HistoryCanForward();
877
878 // Resets History
879 void HistoryClear();
880
881 // Returns pointer to conteiners/cells structure.
882 wxHtmlContainerCell* GetInternalRepresentation();
883
884 // Returns a pointer to the parser.
885 wxHtmlWinParser* GetParser();
886
887 bool ScrollToAnchor(const wxString& anchor);
888 bool HasAnchor(const wxString& anchor);
889
890 //Adds input filter
891 static void AddFilter(wxPyHtmlFilter *filter);
892
893 // Helper functions to select parts of page:
894 void SelectWord(const wxPoint& pos);
895 void SelectLine(const wxPoint& pos);
896 void SelectAll();
897
898
899 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
900 void base_OnSetTitle(const wxString& title);
901 void base_OnCellMouseHover(wxHtmlCell *cell, wxCoord x, wxCoord y);
902 void base_OnCellClicked(wxHtmlCell *cell,
903 wxCoord x, wxCoord y,
904 const wxMouseEvent& event);
905 };
906
907
908
909
910 //---------------------------------------------------------------------------
911 //---------------------------------------------------------------------------
912 %newgroup
913
914
915 class wxHtmlDCRenderer : public wxObject {
916 public:
917 wxHtmlDCRenderer();
918 ~wxHtmlDCRenderer();
919
920 void SetDC(wxDC *dc, int maxwidth);
921 void SetSize(int width, int height);
922 void SetHtmlText(const wxString& html,
923 const wxString& basepath = wxPyEmptyString,
924 bool isdir = True);
925 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
926 %extend {
927 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
928 int* temp = NULL;
929 if (sizes) temp = int_LIST_helper(sizes);
930 self->SetFonts(normal_face, fixed_face, temp);
931 if (temp)
932 delete [] temp;
933 }
934 }
935 int Render(int x, int y, int from = 0, int dont_render = False, int to = INT_MAX,
936 //int *known_pagebreaks = NULL, int number_of_pages = 0
937 int* choices=NULL, int LCOUNT = 0
938 );
939 int GetTotalHeight();
940 // returns total height of the html document
941 // (compare Render's return value with this)
942 };
943
944
945 enum {
946 wxPAGE_ODD,
947 wxPAGE_EVEN,
948 wxPAGE_ALL
949 };
950
951
952 class wxHtmlPrintout : public wxPyPrintout {
953 public:
954 wxHtmlPrintout(const wxString& title = wxPyHtmlPrintoutTitleStr);
955 //~wxHtmlPrintout(); wxPrintPreview object takes ownership...
956
957 void SetHtmlText(const wxString& html,
958 const wxString &basepath = wxPyEmptyString,
959 bool isdir = True);
960 void SetHtmlFile(const wxString &htmlfile);
961 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
962 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
963
964 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
965 %extend {
966 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
967 int* temp = NULL;
968 if (sizes) temp = int_LIST_helper(sizes);
969 self->SetFonts(normal_face, fixed_face, temp);
970 if (temp)
971 delete [] temp;
972 }
973 }
974 void SetMargins(float top = 25.2, float bottom = 25.2,
975 float left = 25.2, float right = 25.2,
976 float spaces = 5);
977
978 // Adds input filter
979 static void AddFilter(wxHtmlFilter *filter);
980
981 // Cleanup
982 static void CleanUpStatics();
983 };
984
985
986
987 class wxHtmlEasyPrinting : public wxObject {
988 public:
989 wxHtmlEasyPrinting(const wxString& name = wxPyHtmlPrintingTitleStr,
990 wxWindow *parentWindow = NULL);
991 ~wxHtmlEasyPrinting();
992
993 void PreviewFile(const wxString &htmlfile);
994 void PreviewText(const wxString &htmltext, const wxString& basepath = wxPyEmptyString);
995 void PrintFile(const wxString &htmlfile);
996 void PrintText(const wxString &htmltext, const wxString& basepath = wxPyEmptyString);
997 void PrinterSetup();
998 void PageSetup();
999 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
1000 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
1001
1002 %extend {
1003 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
1004 int* temp = NULL;
1005 if (sizes) temp = int_LIST_helper(sizes);
1006 self->SetFonts(normal_face, fixed_face, temp);
1007 if (temp)
1008 delete [] temp;
1009 }
1010 }
1011
1012 wxPrintData *GetPrintData() {return m_PrintData;}
1013 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
1014
1015 };
1016
1017
1018 //---------------------------------------------------------------------------
1019 //---------------------------------------------------------------------------
1020 %newgroup
1021
1022
1023 class wxHtmlBookRecord {
1024 public:
1025 wxHtmlBookRecord(const wxString& bookfile, const wxString& basepath,
1026 const wxString& title, const wxString& start);
1027
1028 wxString GetBookFile();
1029 wxString GetTitle();
1030 wxString GetStart();
1031 wxString GetBasePath();
1032
1033 void SetContentsRange(int start, int end);
1034 int GetContentsStart();
1035 int GetContentsEnd();
1036
1037 void SetTitle(const wxString& title);
1038 void SetBasePath(const wxString& path);
1039 void SetStart(const wxString& start);
1040
1041 wxString GetFullPath(const wxString &page) const;
1042 };
1043
1044 //---------------------------------------------------------------------------
1045
1046 struct wxHtmlContentsItem
1047 {
1048 %extend {
1049 int GetLevel() { return self->m_Level; }
1050 int GetID() { return self->m_ID; }
1051 wxString GetName() { return self->m_Name; }
1052 wxString GetPage() { return self->m_Page; }
1053 wxHtmlBookRecord* GetBook() { return self->m_Book; }
1054 }
1055 };
1056
1057 //---------------------------------------------------------------------------
1058
1059 class wxHtmlSearchStatus
1060 {
1061 public:
1062 //wxHtmlSearchStatus(wxHtmlHelpData* base, const wxString& keyword,
1063 // const wxString& book = wxPyEmptyString);
1064 bool Search();
1065 bool IsActive();
1066 int GetCurIndex();
1067 int GetMaxIndex();
1068 const wxString& GetName();
1069 wxHtmlContentsItem* GetContentsItem();
1070 };
1071
1072 //---------------------------------------------------------------------------
1073
1074 class wxHtmlHelpData {
1075 public:
1076 wxHtmlHelpData();
1077 ~wxHtmlHelpData();
1078
1079 void SetTempDir(const wxString& path);
1080 bool AddBook(const wxString& book);
1081 // bool AddBookParam(const wxString& title, const wxString& contfile,
1082 // const wxString& indexfile=wxPyEmptyString,
1083 // const wxString& deftopic=wxPyEmptyString,
1084 // const wxString& path=wxPyEmptyString);
1085
1086 wxString FindPageByName(const wxString& page);
1087 wxString FindPageById(int id);
1088
1089 // TODO: this one needs fixed...
1090 const wxHtmlBookRecArray& GetBookRecArray();
1091
1092 wxHtmlContentsItem* GetContents();
1093 int GetContentsCnt();
1094 wxHtmlContentsItem* GetIndex();
1095 int GetIndexCnt();
1096 };
1097
1098 //---------------------------------------------------------------------------
1099
1100 class wxHtmlHelpFrame : public wxFrame {
1101 public:
1102 %pythonAppend wxHtmlHelpFrame "self._setOORInfo(self)"
1103
1104 wxHtmlHelpFrame(wxWindow* parent, int wxWindowID,
1105 const wxString& title = wxPyEmptyString,
1106 int style = wxHF_DEFAULTSTYLE, wxHtmlHelpData* data = NULL);
1107
1108 wxHtmlHelpData* GetData();
1109 void SetTitleFormat(const wxString& format);
1110 void Display(const wxString& x);
1111 %name(DisplayID) void Display(int id);
1112 void DisplayContents();
1113 void DisplayIndex();
1114 bool KeywordSearch(const wxString& keyword);
1115 void UseConfig(wxConfigBase *config, const wxString& rootpath = wxPyEmptyString);
1116 void ReadCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
1117 void WriteCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
1118 };
1119
1120
1121 //---------------------------------------------------------------------------
1122
1123
1124 enum {
1125 wxHF_TOOLBAR,
1126 wxHF_FLATTOOLBAR,
1127 wxHF_CONTENTS,
1128 wxHF_INDEX,
1129 wxHF_SEARCH,
1130 wxHF_BOOKMARKS,
1131 wxHF_OPENFILES,
1132 wxHF_PRINT,
1133 wxHF_DEFAULTSTYLE,
1134 };
1135
1136
1137 class wxHtmlHelpController : public wxEvtHandler {
1138 public:
1139 %pythonAppend wxHtmlHelpController "self._setOORInfo(self)"
1140
1141 wxHtmlHelpController(int style = wxHF_DEFAULTSTYLE);
1142 ~wxHtmlHelpController();
1143
1144 void SetTitleFormat(const wxString& format);
1145 void SetTempDir(const wxString& path);
1146 bool AddBook(const wxString& book, int show_wait_msg = False);
1147 void Display(const wxString& x);
1148 %name(DisplayID) void Display(int id);
1149 void DisplayContents();
1150 void DisplayIndex();
1151 bool KeywordSearch(const wxString& keyword);
1152 void UseConfig(wxConfigBase *config, const wxString& rootpath = wxPyEmptyString);
1153 void ReadCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
1154 void WriteCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
1155 wxHtmlHelpFrame* GetFrame();
1156 };
1157
1158
1159
1160
1161 //---------------------------------------------------------------------------
1162 %init %{
1163 wxPyPtrTypeMap_Add("wxHtmlTagHandler", "wxPyHtmlTagHandler");
1164 wxPyPtrTypeMap_Add("wxHtmlWinTagHandler", "wxPyHtmlWinTagHandler");
1165 wxPyPtrTypeMap_Add("wxHtmlWindow", "wxPyHtmlWindow");
1166 wxPyPtrTypeMap_Add("wxHtmlFilter", "wxPyHtmlFilter");
1167 %}
1168 //---------------------------------------------------------------------------
1169 //---------------------------------------------------------------------------
1170
1171
1172