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 //---------------------------------------------------------------------------
49 // Macros, similar to what's in helpers.h, to aid in the creation of
50 // virtual methods that are able to make callbacks to Python. Many of these
51 // are specific to wxGrid and so are kept here to reduce the mess in helpers.h
56 #define PYCALLBACK_GCA_INTINTKIND(PCLASS, CBNAME) \
57 wxGridCellAttr* CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
58 wxGridCellAttr* rval = NULL; \
60 wxPyBeginBlockThreads(); \
61 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
63 wxGridCellAttr* ptr; \
64 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iii)", a, b, c)); \
66 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellAttr_p")) \
71 wxPyEndBlockThreads(); \
73 rval = PCLASS::CBNAME(a, b, c); \
76 wxGridCellAttr *base_##CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
77 return PCLASS::CBNAME(a, b, c); \
82 #define PYCALLBACK__GCAINTINT(PCLASS, CBNAME) \
83 void CBNAME(wxGridCellAttr *attr, int a, int b) { \
84 wxPyBeginBlockThreads(); \
86 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
87 PyObject* obj = wxPyConstructObject((void*)attr, "wxGridCellAttr", 0);\
88 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oii)", obj, a, b)); \
91 wxPyEndBlockThreads(); \
93 PCLASS::CBNAME(attr, a, b); \
95 void base_##CBNAME(wxGridCellAttr *attr, int a, int b) { \
96 PCLASS::CBNAME(attr, a, b); \
101 #define PYCALLBACK__GCAINT(PCLASS, CBNAME) \
102 void CBNAME(wxGridCellAttr *attr, int val) { \
103 wxPyBeginBlockThreads(); \
105 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
106 PyObject* obj = wxPyConstructObject((void*)attr, "wxGridCellAttr", 0);\
107 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, val)); \
110 wxPyEndBlockThreads(); \
112 PCLASS::CBNAME(attr, val); \
114 void base_##CBNAME(wxGridCellAttr *attr, int val) { \
115 PCLASS::CBNAME(attr, val); \
120 #define PYCALLBACK_INT__pure(CBNAME) \
122 wxPyBeginBlockThreads(); \
124 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
125 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
126 wxPyEndBlockThreads(); \
132 #define PYCALLBACK_BOOL_INTINT_pure(CBNAME) \
133 bool CBNAME(int a, int b) { \
134 wxPyBeginBlockThreads(); \
136 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
137 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
138 wxPyEndBlockThreads(); \
143 #define PYCALLBACK_STRING_INTINT_pure(CBNAME) \
144 wxString CBNAME(int a, int b) { \
145 wxPyBeginBlockThreads(); \
147 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
149 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
151 rval = Py2wxString(ro); \
155 wxPyEndBlockThreads(); \
160 #define PYCALLBACK__INTINTSTRING_pure(CBNAME) \
161 void CBNAME(int a, int b, const wxString& c) { \
162 wxPyBeginBlockThreads(); \
163 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
164 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,wx2PyString(c)));\
165 wxPyEndBlockThreads(); \
169 #define PYCALLBACK_STRING_INTINT(PCLASS, CBNAME) \
170 wxString CBNAME(int a, int b) { \
172 wxPyBeginBlockThreads(); \
174 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
176 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
178 rval = Py2wxString(ro); \
182 wxPyEndBlockThreads(); \
184 rval = PCLASS::CBNAME(a, b); \
187 wxString base_##CBNAME(int a, int b) { \
188 return PCLASS::CBNAME(a, b); \
192 #define PYCALLBACK_BOOL_INTINTSTRING(PCLASS, CBNAME) \
193 bool CBNAME(int a, int b, const wxString& c) { \
196 wxPyBeginBlockThreads(); \
197 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
198 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", a,b,wx2PyString(c)));\
199 wxPyEndBlockThreads(); \
201 rval = PCLASS::CBNAME(a,b,c); \
204 bool base_##CBNAME(int a, int b, const wxString& c) { \
205 return PCLASS::CBNAME(a,b,c); \
211 #define PYCALLBACK_LONG_INTINT(PCLASS, CBNAME) \
212 long CBNAME(int a, int b) { \
215 wxPyBeginBlockThreads(); \
216 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
217 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
218 wxPyEndBlockThreads(); \
220 rval = PCLASS::CBNAME(a,b); \
223 long base_##CBNAME(int a, int b) { \
224 return PCLASS::CBNAME(a,b); \
229 #define PYCALLBACK_BOOL_INTINT(PCLASS, CBNAME) \
230 bool CBNAME(int a, int b) { \
233 wxPyBeginBlockThreads(); \
234 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
235 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
236 wxPyEndBlockThreads(); \
238 rval = PCLASS::CBNAME(a,b); \
241 bool base_##CBNAME(int a, int b) { \
242 return PCLASS::CBNAME(a,b); \
247 #define PYCALLBACK_DOUBLE_INTINT(PCLASS, CBNAME) \
248 double CBNAME(int a, int b) { \
250 wxPyBeginBlockThreads(); \
252 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
254 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
256 PyObject* str = PyObject_Str(ro); \
257 rval = PyFloat_AsDouble(str); \
258 Py_DECREF(ro); Py_DECREF(str); \
261 wxPyEndBlockThreads(); \
263 rval = PCLASS::CBNAME(a, b); \
266 double base_##CBNAME(int a, int b) { \
267 return PCLASS::CBNAME(a, b); \
272 #define PYCALLBACK__(PCLASS, CBNAME) \
275 wxPyBeginBlockThreads(); \
276 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
277 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
278 wxPyEndBlockThreads(); \
282 void base_##CBNAME() { \
289 #define PYCALLBACK_BOOL_SIZETSIZET(PCLASS, CBNAME) \
290 bool CBNAME(size_t a, size_t b) { \
293 wxPyBeginBlockThreads(); \
294 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
295 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
296 wxPyEndBlockThreads(); \
298 rval = PCLASS::CBNAME(a,b); \
301 bool base_##CBNAME(size_t a, size_t b) { \
302 return PCLASS::CBNAME(a,b); \
307 #define PYCALLBACK_BOOL_SIZET(PCLASS, CBNAME) \
308 bool CBNAME(size_t a) { \
311 wxPyBeginBlockThreads(); \
312 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
313 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)", a)); \
314 wxPyEndBlockThreads(); \
316 rval = PCLASS::CBNAME(a); \
319 bool base_##CBNAME(size_t a) { \
320 return PCLASS::CBNAME(a); \
324 #define PYCALLBACK_STRING_INT(PCLASS, CBNAME) \
325 wxString CBNAME(int a) { \
327 wxPyBeginBlockThreads(); \
329 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
331 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(i)",a)); \
333 rval = Py2wxString(ro); \
337 wxPyEndBlockThreads(); \
339 rval = PCLASS::CBNAME(a); \
342 wxString base_##CBNAME(int a) { \
343 return PCLASS::CBNAME(a); \
347 #define PYCALLBACK__INTSTRING(PCLASS, CBNAME) \
348 void CBNAME(int a, const wxString& c) { \
350 wxPyBeginBlockThreads(); \
351 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
352 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", a, wx2PyString(c))); \
353 wxPyEndBlockThreads(); \
355 PCLASS::CBNAME(a,c); \
357 void base_##CBNAME(int a, const wxString& c) { \
358 PCLASS::CBNAME(a,c); \
364 #define PYCALLBACK_BOOL_(PCLASS, CBNAME) \
368 wxPyBeginBlockThreads(); \
369 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
370 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
371 wxPyEndBlockThreads(); \
373 rval = PCLASS::CBNAME(); \
376 bool base_##CBNAME() { \
377 return PCLASS::CBNAME(); \
382 #define PYCALLBACK__SIZETINT(PCLASS, CBNAME) \
383 void CBNAME(size_t a, int b) { \
385 wxPyBeginBlockThreads(); \
386 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
387 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
388 wxPyEndBlockThreads(); \
390 PCLASS::CBNAME(a,b); \
392 void base_##CBNAME(size_t a, int b) { \
393 PCLASS::CBNAME(a,b); \
399 #define PYCALLBACK__INTINTLONG(PCLASS, CBNAME) \
400 void CBNAME(int a, int b, long c) { \
402 wxPyBeginBlockThreads(); \
403 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
404 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
405 wxPyEndBlockThreads(); \
407 PCLASS::CBNAME(a,b,c); \
409 void base_##CBNAME(int a, int b, long c) { \
410 PCLASS::CBNAME(a,b,c); \
416 #define PYCALLBACK__INTINTDOUBLE(PCLASS, CBNAME) \
417 void CBNAME(int a, int b, double c) { \
419 wxPyBeginBlockThreads(); \
420 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
421 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iif)", a,b,c)); \
422 wxPyEndBlockThreads(); \
424 PCLASS::CBNAME(a,b,c); \
426 void base_##CBNAME(int a, int b, double c) { \
427 PCLASS::CBNAME(a,b,c); \
432 #define PYCALLBACK__INTINTBOOL(PCLASS, CBNAME) \
433 void CBNAME(int a, int b, bool c) { \
435 wxPyBeginBlockThreads(); \
436 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
437 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
438 wxPyEndBlockThreads(); \
440 PCLASS::CBNAME(a,b,c); \
442 void base_##CBNAME(int a, int b, bool c) { \
443 PCLASS::CBNAME(a,b,c); \
451 //---------------------------------------------------------------------------
452 // OOR related typemaps and helper functions
454 %typemap(python, out) wxGridCellRenderer* { $target = wxPyMake_wxGridCellRenderer($source); }
455 %typemap(python, out) wxGridCellEditor* { $target = wxPyMake_wxGridCellEditor($source); }
456 %typemap(python, out) wxGridCellAttr* { $target = wxPyMake_wxGridCellAttr($source); }
457 %typemap(python, out) wxGridCellAttrProvider* { $target = wxPyMake_wxGridCellAttrProvider($source); }
458 %typemap(python, out) wxGridTableBase* { $target = wxPyMake_wxGridTableBase($source); }
463 #define wxPyMake_TEMPLATE(TYPE) \
464 PyObject* wxPyMake_##TYPE(TYPE* source) { \
465 PyObject* target = NULL; \
467 /* Check if there is already a pointer to a Python object in the \
468 OOR data that we can use. */ \
469 wxPyOORClientData* data = (wxPyOORClientData*)source->GetClientObject(); \
471 target = data->m_obj; \
474 /* Otherwise make a new wrapper for it the old fashioned way and \
475 give it the OOR treatment */ \
477 target = wxPyConstructObject(source, #TYPE, FALSE); \
479 source->SetClientObject(new wxPyOORClientData(target)); \
481 } else { /* source was NULL so return None. */ \
482 Py_INCREF(Py_None); target = Py_None; \
487 wxPyMake_TEMPLATE(wxGridCellRenderer)
488 wxPyMake_TEMPLATE(wxGridCellEditor)
489 wxPyMake_TEMPLATE(wxGridCellAttr)
490 wxPyMake_TEMPLATE(wxGridCellAttrProvider)
491 wxPyMake_TEMPLATE(wxGridTableBase)
495 //---------------------------------------------------------------------------
497 class wxGridCellCoords;
498 class wxGridCellAttr;
500 #define wxGRID_VALUE_STRING "string"
501 #define wxGRID_VALUE_BOOL "bool"
502 #define wxGRID_VALUE_NUMBER "long"
503 #define wxGRID_VALUE_FLOAT "double"
504 #define wxGRID_VALUE_CHOICE "choice"
505 #define wxGRID_VALUE_TEXT "string"
506 #define wxGRID_VALUE_LONG "long"
507 #define wxGRID_VALUE_CHOICEINT "choiceint"
508 #define wxGRID_VALUE_DATETIME "datetime"
512 wxGridCellCoords wxGridNoCellCoords;
513 wxRect wxGridNoCellRect;
517 //---------------------------------------------------------------------------
518 // wxGridCellRenderer is an ABC, and several derived classes are available.
519 // Classes implemented in Python should be derived from wxPyGridCellRenderer.
522 class wxGridCellRenderer
526 void _setOORInfo(PyObject* _self) {
527 self->SetClientObject(new wxPyOORClientData(_self));
531 void SetParameters(const wxString& params);
535 virtual void Draw(wxGrid& grid,
536 wxGridCellAttr& attr,
540 bool isSelected) = 0;
541 virtual wxSize GetBestSize(wxGrid& grid,
542 wxGridCellAttr& attr,
544 int row, int col) = 0;
545 virtual wxGridCellRenderer *Clone() const = 0;
549 // The C++ version of wxPyGridCellRenderer
551 class wxPyGridCellRenderer : public wxGridCellRenderer
554 wxPyGridCellRenderer() : wxGridCellRenderer() {};
556 // Implement Python callback aware virtual methods
557 void Draw(wxGrid& grid, wxGridCellAttr& attr,
558 wxDC& dc, const wxRect& rect,
559 int row, int col, bool isSelected) {
560 wxPyBeginBlockThreads();
561 if (wxPyCBH_findCallback(m_myInst, "Draw")) {
562 wxPyCBH_callCallback(m_myInst,
563 Py_BuildValue("(OOOOiii)",
564 wxPyConstructObject((void*)&grid, "wxGrid", 0),
565 wxPyConstructObject((void*)&attr, "wxGridCellAttr", 0),
566 wxPyConstructObject((void*)&dc, "wxDC", 0),
567 wxPyConstructObject((void*)&rect, "wxRect", 0),
568 row, col, isSelected));
570 wxPyEndBlockThreads();
573 wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
576 wxPyBeginBlockThreads();
577 if (wxPyCBH_findCallback(m_myInst, "GetBestSize")) {
580 ro = wxPyCBH_callCallbackObj(m_myInst,
581 Py_BuildValue("(OOOii)",
582 wxPyConstructObject((void*)&grid, "wxGrid", 0),
583 wxPyConstructObject((void*)&attr, "wxGridCellAttr", 0),
584 wxPyConstructObject((void*)&dc, "wxDC", 0),
587 const char* errmsg = "GetBestSize should return a 2-tuple of integers or a wxSize object.";
588 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p")) {
591 else if (PySequence_Check(ro) && PyObject_Length(ro) == 2) {
592 PyObject* o1 = PySequence_GetItem(ro, 0);
593 PyObject* o2 = PySequence_GetItem(ro, 1);
594 if (PyNumber_Check(o1) && PyNumber_Check(o2))
595 rval = wxSize(PyInt_AsLong(o1), PyInt_AsLong(o2));
597 PyErr_SetString(PyExc_TypeError, errmsg);
602 PyErr_SetString(PyExc_TypeError, errmsg);
607 wxPyEndBlockThreads();
612 wxGridCellRenderer *Clone() const {
613 wxGridCellRenderer* rval = NULL;
614 wxPyBeginBlockThreads();
615 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
617 wxGridCellRenderer* ptr;
618 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
620 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellRenderer_p"))
625 wxPyEndBlockThreads();
629 DEC_PYCALLBACK__STRING(SetParameters);
634 IMP_PYCALLBACK__STRING( wxPyGridCellRenderer, wxGridCellRenderer, SetParameters);
639 // Let SWIG know about it so it can create the Python version
640 class wxPyGridCellRenderer : public wxGridCellRenderer {
642 wxPyGridCellRenderer();
643 void _setCallbackInfo(PyObject* self, PyObject* _class);
644 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellRenderer)"
645 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
647 void base_SetParameters(const wxString& params);
650 //---------------------------------------------------------------------------
651 // Predefined Renderers
653 class wxGridCellStringRenderer : public wxGridCellRenderer
656 wxGridCellStringRenderer();
657 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
661 class wxGridCellNumberRenderer : public wxGridCellStringRenderer
664 wxGridCellNumberRenderer();
665 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
669 class wxGridCellFloatRenderer : public wxGridCellStringRenderer
672 wxGridCellFloatRenderer(int width = -1, int precision = -1);
673 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
675 int GetWidth() const;
676 void SetWidth(int width);
677 int GetPrecision() const;
678 void SetPrecision(int precision);
682 class wxGridCellBoolRenderer : public wxGridCellRenderer
685 wxGridCellBoolRenderer();
686 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
690 class wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
693 wxGridCellDateTimeRenderer(wxString outformat = wxPyDateTimeFormatStr,
694 wxString informat = wxPyDateTimeFormatStr);
695 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
699 class wxGridCellEnumRenderer : public wxGridCellStringRenderer
702 wxGridCellEnumRenderer( const wxString& choices = wxPyEmptyString );
703 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
707 class wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer
710 wxGridCellAutoWrapStringRenderer();
711 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
715 //---------------------------------------------------------------------------
716 // wxGridCellEditor is an ABC, and several derived classes are available.
717 // Classes implemented in Python should be derived from wxPyGridCellEditor.
719 class wxGridCellEditor
723 void _setOORInfo(PyObject* _self) {
724 self->SetClientObject(new wxPyOORClientData(_self));
729 wxControl* GetControl();
730 void SetControl(wxControl* control);
732 void SetParameters(const wxString& params);
736 virtual void Create(wxWindow* parent,
738 wxEvtHandler* evtHandler) = 0;
739 virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
740 virtual bool EndEdit(int row, int col, wxGrid* grid) = 0;
741 virtual void Reset() = 0;
742 virtual wxGridCellEditor *Clone() const = 0;
744 virtual void SetSize(const wxRect& rect);
745 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
746 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
747 virtual bool IsAcceptedKey(wxKeyEvent& event);
748 virtual void StartingKey(wxKeyEvent& event);
749 virtual void StartingClick();
750 virtual void HandleReturn(wxKeyEvent& event);
751 virtual void Destroy();
756 // The C++ version of wxPyGridCellEditor
758 class wxPyGridCellEditor : public wxGridCellEditor
761 wxPyGridCellEditor() : wxGridCellEditor() {}
763 void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) {
764 wxPyBeginBlockThreads();
765 if (wxPyCBH_findCallback(m_myInst, "Create")) {
766 wxPyCBH_callCallback(m_myInst,
767 Py_BuildValue("(OiO)",
768 wxPyConstructObject((void*)parent, "wxWindow", 0),
770 wxPyConstructObject((void*)evtHandler, "wxEvtHandler", 0)));
772 wxPyEndBlockThreads();
776 void BeginEdit(int row, int col, wxGrid* grid) {
777 wxPyBeginBlockThreads();
778 if (wxPyCBH_findCallback(m_myInst, "BeginEdit")) {
779 wxPyCBH_callCallback(m_myInst,
780 Py_BuildValue("(iiO)", row, col,
781 wxPyConstructObject((void*)grid, "wxGrid", 0)));
783 wxPyEndBlockThreads();
787 bool EndEdit(int row, int col, wxGrid* grid) {
789 wxPyBeginBlockThreads();
790 if (wxPyCBH_findCallback(m_myInst, "EndEdit")) {
791 rv = wxPyCBH_callCallback(m_myInst,
792 Py_BuildValue("(iiO)", row, col,
793 wxPyConstructObject((void*)grid, "wxGrid", 0)));
795 wxPyEndBlockThreads();
800 wxGridCellEditor*Clone() const {
801 wxGridCellEditor* rval = NULL;
802 wxPyBeginBlockThreads();
803 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
805 wxGridCellEditor* ptr;
806 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
808 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellEditor_p"))
813 wxPyEndBlockThreads();
818 void Show(bool show, wxGridCellAttr *attr) {
820 wxPyBeginBlockThreads();
821 if ((found = wxPyCBH_findCallback(m_myInst, "Show")))
822 wxPyCBH_callCallback(m_myInst,
823 Py_BuildValue("(iO)", show,
824 wxPyConstructObject((void*)attr, "wxGridCellAttr", 0)));
825 wxPyEndBlockThreads();
827 wxGridCellEditor::Show(show, attr);
829 void base_Show(bool show, wxGridCellAttr *attr) {
830 wxGridCellEditor::Show(show, attr);
834 void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
836 wxPyBeginBlockThreads();
837 if ((found = wxPyCBH_findCallback(m_myInst, "PaintBackground)")))
838 wxPyCBH_callCallback(m_myInst,
839 Py_BuildValue("(OO)",
840 wxPyConstructObject((void*)&rectCell, "wxRect", 0),
841 wxPyConstructObject((void*)attr, "wxGridCellAttr", 0)));
842 wxPyEndBlockThreads();
844 wxGridCellEditor::PaintBackground(rectCell, attr);
846 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
847 wxGridCellEditor::PaintBackground(rectCell, attr);
851 DEC_PYCALLBACK___pure(Reset);
852 DEC_PYCALLBACK__constany(SetSize, wxRect);
853 DEC_PYCALLBACK_bool_any(IsAcceptedKey, wxKeyEvent);
854 DEC_PYCALLBACK__any(StartingKey, wxKeyEvent);
855 DEC_PYCALLBACK__any(HandleReturn, wxKeyEvent);
856 DEC_PYCALLBACK__(StartingClick);
857 DEC_PYCALLBACK__(Destroy);
858 DEC_PYCALLBACK__STRING(SetParameters);
864 IMP_PYCALLBACK__STRING( wxPyGridCellEditor, wxGridCellEditor, SetParameters);
865 IMP_PYCALLBACK___pure(wxPyGridCellEditor, wxGridCellEditor, Reset);
866 IMP_PYCALLBACK__constany(wxPyGridCellEditor, wxGridCellEditor, SetSize, wxRect);
867 IMP_PYCALLBACK_bool_any(wxPyGridCellEditor, wxGridCellEditor, IsAcceptedKey, wxKeyEvent);
868 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, StartingKey, wxKeyEvent);
869 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, HandleReturn, wxKeyEvent);
870 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, StartingClick);
871 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, Destroy);
876 // Let SWIG know about it so it can create the Python version
877 class wxPyGridCellEditor : public wxGridCellEditor {
879 wxPyGridCellEditor();
880 void _setCallbackInfo(PyObject* self, PyObject* _class);
881 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellEditor)"
882 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
884 void base_SetSize(const wxRect& rect);
885 void base_Show(bool show, wxGridCellAttr *attr = NULL);
886 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
887 void base_IsAcceptedKey(wxKeyEvent& event);
888 void base_StartingKey(wxKeyEvent& event);
889 void base_StartingClick();
890 void base_HandleReturn(wxKeyEvent& event);
892 void base_SetParameters(const wxString& params);
895 //---------------------------------------------------------------------------
896 // Predefined Editors
898 class wxGridCellTextEditor : public wxGridCellEditor
901 wxGridCellTextEditor();
902 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
906 class wxGridCellNumberEditor : public wxGridCellTextEditor
909 wxGridCellNumberEditor(int min = -1, int max = -1);
910 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
914 class wxGridCellFloatEditor : public wxGridCellTextEditor
917 wxGridCellFloatEditor();
918 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
922 class wxGridCellBoolEditor : public wxGridCellEditor
925 wxGridCellBoolEditor();
926 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
929 class wxGridCellChoiceEditor : public wxGridCellEditor
932 wxGridCellChoiceEditor(int LCOUNT = 0,
933 const wxString* choices = NULL,
934 bool allowOthers = FALSE);
935 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
939 class wxGridCellEnumEditor : public wxGridCellChoiceEditor
942 wxGridCellEnumEditor( const wxString& choices = wxPyEmptyString );
943 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
947 class wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
950 wxGridCellAutoWrapStringEditor();
951 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
956 //---------------------------------------------------------------------------
973 void _setOORInfo(PyObject* _self) {
974 self->SetClientObject(new wxPyOORClientData(_self));
978 wxGridCellAttr(wxGridCellAttr *attrDefault = NULL);
979 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
981 wxGridCellAttr *Clone() const;
982 void MergeWith(wxGridCellAttr *mergefrom);
985 void SetTextColour(const wxColour& colText);
986 void SetBackgroundColour(const wxColour& colBack);
987 void SetFont(const wxFont& font);
988 void SetAlignment(int hAlign, int vAlign);
989 void SetReadOnly(bool isReadOnly = TRUE);
991 void SetRenderer(wxGridCellRenderer *renderer);
992 void SetEditor(wxGridCellEditor* editor);
993 void SetKind(wxAttrKind kind);
995 bool HasTextColour() const;
996 bool HasBackgroundColour() const;
997 bool HasFont() const;
998 bool HasAlignment() const;
999 bool HasRenderer() const;
1000 bool HasEditor() const;
1001 bool HasReadWriteMode() const;
1003 wxColour GetTextColour() const;
1004 wxColour GetBackgroundColour() const;
1005 wxFont GetFont() const;
1006 void GetAlignment(int *OUTPUT, int *OUTPUT) const;
1007 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
1008 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
1010 bool IsReadOnly() const;
1011 void SetDefAttr(wxGridCellAttr* defAttr);
1014 //---------------------------------------------------------------------------
1016 class wxGridCellAttrProvider
1019 wxGridCellAttrProvider();
1020 // ???? virtual ~wxGridCellAttrProvider();
1021 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1024 void _setOORInfo(PyObject* _self) {
1025 self->SetClientObject(new wxPyOORClientData(_self));
1029 wxGridCellAttr *GetAttr(int row, int col,
1030 wxGridCellAttr::wxAttrKind kind) const;
1031 void SetAttr(wxGridCellAttr *attr, int row, int col);
1032 void SetRowAttr(wxGridCellAttr *attr, int row);
1033 void SetColAttr(wxGridCellAttr *attr, int col);
1035 void UpdateAttrRows( size_t pos, int numRows );
1036 void UpdateAttrCols( size_t pos, int numCols );
1041 // A Python-aware version
1043 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1046 wxPyGridCellAttrProvider() : wxGridCellAttrProvider() {};
1048 PYCALLBACK_GCA_INTINTKIND(wxGridCellAttrProvider, GetAttr);
1049 PYCALLBACK__GCAINTINT(wxGridCellAttrProvider, SetAttr);
1050 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetRowAttr);
1051 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetColAttr);
1058 // The python-aware version get's SWIGified
1059 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1062 wxPyGridCellAttrProvider();
1063 void _setCallbackInfo(PyObject* self, PyObject* _class);
1064 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellAttrProvider)"
1066 wxGridCellAttr *base_GetAttr(int row, int col,
1067 wxGridCellAttr::wxAttrKind kind);
1068 void base_SetAttr(wxGridCellAttr *attr, int row, int col);
1069 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1070 void base_SetColAttr(wxGridCellAttr *attr, int col);
1074 //---------------------------------------------------------------------------
1075 // Grid Table Base class and Python aware version
1078 class wxGridTableBase : public wxObject
1081 // wxGridTableBase(); This is an ABC
1082 //~wxGridTableBase();
1085 void _setOORInfo(PyObject* _self) {
1086 self->SetClientObject(new wxPyOORClientData(_self));
1090 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
1091 wxGridCellAttrProvider *GetAttrProvider() const;
1092 void SetView( wxGrid *grid );
1093 wxGrid * GetView() const;
1097 virtual int GetNumberRows() = 0;
1098 virtual int GetNumberCols() = 0;
1099 virtual bool IsEmptyCell( int row, int col ) = 0;
1100 virtual wxString GetValue( int row, int col ) = 0;
1101 virtual void SetValue( int row, int col, const wxString& value ) = 0;
1103 // virtuals overridable in wxPyGridTableBase
1104 virtual wxString GetTypeName( int row, int col );
1105 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
1106 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
1107 virtual long GetValueAsLong( int row, int col );
1108 virtual double GetValueAsDouble( int row, int col );
1109 virtual bool GetValueAsBool( int row, int col );
1110 virtual void SetValueAsLong( int row, int col, long value );
1111 virtual void SetValueAsDouble( int row, int col, double value );
1112 virtual void SetValueAsBool( int row, int col, bool value );
1114 //virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
1115 //virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
1118 virtual void Clear();
1119 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
1120 virtual bool AppendRows( size_t numRows = 1 );
1121 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
1122 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
1123 virtual bool AppendCols( size_t numCols = 1 );
1124 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
1126 virtual wxString GetRowLabelValue( int row );
1127 virtual wxString GetColLabelValue( int col );
1128 virtual void SetRowLabelValue( int row, const wxString& value );
1129 virtual void SetColLabelValue( int col, const wxString& value );
1131 virtual bool CanHaveAttributes();
1133 virtual wxGridCellAttr *GetAttr( int row, int col,
1134 wxGridCellAttr::wxAttrKind kind);
1135 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
1136 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
1137 virtual void SetColAttr(wxGridCellAttr *attr, int col);
1143 // Python-aware version
1145 class wxPyGridTableBase : public wxGridTableBase
1148 wxPyGridTableBase() : wxGridTableBase() {}
1150 PYCALLBACK_INT__pure(GetNumberRows);
1151 PYCALLBACK_INT__pure(GetNumberCols);
1152 PYCALLBACK_BOOL_INTINT_pure(IsEmptyCell);
1153 PYCALLBACK_STRING_INTINT(wxGridTableBase, GetTypeName);
1154 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanGetValueAs);
1155 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanSetValueAs);
1156 PYCALLBACK__(wxGridTableBase, Clear);
1157 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertRows);
1158 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteRows);
1159 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertCols);
1160 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteCols);
1161 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendRows);
1162 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendCols);
1163 PYCALLBACK_STRING_INT(wxGridTableBase, GetRowLabelValue);
1164 PYCALLBACK_STRING_INT(wxGridTableBase, GetColLabelValue);
1165 PYCALLBACK__INTSTRING(wxGridTableBase, SetRowLabelValue);
1166 PYCALLBACK__INTSTRING(wxGridTableBase, SetColLabelValue);
1167 PYCALLBACK_BOOL_(wxGridTableBase, CanHaveAttributes);
1168 PYCALLBACK_GCA_INTINTKIND(wxGridTableBase, GetAttr);
1169 PYCALLBACK__GCAINTINT(wxGridTableBase, SetAttr);
1170 PYCALLBACK__GCAINT(wxGridTableBase, SetRowAttr);
1171 PYCALLBACK__GCAINT(wxGridTableBase, SetColAttr);
1174 wxString GetValue(int row, int col) {
1175 wxPyBeginBlockThreads();
1177 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1179 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",row,col));
1181 rval = Py2wxString(ro);
1185 wxPyEndBlockThreads();
1189 void SetValue(int row, int col, const wxString& val) {
1190 wxPyBeginBlockThreads();
1191 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1192 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",row,col,wx2PyString(val)));
1194 wxPyEndBlockThreads();
1198 // Map the Get/Set methods for the standard non-string types to
1199 // the GetValue and SetValue python methods.
1200 long GetValueAsLong( int row, int col ) {
1202 wxPyBeginBlockThreads();
1203 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1206 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1207 if (ro && PyNumber_Check(ro)) {
1208 num = PyNumber_Int(ro);
1210 rval = PyInt_AsLong(num);
1216 wxPyEndBlockThreads();
1220 double GetValueAsDouble( int row, int col ) {
1222 wxPyBeginBlockThreads();
1223 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1226 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1227 if (ro && PyNumber_Check(ro)) {
1228 num = PyNumber_Float(ro);
1230 rval = PyFloat_AsDouble(num);
1236 wxPyEndBlockThreads();
1240 bool GetValueAsBool( int row, int col ) {
1241 return (bool)GetValueAsLong(row, col);
1244 void SetValueAsLong( int row, int col, long value ) {
1245 wxPyBeginBlockThreads();
1246 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1247 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", row, col, value));
1249 wxPyEndBlockThreads();
1252 void SetValueAsDouble( int row, int col, double value ) {
1253 wxPyBeginBlockThreads();
1254 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1255 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iid)", row, col, value));
1257 wxPyEndBlockThreads();
1260 void SetValueAsBool( int row, int col, bool value ) {
1261 SetValueAsLong( row, col, (long)value );
1270 // The python-aware version get's SWIGified
1271 class wxPyGridTableBase : public wxGridTableBase
1274 wxPyGridTableBase();
1275 void _setCallbackInfo(PyObject* self, PyObject* _class);
1276 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridTableBase)"
1277 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1279 %addmethods { void Destroy() { delete self; } }
1281 wxString base_GetTypeName( int row, int col );
1282 bool base_CanGetValueAs( int row, int col, const wxString& typeName );
1283 bool base_CanSetValueAs( int row, int col, const wxString& typeName );
1285 bool base_InsertRows( size_t pos = 0, size_t numRows = 1 );
1286 bool base_AppendRows( size_t numRows = 1 );
1287 bool base_DeleteRows( size_t pos = 0, size_t numRows = 1 );
1288 bool base_InsertCols( size_t pos = 0, size_t numCols = 1 );
1289 bool base_AppendCols( size_t numCols = 1 );
1290 bool base_DeleteCols( size_t pos = 0, size_t numCols = 1 );
1291 wxString base_GetRowLabelValue( int row );
1292 wxString base_GetColLabelValue( int col );
1293 void base_SetRowLabelValue( int row, const wxString& value );
1294 void base_SetColLabelValue( int col, const wxString& value );
1295 bool base_CanHaveAttributes();
1296 wxGridCellAttr *base_GetAttr( int row, int col,
1297 wxGridCellAttr::wxAttrKind kind );
1298 void base_SetAttr(wxGridCellAttr* attr, int row, int col);
1299 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1300 void base_SetColAttr(wxGridCellAttr *attr, int col);
1304 //---------------------------------------------------------------------------
1305 // Predefined Tables
1307 class wxGridStringTable : public wxGridTableBase
1310 wxGridStringTable( int numRows=0, int numCols=0 );
1311 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1314 //---------------------------------------------------------------------------
1315 // The Table can pass messages to the grid to tell it to update itself if
1316 // something has changed.
1318 enum wxGridTableRequest
1320 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
1321 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
1322 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
1323 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
1324 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
1325 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1326 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
1327 wxGRIDTABLE_NOTIFY_COLS_DELETED
1331 class wxGridTableMessage
1334 wxGridTableMessage( wxGridTableBase *table, int id,
1337 ~wxGridTableMessage();
1339 void SetTableObject( wxGridTableBase *table );
1340 wxGridTableBase * GetTableObject() const;
1341 void SetId( int id );
1343 void SetCommandInt( int comInt1 );
1344 int GetCommandInt();
1345 void SetCommandInt2( int comInt2 );
1346 int GetCommandInt2();
1350 //---------------------------------------------------------------------------
1352 class wxGridCellCoords
1355 wxGridCellCoords( int r=-1, int c=-1 );
1356 ~wxGridCellCoords();
1358 int GetRow() const { return m_row; }
1359 void SetRow( int n ) { m_row = n; }
1360 int GetCol() const { return m_col; }
1361 void SetCol( int n ) { m_col = n; }
1362 void Set( int row, int col ) { m_row = row; m_col = col; }
1365 PyObject* asTuple() {
1366 PyObject* tup = PyTuple_New(2);
1367 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
1368 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
1372 int __cmp__( const wxGridCellCoords& other ) {
1373 return *self != other;
1376 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
1377 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
1380 // Typemap to allow conversion of sequence objects to wxGridCellCoords...
1381 %typemap(python,in) wxGridCellCoords& (wxGridCellCoords temp) {
1383 if (! wxGridCellCoords_helper($source, &$target))
1387 // ...and here is the associated helper.
1389 bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) {
1391 // If source is an object instance then it may already be the right type
1392 if (PyInstance_Check(source)) {
1393 wxGridCellCoords* ptr;
1394 if (SWIG_GetPtrObj(source, (void **)&ptr, "_wxGridCellCoords_p"))
1399 // otherwise a 2-tuple of integers is expected
1400 else if (PySequence_Check(source) && PyObject_Length(source) == 2) {
1401 PyObject* o1 = PySequence_GetItem(source, 0);
1402 PyObject* o2 = PySequence_GetItem(source, 1);
1403 **obj = wxGridCellCoords(PyInt_AsLong(o1), PyInt_AsLong(o2));
1408 PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of integers or a wxGridCellCoords object.");
1413 //---------------------------------------------------------------------------
1414 //---------------------------------------------------------------------------
1418 // Fool SWIG into treating this enum as an int
1419 typedef int WXGRIDSELECTIONMODES;
1421 // but let the C++ code know what it really is.
1423 typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES;
1428 class wxGrid : public wxScrolledWindow
1431 wxGrid( wxWindow *parent,
1433 const wxPoint& pos = wxDefaultPosition,
1434 const wxSize& size = wxDefaultSize,
1435 long style = wxWANTS_CHARS,
1436 const wxString& name = wxPyPanelNameStr);
1438 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1440 enum wxGridSelectionModes {wxGridSelectCells,
1442 wxGridSelectColumns};
1444 bool CreateGrid( int numRows, int numCols,
1445 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1446 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1449 // ------ grid dimensions
1451 int GetNumberRows();
1452 int GetNumberCols();
1455 bool ProcessTableMessage( wxGridTableMessage& );
1458 wxGridTableBase * GetTable() const;
1459 bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE,
1460 WXGRIDSELECTIONMODES selmode =
1461 wxGrid::wxGridSelectCells );
1464 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1465 bool AppendRows( int numRows = 1, bool updateLabels=TRUE );
1466 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1467 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1468 bool AppendCols( int numCols = 1, bool updateLabels=TRUE );
1469 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1472 // this function is called when the current cell highlight must be redrawn
1473 // and may be overridden by the user
1474 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1477 // ------ Cell text drawing functions
1479 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1480 int horizontalAlignment = wxLEFT,
1481 int verticalAlignment = wxTOP );
1483 // // Split a string containing newline chararcters into an array of
1484 // // strings and return the number of lines
1486 // void StringToLines( const wxString& value, wxArrayString& lines );
1488 void GetTextBoxSize( wxDC& dc,
1489 wxArrayString& lines,
1490 long *OUTPUT, long *OUTPUT );
1494 // Code that does a lot of grid modification can be enclosed
1495 // between BeginBatch() and EndBatch() calls to avoid screen
1500 int GetBatchCount();
1501 void ForceRefresh();
1504 // ------ edit control functions
1506 bool IsEditable() { return m_editable; }
1507 void EnableEditing( bool edit );
1509 void EnableCellEditControl( bool enable = TRUE );
1510 void DisableCellEditControl();
1511 bool CanEnableCellControl() const;
1512 bool IsCellEditControlEnabled() const;
1513 bool IsCellEditControlShown() const;
1515 bool IsCurrentCellReadOnly() const;
1517 void ShowCellEditControl();
1518 void HideCellEditControl();
1519 void SaveEditControlValue();
1522 // ------ grid location functions
1523 // Note that all of these functions work with the logical coordinates of
1524 // grid cells and labels so you will need to convert from device
1525 // coordinates for mouse events etc.
1528 //void XYToCell( int x, int y, wxGridCellCoords& );
1530 %new wxGridCellCoords* XYToCell(int x, int y) {
1531 wxGridCellCoords rv;
1532 self->XYToCell(x, y, rv);
1533 return new wxGridCellCoords(rv);
1537 int YToRow( int y );
1538 int XToCol( int x );
1540 int YToEdgeOfRow( int y );
1541 int XToEdgeOfCol( int x );
1543 wxRect CellToRect( int row, int col );
1544 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1547 int GetGridCursorRow();
1548 int GetGridCursorCol();
1550 // check to see if a cell is either wholly visible (the default arg) or
1551 // at least partially visible in the grid window
1553 bool IsVisible( int row, int col, bool wholeCellVisible = TRUE );
1554 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE );
1555 void MakeCellVisible( int row, int col );
1556 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1559 // ------ grid cursor movement functions
1561 void SetGridCursor( int row, int col );
1562 bool MoveCursorUp( bool expandSelection );
1563 bool MoveCursorDown( bool expandSelection );
1564 bool MoveCursorLeft( bool expandSelection );
1565 bool MoveCursorRight( bool expandSelection );
1566 bool MovePageDown();
1568 bool MoveCursorUpBlock( bool expandSelection );
1569 bool MoveCursorDownBlock( bool expandSelection );
1570 bool MoveCursorLeftBlock( bool expandSelection );
1571 bool MoveCursorRightBlock( bool expandSelection );
1574 // ------ label and gridline formatting
1576 int GetDefaultRowLabelSize();
1577 int GetRowLabelSize();
1578 int GetDefaultColLabelSize();
1579 int GetColLabelSize();
1580 wxColour GetLabelBackgroundColour();
1581 wxColour GetLabelTextColour();
1582 wxFont GetLabelFont();
1583 void GetRowLabelAlignment( int *OUTPUT, int *OUTPUT );
1584 void GetColLabelAlignment( int *OUTPUT, int *OUTPUT );
1585 wxString GetRowLabelValue( int row );
1586 wxString GetColLabelValue( int col );
1587 wxColour GetGridLineColour();
1588 wxColour GetCellHighlightColour();
1589 int GetCellHighlightPenWidth();
1590 int GetCellHighlightROPenWidth();
1592 void SetRowLabelSize( int width );
1593 void SetColLabelSize( int height );
1594 void SetLabelBackgroundColour( const wxColour& );
1595 void SetLabelTextColour( const wxColour& );
1596 void SetLabelFont( const wxFont& );
1597 void SetRowLabelAlignment( int horiz, int vert );
1598 void SetColLabelAlignment( int horiz, int vert );
1599 void SetRowLabelValue( int row, const wxString& );
1600 void SetColLabelValue( int col, const wxString& );
1601 void SetGridLineColour( const wxColour& );
1602 void SetCellHighlightColour( const wxColour& );
1603 void SetCellHighlightPenWidth(int width);
1604 void SetCellHighlightROPenWidth(int width);
1606 void EnableDragRowSize( bool enable = TRUE );
1607 void DisableDragRowSize();
1608 bool CanDragRowSize();
1609 void EnableDragColSize( bool enable = TRUE );
1610 void DisableDragColSize();
1611 bool CanDragColSize();
1612 void EnableDragGridSize(bool enable = TRUE);
1613 void DisableDragGridSize();
1614 bool CanDragGridSize();
1616 // this sets the specified attribute for all cells in this row/col
1617 void SetRowAttr(int row, wxGridCellAttr *attr);
1618 void SetColAttr(int col, wxGridCellAttr *attr);
1620 // shortcuts for setting the column parameters
1622 // set the format for the data in the column: default is string
1623 void SetColFormatBool(int col);
1624 void SetColFormatNumber(int col);
1625 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1626 void SetColFormatCustom(int col, const wxString& typeName);
1628 void EnableGridLines( bool enable = TRUE );
1629 bool GridLinesEnabled();
1631 // ------ row and col formatting
1633 int GetDefaultRowSize();
1634 int GetRowSize( int row );
1635 int GetDefaultColSize();
1636 int GetColSize( int col );
1637 wxColour GetDefaultCellBackgroundColour();
1638 wxColour GetCellBackgroundColour( int row, int col );
1639 wxColour GetDefaultCellTextColour();
1640 wxColour GetCellTextColour( int row, int col );
1641 wxFont GetDefaultCellFont();
1642 wxFont GetCellFont( int row, int col );
1643 void GetDefaultCellAlignment( int *horiz, int *vert );
1644 void GetCellAlignment( int row, int col, int *horiz, int *vert );
1646 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
1647 void SetRowSize( int row, int height );
1648 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
1650 void SetColSize( int col, int width );
1652 // automatically size the column or row to fit to its contents, if
1653 // setAsMin is TRUE, this optimal width will also be set as minimal width
1655 void AutoSizeColumn( int col, bool setAsMin = TRUE );
1656 void AutoSizeRow( int row, bool setAsMin = TRUE );
1659 // auto size all columns (very ineffective for big grids!)
1660 void AutoSizeColumns( bool setAsMin = TRUE );
1661 void AutoSizeRows( bool setAsMin = TRUE );
1663 // auto size the grid, that is make the columns/rows of the "right" size
1664 // and also set the grid size to just fit its contents
1667 // column won't be resized to be lesser width - this must be called during
1668 // the grid creation because it won't resize the column if it's already
1669 // narrower than the minimal width
1670 void SetColMinimalWidth( int col, int width );
1671 void SetRowMinimalHeight( int row, int width );
1673 void SetDefaultCellBackgroundColour( const wxColour& );
1674 void SetCellBackgroundColour( int row, int col, const wxColour& );
1675 void SetDefaultCellTextColour( const wxColour& );
1677 void SetCellTextColour( int row, int col, const wxColour& );
1678 void SetDefaultCellFont( const wxFont& );
1679 void SetCellFont( int row, int col, const wxFont& );
1680 void SetDefaultCellAlignment( int horiz, int vert );
1681 void SetCellAlignment( int row, int col, int horiz, int vert );
1683 // takes ownership of the pointer
1684 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1685 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1686 wxGridCellRenderer *GetDefaultRenderer() const;
1687 wxGridCellRenderer* GetCellRenderer(int row, int col);
1689 // takes ownership of the pointer
1690 void SetDefaultEditor(wxGridCellEditor *editor);
1691 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1692 wxGridCellEditor *GetDefaultEditor() const;
1693 wxGridCellEditor* GetCellEditor(int row, int col);
1697 // ------ cell value accessors
1699 wxString GetCellValue( int row, int col );
1700 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1702 void SetCellValue( int row, int col, const wxString& s );
1703 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1705 // returns TRUE if the cell can't be edited
1706 bool IsReadOnly(int row, int col) const;
1708 // make the cell editable/readonly
1709 void SetReadOnly(int row, int col, bool isReadOnly = TRUE);
1711 // ------ selections of blocks of cells
1713 void SelectRow( int row, bool addToSelected = FALSE );
1714 void SelectCol( int col, bool addToSelected = FALSE );
1716 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1717 bool addToSelected = FALSE );
1718 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1719 // TODO: ??? const wxGridCellCoords& bottomRight )
1723 void ClearSelection();
1724 bool IsInSelection( int row, int col );
1725 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1728 // This function returns the rectangle that encloses the block of cells
1729 // limited by TopLeft and BottomRight cell in device coords and clipped
1730 // to the client size of the grid window.
1732 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1733 const wxGridCellCoords & bottomRight );
1736 // Access or update the selection fore/back colours
1737 wxColour GetSelectionBackground() const;
1738 wxColour GetSelectionForeground() const;
1740 void SetSelectionBackground(const wxColour& c);
1741 void SetSelectionForeground(const wxColour& c);
1744 // Methods for a registry for mapping data types to Renderers/Editors
1745 void RegisterDataType(const wxString& typeName,
1746 wxGridCellRenderer* renderer,
1747 wxGridCellEditor* editor);
1748 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1749 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1750 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1751 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1752 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1754 // grid may occupy more space than needed for its rows/columns, this
1755 // function allows to set how big this extra space is
1756 void SetMargins(int extraWidth, int extraHeight);
1759 // Accessors for component windows
1760 wxWindow* GetGridWindow();
1761 wxWindow* GetGridRowLabelWindow();
1762 wxWindow* GetGridColLabelWindow();
1763 wxWindow* GetGridCornerLabelWindow();
1769 //---------------------------------------------------------------------------
1770 //---------------------------------------------------------------------------
1771 // Grid events and stuff
1775 class wxGridEvent : public wxNotifyEvent
1778 wxGridEvent(int id, wxEventType type, wxGrid* obj,
1779 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = TRUE,
1780 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1782 virtual int GetRow();
1783 virtual int GetCol();
1784 wxPoint GetPosition();
1794 class wxGridSizeEvent : public wxNotifyEvent
1797 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
1798 int rowOrCol=-1, int x=-1, int y=-1,
1799 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1802 wxPoint GetPosition();
1811 class wxGridRangeSelectEvent : public wxNotifyEvent
1814 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
1815 const wxGridCellCoords& topLeft,
1816 const wxGridCellCoords& bottomRight,
1818 bool control=FALSE, bool shift=FALSE,
1819 bool alt=FALSE, bool meta=FALSE);
1821 wxGridCellCoords GetTopLeftCoords();
1822 wxGridCellCoords GetBottomRightCoords();
1835 class wxGridEditorCreatedEvent : public wxCommandEvent {
1837 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
1838 int row, int col, wxControl* ctrl);
1842 wxControl* GetControl();
1843 void SetRow(int row);
1844 void SetCol(int col);
1845 void SetControl(wxControl* ctrl);
1851 wxEVT_GRID_CELL_LEFT_CLICK,
1852 wxEVT_GRID_CELL_RIGHT_CLICK,
1853 wxEVT_GRID_CELL_LEFT_DCLICK,
1854 wxEVT_GRID_CELL_RIGHT_DCLICK,
1855 wxEVT_GRID_LABEL_LEFT_CLICK,
1856 wxEVT_GRID_LABEL_RIGHT_CLICK,
1857 wxEVT_GRID_LABEL_LEFT_DCLICK,
1858 wxEVT_GRID_LABEL_RIGHT_DCLICK,
1859 wxEVT_GRID_ROW_SIZE,
1860 wxEVT_GRID_COL_SIZE,
1861 wxEVT_GRID_RANGE_SELECT,
1862 wxEVT_GRID_CELL_CHANGE,
1863 wxEVT_GRID_SELECT_CELL,
1864 wxEVT_GRID_EDITOR_SHOWN,
1865 wxEVT_GRID_EDITOR_HIDDEN,
1866 wxEVT_GRID_EDITOR_CREATED,
1871 %pragma(python) code = "
1872 def EVT_GRID_CELL_LEFT_CLICK(win, fn):
1873 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_CLICK, fn)
1875 def EVT_GRID_CELL_RIGHT_CLICK(win, fn):
1876 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_CLICK, fn)
1878 def EVT_GRID_CELL_LEFT_DCLICK(win, fn):
1879 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_DCLICK, fn)
1881 def EVT_GRID_CELL_RIGHT_DCLICK(win, fn):
1882 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_DCLICK, fn)
1884 def EVT_GRID_LABEL_LEFT_CLICK(win, fn):
1885 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_CLICK, fn)
1887 def EVT_GRID_LABEL_RIGHT_CLICK(win, fn):
1888 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_CLICK, fn)
1890 def EVT_GRID_LABEL_LEFT_DCLICK(win, fn):
1891 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_DCLICK, fn)
1893 def EVT_GRID_LABEL_RIGHT_DCLICK(win, fn):
1894 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_DCLICK, fn)
1896 def EVT_GRID_ROW_SIZE(win, fn):
1897 win.Connect(-1, -1, wxEVT_GRID_ROW_SIZE, fn)
1899 def EVT_GRID_COL_SIZE(win, fn):
1900 win.Connect(-1, -1, wxEVT_GRID_COL_SIZE, fn)
1902 def EVT_GRID_RANGE_SELECT(win, fn):
1903 win.Connect(-1, -1, wxEVT_GRID_RANGE_SELECT, fn)
1905 def EVT_GRID_CELL_CHANGE(win, fn):
1906 win.Connect(-1, -1, wxEVT_GRID_CELL_CHANGE, fn)
1908 def EVT_GRID_SELECT_CELL(win, fn):
1909 win.Connect(-1, -1, wxEVT_GRID_SELECT_CELL, fn)
1911 def EVT_GRID_EDITOR_SHOWN(win, fn):
1912 win.Connect(-1, -1, wxEVT_GRID_EDITOR_SHOWN, fn)
1914 def EVT_GRID_EDITOR_HIDDEN(win, fn):
1915 win.Connect(-1, -1, wxEVT_GRID_EDITOR_HIDDEN, fn)
1917 def EVT_GRID_EDITOR_CREATED(win, fn):
1918 win.Connect(-1, -1, wxEVT_GRID_EDITOR_CREATED, fn)
1922 //---------------------------------------------------------------------------
1925 wxClassInfo::CleanUpClasses();
1926 wxClassInfo::InitializeClasses();
1929 //---------------------------------------------------------------------------
1931 %pragma(python) include="_gridextras.py";
1933 //---------------------------------------------------------------------------