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