]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/html.i
ANSI 'C' fix (decs in "for" clauses no longer have any scope outside clause itself)
[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 "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 wxMouseEvent* GetEvent();
94 wxHtmlCell* GetHtmlCell();
95 };
96
97 //---------------------------------------------------------------------------
98
99 class wxHtmlTag {
100 public:
101 // Never need to create a new tag from Python...
102 //wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
103
104 wxString GetName();
105 bool HasParam(const wxString& par);
106 wxString GetParam(const wxString& par, int with_commas = FALSE);
107
108 // Can't do this one as-is, but GetParam should be enough...
109 //int ScanParam(const wxString& par, const char *format, void* param);
110
111 wxString GetAllParams();
112 bool IsEnding();
113 bool HasEnding();
114 int GetBeginPos();
115 int GetEndPos1();
116 int GetEndPos2();
117 };
118
119
120 //---------------------------------------------------------------------------
121
122 class wxHtmlParser {
123 public:
124 // wxHtmlParser(); This is an abstract base class...
125
126 void SetFS(wxFileSystem *fs);
127 wxFileSystem* GetFS();
128 wxObject* Parse(const wxString& source);
129 void InitParser(const wxString& source);
130 void DoneParser();
131 void DoParsing(int begin_pos, int end_pos);
132 // wxObject* GetProduct();
133 void AddTagHandler(wxHtmlTagHandler *handler);
134 wxString* GetSource();
135 void PushTagHandler(wxHtmlTagHandler* handler, wxString tags);
136 void PopTagHandler();
137
138
139 // void AddText(const char* txt) = 0;
140 // void AddTag(const wxHtmlTag& tag);
141 };
142
143
144 //---------------------------------------------------------------------------
145
146 class wxHtmlWinParser : public wxHtmlParser {
147 public:
148 wxHtmlWinParser(wxWindow *wnd);
149
150 void SetDC(wxDC *dc);
151 wxDC* GetDC();
152 int GetCharHeight();
153 int GetCharWidth();
154 wxWindow* GetWindow();
155 //void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
156 %addmethods {
157 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes) {
158 int* temp = int_LIST_helper(sizes);
159 if (temp) {
160 self->SetFonts(normal_face, fixed_face, temp);
161 delete [] temp;
162 }
163 }
164 }
165
166 wxHtmlContainerCell* GetContainer();
167 wxHtmlContainerCell* OpenContainer();
168 wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
169 wxHtmlContainerCell* CloseContainer();
170
171 int GetFontSize();
172 void SetFontSize(int s);
173 int GetFontBold();
174 void SetFontBold(int x);
175 int GetFontItalic();
176 void SetFontItalic(int x);
177 int GetFontUnderlined();
178 void SetFontUnderlined(int x);
179 int GetFontFixed();
180 void SetFontFixed(int x);
181 int GetAlign();
182 void SetAlign(int a);
183 const wxColour& GetLinkColor();
184 void SetLinkColor(const wxColour& clr);
185 const wxColour& GetActualColor();
186 void SetActualColor(const wxColour& clr);
187 void SetLink(const wxString& link);
188 wxFont* CreateCurrentFont();
189 wxHtmlLinkInfo GetLink();
190
191 };
192
193
194
195 //---------------------------------------------------------------------------
196
197 %{
198 class wxPyHtmlTagHandler : public wxHtmlTagHandler {
199 public:
200 wxPyHtmlTagHandler() : wxHtmlTagHandler() {};
201
202 wxHtmlParser* GetParser() { return m_Parser; }
203 void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); }
204
205 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
206 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
207
208 PYPRIVATE;
209 };
210
211 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
212 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
213 %}
214
215
216 %name(wxHtmlTagHandler) class wxPyHtmlTagHandler {
217 public:
218 wxPyHtmlTagHandler();
219
220 void _setSelf(PyObject* self, PyObject* _class);
221 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxHtmlTagHandler)"
222
223 void SetParser(wxHtmlParser *parser);
224 wxHtmlParser* GetParser();
225 void ParseInner(const wxHtmlTag& tag);
226 };
227
228
229 //---------------------------------------------------------------------------
230
231 %{
232 class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
233 public:
234 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
235
236 wxHtmlWinParser* GetParser() { return m_WParser; }
237 void ParseInner(const wxHtmlTag& tag)
238 { wxHtmlWinTagHandler::ParseInner(tag); }
239
240 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
241 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
242
243 PYPRIVATE;
244 };
245
246 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
247 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
248 %}
249
250
251 %name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
252 public:
253 wxPyHtmlWinTagHandler();
254
255 void _setSelf(PyObject* self, PyObject* _class);
256 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxHtmlWinTagHandler)"
257
258 void SetParser(wxHtmlParser *parser);
259 wxHtmlWinParser* GetParser();
260 void ParseInner(const wxHtmlTag& tag);
261 };
262
263
264 //---------------------------------------------------------------------------
265
266 %{
267
268 class wxPyHtmlTagsModule : public wxHtmlTagsModule {
269 public:
270 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
271 m_tagHandlerClass = thc;
272 Py_INCREF(m_tagHandlerClass);
273 RegisterModule(this);
274 wxHtmlWinParser::AddModule(this);
275 }
276
277 void OnExit() {
278 bool doSave = wxPyRestoreThread();
279 Py_DECREF(m_tagHandlerClass);
280 m_tagHandlerClass = NULL;
281 for (size_t x=0; x < m_objArray.GetCount(); x++) {
282 PyObject* obj = (PyObject*)m_objArray.Item(x);
283 Py_DECREF(obj);
284 }
285 wxPySaveThread(doSave);
286 };
287
288 void FillHandlersTable(wxHtmlWinParser *parser) {
289 // Wave our magic wand... (if it works it's a miracle! ;-)
290
291 // First, make a new instance of the tag handler
292 bool doSave = wxPyRestoreThread();
293 PyObject* arg = Py_BuildValue("()");
294 PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
295 Py_DECREF(arg);
296 wxPySaveThread(doSave);
297
298 // now figure out where it's C++ object is...
299 wxPyHtmlWinTagHandler* thPtr;
300 if (SWIG_GetPtrObj(obj, (void **)&thPtr, "_wxPyHtmlWinTagHandler_p"))
301 return;
302
303 // add it,
304 parser->AddTagHandler(thPtr);
305
306 // and track it.
307 m_objArray.Add(obj);
308 }
309
310 private:
311 PyObject* m_tagHandlerClass;
312 wxArrayPtrVoid m_objArray;
313
314 };
315 %}
316
317
318
319 %inline %{
320 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
321 // Dynamically create a new wxModule. Refcounts tagHandlerClass
322 // and adds itself to the wxModules list and to the wxHtmlWinParser.
323 new wxPyHtmlTagsModule(tagHandlerClass);
324 }
325 %}
326
327
328 //---------------------------------------------------------------------------
329 //---------------------------------------------------------------------------
330
331 class wxHtmlCell {
332 public:
333 wxHtmlCell();
334
335 int GetPosX();
336 int GetPosY();
337 int GetWidth();
338 int GetHeight();
339 int GetDescent();
340 wxHtmlLinkInfo* GetLink(int x = 0, int y = 0);
341 wxHtmlCell* GetNext();
342 wxHtmlContainerCell* GetParent();
343 void SetLink(const wxHtmlLinkInfo& link);
344 void SetNext(wxHtmlCell *cell);
345 void SetParent(wxHtmlContainerCell *p);
346 void SetPos(int x, int y);
347 void Layout(int w);
348 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
349 void DrawInvisible(wxDC& dc, int x, int y);
350 const wxHtmlCell* Find(int condition, const void* param);
351
352 bool AdjustPagebreak(int * pagebreak);
353 void SetCanLiveOnPagebreak(bool can);
354
355 };
356
357
358 class wxHtmlContainerCell : public wxHtmlCell {
359 public:
360 wxHtmlContainerCell(wxHtmlContainerCell *parent);
361
362 void InsertCell(wxHtmlCell *cell);
363 void SetAlignHor(int al);
364 int GetAlignHor();
365 void SetAlignVer(int al);
366 int GetAlignVer();
367 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
368 int GetIndent(int ind);
369 int GetIndentUnits(int ind);
370 void SetAlign(const wxHtmlTag& tag);
371 void SetWidthFloat(int w, int units);
372 %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
373 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
374 void SetBackgroundColour(const wxColour& clr);
375 void SetBorder(const wxColour& clr1, const wxColour& clr2);
376 wxHtmlCell* GetFirstCell();
377 };
378
379
380
381 class wxHtmlColourCell : public wxHtmlCell {
382 public:
383 wxHtmlColourCell(wxColour clr, int flags = wxHTML_CLR_FOREGROUND);
384
385 };
386
387
388
389 class wxHtmlWidgetCell : public wxHtmlCell {
390 public:
391 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
392
393 };
394
395
396
397 //---------------------------------------------------------------------------
398 //---------------------------------------------------------------------------
399 //---------------------------------------------------------------------------
400
401 // item of history list
402 class HtmlHistoryItem {
403 public:
404 HtmlHistoryItem(const char* p, const char* a);
405
406 int GetPos();
407 void SetPos(int p);
408 const wxString& GetPage();
409 const wxString& GetAnchor();
410 };
411
412
413 //---------------------------------------------------------------------------
414 %{
415 class wxPyHtmlWindow : public wxHtmlWindow {
416 public:
417 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
418 const wxPoint& pos = wxDefaultPosition,
419 const wxSize& size = wxDefaultSize,
420 long style = wxHW_SCROLLBAR_AUTO,
421 const wxString& name = "htmlWindow")
422 : wxHtmlWindow(parent, id, pos, size, style, name) {};
423
424 void OnLinkClicked(const wxHtmlLinkInfo& link);
425 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
426
427 DEC_PYCALLBACK__STRING(OnSetTitle);
428 PYPRIVATE;
429 };
430
431
432 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
433
434 void wxPyHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) {
435 bool doSave = wxPyRestoreThread();
436 if (m_myInst.findCallback("OnLinkClicked")) {
437 PyObject* obj = wxPyConstructObject((void*)&link, "wxHtmlLinkInfo");
438 m_myInst.callCallback(Py_BuildValue("(O)", obj));
439 Py_DECREF(obj);
440 }
441 else
442 wxHtmlWindow::OnLinkClicked(link);
443 wxPySaveThread(doSave);
444 }
445 void wxPyHtmlWindow::base_OnLinkClicked(const wxHtmlLinkInfo& link) {
446 wxHtmlWindow::OnLinkClicked(link);
447 }
448 %}
449
450
451
452 %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
453 public:
454 wxPyHtmlWindow(wxWindow *parent, int id = -1,
455 wxPoint& pos = wxPyDefaultPosition,
456 wxSize& size = wxPyDefaultSize,
457 int flags=wxHW_SCROLLBAR_AUTO,
458 char* name = "htmlWindow");
459
460 void _setSelf(PyObject* self, PyObject* _class);
461 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxHtmlWindow)"
462 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
463 %pragma(python) addtomethod = "__init__:#wx._StdOnScrollCallbacks(self)"
464
465
466 bool SetPage(const char* source);
467 bool LoadPage(const char* location);
468 wxString GetOpenedPage();
469 void SetRelatedFrame(wxFrame* frame, const char* format);
470 wxFrame* GetRelatedFrame();
471 void SetRelatedStatusBar(int bar);
472
473 //void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
474 %addmethods {
475 void SetFonts(wxString normal_face, wxString fixed_face, PyObject* sizes) {
476 int* temp = int_LIST_helper(sizes);
477 if (temp) {
478 self->SetFonts(normal_face, fixed_face, temp);
479 delete [] temp;
480 }
481 }
482 }
483
484 void SetTitle(const char* title);
485 void SetBorders(int b);
486 void ReadCustomization(wxConfigBase *cfg, char* path = "");
487 void WriteCustomization(wxConfigBase *cfg, char* path = "");
488 bool HistoryBack();
489 bool HistoryForward();
490 void HistoryClear();
491 wxHtmlContainerCell* GetInternalRepresentation();
492 wxHtmlWinParser* GetParser();
493
494 void base_OnLinkClicked(const wxHtmlLinkInfo& link);
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 %}
589
590 //----------------------------------------------------------------------
591 // And this gets appended to the shadow class file.
592 //----------------------------------------------------------------------
593
594 %pragma(python) include="_htmlextras.py";
595
596 //---------------------------------------------------------------------------
597