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 /////////////////////////////////////////////////////////////////////////////
14 "Classes for implementing a spreadsheet-like control."
16 %module(docstring=DOCSTRING) grid
20 #include "wx/wxPython/wxPython.h"
21 #include "wx/wxPython/pyclasses.h"
22 #include "wx/wxPython/printfw.h"
25 #include <wx/generic/gridctrl.h>
30 //---------------------------------------------------------------------------
33 %pythoncode { wx = _core }
34 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
37 %include _grid_rename.i
39 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
40 MAKE_CONST_WXSTRING_NOSWIG(PanelNameStr);
41 MAKE_CONST_WXSTRING2(DateTimeFormatStr, wxT("%c"));
44 //---------------------------------------------------------------------------
45 // OOR related typemaps and helper functions
47 %typemap(out) wxGridCellRenderer* { $result = wxPyMake_wxGridCellRenderer($1); }
48 %typemap(out) wxGridCellEditor* { $result = wxPyMake_wxGridCellEditor($1); }
49 %typemap(out) wxGridCellAttr* { $result = wxPyMake_wxGridCellAttr($1); }
50 %typemap(out) wxGridCellAttrProvider* { $result = wxPyMake_wxGridCellAttrProvider($1); }
51 %typemap(out) wxGridTableBase* { $result = wxPyMake_wxGridTableBase($1); }
56 #define wxPyMake_TEMPLATE(TYPE) \
57 PyObject* wxPyMake_##TYPE(TYPE* source) { \
58 PyObject* target = NULL; \
60 /* Check if there is already a pointer to a Python object in the \
61 OOR data that we can use. */ \
62 wxPyOORClientData* data = (wxPyOORClientData*)source->GetClientObject(); \
64 target = data->m_obj; \
67 /* Otherwise make a new wrapper for it the old fashioned way and \
68 give it the OOR treatment */ \
70 target = wxPyConstructObject(source, wxT(#TYPE), False); \
72 source->SetClientObject(new wxPyOORClientData(target)); \
74 } else { /* source was NULL so return None. */ \
75 Py_INCREF(Py_None); target = Py_None; \
81 wxPyMake_TEMPLATE(wxGridCellRenderer)
82 wxPyMake_TEMPLATE(wxGridCellEditor)
83 wxPyMake_TEMPLATE(wxGridCellAttr)
84 wxPyMake_TEMPLATE(wxGridCellAttrProvider)
85 wxPyMake_TEMPLATE(wxGridTableBase)
89 //---------------------------------------------------------------------------
90 // Macros, similar to what's in helpers.h, to aid in the creation of
91 // virtual methods that are able to make callbacks to Python. Many of these
92 // are specific to wxGrid and so are kept here to reduce the mess in helpers.h
97 #define PYCALLBACK_GCA_INTINTKIND(PCLASS, CBNAME) \
98 wxGridCellAttr* CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
99 wxGridCellAttr* rval = NULL; \
101 bool blocked = wxPyBeginBlockThreads(); \
102 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
104 wxGridCellAttr* ptr; \
105 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iii)", a, b, c)); \
107 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxGridCellAttr"))) \
112 wxPyEndBlockThreads(blocked); \
114 rval = PCLASS::CBNAME(a, b, c); \
117 wxGridCellAttr *base_##CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
118 return PCLASS::CBNAME(a, b, c); \
123 #define PYCALLBACK__GCAINTINT(PCLASS, CBNAME) \
124 void CBNAME(wxGridCellAttr *attr, int a, int b) { \
125 bool blocked = wxPyBeginBlockThreads(); \
127 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
128 PyObject* obj = wxPyMake_wxGridCellAttr(attr); \
129 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oii)", obj, a, b)); \
132 wxPyEndBlockThreads(blocked); \
134 PCLASS::CBNAME(attr, a, b); \
136 void base_##CBNAME(wxGridCellAttr *attr, int a, int b) { \
137 PCLASS::CBNAME(attr, a, b); \
142 #define PYCALLBACK__GCAINT(PCLASS, CBNAME) \
143 void CBNAME(wxGridCellAttr *attr, int val) { \
144 bool blocked = wxPyBeginBlockThreads(); \
146 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
147 PyObject* obj = wxPyMake_wxGridCellAttr(attr); \
148 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, val)); \
151 wxPyEndBlockThreads(blocked); \
153 PCLASS::CBNAME(attr, val); \
155 void base_##CBNAME(wxGridCellAttr *attr, int val) { \
156 PCLASS::CBNAME(attr, val); \
161 #define PYCALLBACK_INT__pure(CBNAME) \
163 bool blocked = wxPyBeginBlockThreads(); \
165 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
166 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
167 wxPyEndBlockThreads(blocked); \
173 #define PYCALLBACK_BOOL_INTINT_pure(CBNAME) \
174 bool CBNAME(int a, int b) { \
175 bool blocked = wxPyBeginBlockThreads(); \
177 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
178 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
179 wxPyEndBlockThreads(blocked); \
184 #define PYCALLBACK_STRING_INTINT_pure(CBNAME) \
185 wxString CBNAME(int a, int b) { \
186 bool blocked = wxPyBeginBlockThreads(); \
188 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
190 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
192 rval = Py2wxString(ro); \
196 wxPyEndBlockThreads(blocked); \
201 #define PYCALLBACK__INTINTSTRING_pure(CBNAME) \
202 void CBNAME(int a, int b, const wxString& c) { \
203 bool blocked = wxPyBeginBlockThreads(); \
204 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
205 PyObject* s = wx2PyString(c); \
206 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,s));\
209 wxPyEndBlockThreads(blocked); \
213 #define PYCALLBACK_STRING_INTINT(PCLASS, CBNAME) \
214 wxString CBNAME(int a, int b) { \
216 bool blocked = wxPyBeginBlockThreads(); \
218 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
220 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
222 rval = Py2wxString(ro); \
226 wxPyEndBlockThreads(blocked); \
228 rval = PCLASS::CBNAME(a, b); \
231 wxString base_##CBNAME(int a, int b) { \
232 return PCLASS::CBNAME(a, b); \
236 #define PYCALLBACK_BOOL_INTINTSTRING(PCLASS, CBNAME) \
237 bool CBNAME(int a, int b, const wxString& c) { \
240 bool blocked = wxPyBeginBlockThreads(); \
241 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
242 PyObject* s = wx2PyString(c); \
243 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,s));\
246 wxPyEndBlockThreads(blocked); \
248 rval = PCLASS::CBNAME(a,b,c); \
251 bool base_##CBNAME(int a, int b, const wxString& c) { \
252 return PCLASS::CBNAME(a,b,c); \
258 #define PYCALLBACK_LONG_INTINT(PCLASS, CBNAME) \
259 long CBNAME(int a, int b) { \
262 bool blocked = wxPyBeginBlockThreads(); \
263 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
264 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
265 wxPyEndBlockThreads(blocked); \
267 rval = PCLASS::CBNAME(a,b); \
270 long base_##CBNAME(int a, int b) { \
271 return PCLASS::CBNAME(a,b); \
276 #define PYCALLBACK_BOOL_INTINT(PCLASS, CBNAME) \
277 bool CBNAME(int a, int b) { \
280 bool blocked = wxPyBeginBlockThreads(); \
281 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
282 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
283 wxPyEndBlockThreads(blocked); \
285 rval = PCLASS::CBNAME(a,b); \
288 bool base_##CBNAME(int a, int b) { \
289 return PCLASS::CBNAME(a,b); \
294 #define PYCALLBACK_DOUBLE_INTINT(PCLASS, CBNAME) \
295 double CBNAME(int a, int b) { \
297 bool blocked = wxPyBeginBlockThreads(); \
299 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
301 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
303 PyObject* str = PyObject_Str(ro); \
304 rval = PyFloat_AsDouble(str); \
305 Py_DECREF(ro); Py_DECREF(str); \
308 wxPyEndBlockThreads(blocked); \
310 rval = PCLASS::CBNAME(a, b); \
313 double base_##CBNAME(int a, int b) { \
314 return PCLASS::CBNAME(a, b); \
319 #define PYCALLBACK__(PCLASS, CBNAME) \
322 bool blocked = wxPyBeginBlockThreads(); \
323 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
324 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
325 wxPyEndBlockThreads(blocked); \
329 void base_##CBNAME() { \
336 #define PYCALLBACK_BOOL_SIZETSIZET(PCLASS, CBNAME) \
337 bool CBNAME(size_t a, size_t b) { \
340 bool blocked = wxPyBeginBlockThreads(); \
341 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
342 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
343 wxPyEndBlockThreads(blocked); \
345 rval = PCLASS::CBNAME(a,b); \
348 bool base_##CBNAME(size_t a, size_t b) { \
349 return PCLASS::CBNAME(a,b); \
354 #define PYCALLBACK_BOOL_SIZET(PCLASS, CBNAME) \
355 bool CBNAME(size_t a) { \
358 bool blocked = wxPyBeginBlockThreads(); \
359 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
360 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)", a)); \
361 wxPyEndBlockThreads(blocked); \
363 rval = PCLASS::CBNAME(a); \
366 bool base_##CBNAME(size_t a) { \
367 return PCLASS::CBNAME(a); \
371 #define PYCALLBACK_STRING_INT(PCLASS, CBNAME) \
372 wxString CBNAME(int a) { \
374 bool blocked = wxPyBeginBlockThreads(); \
376 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
378 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(i)",a)); \
380 rval = Py2wxString(ro); \
384 wxPyEndBlockThreads(blocked); \
386 rval = PCLASS::CBNAME(a); \
389 wxString base_##CBNAME(int a) { \
390 return PCLASS::CBNAME(a); \
394 #define PYCALLBACK__INTSTRING(PCLASS, CBNAME) \
395 void CBNAME(int a, const wxString& c) { \
397 bool blocked = wxPyBeginBlockThreads(); \
398 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
399 PyObject* s = wx2PyString(c); \
400 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)",a,s)); \
403 wxPyEndBlockThreads(blocked); \
405 PCLASS::CBNAME(a,c); \
407 void base_##CBNAME(int a, const wxString& c) { \
408 PCLASS::CBNAME(a,c); \
414 #define PYCALLBACK_BOOL_(PCLASS, CBNAME) \
418 bool blocked = wxPyBeginBlockThreads(); \
419 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
420 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
421 wxPyEndBlockThreads(blocked); \
423 rval = PCLASS::CBNAME(); \
426 bool base_##CBNAME() { \
427 return PCLASS::CBNAME(); \
432 #define PYCALLBACK__SIZETINT(PCLASS, CBNAME) \
433 void CBNAME(size_t a, int b) { \
435 bool blocked = wxPyBeginBlockThreads(); \
436 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
437 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
438 wxPyEndBlockThreads(blocked); \
440 PCLASS::CBNAME(a,b); \
442 void base_##CBNAME(size_t a, int b) { \
443 PCLASS::CBNAME(a,b); \
449 #define PYCALLBACK__INTINTLONG(PCLASS, CBNAME) \
450 void CBNAME(int a, int b, long c) { \
452 bool blocked = wxPyBeginBlockThreads(); \
453 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
454 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
455 wxPyEndBlockThreads(blocked); \
457 PCLASS::CBNAME(a,b,c); \
459 void base_##CBNAME(int a, int b, long c) { \
460 PCLASS::CBNAME(a,b,c); \
466 #define PYCALLBACK__INTINTDOUBLE(PCLASS, CBNAME) \
467 void CBNAME(int a, int b, double c) { \
469 bool blocked = wxPyBeginBlockThreads(); \
470 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
471 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iif)", a,b,c)); \
472 wxPyEndBlockThreads(blocked); \
474 PCLASS::CBNAME(a,b,c); \
476 void base_##CBNAME(int a, int b, double c) { \
477 PCLASS::CBNAME(a,b,c); \
482 #define PYCALLBACK__INTINTBOOL(PCLASS, CBNAME) \
483 void CBNAME(int a, int b, bool c) { \
485 bool blocked = wxPyBeginBlockThreads(); \
486 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
487 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
488 wxPyEndBlockThreads(blocked); \
490 PCLASS::CBNAME(a,b,c); \
492 void base_##CBNAME(int a, int b, bool c) { \
493 PCLASS::CBNAME(a,b,c); \
501 //---------------------------------------------------------------------------
503 class wxGridCellCoords;
504 class wxGridCellAttr;
506 #define wxGRID_VALUE_STRING "string"
507 #define wxGRID_VALUE_BOOL "bool"
508 #define wxGRID_VALUE_NUMBER "long"
509 #define wxGRID_VALUE_FLOAT "double"
510 #define wxGRID_VALUE_CHOICE "choice"
511 #define wxGRID_VALUE_TEXT "string"
512 #define wxGRID_VALUE_LONG "long"
513 #define wxGRID_VALUE_CHOICEINT "choiceint"
514 #define wxGRID_VALUE_DATETIME "datetime"
518 const wxGridCellCoords wxGridNoCellCoords;
519 const wxRect wxGridNoCellRect;
523 //---------------------------------------------------------------------------
524 // wxGridCellRenderer is an ABC, and several derived classes are available.
525 // Classes implemented in Python should be derived from wxPyGridCellRenderer.
528 class wxGridCellRenderer
532 void _setOORInfo(PyObject* _self) {
533 self->SetClientObject(new wxPyOORClientData(_self));
537 void SetParameters(const wxString& params);
541 virtual void Draw(wxGrid& grid,
542 wxGridCellAttr& attr,
547 virtual wxSize GetBestSize(wxGrid& grid,
548 wxGridCellAttr& attr,
551 virtual wxGridCellRenderer *Clone() const;
555 // The C++ version of wxPyGridCellRenderer
557 class wxPyGridCellRenderer : public wxGridCellRenderer
560 wxPyGridCellRenderer() : wxGridCellRenderer() {};
562 // Implement Python callback aware virtual methods
563 void Draw(wxGrid& grid, wxGridCellAttr& attr,
564 wxDC& dc, const wxRect& rect,
565 int row, int col, bool isSelected) {
566 bool blocked = wxPyBeginBlockThreads();
567 if (wxPyCBH_findCallback(m_myInst, "Draw")) {
568 PyObject* go = wxPyMake_wxObject(&grid);
569 PyObject* dco = wxPyMake_wxObject(&dc);
570 PyObject* ao = wxPyMake_wxGridCellAttr(&attr);
571 PyObject* ro = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
573 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOOOiii)", go, ao, dco, ro,
574 row, col, isSelected));
580 wxPyEndBlockThreads(blocked);
583 wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
586 bool blocked = wxPyBeginBlockThreads();
587 if (wxPyCBH_findCallback(m_myInst, "GetBestSize")) {
590 PyObject* go = wxPyMake_wxObject(&grid);
591 PyObject* dco = wxPyMake_wxObject(&dc);
592 PyObject* ao = wxPyMake_wxGridCellAttr(&attr);
594 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OOOii)",
602 const char* errmsg = "GetBestSize should return a 2-tuple of integers or a wxSize object.";
603 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxSize"))) {
606 else if (PySequence_Check(ro) && PyObject_Length(ro) == 2) {
607 PyObject* o1 = PySequence_GetItem(ro, 0);
608 PyObject* o2 = PySequence_GetItem(ro, 1);
609 if (PyNumber_Check(o1) && PyNumber_Check(o2))
610 rval = wxSize(PyInt_AsLong(o1), PyInt_AsLong(o2));
612 PyErr_SetString(PyExc_TypeError, errmsg);
617 PyErr_SetString(PyExc_TypeError, errmsg);
622 wxPyEndBlockThreads(blocked);
627 wxGridCellRenderer *Clone() const {
628 wxGridCellRenderer* rval = NULL;
629 bool blocked = wxPyBeginBlockThreads();
630 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
632 wxGridCellRenderer* ptr;
633 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
635 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxGridCellRenderer")))
640 wxPyEndBlockThreads(blocked);
644 DEC_PYCALLBACK__STRING(SetParameters);
649 IMP_PYCALLBACK__STRING( wxPyGridCellRenderer, wxGridCellRenderer, SetParameters);
654 // Let SWIG know about it so it can create the Python version
655 class wxPyGridCellRenderer : public wxGridCellRenderer {
657 %pythonAppend wxPyGridCellRenderer "self._setCallbackInfo(self, PyGridCellRenderer);self._setOORInfo(self)"
659 wxPyGridCellRenderer();
660 void _setCallbackInfo(PyObject* self, PyObject* _class);
662 void base_SetParameters(const wxString& params);
665 //---------------------------------------------------------------------------
666 // Predefined Renderers
668 class wxGridCellStringRenderer : public wxGridCellRenderer
671 %pythonAppend wxGridCellStringRenderer "self._setOORInfo(self)"
672 wxGridCellStringRenderer();
676 class wxGridCellNumberRenderer : public wxGridCellStringRenderer
679 %pythonAppend wxGridCellNumberRenderer "self._setOORInfo(self)"
680 wxGridCellNumberRenderer();
684 class wxGridCellFloatRenderer : public wxGridCellStringRenderer
687 %pythonAppend wxGridCellFloatRenderer "self._setOORInfo(self)"
688 wxGridCellFloatRenderer(int width = -1, int precision = -1);
690 int GetWidth() const;
691 void SetWidth(int width);
692 int GetPrecision() const;
693 void SetPrecision(int precision);
697 class wxGridCellBoolRenderer : public wxGridCellRenderer
700 %pythonAppend wxGridCellBoolRenderer "self._setOORInfo(self)"
701 wxGridCellBoolRenderer();
705 class wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
708 %pythonAppend wxGridCellDateTimeRenderer "self._setOORInfo(self)"
709 wxGridCellDateTimeRenderer(wxString outformat = wxPyDateTimeFormatStr,
710 wxString informat = wxPyDateTimeFormatStr);
714 class wxGridCellEnumRenderer : public wxGridCellStringRenderer
717 %pythonAppend wxGridCellEnumRenderer "self._setOORInfo(self)"
718 wxGridCellEnumRenderer( const wxString& choices = wxPyEmptyString );
722 class wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer
725 %pythonAppend wxGridCellAutoWrapStringRenderer "self._setOORInfo(self)"
726 wxGridCellAutoWrapStringRenderer();
730 //---------------------------------------------------------------------------
731 // wxGridCellEditor is an ABC, and several derived classes are available.
732 // Classes implemented in Python should be derived from wxPyGridCellEditor.
734 class wxGridCellEditor
738 void _setOORInfo(PyObject* _self) {
739 self->SetClientObject(new wxPyOORClientData(_self));
744 wxControl* GetControl();
745 void SetControl(wxControl* control);
747 wxGridCellAttr* GetCellAttr();
748 void SetCellAttr(wxGridCellAttr* attr);
750 void SetParameters(const wxString& params);
754 virtual void Create(wxWindow* parent,
756 wxEvtHandler* evtHandler);
757 virtual void BeginEdit(int row, int col, wxGrid* grid);
758 virtual bool EndEdit(int row, int col, wxGrid* grid);
759 virtual void Reset();
760 virtual wxGridCellEditor *Clone() const;
762 virtual void SetSize(const wxRect& rect);
763 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
764 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
765 virtual bool IsAcceptedKey(wxKeyEvent& event);
766 virtual void StartingKey(wxKeyEvent& event);
767 virtual void StartingClick();
768 virtual void HandleReturn(wxKeyEvent& event);
769 virtual void Destroy();
774 // The C++ version of wxPyGridCellEditor
776 class wxPyGridCellEditor : public wxGridCellEditor
779 wxPyGridCellEditor() : wxGridCellEditor() {}
781 void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) {
782 bool blocked = wxPyBeginBlockThreads();
783 if (wxPyCBH_findCallback(m_myInst, "Create")) {
784 PyObject* po = wxPyMake_wxObject(parent);
785 PyObject* eo = wxPyMake_wxObject(evtHandler);
787 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OiO)", po, id, eo));
791 wxPyEndBlockThreads(blocked);
795 void BeginEdit(int row, int col, wxGrid* grid) {
796 bool blocked = wxPyBeginBlockThreads();
797 if (wxPyCBH_findCallback(m_myInst, "BeginEdit")) {
798 PyObject* go = wxPyMake_wxObject(grid);
799 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", row, col, go));
802 wxPyEndBlockThreads(blocked);
806 bool EndEdit(int row, int col, wxGrid* grid) {
808 bool blocked = wxPyBeginBlockThreads();
809 if (wxPyCBH_findCallback(m_myInst, "EndEdit")) {
810 PyObject* go = wxPyMake_wxObject(grid);
811 rv = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", row, col, go));
814 wxPyEndBlockThreads(blocked);
819 wxGridCellEditor* Clone() const {
820 wxGridCellEditor* rval = NULL;
821 bool blocked = wxPyBeginBlockThreads();
822 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
824 wxGridCellEditor* ptr;
825 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
827 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxGridCellEditor")))
832 wxPyEndBlockThreads(blocked);
837 void Show(bool show, wxGridCellAttr *attr) {
839 bool blocked = wxPyBeginBlockThreads();
840 if ((found = wxPyCBH_findCallback(m_myInst, "Show"))) {
841 PyObject* ao = wxPyMake_wxGridCellAttr(attr);
842 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", show, ao));
845 wxPyEndBlockThreads(blocked);
847 wxGridCellEditor::Show(show, attr);
849 void base_Show(bool show, wxGridCellAttr *attr) {
850 wxGridCellEditor::Show(show, attr);
854 void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
856 bool blocked = wxPyBeginBlockThreads();
857 if ((found = wxPyCBH_findCallback(m_myInst, "PaintBackground)"))) {
858 PyObject* ao = wxPyMake_wxGridCellAttr(attr);
859 PyObject* ro = wxPyConstructObject((void*)&rectCell, wxT("wxRect"), 0);
861 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", ro, ao));
866 wxPyEndBlockThreads(blocked);
868 wxGridCellEditor::PaintBackground(rectCell, attr);
870 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
871 wxGridCellEditor::PaintBackground(rectCell, attr);
875 DEC_PYCALLBACK___pure(Reset);
876 DEC_PYCALLBACK__constany(SetSize, wxRect);
877 DEC_PYCALLBACK_bool_any(IsAcceptedKey, wxKeyEvent);
878 DEC_PYCALLBACK__any(StartingKey, wxKeyEvent);
879 DEC_PYCALLBACK__any(HandleReturn, wxKeyEvent);
880 DEC_PYCALLBACK__(StartingClick);
881 DEC_PYCALLBACK__(Destroy);
882 DEC_PYCALLBACK__STRING(SetParameters);
883 DEC_PYCALLBACK_STRING__constpure(GetValue);
889 IMP_PYCALLBACK__STRING( wxPyGridCellEditor, wxGridCellEditor, SetParameters);
890 IMP_PYCALLBACK___pure(wxPyGridCellEditor, wxGridCellEditor, Reset);
891 IMP_PYCALLBACK__constany(wxPyGridCellEditor, wxGridCellEditor, SetSize, wxRect);
892 IMP_PYCALLBACK_bool_any(wxPyGridCellEditor, wxGridCellEditor, IsAcceptedKey, wxKeyEvent);
893 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, StartingKey, wxKeyEvent);
894 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, HandleReturn, wxKeyEvent);
895 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, StartingClick);
896 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, Destroy);
897 IMP_PYCALLBACK_STRING__constpure(wxPyGridCellEditor, wxGridCellEditor, GetValue);
902 // Let SWIG know about it so it can create the Python version
903 class wxPyGridCellEditor : public wxGridCellEditor {
905 %pythonAppend wxPyGridCellEditor "self._setCallbackInfo(self, PyGridCellEditor);self._setOORInfo(self)"
907 wxPyGridCellEditor();
908 void _setCallbackInfo(PyObject* self, PyObject* _class);
910 void base_SetSize(const wxRect& rect);
911 void base_Show(bool show, wxGridCellAttr *attr = NULL);
912 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
913 bool base_IsAcceptedKey(wxKeyEvent& event);
914 void base_StartingKey(wxKeyEvent& event);
915 void base_StartingClick();
916 void base_HandleReturn(wxKeyEvent& event);
918 void base_SetParameters(const wxString& params);
921 //---------------------------------------------------------------------------
922 // Predefined Editors
924 class wxGridCellTextEditor : public wxGridCellEditor
927 %pythonAppend wxGridCellTextEditor "self._setOORInfo(self)"
928 wxGridCellTextEditor();
929 virtual wxString GetValue();
933 class wxGridCellNumberEditor : public wxGridCellTextEditor
936 %pythonAppend wxGridCellNumberEditor "self._setOORInfo(self)"
937 wxGridCellNumberEditor(int min = -1, int max = -1);
938 virtual wxString GetValue();
942 class wxGridCellFloatEditor : public wxGridCellTextEditor
945 %pythonAppend wxGridCellFloatEditor "self._setOORInfo(self)"
946 wxGridCellFloatEditor(int width = -1, int precision = -1);
947 virtual wxString GetValue();
951 class wxGridCellBoolEditor : public wxGridCellEditor
954 %pythonAppend wxGridCellBoolEditor "self._setOORInfo(self)"
955 wxGridCellBoolEditor();
956 virtual wxString GetValue();
959 class wxGridCellChoiceEditor : public wxGridCellEditor
962 %pythonAppend wxGridCellChoiceEditor "self._setOORInfo(self)"
963 wxGridCellChoiceEditor(int choices = 0,
964 const wxString* choices_array = NULL,
965 bool allowOthers = False);
966 virtual wxString GetValue();
970 class wxGridCellEnumEditor : public wxGridCellChoiceEditor
973 %pythonAppend wxGridCellEnumEditor "self._setOORInfo(self)"
974 wxGridCellEnumEditor( const wxString& choices = wxPyEmptyString );
975 virtual wxString GetValue();
979 class wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
982 %pythonAppend wxGridCellAutoWrapStringEditor "self._setOORInfo(self)"
983 wxGridCellAutoWrapStringEditor();
984 virtual wxString GetValue();
989 //---------------------------------------------------------------------------
1006 void _setOORInfo(PyObject* _self) {
1007 self->SetClientObject(new wxPyOORClientData(_self));
1011 %pythonAppend wxGridCellAttr "self._setOORInfo(self)"
1013 wxGridCellAttr(wxGridCellAttr *attrDefault = NULL);
1015 wxGridCellAttr *Clone() const;
1016 void MergeWith(wxGridCellAttr *mergefrom);
1019 void SetTextColour(const wxColour& colText);
1020 void SetBackgroundColour(const wxColour& colBack);
1021 void SetFont(const wxFont& font);
1022 void SetAlignment(int hAlign, int vAlign);
1023 void SetSize(int num_rows, int num_cols);
1024 void SetOverflow( bool allow = True );
1025 void SetReadOnly(bool isReadOnly = True);
1027 void SetRenderer(wxGridCellRenderer *renderer);
1028 void SetEditor(wxGridCellEditor* editor);
1029 void SetKind(wxAttrKind kind);
1031 bool HasTextColour() const;
1032 bool HasBackgroundColour() const;
1033 bool HasFont() const;
1034 bool HasAlignment() const;
1035 bool HasRenderer() const;
1036 bool HasEditor() const;
1037 bool HasReadWriteMode() const;
1038 bool HasOverflowMode() const;
1040 wxColour GetTextColour() const;
1041 wxColour GetBackgroundColour() const;
1042 wxFont GetFont() const;
1045 void, GetAlignment(int *OUTPUT, int *OUTPUT) const,
1046 "GetAlignment() -> (hAlign, vAlign)");
1049 void, GetSize(int *OUTPUT, int *OUTPUT) const,
1050 "GetSize() -> (num_rows, num_cols)");
1052 bool GetOverflow() const;
1053 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
1054 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
1056 bool IsReadOnly() const;
1057 void SetDefAttr(wxGridCellAttr* defAttr);
1060 //---------------------------------------------------------------------------
1062 class wxGridCellAttrProvider
1065 %pythonAppend wxGridCellAttrProvider "self._setOORInfo(self)"
1066 wxGridCellAttrProvider();
1067 // ???? virtual ~wxGridCellAttrProvider();
1070 void _setOORInfo(PyObject* _self) {
1071 self->SetClientObject(new wxPyOORClientData(_self));
1075 wxGridCellAttr *GetAttr(int row, int col,
1076 wxGridCellAttr::wxAttrKind kind) const;
1077 void SetAttr(wxGridCellAttr *attr, int row, int col);
1078 void SetRowAttr(wxGridCellAttr *attr, int row);
1079 void SetColAttr(wxGridCellAttr *attr, int col);
1081 void UpdateAttrRows( size_t pos, int numRows );
1082 void UpdateAttrCols( size_t pos, int numCols );
1087 // A Python-aware version
1089 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1092 wxPyGridCellAttrProvider() : wxGridCellAttrProvider() {};
1094 PYCALLBACK_GCA_INTINTKIND(wxGridCellAttrProvider, GetAttr);
1095 PYCALLBACK__GCAINTINT(wxGridCellAttrProvider, SetAttr);
1096 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetRowAttr);
1097 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetColAttr);
1104 // The python-aware version get's SWIGified
1105 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1108 %pythonAppend wxPyGridCellAttrProvider "self._setCallbackInfo(self, PyGridCellAttrProvider)"
1109 wxPyGridCellAttrProvider();
1110 void _setCallbackInfo(PyObject* self, PyObject* _class);
1112 wxGridCellAttr *base_GetAttr(int row, int col,
1113 wxGridCellAttr::wxAttrKind kind);
1114 void base_SetAttr(wxGridCellAttr *attr, int row, int col);
1115 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1116 void base_SetColAttr(wxGridCellAttr *attr, int col);
1120 //---------------------------------------------------------------------------
1121 // Grid Table Base class and Python aware version
1124 class wxGridTableBase : public wxObject
1127 // wxGridTableBase(); This is an ABC
1128 //~wxGridTableBase();
1131 void _setOORInfo(PyObject* _self) {
1132 self->SetClientObject(new wxPyOORClientData(_self));
1136 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
1137 wxGridCellAttrProvider *GetAttrProvider() const;
1138 void SetView( wxGrid *grid );
1139 wxGrid * GetView() const;
1143 virtual int GetNumberRows();
1144 virtual int GetNumberCols();
1145 virtual bool IsEmptyCell( int row, int col );
1146 virtual wxString GetValue( int row, int col );
1147 virtual void SetValue( int row, int col, const wxString& value );
1149 // virtuals overridable in wxPyGridTableBase
1150 virtual wxString GetTypeName( int row, int col );
1151 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
1152 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
1153 virtual long GetValueAsLong( int row, int col );
1154 virtual double GetValueAsDouble( int row, int col );
1155 virtual bool GetValueAsBool( int row, int col );
1156 virtual void SetValueAsLong( int row, int col, long value );
1157 virtual void SetValueAsDouble( int row, int col, double value );
1158 virtual void SetValueAsBool( int row, int col, bool value );
1160 //virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
1161 //virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
1164 virtual void Clear();
1165 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
1166 virtual bool AppendRows( size_t numRows = 1 );
1167 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
1168 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
1169 virtual bool AppendCols( size_t numCols = 1 );
1170 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
1172 virtual wxString GetRowLabelValue( int row );
1173 virtual wxString GetColLabelValue( int col );
1174 virtual void SetRowLabelValue( int row, const wxString& value );
1175 virtual void SetColLabelValue( int col, const wxString& value );
1177 virtual bool CanHaveAttributes();
1179 virtual wxGridCellAttr *GetAttr( int row, int col,
1180 wxGridCellAttr::wxAttrKind kind);
1181 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
1182 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
1183 virtual void SetColAttr(wxGridCellAttr *attr, int col);
1189 // Python-aware version
1191 class wxPyGridTableBase : public wxGridTableBase
1194 wxPyGridTableBase() : wxGridTableBase() {}
1196 PYCALLBACK_INT__pure(GetNumberRows);
1197 PYCALLBACK_INT__pure(GetNumberCols);
1198 PYCALLBACK_BOOL_INTINT_pure(IsEmptyCell);
1199 PYCALLBACK_STRING_INTINT(wxGridTableBase, GetTypeName);
1200 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanGetValueAs);
1201 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanSetValueAs);
1202 PYCALLBACK__(wxGridTableBase, Clear);
1203 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertRows);
1204 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteRows);
1205 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertCols);
1206 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteCols);
1207 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendRows);
1208 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendCols);
1209 PYCALLBACK_STRING_INT(wxGridTableBase, GetRowLabelValue);
1210 PYCALLBACK_STRING_INT(wxGridTableBase, GetColLabelValue);
1211 PYCALLBACK__INTSTRING(wxGridTableBase, SetRowLabelValue);
1212 PYCALLBACK__INTSTRING(wxGridTableBase, SetColLabelValue);
1213 PYCALLBACK_BOOL_(wxGridTableBase, CanHaveAttributes);
1214 PYCALLBACK_GCA_INTINTKIND(wxGridTableBase, GetAttr);
1215 PYCALLBACK__GCAINTINT(wxGridTableBase, SetAttr);
1216 PYCALLBACK__GCAINT(wxGridTableBase, SetRowAttr);
1217 PYCALLBACK__GCAINT(wxGridTableBase, SetColAttr);
1220 wxString GetValue(int row, int col) {
1221 bool blocked = wxPyBeginBlockThreads();
1223 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1225 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",row,col));
1227 rval = Py2wxString(ro);
1231 wxPyEndBlockThreads(blocked);
1235 void SetValue(int row, int col, const wxString& val) {
1236 bool blocked = wxPyBeginBlockThreads();
1237 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1238 PyObject* s = wx2PyString(val);
1239 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",row,col,s));
1242 wxPyEndBlockThreads(blocked);
1246 // Map the Get/Set methods for the standard non-string types to
1247 // the GetValue and SetValue python methods.
1248 long GetValueAsLong( int row, int col ) {
1250 bool blocked = wxPyBeginBlockThreads();
1251 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1254 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1255 if (ro && PyNumber_Check(ro)) {
1256 num = PyNumber_Int(ro);
1258 rval = PyInt_AsLong(num);
1264 wxPyEndBlockThreads(blocked);
1268 double GetValueAsDouble( int row, int col ) {
1270 bool blocked = wxPyBeginBlockThreads();
1271 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1274 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1275 if (ro && PyNumber_Check(ro)) {
1276 num = PyNumber_Float(ro);
1278 rval = PyFloat_AsDouble(num);
1284 wxPyEndBlockThreads(blocked);
1288 bool GetValueAsBool( int row, int col ) {
1289 return (bool)GetValueAsLong(row, col);
1292 void SetValueAsLong( int row, int col, long value ) {
1293 bool blocked = wxPyBeginBlockThreads();
1294 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1295 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", row, col, value));
1297 wxPyEndBlockThreads(blocked);
1300 void SetValueAsDouble( int row, int col, double value ) {
1301 bool blocked = wxPyBeginBlockThreads();
1302 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1303 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iid)", row, col, value));
1305 wxPyEndBlockThreads(blocked);
1308 void SetValueAsBool( int row, int col, bool value ) {
1309 SetValueAsLong( row, col, (long)value );
1318 // The python-aware version get's SWIGified
1319 class wxPyGridTableBase : public wxGridTableBase
1322 %pythonAppend wxPyGridTableBase "self._setCallbackInfo(self, PyGridTableBase);self._setOORInfo(self)"
1323 wxPyGridTableBase();
1324 void _setCallbackInfo(PyObject* self, PyObject* _class);
1326 %extend { void Destroy() { delete self; } }
1328 wxString base_GetTypeName( int row, int col );
1329 bool base_CanGetValueAs( int row, int col, const wxString& typeName );
1330 bool base_CanSetValueAs( int row, int col, const wxString& typeName );
1332 bool base_InsertRows( size_t pos = 0, size_t numRows = 1 );
1333 bool base_AppendRows( size_t numRows = 1 );
1334 bool base_DeleteRows( size_t pos = 0, size_t numRows = 1 );
1335 bool base_InsertCols( size_t pos = 0, size_t numCols = 1 );
1336 bool base_AppendCols( size_t numCols = 1 );
1337 bool base_DeleteCols( size_t pos = 0, size_t numCols = 1 );
1338 wxString base_GetRowLabelValue( int row );
1339 wxString base_GetColLabelValue( int col );
1340 void base_SetRowLabelValue( int row, const wxString& value );
1341 void base_SetColLabelValue( int col, const wxString& value );
1342 bool base_CanHaveAttributes();
1343 wxGridCellAttr *base_GetAttr( int row, int col,
1344 wxGridCellAttr::wxAttrKind kind );
1345 void base_SetAttr(wxGridCellAttr* attr, int row, int col);
1346 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1347 void base_SetColAttr(wxGridCellAttr *attr, int col);
1351 //---------------------------------------------------------------------------
1352 // Predefined Tables
1354 class wxGridStringTable : public wxGridTableBase
1357 %pythonAppend wxGridStringTable "self._setOORInfo(self)"
1358 wxGridStringTable( int numRows=0, int numCols=0 );
1361 //---------------------------------------------------------------------------
1362 // The Table can pass messages to the grid to tell it to update itself if
1363 // something has changed.
1365 enum wxGridTableRequest
1367 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
1368 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
1369 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
1370 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
1371 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
1372 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1373 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
1374 wxGRIDTABLE_NOTIFY_COLS_DELETED
1378 class wxGridTableMessage
1381 wxGridTableMessage( wxGridTableBase *table, int id,
1384 ~wxGridTableMessage();
1386 void SetTableObject( wxGridTableBase *table );
1387 wxGridTableBase * GetTableObject() const;
1388 void SetId( int id );
1390 void SetCommandInt( int comInt1 );
1391 int GetCommandInt();
1392 void SetCommandInt2( int comInt2 );
1393 int GetCommandInt2();
1397 //---------------------------------------------------------------------------
1400 // Typemap to allow conversion of sequence objects to wxGridCellCoords...
1401 %typemap(in) wxGridCellCoords& (wxGridCellCoords temp) {
1403 if (! wxGridCellCoords_helper($input, &$1)) SWIG_fail;
1405 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxGridCellCoords& {
1406 $1 = wxGridCellCoords_typecheck($input);
1410 // ...and here is the associated helper.
1412 bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) {
1414 if (source == Py_None) {
1415 **obj = wxGridCellCoords(-1,-1);
1419 // If source is an object instance then it may already be the right type
1420 if (wxPySwigInstance_Check(source)) {
1421 wxGridCellCoords* ptr;
1422 if (! wxPyConvertSwigPtr(source, (void **)&ptr, wxT("wxGridCellCoords")))
1427 // otherwise a 2-tuple of integers is expected
1428 else if (PySequence_Check(source) && PyObject_Length(source) == 2) {
1429 PyObject* o1 = PySequence_GetItem(source, 0);
1430 PyObject* o2 = PySequence_GetItem(source, 1);
1431 if (!PyNumber_Check(o1) || !PyNumber_Check(o2)) {
1436 **obj = wxGridCellCoords(PyInt_AsLong(o1), PyInt_AsLong(o2));
1443 PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of integers or a wxGridCellCoords object.");
1448 bool wxGridCellCoords_typecheck(PyObject* source) {
1451 if (wxPySwigInstance_Check(source) &&
1452 wxPyConvertSwigPtr(source, (void **)&ptr, wxT("wxGridCellCoords")))
1456 if (PySequence_Check(source) && PySequence_Length(source) == 2)
1464 // Typemap to convert an array of cells coords to a list of tuples...
1465 %typemap(out) wxGridCellCoordsArray {
1466 $result = wxGridCellCoordsArray_helper($1);
1469 // %typemap(ret) wxGridCellCoordsArray {
1474 // ...and the helper function for the above typemap.
1476 PyObject* wxGridCellCoordsArray_helper(const wxGridCellCoordsArray& source)
1478 PyObject* list = PyList_New(0);
1480 for (idx = 0; idx < source.GetCount(); idx += 1) {
1481 wxGridCellCoords& coord = source.Item(idx);
1482 PyObject* tup = PyTuple_New(2);
1483 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(coord.GetRow()));
1484 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(coord.GetCol()));
1485 PyList_Append(list, tup);
1496 class wxGridCellCoords
1499 wxGridCellCoords( int r=-1, int c=-1 );
1500 ~wxGridCellCoords();
1503 void SetRow( int n );
1505 void SetCol( int n );
1506 void Set( int row, int col );
1508 bool operator==( const wxGridCellCoords& other ) const;
1509 bool operator!=( const wxGridCellCoords& other ) const;
1513 PyObject* tup = PyTuple_New(2);
1514 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
1515 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
1520 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
1521 def __str__(self): return str(self.Get())
1522 def __repr__(self): return 'wxGridCellCoords'+str(self.Get())
1523 def __len__(self): return len(self.Get())
1524 def __getitem__(self, index): return self.asTuple()[index]
1525 def __setitem__(self, index, val):
1526 if index == 0: self.SetRow(val)
1527 elif index == 1: self.SetCol(val)
1528 else: raise IndexError
1534 //---------------------------------------------------------------------------
1535 //---------------------------------------------------------------------------
1539 // Fool SWIG into treating this enum as an int
1540 typedef int WXGRIDSELECTIONMODES;
1542 // but let the C++ code know what it really is.
1544 typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES;
1549 class wxGrid : public wxScrolledWindow
1552 %pythonAppend wxGrid "self._setOORInfo(self)"
1554 wxGrid( wxWindow *parent,
1556 const wxPoint& pos = wxDefaultPosition,
1557 const wxSize& size = wxDefaultSize,
1558 long style = wxWANTS_CHARS,
1559 const wxString& name = wxPyPanelNameStr);
1561 %name(PreGrid) wxGrid();
1564 bool Create( wxWindow *parent,
1566 const wxPoint& pos = wxDefaultPosition,
1567 const wxSize& size = wxDefaultSize,
1568 long style = wxWANTS_CHARS,
1569 const wxString& name = wxPyPanelNameStr );
1572 enum wxGridSelectionModes {
1578 SelectCells = wxGridSelectCells
1579 SelectRows = wxGridSelectRows
1580 SelectColumns = wxGridSelectColumns
1583 bool CreateGrid( int numRows, int numCols,
1584 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1585 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1586 WXGRIDSELECTIONMODES GetSelectionMode();
1589 // ------ grid dimensions
1591 int GetNumberRows();
1592 int GetNumberCols();
1595 bool ProcessTableMessage( wxGridTableMessage& );
1598 wxGridTableBase * GetTable() const;
1599 bool SetTable( wxGridTableBase *table, bool takeOwnership=False,
1600 WXGRIDSELECTIONMODES selmode =
1601 wxGrid::wxGridSelectCells );
1604 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=True );
1605 bool AppendRows( int numRows = 1, bool updateLabels=True );
1606 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=True );
1607 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=True );
1608 bool AppendCols( int numCols = 1, bool updateLabels=True );
1609 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=True );
1612 // this function is called when the current cell highlight must be redrawn
1613 // and may be overridden by the user
1614 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1617 // ------ Cell text drawing functions
1619 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1620 int horizontalAlignment = wxLEFT,
1621 int verticalAlignment = wxTOP,
1622 int textOrientation = wxHORIZONTAL );
1624 // // Split a string containing newline chararcters into an array of
1625 // // strings and return the number of lines
1627 // void StringToLines( const wxString& value, wxArrayString& lines );
1630 void, GetTextBoxSize( wxDC& dc, wxArrayString& lines,
1631 long *OUTPUT, long *OUTPUT ),
1632 "GetTextBoxSize(DC dc, list lines) -> (width, height)");
1636 // Code that does a lot of grid modification can be enclosed
1637 // between BeginBatch() and EndBatch() calls to avoid screen
1642 int GetBatchCount();
1643 void ForceRefresh();
1646 // ------ edit control functions
1649 void EnableEditing( bool edit );
1651 void EnableCellEditControl( bool enable = True );
1652 void DisableCellEditControl();
1653 bool CanEnableCellControl() const;
1654 bool IsCellEditControlEnabled() const;
1655 bool IsCellEditControlShown() const;
1657 bool IsCurrentCellReadOnly() const;
1659 void ShowCellEditControl();
1660 void HideCellEditControl();
1661 void SaveEditControlValue();
1664 // ------ grid location functions
1665 // Note that all of these functions work with the logical coordinates of
1666 // grid cells and labels so you will need to convert from device
1667 // coordinates for mouse events etc.
1670 //void XYToCell( int x, int y, wxGridCellCoords& );
1672 wxGridCellCoords XYToCell(int x, int y) {
1673 wxGridCellCoords rv;
1674 self->XYToCell(x, y, rv);
1679 int YToRow( int y );
1680 int XToCol( int x );
1682 int YToEdgeOfRow( int y );
1683 int XToEdgeOfCol( int x );
1685 wxRect CellToRect( int row, int col );
1686 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1689 int GetGridCursorRow();
1690 int GetGridCursorCol();
1692 // check to see if a cell is either wholly visible (the default arg) or
1693 // at least partially visible in the grid window
1695 bool IsVisible( int row, int col, bool wholeCellVisible = True );
1696 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = True );
1697 void MakeCellVisible( int row, int col );
1698 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1701 // ------ grid cursor movement functions
1703 void SetGridCursor( int row, int col );
1704 bool MoveCursorUp( bool expandSelection );
1705 bool MoveCursorDown( bool expandSelection );
1706 bool MoveCursorLeft( bool expandSelection );
1707 bool MoveCursorRight( bool expandSelection );
1708 bool MovePageDown();
1710 bool MoveCursorUpBlock( bool expandSelection );
1711 bool MoveCursorDownBlock( bool expandSelection );
1712 bool MoveCursorLeftBlock( bool expandSelection );
1713 bool MoveCursorRightBlock( bool expandSelection );
1716 // ------ label and gridline formatting
1718 int GetDefaultRowLabelSize();
1719 int GetRowLabelSize();
1720 int GetDefaultColLabelSize();
1721 int GetColLabelSize();
1722 wxColour GetLabelBackgroundColour();
1723 wxColour GetLabelTextColour();
1724 wxFont GetLabelFont();
1727 void, GetRowLabelAlignment( int *OUTPUT, int *OUTPUT ),
1728 "GetRowLabelAlignment() -> (horiz, vert)");
1731 void, GetColLabelAlignment( int *OUTPUT, int *OUTPUT ),
1732 "GetColLabelAlignment() -> (horiz, vert)");
1734 int GetColLabelTextOrientation();
1735 wxString GetRowLabelValue( int row );
1736 wxString GetColLabelValue( int col );
1737 wxColour GetGridLineColour();
1738 wxColour GetCellHighlightColour();
1739 int GetCellHighlightPenWidth();
1740 int GetCellHighlightROPenWidth();
1742 void SetRowLabelSize( int width );
1743 void SetColLabelSize( int height );
1744 void SetLabelBackgroundColour( const wxColour& );
1745 void SetLabelTextColour( const wxColour& );
1746 void SetLabelFont( const wxFont& );
1747 void SetRowLabelAlignment( int horiz, int vert );
1748 void SetColLabelAlignment( int horiz, int vert );
1749 void SetColLabelTextOrientation( int textOrientation );
1750 void SetRowLabelValue( int row, const wxString& );
1751 void SetColLabelValue( int col, const wxString& );
1752 void SetGridLineColour( const wxColour& );
1753 void SetCellHighlightColour( const wxColour& );
1754 void SetCellHighlightPenWidth(int width);
1755 void SetCellHighlightROPenWidth(int width);
1757 void EnableDragRowSize( bool enable = True );
1758 void DisableDragRowSize();
1759 bool CanDragRowSize();
1760 void EnableDragColSize( bool enable = True );
1761 void DisableDragColSize();
1762 bool CanDragColSize();
1763 void EnableDragGridSize(bool enable = True);
1764 void DisableDragGridSize();
1765 bool CanDragGridSize();
1767 // this sets the specified attribute for all cells in this row/col
1768 void SetAttr(int row, int col, wxGridCellAttr *attr);
1769 void SetRowAttr(int row, wxGridCellAttr *attr);
1770 void SetColAttr(int col, wxGridCellAttr *attr);
1772 // shortcuts for setting the column parameters
1774 // set the format for the data in the column: default is string
1775 void SetColFormatBool(int col);
1776 void SetColFormatNumber(int col);
1777 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1778 void SetColFormatCustom(int col, const wxString& typeName);
1780 void EnableGridLines( bool enable = True );
1781 bool GridLinesEnabled();
1783 // ------ row and col formatting
1785 int GetDefaultRowSize();
1786 int GetRowSize( int row );
1787 int GetDefaultColSize();
1788 int GetColSize( int col );
1789 wxColour GetDefaultCellBackgroundColour();
1790 wxColour GetCellBackgroundColour( int row, int col );
1791 wxColour GetDefaultCellTextColour();
1792 wxColour GetCellTextColour( int row, int col );
1793 wxFont GetDefaultCellFont();
1794 wxFont GetCellFont( int row, int col );
1797 void, GetDefaultCellAlignment( int *OUTPUT, int *OUTPUT ),
1798 "GetDefaultCellAlignment() -> (horiz, vert)");
1801 void, GetCellAlignment( int row, int col, int *OUTPUT, int *OUTPUT ),
1802 "GetCellAlignment() -> (horiz, vert)");
1804 bool GetDefaultCellOverflow();
1805 bool GetCellOverflow( int row, int col );
1808 void, GetCellSize( int row, int col, int *OUTPUT, int *OUTPUT ),
1809 "GetCellSize(int row, int col) -> (num_rows, num_cols)");
1811 void SetDefaultRowSize( int height, bool resizeExistingRows = False );
1812 void SetRowSize( int row, int height );
1813 void SetDefaultColSize( int width, bool resizeExistingCols = False );
1815 void SetColSize( int col, int width );
1817 // automatically size the column or row to fit to its contents, if
1818 // setAsMin is True, this optimal width will also be set as minimal width
1820 void AutoSizeColumn( int col, bool setAsMin = True );
1821 void AutoSizeRow( int row, bool setAsMin = True );
1824 // auto size all columns (very ineffective for big grids!)
1825 void AutoSizeColumns( bool setAsMin = True );
1826 void AutoSizeRows( bool setAsMin = True );
1828 // auto size the grid, that is make the columns/rows of the "right" size
1829 // and also set the grid size to just fit its contents
1832 // autosize row height depending on label text
1833 void AutoSizeRowLabelSize( int row );
1835 // autosize column width depending on label text
1836 void AutoSizeColLabelSize( int col );
1839 // column won't be resized to be lesser width - this must be called during
1840 // the grid creation because it won't resize the column if it's already
1841 // narrower than the minimal width
1842 void SetColMinimalWidth( int col, int width );
1843 void SetRowMinimalHeight( int row, int width );
1845 void SetColMinimalAcceptableWidth( int width );
1846 void SetRowMinimalAcceptableHeight( int width );
1847 int GetColMinimalAcceptableWidth() const;
1848 int GetRowMinimalAcceptableHeight() const;
1850 void SetDefaultCellBackgroundColour( const wxColour& );
1851 void SetCellBackgroundColour( int row, int col, const wxColour& );
1852 void SetDefaultCellTextColour( const wxColour& );
1854 void SetCellTextColour( int row, int col, const wxColour& );
1855 void SetDefaultCellFont( const wxFont& );
1856 void SetCellFont( int row, int col, const wxFont& );
1857 void SetDefaultCellAlignment( int horiz, int vert );
1858 void SetCellAlignment( int row, int col, int horiz, int vert );
1859 void SetDefaultCellOverflow( bool allow );
1860 void SetCellOverflow( int row, int col, bool allow );
1861 void SetCellSize( int row, int col, int num_rows, int num_cols );
1863 // takes ownership of the pointer
1864 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1865 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1866 wxGridCellRenderer *GetDefaultRenderer() const;
1867 wxGridCellRenderer* GetCellRenderer(int row, int col);
1869 // takes ownership of the pointer
1870 void SetDefaultEditor(wxGridCellEditor *editor);
1871 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1872 wxGridCellEditor *GetDefaultEditor() const;
1873 wxGridCellEditor* GetCellEditor(int row, int col);
1877 // ------ cell value accessors
1879 wxString GetCellValue( int row, int col );
1880 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1882 void SetCellValue( int row, int col, const wxString& s );
1883 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1885 // returns True if the cell can't be edited
1886 bool IsReadOnly(int row, int col) const;
1888 // make the cell editable/readonly
1889 void SetReadOnly(int row, int col, bool isReadOnly = True);
1891 // ------ selections of blocks of cells
1893 void SelectRow( int row, bool addToSelected = False );
1894 void SelectCol( int col, bool addToSelected = False );
1896 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1897 bool addToSelected = False );
1898 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1899 // TODO: ??? const wxGridCellCoords& bottomRight )
1903 void ClearSelection();
1904 bool IsInSelection( int row, int col );
1905 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1907 const wxGridCellCoordsArray GetSelectedCells() const;
1908 const wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
1909 const wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
1910 const wxArrayInt GetSelectedRows() const;
1911 const wxArrayInt GetSelectedCols() const;
1913 void DeselectRow( int row );
1914 void DeselectCol( int col );
1915 void DeselectCell( int row, int col );
1918 // This function returns the rectangle that encloses the block of cells
1919 // limited by TopLeft and BottomRight cell in device coords and clipped
1920 // to the client size of the grid window.
1922 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1923 const wxGridCellCoords & bottomRight );
1926 // Access or update the selection fore/back colours
1927 wxColour GetSelectionBackground() const;
1928 wxColour GetSelectionForeground() const;
1930 void SetSelectionBackground(const wxColour& c);
1931 void SetSelectionForeground(const wxColour& c);
1934 // Methods for a registry for mapping data types to Renderers/Editors
1935 void RegisterDataType(const wxString& typeName,
1936 wxGridCellRenderer* renderer,
1937 wxGridCellEditor* editor);
1938 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1939 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1940 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1941 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1942 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1944 // grid may occupy more space than needed for its rows/columns, this
1945 // function allows to set how big this extra space is
1946 void SetMargins(int extraWidth, int extraHeight);
1949 // Accessors for component windows
1950 wxWindow* GetGridWindow();
1951 wxWindow* GetGridRowLabelWindow();
1952 wxWindow* GetGridColLabelWindow();
1953 wxWindow* GetGridCornerLabelWindow();
1956 static wxVisualAttributes
1957 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
1961 //---------------------------------------------------------------------------
1962 //---------------------------------------------------------------------------
1963 // Grid events and stuff
1967 class wxGridEvent : public wxNotifyEvent
1970 wxGridEvent(int id, wxEventType type, wxGrid* obj,
1971 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = True,
1972 bool control=False, bool shift=False, bool alt=False, bool meta=False);
1974 virtual int GetRow();
1975 virtual int GetCol();
1976 wxPoint GetPosition();
1986 class wxGridSizeEvent : public wxNotifyEvent
1989 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
1990 int rowOrCol=-1, int x=-1, int y=-1,
1991 bool control=False, bool shift=False, bool alt=False, bool meta=False);
1994 wxPoint GetPosition();
2003 class wxGridRangeSelectEvent : public wxNotifyEvent
2006 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
2007 const wxGridCellCoords& topLeft,
2008 const wxGridCellCoords& bottomRight,
2010 bool control=False, bool shift=False,
2011 bool alt=False, bool meta=False);
2013 wxGridCellCoords GetTopLeftCoords();
2014 wxGridCellCoords GetBottomRightCoords();
2027 class wxGridEditorCreatedEvent : public wxCommandEvent {
2029 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
2030 int row, int col, wxControl* ctrl);
2034 wxControl* GetControl();
2035 void SetRow(int row);
2036 void SetCol(int col);
2037 void SetControl(wxControl* ctrl);
2042 %constant wxEventType wxEVT_GRID_CELL_LEFT_CLICK;
2043 %constant wxEventType wxEVT_GRID_CELL_RIGHT_CLICK;
2044 %constant wxEventType wxEVT_GRID_CELL_LEFT_DCLICK;
2045 %constant wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK;
2046 %constant wxEventType wxEVT_GRID_LABEL_LEFT_CLICK;
2047 %constant wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK;
2048 %constant wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK;
2049 %constant wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK;
2050 %constant wxEventType wxEVT_GRID_ROW_SIZE;
2051 %constant wxEventType wxEVT_GRID_COL_SIZE;
2052 %constant wxEventType wxEVT_GRID_RANGE_SELECT;
2053 %constant wxEventType wxEVT_GRID_CELL_CHANGE;
2054 %constant wxEventType wxEVT_GRID_SELECT_CELL;
2055 %constant wxEventType wxEVT_GRID_EDITOR_SHOWN;
2056 %constant wxEventType wxEVT_GRID_EDITOR_HIDDEN;
2057 %constant wxEventType wxEVT_GRID_EDITOR_CREATED;
2062 EVT_GRID_CELL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_CLICK )
2063 EVT_GRID_CELL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_CLICK )
2064 EVT_GRID_CELL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_DCLICK )
2065 EVT_GRID_CELL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_DCLICK )
2066 EVT_GRID_LABEL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_CLICK )
2067 EVT_GRID_LABEL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_CLICK )
2068 EVT_GRID_LABEL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_DCLICK )
2069 EVT_GRID_LABEL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_DCLICK )
2070 EVT_GRID_ROW_SIZE = wx.PyEventBinder( wxEVT_GRID_ROW_SIZE )
2071 EVT_GRID_COL_SIZE = wx.PyEventBinder( wxEVT_GRID_COL_SIZE )
2072 EVT_GRID_RANGE_SELECT = wx.PyEventBinder( wxEVT_GRID_RANGE_SELECT )
2073 EVT_GRID_CELL_CHANGE = wx.PyEventBinder( wxEVT_GRID_CELL_CHANGE )
2074 EVT_GRID_SELECT_CELL = wx.PyEventBinder( wxEVT_GRID_SELECT_CELL )
2075 EVT_GRID_EDITOR_SHOWN = wx.PyEventBinder( wxEVT_GRID_EDITOR_SHOWN )
2076 EVT_GRID_EDITOR_HIDDEN = wx.PyEventBinder( wxEVT_GRID_EDITOR_HIDDEN )
2077 EVT_GRID_EDITOR_CREATED = wx.PyEventBinder( wxEVT_GRID_EDITOR_CREATED )
2080 //---------------------------------------------------------------------------
2085 //---------------------------------------------------------------------------
2086 //---------------------------------------------------------------------------