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