4efa244ecce73a445f93787850d09aa141ad8b7d
[wxWidgets.git] / wxPython / include / wx / wxPython / wxPython_int.h
1 ////////////////////////////////////////////////////////////////////////////
2 // Name: wxPython_int.h (int == internal)
3 // Purpose: Helper functions/classes for the wxPython extension module
4 // This header should only be inclued directly by those source
5 // modules included in the wx._core module. All others should
6 // include wx/wxPython/wxPython.h instead.
7 //
8 // Author: Robin Dunn
9 //
10 // Created: 1-July-1997
11 // RCS-ID: $Id$
12 // Copyright: (c) 1998 by Total Control Software
13 // Licence: wxWindows license
14 /////////////////////////////////////////////////////////////////////////////
15
16 #ifndef __wxp_helpers__
17 #define __wxp_helpers__
18
19 #include <wx/wx.h>
20
21 #include <wx/busyinfo.h>
22 #include <wx/caret.h>
23 #include <wx/choicebk.h>
24 #include <wx/clipbrd.h>
25 #include <wx/colordlg.h>
26 #include <wx/config.h>
27 #include <wx/cshelp.h>
28 #include <wx/dcmirror.h>
29 #include <wx/dcps.h>
30 #include <wx/dirctrl.h>
31 #include <wx/dirdlg.h>
32 #include <wx/numdlg.h>
33 #include <wx/dnd.h>
34 #include <wx/docview.h>
35 #include <wx/encconv.h>
36 #include <wx/fdrepdlg.h>
37 #include <wx/fileconf.h>
38 #include <wx/filesys.h>
39 #include <wx/fontdlg.h>
40 #include <wx/fs_inet.h>
41 #include <wx/fs_mem.h>
42 #include <wx/fs_zip.h>
43 #include <wx/gbsizer.h>
44 #include <wx/geometry.h>
45 #include <wx/htmllbox.h>
46 #include <wx/image.h>
47 #include <wx/imaglist.h>
48 #include <wx/intl.h>
49 #include <wx/laywin.h>
50 #include <wx/listbook.h>
51 #include <wx/minifram.h>
52 #include <wx/notebook.h>
53 #include <wx/print.h>
54 #include <wx/printdlg.h>
55 #include <wx/process.h>
56 #include <wx/progdlg.h>
57 #include <wx/sashwin.h>
58 #include <wx/spinbutt.h>
59 #include <wx/spinctrl.h>
60 #include <wx/splash.h>
61 #include <wx/splitter.h>
62 #include <wx/statline.h>
63 #include <wx/stream.h>
64 #include <wx/sysopt.h>
65 #include <wx/taskbar.h>
66 #include <wx/tglbtn.h>
67 #include <wx/tipwin.h>
68 #include <wx/toolbook.h>
69 #include <wx/tooltip.h>
70 #include <wx/treebook.h>
71 #include <wx/vlbox.h>
72 #include <wx/vscroll.h>
73 #include <wx/dateevt.h>
74 #include <wx/datectrl.h>
75 #include <wx/power.h>
76 #include <wx/hyperlink.h>
77 #include <wx/pickerbase.h>
78 #include <wx/clrpicker.h>
79 #include <wx/filepicker.h>
80 #include <wx/fontpicker.h>
81
82
83 #ifdef _MSC_VER
84 # pragma warning(disable:4800)
85 # pragma warning(disable:4190)
86 #endif
87
88 #ifdef __WXMAC__ // avoid a bug in Carbon headers
89 #define scalb scalbn
90 #endif
91
92 //---------------------------------------------------------------------------
93
94 #ifndef wxHAS_POWER_EVENTS
95 class wxPowerEvent : public wxEvent
96 {
97 public:
98 wxPowerEvent(wxEventType evtType) : wxEvent(wxID_NONE, evtType) {}
99 void Veto() {}
100 bool IsVetoed() const { return false; }
101 virtual wxEvent *Clone() const { return new wxPowerEvent(*this); }
102 };
103 #endif
104
105 //---------------------------------------------------------------------------
106 typedef unsigned char byte;
107 typedef unsigned char* buffer;
108
109 typedef wxPoint2DDouble wxPoint2D;
110 typedef wxRect2DDouble wxRect2D;
111
112 #ifndef SWIG_TYPE_TABLE
113 #define SWIG_TYPE_TABLE wxPython_type_table
114 #endif
115
116 #ifdef __WXGTK__
117 #define wxDEFAULT_STATUSBAR_STYLE wxST_SIZEGRIP|wxFULL_REPAINT_ON_RESIZE
118 #else
119 #define wxDEFAULT_STATUSBAR_STYLE wxST_SIZEGRIP
120 #endif
121
122
123 #ifndef wxPyUSE_EXPORTED_API
124
125 void __wxPyPreStart(PyObject*);
126 void __wxPyCleanup();
127 PyObject* __wxPySetDictionary(PyObject*, PyObject* args);
128
129 void wxSetDefaultPyEncoding(const char* encoding);
130 const char* wxGetDefaultPyEncoding();
131
132
133 void wxPyEventThunker(wxObject*, wxEvent& event);
134
135
136 bool wxPyCheckSwigType(const wxChar* className);
137 PyObject* wxPyConstructObject(void* ptr,
138 const wxChar* className,
139 int setThisOwn=0);
140 bool wxPyConvertSwigPtr(PyObject* obj, void **ptr,
141 const wxChar* className);
142 PyObject* wxPyMakeSwigPtr(void* ptr, const wxChar* classname);
143
144
145 PyObject* wx2PyString(const wxString& src);
146 wxString Py2wxString(PyObject* source);
147
148 PyObject* wxPyMake_wxObject(wxObject* source, bool setThisOwn, bool checkEvtHandler=true);
149 PyObject* wxPyMake_wxSizer(wxSizer* source, bool setThisOwn);
150 void wxPyPtrTypeMap_Add(const char* commonName, const char* ptrName);
151
152 PyObject* wxPy_ConvertList(wxListBase* list);
153 long wxPyGetWinHandle(wxWindow* win);
154
155 void wxPy_ReinitStockObjects(int pass);
156
157 bool wxPyInstance_Check(PyObject* obj);
158 bool wxPySwigInstance_Check(PyObject* obj);
159
160
161 #endif // wxPyUSE_EXPORTED_API
162 //---------------------------------------------------------------------------
163
164 // if we want to handle threads and Python threads are available...
165 #if defined(WXP_USE_THREAD) && defined(WITH_THREAD)
166 #define WXP_WITH_THREAD
167 #else // no Python threads...
168 #undef WXP_WITH_THREAD
169 #endif
170
171
172 // In Python 2.3 and later there are the PyGILState_* APIs that we can use for
173 // blocking threads when calling back into Python. Using them instead of my
174 // home-grown hacks greatly simplifies wxPyBeginBlockThreads and
175 // wxPyEndBlockThreads.
176 //
177 // Unfortunatly there is a bug somewhere when using these new APIs on Python
178 // 2.3. It manifests in Boa Constructor's debugger where it is unable to stop
179 // at breakpoints located in event handlers. I think that the cause may be
180 // something like the original PyThreadState for the main thread is not being
181 // restored for the callbacks, but I can't see where that could be
182 // happening... So we'll only activate this new change for Python 2.4+ :-(
183
184 #if PY_VERSION_HEX < 0x02040000
185 #define wxPyUSE_GIL_STATE 0
186 typedef bool wxPyBlock_t;
187 #else
188 #define wxPyUSE_GIL_STATE 1
189 typedef PyGILState_STATE wxPyBlock_t;
190 #endif
191
192
193 // Python 2.5 changes the type of some API parameter and return types. Using
194 // this typedef for versions < 2.5 will help with the transition...
195 #if PY_VERSION_HEX < 0x02050000
196 typedef int Py_ssize_t;
197 #endif
198
199
200 #ifndef wxPyUSE_EXPORTED_API
201
202 // For Python --> C++
203 PyThreadState* wxPyBeginAllowThreads();
204 void wxPyEndAllowThreads(PyThreadState* state);
205
206 // For C++ --> Python
207 wxPyBlock_t wxPyBeginBlockThreads();
208 void wxPyEndBlockThreads(wxPyBlock_t blocked);
209
210 #endif // wxPyUSE_EXPORTED_API
211
212
213 // A macro that will help to execute simple statments wrapped in
214 // StartBlock/EndBlockThreads calls
215 #define wxPyBLOCK_THREADS(stmt) \
216 { wxPyBlock_t blocked = wxPyBeginBlockThreads(); stmt; wxPyEndBlockThreads(blocked); }
217
218 // Raise the NotImplementedError exception (blocking threads)
219 #define wxPyRaiseNotImplemented() \
220 wxPyBLOCK_THREADS(PyErr_SetNone(PyExc_NotImplementedError))
221
222 // Raise any exception with a string value (blocking threads)
223 #define wxPyErr_SetString(err, str) \
224 wxPyBLOCK_THREADS(PyErr_SetString(err, str))
225
226
227 //---------------------------------------------------------------------------
228 // These are helpers used by the typemaps
229
230 #ifndef wxPyUSE_EXPORTED_API
231
232 wxString* wxString_in_helper(PyObject* source);
233
234 byte* byte_LIST_helper(PyObject* source);
235 int* int_LIST_helper(PyObject* source);
236 long* long_LIST_helper(PyObject* source);
237 char** string_LIST_helper(PyObject* source);
238 wxPoint* wxPoint_LIST_helper(PyObject* source, int* npoints);
239 wxPoint2D* wxPoint2D_LIST_helper(PyObject* source, size_t* npoints);
240 wxBitmap** wxBitmap_LIST_helper(PyObject* source);
241 wxString* wxString_LIST_helper(PyObject* source);
242 wxAcceleratorEntry* wxAcceleratorEntry_LIST_helper(PyObject* source);
243 wxPen** wxPen_LIST_helper(PyObject* source);
244
245 bool wxSize_helper(PyObject* source, wxSize** obj);
246 bool wxPoint_helper(PyObject* source, wxPoint** obj);
247 bool wxRealPoint_helper(PyObject* source, wxRealPoint** obj);
248 bool wxRect_helper(PyObject* source, wxRect** obj);
249 bool wxColour_helper(PyObject* source, wxColour** obj);
250 bool wxPoint2D_helper(PyObject* source, wxPoint2D** obj);
251 bool wxRect2D_helper(PyObject* source, wxRect2D** obj);
252
253
254 bool wxPySimple_typecheck(PyObject* source, const wxChar* classname, int seqLen);
255 bool wxColour_typecheck(PyObject* source);
256
257
258 // Other helpful stuff
259 bool wxPyCheckForApp();
260 bool wxPyTestDisplayAvailable();
261
262 bool wxPy2int_seq_helper(PyObject* source, int* i1, int* i2);
263 bool wxPy4int_seq_helper(PyObject* source, int* i1, int* i2, int* i3, int* i4);
264
265 PyObject* wxArrayString2PyList_helper(const wxArrayString& arr);
266 PyObject* wxArrayInt2PyList_helper(const wxArrayInt& arr);
267 PyObject* wxArrayDouble2PyList_helper(const wxArrayDouble& arr);
268
269 #endif // wxPyUSE_EXPORTED_API
270
271 //---------------------------------------------------------------------------
272
273 #if PYTHON_API_VERSION < 1009
274 #define PySequence_Fast_GET_ITEM(o, i) \
275 (PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i))
276 #endif
277
278 #define RETURN_NONE() { Py_INCREF(Py_None); return Py_None; }
279 #define DECLARE_DEF_STRING(name) static const wxString wxPy##name(wx##name)
280 #define DECLARE_DEF_STRING2(name,val) static const wxString wxPy##name(val)
281
282 //---------------------------------------------------------------------------
283
284 #ifndef wxPyUSE_EXPORTED_API
285
286 class wxPyCallback : public wxObject {
287 DECLARE_ABSTRACT_CLASS(wxPyCallback)
288 public:
289 wxPyCallback(PyObject* func);
290 wxPyCallback(const wxPyCallback& other);
291 ~wxPyCallback();
292
293 void EventThunker(wxEvent& event);
294
295 PyObject* m_func;
296 };
297
298 #endif // wxPyUSE_EXPORTED_API
299 //---------------------------------------------------------------------------
300 //---------------------------------------------------------------------------
301 // These Event classes can be derived from in Python and passed through the
302 // event system without loosing anything. They do this by keeping a reference
303 // to themselves and some special case handling in wxPyCallback::EventThunker.
304
305
306
307 class wxPyEvtSelfRef {
308 public:
309 wxPyEvtSelfRef();
310 ~wxPyEvtSelfRef();
311
312 void SetSelf(PyObject* self, bool clone=false);
313 PyObject* GetSelf() const;
314 bool GetCloned() const { return m_cloned; }
315
316 protected:
317 PyObject* m_self;
318 bool m_cloned;
319 };
320
321
322 class wxPyEvent : public wxEvent, public wxPyEvtSelfRef {
323 DECLARE_ABSTRACT_CLASS(wxPyEvent)
324 public:
325 wxPyEvent(int winid=0, wxEventType commandType = wxEVT_NULL);
326 wxPyEvent(const wxPyEvent& evt);
327 ~wxPyEvent();
328
329 virtual wxEvent* Clone() const { return new wxPyEvent(*this); }
330 };
331
332
333 class wxPyCommandEvent : public wxCommandEvent, public wxPyEvtSelfRef {
334 DECLARE_ABSTRACT_CLASS(wxPyCommandEvent)
335 public:
336 wxPyCommandEvent(wxEventType commandType = wxEVT_NULL, int id=0);
337 wxPyCommandEvent(const wxPyCommandEvent& evt);
338 ~wxPyCommandEvent();
339
340 virtual wxEvent* Clone() const { return new wxPyCommandEvent(*this); }
341 };
342
343
344
345 //----------------------------------------------------------------------
346 // Forward decalre a few things used in the exported API
347 class wxPyClientData;
348 class wxPyUserData;
349 class wxPyOORClientData;
350 class wxPyCBInputStream;
351
352 void wxPyClientData_dtor(wxPyClientData* self);
353 void wxPyUserData_dtor(wxPyUserData* self);
354 void wxPyOORClientData_dtor(wxPyOORClientData* self);
355 wxPyCBInputStream* wxPyCBInputStream_create(PyObject *py, bool block);
356 wxPyCBInputStream* wxPyCBInputStream_copy(wxPyCBInputStream* other);
357
358 //---------------------------------------------------------------------------
359 // Export a C API in a struct. Other modules will be able to load this from
360 // the wx.core module and will then have safe access to these functions, even if
361 // in another shared library.
362
363 class wxPyCallbackHelper;
364
365 struct wxPyCoreAPI {
366
367 bool (*p_wxPyCheckSwigType)(const wxChar* className);
368 PyObject* (*p_wxPyConstructObject)(void* ptr, const wxChar* className, int setThisOwn);
369 bool (*p_wxPyConvertSwigPtr)(PyObject* obj, void **ptr, const wxChar* className);
370 PyObject* (*p_wxPyMakeSwigPtr)(void* ptr, const wxChar* className);
371
372 PyThreadState* (*p_wxPyBeginAllowThreads)();
373 void (*p_wxPyEndAllowThreads)(PyThreadState* state);
374 wxPyBlock_t (*p_wxPyBeginBlockThreads)();
375 void (*p_wxPyEndBlockThreads)(wxPyBlock_t blocked);
376
377 PyObject* (*p_wxPy_ConvertList)(wxListBase* list);
378
379 wxString* (*p_wxString_in_helper)(PyObject* source);
380 wxString (*p_Py2wxString)(PyObject* source);
381 PyObject* (*p_wx2PyString)(const wxString& src);
382
383 byte* (*p_byte_LIST_helper)(PyObject* source);
384 int* (*p_int_LIST_helper)(PyObject* source);
385 long* (*p_long_LIST_helper)(PyObject* source);
386 char** (*p_string_LIST_helper)(PyObject* source);
387 wxPoint* (*p_wxPoint_LIST_helper)(PyObject* source, int* npoints);
388 wxBitmap** (*p_wxBitmap_LIST_helper)(PyObject* source);
389 wxString* (*p_wxString_LIST_helper)(PyObject* source);
390 wxAcceleratorEntry* (*p_wxAcceleratorEntry_LIST_helper)(PyObject* source);
391
392 bool (*p_wxSize_helper)(PyObject* source, wxSize** obj);
393 bool (*p_wxPoint_helper)(PyObject* source, wxPoint** obj);
394 bool (*p_wxRealPoint_helper)(PyObject* source, wxRealPoint** obj);
395 bool (*p_wxRect_helper)(PyObject* source, wxRect** obj);
396 bool (*p_wxColour_helper)(PyObject* source, wxColour** obj);
397 bool (*p_wxPoint2D_helper)(PyObject* source, wxPoint2D** obj);
398
399
400 bool (*p_wxPySimple_typecheck)(PyObject* source, const wxChar* classname, int seqLen);
401 bool (*p_wxColour_typecheck)(PyObject* source);
402
403 void (*p_wxPyCBH_setCallbackInfo)(wxPyCallbackHelper& cbh, PyObject* self, PyObject* klass, int incref);
404 bool (*p_wxPyCBH_findCallback)(const wxPyCallbackHelper& cbh, const char* name, bool setGuard);
405 int (*p_wxPyCBH_callCallback)(const wxPyCallbackHelper& cbh, PyObject* argTuple);
406 PyObject* (*p_wxPyCBH_callCallbackObj)(const wxPyCallbackHelper& cbh, PyObject* argTuple);
407 void (*p_wxPyCBH_delete)(wxPyCallbackHelper* cbh);
408
409 PyObject* (*p_wxPyMake_wxObject)(wxObject* source, bool setThisOwn, bool checkEvtHandler);
410 PyObject* (*p_wxPyMake_wxSizer)(wxSizer* source, bool setThisOwn);
411 void (*p_wxPyPtrTypeMap_Add)(const char* commonName, const char* ptrName);
412 bool (*p_wxPy2int_seq_helper)(PyObject* source, int* i1, int* i2);
413 bool (*p_wxPy4int_seq_helper)(PyObject* source, int* i1, int* i2, int* i3, int* i4);
414 PyObject* (*p_wxArrayString2PyList_helper)(const wxArrayString& arr);
415 PyObject* (*p_wxArrayInt2PyList_helper)(const wxArrayInt& arr);
416
417 void (*p_wxPyClientData_dtor)(wxPyClientData*);
418 void (*p_wxPyUserData_dtor)(wxPyUserData*);
419 void (*p_wxPyOORClientData_dtor)(wxPyOORClientData*);
420
421 wxPyCBInputStream* (*p_wxPyCBInputStream_create)(PyObject *py, bool block);
422 wxPyCBInputStream* (*p_wxPyCBInputStream_copy)(wxPyCBInputStream* other);
423
424 bool (*p_wxPyInstance_Check)(PyObject* obj);
425 bool (*p_wxPySwigInstance_Check)(PyObject* obj);
426
427 bool (*p_wxPyCheckForApp)();
428
429 // Add all new items at the end...
430 PyObject* (*p_wxArrayDoublePyList_helper)(const wxArrayDouble& arr);
431 wxPoint2D* (*p_wxPoint2D_LIST_helper)(PyObject* source, size_t* npoints);
432 bool (*p_wxRect2D_helper)(PyObject* source, wxRect2D** obj);
433
434 };
435
436
437 #ifdef wxPyUSE_EXPORTED_API
438 // Notice that this is static, not extern. This is by design, each module
439 // needs one, but doesn't have to use it.
440 static wxPyCoreAPI* wxPyCoreAPIPtr = NULL;
441 inline wxPyCoreAPI* wxPyGetCoreAPIPtr();
442 #endif // wxPyUSE_EXPORTED_API
443
444 //---------------------------------------------------------------------------
445
446 // A wxObject that holds a reference to a Python object
447 class wxPyUserData : public wxObject {
448 public:
449 wxPyUserData(PyObject* obj) {
450 m_obj = obj;
451 Py_INCREF(m_obj);
452 }
453
454 ~wxPyUserData() {
455 #ifdef wxPyUSE_EXPORTED_API
456 wxPyGetCoreAPIPtr()->p_wxPyUserData_dtor(this);
457 #else
458 wxPyUserData_dtor(this);
459 #endif
460 }
461 PyObject* m_obj;
462 };
463
464
465 // A wxClientData that holds a refernece to a Python object
466 class wxPyClientData : public wxClientData {
467 public:
468 wxPyClientData(PyObject* obj, bool incref=true) {
469 m_obj = obj;
470 m_incRef = incref;
471 if (incref)
472 Py_INCREF(m_obj);
473 }
474 ~wxPyClientData() {
475
476 #ifdef wxPyUSE_EXPORTED_API
477 wxPyGetCoreAPIPtr()->p_wxPyClientData_dtor(this);
478 #else
479 wxPyClientData_dtor(this);
480 #endif
481 }
482 PyObject* m_obj;
483 bool m_incRef;
484 };
485
486
487 // Just like wxPyClientData, except when this object is destroyed it does some
488 // OOR magic on the Python Object.
489 class wxPyOORClientData : public wxPyClientData {
490 public:
491 wxPyOORClientData(PyObject* obj, bool incref=true)
492 : wxPyClientData(obj, incref) {}
493 ~wxPyOORClientData() {
494
495 #ifdef wxPyUSE_EXPORTED_API
496 wxPyGetCoreAPIPtr()->p_wxPyOORClientData_dtor(this);
497 #else
498 wxPyOORClientData_dtor(this);
499 #endif
500 }
501 };
502
503
504 //---------------------------------------------------------------------------
505 // A wxImageHandler that can be derived from in Python.
506 //
507
508 class wxPyImageHandler: public wxImageHandler {
509 protected:
510 PyObject *m_self;
511
512 // used for interning method names as PyStrings
513 static PyObject* m_DoCanRead_Name;
514 static PyObject* m_GetImageCount_Name;
515 static PyObject* m_LoadFile_Name;
516 static PyObject* m_SaveFile_Name;
517
518 // converstion helpers
519 PyObject* py_InputStream(wxInputStream* stream);
520 PyObject* py_Image(wxImage* image);
521 PyObject* py_OutputStream(wxOutputStream* stream);
522
523 public:
524 wxPyImageHandler();
525 ~wxPyImageHandler();
526 void _SetSelf(PyObject *self);
527
528 virtual bool LoadFile(wxImage* image, wxInputStream& stream,
529 bool verbose=true, int index=-1 );
530 virtual bool SaveFile(wxImage* image, wxOutputStream& stream,
531 bool verbose=true );
532 virtual int GetImageCount(wxInputStream& stream );
533 virtual bool DoCanRead(wxInputStream &stream);
534 };
535
536
537 //---------------------------------------------------------------------------
538 // This class holds an instance of a Python Shadow Class object and assists
539 // with looking up and invoking Python callback methods from C++ virtual
540 // method redirections. For all classes which have virtuals which should be
541 // overridable in wxPython, a new subclass is created that contains a
542 // wxPyCallbackHelper.
543 //
544
545 class wxPyCallbackHelper {
546 public:
547 wxPyCallbackHelper(const wxPyCallbackHelper& other);
548
549 wxPyCallbackHelper() {
550 m_class = NULL;
551 m_self = NULL;
552 m_lastFound = NULL;
553 m_incRef = false;
554 }
555
556 ~wxPyCallbackHelper() {
557 #ifdef wxPyUSE_EXPORTED_API
558 wxPyGetCoreAPIPtr()->p_wxPyCBH_delete(this);
559 #else
560 wxPyCBH_delete(this);
561 #endif
562 }
563
564 void setSelf(PyObject* self, PyObject* klass, int incref=true);
565 bool findCallback(const char* name, bool setGuard=true) const;
566 int callCallback(PyObject* argTuple) const;
567 PyObject* callCallbackObj(PyObject* argTuple) const;
568 PyObject* GetLastFound() const { return m_lastFound; }
569
570 void setRecursionGuard(PyObject* method) const;
571 void clearRecursionGuard(PyObject* method) const;
572
573 private:
574 PyObject* m_self;
575 PyObject* m_class;
576 PyObject* m_lastFound;
577 int m_incRef;
578
579 friend void wxPyCBH_delete(wxPyCallbackHelper* cbh);
580 };
581
582
583 void wxPyCBH_setCallbackInfo(wxPyCallbackHelper& cbh, PyObject* self, PyObject* klass, int incref);
584 bool wxPyCBH_findCallback(const wxPyCallbackHelper& cbh, const char* name, bool setGuard=true);
585 int wxPyCBH_callCallback(const wxPyCallbackHelper& cbh, PyObject* argTuple);
586 PyObject* wxPyCBH_callCallbackObj(const wxPyCallbackHelper& cbh, PyObject* argTuple);
587 void wxPyCBH_delete(wxPyCallbackHelper* cbh);
588
589
590
591
592 //---------------------------------------------------------------------------
593
594 // This is used in C++ classes that need to be able to make callback to
595 // "overloaded" python methods
596
597 #define PYPRIVATE \
598 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref=1) { \
599 wxPyCBH_setCallbackInfo(m_myInst, self, _class, incref); \
600 } \
601 private: wxPyCallbackHelper m_myInst
602
603
604 //---------------------------------------------------------------------------
605 // The wxPythonApp class
606
607 enum {
608 wxPYAPP_ASSERT_SUPPRESS = 1,
609 wxPYAPP_ASSERT_EXCEPTION = 2,
610 wxPYAPP_ASSERT_DIALOG = 4,
611 wxPYAPP_ASSERT_LOG = 8
612 };
613
614 class wxPyApp: public wxApp
615 {
616 DECLARE_ABSTRACT_CLASS(wxPyApp)
617
618 public:
619 wxPyApp();
620 ~wxPyApp();
621 bool OnInit();
622 int MainLoop();
623
624 int GetAssertMode() { return m_assertMode; }
625 void SetAssertMode(int mode) { m_assertMode = mode; }
626
627 virtual bool OnInitGui();
628 virtual int OnExit();
629 #ifdef __WXDEBUG__
630 virtual void OnAssertFailure(const wxChar *file,
631 int line,
632 const wxChar *func,
633 const wxChar *cond,
634 const wxChar *msg);
635 #endif
636 virtual void ExitMainLoop();
637 // virtual int FilterEvent(wxEvent& event); // This one too????
638
639 // For catching Apple Events
640 virtual void MacOpenFile(const wxString &fileName);
641 virtual void MacPrintFile(const wxString &fileName);
642 virtual void MacNewFile();
643 virtual void MacReopenApp();
644
645 static bool GetMacSupportPCMenuShortcuts();
646 static long GetMacAboutMenuItemId();
647 static long GetMacPreferencesMenuItemId();
648 static long GetMacExitMenuItemId();
649 static wxString GetMacHelpMenuTitleName();
650
651 static void SetMacSupportPCMenuShortcuts(bool val);
652 static void SetMacAboutMenuItemId(long val);
653 static void SetMacPreferencesMenuItemId(long val);
654 static void SetMacExitMenuItemId(long val);
655 static void SetMacHelpMenuTitleName(const wxString& val);
656
657
658 void _BootstrapApp();
659
660 // implementation only
661 void SetStartupComplete(bool val) { m_startupComplete = val; };
662
663 PYPRIVATE;
664 int m_assertMode;
665 bool m_startupComplete;
666 };
667
668 extern wxPyApp *wxPythonApp;
669
670
671 //----------------------------------------------------------------------
672 // These macros are used to implement the virtual methods that should
673 // redirect to a Python method if one exists. The names designate the
674 // return type, if any, as well as any parameter types.
675 //---------------------------------------------------------------------------
676
677 #define DEC_PYCALLBACK__(CBNAME) \
678 void CBNAME()
679
680
681 #define IMP_PYCALLBACK__(CLASS, PCLASS, CBNAME) \
682 void CLASS::CBNAME() { \
683 bool found; \
684 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
685 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
686 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
687 wxPyEndBlockThreads(blocked); \
688 if (! found) \
689 PCLASS::CBNAME(); \
690 }
691
692 #define DEC_PYCALLBACK_VOID_(CBNAME) \
693 DEC_PYCALLBACK__(CBNAME)
694
695 #define IMP_PYCALLBACK_VOID_(CLASS, PCLASS, CBNAME) \
696 IMP_PYCALLBACK__(CLASS, PCLASS, CBNAME)
697
698 //---------------------------------------------------------------------------
699
700 #define DEC_PYCALLBACK_BOOL_INTINT(CBNAME) \
701 bool CBNAME(int a, int b)
702
703
704 #define IMP_PYCALLBACK_BOOL_INTINT(CLASS, PCLASS, CBNAME) \
705 bool CLASS::CBNAME(int a, int b) { \
706 bool rval=false, found; \
707 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
708 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
709 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
710 wxPyEndBlockThreads(blocked); \
711 if (! found) \
712 rval = PCLASS::CBNAME(a,b); \
713 return rval; \
714 }
715
716 //---------------------------------------------------------------------------
717
718 #define DEC_PYCALLBACK_VOID_INTINT(CBNAME) \
719 void CBNAME(int a, int b)
720
721
722 #define IMP_PYCALLBACK_VOID_INTINT(CLASS, PCLASS, CBNAME) \
723 void CLASS::CBNAME(int a, int b) { \
724 bool found; \
725 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
726 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
727 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
728 wxPyEndBlockThreads(blocked); \
729 if (! found) \
730 PCLASS::CBNAME(a,b); \
731 }
732
733 //---------------------------------------------------------------------------
734
735 #define DEC_PYCALLBACK_VOID_INT(CBNAME) \
736 void CBNAME(int a)
737
738
739 #define IMP_PYCALLBACK_VOID_INT(CLASS, PCLASS, CBNAME) \
740 void CLASS::CBNAME(int a) { \
741 bool found; \
742 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
743 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
744 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)",a)); \
745 wxPyEndBlockThreads(blocked); \
746 if (! found) \
747 PCLASS::CBNAME(a); \
748 }
749
750 //---------------------------------------------------------------------------
751
752 #define DEC_PYCALLBACK_VOID_INT4(CBNAME) \
753 void CBNAME(int a, int b, int c, int d)
754
755
756 #define IMP_PYCALLBACK_VOID_INT4(CLASS, PCLASS, CBNAME) \
757 void CLASS::CBNAME(int a, int b, int c, int d) { \
758 bool found; \
759 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
760 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
761 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiii)",a,b,c,d)); \
762 wxPyEndBlockThreads(blocked); \
763 if (! found) \
764 PCLASS::CBNAME(a,b,c,d); \
765 }
766
767 //---------------------------------------------------------------------------
768 #define DEC_PYCALLBACK_VOID_INT5(CBNAME) \
769 void CBNAME(int a, int b, int c, int d, int e)
770
771
772 #define IMP_PYCALLBACK_VOID_INT5(CLASS, PCLASS, CBNAME) \
773 void CLASS::CBNAME(int a, int b, int c, int d, int e) { \
774 bool found; \
775 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
776 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
777 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiiii)",a,b,c,d,e)); \
778 wxPyEndBlockThreads(blocked); \
779 if (! found) \
780 PCLASS::CBNAME(a,b,c,d,e); \
781 }
782
783 //---------------------------------------------------------------------------
784
785 #define DEC_PYCALLBACK_VOID_INTPINTP_const(CBNAME) \
786 void CBNAME(int* a, int* b) const
787
788
789 #define IMP_PYCALLBACK_VOID_INTPINTP_const(CLASS, PCLASS, CBNAME) \
790 void CLASS::CBNAME(int* a, int* b) const { \
791 const char* errmsg = #CBNAME " should return a 2-tuple of integers."; \
792 bool found; \
793 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
794 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
795 PyObject* ro; \
796 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
797 if (ro) { \
798 if (PySequence_Check(ro) && PyObject_Length(ro) == 2) { \
799 PyObject* o1 = PySequence_GetItem(ro, 0); \
800 PyObject* o2 = PySequence_GetItem(ro, 1); \
801 if (PyNumber_Check(o1) && PyNumber_Check(o2)) { \
802 *a = PyInt_AsLong(o1); *b = PyInt_AsLong(o2); \
803 } \
804 else \
805 PyErr_SetString(PyExc_TypeError, errmsg); \
806 Py_DECREF(o1); \
807 Py_DECREF(o2); \
808 } \
809 else { \
810 PyErr_SetString(PyExc_TypeError, errmsg); \
811 } \
812 Py_DECREF(ro); \
813 } \
814 } \
815 wxPyEndBlockThreads(blocked); \
816 if (! found) \
817 PCLASS::CBNAME(a,b); \
818 }
819
820 //---------------------------------------------------------------------------
821
822 #define DEC_PYCALLBACK_SIZE_const(CBNAME) \
823 wxSize CBNAME() const
824
825
826 #define IMP_PYCALLBACK_SIZE_const(CLASS, PCLASS, CBNAME) \
827 wxSize CLASS::CBNAME() const { \
828 const char* errmsg = #CBNAME " should return a 2-tuple of integers."; \
829 bool found; wxSize rval(0,0); \
830 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
831 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
832 PyObject* ro; \
833 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
834 if (ro) { \
835 if (PySequence_Check(ro) && PyObject_Length(ro) == 2) { \
836 PyObject* o1 = PySequence_GetItem(ro, 0); \
837 PyObject* o2 = PySequence_GetItem(ro, 1); \
838 if (PyNumber_Check(o1) && PyNumber_Check(o2)) { \
839 rval = wxSize(PyInt_AsLong(o1), PyInt_AsLong(o2)); \
840 } \
841 else \
842 PyErr_SetString(PyExc_TypeError, errmsg); \
843 Py_DECREF(o1); \
844 Py_DECREF(o2); \
845 } \
846 else { \
847 PyErr_SetString(PyExc_TypeError, errmsg); \
848 } \
849 Py_DECREF(ro); \
850 } \
851 } \
852 wxPyEndBlockThreads(blocked); \
853 if (! found) \
854 return PCLASS::CBNAME(); \
855 else \
856 return rval; \
857 }
858
859 //---------------------------------------------------------------------------
860
861 #define DEC_PYCALLBACK_BOOL_BOOL(CBNAME) \
862 bool CBNAME(bool a)
863
864
865 #define IMP_PYCALLBACK_BOOL_BOOL(CLASS, PCLASS, CBNAME) \
866 bool CLASS::CBNAME(bool a) { \
867 bool rval=false, found; \
868 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
869 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
870 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)",a));\
871 wxPyEndBlockThreads(blocked); \
872 if (! found) \
873 rval = PCLASS::CBNAME(a); \
874 return rval; \
875 }
876
877 //---------------------------------------------------------------------------
878
879 #define DEC_PYCALLBACK_BOOL_INT(CBNAME) \
880 bool CBNAME(int a)
881
882
883 #define IMP_PYCALLBACK_BOOL_INT(CLASS, PCLASS, CBNAME) \
884 bool CLASS::CBNAME(int a) { \
885 bool rval=false, found; \
886 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
887 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
888 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)",a));\
889 wxPyEndBlockThreads(blocked); \
890 if (! found) \
891 rval = PCLASS::CBNAME(a); \
892 return rval; \
893 }
894
895 //---------------------------------------------------------------------------
896
897 #define DEC_PYCALLBACK_BOOL_INT_pure(CBNAME) \
898 bool CBNAME(int a)
899
900
901 #define IMP_PYCALLBACK_BOOL_INT_pure(CLASS, PCLASS, CBNAME) \
902 bool CLASS::CBNAME(int a) { \
903 bool rval=false; \
904 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
905 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
906 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)",a)); \
907 else rval = false; \
908 wxPyEndBlockThreads(blocked); \
909 return rval; \
910 }
911
912
913 //---------------------------------------------------------------------------
914
915 #define DEC_PYCALLBACK_INT_WIN(CBNAME) \
916 int CBNAME(wxWindow* a)
917
918
919 #define IMP_PYCALLBACK_INT_WIN(CLASS, PCLASS, CBNAME) \
920 int CLASS::CBNAME(wxWindow* a) { \
921 int rval=0; \
922 bool found; \
923 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
924 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
925 PyObject* obj = wxPyMake_wxObject(a, false); \
926 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)",obj)); \
927 Py_DECREF(obj); \
928 } \
929 wxPyEndBlockThreads(blocked); \
930 if (! found) \
931 rval = PCLASS::CBNAME(a); \
932 return rval; \
933 }
934
935
936 //---------------------------------------------------------------------------
937
938 #define DEC_PYCALLBACK__DC(CBNAME) \
939 void CBNAME(wxDC& a)
940
941
942 #define IMP_PYCALLBACK__DC(CLASS, PCLASS, CBNAME) \
943 void CLASS::CBNAME(wxDC& a) { \
944 bool found; \
945 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
946 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
947 PyObject* obj = wxPyMake_wxObject(&a,false); \
948 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
949 Py_DECREF(obj); \
950 } \
951 wxPyEndBlockThreads(blocked); \
952 if (! found) \
953 PCLASS::CBNAME(a); \
954 }
955
956
957 //---------------------------------------------------------------------------
958
959 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
960 void CBNAME(wxDC& a, bool b)
961
962
963 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
964 void CLASS::CBNAME(wxDC& a, bool b) { \
965 bool found; \
966 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
967 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
968 PyObject* obj = wxPyMake_wxObject(&a,false); \
969 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, (int)b)); \
970 Py_DECREF(obj); \
971 } \
972 wxPyEndBlockThreads(blocked); \
973 if (! found) \
974 PCLASS::CBNAME(a, b); \
975 }
976
977 //---------------------------------------------------------------------------
978
979 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
980 void CBNAME(wxDC& a, bool b)
981
982
983 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
984 void CLASS::CBNAME(wxDC& a, bool b) { \
985 bool found; \
986 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
987 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
988 PyObject* obj = wxPyMake_wxObject(&a,false); \
989 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, (int)b)); \
990 Py_DECREF(obj); \
991 } \
992 wxPyEndBlockThreads(blocked); \
993 if (! found) \
994 PCLASS::CBNAME(a, b); \
995 }
996
997 //---------------------------------------------------------------------------
998
999 #define DEC_PYCALLBACK__2DBL(CBNAME) \
1000 void CBNAME(double a, double b)
1001
1002
1003 #define IMP_PYCALLBACK__2DBL(CLASS, PCLASS, CBNAME) \
1004 void CLASS::CBNAME(double a, double b) { \
1005 bool found; \
1006 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1007 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
1008 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(dd)",a,b)); \
1009 wxPyEndBlockThreads(blocked); \
1010 if (! found) \
1011 PCLASS::CBNAME(a, b); \
1012 }
1013
1014 //---------------------------------------------------------------------------
1015
1016 #define DEC_PYCALLBACK__2DBL2INT(CBNAME) \
1017 void CBNAME(double a, double b, int c, int d)
1018
1019
1020 #define IMP_PYCALLBACK__2DBL2INT(CLASS, PCLASS, CBNAME) \
1021 void CLASS::CBNAME(double a, double b, int c, int d) { \
1022 bool found; \
1023 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1024 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
1025 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ddii)", \
1026 a,b,c,d)); \
1027 wxPyEndBlockThreads(blocked); \
1028 if (! found) \
1029 PCLASS::CBNAME(a, b, c, d); \
1030 }
1031
1032 //---------------------------------------------------------------------------
1033
1034 #define DEC_PYCALLBACK__DC4DBLBOOL(CBNAME) \
1035 void CBNAME(wxDC& a, double b, double c, double d, double e, bool f)
1036
1037
1038 #define IMP_PYCALLBACK__DC4DBLBOOL(CLASS, PCLASS, CBNAME) \
1039 void CLASS::CBNAME(wxDC& a, double b, double c, double d, double e, bool f) { \
1040 bool found; \
1041 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1042 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1043 PyObject* obj = wxPyMake_wxObject(&a,false); \
1044 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oddddi)", obj, b, c, d, e, (int)f)); \
1045 Py_DECREF(obj); \
1046 } \
1047 wxPyEndBlockThreads(blocked); \
1048 if (! found) \
1049 PCLASS::CBNAME(a, b, c, d, e, f); \
1050 }
1051
1052 //---------------------------------------------------------------------------
1053
1054 #define DEC_PYCALLBACK_BOOL_DC4DBLBOOL(CBNAME) \
1055 bool CBNAME(wxDC& a, double b, double c, double d, double e, bool f)
1056
1057
1058 #define IMP_PYCALLBACK_BOOL_DC4DBLBOOL(CLASS, PCLASS, CBNAME) \
1059 bool CLASS::CBNAME(wxDC& a, double b, double c, double d, double e, bool f) { \
1060 bool found; \
1061 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1062 bool rval=false; \
1063 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1064 PyObject* obj = wxPyMake_wxObject(&a,false); \
1065 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oddddi)", obj, b, c, d, e, (int)f));\
1066 Py_DECREF(obj); \
1067 } \
1068 wxPyEndBlockThreads(blocked); \
1069 if (! found) \
1070 rval = PCLASS::CBNAME(a, b, c, d, e, f); \
1071 return rval; \
1072 }
1073
1074 //---------------------------------------------------------------------------
1075
1076 #define DEC_PYCALLBACK__BOOL2DBL2INT(CBNAME) \
1077 void CBNAME(bool a, double b, double c, int d, int e)
1078
1079
1080 #define IMP_PYCALLBACK__BOOL2DBL2INT(CLASS, PCLASS, CBNAME) \
1081 void CLASS::CBNAME(bool a, double b, double c, int d, int e) { \
1082 bool found; \
1083 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1084 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
1085 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iddii)", \
1086 (int)a,b,c,d,e)); \
1087 wxPyEndBlockThreads(blocked); \
1088 if (! found) \
1089 PCLASS::CBNAME(a, b, c, d, e); \
1090 }
1091
1092 //---------------------------------------------------------------------------
1093
1094 #define DEC_PYCALLBACK__DC4DBL(CBNAME) \
1095 void CBNAME(wxDC& a, double b, double c, double d, double e)
1096
1097
1098 #define IMP_PYCALLBACK__DC4DBL(CLASS, PCLASS, CBNAME) \
1099 void CLASS::CBNAME(wxDC& a, double b, double c, double d, double e) { \
1100 bool found; \
1101 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1102 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1103 PyObject* obj = wxPyMake_wxObject(&a,false); \
1104 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Odddd)", obj, b, c, d, e)); \
1105 Py_DECREF(obj); \
1106 } \
1107 wxPyEndBlockThreads(blocked); \
1108 if (! found) \
1109 PCLASS::CBNAME(a, b, c, d, e); \
1110 }
1111
1112 //---------------------------------------------------------------------------
1113
1114 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
1115 void CBNAME(wxDC& a, bool b)
1116
1117
1118 #define IMP_PYCALLBACK__DCBOOL(CLASS, PCLASS, CBNAME) \
1119 void CLASS::CBNAME(wxDC& a, bool b) { \
1120 bool found; \
1121 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1122 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1123 PyObject* obj = wxPyMake_wxObject(&a,false); \
1124 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, (int)b)); \
1125 Py_DECREF(obj); \
1126 } \
1127 wxPyEndBlockThreads(blocked); \
1128 if (! found) \
1129 PCLASS::CBNAME(a, b); \
1130 }
1131
1132 //---------------------------------------------------------------------------
1133
1134 #define DEC_PYCALLBACK__WXCPBOOL2DBL2INT(CBNAME) \
1135 void CBNAME(wxControlPoint* a, bool b, double c, double d, int e, int f)
1136
1137
1138 #define IMP_PYCALLBACK__WXCPBOOL2DBL2INT(CLASS, PCLASS, CBNAME) \
1139 void CLASS::CBNAME(wxControlPoint* a, bool b, double c, double d, \
1140 int e, int f) { \
1141 bool found; \
1142 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1143 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1144 PyObject* obj = wxPyMake_wxObject(a,false); \
1145 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oiddii)", obj, (int)b, c, d, e, f));\
1146 Py_DECREF(obj); \
1147 } \
1148 wxPyEndBlockThreads(blocked); \
1149 if (! found) \
1150 PCLASS::CBNAME(a, b, c, d, e, f); \
1151 }
1152
1153 //---------------------------------------------------------------------------
1154
1155 #define DEC_PYCALLBACK__WXCP2DBL2INT(CBNAME) \
1156 void CBNAME(wxControlPoint* a, double b, double c, int d, int e)
1157
1158
1159 #define IMP_PYCALLBACK__WXCP2DBL2INT(CLASS, PCLASS, CBNAME) \
1160 void CLASS::CBNAME(wxControlPoint* a, double b, double c, int d, int e) { \
1161 bool found; \
1162 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1163 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1164 PyObject* obj = wxPyMake_wxObject(a,false); \
1165 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oddii)", obj, b, c, d, e)); \
1166 Py_DECREF(obj); \
1167 } \
1168 wxPyEndBlockThreads(blocked); \
1169 if (! found) \
1170 PCLASS::CBNAME(a, b, c, d, e); \
1171 }
1172
1173 //---------------------------------------------------------------------------
1174
1175 #define DEC_PYCALLBACK__2DBLINT(CBNAME) \
1176 void CBNAME(double a, double b, int c)
1177
1178
1179 #define IMP_PYCALLBACK__2DBLINT(CLASS, PCLASS, CBNAME) \
1180 void CLASS::CBNAME(double a, double b, int c) { \
1181 bool found; \
1182 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1183 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
1184 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ddi)", a,b,c)); \
1185 wxPyEndBlockThreads(blocked); \
1186 if (! found) \
1187 PCLASS::CBNAME(a, b, c); \
1188 }
1189
1190 //---------------------------------------------------------------------------
1191
1192 #define DEC_PYCALLBACK__BOOL2DBLINT(CBNAME) \
1193 void CBNAME(bool a, double b, double c, int d)
1194
1195
1196 #define IMP_PYCALLBACK__BOOL2DBLINT(CLASS, PCLASS, CBNAME) \
1197 void CLASS::CBNAME(bool a, double b, double c, int d) { \
1198 bool found; \
1199 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1200 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
1201 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iddi)", (int)a,b,c,d));\
1202 wxPyEndBlockThreads(blocked); \
1203 if (! found) \
1204 PCLASS::CBNAME(a, b, c, d); \
1205 }
1206
1207 //---------------------------------------------------------------------------
1208 //---------------------------------------------------------------------------
1209
1210 #define DEC_PYCALLBACK__STRING(CBNAME) \
1211 void CBNAME(const wxString& a)
1212
1213 #define IMP_PYCALLBACK__STRING(CLASS, PCLASS, CBNAME) \
1214 void CLASS::CBNAME(const wxString& a) { \
1215 bool found; \
1216 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1217 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1218 PyObject* s = wx2PyString(a); \
1219 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", s)); \
1220 Py_DECREF(s); \
1221 } \
1222 wxPyEndBlockThreads(blocked); \
1223 if (! found) \
1224 PCLASS::CBNAME(a); \
1225 }
1226
1227 //---------------------------------------------------------------------------
1228
1229 #define DEC_PYCALLBACK_BOOL_STRING(CBNAME) \
1230 bool CBNAME(const wxString& a)
1231
1232 #define IMP_PYCALLBACK_BOOL_STRING(CLASS, PCLASS, CBNAME) \
1233 bool CLASS::CBNAME(const wxString& a) { \
1234 bool rval=false; \
1235 bool found; \
1236 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1237 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1238 PyObject* s = wx2PyString(a); \
1239 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", s)); \
1240 Py_DECREF(s); \
1241 } \
1242 wxPyEndBlockThreads(blocked); \
1243 if (! found) \
1244 rval = PCLASS::CBNAME(a); \
1245 return rval; \
1246 }
1247
1248 //---------------------------------------------------------------------------
1249
1250 #define DEC_PYCALLBACK_BOOL_STRING_pure(CBNAME) \
1251 bool CBNAME(const wxString& a)
1252
1253 #define IMP_PYCALLBACK_BOOL_STRING_pure(CLASS, PCLASS, CBNAME) \
1254 bool CLASS::CBNAME(const wxString& a) { \
1255 bool rval=false; \
1256 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1257 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1258 PyObject* s = wx2PyString(a); \
1259 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", s)); \
1260 Py_DECREF(s); \
1261 } \
1262 wxPyEndBlockThreads(blocked); \
1263 return rval; \
1264 } \
1265
1266 //---------------------------------------------------------------------------
1267
1268 #define DEC_PYCALLBACK_STRING_STRING_pure(CBNAME) \
1269 wxString CBNAME(const wxString& a)
1270
1271 #define IMP_PYCALLBACK_STRING_STRING_pure(CLASS, PCLASS, CBNAME) \
1272 wxString CLASS::CBNAME(const wxString& a) { \
1273 wxString rval; \
1274 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1275 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1276 PyObject* ro; \
1277 PyObject* s = wx2PyString(a); \
1278 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(O)", s)); \
1279 Py_DECREF(s); \
1280 if (ro) { \
1281 rval = Py2wxString(ro); \
1282 Py_DECREF(ro); \
1283 } \
1284 } \
1285 wxPyEndBlockThreads(blocked); \
1286 return rval; \
1287 } \
1288
1289 //---------------------------------------------------------------------------
1290
1291 #define DEC_PYCALLBACK_STRING_STRING(CBNAME) \
1292 wxString CBNAME(const wxString& a)
1293
1294 #define IMP_PYCALLBACK_STRING_STRING(CLASS, PCLASS, CBNAME) \
1295 wxString CLASS::CBNAME(const wxString& a) { \
1296 wxString rval; \
1297 bool found; \
1298 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1299 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1300 PyObject* ro; \
1301 PyObject* s = wx2PyString(a); \
1302 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(O)", s)); \
1303 Py_DECREF(s); \
1304 if (ro) { \
1305 rval = Py2wxString(ro); \
1306 Py_DECREF(ro); \
1307 } \
1308 } \
1309 wxPyEndBlockThreads(blocked); \
1310 if (! found) \
1311 rval = PCLASS::CBNAME(a); \
1312 return rval; \
1313 } \
1314
1315 //---------------------------------------------------------------------------
1316
1317 #define DEC_PYCALLBACK_STRING_STRINGINT_pure(CBNAME) \
1318 wxString CBNAME(const wxString& a,int b)
1319
1320 #define IMP_PYCALLBACK_STRING_STRINGINT_pure(CLASS, PCLASS, CBNAME) \
1321 wxString CLASS::CBNAME(const wxString& a,int b) { \
1322 wxString rval; \
1323 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1324 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1325 PyObject* ro; \
1326 PyObject* s = wx2PyString(a); \
1327 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(Oi)",s,b)); \
1328 Py_DECREF(s); \
1329 if (ro) { \
1330 rval = Py2wxString(ro); \
1331 Py_DECREF(ro); \
1332 } \
1333 } \
1334 wxPyEndBlockThreads(blocked); \
1335 return rval; \
1336 } \
1337
1338 //---------------------------------------------------------------------------
1339
1340 #define DEC_PYCALLBACK_BOOL_STRINGSTRING(CBNAME) \
1341 bool CBNAME(const wxString& a, const wxString& b)
1342
1343 #define IMP_PYCALLBACK_BOOL_STRINGSTRING(CLASS, PCLASS, CBNAME) \
1344 bool CLASS::CBNAME(const wxString& a, const wxString& b) { \
1345 bool rval=false; \
1346 bool found; \
1347 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1348 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1349 PyObject* s1 = wx2PyString(a); \
1350 PyObject* s2 = wx2PyString(b); \
1351 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)",s1,s2)); \
1352 Py_DECREF(s1); \
1353 Py_DECREF(s2); \
1354 } \
1355 wxPyEndBlockThreads(blocked); \
1356 if (! found) \
1357 rval = PCLASS::CBNAME(a, b); \
1358 return rval; \
1359 }
1360
1361 //---------------------------------------------------------------------------
1362
1363 #define DEC_PYCALLBACK_STRING_(CBNAME) \
1364 wxString CBNAME()
1365
1366 #define IMP_PYCALLBACK_STRING_(CLASS, PCLASS, CBNAME) \
1367 wxString CLASS::CBNAME() { \
1368 wxString rval; \
1369 bool found; \
1370 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1371 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1372 PyObject* ro; \
1373 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
1374 if (ro) { \
1375 rval = Py2wxString(ro); \
1376 Py_DECREF(ro); \
1377 } \
1378 } \
1379 wxPyEndBlockThreads(blocked); \
1380 if (! found) \
1381 rval = PCLASS::CBNAME(); \
1382 return rval; \
1383 }
1384
1385 //---------------------------------------------------------------------------
1386
1387 #define DEC_PYCALLBACK_STRING__const(CBNAME) \
1388 wxString CBNAME() const
1389
1390 #define IMP_PYCALLBACK_STRING__const(CLASS, PCLASS, CBNAME) \
1391 wxString CLASS::CBNAME() const { \
1392 wxString rval; \
1393 bool found; \
1394 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1395 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1396 PyObject* ro; \
1397 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
1398 if (ro) { \
1399 rval = Py2wxString(ro); \
1400 Py_DECREF(ro); \
1401 } \
1402 } \
1403 wxPyEndBlockThreads(blocked); \
1404 if (! found) \
1405 rval = PCLASS::CBNAME(); \
1406 return rval; \
1407 }
1408
1409 //---------------------------------------------------------------------------
1410
1411 #define DEC_PYCALLBACK_STRING__pure(CBNAME) \
1412 wxString CBNAME()
1413
1414 #define IMP_PYCALLBACK_STRING__pure(CLASS, PCLASS, CBNAME) \
1415 wxString CLASS::CBNAME() { \
1416 wxString rval; \
1417 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1418 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1419 PyObject* ro; \
1420 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
1421 if (ro) { \
1422 rval = Py2wxString(ro); \
1423 Py_DECREF(ro); \
1424 } \
1425 } \
1426 wxPyEndBlockThreads(blocked); \
1427 return rval; \
1428 }
1429
1430 //---------------------------------------------------------------------------
1431
1432 #define DEC_PYCALLBACK_STRING__constpure(CBNAME) \
1433 wxString CBNAME() const;
1434
1435 #define IMP_PYCALLBACK_STRING__constpure(CLASS, PCLASS, CBNAME) \
1436 wxString CLASS::CBNAME() const { \
1437 wxString rval; \
1438 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1439 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1440 PyObject* ro; \
1441 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
1442 if (ro) { \
1443 rval = Py2wxString(ro); \
1444 Py_DECREF(ro); \
1445 } \
1446 } \
1447 wxPyEndBlockThreads(blocked); \
1448 return rval; \
1449 }
1450
1451 //---------------------------------------------------------------------------
1452
1453 #define DEC_PYCALLBACK_BOOL_TAG_pure(CBNAME) \
1454 bool CBNAME(const wxHtmlTag& a)
1455
1456
1457 #define IMP_PYCALLBACK_BOOL_TAG_pure(CLASS, PCLASS, CBNAME) \
1458 bool CLASS::CBNAME(const wxHtmlTag& a) { \
1459 bool rval=false; \
1460 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1461 if (wxPyCBH_findCallback2(m_myInst, #CBNAME, false)) { \
1462 PyObject* obj = wxPyConstructObject((void*)&a, wxT("wxHtmlTag"), 0);\
1463 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
1464 Py_DECREF(obj); \
1465 } \
1466 wxPyEndBlockThreads(blocked); \
1467 return rval; \
1468 }
1469
1470 //---------------------------------------------------------------------------
1471
1472 #define DEC_PYCALLBACK__CELLINTINT(CBNAME) \
1473 void CBNAME(wxHtmlCell *cell, wxCoord x, wxCoord y)
1474
1475 #define IMP_PYCALLBACK__CELLINTINT(CLASS, PCLASS, CBNAME) \
1476 void CLASS::CBNAME(wxHtmlCell *cell, wxCoord x, wxCoord y) { \
1477 bool found; \
1478 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1479 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1480 PyObject* obj = wxPyMake_wxObject(cell, 0); \
1481 wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(Oii)",obj,x,y)); \
1482 Py_DECREF(obj); \
1483 } \
1484 wxPyEndBlockThreads(blocked); \
1485 if (! found) \
1486 PCLASS::CBNAME(cell, x, y); \
1487 }
1488
1489 //---------------------------------------------------------------------------
1490
1491 #define DEC_PYCALLBACK__COLOUR(CBNAME) \
1492 void CBNAME(const wxColour& c);
1493
1494 #define IMP_PYCALLBACK__COLOUR(CLASS, PCLASS, CBNAME) \
1495 void CLASS::CBNAME(const wxColour& c) { \
1496 bool found; \
1497 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1498 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1499 PyObject* obj = wxPyConstructObject((void*)&c, wxT("wxColour"), 0); \
1500 wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(O)",obj)); \
1501 Py_DECREF(obj); \
1502 } \
1503 wxPyEndBlockThreads(blocked); \
1504 if (! found) \
1505 PCLASS::CBNAME(c); \
1506 } \
1507
1508 //---------------------------------------------------------------------------
1509 #define DEC_PYCALLBACK__INTCOLOUR(CBNAME) \
1510 void CBNAME(int a, const wxColour& c);
1511
1512 #define IMP_PYCALLBACK__INTCOLOUR(CLASS, PCLASS, CBNAME) \
1513 void CLASS::CBNAME(int a, const wxColour& c) { \
1514 bool found; \
1515 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1516 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1517 PyObject* obj = wxPyConstructObject((void*)&c, wxT("wxColour"), 0); \
1518 wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iO)",a, obj)); \
1519 Py_DECREF(obj); \
1520 } \
1521 wxPyEndBlockThreads(blocked); \
1522 if (! found) \
1523 PCLASS::CBNAME(a, c); \
1524 } \
1525
1526 //---------------------------------------------------------------------------
1527
1528 #define DEC_PYCALLBACK__INTFONT(CBNAME) \
1529 void CBNAME(int a, const wxFont& c);
1530
1531 #define IMP_PYCALLBACK__INTFONT(CLASS, PCLASS, CBNAME) \
1532 void CLASS::CBNAME(int a, const wxFont& c) { \
1533 bool found; \
1534 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1535 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1536 PyObject* obj = wxPyConstructObject((void*)&c, wxT("wxFont"), 0); \
1537 wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iO)",a, obj)); \
1538 Py_DECREF(obj); \
1539 } \
1540 wxPyEndBlockThreads(blocked); \
1541 if (! found) \
1542 PCLASS::CBNAME(a, c); \
1543 } \
1544
1545 //---------------------------------------------------------------------------
1546
1547 #define DEC_PYCALLBACK__FONT(CBNAME) \
1548 void CBNAME(const wxFont& a);
1549
1550 #define IMP_PYCALLBACK__FONT(CLASS, PCLASS, CBNAME) \
1551 void CLASS::CBNAME(const wxFont& a) { \
1552 bool found; \
1553 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1554 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1555 PyObject* obj = wxPyConstructObject((void*)&a, wxT("wxFont"), 0); \
1556 wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(O)", obj)); \
1557 Py_DECREF(obj); \
1558 } \
1559 wxPyEndBlockThreads(blocked); \
1560 if (! found) \
1561 PCLASS::CBNAME(a); \
1562 } \
1563
1564 //---------------------------------------------------------------------------
1565
1566 #define DEC_PYCALLBACK_BOOL_CELLINTINTME(CBNAME) \
1567 bool CBNAME(wxHtmlCell *cell, wxCoord x, wxCoord y, const wxMouseEvent& e)
1568
1569 #define IMP_PYCALLBACK_BOOL_CELLINTINTME(CLASS, PCLASS, CBNAME) \
1570 bool CLASS::CBNAME(wxHtmlCell *cell, wxCoord x, wxCoord y, const wxMouseEvent& e) { \
1571 bool rval=false, found; \
1572 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1573 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1574 PyObject* obj = wxPyMake_wxObject(cell, 0); \
1575 PyObject* o2 = wxPyConstructObject((void*)&e, wxT("wxMouseEvent"), 0); \
1576 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OiiO)",obj,x,y,o2)); \
1577 Py_DECREF(obj); \
1578 Py_DECREF(o2); \
1579 } \
1580 wxPyEndBlockThreads(blocked); \
1581 if (! found) \
1582 rval = PCLASS::CBNAME(cell, x, y, e); \
1583 return rval; \
1584 }
1585
1586
1587 //---------------------------------------------------------------------------
1588
1589 #define DEC_PYCALLBACK___pure(CBNAME) \
1590 void CBNAME()
1591
1592
1593 #define IMP_PYCALLBACK___pure(CLASS, PCLASS, CBNAME) \
1594 void CLASS::CBNAME() { \
1595 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1596 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
1597 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
1598 wxPyEndBlockThreads(blocked); \
1599 }
1600
1601 //---------------------------------------------------------------------------
1602
1603 #define DEC_PYCALLBACK_wxSize__pure(CBNAME) \
1604 wxSize CBNAME()
1605
1606
1607 #define IMP_PYCALLBACK_wxSize__pure(CLASS, PCLASS, CBNAME) \
1608 wxSize CLASS::CBNAME() { \
1609 const char* errmsg = #CBNAME " should return a 2-tuple of integers or a wxSize object."; \
1610 wxSize rval(0,0); \
1611 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1612 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1613 PyObject* ro; \
1614 wxSize* ptr; \
1615 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
1616 if (ro) { \
1617 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxSize"))) \
1618 rval = *ptr; \
1619 else if (PySequence_Check(ro) && PyObject_Length(ro) == 2) { \
1620 PyErr_Clear(); \
1621 PyObject* o1 = PySequence_GetItem(ro, 0); \
1622 PyObject* o2 = PySequence_GetItem(ro, 1); \
1623 if (PyNumber_Check(o1) && PyNumber_Check(o2)) \
1624 rval = wxSize(PyInt_AsLong(o1), PyInt_AsLong(o2)); \
1625 else \
1626 PyErr_SetString(PyExc_TypeError, errmsg); \
1627 Py_DECREF(o1); \
1628 Py_DECREF(o2); \
1629 } \
1630 else { \
1631 PyErr_SetString(PyExc_TypeError, errmsg); \
1632 } \
1633 Py_DECREF(ro); \
1634 } \
1635 } \
1636 wxPyEndBlockThreads(blocked); \
1637 return rval; \
1638 }
1639
1640 //---------------------------------------------------------------------------
1641
1642 #define DEC_PYCALLBACK_BOOL_WXWIN(CBNAME) \
1643 bool CBNAME(wxWindow* a)
1644
1645
1646 #define IMP_PYCALLBACK_BOOL_WXWIN(CLASS, PCLASS, CBNAME) \
1647 bool CLASS::CBNAME(wxWindow* a) { \
1648 bool rval=false; \
1649 bool found; \
1650 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1651 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1652 PyObject* obj = wxPyMake_wxObject(a,false); \
1653 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
1654 Py_DECREF(obj); \
1655 } \
1656 wxPyEndBlockThreads(blocked); \
1657 if (! found) \
1658 rval = PCLASS::CBNAME(a); \
1659 return rval; \
1660 }
1661
1662 //---------------------------------------------------------------------------
1663
1664 #define DEC_PYCALLBACK_BOOL_WXWINDC(CBNAME) \
1665 bool CBNAME(wxWindow* a, wxDC& b)
1666
1667
1668 #define IMP_PYCALLBACK_BOOL_WXWINDC(CLASS, PCLASS, CBNAME) \
1669 bool CLASS::CBNAME(wxWindow* a, wxDC& b) { \
1670 bool rval=false; \
1671 bool found; \
1672 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1673 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1674 PyObject* win = wxPyMake_wxObject(a,false); \
1675 PyObject* dc = wxPyMake_wxObject(&b,false); \
1676 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", win, dc));\
1677 Py_DECREF(win); \
1678 Py_DECREF(dc); \
1679 } \
1680 wxPyEndBlockThreads(blocked); \
1681 if (! found) \
1682 rval = PCLASS::CBNAME(a, b); \
1683 return rval; \
1684 }
1685
1686 //---------------------------------------------------------------------------
1687
1688 #define DEC_PYCALLBACK_VOID_WXWINBASE(CBNAME) \
1689 void CBNAME(wxWindowBase* a)
1690
1691
1692 #define IMP_PYCALLBACK_VOID_WXWINBASE(CLASS, PCLASS, CBNAME) \
1693 void CLASS::CBNAME(wxWindowBase* a) { \
1694 bool found; \
1695 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1696 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1697 PyObject* obj = wxPyMake_wxObject(a,false); \
1698 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
1699 Py_DECREF(obj); \
1700 } \
1701 wxPyEndBlockThreads(blocked); \
1702 if (! found) \
1703 PCLASS::CBNAME(a); \
1704 }
1705
1706 //---------------------------------------------------------------------------
1707
1708 #define DEC_PYCALLBACK_BOOL_(CBNAME) \
1709 bool CBNAME()
1710
1711
1712 #define IMP_PYCALLBACK_BOOL_(CLASS, PCLASS, CBNAME) \
1713 bool CLASS::CBNAME() { \
1714 bool rval=false; \
1715 bool found; \
1716 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1717 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
1718 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
1719 wxPyEndBlockThreads(blocked); \
1720 if (! found) \
1721 rval = PCLASS::CBNAME(); \
1722 return rval; \
1723 }
1724
1725 //---------------------------------------------------------------------------
1726
1727 #define DEC_PYCALLBACK_BOOL_const(CBNAME) \
1728 bool CBNAME() const
1729
1730
1731 #define IMP_PYCALLBACK_BOOL_const(CLASS, PCLASS, CBNAME) \
1732 bool CLASS::CBNAME() const { \
1733 bool rval=false; \
1734 bool found; \
1735 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1736 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
1737 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
1738 wxPyEndBlockThreads(blocked); \
1739 if (! found) \
1740 rval = PCLASS::CBNAME(); \
1741 return rval; \
1742 }
1743
1744 //---------------------------------------------------------------------------
1745
1746 #define DEC_PYCALLBACK_DR_2WXCDR(CBNAME) \
1747 wxDragResult CBNAME(wxCoord x, wxCoord y, wxDragResult def)
1748
1749
1750 #define IMP_PYCALLBACK_DR_2WXCDR(CLASS, PCLASS, CBNAME) \
1751 wxDragResult CLASS::CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
1752 int rval=0; \
1753 bool found; \
1754 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1755 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
1756 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c));\
1757 wxPyEndBlockThreads(blocked); \
1758 if (! found) \
1759 rval = PCLASS::CBNAME(a, b, c); \
1760 return (wxDragResult)rval; \
1761 }
1762
1763 //---------------------------------------------------------------------------
1764
1765 #define DEC_PYCALLBACK_FSF_FSSTRING_pure(CBNAME) \
1766 wxFSFile* CBNAME(wxFileSystem& fs, const wxString& location)
1767
1768 #define IMP_PYCALLBACK_FSF_FSSTRING_pure(CLASS, PCLASS, CBNAME) \
1769 wxFSFile* CLASS::CBNAME(wxFileSystem& a,const wxString& b) { \
1770 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1771 wxFSFile* rval=0; \
1772 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1773 PyObject* ro; \
1774 PyObject* obj = wxPyMake_wxObject(&a,false); \
1775 PyObject* s = wx2PyString(b); \
1776 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OO)", \
1777 obj, s)); \
1778 if (ro) { \
1779 wxPyConvertSwigPtr(ro, (void **)&rval, wxT("wxFSFile")); \
1780 /* release ownership of the C++ wx.FSFile object. */ \
1781 PyObject_SetAttrString(ro, "thisown", Py_False); \
1782 Py_DECREF(ro); \
1783 } \
1784 Py_DECREF(obj); \
1785 Py_DECREF(s); \
1786 } \
1787 wxPyEndBlockThreads(blocked); \
1788 return rval; \
1789 };
1790
1791 //---------------------------------------------------------------------------
1792
1793 #define DEC_PYCALLBACK_BOOL_DR(CBNAME) \
1794 bool CBNAME(wxDragResult a)
1795
1796
1797 #define IMP_PYCALLBACK_BOOL_DR(CLASS, PCLASS, CBNAME) \
1798 bool CLASS::CBNAME(wxDragResult a) { \
1799 bool rval=false; \
1800 bool found; \
1801 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1802 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
1803 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)", a)); \
1804 wxPyEndBlockThreads(blocked); \
1805 if (! found) \
1806 rval = PCLASS::CBNAME(a); \
1807 return rval; \
1808 }
1809
1810 //---------------------------------------------------------------------------
1811
1812 #define DEC_PYCALLBACK_DR_2WXCDR_pure(CBNAME) \
1813 wxDragResult CBNAME(wxCoord x, wxCoord y, wxDragResult def)
1814
1815
1816 #define IMP_PYCALLBACK_DR_2WXCDR_pure(CLASS, PCLASS, CBNAME) \
1817 wxDragResult CLASS::CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
1818 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1819 int rval=0; \
1820 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
1821 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c));\
1822 wxPyEndBlockThreads(blocked); \
1823 return (wxDragResult)rval; \
1824 } \
1825
1826 //---------------------------------------------------------------------------
1827
1828 #define DEC_PYCALLBACK_BOOL_INTINTSTR_pure(CBNAME) \
1829 bool CBNAME(int a, int b, const wxString& c)
1830
1831 #define IMP_PYCALLBACK_BOOL_INTINTSTR_pure(CLASS, PCLASS, CBNAME) \
1832 bool CLASS::CBNAME(int a, int b, const wxString& c) { \
1833 bool rval=false; \
1834 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1835 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1836 PyObject* s = wx2PyString(c); \
1837 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,s));\
1838 Py_DECREF(s); \
1839 } \
1840 wxPyEndBlockThreads(blocked); \
1841 return rval; \
1842 } \
1843
1844 //---------------------------------------------------------------------------
1845
1846 #define DEC_PYCALLBACK_SIZET_(CBNAME) \
1847 size_t CBNAME()
1848
1849
1850 #define IMP_PYCALLBACK_SIZET_(CLASS, PCLASS, CBNAME) \
1851 size_t CLASS::CBNAME() { \
1852 size_t rval=0; \
1853 bool found; \
1854 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1855 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
1856 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
1857 wxPyEndBlockThreads(blocked); \
1858 if (! found) \
1859 rval = PCLASS::CBNAME(); \
1860 return rval; \
1861 }
1862
1863 //---------------------------------------------------------------------------
1864
1865 #define DEC_PYCALLBACK_SIZET__const(CBNAME) \
1866 size_t CBNAME() const
1867
1868
1869 #define IMP_PYCALLBACK_SIZET__const(CLASS, PCLASS, CBNAME) \
1870 size_t CLASS::CBNAME() const { \
1871 size_t rval=0; \
1872 bool found; \
1873 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1874 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
1875 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
1876 wxPyEndBlockThreads(blocked); \
1877 if (! found) \
1878 rval = PCLASS::CBNAME(); \
1879 return rval; \
1880 }
1881
1882 //---------------------------------------------------------------------------
1883
1884 #define DEC_PYCALLBACK_DATAFMT_SIZET(CBNAME) \
1885 wxDataFormat CBNAME(size_t a)
1886
1887
1888 #define IMP_PYCALLBACK_DATAFMT_SIZET(CLASS, PCLASS, CBNAME) \
1889 wxDataFormat CLASS::CBNAME(size_t a) { \
1890 wxDataFormat rval=0; \
1891 bool found; \
1892 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1893 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1894 PyObject* ro; \
1895 wxDataFormat* ptr; \
1896 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(i)", a)); \
1897 if (ro) { \
1898 if (wxPyCOnvertSwigPtr(ro, (void **)&ptr, wxT("wxDataFormat"))) \
1899 rval = *ptr; \
1900 Py_DECREF(ro); \
1901 } \
1902 } \
1903 wxPyEndBlockThreads(blocked); \
1904 if (! found) \
1905 rval = PCLASS::CBNAME(a); \
1906 return rval; \
1907 }
1908
1909 //---------------------------------------------------------------------------
1910
1911 #define DEC_PYCALLBACK__constany(CBNAME, Type) \
1912 void CBNAME(const Type& a)
1913
1914
1915 #define IMP_PYCALLBACK__constany(CLASS, PCLASS, CBNAME, Type) \
1916 void CLASS::CBNAME(const Type& a) { \
1917 bool found; \
1918 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1919 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1920 PyObject* obj = wxPyConstructObject((void*)&a, wxT(#Type), 0); \
1921 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
1922 Py_DECREF(obj); \
1923 } \
1924 wxPyEndBlockThreads(blocked); \
1925 if (! found) \
1926 PCLASS::CBNAME(a); \
1927 }
1928
1929
1930 //---------------------------------------------------------------------------
1931
1932 #define DEC_PYCALLBACK__any(CBNAME, Type) \
1933 void CBNAME(Type& a)
1934
1935
1936 #define IMP_PYCALLBACK__any(CLASS, PCLASS, CBNAME, Type) \
1937 void CLASS::CBNAME(Type& a) { \
1938 bool found; \
1939 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1940 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1941 PyObject* obj = wxPyConstructObject((void*)&a, wxT(#Type), 0); \
1942 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
1943 Py_DECREF(obj); \
1944 } \
1945 wxPyEndBlockThreads(blocked); \
1946 if (! found) \
1947 PCLASS::CBNAME(a); \
1948 }
1949
1950 //---------------------------------------------------------------------------
1951
1952 #define DEC_PYCALLBACK_bool_any(CBNAME, Type) \
1953 bool CBNAME(Type& a)
1954
1955
1956 #define IMP_PYCALLBACK_bool_any(CLASS, PCLASS, CBNAME, Type) \
1957 bool CLASS::CBNAME(Type& a) { \
1958 bool rv=false; \
1959 bool found; \
1960 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1961 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
1962 PyObject* obj = wxPyConstructObject((void*)&a, wxT(#Type), 0); \
1963 rv = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
1964 Py_DECREF(obj); \
1965 } \
1966 wxPyEndBlockThreads(blocked); \
1967 if (! found) \
1968 rv = PCLASS::CBNAME(a); \
1969 return rv; \
1970 }
1971
1972 //---------------------------------------------------------------------------
1973
1974 #define DEC_PYCALLBACK_bool_anypure(CBNAME, Type) \
1975 bool CBNAME(Type& a)
1976
1977
1978 #define IMP_PYCALLBACK_bool_anypure(CLASS, PCLASS, CBNAME, Type) \
1979 bool CLASS::CBNAME(Type& a) { \
1980 bool rv=false; \
1981 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
1982 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
1983 PyObject* obj = wxPyConstructObject((void*)&a, wxT(#Type), 0); \
1984 rv = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
1985 Py_DECREF(obj); \
1986 } \
1987 wxPyEndBlockThreads(blocked); \
1988 return rv; \
1989 } \
1990
1991 //---------------------------------------------------------------------------
1992
1993 #define DEC_PYCALLBACK_STRING_LONGLONG(CBNAME) \
1994 wxString CBNAME(long a, long b) const
1995
1996 #define IMP_PYCALLBACK_STRING_LONGLONG(CLASS, PCLASS, CBNAME) \
1997 wxString CLASS::CBNAME(long a, long b) const { \
1998 wxString rval; \
1999 bool found; \
2000 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2001 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
2002 PyObject* ro; \
2003 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ll)",a,b)); \
2004 if (ro) { \
2005 rval = Py2wxString(ro); \
2006 Py_DECREF(ro); \
2007 } \
2008 } \
2009 wxPyEndBlockThreads(blocked); \
2010 if (! found) \
2011 rval = PCLASS::CBNAME(a,b); \
2012 return rval; \
2013 }
2014
2015 //---------------------------------------------------------------------------
2016
2017 #define DEC_PYCALLBACK_INT_LONG(CBNAME) \
2018 int CBNAME(long a) const
2019
2020
2021 #define IMP_PYCALLBACK_INT_LONG(CLASS, PCLASS, CBNAME) \
2022 int CLASS::CBNAME(long a) const { \
2023 int rval=-1; \
2024 bool found; \
2025 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2026 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
2027 PyObject* ro; \
2028 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(l)",a)); \
2029 if (ro) { \
2030 rval = PyInt_AsLong(ro); \
2031 Py_DECREF(ro); \
2032 } \
2033 } \
2034 wxPyEndBlockThreads(blocked); \
2035 if (! found) \
2036 rval = PCLASS::CBNAME(a); \
2037 return rval; \
2038 }
2039
2040
2041 #define DEC_PYCALLBACK_INT_LONG_virtual(CBNAME) \
2042 int CBNAME(long a) const;
2043
2044
2045 #define IMP_PYCALLBACK_INT_LONG_virtual(CLASS, PCLASS, CBNAME) \
2046 int CLASS::CBNAME(long a) const { \
2047 int rval=-1; /* this rval is important for OnGetItemImage */ \
2048 bool found; \
2049 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2050 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
2051 PyObject* ro; \
2052 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(l)",a)); \
2053 if (ro) { \
2054 rval = PyInt_AsLong(ro); \
2055 Py_DECREF(ro); \
2056 } \
2057 } \
2058 wxPyEndBlockThreads(blocked); \
2059 return rval; \
2060 }
2061
2062
2063 //---------------------------------------------------------------------------
2064
2065 #define DEC_PYCALLBACK_INT_INT(CBNAME) \
2066 int CBNAME(int a)
2067
2068
2069 #define IMP_PYCALLBACK_INT_INT(CLASS, PCLASS, CBNAME) \
2070 int CLASS::CBNAME(int a) { \
2071 int rval=-1; \
2072 bool found; \
2073 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2074 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
2075 PyObject* ro; \
2076 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(i)",a)); \
2077 if (ro) { \
2078 rval = PyInt_AsLong(ro); \
2079 Py_DECREF(ro); \
2080 } \
2081 } \
2082 wxPyEndBlockThreads(blocked); \
2083 if (! found) \
2084 rval = PCLASS::CBNAME(a); \
2085 return rval; \
2086 }
2087
2088 //---------------------------------------------------------------------------
2089
2090 #define DEC_PYCALLBACK_INT_LONGLONG(CBNAME) \
2091 int CBNAME(long a, long b) const
2092
2093
2094 #define IMP_PYCALLBACK_INT_LONGLONG(CLASS, PCLASS, CBNAME) \
2095 int CLASS::CBNAME(long a, long b) const { \
2096 int rval=-1; \
2097 bool found; \
2098 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2099 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
2100 PyObject* ro; \
2101 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ll)",a,b)); \
2102 if (ro) { \
2103 rval = PyInt_AsLong(ro); \
2104 Py_DECREF(ro); \
2105 } \
2106 } \
2107 wxPyEndBlockThreads(blocked); \
2108 if (! found) \
2109 rval = PCLASS::CBNAME(a, b); \
2110 return rval; \
2111 }
2112
2113
2114 #define DEC_PYCALLBACK_INT_LONGLONG_virtual(CBNAME) \
2115 int CBNAME(long a, long b) const;
2116
2117
2118 #define IMP_PYCALLBACK_INT_LONGLONG_virtual(CLASS, PCLASS, CBNAME) \
2119 int CLASS::CBNAME(long a, long b) const { \
2120 int rval=-1; /* this rval is important for OnGetItemImage */ \
2121 bool found; \
2122 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2123 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
2124 PyObject* ro; \
2125 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ll)",a,b)); \
2126 if (ro) { \
2127 rval = PyInt_AsLong(ro); \
2128 Py_DECREF(ro); \
2129 } \
2130 } \
2131 wxPyEndBlockThreads(blocked); \
2132 return rval; \
2133 }
2134
2135
2136 //---------------------------------------------------------------------------
2137
2138 #define DEC_PYCALLBACK_LISTATTR_LONG(CBNAME) \
2139 wxListItemAttr* CBNAME(long a) const
2140
2141
2142 #define IMP_PYCALLBACK_LISTATTR_LONG(CLASS, PCLASS, CBNAME) \
2143 wxListItemAttr *CLASS::CBNAME(long a) const { \
2144 wxListItemAttr *rval = NULL; \
2145 bool found; \
2146 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2147 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
2148 PyObject* ro; \
2149 wxListItemAttr* ptr; \
2150 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(i)", a)); \
2151 if (ro) { \
2152 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxListItemAttr")))\
2153 rval = ptr; \
2154 Py_DECREF(ro); \
2155 } \
2156 } \
2157 wxPyEndBlockThreads(blocked); \
2158 if (! found) \
2159 rval = PCLASS::CBNAME(a); \
2160 return rval; \
2161 }
2162
2163 //---------------------------------------------------------------------------
2164
2165 #define DEC_PYCALLBACK_BOOL_ME(CBNAME) \
2166 bool CBNAME(wxMouseEvent& e)
2167
2168 #define IMP_PYCALLBACK_BOOL_ME(CLASS, PCLASS, CBNAME) \
2169 bool CLASS::CBNAME(wxMouseEvent& e) { \
2170 bool rval=false; \
2171 bool found; \
2172 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2173 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
2174 PyObject* ro; \
2175 PyObject* obj = wxPyConstructObject((void*)&e, wxT("wxMouseEvent"), 0); \
2176 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(O)",obj)); \
2177 if (ro) { \
2178 rval = PyInt_AsLong(ro); \
2179 Py_DECREF(ro); \
2180 } \
2181 Py_DECREF(obj); \
2182 } \
2183 wxPyEndBlockThreads(blocked); \
2184 if (! found) \
2185 return PCLASS::CBNAME(e); \
2186 return rval; \
2187 }
2188
2189 //---------------------------------------------------------------------------
2190
2191 #define DEC_PYCALLBACK_WIZPG__pure(CBNAME) \
2192 wxWizardPage* CBNAME() const
2193
2194 #define IMP_PYCALLBACK_WIZPG__pure(CLASS, PCLASS, CBNAME) \
2195 wxWizardPage* CLASS::CBNAME() const { \
2196 wxWizardPage* rv = NULL; \
2197 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2198 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
2199 PyObject* ro; \
2200 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
2201 if (ro) { \
2202 wxPyConvertSwigPtr(ro, (void **)&rv, wxT("wxWizardPage")); \
2203 Py_DECREF(ro); \
2204 } \
2205 } \
2206 wxPyEndBlockThreads(blocked); \
2207 return rv; \
2208 }
2209
2210 //---------------------------------------------------------------------------
2211
2212 #define DEC_PYCALLBACK_BITMAP__pure(CBNAME) \
2213 wxBitmap CBNAME() const
2214
2215 #define IMP_PYCALLBACK_BITMAP__pure(CLASS, PCLASS, CBNAME) \
2216 wxBitmap CLASS::CBNAME() const { \
2217 wxBitmap rv; \
2218 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2219 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
2220 PyObject* ro; \
2221 wxBitmap* ptr; \
2222 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
2223 if (ro) { \
2224 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxBitmap"))) \
2225 rv = *ptr; \
2226 Py_DECREF(ro); \
2227 } \
2228 } \
2229 wxPyEndBlockThreads(blocked); \
2230 return rv; \
2231 }
2232
2233 //---------------------------------------------------------------------------
2234
2235 #define DEC_PYCALLBACK_OBJECT__pure(CBNAME) \
2236 wxObject* CBNAME()
2237
2238 #define IMP_PYCALLBACK_OBJECT__pure(CLASS, PCLASS, CBNAME) \
2239 wxObject* CLASS::CBNAME() { \
2240 wxObject* rv = NULL; \
2241 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2242 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
2243 PyObject* ro; \
2244 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
2245 if (ro) { \
2246 wxPyConvertSwigPtr(ro, (void **)&rv, wxT("wxObject")); \
2247 Py_DECREF(ro); \
2248 } \
2249 } \
2250 wxPyEndBlockThreads(blocked); \
2251 return rv; \
2252 }
2253
2254 //---------------------------------------------------------------------------
2255
2256 #define DEC_PYCALLBACK_OBJECT_STRING_pure(CBNAME) \
2257 wxObject* CBNAME(const wxString& a)
2258
2259 #define IMP_PYCALLBACK_OBJECT_STRING_pure(CLASS, PCLASS, CBNAME) \
2260 wxObject* CLASS::CBNAME(const wxString& a) { \
2261 wxObject* rv = NULL; \
2262 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2263 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
2264 PyObject* so = wx2PyString(a); \
2265 PyObject* ro; \
2266 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(O)", so)); \
2267 if (ro) { \
2268 wxPyConvertSwigPtr(ro, (void **)&rv, wxT("wxObject")); \
2269 Py_DECREF(ro); \
2270 } \
2271 Py_DECREF(so); \
2272 } \
2273 wxPyEndBlockThreads(blocked); \
2274 return rv; \
2275 }
2276
2277 //---------------------------------------------------------------------------
2278
2279 #define DEC_PYCALLBACK_BOOL_NODE_pure(CBNAME) \
2280 bool CBNAME(wxXmlNode* a)
2281
2282
2283 #define IMP_PYCALLBACK_BOOL_NODE_pure(CLASS, PCLASS, CBNAME) \
2284 bool CLASS::CBNAME(wxXmlNode* a) { \
2285 bool rv=false; \
2286 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2287 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
2288 PyObject* obj = wxPyConstructObject((void*)a, wxT("wxXmlNode"), 0); \
2289 rv = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
2290 Py_DECREF(obj); \
2291 } \
2292 wxPyEndBlockThreads(blocked); \
2293 return rv; \
2294 } \
2295
2296 //---------------------------------------------------------------------------
2297
2298 #define DEC_PYCALLBACK_COORD_SIZET_constpure(CBNAME) \
2299 wxCoord CBNAME(size_t a) const
2300
2301
2302 #define IMP_PYCALLBACK_COORD_SIZET_constpure(CLASS, PCLASS, CBNAME) \
2303 wxCoord CLASS::CBNAME(size_t a) const { \
2304 wxCoord rval=0; \
2305 bool found; \
2306 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2307 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
2308 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)", a)); \
2309 } \
2310 wxPyEndBlockThreads(blocked); \
2311 return rval; \
2312 } \
2313
2314 //---------------------------------------------------------------------------
2315
2316 #define DEC_PYCALLBACK_VOID_SIZETSIZET_const(CBNAME) \
2317 void CBNAME(size_t a, size_t b) const
2318
2319
2320 #define IMP_PYCALLBACK_VOID_SIZETSIZET_const(CLASS, PCLASS, CBNAME) \
2321 void CLASS::CBNAME(size_t a, size_t b) const { \
2322 bool found; \
2323 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2324 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
2325 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
2326 wxPyEndBlockThreads(blocked); \
2327 if (! found) \
2328 PCLASS::CBNAME(a,b); \
2329 }
2330 //---------------------------------------------------------------------------
2331
2332 #define DEC_PYCALLBACK_COORD_const(CBNAME) \
2333 wxCoord CBNAME() const
2334
2335
2336 #define IMP_PYCALLBACK_COORD_const(CLASS, PCLASS, CBNAME) \
2337 wxCoord CLASS::CBNAME() const { \
2338 wxCoord rval=0; \
2339 bool found; \
2340 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2341 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
2342 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
2343 wxPyEndBlockThreads(blocked); \
2344 if (! found) \
2345 rval = PCLASS::CBNAME(); \
2346 return rval; \
2347 }
2348
2349 //---------------------------------------------------------------------------
2350
2351 #define DEC_PYCALLBACK__DCRECTSIZET_constpure(CBNAME) \
2352 void CBNAME(wxDC& a, const wxRect& b, size_t c) const;
2353
2354 #define IMP_PYCALLBACK__DCRECTSIZET_constpure(CLASS, PCLASS, CBNAME) \
2355 void CLASS::CBNAME(wxDC& a, const wxRect& b, size_t c) const { \
2356 bool found; \
2357 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2358 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
2359 PyObject* obj = wxPyMake_wxObject(&a,false); \
2360 PyObject* ro = wxPyConstructObject((void*)&b, wxT("wxRect"), 0); \
2361 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOi)", obj, ro, (int)c)); \
2362 Py_DECREF(obj); Py_DECREF(ro); \
2363 } \
2364 wxPyEndBlockThreads(blocked); \
2365 } \
2366
2367
2368
2369 #define DEC_PYCALLBACK__DCRECTSIZET_const(CBNAME) \
2370 void CBNAME(wxDC& a, const wxRect& b, size_t c) const
2371
2372 #define IMP_PYCALLBACK__DCRECTSIZET_const(CLASS, PCLASS, CBNAME) \
2373 void CLASS::CBNAME(wxDC& a, const wxRect& b, size_t c) const { \
2374 bool found; \
2375 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2376 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
2377 PyObject* obj = wxPyMake_wxObject(&a,false); \
2378 PyObject* ro = wxPyConstructObject((void*)&b, wxT("wxRect"), 0); \
2379 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOi)", obj, ro, (int)c)); \
2380 Py_DECREF(obj); Py_DECREF(ro); \
2381 } \
2382 wxPyEndBlockThreads(blocked); \
2383 if (! found) \
2384 PCLASS::CBNAME(a,b,c); \
2385 }
2386
2387
2388 //---------------------------------------------------------------------------
2389 // Same as the above set, but the wxRect is not const
2390
2391 #define DEC_PYCALLBACK__DCRECTSIZET2_constpure(CBNAME) \
2392 void CBNAME(wxDC& a, wxRect& b, size_t c) const;
2393
2394 #define IMP_PYCALLBACK__DCRECTSIZET2_constpure(CLASS, PCLASS, CBNAME) \
2395 void CLASS::CBNAME(wxDC& a, wxRect& b, size_t c) const { \
2396 bool found; \
2397 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2398 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
2399 PyObject* obj = wxPyMake_wxObject(&a,false); \
2400 PyObject* ro = wxPyConstructObject((void*)&b, wxT("wxRect"), 0); \
2401 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOi)", obj, ro, (int)c)); \
2402 Py_DECREF(obj); Py_DECREF(ro); \
2403 } \
2404 wxPyEndBlockThreads(blocked); \
2405 } \
2406
2407
2408
2409 #define DEC_PYCALLBACK__DCRECTSIZET2_const(CBNAME) \
2410 void CBNAME(wxDC& a, wxRect& b, size_t c) const
2411
2412 #define IMP_PYCALLBACK__DCRECTSIZET2_const(CLASS, PCLASS, CBNAME) \
2413 void CLASS::CBNAME(wxDC& a, wxRect& b, size_t c) const { \
2414 bool found; \
2415 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2416 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
2417 PyObject* obj = wxPyMake_wxObject(&a,false); \
2418 PyObject* ro = wxPyConstructObject((void*)&b, wxT("wxRect"), 0); \
2419 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOi)", obj, ro, (int)c)); \
2420 Py_DECREF(obj); Py_DECREF(ro); \
2421 } \
2422 wxPyEndBlockThreads(blocked); \
2423 if (! found) \
2424 PCLASS::CBNAME(a,b,c); \
2425 }
2426
2427 //---------------------------------------------------------------------------
2428
2429 #define DEC_PYCALLBACK_STRING_SIZET(CBNAME) \
2430 wxString CBNAME(size_t a) const
2431
2432 #define IMP_PYCALLBACK_STRING_SIZET(CLASS, PCLASS, CBNAME) \
2433 wxString CLASS::CBNAME(size_t a) const { \
2434 wxString rval; \
2435 bool found; \
2436 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2437 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
2438 PyObject* ro; \
2439 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(l)",a)); \
2440 if (ro) { \
2441 rval = Py2wxString(ro); \
2442 Py_DECREF(ro); \
2443 } \
2444 } \
2445 wxPyEndBlockThreads(blocked); \
2446 if (! found) \
2447 rval = PCLASS::CBNAME(a); \
2448 return rval; \
2449 }
2450
2451 //---------------------------------------------------------------------------
2452
2453 #define DEC_PYCALLBACK_STRING_SIZET_pure(CBNAME) \
2454 wxString CBNAME(size_t a) const
2455
2456 #define IMP_PYCALLBACK_STRING_SIZET_pure(CLASS, PCLASS, CBNAME) \
2457 wxString CLASS::CBNAME(size_t a) const { \
2458 wxString rval; \
2459 bool found; \
2460 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2461 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
2462 PyObject* ro; \
2463 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(l)",a)); \
2464 if (ro) { \
2465 rval = Py2wxString(ro); \
2466 Py_DECREF(ro); \
2467 } \
2468 } \
2469 wxPyEndBlockThreads(blocked); \
2470 return rval; \
2471 } \
2472
2473 //---------------------------------------------------------------------------
2474
2475 #define DEC_PYCALLBACK_VIZATTR_(CBNAME) \
2476 wxVisualAttributes CBNAME() const
2477
2478
2479 #define IMP_PYCALLBACK_VIZATTR_(CLASS, PCLASS, CBNAME) \
2480 wxVisualAttributes CLASS::CBNAME() const { \
2481 wxVisualAttributes rval; \
2482 bool found; \
2483 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2484 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
2485 PyObject* ro; \
2486 wxVisualAttributes* ptr; \
2487 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
2488 if (ro) { \
2489 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxVisualAttributes"))) \
2490 rval = *ptr; \
2491 Py_DECREF(ro); \
2492 } \
2493 } \
2494 wxPyEndBlockThreads(blocked); \
2495 if (! found) \
2496 rval = PCLASS::CBNAME(); \
2497 return rval; \
2498 }
2499
2500 //---------------------------------------------------------------------------
2501
2502 #define DEC_PYCALLBACK_FONT_INT(CBNAME) \
2503 wxFont CBNAME(int a)
2504
2505 #define IMP_PYCALLBACK_FONT_INT(CLASS, PCLASS, CBNAME) \
2506 wxFont CLASS::CBNAME(int a) { \
2507 wxFont rv; \
2508 bool found; \
2509 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2510 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
2511 PyObject* ro; \
2512 wxFont* ptr; \
2513 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(i)", a)); \
2514 if (ro) { \
2515 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxFont"))) \
2516 rv = *ptr; \
2517 Py_DECREF(ro); \
2518 } \
2519 } \
2520 wxPyEndBlockThreads(blocked); \
2521 if (! found) \
2522 rv = PCLASS::CBNAME(a); \
2523 return rv; \
2524 }
2525
2526 //---------------------------------------------------------------------------
2527
2528 #define DEC_PYCALLBACK_COLOUR_INT(CBNAME) \
2529 wxColour CBNAME(int a)
2530
2531 #define IMP_PYCALLBACK_COLOUR_INT(CLASS, PCLASS, CBNAME) \
2532 wxColour CLASS::CBNAME(int a) { \
2533 wxColour rv; \
2534 bool found; \
2535 wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
2536 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
2537 PyObject* ro; \
2538 wxColour* ptr; \
2539 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(i)", a)); \
2540 if (ro) { \
2541 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxColour"))) \
2542 rv = *ptr; \
2543 Py_DECREF(ro); \
2544 } \
2545 } \
2546 wxPyEndBlockThreads(blocked); \
2547 if (! found) \
2548 rv = PCLASS::CBNAME(a); \
2549 return rv; \
2550 }
2551
2552 //---------------------------------------------------------------------------
2553
2554 #endif