1 ////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG definitions for the new wxGrid and related classes
7 // Created: 17-March-2000
9 // Copyright: (c) 2000 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 #include "wx/wxPython/wxPython.h"
17 #include "wx/wxPython/pyclasses.h"
18 #include "wx/wxPython/printfw.h"
21 #include <wx/generic/gridctrl.h>
23 DECLARE_DEF_STRING(PanelNameStr);
24 DECLARE_DEF_STRING2(DateTimeFormatStr, wxT("%c"));
25 static const wxString wxPyEmptyString(wxT(""));
29 //---------------------------------------------------------------------------
32 %pythoncode { wx = core }
34 %include _grid_rename.i
36 //---------------------------------------------------------------------------
37 // OOR related typemaps and helper functions
39 %typemap(out) wxGridCellRenderer* { $result = wxPyMake_wxGridCellRenderer($1); }
40 %typemap(out) wxGridCellEditor* { $result = wxPyMake_wxGridCellEditor($1); }
41 %typemap(out) wxGridCellAttr* { $result = wxPyMake_wxGridCellAttr($1); }
42 %typemap(out) wxGridCellAttrProvider* { $result = wxPyMake_wxGridCellAttrProvider($1); }
43 %typemap(out) wxGridTableBase* { $result = wxPyMake_wxGridTableBase($1); }
48 #define wxPyMake_TEMPLATE(TYPE) \
49 PyObject* wxPyMake_##TYPE(TYPE* source) { \
50 PyObject* target = NULL; \
52 /* Check if there is already a pointer to a Python object in the \
53 OOR data that we can use. */ \
54 wxPyOORClientData* data = (wxPyOORClientData*)source->GetClientObject(); \
56 target = data->m_obj; \
59 /* Otherwise make a new wrapper for it the old fashioned way and \
60 give it the OOR treatment */ \
62 target = wxPyConstructObject(source, wxT(#TYPE), FALSE); \
64 source->SetClientObject(new wxPyOORClientData(target)); \
66 } else { /* source was NULL so return None. */ \
67 Py_INCREF(Py_None); target = Py_None; \
73 wxPyMake_TEMPLATE(wxGridCellRenderer)
74 wxPyMake_TEMPLATE(wxGridCellEditor)
75 wxPyMake_TEMPLATE(wxGridCellAttr)
76 wxPyMake_TEMPLATE(wxGridCellAttrProvider)
77 wxPyMake_TEMPLATE(wxGridTableBase)
81 //---------------------------------------------------------------------------
82 // Macros, similar to what's in helpers.h, to aid in the creation of
83 // virtual methods that are able to make callbacks to Python. Many of these
84 // are specific to wxGrid and so are kept here to reduce the mess in helpers.h
89 #define PYCALLBACK_GCA_INTINTKIND(PCLASS, CBNAME) \
90 wxGridCellAttr* CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
91 wxGridCellAttr* rval = NULL; \
93 wxPyBeginBlockThreads(); \
94 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
96 wxGridCellAttr* ptr; \
97 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iii)", a, b, c)); \
99 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxGridCellAttr"))) \
104 wxPyEndBlockThreads(); \
106 rval = PCLASS::CBNAME(a, b, c); \
109 wxGridCellAttr *base_##CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
110 return PCLASS::CBNAME(a, b, c); \
115 #define PYCALLBACK__GCAINTINT(PCLASS, CBNAME) \
116 void CBNAME(wxGridCellAttr *attr, int a, int b) { \
117 wxPyBeginBlockThreads(); \
119 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
120 PyObject* obj = wxPyMake_wxGridCellAttr(attr); \
121 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oii)", obj, a, b)); \
124 wxPyEndBlockThreads(); \
126 PCLASS::CBNAME(attr, a, b); \
128 void base_##CBNAME(wxGridCellAttr *attr, int a, int b) { \
129 PCLASS::CBNAME(attr, a, b); \
134 #define PYCALLBACK__GCAINT(PCLASS, CBNAME) \
135 void CBNAME(wxGridCellAttr *attr, int val) { \
136 wxPyBeginBlockThreads(); \
138 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
139 PyObject* obj = wxPyMake_wxGridCellAttr(attr); \
140 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, val)); \
143 wxPyEndBlockThreads(); \
145 PCLASS::CBNAME(attr, val); \
147 void base_##CBNAME(wxGridCellAttr *attr, int val) { \
148 PCLASS::CBNAME(attr, val); \
153 #define PYCALLBACK_INT__pure(CBNAME) \
155 wxPyBeginBlockThreads(); \
157 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
158 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
159 wxPyEndBlockThreads(); \
165 #define PYCALLBACK_BOOL_INTINT_pure(CBNAME) \
166 bool CBNAME(int a, int b) { \
167 wxPyBeginBlockThreads(); \
169 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
170 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
171 wxPyEndBlockThreads(); \
176 #define PYCALLBACK_STRING_INTINT_pure(CBNAME) \
177 wxString CBNAME(int a, int b) { \
178 wxPyBeginBlockThreads(); \
180 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
182 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
184 rval = Py2wxString(ro); \
188 wxPyEndBlockThreads(); \
193 #define PYCALLBACK__INTINTSTRING_pure(CBNAME) \
194 void CBNAME(int a, int b, const wxString& c) { \
195 wxPyBeginBlockThreads(); \
196 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
197 PyObject* s = wx2PyString(c); \
198 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,s));\
201 wxPyEndBlockThreads(); \
205 #define PYCALLBACK_STRING_INTINT(PCLASS, CBNAME) \
206 wxString CBNAME(int a, int b) { \
208 wxPyBeginBlockThreads(); \
210 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
212 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
214 rval = Py2wxString(ro); \
218 wxPyEndBlockThreads(); \
220 rval = PCLASS::CBNAME(a, b); \
223 wxString base_##CBNAME(int a, int b) { \
224 return PCLASS::CBNAME(a, b); \
228 #define PYCALLBACK_BOOL_INTINTSTRING(PCLASS, CBNAME) \
229 bool CBNAME(int a, int b, const wxString& c) { \
232 wxPyBeginBlockThreads(); \
233 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
234 PyObject* s = wx2PyString(c); \
235 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,s));\
238 wxPyEndBlockThreads(); \
240 rval = PCLASS::CBNAME(a,b,c); \
243 bool base_##CBNAME(int a, int b, const wxString& c) { \
244 return PCLASS::CBNAME(a,b,c); \
250 #define PYCALLBACK_LONG_INTINT(PCLASS, CBNAME) \
251 long CBNAME(int a, int b) { \
254 wxPyBeginBlockThreads(); \
255 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
256 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
257 wxPyEndBlockThreads(); \
259 rval = PCLASS::CBNAME(a,b); \
262 long base_##CBNAME(int a, int b) { \
263 return PCLASS::CBNAME(a,b); \
268 #define PYCALLBACK_BOOL_INTINT(PCLASS, CBNAME) \
269 bool CBNAME(int a, int b) { \
272 wxPyBeginBlockThreads(); \
273 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
274 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
275 wxPyEndBlockThreads(); \
277 rval = PCLASS::CBNAME(a,b); \
280 bool base_##CBNAME(int a, int b) { \
281 return PCLASS::CBNAME(a,b); \
286 #define PYCALLBACK_DOUBLE_INTINT(PCLASS, CBNAME) \
287 double CBNAME(int a, int b) { \
289 wxPyBeginBlockThreads(); \
291 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
293 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
295 PyObject* str = PyObject_Str(ro); \
296 rval = PyFloat_AsDouble(str); \
297 Py_DECREF(ro); Py_DECREF(str); \
300 wxPyEndBlockThreads(); \
302 rval = PCLASS::CBNAME(a, b); \
305 double base_##CBNAME(int a, int b) { \
306 return PCLASS::CBNAME(a, b); \
311 #define PYCALLBACK__(PCLASS, CBNAME) \
314 wxPyBeginBlockThreads(); \
315 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
316 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
317 wxPyEndBlockThreads(); \
321 void base_##CBNAME() { \
328 #define PYCALLBACK_BOOL_SIZETSIZET(PCLASS, CBNAME) \
329 bool CBNAME(size_t a, size_t b) { \
332 wxPyBeginBlockThreads(); \
333 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
334 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
335 wxPyEndBlockThreads(); \
337 rval = PCLASS::CBNAME(a,b); \
340 bool base_##CBNAME(size_t a, size_t b) { \
341 return PCLASS::CBNAME(a,b); \
346 #define PYCALLBACK_BOOL_SIZET(PCLASS, CBNAME) \
347 bool CBNAME(size_t a) { \
350 wxPyBeginBlockThreads(); \
351 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
352 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)", a)); \
353 wxPyEndBlockThreads(); \
355 rval = PCLASS::CBNAME(a); \
358 bool base_##CBNAME(size_t a) { \
359 return PCLASS::CBNAME(a); \
363 #define PYCALLBACK_STRING_INT(PCLASS, CBNAME) \
364 wxString CBNAME(int a) { \
366 wxPyBeginBlockThreads(); \
368 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
370 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(i)",a)); \
372 rval = Py2wxString(ro); \
376 wxPyEndBlockThreads(); \
378 rval = PCLASS::CBNAME(a); \
381 wxString base_##CBNAME(int a) { \
382 return PCLASS::CBNAME(a); \
386 #define PYCALLBACK__INTSTRING(PCLASS, CBNAME) \
387 void CBNAME(int a, const wxString& c) { \
389 wxPyBeginBlockThreads(); \
390 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
391 PyObject* s = wx2PyString(c); \
392 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)",a,s)); \
395 wxPyEndBlockThreads(); \
397 PCLASS::CBNAME(a,c); \
399 void base_##CBNAME(int a, const wxString& c) { \
400 PCLASS::CBNAME(a,c); \
406 #define PYCALLBACK_BOOL_(PCLASS, CBNAME) \
410 wxPyBeginBlockThreads(); \
411 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
412 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
413 wxPyEndBlockThreads(); \
415 rval = PCLASS::CBNAME(); \
418 bool base_##CBNAME() { \
419 return PCLASS::CBNAME(); \
424 #define PYCALLBACK__SIZETINT(PCLASS, CBNAME) \
425 void CBNAME(size_t a, int b) { \
427 wxPyBeginBlockThreads(); \
428 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
429 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
430 wxPyEndBlockThreads(); \
432 PCLASS::CBNAME(a,b); \
434 void base_##CBNAME(size_t a, int b) { \
435 PCLASS::CBNAME(a,b); \
441 #define PYCALLBACK__INTINTLONG(PCLASS, CBNAME) \
442 void CBNAME(int a, int b, long c) { \
444 wxPyBeginBlockThreads(); \
445 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
446 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
447 wxPyEndBlockThreads(); \
449 PCLASS::CBNAME(a,b,c); \
451 void base_##CBNAME(int a, int b, long c) { \
452 PCLASS::CBNAME(a,b,c); \
458 #define PYCALLBACK__INTINTDOUBLE(PCLASS, CBNAME) \
459 void CBNAME(int a, int b, double c) { \
461 wxPyBeginBlockThreads(); \
462 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
463 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iif)", a,b,c)); \
464 wxPyEndBlockThreads(); \
466 PCLASS::CBNAME(a,b,c); \
468 void base_##CBNAME(int a, int b, double c) { \
469 PCLASS::CBNAME(a,b,c); \
474 #define PYCALLBACK__INTINTBOOL(PCLASS, CBNAME) \
475 void CBNAME(int a, int b, bool c) { \
477 wxPyBeginBlockThreads(); \
478 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
479 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
480 wxPyEndBlockThreads(); \
482 PCLASS::CBNAME(a,b,c); \
484 void base_##CBNAME(int a, int b, bool c) { \
485 PCLASS::CBNAME(a,b,c); \
493 //---------------------------------------------------------------------------
495 class wxGridCellCoords;
496 class wxGridCellAttr;
498 #define wxGRID_VALUE_STRING "string"
499 #define wxGRID_VALUE_BOOL "bool"
500 #define wxGRID_VALUE_NUMBER "long"
501 #define wxGRID_VALUE_FLOAT "double"
502 #define wxGRID_VALUE_CHOICE "choice"
503 #define wxGRID_VALUE_TEXT "string"
504 #define wxGRID_VALUE_LONG "long"
505 #define wxGRID_VALUE_CHOICEINT "choiceint"
506 #define wxGRID_VALUE_DATETIME "datetime"
510 const wxGridCellCoords wxGridNoCellCoords;
511 const wxRect wxGridNoCellRect;
515 //---------------------------------------------------------------------------
516 // wxGridCellRenderer is an ABC, and several derived classes are available.
517 // Classes implemented in Python should be derived from wxPyGridCellRenderer.
520 class wxGridCellRenderer
524 void _setOORInfo(PyObject* _self) {
525 self->SetClientObject(new wxPyOORClientData(_self));
529 void SetParameters(const wxString& params);
533 virtual void Draw(wxGrid& grid,
534 wxGridCellAttr& attr,
539 virtual wxSize GetBestSize(wxGrid& grid,
540 wxGridCellAttr& attr,
543 virtual wxGridCellRenderer *Clone() const;
547 // The C++ version of wxPyGridCellRenderer
549 class wxPyGridCellRenderer : public wxGridCellRenderer
552 wxPyGridCellRenderer() : wxGridCellRenderer() {};
554 // Implement Python callback aware virtual methods
555 void Draw(wxGrid& grid, wxGridCellAttr& attr,
556 wxDC& dc, const wxRect& rect,
557 int row, int col, bool isSelected) {
558 wxPyBeginBlockThreads();
559 if (wxPyCBH_findCallback(m_myInst, "Draw")) {
560 PyObject* go = wxPyMake_wxObject(&grid);
561 PyObject* dco = wxPyMake_wxObject(&dc);
562 PyObject* ao = wxPyMake_wxGridCellAttr(&attr);
563 PyObject* ro = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
565 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOOOiii)", go, ao, dco, ro,
566 row, col, isSelected));
572 wxPyEndBlockThreads();
575 wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
578 wxPyBeginBlockThreads();
579 if (wxPyCBH_findCallback(m_myInst, "GetBestSize")) {
582 PyObject* go = wxPyMake_wxObject(&grid);
583 PyObject* dco = wxPyMake_wxObject(&dc);
584 PyObject* ao = wxPyMake_wxGridCellAttr(&attr);
586 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OOOii)",
594 const char* errmsg = "GetBestSize should return a 2-tuple of integers or a wxSize object.";
595 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxSize"))) {
598 else if (PySequence_Check(ro) && PyObject_Length(ro) == 2) {
599 PyObject* o1 = PySequence_GetItem(ro, 0);
600 PyObject* o2 = PySequence_GetItem(ro, 1);
601 if (PyNumber_Check(o1) && PyNumber_Check(o2))
602 rval = wxSize(PyInt_AsLong(o1), PyInt_AsLong(o2));
604 PyErr_SetString(PyExc_TypeError, errmsg);
609 PyErr_SetString(PyExc_TypeError, errmsg);
614 wxPyEndBlockThreads();
619 wxGridCellRenderer *Clone() const {
620 wxGridCellRenderer* rval = NULL;
621 wxPyBeginBlockThreads();
622 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
624 wxGridCellRenderer* ptr;
625 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
627 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxGridCellRenderer")))
632 wxPyEndBlockThreads();
636 DEC_PYCALLBACK__STRING(SetParameters);
641 IMP_PYCALLBACK__STRING( wxPyGridCellRenderer, wxGridCellRenderer, SetParameters);
646 // Let SWIG know about it so it can create the Python version
647 class wxPyGridCellRenderer : public wxGridCellRenderer {
649 %addtofunc wxPyGridCellRenderer "self._setCallbackInfo(self, PyGridCellRenderer);self._setOORInfo(self)"
651 wxPyGridCellRenderer();
652 void _setCallbackInfo(PyObject* self, PyObject* _class);
654 void base_SetParameters(const wxString& params);
657 //---------------------------------------------------------------------------
658 // Predefined Renderers
660 class wxGridCellStringRenderer : public wxGridCellRenderer
663 %addtofunc wxGridCellStringRenderer "self._setOORInfo(self)"
664 wxGridCellStringRenderer();
668 class wxGridCellNumberRenderer : public wxGridCellStringRenderer
671 %addtofunc wxGridCellNumberRenderer "self._setOORInfo(self)"
672 wxGridCellNumberRenderer();
676 class wxGridCellFloatRenderer : public wxGridCellStringRenderer
679 %addtofunc wxGridCellFloatRenderer "self._setOORInfo(self)"
680 wxGridCellFloatRenderer(int width = -1, int precision = -1);
682 int GetWidth() const;
683 void SetWidth(int width);
684 int GetPrecision() const;
685 void SetPrecision(int precision);
689 class wxGridCellBoolRenderer : public wxGridCellRenderer
692 %addtofunc wxGridCellBoolRenderer "self._setOORInfo(self)"
693 wxGridCellBoolRenderer();
697 class wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
700 %addtofunc wxGridCellDateTimeRenderer "self._setOORInfo(self)"
701 wxGridCellDateTimeRenderer(wxString outformat = wxPyDateTimeFormatStr,
702 wxString informat = wxPyDateTimeFormatStr);
706 class wxGridCellEnumRenderer : public wxGridCellStringRenderer
709 %addtofunc wxGridCellEnumRenderer "self._setOORInfo(self)"
710 wxGridCellEnumRenderer( const wxString& choices = wxPyEmptyString );
714 class wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer
717 %addtofunc wxGridCellAutoWrapStringRenderer "self._setOORInfo(self)"
718 wxGridCellAutoWrapStringRenderer();
722 //---------------------------------------------------------------------------
723 // wxGridCellEditor is an ABC, and several derived classes are available.
724 // Classes implemented in Python should be derived from wxPyGridCellEditor.
726 class wxGridCellEditor
730 void _setOORInfo(PyObject* _self) {
731 self->SetClientObject(new wxPyOORClientData(_self));
736 wxControl* GetControl();
737 void SetControl(wxControl* control);
739 wxGridCellAttr* GetCellAttr();
740 void SetCellAttr(wxGridCellAttr* attr);
742 void SetParameters(const wxString& params);
746 virtual void Create(wxWindow* parent,
748 wxEvtHandler* evtHandler);
749 virtual void BeginEdit(int row, int col, wxGrid* grid);
750 virtual bool EndEdit(int row, int col, wxGrid* grid);
751 virtual void Reset();
752 virtual wxGridCellEditor *Clone() const;
754 virtual void SetSize(const wxRect& rect);
755 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
756 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
757 virtual bool IsAcceptedKey(wxKeyEvent& event);
758 virtual void StartingKey(wxKeyEvent& event);
759 virtual void StartingClick();
760 virtual void HandleReturn(wxKeyEvent& event);
761 virtual void Destroy();
766 // The C++ version of wxPyGridCellEditor
768 class wxPyGridCellEditor : public wxGridCellEditor
771 wxPyGridCellEditor() : wxGridCellEditor() {}
773 void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) {
774 wxPyBeginBlockThreads();
775 if (wxPyCBH_findCallback(m_myInst, "Create")) {
776 PyObject* po = wxPyMake_wxObject(parent);
777 PyObject* eo = wxPyMake_wxObject(evtHandler);
779 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OiO)", po, id, eo));
783 wxPyEndBlockThreads();
787 void BeginEdit(int row, int col, wxGrid* grid) {
788 wxPyBeginBlockThreads();
789 if (wxPyCBH_findCallback(m_myInst, "BeginEdit")) {
790 PyObject* go = wxPyMake_wxObject(grid);
791 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", row, col, go));
794 wxPyEndBlockThreads();
798 bool EndEdit(int row, int col, wxGrid* grid) {
800 wxPyBeginBlockThreads();
801 if (wxPyCBH_findCallback(m_myInst, "EndEdit")) {
802 PyObject* go = wxPyMake_wxObject(grid);
803 rv = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", row, col, go));
806 wxPyEndBlockThreads();
811 wxGridCellEditor* Clone() const {
812 wxGridCellEditor* rval = NULL;
813 wxPyBeginBlockThreads();
814 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
816 wxGridCellEditor* ptr;
817 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
819 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxGridCellEditor")))
824 wxPyEndBlockThreads();
829 void Show(bool show, wxGridCellAttr *attr) {
831 wxPyBeginBlockThreads();
832 if ((found = wxPyCBH_findCallback(m_myInst, "Show"))) {
833 PyObject* ao = wxPyMake_wxGridCellAttr(attr);
834 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", show, ao));
837 wxPyEndBlockThreads();
839 wxGridCellEditor::Show(show, attr);
841 void base_Show(bool show, wxGridCellAttr *attr) {
842 wxGridCellEditor::Show(show, attr);
846 void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
848 wxPyBeginBlockThreads();
849 if ((found = wxPyCBH_findCallback(m_myInst, "PaintBackground)"))) {
850 PyObject* ao = wxPyMake_wxGridCellAttr(attr);
851 PyObject* ro = wxPyConstructObject((void*)&rectCell, wxT("wxRect"), 0);
853 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", ro, ao));
858 wxPyEndBlockThreads();
860 wxGridCellEditor::PaintBackground(rectCell, attr);
862 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
863 wxGridCellEditor::PaintBackground(rectCell, attr);
867 DEC_PYCALLBACK___pure(Reset);
868 DEC_PYCALLBACK__constany(SetSize, wxRect);
869 DEC_PYCALLBACK_bool_any(IsAcceptedKey, wxKeyEvent);
870 DEC_PYCALLBACK__any(StartingKey, wxKeyEvent);
871 DEC_PYCALLBACK__any(HandleReturn, wxKeyEvent);
872 DEC_PYCALLBACK__(StartingClick);
873 DEC_PYCALLBACK__(Destroy);
874 DEC_PYCALLBACK__STRING(SetParameters);
875 DEC_PYCALLBACK_STRING__constpure(GetValue);
881 IMP_PYCALLBACK__STRING( wxPyGridCellEditor, wxGridCellEditor, SetParameters);
882 IMP_PYCALLBACK___pure(wxPyGridCellEditor, wxGridCellEditor, Reset);
883 IMP_PYCALLBACK__constany(wxPyGridCellEditor, wxGridCellEditor, SetSize, wxRect);
884 IMP_PYCALLBACK_bool_any(wxPyGridCellEditor, wxGridCellEditor, IsAcceptedKey, wxKeyEvent);
885 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, StartingKey, wxKeyEvent);
886 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, HandleReturn, wxKeyEvent);
887 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, StartingClick);
888 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, Destroy);
889 IMP_PYCALLBACK_STRING__constpure(wxPyGridCellEditor, wxGridCellEditor, GetValue);
894 // Let SWIG know about it so it can create the Python version
895 class wxPyGridCellEditor : public wxGridCellEditor {
897 %addtofunc wxPyGridCellEditor "self._setCallbackInfo(self, PyGridCellEditor);self._setOORInfo(self)"
899 wxPyGridCellEditor();
900 void _setCallbackInfo(PyObject* self, PyObject* _class);
902 void base_SetSize(const wxRect& rect);
903 void base_Show(bool show, wxGridCellAttr *attr = NULL);
904 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
905 bool base_IsAcceptedKey(wxKeyEvent& event);
906 void base_StartingKey(wxKeyEvent& event);
907 void base_StartingClick();
908 void base_HandleReturn(wxKeyEvent& event);
910 void base_SetParameters(const wxString& params);
913 //---------------------------------------------------------------------------
914 // Predefined Editors
916 class wxGridCellTextEditor : public wxGridCellEditor
919 %addtofunc wxGridCellTextEditor "self._setOORInfo(self)"
920 wxGridCellTextEditor();
921 virtual wxString GetValue();
925 class wxGridCellNumberEditor : public wxGridCellTextEditor
928 %addtofunc wxGridCellNumberEditor "self._setOORInfo(self)"
929 wxGridCellNumberEditor(int min = -1, int max = -1);
930 virtual wxString GetValue();
934 class wxGridCellFloatEditor : public wxGridCellTextEditor
937 %addtofunc wxGridCellFloatEditor "self._setOORInfo(self)"
938 wxGridCellFloatEditor();
939 virtual wxString GetValue();
943 class wxGridCellBoolEditor : public wxGridCellEditor
946 %addtofunc wxGridCellBoolEditor "self._setOORInfo(self)"
947 wxGridCellBoolEditor();
948 virtual wxString GetValue();
951 class wxGridCellChoiceEditor : public wxGridCellEditor
954 %addtofunc wxGridCellChoiceEditor "self._setOORInfo(self)"
955 wxGridCellChoiceEditor(int LCOUNT = 0,
956 const wxString* choices = NULL,
957 bool allowOthers = FALSE);
958 virtual wxString GetValue();
962 class wxGridCellEnumEditor : public wxGridCellChoiceEditor
965 %addtofunc wxGridCellEnumEditor "self._setOORInfo(self)"
966 wxGridCellEnumEditor( const wxString& choices = wxPyEmptyString );
967 virtual wxString GetValue();
971 class wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
974 %addtofunc wxGridCellAutoWrapStringEditor "self._setOORInfo(self)"
975 wxGridCellAutoWrapStringEditor();
976 virtual wxString GetValue();
981 //---------------------------------------------------------------------------
998 void _setOORInfo(PyObject* _self) {
999 self->SetClientObject(new wxPyOORClientData(_self));
1003 %addtofunc wxGridCellAttr "self._setOORInfo(self)"
1005 wxGridCellAttr(wxGridCellAttr *attrDefault = NULL);
1007 wxGridCellAttr *Clone() const;
1008 void MergeWith(wxGridCellAttr *mergefrom);
1011 void SetTextColour(const wxColour& colText);
1012 void SetBackgroundColour(const wxColour& colBack);
1013 void SetFont(const wxFont& font);
1014 void SetAlignment(int hAlign, int vAlign);
1015 void SetSize(int num_rows, int num_cols);
1016 void SetOverflow( bool allow = TRUE );
1017 void SetReadOnly(bool isReadOnly = TRUE);
1019 void SetRenderer(wxGridCellRenderer *renderer);
1020 void SetEditor(wxGridCellEditor* editor);
1021 void SetKind(wxAttrKind kind);
1023 bool HasTextColour() const;
1024 bool HasBackgroundColour() const;
1025 bool HasFont() const;
1026 bool HasAlignment() const;
1027 bool HasRenderer() const;
1028 bool HasEditor() const;
1029 bool HasReadWriteMode() const;
1030 bool HasOverflowMode() const;
1032 wxColour GetTextColour() const;
1033 wxColour GetBackgroundColour() const;
1034 wxFont GetFont() const;
1035 void GetAlignment(int *OUTPUT, int *OUTPUT) const;
1036 void GetSize(int *OUTPUT, int *OUTPUT) const;
1037 bool GetOverflow() const;
1038 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
1039 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
1041 bool IsReadOnly() const;
1042 void SetDefAttr(wxGridCellAttr* defAttr);
1045 //---------------------------------------------------------------------------
1047 class wxGridCellAttrProvider
1050 %addtofunc wxGridCellAttrProvider "self._setOORInfo(self)"
1051 wxGridCellAttrProvider();
1052 // ???? virtual ~wxGridCellAttrProvider();
1055 void _setOORInfo(PyObject* _self) {
1056 self->SetClientObject(new wxPyOORClientData(_self));
1060 wxGridCellAttr *GetAttr(int row, int col,
1061 wxGridCellAttr::wxAttrKind kind) const;
1062 void SetAttr(wxGridCellAttr *attr, int row, int col);
1063 void SetRowAttr(wxGridCellAttr *attr, int row);
1064 void SetColAttr(wxGridCellAttr *attr, int col);
1066 void UpdateAttrRows( size_t pos, int numRows );
1067 void UpdateAttrCols( size_t pos, int numCols );
1072 // A Python-aware version
1074 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1077 wxPyGridCellAttrProvider() : wxGridCellAttrProvider() {};
1079 PYCALLBACK_GCA_INTINTKIND(wxGridCellAttrProvider, GetAttr);
1080 PYCALLBACK__GCAINTINT(wxGridCellAttrProvider, SetAttr);
1081 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetRowAttr);
1082 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetColAttr);
1089 // The python-aware version get's SWIGified
1090 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1093 %addtofunc wxPyGridCellAttrProvider "self._setCallbackInfo(self, PyGridCellAttrProvider)"
1094 wxPyGridCellAttrProvider();
1095 void _setCallbackInfo(PyObject* self, PyObject* _class);
1097 wxGridCellAttr *base_GetAttr(int row, int col,
1098 wxGridCellAttr::wxAttrKind kind);
1099 void base_SetAttr(wxGridCellAttr *attr, int row, int col);
1100 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1101 void base_SetColAttr(wxGridCellAttr *attr, int col);
1105 //---------------------------------------------------------------------------
1106 // Grid Table Base class and Python aware version
1109 class wxGridTableBase : public wxObject
1112 // wxGridTableBase(); This is an ABC
1113 //~wxGridTableBase();
1116 void _setOORInfo(PyObject* _self) {
1117 self->SetClientObject(new wxPyOORClientData(_self));
1121 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
1122 wxGridCellAttrProvider *GetAttrProvider() const;
1123 void SetView( wxGrid *grid );
1124 wxGrid * GetView() const;
1128 virtual int GetNumberRows();
1129 virtual int GetNumberCols();
1130 virtual bool IsEmptyCell( int row, int col );
1131 virtual wxString GetValue( int row, int col );
1132 virtual void SetValue( int row, int col, const wxString& value );
1134 // virtuals overridable in wxPyGridTableBase
1135 virtual wxString GetTypeName( int row, int col );
1136 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
1137 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
1138 virtual long GetValueAsLong( int row, int col );
1139 virtual double GetValueAsDouble( int row, int col );
1140 virtual bool GetValueAsBool( int row, int col );
1141 virtual void SetValueAsLong( int row, int col, long value );
1142 virtual void SetValueAsDouble( int row, int col, double value );
1143 virtual void SetValueAsBool( int row, int col, bool value );
1145 //virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
1146 //virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
1149 virtual void Clear();
1150 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
1151 virtual bool AppendRows( size_t numRows = 1 );
1152 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
1153 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
1154 virtual bool AppendCols( size_t numCols = 1 );
1155 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
1157 virtual wxString GetRowLabelValue( int row );
1158 virtual wxString GetColLabelValue( int col );
1159 virtual void SetRowLabelValue( int row, const wxString& value );
1160 virtual void SetColLabelValue( int col, const wxString& value );
1162 virtual bool CanHaveAttributes();
1164 virtual wxGridCellAttr *GetAttr( int row, int col,
1165 wxGridCellAttr::wxAttrKind kind);
1166 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
1167 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
1168 virtual void SetColAttr(wxGridCellAttr *attr, int col);
1174 // Python-aware version
1176 class wxPyGridTableBase : public wxGridTableBase
1179 wxPyGridTableBase() : wxGridTableBase() {}
1181 PYCALLBACK_INT__pure(GetNumberRows);
1182 PYCALLBACK_INT__pure(GetNumberCols);
1183 PYCALLBACK_BOOL_INTINT_pure(IsEmptyCell);
1184 PYCALLBACK_STRING_INTINT(wxGridTableBase, GetTypeName);
1185 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanGetValueAs);
1186 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanSetValueAs);
1187 PYCALLBACK__(wxGridTableBase, Clear);
1188 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertRows);
1189 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteRows);
1190 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertCols);
1191 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteCols);
1192 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendRows);
1193 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendCols);
1194 PYCALLBACK_STRING_INT(wxGridTableBase, GetRowLabelValue);
1195 PYCALLBACK_STRING_INT(wxGridTableBase, GetColLabelValue);
1196 PYCALLBACK__INTSTRING(wxGridTableBase, SetRowLabelValue);
1197 PYCALLBACK__INTSTRING(wxGridTableBase, SetColLabelValue);
1198 PYCALLBACK_BOOL_(wxGridTableBase, CanHaveAttributes);
1199 PYCALLBACK_GCA_INTINTKIND(wxGridTableBase, GetAttr);
1200 PYCALLBACK__GCAINTINT(wxGridTableBase, SetAttr);
1201 PYCALLBACK__GCAINT(wxGridTableBase, SetRowAttr);
1202 PYCALLBACK__GCAINT(wxGridTableBase, SetColAttr);
1205 wxString GetValue(int row, int col) {
1206 wxPyBeginBlockThreads();
1208 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1210 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",row,col));
1212 rval = Py2wxString(ro);
1216 wxPyEndBlockThreads();
1220 void SetValue(int row, int col, const wxString& val) {
1221 wxPyBeginBlockThreads();
1222 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1223 PyObject* s = wx2PyString(val);
1224 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",row,col,s));
1227 wxPyEndBlockThreads();
1231 // Map the Get/Set methods for the standard non-string types to
1232 // the GetValue and SetValue python methods.
1233 long GetValueAsLong( int row, int col ) {
1235 wxPyBeginBlockThreads();
1236 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1239 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1240 if (ro && PyNumber_Check(ro)) {
1241 num = PyNumber_Int(ro);
1243 rval = PyInt_AsLong(num);
1249 wxPyEndBlockThreads();
1253 double GetValueAsDouble( int row, int col ) {
1255 wxPyBeginBlockThreads();
1256 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1259 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1260 if (ro && PyNumber_Check(ro)) {
1261 num = PyNumber_Float(ro);
1263 rval = PyFloat_AsDouble(num);
1269 wxPyEndBlockThreads();
1273 bool GetValueAsBool( int row, int col ) {
1274 return (bool)GetValueAsLong(row, col);
1277 void SetValueAsLong( int row, int col, long value ) {
1278 wxPyBeginBlockThreads();
1279 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1280 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", row, col, value));
1282 wxPyEndBlockThreads();
1285 void SetValueAsDouble( int row, int col, double value ) {
1286 wxPyBeginBlockThreads();
1287 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1288 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iid)", row, col, value));
1290 wxPyEndBlockThreads();
1293 void SetValueAsBool( int row, int col, bool value ) {
1294 SetValueAsLong( row, col, (long)value );
1303 // The python-aware version get's SWIGified
1304 class wxPyGridTableBase : public wxGridTableBase
1307 %addtofunc wxPyGridTableBase "self._setCallbackInfo(self, PyGridTableBase);self._setOORInfo(self)"
1308 wxPyGridTableBase();
1309 void _setCallbackInfo(PyObject* self, PyObject* _class);
1311 %extend { void Destroy() { delete self; } }
1313 wxString base_GetTypeName( int row, int col );
1314 bool base_CanGetValueAs( int row, int col, const wxString& typeName );
1315 bool base_CanSetValueAs( int row, int col, const wxString& typeName );
1317 bool base_InsertRows( size_t pos = 0, size_t numRows = 1 );
1318 bool base_AppendRows( size_t numRows = 1 );
1319 bool base_DeleteRows( size_t pos = 0, size_t numRows = 1 );
1320 bool base_InsertCols( size_t pos = 0, size_t numCols = 1 );
1321 bool base_AppendCols( size_t numCols = 1 );
1322 bool base_DeleteCols( size_t pos = 0, size_t numCols = 1 );
1323 wxString base_GetRowLabelValue( int row );
1324 wxString base_GetColLabelValue( int col );
1325 void base_SetRowLabelValue( int row, const wxString& value );
1326 void base_SetColLabelValue( int col, const wxString& value );
1327 bool base_CanHaveAttributes();
1328 wxGridCellAttr *base_GetAttr( int row, int col,
1329 wxGridCellAttr::wxAttrKind kind );
1330 void base_SetAttr(wxGridCellAttr* attr, int row, int col);
1331 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1332 void base_SetColAttr(wxGridCellAttr *attr, int col);
1336 //---------------------------------------------------------------------------
1337 // Predefined Tables
1339 class wxGridStringTable : public wxGridTableBase
1342 %addtofunc wxGridStringTable "self._setOORInfo(self)"
1343 wxGridStringTable( int numRows=0, int numCols=0 );
1346 //---------------------------------------------------------------------------
1347 // The Table can pass messages to the grid to tell it to update itself if
1348 // something has changed.
1350 enum wxGridTableRequest
1352 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
1353 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
1354 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
1355 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
1356 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
1357 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1358 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
1359 wxGRIDTABLE_NOTIFY_COLS_DELETED
1363 class wxGridTableMessage
1366 wxGridTableMessage( wxGridTableBase *table, int id,
1369 ~wxGridTableMessage();
1371 void SetTableObject( wxGridTableBase *table );
1372 wxGridTableBase * GetTableObject() const;
1373 void SetId( int id );
1375 void SetCommandInt( int comInt1 );
1376 int GetCommandInt();
1377 void SetCommandInt2( int comInt2 );
1378 int GetCommandInt2();
1382 //---------------------------------------------------------------------------
1385 class wxGridCellCoords
1388 wxGridCellCoords( int r=-1, int c=-1 );
1389 ~wxGridCellCoords();
1392 void SetRow( int n );
1394 void SetCol( int n );
1395 void Set( int row, int col );
1397 bool operator==( const wxGridCellCoords& other ) const;
1398 bool operator!=( const wxGridCellCoords& other ) const;
1401 PyObject* asTuple() {
1402 PyObject* tup = PyTuple_New(2);
1403 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
1404 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
1409 def __str__(self): return str(self.asTuple())
1410 def __repr__(self): return 'wxGridCellCoords'+str(self.asTuple())
1411 def __len__(self): return len(self.asTuple())
1412 def __getitem__(self, index): return self.asTuple()[index]
1413 def __setitem__(self, index, val):
1414 if index == 0: self.SetRow(val)
1415 elif index == 1: self.SetCol(val)
1416 else: raise IndexError
1421 // Typemap to allow conversion of sequence objects to wxGridCellCoords...
1422 %typemap(in) wxGridCellCoords& (wxGridCellCoords temp) {
1424 if (! wxGridCellCoords_helper($input, &$1)) SWIG_fail;
1426 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxGridCellCoords& {
1427 $1 = wxGridCellCoords_typecheck($input);
1431 // ...and here is the associated helper.
1433 bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) {
1435 // If source is an object instance then it may already be the right type
1436 if (wxPySwigInstance_Check(source)) {
1437 wxGridCellCoords* ptr;
1438 if (! wxPyConvertSwigPtr(source, (void **)&ptr, wxT("wxGridCellCoords")))
1443 // otherwise a 2-tuple of integers is expected
1444 else if (PySequence_Check(source) && PyObject_Length(source) == 2) {
1445 PyObject* o1 = PySequence_GetItem(source, 0);
1446 PyObject* o2 = PySequence_GetItem(source, 1);
1447 if (!PyNumber_Check(o1) || !PyNumber_Check(o2)) {
1452 **obj = wxGridCellCoords(PyInt_AsLong(o1), PyInt_AsLong(o2));
1459 PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of integers or a wxGridCellCoords object.");
1464 bool wxGridCellCoords_typecheck(PyObject* source) {
1467 if (wxPySwigInstance_Check(source) &&
1468 wxPyConvertSwigPtr(source, (void **)&ptr, wxT("wxGridCellCoords")))
1472 if (PySequence_Check(source) && PySequence_Length(source) == 2)
1480 // Typemap to convert an array of cells coords to a list of tuples...
1481 %typemap(out) wxGridCellCoordsArray {
1482 $result = wxGridCellCoordsArray_helper($1);
1485 // %typemap(ret) wxGridCellCoordsArray {
1490 // ...and the helper function for the above typemap.
1492 PyObject* wxGridCellCoordsArray_helper(const wxGridCellCoordsArray& source)
1494 PyObject* list = PyList_New(0);
1496 for (idx = 0; idx < source.GetCount(); idx += 1) {
1497 wxGridCellCoords& coord = source.Item(idx);
1498 PyObject* tup = PyTuple_New(2);
1499 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(coord.GetRow()));
1500 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(coord.GetCol()));
1501 PyList_Append(list, tup);
1508 //---------------------------------------------------------------------------
1509 //---------------------------------------------------------------------------
1513 // Fool SWIG into treating this enum as an int
1514 typedef int WXGRIDSELECTIONMODES;
1516 // but let the C++ code know what it really is.
1518 typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES;
1523 class wxGrid : public wxScrolledWindow
1526 %addtofunc wxGrid "self._setOORInfo(self)"
1528 wxGrid( wxWindow *parent,
1530 const wxPoint& pos = wxDefaultPosition,
1531 const wxSize& size = wxDefaultSize,
1532 long style = wxWANTS_CHARS,
1533 const wxString& name = wxPyPanelNameStr);
1536 enum wxGridSelectionModes {wxGridSelectCells,
1538 wxGridSelectColumns};
1540 bool CreateGrid( int numRows, int numCols,
1541 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1542 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1543 WXGRIDSELECTIONMODES GetSelectionMode();
1546 // ------ grid dimensions
1548 int GetNumberRows();
1549 int GetNumberCols();
1552 bool ProcessTableMessage( wxGridTableMessage& );
1555 wxGridTableBase * GetTable() const;
1556 bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE,
1557 WXGRIDSELECTIONMODES selmode =
1558 wxGrid::wxGridSelectCells );
1561 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1562 bool AppendRows( int numRows = 1, bool updateLabels=TRUE );
1563 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1564 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1565 bool AppendCols( int numCols = 1, bool updateLabels=TRUE );
1566 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1569 // this function is called when the current cell highlight must be redrawn
1570 // and may be overridden by the user
1571 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1574 // ------ Cell text drawing functions
1576 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1577 int horizontalAlignment = wxLEFT,
1578 int verticalAlignment = wxTOP,
1579 int textOrientation = wxHORIZONTAL );
1581 // // Split a string containing newline chararcters into an array of
1582 // // strings and return the number of lines
1584 // void StringToLines( const wxString& value, wxArrayString& lines );
1586 void GetTextBoxSize( wxDC& dc,
1587 wxArrayString& lines,
1588 long *OUTPUT, long *OUTPUT );
1592 // Code that does a lot of grid modification can be enclosed
1593 // between BeginBatch() and EndBatch() calls to avoid screen
1598 int GetBatchCount();
1599 void ForceRefresh();
1600 void Refresh(bool eraseb=TRUE, const wxRect* rect= NULL);
1603 // ------ edit control functions
1606 void EnableEditing( bool edit );
1608 void EnableCellEditControl( bool enable = TRUE );
1609 void DisableCellEditControl();
1610 bool CanEnableCellControl() const;
1611 bool IsCellEditControlEnabled() const;
1612 bool IsCellEditControlShown() const;
1614 bool IsCurrentCellReadOnly() const;
1616 void ShowCellEditControl();
1617 void HideCellEditControl();
1618 void SaveEditControlValue();
1621 // ------ grid location functions
1622 // Note that all of these functions work with the logical coordinates of
1623 // grid cells and labels so you will need to convert from device
1624 // coordinates for mouse events etc.
1627 //void XYToCell( int x, int y, wxGridCellCoords& );
1629 wxGridCellCoords XYToCell(int x, int y) {
1630 wxGridCellCoords rv;
1631 self->XYToCell(x, y, rv);
1636 int YToRow( int y );
1637 int XToCol( int x );
1639 int YToEdgeOfRow( int y );
1640 int XToEdgeOfCol( int x );
1642 wxRect CellToRect( int row, int col );
1643 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1646 int GetGridCursorRow();
1647 int GetGridCursorCol();
1649 // check to see if a cell is either wholly visible (the default arg) or
1650 // at least partially visible in the grid window
1652 bool IsVisible( int row, int col, bool wholeCellVisible = TRUE );
1653 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE );
1654 void MakeCellVisible( int row, int col );
1655 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1658 // ------ grid cursor movement functions
1660 void SetGridCursor( int row, int col );
1661 bool MoveCursorUp( bool expandSelection );
1662 bool MoveCursorDown( bool expandSelection );
1663 bool MoveCursorLeft( bool expandSelection );
1664 bool MoveCursorRight( bool expandSelection );
1665 bool MovePageDown();
1667 bool MoveCursorUpBlock( bool expandSelection );
1668 bool MoveCursorDownBlock( bool expandSelection );
1669 bool MoveCursorLeftBlock( bool expandSelection );
1670 bool MoveCursorRightBlock( bool expandSelection );
1673 // ------ label and gridline formatting
1675 int GetDefaultRowLabelSize();
1676 int GetRowLabelSize();
1677 int GetDefaultColLabelSize();
1678 int GetColLabelSize();
1679 wxColour GetLabelBackgroundColour();
1680 wxColour GetLabelTextColour();
1681 wxFont GetLabelFont();
1682 void GetRowLabelAlignment( int *OUTPUT, int *OUTPUT );
1683 void GetColLabelAlignment( int *OUTPUT, int *OUTPUT );
1684 int GetColLabelTextOrientation();
1685 wxString GetRowLabelValue( int row );
1686 wxString GetColLabelValue( int col );
1687 wxColour GetGridLineColour();
1688 wxColour GetCellHighlightColour();
1689 int GetCellHighlightPenWidth();
1690 int GetCellHighlightROPenWidth();
1692 void SetRowLabelSize( int width );
1693 void SetColLabelSize( int height );
1694 void SetLabelBackgroundColour( const wxColour& );
1695 void SetLabelTextColour( const wxColour& );
1696 void SetLabelFont( const wxFont& );
1697 void SetRowLabelAlignment( int horiz, int vert );
1698 void SetColLabelAlignment( int horiz, int vert );
1699 void SetColLabelTextOrientation( int textOrientation );
1700 void SetRowLabelValue( int row, const wxString& );
1701 void SetColLabelValue( int col, const wxString& );
1702 void SetGridLineColour( const wxColour& );
1703 void SetCellHighlightColour( const wxColour& );
1704 void SetCellHighlightPenWidth(int width);
1705 void SetCellHighlightROPenWidth(int width);
1707 void EnableDragRowSize( bool enable = TRUE );
1708 void DisableDragRowSize();
1709 bool CanDragRowSize();
1710 void EnableDragColSize( bool enable = TRUE );
1711 void DisableDragColSize();
1712 bool CanDragColSize();
1713 void EnableDragGridSize(bool enable = TRUE);
1714 void DisableDragGridSize();
1715 bool CanDragGridSize();
1717 // this sets the specified attribute for all cells in this row/col
1718 void SetAttr(int row, int col, wxGridCellAttr *attr);
1719 void SetRowAttr(int row, wxGridCellAttr *attr);
1720 void SetColAttr(int col, wxGridCellAttr *attr);
1722 // shortcuts for setting the column parameters
1724 // set the format for the data in the column: default is string
1725 void SetColFormatBool(int col);
1726 void SetColFormatNumber(int col);
1727 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1728 void SetColFormatCustom(int col, const wxString& typeName);
1730 void EnableGridLines( bool enable = TRUE );
1731 bool GridLinesEnabled();
1733 // ------ row and col formatting
1735 int GetDefaultRowSize();
1736 int GetRowSize( int row );
1737 int GetDefaultColSize();
1738 int GetColSize( int col );
1739 wxColour GetDefaultCellBackgroundColour();
1740 wxColour GetCellBackgroundColour( int row, int col );
1741 wxColour GetDefaultCellTextColour();
1742 wxColour GetCellTextColour( int row, int col );
1743 wxFont GetDefaultCellFont();
1744 wxFont GetCellFont( int row, int col );
1745 void GetDefaultCellAlignment( int *OUTPUT, int *OUTPUT );
1746 void GetCellAlignment( int row, int col, int *OUTPUT, int *OUTPUT );
1747 bool GetDefaultCellOverflow();
1748 bool GetCellOverflow( int row, int col );
1749 void GetCellSize( int row, int col, int *OUTPUT, int *OUTPUT );
1751 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
1752 void SetRowSize( int row, int height );
1753 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
1755 void SetColSize( int col, int width );
1757 // automatically size the column or row to fit to its contents, if
1758 // setAsMin is TRUE, this optimal width will also be set as minimal width
1760 void AutoSizeColumn( int col, bool setAsMin = TRUE );
1761 void AutoSizeRow( int row, bool setAsMin = TRUE );
1764 // auto size all columns (very ineffective for big grids!)
1765 void AutoSizeColumns( bool setAsMin = TRUE );
1766 void AutoSizeRows( bool setAsMin = TRUE );
1768 // auto size the grid, that is make the columns/rows of the "right" size
1769 // and also set the grid size to just fit its contents
1772 // autosize row height depending on label text
1773 void AutoSizeRowLabelSize( int row );
1775 // autosize column width depending on label text
1776 void AutoSizeColLabelSize( int col );
1779 // column won't be resized to be lesser width - this must be called during
1780 // the grid creation because it won't resize the column if it's already
1781 // narrower than the minimal width
1782 void SetColMinimalWidth( int col, int width );
1783 void SetRowMinimalHeight( int row, int width );
1785 void SetColMinimalAcceptableWidth( int width );
1786 void SetRowMinimalAcceptableHeight( int width );
1787 int GetColMinimalAcceptableWidth() const;
1788 int GetRowMinimalAcceptableHeight() const;
1790 void SetDefaultCellBackgroundColour( const wxColour& );
1791 void SetCellBackgroundColour( int row, int col, const wxColour& );
1792 void SetDefaultCellTextColour( const wxColour& );
1794 void SetCellTextColour( int row, int col, const wxColour& );
1795 void SetDefaultCellFont( const wxFont& );
1796 void SetCellFont( int row, int col, const wxFont& );
1797 void SetDefaultCellAlignment( int horiz, int vert );
1798 void SetCellAlignment( int row, int col, int horiz, int vert );
1799 void SetDefaultCellOverflow( bool allow );
1800 void SetCellOverflow( int row, int col, bool allow );
1801 void SetCellSize( int row, int col, int num_rows, int num_cols );
1803 // takes ownership of the pointer
1804 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1805 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1806 wxGridCellRenderer *GetDefaultRenderer() const;
1807 wxGridCellRenderer* GetCellRenderer(int row, int col);
1809 // takes ownership of the pointer
1810 void SetDefaultEditor(wxGridCellEditor *editor);
1811 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1812 wxGridCellEditor *GetDefaultEditor() const;
1813 wxGridCellEditor* GetCellEditor(int row, int col);
1817 // ------ cell value accessors
1819 wxString GetCellValue( int row, int col );
1820 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1822 void SetCellValue( int row, int col, const wxString& s );
1823 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1825 // returns TRUE if the cell can't be edited
1826 bool IsReadOnly(int row, int col) const;
1828 // make the cell editable/readonly
1829 void SetReadOnly(int row, int col, bool isReadOnly = TRUE);
1831 // ------ selections of blocks of cells
1833 void SelectRow( int row, bool addToSelected = FALSE );
1834 void SelectCol( int col, bool addToSelected = FALSE );
1836 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1837 bool addToSelected = FALSE );
1838 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1839 // TODO: ??? const wxGridCellCoords& bottomRight )
1843 void ClearSelection();
1844 bool IsInSelection( int row, int col );
1845 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1847 const wxGridCellCoordsArray GetSelectedCells() const;
1848 const wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
1849 const wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
1850 const wxArrayInt GetSelectedRows() const;
1851 const wxArrayInt GetSelectedCols() const;
1853 void DeselectRow( int row );
1854 void DeselectCol( int col );
1855 void DeselectCell( int row, int col );
1858 // This function returns the rectangle that encloses the block of cells
1859 // limited by TopLeft and BottomRight cell in device coords and clipped
1860 // to the client size of the grid window.
1862 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1863 const wxGridCellCoords & bottomRight );
1866 // Access or update the selection fore/back colours
1867 wxColour GetSelectionBackground() const;
1868 wxColour GetSelectionForeground() const;
1870 void SetSelectionBackground(const wxColour& c);
1871 void SetSelectionForeground(const wxColour& c);
1874 // Methods for a registry for mapping data types to Renderers/Editors
1875 void RegisterDataType(const wxString& typeName,
1876 wxGridCellRenderer* renderer,
1877 wxGridCellEditor* editor);
1878 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1879 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1880 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1881 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1882 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1884 // grid may occupy more space than needed for its rows/columns, this
1885 // function allows to set how big this extra space is
1886 void SetMargins(int extraWidth, int extraHeight);
1889 // Accessors for component windows
1890 wxWindow* GetGridWindow();
1891 wxWindow* GetGridRowLabelWindow();
1892 wxWindow* GetGridColLabelWindow();
1893 wxWindow* GetGridCornerLabelWindow();
1899 //---------------------------------------------------------------------------
1900 //---------------------------------------------------------------------------
1901 // Grid events and stuff
1905 class wxGridEvent : public wxNotifyEvent
1908 wxGridEvent(int id, wxEventType type, wxGrid* obj,
1909 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = TRUE,
1910 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1912 virtual int GetRow();
1913 virtual int GetCol();
1914 wxPoint GetPosition();
1924 class wxGridSizeEvent : public wxNotifyEvent
1927 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
1928 int rowOrCol=-1, int x=-1, int y=-1,
1929 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1932 wxPoint GetPosition();
1941 class wxGridRangeSelectEvent : public wxNotifyEvent
1944 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
1945 const wxGridCellCoords& topLeft,
1946 const wxGridCellCoords& bottomRight,
1948 bool control=FALSE, bool shift=FALSE,
1949 bool alt=FALSE, bool meta=FALSE);
1951 wxGridCellCoords GetTopLeftCoords();
1952 wxGridCellCoords GetBottomRightCoords();
1965 class wxGridEditorCreatedEvent : public wxCommandEvent {
1967 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
1968 int row, int col, wxControl* ctrl);
1972 wxControl* GetControl();
1973 void SetRow(int row);
1974 void SetCol(int col);
1975 void SetControl(wxControl* ctrl);
1980 %constant wxEventType wxEVT_GRID_CELL_LEFT_CLICK;
1981 %constant wxEventType wxEVT_GRID_CELL_RIGHT_CLICK;
1982 %constant wxEventType wxEVT_GRID_CELL_LEFT_DCLICK;
1983 %constant wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK;
1984 %constant wxEventType wxEVT_GRID_LABEL_LEFT_CLICK;
1985 %constant wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK;
1986 %constant wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK;
1987 %constant wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK;
1988 %constant wxEventType wxEVT_GRID_ROW_SIZE;
1989 %constant wxEventType wxEVT_GRID_COL_SIZE;
1990 %constant wxEventType wxEVT_GRID_RANGE_SELECT;
1991 %constant wxEventType wxEVT_GRID_CELL_CHANGE;
1992 %constant wxEventType wxEVT_GRID_SELECT_CELL;
1993 %constant wxEventType wxEVT_GRID_EDITOR_SHOWN;
1994 %constant wxEventType wxEVT_GRID_EDITOR_HIDDEN;
1995 %constant wxEventType wxEVT_GRID_EDITOR_CREATED;
2000 EVT_GRID_CELL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_CLICK )
2001 EVT_GRID_CELL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_CLICK )
2002 EVT_GRID_CELL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_DCLICK )
2003 EVT_GRID_CELL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_DCLICK )
2004 EVT_GRID_LABEL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_CLICK )
2005 EVT_GRID_LABEL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_CLICK )
2006 EVT_GRID_LABEL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_DCLICK )
2007 EVT_GRID_LABEL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_DCLICK )
2008 EVT_GRID_ROW_SIZE = wx.PyEventBinder( wxEVT_GRID_ROW_SIZE )
2009 EVT_GRID_COL_SIZE = wx.PyEventBinder( wxEVT_GRID_COL_SIZE )
2010 EVT_GRID_RANGE_SELECT = wx.PyEventBinder( wxEVT_GRID_RANGE_SELECT )
2011 EVT_GRID_CELL_CHANGE = wx.PyEventBinder( wxEVT_GRID_CELL_CHANGE )
2012 EVT_GRID_SELECT_CELL = wx.PyEventBinder( wxEVT_GRID_SELECT_CELL )
2013 EVT_GRID_EDITOR_SHOWN = wx.PyEventBinder( wxEVT_GRID_EDITOR_SHOWN )
2014 EVT_GRID_EDITOR_HIDDEN = wx.PyEventBinder( wxEVT_GRID_EDITOR_HIDDEN )
2015 EVT_GRID_EDITOR_CREATED = wx.PyEventBinder( wxEVT_GRID_EDITOR_CREATED )
2018 //---------------------------------------------------------------------------
2023 //---------------------------------------------------------------------------
2024 //---------------------------------------------------------------------------