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