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);
45 //---------------------------------------------------------------------------
46 //---------------------------------------------------------------------------
47 // Macros, similar to what's in helpers.h, to aid in the creation of
48 // virtual methods that are able to make callbacks to Python. Many of these
49 // are specific to wxGrid and so are kept here to reduce the mess in helpers.h
54 #define PYCALLBACK_GCA_INTINTKIND(PCLASS, CBNAME) \
55 wxGridCellAttr* CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
56 wxGridCellAttr* rval = NULL; \
58 wxPyBeginBlockThreads(); \
59 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
61 wxGridCellAttr* ptr; \
62 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iii)", a, b, c)); \
64 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellAttr_p")) \
69 wxPyEndBlockThreads(); \
71 rval = PCLASS::CBNAME(a, b, c); \
74 wxGridCellAttr *base_##CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
75 return PCLASS::CBNAME(a, b, c); \
80 #define PYCALLBACK__GCAINTINT(PCLASS, CBNAME) \
81 void CBNAME(wxGridCellAttr *attr, int a, int b) { \
82 wxPyBeginBlockThreads(); \
84 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
85 PyObject* obj = wxPyConstructObject((void*)attr, "wxGridCellAttr", 0);\
86 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oii)", obj, a, b)); \
89 wxPyEndBlockThreads(); \
91 PCLASS::CBNAME(attr, a, b); \
93 void base_##CBNAME(wxGridCellAttr *attr, int a, int b) { \
94 PCLASS::CBNAME(attr, a, b); \
99 #define PYCALLBACK__GCAINT(PCLASS, CBNAME) \
100 void CBNAME(wxGridCellAttr *attr, int val) { \
101 wxPyBeginBlockThreads(); \
103 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
104 PyObject* obj = wxPyConstructObject((void*)attr, "wxGridCellAttr", 0);\
105 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, val)); \
108 wxPyEndBlockThreads(); \
110 PCLASS::CBNAME(attr, val); \
112 void base_##CBNAME(wxGridCellAttr *attr, int val) { \
113 PCLASS::CBNAME(attr, val); \
118 #define PYCALLBACK_INT__pure(CBNAME) \
120 wxPyBeginBlockThreads(); \
122 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
123 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
124 wxPyEndBlockThreads(); \
130 #define PYCALLBACK_BOOL_INTINT_pure(CBNAME) \
131 bool CBNAME(int a, int b) { \
132 wxPyBeginBlockThreads(); \
134 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
135 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
136 wxPyEndBlockThreads(); \
141 #define PYCALLBACK_STRING_INTINT_pure(CBNAME) \
142 wxString CBNAME(int a, int b) { \
143 wxPyBeginBlockThreads(); \
145 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
147 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
149 rval = Py2wxString(ro); \
153 wxPyEndBlockThreads(); \
158 #define PYCALLBACK__INTINTSTRING_pure(CBNAME) \
159 void CBNAME(int a, int b, const wxString& c) { \
160 wxPyBeginBlockThreads(); \
161 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
162 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,wx2PyString(c)));\
163 wxPyEndBlockThreads(); \
167 #define PYCALLBACK_STRING_INTINT(PCLASS, CBNAME) \
168 wxString CBNAME(int a, int b) { \
170 wxPyBeginBlockThreads(); \
172 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
174 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
176 rval = Py2wxString(ro); \
180 wxPyEndBlockThreads(); \
182 rval = PCLASS::CBNAME(a, b); \
185 wxString base_##CBNAME(int a, int b) { \
186 return PCLASS::CBNAME(a, b); \
190 #define PYCALLBACK_BOOL_INTINTSTRING(PCLASS, CBNAME) \
191 bool CBNAME(int a, int b, const wxString& c) { \
194 wxPyBeginBlockThreads(); \
195 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
196 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", a,b,wx2PyString(c)));\
197 wxPyEndBlockThreads(); \
199 rval = PCLASS::CBNAME(a,b,c); \
202 bool base_##CBNAME(int a, int b, const wxString& c) { \
203 return PCLASS::CBNAME(a,b,c); \
209 #define PYCALLBACK_LONG_INTINT(PCLASS, CBNAME) \
210 long CBNAME(int a, int b) { \
213 wxPyBeginBlockThreads(); \
214 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
215 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
216 wxPyEndBlockThreads(); \
218 rval = PCLASS::CBNAME(a,b); \
221 long base_##CBNAME(int a, int b) { \
222 return PCLASS::CBNAME(a,b); \
227 #define PYCALLBACK_BOOL_INTINT(PCLASS, CBNAME) \
228 bool CBNAME(int a, int b) { \
231 wxPyBeginBlockThreads(); \
232 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
233 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
234 wxPyEndBlockThreads(); \
236 rval = PCLASS::CBNAME(a,b); \
239 bool base_##CBNAME(int a, int b) { \
240 return PCLASS::CBNAME(a,b); \
245 #define PYCALLBACK_DOUBLE_INTINT(PCLASS, CBNAME) \
246 double CBNAME(int a, int b) { \
248 wxPyBeginBlockThreads(); \
250 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
252 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
254 PyObject* str = PyObject_Str(ro); \
255 rval = PyFloat_AsDouble(str); \
256 Py_DECREF(ro); Py_DECREF(str); \
259 wxPyEndBlockThreads(); \
261 rval = PCLASS::CBNAME(a, b); \
264 double base_##CBNAME(int a, int b) { \
265 return PCLASS::CBNAME(a, b); \
270 #define PYCALLBACK__(PCLASS, CBNAME) \
273 wxPyBeginBlockThreads(); \
274 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
275 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
276 wxPyEndBlockThreads(); \
280 void base_##CBNAME() { \
287 #define PYCALLBACK_BOOL_SIZETSIZET(PCLASS, CBNAME) \
288 bool CBNAME(size_t a, size_t b) { \
291 wxPyBeginBlockThreads(); \
292 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
293 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
294 wxPyEndBlockThreads(); \
296 rval = PCLASS::CBNAME(a,b); \
299 bool base_##CBNAME(size_t a, size_t b) { \
300 return PCLASS::CBNAME(a,b); \
305 #define PYCALLBACK_BOOL_SIZET(PCLASS, CBNAME) \
306 bool CBNAME(size_t a) { \
309 wxPyBeginBlockThreads(); \
310 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
311 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)", a)); \
312 wxPyEndBlockThreads(); \
314 rval = PCLASS::CBNAME(a); \
317 bool base_##CBNAME(size_t a) { \
318 return PCLASS::CBNAME(a); \
322 #define PYCALLBACK_STRING_INT(PCLASS, CBNAME) \
323 wxString CBNAME(int a) { \
325 wxPyBeginBlockThreads(); \
327 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
329 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(i)",a)); \
331 rval = Py2wxString(ro); \
335 wxPyEndBlockThreads(); \
337 rval = PCLASS::CBNAME(a); \
340 wxString base_##CBNAME(int a) { \
341 return PCLASS::CBNAME(a); \
345 #define PYCALLBACK__INTSTRING(PCLASS, CBNAME) \
346 void CBNAME(int a, const wxString& c) { \
348 wxPyBeginBlockThreads(); \
349 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
350 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", a, wx2PyString(c))); \
351 wxPyEndBlockThreads(); \
353 PCLASS::CBNAME(a,c); \
355 void base_##CBNAME(int a, const wxString& c) { \
356 PCLASS::CBNAME(a,c); \
362 #define PYCALLBACK_BOOL_(PCLASS, CBNAME) \
366 wxPyBeginBlockThreads(); \
367 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
368 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
369 wxPyEndBlockThreads(); \
371 rval = PCLASS::CBNAME(); \
374 bool base_##CBNAME() { \
375 return PCLASS::CBNAME(); \
380 #define PYCALLBACK__SIZETINT(PCLASS, CBNAME) \
381 void CBNAME(size_t a, int b) { \
383 wxPyBeginBlockThreads(); \
384 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
385 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
386 wxPyEndBlockThreads(); \
388 PCLASS::CBNAME(a,b); \
390 void base_##CBNAME(size_t a, int b) { \
391 PCLASS::CBNAME(a,b); \
397 #define PYCALLBACK__INTINTLONG(PCLASS, CBNAME) \
398 void CBNAME(int a, int b, long c) { \
400 wxPyBeginBlockThreads(); \
401 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
402 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
403 wxPyEndBlockThreads(); \
405 PCLASS::CBNAME(a,b,c); \
407 void base_##CBNAME(int a, int b, long c) { \
408 PCLASS::CBNAME(a,b,c); \
414 #define PYCALLBACK__INTINTDOUBLE(PCLASS, CBNAME) \
415 void CBNAME(int a, int b, double c) { \
417 wxPyBeginBlockThreads(); \
418 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
419 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iif)", a,b,c)); \
420 wxPyEndBlockThreads(); \
422 PCLASS::CBNAME(a,b,c); \
424 void base_##CBNAME(int a, int b, double c) { \
425 PCLASS::CBNAME(a,b,c); \
430 #define PYCALLBACK__INTINTBOOL(PCLASS, CBNAME) \
431 void CBNAME(int a, int b, bool c) { \
433 wxPyBeginBlockThreads(); \
434 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
435 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
436 wxPyEndBlockThreads(); \
438 PCLASS::CBNAME(a,b,c); \
440 void base_##CBNAME(int a, int b, bool c) { \
441 PCLASS::CBNAME(a,b,c); \
449 //---------------------------------------------------------------------------
451 class wxGridCellCoords;
452 class wxGridCellAttr;
456 #define wxGRID_VALUE_STRING "string"
457 #define wxGRID_VALUE_BOOL "bool"
458 #define wxGRID_VALUE_NUMBER "long"
459 #define wxGRID_VALUE_FLOAT "double"
460 #define wxGRID_VALUE_CHOICE "choice"
461 #define wxGRID_VALUE_TEXT "string"
462 #define wxGRID_VALUE_LONG "long"
465 wxGridCellCoords wxGridNoCellCoords;
466 wxRect wxGridNoCellRect;
470 //---------------------------------------------------------------------------
471 // wxGridCellRenderer is an ABC, and several derived classes are available.
472 // Classes implemented in Python should be derived from wxPyGridCellRenderer.
475 class wxGridCellRenderer
478 void SetParameters(const wxString& params);
482 virtual void Draw(wxGrid& grid,
483 wxGridCellAttr& attr,
487 bool isSelected) = 0;
488 virtual wxSize GetBestSize(wxGrid& grid,
489 wxGridCellAttr& attr,
491 int row, int col) = 0;
492 virtual wxGridCellRenderer *Clone() const = 0;
496 // The C++ version of wxPyGridCellRenderer
498 class wxPyGridCellRenderer : public wxGridCellRenderer
501 wxPyGridCellRenderer() : wxGridCellRenderer() {};
503 // Implement Python callback aware virtual methods
504 void Draw(wxGrid& grid, wxGridCellAttr& attr,
505 wxDC& dc, const wxRect& rect,
506 int row, int col, bool isSelected) {
507 wxPyBeginBlockThreads();
508 if (wxPyCBH_findCallback(m_myInst, "Draw")) {
509 wxPyCBH_callCallback(m_myInst,
510 Py_BuildValue("(OOOOiii)",
511 wxPyConstructObject((void*)&grid, "wxGrid", 0),
512 wxPyConstructObject((void*)&attr, "wxGridCellAttr", 0),
513 wxPyConstructObject((void*)&dc, "wxDC", 0),
514 wxPyConstructObject((void*)&rect, "wxRect", 0),
515 row, col, isSelected));
517 wxPyEndBlockThreads();
520 wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
523 wxPyBeginBlockThreads();
524 if (wxPyCBH_findCallback(m_myInst, "GetBestSize")) {
527 ro = wxPyCBH_callCallbackObj(m_myInst,
528 Py_BuildValue("(OOOii)",
529 wxPyConstructObject((void*)&grid, "wxGrid", 0),
530 wxPyConstructObject((void*)&attr, "wxGridCellAttr", 0),
531 wxPyConstructObject((void*)&dc, "wxDC", 0),
534 const char* errmsg = "GetBestSize should return a 2-tuple of integers or a wxSize object.";
535 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p")) {
538 else if (PySequence_Check(ro) && PyObject_Length(ro) == 2) {
539 PyObject* o1 = PySequence_GetItem(ro, 0);
540 PyObject* o2 = PySequence_GetItem(ro, 1);
541 if (PyNumber_Check(o1) && PyNumber_Check(o2))
542 rval = wxSize(PyInt_AsLong(o1), PyInt_AsLong(o2));
544 PyErr_SetString(PyExc_TypeError, errmsg);
549 PyErr_SetString(PyExc_TypeError, errmsg);
554 wxPyEndBlockThreads();
559 wxGridCellRenderer *Clone() const {
560 wxGridCellRenderer* rval = NULL;
561 wxPyBeginBlockThreads();
562 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
564 wxGridCellRenderer* ptr;
565 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
567 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellRenderer_p"))
572 wxPyEndBlockThreads();
576 DEC_PYCALLBACK__STRING(SetParameters);
581 IMP_PYCALLBACK__STRING( wxPyGridCellRenderer, wxGridCellRenderer, SetParameters);
586 // Let SWIG know about it so it can create the Python version
587 class wxPyGridCellRenderer : public wxGridCellRenderer {
589 wxPyGridCellRenderer();
590 void _setCallbackInfo(PyObject* self, PyObject* _class);
591 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellRenderer)"
593 void base_SetParameters(const wxString& params);
596 //---------------------------------------------------------------------------
597 // Predefined Renderers
599 class wxGridCellStringRenderer : public wxGridCellRenderer
602 wxGridCellStringRenderer();
606 class wxGridCellNumberRenderer : public wxGridCellStringRenderer
609 wxGridCellNumberRenderer();
613 class wxGridCellFloatRenderer : public wxGridCellStringRenderer
616 wxGridCellFloatRenderer(int width = -1, int precision = -1);
618 int GetWidth() const;
619 void SetWidth(int width);
620 int GetPrecision() const;
621 void SetPrecision(int precision);
625 class wxGridCellBoolRenderer : public wxGridCellRenderer
628 wxGridCellBoolRenderer();
632 class wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
635 wxGridCellDateTimeRenderer(wxString outformat = "%c",
636 wxString informat = "%c");
640 class wxGridCellEnumRenderer : public wxGridCellStringRenderer
643 wxGridCellEnumRenderer( const wxString& choices = "" );
647 class wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer
650 wxGridCellAutoWrapStringRenderer();
654 //---------------------------------------------------------------------------
655 // wxGridCellEditor is an ABC, and several derived classes are available.
656 // Classes implemented in Python should be derived from wxPyGridCellEditor.
658 class wxGridCellEditor
662 wxControl* GetControl();
663 void SetControl(wxControl* control);
665 void SetParameters(const wxString& params);
669 virtual void Create(wxWindow* parent,
671 wxEvtHandler* evtHandler) = 0;
672 virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
673 virtual bool EndEdit(int row, int col, wxGrid* grid) = 0;
674 virtual void Reset() = 0;
675 virtual wxGridCellEditor *Clone() const = 0;
677 virtual void SetSize(const wxRect& rect);
678 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
679 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
680 virtual bool IsAcceptedKey(wxKeyEvent& event);
681 virtual void StartingKey(wxKeyEvent& event);
682 virtual void StartingClick();
683 virtual void HandleReturn(wxKeyEvent& event);
684 virtual void Destroy();
689 // The C++ version of wxPyGridCellEditor
691 class wxPyGridCellEditor : public wxGridCellEditor
694 wxPyGridCellEditor() : wxGridCellEditor() {}
696 void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) {
697 wxPyBeginBlockThreads();
698 if (wxPyCBH_findCallback(m_myInst, "Create")) {
699 wxPyCBH_callCallback(m_myInst,
700 Py_BuildValue("(OiO)",
701 wxPyConstructObject((void*)parent, "wxWindow", 0),
703 wxPyConstructObject((void*)evtHandler, "wxEvtHandler", 0)));
705 wxPyEndBlockThreads();
709 void BeginEdit(int row, int col, wxGrid* grid) {
710 wxPyBeginBlockThreads();
711 if (wxPyCBH_findCallback(m_myInst, "BeginEdit")) {
712 wxPyCBH_callCallback(m_myInst,
713 Py_BuildValue("(iiO)", row, col,
714 wxPyConstructObject((void*)grid, "wxGrid", 0)));
716 wxPyEndBlockThreads();
720 bool EndEdit(int row, int col, wxGrid* grid) {
722 wxPyBeginBlockThreads();
723 if (wxPyCBH_findCallback(m_myInst, "EndEdit")) {
724 rv = wxPyCBH_callCallback(m_myInst,
725 Py_BuildValue("(iiO)", row, col,
726 wxPyConstructObject((void*)grid, "wxGrid", 0)));
728 wxPyEndBlockThreads();
733 wxGridCellEditor*Clone() const {
734 wxGridCellEditor* rval = NULL;
735 wxPyBeginBlockThreads();
736 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
738 wxGridCellEditor* ptr;
739 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
741 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellEditor_p"))
746 wxPyEndBlockThreads();
751 void Show(bool show, wxGridCellAttr *attr) {
753 wxPyBeginBlockThreads();
754 if ((found = wxPyCBH_findCallback(m_myInst, "Show")))
755 wxPyCBH_callCallback(m_myInst,
756 Py_BuildValue("(iO)", show,
757 wxPyConstructObject((void*)attr, "wxGridCellAttr", 0)));
758 wxPyEndBlockThreads();
760 wxGridCellEditor::Show(show, attr);
762 void base_Show(bool show, wxGridCellAttr *attr) {
763 wxGridCellEditor::Show(show, attr);
767 void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
769 wxPyBeginBlockThreads();
770 if ((found = wxPyCBH_findCallback(m_myInst, "PaintBackground)")))
771 wxPyCBH_callCallback(m_myInst,
772 Py_BuildValue("(OO)",
773 wxPyConstructObject((void*)&rectCell, "wxRect", 0),
774 wxPyConstructObject((void*)attr, "wxGridCellAttr", 0)));
775 wxPyEndBlockThreads();
777 wxGridCellEditor::PaintBackground(rectCell, attr);
779 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
780 wxGridCellEditor::PaintBackground(rectCell, attr);
784 DEC_PYCALLBACK___pure(Reset);
785 DEC_PYCALLBACK__constany(SetSize, wxRect);
786 DEC_PYCALLBACK_bool_any(IsAcceptedKey, wxKeyEvent);
787 DEC_PYCALLBACK__any(StartingKey, wxKeyEvent);
788 DEC_PYCALLBACK__any(HandleReturn, wxKeyEvent);
789 DEC_PYCALLBACK__(StartingClick);
790 DEC_PYCALLBACK__(Destroy);
791 DEC_PYCALLBACK__STRING(SetParameters);
797 IMP_PYCALLBACK__STRING( wxPyGridCellEditor, wxGridCellEditor, SetParameters);
798 IMP_PYCALLBACK___pure(wxPyGridCellEditor, wxGridCellEditor, Reset);
799 IMP_PYCALLBACK__constany(wxPyGridCellEditor, wxGridCellEditor, SetSize, wxRect);
800 IMP_PYCALLBACK_bool_any(wxPyGridCellEditor, wxGridCellEditor, IsAcceptedKey, wxKeyEvent);
801 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, StartingKey, wxKeyEvent);
802 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, HandleReturn, wxKeyEvent);
803 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, StartingClick);
804 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, Destroy);
809 // Let SWIG know about it so it can create the Python version
810 class wxPyGridCellEditor : public wxGridCellEditor {
812 wxPyGridCellEditor();
813 void _setCallbackInfo(PyObject* self, PyObject* _class);
814 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellEditor)"
816 void base_SetSize(const wxRect& rect);
817 void base_Show(bool show, wxGridCellAttr *attr = NULL);
818 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
819 void base_IsAcceptedKey(wxKeyEvent& event);
820 void base_StartingKey(wxKeyEvent& event);
821 void base_StartingClick();
822 void base_HandleReturn(wxKeyEvent& event);
824 void base_SetParameters(const wxString& params);
827 //---------------------------------------------------------------------------
828 // Predefined Editors
830 class wxGridCellTextEditor : public wxGridCellEditor
833 wxGridCellTextEditor();
837 class wxGridCellNumberEditor : public wxGridCellTextEditor
840 wxGridCellNumberEditor(int min = -1, int max = -1);
844 class wxGridCellFloatEditor : public wxGridCellTextEditor
847 wxGridCellFloatEditor();
851 class wxGridCellBoolEditor : public wxGridCellEditor
854 wxGridCellBoolEditor();
857 class wxGridCellChoiceEditor : public wxGridCellEditor
860 wxGridCellChoiceEditor(int LCOUNT = 0,
861 const wxString* choices = NULL,
862 bool allowOthers = FALSE);
866 class wxGridCellEnumEditor : public wxGridCellChoiceEditor
869 wxGridCellEnumEditor( const wxString& choices = "" );
873 class wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
876 wxGridCellAutoWrapStringEditor();
881 //---------------------------------------------------------------------------
897 wxGridCellAttr(wxGridCellAttr *attrDefault = NULL);
899 wxGridCellAttr *Clone() const;
900 void MergeWith(wxGridCellAttr *mergefrom);
903 void SetTextColour(const wxColour& colText);
904 void SetBackgroundColour(const wxColour& colBack);
905 void SetFont(const wxFont& font);
906 void SetAlignment(int hAlign, int vAlign);
907 void SetReadOnly(bool isReadOnly = TRUE);
909 void SetRenderer(wxGridCellRenderer *renderer);
910 void SetEditor(wxGridCellEditor* editor);
911 void SetKind(wxAttrKind kind);
913 bool HasTextColour() const;
914 bool HasBackgroundColour() const;
915 bool HasFont() const;
916 bool HasAlignment() const;
917 bool HasRenderer() const;
918 bool HasEditor() const;
919 bool HasReadWriteMode() const;
921 wxColour GetTextColour() const;
922 wxColour GetBackgroundColour() const;
923 wxFont GetFont() const;
924 void GetAlignment(int *OUTPUT, int *OUTPUT) const;
925 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
926 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
928 bool IsReadOnly() const;
929 void SetDefAttr(wxGridCellAttr* defAttr);
932 //---------------------------------------------------------------------------
934 class wxGridCellAttrProvider
937 wxGridCellAttrProvider();
938 // ???? virtual ~wxGridCellAttrProvider();
940 wxGridCellAttr *GetAttr(int row, int col,
941 wxGridCellAttr::wxAttrKind kind) const;
942 void SetAttr(wxGridCellAttr *attr, int row, int col);
943 void SetRowAttr(wxGridCellAttr *attr, int row);
944 void SetColAttr(wxGridCellAttr *attr, int col);
946 void UpdateAttrRows( size_t pos, int numRows );
947 void UpdateAttrCols( size_t pos, int numCols );
952 // A Python-aware version
954 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
957 wxPyGridCellAttrProvider() : wxGridCellAttrProvider() {};
959 PYCALLBACK_GCA_INTINTKIND(wxGridCellAttrProvider, GetAttr);
960 PYCALLBACK__GCAINTINT(wxGridCellAttrProvider, SetAttr);
961 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetRowAttr);
962 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetColAttr);
969 // The python-aware version get's SWIGified
970 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
973 wxPyGridCellAttrProvider();
974 void _setCallbackInfo(PyObject* self, PyObject* _class);
975 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellAttrProvider)"
977 wxGridCellAttr *base_GetAttr(int row, int col,
978 wxGridCellAttr::wxAttrKind kind);
979 void base_SetAttr(wxGridCellAttr *attr, int row, int col);
980 void base_SetRowAttr(wxGridCellAttr *attr, int row);
981 void base_SetColAttr(wxGridCellAttr *attr, int col);
985 //---------------------------------------------------------------------------
986 // Grid Table Base class and Python aware version
990 class wxGridTableBase : public wxObject
993 // wxGridTableBase(); This is an ABC
994 //~wxGridTableBase();
996 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
997 wxGridCellAttrProvider *GetAttrProvider() const;
998 void SetView( wxGrid *grid );
999 wxGrid * GetView() const;
1003 virtual int GetNumberRows() = 0;
1004 virtual int GetNumberCols() = 0;
1005 virtual bool IsEmptyCell( int row, int col ) = 0;
1006 virtual wxString GetValue( int row, int col ) = 0;
1007 virtual void SetValue( int row, int col, const wxString& value ) = 0;
1009 // virtuals overridable in wxPyGridTableBase
1010 virtual wxString GetTypeName( int row, int col );
1011 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
1012 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
1013 virtual long GetValueAsLong( int row, int col );
1014 virtual double GetValueAsDouble( int row, int col );
1015 virtual bool GetValueAsBool( int row, int col );
1016 virtual void SetValueAsLong( int row, int col, long value );
1017 virtual void SetValueAsDouble( int row, int col, double value );
1018 virtual void SetValueAsBool( int row, int col, bool value );
1020 //virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
1021 //virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
1024 virtual void Clear();
1025 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
1026 virtual bool AppendRows( size_t numRows = 1 );
1027 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
1028 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
1029 virtual bool AppendCols( size_t numCols = 1 );
1030 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
1032 virtual wxString GetRowLabelValue( int row );
1033 virtual wxString GetColLabelValue( int col );
1034 virtual void SetRowLabelValue( int row, const wxString& value );
1035 virtual void SetColLabelValue( int col, const wxString& value );
1037 virtual bool CanHaveAttributes();
1039 virtual wxGridCellAttr *GetAttr( int row, int col,
1040 wxGridCellAttr::wxAttrKind kind);
1041 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
1042 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
1043 virtual void SetColAttr(wxGridCellAttr *attr, int col);
1049 // Python-aware version
1051 class wxPyGridTableBase : public wxGridTableBase
1054 wxPyGridTableBase() : wxGridTableBase() {}
1056 PYCALLBACK_INT__pure(GetNumberRows);
1057 PYCALLBACK_INT__pure(GetNumberCols);
1058 PYCALLBACK_BOOL_INTINT_pure(IsEmptyCell);
1059 PYCALLBACK_STRING_INTINT(wxGridTableBase, GetTypeName);
1060 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanGetValueAs);
1061 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanSetValueAs);
1062 PYCALLBACK__(wxGridTableBase, Clear);
1063 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertRows);
1064 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteRows);
1065 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertCols);
1066 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteCols);
1067 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendRows);
1068 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendCols);
1069 PYCALLBACK_STRING_INT(wxGridTableBase, GetRowLabelValue);
1070 PYCALLBACK_STRING_INT(wxGridTableBase, GetColLabelValue);
1071 PYCALLBACK__INTSTRING(wxGridTableBase, SetRowLabelValue);
1072 PYCALLBACK__INTSTRING(wxGridTableBase, SetColLabelValue);
1073 PYCALLBACK_BOOL_(wxGridTableBase, CanHaveAttributes);
1074 PYCALLBACK_GCA_INTINTKIND(wxGridTableBase, GetAttr);
1075 PYCALLBACK__GCAINTINT(wxGridTableBase, SetAttr);
1076 PYCALLBACK__GCAINT(wxGridTableBase, SetRowAttr);
1077 PYCALLBACK__GCAINT(wxGridTableBase, SetColAttr);
1080 wxString GetValue(int row, int col) {
1081 wxPyBeginBlockThreads();
1083 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1085 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",row,col));
1087 rval = Py2wxString(ro);
1091 wxPyEndBlockThreads();
1095 void SetValue(int row, int col, const wxString& val) {
1096 wxPyBeginBlockThreads();
1097 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1098 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",row,col,wx2PyString(val)));
1100 wxPyEndBlockThreads();
1104 // Map the Get/Set methods for the standard non-string types to
1105 // the GetValue and SetValue python methods.
1106 long GetValueAsLong( int row, int col ) {
1108 wxPyBeginBlockThreads();
1109 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1112 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1113 if (ro && PyNumber_Check(ro)) {
1114 num = PyNumber_Int(ro);
1116 rval = PyInt_AsLong(num);
1122 wxPyEndBlockThreads();
1126 double GetValueAsDouble( int row, int col ) {
1128 wxPyBeginBlockThreads();
1129 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1132 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1133 if (ro && PyNumber_Check(ro)) {
1134 num = PyNumber_Float(ro);
1136 rval = PyFloat_AsDouble(num);
1142 wxPyEndBlockThreads();
1146 bool GetValueAsBool( int row, int col ) {
1147 return (bool)GetValueAsLong(row, col);
1150 void SetValueAsLong( int row, int col, long value ) {
1151 wxPyBeginBlockThreads();
1152 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1153 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", row, col, value));
1155 wxPyEndBlockThreads();
1158 void SetValueAsDouble( int row, int col, double value ) {
1159 wxPyBeginBlockThreads();
1160 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1161 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iid)", row, col, value));
1163 wxPyEndBlockThreads();
1166 void SetValueAsBool( int row, int col, bool value ) {
1167 SetValueAsLong( row, col, (long)value );
1176 // The python-aware version get's SWIGified
1177 class wxPyGridTableBase : public wxGridTableBase
1180 wxPyGridTableBase();
1181 void _setCallbackInfo(PyObject* self, PyObject* _class);
1182 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridTableBase)"
1184 %addmethods { void Destroy() { delete self; } }
1186 wxString base_GetTypeName( int row, int col );
1187 bool base_CanGetValueAs( int row, int col, const wxString& typeName );
1188 bool base_CanSetValueAs( int row, int col, const wxString& typeName );
1190 bool base_InsertRows( size_t pos = 0, size_t numRows = 1 );
1191 bool base_AppendRows( size_t numRows = 1 );
1192 bool base_DeleteRows( size_t pos = 0, size_t numRows = 1 );
1193 bool base_InsertCols( size_t pos = 0, size_t numCols = 1 );
1194 bool base_AppendCols( size_t numCols = 1 );
1195 bool base_DeleteCols( size_t pos = 0, size_t numCols = 1 );
1196 wxString base_GetRowLabelValue( int row );
1197 wxString base_GetColLabelValue( int col );
1198 void base_SetRowLabelValue( int row, const wxString& value );
1199 void base_SetColLabelValue( int col, const wxString& value );
1200 bool base_CanHaveAttributes();
1201 wxGridCellAttr *base_GetAttr( int row, int col,
1202 wxGridCellAttr::wxAttrKind kind );
1203 void base_SetAttr(wxGridCellAttr* attr, int row, int col);
1204 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1205 void base_SetColAttr(wxGridCellAttr *attr, int col);
1209 //---------------------------------------------------------------------------
1210 // Predefined Tables
1212 class wxGridStringTable : public wxGridTableBase
1215 wxGridStringTable( int numRows=0, int numCols=0 );
1218 //---------------------------------------------------------------------------
1219 // The Table can pass messages to the grid to tell it to update itself if
1220 // something has changed.
1222 enum wxGridTableRequest
1224 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
1225 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
1226 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
1227 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
1228 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
1229 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1230 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
1231 wxGRIDTABLE_NOTIFY_COLS_DELETED
1235 class wxGridTableMessage
1238 wxGridTableMessage( wxGridTableBase *table, int id,
1241 ~wxGridTableMessage();
1243 void SetTableObject( wxGridTableBase *table );
1244 wxGridTableBase * GetTableObject() const;
1245 void SetId( int id );
1247 void SetCommandInt( int comInt1 );
1248 int GetCommandInt();
1249 void SetCommandInt2( int comInt2 );
1250 int GetCommandInt2();
1254 //---------------------------------------------------------------------------
1256 class wxGridCellCoords
1259 wxGridCellCoords( int r=-1, int c=-1 );
1260 ~wxGridCellCoords();
1262 int GetRow() const { return m_row; }
1263 void SetRow( int n ) { m_row = n; }
1264 int GetCol() const { return m_col; }
1265 void SetCol( int n ) { m_col = n; }
1266 void Set( int row, int col ) { m_row = row; m_col = col; }
1269 PyObject* asTuple() {
1270 PyObject* tup = PyTuple_New(2);
1271 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
1272 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
1276 int __cmp__( const wxGridCellCoords& other ) {
1277 return *self != other;
1280 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
1281 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
1284 // Typemap to allow conversion of sequence objects to wxGridCellCoords...
1285 %typemap(python,in) wxGridCellCoords& (wxGridCellCoords temp) {
1287 if (! wxGridCellCoords_helper($source, &$target))
1291 // ...and here is the associated helper.
1293 bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) {
1295 // If source is an object instance then it may already be the right type
1296 if (PyInstance_Check(source)) {
1297 wxGridCellCoords* ptr;
1298 if (SWIG_GetPtrObj(source, (void **)&ptr, "_wxGridCellCoords_p"))
1303 // otherwise a 2-tuple of integers is expected
1304 else if (PySequence_Check(source) && PyObject_Length(source) == 2) {
1305 PyObject* o1 = PySequence_GetItem(source, 0);
1306 PyObject* o2 = PySequence_GetItem(source, 1);
1307 **obj = wxGridCellCoords(PyInt_AsLong(o1), PyInt_AsLong(o2));
1312 PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of integers or a wxGridCellCoords object.");
1317 //---------------------------------------------------------------------------
1318 //---------------------------------------------------------------------------
1322 // Fool SWIG into treating this enum as an int
1323 typedef int WXGRIDSELECTIONMODES;
1325 // but let the C++ code know what it really is.
1327 typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES;
1332 class wxGrid : public wxScrolledWindow
1335 wxGrid( wxWindow *parent,
1337 const wxPoint& pos = wxDefaultPosition,
1338 const wxSize& size = wxDefaultSize,
1339 long style = wxWANTS_CHARS,
1340 const wxString& name = wxPyPanelNameStr);
1342 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1344 enum wxGridSelectionModes {wxGridSelectCells,
1346 wxGridSelectColumns};
1348 bool CreateGrid( int numRows, int numCols,
1349 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1350 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1353 // ------ grid dimensions
1355 int GetNumberRows();
1356 int GetNumberCols();
1359 bool ProcessTableMessage( wxGridTableMessage& );
1362 wxGridTableBase * GetTable() const;
1363 bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE,
1364 WXGRIDSELECTIONMODES selmode =
1365 wxGrid::wxGridSelectCells );
1368 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1369 bool AppendRows( int numRows = 1, bool updateLabels=TRUE );
1370 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1371 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1372 bool AppendCols( int numCols = 1, bool updateLabels=TRUE );
1373 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1376 // this function is called when the current cell highlight must be redrawn
1377 // and may be overridden by the user
1378 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1381 // ------ Cell text drawing functions
1383 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1384 int horizontalAlignment = wxLEFT,
1385 int verticalAlignment = wxTOP );
1387 // // Split a string containing newline chararcters into an array of
1388 // // strings and return the number of lines
1390 // void StringToLines( const wxString& value, wxArrayString& lines );
1392 void GetTextBoxSize( wxDC& dc,
1393 wxArrayString& lines,
1394 long *OUTPUT, long *OUTPUT );
1398 // Code that does a lot of grid modification can be enclosed
1399 // between BeginBatch() and EndBatch() calls to avoid screen
1404 int GetBatchCount();
1405 void ForceRefresh();
1408 // ------ edit control functions
1410 bool IsEditable() { return m_editable; }
1411 void EnableEditing( bool edit );
1413 void EnableCellEditControl( bool enable = TRUE );
1414 void DisableCellEditControl();
1415 bool CanEnableCellControl() const;
1416 bool IsCellEditControlEnabled() const;
1417 bool IsCellEditControlShown() const;
1419 bool IsCurrentCellReadOnly() const;
1421 void ShowCellEditControl();
1422 void HideCellEditControl();
1423 void SaveEditControlValue();
1426 // ------ grid location functions
1427 // Note that all of these functions work with the logical coordinates of
1428 // grid cells and labels so you will need to convert from device
1429 // coordinates for mouse events etc.
1432 //void XYToCell( int x, int y, wxGridCellCoords& );
1434 %new wxGridCellCoords* XYToCell(int x, int y) {
1435 wxGridCellCoords rv;
1436 self->XYToCell(x, y, rv);
1437 return new wxGridCellCoords(rv);
1441 int YToRow( int y );
1442 int XToCol( int x );
1444 int YToEdgeOfRow( int y );
1445 int XToEdgeOfCol( int x );
1447 wxRect CellToRect( int row, int col );
1448 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1451 int GetGridCursorRow();
1452 int GetGridCursorCol();
1454 // check to see if a cell is either wholly visible (the default arg) or
1455 // at least partially visible in the grid window
1457 bool IsVisible( int row, int col, bool wholeCellVisible = TRUE );
1458 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE );
1459 void MakeCellVisible( int row, int col );
1460 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1463 // ------ grid cursor movement functions
1465 void SetGridCursor( int row, int col );
1466 bool MoveCursorUp( bool expandSelection );
1467 bool MoveCursorDown( bool expandSelection );
1468 bool MoveCursorLeft( bool expandSelection );
1469 bool MoveCursorRight( bool expandSelection );
1470 bool MovePageDown();
1472 bool MoveCursorUpBlock( bool expandSelection );
1473 bool MoveCursorDownBlock( bool expandSelection );
1474 bool MoveCursorLeftBlock( bool expandSelection );
1475 bool MoveCursorRightBlock( bool expandSelection );
1478 // ------ label and gridline formatting
1480 int GetDefaultRowLabelSize();
1481 int GetRowLabelSize();
1482 int GetDefaultColLabelSize();
1483 int GetColLabelSize();
1484 wxColour GetLabelBackgroundColour();
1485 wxColour GetLabelTextColour();
1486 wxFont GetLabelFont();
1487 void GetRowLabelAlignment( int *OUTPUT, int *OUTPUT );
1488 void GetColLabelAlignment( int *OUTPUT, int *OUTPUT );
1489 wxString GetRowLabelValue( int row );
1490 wxString GetColLabelValue( int col );
1491 wxColour GetGridLineColour();
1492 wxColour GetCellHighlightColour();
1493 int GetCellHighlightPenWidth();
1494 int GetCellHighlightROPenWidth();
1496 void SetRowLabelSize( int width );
1497 void SetColLabelSize( int height );
1498 void SetLabelBackgroundColour( const wxColour& );
1499 void SetLabelTextColour( const wxColour& );
1500 void SetLabelFont( const wxFont& );
1501 void SetRowLabelAlignment( int horiz, int vert );
1502 void SetColLabelAlignment( int horiz, int vert );
1503 void SetRowLabelValue( int row, const wxString& );
1504 void SetColLabelValue( int col, const wxString& );
1505 void SetGridLineColour( const wxColour& );
1506 void SetCellHighlightColour( const wxColour& );
1507 void SetCellHighlightPenWidth(int width);
1508 void SetCellHighlightROPenWidth(int width);
1510 void EnableDragRowSize( bool enable = TRUE );
1511 void DisableDragRowSize();
1512 bool CanDragRowSize();
1513 void EnableDragColSize( bool enable = TRUE );
1514 void DisableDragColSize();
1515 bool CanDragColSize();
1516 void EnableDragGridSize(bool enable = TRUE);
1517 void DisableDragGridSize();
1518 bool CanDragGridSize();
1520 // this sets the specified attribute for all cells in this row/col
1521 void SetRowAttr(int row, wxGridCellAttr *attr);
1522 void SetColAttr(int col, wxGridCellAttr *attr);
1524 // shortcuts for setting the column parameters
1526 // set the format for the data in the column: default is string
1527 void SetColFormatBool(int col);
1528 void SetColFormatNumber(int col);
1529 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1530 void SetColFormatCustom(int col, const wxString& typeName);
1532 void EnableGridLines( bool enable = TRUE );
1533 bool GridLinesEnabled();
1535 // ------ row and col formatting
1537 int GetDefaultRowSize();
1538 int GetRowSize( int row );
1539 int GetDefaultColSize();
1540 int GetColSize( int col );
1541 wxColour GetDefaultCellBackgroundColour();
1542 wxColour GetCellBackgroundColour( int row, int col );
1543 wxColour GetDefaultCellTextColour();
1544 wxColour GetCellTextColour( int row, int col );
1545 wxFont GetDefaultCellFont();
1546 wxFont GetCellFont( int row, int col );
1547 void GetDefaultCellAlignment( int *horiz, int *vert );
1548 void GetCellAlignment( int row, int col, int *horiz, int *vert );
1550 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
1551 void SetRowSize( int row, int height );
1552 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
1554 void SetColSize( int col, int width );
1556 // automatically size the column or row to fit to its contents, if
1557 // setAsMin is TRUE, this optimal width will also be set as minimal width
1559 void AutoSizeColumn( int col, bool setAsMin = TRUE );
1560 void AutoSizeRow( int row, bool setAsMin = TRUE );
1563 // auto size all columns (very ineffective for big grids!)
1564 void AutoSizeColumns( bool setAsMin = TRUE );
1565 void AutoSizeRows( bool setAsMin = TRUE );
1567 // auto size the grid, that is make the columns/rows of the "right" size
1568 // and also set the grid size to just fit its contents
1571 // column won't be resized to be lesser width - this must be called during
1572 // the grid creation because it won't resize the column if it's already
1573 // narrower than the minimal width
1574 void SetColMinimalWidth( int col, int width );
1575 void SetRowMinimalHeight( int row, int width );
1577 void SetDefaultCellBackgroundColour( const wxColour& );
1578 void SetCellBackgroundColour( int row, int col, const wxColour& );
1579 void SetDefaultCellTextColour( const wxColour& );
1581 void SetCellTextColour( int row, int col, const wxColour& );
1582 void SetDefaultCellFont( const wxFont& );
1583 void SetCellFont( int row, int col, const wxFont& );
1584 void SetDefaultCellAlignment( int horiz, int vert );
1585 void SetCellAlignment( int row, int col, int horiz, int vert );
1587 // takes ownership of the pointer
1588 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1589 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1590 wxGridCellRenderer *GetDefaultRenderer() const;
1591 wxGridCellRenderer* GetCellRenderer(int row, int col);
1593 // takes ownership of the pointer
1594 void SetDefaultEditor(wxGridCellEditor *editor);
1595 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1596 wxGridCellEditor *GetDefaultEditor() const;
1597 wxGridCellEditor* GetCellEditor(int row, int col);
1601 // ------ cell value accessors
1603 wxString GetCellValue( int row, int col );
1604 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1606 void SetCellValue( int row, int col, const wxString& s );
1607 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1609 // returns TRUE if the cell can't be edited
1610 bool IsReadOnly(int row, int col) const;
1612 // make the cell editable/readonly
1613 void SetReadOnly(int row, int col, bool isReadOnly = TRUE);
1615 // ------ selections of blocks of cells
1617 void SelectRow( int row, bool addToSelected = FALSE );
1618 void SelectCol( int col, bool addToSelected = FALSE );
1620 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1621 bool addToSelected = FALSE );
1622 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1623 // TODO: ??? const wxGridCellCoords& bottomRight )
1627 void ClearSelection();
1628 bool IsInSelection( int row, int col );
1629 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1632 // This function returns the rectangle that encloses the block of cells
1633 // limited by TopLeft and BottomRight cell in device coords and clipped
1634 // to the client size of the grid window.
1636 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1637 const wxGridCellCoords & bottomRight );
1640 // Access or update the selection fore/back colours
1641 wxColour GetSelectionBackground() const;
1642 wxColour GetSelectionForeground() const;
1644 void SetSelectionBackground(const wxColour& c);
1645 void SetSelectionForeground(const wxColour& c);
1648 // Methods for a registry for mapping data types to Renderers/Editors
1649 void RegisterDataType(const wxString& typeName,
1650 wxGridCellRenderer* renderer,
1651 wxGridCellEditor* editor);
1652 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1653 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1654 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1655 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1656 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1658 // grid may occupy more space than needed for its rows/columns, this
1659 // function allows to set how big this extra space is
1660 void SetMargins(int extraWidth, int extraHeight);
1663 // Accessors for component windows
1664 wxWindow* GetGridWindow();
1665 wxWindow* GetGridRowLabelWindow();
1666 wxWindow* GetGridColLabelWindow();
1667 wxWindow* GetGridCornerLabelWindow();
1673 //---------------------------------------------------------------------------
1674 //---------------------------------------------------------------------------
1675 // Grid events and stuff
1679 class wxGridEvent : public wxNotifyEvent
1682 wxGridEvent(int id, wxEventType type, wxGrid* obj,
1683 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = TRUE,
1684 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1686 virtual int GetRow();
1687 virtual int GetCol();
1688 wxPoint GetPosition();
1698 class wxGridSizeEvent : public wxNotifyEvent
1701 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
1702 int rowOrCol=-1, int x=-1, int y=-1,
1703 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1706 wxPoint GetPosition();
1715 class wxGridRangeSelectEvent : public wxNotifyEvent
1718 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
1719 const wxGridCellCoords& topLeft,
1720 const wxGridCellCoords& bottomRight,
1722 bool control=FALSE, bool shift=FALSE,
1723 bool alt=FALSE, bool meta=FALSE);
1725 wxGridCellCoords GetTopLeftCoords();
1726 wxGridCellCoords GetBottomRightCoords();
1739 class wxGridEditorCreatedEvent : public wxCommandEvent {
1741 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
1742 int row, int col, wxControl* ctrl);
1746 wxControl* GetControl();
1747 void SetRow(int row);
1748 void SetCol(int col);
1749 void SetControl(wxControl* ctrl);
1755 wxEVT_GRID_CELL_LEFT_CLICK,
1756 wxEVT_GRID_CELL_RIGHT_CLICK,
1757 wxEVT_GRID_CELL_LEFT_DCLICK,
1758 wxEVT_GRID_CELL_RIGHT_DCLICK,
1759 wxEVT_GRID_LABEL_LEFT_CLICK,
1760 wxEVT_GRID_LABEL_RIGHT_CLICK,
1761 wxEVT_GRID_LABEL_LEFT_DCLICK,
1762 wxEVT_GRID_LABEL_RIGHT_DCLICK,
1763 wxEVT_GRID_ROW_SIZE,
1764 wxEVT_GRID_COL_SIZE,
1765 wxEVT_GRID_RANGE_SELECT,
1766 wxEVT_GRID_CELL_CHANGE,
1767 wxEVT_GRID_SELECT_CELL,
1768 wxEVT_GRID_EDITOR_SHOWN,
1769 wxEVT_GRID_EDITOR_HIDDEN,
1770 wxEVT_GRID_EDITOR_CREATED,
1775 %pragma(python) code = "
1776 def EVT_GRID_CELL_LEFT_CLICK(win, fn):
1777 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_CLICK, fn)
1779 def EVT_GRID_CELL_RIGHT_CLICK(win, fn):
1780 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_CLICK, fn)
1782 def EVT_GRID_CELL_LEFT_DCLICK(win, fn):
1783 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_DCLICK, fn)
1785 def EVT_GRID_CELL_RIGHT_DCLICK(win, fn):
1786 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_DCLICK, fn)
1788 def EVT_GRID_LABEL_LEFT_CLICK(win, fn):
1789 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_CLICK, fn)
1791 def EVT_GRID_LABEL_RIGHT_CLICK(win, fn):
1792 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_CLICK, fn)
1794 def EVT_GRID_LABEL_LEFT_DCLICK(win, fn):
1795 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_DCLICK, fn)
1797 def EVT_GRID_LABEL_RIGHT_DCLICK(win, fn):
1798 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_DCLICK, fn)
1800 def EVT_GRID_ROW_SIZE(win, fn):
1801 win.Connect(-1, -1, wxEVT_GRID_ROW_SIZE, fn)
1803 def EVT_GRID_COL_SIZE(win, fn):
1804 win.Connect(-1, -1, wxEVT_GRID_COL_SIZE, fn)
1806 def EVT_GRID_RANGE_SELECT(win, fn):
1807 win.Connect(-1, -1, wxEVT_GRID_RANGE_SELECT, fn)
1809 def EVT_GRID_CELL_CHANGE(win, fn):
1810 win.Connect(-1, -1, wxEVT_GRID_CELL_CHANGE, fn)
1812 def EVT_GRID_SELECT_CELL(win, fn):
1813 win.Connect(-1, -1, wxEVT_GRID_SELECT_CELL, fn)
1815 def EVT_GRID_EDITOR_SHOWN(win, fn):
1816 win.Connect(-1, -1, wxEVT_GRID_EDITOR_SHOWN, fn)
1818 def EVT_GRID_EDITOR_HIDDEN(win, fn):
1819 win.Connect(-1, -1, wxEVT_GRID_EDITOR_HIDDEN, fn)
1821 def EVT_GRID_EDITOR_CREATED(win, fn):
1822 win.Connect(-1, -1, wxEVT_GRID_EDITOR_CREATED, fn)
1826 //---------------------------------------------------------------------------
1829 wxClassInfo::CleanUpClasses();
1830 wxClassInfo::InitializeClasses();
1833 //---------------------------------------------------------------------------
1835 %pragma(python) include="_gridextras.py";
1837 //---------------------------------------------------------------------------