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