]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/modules/html/html.i
New wxHtml stuff, including a TagHandler for placing wxPython widgets
[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/image.h>
20 #include <wx/fs_zip.h>
21 #include <wx/fs_inet.h>
22 #include <wx/wfstream.h>
23 #include "helpsys.h"
24 %}
25
26 //---------------------------------------------------------------------------
27
28 %include typemaps.i
29 %include my_typemaps.i
30
31 %extern wx.i
32 %extern windows.i
33 %extern _defs.i
34 %extern events.i
35 %extern controls.i
36 %extern controls2.i
37
38 %extern utils.i
39
40 //---------------------------------------------------------------------------
41
42 %{
43 #ifdef __WXMSW__
44 wxString wxPyEmptyStr("");
45 wxPoint wxPyDefaultPosition(wxDefaultPosition);
46 wxSize wxPyDefaultSize(wxDefaultSize);
47 #endif
48 %}
49
50 %pragma(python) code = "import wx,htmlhelper"
51 %pragma(python) code = "widget = htmlc"
52
53 %{
54
55 #if 0
56 static PyObject* mod_dict = NULL; // will be set by init
57
58 #include <wx/html/mod_templ.h>
59
60 TAG_HANDLER_BEGIN(PYTHONTAG, "PYTHON")
61 TAG_HANDLER_PROC(tag)
62 {
63 wxWindow *wnd;
64 wxString errmsg;
65 char pbuf[256];
66
67 int fl = 0;
68
69 bool doSave = wxPyRestoreThread();
70 while (1) {
71 if (tag.HasParam("FLOAT"))
72 tag.ScanParam("FLOAT", "%i", &fl);
73 PyObject* pyfunc = PyDict_GetItemString(mod_dict, "WidgetStarter");
74 if (pyfunc == NULL) {
75 errmsg = "Could not find object WidgetStarter";
76 break;
77 }
78 if (! PyCallable_Check(pyfunc)) {
79 errmsg = "WidgetStarter does not appear to be callable";
80 break;
81 }
82 SWIG_MakePtr(pbuf, m_WParser->GetWindow(), "_wxPyHtmlWindow_p");
83 PyObject* arglist = Py_BuildValue("(s,s)", pbuf,
84 (const char*)tag.GetAllParams());
85 if (! arglist) {
86 errmsg = "Failed making argument list";
87 break;
88 }
89 PyObject* ret = PyEval_CallObject(pyfunc, arglist);
90 Py_DECREF(arglist);
91 if (ret == NULL) {
92 errmsg = "An error occured while calling WidgetStarter";
93 if (PyErr_Occurred())
94 PyErr_Print();
95 break;
96 }
97 wnd = NULL;
98 if (PyString_Check(ret)) {
99 char* thisc = PyString_AsString(ret);
100 SWIG_GetPtr(thisc, (void**)&wnd, "_wxWindow_p");
101 }
102 Py_DECREF(ret);
103 if (! wnd) {
104 errmsg = "Could not make a wxWindow pointer from return ptr";
105 break;
106 }
107 wxPySaveThread(doSave);
108 wnd -> Show(TRUE);
109 m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, fl));
110 return FALSE;
111 }
112
113 wxPySaveThread(doSave);
114
115 /* we got out of the loop. Must be an error. Show a box stating it. */
116 wnd = new wxTextCtrl( m_WParser -> GetWindow(), -1,
117 errmsg, wxPoint(0,0),
118 wxSize(300, 100), wxTE_MULTILINE );
119 wnd -> Show(TRUE);
120 m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, 100));
121 return FALSE;
122 }
123
124 TAG_HANDLER_END(PYTHONTAG)
125
126 TAGS_MODULE_BEGIN(PythonTag)
127
128 TAGS_MODULE_ADD(PYTHONTAG)
129
130 TAGS_MODULE_END(PythonTag)
131
132 // Note: see also the init function where we add the module!
133 #endif
134 %}
135
136 //---------------------------------------------------------------------------
137
138 enum {
139 HTML_ALIGN_LEFT,
140 HTML_ALIGN_CENTER,
141 HTML_ALIGN_RIGHT,
142 HTML_ALIGN_BOTTOM,
143 HTML_ALIGN_TOP,
144
145 HTML_CLR_FOREGROUND,
146 HTML_CLR_BACKGROUND,
147
148 HTML_UNITS_PIXELS,
149 HTML_UNITS_PERCENT,
150
151 HTML_INDENT_LEFT,
152 HTML_INDENT_RIGHT,
153 HTML_INDENT_TOP,
154 HTML_INDENT_BOTTOM,
155
156 HTML_INDENT_HORIZONTAL,
157 HTML_INDENT_VERTICAL,
158 HTML_INDENT_ALL,
159
160 HTML_COND_ISANCHOR,
161 HTML_COND_ISIMAGEMAP,
162 HTML_COND_USER,
163 };
164
165
166 //---------------------------------------------------------------------------
167
168 class wxHtmlTag {
169 public:
170 // Never need to create a new tag from Python...
171 //wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
172
173 wxString GetName();
174 bool HasParam(const wxString& par);
175 wxString GetParam(const wxString& par, int with_commas = FALSE);
176
177 // Can't do this one as-is, but GetParam should be enough...
178 //int ScanParam(const wxString& par, const char *format, void* param);
179
180 wxString GetAllParams();
181 bool IsEnding();
182 bool HasEnding();
183 int GetBeginPos();
184 int GetEndPos1();
185 int GetEndPos2();
186 };
187
188
189 //---------------------------------------------------------------------------
190
191 class wxHtmlParser {
192 public:
193 // wxHtmlParser(); This is an abstract base class...
194
195 void SetFS(wxFileSystem *fs);
196 wxFileSystem* GetFS();
197 wxObject* Parse(const wxString& source);
198 void InitParser(const wxString& source);
199 void DoneParser();
200 void DoParsing(int begin_pos, int end_pos);
201 // wxObject* GetProduct();
202 void AddTagHandler(wxHtmlTagHandler *handler);
203 wxString* GetSource();
204
205
206 // void AddText(const char* txt) = 0;
207 // void AddTag(const wxHtmlTag& tag);
208 };
209
210
211 //---------------------------------------------------------------------------
212
213 class wxHtmlWinParser : public wxHtmlParser {
214 public:
215 wxHtmlWinParser(wxWindow *wnd);
216
217 void SetDC(wxDC *dc);
218 wxDC* GetDC();
219 int GetCharHeight();
220 int GetCharWidth();
221 wxWindow* GetWindow();
222 void SetFonts(wxString normal_face, int normal_italic_mode,
223 wxString fixed_face, int fixed_italic_mode, int *LIST);
224
225 wxHtmlContainerCell* GetContainer();
226 wxHtmlContainerCell* OpenContainer();
227 wxHtmlContainerCell* CloseContainer();
228 int GetFontSize();
229 void SetFontSize(int s);
230 int GetFontBold();
231 void SetFontBold(int x);
232 int GetFontItalic();
233 void SetFontItalic(int x);
234 int GetFontUnderlined();
235 void SetFontUnderlined(int x);
236 int GetFontFixed();
237 void SetFontFixed(int x);
238 int GetAlign();
239 void SetAlign(int a);
240 const wxColour& GetLinkColor();
241 void SetLinkColor(const wxColour& clr);
242 const wxColour& GetActualColor();
243 void SetActualColor(const wxColour& clr);
244 const wxString& GetLink();
245 void SetLink(const wxString& link);
246 wxFont* CreateCurrentFont();
247 };
248
249
250
251 //---------------------------------------------------------------------------
252
253 %{
254 class wxPyHtmlTagHandler : public wxHtmlTagHandler {
255 public:
256 wxPyHtmlTagHandler() : wxHtmlTagHandler() {};
257
258 wxHtmlParser* GetParser() { return m_Parser; }
259 void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); }
260
261 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
262 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
263
264 PYPRIVATE;
265 };
266
267 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
268 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
269 %}
270
271
272 %name(wxHtmlTagHandler) class wxPyHtmlTagHandler {
273 public:
274 wxPyHtmlTagHandler();
275
276 void _setSelf(PyObject* self);
277 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
278
279 void SetParser(wxHtmlParser *parser);
280 wxHtmlParser* GetParser();
281 void ParseInner(const wxHtmlTag& tag);
282 };
283
284
285 //---------------------------------------------------------------------------
286
287 %{
288 class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
289 public:
290 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
291
292 wxHtmlWinParser* GetParser() { return m_WParser; }
293 void ParseInner(const wxHtmlTag& tag)
294 { wxHtmlWinTagHandler::ParseInner(tag); }
295
296 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
297 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
298
299 PYPRIVATE;
300 };
301
302 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
303 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
304 %}
305
306
307 %name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
308 public:
309 wxPyHtmlWinTagHandler();
310
311 void _setSelf(PyObject* self);
312 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
313
314 void SetParser(wxHtmlParser *parser);
315 wxHtmlWinParser* GetParser();
316 void ParseInner(const wxHtmlTag& tag);
317 };
318
319
320 //---------------------------------------------------------------------------
321
322 %{
323
324 class wxPyHtmlTagsModule : public wxHtmlTagsModule {
325 public:
326 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
327 m_tagHandlerClass = thc;
328 Py_INCREF(m_tagHandlerClass);
329 RegisterModule(this);
330 wxHtmlWinParser::AddModule(this);
331 }
332
333 void OnExit() {
334 Py_DECREF(m_tagHandlerClass);
335 m_tagHandlerClass = NULL;
336 for (int x=0; x < m_objArray.GetCount(); x++) {
337 PyObject* obj = (PyObject*)m_objArray.Item(x);
338 Py_DECREF(obj);
339 }
340 };
341
342 void FillHandlersTable(wxHtmlWinParser *parser) {
343 // Wave our magic wand... (if it works it's a miracle! ;-)
344
345 // First, make a new instance of the tag handler
346 bool doSave = wxPyRestoreThread();
347 PyObject* arg = Py_BuildValue("()");
348 PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
349 Py_DECREF(arg);
350 wxPySaveThread(doSave);
351
352 // now figure out where it's C++ object is...
353 wxPyHtmlWinTagHandler* thPtr;
354 if (SWIG_GetPtrObj(obj, (void **)&thPtr, "_wxPyHtmlWinTagHandler_p"))
355 return;
356
357 // add it,
358 parser->AddTagHandler(thPtr);
359
360 // and track it.
361 m_objArray.Add(obj);
362 }
363
364 private:
365 PyObject* m_tagHandlerClass;
366 wxArrayPtrVoid m_objArray;
367
368 };
369 %}
370
371
372
373 %inline %{
374 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
375 // Dynamically create a new wxModule. Refcounts tagHandlerClass
376 // and adds itself to the wxModules list and to the wxHtmlWinParser.
377 new wxPyHtmlTagsModule(tagHandlerClass);
378 }
379 %}
380
381 //---------------------------------------------------------------------------
382 //---------------------------------------------------------------------------
383
384 class wxHtmlCell {
385 public:
386 wxHtmlCell();
387
388 void SetParent(wxHtmlContainerCell *p);
389 wxHtmlContainerCell* GetParent();
390 int GetPosX();
391 int GetPosY();
392 int GetWidth();
393 int GetHeight();
394 int GetDescent();
395 wxString GetLink(int x = 0, int y = 0);
396 wxHtmlCell* GetNext();
397 void SetPos(int x, int y);
398 void SetLink(const wxString& link);
399 void SetNext(wxHtmlCell *cell);
400 void Layout(int w);
401 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
402 void DrawInvisible(wxDC& dc, int x, int y);
403 const wxHtmlCell* Find(int condition, const void* param);
404 };
405
406
407 class wxHtmlContainerCell : public wxHtmlCell {
408 public:
409 wxHtmlContainerCell(wxHtmlContainerCell *parent);
410
411 void InsertCell(wxHtmlCell *cell);
412 void SetAlignHor(int al);
413 int GetAlignHor();
414 void SetAlignVer(int al);
415 int GetAlignVer();
416 void SetIndent(int i, int what, int units = HTML_UNITS_PIXELS);
417 int GetIndent(int ind);
418 int GetIndentUnits(int ind);
419 void SetAlign(const wxHtmlTag& tag);
420 void SetWidthFloat(int w, int units);
421 %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
422 void SetMinHeight(int h, int align = HTML_ALIGN_TOP);
423 int GetMaxLineWidth();
424 void SetBackgroundColour(const wxColour& clr);
425 void SetBorder(const wxColour& clr1, const wxColour& clr2);
426 wxHtmlCell* GetFirstCell();
427 };
428
429
430
431
432 class wxHtmlWidgetCell : public wxHtmlCell {
433 public:
434 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
435
436 };
437
438
439
440 //---------------------------------------------------------------------------
441 //---------------------------------------------------------------------------
442 //---------------------------------------------------------------------------
443
444 // item of history list
445 class HtmlHistoryItem {
446 public:
447 HtmlHistoryItem(const char* p, const char* a);
448
449 int GetPos();
450 void SetPos(int p);
451 const wxString& GetPage();
452 const wxString& GetAnchor();
453 };
454
455
456 //---------------------------------------------------------------------------
457 %{
458 class wxPyHtmlWindow : public wxHtmlWindow {
459 public:
460 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
461 const wxPoint& pos = wxDefaultPosition,
462 const wxSize& size = wxDefaultSize,
463 long style = wxHW_SCROLLBAR_AUTO,
464 const wxString& name = "htmlWindow")
465 : wxHtmlWindow(parent, id, pos, size, style, name) {};
466
467 DEC_PYCALLBACK__STRING(OnLinkClicked);
468
469 PYPRIVATE;
470 };
471
472 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnLinkClicked);
473
474 %}
475
476
477 %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
478 public:
479 wxPyHtmlWindow(wxWindow *parent, int id = -1,
480 wxPoint& pos = wxPyDefaultPosition,
481 wxSize& size = wxPyDefaultSize,
482 int flags=wxHW_SCROLLBAR_AUTO,
483 char* name = "htmlWindow");
484
485 void _setSelf(PyObject* self);
486 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
487 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
488 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
489
490
491 bool SetPage(const char* source);
492 // Set HTML page and display it. !! source is HTML document itself,
493 // it is NOT address/filename of HTML document. If you want to
494 // specify document location, use LoadPage() istead
495 // Return value : FALSE if an error occured, TRUE otherwise
496
497 bool LoadPage(const char* location);
498 // Load HTML page from given location. Location can be either
499 // a) /usr/wxGTK2/docs/html/wx.htm
500 // b) http://www.somewhere.uk/document.htm
501 // c) ftp://ftp.somesite.cz/pub/something.htm
502 // In case there is no prefix (http:,ftp:), the method
503 // will try to find it itself (1. local file, then http or ftp)
504 // After the page is loaded, the method calls SetPage() to display it.
505 // Note : you can also use path relative to previously loaded page
506 // Return value : same as SetPage
507
508 wxString GetOpenedPage();
509 // Returns full location of opened page
510
511 void SetRelatedFrame(wxFrame* frame, const char* format);
512 // sets frame in which page title will be displayed. Format is format of
513 // frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s
514 wxFrame* GetRelatedFrame();
515
516 void SetRelatedStatusBar(int bar);
517 // after(!) calling SetRelatedFrame, this sets statusbar slot where messages
518 // will be displayed. Default is -1 = no messages.
519
520 void SetFonts(wxString normal_face, int normal_italic_mode,
521 wxString fixed_face, int fixed_italic_mode, int *LIST);
522 // sets fonts to be used when displaying HTML page.
523 // *_italic_mode can be either wxSLANT or wxITALIC
524
525 void SetTitle(const char* title);
526 // Sets the title of the window
527 // (depending on the information passed to SetRelatedFrame() method)
528
529 void SetBorders(int b);
530 // Sets space between text and window borders.
531
532 void ReadCustomization(wxConfigBase *cfg, char* path = "");
533 // saves custom settings into cfg config. it will use the path 'path'
534 // if given, otherwise it will save info into currently selected path.
535 // saved values : things set by SetFonts, SetBorders.
536
537 void WriteCustomization(wxConfigBase *cfg, char* path = "");
538 // ...
539
540 bool HistoryBack();
541 bool HistoryForward();
542 // Goes to previous/next page (in browsing history)
543 // Returns TRUE if successful, FALSE otherwise
544 void HistoryClear();
545 // Resets history
546
547 wxHtmlContainerCell* GetInternalRepresentation();
548 // Returns pointer to conteiners/cells structure.
549 // It should be used ONLY when printing
550
551 wxHtmlWinParser* GetParser();
552
553
554 void base_OnLinkClicked(const char* link);
555 // called when users clicked on hypertext link. Default behavior is to
556 // call LoadPage(loc)
557
558 };
559
560 // Static methods are mapped to stand-alone functions
561 %inline %{
562 void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) {
563 wxHtmlWindow::AddFilter(filter);
564 }
565 %}
566
567
568 //---------------------------------------------------------------------------
569 //---------------------------------------------------------------------------
570
571 %{
572 extern "C" SWIGEXPORT(void) inithtmlhelpc();
573 %}
574
575
576 %init %{
577
578 #if 0
579 /* This is a bit cheesy. SWIG happens to call the dictionary d...
580 * I save it here, 'cause I don't know how to get it back later! */
581 mod_dict = d;
582 #endif
583
584 //inithtmlhelpc();
585
586 wxClassInfo::CleanUpClasses();
587 wxClassInfo::InitializeClasses();
588
589 #if 0
590 /* specifically add our python tag handler; it doesn't seem to
591 * happen by itself... */
592 wxHtmlWinParser::AddModule(new HTML_ModulePythonTag());
593 #endif
594
595 // Until wxFileSystem is wrapped...
596 #if wxUSE_FS_ZIP
597 wxFileSystem::AddHandler(new wxZipFSHandler);
598 #endif
599 %}
600
601 //----------------------------------------------------------------------
602 // And this gets appended to the shadow class file.
603 //----------------------------------------------------------------------
604
605 %pragma(python) include="_extras.py";
606
607 //---------------------------------------------------------------------------
608