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