]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/html.i
no changes, testing cvs logging
[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%{
17#include "helpers.h"
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>
dc2f8a65
RD
24
25#include "printfw.h"
4b123bb9
HH
26%}
27
28//---------------------------------------------------------------------------
29
30%include typemaps.i
31%include my_typemaps.i
32
33%extern wx.i
34%extern windows.i
35%extern _defs.i
36%extern events.i
5ca24bf4
HH
37%extern controls.i
38%extern controls2.i
dc2f8a65 39%extern printfw.i
4b123bb9 40
0f66a9f3
RD
41%extern utils.i
42
43//---------------------------------------------------------------------------
44
4b123bb9 45%{
f6bcfd97
BP
46// #ifdef __WXMSW__
47// wxString wxPyEmptyStr("");
48// wxPoint wxPyDefaultPosition(wxDefaultPosition);
49// wxSize wxPyDefaultSize(wxDefaultSize);
50// #endif
4b123bb9
HH
51%}
52
2f90df85 53%pragma(python) code = "import wx"
4b123bb9 54
4b123bb9 55
0f66a9f3 56//---------------------------------------------------------------------------
e166644c
RD
57
58enum {
9d8bd15f
RD
59 wxHTML_ALIGN_LEFT,
60 wxHTML_ALIGN_CENTER,
61 wxHTML_ALIGN_RIGHT,
62 wxHTML_ALIGN_BOTTOM,
63 wxHTML_ALIGN_TOP,
64
65 wxHTML_CLR_FOREGROUND,
66 wxHTML_CLR_BACKGROUND,
67
68 wxHTML_UNITS_PIXELS,
69 wxHTML_UNITS_PERCENT,
70
71 wxHTML_INDENT_LEFT,
72 wxHTML_INDENT_RIGHT,
73 wxHTML_INDENT_TOP,
74 wxHTML_INDENT_BOTTOM,
75
76 wxHTML_INDENT_HORIZONTAL,
77 wxHTML_INDENT_VERTICAL,
78 wxHTML_INDENT_ALL,
79
80 wxHTML_COND_ISANCHOR,
81 wxHTML_COND_ISIMAGEMAP,
82 wxHTML_COND_USER,
e166644c
RD
83};
84
85
9c00cfa3
RD
86//---------------------------------------------------------------------------
87
88class wxHtmlLinkInfo {
89public:
90 wxHtmlLinkInfo(const wxString& href, const wxString& target = wxEmptyString);
91 wxString GetHref();
92 wxString GetTarget();
c8bc03c3
RD
93 wxMouseEvent* GetEvent();
94 wxHtmlCell* GetHtmlCell();
9c00cfa3
RD
95};
96
0f66a9f3
RD
97//---------------------------------------------------------------------------
98
99class wxHtmlTag {
100public:
e166644c 101 // Never need to create a new tag from Python...
0f66a9f3
RD
102 //wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
103
104 wxString GetName();
105 bool HasParam(const wxString& par);
106 wxString GetParam(const wxString& par, int with_commas = FALSE);
107
108 // Can't do this one as-is, but GetParam should be enough...
109 //int ScanParam(const wxString& par, const char *format, void* param);
110
111 wxString GetAllParams();
112 bool IsEnding();
113 bool HasEnding();
114 int GetBeginPos();
115 int GetEndPos1();
116 int GetEndPos2();
117};
118
119
120//---------------------------------------------------------------------------
121
122class wxHtmlParser {
123public:
124 // wxHtmlParser(); This is an abstract base class...
125
126 void SetFS(wxFileSystem *fs);
127 wxFileSystem* GetFS();
128 wxObject* Parse(const wxString& source);
129 void InitParser(const wxString& source);
130 void DoneParser();
131 void DoParsing(int begin_pos, int end_pos);
132 // wxObject* GetProduct();
133 void AddTagHandler(wxHtmlTagHandler *handler);
134 wxString* GetSource();
dc2f8a65
RD
135 void PushTagHandler(wxHtmlTagHandler* handler, wxString tags);
136 void PopTagHandler();
0f66a9f3
RD
137
138
139 // void AddText(const char* txt) = 0;
140 // void AddTag(const wxHtmlTag& tag);
141};
142
143
144//---------------------------------------------------------------------------
145
146class wxHtmlWinParser : public wxHtmlParser {
147public:
148 wxHtmlWinParser(wxWindow *wnd);
149
150 void SetDC(wxDC *dc);
151 wxDC* GetDC();
152 int GetCharHeight();
153 int GetCharWidth();
154 wxWindow* GetWindow();
f6bcfd97
BP
155 //void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
156 %addmethods {
157 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes) {
158 int* temp = int_LIST_helper(sizes);
159 if (temp) {
160 self->SetFonts(normal_face, fixed_face, temp);
161 delete [] temp;
162 }
163 }
164 }
0f66a9f3
RD
165
166 wxHtmlContainerCell* GetContainer();
167 wxHtmlContainerCell* OpenContainer();
dc2f8a65 168 wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
0f66a9f3 169 wxHtmlContainerCell* CloseContainer();
dc2f8a65 170
0f66a9f3
RD
171 int GetFontSize();
172 void SetFontSize(int s);
173 int GetFontBold();
174 void SetFontBold(int x);
175 int GetFontItalic();
176 void SetFontItalic(int x);
177 int GetFontUnderlined();
178 void SetFontUnderlined(int x);
179 int GetFontFixed();
180 void SetFontFixed(int x);
181 int GetAlign();
182 void SetAlign(int a);
183 const wxColour& GetLinkColor();
184 void SetLinkColor(const wxColour& clr);
185 const wxColour& GetActualColor();
186 void SetActualColor(const wxColour& clr);
0f66a9f3
RD
187 void SetLink(const wxString& link);
188 wxFont* CreateCurrentFont();
9c00cfa3
RD
189 wxHtmlLinkInfo GetLink();
190
0f66a9f3
RD
191};
192
193
194
195//---------------------------------------------------------------------------
196
197%{
198class wxPyHtmlTagHandler : public wxHtmlTagHandler {
199public:
200 wxPyHtmlTagHandler() : wxHtmlTagHandler() {};
201
202 wxHtmlParser* GetParser() { return m_Parser; }
203 void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); }
204
205 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
206 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
207
208 PYPRIVATE;
209};
210
211IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
212IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
0f66a9f3
RD
213%}
214
215
216%name(wxHtmlTagHandler) class wxPyHtmlTagHandler {
217public:
218 wxPyHtmlTagHandler();
219
f6bcfd97
BP
220 void _setSelf(PyObject* self, PyObject* _class);
221 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxHtmlTagHandler)"
0f66a9f3
RD
222
223 void SetParser(wxHtmlParser *parser);
224 wxHtmlParser* GetParser();
225 void ParseInner(const wxHtmlTag& tag);
226};
227
228
229//---------------------------------------------------------------------------
230
231%{
232class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
233public:
234 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
235
236 wxHtmlWinParser* GetParser() { return m_WParser; }
237 void ParseInner(const wxHtmlTag& tag)
238 { wxHtmlWinTagHandler::ParseInner(tag); }
239
240 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
241 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
242
243 PYPRIVATE;
244};
245
246IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
247IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
0f66a9f3
RD
248%}
249
250
251%name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
252public:
253 wxPyHtmlWinTagHandler();
254
f6bcfd97
BP
255 void _setSelf(PyObject* self, PyObject* _class);
256 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxHtmlWinTagHandler)"
0f66a9f3
RD
257
258 void SetParser(wxHtmlParser *parser);
259 wxHtmlWinParser* GetParser();
260 void ParseInner(const wxHtmlTag& tag);
261};
262
263
264//---------------------------------------------------------------------------
265
266%{
267
268class wxPyHtmlTagsModule : public wxHtmlTagsModule {
269public:
270 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
271 m_tagHandlerClass = thc;
272 Py_INCREF(m_tagHandlerClass);
273 RegisterModule(this);
274 wxHtmlWinParser::AddModule(this);
275 }
276
277 void OnExit() {
278 Py_DECREF(m_tagHandlerClass);
279 m_tagHandlerClass = NULL;
dc2f8a65 280 for (size_t x=0; x < m_objArray.GetCount(); x++) {
0f66a9f3
RD
281 PyObject* obj = (PyObject*)m_objArray.Item(x);
282 Py_DECREF(obj);
283 }
284 };
285
286 void FillHandlersTable(wxHtmlWinParser *parser) {
287 // Wave our magic wand... (if it works it's a miracle! ;-)
288
289 // First, make a new instance of the tag handler
e166644c 290 bool doSave = wxPyRestoreThread();
0f66a9f3
RD
291 PyObject* arg = Py_BuildValue("()");
292 PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
293 Py_DECREF(arg);
e166644c 294 wxPySaveThread(doSave);
0f66a9f3
RD
295
296 // now figure out where it's C++ object is...
297 wxPyHtmlWinTagHandler* thPtr;
298 if (SWIG_GetPtrObj(obj, (void **)&thPtr, "_wxPyHtmlWinTagHandler_p"))
299 return;
300
301 // add it,
302 parser->AddTagHandler(thPtr);
303
304 // and track it.
305 m_objArray.Add(obj);
306 }
307
308private:
309 PyObject* m_tagHandlerClass;
310 wxArrayPtrVoid m_objArray;
311
312};
313%}
314
315
316
317%inline %{
318 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
319 // Dynamically create a new wxModule. Refcounts tagHandlerClass
320 // and adds itself to the wxModules list and to the wxHtmlWinParser.
321 new wxPyHtmlTagsModule(tagHandlerClass);
322 }
323%}
324
dc2f8a65 325
e166644c
RD
326//---------------------------------------------------------------------------
327//---------------------------------------------------------------------------
328
329class wxHtmlCell {
330public:
331 wxHtmlCell();
332
e166644c
RD
333 int GetPosX();
334 int GetPosY();
335 int GetWidth();
336 int GetHeight();
337 int GetDescent();
9c00cfa3 338 wxHtmlLinkInfo* GetLink(int x = 0, int y = 0);
e166644c 339 wxHtmlCell* GetNext();
9c00cfa3
RD
340 wxHtmlContainerCell* GetParent();
341 void SetLink(const wxHtmlLinkInfo& link);
e166644c 342 void SetNext(wxHtmlCell *cell);
9c00cfa3
RD
343 void SetParent(wxHtmlContainerCell *p);
344 void SetPos(int x, int y);
e166644c
RD
345 void Layout(int w);
346 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
347 void DrawInvisible(wxDC& dc, int x, int y);
348 const wxHtmlCell* Find(int condition, const void* param);
dc2f8a65
RD
349
350 bool AdjustPagebreak(int * pagebreak);
351 void SetCanLiveOnPagebreak(bool can);
9c00cfa3 352
e166644c
RD
353};
354
355
356class wxHtmlContainerCell : public wxHtmlCell {
357public:
358 wxHtmlContainerCell(wxHtmlContainerCell *parent);
359
360 void InsertCell(wxHtmlCell *cell);
361 void SetAlignHor(int al);
362 int GetAlignHor();
363 void SetAlignVer(int al);
364 int GetAlignVer();
9d8bd15f 365 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
e166644c
RD
366 int GetIndent(int ind);
367 int GetIndentUnits(int ind);
368 void SetAlign(const wxHtmlTag& tag);
369 void SetWidthFloat(int w, int units);
370 %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
9d8bd15f 371 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
e166644c
RD
372 void SetBackgroundColour(const wxColour& clr);
373 void SetBorder(const wxColour& clr1, const wxColour& clr2);
374 wxHtmlCell* GetFirstCell();
375};
376
377
378
9c00cfa3
RD
379class wxHtmlColourCell : public wxHtmlCell {
380public:
381 wxHtmlColourCell(wxColour clr, int flags = wxHTML_CLR_FOREGROUND);
382
383};
384
385
e166644c
RD
386
387class wxHtmlWidgetCell : public wxHtmlCell {
388public:
389 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
390
391};
392
0f66a9f3
RD
393
394
395//---------------------------------------------------------------------------
396//---------------------------------------------------------------------------
4b123bb9
HH
397//---------------------------------------------------------------------------
398
399// item of history list
0f66a9f3
RD
400class HtmlHistoryItem {
401public:
402 HtmlHistoryItem(const char* p, const char* a);
403
404 int GetPos();
405 void SetPos(int p);
406 const wxString& GetPage();
407 const wxString& GetAnchor();
4b123bb9
HH
408};
409
0f66a9f3
RD
410
411//---------------------------------------------------------------------------
412%{
413class wxPyHtmlWindow : public wxHtmlWindow {
414public:
415 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
416 const wxPoint& pos = wxDefaultPosition,
417 const wxSize& size = wxDefaultSize,
418 long style = wxHW_SCROLLBAR_AUTO,
419 const wxString& name = "htmlWindow")
420 : wxHtmlWindow(parent, id, pos, size, style, name) {};
421
c8bc03c3
RD
422 void OnLinkClicked(const wxHtmlLinkInfo& link);
423 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
9c00cfa3
RD
424
425 DEC_PYCALLBACK__STRING(OnSetTitle);
0f66a9f3
RD
426 PYPRIVATE;
427};
428
95837b4d 429
9c00cfa3 430IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
0f66a9f3 431
8e425133 432 void wxPyHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) {
9c00cfa3
RD
433 bool doSave = wxPyRestoreThread();
434 if (m_myInst.findCallback("OnLinkClicked")) {
c8bc03c3 435 PyObject* obj = wxPyConstructObject((void*)&link, "wxHtmlLinkInfo");
9c00cfa3
RD
436 m_myInst.callCallback(Py_BuildValue("(O)", obj));
437 }
438 else
439 wxHtmlWindow::OnLinkClicked(link);
440 wxPySaveThread(doSave);
441}
c8bc03c3 442void wxPyHtmlWindow::base_OnLinkClicked(const wxHtmlLinkInfo& link) {
9c00cfa3
RD
443 wxHtmlWindow::OnLinkClicked(link);
444}
0f66a9f3
RD
445%}
446
447
95837b4d 448
0f66a9f3
RD
449%name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
450public:
451 wxPyHtmlWindow(wxWindow *parent, int id = -1,
452 wxPoint& pos = wxPyDefaultPosition,
453 wxSize& size = wxPyDefaultSize,
454 int flags=wxHW_SCROLLBAR_AUTO,
455 char* name = "htmlWindow");
456
f6bcfd97
BP
457 void _setSelf(PyObject* self, PyObject* _class);
458 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxHtmlWindow)"
459 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
460 %pragma(python) addtomethod = "__init__:#wx._StdOnScrollCallbacks(self)"
0f66a9f3
RD
461
462
463 bool SetPage(const char* source);
0f66a9f3 464 bool LoadPage(const char* location);
0f66a9f3 465 wxString GetOpenedPage();
0f66a9f3 466 void SetRelatedFrame(wxFrame* frame, const char* format);
0f66a9f3 467 wxFrame* GetRelatedFrame();
0f66a9f3 468 void SetRelatedStatusBar(int bar);
f6bcfd97
BP
469
470 //void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
471 %addmethods {
472 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes) {
473 int* temp = int_LIST_helper(sizes);
474 if (temp) {
475 self->SetFonts(normal_face, fixed_face, temp);
476 delete [] temp;
477 }
478 }
479 }
480
0f66a9f3 481 void SetTitle(const char* title);
0f66a9f3 482 void SetBorders(int b);
0f66a9f3 483 void ReadCustomization(wxConfigBase *cfg, char* path = "");
0f66a9f3 484 void WriteCustomization(wxConfigBase *cfg, char* path = "");
0f66a9f3
RD
485 bool HistoryBack();
486 bool HistoryForward();
0f66a9f3 487 void HistoryClear();
a65c6e14 488 wxHtmlContainerCell* GetInternalRepresentation();
e166644c
RD
489 wxHtmlWinParser* GetParser();
490
c8bc03c3 491 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
9c00cfa3 492 void base_OnSetTitle(const char* title);
4b123bb9
HH
493};
494
0f66a9f3
RD
495// Static methods are mapped to stand-alone functions
496%inline %{
497 void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) {
498 wxHtmlWindow::AddFilter(filter);
499 }
500%}
5ca24bf4 501
5ca24bf4 502
dc2f8a65
RD
503//---------------------------------------------------------------------------
504//---------------------------------------------------------------------------
505
506
507class wxHtmlDCRenderer {
508public:
509 wxHtmlDCRenderer();
510 ~wxHtmlDCRenderer();
511
512 void SetDC(wxDC *dc, int maxwidth);
513 void SetSize(int width, int height);
514 void SetHtmlText(const wxString& html,
515 const wxString& basepath = wxEmptyString,
516 bool isdir = TRUE);
517 int Render(int x, int y, int from = 0, int dont_render = FALSE);
518 int GetTotalHeight();
519 // returns total height of the html document
520 // (compare Render's return value with this)
521};
522
523enum {
524 wxPAGE_ODD,
525 wxPAGE_EVEN,
526 wxPAGE_ALL
527};
528
529
530class wxHtmlPrintout : public wxPyPrintout {
531public:
65dd82cb 532 wxHtmlPrintout(const char* title = "Printout");
dc2f8a65
RD
533 ~wxHtmlPrintout();
534
535 void SetHtmlText(const wxString& html,
536 const wxString &basepath = wxEmptyString,
537 bool isdir = TRUE);
538 void SetHtmlFile(const wxString &htmlfile);
539 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
540 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
541 void SetMargins(float top = 25.2, float bottom = 25.2,
542 float left = 25.2, float right = 25.2,
543 float spaces = 5);
544};
545
546
547
548class wxHtmlEasyPrinting {
549public:
65dd82cb 550 wxHtmlEasyPrinting(const char* name = "Printing",
dc2f8a65
RD
551 wxFrame *parent_frame = NULL);
552 ~wxHtmlEasyPrinting();
553
554 void PreviewFile(const wxString &htmlfile);
555 void PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
556 void PrintFile(const wxString &htmlfile);
557 void PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
558 void PrinterSetup();
559 void PageSetup();
560 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
561 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
562
563 wxPrintData *GetPrintData() {return m_PrintData;}
564 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
565
566};
567
568
569
0f66a9f3
RD
570//---------------------------------------------------------------------------
571//---------------------------------------------------------------------------
5ca24bf4 572
0f66a9f3
RD
573%{
574 extern "C" SWIGEXPORT(void) inithtmlhelpc();
575%}
4b123bb9 576
4b123bb9
HH
577
578%init %{
579
2f90df85 580 inithtmlhelpc();
0f66a9f3 581
4b123bb9
HH
582 wxClassInfo::CleanUpClasses();
583 wxClassInfo::InitializeClasses();
584
4b123bb9
HH
585 // Until wxFileSystem is wrapped...
586 #if wxUSE_FS_ZIP
587 wxFileSystem::AddHandler(new wxZipFSHandler);
588 #endif
26b9cf27
RD
589 #if wxUSE_FS_INET
590// wxFileSystem::AddHandler(new wxInternetFSHandler);
591 #endif
4b123bb9
HH
592%}
593
e166644c
RD
594//----------------------------------------------------------------------
595// And this gets appended to the shadow class file.
596//----------------------------------------------------------------------
597
f6bcfd97 598%pragma(python) include="_htmlextras.py";
e166644c 599
4b123bb9 600//---------------------------------------------------------------------------
e166644c 601