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