1 ////////////////////////////////////////////////////////////////////////////
3 // Purpose: Helper functions/classes for the wxPython extenaion module
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef __wxp_helpers__
14 #define __wxp_helpers__
18 //----------------------------------------------------------------------
20 // if we want to handle threads and Python threads are available...
21 #if defined(WXP_USE_THREAD) && defined(WITH_THREAD)
23 #define WXP_WITH_THREAD
24 #define wxPy_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
25 #define wxPy_END_ALLOW_THREADS Py_END_ALLOW_THREADS
27 #else // no Python threads...
28 #undef WXP_WITH_THREAD
29 #define wxPy_BEGIN_ALLOW_THREADS
30 #define wxPy_END_ALLOW_THREADS
34 //---------------------------------------------------------------------------
36 typedef unsigned char byte
;
39 class wxPyApp
: public wxApp
47 extern wxPyApp
*wxPythonApp
;
49 //----------------------------------------------------------------------
52 PyObject
* __wxStart(PyObject
*, PyObject
* args
);
55 extern PyObject
* wxPython_dict
;
56 PyObject
* __wxSetDictionary(PyObject
*, PyObject
* args
);
58 void wxPyEventThunker(wxObject
*, wxEvent
& event
);
60 PyObject
* wxPyConstructObject(void* ptr
,
61 const char* className
,
63 bool wxPyRestoreThread();
64 void wxPySaveThread(bool doSave
);
65 PyObject
* wxPy_ConvertList(wxListBase
* list
, const char* className
);
66 long wxPyGetWinHandle(wxWindow
* win
);
70 //----------------------------------------------------------------------
71 // Handle wxInputStreams by Joerg Baumann
72 // See stream.i for implementations
74 // list class for return list of strings, e.g. readlines()
75 WX_DECLARE_LIST(wxString
, wxStringPtrList
);
78 // C++ class wxPyInputStream to act as base for python class wxInputStream
79 // Use it in python like a python file object
80 class wxPyInputStream
{
82 // underlying wxInputStream
86 wxPyInputStream(wxInputStream
* wxi_
) : wxi(wxi_
) {}
89 // python file object interface for input files (most of it)
93 wxString
* read(int size
=-1);
94 wxString
* readline(int size
=-1);
95 wxStringPtrList
* readlines(int sizehint
=-1);
96 void seek(int offset
, int whence
=0);
101 void truncate(int size=-1);
102 void write(wxString data);
103 void writelines(wxStringPtrList);
108 //----------------------------------------------------------------------
109 // These are helpers used by the typemaps
111 byte
* byte_LIST_helper(PyObject
* source
);
112 int* int_LIST_helper(PyObject
* source
);
113 long* long_LIST_helper(PyObject
* source
);
114 char** string_LIST_helper(PyObject
* source
);
115 wxPoint
* wxPoint_LIST_helper(PyObject
* source
);
116 wxBitmap
** wxBitmap_LIST_helper(PyObject
* source
);
117 wxString
* wxString_LIST_helper(PyObject
* source
);
118 wxAcceleratorEntry
* wxAcceleratorEntry_LIST_helper(PyObject
* source
);
120 bool wxSize_helper(PyObject
* source
, wxSize
** obj
);
121 bool wxPoint_helper(PyObject
* source
, wxPoint
** obj
);
122 bool wxRealPoint_helper(PyObject
* source
, wxRealPoint
** obj
);
123 bool wxRect_helper(PyObject
* source
, wxRect
** obj
);
124 bool wxColour_helper(PyObject
* source
, wxColour
** obj
);
126 //----------------------------------------------------------------------
129 extern "C" void SWIG_MakePtr(char *, void *, char *);
130 extern "C" char *SWIG_GetPtr(char *, void **, char *);
131 extern "C" char *SWIG_GetPtrObj(PyObject
*obj
, void **ptr
, char *type
);
136 # pragma warning(disable:4800)
137 # pragma warning(disable:4190)
142 // Non-const versions to keep SWIG happy.
143 // extern wxPoint wxPyDefaultPosition;
144 // extern wxSize wxPyDefaultSize;
145 // extern wxString wxPyEmptyStr;
147 //----------------------------------------------------------------------
149 class wxPyCallback
: public wxObject
{
150 DECLARE_ABSTRACT_CLASS(wxPyCallback
);
152 wxPyCallback(PyObject
* func
);
153 wxPyCallback(const wxPyCallback
& other
);
156 void EventThunker(wxEvent
& event
);
161 //---------------------------------------------------------------------------
163 class wxPyTimer
: public wxTimer
{
165 wxPyTimer(PyObject
* callback
);
174 //---------------------------------------------------------------------------
175 //---------------------------------------------------------------------------
176 // These Event classes can be derived from in Python and passed through the
177 // event system without loosing anything. They do this by keeping a reference
178 // to themselves and some special case handling in wxPyCallback::EventThunker.
181 class wxPyEvtSelfRef
{
186 void SetSelf(PyObject
* self
, bool clone
=FALSE
);
187 PyObject
* GetSelf() const;
195 class wxPyEvent
: public wxEvent
, public wxPyEvtSelfRef
{
196 DECLARE_DYNAMIC_CLASS(wxPyEvent
)
201 void CopyObject(wxObject
& dest
) const;
205 class wxPyCommandEvent
: public wxCommandEvent
, public wxPyEvtSelfRef
{
206 DECLARE_DYNAMIC_CLASS(wxPyCommandEvent
)
208 wxPyCommandEvent(wxEventType commandType
= wxEVT_NULL
, int id
=0);
211 void CopyObject(wxObject
& dest
) const;
215 //---------------------------------------------------------------------------
216 // Export a C API in a struct. Other modules will be able to load this from
217 // the wxc module and will then have safe access to these functions, even if
218 // in another shared library.
220 class wxPyCallbackHelper
;
224 void (*p_SWIG_MakePtr
)(char*, void*, char*);
225 char* (*p_SWIG_GetPtr
)(char*, void**, char*);
226 char* (*p_SWIG_GetPtrObj
)(PyObject
*, void**, char*);
227 void (*p_SWIG_RegisterMapping
)(char*, char*, void *(*cast
)(void *));
228 void (*p_SWIG_addvarlink
)(PyObject
*, char*, PyObject
*(*get_attr
)(void), int (*set_attr
)(PyObject
*p
));
229 PyObject
* (*p_SWIG_newvarlink
)(void);
231 void (*p_wxPySaveThread
)(bool);
232 bool (*p_wxPyRestoreThread
)();
233 PyObject
* (*p_wxPyConstructObject
)(void *, const char *, int);
234 PyObject
* (*p_wxPy_ConvertList
)(wxListBase
* list
, const char* className
);
236 byte
* (*p_byte_LIST_helper
)(PyObject
* source
);
237 int* (*p_int_LIST_helper
)(PyObject
* source
);
238 long* (*p_long_LIST_helper
)(PyObject
* source
);
239 char** (*p_string_LIST_helper
)(PyObject
* source
);
240 wxPoint
* (*p_wxPoint_LIST_helper
)(PyObject
* source
);
241 wxBitmap
** (*p_wxBitmap_LIST_helper
)(PyObject
* source
);
242 wxString
* (*p_wxString_LIST_helper
)(PyObject
* source
);
243 wxAcceleratorEntry
* (*p_wxAcceleratorEntry_LIST_helper
)(PyObject
* source
);
245 bool (*p_wxSize_helper
)(PyObject
* source
, wxSize
** obj
);
246 bool (*p_wxPoint_helper
)(PyObject
* source
, wxPoint
** obj
);
247 bool (*p_wxRealPoint_helper
)(PyObject
* source
, wxRealPoint
** obj
);
248 bool (*p_wxRect_helper
)(PyObject
* source
, wxRect
** obj
);
249 bool (*p_wxColour_helper
)(PyObject
* source
, wxColour
** obj
);
251 void (*p_wxPyCBH_setSelf
)(wxPyCallbackHelper
& cbh
, PyObject
* self
, PyObject
* klass
, int incref
);
252 bool (*p_wxPyCBH_findCallback
)(const wxPyCallbackHelper
& cbh
, const char* name
);
253 int (*p_wxPyCBH_callCallback
)(const wxPyCallbackHelper
& cbh
, PyObject
* argTuple
);
254 PyObject
* (*p_wxPyCBH_callCallbackObj
)(const wxPyCallbackHelper
& cbh
, PyObject
* argTuple
);
255 void (*p_wxPyCBH_delete
)(wxPyCallbackHelper
* cbh
);
259 #ifdef wxPyUSE_EXPORT
260 static wxPyCoreAPI
* wxPyCoreAPIPtr
= NULL
; // Each module needs one, but may not use it.
263 //---------------------------------------------------------------------------
264 // This class holds an instance of a Python Shadow Class object and assists
265 // with looking up and invoking Python callback methods from C++ virtual
266 // method redirections. For all classes which have virtuals which should be
267 // overridable in wxPython, a new subclass is created that contains a
268 // wxPyCallbackHelper.
271 class wxPyCallbackHelper
{
273 wxPyCallbackHelper(const wxPyCallbackHelper
& other
);
275 wxPyCallbackHelper() {
282 ~wxPyCallbackHelper() {
283 #ifdef wxPyUSE_EXPORT
284 wxPyCoreAPIPtr
->p_wxPyCBH_delete(this);
286 wxPyCBH_delete(this);
290 void setSelf(PyObject
* self
, PyObject
* klass
, int incref
=TRUE
);
291 bool findCallback(const char* name
) const;
292 int callCallback(PyObject
* argTuple
) const;
293 PyObject
* callCallbackObj(PyObject
* argTuple
) const;
298 PyObject
* m_lastFound
;
301 friend void wxPyCBH_delete(wxPyCallbackHelper
* cbh
);
305 void wxPyCBH_setSelf(wxPyCallbackHelper
& cbh
, PyObject
* self
, PyObject
* klass
, int incref
);
306 bool wxPyCBH_findCallback(const wxPyCallbackHelper
& cbh
, const char* name
);
307 int wxPyCBH_callCallback(const wxPyCallbackHelper
& cbh
, PyObject
* argTuple
);
308 PyObject
* wxPyCBH_callCallbackObj(const wxPyCallbackHelper
& cbh
, PyObject
* argTuple
);
309 void wxPyCBH_delete(wxPyCallbackHelper
* cbh
);
313 //----------------------------------------------------------------------
315 class wxPyUserData
: public wxObject
{
317 wxPyUserData(PyObject
* obj
) {
324 #ifdef wxPyUSE_EXPORT
325 doSave
= wxPyCoreAPIPtr
->p_wxPyRestoreThread();
327 wxPyCoreAPIPtr
->p_wxPySaveThread(doSave
);
329 doSave
= wxPyRestoreThread();
331 wxPySaveThread(doSave
);
339 //---------------------------------------------------------------------------
340 // These macros are used to implement the virtual methods that should
341 // redirect to a Python method if one exists. The names designate the
342 // return type, if any, as well as any parameter types.
343 //---------------------------------------------------------------------------
346 void _setSelf(PyObject* self, PyObject* _class, int incref=1) { \
347 wxPyCBH_setSelf(m_myInst, self, _class, incref); \
349 private: wxPyCallbackHelper m_myInst
351 //---------------------------------------------------------------------------
353 #define DEC_PYCALLBACK__(CBNAME) \
355 void base_##CBNAME();
358 #define IMP_PYCALLBACK__(CLASS, PCLASS, CBNAME) \
359 void CLASS::CBNAME() { \
360 bool doSave = wxPyRestoreThread(); \
361 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
362 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
365 wxPySaveThread(doSave); \
367 void CLASS::base_##CBNAME() { \
371 //---------------------------------------------------------------------------
373 #define DEC_PYCALLBACK_BOOL_INTINT(CBNAME) \
374 bool CBNAME(int a, int b); \
375 bool base_##CBNAME(int a, int b);
378 #define IMP_PYCALLBACK_BOOL_INTINT(CLASS, PCLASS, CBNAME) \
379 bool CLASS::CBNAME(int a, int b) { \
381 bool doSave = wxPyRestoreThread(); \
382 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
383 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
385 rval = PCLASS::CBNAME(a,b); \
386 wxPySaveThread(doSave); \
389 bool CLASS::base_##CBNAME(int a, int b) { \
390 return PCLASS::CBNAME(a,b); \
393 //---------------------------------------------------------------------------
395 #define DEC_PYCALLBACK_VOID_INTINT(CBNAME) \
396 void CBNAME(int a, int b); \
397 void base_##CBNAME(int a, int b);
400 #define IMP_PYCALLBACK_VOID_INTINT(CLASS, PCLASS, CBNAME) \
401 void CLASS::CBNAME(int a, int b) { \
402 bool doSave = wxPyRestoreThread(); \
403 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
404 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
406 PCLASS::CBNAME(a,b); \
407 wxPySaveThread(doSave); \
409 void CLASS::base_##CBNAME(int a, int b) { \
410 PCLASS::CBNAME(a,b); \
413 //---------------------------------------------------------------------------
415 #define DEC_PYCALLBACK_BOOL_INT(CBNAME) \
416 bool CBNAME(int a); \
417 bool base_##CBNAME(int a);
420 #define IMP_PYCALLBACK_BOOL_INT(CLASS, PCLASS, CBNAME) \
421 bool CLASS::CBNAME(int a) { \
423 bool doSave = wxPyRestoreThread(); \
424 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
425 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)",a)); \
427 rval = PCLASS::CBNAME(a); \
428 wxPySaveThread(doSave); \
431 bool CLASS::base_##CBNAME(int a) { \
432 return PCLASS::CBNAME(a); \
435 //---------------------------------------------------------------------------
437 #define DEC_PYCALLBACK_BOOL_INT_pure(CBNAME) \
441 #define IMP_PYCALLBACK_BOOL_INT_pure(CLASS, PCLASS, CBNAME) \
442 bool CLASS::CBNAME(int a) { \
444 bool doSave = wxPyRestoreThread(); \
445 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
446 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)",a)); \
448 wxPySaveThread(doSave); \
453 //---------------------------------------------------------------------------
455 #define DEC_PYCALLBACK__DC(CBNAME) \
456 void CBNAME(wxDC& a); \
457 void base_##CBNAME(wxDC& a);
460 #define IMP_PYCALLBACK__DC(CLASS, PCLASS, CBNAME) \
461 void CLASS::CBNAME(wxDC& a) { \
462 bool doSave = wxPyRestoreThread(); \
463 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
464 PyObject* obj = wxPyConstructObject(&a, "wxDC", 0); \
465 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
470 wxPySaveThread(doSave); \
472 void CLASS::base_##CBNAME(wxDC& a) { \
478 //---------------------------------------------------------------------------
480 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
481 void CBNAME(wxDC& a, bool b); \
482 void base_##CBNAME(wxDC& a, bool b);
485 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
486 void CLASS::CBNAME(wxDC& a, bool b) { \
487 bool doSave = wxPyRestoreThread(); \
488 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
489 PyObject* obj = wxPyConstructObject(&a, "wxDC", 0); \
490 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, (int)b)); \
494 PCLASS::CBNAME(a, b); \
495 wxPySaveThread(doSave); \
497 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
498 PCLASS::CBNAME(a, b); \
501 //---------------------------------------------------------------------------
503 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
504 void CBNAME(wxDC& a, bool b); \
505 void base_##CBNAME(wxDC& a, bool b);
508 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
509 void CLASS::CBNAME(wxDC& a, bool b) { \
510 bool doSave = wxPyRestoreThread(); \
511 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
512 PyObject* obj = wxPyConstructObject(&a, "wxDC", 0); \
513 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, (int)b)); \
517 PCLASS::CBNAME(a, b); \
518 wxPySaveThread(doSave); \
520 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
521 PCLASS::CBNAME(a, b); \
524 //---------------------------------------------------------------------------
526 #define DEC_PYCALLBACK__2DBL(CBNAME) \
527 void CBNAME(double a, double b); \
528 void base_##CBNAME(double a, double b);
531 #define IMP_PYCALLBACK__2DBL(CLASS, PCLASS, CBNAME) \
532 void CLASS::CBNAME(double a, double b) { \
533 bool doSave = wxPyRestoreThread(); \
534 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
535 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(dd)",a,b)); \
537 PCLASS::CBNAME(a, b); \
538 wxPySaveThread(doSave); \
540 void CLASS::base_##CBNAME(double a, double b) { \
541 PCLASS::CBNAME(a, b); \
544 //---------------------------------------------------------------------------
546 #define DEC_PYCALLBACK__2DBL2INT(CBNAME) \
547 void CBNAME(double a, double b, int c, int d); \
548 void base_##CBNAME(double a, double b, int c, int d);
551 #define IMP_PYCALLBACK__2DBL2INT(CLASS, PCLASS, CBNAME) \
552 void CLASS::CBNAME(double a, double b, int c, int d) { \
553 bool doSave = wxPyRestoreThread(); \
554 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
555 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ddii)", \
558 PCLASS::CBNAME(a, b, c, d); \
559 wxPySaveThread(doSave); \
561 void CLASS::base_##CBNAME(double a, double b, int c, int d) { \
562 PCLASS::CBNAME(a, b, c, d); \
565 //---------------------------------------------------------------------------
567 #define DEC_PYCALLBACK__DC4DBLBOOL(CBNAME) \
568 void CBNAME(wxDC& a, double b, double c, double d, double e, bool f); \
569 void base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f);
572 #define IMP_PYCALLBACK__DC4DBLBOOL(CLASS, PCLASS, CBNAME) \
573 void CLASS::CBNAME(wxDC& a, double b, double c, double d, double e, bool f) { \
574 bool doSave = wxPyRestoreThread(); \
575 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
576 PyObject* obj = wxPyConstructObject(&a, "wxDC", 0); \
577 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oddddi)", obj, b, c, d, e, (int)f)); \
581 PCLASS::CBNAME(a, b, c, d, e, f); \
582 wxPySaveThread(doSave); \
584 void CLASS::base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f) {\
585 PCLASS::CBNAME(a, b, c, d, e, f); \
588 //---------------------------------------------------------------------------
590 #define DEC_PYCALLBACK_BOOL_DC4DBLBOOL(CBNAME) \
591 bool CBNAME(wxDC& a, double b, double c, double d, double e, bool f); \
592 bool base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f);
595 #define IMP_PYCALLBACK_BOOL_DC4DBLBOOL(CLASS, PCLASS, CBNAME) \
596 bool CLASS::CBNAME(wxDC& a, double b, double c, double d, double e, bool f) { \
597 bool doSave = wxPyRestoreThread(); \
599 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
600 PyObject* obj = wxPyConstructObject(&a, "wxDC", 0); \
601 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oddddi)", obj, b, c, d, e, (int)f));\
605 rval = PCLASS::CBNAME(a, b, c, d, e, f); \
606 wxPySaveThread(doSave); \
609 bool CLASS::base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f) {\
610 return PCLASS::CBNAME(a, b, c, d, e, f); \
613 //---------------------------------------------------------------------------
615 #define DEC_PYCALLBACK__BOOL2DBL2INT(CBNAME) \
616 void CBNAME(bool a, double b, double c, int d, int e); \
617 void base_##CBNAME(bool a, double b, double c, int d, int e);
620 #define IMP_PYCALLBACK__BOOL2DBL2INT(CLASS, PCLASS, CBNAME) \
621 void CLASS::CBNAME(bool a, double b, double c, int d, int e) { \
622 bool doSave = wxPyRestoreThread(); \
623 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
624 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(idii)", \
627 PCLASS::CBNAME(a, b, c, d, e); \
628 wxPySaveThread(doSave); \
630 void CLASS::base_##CBNAME(bool a, double b, double c, int d, int e) { \
631 PCLASS::CBNAME(a, b, c, d, e); \
634 //---------------------------------------------------------------------------
636 #define DEC_PYCALLBACK__DC4DBL(CBNAME) \
637 void CBNAME(wxDC& a, double b, double c, double d, double e); \
638 void base_##CBNAME(wxDC& a, double b, double c, double d, double e);
641 #define IMP_PYCALLBACK__DC4DBL(CLASS, PCLASS, CBNAME) \
642 void CLASS::CBNAME(wxDC& a, double b, double c, double d, double e) { \
643 bool doSave = wxPyRestoreThread(); \
644 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
645 PyObject* obj = wxPyConstructObject(&a, "wxDC", 0); \
646 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Odddd)", obj, b, c, d, e)); \
650 PCLASS::CBNAME(a, b, c, d, e); \
651 wxPySaveThread(doSave); \
653 void CLASS::base_##CBNAME(wxDC& a, double b, double c, double d, double e) {\
654 PCLASS::CBNAME(a, b, c, d, e); \
657 //---------------------------------------------------------------------------
659 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
660 void CBNAME(wxDC& a, bool b); \
661 void base_##CBNAME(wxDC& a, bool b);
664 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
665 void CLASS::CBNAME(wxDC& a, bool b) { \
666 bool doSave = wxPyRestoreThread(); \
667 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
668 PyObject* obj = wxPyConstructObject(&a, "wxDC", 0); \
669 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, (int)b)); \
673 PCLASS::CBNAME(a, b); \
674 wxPySaveThread(doSave); \
676 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
677 PCLASS::CBNAME(a, b); \
680 //---------------------------------------------------------------------------
682 #define DEC_PYCALLBACK__WXCPBOOL2DBL2INT(CBNAME) \
683 void CBNAME(wxControlPoint* a, bool b, double c, double d, int e, int f); \
684 void base_##CBNAME(wxControlPoint* a, bool b, double c, double d, int e, int f);
687 #define IMP_PYCALLBACK__WXCPBOOL2DBL2INT(CLASS, PCLASS, CBNAME) \
688 void CLASS::CBNAME(wxControlPoint* a, bool b, double c, double d, \
690 bool doSave = wxPyRestoreThread(); \
691 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
692 PyObject* obj = wxPyConstructObject(a, "wxPyControlPoint", 0); \
693 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oiddii)", obj, (int)b, c, d, e, f));\
697 PCLASS::CBNAME(a, b, c, d, e, f); \
698 wxPySaveThread(doSave); \
700 void CLASS::base_##CBNAME(wxControlPoint* a, bool b, double c, double d, \
702 PCLASS::CBNAME(a, b, c, d, e, f); \
705 //---------------------------------------------------------------------------
707 #define DEC_PYCALLBACK__WXCP2DBL2INT(CBNAME) \
708 void CBNAME(wxControlPoint* a, double b, double c, int d, int e); \
709 void base_##CBNAME(wxControlPoint* a, double b, double c, int d, int e);
712 #define IMP_PYCALLBACK__WXCP2DBL2INT(CLASS, PCLASS, CBNAME) \
713 void CLASS::CBNAME(wxControlPoint* a, double b, double c, int d, int e) { \
714 bool doSave = wxPyRestoreThread(); \
715 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
716 PyObject* obj = wxPyConstructObject(a, "wxPyControlPoint", 0); \
717 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oddii)", obj, b, c, d, e)); \
721 PCLASS::CBNAME(a, b, c, d, e); \
722 wxPySaveThread(doSave); \
724 void CLASS::base_##CBNAME(wxControlPoint* a, double b, double c, \
726 PCLASS::CBNAME(a, b, c, d, e); \
729 //---------------------------------------------------------------------------
731 #define DEC_PYCALLBACK__2DBLINT(CBNAME) \
732 void CBNAME(double a, double b, int c); \
733 void base_##CBNAME(double a, double b, int c);
736 #define IMP_PYCALLBACK__2DBLINT(CLASS, PCLASS, CBNAME) \
737 void CLASS::CBNAME(double a, double b, int c) { \
738 bool doSave = wxPyRestoreThread(); \
739 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
740 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ddi)", a,b,c)); \
742 PCLASS::CBNAME(a, b, c); \
743 wxPySaveThread(doSave); \
745 void CLASS::base_##CBNAME(double a, double b, int c) { \
746 PCLASS::CBNAME(a, b, c); \
749 //---------------------------------------------------------------------------
751 #define DEC_PYCALLBACK__BOOL2DBLINT(CBNAME) \
752 void CBNAME(bool a, double b, double c, int d); \
753 void base_##CBNAME(bool a, double b, double c, int d);
756 #define IMP_PYCALLBACK__BOOL2DBLINT(CLASS, PCLASS, CBNAME) \
757 void CLASS::CBNAME(bool a, double b, double c, int d) { \
758 bool doSave = wxPyRestoreThread(); \
759 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
760 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iddi)", (int)a,b,c,d)); \
762 PCLASS::CBNAME(a, b, c, d); \
763 wxPySaveThread(doSave); \
765 void CLASS::base_##CBNAME(bool a, double b, double c, int d) { \
766 PCLASS::CBNAME(a, b, c, d); \
769 //---------------------------------------------------------------------------
770 //---------------------------------------------------------------------------
772 #define DEC_PYCALLBACK__STRING(CBNAME) \
773 void CBNAME(const wxString& a); \
774 void base_##CBNAME(const wxString& a);
777 #define IMP_PYCALLBACK__STRING(CLASS, PCLASS, CBNAME) \
778 void CLASS::CBNAME(const wxString& a) { \
779 bool doSave = wxPyRestoreThread(); \
780 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
781 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(s)", a.c_str())); \
784 wxPySaveThread(doSave); \
786 void CLASS::base_##CBNAME(const wxString& a) { \
790 //---------------------------------------------------------------------------
792 #define DEC_PYCALLBACK_BOOL_STRING(CBNAME) \
793 bool CBNAME(const wxString& a); \
794 bool base_##CBNAME(const wxString& a);
797 #define IMP_PYCALLBACK_BOOL_STRING(CLASS, PCLASS, CBNAME) \
798 bool CLASS::CBNAME(const wxString& a) { \
800 bool doSave = wxPyRestoreThread(); \
801 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
802 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(s)", a.c_str())); \
804 rval = PCLASS::CBNAME(a); \
805 wxPySaveThread(doSave); \
808 bool CLASS::base_##CBNAME(const wxString& a) { \
809 return PCLASS::CBNAME(a); \
812 //---------------------------------------------------------------------------
814 #define DEC_PYCALLBACK_BOOL_STRING_pure(CBNAME) \
815 bool CBNAME(const wxString& a);
817 #define IMP_PYCALLBACK_BOOL_STRING_pure(CLASS, PCLASS, CBNAME) \
818 bool CLASS::CBNAME(const wxString& a) { \
820 bool doSave = wxPyRestoreThread(); \
821 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
822 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(s)", a.c_str())); \
823 wxPySaveThread(doSave); \
827 //---------------------------------------------------------------------------
829 #define DEC_PYCALLBACK_STRING_STRING_pure(CBNAME) \
830 wxString CBNAME(const wxString& a); \
832 #define IMP_PYCALLBACK_STRING_STRING_pure(CLASS, PCLASS, CBNAME) \
833 wxString CLASS::CBNAME(const wxString& a) { \
835 bool doSave = wxPyRestoreThread(); \
836 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
838 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(s)", a.c_str())); \
840 PyObject* str = PyObject_Str(ro); \
841 rval = PyString_AsString(str); \
842 Py_DECREF(ro); Py_DECREF(str); \
845 wxPySaveThread(doSave); \
849 //---------------------------------------------------------------------------
851 #define DEC_PYCALLBACK_STRING_STRINGINT_pure(CBNAME) \
852 wxString CBNAME(const wxString& a,int b); \
854 #define IMP_PYCALLBACK_STRING_STRINGINT_pure(CLASS, PCLASS, CBNAME) \
855 wxString CLASS::CBNAME(const wxString& a,int b) { \
857 bool doSave = wxPyRestoreThread(); \
858 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
860 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(si)", a.c_str(),b)); \
862 PyObject* str = PyObject_Str(ro); \
863 rval = PyString_AsString(str); \
864 Py_DECREF(ro); Py_DECREF(str); \
867 wxPySaveThread(doSave); \
871 //---------------------------------------------------------------------------
873 #define DEC_PYCALLBACK_BOOL_STRINGSTRING(CBNAME) \
874 bool CBNAME(const wxString& a, const wxString& b); \
875 bool base_##CBNAME(const wxString& a, const wxString& b);
878 #define IMP_PYCALLBACK_BOOL_STRINGSTRING(CLASS, PCLASS, CBNAME) \
879 bool CLASS::CBNAME(const wxString& a, const wxString& b) { \
881 bool doSave = wxPyRestoreThread(); \
882 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
883 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ss)", \
884 a.c_str(), b.c_str())); \
886 rval = PCLASS::CBNAME(a, b); \
887 wxPySaveThread(doSave); \
890 bool CLASS::base_##CBNAME(const wxString& a, const wxString& b) { \
891 return PCLASS::CBNAME(a, b); \
894 //---------------------------------------------------------------------------
896 #define DEC_PYCALLBACK_STRING_(CBNAME) \
898 wxString base_##CBNAME();
901 #define IMP_PYCALLBACK_STRING_(CLASS, PCLASS, CBNAME) \
902 wxString CLASS::CBNAME() { \
904 bool doSave = wxPyRestoreThread(); \
905 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
907 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
909 PyObject* str = PyObject_Str(ro); \
910 rval = PyString_AsString(str); \
911 Py_DECREF(ro); Py_DECREF(str); \
915 rval = PCLASS::CBNAME(); \
916 wxPySaveThread(doSave); \
919 wxString CLASS::base_##CBNAME() { \
920 return PCLASS::CBNAME(); \
923 //---------------------------------------------------------------------------
925 #define DEC_PYCALLBACK_STRING__pure(CBNAME) \
929 #define IMP_PYCALLBACK_STRING__pure(CLASS, PCLASS, CBNAME) \
930 wxString CLASS::CBNAME() { \
932 bool doSave = wxPyRestoreThread(); \
933 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
935 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
937 PyObject* str = PyObject_Str(ro); \
938 rval = PyString_AsString(str); \
939 Py_DECREF(ro); Py_DECREF(str); \
942 wxPySaveThread(doSave); \
946 //---------------------------------------------------------------------------
948 #define DEC_PYCALLBACK_BOOL_TAG_pure(CBNAME) \
949 bool CBNAME(const wxHtmlTag& a); \
952 #define IMP_PYCALLBACK_BOOL_TAG_pure(CLASS, PCLASS, CBNAME) \
953 bool CLASS::CBNAME(const wxHtmlTag& a) { \
955 bool doSave = wxPyRestoreThread(); \
956 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
957 PyObject* obj = wxPyConstructObject((void*)&a,"wxHtmlTag", 0); \
958 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
961 wxPySaveThread(doSave); \
965 //---------------------------------------------------------------------------
967 #define DEC_PYCALLBACK___pure(CBNAME) \
971 #define IMP_PYCALLBACK___pure(CLASS, PCLASS, CBNAME) \
972 void CLASS::CBNAME() { \
973 bool doSave = wxPyRestoreThread(); \
974 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
975 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
976 wxPySaveThread(doSave); \
979 //---------------------------------------------------------------------------
981 #define DEC_PYCALLBACK_wxSize__pure(CBNAME) \
985 #define IMP_PYCALLBACK_wxSize__pure(CLASS, PCLASS, CBNAME) \
986 wxSize CLASS::CBNAME() { \
988 bool doSave = wxPyRestoreThread(); \
989 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
992 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
994 if (! SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p")) \
999 wxPySaveThread(doSave); \
1003 //---------------------------------------------------------------------------
1005 #define DEC_PYCALLBACK_BOOL_WXWIN(CBNAME) \
1006 bool CBNAME(wxWindow* a); \
1007 bool base_##CBNAME(wxWindow* a);
1010 #define IMP_PYCALLBACK_BOOL_WXWIN(CLASS, PCLASS, CBNAME) \
1011 bool CLASS::CBNAME(wxWindow* a) { \
1013 bool doSave = wxPyRestoreThread(); \
1014 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1015 PyObject* obj = wxPyConstructObject((void*)a,"wxWindow", 0);\
1016 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
1020 rval = PCLASS::CBNAME(a); \
1021 wxPySaveThread(doSave); \
1024 bool CLASS::base_##CBNAME(wxWindow* a) { \
1025 return PCLASS::CBNAME(a); \
1028 //---------------------------------------------------------------------------
1030 #define DEC_PYCALLBACK_BOOL_(CBNAME) \
1032 bool base_##CBNAME();
1035 #define IMP_PYCALLBACK_BOOL_(CLASS, PCLASS, CBNAME) \
1036 bool CLASS::CBNAME() { \
1038 bool doSave = wxPyRestoreThread(); \
1039 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
1040 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
1042 rval = PCLASS::CBNAME(); \
1043 wxPySaveThread(doSave); \
1046 bool CLASS::base_##CBNAME() { \
1047 return PCLASS::CBNAME(); \
1050 //---------------------------------------------------------------------------
1052 #define DEC_PYCALLBACK_DR_2WXCDR(CBNAME) \
1053 wxDragResult CBNAME(wxCoord x, wxCoord y, wxDragResult def); \
1054 wxDragResult base_##CBNAME(wxCoord x, wxCoord y, wxDragResult def);
1057 #define IMP_PYCALLBACK_DR_2WXCDR(CLASS, PCLASS, CBNAME) \
1058 wxDragResult CLASS::CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
1059 bool doSave = wxPyRestoreThread(); \
1061 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
1062 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c));\
1064 rval = PCLASS::CBNAME(a, b, c); \
1065 wxPySaveThread(doSave); \
1066 return (wxDragResult)rval; \
1068 wxDragResult CLASS::base_##CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
1069 return PCLASS::CBNAME(a, b, c); \
1072 //---------------------------------------------------------------------------
1074 #define DEC_PYCALLBACK_FSF_FSSTRING_pure(CBNAME) \
1075 wxFSFile* CBNAME(wxFileSystem& fs, const wxString& location); \
1077 #define IMP_PYCALLBACK_FSF_FSSTRING_pure(CLASS, PCLASS, CBNAME) \
1078 wxFSFile* CLASS::CBNAME(wxFileSystem& a,const wxString& b) { \
1079 bool doSave = wxPyRestoreThread(); \
1081 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1083 PyObject* obj = wxPyConstructObject(&a, "wxFileSystem", 0); \
1084 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(Os)", \
1087 SWIG_GetPtrObj(ro, (void **)&rval, "_wxFSFILE_p"); \
1092 wxPySaveThread(doSave); \
1096 //---------------------------------------------------------------------------
1098 #define DEC_PYCALLBACK_BOOL_DR(CBNAME) \
1099 bool CBNAME(wxDragResult a); \
1100 bool base_##CBNAME(wxDragResult a);
1103 #define IMP_PYCALLBACK_BOOL_DR(CLASS, PCLASS, CBNAME) \
1104 bool CLASS::CBNAME(wxDragResult a) { \
1105 bool doSave = wxPyRestoreThread(); \
1107 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
1108 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)", a)); \
1110 rval = PCLASS::CBNAME(a); \
1111 wxPySaveThread(doSave); \
1114 bool CLASS::base_##CBNAME(wxDragResult a) { \
1115 return PCLASS::CBNAME(a); \
1118 //---------------------------------------------------------------------------
1120 #define DEC_PYCALLBACK_DR_2WXCDR_pure(CBNAME) \
1121 wxDragResult CBNAME(wxCoord x, wxCoord y, wxDragResult def);
1124 #define IMP_PYCALLBACK_DR_2WXCDR_pure(CLASS, PCLASS, CBNAME) \
1125 wxDragResult CLASS::CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
1126 bool doSave = wxPyRestoreThread(); \
1128 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
1129 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c));\
1130 wxPySaveThread(doSave); \
1131 return (wxDragResult)rval; \
1134 //---------------------------------------------------------------------------
1136 #define DEC_PYCALLBACK_BOOL_INTINTSTR_pure(CBNAME) \
1137 bool CBNAME(int a, int b, const wxString& c);
1140 #define IMP_PYCALLBACK_BOOL_INTINTSTR_pure(CLASS, PCLASS, CBNAME) \
1141 bool CLASS::CBNAME(int a, int b, const wxString& c) { \
1143 bool doSave = wxPyRestoreThread(); \
1144 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
1145 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iis)",a,b,c.c_str()));\
1146 wxPySaveThread(doSave); \
1150 //---------------------------------------------------------------------------
1152 #define DEC_PYCALLBACK_SIZET_(CBNAME) \
1154 size_t base_##CBNAME();
1157 #define IMP_PYCALLBACK_SIZET_(CLASS, PCLASS, CBNAME) \
1158 size_t CLASS::CBNAME() { \
1160 bool doSave = wxPyRestoreThread(); \
1161 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
1162 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
1164 rval = PCLASS::CBNAME(); \
1165 wxPySaveThread(doSave); \
1168 size_t CLASS::base_##CBNAME() { \
1169 return PCLASS::CBNAME(); \
1172 //---------------------------------------------------------------------------
1174 #define DEC_PYCALLBACK_DATAFMT_SIZET(CBNAME) \
1175 wxDataFormat CBNAME(); \
1176 wxDataFormat base_##CBNAME();
1179 #define IMP_PYCALLBACK_DATAFMT_SIZET(CLASS, PCLASS, CBNAME) \
1180 wxDataFormat CLASS::CBNAME(size_t a) { \
1181 wxDataFormat rval; \
1182 bool doSave = wxPyRestoreThread(); \
1183 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1185 wxDataFormat* ptr; \
1186 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(i)", a)); \
1188 if (! SWIG_GetPtrObj(ro, (void **)&ptr, "_wxDataFormat_p")) \
1194 rval = PCLASS::CBNAME(a); \
1195 wxPySaveThread(doSave); \
1198 wxDataFormat CLASS::base_##CBNAME(size_t a) { \
1199 return PCLASS::CBNAME(a); \
1202 //---------------------------------------------------------------------------
1204 #define DEC_PYCALLBACK__constany(CBNAME, Type) \
1205 void CBNAME(const Type& a); \
1206 void base_##CBNAME(const Type& a);
1209 #define IMP_PYCALLBACK__constany(CLASS, PCLASS, CBNAME, Type) \
1210 void CLASS::CBNAME(const Type& a) { \
1211 bool doSave = wxPyRestoreThread(); \
1212 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1213 PyObject* obj = wxPyConstructObject((void*)&a, #Type, 0); \
1214 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
1218 PCLASS::CBNAME(a); \
1219 wxPySaveThread(doSave); \
1221 void CLASS::base_##CBNAME(const Type& a) { \
1222 PCLASS::CBNAME(a); \
1226 //---------------------------------------------------------------------------
1228 #define DEC_PYCALLBACK__any(CBNAME, Type) \
1229 void CBNAME(Type& a); \
1230 void base_##CBNAME(Type& a);
1233 #define IMP_PYCALLBACK__any(CLASS, PCLASS, CBNAME, Type) \
1234 void CLASS::CBNAME(Type& a) { \
1235 bool doSave = wxPyRestoreThread(); \
1236 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1237 PyObject* obj = wxPyConstructObject((void*)&a, #Type, 0); \
1238 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
1242 PCLASS::CBNAME(a); \
1243 wxPySaveThread(doSave); \
1245 void CLASS::base_##CBNAME(Type& a) { \
1246 PCLASS::CBNAME(a); \
1249 //---------------------------------------------------------------------------
1251 #define DEC_PYCALLBACK_bool_any(CBNAME, Type) \
1252 bool CBNAME(Type& a); \
1253 bool base_##CBNAME(Type& a);
1256 #define IMP_PYCALLBACK_bool_any(CLASS, PCLASS, CBNAME, Type) \
1257 bool CLASS::CBNAME(Type& a) { \
1259 bool doSave = wxPyRestoreThread(); \
1260 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1261 PyObject* obj = wxPyConstructObject((void*)&a, #Type, 0); \
1262 rv = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
1266 rv = PCLASS::CBNAME(a); \
1267 wxPySaveThread(doSave); \
1270 bool CLASS::base_##CBNAME(Type& a) { \
1271 return PCLASS::CBNAME(a); \
1274 //---------------------------------------------------------------------------