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