]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/src/helpers.h
Squashed another threading and interpreter lock bug
[wxWidgets.git] / utils / wxPython / src / helpers.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: helpers.h
3 // Purpose: Helper functions/classes for the wxPython extenaion module
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 7/1/97
8 // RCS-ID: $Id$
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef __wxp_helpers__
14 #define __wxp_helpers__
15
16 #include <wx/wx.h>
17
18
19 //----------------------------------------------------------------------
20
21 // if we want to handle threads and Python threads are available...
22 #if defined(WXP_USE_THREAD) && defined(WITH_THREAD)
23
24 #define WXP_WITH_THREAD
25 #define wxPy_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
26 #define wxPy_END_ALLOW_THREADS Py_END_ALLOW_THREADS
27
28 #else // no Python threads...
29 #undef WXP_WITH_THREAD
30 #define wxPy_BEGIN_ALLOW_THREADS
31 #define wxPy_END_ALLOW_THREADS
32 #endif
33
34
35 //---------------------------------------------------------------------------
36
37 #if defined(__WXMSW__)
38 # define HELPEREXPORT __declspec(dllexport)
39 #else
40 # define HELPEREXPORT
41 #endif
42
43 typedef unsigned char byte;
44
45 //----------------------------------------------------------------------
46
47 class wxPyApp: public wxApp
48 {
49 public:
50 wxPyApp();
51 ~wxPyApp();
52 int MainLoop(void);
53 bool OnInit(void);
54 //# void AfterMainLoop(void);
55 };
56
57 extern wxPyApp *wxPythonApp;
58
59 //----------------------------------------------------------------------
60
61 void __wxPreStart();
62 PyObject* __wxStart(PyObject*, PyObject* args);
63
64 extern PyObject* wxPython_dict;
65 PyObject* __wxSetDictionary(PyObject*, PyObject* args);
66
67 void wxPyEventThunker(wxObject*, wxEvent& event);
68
69 HELPEREXPORT PyObject* wxPyConstructObject(void* ptr, char* className);
70 HELPEREXPORT bool wxPyRestoreThread();
71 HELPEREXPORT void wxPySaveThread(bool doSave);
72 HELPEREXPORT PyObject* wxPy_ConvertList(wxListBase* list, char* className);
73
74 //----------------------------------------------------------------------
75 // These are helpers used by the typemaps
76
77 HELPEREXPORT byte* byte_LIST_helper(PyObject* source);
78 HELPEREXPORT int* int_LIST_helper(PyObject* source);
79 HELPEREXPORT long* long_LIST_helper(PyObject* source);
80 HELPEREXPORT char** string_LIST_helper(PyObject* source);
81 HELPEREXPORT wxPoint* wxPoint_LIST_helper(PyObject* source);
82 HELPEREXPORT wxBitmap** wxBitmap_LIST_helper(PyObject* source);
83 HELPEREXPORT wxString* wxString_LIST_helper(PyObject* source);
84 HELPEREXPORT wxAcceleratorEntry* wxAcceleratorEntry_LIST_helper(PyObject* source);
85
86 HELPEREXPORT bool wxSize_helper(PyObject* source, wxSize** obj);
87 HELPEREXPORT bool wxPoint_helper(PyObject* source, wxPoint** obj);
88 HELPEREXPORT bool wxRealPoint_helper(PyObject* source, wxRealPoint** obj);
89 HELPEREXPORT bool wxRect_helper(PyObject* source, wxRect** obj);
90
91 //----------------------------------------------------------------------
92
93 #ifndef SWIGCODE
94 extern "C" void SWIG_MakePtr(char *, void *, char *);
95 extern "C" char *SWIG_GetPtr(char *, void **, char *);
96 extern "C" char *SWIG_GetPtrObj(PyObject *obj, void **ptr, char *type);
97 #endif
98
99
100 #ifdef _MSC_VER
101 # pragma warning(disable:4800)
102 #endif
103
104
105
106 // Non-const versions to keep SWIG happy.
107 extern wxPoint wxPyDefaultPosition;
108 extern wxSize wxPyDefaultSize;
109 extern wxString wxPyEmptyStr;
110
111 //----------------------------------------------------------------------
112
113 class wxPyCallback : public wxObject {
114 DECLARE_ABSTRACT_CLASS(wxPyCallback);
115 public:
116 wxPyCallback(PyObject* func);
117 wxPyCallback(const wxPyCallback& other);
118 ~wxPyCallback();
119
120 void EventThunker(wxEvent& event);
121
122 PyObject* m_func;
123 };
124
125 //---------------------------------------------------------------------------
126
127 // class wxPyMenu : public wxMenu {
128 // public:
129 // wxPyMenu(const wxString& title = "", PyObject* func=NULL);
130 // ~wxPyMenu();
131
132 // private:
133 // static void MenuCallback(wxMenu& menu, wxCommandEvent& evt);
134 // PyObject* func;
135 // };
136
137
138 //---------------------------------------------------------------------------
139
140 class wxPyTimer : public wxTimer {
141 public:
142 wxPyTimer(PyObject* callback);
143 ~wxPyTimer();
144
145 void Notify();
146
147 private:
148 PyObject* func;
149 };
150
151 //---------------------------------------------------------------------------
152
153
154
155
156 //---------------------------------------------------------------------------
157 // This class holds an instance of a Python Shadow Class object and assists
158 // with looking up and invoking Python callback methods from C++ virtual
159 // method redirections. For all classes which have virtuals which should be
160 // overridable in wxPython, a new subclass is created that contains a
161 // wxPyCallbackHelper.
162 //
163 // **** This class should be combined with wxPyCallback defined above.
164 //
165
166 class HELPEREXPORT wxPyCallbackHelper {
167 public:
168 wxPyCallbackHelper();
169 ~wxPyCallbackHelper();
170
171 wxPyCallbackHelper(const wxPyCallbackHelper& other);
172
173 void setSelf(PyObject* self, int incref=TRUE);
174
175 bool findCallback(const wxString& name);
176 int callCallback(PyObject* argTuple);
177 PyObject* callCallbackObj(PyObject* argTuple);
178
179 private:
180 PyObject* m_self;
181 PyObject* m_lastFound;
182 };
183
184
185
186 //---------------------------------------------------------------------------
187 // These macros are used to implement the virtual methods that should
188 // redirect to a Python method if one exists. The names designate the
189 // return type, if any as well as any parameter types.
190 //---------------------------------------------------------------------------
191
192 #define PYPRIVATE \
193 void _setSelf(PyObject* self, int incref=TRUE) { \
194 m_myInst.setSelf(self, incref); \
195 } \
196 private: wxPyCallbackHelper m_myInst;
197
198 //---------------------------------------------------------------------------
199
200 #define DEC_PYCALLBACK__(CBNAME) \
201 void CBNAME(); \
202 void base_##CBNAME();
203
204
205 #define IMP_PYCALLBACK__(CLASS, PCLASS, CBNAME) \
206 void CLASS::CBNAME() { \
207 bool doSave = wxPyRestoreThread(); \
208 if (m_myInst.findCallback(#CBNAME)) \
209 m_myInst.callCallback(Py_BuildValue("()")); \
210 else \
211 PCLASS::CBNAME(); \
212 wxPySaveThread(doSave); \
213 } \
214 void CLASS::base_##CBNAME() { \
215 PCLASS::CBNAME(); \
216 }
217
218 //---------------------------------------------------------------------------
219
220 #define DEC_PYCALLBACK_BOOL_INTINT(CBNAME) \
221 bool CBNAME(int a, int b); \
222 bool base_##CBNAME(int a, int b);
223
224
225 #define IMP_PYCALLBACK_BOOL_INTINT(CLASS, PCLASS, CBNAME) \
226 bool CLASS::CBNAME(int a, int b) { \
227 bool rval; \
228 bool doSave = wxPyRestoreThread(); \
229 if (m_myInst.findCallback(#CBNAME)) \
230 rval = m_myInst.callCallback(Py_BuildValue("(ii)",a,b)); \
231 else \
232 rval = PCLASS::CBNAME(a,b); \
233 wxPySaveThread(doSave); \
234 return rval; \
235 } \
236 bool CLASS::base_##CBNAME(int a, int b) { \
237 return PCLASS::CBNAME(a,b); \
238 }
239
240 //---------------------------------------------------------------------------
241
242 #define DEC_PYCALLBACK_BOOL_INT(CBNAME) \
243 bool CBNAME(int a); \
244 bool base_##CBNAME(int a);
245
246
247 #define IMP_PYCALLBACK_BOOL_INT(CLASS, PCLASS, CBNAME) \
248 bool CLASS::CBNAME(int a) { \
249 bool rval; \
250 bool doSave = wxPyRestoreThread(); \
251 if (m_myInst.findCallback(#CBNAME)) \
252 rval = m_myInst.callCallback(Py_BuildValue("(i)",a)); \
253 else \
254 rval = PCLASS::CBNAME(a); \
255 wxPySaveThread(doSave); \
256 return rval; \
257 } \
258 bool CLASS::base_##CBNAME(int a) { \
259 return PCLASS::CBNAME(a); \
260 }
261
262 //---------------------------------------------------------------------------
263
264 #define DEC_PYCALLBACK_BOOL_INT_pure(CBNAME) \
265 bool CBNAME(int a);
266
267
268 #define IMP_PYCALLBACK_BOOL_INT_pure(CLASS, PCLASS, CBNAME) \
269 bool CLASS::CBNAME(int a) { \
270 bool rval; \
271 bool doSave = wxPyRestoreThread(); \
272 if (m_myInst.findCallback(#CBNAME)) \
273 rval = m_myInst.callCallback(Py_BuildValue("(i)",a)); \
274 else rval = false; \
275 wxPySaveThread(doSave); \
276 return rval; \
277 }
278
279
280 //---------------------------------------------------------------------------
281
282 #define DEC_PYCALLBACK__DC(CBNAME) \
283 void CBNAME(wxDC& a); \
284 void base_##CBNAME(wxDC& a);
285
286
287 #define IMP_PYCALLBACK__DC(CLASS, PCLASS, CBNAME) \
288 void CLASS::CBNAME(wxDC& a) { \
289 bool doSave = wxPyRestoreThread(); \
290 if (m_myInst.findCallback(#CBNAME)) \
291 m_myInst.callCallback(Py_BuildValue("(O)", \
292 wxPyConstructObject(&a, "wxDC"))); \
293 else \
294 PCLASS::CBNAME(a); \
295 wxPySaveThread(doSave); \
296 } \
297 void CLASS::base_##CBNAME(wxDC& a) { \
298 PCLASS::CBNAME(a); \
299 }
300
301
302
303 //---------------------------------------------------------------------------
304
305 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
306 void CBNAME(wxDC& a, bool b); \
307 void base_##CBNAME(wxDC& a, bool b);
308
309
310 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
311 void CLASS::CBNAME(wxDC& a, bool b) { \
312 bool doSave = wxPyRestoreThread(); \
313 if (m_myInst.findCallback(#CBNAME)) \
314 m_myInst.callCallback(Py_BuildValue("(Oi)", \
315 wxPyConstructObject(&a, "wxDC"), (int)b)); \
316 else \
317 PCLASS::CBNAME(a, b); \
318 wxPySaveThread(doSave); \
319 } \
320 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
321 PCLASS::CBNAME(a, b); \
322 }
323
324 //---------------------------------------------------------------------------
325
326 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
327 void CBNAME(wxDC& a, bool b); \
328 void base_##CBNAME(wxDC& a, bool b);
329
330
331 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
332 void CLASS::CBNAME(wxDC& a, bool b) { \
333 bool doSave = wxPyRestoreThread(); \
334 if (m_myInst.findCallback(#CBNAME)) \
335 m_myInst.callCallback(Py_BuildValue("(Oi)", \
336 wxPyConstructObject(&a, "wxDC"), (int)b)); \
337 else \
338 PCLASS::CBNAME(a, b); \
339 wxPySaveThread(doSave); \
340 } \
341 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
342 PCLASS::CBNAME(a, b); \
343 }
344
345 //---------------------------------------------------------------------------
346
347 #define DEC_PYCALLBACK__2DBL(CBNAME) \
348 void CBNAME(double a, double b); \
349 void base_##CBNAME(double a, double b);
350
351
352 #define IMP_PYCALLBACK__2DBL(CLASS, PCLASS, CBNAME) \
353 void CLASS::CBNAME(double a, double b) { \
354 bool doSave = wxPyRestoreThread(); \
355 if (m_myInst.findCallback(#CBNAME)) \
356 m_myInst.callCallback(Py_BuildValue("(dd)",a,b)); \
357 else \
358 PCLASS::CBNAME(a, b); \
359 wxPySaveThread(doSave); \
360 } \
361 void CLASS::base_##CBNAME(double a, double b) { \
362 PCLASS::CBNAME(a, b); \
363 }
364
365 //---------------------------------------------------------------------------
366
367 #define DEC_PYCALLBACK__2DBL2INT(CBNAME) \
368 void CBNAME(double a, double b, int c, int d); \
369 void base_##CBNAME(double a, double b, int c, int d);
370
371
372 #define IMP_PYCALLBACK__2DBL2INT(CLASS, PCLASS, CBNAME) \
373 void CLASS::CBNAME(double a, double b, int c, int d) { \
374 bool doSave = wxPyRestoreThread(); \
375 if (m_myInst.findCallback(#CBNAME)) \
376 m_myInst.callCallback(Py_BuildValue("(ddii)", \
377 a,b,c,d)); \
378 else \
379 PCLASS::CBNAME(a, b, c, d); \
380 wxPySaveThread(doSave); \
381 } \
382 void CLASS::base_##CBNAME(double a, double b, int c, int d) { \
383 PCLASS::CBNAME(a, b, c, d); \
384 }
385
386 //---------------------------------------------------------------------------
387
388 #define DEC_PYCALLBACK__DC4DBLBOOL(CBNAME) \
389 void CBNAME(wxDC& a, double b, double c, double d, double e, bool f); \
390 void base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f);
391
392
393 #define IMP_PYCALLBACK__DC4DBLBOOL(CLASS, PCLASS, CBNAME) \
394 void CLASS::CBNAME(wxDC& a, double b, double c, double d, double e, bool f) { \
395 bool doSave = wxPyRestoreThread(); \
396 if (m_myInst.findCallback(#CBNAME)) \
397 m_myInst.callCallback(Py_BuildValue("(Oddddi)", \
398 wxPyConstructObject(&a, "wxDC"), \
399 b, c, d, e, (int)f)); \
400 else \
401 PCLASS::CBNAME(a, b, c, d, e, f); \
402 wxPySaveThread(doSave); \
403 } \
404 void CLASS::base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f) {\
405 PCLASS::CBNAME(a, b, c, d, e, f); \
406 }
407
408 //---------------------------------------------------------------------------
409
410 #define DEC_PYCALLBACK_BOOL_DC4DBLBOOL(CBNAME) \
411 bool CBNAME(wxDC& a, double b, double c, double d, double e, bool f); \
412 bool base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f);
413
414
415 #define IMP_PYCALLBACK_BOOL_DC4DBLBOOL(CLASS, PCLASS, CBNAME) \
416 bool CLASS::CBNAME(wxDC& a, double b, double c, double d, double e, bool f) { \
417 bool doSave = wxPyRestoreThread(); \
418 bool rval; \
419 if (m_myInst.findCallback(#CBNAME)) \
420 rval = m_myInst.callCallback(Py_BuildValue("(Oddddi)", \
421 wxPyConstructObject(&a, "wxDC"), \
422 b, c, d, e, (int)f)); \
423 else \
424 rval = PCLASS::CBNAME(a, b, c, d, e, f); \
425 wxPySaveThread(doSave); \
426 return rval; \
427 } \
428 bool CLASS::base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f) {\
429 return PCLASS::CBNAME(a, b, c, d, e, f); \
430 }
431
432 //---------------------------------------------------------------------------
433
434 #define DEC_PYCALLBACK__BOOL2DBL2INT(CBNAME) \
435 void CBNAME(bool a, double b, double c, int d, int e); \
436 void base_##CBNAME(bool a, double b, double c, int d, int e);
437
438
439 #define IMP_PYCALLBACK__BOOL2DBL2INT(CLASS, PCLASS, CBNAME) \
440 void CLASS::CBNAME(bool a, double b, double c, int d, int e) { \
441 bool doSave = wxPyRestoreThread(); \
442 if (m_myInst.findCallback(#CBNAME)) \
443 m_myInst.callCallback(Py_BuildValue("(idii)", \
444 (int)a,b,c,d,e)); \
445 else \
446 PCLASS::CBNAME(a, b, c, d, e); \
447 wxPySaveThread(doSave); \
448 } \
449 void CLASS::base_##CBNAME(bool a, double b, double c, int d, int e) { \
450 PCLASS::CBNAME(a, b, c, d, e); \
451 }
452
453 //---------------------------------------------------------------------------
454
455 #define DEC_PYCALLBACK__DC4DBL(CBNAME) \
456 void CBNAME(wxDC& a, double b, double c, double d, double e); \
457 void base_##CBNAME(wxDC& a, double b, double c, double d, double e);
458
459
460 #define IMP_PYCALLBACK__DC4DBL(CLASS, PCLASS, CBNAME) \
461 void CLASS::CBNAME(wxDC& a, double b, double c, double d, double e) { \
462 bool doSave = wxPyRestoreThread(); \
463 if (m_myInst.findCallback(#CBNAME)) \
464 m_myInst.callCallback(Py_BuildValue("(Odddd)", \
465 wxPyConstructObject(&a, "wxDC"), \
466 b, c, d, e)); \
467 else \
468 PCLASS::CBNAME(a, b, c, d, e); \
469 wxPySaveThread(doSave); \
470 } \
471 void CLASS::base_##CBNAME(wxDC& a, double b, double c, double d, double e) {\
472 PCLASS::CBNAME(a, b, c, d, e); \
473 }
474
475 //---------------------------------------------------------------------------
476
477 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
478 void CBNAME(wxDC& a, bool b); \
479 void base_##CBNAME(wxDC& a, bool b);
480
481
482 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
483 void CLASS::CBNAME(wxDC& a, bool b) { \
484 bool doSave = wxPyRestoreThread(); \
485 if (m_myInst.findCallback(#CBNAME)) \
486 m_myInst.callCallback(Py_BuildValue("(Oi)", \
487 wxPyConstructObject(&a, "wxDC"), \
488 (int)b)); \
489 else \
490 PCLASS::CBNAME(a, b); \
491 wxPySaveThread(doSave); \
492 } \
493 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
494 PCLASS::CBNAME(a, b); \
495 }
496
497 //---------------------------------------------------------------------------
498
499 #define DEC_PYCALLBACK__WXCPBOOL2DBL2INT(CBNAME) \
500 void CBNAME(wxControlPoint* a, bool b, double c, double d, int e, int f); \
501 void base_##CBNAME(wxControlPoint* a, bool b, double c, double d, int e, int f);
502
503
504 #define IMP_PYCALLBACK__WXCPBOOL2DBL2INT(CLASS, PCLASS, CBNAME) \
505 void CLASS::CBNAME(wxControlPoint* a, bool b, double c, double d, \
506 int e, int f) { \
507 bool doSave = wxPyRestoreThread(); \
508 if (m_myInst.findCallback(#CBNAME)) \
509 m_myInst.callCallback(Py_BuildValue("(Oiddii)", \
510 wxPyConstructObject(a, "wxPyControlPoint"), \
511 (int)b, c, d, e, f)); \
512 else \
513 PCLASS::CBNAME(a, b, c, d, e, f); \
514 wxPySaveThread(doSave); \
515 } \
516 void CLASS::base_##CBNAME(wxControlPoint* a, bool b, double c, double d, \
517 int e, int f) { \
518 PCLASS::CBNAME(a, b, c, d, e, f); \
519 }
520
521 //---------------------------------------------------------------------------
522
523 #define DEC_PYCALLBACK__WXCP2DBL2INT(CBNAME) \
524 void CBNAME(wxControlPoint* a, double b, double c, int d, int e); \
525 void base_##CBNAME(wxControlPoint* a, double b, double c, int d, int e);
526
527
528 #define IMP_PYCALLBACK__WXCP2DBL2INT(CLASS, PCLASS, CBNAME) \
529 void CLASS::CBNAME(wxControlPoint* a, double b, double c, int d, int e) { \
530 bool doSave = wxPyRestoreThread(); \
531 if (m_myInst.findCallback(#CBNAME)) \
532 m_myInst.callCallback(Py_BuildValue("(Oddii)", \
533 wxPyConstructObject(a, "wxPyControlPoint"), \
534 b, c, d, e)); \
535 else \
536 PCLASS::CBNAME(a, b, c, d, e); \
537 wxPySaveThread(doSave); \
538 } \
539 void CLASS::base_##CBNAME(wxControlPoint* a, double b, double c, \
540 int d, int e) { \
541 PCLASS::CBNAME(a, b, c, d, e); \
542 }
543
544 //---------------------------------------------------------------------------
545
546 #define DEC_PYCALLBACK__2DBLINT(CBNAME) \
547 void CBNAME(double a, double b, int c); \
548 void base_##CBNAME(double a, double b, int c);
549
550
551 #define IMP_PYCALLBACK__2DBLINT(CLASS, PCLASS, CBNAME) \
552 void CLASS::CBNAME(double a, double b, int c) { \
553 bool doSave = wxPyRestoreThread(); \
554 if (m_myInst.findCallback(#CBNAME)) \
555 m_myInst.callCallback(Py_BuildValue("(ddi)", a,b,c)); \
556 else \
557 PCLASS::CBNAME(a, b, c); \
558 wxPySaveThread(doSave); \
559 } \
560 void CLASS::base_##CBNAME(double a, double b, int c) { \
561 PCLASS::CBNAME(a, b, c); \
562 }
563
564 //---------------------------------------------------------------------------
565
566 #define DEC_PYCALLBACK__BOOL2DBLINT(CBNAME) \
567 void CBNAME(bool a, double b, double c, int d); \
568 void base_##CBNAME(bool a, double b, double c, int d);
569
570
571 #define IMP_PYCALLBACK__BOOL2DBLINT(CLASS, PCLASS, CBNAME) \
572 void CLASS::CBNAME(bool a, double b, double c, int d) { \
573 bool doSave = wxPyRestoreThread(); \
574 if (m_myInst.findCallback(#CBNAME)) \
575 m_myInst.callCallback(Py_BuildValue("(iddi)", (int)a,b,c,d)); \
576 else \
577 PCLASS::CBNAME(a, b, c, d); \
578 wxPySaveThread(doSave); \
579 } \
580 void CLASS::base_##CBNAME(bool a, double b, double c, int d) { \
581 PCLASS::CBNAME(a, b, c, d); \
582 }
583
584 //---------------------------------------------------------------------------
585 //---------------------------------------------------------------------------
586
587 #define DEC_PYCALLBACK__STRING(CBNAME) \
588 void CBNAME(const wxString& a); \
589 void base_##CBNAME(const wxString& a);
590
591
592 #define IMP_PYCALLBACK__STRING(CLASS, PCLASS, CBNAME) \
593 void CLASS::CBNAME(const wxString& a) { \
594 bool doSave = wxPyRestoreThread(); \
595 if (m_myInst.findCallback(#CBNAME)) \
596 m_myInst.callCallback(Py_BuildValue("(s)", a.c_str())); \
597 else \
598 PCLASS::CBNAME(a); \
599 wxPySaveThread(doSave); \
600 } \
601 void CLASS::base_##CBNAME(const wxString& a) { \
602 PCLASS::CBNAME(a); \
603 }
604
605 //---------------------------------------------------------------------------
606
607 #define DEC_PYCALLBACK_BOOL_STRING(CBNAME) \
608 bool CBNAME(const wxString& a); \
609 bool base_##CBNAME(const wxString& a);
610
611
612 #define IMP_PYCALLBACK_BOOL_STRING(CLASS, PCLASS, CBNAME) \
613 bool CLASS::CBNAME(const wxString& a) { \
614 bool rval; \
615 bool doSave = wxPyRestoreThread(); \
616 if (m_myInst.findCallback(#CBNAME)) \
617 rval = m_myInst.callCallback(Py_BuildValue("(s)", a.c_str())); \
618 else \
619 rval = PCLASS::CBNAME(a); \
620 wxPySaveThread(doSave); \
621 return rval; \
622 } \
623 bool CLASS::base_##CBNAME(const wxString& a) { \
624 return PCLASS::CBNAME(a); \
625 }
626
627 //---------------------------------------------------------------------------
628
629 #define DEC_PYCALLBACK_BOOL_STRINGSTRING(CBNAME) \
630 bool CBNAME(const wxString& a, const wxString& b); \
631 bool base_##CBNAME(const wxString& a, const wxString& b);
632
633
634 #define IMP_PYCALLBACK_BOOL_STRINGSTRING(CLASS, PCLASS, CBNAME) \
635 bool CLASS::CBNAME(const wxString& a, const wxString& b) { \
636 bool rval; \
637 bool doSave = wxPyRestoreThread(); \
638 if (m_myInst.findCallback(#CBNAME)) \
639 rval = m_myInst.callCallback(Py_BuildValue("(ss)", \
640 a.c_str(), b.c_str())); \
641 else \
642 rval = PCLASS::CBNAME(a, b); \
643 wxPySaveThread(doSave); \
644 return rval; \
645 } \
646 bool CLASS::base_##CBNAME(const wxString& a, const wxString& b) { \
647 return PCLASS::CBNAME(a, b); \
648 }
649
650 //---------------------------------------------------------------------------
651
652 #define DEC_PYCALLBACK_STRING_(CBNAME) \
653 wxString CBNAME(); \
654 wxString base_##CBNAME();
655
656
657 #define IMP_PYCALLBACK_STRING_(CLASS, PCLASS, CBNAME) \
658 wxString CLASS::CBNAME() { \
659 wxString rval; \
660 bool doSave = wxPyRestoreThread(); \
661 if (m_myInst.findCallback(#CBNAME)) { \
662 PyObject* ro; \
663 ro = m_myInst.callCallbackObj(Py_BuildValue("()")); \
664 rval = PyString_AsString(PyObject_Str(ro)); \
665 } \
666 else \
667 rval = PCLASS::CBNAME(a); \
668 wxPySaveThread(doSave); \
669 return rval; \
670 } \
671 bool CLASS::base_##CBNAME(const wxString& a) { \
672 return PCLASS::CBNAME(a); \
673 }
674
675 //---------------------------------------------------------------------------
676
677 #define DEC_PYCALLBACK_STRING__pure(CBNAME) \
678 wxString CBNAME();
679
680
681 #define IMP_PYCALLBACK_STRING__pure(CLASS, PCLASS, CBNAME) \
682 wxString CLASS::CBNAME() { \
683 wxString rval; \
684 bool doSave = wxPyRestoreThread(); \
685 if (m_myInst.findCallback(#CBNAME)) { \
686 PyObject* ro; \
687 ro = m_myInst.callCallbackObj(Py_BuildValue("()")); \
688 rval = PyString_AsString(PyObject_Str(ro)); \
689 } \
690 wxPySaveThread(doSave); \
691 return rval; \
692 }
693
694 //---------------------------------------------------------------------------
695
696 #define DEC_PYCALLBACK_BOOL_TAG_pure(CBNAME) \
697 bool CBNAME(const wxHtmlTag& a); \
698
699
700 #define IMP_PYCALLBACK_BOOL_TAG_pure(CLASS, PCLASS, CBNAME) \
701 bool CLASS::CBNAME(const wxHtmlTag& a) { \
702 bool rval = false; \
703 bool doSave = wxPyRestoreThread(); \
704 if (m_myInst.findCallback(#CBNAME)) \
705 rval = m_myInst.callCallback(Py_BuildValue("(O)", \
706 wxPyConstructObject((void*)&a,"wxHtmlTag"))); \
707 wxPySaveThread(doSave); \
708 return rval; \
709 }
710
711 //---------------------------------------------------------------------------
712
713 #define DEC_PYCALLBACK___pure(CBNAME) \
714 void CBNAME(); \
715
716
717 #define IMP_PYCALLBACK___pure(CLASS, PCLASS, CBNAME) \
718 void CLASS::CBNAME() { \
719 bool doSave = wxPyRestoreThread(); \
720 if (m_myInst.findCallback(#CBNAME)) \
721 m_myInst.callCallback(Py_BuildValue("()")); \
722 wxPySaveThread(doSave); \
723 }
724
725 //---------------------------------------------------------------------------
726
727 #define DEC_PYCALLBACK_wxSize__pure(CBNAME) \
728 wxSize CBNAME(); \
729
730
731 #define IMP_PYCALLBACK_wxSize__pure(CLASS, PCLASS, CBNAME) \
732 wxSize CLASS::CBNAME() { \
733 wxSize rval(0,0); \
734 bool doSave = wxPyRestoreThread(); \
735 if (m_myInst.findCallback(#CBNAME)) { \
736 PyObject* ro; \
737 wxSize* ptr; \
738 ro = m_myInst.callCallbackObj(Py_BuildValue("()")); \
739 if (! SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p")) \
740 rval = *ptr; \
741 } \
742 wxPySaveThread(doSave); \
743 return rval; \
744 }
745
746 //---------------------------------------------------------------------------
747
748 #define DEC_PYCALLBACK_BOOL_WXWIN(CBNAME) \
749 bool CBNAME(wxWindow* a); \
750 bool base_##CBNAME(wxWindow* a);
751
752
753 #define IMP_PYCALLBACK_BOOL_WXWIN(CLASS, PCLASS, CBNAME) \
754 bool CLASS::CBNAME(wxWindow* a) { \
755 bool rval; \
756 bool doSave = wxPyRestoreThread(); \
757 if (m_myInst.findCallback(#CBNAME)) \
758 rval = m_myInst.callCallback(Py_BuildValue("(O)", \
759 wxPyConstructObject((void*)a,"wxWindow"))); \
760 else \
761 rval = PCLASS::CBNAME(a); \
762 wxPySaveThread(doSave); \
763 return rval; \
764 } \
765 bool CLASS::base_##CBNAME(wxWindow* a) { \
766 return PCLASS::CBNAME(a); \
767 }
768
769 //---------------------------------------------------------------------------
770
771 #define DEC_PYCALLBACK_BOOL_(CBNAME) \
772 bool CBNAME(); \
773 bool base_##CBNAME();
774
775
776 #define IMP_PYCALLBACK_BOOL_(CLASS, PCLASS, CBNAME) \
777 bool CLASS::CBNAME() { \
778 bool rval; \
779 bool doSave = wxPyRestoreThread(); \
780 if (m_myInst.findCallback(#CBNAME)) \
781 rval = m_myInst.callCallback(Py_BuildValue("()")); \
782 else \
783 rval = PCLASS::CBNAME(); \
784 wxPySaveThread(doSave); \
785 return rval; \
786 } \
787 bool CLASS::base_##CBNAME() { \
788 return PCLASS::CBNAME(); \
789 }
790
791 //---------------------------------------------------------------------------
792 //---------------------------------------------------------------------------
793 //---------------------------------------------------------------------------
794
795 #endif
796
797
798