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