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 /////////////////////////////////////////////////////////////////////////////
20 #include <wx/generic/gridctrl.h>
23 //----------------------------------------------------------------------
26 %include my_typemaps.i
28 // Import some definitions of other classes, etc.
36 %pragma(python) code = "import wx"
38 //----------------------------------------------------------------------
41 // Put some wx default wxChar* values into wxStrings.
42 DECLARE_DEF_STRING(PanelNameStr);
43 DECLARE_DEF_STRING2(DateTimeFormatStr, wxT("%c"));
44 static const wxString wxPyEmptyString(wxT(""));
47 //---------------------------------------------------------------------------
48 // OOR related typemaps and helper functions
50 %typemap(python, out) wxGridCellRenderer* { $target = wxPyMake_wxGridCellRenderer($source); }
51 %typemap(python, out) wxGridCellEditor* { $target = wxPyMake_wxGridCellEditor($source); }
52 %typemap(python, out) wxGridCellAttr* { $target = wxPyMake_wxGridCellAttr($source); }
53 %typemap(python, out) wxGridCellAttrProvider* { $target = wxPyMake_wxGridCellAttrProvider($source); }
54 %typemap(python, out) wxGridTableBase* { $target = wxPyMake_wxGridTableBase($source); }
59 #define wxPyMake_TEMPLATE(TYPE) \
60 PyObject* wxPyMake_##TYPE(TYPE* source) { \
61 PyObject* target = NULL; \
63 /* Check if there is already a pointer to a Python object in the \
64 OOR data that we can use. */ \
65 wxPyOORClientData* data = (wxPyOORClientData*)source->GetClientObject(); \
67 target = data->m_obj; \
70 /* Otherwise make a new wrapper for it the old fashioned way and \
71 give it the OOR treatment */ \
73 target = wxPyConstructObject(source, #TYPE, FALSE); \
75 source->SetClientObject(new wxPyOORClientData(target)); \
77 } else { /* source was NULL so return None. */ \
78 Py_INCREF(Py_None); target = Py_None; \
84 wxPyMake_TEMPLATE(wxGridCellRenderer)
85 wxPyMake_TEMPLATE(wxGridCellEditor)
86 wxPyMake_TEMPLATE(wxGridCellAttr)
87 wxPyMake_TEMPLATE(wxGridCellAttrProvider)
88 wxPyMake_TEMPLATE(wxGridTableBase)
92 //---------------------------------------------------------------------------
93 // Macros, similar to what's in helpers.h, to aid in the creation of
94 // virtual methods that are able to make callbacks to Python. Many of these
95 // are specific to wxGrid and so are kept here to reduce the mess in helpers.h
100 #define PYCALLBACK_GCA_INTINTKIND(PCLASS, CBNAME) \
101 wxGridCellAttr* CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
102 wxGridCellAttr* rval = NULL; \
104 wxPyBeginBlockThreads(); \
105 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
107 wxGridCellAttr* ptr; \
108 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iii)", a, b, c)); \
110 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellAttr_p")) \
115 wxPyEndBlockThreads(); \
117 rval = PCLASS::CBNAME(a, b, c); \
120 wxGridCellAttr *base_##CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
121 return PCLASS::CBNAME(a, b, c); \
126 #define PYCALLBACK__GCAINTINT(PCLASS, CBNAME) \
127 void CBNAME(wxGridCellAttr *attr, int a, int b) { \
128 wxPyBeginBlockThreads(); \
130 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
131 PyObject* obj = wxPyMake_wxGridCellAttr(attr); \
132 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oii)", obj, a, b)); \
135 wxPyEndBlockThreads(); \
137 PCLASS::CBNAME(attr, a, b); \
139 void base_##CBNAME(wxGridCellAttr *attr, int a, int b) { \
140 PCLASS::CBNAME(attr, a, b); \
145 #define PYCALLBACK__GCAINT(PCLASS, CBNAME) \
146 void CBNAME(wxGridCellAttr *attr, int val) { \
147 wxPyBeginBlockThreads(); \
149 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
150 PyObject* obj = wxPyMake_wxGridCellAttr(attr); \
151 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, val)); \
154 wxPyEndBlockThreads(); \
156 PCLASS::CBNAME(attr, val); \
158 void base_##CBNAME(wxGridCellAttr *attr, int val) { \
159 PCLASS::CBNAME(attr, val); \
164 #define PYCALLBACK_INT__pure(CBNAME) \
166 wxPyBeginBlockThreads(); \
168 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
169 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
170 wxPyEndBlockThreads(); \
176 #define PYCALLBACK_BOOL_INTINT_pure(CBNAME) \
177 bool CBNAME(int a, int b) { \
178 wxPyBeginBlockThreads(); \
180 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
181 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
182 wxPyEndBlockThreads(); \
187 #define PYCALLBACK_STRING_INTINT_pure(CBNAME) \
188 wxString CBNAME(int a, int b) { \
189 wxPyBeginBlockThreads(); \
191 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
193 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
195 rval = Py2wxString(ro); \
199 wxPyEndBlockThreads(); \
204 #define PYCALLBACK__INTINTSTRING_pure(CBNAME) \
205 void CBNAME(int a, int b, const wxString& c) { \
206 wxPyBeginBlockThreads(); \
207 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
208 PyObject* s = wx2PyString(c); \
209 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,s));\
212 wxPyEndBlockThreads(); \
216 #define PYCALLBACK_STRING_INTINT(PCLASS, CBNAME) \
217 wxString CBNAME(int a, int b) { \
219 wxPyBeginBlockThreads(); \
221 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
223 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
225 rval = Py2wxString(ro); \
229 wxPyEndBlockThreads(); \
231 rval = PCLASS::CBNAME(a, b); \
234 wxString base_##CBNAME(int a, int b) { \
235 return PCLASS::CBNAME(a, b); \
239 #define PYCALLBACK_BOOL_INTINTSTRING(PCLASS, CBNAME) \
240 bool CBNAME(int a, int b, const wxString& c) { \
243 wxPyBeginBlockThreads(); \
244 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
245 PyObject* s = wx2PyString(c); \
246 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,s));\
249 wxPyEndBlockThreads(); \
251 rval = PCLASS::CBNAME(a,b,c); \
254 bool base_##CBNAME(int a, int b, const wxString& c) { \
255 return PCLASS::CBNAME(a,b,c); \
261 #define PYCALLBACK_LONG_INTINT(PCLASS, CBNAME) \
262 long CBNAME(int a, int b) { \
265 wxPyBeginBlockThreads(); \
266 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
267 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
268 wxPyEndBlockThreads(); \
270 rval = PCLASS::CBNAME(a,b); \
273 long base_##CBNAME(int a, int b) { \
274 return PCLASS::CBNAME(a,b); \
279 #define PYCALLBACK_BOOL_INTINT(PCLASS, CBNAME) \
280 bool CBNAME(int a, int b) { \
283 wxPyBeginBlockThreads(); \
284 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
285 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
286 wxPyEndBlockThreads(); \
288 rval = PCLASS::CBNAME(a,b); \
291 bool base_##CBNAME(int a, int b) { \
292 return PCLASS::CBNAME(a,b); \
297 #define PYCALLBACK_DOUBLE_INTINT(PCLASS, CBNAME) \
298 double CBNAME(int a, int b) { \
300 wxPyBeginBlockThreads(); \
302 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
304 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
306 PyObject* str = PyObject_Str(ro); \
307 rval = PyFloat_AsDouble(str); \
308 Py_DECREF(ro); Py_DECREF(str); \
311 wxPyEndBlockThreads(); \
313 rval = PCLASS::CBNAME(a, b); \
316 double base_##CBNAME(int a, int b) { \
317 return PCLASS::CBNAME(a, b); \
322 #define PYCALLBACK__(PCLASS, CBNAME) \
325 wxPyBeginBlockThreads(); \
326 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
327 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
328 wxPyEndBlockThreads(); \
332 void base_##CBNAME() { \
339 #define PYCALLBACK_BOOL_SIZETSIZET(PCLASS, CBNAME) \
340 bool CBNAME(size_t a, size_t b) { \
343 wxPyBeginBlockThreads(); \
344 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
345 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
346 wxPyEndBlockThreads(); \
348 rval = PCLASS::CBNAME(a,b); \
351 bool base_##CBNAME(size_t a, size_t b) { \
352 return PCLASS::CBNAME(a,b); \
357 #define PYCALLBACK_BOOL_SIZET(PCLASS, CBNAME) \
358 bool CBNAME(size_t a) { \
361 wxPyBeginBlockThreads(); \
362 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
363 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)", a)); \
364 wxPyEndBlockThreads(); \
366 rval = PCLASS::CBNAME(a); \
369 bool base_##CBNAME(size_t a) { \
370 return PCLASS::CBNAME(a); \
374 #define PYCALLBACK_STRING_INT(PCLASS, CBNAME) \
375 wxString CBNAME(int a) { \
377 wxPyBeginBlockThreads(); \
379 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
381 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(i)",a)); \
383 rval = Py2wxString(ro); \
387 wxPyEndBlockThreads(); \
389 rval = PCLASS::CBNAME(a); \
392 wxString base_##CBNAME(int a) { \
393 return PCLASS::CBNAME(a); \
397 #define PYCALLBACK__INTSTRING(PCLASS, CBNAME) \
398 void CBNAME(int a, const wxString& c) { \
400 wxPyBeginBlockThreads(); \
401 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
402 PyObject* s = wx2PyString(c); \
403 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)",a,s)); \
406 wxPyEndBlockThreads(); \
408 PCLASS::CBNAME(a,c); \
410 void base_##CBNAME(int a, const wxString& c) { \
411 PCLASS::CBNAME(a,c); \
417 #define PYCALLBACK_BOOL_(PCLASS, CBNAME) \
421 wxPyBeginBlockThreads(); \
422 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
423 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
424 wxPyEndBlockThreads(); \
426 rval = PCLASS::CBNAME(); \
429 bool base_##CBNAME() { \
430 return PCLASS::CBNAME(); \
435 #define PYCALLBACK__SIZETINT(PCLASS, CBNAME) \
436 void CBNAME(size_t a, int b) { \
438 wxPyBeginBlockThreads(); \
439 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
440 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
441 wxPyEndBlockThreads(); \
443 PCLASS::CBNAME(a,b); \
445 void base_##CBNAME(size_t a, int b) { \
446 PCLASS::CBNAME(a,b); \
452 #define PYCALLBACK__INTINTLONG(PCLASS, CBNAME) \
453 void CBNAME(int a, int b, long c) { \
455 wxPyBeginBlockThreads(); \
456 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
457 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
458 wxPyEndBlockThreads(); \
460 PCLASS::CBNAME(a,b,c); \
462 void base_##CBNAME(int a, int b, long c) { \
463 PCLASS::CBNAME(a,b,c); \
469 #define PYCALLBACK__INTINTDOUBLE(PCLASS, CBNAME) \
470 void CBNAME(int a, int b, double c) { \
472 wxPyBeginBlockThreads(); \
473 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
474 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iif)", a,b,c)); \
475 wxPyEndBlockThreads(); \
477 PCLASS::CBNAME(a,b,c); \
479 void base_##CBNAME(int a, int b, double c) { \
480 PCLASS::CBNAME(a,b,c); \
485 #define PYCALLBACK__INTINTBOOL(PCLASS, CBNAME) \
486 void CBNAME(int a, int b, bool c) { \
488 wxPyBeginBlockThreads(); \
489 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
490 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
491 wxPyEndBlockThreads(); \
493 PCLASS::CBNAME(a,b,c); \
495 void base_##CBNAME(int a, int b, bool c) { \
496 PCLASS::CBNAME(a,b,c); \
504 //---------------------------------------------------------------------------
506 class wxGridCellCoords;
507 class wxGridCellAttr;
509 #define wxGRID_VALUE_STRING "string"
510 #define wxGRID_VALUE_BOOL "bool"
511 #define wxGRID_VALUE_NUMBER "long"
512 #define wxGRID_VALUE_FLOAT "double"
513 #define wxGRID_VALUE_CHOICE "choice"
514 #define wxGRID_VALUE_TEXT "string"
515 #define wxGRID_VALUE_LONG "long"
516 #define wxGRID_VALUE_CHOICEINT "choiceint"
517 #define wxGRID_VALUE_DATETIME "datetime"
521 wxGridCellCoords wxGridNoCellCoords;
522 wxRect wxGridNoCellRect;
526 //---------------------------------------------------------------------------
527 // wxGridCellRenderer is an ABC, and several derived classes are available.
528 // Classes implemented in Python should be derived from wxPyGridCellRenderer.
531 class wxGridCellRenderer
535 void _setOORInfo(PyObject* _self) {
536 self->SetClientObject(new wxPyOORClientData(_self));
540 void SetParameters(const wxString& params);
544 virtual void Draw(wxGrid& grid,
545 wxGridCellAttr& attr,
549 bool isSelected) = 0;
550 virtual wxSize GetBestSize(wxGrid& grid,
551 wxGridCellAttr& attr,
553 int row, int col) = 0;
554 virtual wxGridCellRenderer *Clone() const = 0;
558 // The C++ version of wxPyGridCellRenderer
560 class wxPyGridCellRenderer : public wxGridCellRenderer
563 wxPyGridCellRenderer() : wxGridCellRenderer() {};
565 // Implement Python callback aware virtual methods
566 void Draw(wxGrid& grid, wxGridCellAttr& attr,
567 wxDC& dc, const wxRect& rect,
568 int row, int col, bool isSelected) {
569 wxPyBeginBlockThreads();
570 if (wxPyCBH_findCallback(m_myInst, "Draw")) {
571 PyObject* go = wxPyMake_wxObject(&grid);
572 PyObject* dco = wxPyMake_wxObject(&dc);
573 PyObject* ao = wxPyMake_wxGridCellAttr(&attr);
574 PyObject* ro = wxPyConstructObject((void*)&rect, "wxRect", 0);
576 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOOOiii)", go, ao, dco, ro,
577 row, col, isSelected));
583 wxPyEndBlockThreads();
586 wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
589 wxPyBeginBlockThreads();
590 if (wxPyCBH_findCallback(m_myInst, "GetBestSize")) {
593 PyObject* go = wxPyMake_wxObject(&grid);
594 PyObject* dco = wxPyMake_wxObject(&dc);
595 PyObject* ao = wxPyMake_wxGridCellAttr(&attr);
597 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OOOii)",
605 const char* errmsg = "GetBestSize should return a 2-tuple of integers or a wxSize object.";
606 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p")) {
609 else if (PySequence_Check(ro) && PyObject_Length(ro) == 2) {
610 PyObject* o1 = PySequence_GetItem(ro, 0);
611 PyObject* o2 = PySequence_GetItem(ro, 1);
612 if (PyNumber_Check(o1) && PyNumber_Check(o2))
613 rval = wxSize(PyInt_AsLong(o1), PyInt_AsLong(o2));
615 PyErr_SetString(PyExc_TypeError, errmsg);
620 PyErr_SetString(PyExc_TypeError, errmsg);
625 wxPyEndBlockThreads();
630 wxGridCellRenderer *Clone() const {
631 wxGridCellRenderer* rval = NULL;
632 wxPyBeginBlockThreads();
633 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
635 wxGridCellRenderer* ptr;
636 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
638 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellRenderer_p"))
643 wxPyEndBlockThreads();
647 DEC_PYCALLBACK__STRING(SetParameters);
652 IMP_PYCALLBACK__STRING( wxPyGridCellRenderer, wxGridCellRenderer, SetParameters);
657 // Let SWIG know about it so it can create the Python version
658 class wxPyGridCellRenderer : public wxGridCellRenderer {
660 wxPyGridCellRenderer();
661 void _setCallbackInfo(PyObject* self, PyObject* _class);
662 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellRenderer)"
663 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
665 void base_SetParameters(const wxString& params);
668 //---------------------------------------------------------------------------
669 // Predefined Renderers
671 class wxGridCellStringRenderer : public wxGridCellRenderer
674 wxGridCellStringRenderer();
675 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
679 class wxGridCellNumberRenderer : public wxGridCellStringRenderer
682 wxGridCellNumberRenderer();
683 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
687 class wxGridCellFloatRenderer : public wxGridCellStringRenderer
690 wxGridCellFloatRenderer(int width = -1, int precision = -1);
691 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
693 int GetWidth() const;
694 void SetWidth(int width);
695 int GetPrecision() const;
696 void SetPrecision(int precision);
700 class wxGridCellBoolRenderer : public wxGridCellRenderer
703 wxGridCellBoolRenderer();
704 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
708 class wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
711 wxGridCellDateTimeRenderer(wxString outformat = wxPyDateTimeFormatStr,
712 wxString informat = wxPyDateTimeFormatStr);
713 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
717 class wxGridCellEnumRenderer : public wxGridCellStringRenderer
720 wxGridCellEnumRenderer( const wxString& choices = wxPyEmptyString );
721 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
725 class wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer
728 wxGridCellAutoWrapStringRenderer();
729 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
733 //---------------------------------------------------------------------------
734 // wxGridCellEditor is an ABC, and several derived classes are available.
735 // Classes implemented in Python should be derived from wxPyGridCellEditor.
737 class wxGridCellEditor
741 void _setOORInfo(PyObject* _self) {
742 self->SetClientObject(new wxPyOORClientData(_self));
747 wxControl* GetControl();
748 void SetControl(wxControl* control);
750 void SetParameters(const wxString& params);
754 virtual void Create(wxWindow* parent,
756 wxEvtHandler* evtHandler) = 0;
757 virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
758 virtual bool EndEdit(int row, int col, wxGrid* grid) = 0;
759 virtual void Reset() = 0;
760 virtual wxGridCellEditor *Clone() const = 0;
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 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();
795 void BeginEdit(int row, int col, wxGrid* grid) {
796 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();
806 bool EndEdit(int row, int col, wxGrid* grid) {
808 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();
819 wxGridCellEditor*Clone() const {
820 wxGridCellEditor* rval = NULL;
821 wxPyBeginBlockThreads();
822 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
824 wxGridCellEditor* ptr;
825 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
827 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellEditor_p"))
832 wxPyEndBlockThreads();
837 void Show(bool show, wxGridCellAttr *attr) {
839 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();
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 wxPyBeginBlockThreads();
857 if ((found = wxPyCBH_findCallback(m_myInst, "PaintBackground)"))) {
858 PyObject* ao = wxPyMake_wxGridCellAttr(attr);
859 PyObject* ro = wxPyConstructObject((void*)&rectCell, "wxRect", 0);
861 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", ro, ao));
866 wxPyEndBlockThreads();
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);
888 IMP_PYCALLBACK__STRING( wxPyGridCellEditor, wxGridCellEditor, SetParameters);
889 IMP_PYCALLBACK___pure(wxPyGridCellEditor, wxGridCellEditor, Reset);
890 IMP_PYCALLBACK__constany(wxPyGridCellEditor, wxGridCellEditor, SetSize, wxRect);
891 IMP_PYCALLBACK_bool_any(wxPyGridCellEditor, wxGridCellEditor, IsAcceptedKey, wxKeyEvent);
892 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, StartingKey, wxKeyEvent);
893 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, HandleReturn, wxKeyEvent);
894 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, StartingClick);
895 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, Destroy);
900 // Let SWIG know about it so it can create the Python version
901 class wxPyGridCellEditor : public wxGridCellEditor {
903 wxPyGridCellEditor();
904 void _setCallbackInfo(PyObject* self, PyObject* _class);
905 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellEditor)"
906 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
908 void base_SetSize(const wxRect& rect);
909 void base_Show(bool show, wxGridCellAttr *attr = NULL);
910 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
911 void base_IsAcceptedKey(wxKeyEvent& event);
912 void base_StartingKey(wxKeyEvent& event);
913 void base_StartingClick();
914 void base_HandleReturn(wxKeyEvent& event);
916 void base_SetParameters(const wxString& params);
919 //---------------------------------------------------------------------------
920 // Predefined Editors
922 class wxGridCellTextEditor : public wxGridCellEditor
925 wxGridCellTextEditor();
926 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
930 class wxGridCellNumberEditor : public wxGridCellTextEditor
933 wxGridCellNumberEditor(int min = -1, int max = -1);
934 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
938 class wxGridCellFloatEditor : public wxGridCellTextEditor
941 wxGridCellFloatEditor();
942 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
946 class wxGridCellBoolEditor : public wxGridCellEditor
949 wxGridCellBoolEditor();
950 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
953 class wxGridCellChoiceEditor : public wxGridCellEditor
956 wxGridCellChoiceEditor(int LCOUNT = 0,
957 const wxString* choices = NULL,
958 bool allowOthers = FALSE);
959 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
963 class wxGridCellEnumEditor : public wxGridCellChoiceEditor
966 wxGridCellEnumEditor( const wxString& choices = wxPyEmptyString );
967 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
971 class wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
974 wxGridCellAutoWrapStringEditor();
975 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
980 //---------------------------------------------------------------------------
997 void _setOORInfo(PyObject* _self) {
998 self->SetClientObject(new wxPyOORClientData(_self));
1002 wxGridCellAttr(wxGridCellAttr *attrDefault = NULL);
1003 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1005 wxGridCellAttr *Clone() const;
1006 void MergeWith(wxGridCellAttr *mergefrom);
1009 void SetTextColour(const wxColour& colText);
1010 void SetBackgroundColour(const wxColour& colBack);
1011 void SetFont(const wxFont& font);
1012 void SetAlignment(int hAlign, int vAlign);
1013 void SetSize(int num_rows, int num_cols);
1014 void SetOverflow( bool allow );
1015 void SetReadOnly(bool isReadOnly = TRUE);
1017 void SetRenderer(wxGridCellRenderer *renderer);
1018 void SetEditor(wxGridCellEditor* editor);
1019 void SetKind(wxAttrKind kind);
1021 bool HasTextColour() const;
1022 bool HasBackgroundColour() const;
1023 bool HasFont() const;
1024 bool HasAlignment() const;
1025 bool HasRenderer() const;
1026 bool HasEditor() const;
1027 bool HasReadWriteMode() const;
1029 wxColour GetTextColour() const;
1030 wxColour GetBackgroundColour() const;
1031 wxFont GetFont() const;
1032 void GetAlignment(int *OUTPUT, int *OUTPUT) const;
1033 void GetSize(int *num_rows, int *num_cols) const;
1034 bool GetOverflow() const;
1035 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
1036 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
1038 bool IsReadOnly() const;
1039 void SetDefAttr(wxGridCellAttr* defAttr);
1042 //---------------------------------------------------------------------------
1044 class wxGridCellAttrProvider
1047 wxGridCellAttrProvider();
1048 // ???? virtual ~wxGridCellAttrProvider();
1049 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1052 void _setOORInfo(PyObject* _self) {
1053 self->SetClientObject(new wxPyOORClientData(_self));
1057 wxGridCellAttr *GetAttr(int row, int col,
1058 wxGridCellAttr::wxAttrKind kind) const;
1059 void SetAttr(wxGridCellAttr *attr, int row, int col);
1060 void SetRowAttr(wxGridCellAttr *attr, int row);
1061 void SetColAttr(wxGridCellAttr *attr, int col);
1063 void UpdateAttrRows( size_t pos, int numRows );
1064 void UpdateAttrCols( size_t pos, int numCols );
1069 // A Python-aware version
1071 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1074 wxPyGridCellAttrProvider() : wxGridCellAttrProvider() {};
1076 PYCALLBACK_GCA_INTINTKIND(wxGridCellAttrProvider, GetAttr);
1077 PYCALLBACK__GCAINTINT(wxGridCellAttrProvider, SetAttr);
1078 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetRowAttr);
1079 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetColAttr);
1086 // The python-aware version get's SWIGified
1087 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1090 wxPyGridCellAttrProvider();
1091 void _setCallbackInfo(PyObject* self, PyObject* _class);
1092 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellAttrProvider)"
1094 wxGridCellAttr *base_GetAttr(int row, int col,
1095 wxGridCellAttr::wxAttrKind kind);
1096 void base_SetAttr(wxGridCellAttr *attr, int row, int col);
1097 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1098 void base_SetColAttr(wxGridCellAttr *attr, int col);
1102 //---------------------------------------------------------------------------
1103 // Grid Table Base class and Python aware version
1106 class wxGridTableBase : public wxObject
1109 // wxGridTableBase(); This is an ABC
1110 //~wxGridTableBase();
1113 void _setOORInfo(PyObject* _self) {
1114 self->SetClientObject(new wxPyOORClientData(_self));
1118 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
1119 wxGridCellAttrProvider *GetAttrProvider() const;
1120 void SetView( wxGrid *grid );
1121 wxGrid * GetView() const;
1125 virtual int GetNumberRows() = 0;
1126 virtual int GetNumberCols() = 0;
1127 virtual bool IsEmptyCell( int row, int col ) = 0;
1128 virtual wxString GetValue( int row, int col ) = 0;
1129 virtual void SetValue( int row, int col, const wxString& value ) = 0;
1131 // virtuals overridable in wxPyGridTableBase
1132 virtual wxString GetTypeName( int row, int col );
1133 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
1134 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
1135 virtual long GetValueAsLong( int row, int col );
1136 virtual double GetValueAsDouble( int row, int col );
1137 virtual bool GetValueAsBool( int row, int col );
1138 virtual void SetValueAsLong( int row, int col, long value );
1139 virtual void SetValueAsDouble( int row, int col, double value );
1140 virtual void SetValueAsBool( int row, int col, bool value );
1142 //virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
1143 //virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
1146 virtual void Clear();
1147 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
1148 virtual bool AppendRows( size_t numRows = 1 );
1149 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
1150 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
1151 virtual bool AppendCols( size_t numCols = 1 );
1152 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
1154 virtual wxString GetRowLabelValue( int row );
1155 virtual wxString GetColLabelValue( int col );
1156 virtual void SetRowLabelValue( int row, const wxString& value );
1157 virtual void SetColLabelValue( int col, const wxString& value );
1159 virtual bool CanHaveAttributes();
1161 virtual wxGridCellAttr *GetAttr( int row, int col,
1162 wxGridCellAttr::wxAttrKind kind);
1163 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
1164 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
1165 virtual void SetColAttr(wxGridCellAttr *attr, int col);
1171 // Python-aware version
1173 class wxPyGridTableBase : public wxGridTableBase
1176 wxPyGridTableBase() : wxGridTableBase() {}
1178 PYCALLBACK_INT__pure(GetNumberRows);
1179 PYCALLBACK_INT__pure(GetNumberCols);
1180 PYCALLBACK_BOOL_INTINT_pure(IsEmptyCell);
1181 PYCALLBACK_STRING_INTINT(wxGridTableBase, GetTypeName);
1182 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanGetValueAs);
1183 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanSetValueAs);
1184 PYCALLBACK__(wxGridTableBase, Clear);
1185 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertRows);
1186 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteRows);
1187 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertCols);
1188 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteCols);
1189 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendRows);
1190 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendCols);
1191 PYCALLBACK_STRING_INT(wxGridTableBase, GetRowLabelValue);
1192 PYCALLBACK_STRING_INT(wxGridTableBase, GetColLabelValue);
1193 PYCALLBACK__INTSTRING(wxGridTableBase, SetRowLabelValue);
1194 PYCALLBACK__INTSTRING(wxGridTableBase, SetColLabelValue);
1195 PYCALLBACK_BOOL_(wxGridTableBase, CanHaveAttributes);
1196 PYCALLBACK_GCA_INTINTKIND(wxGridTableBase, GetAttr);
1197 PYCALLBACK__GCAINTINT(wxGridTableBase, SetAttr);
1198 PYCALLBACK__GCAINT(wxGridTableBase, SetRowAttr);
1199 PYCALLBACK__GCAINT(wxGridTableBase, SetColAttr);
1202 wxString GetValue(int row, int col) {
1203 wxPyBeginBlockThreads();
1205 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1207 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",row,col));
1209 rval = Py2wxString(ro);
1213 wxPyEndBlockThreads();
1217 void SetValue(int row, int col, const wxString& val) {
1218 wxPyBeginBlockThreads();
1219 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1220 PyObject* s = wx2PyString(val);
1221 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",row,col,s));
1224 wxPyEndBlockThreads();
1228 // Map the Get/Set methods for the standard non-string types to
1229 // the GetValue and SetValue python methods.
1230 long GetValueAsLong( int row, int col ) {
1232 wxPyBeginBlockThreads();
1233 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1236 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1237 if (ro && PyNumber_Check(ro)) {
1238 num = PyNumber_Int(ro);
1240 rval = PyInt_AsLong(num);
1246 wxPyEndBlockThreads();
1250 double GetValueAsDouble( int row, int col ) {
1252 wxPyBeginBlockThreads();
1253 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1256 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1257 if (ro && PyNumber_Check(ro)) {
1258 num = PyNumber_Float(ro);
1260 rval = PyFloat_AsDouble(num);
1266 wxPyEndBlockThreads();
1270 bool GetValueAsBool( int row, int col ) {
1271 return (bool)GetValueAsLong(row, col);
1274 void SetValueAsLong( int row, int col, long value ) {
1275 wxPyBeginBlockThreads();
1276 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1277 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", row, col, value));
1279 wxPyEndBlockThreads();
1282 void SetValueAsDouble( int row, int col, double value ) {
1283 wxPyBeginBlockThreads();
1284 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1285 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iid)", row, col, value));
1287 wxPyEndBlockThreads();
1290 void SetValueAsBool( int row, int col, bool value ) {
1291 SetValueAsLong( row, col, (long)value );
1300 // The python-aware version get's SWIGified
1301 class wxPyGridTableBase : public wxGridTableBase
1304 wxPyGridTableBase();
1305 void _setCallbackInfo(PyObject* self, PyObject* _class);
1306 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridTableBase)"
1307 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1309 %addmethods { void Destroy() { delete self; } }
1311 wxString base_GetTypeName( int row, int col );
1312 bool base_CanGetValueAs( int row, int col, const wxString& typeName );
1313 bool base_CanSetValueAs( int row, int col, const wxString& typeName );
1315 bool base_InsertRows( size_t pos = 0, size_t numRows = 1 );
1316 bool base_AppendRows( size_t numRows = 1 );
1317 bool base_DeleteRows( size_t pos = 0, size_t numRows = 1 );
1318 bool base_InsertCols( size_t pos = 0, size_t numCols = 1 );
1319 bool base_AppendCols( size_t numCols = 1 );
1320 bool base_DeleteCols( size_t pos = 0, size_t numCols = 1 );
1321 wxString base_GetRowLabelValue( int row );
1322 wxString base_GetColLabelValue( int col );
1323 void base_SetRowLabelValue( int row, const wxString& value );
1324 void base_SetColLabelValue( int col, const wxString& value );
1325 bool base_CanHaveAttributes();
1326 wxGridCellAttr *base_GetAttr( int row, int col,
1327 wxGridCellAttr::wxAttrKind kind );
1328 void base_SetAttr(wxGridCellAttr* attr, int row, int col);
1329 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1330 void base_SetColAttr(wxGridCellAttr *attr, int col);
1334 //---------------------------------------------------------------------------
1335 // Predefined Tables
1337 class wxGridStringTable : public wxGridTableBase
1340 wxGridStringTable( int numRows=0, int numCols=0 );
1341 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1344 //---------------------------------------------------------------------------
1345 // The Table can pass messages to the grid to tell it to update itself if
1346 // something has changed.
1348 enum wxGridTableRequest
1350 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
1351 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
1352 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
1353 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
1354 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
1355 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1356 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
1357 wxGRIDTABLE_NOTIFY_COLS_DELETED
1361 class wxGridTableMessage
1364 wxGridTableMessage( wxGridTableBase *table, int id,
1367 ~wxGridTableMessage();
1369 void SetTableObject( wxGridTableBase *table );
1370 wxGridTableBase * GetTableObject() const;
1371 void SetId( int id );
1373 void SetCommandInt( int comInt1 );
1374 int GetCommandInt();
1375 void SetCommandInt2( int comInt2 );
1376 int GetCommandInt2();
1380 //---------------------------------------------------------------------------
1382 class wxGridCellCoords
1385 wxGridCellCoords( int r=-1, int c=-1 );
1386 ~wxGridCellCoords();
1388 int GetRow() const { return m_row; }
1389 void SetRow( int n ) { m_row = n; }
1390 int GetCol() const { return m_col; }
1391 void SetCol( int n ) { m_col = n; }
1392 void Set( int row, int col ) { m_row = row; m_col = col; }
1395 PyObject* asTuple() {
1396 PyObject* tup = PyTuple_New(2);
1397 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
1398 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
1402 int __cmp__( const wxGridCellCoords& other ) {
1403 return *self != other;
1406 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
1407 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
1410 // Typemap to allow conversion of sequence objects to wxGridCellCoords...
1411 %typemap(python,in) wxGridCellCoords& (wxGridCellCoords temp) {
1413 if (! wxGridCellCoords_helper($source, &$target))
1417 // ...and here is the associated helper.
1419 bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) {
1421 // If source is an object instance then it may already be the right type
1422 if (PyInstance_Check(source)) {
1423 wxGridCellCoords* ptr;
1424 if (SWIG_GetPtrObj(source, (void **)&ptr, "_wxGridCellCoords_p"))
1429 // otherwise a 2-tuple of integers is expected
1430 else if (PySequence_Check(source) && PyObject_Length(source) == 2) {
1431 PyObject* o1 = PySequence_GetItem(source, 0);
1432 PyObject* o2 = PySequence_GetItem(source, 1);
1433 **obj = wxGridCellCoords(PyInt_AsLong(o1), PyInt_AsLong(o2));
1438 PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of integers or a wxGridCellCoords object.");
1443 //---------------------------------------------------------------------------
1444 //---------------------------------------------------------------------------
1448 // Fool SWIG into treating this enum as an int
1449 typedef int WXGRIDSELECTIONMODES;
1451 // but let the C++ code know what it really is.
1453 typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES;
1458 class wxGrid : public wxScrolledWindow
1461 wxGrid( wxWindow *parent,
1463 const wxPoint& pos = wxDefaultPosition,
1464 const wxSize& size = wxDefaultSize,
1465 long style = wxWANTS_CHARS,
1466 const wxString& name = wxPyPanelNameStr);
1468 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1470 enum wxGridSelectionModes {wxGridSelectCells,
1472 wxGridSelectColumns};
1474 bool CreateGrid( int numRows, int numCols,
1475 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1476 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1479 // ------ grid dimensions
1481 int GetNumberRows();
1482 int GetNumberCols();
1485 bool ProcessTableMessage( wxGridTableMessage& );
1488 wxGridTableBase * GetTable() const;
1489 bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE,
1490 WXGRIDSELECTIONMODES selmode =
1491 wxGrid::wxGridSelectCells );
1494 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1495 bool AppendRows( int numRows = 1, bool updateLabels=TRUE );
1496 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1497 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1498 bool AppendCols( int numCols = 1, bool updateLabels=TRUE );
1499 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1502 // this function is called when the current cell highlight must be redrawn
1503 // and may be overridden by the user
1504 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1507 // ------ Cell text drawing functions
1509 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1510 int horizontalAlignment = wxLEFT,
1511 int verticalAlignment = wxTOP );
1513 // // Split a string containing newline chararcters into an array of
1514 // // strings and return the number of lines
1516 // void StringToLines( const wxString& value, wxArrayString& lines );
1518 void GetTextBoxSize( wxDC& dc,
1519 wxArrayString& lines,
1520 long *OUTPUT, long *OUTPUT );
1524 // Code that does a lot of grid modification can be enclosed
1525 // between BeginBatch() and EndBatch() calls to avoid screen
1530 int GetBatchCount();
1531 void ForceRefresh();
1532 void Refresh(bool eraseb=TRUE, wxRect* rect= NULL);
1535 // ------ edit control functions
1538 void EnableEditing( bool edit );
1540 void EnableCellEditControl( bool enable = TRUE );
1541 void DisableCellEditControl();
1542 bool CanEnableCellControl() const;
1543 bool IsCellEditControlEnabled() const;
1544 bool IsCellEditControlShown() const;
1546 bool IsCurrentCellReadOnly() const;
1548 void ShowCellEditControl();
1549 void HideCellEditControl();
1550 void SaveEditControlValue();
1553 // ------ grid location functions
1554 // Note that all of these functions work with the logical coordinates of
1555 // grid cells and labels so you will need to convert from device
1556 // coordinates for mouse events etc.
1559 //void XYToCell( int x, int y, wxGridCellCoords& );
1561 %new wxGridCellCoords* XYToCell(int x, int y) {
1562 wxGridCellCoords rv;
1563 self->XYToCell(x, y, rv);
1564 return new wxGridCellCoords(rv);
1568 int YToRow( int y );
1569 int XToCol( int x );
1571 int YToEdgeOfRow( int y );
1572 int XToEdgeOfCol( int x );
1574 wxRect CellToRect( int row, int col );
1575 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1578 int GetGridCursorRow();
1579 int GetGridCursorCol();
1581 // check to see if a cell is either wholly visible (the default arg) or
1582 // at least partially visible in the grid window
1584 bool IsVisible( int row, int col, bool wholeCellVisible = TRUE );
1585 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE );
1586 void MakeCellVisible( int row, int col );
1587 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1590 // ------ grid cursor movement functions
1592 void SetGridCursor( int row, int col );
1593 bool MoveCursorUp( bool expandSelection );
1594 bool MoveCursorDown( bool expandSelection );
1595 bool MoveCursorLeft( bool expandSelection );
1596 bool MoveCursorRight( bool expandSelection );
1597 bool MovePageDown();
1599 bool MoveCursorUpBlock( bool expandSelection );
1600 bool MoveCursorDownBlock( bool expandSelection );
1601 bool MoveCursorLeftBlock( bool expandSelection );
1602 bool MoveCursorRightBlock( bool expandSelection );
1605 // ------ label and gridline formatting
1607 int GetDefaultRowLabelSize();
1608 int GetRowLabelSize();
1609 int GetDefaultColLabelSize();
1610 int GetColLabelSize();
1611 wxColour GetLabelBackgroundColour();
1612 wxColour GetLabelTextColour();
1613 wxFont GetLabelFont();
1614 void GetRowLabelAlignment( int *OUTPUT, int *OUTPUT );
1615 void GetColLabelAlignment( int *OUTPUT, int *OUTPUT );
1616 wxString GetRowLabelValue( int row );
1617 wxString GetColLabelValue( int col );
1618 wxColour GetGridLineColour();
1619 wxColour GetCellHighlightColour();
1620 int GetCellHighlightPenWidth();
1621 int GetCellHighlightROPenWidth();
1623 void SetRowLabelSize( int width );
1624 void SetColLabelSize( int height );
1625 void SetLabelBackgroundColour( const wxColour& );
1626 void SetLabelTextColour( const wxColour& );
1627 void SetLabelFont( const wxFont& );
1628 void SetRowLabelAlignment( int horiz, int vert );
1629 void SetColLabelAlignment( int horiz, int vert );
1630 void SetRowLabelValue( int row, const wxString& );
1631 void SetColLabelValue( int col, const wxString& );
1632 void SetGridLineColour( const wxColour& );
1633 void SetCellHighlightColour( const wxColour& );
1634 void SetCellHighlightPenWidth(int width);
1635 void SetCellHighlightROPenWidth(int width);
1637 void EnableDragRowSize( bool enable = TRUE );
1638 void DisableDragRowSize();
1639 bool CanDragRowSize();
1640 void EnableDragColSize( bool enable = TRUE );
1641 void DisableDragColSize();
1642 bool CanDragColSize();
1643 void EnableDragGridSize(bool enable = TRUE);
1644 void DisableDragGridSize();
1645 bool CanDragGridSize();
1647 // this sets the specified attribute for all cells in this row/col
1648 void SetAttr(int row, int col, wxGridCellAttr *attr);
1649 void SetRowAttr(int row, wxGridCellAttr *attr);
1650 void SetColAttr(int col, wxGridCellAttr *attr);
1652 // shortcuts for setting the column parameters
1654 // set the format for the data in the column: default is string
1655 void SetColFormatBool(int col);
1656 void SetColFormatNumber(int col);
1657 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1658 void SetColFormatCustom(int col, const wxString& typeName);
1660 void EnableGridLines( bool enable = TRUE );
1661 bool GridLinesEnabled();
1663 // ------ row and col formatting
1665 int GetDefaultRowSize();
1666 int GetRowSize( int row );
1667 int GetDefaultColSize();
1668 int GetColSize( int col );
1669 wxColour GetDefaultCellBackgroundColour();
1670 wxColour GetCellBackgroundColour( int row, int col );
1671 wxColour GetDefaultCellTextColour();
1672 wxColour GetCellTextColour( int row, int col );
1673 wxFont GetDefaultCellFont();
1674 wxFont GetCellFont( int row, int col );
1675 void GetDefaultCellAlignment( int *horiz, int *vert );
1676 void GetCellAlignment( int row, int col, int *horiz, int *vert );
1677 bool GetDefaultCellOverflow();
1678 bool GetCellOverflow( int row, int col );
1679 void GetCellSize( int row, int col, int *OUTPUT, int *OUTPUT );
1681 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
1682 void SetRowSize( int row, int height );
1683 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
1685 void SetColSize( int col, int width );
1687 // automatically size the column or row to fit to its contents, if
1688 // setAsMin is TRUE, this optimal width will also be set as minimal width
1690 void AutoSizeColumn( int col, bool setAsMin = TRUE );
1691 void AutoSizeRow( int row, bool setAsMin = TRUE );
1694 // auto size all columns (very ineffective for big grids!)
1695 void AutoSizeColumns( bool setAsMin = TRUE );
1696 void AutoSizeRows( bool setAsMin = TRUE );
1698 // auto size the grid, that is make the columns/rows of the "right" size
1699 // and also set the grid size to just fit its contents
1702 // column won't be resized to be lesser width - this must be called during
1703 // the grid creation because it won't resize the column if it's already
1704 // narrower than the minimal width
1705 void SetColMinimalWidth( int col, int width );
1706 void SetRowMinimalHeight( int row, int width );
1708 void SetDefaultCellBackgroundColour( const wxColour& );
1709 void SetCellBackgroundColour( int row, int col, const wxColour& );
1710 void SetDefaultCellTextColour( const wxColour& );
1712 void SetCellTextColour( int row, int col, const wxColour& );
1713 void SetDefaultCellFont( const wxFont& );
1714 void SetCellFont( int row, int col, const wxFont& );
1715 void SetDefaultCellAlignment( int horiz, int vert );
1716 void SetCellAlignment( int row, int col, int horiz, int vert );
1717 void SetDefaultCellOverflow( bool allow );
1718 void SetCellOverflow( int row, int col, bool allow );
1719 void SetCellSize( int row, int col, int num_rows, int num_cols );
1721 // takes ownership of the pointer
1722 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1723 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1724 wxGridCellRenderer *GetDefaultRenderer() const;
1725 wxGridCellRenderer* GetCellRenderer(int row, int col);
1727 // takes ownership of the pointer
1728 void SetDefaultEditor(wxGridCellEditor *editor);
1729 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1730 wxGridCellEditor *GetDefaultEditor() const;
1731 wxGridCellEditor* GetCellEditor(int row, int col);
1735 // ------ cell value accessors
1737 wxString GetCellValue( int row, int col );
1738 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1740 void SetCellValue( int row, int col, const wxString& s );
1741 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1743 // returns TRUE if the cell can't be edited
1744 bool IsReadOnly(int row, int col) const;
1746 // make the cell editable/readonly
1747 void SetReadOnly(int row, int col, bool isReadOnly = TRUE);
1749 // ------ selections of blocks of cells
1751 void SelectRow( int row, bool addToSelected = FALSE );
1752 void SelectCol( int col, bool addToSelected = FALSE );
1754 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1755 bool addToSelected = FALSE );
1756 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1757 // TODO: ??? const wxGridCellCoords& bottomRight )
1761 void ClearSelection();
1762 bool IsInSelection( int row, int col );
1763 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1766 // This function returns the rectangle that encloses the block of cells
1767 // limited by TopLeft and BottomRight cell in device coords and clipped
1768 // to the client size of the grid window.
1770 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1771 const wxGridCellCoords & bottomRight );
1774 // Access or update the selection fore/back colours
1775 wxColour GetSelectionBackground() const;
1776 wxColour GetSelectionForeground() const;
1778 void SetSelectionBackground(const wxColour& c);
1779 void SetSelectionForeground(const wxColour& c);
1782 // Methods for a registry for mapping data types to Renderers/Editors
1783 void RegisterDataType(const wxString& typeName,
1784 wxGridCellRenderer* renderer,
1785 wxGridCellEditor* editor);
1786 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1787 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1788 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1789 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1790 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1792 // grid may occupy more space than needed for its rows/columns, this
1793 // function allows to set how big this extra space is
1794 void SetMargins(int extraWidth, int extraHeight);
1797 // Accessors for component windows
1798 wxWindow* GetGridWindow();
1799 wxWindow* GetGridRowLabelWindow();
1800 wxWindow* GetGridColLabelWindow();
1801 wxWindow* GetGridCornerLabelWindow();
1807 //---------------------------------------------------------------------------
1808 //---------------------------------------------------------------------------
1809 // Grid events and stuff
1813 class wxGridEvent : public wxNotifyEvent
1816 wxGridEvent(int id, wxEventType type, wxGrid* obj,
1817 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = TRUE,
1818 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1820 virtual int GetRow();
1821 virtual int GetCol();
1822 wxPoint GetPosition();
1832 class wxGridSizeEvent : public wxNotifyEvent
1835 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
1836 int rowOrCol=-1, int x=-1, int y=-1,
1837 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1840 wxPoint GetPosition();
1849 class wxGridRangeSelectEvent : public wxNotifyEvent
1852 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
1853 const wxGridCellCoords& topLeft,
1854 const wxGridCellCoords& bottomRight,
1856 bool control=FALSE, bool shift=FALSE,
1857 bool alt=FALSE, bool meta=FALSE);
1859 wxGridCellCoords GetTopLeftCoords();
1860 wxGridCellCoords GetBottomRightCoords();
1873 class wxGridEditorCreatedEvent : public wxCommandEvent {
1875 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
1876 int row, int col, wxControl* ctrl);
1880 wxControl* GetControl();
1881 void SetRow(int row);
1882 void SetCol(int col);
1883 void SetControl(wxControl* ctrl);
1889 wxEVT_GRID_CELL_LEFT_CLICK,
1890 wxEVT_GRID_CELL_RIGHT_CLICK,
1891 wxEVT_GRID_CELL_LEFT_DCLICK,
1892 wxEVT_GRID_CELL_RIGHT_DCLICK,
1893 wxEVT_GRID_LABEL_LEFT_CLICK,
1894 wxEVT_GRID_LABEL_RIGHT_CLICK,
1895 wxEVT_GRID_LABEL_LEFT_DCLICK,
1896 wxEVT_GRID_LABEL_RIGHT_DCLICK,
1897 wxEVT_GRID_ROW_SIZE,
1898 wxEVT_GRID_COL_SIZE,
1899 wxEVT_GRID_RANGE_SELECT,
1900 wxEVT_GRID_CELL_CHANGE,
1901 wxEVT_GRID_SELECT_CELL,
1902 wxEVT_GRID_EDITOR_SHOWN,
1903 wxEVT_GRID_EDITOR_HIDDEN,
1904 wxEVT_GRID_EDITOR_CREATED,
1909 %pragma(python) code = "
1910 def EVT_GRID_CELL_LEFT_CLICK(win, fn):
1911 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_CLICK, fn)
1913 def EVT_GRID_CELL_RIGHT_CLICK(win, fn):
1914 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_CLICK, fn)
1916 def EVT_GRID_CELL_LEFT_DCLICK(win, fn):
1917 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_DCLICK, fn)
1919 def EVT_GRID_CELL_RIGHT_DCLICK(win, fn):
1920 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_DCLICK, fn)
1922 def EVT_GRID_LABEL_LEFT_CLICK(win, fn):
1923 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_CLICK, fn)
1925 def EVT_GRID_LABEL_RIGHT_CLICK(win, fn):
1926 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_CLICK, fn)
1928 def EVT_GRID_LABEL_LEFT_DCLICK(win, fn):
1929 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_DCLICK, fn)
1931 def EVT_GRID_LABEL_RIGHT_DCLICK(win, fn):
1932 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_DCLICK, fn)
1934 def EVT_GRID_ROW_SIZE(win, fn):
1935 win.Connect(-1, -1, wxEVT_GRID_ROW_SIZE, fn)
1937 def EVT_GRID_COL_SIZE(win, fn):
1938 win.Connect(-1, -1, wxEVT_GRID_COL_SIZE, fn)
1940 def EVT_GRID_RANGE_SELECT(win, fn):
1941 win.Connect(-1, -1, wxEVT_GRID_RANGE_SELECT, fn)
1943 def EVT_GRID_CELL_CHANGE(win, fn):
1944 win.Connect(-1, -1, wxEVT_GRID_CELL_CHANGE, fn)
1946 def EVT_GRID_SELECT_CELL(win, fn):
1947 win.Connect(-1, -1, wxEVT_GRID_SELECT_CELL, fn)
1949 def EVT_GRID_EDITOR_SHOWN(win, fn):
1950 win.Connect(-1, -1, wxEVT_GRID_EDITOR_SHOWN, fn)
1952 def EVT_GRID_EDITOR_HIDDEN(win, fn):
1953 win.Connect(-1, -1, wxEVT_GRID_EDITOR_HIDDEN, fn)
1955 def EVT_GRID_EDITOR_CREATED(win, fn):
1956 win.Connect(-1, -1, wxEVT_GRID_EDITOR_CREATED, fn)
1960 //---------------------------------------------------------------------------
1963 wxClassInfo::CleanUpClasses();
1964 wxClassInfo::InitializeClasses();
1967 //---------------------------------------------------------------------------
1969 %pragma(python) include="_gridextras.py";
1971 //---------------------------------------------------------------------------