]>
Commit | Line | Data |
---|---|---|
4b123bb9 HH |
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) 1998 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | ||
14 | %module html | |
15 | ||
16 | %{ | |
6e2129f9 | 17 | #include "wxPython.h" |
4b123bb9 | 18 | #include <wx/html/htmlwin.h> |
dc2f8a65 | 19 | #include <wx/html/htmprint.h> |
4b123bb9 HH |
20 | #include <wx/image.h> |
21 | #include <wx/fs_zip.h> | |
22 | #include <wx/fs_inet.h> | |
5ca24bf4 | 23 | #include <wx/wfstream.h> |
1e4a197e | 24 | #include <wx/filesys.h> |
dc2f8a65 RD |
25 | |
26 | #include "printfw.h" | |
4b123bb9 HH |
27 | %} |
28 | ||
29 | //--------------------------------------------------------------------------- | |
30 | ||
31 | %include typemaps.i | |
32 | %include my_typemaps.i | |
33 | ||
34 | %extern wx.i | |
35 | %extern windows.i | |
36 | %extern _defs.i | |
37 | %extern events.i | |
5ca24bf4 HH |
38 | %extern controls.i |
39 | %extern controls2.i | |
dc2f8a65 | 40 | %extern printfw.i |
0f66a9f3 | 41 | %extern utils.i |
1e4a197e RD |
42 | %extern filesys.i |
43 | %extern streams.i | |
44 | ||
0f66a9f3 | 45 | |
2f90df85 | 46 | %pragma(python) code = "import wx" |
4b123bb9 | 47 | |
4b123bb9 | 48 | |
137b5242 RD |
49 | //---------------------------------------------------------------------- |
50 | ||
51 | %{ | |
52 | // Put some wx default wxChar* values into wxStrings. | |
53 | static const wxChar* wxHtmlWindowNameStr = wxT("htmlWindow"); | |
54 | DECLARE_DEF_STRING(HtmlWindowNameStr); | |
55 | ||
56 | static const wxChar* wxHtmlPrintoutTitleStr = wxT("Printout"); | |
57 | DECLARE_DEF_STRING(HtmlPrintoutTitleStr); | |
58 | ||
59 | static const wxChar* wxHtmlPrintingTitleStr = wxT("Printing"); | |
60 | DECLARE_DEF_STRING(HtmlPrintingTitleStr); | |
61 | ||
62 | static const wxString wxPyEmptyString(wxT("")); | |
63 | %} | |
64 | ||
0f66a9f3 | 65 | //--------------------------------------------------------------------------- |
e166644c RD |
66 | |
67 | enum { | |
9d8bd15f RD |
68 | wxHTML_ALIGN_LEFT, |
69 | wxHTML_ALIGN_CENTER, | |
70 | wxHTML_ALIGN_RIGHT, | |
71 | wxHTML_ALIGN_BOTTOM, | |
72 | wxHTML_ALIGN_TOP, | |
73 | ||
74 | wxHTML_CLR_FOREGROUND, | |
75 | wxHTML_CLR_BACKGROUND, | |
76 | ||
77 | wxHTML_UNITS_PIXELS, | |
78 | wxHTML_UNITS_PERCENT, | |
79 | ||
80 | wxHTML_INDENT_LEFT, | |
81 | wxHTML_INDENT_RIGHT, | |
82 | wxHTML_INDENT_TOP, | |
83 | wxHTML_INDENT_BOTTOM, | |
84 | ||
85 | wxHTML_INDENT_HORIZONTAL, | |
86 | wxHTML_INDENT_VERTICAL, | |
87 | wxHTML_INDENT_ALL, | |
88 | ||
89 | wxHTML_COND_ISANCHOR, | |
90 | wxHTML_COND_ISIMAGEMAP, | |
91 | wxHTML_COND_USER, | |
e166644c RD |
92 | }; |
93 | ||
94 | ||
c6c593e8 RD |
95 | enum { |
96 | wxHW_SCROLLBAR_NEVER, | |
97 | wxHW_SCROLLBAR_AUTO, | |
98 | }; | |
99 | ||
100 | ||
101 | // enums for wxHtmlWindow::OnOpeningURL | |
102 | enum wxHtmlOpeningStatus | |
103 | { | |
104 | wxHTML_OPEN, | |
105 | wxHTML_BLOCK, | |
106 | wxHTML_REDIRECT | |
107 | }; | |
108 | ||
109 | enum wxHtmlURLType | |
110 | { | |
111 | wxHTML_URL_PAGE, | |
112 | wxHTML_URL_IMAGE, | |
113 | wxHTML_URL_OTHER | |
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); | |
139 | wxString GetParam(const wxString& par, int with_commas = FALSE); | |
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 | ||
151 | ||
152 | //--------------------------------------------------------------------------- | |
153 | ||
9416aa89 | 154 | class wxHtmlParser : public wxObject { |
0f66a9f3 RD |
155 | public: |
156 | // wxHtmlParser(); This is an abstract base class... | |
157 | ||
158 | void SetFS(wxFileSystem *fs); | |
159 | wxFileSystem* GetFS(); | |
160 | wxObject* Parse(const wxString& source); | |
161 | void InitParser(const wxString& source); | |
162 | void DoneParser(); | |
163 | void DoParsing(int begin_pos, int end_pos); | |
1e4a197e | 164 | void StopParsing(); |
0f66a9f3 | 165 | // wxObject* GetProduct(); |
1e4a197e | 166 | |
0f66a9f3 RD |
167 | void AddTagHandler(wxHtmlTagHandler *handler); |
168 | wxString* GetSource(); | |
dc2f8a65 RD |
169 | void PushTagHandler(wxHtmlTagHandler* handler, wxString tags); |
170 | void PopTagHandler(); | |
0f66a9f3 | 171 | |
c6c593e8 | 172 | // virtual wxFSFile *OpenURL(wxHtmlURLType type, const wxString& url) const; |
0f66a9f3 RD |
173 | |
174 | // void AddText(const char* txt) = 0; | |
175 | // void AddTag(const wxHtmlTag& tag); | |
176 | }; | |
177 | ||
178 | ||
179 | //--------------------------------------------------------------------------- | |
180 | ||
181 | class wxHtmlWinParser : public wxHtmlParser { | |
182 | public: | |
ce914f73 | 183 | wxHtmlWinParser(wxHtmlWindow *wnd = NULL); |
0f66a9f3 RD |
184 | |
185 | void SetDC(wxDC *dc); | |
186 | wxDC* GetDC(); | |
187 | int GetCharHeight(); | |
188 | int GetCharWidth(); | |
6c5ae2d2 | 189 | wxHtmlWindow* GetWindow(); |
f6bcfd97 | 190 | %addmethods { |
9cbf6f6e RD |
191 | void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) { |
192 | int* temp = NULL; | |
193 | if (sizes) temp = int_LIST_helper(sizes); | |
194 | self->SetFonts(normal_face, fixed_face, temp); | |
195 | if (temp) | |
f6bcfd97 | 196 | delete [] temp; |
f6bcfd97 BP |
197 | } |
198 | } | |
0f66a9f3 RD |
199 | |
200 | wxHtmlContainerCell* GetContainer(); | |
201 | wxHtmlContainerCell* OpenContainer(); | |
dc2f8a65 | 202 | wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c); |
0f66a9f3 | 203 | wxHtmlContainerCell* CloseContainer(); |
dc2f8a65 | 204 | |
0f66a9f3 RD |
205 | int GetFontSize(); |
206 | void SetFontSize(int s); | |
207 | int GetFontBold(); | |
208 | void SetFontBold(int x); | |
209 | int GetFontItalic(); | |
210 | void SetFontItalic(int x); | |
211 | int GetFontUnderlined(); | |
212 | void SetFontUnderlined(int x); | |
213 | int GetFontFixed(); | |
214 | void SetFontFixed(int x); | |
215 | int GetAlign(); | |
216 | void SetAlign(int a); | |
c5943253 | 217 | wxColour GetLinkColor(); |
0f66a9f3 | 218 | void SetLinkColor(const wxColour& clr); |
c5943253 | 219 | wxColour GetActualColor(); |
0f66a9f3 | 220 | void SetActualColor(const wxColour& clr); |
0f66a9f3 RD |
221 | void SetLink(const wxString& link); |
222 | wxFont* CreateCurrentFont(); | |
9c00cfa3 RD |
223 | wxHtmlLinkInfo GetLink(); |
224 | ||
0f66a9f3 RD |
225 | }; |
226 | ||
227 | ||
228 | ||
229 | //--------------------------------------------------------------------------- | |
230 | ||
231 | %{ | |
232 | class wxPyHtmlTagHandler : public wxHtmlTagHandler { | |
9416aa89 | 233 | DECLARE_DYNAMIC_CLASS(wxPyHtmlTagHandler); |
0f66a9f3 RD |
234 | public: |
235 | wxPyHtmlTagHandler() : wxHtmlTagHandler() {}; | |
236 | ||
237 | wxHtmlParser* GetParser() { return m_Parser; } | |
238 | void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); } | |
239 | ||
240 | DEC_PYCALLBACK_STRING__pure(GetSupportedTags); | |
241 | DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag); | |
242 | ||
243 | PYPRIVATE; | |
244 | }; | |
245 | ||
9416aa89 RD |
246 | IMPLEMENT_DYNAMIC_CLASS(wxPyHtmlTagHandler, wxHtmlTagHandler); |
247 | ||
0f66a9f3 RD |
248 | IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags); |
249 | IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag); | |
0f66a9f3 RD |
250 | %} |
251 | ||
252 | ||
9416aa89 | 253 | %name(wxHtmlTagHandler) class wxPyHtmlTagHandler : public wxObject { |
0f66a9f3 RD |
254 | public: |
255 | wxPyHtmlTagHandler(); | |
256 | ||
0122b7e3 RD |
257 | void _setCallbackInfo(PyObject* self, PyObject* _class); |
258 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxHtmlTagHandler)" | |
0f66a9f3 RD |
259 | |
260 | void SetParser(wxHtmlParser *parser); | |
261 | wxHtmlParser* GetParser(); | |
262 | void ParseInner(const wxHtmlTag& tag); | |
263 | }; | |
264 | ||
265 | ||
266 | //--------------------------------------------------------------------------- | |
267 | ||
268 | %{ | |
269 | class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler { | |
9416aa89 | 270 | DECLARE_DYNAMIC_CLASS(wxPyHtmlWinTagHandler); |
0f66a9f3 RD |
271 | public: |
272 | wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {}; | |
273 | ||
274 | wxHtmlWinParser* GetParser() { return m_WParser; } | |
275 | void ParseInner(const wxHtmlTag& tag) | |
276 | { wxHtmlWinTagHandler::ParseInner(tag); } | |
277 | ||
278 | DEC_PYCALLBACK_STRING__pure(GetSupportedTags); | |
279 | DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag); | |
280 | ||
281 | PYPRIVATE; | |
282 | }; | |
283 | ||
9416aa89 RD |
284 | IMPLEMENT_DYNAMIC_CLASS( wxPyHtmlWinTagHandler, wxHtmlWinTagHandler); |
285 | ||
0f66a9f3 RD |
286 | IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags); |
287 | IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag); | |
0f66a9f3 RD |
288 | %} |
289 | ||
290 | ||
291 | %name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler { | |
292 | public: | |
293 | wxPyHtmlWinTagHandler(); | |
294 | ||
0122b7e3 RD |
295 | void _setCallbackInfo(PyObject* self, PyObject* _class); |
296 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxHtmlWinTagHandler)" | |
0f66a9f3 RD |
297 | |
298 | void SetParser(wxHtmlParser *parser); | |
299 | wxHtmlWinParser* GetParser(); | |
300 | void ParseInner(const wxHtmlTag& tag); | |
301 | }; | |
302 | ||
303 | ||
304 | //--------------------------------------------------------------------------- | |
305 | ||
306 | %{ | |
307 | ||
308 | class wxPyHtmlTagsModule : public wxHtmlTagsModule { | |
309 | public: | |
310 | wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() { | |
311 | m_tagHandlerClass = thc; | |
312 | Py_INCREF(m_tagHandlerClass); | |
313 | RegisterModule(this); | |
314 | wxHtmlWinParser::AddModule(this); | |
315 | } | |
316 | ||
317 | void OnExit() { | |
4268f798 | 318 | wxPyBeginBlockThreads(); |
0f66a9f3 RD |
319 | Py_DECREF(m_tagHandlerClass); |
320 | m_tagHandlerClass = NULL; | |
dc2f8a65 | 321 | for (size_t x=0; x < m_objArray.GetCount(); x++) { |
0f66a9f3 RD |
322 | PyObject* obj = (PyObject*)m_objArray.Item(x); |
323 | Py_DECREF(obj); | |
324 | } | |
4268f798 | 325 | wxPyEndBlockThreads(); |
0f66a9f3 RD |
326 | }; |
327 | ||
328 | void FillHandlersTable(wxHtmlWinParser *parser) { | |
329 | // Wave our magic wand... (if it works it's a miracle! ;-) | |
330 | ||
331 | // First, make a new instance of the tag handler | |
4268f798 | 332 | wxPyBeginBlockThreads(); |
0f66a9f3 RD |
333 | PyObject* arg = Py_BuildValue("()"); |
334 | PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL); | |
335 | Py_DECREF(arg); | |
4268f798 | 336 | wxPyEndBlockThreads(); |
0f66a9f3 RD |
337 | |
338 | // now figure out where it's C++ object is... | |
339 | wxPyHtmlWinTagHandler* thPtr; | |
340 | if (SWIG_GetPtrObj(obj, (void **)&thPtr, "_wxPyHtmlWinTagHandler_p")) | |
341 | return; | |
342 | ||
343 | // add it, | |
344 | parser->AddTagHandler(thPtr); | |
345 | ||
346 | // and track it. | |
347 | m_objArray.Add(obj); | |
348 | } | |
349 | ||
350 | private: | |
351 | PyObject* m_tagHandlerClass; | |
352 | wxArrayPtrVoid m_objArray; | |
353 | ||
354 | }; | |
355 | %} | |
356 | ||
357 | ||
358 | ||
359 | %inline %{ | |
360 | void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) { | |
361 | // Dynamically create a new wxModule. Refcounts tagHandlerClass | |
362 | // and adds itself to the wxModules list and to the wxHtmlWinParser. | |
363 | new wxPyHtmlTagsModule(tagHandlerClass); | |
364 | } | |
365 | %} | |
366 | ||
dc2f8a65 | 367 | |
e166644c RD |
368 | //--------------------------------------------------------------------------- |
369 | //--------------------------------------------------------------------------- | |
370 | ||
9416aa89 | 371 | class wxHtmlCell : public wxObject { |
e166644c RD |
372 | public: |
373 | wxHtmlCell(); | |
374 | ||
e166644c RD |
375 | int GetPosX(); |
376 | int GetPosY(); | |
377 | int GetWidth(); | |
378 | int GetHeight(); | |
379 | int GetDescent(); | |
9c00cfa3 | 380 | wxHtmlLinkInfo* GetLink(int x = 0, int y = 0); |
e166644c | 381 | wxHtmlCell* GetNext(); |
9c00cfa3 RD |
382 | wxHtmlContainerCell* GetParent(); |
383 | void SetLink(const wxHtmlLinkInfo& link); | |
e166644c | 384 | void SetNext(wxHtmlCell *cell); |
9c00cfa3 RD |
385 | void SetParent(wxHtmlContainerCell *p); |
386 | void SetPos(int x, int y); | |
e166644c RD |
387 | void Layout(int w); |
388 | void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2); | |
389 | void DrawInvisible(wxDC& dc, int x, int y); | |
390 | const wxHtmlCell* Find(int condition, const void* param); | |
dc2f8a65 RD |
391 | |
392 | bool AdjustPagebreak(int * pagebreak); | |
393 | void SetCanLiveOnPagebreak(bool can); | |
9c00cfa3 | 394 | |
e166644c RD |
395 | }; |
396 | ||
397 | ||
9416aa89 RD |
398 | class wxHtmlWordCell : public wxHtmlCell |
399 | { | |
400 | public: | |
401 | wxHtmlWordCell(const wxString& word, wxDC& dc); | |
402 | }; | |
403 | ||
404 | ||
e166644c RD |
405 | class wxHtmlContainerCell : public wxHtmlCell { |
406 | public: | |
407 | wxHtmlContainerCell(wxHtmlContainerCell *parent); | |
408 | ||
409 | void InsertCell(wxHtmlCell *cell); | |
410 | void SetAlignHor(int al); | |
411 | int GetAlignHor(); | |
412 | void SetAlignVer(int al); | |
413 | int GetAlignVer(); | |
9d8bd15f | 414 | void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS); |
e166644c RD |
415 | int GetIndent(int ind); |
416 | int GetIndentUnits(int ind); | |
417 | void SetAlign(const wxHtmlTag& tag); | |
418 | void SetWidthFloat(int w, int units); | |
419 | %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag); | |
9d8bd15f | 420 | void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP); |
e166644c | 421 | void SetBackgroundColour(const wxColour& clr); |
1e4a197e | 422 | wxColour GetBackgroundColour(); |
e166644c RD |
423 | void SetBorder(const wxColour& clr1, const wxColour& clr2); |
424 | wxHtmlCell* GetFirstCell(); | |
425 | }; | |
426 | ||
427 | ||
428 | ||
9c00cfa3 RD |
429 | class wxHtmlColourCell : public wxHtmlCell { |
430 | public: | |
431 | wxHtmlColourCell(wxColour clr, int flags = wxHTML_CLR_FOREGROUND); | |
432 | ||
433 | }; | |
434 | ||
435 | ||
9416aa89 RD |
436 | class wxHtmlFontCell : public wxHtmlCell |
437 | { | |
438 | public: | |
439 | wxHtmlFontCell(wxFont *font); | |
440 | }; | |
441 | ||
e166644c RD |
442 | |
443 | class wxHtmlWidgetCell : public wxHtmlCell { | |
444 | public: | |
445 | wxHtmlWidgetCell(wxWindow* wnd, int w = 0); | |
446 | ||
447 | }; | |
448 | ||
0f66a9f3 | 449 | |
0f66a9f3 | 450 | //--------------------------------------------------------------------------- |
1e4a197e RD |
451 | // wxHtmlFilter |
452 | //--------------------------------------------------------------------------- | |
453 | ||
454 | ||
455 | %{ // here's the C++ version | |
456 | class wxPyHtmlFilter : public wxHtmlFilter { | |
457 | DECLARE_ABSTRACT_CLASS(wxPyHtmlFilter); | |
458 | public: | |
459 | wxPyHtmlFilter() : wxHtmlFilter() {} | |
460 | ||
461 | // returns TRUE if this filter is able to open&read given file | |
462 | virtual bool CanRead(const wxFSFile& file) const { | |
463 | bool rval = FALSE; | |
464 | bool found; | |
465 | wxPyBeginBlockThreads(); | |
466 | if ((found = wxPyCBH_findCallback(m_myInst, "CanRead"))) { | |
467 | PyObject* obj = wxPyMake_wxObject((wxFSFile*)&file); // cast away const | |
468 | rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); | |
469 | Py_DECREF(obj); | |
470 | } | |
471 | wxPyEndBlockThreads(); | |
472 | return rval; | |
473 | } | |
474 | ||
475 | ||
476 | // Reads given file and returns HTML document. | |
477 | // Returns empty string if opening failed | |
478 | virtual wxString ReadFile(const wxFSFile& file) const { | |
479 | wxString rval; | |
480 | bool found; | |
481 | wxPyBeginBlockThreads(); | |
482 | if ((found = wxPyCBH_findCallback(m_myInst, "ReadFile"))) { | |
483 | PyObject* obj = wxPyMake_wxObject((wxFSFile*)&file); // cast away const | |
484 | PyObject* ro; | |
485 | ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(O)", obj)); | |
486 | Py_DECREF(obj); | |
487 | if (ro) { | |
488 | rval = Py2wxString(ro); | |
489 | Py_DECREF(ro); | |
490 | } | |
491 | } | |
492 | wxPyEndBlockThreads(); | |
493 | return rval; | |
494 | } | |
495 | ||
496 | PYPRIVATE; | |
497 | }; | |
498 | ||
499 | IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlFilter, wxHtmlFilter); | |
500 | %} | |
501 | ||
502 | ||
503 | // And now the version seen by SWIG | |
504 | ||
505 | %name(wxHtmlFilter) class wxPyHtmlFilter : public wxObject { | |
506 | public: | |
507 | wxPyHtmlFilter(); | |
508 | ||
509 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
510 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxHtmlFilter)" | |
511 | }; | |
512 | ||
513 | ||
514 | // TODO: wxHtmlFilterHTML | |
515 | ||
516 | ||
0f66a9f3 | 517 | //--------------------------------------------------------------------------- |
1e4a197e | 518 | // wxHtmlWindow |
4b123bb9 HH |
519 | //--------------------------------------------------------------------------- |
520 | ||
0f66a9f3 RD |
521 | %{ |
522 | class wxPyHtmlWindow : public wxHtmlWindow { | |
cdf14688 | 523 | DECLARE_ABSTRACT_CLASS(wxPyHtmlWindow); |
0f66a9f3 RD |
524 | public: |
525 | wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1, | |
526 | const wxPoint& pos = wxDefaultPosition, | |
527 | const wxSize& size = wxDefaultSize, | |
528 | long style = wxHW_SCROLLBAR_AUTO, | |
1e4a197e | 529 | const wxString& name = wxPyHtmlWindowNameStr) |
0f66a9f3 | 530 | : wxHtmlWindow(parent, id, pos, size, style, name) {}; |
7b7ac0ab | 531 | wxPyHtmlWindow() : wxHtmlWindow() {}; |
0f66a9f3 | 532 | |
e5d41db0 RD |
533 | bool ScrollToAnchor(const wxString& anchor) { |
534 | return wxHtmlWindow::ScrollToAnchor(anchor); | |
535 | } | |
536 | ||
537 | bool HasAnchor(const wxString& anchor) { | |
538 | const wxHtmlCell *c = m_Cell->Find(wxHTML_COND_ISANCHOR, &anchor); | |
539 | return c!=NULL; | |
540 | } | |
541 | ||
c8bc03c3 RD |
542 | void OnLinkClicked(const wxHtmlLinkInfo& link); |
543 | void base_OnLinkClicked(const wxHtmlLinkInfo& link); | |
9c00cfa3 | 544 | |
e5d41db0 | 545 | wxHtmlOpeningStatus OnOpeningURL(wxHtmlURLType type, |
c6c593e8 RD |
546 | const wxString& url, |
547 | wxString *redirect) const; | |
548 | ||
9c00cfa3 | 549 | DEC_PYCALLBACK__STRING(OnSetTitle); |
0122b7e3 RD |
550 | DEC_PYCALLBACK__CELLINTINT(OnCellMouseHover); |
551 | DEC_PYCALLBACK__CELLINTINTME(OnCellClicked); | |
0f66a9f3 RD |
552 | PYPRIVATE; |
553 | }; | |
554 | ||
cdf14688 | 555 | IMPLEMENT_ABSTRACT_CLASS( wxPyHtmlWindow, wxHtmlWindow ); |
9c00cfa3 | 556 | IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle); |
0122b7e3 RD |
557 | IMP_PYCALLBACK__CELLINTINT(wxPyHtmlWindow, wxHtmlWindow, OnCellMouseHover); |
558 | IMP_PYCALLBACK__CELLINTINTME(wxPyHtmlWindow, wxHtmlWindow, OnCellClicked); | |
559 | ||
0f66a9f3 | 560 | |
9416aa89 | 561 | void wxPyHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) { |
19a97bd6 | 562 | bool found; |
4268f798 | 563 | wxPyBeginBlockThreads(); |
0122b7e3 | 564 | if ((found = wxPyCBH_findCallback(m_myInst, "OnLinkClicked"))) { |
1e4a197e | 565 | PyObject* obj = wxPyConstructObject((void*)&link, wxT("wxHtmlLinkInfo"), 0); |
1e7ecb7b | 566 | wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); |
de20db99 | 567 | Py_DECREF(obj); |
9c00cfa3 | 568 | } |
4268f798 | 569 | wxPyEndBlockThreads(); |
19a97bd6 | 570 | if (! found) |
9c00cfa3 | 571 | wxHtmlWindow::OnLinkClicked(link); |
9c00cfa3 | 572 | } |
c8bc03c3 | 573 | void wxPyHtmlWindow::base_OnLinkClicked(const wxHtmlLinkInfo& link) { |
9c00cfa3 RD |
574 | wxHtmlWindow::OnLinkClicked(link); |
575 | } | |
0122b7e3 | 576 | |
c6c593e8 RD |
577 | |
578 | wxHtmlOpeningStatus wxPyHtmlWindow::OnOpeningURL(wxHtmlURLType type, | |
579 | const wxString& url, | |
580 | wxString *redirect) const { | |
581 | bool found; | |
582 | wxHtmlOpeningStatus rval; | |
583 | wxPyBeginBlockThreads(); | |
584 | if ((found = wxPyCBH_findCallback(m_myInst, "OnOpeningURL"))) { | |
585 | PyObject* ro; | |
a66212dc RD |
586 | PyObject* s = wx2PyString(url); |
587 | ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iO)", type, s)); | |
588 | Py_DECREF(s); | |
c6c593e8 RD |
589 | if (PyString_Check(ro) |
590 | #if PYTHON_API_VERSION >= 1009 | |
591 | || PyUnicode_Check(ro) | |
592 | #endif | |
593 | ) { | |
a541c325 | 594 | *redirect = Py2wxString(ro); |
c6c593e8 RD |
595 | rval = wxHTML_REDIRECT; |
596 | } | |
597 | else { | |
598 | PyObject* num = PyNumber_Int(ro); | |
599 | rval = (wxHtmlOpeningStatus)PyInt_AsLong(num); | |
600 | Py_DECREF(num); | |
601 | } | |
602 | Py_DECREF(ro); | |
603 | } | |
604 | wxPyEndBlockThreads(); | |
605 | if (! found) | |
606 | rval = wxHtmlWindow::OnOpeningURL(type, url, redirect); | |
607 | return rval; | |
608 | } | |
609 | ||
610 | ||
0f66a9f3 RD |
611 | %} |
612 | ||
613 | ||
95837b4d | 614 | |
0f66a9f3 RD |
615 | %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow { |
616 | public: | |
617 | wxPyHtmlWindow(wxWindow *parent, int id = -1, | |
1e7ecb7b RD |
618 | wxPoint& pos = wxDefaultPosition, |
619 | wxSize& size = wxDefaultSize, | |
fc51b8c3 | 620 | int style=wxHW_SCROLLBAR_AUTO, |
137b5242 | 621 | const wxString& name = wxPyHtmlWindowNameStr); |
7b7ac0ab RD |
622 | %name(wxPreHtmlWindow)wxPyHtmlWindow(); |
623 | ||
624 | bool Create(wxWindow *parent, int id = -1, | |
625 | wxPoint& pos = wxDefaultPosition, | |
626 | wxSize& size = wxDefaultSize, | |
fc51b8c3 | 627 | int style=wxHW_SCROLLBAR_AUTO, |
137b5242 | 628 | const wxString& name = wxPyHtmlWindowNameStr); |
7b7ac0ab | 629 | |
0f66a9f3 | 630 | |
0122b7e3 RD |
631 | void _setCallbackInfo(PyObject* self, PyObject* _class); |
632 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxHtmlWindow)" | |
0122b7e3 | 633 | %pragma(python) addtomethod = "__init__:self._setOORInfo(self)" |
7b7ac0ab | 634 | %pragma(python) addtomethod = "wxPreHtmlWindow:val._setOORInfo(val)" |
0f66a9f3 | 635 | |
1e4a197e RD |
636 | // Set HTML page and display it. !! source is HTML document itself, |
637 | // it is NOT address/filename of HTML document. If you want to | |
638 | // specify document location, use LoadPage() istead | |
639 | // Return value : FALSE if an error occured, TRUE otherwise | |
7a446686 | 640 | bool SetPage(const wxString& source); |
1e4a197e RD |
641 | |
642 | // Load HTML page from given location. Location can be either | |
643 | // a) /usr/wxGTK2/docs/html/wx.htm | |
644 | // b) http://www.somewhere.uk/document.htm | |
645 | // c) ftp://ftp.somesite.cz/pub/something.htm | |
646 | // In case there is no prefix (http:,ftp:), the method | |
647 | // will try to find it itself (1. local file, then http or ftp) | |
648 | // After the page is loaded, the method calls SetPage() to display it. | |
649 | // Note : you can also use path relative to previously loaded page | |
650 | // Return value : same as SetPage | |
7a446686 | 651 | bool LoadPage(const wxString& location); |
1e4a197e | 652 | |
9cbf6f6e RD |
653 | // TODO: (accept a string, convert to filename) |
654 | // Loads HTML page from file | |
655 | // bool LoadFile(const wxFileName& filename); | |
656 | ||
1e4a197e | 657 | // Append to current page |
de112a55 | 658 | bool AppendToPage(const wxString& source); |
1e4a197e RD |
659 | |
660 | // Returns full location of opened page | |
0f66a9f3 | 661 | wxString GetOpenedPage(); |
1e4a197e RD |
662 | |
663 | // Returns anchor within opened page | |
7a446686 | 664 | wxString GetOpenedAnchor(); |
1e4a197e RD |
665 | |
666 | // Returns <TITLE> of opened page or empty string otherwise | |
7a446686 RD |
667 | wxString GetOpenedPageTitle(); |
668 | ||
1e4a197e RD |
669 | // Sets frame in which page title will be displayed. Format is format of |
670 | // frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s | |
137b5242 | 671 | void SetRelatedFrame(wxFrame* frame, const wxString& format); |
0f66a9f3 | 672 | wxFrame* GetRelatedFrame(); |
1e4a197e RD |
673 | |
674 | // After(!) calling SetRelatedFrame, this sets statusbar slot where messages | |
675 | // will be displayed. Default is -1 = no messages. | |
0f66a9f3 | 676 | void SetRelatedStatusBar(int bar); |
f6bcfd97 | 677 | |
1e4a197e | 678 | // Sets fonts to be used when displaying HTML page. |
f6bcfd97 | 679 | %addmethods { |
9cbf6f6e RD |
680 | void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) { |
681 | int* temp = NULL; | |
682 | if (sizes) temp = int_LIST_helper(sizes); | |
683 | self->SetFonts(normal_face, fixed_face, temp); | |
684 | if (temp) | |
f6bcfd97 | 685 | delete [] temp; |
f6bcfd97 BP |
686 | } |
687 | } | |
688 | ||
7a446686 | 689 | void SetTitle(const wxString& title); |
1e4a197e RD |
690 | |
691 | // Sets space between text and window borders. | |
0f66a9f3 | 692 | void SetBorders(int b); |
1e4a197e RD |
693 | |
694 | // Saves custom settings into cfg config. it will use the path 'path' | |
695 | // if given, otherwise it will save info into currently selected path. | |
696 | // saved values : things set by SetFonts, SetBorders. | |
137b5242 RD |
697 | void ReadCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString); |
698 | void WriteCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString); | |
1e4a197e RD |
699 | |
700 | // Goes to previous/next page (in browsing history) | |
701 | // Returns TRUE if successful, FALSE otherwise | |
0f66a9f3 RD |
702 | bool HistoryBack(); |
703 | bool HistoryForward(); | |
7a446686 RD |
704 | bool HistoryCanBack(); |
705 | bool HistoryCanForward(); | |
1e4a197e RD |
706 | |
707 | // Resets History | |
0f66a9f3 | 708 | void HistoryClear(); |
1e4a197e RD |
709 | |
710 | // Returns pointer to conteiners/cells structure. | |
a65c6e14 | 711 | wxHtmlContainerCell* GetInternalRepresentation(); |
1e4a197e RD |
712 | |
713 | // Returns a pointer to the parser. | |
e166644c RD |
714 | wxHtmlWinParser* GetParser(); |
715 | ||
e5d41db0 RD |
716 | bool ScrollToAnchor(const wxString& anchor); |
717 | bool HasAnchor(const wxString& anchor); | |
718 | ||
1e4a197e RD |
719 | //Adds input filter |
720 | static void AddFilter(wxPyHtmlFilter *filter); | |
721 | ||
722 | ||
c8bc03c3 | 723 | void base_OnLinkClicked(const wxHtmlLinkInfo& link); |
137b5242 | 724 | void base_OnSetTitle(const wxString& title); |
0122b7e3 RD |
725 | void base_OnCellMouseHover(wxHtmlCell *cell, wxCoord x, wxCoord y); |
726 | void base_OnCellClicked(wxHtmlCell *cell, | |
727 | wxCoord x, wxCoord y, | |
728 | const wxMouseEvent& event); | |
4b123bb9 HH |
729 | }; |
730 | ||
5ca24bf4 | 731 | |
5ca24bf4 | 732 | |
dc2f8a65 RD |
733 | //--------------------------------------------------------------------------- |
734 | //--------------------------------------------------------------------------- | |
735 | ||
736 | ||
9416aa89 | 737 | class wxHtmlDCRenderer : public wxObject { |
dc2f8a65 RD |
738 | public: |
739 | wxHtmlDCRenderer(); | |
740 | ~wxHtmlDCRenderer(); | |
741 | ||
742 | void SetDC(wxDC *dc, int maxwidth); | |
743 | void SetSize(int width, int height); | |
744 | void SetHtmlText(const wxString& html, | |
137b5242 | 745 | const wxString& basepath = wxPyEmptyString, |
dc2f8a65 | 746 | bool isdir = TRUE); |
9cbf6f6e RD |
747 | %addmethods { |
748 | void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) { | |
749 | int* temp = NULL; | |
750 | if (sizes) temp = int_LIST_helper(sizes); | |
751 | self->SetFonts(normal_face, fixed_face, temp); | |
752 | if (temp) | |
753 | delete [] temp; | |
754 | } | |
755 | } | |
dc2f8a65 RD |
756 | int Render(int x, int y, int from = 0, int dont_render = FALSE); |
757 | int GetTotalHeight(); | |
758 | // returns total height of the html document | |
759 | // (compare Render's return value with this) | |
760 | }; | |
761 | ||
762 | enum { | |
763 | wxPAGE_ODD, | |
764 | wxPAGE_EVEN, | |
765 | wxPAGE_ALL | |
766 | }; | |
767 | ||
768 | ||
769 | class wxHtmlPrintout : public wxPyPrintout { | |
770 | public: | |
137b5242 | 771 | wxHtmlPrintout(const wxString& title = wxPyHtmlPrintoutTitleStr); |
f3d9dc1d | 772 | //~wxHtmlPrintout(); wxPrintPreview object takes ownership... |
dc2f8a65 RD |
773 | |
774 | void SetHtmlText(const wxString& html, | |
137b5242 | 775 | const wxString &basepath = wxPyEmptyString, |
dc2f8a65 RD |
776 | bool isdir = TRUE); |
777 | void SetHtmlFile(const wxString &htmlfile); | |
778 | void SetHeader(const wxString& header, int pg = wxPAGE_ALL); | |
779 | void SetFooter(const wxString& footer, int pg = wxPAGE_ALL); | |
9cbf6f6e RD |
780 | %addmethods { |
781 | void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) { | |
782 | int* temp = NULL; | |
783 | if (sizes) temp = int_LIST_helper(sizes); | |
784 | self->SetFonts(normal_face, fixed_face, temp); | |
785 | if (temp) | |
786 | delete [] temp; | |
787 | } | |
788 | } | |
dc2f8a65 RD |
789 | void SetMargins(float top = 25.2, float bottom = 25.2, |
790 | float left = 25.2, float right = 25.2, | |
791 | float spaces = 5); | |
792 | }; | |
793 | ||
794 | ||
795 | ||
9416aa89 | 796 | class wxHtmlEasyPrinting : public wxObject { |
dc2f8a65 | 797 | public: |
137b5242 | 798 | wxHtmlEasyPrinting(const wxString& name = wxPyHtmlPrintingTitleStr, |
dc2f8a65 RD |
799 | wxFrame *parent_frame = NULL); |
800 | ~wxHtmlEasyPrinting(); | |
801 | ||
802 | void PreviewFile(const wxString &htmlfile); | |
137b5242 | 803 | void PreviewText(const wxString &htmltext, const wxString& basepath = wxPyEmptyString); |
dc2f8a65 | 804 | void PrintFile(const wxString &htmlfile); |
137b5242 | 805 | void PrintText(const wxString &htmltext, const wxString& basepath = wxPyEmptyString); |
dc2f8a65 RD |
806 | void PrinterSetup(); |
807 | void PageSetup(); | |
808 | void SetHeader(const wxString& header, int pg = wxPAGE_ALL); | |
809 | void SetFooter(const wxString& footer, int pg = wxPAGE_ALL); | |
810 | ||
9cbf6f6e RD |
811 | %addmethods { |
812 | void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) { | |
813 | int* temp = NULL; | |
814 | if (sizes) temp = int_LIST_helper(sizes); | |
815 | self->SetFonts(normal_face, fixed_face, temp); | |
816 | if (temp) | |
817 | delete [] temp; | |
818 | } | |
819 | } | |
820 | ||
dc2f8a65 RD |
821 | wxPrintData *GetPrintData() {return m_PrintData;} |
822 | wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;} | |
823 | ||
824 | }; | |
825 | ||
826 | ||
827 | ||
0f66a9f3 RD |
828 | //--------------------------------------------------------------------------- |
829 | //--------------------------------------------------------------------------- | |
5ca24bf4 | 830 | |
0f66a9f3 RD |
831 | %{ |
832 | extern "C" SWIGEXPORT(void) inithtmlhelpc(); | |
833 | %} | |
4b123bb9 | 834 | |
4b123bb9 HH |
835 | |
836 | %init %{ | |
837 | ||
2f90df85 | 838 | inithtmlhelpc(); |
0f66a9f3 | 839 | |
e508a2b6 RD |
840 | wxClassInfo::CleanUpClasses(); |
841 | wxClassInfo::InitializeClasses(); | |
9416aa89 RD |
842 | |
843 | wxPyPtrTypeMap_Add("wxHtmlTagHandler", "wxPyHtmlTagHandler"); | |
844 | wxPyPtrTypeMap_Add("wxHtmlWinTagHandler", "wxPyHtmlWinTagHandler"); | |
845 | wxPyPtrTypeMap_Add("wxHtmlWindow", "wxPyHtmlWindow"); | |
1e4a197e | 846 | wxPyPtrTypeMap_Add("wxHtmlFilter", "wxPyHtmlFilter"); |
4b123bb9 HH |
847 | %} |
848 | ||
e166644c RD |
849 | //---------------------------------------------------------------------- |
850 | // And this gets appended to the shadow class file. | |
851 | //---------------------------------------------------------------------- | |
852 | ||
f6bcfd97 | 853 | %pragma(python) include="_htmlextras.py"; |
e166644c | 854 | |
4b123bb9 | 855 | //--------------------------------------------------------------------------- |