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