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