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 PyObject
* wxPyConstructObject(void* ptr
,
64 const char* className
,
67 PyObject
* wxPyClassExists(const char* className
);
68 PyObject
* wxPyMake_wxObject(wxObject
* source
);
69 void wxPyPtrTypeMap_Add(const char* commonName
, const char* ptrName
);
71 bool wxPyRestoreThread();
72 void wxPySaveThread(bool doSave
);
73 PyObject
* wxPy_ConvertList(wxListBase
* list
, const char* className
);
74 long wxPyGetWinHandle(wxWindow
* win
);
78 //----------------------------------------------------------------------
79 // Handle wxInputStreams by Joerg Baumann
80 // See stream.i for implementations
82 // list class for return list of strings, e.g. readlines()
83 WX_DECLARE_LIST(wxString
, wxStringPtrList
);
86 // C++ class wxPyInputStream to act as base for python class wxInputStream
87 // Use it in python like a python file object
88 class wxPyInputStream
{
90 // underlying wxInputStream
94 wxPyInputStream(wxInputStream
* wxi_
) : wxi(wxi_
) {}
97 // python file object interface for input files (most of it)
101 wxString
* read(int size
=-1);
102 wxString
* readline(int size
=-1);
103 wxStringPtrList
* readlines(int sizehint
=-1);
104 void seek(int offset
, int whence
=0);
109 void truncate(int size=-1);
110 void write(wxString data);
111 void writelines(wxStringPtrList);
116 //----------------------------------------------------------------------
117 // These are helpers used by the typemaps
119 byte
* byte_LIST_helper(PyObject
* source
);
120 int* int_LIST_helper(PyObject
* source
);
121 long* long_LIST_helper(PyObject
* source
);
122 char** string_LIST_helper(PyObject
* source
);
123 wxPoint
* wxPoint_LIST_helper(PyObject
* source
, int* npoints
);
124 wxBitmap
** wxBitmap_LIST_helper(PyObject
* source
);
125 wxString
* wxString_LIST_helper(PyObject
* source
);
126 wxAcceleratorEntry
* wxAcceleratorEntry_LIST_helper(PyObject
* source
);
128 bool wxSize_helper(PyObject
* source
, wxSize
** obj
);
129 bool wxPoint_helper(PyObject
* source
, wxPoint
** obj
);
130 bool wxRealPoint_helper(PyObject
* source
, wxRealPoint
** obj
);
131 bool wxRect_helper(PyObject
* source
, wxRect
** obj
);
132 bool wxColour_helper(PyObject
* source
, wxColour
** obj
);
134 //----------------------------------------------------------------------
137 extern "C" void SWIG_MakePtr(char *, void *, char *);
138 extern "C" char *SWIG_GetPtr(char *, void **, char *);
139 extern "C" char *SWIG_GetPtrObj(PyObject
*obj
, void **ptr
, char *type
);
144 # pragma warning(disable:4800)
145 # pragma warning(disable:4190)
148 //----------------------------------------------------------------------
150 class wxPyCallback
: public wxObject
{
151 DECLARE_ABSTRACT_CLASS(wxPyCallback
);
153 wxPyCallback(PyObject
* func
);
154 wxPyCallback(const wxPyCallback
& other
);
157 void EventThunker(wxEvent
& event
);
162 //---------------------------------------------------------------------------
164 class wxPyTimer
: public wxTimer
{
166 wxPyTimer(PyObject
* callback
);
175 //---------------------------------------------------------------------------
176 //---------------------------------------------------------------------------
177 // These Event classes can be derived from in Python and passed through the
178 // event system without loosing anything. They do this by keeping a reference
179 // to themselves and some special case handling in wxPyCallback::EventThunker.
182 class wxPyEvtSelfRef
{
187 void SetSelf(PyObject
* self
, bool clone
=FALSE
);
188 PyObject
* GetSelf() const;
196 class wxPyEvent
: public wxEvent
, public wxPyEvtSelfRef
{
197 DECLARE_DYNAMIC_CLASS(wxPyEvent
)
202 void CopyObject(wxObject
& dest
) const;
206 class wxPyCommandEvent
: public wxCommandEvent
, public wxPyEvtSelfRef
{
207 DECLARE_DYNAMIC_CLASS(wxPyCommandEvent
)
209 wxPyCommandEvent(wxEventType commandType
= wxEVT_NULL
, int id
=0);
212 void CopyObject(wxObject
& dest
) const;
216 //---------------------------------------------------------------------------
217 // Export a C API in a struct. Other modules will be able to load this from
218 // the wxc module and will then have safe access to these functions, even if
219 // in another shared library.
221 class wxPyCallbackHelper
;
225 void (*p_SWIG_MakePtr
)(char*, void*, char*);
226 char* (*p_SWIG_GetPtr
)(char*, void**, char*);
227 char* (*p_SWIG_GetPtrObj
)(PyObject
*, void**, char*);
228 void (*p_SWIG_RegisterMapping
)(char*, char*, void *(*cast
)(void *));
229 void (*p_SWIG_addvarlink
)(PyObject
*, char*, PyObject
*(*get_attr
)(void), int (*set_attr
)(PyObject
*p
));
230 PyObject
* (*p_SWIG_newvarlink
)(void);
232 void (*p_wxPySaveThread
)(bool);
233 bool (*p_wxPyRestoreThread
)();
234 PyObject
* (*p_wxPyConstructObject
)(void *, const char *, int);
235 PyObject
* (*p_wxPy_ConvertList
)(wxListBase
* list
, const char* className
);
237 byte
* (*p_byte_LIST_helper
)(PyObject
* source
);
238 int* (*p_int_LIST_helper
)(PyObject
* source
);
239 long* (*p_long_LIST_helper
)(PyObject
* source
);
240 char** (*p_string_LIST_helper
)(PyObject
* source
);
241 wxPoint
* (*p_wxPoint_LIST_helper
)(PyObject
* source
, int* npoints
);
242 wxBitmap
** (*p_wxBitmap_LIST_helper
)(PyObject
* source
);
243 wxString
* (*p_wxString_LIST_helper
)(PyObject
* source
);
244 wxAcceleratorEntry
* (*p_wxAcceleratorEntry_LIST_helper
)(PyObject
* source
);
246 bool (*p_wxSize_helper
)(PyObject
* source
, wxSize
** obj
);
247 bool (*p_wxPoint_helper
)(PyObject
* source
, wxPoint
** obj
);
248 bool (*p_wxRealPoint_helper
)(PyObject
* source
, wxRealPoint
** obj
);
249 bool (*p_wxRect_helper
)(PyObject
* source
, wxRect
** obj
);
250 bool (*p_wxColour_helper
)(PyObject
* source
, wxColour
** obj
);
252 void (*p_wxPyCBH_setSelf
)(wxPyCallbackHelper
& cbh
, PyObject
* self
, PyObject
* klass
, int incref
);
253 bool (*p_wxPyCBH_findCallback
)(const wxPyCallbackHelper
& cbh
, const char* name
);
254 int (*p_wxPyCBH_callCallback
)(const wxPyCallbackHelper
& cbh
, PyObject
* argTuple
);
255 PyObject
* (*p_wxPyCBH_callCallbackObj
)(const wxPyCallbackHelper
& cbh
, PyObject
* argTuple
);
256 void (*p_wxPyCBH_delete
)(wxPyCallbackHelper
* cbh
);
258 PyObject
* (*p_wxPyClassExists
)(const char* className
);
259 PyObject
* (*p_wxPyMake_wxObject
)(wxObject
* source
);
260 void (*p_wxPyPtrTypeMap_Add
)(const char* commonName
, const char* ptrName
);
264 #ifdef wxPyUSE_EXPORT
265 static wxPyCoreAPI
* wxPyCoreAPIPtr
= NULL
; // Each module needs one, but may not use it.
268 //---------------------------------------------------------------------------
269 // This class holds an instance of a Python Shadow Class object and assists
270 // with looking up and invoking Python callback methods from C++ virtual
271 // method redirections. For all classes which have virtuals which should be
272 // overridable in wxPython, a new subclass is created that contains a
273 // wxPyCallbackHelper.
276 class wxPyCallbackHelper
{
278 wxPyCallbackHelper(const wxPyCallbackHelper
& other
);
280 wxPyCallbackHelper() {
287 ~wxPyCallbackHelper() {
288 #ifdef wxPyUSE_EXPORT
289 wxPyCoreAPIPtr
->p_wxPyCBH_delete(this);
291 wxPyCBH_delete(this);
295 void setSelf(PyObject
* self
, PyObject
* klass
, int incref
=TRUE
);
296 bool findCallback(const char* name
) const;
297 int callCallback(PyObject
* argTuple
) const;
298 PyObject
* callCallbackObj(PyObject
* argTuple
) const;
303 PyObject
* m_lastFound
;
306 friend void wxPyCBH_delete(wxPyCallbackHelper
* cbh
);
310 void wxPyCBH_setSelf(wxPyCallbackHelper
& cbh
, PyObject
* self
, PyObject
* klass
, int incref
);
311 bool wxPyCBH_findCallback(const wxPyCallbackHelper
& cbh
, const char* name
);
312 int wxPyCBH_callCallback(const wxPyCallbackHelper
& cbh
, PyObject
* argTuple
);
313 PyObject
* wxPyCBH_callCallbackObj(const wxPyCallbackHelper
& cbh
, PyObject
* argTuple
);
314 void wxPyCBH_delete(wxPyCallbackHelper
* cbh
);
318 //----------------------------------------------------------------------
320 class wxPyUserData
: public wxObject
{
322 wxPyUserData(PyObject
* obj
) {
329 #ifdef wxPyUSE_EXPORT
330 doSave
= wxPyCoreAPIPtr
->p_wxPyRestoreThread();
332 wxPyCoreAPIPtr
->p_wxPySaveThread(doSave
);
334 doSave
= wxPyRestoreThread();
336 wxPySaveThread(doSave
);
344 //---------------------------------------------------------------------------
345 // These macros are used to implement the virtual methods that should
346 // redirect to a Python method if one exists. The names designate the
347 // return type, if any, as well as any parameter types.
348 //---------------------------------------------------------------------------
351 void _setSelf(PyObject* self, PyObject* _class, int incref=1) { \
352 wxPyCBH_setSelf(m_myInst, self, _class, incref); \
354 private: wxPyCallbackHelper m_myInst
356 //---------------------------------------------------------------------------
358 #define DEC_PYCALLBACK__(CBNAME) \
360 void base_##CBNAME();
363 #define IMP_PYCALLBACK__(CLASS, PCLASS, CBNAME) \
364 void CLASS::CBNAME() { \
365 bool doSave = wxPyRestoreThread(); \
366 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
367 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
370 wxPySaveThread(doSave); \
372 void CLASS::base_##CBNAME() { \
376 //---------------------------------------------------------------------------
378 #define DEC_PYCALLBACK_BOOL_INTINT(CBNAME) \
379 bool CBNAME(int a, int b); \
380 bool base_##CBNAME(int a, int b);
383 #define IMP_PYCALLBACK_BOOL_INTINT(CLASS, PCLASS, CBNAME) \
384 bool CLASS::CBNAME(int a, int b) { \
386 bool doSave = wxPyRestoreThread(); \
387 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
388 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
390 rval = PCLASS::CBNAME(a,b); \
391 wxPySaveThread(doSave); \
394 bool CLASS::base_##CBNAME(int a, int b) { \
395 return PCLASS::CBNAME(a,b); \
398 //---------------------------------------------------------------------------
400 #define DEC_PYCALLBACK_VOID_INTINT(CBNAME) \
401 void CBNAME(int a, int b); \
402 void base_##CBNAME(int a, int b);
405 #define IMP_PYCALLBACK_VOID_INTINT(CLASS, PCLASS, CBNAME) \
406 void CLASS::CBNAME(int a, int b) { \
407 bool doSave = wxPyRestoreThread(); \
408 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
409 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
411 PCLASS::CBNAME(a,b); \
412 wxPySaveThread(doSave); \
414 void CLASS::base_##CBNAME(int a, int b) { \
415 PCLASS::CBNAME(a,b); \
418 //---------------------------------------------------------------------------
420 #define DEC_PYCALLBACK_BOOL_INT(CBNAME) \
421 bool CBNAME(int a); \
422 bool base_##CBNAME(int a);
425 #define IMP_PYCALLBACK_BOOL_INT(CLASS, PCLASS, CBNAME) \
426 bool CLASS::CBNAME(int a) { \
428 bool doSave = wxPyRestoreThread(); \
429 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
430 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)",a)); \
432 rval = PCLASS::CBNAME(a); \
433 wxPySaveThread(doSave); \
436 bool CLASS::base_##CBNAME(int a) { \
437 return PCLASS::CBNAME(a); \
440 //---------------------------------------------------------------------------
442 #define DEC_PYCALLBACK_BOOL_INT_pure(CBNAME) \
446 #define IMP_PYCALLBACK_BOOL_INT_pure(CLASS, PCLASS, CBNAME) \
447 bool CLASS::CBNAME(int a) { \
449 bool doSave = wxPyRestoreThread(); \
450 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
451 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)",a)); \
453 wxPySaveThread(doSave); \
458 //---------------------------------------------------------------------------
460 #define DEC_PYCALLBACK__DC(CBNAME) \
461 void CBNAME(wxDC& a); \
462 void base_##CBNAME(wxDC& a);
465 #define IMP_PYCALLBACK__DC(CLASS, PCLASS, CBNAME) \
466 void CLASS::CBNAME(wxDC& a) { \
467 bool doSave = wxPyRestoreThread(); \
468 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
469 PyObject* obj = wxPyMake_wxObject(&a); \
470 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
475 wxPySaveThread(doSave); \
477 void CLASS::base_##CBNAME(wxDC& a) { \
483 //---------------------------------------------------------------------------
485 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
486 void CBNAME(wxDC& a, bool b); \
487 void base_##CBNAME(wxDC& a, bool b);
490 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
491 void CLASS::CBNAME(wxDC& a, bool b) { \
492 bool doSave = wxPyRestoreThread(); \
493 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
494 PyObject* obj = wxPyMake_wxObject(&a); \
495 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, (int)b)); \
499 PCLASS::CBNAME(a, b); \
500 wxPySaveThread(doSave); \
502 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
503 PCLASS::CBNAME(a, b); \
506 //---------------------------------------------------------------------------
508 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
509 void CBNAME(wxDC& a, bool b); \
510 void base_##CBNAME(wxDC& a, bool b);
513 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
514 void CLASS::CBNAME(wxDC& a, bool b) { \
515 bool doSave = wxPyRestoreThread(); \
516 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
517 PyObject* obj = wxPyMake_wxObject(&a); \
518 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, (int)b)); \
522 PCLASS::CBNAME(a, b); \
523 wxPySaveThread(doSave); \
525 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
526 PCLASS::CBNAME(a, b); \
529 //---------------------------------------------------------------------------
531 #define DEC_PYCALLBACK__2DBL(CBNAME) \
532 void CBNAME(double a, double b); \
533 void base_##CBNAME(double a, double b);
536 #define IMP_PYCALLBACK__2DBL(CLASS, PCLASS, CBNAME) \
537 void CLASS::CBNAME(double a, double b) { \
538 bool doSave = wxPyRestoreThread(); \
539 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
540 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(dd)",a,b)); \
542 PCLASS::CBNAME(a, b); \
543 wxPySaveThread(doSave); \
545 void CLASS::base_##CBNAME(double a, double b) { \
546 PCLASS::CBNAME(a, b); \
549 //---------------------------------------------------------------------------
551 #define DEC_PYCALLBACK__2DBL2INT(CBNAME) \
552 void CBNAME(double a, double b, int c, int d); \
553 void base_##CBNAME(double a, double b, int c, int d);
556 #define IMP_PYCALLBACK__2DBL2INT(CLASS, PCLASS, CBNAME) \
557 void CLASS::CBNAME(double a, double b, int c, int d) { \
558 bool doSave = wxPyRestoreThread(); \
559 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
560 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ddii)", \
563 PCLASS::CBNAME(a, b, c, d); \
564 wxPySaveThread(doSave); \
566 void CLASS::base_##CBNAME(double a, double b, int c, int d) { \
567 PCLASS::CBNAME(a, b, c, d); \
570 //---------------------------------------------------------------------------
572 #define DEC_PYCALLBACK__DC4DBLBOOL(CBNAME) \
573 void CBNAME(wxDC& a, double b, double c, double d, double e, bool f); \
574 void base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f);
577 #define IMP_PYCALLBACK__DC4DBLBOOL(CLASS, PCLASS, CBNAME) \
578 void CLASS::CBNAME(wxDC& a, double b, double c, double d, double e, bool f) { \
579 bool doSave = wxPyRestoreThread(); \
580 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
581 PyObject* obj = wxPyMake_wxObject(&a); \
582 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oddddi)", obj, b, c, d, e, (int)f)); \
586 PCLASS::CBNAME(a, b, c, d, e, f); \
587 wxPySaveThread(doSave); \
589 void CLASS::base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f) {\
590 PCLASS::CBNAME(a, b, c, d, e, f); \
593 //---------------------------------------------------------------------------
595 #define DEC_PYCALLBACK_BOOL_DC4DBLBOOL(CBNAME) \
596 bool CBNAME(wxDC& a, double b, double c, double d, double e, bool f); \
597 bool base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f);
600 #define IMP_PYCALLBACK_BOOL_DC4DBLBOOL(CLASS, PCLASS, CBNAME) \
601 bool CLASS::CBNAME(wxDC& a, double b, double c, double d, double e, bool f) { \
602 bool doSave = wxPyRestoreThread(); \
604 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
605 PyObject* obj = wxPyMake_wxObject(&a); \
606 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oddddi)", obj, b, c, d, e, (int)f));\
610 rval = PCLASS::CBNAME(a, b, c, d, e, f); \
611 wxPySaveThread(doSave); \
614 bool CLASS::base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f) {\
615 return PCLASS::CBNAME(a, b, c, d, e, f); \
618 //---------------------------------------------------------------------------
620 #define DEC_PYCALLBACK__BOOL2DBL2INT(CBNAME) \
621 void CBNAME(bool a, double b, double c, int d, int e); \
622 void base_##CBNAME(bool a, double b, double c, int d, int e);
625 #define IMP_PYCALLBACK__BOOL2DBL2INT(CLASS, PCLASS, CBNAME) \
626 void CLASS::CBNAME(bool a, double b, double c, int d, int e) { \
627 bool doSave = wxPyRestoreThread(); \
628 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
629 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iddii)", \
632 PCLASS::CBNAME(a, b, c, d, e); \
633 wxPySaveThread(doSave); \
635 void CLASS::base_##CBNAME(bool a, double b, double c, int d, int e) { \
636 PCLASS::CBNAME(a, b, c, d, e); \
639 //---------------------------------------------------------------------------
641 #define DEC_PYCALLBACK__DC4DBL(CBNAME) \
642 void CBNAME(wxDC& a, double b, double c, double d, double e); \
643 void base_##CBNAME(wxDC& a, double b, double c, double d, double e);
646 #define IMP_PYCALLBACK__DC4DBL(CLASS, PCLASS, CBNAME) \
647 void CLASS::CBNAME(wxDC& a, double b, double c, double d, double e) { \
648 bool doSave = wxPyRestoreThread(); \
649 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
650 PyObject* obj = wxPyMake_wxObject(&a); \
651 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Odddd)", obj, b, c, d, e)); \
655 PCLASS::CBNAME(a, b, c, d, e); \
656 wxPySaveThread(doSave); \
658 void CLASS::base_##CBNAME(wxDC& a, double b, double c, double d, double e) {\
659 PCLASS::CBNAME(a, b, c, d, e); \
662 //---------------------------------------------------------------------------
664 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
665 void CBNAME(wxDC& a, bool b); \
666 void base_##CBNAME(wxDC& a, bool b);
669 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
670 void CLASS::CBNAME(wxDC& a, bool b) { \
671 bool doSave = wxPyRestoreThread(); \
672 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
673 PyObject* obj = wxPyMake_wxObject(&a); \
674 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, (int)b)); \
678 PCLASS::CBNAME(a, b); \
679 wxPySaveThread(doSave); \
681 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
682 PCLASS::CBNAME(a, b); \
685 //---------------------------------------------------------------------------
687 #define DEC_PYCALLBACK__WXCPBOOL2DBL2INT(CBNAME) \
688 void CBNAME(wxControlPoint* a, bool b, double c, double d, int e, int f); \
689 void base_##CBNAME(wxControlPoint* a, bool b, double c, double d, int e, int f);
692 #define IMP_PYCALLBACK__WXCPBOOL2DBL2INT(CLASS, PCLASS, CBNAME) \
693 void CLASS::CBNAME(wxControlPoint* a, bool b, double c, double d, \
695 bool doSave = wxPyRestoreThread(); \
696 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
697 PyObject* obj = wxPyMake_wxObject(a); \
698 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oiddii)", obj, (int)b, c, d, e, f));\
702 PCLASS::CBNAME(a, b, c, d, e, f); \
703 wxPySaveThread(doSave); \
705 void CLASS::base_##CBNAME(wxControlPoint* a, bool b, double c, double d, \
707 PCLASS::CBNAME(a, b, c, d, e, f); \
710 //---------------------------------------------------------------------------
712 #define DEC_PYCALLBACK__WXCP2DBL2INT(CBNAME) \
713 void CBNAME(wxControlPoint* a, double b, double c, int d, int e); \
714 void base_##CBNAME(wxControlPoint* a, double b, double c, int d, int e);
717 #define IMP_PYCALLBACK__WXCP2DBL2INT(CLASS, PCLASS, CBNAME) \
718 void CLASS::CBNAME(wxControlPoint* a, double b, double c, int d, int e) { \
719 bool doSave = wxPyRestoreThread(); \
720 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
721 PyObject* obj = wxPyMake_wxObject(a); \
722 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oddii)", obj, b, c, d, e)); \
726 PCLASS::CBNAME(a, b, c, d, e); \
727 wxPySaveThread(doSave); \
729 void CLASS::base_##CBNAME(wxControlPoint* a, double b, double c, \
731 PCLASS::CBNAME(a, b, c, d, e); \
734 //---------------------------------------------------------------------------
736 #define DEC_PYCALLBACK__2DBLINT(CBNAME) \
737 void CBNAME(double a, double b, int c); \
738 void base_##CBNAME(double a, double b, int c);
741 #define IMP_PYCALLBACK__2DBLINT(CLASS, PCLASS, CBNAME) \
742 void CLASS::CBNAME(double a, double b, int c) { \
743 bool doSave = wxPyRestoreThread(); \
744 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
745 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ddi)", a,b,c)); \
747 PCLASS::CBNAME(a, b, c); \
748 wxPySaveThread(doSave); \
750 void CLASS::base_##CBNAME(double a, double b, int c) { \
751 PCLASS::CBNAME(a, b, c); \
754 //---------------------------------------------------------------------------
756 #define DEC_PYCALLBACK__BOOL2DBLINT(CBNAME) \
757 void CBNAME(bool a, double b, double c, int d); \
758 void base_##CBNAME(bool a, double b, double c, int d);
761 #define IMP_PYCALLBACK__BOOL2DBLINT(CLASS, PCLASS, CBNAME) \
762 void CLASS::CBNAME(bool a, double b, double c, int d) { \
763 bool doSave = wxPyRestoreThread(); \
764 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
765 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iddi)", (int)a,b,c,d)); \
767 PCLASS::CBNAME(a, b, c, d); \
768 wxPySaveThread(doSave); \
770 void CLASS::base_##CBNAME(bool a, double b, double c, int d) { \
771 PCLASS::CBNAME(a, b, c, d); \
774 //---------------------------------------------------------------------------
775 //---------------------------------------------------------------------------
777 #define DEC_PYCALLBACK__STRING(CBNAME) \
778 void CBNAME(const wxString& a); \
779 void base_##CBNAME(const wxString& a);
782 #define IMP_PYCALLBACK__STRING(CLASS, PCLASS, CBNAME) \
783 void CLASS::CBNAME(const wxString& a) { \
784 bool doSave = wxPyRestoreThread(); \
785 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
786 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(s)", a.c_str())); \
789 wxPySaveThread(doSave); \
791 void CLASS::base_##CBNAME(const wxString& a) { \
795 //---------------------------------------------------------------------------
797 #define DEC_PYCALLBACK_BOOL_STRING(CBNAME) \
798 bool CBNAME(const wxString& a); \
799 bool base_##CBNAME(const wxString& a);
802 #define IMP_PYCALLBACK_BOOL_STRING(CLASS, PCLASS, CBNAME) \
803 bool CLASS::CBNAME(const wxString& a) { \
805 bool doSave = wxPyRestoreThread(); \
806 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
807 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(s)", a.c_str())); \
809 rval = PCLASS::CBNAME(a); \
810 wxPySaveThread(doSave); \
813 bool CLASS::base_##CBNAME(const wxString& a) { \
814 return PCLASS::CBNAME(a); \
817 //---------------------------------------------------------------------------
819 #define DEC_PYCALLBACK_BOOL_STRING_pure(CBNAME) \
820 bool CBNAME(const wxString& a);
822 #define IMP_PYCALLBACK_BOOL_STRING_pure(CLASS, PCLASS, CBNAME) \
823 bool CLASS::CBNAME(const wxString& a) { \
825 bool doSave = wxPyRestoreThread(); \
826 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
827 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(s)", a.c_str())); \
828 wxPySaveThread(doSave); \
832 //---------------------------------------------------------------------------
834 #define DEC_PYCALLBACK_STRING_STRING_pure(CBNAME) \
835 wxString CBNAME(const wxString& a); \
837 #define IMP_PYCALLBACK_STRING_STRING_pure(CLASS, PCLASS, CBNAME) \
838 wxString CLASS::CBNAME(const wxString& a) { \
840 bool doSave = wxPyRestoreThread(); \
841 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
843 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(s)", a.c_str())); \
845 PyObject* str = PyObject_Str(ro); \
846 rval = PyString_AsString(str); \
847 Py_DECREF(ro); Py_DECREF(str); \
850 wxPySaveThread(doSave); \
854 //---------------------------------------------------------------------------
856 #define DEC_PYCALLBACK_STRING_STRINGINT_pure(CBNAME) \
857 wxString CBNAME(const wxString& a,int b); \
859 #define IMP_PYCALLBACK_STRING_STRINGINT_pure(CLASS, PCLASS, CBNAME) \
860 wxString CLASS::CBNAME(const wxString& a,int b) { \
862 bool doSave = wxPyRestoreThread(); \
863 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
865 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(si)", a.c_str(),b)); \
867 PyObject* str = PyObject_Str(ro); \
868 rval = PyString_AsString(str); \
869 Py_DECREF(ro); Py_DECREF(str); \
872 wxPySaveThread(doSave); \
876 //---------------------------------------------------------------------------
878 #define DEC_PYCALLBACK_BOOL_STRINGSTRING(CBNAME) \
879 bool CBNAME(const wxString& a, const wxString& b); \
880 bool base_##CBNAME(const wxString& a, const wxString& b);
883 #define IMP_PYCALLBACK_BOOL_STRINGSTRING(CLASS, PCLASS, CBNAME) \
884 bool CLASS::CBNAME(const wxString& a, const wxString& b) { \
886 bool doSave = wxPyRestoreThread(); \
887 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
888 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ss)", \
889 a.c_str(), b.c_str())); \
891 rval = PCLASS::CBNAME(a, b); \
892 wxPySaveThread(doSave); \
895 bool CLASS::base_##CBNAME(const wxString& a, const wxString& b) { \
896 return PCLASS::CBNAME(a, b); \
899 //---------------------------------------------------------------------------
901 #define DEC_PYCALLBACK_STRING_(CBNAME) \
903 wxString base_##CBNAME();
906 #define IMP_PYCALLBACK_STRING_(CLASS, PCLASS, CBNAME) \
907 wxString CLASS::CBNAME() { \
909 bool doSave = wxPyRestoreThread(); \
910 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
912 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
914 PyObject* str = PyObject_Str(ro); \
915 rval = PyString_AsString(str); \
916 Py_DECREF(ro); Py_DECREF(str); \
920 rval = PCLASS::CBNAME(); \
921 wxPySaveThread(doSave); \
924 wxString CLASS::base_##CBNAME() { \
925 return PCLASS::CBNAME(); \
928 //---------------------------------------------------------------------------
930 #define DEC_PYCALLBACK_STRING__pure(CBNAME) \
934 #define IMP_PYCALLBACK_STRING__pure(CLASS, PCLASS, CBNAME) \
935 wxString CLASS::CBNAME() { \
937 bool doSave = wxPyRestoreThread(); \
938 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
940 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
942 PyObject* str = PyObject_Str(ro); \
943 rval = PyString_AsString(str); \
944 Py_DECREF(ro); Py_DECREF(str); \
947 wxPySaveThread(doSave); \
951 //---------------------------------------------------------------------------
953 #define DEC_PYCALLBACK_BOOL_TAG_pure(CBNAME) \
954 bool CBNAME(const wxHtmlTag& a); \
957 #define IMP_PYCALLBACK_BOOL_TAG_pure(CLASS, PCLASS, CBNAME) \
958 bool CLASS::CBNAME(const wxHtmlTag& a) { \
960 bool doSave = wxPyRestoreThread(); \
961 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
962 PyObject* obj = wxPyConstructObject((void*)&a, "wxHtmlTag", 0); \
963 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
966 wxPySaveThread(doSave); \
970 //---------------------------------------------------------------------------
972 #define DEC_PYCALLBACK___pure(CBNAME) \
976 #define IMP_PYCALLBACK___pure(CLASS, PCLASS, CBNAME) \
977 void CLASS::CBNAME() { \
978 bool doSave = wxPyRestoreThread(); \
979 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
980 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
981 wxPySaveThread(doSave); \
984 //---------------------------------------------------------------------------
986 #define DEC_PYCALLBACK_wxSize__pure(CBNAME) \
990 #define IMP_PYCALLBACK_wxSize__pure(CLASS, PCLASS, CBNAME) \
991 wxSize CLASS::CBNAME() { \
993 bool doSave = wxPyRestoreThread(); \
994 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
997 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
999 if (! SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p")) \
1004 wxPySaveThread(doSave); \
1008 //---------------------------------------------------------------------------
1010 #define DEC_PYCALLBACK_BOOL_WXWIN(CBNAME) \
1011 bool CBNAME(wxWindow* a); \
1012 bool base_##CBNAME(wxWindow* a);
1015 #define IMP_PYCALLBACK_BOOL_WXWIN(CLASS, PCLASS, CBNAME) \
1016 bool CLASS::CBNAME(wxWindow* a) { \
1018 bool doSave = wxPyRestoreThread(); \
1019 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1020 PyObject* obj = wxPyMake_wxObject(a); \
1021 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
1025 rval = PCLASS::CBNAME(a); \
1026 wxPySaveThread(doSave); \
1029 bool CLASS::base_##CBNAME(wxWindow* a) { \
1030 return PCLASS::CBNAME(a); \
1033 //---------------------------------------------------------------------------
1035 #define DEC_PYCALLBACK_BOOL_(CBNAME) \
1037 bool base_##CBNAME();
1040 #define IMP_PYCALLBACK_BOOL_(CLASS, PCLASS, CBNAME) \
1041 bool CLASS::CBNAME() { \
1043 bool doSave = wxPyRestoreThread(); \
1044 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
1045 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
1047 rval = PCLASS::CBNAME(); \
1048 wxPySaveThread(doSave); \
1051 bool CLASS::base_##CBNAME() { \
1052 return PCLASS::CBNAME(); \
1055 //---------------------------------------------------------------------------
1057 #define DEC_PYCALLBACK_DR_2WXCDR(CBNAME) \
1058 wxDragResult CBNAME(wxCoord x, wxCoord y, wxDragResult def); \
1059 wxDragResult base_##CBNAME(wxCoord x, wxCoord y, wxDragResult def);
1062 #define IMP_PYCALLBACK_DR_2WXCDR(CLASS, PCLASS, CBNAME) \
1063 wxDragResult CLASS::CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
1064 bool doSave = wxPyRestoreThread(); \
1066 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
1067 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c));\
1069 rval = PCLASS::CBNAME(a, b, c); \
1070 wxPySaveThread(doSave); \
1071 return (wxDragResult)rval; \
1073 wxDragResult CLASS::base_##CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
1074 return PCLASS::CBNAME(a, b, c); \
1077 //---------------------------------------------------------------------------
1079 #define DEC_PYCALLBACK_FSF_FSSTRING_pure(CBNAME) \
1080 wxFSFile* CBNAME(wxFileSystem& fs, const wxString& location); \
1082 #define IMP_PYCALLBACK_FSF_FSSTRING_pure(CLASS, PCLASS, CBNAME) \
1083 wxFSFile* CLASS::CBNAME(wxFileSystem& a,const wxString& b) { \
1084 bool doSave = wxPyRestoreThread(); \
1086 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1088 PyObject* obj = wxPyMake_wxObject(&a); \
1089 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(Os)", \
1092 SWIG_GetPtrObj(ro, (void **)&rval, "_wxFSFILE_p"); \
1097 wxPySaveThread(doSave); \
1101 //---------------------------------------------------------------------------
1103 #define DEC_PYCALLBACK_BOOL_DR(CBNAME) \
1104 bool CBNAME(wxDragResult a); \
1105 bool base_##CBNAME(wxDragResult a);
1108 #define IMP_PYCALLBACK_BOOL_DR(CLASS, PCLASS, CBNAME) \
1109 bool CLASS::CBNAME(wxDragResult a) { \
1110 bool doSave = wxPyRestoreThread(); \
1112 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
1113 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)", a)); \
1115 rval = PCLASS::CBNAME(a); \
1116 wxPySaveThread(doSave); \
1119 bool CLASS::base_##CBNAME(wxDragResult a) { \
1120 return PCLASS::CBNAME(a); \
1123 //---------------------------------------------------------------------------
1125 #define DEC_PYCALLBACK_DR_2WXCDR_pure(CBNAME) \
1126 wxDragResult CBNAME(wxCoord x, wxCoord y, wxDragResult def);
1129 #define IMP_PYCALLBACK_DR_2WXCDR_pure(CLASS, PCLASS, CBNAME) \
1130 wxDragResult CLASS::CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
1131 bool doSave = wxPyRestoreThread(); \
1133 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
1134 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c));\
1135 wxPySaveThread(doSave); \
1136 return (wxDragResult)rval; \
1139 //---------------------------------------------------------------------------
1141 #define DEC_PYCALLBACK_BOOL_INTINTSTR_pure(CBNAME) \
1142 bool CBNAME(int a, int b, const wxString& c);
1145 #define IMP_PYCALLBACK_BOOL_INTINTSTR_pure(CLASS, PCLASS, CBNAME) \
1146 bool CLASS::CBNAME(int a, int b, const wxString& c) { \
1148 bool doSave = wxPyRestoreThread(); \
1149 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
1150 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iis)",a,b,c.c_str()));\
1151 wxPySaveThread(doSave); \
1155 //---------------------------------------------------------------------------
1157 #define DEC_PYCALLBACK_SIZET_(CBNAME) \
1159 size_t base_##CBNAME();
1162 #define IMP_PYCALLBACK_SIZET_(CLASS, PCLASS, CBNAME) \
1163 size_t CLASS::CBNAME() { \
1165 bool doSave = wxPyRestoreThread(); \
1166 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
1167 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
1169 rval = PCLASS::CBNAME(); \
1170 wxPySaveThread(doSave); \
1173 size_t CLASS::base_##CBNAME() { \
1174 return PCLASS::CBNAME(); \
1177 //---------------------------------------------------------------------------
1179 #define DEC_PYCALLBACK_DATAFMT_SIZET(CBNAME) \
1180 wxDataFormat CBNAME(); \
1181 wxDataFormat base_##CBNAME();
1184 #define IMP_PYCALLBACK_DATAFMT_SIZET(CLASS, PCLASS, CBNAME) \
1185 wxDataFormat CLASS::CBNAME(size_t a) { \
1186 wxDataFormat rval; \
1187 bool doSave = wxPyRestoreThread(); \
1188 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1190 wxDataFormat* ptr; \
1191 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(i)", a)); \
1193 if (! SWIG_GetPtrObj(ro, (void **)&ptr, "_wxDataFormat_p")) \
1199 rval = PCLASS::CBNAME(a); \
1200 wxPySaveThread(doSave); \
1203 wxDataFormat CLASS::base_##CBNAME(size_t a) { \
1204 return PCLASS::CBNAME(a); \
1207 //---------------------------------------------------------------------------
1209 #define DEC_PYCALLBACK__constany(CBNAME, Type) \
1210 void CBNAME(const Type& a); \
1211 void base_##CBNAME(const Type& a);
1214 #define IMP_PYCALLBACK__constany(CLASS, PCLASS, CBNAME, Type) \
1215 void CLASS::CBNAME(const Type& a) { \
1216 bool doSave = wxPyRestoreThread(); \
1217 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1218 PyObject* obj = wxPyConstructObject((void*)&a, #Type, 0); \
1219 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
1223 PCLASS::CBNAME(a); \
1224 wxPySaveThread(doSave); \
1226 void CLASS::base_##CBNAME(const Type& a) { \
1227 PCLASS::CBNAME(a); \
1231 //---------------------------------------------------------------------------
1233 #define DEC_PYCALLBACK__any(CBNAME, Type) \
1234 void CBNAME(Type& a); \
1235 void base_##CBNAME(Type& a);
1238 #define IMP_PYCALLBACK__any(CLASS, PCLASS, CBNAME, Type) \
1239 void CLASS::CBNAME(Type& a) { \
1240 bool doSave = wxPyRestoreThread(); \
1241 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1242 PyObject* obj = wxPyConstructObject((void*)&a, #Type, 0); \
1243 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
1247 PCLASS::CBNAME(a); \
1248 wxPySaveThread(doSave); \
1250 void CLASS::base_##CBNAME(Type& a) { \
1251 PCLASS::CBNAME(a); \
1254 //---------------------------------------------------------------------------
1256 #define DEC_PYCALLBACK_bool_any(CBNAME, Type) \
1257 bool CBNAME(Type& a); \
1258 bool base_##CBNAME(Type& a);
1261 #define IMP_PYCALLBACK_bool_any(CLASS, PCLASS, CBNAME, Type) \
1262 bool CLASS::CBNAME(Type& a) { \
1264 bool doSave = wxPyRestoreThread(); \
1265 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1266 PyObject* obj = wxPyConstructObject((void*)&a, #Type, 0); \
1267 rv = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
1271 rv = PCLASS::CBNAME(a); \
1272 wxPySaveThread(doSave); \
1275 bool CLASS::base_##CBNAME(Type& a) { \
1276 return PCLASS::CBNAME(a); \
1279 //---------------------------------------------------------------------------