]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/html.i
add Create to wxDocParentFrame
[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 #include <wx/html/helpwnd.h>
29 #include <wx/html/helpfrm.h>
30 #include <wx/html/helpdlg.h>
31
32 %}
33
34
35 //---------------------------------------------------------------------------
36
37 %import windows.i
38 %pythoncode { wx = _core }
39 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
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 %newgroup
52
53
54 enum {
55 wxHTML_ALIGN_LEFT,
56 wxHTML_ALIGN_CENTER,
57 wxHTML_ALIGN_RIGHT,
58 wxHTML_ALIGN_BOTTOM,
59 wxHTML_ALIGN_TOP,
60
61 wxHTML_CLR_FOREGROUND,
62 wxHTML_CLR_BACKGROUND,
63
64 wxHTML_UNITS_PIXELS,
65 wxHTML_UNITS_PERCENT,
66
67 wxHTML_INDENT_LEFT,
68 wxHTML_INDENT_RIGHT,
69 wxHTML_INDENT_TOP,
70 wxHTML_INDENT_BOTTOM,
71
72 wxHTML_INDENT_HORIZONTAL,
73 wxHTML_INDENT_VERTICAL,
74 wxHTML_INDENT_ALL,
75
76 wxHTML_COND_ISANCHOR,
77 wxHTML_COND_ISIMAGEMAP,
78 wxHTML_COND_USER,
79
80 };
81
82
83 enum {
84 wxHW_SCROLLBAR_NEVER,
85 wxHW_SCROLLBAR_AUTO,
86 wxHW_NO_SELECTION,
87 wxHW_DEFAULT_STYLE,
88 };
89
90
91 // enums for wxHtmlWindow::OnOpeningURL
92 enum wxHtmlOpeningStatus
93 {
94 wxHTML_OPEN,
95 wxHTML_BLOCK,
96 wxHTML_REDIRECT
97 };
98
99 enum wxHtmlURLType
100 {
101 wxHTML_URL_PAGE,
102 wxHTML_URL_IMAGE,
103 wxHTML_URL_OTHER
104 };
105
106
107
108 //---------------------------------------------------------------------------
109
110 class wxHtmlLinkInfo : public wxObject {
111 public:
112 wxHtmlLinkInfo(const wxString& href, const wxString& target = wxPyEmptyString);
113 wxString GetHref();
114 wxString GetTarget();
115 wxMouseEvent* GetEvent();
116 wxHtmlCell* GetHtmlCell();
117
118 void SetEvent(const wxMouseEvent *e);
119 void SetHtmlCell(const wxHtmlCell * e);
120 };
121
122 //---------------------------------------------------------------------------
123
124 class wxHtmlTag : public wxObject {
125 public:
126 // Never need to create a new tag from Python...
127 //wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
128
129 wxString GetName();
130 bool HasParam(const wxString& par);
131 wxString GetParam(const wxString& par, int with_commas = false);
132
133 // Can't do this one as-is, but GetParam should be enough...
134 //int ScanParam(const wxString& par, const char *format, void* param);
135
136 wxString GetAllParams();
137 bool HasEnding();
138 int GetBeginPos();
139 int GetEndPos1();
140 int GetEndPos2();
141 };
142
143 //---------------------------------------------------------------------------
144
145 class wxHtmlParser : public wxObject {
146 public:
147 // wxHtmlParser(); This is an abstract base class...
148
149 void SetFS(wxFileSystem *fs);
150 wxFileSystem* GetFS();
151 wxObject* Parse(const wxString& source);
152 void InitParser(const wxString& source);
153 void DoneParser();
154 void DoParsing(int begin_pos, int end_pos);
155 void StopParsing();
156 // wxObject* GetProduct();
157
158 void AddTagHandler(wxHtmlTagHandler *handler);
159 wxString* GetSource();
160 void PushTagHandler(wxHtmlTagHandler* handler, wxString tags);
161 void PopTagHandler();
162
163 // virtual wxFSFile *OpenURL(wxHtmlURLType type, const wxString& url) const;
164
165 // void AddText(const char* txt) = 0;
166 // void AddTag(const wxHtmlTag& tag);
167
168
169 // Returns HTML source inside the element (i.e. between the starting
170 // and ending tag)
171 wxString GetInnerSource(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 %pythoncode { GetWindow = wx._deprecated(GetWindow) }
187
188 wxHtmlWindowInterface *GetWindowInterface();
189
190 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
191 %extend {
192 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
193 int* temp = NULL;
194 if (sizes) temp = int_LIST_helper(sizes);
195 self->SetFonts(normal_face, fixed_face, temp);
196 if (temp)
197 delete [] temp;
198 }
199 }
200
201 // Sets font sizes to be relative to the given size or the system
202 // default size; use either specified or default font
203 void SetStandardFonts(int size = -1,
204 const wxString& normal_face = wxPyEmptyString,
205 const wxString& fixed_face = wxPyEmptyString);
206
207
208 wxHtmlContainerCell* GetContainer();
209 wxHtmlContainerCell* OpenContainer();
210 wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
211 wxHtmlContainerCell* CloseContainer();
212
213 int GetFontSize();
214 void SetFontSize(int s);
215 int GetFontBold();
216 void SetFontBold(int x);
217 int GetFontItalic();
218 void SetFontItalic(int x);
219 int GetFontUnderlined();
220 void SetFontUnderlined(int x);
221 int GetFontFixed();
222 void SetFontFixed(int x);
223 int GetAlign();
224 void SetAlign(int a);
225 wxColour GetLinkColor();
226 void SetLinkColor(const wxColour& clr);
227 wxColour GetActualColor();
228 void SetActualColor(const wxColour& clr);
229 %pythoncode {
230 GetActualColour = GetActualColor
231 SetActualColour = SetActualColor
232 }
233 void SetLink(const wxString& link);
234 wxFont* CreateCurrentFont();
235 wxHtmlLinkInfo GetLink();
236
237 };
238
239
240 //---------------------------------------------------------------------------
241
242 %{
243 class wxPyHtmlTagHandler : public wxHtmlTagHandler {
244 DECLARE_DYNAMIC_CLASS(wxPyHtmlTagHandler)
245 public:
246 wxPyHtmlTagHandler() : wxHtmlTagHandler() {};
247
248 wxHtmlParser* GetParser() { return m_Parser; }
249 void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); }
250
251 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
252 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
253
254 PYPRIVATE;
255 };
256
257 IMPLEMENT_DYNAMIC_CLASS(wxPyHtmlTagHandler, wxHtmlTagHandler);
258
259 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
260 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
261 %}
262
263
264 %rename(HtmlTagHandler) wxPyHtmlTagHandler;
265 class wxPyHtmlTagHandler : public wxObject {
266 public:
267 %pythonAppend wxPyHtmlTagHandler "self._setCallbackInfo(self, HtmlTagHandler)"
268 wxPyHtmlTagHandler();
269
270 void _setCallbackInfo(PyObject* self, PyObject* _class);
271
272 void SetParser(wxHtmlParser *parser);
273 wxHtmlParser* GetParser();
274 void ParseInner(const wxHtmlTag& tag);
275 };
276
277
278 //---------------------------------------------------------------------------
279
280 %{
281 class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
282 DECLARE_DYNAMIC_CLASS(wxPyHtmlWinTagHandler)
283 public:
284 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
285
286 wxHtmlWinParser* GetParser() { return m_WParser; }
287 void ParseInner(const wxHtmlTag& tag)
288 { wxHtmlWinTagHandler::ParseInner(tag); }
289
290 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
291 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
292
293 PYPRIVATE;
294 };
295
296 IMPLEMENT_DYNAMIC_CLASS( wxPyHtmlWinTagHandler, wxHtmlWinTagHandler);
297
298 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
299 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
300 %}
301
302
303 %rename(HtmlWinTagHandler) wxPyHtmlWinTagHandler;
304 class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
305 public:
306 %pythonAppend wxPyHtmlWinTagHandler "self._setCallbackInfo(self, HtmlWinTagHandler)"
307 wxPyHtmlWinTagHandler();
308
309 void _setCallbackInfo(PyObject* self, PyObject* _class);
310
311 void SetParser(wxHtmlParser *parser);
312 wxHtmlWinParser* GetParser();
313 void ParseInner(const wxHtmlTag& tag);
314 };
315
316
317 //---------------------------------------------------------------------------
318
319 %{
320
321 class wxPyHtmlTagsModule : public wxHtmlTagsModule {
322 public:
323 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
324 m_tagHandlerClass = thc;
325 Py_INCREF(m_tagHandlerClass);
326 RegisterModule(this);
327 wxHtmlWinParser::AddModule(this);
328 }
329
330 void OnExit() {
331 wxPyBlock_t blocked = wxPyBeginBlockThreads();
332 Py_DECREF(m_tagHandlerClass);
333 m_tagHandlerClass = NULL;
334 for (size_t x=0; x < m_objArray.GetCount(); x++) {
335 PyObject* obj = (PyObject*)m_objArray.Item(x);
336 Py_DECREF(obj);
337 }
338 wxPyEndBlockThreads(blocked);
339 };
340
341 void FillHandlersTable(wxHtmlWinParser *parser) {
342 // Wave our magic wand... (if it works it's a miracle! ;-)
343
344 // First, make a new instance of the tag handler
345 wxPyBlock_t blocked = wxPyBeginBlockThreads();
346 PyObject* arg = PyTuple_New(0);
347 PyObject* obj = PyObject_CallObject(m_tagHandlerClass, arg);
348 Py_DECREF(arg);
349
350 // now figure out where it's C++ object is...
351 wxPyHtmlWinTagHandler* thPtr;
352 if (! wxPyConvertSwigPtr(obj, (void **)&thPtr, wxT("wxPyHtmlWinTagHandler"))) {
353 wxPyEndBlockThreads(blocked);
354 return;
355 }
356 wxPyEndBlockThreads(blocked);
357
358 // add it,
359 parser->AddTagHandler(thPtr);
360
361 // and track it.
362 m_objArray.Add(obj);
363 }
364
365 private:
366 PyObject* m_tagHandlerClass;
367 wxArrayPtrVoid m_objArray;
368
369 };
370 %}
371
372
373
374 %inline %{
375 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
376 // Dynamically create a new wxModule. Refcounts tagHandlerClass
377 // and adds itself to the wxModules list and to the wxHtmlWinParser.
378 new wxPyHtmlTagsModule(tagHandlerClass);
379 }
380 %}
381
382
383 //---------------------------------------------------------------------------
384
385 %typemap(out) wxHtmlCell* { $result = wxPyMake_wxObject($1, $owner); }
386 %typemap(out) const wxHtmlCell* { $result = wxPyMake_wxObject($1, $owner); }
387
388 //---------------------------------------------------------------------------
389 %newgroup
390
391
392 // wxHtmlSelection is data holder with information about text selection.
393 // Selection is defined by two positions (beginning and end of the selection)
394 // and two leaf(!) cells at these positions.
395 class wxHtmlSelection
396 {
397 public:
398 wxHtmlSelection();
399 ~wxHtmlSelection();
400
401 void Set(const wxPoint& fromPos, const wxHtmlCell *fromCell,
402 const wxPoint& toPos, const wxHtmlCell *toCell);
403 %Rename(SetCells, void, Set(const wxHtmlCell *fromCell, const wxHtmlCell *toCell));
404
405 const wxHtmlCell *GetFromCell() const;
406 const wxHtmlCell *GetToCell() const;
407
408 // these values are in absolute coordinates:
409 const wxPoint& GetFromPos() const;
410 const wxPoint& GetToPos() const;
411
412 // these are From/ToCell's private data
413 const wxPoint& GetFromPrivPos() const;
414 const wxPoint& GetToPrivPos() const;
415 void SetFromPrivPos(const wxPoint& pos);
416 void SetToPrivPos(const wxPoint& pos);
417 void ClearPrivPos();
418
419 const bool IsEmpty() const;
420
421 };
422
423
424 enum wxHtmlSelectionState
425 {
426 wxHTML_SEL_OUT, // currently rendered cell is outside the selection
427 wxHTML_SEL_IN, // ... is inside selection
428 wxHTML_SEL_CHANGING // ... is the cell on which selection state changes
429 };
430
431
432
433 // Selection state is passed to wxHtmlCell::Draw so that it can render itself
434 // differently e.g. when inside text selection or outside it.
435 class wxHtmlRenderingState
436 {
437 public:
438 wxHtmlRenderingState();
439 ~wxHtmlRenderingState();
440
441 void SetSelectionState(wxHtmlSelectionState s);
442 wxHtmlSelectionState GetSelectionState() const;
443
444 void SetFgColour(const wxColour& c);
445 const wxColour& GetFgColour() const;
446 void SetBgColour(const wxColour& c);
447 const wxColour& GetBgColour() const;
448 };
449
450
451
452 // HTML rendering customization. This class is used when rendering wxHtmlCells
453 // as a callback:
454 class wxHtmlRenderingStyle
455 {
456 public:
457 virtual wxColour GetSelectedTextColour(const wxColour& clr) = 0;
458 virtual wxColour GetSelectedTextBgColour(const wxColour& clr) = 0;
459 };
460
461 // Standard style:
462 class wxDefaultHtmlRenderingStyle : public wxHtmlRenderingStyle
463 {
464 public:
465 virtual wxColour GetSelectedTextColour(const wxColour& clr);
466 virtual wxColour GetSelectedTextBgColour(const wxColour& clr);
467 };
468
469
470
471 // Information given to cells when drawing them. Contains rendering state,
472 // selection information and rendering style object that can be used to
473 // customize the output.
474 class wxHtmlRenderingInfo
475 {
476 public:
477 wxHtmlRenderingInfo();
478 ~wxHtmlRenderingInfo();
479
480 void SetSelection(wxHtmlSelection *s);
481 wxHtmlSelection *GetSelection() const;
482
483 void SetStyle(wxHtmlRenderingStyle *style);
484 wxHtmlRenderingStyle& GetStyle();
485
486 wxHtmlRenderingState& GetState();
487 };
488
489 //---------------------------------------------------------------------------
490 %newgroup
491
492
493 enum
494 {
495 wxHTML_FIND_EXACT = 1,
496 wxHTML_FIND_NEAREST_BEFORE = 2,
497 wxHTML_FIND_NEAREST_AFTER = 4
498 };
499
500
501 class wxHtmlCell : public wxObject {
502 public:
503 %typemap(out) wxHtmlCell*; // turn off this typemap
504
505 wxHtmlCell();
506 ~wxHtmlCell();
507
508 // Turn it back on again
509 %typemap(out) wxHtmlCell* { $result = wxPyMake_wxObject($1, $owner); }
510
511 int GetPosX();
512 int GetPosY();
513 int GetWidth();
514 int GetHeight();
515 int GetDescent();
516
517 // Returns the maximum possible length of the cell.
518 // Call Layout at least once before using GetMaxTotalWidth()
519 int GetMaxTotalWidth() const;
520
521 const wxString& GetId() const;
522 void SetId(const wxString& id);
523 wxHtmlLinkInfo* GetLink(int x = 0, int y = 0);
524 wxHtmlCell* GetNext();
525 wxHtmlContainerCell* GetParent();
526 wxHtmlCell* GetFirstChild() const;
527
528 // Returns cursor to be used when mouse is over the cell:
529 virtual wxCursor GetMouseCursor(wxHtmlWindowInterface *window) const;
530
531 // Returns cursor to be used when mouse is over the cell:
532 wxCursor GetCursor() const;
533 %pythoncode { GetCursor = wx._deprecated(GetCursor) }
534
535 // Formatting cells are not visible on the screen, they only alter
536 // renderer's state.
537 bool IsFormattingCell() const;
538
539
540 void SetLink(const wxHtmlLinkInfo& link);
541
542 %disownarg(wxHtmlCell*);
543 void SetNext(wxHtmlCell *cell);
544 %cleardisown(wxHtmlCell*);
545
546 void SetParent(wxHtmlContainerCell *p);
547 void SetPos(int x, int y);
548 void Layout(int w);
549 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
550 wxHtmlRenderingInfo& info);
551 void DrawInvisible(wxDC& dc, int x, int y,
552 wxHtmlRenderingInfo& info);
553 const wxHtmlCell* Find(int condition, const void* param);
554
555
556 virtual bool ProcessMouseClick(wxHtmlWindowInterface *window,
557 const wxPoint& pos,
558 const wxMouseEvent& event);
559
560 // TODO: bool AdjustPagebreak(int* INOUT,
561 // wxArrayInt& known_pagebreaks);
562 void SetCanLiveOnPagebreak(bool can);
563
564 // Can the line be broken before this cell?
565 bool IsLinebreakAllowed() const;
566
567 // Returns True for simple == terminal cells, i.e. not composite ones.
568 // This if for internal usage only and may disappear in future versions!
569 bool IsTerminalCell() const;
570
571 // Find a cell inside this cell positioned at the given coordinates
572 // (relative to this's positions). Returns NULL if no such cell exists.
573 // The flag can be used to specify whether to look for terminal or
574 // nonterminal cells or both. In either case, returned cell is deepest
575 // cell in cells tree that contains [x,y].
576 wxHtmlCell *FindCellByPos(wxCoord x, wxCoord y,
577 unsigned flags = wxHTML_FIND_EXACT) const;
578
579 // Returns absolute position of the cell on HTML canvas
580 // If rootCell is provided, then it's considered to be the root of the
581 // hierarchy and the returned value is relative to it.
582 wxPoint GetAbsPos(wxHtmlCell *rootCell = NULL) const;
583
584 // Returns root cell of the hierarchy (i.e. grand-grand-...-parent that
585 // doesn't have a parent itself)
586 wxHtmlCell *GetRootCell() const;
587
588 // Returns first (last) terminal cell inside this cell. It may return NULL,
589 // but it is rare -- only if there are no terminals in the tree.
590 wxHtmlCell *GetFirstTerminal() const ;
591 wxHtmlCell *GetLastTerminal() const ;
592
593 // Returns cell's depth, i.e. how far under the root cell it is
594 // (if it is the root, depth is 0)
595 unsigned GetDepth() const;
596
597 // Returns True if the cell appears before 'cell' in natural order of
598 // cells (= as they are read). If cell A is (grand)parent of cell B,
599 // then both A.IsBefore(B) and B.IsBefore(A) always return True.
600 bool IsBefore(wxHtmlCell *cell) const;
601
602 // Converts the cell into text representation. If sel != NULL then
603 // only part of the cell inside the selection is converted.
604 wxString ConvertToText(wxHtmlSelection *sel) const;
605 };
606
607
608 class wxHtmlWordCell : public wxHtmlCell
609 {
610 public:
611 wxHtmlWordCell(const wxString& word, wxDC& dc);
612 wxString ConvertToText(wxHtmlSelection *sel) const;
613 bool IsLinebreakAllowed() const;
614 void SetPreviousWord(wxHtmlWordCell *cell);
615 };
616
617
618 class wxHtmlContainerCell : public wxHtmlCell {
619 public:
620 wxHtmlContainerCell(wxHtmlContainerCell *parent);
621
622 %disownarg(wxHtmlCell*);
623 void InsertCell(wxHtmlCell *cell);
624 %cleardisown(wxHtmlCell*);
625
626 void SetAlignHor(int al);
627 int GetAlignHor();
628 void SetAlignVer(int al);
629 int GetAlignVer();
630 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
631 int GetIndent(int ind);
632 int GetIndentUnits(int ind);
633 void SetAlign(const wxHtmlTag& tag);
634 void SetWidthFloat(int w, int units);
635 %Rename(SetWidthFloatFromTag, void, SetWidthFloat(const wxHtmlTag& tag));
636 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
637 void SetBackgroundColour(const wxColour& clr);
638 wxColour GetBackgroundColour();
639 void SetBorder(const wxColour& clr1, const wxColour& clr2);
640 wxHtmlCell* GetFirstChild();
641 %pragma(python) addtoclass = "GetFirstCell = GetFirstChild"
642 };
643
644
645
646 class wxHtmlColourCell : public wxHtmlCell {
647 public:
648 wxHtmlColourCell(const wxColour& clr, int flags = wxHTML_CLR_FOREGROUND);
649
650 };
651
652
653 class wxHtmlFontCell : public wxHtmlCell
654 {
655 public:
656 wxHtmlFontCell(wxFont *font);
657 };
658
659
660 class wxHtmlWidgetCell : public wxHtmlCell {
661 public:
662 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
663
664 };
665
666
667
668
669 //---------------------------------------------------------------------------
670 // wxHtmlFilter
671 //---------------------------------------------------------------------------
672 %newgroup
673
674
675 %{ // here's the C++ version
676 class wxPyHtmlFilter : public wxHtmlFilter {
677 DECLARE_ABSTRACT_CLASS(wxPyHtmlFilter)
678 public:
679 wxPyHtmlFilter() : wxHtmlFilter() {}
680
681 // returns True if this filter is able to open&read given file
682 virtual bool CanRead(const wxFSFile& file) const {
683 bool rval = false;
684 bool found;
685 wxPyBlock_t blocked = wxPyBeginBlockThreads();
686 if ((found = wxPyCBH_findCallback(m_myInst, "CanRead"))) {
687 PyObject* obj = wxPyMake_wxObject((wxFSFile*)&file,false); // cast away const
688 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj));
689 Py_DECREF(obj);
690 }
691 wxPyEndBlockThreads(blocked);
692 return rval;
693 }
694
695
696 // Reads given file and returns HTML document.
697 // Returns empty string if opening failed
698 virtual wxString ReadFile(const wxFSFile& file) const {
699 wxString rval;
700 bool found;
701 wxPyBlock_t blocked = wxPyBeginBlockThreads();
702 if ((found = wxPyCBH_findCallback(m_myInst, "ReadFile"))) {
703 PyObject* obj = wxPyMake_wxObject((wxFSFile*)&file,false); // cast away const
704 PyObject* ro;
705 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(O)", obj));
706 Py_DECREF(obj);
707 if (ro) {
708 rval = Py2wxString(ro);
709 Py_DECREF(ro);
710 }
711 }
712 wxPyEndBlockThreads(blocked);
713 return rval;
714 }
715
716 PYPRIVATE;
717 };
718
719 IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlFilter, wxHtmlFilter);
720 %}
721
722
723 // And now the version seen by SWIG
724
725 %rename(HtmlFilter) wxPyHtmlFilter;
726 class wxPyHtmlFilter : public wxObject {
727 public:
728 %pythonAppend wxPyHtmlFilter "self._setCallbackInfo(self, HtmlFilter)"
729 wxPyHtmlFilter();
730
731 void _setCallbackInfo(PyObject* self, PyObject* _class);
732 };
733
734
735 // TODO: wxHtmlFilterHTML
736
737
738 //---------------------------------------------------------------------------
739
740
741 class wxHtmlWindowInterface
742 {
743 public:
744 /// Ctor
745 wxHtmlWindowInterface();
746 virtual ~wxHtmlWindowInterface();
747
748 /**
749 Called by the parser to set window's title to given text.
750 */
751 virtual void SetHTMLWindowTitle(const wxString& title) = 0;
752
753 // /**
754 // Called when a link is clicked.
755
756 // @param link information about the clicked link
757 // */
758 // virtual void OnHTMLLinkClicked(const wxHtmlLinkInfo& link) = 0;
759
760 // /**
761 // Called when the parser needs to open another URL (e.g. an image).
762
763 // @param type Type of the URL request (e.g. image)
764 // @param url URL the parser wants to open
765 // @param redirect If the return value is wxHTML_REDIRECT, then the
766 // URL to redirect to will be stored in this variable
767 // (the pointer must never be NULL)
768
769 // @return indicator of how to treat the request
770 // */
771 // virtual wxHtmlOpeningStatus OnHTMLOpeningURL(wxHtmlURLType type,
772 // const wxString& url,
773 // wxString *redirect) const = 0;
774
775 /**
776 Converts coordinates @a pos relative to given @a cell to
777 physical coordinates in the window.
778 */
779 virtual wxPoint HTMLCoordsToWindow(wxHtmlCell *cell,
780 const wxPoint& pos) const = 0;
781
782 /// Returns the window used for rendering (may be NULL).
783 virtual wxWindow* GetHTMLWindow() = 0;
784
785 /// Returns background colour to use by default.
786 virtual wxColour GetHTMLBackgroundColour() const = 0;
787
788 /// Sets window's background to colour @a clr.
789 virtual void SetHTMLBackgroundColour(const wxColour& clr) = 0;
790
791 /// Sets window's background to given bitmap.
792 virtual void SetHTMLBackgroundImage(const wxBitmap& bmpBg) = 0;
793
794 /// Sets status bar text.
795 virtual void SetHTMLStatusText(const wxString& text) = 0;
796
797 /// Type of mouse cursor
798 enum HTMLCursor
799 {
800 /// Standard mouse cursor (typically an arrow)
801 HTMLCursor_Default,
802 /// Cursor shown over links
803 HTMLCursor_Link,
804 /// Cursor shown over selectable text
805 HTMLCursor_Text
806 };
807
808 /**
809 Returns mouse cursor of given @a type.
810 */
811 // virtual wxCursor GetHTMLCursor(HTMLCursor type) const = 0;
812 };
813
814
815 //---------------------------------------------------------------------------
816 // wxHtmlWindow
817 //---------------------------------------------------------------------------
818 %newgroup
819
820 // TODO?
821 // wxHtmlWindowInterface and wxHtmlWindowMouseHelper
822
823
824 %{
825 class wxPyHtmlWindow : public wxHtmlWindow {
826 DECLARE_ABSTRACT_CLASS(wxPyHtmlWindow)
827 public:
828 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
829 const wxPoint& pos = wxDefaultPosition,
830 const wxSize& size = wxDefaultSize,
831 long style = wxHW_DEFAULT_STYLE,
832 const wxString& name = wxPyHtmlWindowNameStr)
833 : wxHtmlWindow(parent, id, pos, size, style, name) {};
834 wxPyHtmlWindow() : wxHtmlWindow() {};
835
836 bool ScrollToAnchor(const wxString& anchor) {
837 return wxHtmlWindow::ScrollToAnchor(anchor);
838 }
839
840 bool HasAnchor(const wxString& anchor) {
841 const wxHtmlCell *c = m_Cell->Find(wxHTML_COND_ISANCHOR, &anchor);
842 return c!=NULL;
843 }
844
845 void OnLinkClicked(const wxHtmlLinkInfo& link);
846
847 wxHtmlOpeningStatus OnOpeningURL(wxHtmlURLType type,
848 const wxString& url,
849 wxString *redirect) const;
850
851 DEC_PYCALLBACK__STRING(OnSetTitle);
852 DEC_PYCALLBACK__CELLINTINT(OnCellMouseHover);
853 DEC_PYCALLBACK_BOOL_CELLINTINTME(OnCellClicked);
854
855 PYPRIVATE;
856 };
857
858 IMPLEMENT_ABSTRACT_CLASS( wxPyHtmlWindow, wxHtmlWindow );
859 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
860 IMP_PYCALLBACK__CELLINTINT(wxPyHtmlWindow, wxHtmlWindow, OnCellMouseHover);
861 IMP_PYCALLBACK_BOOL_CELLINTINTME(wxPyHtmlWindow, wxHtmlWindow, OnCellClicked);
862
863
864 void wxPyHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) {
865 bool found;
866 wxPyBlock_t blocked = wxPyBeginBlockThreads();
867 if ((found = wxPyCBH_findCallback(m_myInst, "OnLinkClicked"))) {
868 PyObject* obj = wxPyConstructObject((void*)&link, wxT("wxHtmlLinkInfo"), 0);
869 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj));
870 Py_DECREF(obj);
871 }
872 wxPyEndBlockThreads(blocked);
873 if (! found)
874 wxHtmlWindow::OnLinkClicked(link);
875 }
876
877
878 wxHtmlOpeningStatus wxPyHtmlWindow::OnOpeningURL(wxHtmlURLType type,
879 const wxString& url,
880 wxString *redirect) const {
881 bool found;
882 wxHtmlOpeningStatus rval;
883 wxPyBlock_t blocked = wxPyBeginBlockThreads();
884 if ((found = wxPyCBH_findCallback(m_myInst, "OnOpeningURL"))) {
885 PyObject* ro;
886 PyObject* s = wx2PyString(url);
887 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iO)", type, s));
888 Py_DECREF(s);
889 if (PyString_Check(ro)
890 #if PYTHON_API_VERSION >= 1009
891 || PyUnicode_Check(ro)
892 #endif
893 ) {
894 *redirect = Py2wxString(ro);
895 rval = wxHTML_REDIRECT;
896 }
897 else {
898 PyObject* num = PyNumber_Int(ro);
899 rval = (wxHtmlOpeningStatus)PyInt_AsLong(num);
900 Py_DECREF(num);
901 }
902 Py_DECREF(ro);
903 }
904 wxPyEndBlockThreads(blocked);
905 if (! found)
906 rval = wxHtmlWindow::OnOpeningURL(type, url, redirect);
907 return rval;
908 }
909
910
911 %}
912
913
914
915 MustHaveApp(wxPyHtmlWindow);
916
917 %rename(HtmlWindow) wxPyHtmlWindow;
918 class wxPyHtmlWindow : public wxScrolledWindow //,
919 // public wxHtmlWindowInterface //,
920 // public wxHtmlWindowMouseHelper
921 {
922 public:
923 %pythonAppend wxPyHtmlWindow "self._setCallbackInfo(self, HtmlWindow); self._setOORInfo(self)"
924 %pythonAppend wxPyHtmlWindow() ""
925 %typemap(out) wxPyHtmlWindow*; // turn off this typemap
926
927 wxPyHtmlWindow(wxWindow *parent, int id = -1,
928 const wxPoint& pos = wxDefaultPosition,
929 const wxSize& size = wxDefaultSize,
930 int style=wxHW_DEFAULT_STYLE,
931 const wxString& name = wxPyHtmlWindowNameStr);
932 %RenameCtor(PreHtmlWindow, wxPyHtmlWindow());
933
934 // Turn it back on again
935 %typemap(out) wxPyHtmlWindow* { $result = wxPyMake_wxObject($1, $owner); }
936
937 bool Create(wxWindow *parent, int id = -1,
938 const wxPoint& pos = wxDefaultPosition,
939 const wxSize& size = wxDefaultSize,
940 int style=wxHW_SCROLLBAR_AUTO,
941 const wxString& name = wxPyHtmlWindowNameStr);
942
943
944 void _setCallbackInfo(PyObject* self, PyObject* _class);
945
946
947 // Set HTML page and display it. !! source is HTML document itself,
948 // it is NOT address/filename of HTML document. If you want to
949 // specify document location, use LoadPage() instead
950 // Return value : False if an error occurred, True otherwise
951 bool SetPage(const wxString& source);
952
953 // Load HTML page from given location. Location can be either
954 // a) /usr/wxGTK2/docs/html/wx.htm
955 // b) http://www.somewhere.uk/document.htm
956 // c) ftp://ftp.somesite.cz/pub/something.htm
957 // In case there is no prefix (http:,ftp:), the method
958 // will try to find it itself (1. local file, then http or ftp)
959 // After the page is loaded, the method calls SetPage() to display it.
960 // Note : you can also use path relative to previously loaded page
961 // Return value : same as SetPage
962 bool LoadPage(const wxString& location);
963
964 // Loads HTML page from file
965 bool LoadFile(const wxString& filename);
966
967 // Append to current page
968 bool AppendToPage(const wxString& source);
969
970 // Returns full location of opened page
971 wxString GetOpenedPage();
972
973 // Returns anchor within opened page
974 wxString GetOpenedAnchor();
975
976 // Returns <TITLE> of opened page or empty string otherwise
977 wxString GetOpenedPageTitle();
978
979 // Sets frame in which page title will be displayed. Format is format of
980 // frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s
981 void SetRelatedFrame(wxFrame* frame, const wxString& format);
982 wxFrame* GetRelatedFrame();
983
984 // After(!) calling SetRelatedFrame, this sets statusbar slot where messages
985 // will be displayed. Default is -1 = no messages.
986 void SetRelatedStatusBar(int bar);
987
988 // Sets fonts to be used when displaying HTML page.
989 %extend {
990 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
991 int* temp = NULL;
992 if (sizes) temp = int_LIST_helper(sizes);
993 self->SetFonts(normal_face, fixed_face, temp);
994 if (temp)
995 delete [] temp;
996 }
997 }
998
999 // Sets font sizes to be relative to the given size or the system
1000 // default size; use either specified or default font
1001 void SetStandardFonts(int size = -1,
1002 const wxString& normal_face = wxPyEmptyString,
1003 const wxString& fixed_face = wxPyEmptyString);
1004
1005 DocDeclStr(
1006 void, SetLabel(const wxString& title),
1007 "", "");
1008
1009 // Sets space between text and window borders.
1010 void SetBorders(int b);
1011
1012 // Sets the bitmap to use for background (currnetly it will be tiled,
1013 // when/if we have CSS support we could add other possibilities...)
1014 void SetBackgroundImage(const wxBitmap& bmpBg);
1015
1016 // Saves custom settings into cfg config. it will use the path 'path'
1017 // if given, otherwise it will save info into currently selected path.
1018 // saved values : things set by SetFonts, SetBorders.
1019 void ReadCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
1020 void WriteCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
1021
1022 // Goes to previous/next page (in browsing history)
1023 // Returns True if successful, False otherwise
1024 bool HistoryBack();
1025 bool HistoryForward();
1026 bool HistoryCanBack();
1027 bool HistoryCanForward();
1028
1029 // Resets History
1030 void HistoryClear();
1031
1032 // Returns pointer to conteiners/cells structure.
1033 wxHtmlContainerCell* GetInternalRepresentation();
1034
1035 // Returns a pointer to the parser.
1036 wxHtmlWinParser* GetParser();
1037
1038 bool ScrollToAnchor(const wxString& anchor);
1039 bool HasAnchor(const wxString& anchor);
1040
1041 //Adds input filter
1042 static void AddFilter(wxPyHtmlFilter *filter);
1043
1044 // Helper functions to select parts of page:
1045 void SelectWord(const wxPoint& pos);
1046 void SelectLine(const wxPoint& pos);
1047 void SelectAll();
1048
1049 // Convert selection to text:
1050 wxString SelectionToText();
1051
1052 // Converts current page to text:
1053 wxString ToText();
1054
1055 void OnLinkClicked(const wxHtmlLinkInfo& link);
1056 void OnSetTitle(const wxString& title);
1057 void OnCellMouseHover(wxHtmlCell *cell, wxCoord x, wxCoord y);
1058 bool OnCellClicked(wxHtmlCell *cell,
1059 wxCoord x, wxCoord y,
1060 const wxMouseEvent& event);
1061 wxHtmlOpeningStatus OnOpeningURL(wxHtmlURLType type,
1062 const wxString& url,
1063 wxString *redirect) const;
1064 %MAKE_BASE_FUNC(HtmlWindow, OnLinkClicked);
1065 %MAKE_BASE_FUNC(HtmlWindow, OnSetTitle);
1066 %MAKE_BASE_FUNC(HtmlWindow, OnCellMouseHover);
1067 %MAKE_BASE_FUNC(HtmlWindow, OnCellClicked);
1068
1069 static wxVisualAttributes
1070 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
1071
1072 /// Type of mouse cursor
1073 enum HTMLCursor
1074 {
1075 /// Standard mouse cursor (typically an arrow)
1076 HTMLCursor_Default,
1077 /// Cursor shown over links
1078 HTMLCursor_Link,
1079 /// Cursor shown over selectable text
1080 HTMLCursor_Text
1081 };
1082
1083 // Returns standard HTML cursor as used by wxHtmlWindow
1084 static wxCursor GetDefaultHTMLCursor(HTMLCursor type);
1085
1086
1087 // private:
1088 // // wxHtmlWindowInterface methods:
1089 // virtual void SetHTMLWindowTitle(const wxString& title);
1090 // virtual void OnHTMLLinkClicked(const wxHtmlLinkInfo& link);
1091 // virtual wxHtmlOpeningStatus OnHTMLOpeningURL(wxHtmlURLType type,
1092 // const wxString& url,
1093 // wxString *redirect) const;
1094 // virtual wxPoint HTMLCoordsToWindow(wxHtmlCell *cell,
1095 // const wxPoint& pos) const;
1096 // virtual wxWindow* GetHTMLWindow();
1097 // virtual wxColour GetHTMLBackgroundColour() const;
1098 // virtual void SetHTMLBackgroundColour(const wxColour& clr);
1099 // virtual void SetHTMLBackgroundImage(const wxBitmap& bmpBg);
1100 // virtual void SetHTMLStatusText(const wxString& text);
1101 // virtual wxCursor GetHTMLCursor(HTMLCursor type) const;
1102
1103 };
1104
1105
1106
1107
1108 //---------------------------------------------------------------------------
1109 //---------------------------------------------------------------------------
1110 %newgroup
1111
1112
1113 MustHaveApp(wxHtmlDCRenderer);
1114
1115 class wxHtmlDCRenderer : public wxObject {
1116 public:
1117 wxHtmlDCRenderer();
1118 ~wxHtmlDCRenderer();
1119
1120 void SetDC(wxDC *dc, int maxwidth);
1121 void SetSize(int width, int height);
1122 void SetHtmlText(const wxString& html,
1123 const wxString& basepath = wxPyEmptyString,
1124 bool isdir = true);
1125 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
1126 %extend {
1127 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
1128 int* temp = NULL;
1129 if (sizes) temp = int_LIST_helper(sizes);
1130 self->SetFonts(normal_face, fixed_face, temp);
1131 if (temp)
1132 delete [] temp;
1133 }
1134 }
1135
1136 // Sets font sizes to be relative to the given size or the system
1137 // default size; use either specified or default font
1138 void SetStandardFonts(int size = -1,
1139 const wxString& normal_face = wxPyEmptyString,
1140 const wxString& fixed_face = wxPyEmptyString);
1141
1142 int Render(int x, int y, wxArrayInt& known_pagebreaks, int from = 0,
1143 int dont_render = FALSE, int to = INT_MAX);
1144 int GetTotalHeight();
1145 // returns total height of the html document
1146 // (compare Render's return value with this)
1147 };
1148
1149
1150 enum {
1151 wxPAGE_ODD,
1152 wxPAGE_EVEN,
1153 wxPAGE_ALL
1154 };
1155
1156
1157 MustHaveApp(wxHtmlPrintout);
1158
1159 class wxHtmlPrintout : public wxPyPrintout {
1160 public:
1161 wxHtmlPrintout(const wxString& title = wxPyHtmlPrintoutTitleStr);
1162 //~wxHtmlPrintout(); wxPrintPreview object takes ownership...
1163
1164 void SetHtmlText(const wxString& html,
1165 const wxString &basepath = wxPyEmptyString,
1166 bool isdir = true);
1167 void SetHtmlFile(const wxString &htmlfile);
1168 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
1169 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
1170
1171 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
1172 %extend {
1173 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
1174 int* temp = NULL;
1175 if (sizes) temp = int_LIST_helper(sizes);
1176 self->SetFonts(normal_face, fixed_face, temp);
1177 if (temp)
1178 delete [] temp;
1179 }
1180 }
1181
1182 // Sets font sizes to be relative to the given size or the system
1183 // default size; use either specified or default font
1184 void SetStandardFonts(int size = -1,
1185 const wxString& normal_face = wxPyEmptyString,
1186 const wxString& fixed_face = wxPyEmptyString);
1187
1188 void SetMargins(float top = 25.2, float bottom = 25.2,
1189 float left = 25.2, float right = 25.2,
1190 float spaces = 5);
1191
1192 // Adds input filter
1193 static void AddFilter(wxHtmlFilter *filter);
1194
1195 // Cleanup
1196 static void CleanUpStatics();
1197 };
1198
1199
1200
1201 MustHaveApp(wxHtmlEasyPrinting);
1202
1203 class wxHtmlEasyPrinting : public wxObject {
1204 public:
1205 wxHtmlEasyPrinting(const wxString& name = wxPyHtmlPrintingTitleStr,
1206 wxWindow *parentWindow = NULL);
1207 ~wxHtmlEasyPrinting();
1208
1209 void PreviewFile(const wxString &htmlfile);
1210 void PreviewText(const wxString &htmltext, const wxString& basepath = wxPyEmptyString);
1211 void PrintFile(const wxString &htmlfile);
1212 void PrintText(const wxString &htmltext, const wxString& basepath = wxPyEmptyString);
1213 // void PrinterSetup();
1214 void PageSetup();
1215 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
1216 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
1217
1218 %extend {
1219 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) {
1220 int* temp = NULL;
1221 if (sizes) temp = int_LIST_helper(sizes);
1222 self->SetFonts(normal_face, fixed_face, temp);
1223 if (temp)
1224 delete [] temp;
1225 }
1226 }
1227
1228 // Sets font sizes to be relative to the given size or the system
1229 // default size; use either specified or default font
1230 void SetStandardFonts(int size = -1,
1231 const wxString& normal_face = wxPyEmptyString,
1232 const wxString& fixed_face = wxPyEmptyString);
1233
1234 wxPrintData *GetPrintData() {return m_PrintData;}
1235 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
1236
1237 };
1238
1239
1240 //---------------------------------------------------------------------------
1241 //---------------------------------------------------------------------------
1242 %newgroup
1243
1244
1245 class wxHtmlBookRecord {
1246 public:
1247 wxHtmlBookRecord(const wxString& bookfile, const wxString& basepath,
1248 const wxString& title, const wxString& start);
1249
1250 wxString GetBookFile();
1251 wxString GetTitle();
1252 wxString GetStart();
1253 wxString GetBasePath();
1254
1255 void SetContentsRange(int start, int end);
1256 int GetContentsStart();
1257 int GetContentsEnd();
1258
1259 void SetTitle(const wxString& title);
1260 void SetBasePath(const wxString& path);
1261 void SetStart(const wxString& start);
1262
1263 wxString GetFullPath(const wxString &page) const;
1264 };
1265
1266 //---------------------------------------------------------------------------
1267 // WXWIN_COMPATIBILITY_2_4
1268 #if 0
1269 struct wxHtmlContentsItem
1270 {
1271 %extend {
1272 int GetLevel() { return self->m_Level; }
1273 int GetID() { return self->m_ID; }
1274 wxString GetName() { return self->m_Name; }
1275 wxString GetPage() { return self->m_Page; }
1276 wxHtmlBookRecord* GetBook() { return self->m_Book; }
1277 }
1278 };
1279 #endif
1280 //---------------------------------------------------------------------------
1281
1282 class wxHtmlSearchStatus
1283 {
1284 public:
1285 //wxHtmlSearchStatus(wxHtmlHelpData* base, const wxString& keyword,
1286 // const wxString& book = wxPyEmptyString);
1287 bool Search();
1288 bool IsActive();
1289 int GetCurIndex();
1290 int GetMaxIndex();
1291 const wxString& GetName();
1292 };
1293
1294 //---------------------------------------------------------------------------
1295
1296 class wxHtmlHelpData {
1297 public:
1298 wxHtmlHelpData();
1299 ~wxHtmlHelpData();
1300
1301 void SetTempDir(const wxString& path);
1302 bool AddBook(const wxString& book);
1303 // bool AddBookParam(const wxString& title, const wxString& contfile,
1304 // const wxString& indexfile=wxPyEmptyString,
1305 // const wxString& deftopic=wxPyEmptyString,
1306 // const wxString& path=wxPyEmptyString);
1307
1308 wxString FindPageByName(const wxString& page);
1309 wxString FindPageById(int id);
1310
1311 // TODO: this one needs fixed...
1312 const wxHtmlBookRecArray& GetBookRecArray();
1313
1314 };
1315
1316 //---------------------------------------------------------------------------
1317
1318 enum {
1319 wxHF_TOOLBAR,
1320 wxHF_CONTENTS,
1321 wxHF_INDEX,
1322 wxHF_SEARCH,
1323 wxHF_BOOKMARKS,
1324 wxHF_OPEN_FILES,
1325 wxHF_PRINT,
1326 wxHF_FLAT_TOOLBAR,
1327 wxHF_MERGE_BOOKS,
1328 wxHF_ICONS_BOOK,
1329 wxHF_ICONS_BOOK_CHAPTER,
1330 wxHF_ICONS_FOLDER,
1331 wxHF_DEFAULT_STYLE,
1332
1333 wxHF_EMBEDDED,
1334 wxHF_DIALOG,
1335 wxHF_FRAME,
1336 wxHF_MODAL,
1337 };
1338
1339 enum {
1340 wxID_HTML_PANEL,
1341 wxID_HTML_BACK,
1342 wxID_HTML_FORWARD,
1343 wxID_HTML_UPNODE,
1344 wxID_HTML_UP,
1345 wxID_HTML_DOWN,
1346 wxID_HTML_PRINT,
1347 wxID_HTML_OPENFILE,
1348 wxID_HTML_OPTIONS,
1349 wxID_HTML_BOOKMARKSLIST,
1350 wxID_HTML_BOOKMARKSADD,
1351 wxID_HTML_BOOKMARKSREMOVE,
1352 wxID_HTML_TREECTRL,
1353 wxID_HTML_INDEXPAGE,
1354 wxID_HTML_INDEXLIST,
1355 wxID_HTML_INDEXTEXT,
1356 wxID_HTML_INDEXBUTTON,
1357 wxID_HTML_INDEXBUTTONALL,
1358 wxID_HTML_NOTEBOOK,
1359 wxID_HTML_SEARCHPAGE,
1360 wxID_HTML_SEARCHTEXT,
1361 wxID_HTML_SEARCHLIST,
1362 wxID_HTML_SEARCHBUTTON,
1363 wxID_HTML_SEARCHCHOICE,
1364 wxID_HTML_COUNTINFO
1365 };
1366
1367
1368 %{
1369 typedef wxTreeCtrl wxPyTreeCtrl;
1370 %}
1371
1372 MustHaveApp(wxHtmlHelpWindow);
1373
1374 class wxHtmlHelpWindow : public wxWindow
1375 {
1376 public:
1377 %pythonAppend wxHtmlHelpWindow "self._setOORInfo(self)"
1378 %pythonAppend wxHtmlHelpWindow() ""
1379 %typemap(out) wxHtmlHelpWindow*; // turn off this typemap
1380
1381 wxHtmlHelpWindow(wxWindow* parent, wxWindowID wxWindowID,
1382 const wxPoint& pos = wxDefaultPosition,
1383 const wxSize& size = wxDefaultSize,
1384 int style = wxTAB_TRAVERSAL|wxNO_BORDER,
1385 int helpStyle = wxHF_DEFAULT_STYLE,
1386 wxHtmlHelpData* data = NULL);
1387 %RenameCtor(PreHtmlHelpWindow, wxHtmlHelpWindow(wxHtmlHelpData* data = NULL));
1388
1389 // Turn it back on again
1390 %typemap(out) wxHtmlHelpWindow* { $result = wxPyMake_wxObject($1, $owner); }
1391
1392 bool Create(wxWindow* parent, wxWindowID id,
1393 const wxPoint& pos = wxDefaultPosition,
1394 const wxSize& size = wxDefaultSize,
1395 int style = wxTAB_TRAVERSAL|wxNO_BORDER,
1396 int helpStyle = wxHF_DEFAULT_STYLE);
1397
1398 wxHtmlHelpData* GetData();
1399 wxHtmlHelpController* GetController() const;
1400
1401 %disownarg( wxHtmlHelpController* controller );
1402 void SetController(wxHtmlHelpController* controller);
1403 %cleardisown( wxHtmlHelpController* controller );
1404
1405 // Displays page x. If not found it will offect the user a choice of
1406 // searching books.
1407 // Looking for the page runs in these steps:
1408 // 1. try to locate file named x (if x is for example "doc/howto.htm")
1409 // 2. try to open starting page of book x
1410 // 3. try to find x in contents (if x is for example "How To ...")
1411 // 4. try to find x in index (if x is for example "How To ...")
1412 bool Display(const wxString& x);
1413
1414 // Alternative version that works with numeric ID.
1415 // (uses extension to MS format, <param name="ID" value=id>, see docs)
1416 %Rename(DisplayID, bool, Display(int id));
1417
1418 // Displays help window and focuses contents.
1419 bool DisplayContents();
1420
1421 // Displays help window and focuses index.
1422 bool DisplayIndex();
1423
1424 // Searches for keyword. Returns true and display page if found, return
1425 // false otherwise
1426 // Syntax of keyword is Altavista-like:
1427 // * words are separated by spaces
1428 // (but "\"hello world\"" is only one world "hello world")
1429 // * word may be pretended by + or -
1430 // (+ : page must contain the word ; - : page can't contain the word)
1431 // * if there is no + or - before the word, + is default
1432 bool KeywordSearch(const wxString& keyword,
1433 wxHelpSearchMode mode = wxHELP_SEARCH_ALL);
1434
1435 void UseConfig(wxConfigBase *config, const wxString& rootpath = wxEmptyString);
1436
1437 // Saves custom settings into cfg config. it will use the path 'path'
1438 // if given, otherwise it will save info into currently selected path.
1439 // saved values : things set by SetFonts, SetBorders.
1440 void ReadCustomization(wxConfigBase *cfg, const wxString& path = wxEmptyString);
1441 void WriteCustomization(wxConfigBase *cfg, const wxString& path = wxEmptyString);
1442
1443 // call this to let wxHtmlHelpWindow know page changed
1444 void NotifyPageChanged();
1445
1446 // Refreshes Contents and Index tabs
1447 void RefreshLists();
1448
1449 // Gets the HTML window
1450 wxHtmlWindow* GetHtmlWindow() const;
1451
1452 // Gets the splitter window
1453 wxSplitterWindow* GetSplitterWindow();
1454
1455 // Gets the toolbar
1456 wxToolBar* GetToolBar() const;
1457
1458 // Gets the configuration data
1459 wxHtmlHelpFrameCfg& GetCfgData();
1460
1461 // Gets the tree control
1462 wxPyTreeCtrl *GetTreeCtrl() const;
1463
1464 };
1465
1466
1467 class wxHtmlWindowEvent: public wxNotifyEvent
1468 {
1469 public:
1470 wxHtmlWindowEvent(wxEventType commandType = wxEVT_NULL, int id = 0):
1471 wxNotifyEvent(commandType, id);
1472
1473 void SetURL(const wxString& url);
1474 const wxString& GetURL() const;
1475 };
1476
1477
1478
1479 MustHaveApp(wxHtmlHelpFrame);
1480
1481 class wxHtmlHelpFrame : public wxFrame {
1482 public:
1483 %pythonAppend wxHtmlHelpFrame "self._setOORInfo(self)"
1484 %pythonAppend wxHtmlHelpFrame() ""
1485 %typemap(out) wxHtmlHelpFrame*; // turn off this typemap
1486
1487 wxHtmlHelpFrame(wxWindow* parent, int wxWindowID,
1488 const wxString& title = wxPyEmptyString,
1489 int style = wxHF_DEFAULTSTYLE, wxHtmlHelpData* data = NULL);
1490 %RenameCtor(PreHtmlHelpFrame, wxHtmlHelpFrame(wxHtmlHelpData* data = NULL));
1491
1492 // Turn it back on again
1493 %typemap(out) wxHtmlHelpFrame* { $result = wxPyMake_wxObject($1, $owner); }
1494
1495 bool Create(wxWindow* parent, wxWindowID id,
1496 const wxString& title = wxPyEmptyString,
1497 int style = wxHF_DEFAULT_STYLE);
1498
1499 wxHtmlHelpData* GetData();
1500 void SetTitleFormat(const wxString& format);
1501
1502 void AddGrabIfNeeded();
1503
1504 /// Returns the help controller associated with the window.
1505 wxHtmlHelpController* GetController() const;
1506
1507 /// Sets the help controller associated with the window.
1508 %disownarg( wxHtmlHelpController* controller );
1509 void SetController(wxHtmlHelpController* controller);
1510 %cleardisown( wxHtmlHelpController* controller );
1511
1512 /// Returns the help window.
1513 wxHtmlHelpWindow* GetHelpWindow() const;
1514
1515 %pythoncode {
1516 %# For compatibility from before the refactor
1517 def Display(self, x):
1518 return self.GetHelpWindow().Display(x)
1519 def DisplayID(self, x):
1520 return self.GetHelpWindow().DisplayID(id)
1521 def DisplayContents(self):
1522 return self.GetHelpWindow().DisplayContents()
1523 def DisplayIndex(self):
1524 return self.GetHelpWindow().DisplayIndex()
1525
1526 def KeywordSearch(self, keyword):
1527 return self.GetHelpWindow().KeywordSearch(keyword)
1528
1529 def UseConfig(self, config, rootpath=""):
1530 return self.GetHelpWindow().UseConfig(config, rootpath)
1531 def ReadCustomization(self, config, rootpath=""):
1532 return self.GetHelpWindow().ReadCustomization(config, rootpath)
1533 def WriteCustomization(self, config, rootpath=""):
1534 return self.GetHelpWindow().WriteCustomization(config, rootpath)
1535 %}
1536 };
1537
1538
1539
1540 MustHaveApp(wxHtmlHelpDialog);
1541
1542 class wxHtmlHelpDialog : public wxDialog
1543 {
1544 public:
1545 %pythonAppend wxHtmlHelpDialog "self._setOORInfo(self)"
1546 %pythonAppend wxHtmlHelpDialog() ""
1547 %typemap(out) wxHtmlHelpDialog*; // turn off this typemap
1548
1549 wxHtmlHelpDialog(wxWindow* parent, wxWindowID wxWindowID,
1550 const wxString& title = wxPyEmptyString,
1551 int style = wxHF_DEFAULT_STYLE, wxHtmlHelpData* data = NULL);
1552 %RenameCtor(PreHtmlHelpDialog, wxHtmlHelpDialog(wxHtmlHelpData* data = NULL));
1553
1554 // Turn it back on again
1555 %typemap(out) wxHtmlHelpDialog* { $result = wxPyMake_wxObject($1, $owner); }
1556
1557 bool Create(wxWindow* parent, wxWindowID id, const wxString& title = wxPyEmptyString,
1558 int style = wxHF_DEFAULT_STYLE);
1559
1560 /// Returns the data associated with this dialog.
1561 wxHtmlHelpData* GetData();
1562
1563 /// Returns the controller that created this dialog.
1564 wxHtmlHelpController* GetController() const;
1565
1566 /// Sets the controller associated with this dialog.
1567 %disownarg( wxHtmlHelpController* controller );
1568 void SetController(wxHtmlHelpController* controller);
1569 %cleardisown( wxHtmlHelpController* controller );
1570
1571 /// Returns the help window.
1572 wxHtmlHelpWindow* GetHelpWindow() const;
1573
1574 // Sets format of title of the frame. Must contain exactly one "%s"
1575 // (for title of displayed HTML page)
1576 void SetTitleFormat(const wxString& format);
1577
1578 // Override to add custom buttons to the toolbar
1579 // virtual void AddToolbarButtons(wxToolBar* WXUNUSED(toolBar), int WXUNUSED(style)) {};
1580
1581 };
1582
1583
1584 //---------------------------------------------------------------------------
1585
1586
1587 // TODO: Make virtual methods of this class overridable in Python.
1588
1589 MustHaveApp(wxHelpControllerBase);
1590
1591 class wxHelpControllerBase: public wxObject
1592 {
1593 public:
1594 // wxHelpControllerBase(wxWindow* parentWindow = NULL);
1595 // ~wxHelpControllerBase();
1596
1597 %nokwargs Initialize;
1598 virtual bool Initialize(const wxString& file, int server );
1599 virtual bool Initialize(const wxString& file);
1600
1601 virtual void SetViewer(const wxString& viewer, long flags = 0);
1602
1603 // If file is "", reloads file given in Initialize
1604 virtual bool LoadFile(const wxString& file = wxEmptyString) /* = 0 */;
1605
1606 // Displays the contents
1607 virtual bool DisplayContents(void) /* = 0 */;
1608
1609 %nokwargs DisplaySection;
1610
1611 // Display the given section
1612 virtual bool DisplaySection(int sectionNo) /* = 0 */;
1613
1614 // Display the section using a context id
1615 virtual bool DisplayContextPopup(int contextId);
1616
1617 // Display the text in a popup, if possible
1618 virtual bool DisplayTextPopup(const wxString& text, const wxPoint& pos);
1619
1620 // By default, uses KeywordSection to display a topic. Implementations
1621 // may override this for more specific behaviour.
1622 virtual bool DisplaySection(const wxString& section);
1623
1624 virtual bool DisplayBlock(long blockNo) /* = 0 */;
1625 virtual bool KeywordSearch(const wxString& k,
1626 wxHelpSearchMode mode = wxHELP_SEARCH_ALL) /* = 0 */;
1627
1628 /// Allows one to override the default settings for the help frame.
1629 virtual void SetFrameParameters(const wxString& title,
1630 const wxSize& size,
1631 const wxPoint& pos = wxDefaultPosition,
1632 bool newFrameEachTime = false);
1633
1634 /// Obtains the latest settings used by the help frame and the help
1635 /// frame.
1636 virtual wxFrame *GetFrameParameters(wxSize *size = NULL,
1637 wxPoint *pos = NULL,
1638 bool *newFrameEachTime = NULL);
1639
1640 virtual bool Quit() /* = 0 */;
1641
1642 virtual void OnQuit();
1643
1644 /// Set the window that can optionally be used for the help window's parent.
1645 virtual void SetParentWindow(wxWindow* win);
1646
1647 /// Get the window that can optionally be used for the help window's parent.
1648 virtual wxWindow* GetParentWindow() const;
1649
1650 };
1651
1652
1653
1654
1655 MustHaveApp(wxHtmlHelpController);
1656
1657 class wxHtmlHelpController : public wxHelpControllerBase
1658 {
1659 public:
1660 // %pythonAppend wxHtmlHelpController "self._setOORInfo(self)"
1661
1662 wxHtmlHelpController(int style = wxHF_DEFAULT_STYLE, wxWindow* parentWindow = NULL);
1663 ~wxHtmlHelpController();
1664
1665 wxHtmlHelpWindow* GetHelpWindow();
1666 void SetHelpWindow(wxHtmlHelpWindow* helpWindow);
1667
1668 wxHtmlHelpFrame* GetFrame();
1669 wxHtmlHelpDialog* GetDialog();
1670
1671 void SetTitleFormat(const wxString& format);
1672 void SetTempDir(const wxString& path);
1673 bool AddBook(const wxString& book, int show_wait_msg = false);
1674 void Display(const wxString& x);
1675 %Rename(DisplayID, void, Display(int id));
1676 void DisplayContents();
1677 void DisplayIndex();
1678 bool KeywordSearch(const wxString& keyword);
1679 void UseConfig(wxConfigBase *config, const wxString& rootpath = wxPyEmptyString);
1680 void ReadCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
1681 void WriteCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString);
1682
1683 void MakeModalIfNeeded();
1684 wxWindow* FindTopLevelWindow();
1685 };
1686
1687
1688 /*
1689 * wxHtmlModalHelp
1690 * A convenience class particularly for use on wxMac,
1691 * where you can only show modal dialogs from a modal
1692 * dialog.
1693 *
1694 * Use like this:
1695 *
1696 * wxHtmlModalHelp help(parent, filename, topic);
1697 *
1698 * If topic is empty, the help contents is displayed.
1699 */
1700
1701 class wxHtmlModalHelp
1702 {
1703 public:
1704 wxHtmlModalHelp(wxWindow* parent, const wxString& helpFile,
1705 const wxString& topic = wxEmptyString,
1706 int style = wxHF_DEFAULT_STYLE | wxHF_DIALOG | wxHF_MODAL);
1707 };
1708
1709
1710 //---------------------------------------------------------------------------
1711 %init %{
1712 wxPyPtrTypeMap_Add("wxHtmlTagHandler", "wxPyHtmlTagHandler");
1713 wxPyPtrTypeMap_Add("wxHtmlWinTagHandler", "wxPyHtmlWinTagHandler");
1714 wxPyPtrTypeMap_Add("wxHtmlWindow", "wxPyHtmlWindow");
1715 wxPyPtrTypeMap_Add("wxHtmlFilter", "wxPyHtmlFilter");
1716 %}
1717 //---------------------------------------------------------------------------
1718 //---------------------------------------------------------------------------
1719
1720
1721