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 #if defined(__WXMSW__)
37 # define HELPEREXPORT __declspec(dllexport)
42 typedef unsigned char byte
;
44 //----------------------------------------------------------------------
46 class wxPyApp
: public wxApp
53 //# void AfterMainLoop(void);
56 extern wxPyApp
*wxPythonApp
;
58 //----------------------------------------------------------------------
61 PyObject
* __wxStart(PyObject
*, PyObject
* args
);
64 extern PyObject
* wxPython_dict
;
65 PyObject
* __wxSetDictionary(PyObject
*, PyObject
* args
);
67 void wxPyEventThunker(wxObject
*, wxEvent
& event
);
69 HELPEREXPORT PyObject
* wxPyConstructObject(void* ptr
,
70 const char* className
,
72 HELPEREXPORT
bool wxPyRestoreThread();
73 HELPEREXPORT
void wxPySaveThread(bool doSave
);
74 HELPEREXPORT PyObject
* wxPy_ConvertList(wxListBase
* list
, const char* className
);
75 HELPEREXPORT
long wxPyGetWinHandle(wxWindow
* win
);
77 //----------------------------------------------------------------------
79 class wxPyUserData
: public wxObject
{
81 wxPyUserData(PyObject
* obj
) { m_obj
= obj
; Py_INCREF(m_obj
); }
83 bool doSave
= wxPyRestoreThread();
85 wxPySaveThread(doSave
);
90 //----------------------------------------------------------------------
91 // Handle wxInputStreams by Joerg Baumann
92 // See stream.i for implementations
94 // list class for return list of strings, e.g. readlines()
95 WX_DECLARE_LIST(wxString
, wxStringPtrList
);
98 // C++ class wxPyInputStream to act as base for python class wxInputStream
99 // Use it in python like a python file object
100 class wxPyInputStream
{
102 // underlying wxInputStream
106 wxPyInputStream(wxInputStream
* wxi_
) : wxi(wxi_
) {}
109 // python file object interface for input files (most of it)
113 wxString
* read(int size
=-1);
114 wxString
* readline(int size
=-1);
115 wxStringPtrList
* readlines(int sizehint
=-1);
116 void seek(int offset
, int whence
=0);
121 void truncate(int size=-1);
122 void write(wxString data);
123 void writelines(wxStringPtrList);
128 //----------------------------------------------------------------------
129 // These are helpers used by the typemaps
131 HELPEREXPORT byte
* byte_LIST_helper(PyObject
* source
);
132 HELPEREXPORT
int* int_LIST_helper(PyObject
* source
);
133 HELPEREXPORT
long* long_LIST_helper(PyObject
* source
);
134 HELPEREXPORT
char** string_LIST_helper(PyObject
* source
);
135 HELPEREXPORT wxPoint
* wxPoint_LIST_helper(PyObject
* source
);
136 HELPEREXPORT wxBitmap
** wxBitmap_LIST_helper(PyObject
* source
);
137 HELPEREXPORT wxString
* wxString_LIST_helper(PyObject
* source
);
138 HELPEREXPORT wxAcceleratorEntry
* wxAcceleratorEntry_LIST_helper(PyObject
* source
);
140 HELPEREXPORT
bool wxSize_helper(PyObject
* source
, wxSize
** obj
);
141 HELPEREXPORT
bool wxPoint_helper(PyObject
* source
, wxPoint
** obj
);
142 HELPEREXPORT
bool wxRealPoint_helper(PyObject
* source
, wxRealPoint
** obj
);
143 HELPEREXPORT
bool wxRect_helper(PyObject
* source
, wxRect
** obj
);
144 HELPEREXPORT
bool wxColour_helper(PyObject
* source
, wxColour
** obj
);
146 //----------------------------------------------------------------------
149 extern "C" void SWIG_MakePtr(char *, void *, char *);
150 extern "C" char *SWIG_GetPtr(char *, void **, char *);
151 extern "C" char *SWIG_GetPtrObj(PyObject
*obj
, void **ptr
, char *type
);
156 # pragma warning(disable:4800)
157 # pragma warning(disable:4190)
162 // Non-const versions to keep SWIG happy.
163 extern wxPoint wxPyDefaultPosition
;
164 extern wxSize wxPyDefaultSize
;
165 extern wxString wxPyEmptyStr
;
167 //----------------------------------------------------------------------
169 class wxPyCallback
: public wxObject
{
170 DECLARE_ABSTRACT_CLASS(wxPyCallback
);
172 wxPyCallback(PyObject
* func
);
173 wxPyCallback(const wxPyCallback
& other
);
176 void EventThunker(wxEvent
& event
);
181 //---------------------------------------------------------------------------
183 class wxPyTimer
: public wxTimer
{
185 wxPyTimer(PyObject
* callback
);
194 //---------------------------------------------------------------------------
199 //---------------------------------------------------------------------------
200 // This class holds an instance of a Python Shadow Class object and assists
201 // with looking up and invoking Python callback methods from C++ virtual
202 // method redirections. For all classes which have virtuals which should be
203 // overridable in wxPython, a new subclass is created that contains a
204 // wxPyCallbackHelper.
206 // TODO: This class should be combined with wxPyCallback defined above.
209 class HELPEREXPORT wxPyCallbackHelper
{
211 wxPyCallbackHelper();
212 ~wxPyCallbackHelper();
214 wxPyCallbackHelper(const wxPyCallbackHelper
& other
);
216 void setSelf(PyObject
* self
, PyObject
* klass
, int incref
=TRUE
);
218 bool findCallback(const char* name
) const;
219 int callCallback(PyObject
* argTuple
) const;
220 PyObject
* callCallbackObj(PyObject
* argTuple
) const;
225 PyObject
* m_lastFound
;
230 //---------------------------------------------------------------------------
231 //---------------------------------------------------------------------------
232 // These Event classes can be derived from in Python and passed through the
233 // event system without loosing anything. They do this by keeping a reference
234 // to themselves and some special case handling in wxPyCallback::EventThunker.
237 class wxPyEvtSelfRef
{
242 void SetSelf(PyObject
* self
, bool clone
=FALSE
);
243 PyObject
* GetSelf() const;
251 class wxPyEvent
: public wxEvent
, public wxPyEvtSelfRef
{
252 DECLARE_DYNAMIC_CLASS(wxPyEvent
)
257 void CopyObject(wxObject
& dest
) const;
261 class wxPyCommandEvent
: public wxCommandEvent
, public wxPyEvtSelfRef
{
262 DECLARE_DYNAMIC_CLASS(wxPyCommandEvent
)
264 wxPyCommandEvent(wxEventType commandType
= wxEVT_NULL
, int id
=0);
267 void CopyObject(wxObject
& dest
) const;
271 //---------------------------------------------------------------------------
272 // These macros are used to implement the virtual methods that should
273 // redirect to a Python method if one exists. The names designate the
274 // return type, if any, as well as any parameter types.
275 //---------------------------------------------------------------------------
278 void _setSelf(PyObject* self, PyObject* _class, int incref=1) { \
279 m_myInst.setSelf(self, _class, incref); \
281 private: wxPyCallbackHelper m_myInst
283 //---------------------------------------------------------------------------
285 #define DEC_PYCALLBACK__(CBNAME) \
287 void base_##CBNAME();
290 #define IMP_PYCALLBACK__(CLASS, PCLASS, CBNAME) \
291 void CLASS::CBNAME() { \
292 bool doSave = wxPyRestoreThread(); \
293 if (m_myInst.findCallback(#CBNAME)) \
294 m_myInst.callCallback(Py_BuildValue("()")); \
297 wxPySaveThread(doSave); \
299 void CLASS::base_##CBNAME() { \
303 //---------------------------------------------------------------------------
305 #define DEC_PYCALLBACK_BOOL_INTINT(CBNAME) \
306 bool CBNAME(int a, int b); \
307 bool base_##CBNAME(int a, int b);
310 #define IMP_PYCALLBACK_BOOL_INTINT(CLASS, PCLASS, CBNAME) \
311 bool CLASS::CBNAME(int a, int b) { \
313 bool doSave = wxPyRestoreThread(); \
314 if (m_myInst.findCallback(#CBNAME)) \
315 rval = m_myInst.callCallback(Py_BuildValue("(ii)",a,b)); \
317 rval = PCLASS::CBNAME(a,b); \
318 wxPySaveThread(doSave); \
321 bool CLASS::base_##CBNAME(int a, int b) { \
322 return PCLASS::CBNAME(a,b); \
325 //---------------------------------------------------------------------------
327 #define DEC_PYCALLBACK_VOID_INTINT(CBNAME) \
328 void CBNAME(int a, int b); \
329 void base_##CBNAME(int a, int b);
332 #define IMP_PYCALLBACK_VOID_INTINT(CLASS, PCLASS, CBNAME) \
333 void CLASS::CBNAME(int a, int b) { \
334 bool doSave = wxPyRestoreThread(); \
335 if (m_myInst.findCallback(#CBNAME)) \
336 m_myInst.callCallback(Py_BuildValue("(ii)",a,b)); \
338 PCLASS::CBNAME(a,b); \
339 wxPySaveThread(doSave); \
341 void CLASS::base_##CBNAME(int a, int b) { \
342 PCLASS::CBNAME(a,b); \
345 //---------------------------------------------------------------------------
347 #define DEC_PYCALLBACK_BOOL_INT(CBNAME) \
348 bool CBNAME(int a); \
349 bool base_##CBNAME(int a);
352 #define IMP_PYCALLBACK_BOOL_INT(CLASS, PCLASS, CBNAME) \
353 bool CLASS::CBNAME(int a) { \
355 bool doSave = wxPyRestoreThread(); \
356 if (m_myInst.findCallback(#CBNAME)) \
357 rval = m_myInst.callCallback(Py_BuildValue("(i)",a)); \
359 rval = PCLASS::CBNAME(a); \
360 wxPySaveThread(doSave); \
363 bool CLASS::base_##CBNAME(int a) { \
364 return PCLASS::CBNAME(a); \
367 //---------------------------------------------------------------------------
369 #define DEC_PYCALLBACK_BOOL_INT_pure(CBNAME) \
373 #define IMP_PYCALLBACK_BOOL_INT_pure(CLASS, PCLASS, CBNAME) \
374 bool CLASS::CBNAME(int a) { \
376 bool doSave = wxPyRestoreThread(); \
377 if (m_myInst.findCallback(#CBNAME)) \
378 rval = m_myInst.callCallback(Py_BuildValue("(i)",a)); \
380 wxPySaveThread(doSave); \
385 //---------------------------------------------------------------------------
387 #define DEC_PYCALLBACK__DC(CBNAME) \
388 void CBNAME(wxDC& a); \
389 void base_##CBNAME(wxDC& a);
392 #define IMP_PYCALLBACK__DC(CLASS, PCLASS, CBNAME) \
393 void CLASS::CBNAME(wxDC& a) { \
394 bool doSave = wxPyRestoreThread(); \
395 if (m_myInst.findCallback(#CBNAME)) { \
396 PyObject* obj = wxPyConstructObject(&a, "wxDC"); \
397 m_myInst.callCallback(Py_BuildValue("(O)", obj)); \
402 wxPySaveThread(doSave); \
404 void CLASS::base_##CBNAME(wxDC& a) { \
410 //---------------------------------------------------------------------------
412 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
413 void CBNAME(wxDC& a, bool b); \
414 void base_##CBNAME(wxDC& a, bool b);
417 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
418 void CLASS::CBNAME(wxDC& a, bool b) { \
419 bool doSave = wxPyRestoreThread(); \
420 if (m_myInst.findCallback(#CBNAME)) { \
421 PyObject* obj = wxPyConstructObject(&a, "wxDC"); \
422 m_myInst.callCallback(Py_BuildValue("(Oi)", obj, (int)b)); \
426 PCLASS::CBNAME(a, b); \
427 wxPySaveThread(doSave); \
429 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
430 PCLASS::CBNAME(a, b); \
433 //---------------------------------------------------------------------------
435 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
436 void CBNAME(wxDC& a, bool b); \
437 void base_##CBNAME(wxDC& a, bool b);
440 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
441 void CLASS::CBNAME(wxDC& a, bool b) { \
442 bool doSave = wxPyRestoreThread(); \
443 if (m_myInst.findCallback(#CBNAME)) { \
444 PyObject* obj = wxPyConstructObject(&a, "wxDC"); \
445 m_myInst.callCallback(Py_BuildValue("(Oi)", obj, (int)b)); \
449 PCLASS::CBNAME(a, b); \
450 wxPySaveThread(doSave); \
452 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
453 PCLASS::CBNAME(a, b); \
456 //---------------------------------------------------------------------------
458 #define DEC_PYCALLBACK__2DBL(CBNAME) \
459 void CBNAME(double a, double b); \
460 void base_##CBNAME(double a, double b);
463 #define IMP_PYCALLBACK__2DBL(CLASS, PCLASS, CBNAME) \
464 void CLASS::CBNAME(double a, double b) { \
465 bool doSave = wxPyRestoreThread(); \
466 if (m_myInst.findCallback(#CBNAME)) \
467 m_myInst.callCallback(Py_BuildValue("(dd)",a,b)); \
469 PCLASS::CBNAME(a, b); \
470 wxPySaveThread(doSave); \
472 void CLASS::base_##CBNAME(double a, double b) { \
473 PCLASS::CBNAME(a, b); \
476 //---------------------------------------------------------------------------
478 #define DEC_PYCALLBACK__2DBL2INT(CBNAME) \
479 void CBNAME(double a, double b, int c, int d); \
480 void base_##CBNAME(double a, double b, int c, int d);
483 #define IMP_PYCALLBACK__2DBL2INT(CLASS, PCLASS, CBNAME) \
484 void CLASS::CBNAME(double a, double b, int c, int d) { \
485 bool doSave = wxPyRestoreThread(); \
486 if (m_myInst.findCallback(#CBNAME)) \
487 m_myInst.callCallback(Py_BuildValue("(ddii)", \
490 PCLASS::CBNAME(a, b, c, d); \
491 wxPySaveThread(doSave); \
493 void CLASS::base_##CBNAME(double a, double b, int c, int d) { \
494 PCLASS::CBNAME(a, b, c, d); \
497 //---------------------------------------------------------------------------
499 #define DEC_PYCALLBACK__DC4DBLBOOL(CBNAME) \
500 void CBNAME(wxDC& a, double b, double c, double d, double e, bool f); \
501 void base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f);
504 #define IMP_PYCALLBACK__DC4DBLBOOL(CLASS, PCLASS, CBNAME) \
505 void CLASS::CBNAME(wxDC& a, double b, double c, double d, double e, bool f) { \
506 bool doSave = wxPyRestoreThread(); \
507 if (m_myInst.findCallback(#CBNAME)) { \
508 PyObject* obj = wxPyConstructObject(&a, "wxDC"); \
509 m_myInst.callCallback(Py_BuildValue("(Oddddi)", obj, b, c, d, e, (int)f)); \
513 PCLASS::CBNAME(a, b, c, d, e, f); \
514 wxPySaveThread(doSave); \
516 void CLASS::base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f) {\
517 PCLASS::CBNAME(a, b, c, d, e, f); \
520 //---------------------------------------------------------------------------
522 #define DEC_PYCALLBACK_BOOL_DC4DBLBOOL(CBNAME) \
523 bool CBNAME(wxDC& a, double b, double c, double d, double e, bool f); \
524 bool base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f);
527 #define IMP_PYCALLBACK_BOOL_DC4DBLBOOL(CLASS, PCLASS, CBNAME) \
528 bool CLASS::CBNAME(wxDC& a, double b, double c, double d, double e, bool f) { \
529 bool doSave = wxPyRestoreThread(); \
531 if (m_myInst.findCallback(#CBNAME)) { \
532 PyObject* obj = wxPyConstructObject(&a, "wxDC"); \
533 rval = m_myInst.callCallback(Py_BuildValue("(Oddddi)", obj, b, c, d, e, (int)f));\
537 rval = PCLASS::CBNAME(a, b, c, d, e, f); \
538 wxPySaveThread(doSave); \
541 bool CLASS::base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f) {\
542 return PCLASS::CBNAME(a, b, c, d, e, f); \
545 //---------------------------------------------------------------------------
547 #define DEC_PYCALLBACK__BOOL2DBL2INT(CBNAME) \
548 void CBNAME(bool a, double b, double c, int d, int e); \
549 void base_##CBNAME(bool a, double b, double c, int d, int e);
552 #define IMP_PYCALLBACK__BOOL2DBL2INT(CLASS, PCLASS, CBNAME) \
553 void CLASS::CBNAME(bool a, double b, double c, int d, int e) { \
554 bool doSave = wxPyRestoreThread(); \
555 if (m_myInst.findCallback(#CBNAME)) \
556 m_myInst.callCallback(Py_BuildValue("(idii)", \
559 PCLASS::CBNAME(a, b, c, d, e); \
560 wxPySaveThread(doSave); \
562 void CLASS::base_##CBNAME(bool a, double b, double c, int d, int e) { \
563 PCLASS::CBNAME(a, b, c, d, e); \
566 //---------------------------------------------------------------------------
568 #define DEC_PYCALLBACK__DC4DBL(CBNAME) \
569 void CBNAME(wxDC& a, double b, double c, double d, double e); \
570 void base_##CBNAME(wxDC& a, double b, double c, double d, double e);
573 #define IMP_PYCALLBACK__DC4DBL(CLASS, PCLASS, CBNAME) \
574 void CLASS::CBNAME(wxDC& a, double b, double c, double d, double e) { \
575 bool doSave = wxPyRestoreThread(); \
576 if (m_myInst.findCallback(#CBNAME)) { \
577 PyObject* obj = wxPyConstructObject(&a, "wxDC"); \
578 m_myInst.callCallback(Py_BuildValue("(Odddd)", obj, b, c, d, e)); \
582 PCLASS::CBNAME(a, b, c, d, e); \
583 wxPySaveThread(doSave); \
585 void CLASS::base_##CBNAME(wxDC& a, double b, double c, double d, double e) {\
586 PCLASS::CBNAME(a, b, c, d, e); \
589 //---------------------------------------------------------------------------
591 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
592 void CBNAME(wxDC& a, bool b); \
593 void base_##CBNAME(wxDC& a, bool b);
596 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
597 void CLASS::CBNAME(wxDC& a, bool b) { \
598 bool doSave = wxPyRestoreThread(); \
599 if (m_myInst.findCallback(#CBNAME)) { \
600 PyObject* obj = wxPyConstructObject(&a, "wxDC"); \
601 m_myInst.callCallback(Py_BuildValue("(Oi)", obj, (int)b)); \
605 PCLASS::CBNAME(a, b); \
606 wxPySaveThread(doSave); \
608 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
609 PCLASS::CBNAME(a, b); \
612 //---------------------------------------------------------------------------
614 #define DEC_PYCALLBACK__WXCPBOOL2DBL2INT(CBNAME) \
615 void CBNAME(wxControlPoint* a, bool b, double c, double d, int e, int f); \
616 void base_##CBNAME(wxControlPoint* a, bool b, double c, double d, int e, int f);
619 #define IMP_PYCALLBACK__WXCPBOOL2DBL2INT(CLASS, PCLASS, CBNAME) \
620 void CLASS::CBNAME(wxControlPoint* a, bool b, double c, double d, \
622 bool doSave = wxPyRestoreThread(); \
623 if (m_myInst.findCallback(#CBNAME)) { \
624 PyObject* obj = wxPyConstructObject(a, "wxPyControlPoint"); \
625 m_myInst.callCallback(Py_BuildValue("(Oiddii)", obj, (int)b, c, d, e, f));\
629 PCLASS::CBNAME(a, b, c, d, e, f); \
630 wxPySaveThread(doSave); \
632 void CLASS::base_##CBNAME(wxControlPoint* a, bool b, double c, double d, \
634 PCLASS::CBNAME(a, b, c, d, e, f); \
637 //---------------------------------------------------------------------------
639 #define DEC_PYCALLBACK__WXCP2DBL2INT(CBNAME) \
640 void CBNAME(wxControlPoint* a, double b, double c, int d, int e); \
641 void base_##CBNAME(wxControlPoint* a, double b, double c, int d, int e);
644 #define IMP_PYCALLBACK__WXCP2DBL2INT(CLASS, PCLASS, CBNAME) \
645 void CLASS::CBNAME(wxControlPoint* a, double b, double c, int d, int e) { \
646 bool doSave = wxPyRestoreThread(); \
647 if (m_myInst.findCallback(#CBNAME)) { \
648 PyObject* obj = wxPyConstructObject(a, "wxPyControlPoint"); \
649 m_myInst.callCallback(Py_BuildValue("(Oddii)", obj, b, c, d, e)); \
653 PCLASS::CBNAME(a, b, c, d, e); \
654 wxPySaveThread(doSave); \
656 void CLASS::base_##CBNAME(wxControlPoint* a, double b, double c, \
658 PCLASS::CBNAME(a, b, c, d, e); \
661 //---------------------------------------------------------------------------
663 #define DEC_PYCALLBACK__2DBLINT(CBNAME) \
664 void CBNAME(double a, double b, int c); \
665 void base_##CBNAME(double a, double b, int c);
668 #define IMP_PYCALLBACK__2DBLINT(CLASS, PCLASS, CBNAME) \
669 void CLASS::CBNAME(double a, double b, int c) { \
670 bool doSave = wxPyRestoreThread(); \
671 if (m_myInst.findCallback(#CBNAME)) \
672 m_myInst.callCallback(Py_BuildValue("(ddi)", a,b,c)); \
674 PCLASS::CBNAME(a, b, c); \
675 wxPySaveThread(doSave); \
677 void CLASS::base_##CBNAME(double a, double b, int c) { \
678 PCLASS::CBNAME(a, b, c); \
681 //---------------------------------------------------------------------------
683 #define DEC_PYCALLBACK__BOOL2DBLINT(CBNAME) \
684 void CBNAME(bool a, double b, double c, int d); \
685 void base_##CBNAME(bool a, double b, double c, int d);
688 #define IMP_PYCALLBACK__BOOL2DBLINT(CLASS, PCLASS, CBNAME) \
689 void CLASS::CBNAME(bool a, double b, double c, int d) { \
690 bool doSave = wxPyRestoreThread(); \
691 if (m_myInst.findCallback(#CBNAME)) \
692 m_myInst.callCallback(Py_BuildValue("(iddi)", (int)a,b,c,d)); \
694 PCLASS::CBNAME(a, b, c, d); \
695 wxPySaveThread(doSave); \
697 void CLASS::base_##CBNAME(bool a, double b, double c, int d) { \
698 PCLASS::CBNAME(a, b, c, d); \
701 //---------------------------------------------------------------------------
702 //---------------------------------------------------------------------------
704 #define DEC_PYCALLBACK__STRING(CBNAME) \
705 void CBNAME(const wxString& a); \
706 void base_##CBNAME(const wxString& a);
709 #define IMP_PYCALLBACK__STRING(CLASS, PCLASS, CBNAME) \
710 void CLASS::CBNAME(const wxString& a) { \
711 bool doSave = wxPyRestoreThread(); \
712 if (m_myInst.findCallback(#CBNAME)) \
713 m_myInst.callCallback(Py_BuildValue("(s)", a.c_str())); \
716 wxPySaveThread(doSave); \
718 void CLASS::base_##CBNAME(const wxString& a) { \
722 //---------------------------------------------------------------------------
724 #define DEC_PYCALLBACK_BOOL_STRING(CBNAME) \
725 bool CBNAME(const wxString& a); \
726 bool base_##CBNAME(const wxString& a);
729 #define IMP_PYCALLBACK_BOOL_STRING(CLASS, PCLASS, CBNAME) \
730 bool CLASS::CBNAME(const wxString& a) { \
732 bool doSave = wxPyRestoreThread(); \
733 if (m_myInst.findCallback(#CBNAME)) \
734 rval = m_myInst.callCallback(Py_BuildValue("(s)", a.c_str())); \
736 rval = PCLASS::CBNAME(a); \
737 wxPySaveThread(doSave); \
740 bool CLASS::base_##CBNAME(const wxString& a) { \
741 return PCLASS::CBNAME(a); \
744 //---------------------------------------------------------------------------
746 #define DEC_PYCALLBACK_BOOL_STRING_pure(CBNAME) \
747 bool CBNAME(const wxString& a);
749 #define IMP_PYCALLBACK_BOOL_STRING_pure(CLASS, PCLASS, CBNAME) \
750 bool CLASS::CBNAME(const wxString& a) { \
752 bool doSave = wxPyRestoreThread(); \
753 if (m_myInst.findCallback(#CBNAME)) \
754 rval = m_myInst.callCallback(Py_BuildValue("(s)", a.c_str())); \
755 wxPySaveThread(doSave); \
759 //---------------------------------------------------------------------------
761 #define DEC_PYCALLBACK_STRING_STRING_pure(CBNAME) \
762 wxString CBNAME(const wxString& a); \
764 #define IMP_PYCALLBACK_STRING_STRING_pure(CLASS, PCLASS, CBNAME) \
765 wxString CLASS::CBNAME(const wxString& a) { \
767 bool doSave = wxPyRestoreThread(); \
768 if (m_myInst.findCallback(#CBNAME)) { \
770 ro = m_myInst.callCallbackObj(Py_BuildValue("(s)", a.c_str())); \
772 PyObject* str = PyObject_Str(ro); \
773 rval = PyString_AsString(str); \
774 Py_DECREF(ro); Py_DECREF(str); \
777 wxPySaveThread(doSave); \
781 //---------------------------------------------------------------------------
783 #define DEC_PYCALLBACK_STRING_STRINGINT_pure(CBNAME) \
784 wxString CBNAME(const wxString& a,int b); \
786 #define IMP_PYCALLBACK_STRING_STRINGINT_pure(CLASS, PCLASS, CBNAME) \
787 wxString CLASS::CBNAME(const wxString& a,int b) { \
789 bool doSave = wxPyRestoreThread(); \
790 if (m_myInst.findCallback(#CBNAME)) { \
792 ro = m_myInst.callCallbackObj(Py_BuildValue("(si)", a.c_str(),b)); \
794 PyObject* str = PyObject_Str(ro); \
795 rval = PyString_AsString(str); \
796 Py_DECREF(ro); Py_DECREF(str); \
799 wxPySaveThread(doSave); \
803 //---------------------------------------------------------------------------
805 #define DEC_PYCALLBACK_BOOL_STRINGSTRING(CBNAME) \
806 bool CBNAME(const wxString& a, const wxString& b); \
807 bool base_##CBNAME(const wxString& a, const wxString& b);
810 #define IMP_PYCALLBACK_BOOL_STRINGSTRING(CLASS, PCLASS, CBNAME) \
811 bool CLASS::CBNAME(const wxString& a, const wxString& b) { \
813 bool doSave = wxPyRestoreThread(); \
814 if (m_myInst.findCallback(#CBNAME)) \
815 rval = m_myInst.callCallback(Py_BuildValue("(ss)", \
816 a.c_str(), b.c_str())); \
818 rval = PCLASS::CBNAME(a, b); \
819 wxPySaveThread(doSave); \
822 bool CLASS::base_##CBNAME(const wxString& a, const wxString& b) { \
823 return PCLASS::CBNAME(a, b); \
826 //---------------------------------------------------------------------------
828 #define DEC_PYCALLBACK_STRING_(CBNAME) \
830 wxString base_##CBNAME();
833 #define IMP_PYCALLBACK_STRING_(CLASS, PCLASS, CBNAME) \
834 wxString CLASS::CBNAME() { \
836 bool doSave = wxPyRestoreThread(); \
837 if (m_myInst.findCallback(#CBNAME)) { \
839 ro = m_myInst.callCallbackObj(Py_BuildValue("()")); \
841 PyObject* str = PyObject_Str(ro); \
842 rval = PyString_AsString(str); \
843 Py_DECREF(ro); Py_DECREF(str); \
847 rval = PCLASS::CBNAME(); \
848 wxPySaveThread(doSave); \
851 wxString CLASS::base_##CBNAME() { \
852 return PCLASS::CBNAME(); \
855 //---------------------------------------------------------------------------
857 #define DEC_PYCALLBACK_STRING__pure(CBNAME) \
861 #define IMP_PYCALLBACK_STRING__pure(CLASS, PCLASS, CBNAME) \
862 wxString CLASS::CBNAME() { \
864 bool doSave = wxPyRestoreThread(); \
865 if (m_myInst.findCallback(#CBNAME)) { \
867 ro = m_myInst.callCallbackObj(Py_BuildValue("()")); \
869 PyObject* str = PyObject_Str(ro); \
870 rval = PyString_AsString(str); \
871 Py_DECREF(ro); Py_DECREF(str); \
874 wxPySaveThread(doSave); \
878 //---------------------------------------------------------------------------
880 #define DEC_PYCALLBACK_BOOL_TAG_pure(CBNAME) \
881 bool CBNAME(const wxHtmlTag& a); \
884 #define IMP_PYCALLBACK_BOOL_TAG_pure(CLASS, PCLASS, CBNAME) \
885 bool CLASS::CBNAME(const wxHtmlTag& a) { \
887 bool doSave = wxPyRestoreThread(); \
888 if (m_myInst.findCallback(#CBNAME)) { \
889 PyObject* obj = wxPyConstructObject((void*)&a,"wxHtmlTag"); \
890 rval = m_myInst.callCallback(Py_BuildValue("(O)", obj)); \
893 wxPySaveThread(doSave); \
897 //---------------------------------------------------------------------------
899 #define DEC_PYCALLBACK___pure(CBNAME) \
903 #define IMP_PYCALLBACK___pure(CLASS, PCLASS, CBNAME) \
904 void CLASS::CBNAME() { \
905 bool doSave = wxPyRestoreThread(); \
906 if (m_myInst.findCallback(#CBNAME)) \
907 m_myInst.callCallback(Py_BuildValue("()")); \
908 wxPySaveThread(doSave); \
911 //---------------------------------------------------------------------------
913 #define DEC_PYCALLBACK_wxSize__pure(CBNAME) \
917 #define IMP_PYCALLBACK_wxSize__pure(CLASS, PCLASS, CBNAME) \
918 wxSize CLASS::CBNAME() { \
920 bool doSave = wxPyRestoreThread(); \
921 if (m_myInst.findCallback(#CBNAME)) { \
924 ro = m_myInst.callCallbackObj(Py_BuildValue("()")); \
926 if (! SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p")) \
931 wxPySaveThread(doSave); \
935 //---------------------------------------------------------------------------
937 #define DEC_PYCALLBACK_BOOL_WXWIN(CBNAME) \
938 bool CBNAME(wxWindow* a); \
939 bool base_##CBNAME(wxWindow* a);
942 #define IMP_PYCALLBACK_BOOL_WXWIN(CLASS, PCLASS, CBNAME) \
943 bool CLASS::CBNAME(wxWindow* a) { \
945 bool doSave = wxPyRestoreThread(); \
946 if (m_myInst.findCallback(#CBNAME)) { \
947 PyObject* obj = wxPyConstructObject((void*)a,"wxWindow"); \
948 rval = m_myInst.callCallback(Py_BuildValue("(O)", obj)); \
952 rval = PCLASS::CBNAME(a); \
953 wxPySaveThread(doSave); \
956 bool CLASS::base_##CBNAME(wxWindow* a) { \
957 return PCLASS::CBNAME(a); \
960 //---------------------------------------------------------------------------
962 #define DEC_PYCALLBACK_BOOL_(CBNAME) \
964 bool base_##CBNAME();
967 #define IMP_PYCALLBACK_BOOL_(CLASS, PCLASS, CBNAME) \
968 bool CLASS::CBNAME() { \
970 bool doSave = wxPyRestoreThread(); \
971 if (m_myInst.findCallback(#CBNAME)) \
972 rval = m_myInst.callCallback(Py_BuildValue("()")); \
974 rval = PCLASS::CBNAME(); \
975 wxPySaveThread(doSave); \
978 bool CLASS::base_##CBNAME() { \
979 return PCLASS::CBNAME(); \
982 //---------------------------------------------------------------------------
984 #define DEC_PYCALLBACK_DR_2WXCDR(CBNAME) \
985 wxDragResult CBNAME(wxCoord x, wxCoord y, wxDragResult def); \
986 wxDragResult base_##CBNAME(wxCoord x, wxCoord y, wxDragResult def);
989 #define IMP_PYCALLBACK_DR_2WXCDR(CLASS, PCLASS, CBNAME) \
990 wxDragResult CLASS::CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
991 bool doSave = wxPyRestoreThread(); \
993 if (m_myInst.findCallback(#CBNAME)) \
994 rval = m_myInst.callCallback(Py_BuildValue("(iii)", a,b,c));\
996 rval = PCLASS::CBNAME(a, b, c); \
997 wxPySaveThread(doSave); \
998 return (wxDragResult)rval; \
1000 wxDragResult CLASS::base_##CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
1001 return PCLASS::CBNAME(a, b, c); \
1004 //---------------------------------------------------------------------------
1006 #define DEC_PYCALLBACK_FSF_FSSTRING_pure(CBNAME) \
1007 wxFSFile* CBNAME(wxFileSystem& fs, const wxString& location); \
1009 #define IMP_PYCALLBACK_FSF_FSSTRING_pure(CLASS, PCLASS, CBNAME) \
1010 wxFSFile* CLASS::CBNAME(wxFileSystem& a,const wxString& b) { \
1011 bool doSave = wxPyRestoreThread(); \
1013 if (m_myInst.findCallback(#CBNAME)) { \
1015 PyObject* obj = wxPyConstructObject(&a, "(wxFileSystem"); \
1016 ro = m_myInst.callCallbackObj(Py_BuildValue("(Os)", \
1019 SWIG_GetPtrObj(ro, (void **)&rval, "_wxFSFILE_p"); \
1024 wxPySaveThread(doSave); \
1028 //---------------------------------------------------------------------------
1030 #define DEC_PYCALLBACK_BOOL_DR(CBNAME) \
1031 bool CBNAME(wxDragResult a); \
1032 bool base_##CBNAME(wxDragResult a);
1035 #define IMP_PYCALLBACK_BOOL_DR(CLASS, PCLASS, CBNAME) \
1036 bool CLASS::CBNAME(wxDragResult a) { \
1037 bool doSave = wxPyRestoreThread(); \
1039 if (m_myInst.findCallback(#CBNAME)) \
1040 rval = m_myInst.callCallback(Py_BuildValue("(i)", a)); \
1042 rval = PCLASS::CBNAME(a); \
1043 wxPySaveThread(doSave); \
1046 bool CLASS::base_##CBNAME(wxDragResult a) { \
1047 return PCLASS::CBNAME(a); \
1050 //---------------------------------------------------------------------------
1052 #define DEC_PYCALLBACK_DR_2WXCDR_pure(CBNAME) \
1053 wxDragResult CBNAME(wxCoord x, wxCoord y, wxDragResult def);
1056 #define IMP_PYCALLBACK_DR_2WXCDR_pure(CLASS, PCLASS, CBNAME) \
1057 wxDragResult CLASS::CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
1058 bool doSave = wxPyRestoreThread(); \
1060 if (m_myInst.findCallback(#CBNAME)) \
1061 rval = m_myInst.callCallback(Py_BuildValue("(iii)", a,b,c));\
1062 wxPySaveThread(doSave); \
1063 return (wxDragResult)rval; \
1066 //---------------------------------------------------------------------------
1068 #define DEC_PYCALLBACK_BOOL_INTINTSTR_pure(CBNAME) \
1069 bool CBNAME(int a, int b, const wxString& c);
1072 #define IMP_PYCALLBACK_BOOL_INTINTSTR_pure(CLASS, PCLASS, CBNAME) \
1073 bool CLASS::CBNAME(int a, int b, const wxString& c) { \
1075 bool doSave = wxPyRestoreThread(); \
1076 if (m_myInst.findCallback(#CBNAME)) \
1077 rval = m_myInst.callCallback(Py_BuildValue("(iis)",a,b,c.c_str()));\
1078 wxPySaveThread(doSave); \
1082 //---------------------------------------------------------------------------
1084 #define DEC_PYCALLBACK_SIZET_(CBNAME) \
1086 size_t base_##CBNAME();
1089 #define IMP_PYCALLBACK_SIZET_(CLASS, PCLASS, CBNAME) \
1090 size_t CLASS::CBNAME() { \
1092 bool doSave = wxPyRestoreThread(); \
1093 if (m_myInst.findCallback(#CBNAME)) \
1094 rval = m_myInst.callCallback(Py_BuildValue("()")); \
1096 rval = PCLASS::CBNAME(); \
1097 wxPySaveThread(doSave); \
1100 size_t CLASS::base_##CBNAME() { \
1101 return PCLASS::CBNAME(); \
1104 //---------------------------------------------------------------------------
1106 #define DEC_PYCALLBACK_DATAFMT_SIZET(CBNAME) \
1107 wxDataFormat CBNAME(); \
1108 wxDataFormat base_##CBNAME();
1111 #define IMP_PYCALLBACK_DATAFMT_SIZET(CLASS, PCLASS, CBNAME) \
1112 wxDataFormat CLASS::CBNAME(size_t a) { \
1113 wxDataFormat rval; \
1114 bool doSave = wxPyRestoreThread(); \
1115 if (m_myInst.findCallback(#CBNAME)) { \
1117 wxDataFormat* ptr; \
1118 ro = m_myInst.callCallbackObj(Py_BuildValue("(i)", a)); \
1120 if (! SWIG_GetPtrObj(ro, (void **)&ptr, "_wxDataFormat_p")) \
1126 rval = PCLASS::CBNAME(a); \
1127 wxPySaveThread(doSave); \
1130 wxDataFormat CLASS::base_##CBNAME(size_t a) { \
1131 return PCLASS::CBNAME(a); \
1134 //---------------------------------------------------------------------------
1136 #define DEC_PYCALLBACK__constany(CBNAME, Type) \
1137 void CBNAME(const Type& a); \
1138 void base_##CBNAME(const Type& a);
1141 #define IMP_PYCALLBACK__constany(CLASS, PCLASS, CBNAME, Type) \
1142 void CLASS::CBNAME(const Type& a) { \
1143 bool doSave = wxPyRestoreThread(); \
1144 if (m_myInst.findCallback(#CBNAME)) { \
1145 PyObject* obj = wxPyConstructObject((void*)&a, #Type); \
1146 m_myInst.callCallback(Py_BuildValue("(O)", obj)); \
1150 PCLASS::CBNAME(a); \
1151 wxPySaveThread(doSave); \
1153 void CLASS::base_##CBNAME(const Type& a) { \
1154 PCLASS::CBNAME(a); \
1158 //---------------------------------------------------------------------------
1160 #define DEC_PYCALLBACK__any(CBNAME, Type) \
1161 void CBNAME(Type& a); \
1162 void base_##CBNAME(Type& a);
1165 #define IMP_PYCALLBACK__any(CLASS, PCLASS, CBNAME, Type) \
1166 void CLASS::CBNAME(Type& a) { \
1167 bool doSave = wxPyRestoreThread(); \
1168 if (m_myInst.findCallback(#CBNAME)) { \
1169 PyObject* obj = wxPyConstructObject((void*)&a, #Type); \
1170 m_myInst.callCallback(Py_BuildValue("(O)", obj)); \
1174 PCLASS::CBNAME(a); \
1175 wxPySaveThread(doSave); \
1177 void CLASS::base_##CBNAME(Type& a) { \
1178 PCLASS::CBNAME(a); \
1181 //---------------------------------------------------------------------------
1183 #define DEC_PYCALLBACK_bool_any(CBNAME, Type) \
1184 bool CBNAME(Type& a); \
1185 bool base_##CBNAME(Type& a);
1188 #define IMP_PYCALLBACK_bool_any(CLASS, PCLASS, CBNAME, Type) \
1189 bool CLASS::CBNAME(Type& a) { \
1191 bool doSave = wxPyRestoreThread(); \
1192 if (m_myInst.findCallback(#CBNAME)) { \
1193 PyObject* obj = wxPyConstructObject((void*)&a, #Type); \
1194 rv = m_myInst.callCallback(Py_BuildValue("(O)", obj)); \
1198 rv = PCLASS::CBNAME(a); \
1199 wxPySaveThread(doSave); \
1202 bool CLASS::base_##CBNAME(Type& a) { \
1203 return PCLASS::CBNAME(a); \
1206 //---------------------------------------------------------------------------