]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/modules/html/html.i
Added limits to wxSpinCtrls, fixed one bug
[wxWidgets.git] / utils / wxPython / modules / html / html.i
CommitLineData
4b123bb9
HH
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>
dc2f8a65 19#include <wx/html/htmprint.h>
4b123bb9
HH
20#include <wx/image.h>
21#include <wx/fs_zip.h>
22#include <wx/fs_inet.h>
5ca24bf4 23#include <wx/wfstream.h>
dc2f8a65
RD
24
25#include "printfw.h"
4b123bb9
HH
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
5ca24bf4
HH
37%extern controls.i
38%extern controls2.i
dc2f8a65 39%extern printfw.i
4b123bb9 40
0f66a9f3
RD
41%extern utils.i
42
43//---------------------------------------------------------------------------
44
4b123bb9
HH
45%{
46#ifdef __WXMSW__
0f66a9f3
RD
47wxString wxPyEmptyStr("");
48wxPoint wxPyDefaultPosition(wxDefaultPosition);
49wxSize wxPyDefaultSize(wxDefaultSize);
4b123bb9 50#endif
4b123bb9
HH
51%}
52
2f90df85 53%pragma(python) code = "import wx"
4b123bb9 54
4b123bb9 55
0f66a9f3 56//---------------------------------------------------------------------------
e166644c
RD
57
58enum {
9d8bd15f
RD
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,
e166644c
RD
83};
84
85
9c00cfa3
RD
86//---------------------------------------------------------------------------
87
88class wxHtmlLinkInfo {
89public:
90 wxHtmlLinkInfo(const wxString& href, const wxString& target = wxEmptyString);
91 wxString GetHref();
92 wxString GetTarget();
93};
94
0f66a9f3
RD
95//---------------------------------------------------------------------------
96
97class wxHtmlTag {
98public:
e166644c 99 // Never need to create a new tag from Python...
0f66a9f3
RD
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
120class wxHtmlParser {
121public:
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();
dc2f8a65
RD
133 void PushTagHandler(wxHtmlTagHandler* handler, wxString tags);
134 void PopTagHandler();
0f66a9f3
RD
135
136
137 // void AddText(const char* txt) = 0;
138 // void AddTag(const wxHtmlTag& tag);
139};
140
141
142//---------------------------------------------------------------------------
143
144class wxHtmlWinParser : public wxHtmlParser {
145public:
146 wxHtmlWinParser(wxWindow *wnd);
147
148 void SetDC(wxDC *dc);
149 wxDC* GetDC();
150 int GetCharHeight();
151 int GetCharWidth();
152 wxWindow* GetWindow();
9c00cfa3 153 void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
0f66a9f3
RD
154
155 wxHtmlContainerCell* GetContainer();
156 wxHtmlContainerCell* OpenContainer();
dc2f8a65 157 wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
0f66a9f3 158 wxHtmlContainerCell* CloseContainer();
dc2f8a65 159
0f66a9f3
RD
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);
0f66a9f3
RD
176 void SetLink(const wxString& link);
177 wxFont* CreateCurrentFont();
9c00cfa3
RD
178 wxHtmlLinkInfo GetLink();
179
0f66a9f3
RD
180};
181
182
183
184//---------------------------------------------------------------------------
185
186%{
187class wxPyHtmlTagHandler : public wxHtmlTagHandler {
188public:
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
200IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
201IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
0f66a9f3
RD
202%}
203
204
205%name(wxHtmlTagHandler) class wxPyHtmlTagHandler {
206public:
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%{
221class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
222public:
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
235IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
236IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
0f66a9f3
RD
237%}
238
239
240%name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
241public:
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
257class wxPyHtmlTagsModule : public wxHtmlTagsModule {
258public:
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;
dc2f8a65 269 for (size_t x=0; x < m_objArray.GetCount(); x++) {
0f66a9f3
RD
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
e166644c 279 bool doSave = wxPyRestoreThread();
0f66a9f3
RD
280 PyObject* arg = Py_BuildValue("()");
281 PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
282 Py_DECREF(arg);
e166644c 283 wxPySaveThread(doSave);
0f66a9f3
RD
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
297private:
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
dc2f8a65 314
e166644c
RD
315//---------------------------------------------------------------------------
316//---------------------------------------------------------------------------
317
318class wxHtmlCell {
319public:
320 wxHtmlCell();
321
e166644c
RD
322 int GetPosX();
323 int GetPosY();
324 int GetWidth();
325 int GetHeight();
326 int GetDescent();
9c00cfa3 327 wxHtmlLinkInfo* GetLink(int x = 0, int y = 0);
e166644c 328 wxHtmlCell* GetNext();
9c00cfa3
RD
329 wxHtmlContainerCell* GetParent();
330 void SetLink(const wxHtmlLinkInfo& link);
e166644c 331 void SetNext(wxHtmlCell *cell);
9c00cfa3
RD
332 void SetParent(wxHtmlContainerCell *p);
333 void SetPos(int x, int y);
e166644c
RD
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);
dc2f8a65
RD
338
339 bool AdjustPagebreak(int * pagebreak);
340 void SetCanLiveOnPagebreak(bool can);
9c00cfa3 341
e166644c
RD
342};
343
344
345class wxHtmlContainerCell : public wxHtmlCell {
346public:
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();
9d8bd15f 354 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
e166644c
RD
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);
9d8bd15f 360 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
e166644c
RD
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
9c00cfa3
RD
369class wxHtmlColourCell : public wxHtmlCell {
370public:
371 wxHtmlColourCell(wxColour clr, int flags = wxHTML_CLR_FOREGROUND);
372
373};
374
375
e166644c
RD
376
377class wxHtmlWidgetCell : public wxHtmlCell {
378public:
379 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
380
381};
382
0f66a9f3
RD
383
384
385//---------------------------------------------------------------------------
386//---------------------------------------------------------------------------
4b123bb9
HH
387//---------------------------------------------------------------------------
388
389// item of history list
0f66a9f3
RD
390class HtmlHistoryItem {
391public:
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();
4b123bb9
HH
398};
399
0f66a9f3
RD
400
401//---------------------------------------------------------------------------
402%{
403class wxPyHtmlWindow : public wxHtmlWindow {
404public:
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
0f66a9f3 412
9c00cfa3
RD
413 void OnLinkClicked(wxHtmlLinkInfo* link);
414 void base_OnLinkClicked(wxHtmlLinkInfo* link);
415
416 DEC_PYCALLBACK__STRING(OnSetTitle);
0f66a9f3
RD
417 PYPRIVATE;
418};
419
9c00cfa3 420IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
0f66a9f3 421
9c00cfa3
RD
422void 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}
432void wxPyHtmlWindow::base_OnLinkClicked(wxHtmlLinkInfo* link) {
433 wxHtmlWindow::OnLinkClicked(link);
434}
0f66a9f3
RD
435%}
436
437
438%name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
439public:
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);
0f66a9f3 453 bool LoadPage(const char* location);
0f66a9f3 454 wxString GetOpenedPage();
0f66a9f3 455 void SetRelatedFrame(wxFrame* frame, const char* format);
0f66a9f3 456 wxFrame* GetRelatedFrame();
0f66a9f3 457 void SetRelatedStatusBar(int bar);
9c00cfa3 458 void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
0f66a9f3 459 void SetTitle(const char* title);
0f66a9f3 460 void SetBorders(int b);
0f66a9f3 461 void ReadCustomization(wxConfigBase *cfg, char* path = "");
0f66a9f3 462 void WriteCustomization(wxConfigBase *cfg, char* path = "");
0f66a9f3
RD
463 bool HistoryBack();
464 bool HistoryForward();
0f66a9f3 465 void HistoryClear();
a65c6e14 466 wxHtmlContainerCell* GetInternalRepresentation();
e166644c
RD
467 wxHtmlWinParser* GetParser();
468
4b123bb9 469
9c00cfa3 470 void base_OnSetTitle(const char* title);
4b123bb9
HH
471};
472
0f66a9f3
RD
473// Static methods are mapped to stand-alone functions
474%inline %{
475 void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) {
476 wxHtmlWindow::AddFilter(filter);
477 }
478%}
5ca24bf4 479
5ca24bf4 480
dc2f8a65
RD
481//---------------------------------------------------------------------------
482//---------------------------------------------------------------------------
483
484
485class wxHtmlDCRenderer {
486public:
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
501enum {
502 wxPAGE_ODD,
503 wxPAGE_EVEN,
504 wxPAGE_ALL
505};
506
507
508class wxHtmlPrintout : public wxPyPrintout {
509public:
65dd82cb 510 wxHtmlPrintout(const char* title = "Printout");
dc2f8a65
RD
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
526class wxHtmlEasyPrinting {
527public:
65dd82cb 528 wxHtmlEasyPrinting(const char* name = "Printing",
dc2f8a65
RD
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
0f66a9f3
RD
548//---------------------------------------------------------------------------
549//---------------------------------------------------------------------------
5ca24bf4 550
0f66a9f3
RD
551%{
552 extern "C" SWIGEXPORT(void) inithtmlhelpc();
553%}
4b123bb9 554
4b123bb9
HH
555
556%init %{
557
2f90df85 558 inithtmlhelpc();
0f66a9f3 559
4b123bb9
HH
560 wxClassInfo::CleanUpClasses();
561 wxClassInfo::InitializeClasses();
562
4b123bb9
HH
563 // Until wxFileSystem is wrapped...
564 #if wxUSE_FS_ZIP
565 wxFileSystem::AddHandler(new wxZipFSHandler);
566 #endif
567%}
568
e166644c
RD
569//----------------------------------------------------------------------
570// And this gets appended to the shadow class file.
571//----------------------------------------------------------------------
572
573%pragma(python) include="_extras.py";
574
4b123bb9 575//---------------------------------------------------------------------------
e166644c 576