]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/src/helpers.h
Some updates and fixes
[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, const char* className);
70 HELPEREXPORT bool wxPyRestoreThread();
71 HELPEREXPORT void wxPySaveThread(bool doSave);
72 HELPEREXPORT PyObject* wxPy_ConvertList(wxListBase* list, const char* className);
73 HELPEREXPORT long wxPyGetWinHandle(wxWindow* win);
74
75 //----------------------------------------------------------------------
76
77 class wxPyUserData : public wxObject {
78 public:
79 wxPyUserData(PyObject* obj) { m_obj = obj; Py_INCREF(m_obj); }
80 ~wxPyUserData() {
81 bool doSave = wxPyRestoreThread();
82 Py_DECREF(m_obj);
83 wxPySaveThread(doSave);
84 }
85 PyObject* m_obj;
86 };
87
88 //----------------------------------------------------------------------
89 // These are helpers used by the typemaps
90
91 HELPEREXPORT byte* byte_LIST_helper(PyObject* source);
92 HELPEREXPORT int* int_LIST_helper(PyObject* source);
93 HELPEREXPORT long* long_LIST_helper(PyObject* source);
94 HELPEREXPORT char** string_LIST_helper(PyObject* source);
95 HELPEREXPORT wxPoint* wxPoint_LIST_helper(PyObject* source);
96 HELPEREXPORT wxBitmap** wxBitmap_LIST_helper(PyObject* source);
97 HELPEREXPORT wxString* wxString_LIST_helper(PyObject* source);
98 HELPEREXPORT wxAcceleratorEntry* wxAcceleratorEntry_LIST_helper(PyObject* source);
99
100 HELPEREXPORT bool wxSize_helper(PyObject* source, wxSize** obj);
101 HELPEREXPORT bool wxPoint_helper(PyObject* source, wxPoint** obj);
102 HELPEREXPORT bool wxRealPoint_helper(PyObject* source, wxRealPoint** obj);
103 HELPEREXPORT bool wxRect_helper(PyObject* source, wxRect** obj);
104
105 //----------------------------------------------------------------------
106
107 #ifndef SWIGCODE
108 extern "C" void SWIG_MakePtr(char *, void *, char *);
109 extern "C" char *SWIG_GetPtr(char *, void **, char *);
110 extern "C" char *SWIG_GetPtrObj(PyObject *obj, void **ptr, char *type);
111 #endif
112
113
114 #ifdef _MSC_VER
115 # pragma warning(disable:4800)
116 #endif
117
118
119
120 // Non-const versions to keep SWIG happy.
121 extern wxPoint wxPyDefaultPosition;
122 extern wxSize wxPyDefaultSize;
123 extern wxString wxPyEmptyStr;
124
125 //----------------------------------------------------------------------
126
127 class wxPyCallback : public wxObject {
128 DECLARE_ABSTRACT_CLASS(wxPyCallback);
129 public:
130 wxPyCallback(PyObject* func);
131 wxPyCallback(const wxPyCallback& other);
132 ~wxPyCallback();
133
134 void EventThunker(wxEvent& event);
135
136 PyObject* m_func;
137 };
138
139 //---------------------------------------------------------------------------
140
141 class wxPyTimer : public wxTimer {
142 public:
143 wxPyTimer(PyObject* callback);
144 ~wxPyTimer();
145
146 void Notify();
147
148 private:
149 PyObject* func;
150 };
151
152 //---------------------------------------------------------------------------
153
154
155
156
157 //---------------------------------------------------------------------------
158 // This class holds an instance of a Python Shadow Class object and assists
159 // with looking up and invoking Python callback methods from C++ virtual
160 // method redirections. For all classes which have virtuals which should be
161 // overridable in wxPython, a new subclass is created that contains a
162 // wxPyCallbackHelper.
163 //
164 // **** This class should be combined with wxPyCallback defined above.
165 //
166
167 class HELPEREXPORT wxPyCallbackHelper {
168 public:
169 wxPyCallbackHelper();
170 ~wxPyCallbackHelper();
171
172 wxPyCallbackHelper(const wxPyCallbackHelper& other);
173
174 void setSelf(PyObject* self, int incref=TRUE);
175
176 bool findCallback(const wxString& name);
177 int callCallback(PyObject* argTuple);
178 PyObject* callCallbackObj(PyObject* argTuple);
179
180 private:
181 PyObject* m_self;
182 PyObject* m_lastFound;
183 int m_incRef;
184 };
185
186
187 //---------------------------------------------------------------------------
188 //---------------------------------------------------------------------------
189 // These Event classes can be derived from in Python and passed through the
190 // event system without loosing anything. They do this by keeping a reference
191 // to themselves and some special case handling in wxPyCallback::EventThunker.
192
193
194 class wxPyEvtSelfRef {
195 public:
196 wxPyEvtSelfRef();
197 ~wxPyEvtSelfRef();
198
199 void SetSelf(PyObject* self, bool clone=FALSE);
200 PyObject* GetSelf() const;
201
202 protected:
203 PyObject* m_self;
204 bool m_cloned;
205 };
206
207
208 class wxPyEvent : public wxEvent, public wxPyEvtSelfRef {
209 DECLARE_DYNAMIC_CLASS(wxPyEvent)
210 public:
211 wxPyEvent(int id=0);
212 ~wxPyEvent();
213
214 void CopyObject(wxObject& dest) const;
215 };
216
217
218 class wxPyCommandEvent : public wxCommandEvent, public wxPyEvtSelfRef {
219 DECLARE_DYNAMIC_CLASS(wxPyCommandEvent)
220 public:
221 wxPyCommandEvent(wxEventType commandType = wxEVT_NULL, int id=0);
222 ~wxPyCommandEvent();
223
224 void CopyObject(wxObject& dest) const;
225 };
226
227
228 //---------------------------------------------------------------------------
229 // These macros are used to implement the virtual methods that should
230 // redirect to a Python method if one exists. The names designate the
231 // return type, if any, as well as any parameter types.
232 //---------------------------------------------------------------------------
233
234 #define PYPRIVATE \
235 void _setSelf(PyObject* self, int incref=1) { \
236 m_myInst.setSelf(self, incref); \
237 } \
238 private: wxPyCallbackHelper m_myInst;
239
240 //---------------------------------------------------------------------------
241
242 #define DEC_PYCALLBACK__(CBNAME) \
243 void CBNAME(); \
244 void base_##CBNAME();
245
246
247 #define IMP_PYCALLBACK__(CLASS, PCLASS, CBNAME) \
248 void CLASS::CBNAME() { \
249 bool doSave = wxPyRestoreThread(); \
250 if (m_myInst.findCallback(#CBNAME)) \
251 m_myInst.callCallback(Py_BuildValue("()")); \
252 else \
253 PCLASS::CBNAME(); \
254 wxPySaveThread(doSave); \
255 } \
256 void CLASS::base_##CBNAME() { \
257 PCLASS::CBNAME(); \
258 }
259
260 //---------------------------------------------------------------------------
261
262 #define DEC_PYCALLBACK_BOOL_INTINT(CBNAME) \
263 bool CBNAME(int a, int b); \
264 bool base_##CBNAME(int a, int b);
265
266
267 #define IMP_PYCALLBACK_BOOL_INTINT(CLASS, PCLASS, CBNAME) \
268 bool CLASS::CBNAME(int a, int b) { \
269 bool rval; \
270 bool doSave = wxPyRestoreThread(); \
271 if (m_myInst.findCallback(#CBNAME)) \
272 rval = m_myInst.callCallback(Py_BuildValue("(ii)",a,b)); \
273 else \
274 rval = PCLASS::CBNAME(a,b); \
275 wxPySaveThread(doSave); \
276 return rval; \
277 } \
278 bool CLASS::base_##CBNAME(int a, int b) { \
279 return PCLASS::CBNAME(a,b); \
280 }
281
282 //---------------------------------------------------------------------------
283
284 #define DEC_PYCALLBACK_BOOL_INT(CBNAME) \
285 bool CBNAME(int a); \
286 bool base_##CBNAME(int a);
287
288
289 #define IMP_PYCALLBACK_BOOL_INT(CLASS, PCLASS, CBNAME) \
290 bool CLASS::CBNAME(int a) { \
291 bool rval; \
292 bool doSave = wxPyRestoreThread(); \
293 if (m_myInst.findCallback(#CBNAME)) \
294 rval = m_myInst.callCallback(Py_BuildValue("(i)",a)); \
295 else \
296 rval = PCLASS::CBNAME(a); \
297 wxPySaveThread(doSave); \
298 return rval; \
299 } \
300 bool CLASS::base_##CBNAME(int a) { \
301 return PCLASS::CBNAME(a); \
302 }
303
304 //---------------------------------------------------------------------------
305
306 #define DEC_PYCALLBACK_BOOL_INT_pure(CBNAME) \
307 bool CBNAME(int a);
308
309
310 #define IMP_PYCALLBACK_BOOL_INT_pure(CLASS, PCLASS, CBNAME) \
311 bool CLASS::CBNAME(int a) { \
312 bool rval; \
313 bool doSave = wxPyRestoreThread(); \
314 if (m_myInst.findCallback(#CBNAME)) \
315 rval = m_myInst.callCallback(Py_BuildValue("(i)",a)); \
316 else rval = FALSE; \
317 wxPySaveThread(doSave); \
318 return rval; \
319 }
320
321
322 //---------------------------------------------------------------------------
323
324 #define DEC_PYCALLBACK__DC(CBNAME) \
325 void CBNAME(wxDC& a); \
326 void base_##CBNAME(wxDC& a);
327
328
329 #define IMP_PYCALLBACK__DC(CLASS, PCLASS, CBNAME) \
330 void CLASS::CBNAME(wxDC& a) { \
331 bool doSave = wxPyRestoreThread(); \
332 if (m_myInst.findCallback(#CBNAME)) \
333 m_myInst.callCallback(Py_BuildValue("(O)", \
334 wxPyConstructObject(&a, "wxDC"))); \
335 else \
336 PCLASS::CBNAME(a); \
337 wxPySaveThread(doSave); \
338 } \
339 void CLASS::base_##CBNAME(wxDC& a) { \
340 PCLASS::CBNAME(a); \
341 }
342
343
344
345 //---------------------------------------------------------------------------
346
347 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
348 void CBNAME(wxDC& a, bool b); \
349 void base_##CBNAME(wxDC& a, bool b);
350
351
352 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
353 void CLASS::CBNAME(wxDC& a, bool b) { \
354 bool doSave = wxPyRestoreThread(); \
355 if (m_myInst.findCallback(#CBNAME)) \
356 m_myInst.callCallback(Py_BuildValue("(Oi)", \
357 wxPyConstructObject(&a, "wxDC"), (int)b)); \
358 else \
359 PCLASS::CBNAME(a, b); \
360 wxPySaveThread(doSave); \
361 } \
362 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
363 PCLASS::CBNAME(a, b); \
364 }
365
366 //---------------------------------------------------------------------------
367
368 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
369 void CBNAME(wxDC& a, bool b); \
370 void base_##CBNAME(wxDC& a, bool b);
371
372
373 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
374 void CLASS::CBNAME(wxDC& a, bool b) { \
375 bool doSave = wxPyRestoreThread(); \
376 if (m_myInst.findCallback(#CBNAME)) \
377 m_myInst.callCallback(Py_BuildValue("(Oi)", \
378 wxPyConstructObject(&a, "wxDC"), (int)b)); \
379 else \
380 PCLASS::CBNAME(a, b); \
381 wxPySaveThread(doSave); \
382 } \
383 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
384 PCLASS::CBNAME(a, b); \
385 }
386
387 //---------------------------------------------------------------------------
388
389 #define DEC_PYCALLBACK__2DBL(CBNAME) \
390 void CBNAME(double a, double b); \
391 void base_##CBNAME(double a, double b);
392
393
394 #define IMP_PYCALLBACK__2DBL(CLASS, PCLASS, CBNAME) \
395 void CLASS::CBNAME(double a, double b) { \
396 bool doSave = wxPyRestoreThread(); \
397 if (m_myInst.findCallback(#CBNAME)) \
398 m_myInst.callCallback(Py_BuildValue("(dd)",a,b)); \
399 else \
400 PCLASS::CBNAME(a, b); \
401 wxPySaveThread(doSave); \
402 } \
403 void CLASS::base_##CBNAME(double a, double b) { \
404 PCLASS::CBNAME(a, b); \
405 }
406
407 //---------------------------------------------------------------------------
408
409 #define DEC_PYCALLBACK__2DBL2INT(CBNAME) \
410 void CBNAME(double a, double b, int c, int d); \
411 void base_##CBNAME(double a, double b, int c, int d);
412
413
414 #define IMP_PYCALLBACK__2DBL2INT(CLASS, PCLASS, CBNAME) \
415 void CLASS::CBNAME(double a, double b, int c, int d) { \
416 bool doSave = wxPyRestoreThread(); \
417 if (m_myInst.findCallback(#CBNAME)) \
418 m_myInst.callCallback(Py_BuildValue("(ddii)", \
419 a,b,c,d)); \
420 else \
421 PCLASS::CBNAME(a, b, c, d); \
422 wxPySaveThread(doSave); \
423 } \
424 void CLASS::base_##CBNAME(double a, double b, int c, int d) { \
425 PCLASS::CBNAME(a, b, c, d); \
426 }
427
428 //---------------------------------------------------------------------------
429
430 #define DEC_PYCALLBACK__DC4DBLBOOL(CBNAME) \
431 void CBNAME(wxDC& a, double b, double c, double d, double e, bool f); \
432 void base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f);
433
434
435 #define IMP_PYCALLBACK__DC4DBLBOOL(CLASS, PCLASS, CBNAME) \
436 void CLASS::CBNAME(wxDC& a, double b, double c, double d, double e, bool f) { \
437 bool doSave = wxPyRestoreThread(); \
438 if (m_myInst.findCallback(#CBNAME)) \
439 m_myInst.callCallback(Py_BuildValue("(Oddddi)", \
440 wxPyConstructObject(&a, "wxDC"), \
441 b, c, d, e, (int)f)); \
442 else \
443 PCLASS::CBNAME(a, b, c, d, e, f); \
444 wxPySaveThread(doSave); \
445 } \
446 void CLASS::base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f) {\
447 PCLASS::CBNAME(a, b, c, d, e, f); \
448 }
449
450 //---------------------------------------------------------------------------
451
452 #define DEC_PYCALLBACK_BOOL_DC4DBLBOOL(CBNAME) \
453 bool CBNAME(wxDC& a, double b, double c, double d, double e, bool f); \
454 bool base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f);
455
456
457 #define IMP_PYCALLBACK_BOOL_DC4DBLBOOL(CLASS, PCLASS, CBNAME) \
458 bool CLASS::CBNAME(wxDC& a, double b, double c, double d, double e, bool f) { \
459 bool doSave = wxPyRestoreThread(); \
460 bool rval; \
461 if (m_myInst.findCallback(#CBNAME)) \
462 rval = m_myInst.callCallback(Py_BuildValue("(Oddddi)", \
463 wxPyConstructObject(&a, "wxDC"), \
464 b, c, d, e, (int)f)); \
465 else \
466 rval = PCLASS::CBNAME(a, b, c, d, e, f); \
467 wxPySaveThread(doSave); \
468 return rval; \
469 } \
470 bool CLASS::base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f) {\
471 return PCLASS::CBNAME(a, b, c, d, e, f); \
472 }
473
474 //---------------------------------------------------------------------------
475
476 #define DEC_PYCALLBACK__BOOL2DBL2INT(CBNAME) \
477 void CBNAME(bool a, double b, double c, int d, int e); \
478 void base_##CBNAME(bool a, double b, double c, int d, int e);
479
480
481 #define IMP_PYCALLBACK__BOOL2DBL2INT(CLASS, PCLASS, CBNAME) \
482 void CLASS::CBNAME(bool a, double b, double c, int d, int e) { \
483 bool doSave = wxPyRestoreThread(); \
484 if (m_myInst.findCallback(#CBNAME)) \
485 m_myInst.callCallback(Py_BuildValue("(idii)", \
486 (int)a,b,c,d,e)); \
487 else \
488 PCLASS::CBNAME(a, b, c, d, e); \
489 wxPySaveThread(doSave); \
490 } \
491 void CLASS::base_##CBNAME(bool a, double b, double c, int d, int e) { \
492 PCLASS::CBNAME(a, b, c, d, e); \
493 }
494
495 //---------------------------------------------------------------------------
496
497 #define DEC_PYCALLBACK__DC4DBL(CBNAME) \
498 void CBNAME(wxDC& a, double b, double c, double d, double e); \
499 void base_##CBNAME(wxDC& a, double b, double c, double d, double e);
500
501
502 #define IMP_PYCALLBACK__DC4DBL(CLASS, PCLASS, CBNAME) \
503 void CLASS::CBNAME(wxDC& a, double b, double c, double d, double e) { \
504 bool doSave = wxPyRestoreThread(); \
505 if (m_myInst.findCallback(#CBNAME)) \
506 m_myInst.callCallback(Py_BuildValue("(Odddd)", \
507 wxPyConstructObject(&a, "wxDC"), \
508 b, c, d, e)); \
509 else \
510 PCLASS::CBNAME(a, b, c, d, e); \
511 wxPySaveThread(doSave); \
512 } \
513 void CLASS::base_##CBNAME(wxDC& a, double b, double c, double d, double e) {\
514 PCLASS::CBNAME(a, b, c, d, e); \
515 }
516
517 //---------------------------------------------------------------------------
518
519 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
520 void CBNAME(wxDC& a, bool b); \
521 void base_##CBNAME(wxDC& a, bool b);
522
523
524 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
525 void CLASS::CBNAME(wxDC& a, bool b) { \
526 bool doSave = wxPyRestoreThread(); \
527 if (m_myInst.findCallback(#CBNAME)) \
528 m_myInst.callCallback(Py_BuildValue("(Oi)", \
529 wxPyConstructObject(&a, "wxDC"), \
530 (int)b)); \
531 else \
532 PCLASS::CBNAME(a, b); \
533 wxPySaveThread(doSave); \
534 } \
535 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
536 PCLASS::CBNAME(a, b); \
537 }
538
539 //---------------------------------------------------------------------------
540
541 #define DEC_PYCALLBACK__WXCPBOOL2DBL2INT(CBNAME) \
542 void CBNAME(wxControlPoint* a, bool b, double c, double d, int e, int f); \
543 void base_##CBNAME(wxControlPoint* a, bool b, double c, double d, int e, int f);
544
545
546 #define IMP_PYCALLBACK__WXCPBOOL2DBL2INT(CLASS, PCLASS, CBNAME) \
547 void CLASS::CBNAME(wxControlPoint* a, bool b, double c, double d, \
548 int e, int f) { \
549 bool doSave = wxPyRestoreThread(); \
550 if (m_myInst.findCallback(#CBNAME)) \
551 m_myInst.callCallback(Py_BuildValue("(Oiddii)", \
552 wxPyConstructObject(a, "wxPyControlPoint"), \
553 (int)b, c, d, e, f)); \
554 else \
555 PCLASS::CBNAME(a, b, c, d, e, f); \
556 wxPySaveThread(doSave); \
557 } \
558 void CLASS::base_##CBNAME(wxControlPoint* a, bool b, double c, double d, \
559 int e, int f) { \
560 PCLASS::CBNAME(a, b, c, d, e, f); \
561 }
562
563 //---------------------------------------------------------------------------
564
565 #define DEC_PYCALLBACK__WXCP2DBL2INT(CBNAME) \
566 void CBNAME(wxControlPoint* a, double b, double c, int d, int e); \
567 void base_##CBNAME(wxControlPoint* a, double b, double c, int d, int e);
568
569
570 #define IMP_PYCALLBACK__WXCP2DBL2INT(CLASS, PCLASS, CBNAME) \
571 void CLASS::CBNAME(wxControlPoint* a, double b, double c, int d, int e) { \
572 bool doSave = wxPyRestoreThread(); \
573 if (m_myInst.findCallback(#CBNAME)) \
574 m_myInst.callCallback(Py_BuildValue("(Oddii)", \
575 wxPyConstructObject(a, "wxPyControlPoint"), \
576 b, c, d, e)); \
577 else \
578 PCLASS::CBNAME(a, b, c, d, e); \
579 wxPySaveThread(doSave); \
580 } \
581 void CLASS::base_##CBNAME(wxControlPoint* a, double b, double c, \
582 int d, int e) { \
583 PCLASS::CBNAME(a, b, c, d, e); \
584 }
585
586 //---------------------------------------------------------------------------
587
588 #define DEC_PYCALLBACK__2DBLINT(CBNAME) \
589 void CBNAME(double a, double b, int c); \
590 void base_##CBNAME(double a, double b, int c);
591
592
593 #define IMP_PYCALLBACK__2DBLINT(CLASS, PCLASS, CBNAME) \
594 void CLASS::CBNAME(double a, double b, int c) { \
595 bool doSave = wxPyRestoreThread(); \
596 if (m_myInst.findCallback(#CBNAME)) \
597 m_myInst.callCallback(Py_BuildValue("(ddi)", a,b,c)); \
598 else \
599 PCLASS::CBNAME(a, b, c); \
600 wxPySaveThread(doSave); \
601 } \
602 void CLASS::base_##CBNAME(double a, double b, int c) { \
603 PCLASS::CBNAME(a, b, c); \
604 }
605
606 //---------------------------------------------------------------------------
607
608 #define DEC_PYCALLBACK__BOOL2DBLINT(CBNAME) \
609 void CBNAME(bool a, double b, double c, int d); \
610 void base_##CBNAME(bool a, double b, double c, int d);
611
612
613 #define IMP_PYCALLBACK__BOOL2DBLINT(CLASS, PCLASS, CBNAME) \
614 void CLASS::CBNAME(bool a, double b, double c, int d) { \
615 bool doSave = wxPyRestoreThread(); \
616 if (m_myInst.findCallback(#CBNAME)) \
617 m_myInst.callCallback(Py_BuildValue("(iddi)", (int)a,b,c,d)); \
618 else \
619 PCLASS::CBNAME(a, b, c, d); \
620 wxPySaveThread(doSave); \
621 } \
622 void CLASS::base_##CBNAME(bool a, double b, double c, int d) { \
623 PCLASS::CBNAME(a, b, c, d); \
624 }
625
626 //---------------------------------------------------------------------------
627 //---------------------------------------------------------------------------
628
629 #define DEC_PYCALLBACK__STRING(CBNAME) \
630 void CBNAME(const wxString& a); \
631 void base_##CBNAME(const wxString& a);
632
633
634 #define IMP_PYCALLBACK__STRING(CLASS, PCLASS, CBNAME) \
635 void CLASS::CBNAME(const wxString& a) { \
636 bool doSave = wxPyRestoreThread(); \
637 if (m_myInst.findCallback(#CBNAME)) \
638 m_myInst.callCallback(Py_BuildValue("(s)", a.c_str())); \
639 else \
640 PCLASS::CBNAME(a); \
641 wxPySaveThread(doSave); \
642 } \
643 void CLASS::base_##CBNAME(const wxString& a) { \
644 PCLASS::CBNAME(a); \
645 }
646
647 //---------------------------------------------------------------------------
648
649 #define DEC_PYCALLBACK_BOOL_STRING(CBNAME) \
650 bool CBNAME(const wxString& a); \
651 bool base_##CBNAME(const wxString& a);
652
653
654 #define IMP_PYCALLBACK_BOOL_STRING(CLASS, PCLASS, CBNAME) \
655 bool CLASS::CBNAME(const wxString& a) { \
656 bool rval; \
657 bool doSave = wxPyRestoreThread(); \
658 if (m_myInst.findCallback(#CBNAME)) \
659 rval = m_myInst.callCallback(Py_BuildValue("(s)", a.c_str())); \
660 else \
661 rval = PCLASS::CBNAME(a); \
662 wxPySaveThread(doSave); \
663 return rval; \
664 } \
665 bool CLASS::base_##CBNAME(const wxString& a) { \
666 return PCLASS::CBNAME(a); \
667 }
668
669 //---------------------------------------------------------------------------
670
671 #define DEC_PYCALLBACK_BOOL_STRINGSTRING(CBNAME) \
672 bool CBNAME(const wxString& a, const wxString& b); \
673 bool base_##CBNAME(const wxString& a, const wxString& b);
674
675
676 #define IMP_PYCALLBACK_BOOL_STRINGSTRING(CLASS, PCLASS, CBNAME) \
677 bool CLASS::CBNAME(const wxString& a, const wxString& b) { \
678 bool rval; \
679 bool doSave = wxPyRestoreThread(); \
680 if (m_myInst.findCallback(#CBNAME)) \
681 rval = m_myInst.callCallback(Py_BuildValue("(ss)", \
682 a.c_str(), b.c_str())); \
683 else \
684 rval = PCLASS::CBNAME(a, b); \
685 wxPySaveThread(doSave); \
686 return rval; \
687 } \
688 bool CLASS::base_##CBNAME(const wxString& a, const wxString& b) { \
689 return PCLASS::CBNAME(a, b); \
690 }
691
692 //---------------------------------------------------------------------------
693
694 #define DEC_PYCALLBACK_STRING_(CBNAME) \
695 wxString CBNAME(); \
696 wxString base_##CBNAME();
697
698
699 #define IMP_PYCALLBACK_STRING_(CLASS, PCLASS, CBNAME) \
700 wxString CLASS::CBNAME() { \
701 wxString rval; \
702 bool doSave = wxPyRestoreThread(); \
703 if (m_myInst.findCallback(#CBNAME)) { \
704 PyObject* ro; \
705 ro = m_myInst.callCallbackObj(Py_BuildValue("()")); \
706 rval = PyString_AsString(PyObject_Str(ro)); \
707 } \
708 else \
709 rval = PCLASS::CBNAME(); \
710 wxPySaveThread(doSave); \
711 return rval; \
712 } \
713 wxString CLASS::base_##CBNAME() { \
714 return PCLASS::CBNAME(); \
715 }
716
717 //---------------------------------------------------------------------------
718
719 #define DEC_PYCALLBACK_STRING__pure(CBNAME) \
720 wxString CBNAME();
721
722
723 #define IMP_PYCALLBACK_STRING__pure(CLASS, PCLASS, CBNAME) \
724 wxString CLASS::CBNAME() { \
725 wxString rval; \
726 bool doSave = wxPyRestoreThread(); \
727 if (m_myInst.findCallback(#CBNAME)) { \
728 PyObject* ro; \
729 ro = m_myInst.callCallbackObj(Py_BuildValue("()")); \
730 rval = PyString_AsString(PyObject_Str(ro)); \
731 } \
732 wxPySaveThread(doSave); \
733 return rval; \
734 }
735
736 //---------------------------------------------------------------------------
737
738 #define DEC_PYCALLBACK_BOOL_TAG_pure(CBNAME) \
739 bool CBNAME(const wxHtmlTag& a); \
740
741
742 #define IMP_PYCALLBACK_BOOL_TAG_pure(CLASS, PCLASS, CBNAME) \
743 bool CLASS::CBNAME(const wxHtmlTag& a) { \
744 bool rval = FALSE; \
745 bool doSave = wxPyRestoreThread(); \
746 if (m_myInst.findCallback(#CBNAME)) \
747 rval = m_myInst.callCallback(Py_BuildValue("(O)", \
748 wxPyConstructObject((void*)&a,"wxHtmlTag"))); \
749 wxPySaveThread(doSave); \
750 return rval; \
751 }
752
753 //---------------------------------------------------------------------------
754
755 #define DEC_PYCALLBACK___pure(CBNAME) \
756 void CBNAME(); \
757
758
759 #define IMP_PYCALLBACK___pure(CLASS, PCLASS, CBNAME) \
760 void CLASS::CBNAME() { \
761 bool doSave = wxPyRestoreThread(); \
762 if (m_myInst.findCallback(#CBNAME)) \
763 m_myInst.callCallback(Py_BuildValue("()")); \
764 wxPySaveThread(doSave); \
765 }
766
767 //---------------------------------------------------------------------------
768
769 #define DEC_PYCALLBACK_wxSize__pure(CBNAME) \
770 wxSize CBNAME(); \
771
772
773 #define IMP_PYCALLBACK_wxSize__pure(CLASS, PCLASS, CBNAME) \
774 wxSize CLASS::CBNAME() { \
775 wxSize rval(0,0); \
776 bool doSave = wxPyRestoreThread(); \
777 if (m_myInst.findCallback(#CBNAME)) { \
778 PyObject* ro; \
779 wxSize* ptr; \
780 ro = m_myInst.callCallbackObj(Py_BuildValue("()")); \
781 if (! SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p")) \
782 rval = *ptr; \
783 } \
784 wxPySaveThread(doSave); \
785 return rval; \
786 }
787
788 //---------------------------------------------------------------------------
789
790 #define DEC_PYCALLBACK_BOOL_WXWIN(CBNAME) \
791 bool CBNAME(wxWindow* a); \
792 bool base_##CBNAME(wxWindow* a);
793
794
795 #define IMP_PYCALLBACK_BOOL_WXWIN(CLASS, PCLASS, CBNAME) \
796 bool CLASS::CBNAME(wxWindow* a) { \
797 bool rval; \
798 bool doSave = wxPyRestoreThread(); \
799 if (m_myInst.findCallback(#CBNAME)) \
800 rval = m_myInst.callCallback(Py_BuildValue("(O)", \
801 wxPyConstructObject((void*)a,"wxWindow"))); \
802 else \
803 rval = PCLASS::CBNAME(a); \
804 wxPySaveThread(doSave); \
805 return rval; \
806 } \
807 bool CLASS::base_##CBNAME(wxWindow* a) { \
808 return PCLASS::CBNAME(a); \
809 }
810
811 //---------------------------------------------------------------------------
812
813 #define DEC_PYCALLBACK_BOOL_(CBNAME) \
814 bool CBNAME(); \
815 bool base_##CBNAME();
816
817
818 #define IMP_PYCALLBACK_BOOL_(CLASS, PCLASS, CBNAME) \
819 bool CLASS::CBNAME() { \
820 bool rval; \
821 bool doSave = wxPyRestoreThread(); \
822 if (m_myInst.findCallback(#CBNAME)) \
823 rval = m_myInst.callCallback(Py_BuildValue("()")); \
824 else \
825 rval = PCLASS::CBNAME(); \
826 wxPySaveThread(doSave); \
827 return rval; \
828 } \
829 bool CLASS::base_##CBNAME() { \
830 return PCLASS::CBNAME(); \
831 }
832
833 //---------------------------------------------------------------------------
834
835 #define DEC_PYCALLBACK_DR_2WXCDR(CBNAME) \
836 wxDragResult CBNAME(wxCoord x, wxCoord y, wxDragResult def); \
837 wxDragResult base_##CBNAME(wxCoord x, wxCoord y, wxDragResult def);
838
839
840 #define IMP_PYCALLBACK_DR_2WXCDR(CLASS, PCLASS, CBNAME) \
841 wxDragResult CLASS::CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
842 bool doSave = wxPyRestoreThread(); \
843 int rval; \
844 if (m_myInst.findCallback(#CBNAME)) \
845 rval = m_myInst.callCallback(Py_BuildValue("(iii)", a,b,c));\
846 else \
847 rval = PCLASS::CBNAME(a, b, c); \
848 wxPySaveThread(doSave); \
849 return (wxDragResult)rval; \
850 } \
851 wxDragResult CLASS::base_##CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
852 return PCLASS::CBNAME(a, b, c); \
853 }
854
855 //---------------------------------------------------------------------------
856
857 #define DEC_PYCALLBACK_BOOL_DR(CBNAME) \
858 bool CBNAME(wxDragResult a); \
859 bool base_##CBNAME(wxDragResult a);
860
861
862 #define IMP_PYCALLBACK_BOOL_DR(CLASS, PCLASS, CBNAME) \
863 bool CLASS::CBNAME(wxDragResult a) { \
864 bool doSave = wxPyRestoreThread(); \
865 bool rval; \
866 if (m_myInst.findCallback(#CBNAME)) \
867 rval = m_myInst.callCallback(Py_BuildValue("(i)", a)); \
868 else \
869 rval = PCLASS::CBNAME(a); \
870 wxPySaveThread(doSave); \
871 return rval; \
872 } \
873 bool CLASS::base_##CBNAME(wxDragResult a) { \
874 return PCLASS::CBNAME(a); \
875 }
876
877 //---------------------------------------------------------------------------
878
879 #define DEC_PYCALLBACK_DR_2WXCDR_pure(CBNAME) \
880 wxDragResult CBNAME(wxCoord x, wxCoord y, wxDragResult def);
881
882
883 #define IMP_PYCALLBACK_DR_2WXCDR_pure(CLASS, PCLASS, CBNAME) \
884 wxDragResult CLASS::CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
885 bool doSave = wxPyRestoreThread(); \
886 int rval; \
887 if (m_myInst.findCallback(#CBNAME)) \
888 rval = m_myInst.callCallback(Py_BuildValue("(iii)", a,b,c));\
889 wxPySaveThread(doSave); \
890 return (wxDragResult)rval; \
891 } \
892
893 //---------------------------------------------------------------------------
894
895 #define DEC_PYCALLBACK_BOOL_INTINTSTR_pure(CBNAME) \
896 bool CBNAME(int a, int b, const wxString& c);
897
898
899 #define IMP_PYCALLBACK_BOOL_INTINTSTR_pure(CLASS, PCLASS, CBNAME) \
900 bool CLASS::CBNAME(int a, int b, const wxString& c) { \
901 bool rval; \
902 bool doSave = wxPyRestoreThread(); \
903 if (m_myInst.findCallback(#CBNAME)) \
904 rval = m_myInst.callCallback(Py_BuildValue("(iis)",a,b,c.c_str()));\
905 wxPySaveThread(doSave); \
906 return rval; \
907 } \
908
909 //---------------------------------------------------------------------------
910
911 #define DEC_PYCALLBACK_SIZET_(CBNAME) \
912 size_t CBNAME(); \
913 size_t base_##CBNAME();
914
915
916 #define IMP_PYCALLBACK_SIZET_(CLASS, PCLASS, CBNAME) \
917 size_t CLASS::CBNAME() { \
918 size_t rval; \
919 bool doSave = wxPyRestoreThread(); \
920 if (m_myInst.findCallback(#CBNAME)) \
921 rval = m_myInst.callCallback(Py_BuildValue("()")); \
922 else \
923 rval = PCLASS::CBNAME(); \
924 wxPySaveThread(doSave); \
925 return rval; \
926 } \
927 size_t CLASS::base_##CBNAME() { \
928 return PCLASS::CBNAME(); \
929 }
930
931 //---------------------------------------------------------------------------
932
933 #define DEC_PYCALLBACK_DATAFMT_SIZET(CBNAME) \
934 wxDataFormat CBNAME(); \
935 wxDataFormat base_##CBNAME();
936
937
938 #define IMP_PYCALLBACK_DATAFMT_SIZET(CLASS, PCLASS, CBNAME) \
939 wxDataFormat CLASS::CBNAME(size_t a) { \
940 wxDataFormat rval; \
941 bool doSave = wxPyRestoreThread(); \
942 if (m_myInst.findCallback(#CBNAME)) { \
943 PyObject* ro; \
944 wxDataFormat* ptr; \
945 ro = m_myInst.callCallbackObj(Py_BuildValue("(i)", a)); \
946 if (! SWIG_GetPtrObj(ro, (void **)&ptr, "_wxDataFormat_p")) \
947 rval = *ptr; \
948 } \
949 else \
950 rval = PCLASS::CBNAME(a); \
951 wxPySaveThread(doSave); \
952 return rval; \
953 } \
954 wxDataFormat CLASS::base_##CBNAME(size_t a) { \
955 return PCLASS::CBNAME(a); \
956 }
957
958 //---------------------------------------------------------------------------
959 //---------------------------------------------------------------------------
960 //---------------------------------------------------------------------------
961
962 #endif
963
964
965
966