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