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