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 //---------------------------------------------------------------------------
39 //---------------------------------------------------------------------------
40 // Macros, similar to what's in helpers.h, to aid in the creation of
41 // virtual methods that are able to make callbacks to Python. Many of these
42 // are specific to wxGrid and so are kept here to reduce the mess in helpers.h
47 #define PYCALLBACK_GCA_INTINTKIND(PCLASS, CBNAME) \
48 wxGridCellAttr* CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
49 wxGridCellAttr* rval = NULL; \
51 wxPyBeginBlockThreads(); \
52 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
54 wxGridCellAttr* ptr; \
55 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iii)", a, b, c)); \
57 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellAttr_p")) \
62 wxPyEndBlockThreads(); \
64 rval = PCLASS::CBNAME(a, b, c); \
67 wxGridCellAttr *base_##CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
68 return PCLASS::CBNAME(a, b, c); \
73 #define PYCALLBACK__GCAINTINT(PCLASS, CBNAME) \
74 void CBNAME(wxGridCellAttr *attr, int a, int b) { \
75 wxPyBeginBlockThreads(); \
77 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
78 PyObject* obj = wxPyConstructObject((void*)attr, "wxGridCellAttr", 0);\
79 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oii)", obj, a, b)); \
82 wxPyEndBlockThreads(); \
84 PCLASS::CBNAME(attr, a, b); \
86 void base_##CBNAME(wxGridCellAttr *attr, int a, int b) { \
87 PCLASS::CBNAME(attr, a, b); \
92 #define PYCALLBACK__GCAINT(PCLASS, CBNAME) \
93 void CBNAME(wxGridCellAttr *attr, int val) { \
94 wxPyBeginBlockThreads(); \
96 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
97 PyObject* obj = wxPyConstructObject((void*)attr, "wxGridCellAttr", 0);\
98 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, val)); \
101 wxPyEndBlockThreads(); \
103 PCLASS::CBNAME(attr, val); \
105 void base_##CBNAME(wxGridCellAttr *attr, int val) { \
106 PCLASS::CBNAME(attr, val); \
111 #define PYCALLBACK_INT__pure(CBNAME) \
113 wxPyBeginBlockThreads(); \
115 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
116 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
117 wxPyEndBlockThreads(); \
123 #define PYCALLBACK_BOOL_INTINT_pure(CBNAME) \
124 bool CBNAME(int a, int b) { \
125 wxPyBeginBlockThreads(); \
127 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
128 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
129 wxPyEndBlockThreads(); \
134 #define PYCALLBACK_STRING_INTINT_pure(CBNAME) \
135 wxString CBNAME(int a, int b) { \
136 wxPyBeginBlockThreads(); \
138 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
140 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
142 rval = Py2wxString(ro); \
146 wxPyEndBlockThreads(); \
151 #define PYCALLBACK__INTINTSTRING_pure(CBNAME) \
152 void CBNAME(int a, int b, const wxString& c) { \
153 wxPyBeginBlockThreads(); \
154 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
155 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,wx2PyString(c)));\
156 wxPyEndBlockThreads(); \
160 #define PYCALLBACK_STRING_INTINT(PCLASS, CBNAME) \
161 wxString CBNAME(int a, int b) { \
163 wxPyBeginBlockThreads(); \
165 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
167 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
169 rval = Py2wxString(ro); \
173 wxPyEndBlockThreads(); \
175 rval = PCLASS::CBNAME(a, b); \
178 wxString base_##CBNAME(int a, int b) { \
179 return PCLASS::CBNAME(a, b); \
183 #define PYCALLBACK_BOOL_INTINTSTRING(PCLASS, CBNAME) \
184 bool CBNAME(int a, int b, const wxString& c) { \
187 wxPyBeginBlockThreads(); \
188 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
189 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", a,b,wx2PyString(c)));\
190 wxPyEndBlockThreads(); \
192 rval = PCLASS::CBNAME(a,b,c); \
195 bool base_##CBNAME(int a, int b, const wxString& c) { \
196 return PCLASS::CBNAME(a,b,c); \
202 #define PYCALLBACK_LONG_INTINT(PCLASS, CBNAME) \
203 long CBNAME(int a, int b) { \
206 wxPyBeginBlockThreads(); \
207 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
208 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
209 wxPyEndBlockThreads(); \
211 rval = PCLASS::CBNAME(a,b); \
214 long base_##CBNAME(int a, int b) { \
215 return PCLASS::CBNAME(a,b); \
220 #define PYCALLBACK_BOOL_INTINT(PCLASS, CBNAME) \
221 bool CBNAME(int a, int b) { \
224 wxPyBeginBlockThreads(); \
225 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
226 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
227 wxPyEndBlockThreads(); \
229 rval = PCLASS::CBNAME(a,b); \
232 bool base_##CBNAME(int a, int b) { \
233 return PCLASS::CBNAME(a,b); \
238 #define PYCALLBACK_DOUBLE_INTINT(PCLASS, CBNAME) \
239 double CBNAME(int a, int b) { \
241 wxPyBeginBlockThreads(); \
243 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
245 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
247 PyObject* str = PyObject_Str(ro); \
248 rval = PyFloat_AsDouble(str); \
249 Py_DECREF(ro); Py_DECREF(str); \
252 wxPyEndBlockThreads(); \
254 rval = PCLASS::CBNAME(a, b); \
257 double base_##CBNAME(int a, int b) { \
258 return PCLASS::CBNAME(a, b); \
263 #define PYCALLBACK__(PCLASS, CBNAME) \
266 wxPyBeginBlockThreads(); \
267 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
268 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
269 wxPyEndBlockThreads(); \
273 void base_##CBNAME() { \
280 #define PYCALLBACK_BOOL_SIZETSIZET(PCLASS, CBNAME) \
281 bool CBNAME(size_t a, size_t b) { \
284 wxPyBeginBlockThreads(); \
285 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
286 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
287 wxPyEndBlockThreads(); \
289 rval = PCLASS::CBNAME(a,b); \
292 bool base_##CBNAME(size_t a, size_t b) { \
293 return PCLASS::CBNAME(a,b); \
298 #define PYCALLBACK_BOOL_SIZET(PCLASS, CBNAME) \
299 bool CBNAME(size_t a) { \
302 wxPyBeginBlockThreads(); \
303 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
304 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)", a)); \
305 wxPyEndBlockThreads(); \
307 rval = PCLASS::CBNAME(a); \
310 bool base_##CBNAME(size_t a) { \
311 return PCLASS::CBNAME(a); \
315 #define PYCALLBACK_STRING_INT(PCLASS, CBNAME) \
316 wxString CBNAME(int a) { \
318 wxPyBeginBlockThreads(); \
320 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
322 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(i)",a)); \
324 rval = Py2wxString(ro); \
328 wxPyEndBlockThreads(); \
330 rval = PCLASS::CBNAME(a); \
333 wxString base_##CBNAME(int a) { \
334 return PCLASS::CBNAME(a); \
338 #define PYCALLBACK__INTSTRING(PCLASS, CBNAME) \
339 void CBNAME(int a, const wxString& c) { \
341 wxPyBeginBlockThreads(); \
342 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
343 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", a, wx2PyString(c))); \
344 wxPyEndBlockThreads(); \
346 PCLASS::CBNAME(a,c); \
348 void base_##CBNAME(int a, const wxString& c) { \
349 PCLASS::CBNAME(a,c); \
355 #define PYCALLBACK_BOOL_(PCLASS, CBNAME) \
359 wxPyBeginBlockThreads(); \
360 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
361 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
362 wxPyEndBlockThreads(); \
364 rval = PCLASS::CBNAME(); \
367 bool base_##CBNAME() { \
368 return PCLASS::CBNAME(); \
373 #define PYCALLBACK__SIZETINT(PCLASS, CBNAME) \
374 void CBNAME(size_t a, int b) { \
376 wxPyBeginBlockThreads(); \
377 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
378 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
379 wxPyEndBlockThreads(); \
381 PCLASS::CBNAME(a,b); \
383 void base_##CBNAME(size_t a, int b) { \
384 PCLASS::CBNAME(a,b); \
390 #define PYCALLBACK__INTINTLONG(PCLASS, CBNAME) \
391 void CBNAME(int a, int b, long c) { \
393 wxPyBeginBlockThreads(); \
394 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
395 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
396 wxPyEndBlockThreads(); \
398 PCLASS::CBNAME(a,b,c); \
400 void base_##CBNAME(int a, int b, long c) { \
401 PCLASS::CBNAME(a,b,c); \
407 #define PYCALLBACK__INTINTDOUBLE(PCLASS, CBNAME) \
408 void CBNAME(int a, int b, double c) { \
410 wxPyBeginBlockThreads(); \
411 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
412 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iif)", a,b,c)); \
413 wxPyEndBlockThreads(); \
415 PCLASS::CBNAME(a,b,c); \
417 void base_##CBNAME(int a, int b, double c) { \
418 PCLASS::CBNAME(a,b,c); \
423 #define PYCALLBACK__INTINTBOOL(PCLASS, CBNAME) \
424 void CBNAME(int a, int b, bool c) { \
426 wxPyBeginBlockThreads(); \
427 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
428 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
429 wxPyEndBlockThreads(); \
431 PCLASS::CBNAME(a,b,c); \
433 void base_##CBNAME(int a, int b, bool c) { \
434 PCLASS::CBNAME(a,b,c); \
442 //---------------------------------------------------------------------------
444 class wxGridCellCoords;
445 class wxGridCellAttr;
449 #define wxGRID_VALUE_STRING "string"
450 #define wxGRID_VALUE_BOOL "bool"
451 #define wxGRID_VALUE_NUMBER "long"
452 #define wxGRID_VALUE_FLOAT "double"
453 #define wxGRID_VALUE_CHOICE "choice"
454 #define wxGRID_VALUE_TEXT "string"
455 #define wxGRID_VALUE_LONG "long"
458 wxGridCellCoords wxGridNoCellCoords;
459 wxRect wxGridNoCellRect;
463 //---------------------------------------------------------------------------
464 // wxGridCellRenderer is an ABC, and several derived classes are available.
465 // Classes implemented in Python should be derived from wxPyGridCellRenderer.
468 class wxGridCellRenderer
471 void SetParameters(const wxString& params);
475 virtual void Draw(wxGrid& grid,
476 wxGridCellAttr& attr,
480 bool isSelected) = 0;
481 virtual wxSize GetBestSize(wxGrid& grid,
482 wxGridCellAttr& attr,
484 int row, int col) = 0;
485 virtual wxGridCellRenderer *Clone() const = 0;
489 // The C++ version of wxPyGridCellRenderer
491 class wxPyGridCellRenderer : public wxGridCellRenderer
494 wxPyGridCellRenderer() : wxGridCellRenderer() {};
496 // Implement Python callback aware virtual methods
497 void Draw(wxGrid& grid, wxGridCellAttr& attr,
498 wxDC& dc, const wxRect& rect,
499 int row, int col, bool isSelected) {
500 wxPyBeginBlockThreads();
501 if (wxPyCBH_findCallback(m_myInst, "Draw")) {
502 wxPyCBH_callCallback(m_myInst,
503 Py_BuildValue("(OOOOiii)",
504 wxPyConstructObject((void*)&grid, "wxGrid", 0),
505 wxPyConstructObject((void*)&attr, "wxGridCellAttr", 0),
506 wxPyConstructObject((void*)&dc, "wxDC", 0),
507 wxPyConstructObject((void*)&rect, "wxRect", 0),
508 row, col, isSelected));
510 wxPyEndBlockThreads();
513 wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
516 wxPyBeginBlockThreads();
517 if (wxPyCBH_findCallback(m_myInst, "GetBestSize")) {
520 ro = wxPyCBH_callCallbackObj(m_myInst,
521 Py_BuildValue("(OOOii)",
522 wxPyConstructObject((void*)&grid, "wxGrid", 0),
523 wxPyConstructObject((void*)&attr, "wxGridCellAttr", 0),
524 wxPyConstructObject((void*)&dc, "wxDC", 0),
527 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p"))
532 wxPyEndBlockThreads();
537 wxGridCellRenderer *Clone() const {
538 wxGridCellRenderer* rval = NULL;
539 wxPyBeginBlockThreads();
540 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
542 wxGridCellRenderer* ptr;
543 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
545 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellRenderer_p"))
550 wxPyEndBlockThreads();
554 DEC_PYCALLBACK__STRING(SetParameters);
559 IMP_PYCALLBACK__STRING( wxPyGridCellRenderer, wxGridCellRenderer, SetParameters);
564 // Let SWIG know about it so it can create the Python version
565 class wxPyGridCellRenderer : public wxGridCellRenderer {
567 wxPyGridCellRenderer();
568 void _setCallbackInfo(PyObject* self, PyObject* _class);
569 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellRenderer)"
571 void base_SetParameters(const wxString& params);
574 //---------------------------------------------------------------------------
575 // Predefined Renderers
577 class wxGridCellStringRenderer : public wxGridCellRenderer
580 wxGridCellStringRenderer();
584 class wxGridCellNumberRenderer : public wxGridCellStringRenderer
587 wxGridCellNumberRenderer();
591 class wxGridCellFloatRenderer : public wxGridCellStringRenderer
594 wxGridCellFloatRenderer(int width = -1, int precision = -1);
596 int GetWidth() const;
597 void SetWidth(int width);
598 int GetPrecision() const;
599 void SetPrecision(int precision);
603 class wxGridCellBoolRenderer : public wxGridCellRenderer
606 wxGridCellBoolRenderer();
610 class wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
613 wxGridCellDateTimeRenderer(wxString outformat = "%c",
614 wxString informat = "%c");
618 class wxGridCellEnumRenderer : public wxGridCellStringRenderer
621 wxGridCellEnumRenderer( const wxString& choices = "" );
625 class wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer
628 wxGridCellAutoWrapStringRenderer();
632 //---------------------------------------------------------------------------
633 // wxGridCellEditor is an ABC, and several derived classes are available.
634 // Classes implemented in Python should be derived from wxPyGridCellEditor.
636 class wxGridCellEditor
640 wxControl* GetControl();
641 void SetControl(wxControl* control);
643 void SetParameters(const wxString& params);
647 virtual void Create(wxWindow* parent,
649 wxEvtHandler* evtHandler) = 0;
650 virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
651 virtual bool EndEdit(int row, int col, wxGrid* grid) = 0;
652 virtual void Reset() = 0;
653 virtual wxGridCellEditor *Clone() const = 0;
655 virtual void SetSize(const wxRect& rect);
656 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
657 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
658 virtual bool IsAcceptedKey(wxKeyEvent& event);
659 virtual void StartingKey(wxKeyEvent& event);
660 virtual void StartingClick();
661 virtual void HandleReturn(wxKeyEvent& event);
662 virtual void Destroy();
667 // The C++ version of wxPyGridCellEditor
669 class wxPyGridCellEditor : public wxGridCellEditor
672 wxPyGridCellEditor() : wxGridCellEditor() {}
674 void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) {
675 wxPyBeginBlockThreads();
676 if (wxPyCBH_findCallback(m_myInst, "Create")) {
677 wxPyCBH_callCallback(m_myInst,
678 Py_BuildValue("(OiO)",
679 wxPyConstructObject((void*)parent, "wxWindow", 0),
681 wxPyConstructObject((void*)evtHandler, "wxEvtHandler", 0)));
683 wxPyEndBlockThreads();
687 void BeginEdit(int row, int col, wxGrid* grid) {
688 wxPyBeginBlockThreads();
689 if (wxPyCBH_findCallback(m_myInst, "BeginEdit")) {
690 wxPyCBH_callCallback(m_myInst,
691 Py_BuildValue("(iiO)", row, col,
692 wxPyConstructObject((void*)grid, "wxGrid", 0)));
694 wxPyEndBlockThreads();
698 bool EndEdit(int row, int col, wxGrid* grid) {
700 wxPyBeginBlockThreads();
701 if (wxPyCBH_findCallback(m_myInst, "EndEdit")) {
702 rv = wxPyCBH_callCallback(m_myInst,
703 Py_BuildValue("(iiO)", row, col,
704 wxPyConstructObject((void*)grid, "wxGrid", 0)));
706 wxPyEndBlockThreads();
711 wxGridCellEditor*Clone() const {
712 wxGridCellEditor* rval = NULL;
713 wxPyBeginBlockThreads();
714 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
716 wxGridCellEditor* ptr;
717 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
719 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellEditor_p"))
724 wxPyEndBlockThreads();
729 void Show(bool show, wxGridCellAttr *attr) {
731 wxPyBeginBlockThreads();
732 if ((found = wxPyCBH_findCallback(m_myInst, "Show")))
733 wxPyCBH_callCallback(m_myInst,
734 Py_BuildValue("(iO)", show,
735 wxPyConstructObject((void*)attr, "wxGridCellAttr", 0)));
736 wxPyEndBlockThreads();
738 wxGridCellEditor::Show(show, attr);
740 void base_Show(bool show, wxGridCellAttr *attr) {
741 wxGridCellEditor::Show(show, attr);
745 void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
747 wxPyBeginBlockThreads();
748 if ((found = wxPyCBH_findCallback(m_myInst, "PaintBackground)")))
749 wxPyCBH_callCallback(m_myInst,
750 Py_BuildValue("(OO)",
751 wxPyConstructObject((void*)&rectCell, "wxRect", 0),
752 wxPyConstructObject((void*)attr, "wxGridCellAttr", 0)));
753 wxPyEndBlockThreads();
755 wxGridCellEditor::PaintBackground(rectCell, attr);
757 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
758 wxGridCellEditor::PaintBackground(rectCell, attr);
762 DEC_PYCALLBACK___pure(Reset);
763 DEC_PYCALLBACK__constany(SetSize, wxRect);
764 DEC_PYCALLBACK_bool_any(IsAcceptedKey, wxKeyEvent);
765 DEC_PYCALLBACK__any(StartingKey, wxKeyEvent);
766 DEC_PYCALLBACK__any(HandleReturn, wxKeyEvent);
767 DEC_PYCALLBACK__(StartingClick);
768 DEC_PYCALLBACK__(Destroy);
769 DEC_PYCALLBACK__STRING(SetParameters);
775 IMP_PYCALLBACK__STRING( wxPyGridCellEditor, wxGridCellEditor, SetParameters);
776 IMP_PYCALLBACK___pure(wxPyGridCellEditor, wxGridCellEditor, Reset);
777 IMP_PYCALLBACK__constany(wxPyGridCellEditor, wxGridCellEditor, SetSize, wxRect);
778 IMP_PYCALLBACK_bool_any(wxPyGridCellEditor, wxGridCellEditor, IsAcceptedKey, wxKeyEvent);
779 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, StartingKey, wxKeyEvent);
780 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, HandleReturn, wxKeyEvent);
781 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, StartingClick);
782 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, Destroy);
787 // Let SWIG know about it so it can create the Python version
788 class wxPyGridCellEditor : public wxGridCellEditor {
790 wxPyGridCellEditor();
791 void _setCallbackInfo(PyObject* self, PyObject* _class);
792 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellEditor)"
794 void base_SetSize(const wxRect& rect);
795 void base_Show(bool show, wxGridCellAttr *attr = NULL);
796 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
797 void base_IsAcceptedKey(wxKeyEvent& event);
798 void base_StartingKey(wxKeyEvent& event);
799 void base_StartingClick();
800 void base_HandleReturn(wxKeyEvent& event);
802 void base_SetParameters(const wxString& params);
805 //---------------------------------------------------------------------------
806 // Predefined Editors
808 class wxGridCellTextEditor : public wxGridCellEditor
811 wxGridCellTextEditor();
815 class wxGridCellNumberEditor : public wxGridCellTextEditor
818 wxGridCellNumberEditor(int min = -1, int max = -1);
822 class wxGridCellFloatEditor : public wxGridCellTextEditor
825 wxGridCellFloatEditor();
829 class wxGridCellBoolEditor : public wxGridCellEditor
832 wxGridCellBoolEditor();
835 class wxGridCellChoiceEditor : public wxGridCellEditor
838 wxGridCellChoiceEditor(int LCOUNT = 0,
839 const wxString* choices = NULL,
840 bool allowOthers = FALSE);
844 class wxGridCellEnumEditor : public wxGridCellChoiceEditor
847 wxGridCellEnumEditor( const wxString& choices = "" );
851 class wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
854 wxGridCellAutoWrapStringEditor();
859 //---------------------------------------------------------------------------
875 wxGridCellAttr(wxGridCellAttr *attrDefault = NULL);
877 wxGridCellAttr *Clone() const;
878 void MergeWith(wxGridCellAttr *mergefrom);
881 void SetTextColour(const wxColour& colText);
882 void SetBackgroundColour(const wxColour& colBack);
883 void SetFont(const wxFont& font);
884 void SetAlignment(int hAlign, int vAlign);
885 void SetReadOnly(bool isReadOnly = TRUE);
887 void SetRenderer(wxGridCellRenderer *renderer);
888 void SetEditor(wxGridCellEditor* editor);
889 void SetKind(wxAttrKind kind);
891 bool HasTextColour() const;
892 bool HasBackgroundColour() const;
893 bool HasFont() const;
894 bool HasAlignment() const;
895 bool HasRenderer() const;
896 bool HasEditor() const;
897 bool HasReadWriteMode() const;
899 wxColour GetTextColour() const;
900 wxColour GetBackgroundColour() const;
901 wxFont GetFont() const;
902 void GetAlignment(int *OUTPUT, int *OUTPUT) const;
903 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
904 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
906 bool IsReadOnly() const;
907 void SetDefAttr(wxGridCellAttr* defAttr);
910 //---------------------------------------------------------------------------
912 class wxGridCellAttrProvider
915 wxGridCellAttrProvider();
916 // ???? virtual ~wxGridCellAttrProvider();
918 wxGridCellAttr *GetAttr(int row, int col,
919 wxGridCellAttr::wxAttrKind kind) const;
920 void SetAttr(wxGridCellAttr *attr, int row, int col);
921 void SetRowAttr(wxGridCellAttr *attr, int row);
922 void SetColAttr(wxGridCellAttr *attr, int col);
924 void UpdateAttrRows( size_t pos, int numRows );
925 void UpdateAttrCols( size_t pos, int numCols );
930 // A Python-aware version
932 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
935 wxPyGridCellAttrProvider() : wxGridCellAttrProvider() {};
937 PYCALLBACK_GCA_INTINTKIND(wxGridCellAttrProvider, GetAttr);
938 PYCALLBACK__GCAINTINT(wxGridCellAttrProvider, SetAttr);
939 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetRowAttr);
940 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetColAttr);
947 // The python-aware version get's SWIGified
948 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
951 wxPyGridCellAttrProvider();
952 void _setCallbackInfo(PyObject* self, PyObject* _class);
953 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellAttrProvider)"
955 wxGridCellAttr *base_GetAttr(int row, int col,
956 wxGridCellAttr::wxAttrKind kind);
957 void base_SetAttr(wxGridCellAttr *attr, int row, int col);
958 void base_SetRowAttr(wxGridCellAttr *attr, int row);
959 void base_SetColAttr(wxGridCellAttr *attr, int col);
963 //---------------------------------------------------------------------------
964 // Grid Table Base class and Python aware version
968 class wxGridTableBase : public wxObject
971 // wxGridTableBase(); This is an ABC
972 //~wxGridTableBase();
974 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
975 wxGridCellAttrProvider *GetAttrProvider() const;
976 void SetView( wxGrid *grid );
977 wxGrid * GetView() const;
981 virtual int GetNumberRows() = 0;
982 virtual int GetNumberCols() = 0;
983 virtual bool IsEmptyCell( int row, int col ) = 0;
984 virtual wxString GetValue( int row, int col ) = 0;
985 virtual void SetValue( int row, int col, const wxString& value ) = 0;
987 // virtuals overridable in wxPyGridTableBase
988 virtual wxString GetTypeName( int row, int col );
989 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
990 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
991 virtual long GetValueAsLong( int row, int col );
992 virtual double GetValueAsDouble( int row, int col );
993 virtual bool GetValueAsBool( int row, int col );
994 virtual void SetValueAsLong( int row, int col, long value );
995 virtual void SetValueAsDouble( int row, int col, double value );
996 virtual void SetValueAsBool( int row, int col, bool value );
998 //virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
999 //virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
1002 virtual void Clear();
1003 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
1004 virtual bool AppendRows( size_t numRows = 1 );
1005 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
1006 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
1007 virtual bool AppendCols( size_t numCols = 1 );
1008 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
1010 virtual wxString GetRowLabelValue( int row );
1011 virtual wxString GetColLabelValue( int col );
1012 virtual void SetRowLabelValue( int row, const wxString& value );
1013 virtual void SetColLabelValue( int col, const wxString& value );
1015 virtual bool CanHaveAttributes();
1017 virtual wxGridCellAttr *GetAttr( int row, int col,
1018 wxGridCellAttr::wxAttrKind kind);
1019 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
1020 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
1021 virtual void SetColAttr(wxGridCellAttr *attr, int col);
1027 // Python-aware version
1029 class wxPyGridTableBase : public wxGridTableBase
1032 wxPyGridTableBase() : wxGridTableBase() {}
1034 PYCALLBACK_INT__pure(GetNumberRows);
1035 PYCALLBACK_INT__pure(GetNumberCols);
1036 PYCALLBACK_BOOL_INTINT_pure(IsEmptyCell);
1037 PYCALLBACK_STRING_INTINT(wxGridTableBase, GetTypeName);
1038 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanGetValueAs);
1039 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanSetValueAs);
1040 PYCALLBACK__(wxGridTableBase, Clear);
1041 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertRows);
1042 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteRows);
1043 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertCols);
1044 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteCols);
1045 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendRows);
1046 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendCols);
1047 PYCALLBACK_STRING_INT(wxGridTableBase, GetRowLabelValue);
1048 PYCALLBACK_STRING_INT(wxGridTableBase, GetColLabelValue);
1049 PYCALLBACK__INTSTRING(wxGridTableBase, SetRowLabelValue);
1050 PYCALLBACK__INTSTRING(wxGridTableBase, SetColLabelValue);
1051 PYCALLBACK_BOOL_(wxGridTableBase, CanHaveAttributes);
1052 PYCALLBACK_GCA_INTINTKIND(wxGridTableBase, GetAttr);
1053 PYCALLBACK__GCAINTINT(wxGridTableBase, SetAttr);
1054 PYCALLBACK__GCAINT(wxGridTableBase, SetRowAttr);
1055 PYCALLBACK__GCAINT(wxGridTableBase, SetColAttr);
1058 wxString GetValue(int row, int col) {
1059 wxPyBeginBlockThreads();
1061 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1063 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",row,col));
1065 rval = Py2wxString(ro);
1069 wxPyEndBlockThreads();
1073 void SetValue(int row, int col, const wxString& val) {
1074 wxPyBeginBlockThreads();
1075 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1076 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",row,col,wx2PyString(val)));
1078 wxPyEndBlockThreads();
1082 // Map the Get/Set methods for the standard non-string types to
1083 // the GetValue and SetValue python methods.
1084 long GetValueAsLong( int row, int col ) {
1086 wxPyBeginBlockThreads();
1087 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1090 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1091 if (ro && PyNumber_Check(ro)) {
1092 num = PyNumber_Int(ro);
1094 rval = PyInt_AsLong(num);
1100 wxPyEndBlockThreads();
1104 double GetValueAsDouble( int row, int col ) {
1106 wxPyBeginBlockThreads();
1107 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1110 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1111 if (ro && PyNumber_Check(ro)) {
1112 num = PyNumber_Float(ro);
1114 rval = PyFloat_AsDouble(num);
1120 wxPyEndBlockThreads();
1124 bool GetValueAsBool( int row, int col ) {
1125 return (bool)GetValueAsLong(row, col);
1128 void SetValueAsLong( int row, int col, long value ) {
1129 wxPyBeginBlockThreads();
1130 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1131 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", row, col, value));
1133 wxPyEndBlockThreads();
1136 void SetValueAsDouble( int row, int col, double value ) {
1137 wxPyBeginBlockThreads();
1138 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1139 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iid)", row, col, value));
1141 wxPyEndBlockThreads();
1144 void SetValueAsBool( int row, int col, bool value ) {
1145 SetValueAsLong( row, col, (long)value );
1154 // The python-aware version get's SWIGified
1155 class wxPyGridTableBase : public wxGridTableBase
1158 wxPyGridTableBase();
1159 void _setCallbackInfo(PyObject* self, PyObject* _class);
1160 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridTableBase)"
1162 %addmethods { void Destroy() { delete self; } }
1164 wxString base_GetTypeName( int row, int col );
1165 bool base_CanGetValueAs( int row, int col, const wxString& typeName );
1166 bool base_CanSetValueAs( int row, int col, const wxString& typeName );
1168 bool base_InsertRows( size_t pos = 0, size_t numRows = 1 );
1169 bool base_AppendRows( size_t numRows = 1 );
1170 bool base_DeleteRows( size_t pos = 0, size_t numRows = 1 );
1171 bool base_InsertCols( size_t pos = 0, size_t numCols = 1 );
1172 bool base_AppendCols( size_t numCols = 1 );
1173 bool base_DeleteCols( size_t pos = 0, size_t numCols = 1 );
1174 wxString base_GetRowLabelValue( int row );
1175 wxString base_GetColLabelValue( int col );
1176 void base_SetRowLabelValue( int row, const wxString& value );
1177 void base_SetColLabelValue( int col, const wxString& value );
1178 bool base_CanHaveAttributes();
1179 wxGridCellAttr *base_GetAttr( int row, int col,
1180 wxGridCellAttr::wxAttrKind kind );
1181 void base_SetAttr(wxGridCellAttr* attr, int row, int col);
1182 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1183 void base_SetColAttr(wxGridCellAttr *attr, int col);
1187 //---------------------------------------------------------------------------
1188 // Predefined Tables
1190 class wxGridStringTable : public wxGridTableBase
1193 wxGridStringTable( int numRows=0, int numCols=0 );
1196 //---------------------------------------------------------------------------
1197 // The Table can pass messages to the grid to tell it to update itself if
1198 // something has changed.
1200 enum wxGridTableRequest
1202 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
1203 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
1204 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
1205 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
1206 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
1207 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1208 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
1209 wxGRIDTABLE_NOTIFY_COLS_DELETED
1213 class wxGridTableMessage
1216 wxGridTableMessage( wxGridTableBase *table, int id,
1219 ~wxGridTableMessage();
1221 void SetTableObject( wxGridTableBase *table );
1222 wxGridTableBase * GetTableObject() const;
1223 void SetId( int id );
1225 void SetCommandInt( int comInt1 );
1226 int GetCommandInt();
1227 void SetCommandInt2( int comInt2 );
1228 int GetCommandInt2();
1232 //---------------------------------------------------------------------------
1234 class wxGridCellCoords
1237 wxGridCellCoords( int r=-1, int c=-1 );
1238 ~wxGridCellCoords();
1240 int GetRow() const { return m_row; }
1241 void SetRow( int n ) { m_row = n; }
1242 int GetCol() const { return m_col; }
1243 void SetCol( int n ) { m_col = n; }
1244 void Set( int row, int col ) { m_row = row; m_col = col; }
1247 PyObject* asTuple() {
1248 PyObject* tup = PyTuple_New(2);
1249 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
1250 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
1254 int __cmp__( const wxGridCellCoords& other ) {
1255 return *self != other;
1258 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
1259 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
1262 // Typemap to allow conversion of sequence objects to wxGridCellCoords...
1263 %typemap(python,in) wxGridCellCoords& (wxGridCellCoords temp) {
1265 if (! wxGridCellCoords_helper($source, &$target))
1269 // ...and here is the associated helper.
1271 bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) {
1273 // If source is an object instance then it may already be the right type
1274 if (PyInstance_Check(source)) {
1275 wxGridCellCoords* ptr;
1276 if (SWIG_GetPtrObj(source, (void **)&ptr, "_wxGridCellCoords_p"))
1281 // otherwise a 2-tuple of integers is expected
1282 else if (PySequence_Check(source) && PyObject_Length(source) == 2) {
1283 PyObject* o1 = PySequence_GetItem(source, 0);
1284 PyObject* o2 = PySequence_GetItem(source, 1);
1285 **obj = wxGridCellCoords(PyInt_AsLong(o1), PyInt_AsLong(o2));
1290 PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of integers or a wxGridCellCoords object.");
1295 //---------------------------------------------------------------------------
1296 //---------------------------------------------------------------------------
1300 // Fool SWIG into treating this enum as an int
1301 typedef int WXGRIDSELECTIONMODES;
1303 // but let the C++ code know what it really is.
1305 typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES;
1310 class wxGrid : public wxScrolledWindow
1313 wxGrid( wxWindow *parent,
1315 const wxPoint& pos = wxDefaultPosition,
1316 const wxSize& size = wxDefaultSize,
1317 long style = wxWANTS_CHARS,
1318 const char* name = wxPanelNameStr );
1320 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1322 enum wxGridSelectionModes {wxGridSelectCells,
1324 wxGridSelectColumns};
1326 bool CreateGrid( int numRows, int numCols,
1327 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1328 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1331 // ------ grid dimensions
1333 int GetNumberRows();
1334 int GetNumberCols();
1337 bool ProcessTableMessage( wxGridTableMessage& );
1340 wxGridTableBase * GetTable() const;
1341 bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE,
1342 WXGRIDSELECTIONMODES selmode =
1343 wxGrid::wxGridSelectCells );
1346 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1347 bool AppendRows( int numRows = 1, bool updateLabels=TRUE );
1348 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1349 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1350 bool AppendCols( int numCols = 1, bool updateLabels=TRUE );
1351 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1354 // this function is called when the current cell highlight must be redrawn
1355 // and may be overridden by the user
1356 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1359 // ------ Cell text drawing functions
1361 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1362 int horizontalAlignment = wxLEFT,
1363 int verticalAlignment = wxTOP );
1365 // // Split a string containing newline chararcters into an array of
1366 // // strings and return the number of lines
1368 // void StringToLines( const wxString& value, wxArrayString& lines );
1370 void GetTextBoxSize( wxDC& dc,
1371 wxArrayString& lines,
1372 long *OUTPUT, long *OUTPUT );
1376 // Code that does a lot of grid modification can be enclosed
1377 // between BeginBatch() and EndBatch() calls to avoid screen
1382 int GetBatchCount();
1383 void ForceRefresh();
1386 // ------ edit control functions
1388 bool IsEditable() { return m_editable; }
1389 void EnableEditing( bool edit );
1391 void EnableCellEditControl( bool enable = TRUE );
1392 void DisableCellEditControl();
1393 bool CanEnableCellControl() const;
1394 bool IsCellEditControlEnabled() const;
1395 bool IsCellEditControlShown() const;
1397 bool IsCurrentCellReadOnly() const;
1399 void ShowCellEditControl();
1400 void HideCellEditControl();
1401 void SaveEditControlValue();
1404 // ------ grid location functions
1405 // Note that all of these functions work with the logical coordinates of
1406 // grid cells and labels so you will need to convert from device
1407 // coordinates for mouse events etc.
1410 //void XYToCell( int x, int y, wxGridCellCoords& );
1412 %new wxGridCellCoords* XYToCell(int x, int y) {
1413 wxGridCellCoords rv;
1414 self->XYToCell(x, y, rv);
1415 return new wxGridCellCoords(rv);
1419 int YToRow( int y );
1420 int XToCol( int x );
1422 int YToEdgeOfRow( int y );
1423 int XToEdgeOfCol( int x );
1425 wxRect CellToRect( int row, int col );
1426 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1429 int GetGridCursorRow();
1430 int GetGridCursorCol();
1432 // check to see if a cell is either wholly visible (the default arg) or
1433 // at least partially visible in the grid window
1435 bool IsVisible( int row, int col, bool wholeCellVisible = TRUE );
1436 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE );
1437 void MakeCellVisible( int row, int col );
1438 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1441 // ------ grid cursor movement functions
1443 void SetGridCursor( int row, int col );
1444 bool MoveCursorUp( bool expandSelection );
1445 bool MoveCursorDown( bool expandSelection );
1446 bool MoveCursorLeft( bool expandSelection );
1447 bool MoveCursorRight( bool expandSelection );
1448 bool MovePageDown();
1450 bool MoveCursorUpBlock( bool expandSelection );
1451 bool MoveCursorDownBlock( bool expandSelection );
1452 bool MoveCursorLeftBlock( bool expandSelection );
1453 bool MoveCursorRightBlock( bool expandSelection );
1456 // ------ label and gridline formatting
1458 int GetDefaultRowLabelSize();
1459 int GetRowLabelSize();
1460 int GetDefaultColLabelSize();
1461 int GetColLabelSize();
1462 wxColour GetLabelBackgroundColour();
1463 wxColour GetLabelTextColour();
1464 wxFont GetLabelFont();
1465 void GetRowLabelAlignment( int *OUTPUT, int *OUTPUT );
1466 void GetColLabelAlignment( int *OUTPUT, int *OUTPUT );
1467 wxString GetRowLabelValue( int row );
1468 wxString GetColLabelValue( int col );
1469 wxColour GetGridLineColour();
1470 wxColour GetCellHighlightColour();
1471 int GetCellHighlightPenWidth();
1472 int GetCellHighlightROPenWidth();
1474 void SetRowLabelSize( int width );
1475 void SetColLabelSize( int height );
1476 void SetLabelBackgroundColour( const wxColour& );
1477 void SetLabelTextColour( const wxColour& );
1478 void SetLabelFont( const wxFont& );
1479 void SetRowLabelAlignment( int horiz, int vert );
1480 void SetColLabelAlignment( int horiz, int vert );
1481 void SetRowLabelValue( int row, const wxString& );
1482 void SetColLabelValue( int col, const wxString& );
1483 void SetGridLineColour( const wxColour& );
1484 void SetCellHighlightColour( const wxColour& );
1485 void SetCellHighlightPenWidth(int width);
1486 void SetCellHighlightROPenWidth(int width);
1488 void EnableDragRowSize( bool enable = TRUE );
1489 void DisableDragRowSize();
1490 bool CanDragRowSize();
1491 void EnableDragColSize( bool enable = TRUE );
1492 void DisableDragColSize();
1493 bool CanDragColSize();
1494 void EnableDragGridSize(bool enable = TRUE);
1495 void DisableDragGridSize();
1496 bool CanDragGridSize();
1498 // this sets the specified attribute for all cells in this row/col
1499 void SetRowAttr(int row, wxGridCellAttr *attr);
1500 void SetColAttr(int col, wxGridCellAttr *attr);
1502 // shortcuts for setting the column parameters
1504 // set the format for the data in the column: default is string
1505 void SetColFormatBool(int col);
1506 void SetColFormatNumber(int col);
1507 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1508 void SetColFormatCustom(int col, const wxString& typeName);
1510 void EnableGridLines( bool enable = TRUE );
1511 bool GridLinesEnabled();
1513 // ------ row and col formatting
1515 int GetDefaultRowSize();
1516 int GetRowSize( int row );
1517 int GetDefaultColSize();
1518 int GetColSize( int col );
1519 wxColour GetDefaultCellBackgroundColour();
1520 wxColour GetCellBackgroundColour( int row, int col );
1521 wxColour GetDefaultCellTextColour();
1522 wxColour GetCellTextColour( int row, int col );
1523 wxFont GetDefaultCellFont();
1524 wxFont GetCellFont( int row, int col );
1525 void GetDefaultCellAlignment( int *horiz, int *vert );
1526 void GetCellAlignment( int row, int col, int *horiz, int *vert );
1528 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
1529 void SetRowSize( int row, int height );
1530 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
1532 void SetColSize( int col, int width );
1534 // automatically size the column or row to fit to its contents, if
1535 // setAsMin is TRUE, this optimal width will also be set as minimal width
1537 void AutoSizeColumn( int col, bool setAsMin = TRUE );
1538 void AutoSizeRow( int row, bool setAsMin = TRUE );
1541 // auto size all columns (very ineffective for big grids!)
1542 void AutoSizeColumns( bool setAsMin = TRUE );
1543 void AutoSizeRows( bool setAsMin = TRUE );
1545 // auto size the grid, that is make the columns/rows of the "right" size
1546 // and also set the grid size to just fit its contents
1549 // column won't be resized to be lesser width - this must be called during
1550 // the grid creation because it won't resize the column if it's already
1551 // narrower than the minimal width
1552 void SetColMinimalWidth( int col, int width );
1553 void SetRowMinimalHeight( int row, int width );
1555 void SetDefaultCellBackgroundColour( const wxColour& );
1556 void SetCellBackgroundColour( int row, int col, const wxColour& );
1557 void SetDefaultCellTextColour( const wxColour& );
1559 void SetCellTextColour( int row, int col, const wxColour& );
1560 void SetDefaultCellFont( const wxFont& );
1561 void SetCellFont( int row, int col, const wxFont& );
1562 void SetDefaultCellAlignment( int horiz, int vert );
1563 void SetCellAlignment( int row, int col, int horiz, int vert );
1565 // takes ownership of the pointer
1566 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1567 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1568 wxGridCellRenderer *GetDefaultRenderer() const;
1569 wxGridCellRenderer* GetCellRenderer(int row, int col);
1571 // takes ownership of the pointer
1572 void SetDefaultEditor(wxGridCellEditor *editor);
1573 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1574 wxGridCellEditor *GetDefaultEditor() const;
1575 wxGridCellEditor* GetCellEditor(int row, int col);
1579 // ------ cell value accessors
1581 wxString GetCellValue( int row, int col );
1582 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1584 void SetCellValue( int row, int col, const wxString& s );
1585 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1587 // returns TRUE if the cell can't be edited
1588 bool IsReadOnly(int row, int col) const;
1590 // make the cell editable/readonly
1591 void SetReadOnly(int row, int col, bool isReadOnly = TRUE);
1593 // ------ selections of blocks of cells
1595 void SelectRow( int row, bool addToSelected = FALSE );
1596 void SelectCol( int col, bool addToSelected = FALSE );
1598 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1599 bool addToSelected = FALSE );
1600 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1601 // TODO: ??? const wxGridCellCoords& bottomRight )
1605 void ClearSelection();
1606 bool IsInSelection( int row, int col );
1607 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1610 // This function returns the rectangle that encloses the block of cells
1611 // limited by TopLeft and BottomRight cell in device coords and clipped
1612 // to the client size of the grid window.
1614 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1615 const wxGridCellCoords & bottomRight );
1618 // Access or update the selection fore/back colours
1619 wxColour GetSelectionBackground() const;
1620 wxColour GetSelectionForeground() const;
1622 void SetSelectionBackground(const wxColour& c);
1623 void SetSelectionForeground(const wxColour& c);
1626 // Methods for a registry for mapping data types to Renderers/Editors
1627 void RegisterDataType(const wxString& typeName,
1628 wxGridCellRenderer* renderer,
1629 wxGridCellEditor* editor);
1630 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1631 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1632 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1633 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1634 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1636 // grid may occupy more space than needed for its rows/columns, this
1637 // function allows to set how big this extra space is
1638 void SetMargins(int extraWidth, int extraHeight);
1641 // Accessors for component windows
1642 wxWindow* GetGridWindow();
1643 wxWindow* GetGridRowLabelWindow();
1644 wxWindow* GetGridColLabelWindow();
1645 wxWindow* GetGridCornerLabelWindow();
1651 //---------------------------------------------------------------------------
1652 //---------------------------------------------------------------------------
1653 // Grid events and stuff
1657 class wxGridEvent : public wxNotifyEvent
1660 wxGridEvent(int id, wxEventType type, wxGrid* obj,
1661 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = TRUE,
1662 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1664 virtual int GetRow();
1665 virtual int GetCol();
1666 wxPoint GetPosition();
1676 class wxGridSizeEvent : public wxNotifyEvent
1679 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
1680 int rowOrCol=-1, int x=-1, int y=-1,
1681 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1684 wxPoint GetPosition();
1693 class wxGridRangeSelectEvent : public wxNotifyEvent
1696 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
1697 const wxGridCellCoords& topLeft,
1698 const wxGridCellCoords& bottomRight,
1700 bool control=FALSE, bool shift=FALSE,
1701 bool alt=FALSE, bool meta=FALSE);
1703 wxGridCellCoords GetTopLeftCoords();
1704 wxGridCellCoords GetBottomRightCoords();
1717 class wxGridEditorCreatedEvent : public wxCommandEvent {
1719 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
1720 int row, int col, wxControl* ctrl);
1724 wxControl* GetControl();
1725 void SetRow(int row);
1726 void SetCol(int col);
1727 void SetControl(wxControl* ctrl);
1733 wxEVT_GRID_CELL_LEFT_CLICK,
1734 wxEVT_GRID_CELL_RIGHT_CLICK,
1735 wxEVT_GRID_CELL_LEFT_DCLICK,
1736 wxEVT_GRID_CELL_RIGHT_DCLICK,
1737 wxEVT_GRID_LABEL_LEFT_CLICK,
1738 wxEVT_GRID_LABEL_RIGHT_CLICK,
1739 wxEVT_GRID_LABEL_LEFT_DCLICK,
1740 wxEVT_GRID_LABEL_RIGHT_DCLICK,
1741 wxEVT_GRID_ROW_SIZE,
1742 wxEVT_GRID_COL_SIZE,
1743 wxEVT_GRID_RANGE_SELECT,
1744 wxEVT_GRID_CELL_CHANGE,
1745 wxEVT_GRID_SELECT_CELL,
1746 wxEVT_GRID_EDITOR_SHOWN,
1747 wxEVT_GRID_EDITOR_HIDDEN,
1748 wxEVT_GRID_EDITOR_CREATED,
1753 %pragma(python) code = "
1754 def EVT_GRID_CELL_LEFT_CLICK(win, fn):
1755 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_CLICK, fn)
1757 def EVT_GRID_CELL_RIGHT_CLICK(win, fn):
1758 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_CLICK, fn)
1760 def EVT_GRID_CELL_LEFT_DCLICK(win, fn):
1761 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_DCLICK, fn)
1763 def EVT_GRID_CELL_RIGHT_DCLICK(win, fn):
1764 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_DCLICK, fn)
1766 def EVT_GRID_LABEL_LEFT_CLICK(win, fn):
1767 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_CLICK, fn)
1769 def EVT_GRID_LABEL_RIGHT_CLICK(win, fn):
1770 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_CLICK, fn)
1772 def EVT_GRID_LABEL_LEFT_DCLICK(win, fn):
1773 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_DCLICK, fn)
1775 def EVT_GRID_LABEL_RIGHT_DCLICK(win, fn):
1776 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_DCLICK, fn)
1778 def EVT_GRID_ROW_SIZE(win, fn):
1779 win.Connect(-1, -1, wxEVT_GRID_ROW_SIZE, fn)
1781 def EVT_GRID_COL_SIZE(win, fn):
1782 win.Connect(-1, -1, wxEVT_GRID_COL_SIZE, fn)
1784 def EVT_GRID_RANGE_SELECT(win, fn):
1785 win.Connect(-1, -1, wxEVT_GRID_RANGE_SELECT, fn)
1787 def EVT_GRID_CELL_CHANGE(win, fn):
1788 win.Connect(-1, -1, wxEVT_GRID_CELL_CHANGE, fn)
1790 def EVT_GRID_SELECT_CELL(win, fn):
1791 win.Connect(-1, -1, wxEVT_GRID_SELECT_CELL, fn)
1793 def EVT_GRID_EDITOR_SHOWN(win, fn):
1794 win.Connect(-1, -1, wxEVT_GRID_EDITOR_SHOWN, fn)
1796 def EVT_GRID_EDITOR_HIDDEN(win, fn):
1797 win.Connect(-1, -1, wxEVT_GRID_EDITOR_HIDDEN, fn)
1799 def EVT_GRID_EDITOR_CREATED(win, fn):
1800 win.Connect(-1, -1, wxEVT_GRID_EDITOR_CREATED, fn)
1804 //---------------------------------------------------------------------------
1807 wxClassInfo::CleanUpClasses();
1808 wxClassInfo::InitializeClasses();
1811 //---------------------------------------------------------------------------
1813 %pragma(python) include="_gridextras.py";
1815 //---------------------------------------------------------------------------