]>
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: | |
1fded56b | 183 | wxHtmlWinParser(wxPyHtmlWindow *wnd = NULL); |
0f66a9f3 RD |
184 | |
185 | void SetDC(wxDC *dc); | |
186 | wxDC* GetDC(); | |
187 | int GetCharHeight(); | |
188 | int GetCharWidth(); | |
1fded56b RD |
189 | wxPyHtmlWindow* GetWindow(); |
190 | // Sets fonts to be used when displaying HTML page. (if size null then default sizes used). | |
f6bcfd97 | 191 | %addmethods { |
9cbf6f6e RD |
192 | void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) { |
193 | int* temp = NULL; | |
194 | if (sizes) temp = int_LIST_helper(sizes); | |
195 | self->SetFonts(normal_face, fixed_face, temp); | |
196 | if (temp) | |
f6bcfd97 | 197 | delete [] temp; |
f6bcfd97 BP |
198 | } |
199 | } | |
0f66a9f3 RD |
200 | |
201 | wxHtmlContainerCell* GetContainer(); | |
202 | wxHtmlContainerCell* OpenContainer(); | |
dc2f8a65 | 203 | wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c); |
0f66a9f3 | 204 | wxHtmlContainerCell* CloseContainer(); |
dc2f8a65 | 205 | |
0f66a9f3 RD |
206 | int GetFontSize(); |
207 | void SetFontSize(int s); | |
208 | int GetFontBold(); | |
209 | void SetFontBold(int x); | |
210 | int GetFontItalic(); | |
211 | void SetFontItalic(int x); | |
212 | int GetFontUnderlined(); | |
213 | void SetFontUnderlined(int x); | |
214 | int GetFontFixed(); | |
215 | void SetFontFixed(int x); | |
216 | int GetAlign(); | |
217 | void SetAlign(int a); | |
c5943253 | 218 | wxColour GetLinkColor(); |
0f66a9f3 | 219 | void SetLinkColor(const wxColour& clr); |
c5943253 | 220 | wxColour GetActualColor(); |
0f66a9f3 | 221 | void SetActualColor(const wxColour& clr); |
0f66a9f3 RD |
222 | void SetLink(const wxString& link); |
223 | wxFont* CreateCurrentFont(); | |
9c00cfa3 RD |
224 | wxHtmlLinkInfo GetLink(); |
225 | ||
0f66a9f3 RD |
226 | }; |
227 | ||
228 | ||
229 | ||
230 | //--------------------------------------------------------------------------- | |
231 | ||
232 | %{ | |
233 | class wxPyHtmlTagHandler : public wxHtmlTagHandler { | |
9416aa89 | 234 | DECLARE_DYNAMIC_CLASS(wxPyHtmlTagHandler); |
0f66a9f3 RD |
235 | public: |
236 | wxPyHtmlTagHandler() : wxHtmlTagHandler() {}; | |
237 | ||
238 | wxHtmlParser* GetParser() { return m_Parser; } | |
239 | void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); } | |
240 | ||
241 | DEC_PYCALLBACK_STRING__pure(GetSupportedTags); | |
242 | DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag); | |
243 | ||
244 | PYPRIVATE; | |
245 | }; | |
246 | ||
9416aa89 RD |
247 | IMPLEMENT_DYNAMIC_CLASS(wxPyHtmlTagHandler, wxHtmlTagHandler); |
248 | ||
0f66a9f3 RD |
249 | IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags); |
250 | IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag); | |
0f66a9f3 RD |
251 | %} |
252 | ||
253 | ||
9416aa89 | 254 | %name(wxHtmlTagHandler) class wxPyHtmlTagHandler : public wxObject { |
0f66a9f3 RD |
255 | public: |
256 | wxPyHtmlTagHandler(); | |
257 | ||
0122b7e3 RD |
258 | void _setCallbackInfo(PyObject* self, PyObject* _class); |
259 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxHtmlTagHandler)" | |
0f66a9f3 RD |
260 | |
261 | void SetParser(wxHtmlParser *parser); | |
262 | wxHtmlParser* GetParser(); | |
263 | void ParseInner(const wxHtmlTag& tag); | |
264 | }; | |
265 | ||
266 | ||
267 | //--------------------------------------------------------------------------- | |
268 | ||
269 | %{ | |
270 | class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler { | |
9416aa89 | 271 | DECLARE_DYNAMIC_CLASS(wxPyHtmlWinTagHandler); |
0f66a9f3 RD |
272 | public: |
273 | wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {}; | |
274 | ||
275 | wxHtmlWinParser* GetParser() { return m_WParser; } | |
276 | void ParseInner(const wxHtmlTag& tag) | |
277 | { wxHtmlWinTagHandler::ParseInner(tag); } | |
278 | ||
279 | DEC_PYCALLBACK_STRING__pure(GetSupportedTags); | |
280 | DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag); | |
281 | ||
282 | PYPRIVATE; | |
283 | }; | |
284 | ||
9416aa89 RD |
285 | IMPLEMENT_DYNAMIC_CLASS( wxPyHtmlWinTagHandler, wxHtmlWinTagHandler); |
286 | ||
0f66a9f3 RD |
287 | IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags); |
288 | IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag); | |
0f66a9f3 RD |
289 | %} |
290 | ||
291 | ||
292 | %name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler { | |
293 | public: | |
294 | wxPyHtmlWinTagHandler(); | |
295 | ||
0122b7e3 RD |
296 | void _setCallbackInfo(PyObject* self, PyObject* _class); |
297 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxHtmlWinTagHandler)" | |
0f66a9f3 RD |
298 | |
299 | void SetParser(wxHtmlParser *parser); | |
300 | wxHtmlWinParser* GetParser(); | |
301 | void ParseInner(const wxHtmlTag& tag); | |
302 | }; | |
303 | ||
304 | ||
305 | //--------------------------------------------------------------------------- | |
306 | ||
307 | %{ | |
308 | ||
309 | class wxPyHtmlTagsModule : public wxHtmlTagsModule { | |
310 | public: | |
311 | wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() { | |
312 | m_tagHandlerClass = thc; | |
313 | Py_INCREF(m_tagHandlerClass); | |
314 | RegisterModule(this); | |
315 | wxHtmlWinParser::AddModule(this); | |
316 | } | |
317 | ||
318 | void OnExit() { | |
4268f798 | 319 | wxPyBeginBlockThreads(); |
0f66a9f3 RD |
320 | Py_DECREF(m_tagHandlerClass); |
321 | m_tagHandlerClass = NULL; | |
dc2f8a65 | 322 | for (size_t x=0; x < m_objArray.GetCount(); x++) { |
0f66a9f3 RD |
323 | PyObject* obj = (PyObject*)m_objArray.Item(x); |
324 | Py_DECREF(obj); | |
325 | } | |
4268f798 | 326 | wxPyEndBlockThreads(); |
0f66a9f3 RD |
327 | }; |
328 | ||
329 | void FillHandlersTable(wxHtmlWinParser *parser) { | |
330 | // Wave our magic wand... (if it works it's a miracle! ;-) | |
331 | ||
332 | // First, make a new instance of the tag handler | |
4268f798 | 333 | wxPyBeginBlockThreads(); |
0f66a9f3 RD |
334 | PyObject* arg = Py_BuildValue("()"); |
335 | PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL); | |
336 | Py_DECREF(arg); | |
4268f798 | 337 | wxPyEndBlockThreads(); |
0f66a9f3 RD |
338 | |
339 | // now figure out where it's C++ object is... | |
340 | wxPyHtmlWinTagHandler* thPtr; | |
341 | if (SWIG_GetPtrObj(obj, (void **)&thPtr, "_wxPyHtmlWinTagHandler_p")) | |
342 | return; | |
343 | ||
344 | // add it, | |
345 | parser->AddTagHandler(thPtr); | |
346 | ||
347 | // and track it. | |
348 | m_objArray.Add(obj); | |
349 | } | |
350 | ||
351 | private: | |
352 | PyObject* m_tagHandlerClass; | |
353 | wxArrayPtrVoid m_objArray; | |
354 | ||
355 | }; | |
356 | %} | |
357 | ||
358 | ||
359 | ||
360 | %inline %{ | |
361 | void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) { | |
362 | // Dynamically create a new wxModule. Refcounts tagHandlerClass | |
363 | // and adds itself to the wxModules list and to the wxHtmlWinParser. | |
364 | new wxPyHtmlTagsModule(tagHandlerClass); | |
365 | } | |
366 | %} | |
367 | ||
dc2f8a65 | 368 | |
e166644c RD |
369 | //--------------------------------------------------------------------------- |
370 | //--------------------------------------------------------------------------- | |
371 | ||
dd116e73 RD |
372 | |
373 | // wxHtmlSelection is data holder with information about text selection. | |
374 | // Selection is defined by two positions (beginning and end of the selection) | |
375 | // and two leaf(!) cells at these positions. | |
376 | class wxHtmlSelection | |
377 | { | |
378 | public: | |
379 | wxHtmlSelection(); | |
380 | ~wxHtmlSelection(); | |
381 | ||
382 | void Set(const wxPoint& fromPos, const wxHtmlCell *fromCell, | |
383 | const wxPoint& toPos, const wxHtmlCell *toCell); | |
384 | %name(SetCells)void Set(const wxHtmlCell *fromCell, const wxHtmlCell *toCell); | |
385 | ||
386 | const wxHtmlCell *GetFromCell() const; | |
387 | const wxHtmlCell *GetToCell() const; | |
388 | ||
389 | // these values are in absolute coordinates: | |
390 | const wxPoint& GetFromPos() const; | |
391 | const wxPoint& GetToPos() const; | |
392 | ||
393 | // these are From/ToCell's private data | |
394 | const wxPoint& GetFromPrivPos() const; | |
395 | const wxPoint& GetToPrivPos() const; | |
396 | void SetFromPrivPos(const wxPoint& pos); | |
397 | void SetToPrivPos(const wxPoint& pos); | |
398 | void ClearPrivPos(); | |
399 | ||
400 | const bool IsEmpty() const; | |
401 | ||
402 | }; | |
403 | ||
404 | ||
405 | enum wxHtmlSelectionState | |
406 | { | |
407 | wxHTML_SEL_OUT, // currently rendered cell is outside the selection | |
408 | wxHTML_SEL_IN, // ... is inside selection | |
409 | wxHTML_SEL_CHANGING // ... is the cell on which selection state changes | |
410 | }; | |
411 | ||
412 | // Selection state is passed to wxHtmlCell::Draw so that it can render itself | |
413 | // differently e.g. when inside text selection or outside it. | |
414 | class wxHtmlRenderingState | |
415 | { | |
416 | public: | |
417 | wxHtmlRenderingState(); | |
418 | ~wxHtmlRenderingState(); | |
419 | ||
420 | void SetSelectionState(wxHtmlSelectionState s); | |
421 | wxHtmlSelectionState GetSelectionState() const; | |
422 | ||
423 | void SetFgColour(const wxColour& c); | |
424 | const wxColour& GetFgColour() const; | |
425 | void SetBgColour(const wxColour& c); | |
426 | const wxColour& GetBgColour() const; | |
427 | }; | |
428 | ||
429 | ||
430 | // HTML rendering customization. This class is used when rendering wxHtmlCells | |
431 | // as a callback: | |
432 | class wxHtmlRenderingStyle | |
433 | { | |
434 | public: | |
435 | virtual wxColour GetSelectedTextColour(const wxColour& clr) = 0; | |
436 | virtual wxColour GetSelectedTextBgColour(const wxColour& clr) = 0; | |
437 | }; | |
438 | ||
439 | // Standard style: | |
440 | class wxDefaultHtmlRenderingStyle : public wxHtmlRenderingStyle | |
441 | { | |
442 | public: | |
443 | virtual wxColour GetSelectedTextColour(const wxColour& clr); | |
444 | virtual wxColour GetSelectedTextBgColour(const wxColour& clr); | |
445 | }; | |
446 | ||
447 | ||
448 | ||
449 | // Information given to cells when drawing them. Contains rendering state, | |
450 | // selection information and rendering style object that can be used to | |
451 | // customize the output. | |
452 | class wxHtmlRenderingInfo | |
453 | { | |
454 | public: | |
455 | wxHtmlRenderingInfo(); | |
456 | ~wxHtmlRenderingInfo(); | |
457 | ||
458 | void SetSelection(wxHtmlSelection *s); | |
459 | wxHtmlSelection *GetSelection() const; | |
460 | ||
461 | void SetStyle(wxHtmlRenderingStyle *style); | |
462 | wxHtmlRenderingStyle& GetStyle(); | |
463 | ||
464 | wxHtmlRenderingState& GetState(); | |
465 | }; | |
466 | ||
467 | //--------------------------------------------------------------------------- | |
468 | ||
9416aa89 | 469 | class wxHtmlCell : public wxObject { |
e166644c RD |
470 | public: |
471 | wxHtmlCell(); | |
472 | ||
e166644c RD |
473 | int GetPosX(); |
474 | int GetPosY(); | |
475 | int GetWidth(); | |
476 | int GetHeight(); | |
477 | int GetDescent(); | |
9c00cfa3 | 478 | wxHtmlLinkInfo* GetLink(int x = 0, int y = 0); |
e166644c | 479 | wxHtmlCell* GetNext(); |
9c00cfa3 RD |
480 | wxHtmlContainerCell* GetParent(); |
481 | void SetLink(const wxHtmlLinkInfo& link); | |
e166644c | 482 | void SetNext(wxHtmlCell *cell); |
9c00cfa3 RD |
483 | void SetParent(wxHtmlContainerCell *p); |
484 | void SetPos(int x, int y); | |
e166644c | 485 | void Layout(int w); |
dd116e73 RD |
486 | void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2, |
487 | wxHtmlRenderingInfo& info); | |
488 | void DrawInvisible(wxDC& dc, int x, int y, | |
489 | wxHtmlRenderingInfo& info); | |
e166644c | 490 | const wxHtmlCell* Find(int condition, const void* param); |
dc2f8a65 | 491 | |
1fded56b | 492 | bool AdjustPagebreak(int* INOUT); |
dc2f8a65 | 493 | void SetCanLiveOnPagebreak(bool can); |
9c00cfa3 | 494 | |
e166644c RD |
495 | }; |
496 | ||
497 | ||
9416aa89 RD |
498 | class wxHtmlWordCell : public wxHtmlCell |
499 | { | |
500 | public: | |
501 | wxHtmlWordCell(const wxString& word, wxDC& dc); | |
502 | }; | |
503 | ||
504 | ||
e166644c RD |
505 | class wxHtmlContainerCell : public wxHtmlCell { |
506 | public: | |
507 | wxHtmlContainerCell(wxHtmlContainerCell *parent); | |
508 | ||
509 | void InsertCell(wxHtmlCell *cell); | |
510 | void SetAlignHor(int al); | |
511 | int GetAlignHor(); | |
512 | void SetAlignVer(int al); | |
513 | int GetAlignVer(); | |
9d8bd15f | 514 | void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS); |
e166644c RD |
515 | int GetIndent(int ind); |
516 | int GetIndentUnits(int ind); | |
517 | void SetAlign(const wxHtmlTag& tag); | |
518 | void SetWidthFloat(int w, int units); | |
519 | %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag); | |
9d8bd15f | 520 | void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP); |
e166644c | 521 | void SetBackgroundColour(const wxColour& clr); |
1e4a197e | 522 | wxColour GetBackgroundColour(); |
e166644c | 523 | void SetBorder(const wxColour& clr1, const wxColour& clr2); |
dd116e73 RD |
524 | wxHtmlCell* GetFirstChild(); |
525 | %pragma(python) addtoclass = "GetFirstCell = GetFirstChild" | |
e166644c RD |
526 | }; |
527 | ||
528 | ||
529 | ||
9c00cfa3 RD |
530 | class wxHtmlColourCell : public wxHtmlCell { |
531 | public: | |
532 | wxHtmlColourCell(wxColour clr, int flags = wxHTML_CLR_FOREGROUND); | |
533 | ||
534 | }; | |
535 | ||
536 | ||
9416aa89 RD |
537 | class wxHtmlFontCell : public wxHtmlCell |
538 | { | |
539 | public: | |
540 | wxHtmlFontCell(wxFont *font); | |
541 | }; | |
542 | ||
e166644c RD |
543 | |
544 | class wxHtmlWidgetCell : public wxHtmlCell { | |
545 | public: | |
546 | wxHtmlWidgetCell(wxWindow* wnd, int w = 0); | |
547 | ||
548 | }; | |
549 | ||
0f66a9f3 | 550 | |
0f66a9f3 | 551 | //--------------------------------------------------------------------------- |
1e4a197e RD |
552 | // wxHtmlFilter |
553 | //--------------------------------------------------------------------------- | |
554 | ||
555 | ||
556 | %{ // here's the C++ version | |
557 | class wxPyHtmlFilter : public wxHtmlFilter { | |
558 | DECLARE_ABSTRACT_CLASS(wxPyHtmlFilter); | |
559 | public: | |
560 | wxPyHtmlFilter() : wxHtmlFilter() {} | |
561 | ||
562 | // returns TRUE if this filter is able to open&read given file | |
563 | virtual bool CanRead(const wxFSFile& file) const { | |
564 | bool rval = FALSE; | |
565 | bool found; | |
566 | wxPyBeginBlockThreads(); | |
567 | if ((found = wxPyCBH_findCallback(m_myInst, "CanRead"))) { | |
568 | PyObject* obj = wxPyMake_wxObject((wxFSFile*)&file); // cast away const | |
569 | rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); | |
570 | Py_DECREF(obj); | |
571 | } | |
572 | wxPyEndBlockThreads(); | |
573 | return rval; | |
574 | } | |
575 | ||
576 | ||
577 | // Reads given file and returns HTML document. | |
578 | // Returns empty string if opening failed | |
579 | virtual wxString ReadFile(const wxFSFile& file) const { | |
580 | wxString rval; | |
581 | bool found; | |
582 | wxPyBeginBlockThreads(); | |
583 | if ((found = wxPyCBH_findCallback(m_myInst, "ReadFile"))) { | |
584 | PyObject* obj = wxPyMake_wxObject((wxFSFile*)&file); // cast away const | |
585 | PyObject* ro; | |
586 | ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(O)", obj)); | |
587 | Py_DECREF(obj); | |
588 | if (ro) { | |
589 | rval = Py2wxString(ro); | |
590 | Py_DECREF(ro); | |
591 | } | |
592 | } | |
593 | wxPyEndBlockThreads(); | |
594 | return rval; | |
595 | } | |
596 | ||
597 | PYPRIVATE; | |
598 | }; | |
599 | ||
600 | IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlFilter, wxHtmlFilter); | |
601 | %} | |
602 | ||
603 | ||
604 | // And now the version seen by SWIG | |
605 | ||
606 | %name(wxHtmlFilter) class wxPyHtmlFilter : public wxObject { | |
607 | public: | |
608 | wxPyHtmlFilter(); | |
609 | ||
610 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
611 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxHtmlFilter)" | |
612 | }; | |
613 | ||
614 | ||
615 | // TODO: wxHtmlFilterHTML | |
616 | ||
617 | ||
0f66a9f3 | 618 | //--------------------------------------------------------------------------- |
1e4a197e | 619 | // wxHtmlWindow |
4b123bb9 HH |
620 | //--------------------------------------------------------------------------- |
621 | ||
0f66a9f3 RD |
622 | %{ |
623 | class wxPyHtmlWindow : public wxHtmlWindow { | |
cdf14688 | 624 | DECLARE_ABSTRACT_CLASS(wxPyHtmlWindow); |
0f66a9f3 RD |
625 | public: |
626 | wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1, | |
627 | const wxPoint& pos = wxDefaultPosition, | |
628 | const wxSize& size = wxDefaultSize, | |
629 | long style = wxHW_SCROLLBAR_AUTO, | |
1e4a197e | 630 | const wxString& name = wxPyHtmlWindowNameStr) |
0f66a9f3 | 631 | : wxHtmlWindow(parent, id, pos, size, style, name) {}; |
7b7ac0ab | 632 | wxPyHtmlWindow() : wxHtmlWindow() {}; |
0f66a9f3 | 633 | |
e5d41db0 RD |
634 | bool ScrollToAnchor(const wxString& anchor) { |
635 | return wxHtmlWindow::ScrollToAnchor(anchor); | |
636 | } | |
637 | ||
638 | bool HasAnchor(const wxString& anchor) { | |
639 | const wxHtmlCell *c = m_Cell->Find(wxHTML_COND_ISANCHOR, &anchor); | |
640 | return c!=NULL; | |
641 | } | |
642 | ||
c8bc03c3 RD |
643 | void OnLinkClicked(const wxHtmlLinkInfo& link); |
644 | void base_OnLinkClicked(const wxHtmlLinkInfo& link); | |
9c00cfa3 | 645 | |
e5d41db0 | 646 | wxHtmlOpeningStatus OnOpeningURL(wxHtmlURLType type, |
c6c593e8 RD |
647 | const wxString& url, |
648 | wxString *redirect) const; | |
649 | ||
9c00cfa3 | 650 | DEC_PYCALLBACK__STRING(OnSetTitle); |
0122b7e3 RD |
651 | DEC_PYCALLBACK__CELLINTINT(OnCellMouseHover); |
652 | DEC_PYCALLBACK__CELLINTINTME(OnCellClicked); | |
0f66a9f3 RD |
653 | PYPRIVATE; |
654 | }; | |
655 | ||
cdf14688 | 656 | IMPLEMENT_ABSTRACT_CLASS( wxPyHtmlWindow, wxHtmlWindow ); |
9c00cfa3 | 657 | IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle); |
0122b7e3 RD |
658 | IMP_PYCALLBACK__CELLINTINT(wxPyHtmlWindow, wxHtmlWindow, OnCellMouseHover); |
659 | IMP_PYCALLBACK__CELLINTINTME(wxPyHtmlWindow, wxHtmlWindow, OnCellClicked); | |
660 | ||
0f66a9f3 | 661 | |
9416aa89 | 662 | void wxPyHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) { |
19a97bd6 | 663 | bool found; |
4268f798 | 664 | wxPyBeginBlockThreads(); |
0122b7e3 | 665 | if ((found = wxPyCBH_findCallback(m_myInst, "OnLinkClicked"))) { |
1e4a197e | 666 | PyObject* obj = wxPyConstructObject((void*)&link, wxT("wxHtmlLinkInfo"), 0); |
1e7ecb7b | 667 | wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); |
de20db99 | 668 | Py_DECREF(obj); |
9c00cfa3 | 669 | } |
4268f798 | 670 | wxPyEndBlockThreads(); |
19a97bd6 | 671 | if (! found) |
9c00cfa3 | 672 | wxHtmlWindow::OnLinkClicked(link); |
9c00cfa3 | 673 | } |
c8bc03c3 | 674 | void wxPyHtmlWindow::base_OnLinkClicked(const wxHtmlLinkInfo& link) { |
9c00cfa3 RD |
675 | wxHtmlWindow::OnLinkClicked(link); |
676 | } | |
0122b7e3 | 677 | |
c6c593e8 RD |
678 | |
679 | wxHtmlOpeningStatus wxPyHtmlWindow::OnOpeningURL(wxHtmlURLType type, | |
680 | const wxString& url, | |
681 | wxString *redirect) const { | |
682 | bool found; | |
683 | wxHtmlOpeningStatus rval; | |
684 | wxPyBeginBlockThreads(); | |
685 | if ((found = wxPyCBH_findCallback(m_myInst, "OnOpeningURL"))) { | |
686 | PyObject* ro; | |
a66212dc RD |
687 | PyObject* s = wx2PyString(url); |
688 | ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iO)", type, s)); | |
689 | Py_DECREF(s); | |
c6c593e8 RD |
690 | if (PyString_Check(ro) |
691 | #if PYTHON_API_VERSION >= 1009 | |
692 | || PyUnicode_Check(ro) | |
693 | #endif | |
694 | ) { | |
a541c325 | 695 | *redirect = Py2wxString(ro); |
c6c593e8 RD |
696 | rval = wxHTML_REDIRECT; |
697 | } | |
698 | else { | |
699 | PyObject* num = PyNumber_Int(ro); | |
700 | rval = (wxHtmlOpeningStatus)PyInt_AsLong(num); | |
701 | Py_DECREF(num); | |
702 | } | |
703 | Py_DECREF(ro); | |
704 | } | |
705 | wxPyEndBlockThreads(); | |
706 | if (! found) | |
707 | rval = wxHtmlWindow::OnOpeningURL(type, url, redirect); | |
708 | return rval; | |
709 | } | |
710 | ||
711 | ||
0f66a9f3 RD |
712 | %} |
713 | ||
714 | ||
95837b4d | 715 | |
0f66a9f3 RD |
716 | %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow { |
717 | public: | |
718 | wxPyHtmlWindow(wxWindow *parent, int id = -1, | |
1e7ecb7b RD |
719 | wxPoint& pos = wxDefaultPosition, |
720 | wxSize& size = wxDefaultSize, | |
fc51b8c3 | 721 | int style=wxHW_SCROLLBAR_AUTO, |
137b5242 | 722 | const wxString& name = wxPyHtmlWindowNameStr); |
7b7ac0ab RD |
723 | %name(wxPreHtmlWindow)wxPyHtmlWindow(); |
724 | ||
725 | bool Create(wxWindow *parent, int id = -1, | |
726 | wxPoint& pos = wxDefaultPosition, | |
727 | wxSize& size = wxDefaultSize, | |
fc51b8c3 | 728 | int style=wxHW_SCROLLBAR_AUTO, |
137b5242 | 729 | const wxString& name = wxPyHtmlWindowNameStr); |
7b7ac0ab | 730 | |
0f66a9f3 | 731 | |
0122b7e3 RD |
732 | void _setCallbackInfo(PyObject* self, PyObject* _class); |
733 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxHtmlWindow)" | |
0122b7e3 | 734 | %pragma(python) addtomethod = "__init__:self._setOORInfo(self)" |
7b7ac0ab | 735 | %pragma(python) addtomethod = "wxPreHtmlWindow:val._setOORInfo(val)" |
0f66a9f3 | 736 | |
1e4a197e RD |
737 | // Set HTML page and display it. !! source is HTML document itself, |
738 | // it is NOT address/filename of HTML document. If you want to | |
739 | // specify document location, use LoadPage() istead | |
740 | // Return value : FALSE if an error occured, TRUE otherwise | |
7a446686 | 741 | bool SetPage(const wxString& source); |
1e4a197e RD |
742 | |
743 | // Load HTML page from given location. Location can be either | |
744 | // a) /usr/wxGTK2/docs/html/wx.htm | |
745 | // b) http://www.somewhere.uk/document.htm | |
746 | // c) ftp://ftp.somesite.cz/pub/something.htm | |
747 | // In case there is no prefix (http:,ftp:), the method | |
748 | // will try to find it itself (1. local file, then http or ftp) | |
749 | // After the page is loaded, the method calls SetPage() to display it. | |
750 | // Note : you can also use path relative to previously loaded page | |
751 | // Return value : same as SetPage | |
7a446686 | 752 | bool LoadPage(const wxString& location); |
1e4a197e | 753 | |
9cbf6f6e | 754 | // Loads HTML page from file |
1fded56b | 755 | bool LoadFile(const wxString& filename); |
9cbf6f6e | 756 | |
1e4a197e | 757 | // Append to current page |
de112a55 | 758 | bool AppendToPage(const wxString& source); |
1e4a197e RD |
759 | |
760 | // Returns full location of opened page | |
0f66a9f3 | 761 | wxString GetOpenedPage(); |
1e4a197e RD |
762 | |
763 | // Returns anchor within opened page | |
7a446686 | 764 | wxString GetOpenedAnchor(); |
1e4a197e RD |
765 | |
766 | // Returns <TITLE> of opened page or empty string otherwise | |
7a446686 RD |
767 | wxString GetOpenedPageTitle(); |
768 | ||
1e4a197e RD |
769 | // Sets frame in which page title will be displayed. Format is format of |
770 | // frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s | |
137b5242 | 771 | void SetRelatedFrame(wxFrame* frame, const wxString& format); |
0f66a9f3 | 772 | wxFrame* GetRelatedFrame(); |
1e4a197e RD |
773 | |
774 | // After(!) calling SetRelatedFrame, this sets statusbar slot where messages | |
775 | // will be displayed. Default is -1 = no messages. | |
0f66a9f3 | 776 | void SetRelatedStatusBar(int bar); |
f6bcfd97 | 777 | |
1e4a197e | 778 | // Sets fonts to be used when displaying HTML page. |
f6bcfd97 | 779 | %addmethods { |
9cbf6f6e RD |
780 | void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) { |
781 | int* temp = NULL; | |
782 | if (sizes) temp = int_LIST_helper(sizes); | |
783 | self->SetFonts(normal_face, fixed_face, temp); | |
784 | if (temp) | |
f6bcfd97 | 785 | delete [] temp; |
f6bcfd97 BP |
786 | } |
787 | } | |
788 | ||
7a446686 | 789 | void SetTitle(const wxString& title); |
1e4a197e RD |
790 | |
791 | // Sets space between text and window borders. | |
0f66a9f3 | 792 | void SetBorders(int b); |
1e4a197e RD |
793 | |
794 | // Saves custom settings into cfg config. it will use the path 'path' | |
795 | // if given, otherwise it will save info into currently selected path. | |
796 | // saved values : things set by SetFonts, SetBorders. | |
137b5242 RD |
797 | void ReadCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString); |
798 | void WriteCustomization(wxConfigBase *cfg, wxString path = wxPyEmptyString); | |
1e4a197e RD |
799 | |
800 | // Goes to previous/next page (in browsing history) | |
801 | // Returns TRUE if successful, FALSE otherwise | |
0f66a9f3 RD |
802 | bool HistoryBack(); |
803 | bool HistoryForward(); | |
7a446686 RD |
804 | bool HistoryCanBack(); |
805 | bool HistoryCanForward(); | |
1e4a197e RD |
806 | |
807 | // Resets History | |
0f66a9f3 | 808 | void HistoryClear(); |
1e4a197e RD |
809 | |
810 | // Returns pointer to conteiners/cells structure. | |
a65c6e14 | 811 | wxHtmlContainerCell* GetInternalRepresentation(); |
1e4a197e RD |
812 | |
813 | // Returns a pointer to the parser. | |
e166644c RD |
814 | wxHtmlWinParser* GetParser(); |
815 | ||
e5d41db0 RD |
816 | bool ScrollToAnchor(const wxString& anchor); |
817 | bool HasAnchor(const wxString& anchor); | |
818 | ||
1e4a197e RD |
819 | //Adds input filter |
820 | static void AddFilter(wxPyHtmlFilter *filter); | |
821 | ||
822 | ||
c8bc03c3 | 823 | void base_OnLinkClicked(const wxHtmlLinkInfo& link); |
137b5242 | 824 | void base_OnSetTitle(const wxString& title); |
0122b7e3 RD |
825 | void base_OnCellMouseHover(wxHtmlCell *cell, wxCoord x, wxCoord y); |
826 | void base_OnCellClicked(wxHtmlCell *cell, | |
827 | wxCoord x, wxCoord y, | |
828 | const wxMouseEvent& event); | |
4b123bb9 HH |
829 | }; |
830 | ||
5ca24bf4 | 831 | |
5ca24bf4 | 832 | |
dc2f8a65 RD |
833 | //--------------------------------------------------------------------------- |
834 | //--------------------------------------------------------------------------- | |
835 | ||
836 | ||
9416aa89 | 837 | class wxHtmlDCRenderer : public wxObject { |
dc2f8a65 RD |
838 | public: |
839 | wxHtmlDCRenderer(); | |
840 | ~wxHtmlDCRenderer(); | |
841 | ||
842 | void SetDC(wxDC *dc, int maxwidth); | |
843 | void SetSize(int width, int height); | |
844 | void SetHtmlText(const wxString& html, | |
137b5242 | 845 | const wxString& basepath = wxPyEmptyString, |
dc2f8a65 | 846 | bool isdir = TRUE); |
1fded56b | 847 | // Sets fonts to be used when displaying HTML page. (if size null then default sizes used). |
9cbf6f6e RD |
848 | %addmethods { |
849 | void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) { | |
850 | int* temp = NULL; | |
851 | if (sizes) temp = int_LIST_helper(sizes); | |
852 | self->SetFonts(normal_face, fixed_face, temp); | |
853 | if (temp) | |
854 | delete [] temp; | |
855 | } | |
856 | } | |
dc2f8a65 RD |
857 | int Render(int x, int y, int from = 0, int dont_render = FALSE); |
858 | int GetTotalHeight(); | |
859 | // returns total height of the html document | |
860 | // (compare Render's return value with this) | |
861 | }; | |
862 | ||
863 | enum { | |
864 | wxPAGE_ODD, | |
865 | wxPAGE_EVEN, | |
866 | wxPAGE_ALL | |
867 | }; | |
868 | ||
869 | ||
870 | class wxHtmlPrintout : public wxPyPrintout { | |
871 | public: | |
137b5242 | 872 | wxHtmlPrintout(const wxString& title = wxPyHtmlPrintoutTitleStr); |
f3d9dc1d | 873 | //~wxHtmlPrintout(); wxPrintPreview object takes ownership... |
dc2f8a65 RD |
874 | |
875 | void SetHtmlText(const wxString& html, | |
137b5242 | 876 | const wxString &basepath = wxPyEmptyString, |
dc2f8a65 RD |
877 | bool isdir = TRUE); |
878 | void SetHtmlFile(const wxString &htmlfile); | |
879 | void SetHeader(const wxString& header, int pg = wxPAGE_ALL); | |
880 | void SetFooter(const wxString& footer, int pg = wxPAGE_ALL); | |
1fded56b | 881 | // Sets fonts to be used when displaying HTML page. (if size null then default sizes used). |
9cbf6f6e RD |
882 | %addmethods { |
883 | void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) { | |
884 | int* temp = NULL; | |
885 | if (sizes) temp = int_LIST_helper(sizes); | |
886 | self->SetFonts(normal_face, fixed_face, temp); | |
887 | if (temp) | |
888 | delete [] temp; | |
889 | } | |
890 | } | |
dc2f8a65 RD |
891 | void SetMargins(float top = 25.2, float bottom = 25.2, |
892 | float left = 25.2, float right = 25.2, | |
893 | float spaces = 5); | |
894 | }; | |
895 | ||
896 | ||
897 | ||
9416aa89 | 898 | class wxHtmlEasyPrinting : public wxObject { |
dc2f8a65 | 899 | public: |
137b5242 | 900 | wxHtmlEasyPrinting(const wxString& name = wxPyHtmlPrintingTitleStr, |
dc2f8a65 RD |
901 | wxFrame *parent_frame = NULL); |
902 | ~wxHtmlEasyPrinting(); | |
903 | ||
904 | void PreviewFile(const wxString &htmlfile); | |
137b5242 | 905 | void PreviewText(const wxString &htmltext, const wxString& basepath = wxPyEmptyString); |
dc2f8a65 | 906 | void PrintFile(const wxString &htmlfile); |
137b5242 | 907 | void PrintText(const wxString &htmltext, const wxString& basepath = wxPyEmptyString); |
dc2f8a65 RD |
908 | void PrinterSetup(); |
909 | void PageSetup(); | |
910 | void SetHeader(const wxString& header, int pg = wxPAGE_ALL); | |
911 | void SetFooter(const wxString& footer, int pg = wxPAGE_ALL); | |
912 | ||
9cbf6f6e RD |
913 | %addmethods { |
914 | void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes=NULL) { | |
915 | int* temp = NULL; | |
916 | if (sizes) temp = int_LIST_helper(sizes); | |
917 | self->SetFonts(normal_face, fixed_face, temp); | |
918 | if (temp) | |
919 | delete [] temp; | |
920 | } | |
921 | } | |
922 | ||
dc2f8a65 RD |
923 | wxPrintData *GetPrintData() {return m_PrintData;} |
924 | wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;} | |
925 | ||
926 | }; | |
927 | ||
928 | ||
929 | ||
0f66a9f3 RD |
930 | //--------------------------------------------------------------------------- |
931 | //--------------------------------------------------------------------------- | |
5ca24bf4 | 932 | |
0f66a9f3 RD |
933 | %{ |
934 | extern "C" SWIGEXPORT(void) inithtmlhelpc(); | |
935 | %} | |
4b123bb9 | 936 | |
4b123bb9 HH |
937 | |
938 | %init %{ | |
939 | ||
2f90df85 | 940 | inithtmlhelpc(); |
0f66a9f3 | 941 | |
e508a2b6 RD |
942 | wxClassInfo::CleanUpClasses(); |
943 | wxClassInfo::InitializeClasses(); | |
9416aa89 RD |
944 | |
945 | wxPyPtrTypeMap_Add("wxHtmlTagHandler", "wxPyHtmlTagHandler"); | |
946 | wxPyPtrTypeMap_Add("wxHtmlWinTagHandler", "wxPyHtmlWinTagHandler"); | |
947 | wxPyPtrTypeMap_Add("wxHtmlWindow", "wxPyHtmlWindow"); | |
1e4a197e | 948 | wxPyPtrTypeMap_Add("wxHtmlFilter", "wxPyHtmlFilter"); |
4b123bb9 HH |
949 | %} |
950 | ||
e166644c RD |
951 | //---------------------------------------------------------------------- |
952 | // And this gets appended to the shadow class file. | |
953 | //---------------------------------------------------------------------- | |
954 | ||
f6bcfd97 | 955 | %pragma(python) include="_htmlextras.py"; |
e166644c | 956 | |
4b123bb9 | 957 | //--------------------------------------------------------------------------- |