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