Repository navigation
Expand file tree
/
Copy pathwxPython_int.h
More file actions
2746 lines (2235 loc) · 148 KB
/
Copy pathwxPython_int.h
File metadata and controls
2746 lines (2235 loc) · 148 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
////////////////////////////////////////////////////////////////////////////
// Name: wxPython_int.h (int == internal)
// Purpose: Helper functions/classes for the wxPython extension module
// This header should only be inclued directly by those source
// modules included in the wx._core module. All others should
// include wx/wxPython/wxPython.h instead.
//
// Author: Robin Dunn
//
// Created: 1-July-1997
// RCS-ID: $Id: wxPython_int.h 60300 2009-04-24 05:26:27Z RD $
// Copyright: (c) 1998 by Total Control Software
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifndef __wxp_helpers__
#define __wxp_helpers__
#include <wx/wx.h>
#include <wx/busyinfo.h>
#include <wx/caret.h>
#include <wx/choicebk.h>
#include <wx/clipbrd.h>
#include <wx/colordlg.h>
#include <wx/config.h>
#include <wx/cshelp.h>
#include <wx/dcmirror.h>
#include <wx/dcps.h>
#include <wx/dirctrl.h>
#include <wx/dirdlg.h>
#include <wx/numdlg.h>
#include <wx/dnd.h>
#include <wx/docview.h>
#include <wx/encconv.h>
#include <wx/fdrepdlg.h>
#include <wx/fileconf.h>
#include <wx/filesys.h>
#include <wx/fontdlg.h>
#include <wx/fs_inet.h>
#include <wx/fs_mem.h>
#include <wx/fs_zip.h>
#include <wx/gbsizer.h>
#include <wx/geometry.h>
#include <wx/htmllbox.h>
#include <wx/image.h>
#include <wx/imaglist.h>
#include <wx/intl.h>
#include <wx/laywin.h>
#include <wx/listbook.h>
#include <wx/minifram.h>
#include <wx/notebook.h>
#include <wx/print.h>
#include <wx/printdlg.h>
#include <wx/process.h>
#include <wx/progdlg.h>
#include <wx/sashwin.h>
#include <wx/spinbutt.h>
#include <wx/spinctrl.h>
#include <wx/splash.h>
#include <wx/splitter.h>
#include <wx/statline.h>
#include <wx/stream.h>
#include <wx/sysopt.h>
#include <wx/taskbar.h>
#include <wx/tglbtn.h>
#include <wx/tipwin.h>
#include <wx/toolbook.h>
#include <wx/tooltip.h>
#include <wx/treebook.h>
#include <wx/vlbox.h>
#include <wx/vscroll.h>
#include <wx/dateevt.h>
#include <wx/datectrl.h>
#include <wx/power.h>
#include <wx/hyperlink.h>
#include <wx/pickerbase.h>
#include <wx/clrpicker.h>
#include <wx/filepicker.h>
#include <wx/fontpicker.h>
#include <wx/collpane.h>
#include <wx/srchctrl.h>
#include <wx/generic/datectrl.h>
#ifdef _MSC_VER
# pragma warning(disable:4800)
# pragma warning(disable:4190)
#endif
#ifdef __WXMAC__ // avoid a bug in Carbon headers
#define scalb scalbn
#endif
//---------------------------------------------------------------------------
#ifndef wxHAS_POWER_EVENTS
class wxPowerEvent : public wxEvent
{
public:
wxPowerEvent(wxEventType evtType) : wxEvent(wxID_NONE, evtType) {}
void Veto() {}
bool IsVetoed() const { return false; }
virtual wxEvent *Clone() const { return new wxPowerEvent(*this); }
};
#endif
//---------------------------------------------------------------------------
typedef unsigned char byte;
typedef unsigned char* buffer;
typedef wxPoint2DDouble wxPoint2D;
typedef wxRect2DDouble wxRect2D;
#ifndef SWIG_TYPE_TABLE
#define SWIG_TYPE_TABLE wxPython_type_table
#endif
#ifdef __WXGTK__
#define wxDEFAULT_STATUSBAR_STYLE wxST_SIZEGRIP|wxFULL_REPAINT_ON_RESIZE
#else
#define wxDEFAULT_STATUSBAR_STYLE wxST_SIZEGRIP
#endif
#ifndef wxPyUSE_EXPORTED_API
void __wxPyPreStart(PyObject*);
void __wxPyCleanup();
PyObject* __wxPySetDictionary(PyObject*, PyObject* args);
void wxSetDefaultPyEncoding(const char* encoding);
const char* wxGetDefaultPyEncoding();
void wxPyEventThunker(wxObject*, wxEvent& event);
bool wxPyCheckSwigType(const wxChar* className);
PyObject* wxPyConstructObject(void* ptr,
const wxChar* className,
int setThisOwn=0);
bool wxPyConvertSwigPtr(PyObject* obj, void **ptr,
const wxChar* className);
PyObject* wxPyMakeSwigPtr(void* ptr, const wxChar* classname);
PyObject* wx2PyString(const wxString& src);
wxString Py2wxString(PyObject* source);
PyObject* wxPyMake_wxObject(wxObject* source, bool setThisOwn, bool checkEvtHandler=true);
PyObject* wxPyMake_wxSizer(wxSizer* source, bool setThisOwn);
void wxPyPtrTypeMap_Add(const char* commonName, const char* ptrName);
long wxPyGetWinHandle(wxWindow* win);
void wxPy_ReinitStockObjects(int pass);
bool wxPyInstance_Check(PyObject* obj);
bool wxPySwigInstance_Check(PyObject* obj);
#endif // wxPyUSE_EXPORTED_API
//---------------------------------------------------------------------------
// if we want to handle threads and Python threads are available...
#if defined(WXP_USE_THREAD) && defined(WITH_THREAD)
#define WXP_WITH_THREAD
#else // no Python threads...
#undef WXP_WITH_THREAD
#endif
// In Python 2.3 and later there are the PyGILState_* APIs that we can use for
// blocking threads when calling back into Python. Using them instead of my
// home-grown hacks greatly simplifies wxPyBeginBlockThreads and
// wxPyEndBlockThreads.
//
// Unfortunatly there is a bug somewhere when using these new APIs on Python
// 2.3. It manifests in Boa Constructor's debugger where it is unable to stop
// at breakpoints located in event handlers. I think that the cause may be
// something like the original PyThreadState for the main thread is not being
// restored for the callbacks, but I can't see where that could be
// happening... So we'll only activate this new change for Python 2.4+ :-(
#if PY_VERSION_HEX < 0x02040000
#define wxPyUSE_GIL_STATE 0
typedef bool wxPyBlock_t;
#define wxPyBlock_t_default false
#else
#define wxPyUSE_GIL_STATE 1
typedef PyGILState_STATE wxPyBlock_t;
#define wxPyBlock_t_default PyGILState_UNLOCKED
#endif
// Python 2.5 changes the type of some API parameter and return types. Using
// this typedef for versions < 2.5 will help with the transition...
#if PY_VERSION_HEX < 0x02050000
typedef int Py_ssize_t;
#endif
#ifndef wxPyUSE_EXPORTED_API
// For Python --> C++
PyThreadState* wxPyBeginAllowThreads();
void wxPyEndAllowThreads(PyThreadState* state);
// For C++ --> Python
wxPyBlock_t wxPyBeginBlockThreads();
void wxPyEndBlockThreads(wxPyBlock_t blocked);
#endif // wxPyUSE_EXPORTED_API
// A macro that will help to execute simple statments wrapped in
// StartBlock/EndBlockThreads calls
#define wxPyBLOCK_THREADS(stmt) \
{ wxPyBlock_t blocked = wxPyBeginBlockThreads(); stmt; wxPyEndBlockThreads(blocked); }
// Raise the NotImplementedError exception (blocking threads)
#define wxPyRaiseNotImplemented() \
wxPyBLOCK_THREADS(PyErr_SetNone(PyExc_NotImplementedError))
// Raise any exception with a string value (blocking threads)
#define wxPyErr_SetString(err, str) \
wxPyBLOCK_THREADS(PyErr_SetString(err, str))
//---------------------------------------------------------------------------
// These are helpers used by the typemaps
#ifndef wxPyUSE_EXPORTED_API
wxString* wxString_in_helper(PyObject* source);
byte* byte_LIST_helper(PyObject* source);
int* int_LIST_helper(PyObject* source);
long* long_LIST_helper(PyObject* source);
char** string_LIST_helper(PyObject* source);
wxPoint* wxPoint_LIST_helper(PyObject* source, int* npoints);
wxPoint2D* wxPoint2D_LIST_helper(PyObject* source, size_t* npoints);
wxBitmap** wxBitmap_LIST_helper(PyObject* source);
wxString* wxString_LIST_helper(PyObject* source);
wxAcceleratorEntry* wxAcceleratorEntry_LIST_helper(PyObject* source);
wxPen** wxPen_LIST_helper(PyObject* source);
bool wxSize_helper(PyObject* source, wxSize** obj);
bool wxPoint_helper(PyObject* source, wxPoint** obj);
bool wxRealPoint_helper(PyObject* source, wxRealPoint** obj);
bool wxRect_helper(PyObject* source, wxRect** obj);
bool wxColour_helper(PyObject* source, wxColour** obj);
bool wxPoint2D_helper(PyObject* source, wxPoint2D** obj);
bool wxRect2D_helper(PyObject* source, wxRect2D** obj);
bool wxPySimple_typecheck(PyObject* source, const wxChar* classname, int seqLen);
bool wxColour_typecheck(PyObject* source);
// Other helpful stuff
bool wxPyCheckForApp();
bool wxPyTestDisplayAvailable();
bool wxPy2int_seq_helper(PyObject* source, int* i1, int* i2);
bool wxPy4int_seq_helper(PyObject* source, int* i1, int* i2, int* i3, int* i4);
PyObject* wxArrayString2PyList_helper(const wxArrayString& arr);
PyObject* wxArrayInt2PyList_helper(const wxArrayInt& arr);
PyObject* wxArrayDouble2PyList_helper(const wxArrayDouble& arr);
#endif // wxPyUSE_EXPORTED_API
//---------------------------------------------------------------------------
#if PYTHON_API_VERSION < 1009
#define PySequence_Fast_GET_ITEM(o, i) \
(PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i))
#endif
#define RETURN_NONE() { Py_INCREF(Py_None); return Py_None; }
#define DECLARE_DEF_STRING(name) static const wxString wxPy##name(wx##name)
#define DECLARE_DEF_STRING2(name,val) static const wxString wxPy##name(val)
//---------------------------------------------------------------------------
#ifndef wxPyUSE_EXPORTED_API
class wxPyCallback : public wxObject {
DECLARE_ABSTRACT_CLASS(wxPyCallback)
public:
wxPyCallback(PyObject* func);
wxPyCallback(const wxPyCallback& other);
~wxPyCallback();
void EventThunker(wxEvent& event);
PyObject* m_func;
};
#endif // wxPyUSE_EXPORTED_API
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// These Event classes can be derived from in Python and passed through the
// event system without loosing anything. They do this by keeping a reference
// to themselves and some special case handling in wxPyCallback::EventThunker.
class wxPyEvtSelfRef {
public:
wxPyEvtSelfRef();
~wxPyEvtSelfRef();
void SetSelf(PyObject* self, bool clone=false);
PyObject* GetSelf() const;
bool GetCloned() const { return m_cloned; }
protected:
PyObject* m_self;
bool m_cloned;
};
class wxPyEvent : public wxEvent, public wxPyEvtSelfRef {
DECLARE_ABSTRACT_CLASS(wxPyEvent)
public:
wxPyEvent(int winid=0, wxEventType commandType = wxEVT_NULL);
wxPyEvent(const wxPyEvent& evt);
~wxPyEvent();
virtual wxEvent* Clone() const { return new wxPyEvent(*this); }
};
class wxPyCommandEvent : public wxCommandEvent, public wxPyEvtSelfRef {
DECLARE_ABSTRACT_CLASS(wxPyCommandEvent)
public:
wxPyCommandEvent(wxEventType commandType = wxEVT_NULL, int id=0);
wxPyCommandEvent(const wxPyCommandEvent& evt);
~wxPyCommandEvent();
virtual wxEvent* Clone() const { return new wxPyCommandEvent(*this); }
};
//----------------------------------------------------------------------
// Forward decalre a few things used in the exported API
class wxPyClientData;
class wxPyUserData;
class wxPyOORClientData;
class wxPyCBInputStream;
class wxPyCBOutputStream;
void wxPyClientData_dtor(wxPyClientData* self);
void wxPyUserData_dtor(wxPyUserData* self);
void wxPyOORClientData_dtor(wxPyOORClientData* self);
wxPyCBInputStream* wxPyCBInputStream_create(PyObject *py, bool block);
wxPyCBInputStream* wxPyCBInputStream_copy(wxPyCBInputStream* other);
wxPyCBOutputStream* wxPyCBOutputStream_create(PyObject *py, bool block);
wxPyCBOutputStream* wxPyCBOutputStream_copy(wxPyCBOutputStream* other);
//---------------------------------------------------------------------------
// Export a C API in a struct. Other modules will be able to load this from
// the wx.core module and will then have safe access to these functions, even if
// in another shared library.
class wxPyCallbackHelper;
struct wxPyCoreAPI {
bool (*p_wxPyCheckSwigType)(const wxChar* className);
PyObject* (*p_wxPyConstructObject)(void* ptr, const wxChar* className, int setThisOwn);
bool (*p_wxPyConvertSwigPtr)(PyObject* obj, void **ptr, const wxChar* className);
PyObject* (*p_wxPyMakeSwigPtr)(void* ptr, const wxChar* className);
PyThreadState* (*p_wxPyBeginAllowThreads)();
void (*p_wxPyEndAllowThreads)(PyThreadState* state);
wxPyBlock_t (*p_wxPyBeginBlockThreads)();
void (*p_wxPyEndBlockThreads)(wxPyBlock_t blocked);
void* unused1; // this slot is no longer used
wxString* (*p_wxString_in_helper)(PyObject* source);
wxString (*p_Py2wxString)(PyObject* source);
PyObject* (*p_wx2PyString)(const wxString& src);
byte* (*p_byte_LIST_helper)(PyObject* source);
int* (*p_int_LIST_helper)(PyObject* source);
long* (*p_long_LIST_helper)(PyObject* source);
char** (*p_string_LIST_helper)(PyObject* source);
wxPoint* (*p_wxPoint_LIST_helper)(PyObject* source, int* npoints);
wxBitmap** (*p_wxBitmap_LIST_helper)(PyObject* source);
wxString* (*p_wxString_LIST_helper)(PyObject* source);
wxAcceleratorEntry* (*p_wxAcceleratorEntry_LIST_helper)(PyObject* source);
bool (*p_wxSize_helper)(PyObject* source, wxSize** obj);
bool (*p_wxPoint_helper)(PyObject* source, wxPoint** obj);
bool (*p_wxRealPoint_helper)(PyObject* source, wxRealPoint** obj);
bool (*p_wxRect_helper)(PyObject* source, wxRect** obj);
bool (*p_wxColour_helper)(PyObject* source, wxColour** obj);
bool (*p_wxPoint2D_helper)(PyObject* source, wxPoint2D** obj);
bool (*p_wxPySimple_typecheck)(PyObject* source, const wxChar* classname, int seqLen);
bool (*p_wxColour_typecheck)(PyObject* source);
void (*p_wxPyCBH_setCallbackInfo)(wxPyCallbackHelper& cbh, PyObject* self, PyObject* klass, int incref);
bool (*p_wxPyCBH_findCallback)(const wxPyCallbackHelper& cbh, const char* name, bool setGuard);
int (*p_wxPyCBH_callCallback)(const wxPyCallbackHelper& cbh, PyObject* argTuple);
PyObject* (*p_wxPyCBH_callCallbackObj)(const wxPyCallbackHelper& cbh, PyObject* argTuple);
void (*p_wxPyCBH_delete)(wxPyCallbackHelper* cbh);
PyObject* (*p_wxPyMake_wxObject)(wxObject* source, bool setThisOwn, bool checkEvtHandler);
PyObject* (*p_wxPyMake_wxSizer)(wxSizer* source, bool setThisOwn);
void (*p_wxPyPtrTypeMap_Add)(const char* commonName, const char* ptrName);
bool (*p_wxPy2int_seq_helper)(PyObject* source, int* i1, int* i2);
bool (*p_wxPy4int_seq_helper)(PyObject* source, int* i1, int* i2, int* i3, int* i4);
PyObject* (*p_wxArrayString2PyList_helper)(const wxArrayString& arr);
PyObject* (*p_wxArrayInt2PyList_helper)(const wxArrayInt& arr);
void (*p_wxPyClientData_dtor)(wxPyClientData*);
void (*p_wxPyUserData_dtor)(wxPyUserData*);
void (*p_wxPyOORClientData_dtor)(wxPyOORClientData*);
wxPyCBInputStream* (*p_wxPyCBInputStream_create)(PyObject *py, bool block);
wxPyCBInputStream* (*p_wxPyCBInputStream_copy)(wxPyCBInputStream* other);
bool (*p_wxPyInstance_Check)(PyObject* obj);
bool (*p_wxPySwigInstance_Check)(PyObject* obj);
bool (*p_wxPyCheckForApp)();
// Add all new items at the end...
PyObject* (*p_wxArrayDoublePyList_helper)(const wxArrayDouble& arr);
wxPoint2D* (*p_wxPoint2D_LIST_helper)(PyObject* source, size_t* npoints);
bool (*p_wxRect2D_helper)(PyObject* source, wxRect2D** obj);
wxPyCBOutputStream* (*p_wxPyCBOutputStream_create)(PyObject *py, bool block);
wxPyCBOutputStream* (*p_wxPyCBOutputStream_copy)(wxPyCBOutputStream* other);
};
#ifdef wxPyUSE_EXPORTED_API
// Notice that this is static, not extern. This is by design, each module
// needs one, but doesn't have to use it.
static wxPyCoreAPI* wxPyCoreAPIPtr = NULL;
inline wxPyCoreAPI* wxPyGetCoreAPIPtr();
#endif // wxPyUSE_EXPORTED_API
//---------------------------------------------------------------------------
// A wxObject that holds a reference to a Python object
class wxPyUserData : public wxObject {
public:
wxPyUserData(PyObject* obj) {
m_obj = obj;
Py_INCREF(m_obj);
}
~wxPyUserData() {
#ifdef wxPyUSE_EXPORTED_API
wxPyGetCoreAPIPtr()->p_wxPyUserData_dtor(this);
#else
wxPyUserData_dtor(this);
#endif
}
PyObject* m_obj;
};
// A wxClientData that holds a refernece to a Python object
class wxPyClientData : public wxClientData {
public:
wxPyClientData(PyObject* obj, bool incref=true) {
m_obj = obj;
m_incRef = incref;
if (incref)
Py_INCREF(m_obj);
}
~wxPyClientData() {
#ifdef wxPyUSE_EXPORTED_API
wxPyGetCoreAPIPtr()->p_wxPyClientData_dtor(this);
#else
wxPyClientData_dtor(this);
#endif
}
PyObject* m_obj;
bool m_incRef;
};
// Just like wxPyClientData, except when this object is destroyed it does some
// OOR magic on the Python Object.
class wxPyOORClientData : public wxPyClientData {
public:
wxPyOORClientData(PyObject* obj, bool incref=true)
: wxPyClientData(obj, incref) {}
~wxPyOORClientData() {
#ifdef wxPyUSE_EXPORTED_API
wxPyGetCoreAPIPtr()->p_wxPyOORClientData_dtor(this);
#else
wxPyOORClientData_dtor(this);
#endif
}
};
//---------------------------------------------------------------------------
// A wxImageHandler that can be derived from in Python.
//
class wxPyImageHandler: public wxImageHandler {
protected:
PyObject *m_self;
// used for interning method names as PyStrings
static PyObject* m_DoCanRead_Name;
static PyObject* m_GetImageCount_Name;
static PyObject* m_LoadFile_Name;
static PyObject* m_SaveFile_Name;
// converstion helpers
PyObject* py_InputStream(wxInputStream* stream);
PyObject* py_Image(wxImage* image);
PyObject* py_OutputStream(wxOutputStream* stream);
public:
wxPyImageHandler();
~wxPyImageHandler();
void _SetSelf(PyObject *self);
virtual bool LoadFile(wxImage* image, wxInputStream& stream,
bool verbose=true, int index=-1 );
virtual bool SaveFile(wxImage* image, wxOutputStream& stream,
bool verbose=true );
virtual int GetImageCount(wxInputStream& stream );
virtual bool DoCanRead(wxInputStream &stream);
};
//---------------------------------------------------------------------------
// This class holds an instance of a Python Shadow Class object and assists
// with looking up and invoking Python callback methods from C++ virtual
// method redirections. For all classes which have virtuals which should be
// overridable in wxPython, a new subclass is created that contains a
// wxPyCallbackHelper.
//
class wxPyCallbackHelper {
public:
wxPyCallbackHelper(const wxPyCallbackHelper& other);
wxPyCallbackHelper() {
m_class = NULL;
m_self = NULL;
m_lastFound = NULL;
m_incRef = false;
}
~wxPyCallbackHelper() {
#ifdef wxPyUSE_EXPORTED_API
wxPyGetCoreAPIPtr()->p_wxPyCBH_delete(this);
#else
wxPyCBH_delete(this);
#endif
}
void setSelf(PyObject* self, PyObject* klass, int incref=true);
bool findCallback(const char* name, bool setGuard=true) const;
int callCallback(PyObject* argTuple) const;
PyObject* callCallbackObj(PyObject* argTuple) const;
PyObject* GetLastFound() const { return m_lastFound; }
void setRecursionGuard(PyObject* method) const;
void clearRecursionGuard(PyObject* method) const;
private:
PyObject* m_self;
PyObject* m_class;
PyObject* m_lastFound;
int m_incRef;
friend void wxPyCBH_delete(wxPyCallbackHelper* cbh);
};
void wxPyCBH_setCallbackInfo(wxPyCallbackHelper& cbh, PyObject* self, PyObject* klass, int incref);
bool wxPyCBH_findCallback(const wxPyCallbackHelper& cbh, const char* name, bool setGuard=true);
int wxPyCBH_callCallback(const wxPyCallbackHelper& cbh, PyObject* argTuple);
PyObject* wxPyCBH_callCallbackObj(const wxPyCallbackHelper& cbh, PyObject* argTuple);
void wxPyCBH_delete(wxPyCallbackHelper* cbh);
//---------------------------------------------------------------------------
// This is used in C++ classes that need to be able to make callback to
// "overloaded" python methods
#define PYPRIVATE \
void _setCallbackInfo(PyObject* self, PyObject* _class, int incref=1) { \
wxPyCBH_setCallbackInfo(m_myInst, self, _class, incref); \
} \
private: wxPyCallbackHelper m_myInst
//---------------------------------------------------------------------------
// The wxPythonApp class
enum {
wxPYAPP_ASSERT_SUPPRESS = 1,
wxPYAPP_ASSERT_EXCEPTION = 2,
wxPYAPP_ASSERT_DIALOG = 4,
wxPYAPP_ASSERT_LOG = 8
};
class wxPyApp: public wxApp
{
DECLARE_ABSTRACT_CLASS(wxPyApp)
public:
wxPyApp();
~wxPyApp();
bool OnInit();
int MainLoop();
int GetAssertMode() { return m_assertMode; }
void SetAssertMode(int mode) { m_assertMode = mode; }
bool GetCallFilterEvent() { return m_callFilterEvent; }
void SetCallFilterEvent(bool callFilterEvent=true) { m_callFilterEvent = callFilterEvent; }
virtual bool OnInitGui();
virtual int OnExit();
#ifdef __WXDEBUG__
virtual void OnAssertFailure(const wxChar *file,
int line,
const wxChar *func,
const wxChar *cond,
const wxChar *msg);
#endif
#if wxUSE_EXCEPTIONS
virtual bool OnExceptionInMainLoop();
#endif
virtual void ExitMainLoop();
virtual int FilterEvent(wxEvent& event);
// For catching Apple Events
virtual void MacOpenFile(const wxString &fileName);
virtual void MacPrintFile(const wxString &fileName);
virtual void MacNewFile();
virtual void MacReopenApp();
static bool GetMacSupportPCMenuShortcuts();
static long GetMacAboutMenuItemId();
static long GetMacPreferencesMenuItemId();
static long GetMacExitMenuItemId();
static wxString GetMacHelpMenuTitleName();
static void SetMacSupportPCMenuShortcuts(bool val);
static void SetMacAboutMenuItemId(long val);
static void SetMacPreferencesMenuItemId(long val);
static void SetMacExitMenuItemId(long val);
static void SetMacHelpMenuTitleName(const wxString& val);
void _BootstrapApp();
// implementation only
void SetStartupComplete(bool val) { m_startupComplete = val; };
PYPRIVATE;
int m_assertMode;
bool m_startupComplete;
bool m_callFilterEvent;
};
extern wxPyApp *wxPythonApp;
//----------------------------------------------------------------------
// These macros are used to implement the virtual methods that should
// redirect to a Python method if one exists. The names designate the
// return type, if any, as well as any parameter types.
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK__(CBNAME) \
void CBNAME()
#define IMP_PYCALLBACK__(CLASS, PCLASS, CBNAME) \
void CLASS::CBNAME() { \
bool found; \
wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
wxPyEndBlockThreads(blocked); \
if (! found) \
PCLASS::CBNAME(); \
}
#define DEC_PYCALLBACK_VOID_(CBNAME) \
DEC_PYCALLBACK__(CBNAME)
#define IMP_PYCALLBACK_VOID_(CLASS, PCLASS, CBNAME) \
IMP_PYCALLBACK__(CLASS, PCLASS, CBNAME)
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_BOOL_INTINT(CBNAME) \
bool CBNAME(int a, int b)
#define IMP_PYCALLBACK_BOOL_INTINT(CLASS, PCLASS, CBNAME) \
bool CLASS::CBNAME(int a, int b) { \
bool rval=false, found; \
wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
wxPyEndBlockThreads(blocked); \
if (! found) \
rval = PCLASS::CBNAME(a,b); \
return rval; \
}
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_VOID_INTINT(CBNAME) \
void CBNAME(int a, int b)
#define IMP_PYCALLBACK_VOID_INTINT(CLASS, PCLASS, CBNAME) \
void CLASS::CBNAME(int a, int b) { \
bool found; \
wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
wxPyEndBlockThreads(blocked); \
if (! found) \
PCLASS::CBNAME(a,b); \
}
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_VOID_INT(CBNAME) \
void CBNAME(int a)
#define IMP_PYCALLBACK_VOID_INT(CLASS, PCLASS, CBNAME) \
void CLASS::CBNAME(int a) { \
bool found; \
wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)",a)); \
wxPyEndBlockThreads(blocked); \
if (! found) \
PCLASS::CBNAME(a); \
}
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_VOID_INT4(CBNAME) \
void CBNAME(int a, int b, int c, int d)
#define IMP_PYCALLBACK_VOID_INT4(CLASS, PCLASS, CBNAME) \
void CLASS::CBNAME(int a, int b, int c, int d) { \
bool found; \
wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiii)",a,b,c,d)); \
wxPyEndBlockThreads(blocked); \
if (! found) \
PCLASS::CBNAME(a,b,c,d); \
}
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_VOID_INT5(CBNAME) \
void CBNAME(int a, int b, int c, int d, int e)
#define IMP_PYCALLBACK_VOID_INT5(CLASS, PCLASS, CBNAME) \
void CLASS::CBNAME(int a, int b, int c, int d, int e) { \
bool found; \
wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiiii)",a,b,c,d,e)); \
wxPyEndBlockThreads(blocked); \
if (! found) \
PCLASS::CBNAME(a,b,c,d,e); \
}
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_VOID_INTPINTP_const(CBNAME) \
void CBNAME(int* a, int* b) const
#define IMP_PYCALLBACK_VOID_INTPINTP_const(CLASS, PCLASS, CBNAME) \
void CLASS::CBNAME(int* a, int* b) const { \
const char* errmsg = #CBNAME " should return a 2-tuple of integers."; \
bool found; \
wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
PyObject* ro; \
ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
if (ro) { \
if (PySequence_Check(ro) && PyObject_Length(ro) == 2) { \
PyObject* o1 = PySequence_GetItem(ro, 0); \
PyObject* o2 = PySequence_GetItem(ro, 1); \
if (PyNumber_Check(o1) && PyNumber_Check(o2)) { \
*a = PyInt_AsLong(o1); *b = PyInt_AsLong(o2); \
} \
else \
PyErr_SetString(PyExc_TypeError, errmsg); \
Py_DECREF(o1); \
Py_DECREF(o2); \
} \
else { \
PyErr_SetString(PyExc_TypeError, errmsg); \
} \
Py_DECREF(ro); \
} \
} \
wxPyEndBlockThreads(blocked); \
if (! found) \
PCLASS::CBNAME(a,b); \
}
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_SIZE_const(CBNAME) \
wxSize CBNAME() const
#define IMP_PYCALLBACK_SIZE_const(CLASS, PCLASS, CBNAME) \
wxSize CLASS::CBNAME() const { \
const char* errmsg = #CBNAME " should return a 2-tuple of integers or a Size object."; \
bool found; wxSize rval(0,0); \
wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
PyObject* ro; \
wxSize* ptr; \
ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
if (ro) { \
if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxSize"))) \
rval = *ptr; \
else if (PySequence_Check(ro) && PyObject_Length(ro) == 2) { \
PyObject* o1 = PySequence_GetItem(ro, 0); \
PyObject* o2 = PySequence_GetItem(ro, 1); \
if (PyNumber_Check(o1) && PyNumber_Check(o2)) { \
rval = wxSize(PyInt_AsLong(o1), PyInt_AsLong(o2)); \
} \
else \
PyErr_SetString(PyExc_TypeError, errmsg); \
Py_DECREF(o1); \
Py_DECREF(o2); \
} \
else { \
PyErr_SetString(PyExc_TypeError, errmsg); \
} \
Py_DECREF(ro); \
} \
} \
wxPyEndBlockThreads(blocked); \
if (! found) \
return PCLASS::CBNAME(); \
else \
return rval; \
}
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_POINT_const(CBNAME) \
wxPoint CBNAME() const
#define IMP_PYCALLBACK_POINT_const(CLASS, PCLASS, CBNAME) \
wxPoint CLASS::CBNAME() const { \
const char* errmsg = #CBNAME " should return a 2-tuple of integers or a Point object."; \
bool found; wxPoint rval(0,0); \
wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
PyObject* ro; \
wxPoint* ptr; \
ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
if (ro) { \
if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxPoint"))) \
rval = *ptr; \
else if (PySequence_Check(ro) && PyObject_Length(ro) == 2) { \
PyObject* o1 = PySequence_GetItem(ro, 0); \
PyObject* o2 = PySequence_GetItem(ro, 1); \
if (PyNumber_Check(o1) && PyNumber_Check(o2)) { \
rval = wxPoint(PyInt_AsLong(o1), PyInt_AsLong(o2)); \
} \
else \
PyErr_SetString(PyExc_TypeError, errmsg); \
Py_DECREF(o1); \
Py_DECREF(o2); \
} \
else { \
PyErr_SetString(PyExc_TypeError, errmsg); \
} \
Py_DECREF(ro); \
} \
} \
wxPyEndBlockThreads(blocked); \
if (! found) \
return PCLASS::CBNAME(); \
else \
return rval; \
}
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_BOOL_BOOL(CBNAME) \
bool CBNAME(bool a)
#define IMP_PYCALLBACK_BOOL_BOOL(CLASS, PCLASS, CBNAME) \
bool CLASS::CBNAME(bool a) { \
bool rval=false, found; \
wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)",a));\
wxPyEndBlockThreads(blocked); \
if (! found) \
rval = PCLASS::CBNAME(a); \
return rval; \
}
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_BOOL_INT(CBNAME) \
bool CBNAME(int a)
#define IMP_PYCALLBACK_BOOL_INT(CLASS, PCLASS, CBNAME) \
bool CLASS::CBNAME(int a) { \
bool rval=false, found; \
wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)",a));\
wxPyEndBlockThreads(blocked); \
if (! found) \
rval = PCLASS::CBNAME(a); \
return rval; \
}
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_BOOL_INT_pure(CBNAME) \
bool CBNAME(int a)
#define IMP_PYCALLBACK_BOOL_INT_pure(CLASS, PCLASS, CBNAME) \
bool CLASS::CBNAME(int a) { \
bool rval=false; \
wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)",a)); \
else rval = false; \
wxPyEndBlockThreads(blocked); \
return rval; \
}
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_INT_WIN(CBNAME) \
int CBNAME(wxWindow* a)
#define IMP_PYCALLBACK_INT_WIN(CLASS, PCLASS, CBNAME) \
int CLASS::CBNAME(wxWindow* a) { \
int rval=0; \
bool found; \
wxPyBlock_t blocked = wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
PyObject* obj = wxPyMake_wxObject(a, false); \
rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)",obj)); \
Py_DECREF(obj); \
} \
wxPyEndBlockThreads(blocked); \
if (! found) \
rval = PCLASS::CBNAME(a); \
return rval; \
}
//---------------------------------------------------------------------------