]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/helpers.h
The sticky tag as a bit too sticky... This check-in should now update
[wxWidgets.git] / wxPython / src / helpers.h
1 ////////////////////////////////////////////////////////////////////////////
2 // Name: helpers.h
3 // Purpose: Helper functions/classes for the wxPython extenaion module
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 7/1/97
8 // RCS-ID: $Id$
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef __wxp_helpers__
14 #define __wxp_helpers__
15
16 #include <wx/wx.h>
17
18
19 //----------------------------------------------------------------------
20
21 // if we want to handle threads and Python threads are available...
22 #if defined(WXP_USE_THREAD) && defined(WITH_THREAD)
23
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
27
28 #else // no Python threads...
29 #undef WXP_WITH_THREAD
30 #define wxPy_BEGIN_ALLOW_THREADS
31 #define wxPy_END_ALLOW_THREADS
32 #endif
33
34
35 //---------------------------------------------------------------------------
36
37 #if defined(__WXMSW__)
38 # define HELPEREXPORT __declspec(dllexport)
39 #else
40 # define HELPEREXPORT
41 #endif
42
43 typedef unsigned char byte;
44
45 //----------------------------------------------------------------------
46
47 class wxPyApp: public wxApp
48 {
49 public:
50 wxPyApp();
51 ~wxPyApp();
52 int MainLoop(void);
53 bool OnInit(void);
54 //# void AfterMainLoop(void);
55 };
56
57 extern wxPyApp *wxPythonApp;
58
59 //----------------------------------------------------------------------
60
61 void __wxPreStart();
62 PyObject* __wxStart(PyObject*, PyObject* args);
63 void __wxCleanup();
64
65 extern PyObject* wxPython_dict;
66 PyObject* __wxSetDictionary(PyObject*, PyObject* args);
67
68 void wxPyEventThunker(wxObject*, wxEvent& event);
69
70 HELPEREXPORT PyObject* wxPyConstructObject(void* ptr,
71 const char* className,
72 int setThisOwn=0);
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);
77
78 //----------------------------------------------------------------------
79
80 class wxPyUserData : public wxObject {
81 public:
82 wxPyUserData(PyObject* obj) { m_obj = obj; Py_INCREF(m_obj); }
83 ~wxPyUserData() {
84 bool doSave = wxPyRestoreThread();
85 Py_DECREF(m_obj);
86 wxPySaveThread(doSave);
87 }
88 PyObject* m_obj;
89 };
90
91 //----------------------------------------------------------------------
92 // Handle wxInputStreams by Joerg Baumann
93 // See stream.i for implementations
94
95 // list class for return list of strings, e.g. readlines()
96 WX_DECLARE_LIST(wxString, wxStringPtrList);
97
98
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{
102 public:
103 // underlying wxInputStream
104 wxInputStream* wxi;
105
106 public:
107 wxPyInputStream(wxInputStream* wxi_) : wxi(wxi_) {}
108 ~wxPyInputStream();
109
110 // python file object interface for input files (most of it)
111 void close();
112 void flush();
113 bool eof();
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);
118 int tell();
119 /*
120 bool isatty();
121 int fileno();
122 void truncate(int size=-1);
123 void write(wxString data);
124 void writelines(wxStringPtrList);
125 */
126 };
127
128
129 //----------------------------------------------------------------------
130 // These are helpers used by the typemaps
131
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);
140
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);
146
147 //----------------------------------------------------------------------
148
149 #ifndef SWIGCODE
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);
153 #endif
154
155
156 #ifdef _MSC_VER
157 # pragma warning(disable:4800)
158 # pragma warning(disable:4190)
159 #endif
160
161
162
163 // Non-const versions to keep SWIG happy.
164 extern wxPoint wxPyDefaultPosition;
165 extern wxSize wxPyDefaultSize;
166 extern wxString wxPyEmptyStr;
167
168 //----------------------------------------------------------------------
169
170 class wxPyCallback : public wxObject {
171 DECLARE_ABSTRACT_CLASS(wxPyCallback);
172 public:
173 wxPyCallback(PyObject* func);
174 wxPyCallback(const wxPyCallback& other);
175 ~wxPyCallback();
176
177 void EventThunker(wxEvent& event);
178
179 PyObject* m_func;
180 };
181
182 //---------------------------------------------------------------------------
183
184 class wxPyTimer : public wxTimer {
185 public:
186 wxPyTimer(PyObject* callback);
187 ~wxPyTimer();
188
189 void Notify();
190
191 private:
192 PyObject* func;
193 };
194
195 //---------------------------------------------------------------------------
196
197
198
199
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.
206 //
207 // TODO: This class should be combined with wxPyCallback defined above.
208 //
209
210 class HELPEREXPORT wxPyCallbackHelper {
211 public:
212 wxPyCallbackHelper();
213 ~wxPyCallbackHelper();
214
215 wxPyCallbackHelper(const wxPyCallbackHelper& other);
216
217 void setSelf(PyObject* self, PyObject* _class, int incref=TRUE);
218
219 bool findCallback(const wxString& name) const;
220 int callCallback(PyObject* argTuple) const;
221 PyObject* callCallbackObj(PyObject* argTuple) const;
222
223 private:
224 PyObject* m_self;
225 PyObject* m_class;
226 PyObject* m_lastFound;
227 int m_incRef;
228 };
229
230
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.
236
237
238 class wxPyEvtSelfRef {
239 public:
240 wxPyEvtSelfRef();
241 ~wxPyEvtSelfRef();
242
243 void SetSelf(PyObject* self, bool clone=FALSE);
244 PyObject* GetSelf() const;
245
246 protected:
247 PyObject* m_self;
248 bool m_cloned;
249 };
250
251
252 class wxPyEvent : public wxEvent, public wxPyEvtSelfRef {
253 DECLARE_DYNAMIC_CLASS(wxPyEvent)
254 public:
255 wxPyEvent(int id=0);
256 ~wxPyEvent();
257
258 void CopyObject(wxObject& dest) const;
259 };
260
261
262 class wxPyCommandEvent : public wxCommandEvent, public wxPyEvtSelfRef {
263 DECLARE_DYNAMIC_CLASS(wxPyCommandEvent)
264 public:
265 wxPyCommandEvent(wxEventType commandType = wxEVT_NULL, int id=0);
266 ~wxPyCommandEvent();
267
268 void CopyObject(wxObject& dest) const;
269 };
270
271
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 //---------------------------------------------------------------------------
277
278 #define PYPRIVATE \
279 void _setSelf(PyObject* self, PyObject* _class, int incref=1) { \
280 m_myInst.setSelf(self, _class, incref); \
281 } \
282 private: wxPyCallbackHelper m_myInst
283
284 //---------------------------------------------------------------------------
285
286 #define DEC_PYCALLBACK__(CBNAME) \
287 void CBNAME(); \
288 void base_##CBNAME();
289
290
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("()")); \
296 else \
297 PCLASS::CBNAME(); \
298 wxPySaveThread(doSave); \
299 } \
300 void CLASS::base_##CBNAME() { \
301 PCLASS::CBNAME(); \
302 }
303
304 //---------------------------------------------------------------------------
305
306 #define DEC_PYCALLBACK_BOOL_INTINT(CBNAME) \
307 bool CBNAME(int a, int b); \
308 bool base_##CBNAME(int a, int b);
309
310
311 #define IMP_PYCALLBACK_BOOL_INTINT(CLASS, PCLASS, CBNAME) \
312 bool CLASS::CBNAME(int a, int b) { \
313 bool rval; \
314 bool doSave = wxPyRestoreThread(); \
315 if (m_myInst.findCallback(#CBNAME)) \
316 rval = m_myInst.callCallback(Py_BuildValue("(ii)",a,b)); \
317 else \
318 rval = PCLASS::CBNAME(a,b); \
319 wxPySaveThread(doSave); \
320 return rval; \
321 } \
322 bool CLASS::base_##CBNAME(int a, int b) { \
323 return PCLASS::CBNAME(a,b); \
324 }
325
326 //---------------------------------------------------------------------------
327
328 #define DEC_PYCALLBACK_VOID_INTINT(CBNAME) \
329 void CBNAME(int a, int b); \
330 void base_##CBNAME(int a, int b);
331
332
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)); \
338 else \
339 PCLASS::CBNAME(a,b); \
340 wxPySaveThread(doSave); \
341 } \
342 void CLASS::base_##CBNAME(int a, int b) { \
343 PCLASS::CBNAME(a,b); \
344 }
345
346 //---------------------------------------------------------------------------
347
348 #define DEC_PYCALLBACK_BOOL_INT(CBNAME) \
349 bool CBNAME(int a); \
350 bool base_##CBNAME(int a);
351
352
353 #define IMP_PYCALLBACK_BOOL_INT(CLASS, PCLASS, CBNAME) \
354 bool CLASS::CBNAME(int a) { \
355 bool rval; \
356 bool doSave = wxPyRestoreThread(); \
357 if (m_myInst.findCallback(#CBNAME)) \
358 rval = m_myInst.callCallback(Py_BuildValue("(i)",a)); \
359 else \
360 rval = PCLASS::CBNAME(a); \
361 wxPySaveThread(doSave); \
362 return rval; \
363 } \
364 bool CLASS::base_##CBNAME(int a) { \
365 return PCLASS::CBNAME(a); \
366 }
367
368 //---------------------------------------------------------------------------
369
370 #define DEC_PYCALLBACK_BOOL_INT_pure(CBNAME) \
371 bool CBNAME(int a);
372
373
374 #define IMP_PYCALLBACK_BOOL_INT_pure(CLASS, PCLASS, CBNAME) \
375 bool CLASS::CBNAME(int a) { \
376 bool rval; \
377 bool doSave = wxPyRestoreThread(); \
378 if (m_myInst.findCallback(#CBNAME)) \
379 rval = m_myInst.callCallback(Py_BuildValue("(i)",a)); \
380 else rval = FALSE; \
381 wxPySaveThread(doSave); \
382 return rval; \
383 }
384
385
386 //---------------------------------------------------------------------------
387
388 #define DEC_PYCALLBACK__DC(CBNAME) \
389 void CBNAME(wxDC& a); \
390 void base_##CBNAME(wxDC& a);
391
392
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"))); \
399 else \
400 PCLASS::CBNAME(a); \
401 wxPySaveThread(doSave); \
402 } \
403 void CLASS::base_##CBNAME(wxDC& a) { \
404 PCLASS::CBNAME(a); \
405 }
406
407
408
409 //---------------------------------------------------------------------------
410
411 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
412 void CBNAME(wxDC& a, bool b); \
413 void base_##CBNAME(wxDC& a, bool b);
414
415
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)); \
422 else \
423 PCLASS::CBNAME(a, b); \
424 wxPySaveThread(doSave); \
425 } \
426 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
427 PCLASS::CBNAME(a, b); \
428 }
429
430 //---------------------------------------------------------------------------
431
432 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
433 void CBNAME(wxDC& a, bool b); \
434 void base_##CBNAME(wxDC& a, bool b);
435
436
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)); \
443 else \
444 PCLASS::CBNAME(a, b); \
445 wxPySaveThread(doSave); \
446 } \
447 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
448 PCLASS::CBNAME(a, b); \
449 }
450
451 //---------------------------------------------------------------------------
452
453 #define DEC_PYCALLBACK__2DBL(CBNAME) \
454 void CBNAME(double a, double b); \
455 void base_##CBNAME(double a, double b);
456
457
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)); \
463 else \
464 PCLASS::CBNAME(a, b); \
465 wxPySaveThread(doSave); \
466 } \
467 void CLASS::base_##CBNAME(double a, double b) { \
468 PCLASS::CBNAME(a, b); \
469 }
470
471 //---------------------------------------------------------------------------
472
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);
476
477
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)", \
483 a,b,c,d)); \
484 else \
485 PCLASS::CBNAME(a, b, c, d); \
486 wxPySaveThread(doSave); \
487 } \
488 void CLASS::base_##CBNAME(double a, double b, int c, int d) { \
489 PCLASS::CBNAME(a, b, c, d); \
490 }
491
492 //---------------------------------------------------------------------------
493
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);
497
498
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)); \
506 else \
507 PCLASS::CBNAME(a, b, c, d, e, f); \
508 wxPySaveThread(doSave); \
509 } \
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); \
512 }
513
514 //---------------------------------------------------------------------------
515
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);
519
520
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(); \
524 bool rval; \
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)); \
529 else \
530 rval = PCLASS::CBNAME(a, b, c, d, e, f); \
531 wxPySaveThread(doSave); \
532 return rval; \
533 } \
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); \
536 }
537
538 //---------------------------------------------------------------------------
539
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);
543
544
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)", \
550 (int)a,b,c,d,e)); \
551 else \
552 PCLASS::CBNAME(a, b, c, d, e); \
553 wxPySaveThread(doSave); \
554 } \
555 void CLASS::base_##CBNAME(bool a, double b, double c, int d, int e) { \
556 PCLASS::CBNAME(a, b, c, d, e); \
557 }
558
559 //---------------------------------------------------------------------------
560
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);
564
565
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"), \
572 b, c, d, e)); \
573 else \
574 PCLASS::CBNAME(a, b, c, d, e); \
575 wxPySaveThread(doSave); \
576 } \
577 void CLASS::base_##CBNAME(wxDC& a, double b, double c, double d, double e) {\
578 PCLASS::CBNAME(a, b, c, d, e); \
579 }
580
581 //---------------------------------------------------------------------------
582
583 #define DEC_PYCALLBACK__DCBOOL(CBNAME) \
584 void CBNAME(wxDC& a, bool b); \
585 void base_##CBNAME(wxDC& a, bool b);
586
587
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"), \
594 (int)b)); \
595 else \
596 PCLASS::CBNAME(a, b); \
597 wxPySaveThread(doSave); \
598 } \
599 void CLASS::base_##CBNAME(wxDC& a, bool b) { \
600 PCLASS::CBNAME(a, b); \
601 }
602
603 //---------------------------------------------------------------------------
604
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);
608
609
610 #define IMP_PYCALLBACK__WXCPBOOL2DBL2INT(CLASS, PCLASS, CBNAME) \
611 void CLASS::CBNAME(wxControlPoint* a, bool b, double c, double d, \
612 int e, int f) { \
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)); \
618 else \
619 PCLASS::CBNAME(a, b, c, d, e, f); \
620 wxPySaveThread(doSave); \
621 } \
622 void CLASS::base_##CBNAME(wxControlPoint* a, bool b, double c, double d, \
623 int e, int f) { \
624 PCLASS::CBNAME(a, b, c, d, e, f); \
625 }
626
627 //---------------------------------------------------------------------------
628
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);
632
633
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"), \
640 b, c, d, e)); \
641 else \
642 PCLASS::CBNAME(a, b, c, d, e); \
643 wxPySaveThread(doSave); \
644 } \
645 void CLASS::base_##CBNAME(wxControlPoint* a, double b, double c, \
646 int d, int e) { \
647 PCLASS::CBNAME(a, b, c, d, e); \
648 }
649
650 //---------------------------------------------------------------------------
651
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);
655
656
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)); \
662 else \
663 PCLASS::CBNAME(a, b, c); \
664 wxPySaveThread(doSave); \
665 } \
666 void CLASS::base_##CBNAME(double a, double b, int c) { \
667 PCLASS::CBNAME(a, b, c); \
668 }
669
670 //---------------------------------------------------------------------------
671
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);
675
676
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)); \
682 else \
683 PCLASS::CBNAME(a, b, c, d); \
684 wxPySaveThread(doSave); \
685 } \
686 void CLASS::base_##CBNAME(bool a, double b, double c, int d) { \
687 PCLASS::CBNAME(a, b, c, d); \
688 }
689
690 //---------------------------------------------------------------------------
691 //---------------------------------------------------------------------------
692
693 #define DEC_PYCALLBACK__STRING(CBNAME) \
694 void CBNAME(const wxString& a); \
695 void base_##CBNAME(const wxString& a);
696
697
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())); \
703 else \
704 PCLASS::CBNAME(a); \
705 wxPySaveThread(doSave); \
706 } \
707 void CLASS::base_##CBNAME(const wxString& a) { \
708 PCLASS::CBNAME(a); \
709 }
710
711 //---------------------------------------------------------------------------
712
713 #define DEC_PYCALLBACK_BOOL_STRING(CBNAME) \
714 bool CBNAME(const wxString& a); \
715 bool base_##CBNAME(const wxString& a);
716
717
718 #define IMP_PYCALLBACK_BOOL_STRING(CLASS, PCLASS, CBNAME) \
719 bool CLASS::CBNAME(const wxString& a) { \
720 bool rval; \
721 bool doSave = wxPyRestoreThread(); \
722 if (m_myInst.findCallback(#CBNAME)) \
723 rval = m_myInst.callCallback(Py_BuildValue("(s)", a.c_str())); \
724 else \
725 rval = PCLASS::CBNAME(a); \
726 wxPySaveThread(doSave); \
727 return rval; \
728 } \
729 bool CLASS::base_##CBNAME(const wxString& a) { \
730 return PCLASS::CBNAME(a); \
731 }
732
733 //---------------------------------------------------------------------------
734
735 #define DEC_PYCALLBACK_BOOL_STRING_pure(CBNAME) \
736 bool CBNAME(const wxString& a);
737 \
738 #define IMP_PYCALLBACK_BOOL_STRING_pure(CLASS, PCLASS, CBNAME) \
739 bool CLASS::CBNAME(const wxString& a) { \
740 bool rval; \
741 bool doSave = wxPyRestoreThread(); \
742 if (m_myInst.findCallback(#CBNAME)) \
743 rval = m_myInst.callCallback(Py_BuildValue("(s)", a.c_str())); \
744 wxPySaveThread(doSave); \
745 return rval; \
746 } \
747
748 //---------------------------------------------------------------------------
749
750 #define DEC_PYCALLBACK_STRING_STRING_pure(CBNAME) \
751 wxString CBNAME(const wxString& a); \
752
753 #define IMP_PYCALLBACK_STRING_STRING_pure(CLASS, PCLASS, CBNAME) \
754 wxString CLASS::CBNAME(const wxString& a) { \
755 wxString rval; \
756 bool doSave = wxPyRestoreThread(); \
757 if (m_myInst.findCallback(#CBNAME)) { \
758 PyObject* ro; \
759 ro = m_myInst.callCallbackObj(Py_BuildValue("(s)", a.c_str())); \
760 if (ro) { \
761 rval = PyString_AsString(PyObject_Str(ro)); \
762 Py_DECREF(ro); \
763 } \
764 } \
765 wxPySaveThread(doSave); \
766 return rval; \
767 } \
768
769 //---------------------------------------------------------------------------
770
771 #define DEC_PYCALLBACK_STRING_STRINGINT_pure(CBNAME) \
772 wxString CBNAME(const wxString& a,int b); \
773
774 #define IMP_PYCALLBACK_STRING_STRINGINT_pure(CLASS, PCLASS, CBNAME) \
775 wxString CLASS::CBNAME(const wxString& a,int b) { \
776 wxString rval; \
777 bool doSave = wxPyRestoreThread(); \
778 if (m_myInst.findCallback(#CBNAME)) { \
779 PyObject* ro; \
780 ro = m_myInst.callCallbackObj(Py_BuildValue("(si)", a.c_str(),b)); \
781 if (ro) { \
782 rval = PyString_AsString(PyObject_Str(ro)); \
783 Py_DECREF(ro); \
784 } \
785 } \
786 wxPySaveThread(doSave); \
787 return rval; \
788 } \
789
790 //---------------------------------------------------------------------------
791
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);
795
796
797 #define IMP_PYCALLBACK_BOOL_STRINGSTRING(CLASS, PCLASS, CBNAME) \
798 bool CLASS::CBNAME(const wxString& a, const wxString& b) { \
799 bool rval; \
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())); \
804 else \
805 rval = PCLASS::CBNAME(a, b); \
806 wxPySaveThread(doSave); \
807 return rval; \
808 } \
809 bool CLASS::base_##CBNAME(const wxString& a, const wxString& b) { \
810 return PCLASS::CBNAME(a, b); \
811 }
812
813 //---------------------------------------------------------------------------
814
815 #define DEC_PYCALLBACK_STRING_(CBNAME) \
816 wxString CBNAME(); \
817 wxString base_##CBNAME();
818
819
820 #define IMP_PYCALLBACK_STRING_(CLASS, PCLASS, CBNAME) \
821 wxString CLASS::CBNAME() { \
822 wxString rval; \
823 bool doSave = wxPyRestoreThread(); \
824 if (m_myInst.findCallback(#CBNAME)) { \
825 PyObject* ro; \
826 ro = m_myInst.callCallbackObj(Py_BuildValue("()")); \
827 if (ro) { \
828 rval = PyString_AsString(PyObject_Str(ro)); \
829 Py_DECREF(ro); \
830 } \
831 } \
832 else \
833 rval = PCLASS::CBNAME(); \
834 wxPySaveThread(doSave); \
835 return rval; \
836 } \
837 wxString CLASS::base_##CBNAME() { \
838 return PCLASS::CBNAME(); \
839 }
840
841 //---------------------------------------------------------------------------
842
843 #define DEC_PYCALLBACK_STRING__pure(CBNAME) \
844 wxString CBNAME();
845
846
847 #define IMP_PYCALLBACK_STRING__pure(CLASS, PCLASS, CBNAME) \
848 wxString CLASS::CBNAME() { \
849 wxString rval; \
850 bool doSave = wxPyRestoreThread(); \
851 if (m_myInst.findCallback(#CBNAME)) { \
852 PyObject* ro; \
853 ro = m_myInst.callCallbackObj(Py_BuildValue("()")); \
854 if (ro) { \
855 rval = PyString_AsString(PyObject_Str(ro)); \
856 Py_DECREF(ro); \
857 } \
858 } \
859 wxPySaveThread(doSave); \
860 return rval; \
861 }
862
863 //---------------------------------------------------------------------------
864
865 #define DEC_PYCALLBACK_BOOL_TAG_pure(CBNAME) \
866 bool CBNAME(const wxHtmlTag& a); \
867
868
869 #define IMP_PYCALLBACK_BOOL_TAG_pure(CLASS, PCLASS, CBNAME) \
870 bool CLASS::CBNAME(const wxHtmlTag& a) { \
871 bool rval = FALSE; \
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); \
877 return rval; \
878 }
879
880 //---------------------------------------------------------------------------
881
882 #define DEC_PYCALLBACK___pure(CBNAME) \
883 void CBNAME(); \
884
885
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); \
892 }
893
894 //---------------------------------------------------------------------------
895
896 #define DEC_PYCALLBACK_wxSize__pure(CBNAME) \
897 wxSize CBNAME(); \
898
899
900 #define IMP_PYCALLBACK_wxSize__pure(CLASS, PCLASS, CBNAME) \
901 wxSize CLASS::CBNAME() { \
902 wxSize rval(0,0); \
903 bool doSave = wxPyRestoreThread(); \
904 if (m_myInst.findCallback(#CBNAME)) { \
905 PyObject* ro; \
906 wxSize* ptr; \
907 ro = m_myInst.callCallbackObj(Py_BuildValue("()")); \
908 if (ro) { \
909 if (! SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p")) \
910 rval = *ptr; \
911 Py_DECREF(ro); \
912 } \
913 } \
914 wxPySaveThread(doSave); \
915 return rval; \
916 }
917
918 //---------------------------------------------------------------------------
919
920 #define DEC_PYCALLBACK_BOOL_WXWIN(CBNAME) \
921 bool CBNAME(wxWindow* a); \
922 bool base_##CBNAME(wxWindow* a);
923
924
925 #define IMP_PYCALLBACK_BOOL_WXWIN(CLASS, PCLASS, CBNAME) \
926 bool CLASS::CBNAME(wxWindow* a) { \
927 bool rval; \
928 bool doSave = wxPyRestoreThread(); \
929 if (m_myInst.findCallback(#CBNAME)) \
930 rval = m_myInst.callCallback(Py_BuildValue("(O)", \
931 wxPyConstructObject((void*)a,"wxWindow"))); \
932 else \
933 rval = PCLASS::CBNAME(a); \
934 wxPySaveThread(doSave); \
935 return rval; \
936 } \
937 bool CLASS::base_##CBNAME(wxWindow* a) { \
938 return PCLASS::CBNAME(a); \
939 }
940
941 //---------------------------------------------------------------------------
942
943 #define DEC_PYCALLBACK_BOOL_(CBNAME) \
944 bool CBNAME(); \
945 bool base_##CBNAME();
946
947
948 #define IMP_PYCALLBACK_BOOL_(CLASS, PCLASS, CBNAME) \
949 bool CLASS::CBNAME() { \
950 bool rval; \
951 bool doSave = wxPyRestoreThread(); \
952 if (m_myInst.findCallback(#CBNAME)) \
953 rval = m_myInst.callCallback(Py_BuildValue("()")); \
954 else \
955 rval = PCLASS::CBNAME(); \
956 wxPySaveThread(doSave); \
957 return rval; \
958 } \
959 bool CLASS::base_##CBNAME() { \
960 return PCLASS::CBNAME(); \
961 }
962
963 //---------------------------------------------------------------------------
964
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);
968
969
970 #define IMP_PYCALLBACK_DR_2WXCDR(CLASS, PCLASS, CBNAME) \
971 wxDragResult CLASS::CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
972 bool doSave = wxPyRestoreThread(); \
973 int rval; \
974 if (m_myInst.findCallback(#CBNAME)) \
975 rval = m_myInst.callCallback(Py_BuildValue("(iii)", a,b,c));\
976 else \
977 rval = PCLASS::CBNAME(a, b, c); \
978 wxPySaveThread(doSave); \
979 return (wxDragResult)rval; \
980 } \
981 wxDragResult CLASS::base_##CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
982 return PCLASS::CBNAME(a, b, c); \
983 }
984
985 //---------------------------------------------------------------------------
986
987 #define DEC_PYCALLBACK_FSF_FSSTRING_pure(CBNAME) \
988 wxFSFile* CBNAME(wxFileSystem& fs, const wxString& location); \
989
990 #define IMP_PYCALLBACK_FSF_FSSTRING_pure(CLASS, PCLASS, CBNAME) \
991 wxFSFile* CLASS::CBNAME(wxFileSystem& a,const wxString& b) { \
992 bool doSave = wxPyRestoreThread(); \
993 wxFSFile* rval=0; \
994 if (m_myInst.findCallback(#CBNAME)) { \
995 PyObject* ro; \
996 ro=m_myInst.callCallbackObj(Py_BuildValue("(Os)", \
997 wxPyConstructObject(&a, "(wxFileSystemC"),b.c_str())); \
998 if (ro) { \
999 SWIG_GetPtrObj(ro, (void **)&rval, "_wxFSFILE_p"); \
1000 Py_DECREF(ro); \
1001 } \
1002 } \
1003 wxPySaveThread(doSave); \
1004 return rval; \
1005 };
1006
1007 //---------------------------------------------------------------------------
1008
1009 #define DEC_PYCALLBACK_BOOL_DR(CBNAME) \
1010 bool CBNAME(wxDragResult a); \
1011 bool base_##CBNAME(wxDragResult a);
1012
1013
1014 #define IMP_PYCALLBACK_BOOL_DR(CLASS, PCLASS, CBNAME) \
1015 bool CLASS::CBNAME(wxDragResult a) { \
1016 bool doSave = wxPyRestoreThread(); \
1017 bool rval; \
1018 if (m_myInst.findCallback(#CBNAME)) \
1019 rval = m_myInst.callCallback(Py_BuildValue("(i)", a)); \
1020 else \
1021 rval = PCLASS::CBNAME(a); \
1022 wxPySaveThread(doSave); \
1023 return rval; \
1024 } \
1025 bool CLASS::base_##CBNAME(wxDragResult a) { \
1026 return PCLASS::CBNAME(a); \
1027 }
1028
1029 //---------------------------------------------------------------------------
1030
1031 #define DEC_PYCALLBACK_DR_2WXCDR_pure(CBNAME) \
1032 wxDragResult CBNAME(wxCoord x, wxCoord y, wxDragResult def);
1033
1034
1035 #define IMP_PYCALLBACK_DR_2WXCDR_pure(CLASS, PCLASS, CBNAME) \
1036 wxDragResult CLASS::CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
1037 bool doSave = wxPyRestoreThread(); \
1038 int rval; \
1039 if (m_myInst.findCallback(#CBNAME)) \
1040 rval = m_myInst.callCallback(Py_BuildValue("(iii)", a,b,c));\
1041 wxPySaveThread(doSave); \
1042 return (wxDragResult)rval; \
1043 } \
1044
1045 //---------------------------------------------------------------------------
1046
1047 #define DEC_PYCALLBACK_BOOL_INTINTSTR_pure(CBNAME) \
1048 bool CBNAME(int a, int b, const wxString& c);
1049
1050
1051 #define IMP_PYCALLBACK_BOOL_INTINTSTR_pure(CLASS, PCLASS, CBNAME) \
1052 bool CLASS::CBNAME(int a, int b, const wxString& c) { \
1053 bool rval; \
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); \
1058 return rval; \
1059 } \
1060
1061 //---------------------------------------------------------------------------
1062
1063 #define DEC_PYCALLBACK_SIZET_(CBNAME) \
1064 size_t CBNAME(); \
1065 size_t base_##CBNAME();
1066
1067
1068 #define IMP_PYCALLBACK_SIZET_(CLASS, PCLASS, CBNAME) \
1069 size_t CLASS::CBNAME() { \
1070 size_t rval; \
1071 bool doSave = wxPyRestoreThread(); \
1072 if (m_myInst.findCallback(#CBNAME)) \
1073 rval = m_myInst.callCallback(Py_BuildValue("()")); \
1074 else \
1075 rval = PCLASS::CBNAME(); \
1076 wxPySaveThread(doSave); \
1077 return rval; \
1078 } \
1079 size_t CLASS::base_##CBNAME() { \
1080 return PCLASS::CBNAME(); \
1081 }
1082
1083 //---------------------------------------------------------------------------
1084
1085 #define DEC_PYCALLBACK_DATAFMT_SIZET(CBNAME) \
1086 wxDataFormat CBNAME(); \
1087 wxDataFormat base_##CBNAME();
1088
1089
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)) { \
1095 PyObject* ro; \
1096 wxDataFormat* ptr; \
1097 ro = m_myInst.callCallbackObj(Py_BuildValue("(i)", a)); \
1098 if (ro) { \
1099 if (! SWIG_GetPtrObj(ro, (void **)&ptr, "_wxDataFormat_p")) \
1100 rval = *ptr; \
1101 Py_DECREF(ro); \
1102 } \
1103 } \
1104 else \
1105 rval = PCLASS::CBNAME(a); \
1106 wxPySaveThread(doSave); \
1107 return rval; \
1108 } \
1109 wxDataFormat CLASS::base_##CBNAME(size_t a) { \
1110 return PCLASS::CBNAME(a); \
1111 }
1112
1113 //---------------------------------------------------------------------------
1114
1115 #define DEC_PYCALLBACK__constany(CBNAME, Type) \
1116 void CBNAME(const Type& a); \
1117 void base_##CBNAME(const Type& a);
1118
1119
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))); \
1126 else \
1127 PCLASS::CBNAME(a); \
1128 wxPySaveThread(doSave); \
1129 } \
1130 void CLASS::base_##CBNAME(const Type& a) { \
1131 PCLASS::CBNAME(a); \
1132 }
1133
1134
1135 //---------------------------------------------------------------------------
1136
1137 #define DEC_PYCALLBACK__any(CBNAME, Type) \
1138 void CBNAME(Type& a); \
1139 void base_##CBNAME(Type& a);
1140
1141
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))); \
1148 else \
1149 PCLASS::CBNAME(a); \
1150 wxPySaveThread(doSave); \
1151 } \
1152 void CLASS::base_##CBNAME(Type& a) { \
1153 PCLASS::CBNAME(a); \
1154 }
1155
1156 //---------------------------------------------------------------------------
1157
1158 #define DEC_PYCALLBACK_bool_any(CBNAME, Type) \
1159 bool CBNAME(Type& a); \
1160 bool base_##CBNAME(Type& a);
1161
1162
1163 #define IMP_PYCALLBACK_bool_any(CLASS, PCLASS, CBNAME, Type) \
1164 bool CLASS::CBNAME(Type& a) { \
1165 bool rv; \
1166 bool doSave = wxPyRestoreThread(); \
1167 if (m_myInst.findCallback(#CBNAME)) \
1168 rv = m_myInst.callCallback(Py_BuildValue("(O)", \
1169 wxPyConstructObject(&a, #Type))); \
1170 else \
1171 rv = PCLASS::CBNAME(a); \
1172 wxPySaveThread(doSave); \
1173 return rv; \
1174 } \
1175 bool CLASS::base_##CBNAME(Type& a) { \
1176 return PCLASS::CBNAME(a); \
1177 }
1178
1179 //---------------------------------------------------------------------------
1180
1181 #endif
1182
1183
1184
1185