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__
19 //----------------------------------------------------------------------
21 // if we want to handle threads and Python threads are available...
22 #if defined(WXP_USE_THREAD) && defined(WITH_THREAD)
24 #define WXP_WITH_THREAD
25 #define wxPy_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
26 #define wxPy_END_ALLOW_THREADS Py_END_ALLOW_THREADS
28 #else // no Python threads...
29 #undef WXP_WITH_THREAD
30 #define wxPy_BEGIN_ALLOW_THREADS
31 #define wxPy_END_ALLOW_THREADS
35 //---------------------------------------------------------------------------
37 #if defined(__WXMSW__)
38 # define HELPEREXPORT __declspec(dllexport)
43 typedef unsigned char byte
;
45 //----------------------------------------------------------------------
47 class wxPyApp
: public wxApp
54 //# void AfterMainLoop(void);
57 extern wxPyApp
*wxPythonApp
;
59 //----------------------------------------------------------------------
62 PyObject
* __wxStart(PyObject
*, PyObject
* args
);
65 extern PyObject
* wxPython_dict
;
66 PyObject
* __wxSetDictionary(PyObject
*, PyObject
* args
);
68 void wxPyEventThunker(wxObject
*, wxEvent
& event
);
70 HELPEREXPORT PyObject
* wxPyConstructObject(void* ptr
,
71 const char* className
,
73 HELPEREXPORT
bool wxPyRestoreThread();
74 HELPEREXPORT
void wxPySaveThread(bool doSave
);
75 HELPEREXPORT PyObject
* wxPy_ConvertList(wxListBase
* list
, const char* className
);
76 HELPEREXPORT
long wxPyGetWinHandle(wxWindow
* win
);
78 //----------------------------------------------------------------------
80 class wxPyUserData
: public wxObject
{
82 wxPyUserData(PyObject
* obj
) { m_obj
= obj
; Py_INCREF(m_obj
); }
84 bool doSave
= wxPyRestoreThread();
86 wxPySaveThread(doSave
);
91 //----------------------------------------------------------------------
92 // Handle wxInputStreams by Joerg Baumann
93 // See stream.i for implementations
95 // list class for return list of strings, e.g. readlines()
96 WX_DECLARE_LIST(wxString
, wxStringPtrList
);
99 // C++ class wxPyInputStream to act as base for python class wxInputStream
100 // Use it in python like a python file object
101 class wxPyInputStream
{
103 // underlying wxInputStream
107 wxPyInputStream(wxInputStream
* wxi_
) : wxi(wxi_
) {}
110 // python file object interface for input files (most of it)
114 wxString
* read(int size
=-1);
115 wxString
* readline(int size
=-1);
116 wxStringPtrList
* readlines(int sizehint
=-1);
117 void seek(int offset
, int whence
=0);
122 void truncate(int size=-1);
123 void write(wxString data);
124 void writelines(wxStringPtrList);
129 //----------------------------------------------------------------------
130 // These are helpers used by the typemaps
132 HELPEREXPORT byte
* byte_LIST_helper(PyObject
* source
);
133 HELPEREXPORT
int* int_LIST_helper(PyObject
* source
);
134 HELPEREXPORT
long* long_LIST_helper(PyObject
* source
);
135 HELPEREXPORT
char** string_LIST_helper(PyObject
* source
);
136 HELPEREXPORT wxPoint
* wxPoint_LIST_helper(PyObject
* source
);
137 HELPEREXPORT wxBitmap
** wxBitmap_LIST_helper(PyObject
* source
);
138 HELPEREXPORT wxString
* wxString_LIST_helper(PyObject
* source
);
139 HELPEREXPORT wxAcceleratorEntry
* wxAcceleratorEntry_LIST_helper(PyObject
* source
);
141 HELPEREXPORT
bool wxSize_helper(PyObject
* source
, wxSize
** obj
);
142 HELPEREXPORT
bool wxPoint_helper(PyObject
* source
, wxPoint
** obj
);
143 HELPEREXPORT
bool wxRealPoint_helper(PyObject
* source
, wxRealPoint
** obj
);
144 HELPEREXPORT
bool wxRect_helper(PyObject
* source
, wxRect
** obj
);
145 HELPEREXPORT
bool wxColour_helper(PyObject
* source
, wxColour
** obj
);
147 //----------------------------------------------------------------------
150 extern "C" void SWIG_MakePtr(char *, void *, char *);
151 extern "C" char *SWIG_GetPtr(char *, void **, char *);
152 extern "C" char *SWIG_GetPtrObj(PyObject
*obj
, void **ptr
, char *type
);
157 # pragma warning(disable:4800)
158 # pragma warning(disable:4190)
163 // Non-const versions to keep SWIG happy.
164 extern wxPoint wxPyDefaultPosition
;
165 extern wxSize wxPyDefaultSize
;
166 extern wxString wxPyEmptyStr
;
168 //----------------------------------------------------------------------
170 class wxPyCallback
: public wxObject
{
171 DECLARE_ABSTRACT_CLASS(wxPyCallback
);
173 wxPyCallback(PyObject
* func
);
174 wxPyCallback(const wxPyCallback
& other
);
177 void EventThunker(wxEvent
& event
);
182 //---------------------------------------------------------------------------
184 class wxPyTimer
: public wxTimer
{
186 wxPyTimer(PyObject
* callback
);
195 //---------------------------------------------------------------------------
200 //---------------------------------------------------------------------------
201 // This class holds an instance of a Python Shadow Class object and assists
202 // with looking up and invoking Python callback methods from C++ virtual
203 // method redirections. For all classes which have virtuals which should be
204 // overridable in wxPython, a new subclass is created that contains a
205 // wxPyCallbackHelper.
207 // TODO: This class should be combined with wxPyCallback defined above.
210 class HELPEREXPORT wxPyCallbackHelper
{
212 wxPyCallbackHelper();
213 ~wxPyCallbackHelper();
215 wxPyCallbackHelper(const wxPyCallbackHelper
& other
);
217 void setSelf(PyObject
* self
, PyObject
* _class
, int incref
=TRUE
);
219 bool findCallback(const wxString
& name
) const;
220 int callCallback(PyObject
* argTuple
) const;
221 PyObject
* callCallbackObj(PyObject
* argTuple
) const;
226 PyObject
* m_lastFound
;
231 //---------------------------------------------------------------------------
232 //---------------------------------------------------------------------------
233 // These Event classes can be derived from in Python and passed through the
234 // event system without loosing anything. They do this by keeping a reference
235 // to themselves and some special case handling in wxPyCallback::EventThunker.
238 class wxPyEvtSelfRef
{
243 void SetSelf(PyObject
* self
, bool clone
=FALSE
);
244 PyObject
* GetSelf() const;
252 class wxPyEvent
: public wxEvent
, public wxPyEvtSelfRef
{
253 DECLARE_DYNAMIC_CLASS(wxPyEvent
)
258 void CopyObject(wxObject
& dest
) const;
262 class wxPyCommandEvent
: public wxCommandEvent
, public wxPyEvtSelfRef
{
263 DECLARE_DYNAMIC_CLASS(wxPyCommandEvent
)
265 wxPyCommandEvent(wxEventType commandType
= wxEVT_NULL
, int id
=0);
268 void CopyObject(wxObject
& dest
) const;
272 //---------------------------------------------------------------------------
273 // These macros are used to implement the virtual methods that should
274 // redirect to a Python method if one exists. The names designate the
275 // return type, if any, as well as any parameter types.
276 //---------------------------------------------------------------------------
279 void _setSelf(PyObject* self, PyObject* _class, int incref=1) { \
280 m_myInst.setSelf(self, _class, incref); \
282 private: wxPyCallbackHelper m_myInst
284 //---------------------------------------------------------------------------
286 #define DEC_PYCALLBACK__(CBNAME) \
288 void base_##CBNAME();
291 #define IMP_PYCALLBACK__(CLASS, PCLASS, CBNAME) \
292 void CLASS::CBNAME() { \
293 bool doSave = wxPyRestoreThread(); \
294 if (m_myInst.findCallback(#CBNAME)) \
295 m_myInst.callCallback(Py_BuildValue("()")); \
298 wxPySaveThread(doSave); \
300 void CLASS::base_##CBNAME() { \
304 //---------------------------------------------------------------------------
306 #define DEC_PYCALLBACK_BOOL_INTINT(CBNAME) \
307 bool CBNAME(int a, int b); \
308 bool base_##CBNAME(int a, int b);
311 #define IMP_PYCALLBACK_BOOL_INTINT(CLASS, PCLASS, CBNAME) \
312 bool CLASS::CBNAME(int a, int b) { \
314 bool doSave = wxPyRestoreThread(); \
315 if (m_myInst.findCallback(#CBNAME)) \
316 rval = m_myInst.callCallback(Py_BuildValue("(ii)",a,b)); \
318 rval = PCLASS::CBNAME(a,b); \
319 wxPySaveThread(doSave); \
322 bool CLASS::base_##CBNAME(int a, int b) { \
323 return PCLASS::CBNAME(a,b); \
326 //---------------------------------------------------------------------------
328 #define DEC_PYCALLBACK_VOID_INTINT(CBNAME) \
329 void CBNAME(int a, int b); \
330 void base_##CBNAME(int a, int b);
333 #define IMP_PYCALLBACK_VOID_INTINT(CLASS, PCLASS, CBNAME) \
334 void CLASS::CBNAME(int a, int b) { \
335 bool doSave = wxPyRestoreThread(); \
336 if (m_myInst.findCallback(#CBNAME)) \
337 m_myInst.callCallback(Py_BuildValue("(ii)",a,b)); \
339 PCLASS::CBNAME(a,b); \
340 wxPySaveThread(doSave); \
342 void CLASS::base_##CBNAME(int a, int b) { \
343 PCLASS::CBNAME(a,b); \
346 //---------------------------------------------------------------------------
348 #define DEC_PYCALLBACK_BOOL_INT(CBNAME) \
349 bool CBNAME(int a); \
350 bool base_##CBNAME(int a);
353 #define IMP_PYCALLBACK_BOOL_INT(CLASS, PCLASS, CBNAME) \
354 bool CLASS::CBNAME(int a) { \
356 bool doSave = wxPyRestoreThread(); \
357 if (m_myInst.findCallback(#CBNAME)) \
358 rval = m_myInst.callCallback(Py_BuildValue("(i)",a)); \
360 rval = PCLASS::CBNAME(a); \
361 wxPySaveThread(doSave); \
364 bool CLASS::base_##CBNAME(int a) { \
365 return PCLASS::CBNAME(a); \
368 //---------------------------------------------------------------------------
370 #define DEC_PYCALLBACK_BOOL_INT_pure(CBNAME) \
374 #define IMP_PYCALLBACK_BOOL_INT_pure(CLASS, PCLASS, CBNAME) \
375 bool CLASS::CBNAME(int a) { \
377 bool doSave = wxPyRestoreThread(); \
378 if (m_myInst.findCallback(#CBNAME)) \
379 rval = m_myInst.callCallback(Py_BuildValue("(i)",a)); \
381 wxPySaveThread(doSave); \
386 //---------------------------------------------------------------------------
388 #define DEC_PYCALLBACK__DC(CBNAME) \
389 void CBNAME(wxDC& a); \
390 void base_##CBNAME(wxDC& a);
393 #define IMP_PYCALLBACK__DC(CLASS, PCLASS, CBNAME) \
394 void CLASS::CBNAME(wxDC& a) { \
395 bool doSave = wxPyRestoreThread(); \
396 if (m_myInst.findCallback(#CBNAME)) \
397 m_myInst.callCallback(Py_BuildValue("(O)", \
398 wxPyConstructObject(&a, "wxDC"))); \
401 wxPySaveThread(doSave); \
403 void CLASS::base_##CBNAME(wxDC& a) { \
409 //---------------------------------------------------------------------------
411 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
412 void CBNAME(wxDC& a, bool b); \
413 void base_##CBNAME(wxDC& a, bool b);
416 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
417 void CLASS::CBNAME(wxDC& a, bool b) { \
418 bool doSave = wxPyRestoreThread(); \
419 if (m_myInst.findCallback(#CBNAME)) \
420 m_myInst.callCallback(Py_BuildValue("(Oi)", \
421 wxPyConstructObject(&a, "wxDC"), (int)b)); \
423 PCLASS::CBNAME(a, b); \
424 wxPySaveThread(doSave); \
426 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
427 PCLASS::CBNAME(a, b); \
430 //---------------------------------------------------------------------------
432 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
433 void CBNAME(wxDC& a, bool b); \
434 void base_##CBNAME(wxDC& a, bool b);
437 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
438 void CLASS::CBNAME(wxDC& a, bool b) { \
439 bool doSave = wxPyRestoreThread(); \
440 if (m_myInst.findCallback(#CBNAME)) \
441 m_myInst.callCallback(Py_BuildValue("(Oi)", \
442 wxPyConstructObject(&a, "wxDC"), (int)b)); \
444 PCLASS::CBNAME(a, b); \
445 wxPySaveThread(doSave); \
447 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
448 PCLASS::CBNAME(a, b); \
451 //---------------------------------------------------------------------------
453 #define DEC_PYCALLBACK__2DBL(CBNAME) \
454 void CBNAME(double a, double b); \
455 void base_##CBNAME(double a, double b);
458 #define IMP_PYCALLBACK__2DBL(CLASS, PCLASS, CBNAME) \
459 void CLASS::CBNAME(double a, double b) { \
460 bool doSave = wxPyRestoreThread(); \
461 if (m_myInst.findCallback(#CBNAME)) \
462 m_myInst.callCallback(Py_BuildValue("(dd)",a,b)); \
464 PCLASS::CBNAME(a, b); \
465 wxPySaveThread(doSave); \
467 void CLASS::base_##CBNAME(double a, double b) { \
468 PCLASS::CBNAME(a, b); \
471 //---------------------------------------------------------------------------
473 #define DEC_PYCALLBACK__2DBL2INT(CBNAME) \
474 void CBNAME(double a, double b, int c, int d); \
475 void base_##CBNAME(double a, double b, int c, int d);
478 #define IMP_PYCALLBACK__2DBL2INT(CLASS, PCLASS, CBNAME) \
479 void CLASS::CBNAME(double a, double b, int c, int d) { \
480 bool doSave = wxPyRestoreThread(); \
481 if (m_myInst.findCallback(#CBNAME)) \
482 m_myInst.callCallback(Py_BuildValue("(ddii)", \
485 PCLASS::CBNAME(a, b, c, d); \
486 wxPySaveThread(doSave); \
488 void CLASS::base_##CBNAME(double a, double b, int c, int d) { \
489 PCLASS::CBNAME(a, b, c, d); \
492 //---------------------------------------------------------------------------
494 #define DEC_PYCALLBACK__DC4DBLBOOL(CBNAME) \
495 void CBNAME(wxDC& a, double b, double c, double d, double e, bool f); \
496 void base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f);
499 #define IMP_PYCALLBACK__DC4DBLBOOL(CLASS, PCLASS, CBNAME) \
500 void CLASS::CBNAME(wxDC& a, double b, double c, double d, double e, bool f) { \
501 bool doSave = wxPyRestoreThread(); \
502 if (m_myInst.findCallback(#CBNAME)) \
503 m_myInst.callCallback(Py_BuildValue("(Oddddi)", \
504 wxPyConstructObject(&a, "wxDC"), \
505 b, c, d, e, (int)f)); \
507 PCLASS::CBNAME(a, b, c, d, e, f); \
508 wxPySaveThread(doSave); \
510 void CLASS::base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f) {\
511 PCLASS::CBNAME(a, b, c, d, e, f); \
514 //---------------------------------------------------------------------------
516 #define DEC_PYCALLBACK_BOOL_DC4DBLBOOL(CBNAME) \
517 bool CBNAME(wxDC& a, double b, double c, double d, double e, bool f); \
518 bool base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f);
521 #define IMP_PYCALLBACK_BOOL_DC4DBLBOOL(CLASS, PCLASS, CBNAME) \
522 bool CLASS::CBNAME(wxDC& a, double b, double c, double d, double e, bool f) { \
523 bool doSave = wxPyRestoreThread(); \
525 if (m_myInst.findCallback(#CBNAME)) \
526 rval = m_myInst.callCallback(Py_BuildValue("(Oddddi)", \
527 wxPyConstructObject(&a, "wxDC"), \
528 b, c, d, e, (int)f)); \
530 rval = PCLASS::CBNAME(a, b, c, d, e, f); \
531 wxPySaveThread(doSave); \
534 bool CLASS::base_##CBNAME(wxDC& a, double b, double c, double d, double e, bool f) {\
535 return PCLASS::CBNAME(a, b, c, d, e, f); \
538 //---------------------------------------------------------------------------
540 #define DEC_PYCALLBACK__BOOL2DBL2INT(CBNAME) \
541 void CBNAME(bool a, double b, double c, int d, int e); \
542 void base_##CBNAME(bool a, double b, double c, int d, int e);
545 #define IMP_PYCALLBACK__BOOL2DBL2INT(CLASS, PCLASS, CBNAME) \
546 void CLASS::CBNAME(bool a, double b, double c, int d, int e) { \
547 bool doSave = wxPyRestoreThread(); \
548 if (m_myInst.findCallback(#CBNAME)) \
549 m_myInst.callCallback(Py_BuildValue("(idii)", \
552 PCLASS::CBNAME(a, b, c, d, e); \
553 wxPySaveThread(doSave); \
555 void CLASS::base_##CBNAME(bool a, double b, double c, int d, int e) { \
556 PCLASS::CBNAME(a, b, c, d, e); \
559 //---------------------------------------------------------------------------
561 #define DEC_PYCALLBACK__DC4DBL(CBNAME) \
562 void CBNAME(wxDC& a, double b, double c, double d, double e); \
563 void base_##CBNAME(wxDC& a, double b, double c, double d, double e);
566 #define IMP_PYCALLBACK__DC4DBL(CLASS, PCLASS, CBNAME) \
567 void CLASS::CBNAME(wxDC& a, double b, double c, double d, double e) { \
568 bool doSave = wxPyRestoreThread(); \
569 if (m_myInst.findCallback(#CBNAME)) \
570 m_myInst.callCallback(Py_BuildValue("(Odddd)", \
571 wxPyConstructObject(&a, "wxDC"), \
574 PCLASS::CBNAME(a, b, c, d, e); \
575 wxPySaveThread(doSave); \
577 void CLASS::base_##CBNAME(wxDC& a, double b, double c, double d, double e) {\
578 PCLASS::CBNAME(a, b, c, d, e); \
581 //---------------------------------------------------------------------------
583 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
584 void CBNAME(wxDC& a, bool b); \
585 void base_##CBNAME(wxDC& a, bool b);
588 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
589 void CLASS::CBNAME(wxDC& a, bool b) { \
590 bool doSave = wxPyRestoreThread(); \
591 if (m_myInst.findCallback(#CBNAME)) \
592 m_myInst.callCallback(Py_BuildValue("(Oi)", \
593 wxPyConstructObject(&a, "wxDC"), \
596 PCLASS::CBNAME(a, b); \
597 wxPySaveThread(doSave); \
599 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
600 PCLASS::CBNAME(a, b); \
603 //---------------------------------------------------------------------------
605 #define DEC_PYCALLBACK__WXCPBOOL2DBL2INT(CBNAME) \
606 void CBNAME(wxControlPoint* a, bool b, double c, double d, int e, int f); \
607 void base_##CBNAME(wxControlPoint* a, bool b, double c, double d, int e, int f);
610 #define IMP_PYCALLBACK__WXCPBOOL2DBL2INT(CLASS, PCLASS, CBNAME) \
611 void CLASS::CBNAME(wxControlPoint* a, bool b, double c, double d, \
613 bool doSave = wxPyRestoreThread(); \
614 if (m_myInst.findCallback(#CBNAME)) \
615 m_myInst.callCallback(Py_BuildValue("(Oiddii)", \
616 wxPyConstructObject(a, "wxPyControlPoint"), \
617 (int)b, c, d, e, f)); \
619 PCLASS::CBNAME(a, b, c, d, e, f); \
620 wxPySaveThread(doSave); \
622 void CLASS::base_##CBNAME(wxControlPoint* a, bool b, double c, double d, \
624 PCLASS::CBNAME(a, b, c, d, e, f); \
627 //---------------------------------------------------------------------------
629 #define DEC_PYCALLBACK__WXCP2DBL2INT(CBNAME) \
630 void CBNAME(wxControlPoint* a, double b, double c, int d, int e); \
631 void base_##CBNAME(wxControlPoint* a, double b, double c, int d, int e);
634 #define IMP_PYCALLBACK__WXCP2DBL2INT(CLASS, PCLASS, CBNAME) \
635 void CLASS::CBNAME(wxControlPoint* a, double b, double c, int d, int e) { \
636 bool doSave = wxPyRestoreThread(); \
637 if (m_myInst.findCallback(#CBNAME)) \
638 m_myInst.callCallback(Py_BuildValue("(Oddii)", \
639 wxPyConstructObject(a, "wxPyControlPoint"), \
642 PCLASS::CBNAME(a, b, c, d, e); \
643 wxPySaveThread(doSave); \
645 void CLASS::base_##CBNAME(wxControlPoint* a, double b, double c, \
647 PCLASS::CBNAME(a, b, c, d, e); \
650 //---------------------------------------------------------------------------
652 #define DEC_PYCALLBACK__2DBLINT(CBNAME) \
653 void CBNAME(double a, double b, int c); \
654 void base_##CBNAME(double a, double b, int c);
657 #define IMP_PYCALLBACK__2DBLINT(CLASS, PCLASS, CBNAME) \
658 void CLASS::CBNAME(double a, double b, int c) { \
659 bool doSave = wxPyRestoreThread(); \
660 if (m_myInst.findCallback(#CBNAME)) \
661 m_myInst.callCallback(Py_BuildValue("(ddi)", a,b,c)); \
663 PCLASS::CBNAME(a, b, c); \
664 wxPySaveThread(doSave); \
666 void CLASS::base_##CBNAME(double a, double b, int c) { \
667 PCLASS::CBNAME(a, b, c); \
670 //---------------------------------------------------------------------------
672 #define DEC_PYCALLBACK__BOOL2DBLINT(CBNAME) \
673 void CBNAME(bool a, double b, double c, int d); \
674 void base_##CBNAME(bool a, double b, double c, int d);
677 #define IMP_PYCALLBACK__BOOL2DBLINT(CLASS, PCLASS, CBNAME) \
678 void CLASS::CBNAME(bool a, double b, double c, int d) { \
679 bool doSave = wxPyRestoreThread(); \
680 if (m_myInst.findCallback(#CBNAME)) \
681 m_myInst.callCallback(Py_BuildValue("(iddi)", (int)a,b,c,d)); \
683 PCLASS::CBNAME(a, b, c, d); \
684 wxPySaveThread(doSave); \
686 void CLASS::base_##CBNAME(bool a, double b, double c, int d) { \
687 PCLASS::CBNAME(a, b, c, d); \
690 //---------------------------------------------------------------------------
691 //---------------------------------------------------------------------------
693 #define DEC_PYCALLBACK__STRING(CBNAME) \
694 void CBNAME(const wxString& a); \
695 void base_##CBNAME(const wxString& a);
698 #define IMP_PYCALLBACK__STRING(CLASS, PCLASS, CBNAME) \
699 void CLASS::CBNAME(const wxString& a) { \
700 bool doSave = wxPyRestoreThread(); \
701 if (m_myInst.findCallback(#CBNAME)) \
702 m_myInst.callCallback(Py_BuildValue("(s)", a.c_str())); \
705 wxPySaveThread(doSave); \
707 void CLASS::base_##CBNAME(const wxString& a) { \
711 //---------------------------------------------------------------------------
713 #define DEC_PYCALLBACK_BOOL_STRING(CBNAME) \
714 bool CBNAME(const wxString& a); \
715 bool base_##CBNAME(const wxString& a);
718 #define IMP_PYCALLBACK_BOOL_STRING(CLASS, PCLASS, CBNAME) \
719 bool CLASS::CBNAME(const wxString& a) { \
721 bool doSave = wxPyRestoreThread(); \
722 if (m_myInst.findCallback(#CBNAME)) \
723 rval = m_myInst.callCallback(Py_BuildValue("(s)", a.c_str())); \
725 rval = PCLASS::CBNAME(a); \
726 wxPySaveThread(doSave); \
729 bool CLASS::base_##CBNAME(const wxString& a) { \
730 return PCLASS::CBNAME(a); \
733 //---------------------------------------------------------------------------
735 #define DEC_PYCALLBACK_BOOL_STRING_pure(CBNAME) \
736 bool CBNAME(const wxString& a);
738 #define IMP_PYCALLBACK_BOOL_STRING_pure(CLASS, PCLASS, CBNAME) \
739 bool CLASS::CBNAME(const wxString& a) { \
741 bool doSave = wxPyRestoreThread(); \
742 if (m_myInst.findCallback(#CBNAME)) \
743 rval = m_myInst.callCallback(Py_BuildValue("(s)", a.c_str())); \
744 wxPySaveThread(doSave); \
748 //---------------------------------------------------------------------------
750 #define DEC_PYCALLBACK_STRING_STRING_pure(CBNAME) \
751 wxString CBNAME(const wxString& a); \
753 #define IMP_PYCALLBACK_STRING_STRING_pure(CLASS, PCLASS, CBNAME) \
754 wxString CLASS::CBNAME(const wxString& a) { \
756 bool doSave = wxPyRestoreThread(); \
757 if (m_myInst.findCallback(#CBNAME)) { \
759 ro = m_myInst.callCallbackObj(Py_BuildValue("(s)", a.c_str())); \
761 rval = PyString_AsString(PyObject_Str(ro)); \
765 wxPySaveThread(doSave); \
769 //---------------------------------------------------------------------------
771 #define DEC_PYCALLBACK_STRING_STRINGINT_pure(CBNAME) \
772 wxString CBNAME(const wxString& a,int b); \
774 #define IMP_PYCALLBACK_STRING_STRINGINT_pure(CLASS, PCLASS, CBNAME) \
775 wxString CLASS::CBNAME(const wxString& a,int b) { \
777 bool doSave = wxPyRestoreThread(); \
778 if (m_myInst.findCallback(#CBNAME)) { \
780 ro = m_myInst.callCallbackObj(Py_BuildValue("(si)", a.c_str(),b)); \
782 rval = PyString_AsString(PyObject_Str(ro)); \
786 wxPySaveThread(doSave); \
790 //---------------------------------------------------------------------------
792 #define DEC_PYCALLBACK_BOOL_STRINGSTRING(CBNAME) \
793 bool CBNAME(const wxString& a, const wxString& b); \
794 bool base_##CBNAME(const wxString& a, const wxString& b);
797 #define IMP_PYCALLBACK_BOOL_STRINGSTRING(CLASS, PCLASS, CBNAME) \
798 bool CLASS::CBNAME(const wxString& a, const wxString& b) { \
800 bool doSave = wxPyRestoreThread(); \
801 if (m_myInst.findCallback(#CBNAME)) \
802 rval = m_myInst.callCallback(Py_BuildValue("(ss)", \
803 a.c_str(), b.c_str())); \
805 rval = PCLASS::CBNAME(a, b); \
806 wxPySaveThread(doSave); \
809 bool CLASS::base_##CBNAME(const wxString& a, const wxString& b) { \
810 return PCLASS::CBNAME(a, b); \
813 //---------------------------------------------------------------------------
815 #define DEC_PYCALLBACK_STRING_(CBNAME) \
817 wxString base_##CBNAME();
820 #define IMP_PYCALLBACK_STRING_(CLASS, PCLASS, CBNAME) \
821 wxString CLASS::CBNAME() { \
823 bool doSave = wxPyRestoreThread(); \
824 if (m_myInst.findCallback(#CBNAME)) { \
826 ro = m_myInst.callCallbackObj(Py_BuildValue("()")); \
828 rval = PyString_AsString(PyObject_Str(ro)); \
833 rval = PCLASS::CBNAME(); \
834 wxPySaveThread(doSave); \
837 wxString CLASS::base_##CBNAME() { \
838 return PCLASS::CBNAME(); \
841 //---------------------------------------------------------------------------
843 #define DEC_PYCALLBACK_STRING__pure(CBNAME) \
847 #define IMP_PYCALLBACK_STRING__pure(CLASS, PCLASS, CBNAME) \
848 wxString CLASS::CBNAME() { \
850 bool doSave = wxPyRestoreThread(); \
851 if (m_myInst.findCallback(#CBNAME)) { \
853 ro = m_myInst.callCallbackObj(Py_BuildValue("()")); \
855 rval = PyString_AsString(PyObject_Str(ro)); \
859 wxPySaveThread(doSave); \
863 //---------------------------------------------------------------------------
865 #define DEC_PYCALLBACK_BOOL_TAG_pure(CBNAME) \
866 bool CBNAME(const wxHtmlTag& a); \
869 #define IMP_PYCALLBACK_BOOL_TAG_pure(CLASS, PCLASS, CBNAME) \
870 bool CLASS::CBNAME(const wxHtmlTag& a) { \
872 bool doSave = wxPyRestoreThread(); \
873 if (m_myInst.findCallback(#CBNAME)) \
874 rval = m_myInst.callCallback(Py_BuildValue("(O)", \
875 wxPyConstructObject((void*)&a,"wxHtmlTag"))); \
876 wxPySaveThread(doSave); \
880 //---------------------------------------------------------------------------
882 #define DEC_PYCALLBACK___pure(CBNAME) \
886 #define IMP_PYCALLBACK___pure(CLASS, PCLASS, CBNAME) \
887 void CLASS::CBNAME() { \
888 bool doSave = wxPyRestoreThread(); \
889 if (m_myInst.findCallback(#CBNAME)) \
890 m_myInst.callCallback(Py_BuildValue("()")); \
891 wxPySaveThread(doSave); \
894 //---------------------------------------------------------------------------
896 #define DEC_PYCALLBACK_wxSize__pure(CBNAME) \
900 #define IMP_PYCALLBACK_wxSize__pure(CLASS, PCLASS, CBNAME) \
901 wxSize CLASS::CBNAME() { \
903 bool doSave = wxPyRestoreThread(); \
904 if (m_myInst.findCallback(#CBNAME)) { \
907 ro = m_myInst.callCallbackObj(Py_BuildValue("()")); \
909 if (! SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p")) \
914 wxPySaveThread(doSave); \
918 //---------------------------------------------------------------------------
920 #define DEC_PYCALLBACK_BOOL_WXWIN(CBNAME) \
921 bool CBNAME(wxWindow* a); \
922 bool base_##CBNAME(wxWindow* a);
925 #define IMP_PYCALLBACK_BOOL_WXWIN(CLASS, PCLASS, CBNAME) \
926 bool CLASS::CBNAME(wxWindow* a) { \
928 bool doSave = wxPyRestoreThread(); \
929 if (m_myInst.findCallback(#CBNAME)) \
930 rval = m_myInst.callCallback(Py_BuildValue("(O)", \
931 wxPyConstructObject((void*)a,"wxWindow"))); \
933 rval = PCLASS::CBNAME(a); \
934 wxPySaveThread(doSave); \
937 bool CLASS::base_##CBNAME(wxWindow* a) { \
938 return PCLASS::CBNAME(a); \
941 //---------------------------------------------------------------------------
943 #define DEC_PYCALLBACK_BOOL_(CBNAME) \
945 bool base_##CBNAME();
948 #define IMP_PYCALLBACK_BOOL_(CLASS, PCLASS, CBNAME) \
949 bool CLASS::CBNAME() { \
951 bool doSave = wxPyRestoreThread(); \
952 if (m_myInst.findCallback(#CBNAME)) \
953 rval = m_myInst.callCallback(Py_BuildValue("()")); \
955 rval = PCLASS::CBNAME(); \
956 wxPySaveThread(doSave); \
959 bool CLASS::base_##CBNAME() { \
960 return PCLASS::CBNAME(); \
963 //---------------------------------------------------------------------------
965 #define DEC_PYCALLBACK_DR_2WXCDR(CBNAME) \
966 wxDragResult CBNAME(wxCoord x, wxCoord y, wxDragResult def); \
967 wxDragResult base_##CBNAME(wxCoord x, wxCoord y, wxDragResult def);
970 #define IMP_PYCALLBACK_DR_2WXCDR(CLASS, PCLASS, CBNAME) \
971 wxDragResult CLASS::CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
972 bool doSave = wxPyRestoreThread(); \
974 if (m_myInst.findCallback(#CBNAME)) \
975 rval = m_myInst.callCallback(Py_BuildValue("(iii)", a,b,c));\
977 rval = PCLASS::CBNAME(a, b, c); \
978 wxPySaveThread(doSave); \
979 return (wxDragResult)rval; \
981 wxDragResult CLASS::base_##CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
982 return PCLASS::CBNAME(a, b, c); \
985 //---------------------------------------------------------------------------
987 #define DEC_PYCALLBACK_FSF_FSSTRING_pure(CBNAME) \
988 wxFSFile* CBNAME(wxFileSystem& fs, const wxString& location); \
990 #define IMP_PYCALLBACK_FSF_FSSTRING_pure(CLASS, PCLASS, CBNAME) \
991 wxFSFile* CLASS::CBNAME(wxFileSystem& a,const wxString& b) { \
992 bool doSave = wxPyRestoreThread(); \
994 if (m_myInst.findCallback(#CBNAME)) { \
996 ro=m_myInst.callCallbackObj(Py_BuildValue("(Os)", \
997 wxPyConstructObject(&a, "(wxFileSystemC"),b.c_str())); \
999 SWIG_GetPtrObj(ro, (void **)&rval, "_wxFSFILE_p"); \
1003 wxPySaveThread(doSave); \
1007 //---------------------------------------------------------------------------
1009 #define DEC_PYCALLBACK_BOOL_DR(CBNAME) \
1010 bool CBNAME(wxDragResult a); \
1011 bool base_##CBNAME(wxDragResult a);
1014 #define IMP_PYCALLBACK_BOOL_DR(CLASS, PCLASS, CBNAME) \
1015 bool CLASS::CBNAME(wxDragResult a) { \
1016 bool doSave = wxPyRestoreThread(); \
1018 if (m_myInst.findCallback(#CBNAME)) \
1019 rval = m_myInst.callCallback(Py_BuildValue("(i)", a)); \
1021 rval = PCLASS::CBNAME(a); \
1022 wxPySaveThread(doSave); \
1025 bool CLASS::base_##CBNAME(wxDragResult a) { \
1026 return PCLASS::CBNAME(a); \
1029 //---------------------------------------------------------------------------
1031 #define DEC_PYCALLBACK_DR_2WXCDR_pure(CBNAME) \
1032 wxDragResult CBNAME(wxCoord x, wxCoord y, wxDragResult def);
1035 #define IMP_PYCALLBACK_DR_2WXCDR_pure(CLASS, PCLASS, CBNAME) \
1036 wxDragResult CLASS::CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
1037 bool doSave = wxPyRestoreThread(); \
1039 if (m_myInst.findCallback(#CBNAME)) \
1040 rval = m_myInst.callCallback(Py_BuildValue("(iii)", a,b,c));\
1041 wxPySaveThread(doSave); \
1042 return (wxDragResult)rval; \
1045 //---------------------------------------------------------------------------
1047 #define DEC_PYCALLBACK_BOOL_INTINTSTR_pure(CBNAME) \
1048 bool CBNAME(int a, int b, const wxString& c);
1051 #define IMP_PYCALLBACK_BOOL_INTINTSTR_pure(CLASS, PCLASS, CBNAME) \
1052 bool CLASS::CBNAME(int a, int b, const wxString& c) { \
1054 bool doSave = wxPyRestoreThread(); \
1055 if (m_myInst.findCallback(#CBNAME)) \
1056 rval = m_myInst.callCallback(Py_BuildValue("(iis)",a,b,c.c_str()));\
1057 wxPySaveThread(doSave); \
1061 //---------------------------------------------------------------------------
1063 #define DEC_PYCALLBACK_SIZET_(CBNAME) \
1065 size_t base_##CBNAME();
1068 #define IMP_PYCALLBACK_SIZET_(CLASS, PCLASS, CBNAME) \
1069 size_t CLASS::CBNAME() { \
1071 bool doSave = wxPyRestoreThread(); \
1072 if (m_myInst.findCallback(#CBNAME)) \
1073 rval = m_myInst.callCallback(Py_BuildValue("()")); \
1075 rval = PCLASS::CBNAME(); \
1076 wxPySaveThread(doSave); \
1079 size_t CLASS::base_##CBNAME() { \
1080 return PCLASS::CBNAME(); \
1083 //---------------------------------------------------------------------------
1085 #define DEC_PYCALLBACK_DATAFMT_SIZET(CBNAME) \
1086 wxDataFormat CBNAME(); \
1087 wxDataFormat base_##CBNAME();
1090 #define IMP_PYCALLBACK_DATAFMT_SIZET(CLASS, PCLASS, CBNAME) \
1091 wxDataFormat CLASS::CBNAME(size_t a) { \
1092 wxDataFormat rval; \
1093 bool doSave = wxPyRestoreThread(); \
1094 if (m_myInst.findCallback(#CBNAME)) { \
1096 wxDataFormat* ptr; \
1097 ro = m_myInst.callCallbackObj(Py_BuildValue("(i)", a)); \
1099 if (! SWIG_GetPtrObj(ro, (void **)&ptr, "_wxDataFormat_p")) \
1105 rval = PCLASS::CBNAME(a); \
1106 wxPySaveThread(doSave); \
1109 wxDataFormat CLASS::base_##CBNAME(size_t a) { \
1110 return PCLASS::CBNAME(a); \
1113 //---------------------------------------------------------------------------
1115 #define DEC_PYCALLBACK__constany(CBNAME, Type) \
1116 void CBNAME(const Type& a); \
1117 void base_##CBNAME(const Type& a);
1120 #define IMP_PYCALLBACK__constany(CLASS, PCLASS, CBNAME, Type) \
1121 void CLASS::CBNAME(const Type& a) { \
1122 bool doSave = wxPyRestoreThread(); \
1123 if (m_myInst.findCallback(#CBNAME)) \
1124 m_myInst.callCallback(Py_BuildValue("(O)", \
1125 wxPyConstructObject((void*)&a, #Type))); \
1127 PCLASS::CBNAME(a); \
1128 wxPySaveThread(doSave); \
1130 void CLASS::base_##CBNAME(const Type& a) { \
1131 PCLASS::CBNAME(a); \
1135 //---------------------------------------------------------------------------
1137 #define DEC_PYCALLBACK__any(CBNAME, Type) \
1138 void CBNAME(Type& a); \
1139 void base_##CBNAME(Type& a);
1142 #define IMP_PYCALLBACK__any(CLASS, PCLASS, CBNAME, Type) \
1143 void CLASS::CBNAME(Type& a) { \
1144 bool doSave = wxPyRestoreThread(); \
1145 if (m_myInst.findCallback(#CBNAME)) \
1146 m_myInst.callCallback(Py_BuildValue("(O)", \
1147 wxPyConstructObject(&a, #Type))); \
1149 PCLASS::CBNAME(a); \
1150 wxPySaveThread(doSave); \
1152 void CLASS::base_##CBNAME(Type& a) { \
1153 PCLASS::CBNAME(a); \
1156 //---------------------------------------------------------------------------
1158 #define DEC_PYCALLBACK_bool_any(CBNAME, Type) \
1159 bool CBNAME(Type& a); \
1160 bool base_##CBNAME(Type& a);
1163 #define IMP_PYCALLBACK_bool_any(CLASS, PCLASS, CBNAME, Type) \
1164 bool CLASS::CBNAME(Type& a) { \
1166 bool doSave = wxPyRestoreThread(); \
1167 if (m_myInst.findCallback(#CBNAME)) \
1168 rv = m_myInst.callCallback(Py_BuildValue("(O)", \
1169 wxPyConstructObject(&a, #Type))); \
1171 rv = PCLASS::CBNAME(a); \
1172 wxPySaveThread(doSave); \
1175 bool CLASS::base_##CBNAME(Type& a) { \
1176 return PCLASS::CBNAME(a); \
1179 //---------------------------------------------------------------------------