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