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 /////////////////////////////////////////////////////////////////////////////
22 //----------------------------------------------------------------------
25 %include my_typemaps.i
27 // Import some definitions of other classes, etc.
35 %pragma(python) code = "import wx"
37 //---------------------------------------------------------------------------
38 //---------------------------------------------------------------------------
39 // Macros, similar to what's in helpers.h, to aid in the creation of
40 // virtual methods that are able to make callbacks to Python. Many of these
41 // are specific to wxGrid and so are kept here to reduce the mess in helpers.h
46 #define PYCALLBACK_GCA_INTINT(PCLASS, CBNAME) \
47 wxGridCellAttr* CBNAME(int a, int b) { \
48 wxGridCellAttr* rval = NULL; \
49 bool doSave = wxPyRestoreThread(); \
50 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
52 wxGridCellAttr* ptr; \
53 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", a, b)); \
55 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellAttr_p")) \
61 rval = PCLASS::CBNAME(a, b); \
62 wxPySaveThread(doSave); \
65 wxGridCellAttr *base_##CBNAME(int a, int b) { \
66 return PCLASS::CBNAME(a, b); \
71 #define PYCALLBACK__GCAINTINT(PCLASS, CBNAME) \
72 void CBNAME(wxGridCellAttr *attr, int a, int b) { \
73 bool doSave = wxPyRestoreThread(); \
74 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
75 PyObject* obj = wxPyConstructObject((void*)attr, "wxGridCellAttr", 0);\
76 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oii)", obj, a, b)); \
80 PCLASS::CBNAME(attr, a, b); \
81 wxPySaveThread(doSave); \
83 void base_##CBNAME(wxGridCellAttr *attr, int a, int b) { \
84 PCLASS::CBNAME(attr, a, b); \
89 #define PYCALLBACK__GCAINT(PCLASS, CBNAME) \
90 void CBNAME(wxGridCellAttr *attr, int val) { \
91 bool doSave = wxPyRestoreThread(); \
92 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
93 PyObject* obj = wxPyConstructObject((void*)attr, "wxGridCellAttr", 0);\
94 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, val)); \
98 PCLASS::CBNAME(attr, val); \
99 wxPySaveThread(doSave); \
101 void base_##CBNAME(wxGridCellAttr *attr, int val) { \
102 PCLASS::CBNAME(attr, val); \
107 #define PYCALLBACK_INT__pure(CBNAME) \
109 bool doSave = wxPyRestoreThread(); \
111 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
112 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
113 wxPySaveThread(doSave); \
119 #define PYCALLBACK_BOOL_INTINT_pure(CBNAME) \
120 bool CBNAME(int a, int b) { \
121 bool doSave = wxPyRestoreThread(); \
123 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
124 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
125 wxPySaveThread(doSave); \
131 #define PYCALLBACK_STRING_INTINT_pure(CBNAME) \
132 wxString CBNAME(int a, int b) { \
133 bool doSave = wxPyRestoreThread(); \
135 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
137 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
139 PyObject* str = PyObject_Str(ro); \
140 rval = PyString_AsString(str); \
141 Py_DECREF(ro); Py_DECREF(str); \
144 wxPySaveThread(doSave); \
150 #define PYCALLBACK__INTINTSTRING_pure(CBNAME) \
151 void CBNAME(int a, int b, const wxString& c) { \
152 bool doSave = wxPyRestoreThread(); \
153 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
154 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iis)",a,b,c.c_str())); \
155 wxPySaveThread(doSave); \
159 #define PYCALLBACK_STRING_INTINT(PCLASS, CBNAME) \
160 wxString CBNAME(int a, int b) { \
161 bool doSave = wxPyRestoreThread(); \
163 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
165 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
167 PyObject* str = PyObject_Str(ro); \
168 rval = PyString_AsString(str); \
169 Py_DECREF(ro); Py_DECREF(str); \
172 rval = PCLASS::CBNAME(a, b); \
173 wxPySaveThread(doSave); \
176 wxString base_##CBNAME(int a, int b) { \
177 return PCLASS::CBNAME(a, b); \
182 #define PYCALLBACK_BOOL_INTINTSTRING(PCLASS, CBNAME) \
183 bool CBNAME(int a, int b, const wxString& c) { \
185 bool doSave = wxPyRestoreThread(); \
186 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
187 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iis)", a,b,c.c_str())); \
189 rval = PCLASS::CBNAME(a,b,c); \
190 wxPySaveThread(doSave); \
193 bool base_##CBNAME(int a, int b, const wxString& c) { \
194 return PCLASS::CBNAME(a,b,c); \
200 #define PYCALLBACK_LONG_INTINT(PCLASS, CBNAME) \
201 long CBNAME(int a, int b) { \
203 bool doSave = wxPyRestoreThread(); \
204 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
205 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
207 rval = PCLASS::CBNAME(a,b); \
208 wxPySaveThread(doSave); \
211 long base_##CBNAME(int a, int b) { \
212 return PCLASS::CBNAME(a,b); \
217 #define PYCALLBACK_BOOL_INTINT(PCLASS, CBNAME) \
218 bool CBNAME(int a, int b) { \
220 bool doSave = wxPyRestoreThread(); \
221 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
222 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
224 rval = PCLASS::CBNAME(a,b); \
225 wxPySaveThread(doSave); \
228 bool base_##CBNAME(int a, int b) { \
229 return PCLASS::CBNAME(a,b); \
234 #define PYCALLBACK_DOUBLE_INTINT(PCLASS, CBNAME) \
235 double CBNAME(int a, int b) { \
236 bool doSave = wxPyRestoreThread(); \
238 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
240 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
242 PyObject* str = PyObject_Str(ro); \
243 rval = PyFloat_AsDouble(str); \
244 Py_DECREF(ro); Py_DECREF(str); \
247 rval = PCLASS::CBNAME(a, b); \
248 wxPySaveThread(doSave); \
251 double base_##CBNAME(int a, int b) { \
252 return PCLASS::CBNAME(a, b); \
257 #define PYCALLBACK__(PCLASS, CBNAME) \
259 bool doSave = wxPyRestoreThread(); \
260 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
261 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
264 wxPySaveThread(doSave); \
266 void base_##CBNAME() { \
273 #define PYCALLBACK_BOOL_SIZETSIZET(PCLASS, CBNAME) \
274 bool CBNAME(size_t a, size_t b) { \
276 bool doSave = wxPyRestoreThread(); \
277 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
278 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
280 rval = PCLASS::CBNAME(a,b); \
281 wxPySaveThread(doSave); \
284 bool base_##CBNAME(size_t a, size_t b) { \
285 return PCLASS::CBNAME(a,b); \
290 #define PYCALLBACK_BOOL_SIZET(PCLASS, CBNAME) \
291 bool CBNAME(size_t a) { \
293 bool doSave = wxPyRestoreThread(); \
294 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
295 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)", a)); \
297 rval = PCLASS::CBNAME(a); \
298 wxPySaveThread(doSave); \
301 bool base_##CBNAME(size_t a) { \
302 return PCLASS::CBNAME(a); \
307 #define PYCALLBACK_STRING_INT(PCLASS, CBNAME) \
308 wxString CBNAME(int a) { \
309 bool doSave = wxPyRestoreThread(); \
311 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
313 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(i)",a)); \
315 PyObject* str = PyObject_Str(ro); \
316 rval = PyString_AsString(str); \
317 Py_DECREF(ro); Py_DECREF(str); \
320 rval = PCLASS::CBNAME(a); \
321 wxPySaveThread(doSave); \
324 wxString base_##CBNAME(int a) { \
325 return PCLASS::CBNAME(a); \
330 #define PYCALLBACK__INTSTRING(PCLASS, CBNAME) \
331 void CBNAME(int a, const wxString& c) { \
332 bool doSave = wxPyRestoreThread(); \
333 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
334 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(is)", a,c.c_str())); \
336 PCLASS::CBNAME(a,c); \
337 wxPySaveThread(doSave); \
339 void base_##CBNAME(int a, const wxString& c) { \
340 PCLASS::CBNAME(a,c); \
346 #define PYCALLBACK_BOOL_(PCLASS, CBNAME) \
349 bool doSave = wxPyRestoreThread(); \
350 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
351 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
353 rval = PCLASS::CBNAME(); \
354 wxPySaveThread(doSave); \
357 bool base_##CBNAME() { \
358 return PCLASS::CBNAME(); \
363 #define PYCALLBACK__SIZETINT(PCLASS, CBNAME) \
364 void CBNAME(size_t a, int b) { \
365 bool doSave = wxPyRestoreThread(); \
366 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
367 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
369 PCLASS::CBNAME(a,b); \
370 wxPySaveThread(doSave); \
372 void base_##CBNAME(size_t a, int b) { \
373 PCLASS::CBNAME(a,b); \
379 #define PYCALLBACK__INTINTLONG(PCLASS, CBNAME) \
380 void CBNAME(int a, int b, long c) { \
381 bool doSave = wxPyRestoreThread(); \
382 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
383 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
385 PCLASS::CBNAME(a,b,c); \
386 wxPySaveThread(doSave); \
388 void base_##CBNAME(int a, int b, long c) { \
389 PCLASS::CBNAME(a,b,c); \
395 #define PYCALLBACK__INTINTDOUBLE(PCLASS, CBNAME) \
396 void CBNAME(int a, int b, double c) { \
397 bool doSave = wxPyRestoreThread(); \
398 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
399 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iif)", a,b,c)); \
401 PCLASS::CBNAME(a,b,c); \
402 wxPySaveThread(doSave); \
404 void base_##CBNAME(int a, int b, double c) { \
405 PCLASS::CBNAME(a,b,c); \
410 #define PYCALLBACK__INTINTBOOL(PCLASS, CBNAME) \
411 void CBNAME(int a, int b, bool c) { \
412 bool doSave = wxPyRestoreThread(); \
413 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
414 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
416 PCLASS::CBNAME(a,b,c); \
417 wxPySaveThread(doSave); \
419 void base_##CBNAME(int a, int b, bool c) { \
420 PCLASS::CBNAME(a,b,c); \
428 //---------------------------------------------------------------------------
430 class wxGridCellCoords;
431 class wxGridCellAttr;
435 #define wxGRID_VALUE_STRING "string"
436 #define wxGRID_VALUE_BOOL "bool"
437 #define wxGRID_VALUE_NUMBER "long"
438 #define wxGRID_VALUE_FLOAT "double"
439 #define wxGRID_VALUE_CHOICE "choice"
440 #define wxGRID_VALUE_TEXT "string"
441 #define wxGRID_VALUE_LONG "long"
444 wxGridCellCoords wxGridNoCellCoords;
445 wxRect wxGridNoCellRect;
449 //---------------------------------------------------------------------------
450 // wxGridCellRenderer is an ABC, and several derived classes are available.
451 // Classes implemented in Python should be derived from wxPyGridCellRenderer.
454 class wxGridCellRenderer
457 void SetParameters(const wxString& params);
461 virtual void Draw(wxGrid& grid,
462 wxGridCellAttr& attr,
466 bool isSelected) = 0;
467 virtual wxSize GetBestSize(wxGrid& grid,
468 wxGridCellAttr& attr,
470 int row, int col) = 0;
471 virtual wxGridCellRenderer *Clone() const = 0;
475 // The C++ version of wxPyGridCellRenderer
477 class wxPyGridCellRenderer : public wxGridCellRenderer
480 wxPyGridCellRenderer() : wxGridCellRenderer() {};
482 // Implement Python callback aware virtual methods
483 void Draw(wxGrid& grid, wxGridCellAttr& attr,
484 wxDC& dc, const wxRect& rect,
485 int row, int col, bool isSelected) {
486 bool doSave = wxPyRestoreThread();
487 if (wxPyCBH_findCallback(m_myInst, "Draw")) {
488 wxPyCBH_callCallback(m_myInst,
489 Py_BuildValue("(OOOOiii)",
490 wxPyConstructObject((void*)&grid, "wxGrid", 0),
491 wxPyConstructObject((void*)&attr, "wxGridCellAttr", 0),
492 wxPyConstructObject((void*)&dc, "wxDC", 0),
493 wxPyConstructObject((void*)&rect, "wxRect", 0),
494 row, col, isSelected));
496 wxPySaveThread(doSave);
499 wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
502 bool doSave = wxPyRestoreThread();
503 if (wxPyCBH_findCallback(m_myInst, "GetBestSize")) {
506 ro = wxPyCBH_callCallbackObj(m_myInst,
507 Py_BuildValue("(OOOii)",
508 wxPyConstructObject((void*)&grid, "wxGrid", 0),
509 wxPyConstructObject((void*)&attr, "wxGridCellAttr", 0),
510 wxPyConstructObject((void*)&dc, "wxDC", 0),
513 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p"))
518 wxPySaveThread(doSave);
523 wxGridCellRenderer *Clone() const {
524 wxGridCellRenderer* rval = NULL;
525 bool doSave = wxPyRestoreThread();
526 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
528 wxGridCellRenderer* ptr;
529 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
531 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellRenderer_p"))
536 wxPySaveThread(doSave);
540 DEC_PYCALLBACK__STRING(SetParameters);
545 IMP_PYCALLBACK__STRING( wxPyGridCellRenderer, wxGridCellRenderer, SetParameters);
550 // Let SWIG know about it so it can create the Python version
551 class wxPyGridCellRenderer : public wxGridCellRenderer {
553 wxPyGridCellRenderer();
554 void _setSelf(PyObject* self, PyObject* _class);
555 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyGridCellRenderer)"
557 void base_SetParameters(const wxString& params);
560 //---------------------------------------------------------------------------
561 // Predefined Renderers
563 class wxGridCellStringRenderer : public wxGridCellRenderer
566 wxGridCellStringRenderer();
570 class wxGridCellNumberRenderer : public wxGridCellStringRenderer
573 wxGridCellNumberRenderer();
577 class wxGridCellFloatRenderer : public wxGridCellStringRenderer
580 wxGridCellFloatRenderer(int width = -1, int precision = -1);
582 int GetWidth() const;
583 void SetWidth(int width);
584 int GetPrecision() const;
585 void SetPrecision(int precision);
589 class wxGridCellBoolRenderer : public wxGridCellRenderer
592 wxGridCellBoolRenderer();
597 //---------------------------------------------------------------------------
598 // wxGridCellEditor is an ABC, and several derived classes are available.
599 // Classes implemented in Python should be derived from wxPyGridCellEditor.
601 class wxGridCellEditor
605 wxControl* GetControl();
606 void SetControl(wxControl* control);
608 void SetParameters(const wxString& params);
612 virtual void Create(wxWindow* parent,
614 wxEvtHandler* evtHandler) = 0;
615 virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
616 virtual bool EndEdit(int row, int col, wxGrid* grid) = 0;
617 virtual void Reset() = 0;
618 virtual wxGridCellEditor *Clone() const = 0;
620 virtual void SetSize(const wxRect& rect);
621 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
622 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
623 virtual bool IsAcceptedKey(wxKeyEvent& event);
624 virtual void StartingKey(wxKeyEvent& event);
625 virtual void StartingClick();
626 virtual void HandleReturn(wxKeyEvent& event);
627 virtual void Destroy();
632 // The C++ version of wxPyGridCellEditor
634 class wxPyGridCellEditor : public wxGridCellEditor
637 wxPyGridCellEditor() : wxGridCellEditor() {}
639 void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) {
640 bool doSave = wxPyRestoreThread();
641 if (wxPyCBH_findCallback(m_myInst, "Create")) {
642 wxPyCBH_callCallback(m_myInst,
643 Py_BuildValue("(OiO)",
644 wxPyConstructObject((void*)parent, "wxWindow", 0),
646 wxPyConstructObject((void*)evtHandler, "wxEvtHandler", 0)));
648 wxPySaveThread(doSave);
652 void BeginEdit(int row, int col, wxGrid* grid) {
653 bool doSave = wxPyRestoreThread();
654 if (wxPyCBH_findCallback(m_myInst, "BeginEdit")) {
655 wxPyCBH_callCallback(m_myInst,
656 Py_BuildValue("(iiO)", row, col,
657 wxPyConstructObject((void*)grid, "wxGrid", 0)));
659 wxPySaveThread(doSave);
663 bool EndEdit(int row, int col, wxGrid* grid) {
665 bool doSave = wxPyRestoreThread();
666 if (wxPyCBH_findCallback(m_myInst, "EndEdit")) {
667 rv = wxPyCBH_callCallback(m_myInst,
668 Py_BuildValue("(iiO)", row, col,
669 wxPyConstructObject((void*)grid, "wxGrid", 0)));
671 wxPySaveThread(doSave);
676 wxGridCellEditor*Clone() const {
677 wxGridCellEditor* rval = NULL;
678 bool doSave = wxPyRestoreThread();
679 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
681 wxGridCellEditor* ptr;
682 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
684 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellEditor_p"))
689 wxPySaveThread(doSave);
694 void Show(bool show, wxGridCellAttr *attr) {
695 bool doSave = wxPyRestoreThread();
696 if (wxPyCBH_findCallback(m_myInst, "Show"))
697 wxPyCBH_callCallback(m_myInst,
698 Py_BuildValue("(iO)", show,
699 wxPyConstructObject((void*)attr, "wxGridCellAttr", 0)));
701 wxGridCellEditor::Show(show, attr);
702 wxPySaveThread(doSave);
704 void base_Show(bool show, wxGridCellAttr *attr) {
705 wxGridCellEditor::Show(show, attr);
709 void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
710 bool doSave = wxPyRestoreThread();
711 if (wxPyCBH_findCallback(m_myInst, "PaintBackground"))
712 wxPyCBH_callCallback(m_myInst,
713 Py_BuildValue("(OO)",
714 wxPyConstructObject((void*)&rectCell, "wxRect", 0),
715 wxPyConstructObject((void*)attr, "wxGridCellAttr", 0)));
717 wxGridCellEditor::PaintBackground(rectCell, attr);
718 wxPySaveThread(doSave);
720 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
721 wxGridCellEditor::PaintBackground(rectCell, attr);
725 DEC_PYCALLBACK___pure(Reset);
726 DEC_PYCALLBACK__constany(SetSize, wxRect);
727 DEC_PYCALLBACK_bool_any(IsAcceptedKey, wxKeyEvent);
728 DEC_PYCALLBACK__any(StartingKey, wxKeyEvent);
729 DEC_PYCALLBACK__any(HandleReturn, wxKeyEvent);
730 DEC_PYCALLBACK__(StartingClick);
731 DEC_PYCALLBACK__(Destroy);
732 DEC_PYCALLBACK__STRING(SetParameters);
738 IMP_PYCALLBACK__STRING( wxPyGridCellEditor, wxGridCellEditor, SetParameters);
739 IMP_PYCALLBACK___pure(wxPyGridCellEditor, wxGridCellEditor, Reset);
740 IMP_PYCALLBACK__constany(wxPyGridCellEditor, wxGridCellEditor, SetSize, wxRect);
741 IMP_PYCALLBACK_bool_any(wxPyGridCellEditor, wxGridCellEditor, IsAcceptedKey, wxKeyEvent);
742 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, StartingKey, wxKeyEvent);
743 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, HandleReturn, wxKeyEvent);
744 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, StartingClick);
745 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, Destroy);
750 // Let SWIG know about it so it can create the Python version
751 class wxPyGridCellEditor : public wxGridCellEditor {
753 wxPyGridCellEditor();
754 void _setSelf(PyObject* self, PyObject* _class);
755 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyGridCellEditor)"
757 void base_SetSize(const wxRect& rect);
758 void base_Show(bool show, wxGridCellAttr *attr = NULL);
759 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
760 void base_IsAcceptedKey(wxKeyEvent& event);
761 void base_StartingKey(wxKeyEvent& event);
762 void base_StartingClick();
763 void base_HandleReturn(wxKeyEvent& event);
765 void base_SetParameters(const wxString& params);
768 //---------------------------------------------------------------------------
769 // Predefined Editors
771 class wxGridCellTextEditor : public wxGridCellEditor
774 wxGridCellTextEditor();
778 class wxGridCellNumberEditor : public wxGridCellTextEditor
781 wxGridCellNumberEditor(int min = -1, int max = -1);
785 class wxGridCellFloatEditor : public wxGridCellTextEditor
788 wxGridCellFloatEditor();
792 class wxGridCellBoolEditor : public wxGridCellEditor
795 wxGridCellBoolEditor();
798 class wxGridCellChoiceEditor : public wxGridCellEditor
801 wxGridCellChoiceEditor(int LCOUNT = 0,
802 const wxString* choices = NULL,
803 bool allowOthers = FALSE);
806 //---------------------------------------------------------------------------
814 wxGridCellAttr *Clone() const;
817 void SetTextColour(const wxColour& colText);
818 void SetBackgroundColour(const wxColour& colBack);
819 void SetFont(const wxFont& font);
820 void SetAlignment(int hAlign, int vAlign);
821 void SetReadOnly(bool isReadOnly = TRUE);
823 void SetRenderer(wxGridCellRenderer *renderer);
824 void SetEditor(wxGridCellEditor* editor);
826 bool HasTextColour() const;
827 bool HasBackgroundColour() const;
828 bool HasFont() const;
829 bool HasAlignment() const;
830 bool HasRenderer() const;
831 bool HasEditor() const;
833 const wxColour& GetTextColour() const;
834 const wxColour& GetBackgroundColour() const;
835 const wxFont& GetFont() const;
836 void GetAlignment(int *OUTPUT, int *OUTPUT) const;
837 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
838 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
840 bool IsReadOnly() const;
841 void SetDefAttr(wxGridCellAttr* defAttr);
844 //---------------------------------------------------------------------------
846 class wxGridCellAttrProvider
849 wxGridCellAttrProvider();
850 // ???? virtual ~wxGridCellAttrProvider();
852 wxGridCellAttr *GetAttr(int row, int col) const;
853 void SetAttr(wxGridCellAttr *attr, int row, int col);
854 void SetRowAttr(wxGridCellAttr *attr, int row);
855 void SetColAttr(wxGridCellAttr *attr, int col);
857 void UpdateAttrRows( size_t pos, int numRows );
858 void UpdateAttrCols( size_t pos, int numCols );
863 // A Python-aware version
865 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
868 wxPyGridCellAttrProvider() : wxGridCellAttrProvider() {};
870 PYCALLBACK_GCA_INTINT(wxGridCellAttrProvider, GetAttr);
871 PYCALLBACK__GCAINTINT(wxGridCellAttrProvider, SetAttr);
872 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetRowAttr);
873 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetColAttr);
880 // The python-aware version get's SWIGified
881 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
884 wxPyGridCellAttrProvider();
885 void _setSelf(PyObject* self, PyObject* _class);
886 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyGridCellAttrProvider)"
888 wxGridCellAttr *base_GetAttr(int row, int col);
889 void base_SetAttr(wxGridCellAttr *attr, int row, int col);
890 void base_SetRowAttr(wxGridCellAttr *attr, int row);
891 void base_SetColAttr(wxGridCellAttr *attr, int col);
895 //---------------------------------------------------------------------------
896 // Grid Table Base class and Python aware version
900 class wxGridTableBase
903 // wxGridTableBase(); This is an ABC
904 //~wxGridTableBase();
906 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
907 wxGridCellAttrProvider *GetAttrProvider() const;
908 void SetView( wxGrid *grid );
909 wxGrid * GetView() const;
913 virtual int GetNumberRows() = 0;
914 virtual int GetNumberCols() = 0;
915 virtual bool IsEmptyCell( int row, int col ) = 0;
916 virtual wxString GetValue( int row, int col ) = 0;
917 virtual void SetValue( int row, int col, const wxString& value ) = 0;
919 // virtuals overridable in wxPyGridTableBase
920 virtual wxString GetTypeName( int row, int col );
921 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
922 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
923 virtual long GetValueAsLong( int row, int col );
924 virtual double GetValueAsDouble( int row, int col );
925 virtual bool GetValueAsBool( int row, int col );
926 virtual void SetValueAsLong( int row, int col, long value );
927 virtual void SetValueAsDouble( int row, int col, double value );
928 virtual void SetValueAsBool( int row, int col, bool value );
930 //virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
931 //virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
934 virtual void Clear();
935 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
936 virtual bool AppendRows( size_t numRows = 1 );
937 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
938 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
939 virtual bool AppendCols( size_t numCols = 1 );
940 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
942 virtual wxString GetRowLabelValue( int row );
943 virtual wxString GetColLabelValue( int col );
944 virtual void SetRowLabelValue( int row, const wxString& value );
945 virtual void SetColLabelValue( int col, const wxString& value );
947 virtual bool CanHaveAttributes();
949 virtual wxGridCellAttr *GetAttr( int row, int col );
950 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
951 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
952 virtual void SetColAttr(wxGridCellAttr *attr, int col);
958 // Python-aware version
960 class wxPyGridTableBase : public wxGridTableBase
963 wxPyGridTableBase() : wxGridTableBase() {}
965 PYCALLBACK_INT__pure(GetNumberRows);
966 PYCALLBACK_INT__pure(GetNumberCols);
967 PYCALLBACK_BOOL_INTINT_pure(IsEmptyCell);
968 PYCALLBACK_STRING_INTINT(wxGridTableBase, GetTypeName);
969 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanGetValueAs);
970 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanSetValueAs);
971 PYCALLBACK__(wxGridTableBase, Clear);
972 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertRows);
973 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteRows);
974 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertCols);
975 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteCols);
976 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendRows);
977 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendCols);
978 PYCALLBACK_STRING_INT(wxGridTableBase, GetRowLabelValue);
979 PYCALLBACK_STRING_INT(wxGridTableBase, GetColLabelValue);
980 PYCALLBACK__INTSTRING(wxGridTableBase, SetRowLabelValue);
981 PYCALLBACK__INTSTRING(wxGridTableBase, SetColLabelValue);
982 PYCALLBACK_BOOL_(wxGridTableBase, CanHaveAttributes);
983 PYCALLBACK_GCA_INTINT(wxGridTableBase, GetAttr);
984 PYCALLBACK__GCAINTINT(wxGridTableBase, SetAttr);
985 PYCALLBACK__GCAINT(wxGridTableBase, SetRowAttr);
986 PYCALLBACK__GCAINT(wxGridTableBase, SetColAttr);
989 wxString GetValue(int row, int col) {
990 bool doSave = wxPyRestoreThread();
992 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
994 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",row,col));
996 PyObject* str = PyObject_Str(ro);
997 rval = PyString_AsString(str);
1002 wxPySaveThread(doSave);
1006 void SetValue(int row, int col, const wxString& val) {
1007 bool doSave = wxPyRestoreThread();
1008 if (wxPyCBH_findCallback(m_myInst, "SetValue"))
1009 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iis)",row,col,val.c_str()));
1010 wxPySaveThread(doSave);
1014 // Map the Get/Set methods for the standard non-string types to
1015 // the GetValue and SetValue python methods.
1016 long GetValueAsLong( int row, int col ) {
1018 bool doSave = wxPyRestoreThread();
1019 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1022 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1023 if (ro && PyNumber_Check(ro)) {
1024 num = PyNumber_Int(ro);
1026 rval = PyInt_AsLong(num);
1032 wxPySaveThread(doSave);
1036 double GetValueAsDouble( int row, int col ) {
1038 bool doSave = wxPyRestoreThread();
1039 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1042 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1043 if (ro && PyNumber_Check(ro)) {
1044 num = PyNumber_Float(ro);
1046 rval = PyFloat_AsDouble(num);
1052 wxPySaveThread(doSave);
1056 bool GetValueAsBool( int row, int col ) {
1057 return (bool)GetValueAsLong(row, col);
1060 void SetValueAsLong( int row, int col, long value ) {
1061 bool doSave = wxPyRestoreThread();
1062 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1063 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", row, col, value));
1065 wxPySaveThread(doSave);
1068 void SetValueAsDouble( int row, int col, double value ) {
1069 bool doSave = wxPyRestoreThread();
1070 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1071 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iid)", row, col, value));
1073 wxPySaveThread(doSave);
1076 void SetValueAsBool( int row, int col, bool value ) {
1077 SetValueAsLong( row, col, (long)value );
1086 // The python-aware version get's SWIGified
1087 class wxPyGridTableBase : public wxGridTableBase
1090 wxPyGridTableBase();
1091 void _setSelf(PyObject* self, PyObject* _class);
1092 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyGridTableBase)"
1094 %addmethods { void Destroy() { delete self; } }
1096 wxString base_GetTypeName( int row, int col );
1097 bool base_CanGetValueAs( int row, int col, const wxString& typeName );
1098 bool base_CanSetValueAs( int row, int col, const wxString& typeName );
1100 bool base_InsertRows( size_t pos = 0, size_t numRows = 1 );
1101 bool base_AppendRows( size_t numRows = 1 );
1102 bool base_DeleteRows( size_t pos = 0, size_t numRows = 1 );
1103 bool base_InsertCols( size_t pos = 0, size_t numCols = 1 );
1104 bool base_AppendCols( size_t numCols = 1 );
1105 bool base_DeleteCols( size_t pos = 0, size_t numCols = 1 );
1106 wxString base_GetRowLabelValue( int row );
1107 wxString base_GetColLabelValue( int col );
1108 void base_SetRowLabelValue( int row, const wxString& value );
1109 void base_SetColLabelValue( int col, const wxString& value );
1110 bool base_CanHaveAttributes();
1111 wxGridCellAttr *base_GetAttr( int row, int col );
1112 void base_SetAttr(wxGridCellAttr* attr, int row, int col);
1113 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1114 void base_SetColAttr(wxGridCellAttr *attr, int col);
1118 //---------------------------------------------------------------------------
1119 // Predefined Tables
1121 class wxGridStringTable : public wxGridTableBase
1124 wxGridStringTable( int numRows=0, int numCols=0 );
1127 //---------------------------------------------------------------------------
1128 // The Table can pass messages to the grid to tell it to update itself if
1129 // something has changed.
1131 enum wxGridTableRequest
1133 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
1134 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
1135 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
1136 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
1137 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
1138 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1139 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
1140 wxGRIDTABLE_NOTIFY_COLS_DELETED
1144 class wxGridTableMessage
1147 wxGridTableMessage( wxGridTableBase *table, int id,
1150 ~wxGridTableMessage();
1152 void SetTableObject( wxGridTableBase *table );
1153 wxGridTableBase * GetTableObject() const;
1154 void SetId( int id );
1156 void SetCommandInt( int comInt1 );
1157 int GetCommandInt();
1158 void SetCommandInt2( int comInt2 );
1159 int GetCommandInt2();
1163 //---------------------------------------------------------------------------
1165 class wxGridCellCoords
1168 wxGridCellCoords( int r=-1, int c=-1 );
1169 ~wxGridCellCoords();
1171 int GetRow() const { return m_row; }
1172 void SetRow( int n ) { m_row = n; }
1173 int GetCol() const { return m_col; }
1174 void SetCol( int n ) { m_col = n; }
1175 void Set( int row, int col ) { m_row = row; m_col = col; }
1178 PyObject* asTuple() {
1179 PyObject* tup = PyTuple_New(2);
1180 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
1181 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
1185 int __cmp__( const wxGridCellCoords& other ) {
1186 return *self != other;
1189 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
1190 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
1193 // Typemap to allow conversion of sequence objects to wxGridCellCoords...
1194 %typemap(python,in) wxGridCellCoords& (wxGridCellCoords temp) {
1196 if (! wxGridCellCoords_helper($source, &$target))
1200 // ...and here is the associated helper.
1202 bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) {
1204 // If source is an object instance then it may already be the right type
1205 if (PyInstance_Check(source)) {
1206 wxGridCellCoords* ptr;
1207 if (SWIG_GetPtrObj(source, (void **)&ptr, "_wxGridCellCoords_p"))
1212 // otherwise a 2-tuple of integers is expected
1213 else if (PySequence_Check(source) && PyObject_Length(source) == 2) {
1214 PyObject* o1 = PySequence_GetItem(source, 0);
1215 PyObject* o2 = PySequence_GetItem(source, 1);
1216 **obj = wxGridCellCoords(PyInt_AsLong(o1), PyInt_AsLong(o2));
1221 PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of integers or a wxGridCellCoords object.");
1226 //---------------------------------------------------------------------------
1227 //---------------------------------------------------------------------------
1231 // Fool SWIG into treating this enum as an int
1232 typedef int WXGRIDSELECTIONMODES;
1234 // but let the C++ code know what it really is.
1236 typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES;
1241 class wxGrid : public wxScrolledWindow
1244 wxGrid( wxWindow *parent,
1246 const wxPoint& pos = wxDefaultPosition,
1247 const wxSize& size = wxDefaultSize,
1248 long style = wxWANTS_CHARS,
1249 const char* name = wxPanelNameStr );
1253 enum wxGridSelectionModes {wxGridSelectCells,
1255 wxGridSelectColumns};
1257 bool CreateGrid( int numRows, int numCols,
1258 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1259 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1262 // ------ grid dimensions
1264 int GetNumberRows();
1265 int GetNumberCols();
1269 #ifdef NOTNEEDED // ????
1270 // ------ display update functions
1272 void CalcRowLabelsExposed( wxRegion& reg );
1273 void CalcColLabelsExposed( wxRegion& reg );
1274 void CalcCellsExposed( wxRegion& reg );
1276 // ------ event handlers
1278 void ProcessRowLabelMouseEvent( wxMouseEvent& event );
1279 void ProcessColLabelMouseEvent( wxMouseEvent& event );
1280 void ProcessCornerLabelMouseEvent( wxMouseEvent& event );
1281 void ProcessGridCellMouseEvent( wxMouseEvent& event );
1282 void DoEndDragResizeRow();
1283 void DoEndDragResizeCol();
1286 bool ProcessTableMessage( wxGridTableMessage& );
1289 wxGridTableBase * GetTable() const;
1290 bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE,
1291 WXGRIDSELECTIONMODES selmode =
1292 wxGrid::wxGridSelectCells );
1295 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1296 bool AppendRows( int numRows = 1, bool updateLabels=TRUE );
1297 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1298 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1299 bool AppendCols( int numCols = 1, bool updateLabels=TRUE );
1300 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1302 #ifdef NOTNEEDED // ????
1303 void DrawGridCellArea( wxDC& dc );
1304 void DrawGridSpace( wxDC& dc );
1305 void DrawCellBorder( wxDC& dc, const wxGridCellCoords& );
1306 void DrawAllGridLines( wxDC& dc, const wxRegion & reg );
1307 void DrawCell( wxDC& dc, const wxGridCellCoords& );
1308 void DrawHighlight(wxDC& dc);
1311 // this function is called when the current cell highlight must be redrawn
1312 // and may be overridden by the user
1313 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1315 #ifdef NOTNEEDED // ????
1316 void DrawRowLabels( wxDC& dc );
1317 void DrawRowLabel( wxDC& dc, int row );
1319 void DrawColLabels( wxDC& dc );
1320 void DrawColLabel( wxDC& dc, int col );
1323 // ------ Cell text drawing functions
1325 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1326 int horizontalAlignment = wxLEFT,
1327 int verticalAlignment = wxTOP );
1329 // Split a string containing newline chararcters into an array of
1330 // strings and return the number of lines
1332 void StringToLines( const wxString& value, wxArrayString& lines );
1334 void GetTextBoxSize( wxDC& dc,
1335 wxArrayString& lines,
1336 long *OUTPUT, long *OUTPUT );
1340 // Code that does a lot of grid modification can be enclosed
1341 // between BeginBatch() and EndBatch() calls to avoid screen
1346 int GetBatchCount();
1349 // ------ edit control functions
1351 bool IsEditable() { return m_editable; }
1352 void EnableEditing( bool edit );
1354 void EnableCellEditControl( bool enable = TRUE );
1355 void DisableCellEditControl();
1356 bool CanEnableCellControl() const;
1357 bool IsCellEditControlEnabled() const;
1358 bool IsCellEditControlShown() const;
1360 bool IsCurrentCellReadOnly() const;
1362 void ShowCellEditControl();
1363 void HideCellEditControl();
1364 void SaveEditControlValue();
1367 // ------ grid location functions
1368 // Note that all of these functions work with the logical coordinates of
1369 // grid cells and labels so you will need to convert from device
1370 // coordinates for mouse events etc.
1373 //void XYToCell( int x, int y, wxGridCellCoords& );
1375 %new wxGridCellCoords* XYToCell(int x, int y) {
1376 wxGridCellCoords rv;
1377 self->XYToCell(x, y, rv);
1378 return new wxGridCellCoords(rv);
1382 int YToRow( int y );
1383 int XToCol( int x );
1385 int YToEdgeOfRow( int y );
1386 int XToEdgeOfCol( int x );
1388 wxRect CellToRect( int row, int col );
1389 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1392 int GetGridCursorRow();
1393 int GetGridCursorCol();
1395 // check to see if a cell is either wholly visible (the default arg) or
1396 // at least partially visible in the grid window
1398 bool IsVisible( int row, int col, bool wholeCellVisible = TRUE );
1399 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE );
1400 void MakeCellVisible( int row, int col );
1401 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1404 // ------ grid cursor movement functions
1406 void SetGridCursor( int row, int col );
1407 bool MoveCursorUp( bool expandSelection );
1408 bool MoveCursorDown( bool expandSelection );
1409 bool MoveCursorLeft( bool expandSelection );
1410 bool MoveCursorRight( bool expandSelection );
1411 bool MovePageDown();
1413 bool MoveCursorUpBlock( bool expandSelection );
1414 bool MoveCursorDownBlock( bool expandSelection );
1415 bool MoveCursorLeftBlock( bool expandSelection );
1416 bool MoveCursorRightBlock( bool expandSelection );
1419 // ------ label and gridline formatting
1421 int GetDefaultRowLabelSize();
1422 int GetRowLabelSize();
1423 int GetDefaultColLabelSize();
1424 int GetColLabelSize();
1425 wxColour GetLabelBackgroundColour();
1426 wxColour GetLabelTextColour();
1427 wxFont GetLabelFont();
1428 void GetRowLabelAlignment( int *OUTPUT, int *OUTPUT );
1429 void GetColLabelAlignment( int *OUTPUT, int *OUTPUT );
1430 wxString GetRowLabelValue( int row );
1431 wxString GetColLabelValue( int col );
1432 wxColour GetGridLineColour();
1433 wxColour GetCellHighlightColour();
1435 void SetRowLabelSize( int width );
1436 void SetColLabelSize( int height );
1437 void SetLabelBackgroundColour( const wxColour& );
1438 void SetLabelTextColour( const wxColour& );
1439 void SetLabelFont( const wxFont& );
1440 void SetRowLabelAlignment( int horiz, int vert );
1441 void SetColLabelAlignment( int horiz, int vert );
1442 void SetRowLabelValue( int row, const wxString& );
1443 void SetColLabelValue( int col, const wxString& );
1444 void SetGridLineColour( const wxColour& );
1445 void SetCellHighlightColour( const wxColour& );
1447 void EnableDragRowSize( bool enable = TRUE );
1448 void DisableDragRowSize();
1449 bool CanDragRowSize();
1450 void EnableDragColSize( bool enable = TRUE );
1451 void DisableDragColSize();
1452 bool CanDragColSize();
1453 void EnableDragGridSize(bool enable = TRUE);
1454 void DisableDragGridSize();
1455 bool CanDragGridSize();
1457 // this sets the specified attribute for all cells in this row/col
1458 void SetRowAttr(int row, wxGridCellAttr *attr);
1459 void SetColAttr(int col, wxGridCellAttr *attr);
1461 // shortcuts for setting the column parameters
1463 // set the format for the data in the column: default is string
1464 void SetColFormatBool(int col);
1465 void SetColFormatNumber(int col);
1466 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1467 void SetColFormatCustom(int col, const wxString& typeName);
1469 void EnableGridLines( bool enable = TRUE );
1470 bool GridLinesEnabled();
1472 // ------ row and col formatting
1474 int GetDefaultRowSize();
1475 int GetRowSize( int row );
1476 int GetDefaultColSize();
1477 int GetColSize( int col );
1478 wxColour GetDefaultCellBackgroundColour();
1479 wxColour GetCellBackgroundColour( int row, int col );
1480 wxColour GetDefaultCellTextColour();
1481 wxColour GetCellTextColour( int row, int col );
1482 wxFont GetDefaultCellFont();
1483 wxFont GetCellFont( int row, int col );
1484 void GetDefaultCellAlignment( int *horiz, int *vert );
1485 void GetCellAlignment( int row, int col, int *horiz, int *vert );
1487 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
1488 void SetRowSize( int row, int height );
1489 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
1491 void SetColSize( int col, int width );
1493 // automatically size the column or row to fit to its contents, if
1494 // setAsMin is TRUE, this optimal width will also be set as minimal width
1496 void AutoSizeColumn( int col, bool setAsMin = TRUE );
1497 void AutoSizeRow( int row, bool setAsMin = TRUE );
1500 // auto size all columns (very ineffective for big grids!)
1501 void AutoSizeColumns( bool setAsMin = TRUE );
1502 void AutoSizeRows( bool setAsMin = TRUE );
1504 // auto size the grid, that is make the columns/rows of the "right" size
1505 // and also set the grid size to just fit its contents
1508 // column won't be resized to be lesser width - this must be called during
1509 // the grid creation because it won't resize the column if it's already
1510 // narrower than the minimal width
1511 void SetColMinimalWidth( int col, int width );
1512 void SetRowMinimalHeight( int row, int width );
1514 void SetDefaultCellBackgroundColour( const wxColour& );
1515 void SetCellBackgroundColour( int row, int col, const wxColour& );
1516 void SetDefaultCellTextColour( const wxColour& );
1518 void SetCellTextColour( int row, int col, const wxColour& );
1519 void SetDefaultCellFont( const wxFont& );
1520 void SetCellFont( int row, int col, const wxFont& );
1521 void SetDefaultCellAlignment( int horiz, int vert );
1522 void SetCellAlignment( int row, int col, int horiz, int vert );
1524 // takes ownership of the pointer
1525 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1526 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1527 wxGridCellRenderer *GetDefaultRenderer() const;
1528 wxGridCellRenderer* GetCellRenderer(int row, int col);
1530 // takes ownership of the pointer
1531 void SetDefaultEditor(wxGridCellEditor *editor);
1532 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1533 wxGridCellEditor *GetDefaultEditor() const;
1534 wxGridCellEditor* GetCellEditor(int row, int col);
1538 // ------ cell value accessors
1540 wxString GetCellValue( int row, int col );
1541 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1543 void SetCellValue( int row, int col, const wxString& s );
1544 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1546 // returns TRUE if the cell can't be edited
1547 bool IsReadOnly(int row, int col) const;
1549 // make the cell editable/readonly
1550 void SetReadOnly(int row, int col, bool isReadOnly = TRUE);
1552 // ------ selections of blocks of cells
1554 void SelectRow( int row, bool addToSelected = FALSE );
1555 void SelectCol( int col, bool addToSelected = FALSE );
1557 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1558 bool addToSelected = FALSE );
1559 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1560 // TODO: ??? const wxGridCellCoords& bottomRight )
1564 void ClearSelection();
1565 bool IsInSelection( int row, int col );
1566 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1569 // This function returns the rectangle that encloses the block of cells
1570 // limited by TopLeft and BottomRight cell in device coords and clipped
1571 // to the client size of the grid window.
1573 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1574 const wxGridCellCoords & bottomRight );
1577 // Access or update the selection fore/back colours
1578 wxColour GetSelectionBackground() const;
1579 wxColour GetSelectionForeground() const;
1581 void SetSelectionBackground(const wxColour& c);
1582 void SetSelectionForeground(const wxColour& c);
1585 // Methods for a registry for mapping data types to Renderers/Editors
1586 void RegisterDataType(const wxString& typeName,
1587 wxGridCellRenderer* renderer,
1588 wxGridCellEditor* editor);
1589 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1590 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1591 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1592 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1593 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1595 // grid may occupy more space than needed for its rows/columns, this
1596 // function allows to set how big this extra space is
1597 void SetMargins(int extraWidth, int extraHeight);
1601 //---------------------------------------------------------------------------
1602 //---------------------------------------------------------------------------
1603 // Grid events and stuff
1607 class wxGridEvent : public wxNotifyEvent
1610 wxGridEvent(int id, wxEventType type, wxGrid* obj,
1611 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = TRUE,
1612 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1614 virtual int GetRow();
1615 virtual int GetCol();
1616 wxPoint GetPosition();
1626 class wxGridSizeEvent : public wxNotifyEvent
1629 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
1630 int rowOrCol=-1, int x=-1, int y=-1,
1631 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1634 wxPoint GetPosition();
1643 class wxGridRangeSelectEvent : public wxNotifyEvent
1646 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
1647 const wxGridCellCoords& topLeft,
1648 const wxGridCellCoords& bottomRight,
1650 bool control=FALSE, bool shift=FALSE,
1651 bool alt=FALSE, bool meta=FALSE);
1653 wxGridCellCoords GetTopLeftCoords();
1654 wxGridCellCoords GetBottomRightCoords();
1667 wxEVT_GRID_CELL_LEFT_CLICK,
1668 wxEVT_GRID_CELL_RIGHT_CLICK,
1669 wxEVT_GRID_CELL_LEFT_DCLICK,
1670 wxEVT_GRID_CELL_RIGHT_DCLICK,
1671 wxEVT_GRID_LABEL_LEFT_CLICK,
1672 wxEVT_GRID_LABEL_RIGHT_CLICK,
1673 wxEVT_GRID_LABEL_LEFT_DCLICK,
1674 wxEVT_GRID_LABEL_RIGHT_DCLICK,
1675 wxEVT_GRID_ROW_SIZE,
1676 wxEVT_GRID_COL_SIZE,
1677 wxEVT_GRID_RANGE_SELECT,
1678 wxEVT_GRID_CELL_CHANGE,
1679 wxEVT_GRID_SELECT_CELL,
1680 wxEVT_GRID_EDITOR_SHOWN,
1681 wxEVT_GRID_EDITOR_HIDDEN,
1686 %pragma(python) code = "
1687 def EVT_GRID_CELL_LEFT_CLICK(win, fn):
1688 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_CLICK, fn)
1690 def EVT_GRID_CELL_RIGHT_CLICK(win, fn):
1691 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_CLICK, fn)
1693 def EVT_GRID_CELL_LEFT_DCLICK(win, fn):
1694 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_DCLICK, fn)
1696 def EVT_GRID_CELL_RIGHT_DCLICK(win, fn):
1697 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_DCLICK, fn)
1699 def EVT_GRID_LABEL_LEFT_CLICK(win, fn):
1700 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_CLICK, fn)
1702 def EVT_GRID_LABEL_RIGHT_CLICK(win, fn):
1703 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_CLICK, fn)
1705 def EVT_GRID_LABEL_LEFT_DCLICK(win, fn):
1706 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_DCLICK, fn)
1708 def EVT_GRID_LABEL_RIGHT_DCLICK(win, fn):
1709 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_DCLICK, fn)
1711 def EVT_GRID_ROW_SIZE(win, fn):
1712 win.Connect(-1, -1, wxEVT_GRID_ROW_SIZE, fn)
1714 def EVT_GRID_COL_SIZE(win, fn):
1715 win.Connect(-1, -1, wxEVT_GRID_COL_SIZE, fn)
1717 def EVT_GRID_RANGE_SELECT(win, fn):
1718 win.Connect(-1, -1, wxEVT_GRID_RANGE_SELECT, fn)
1720 def EVT_GRID_CELL_CHANGE(win, fn):
1721 win.Connect(-1, -1, wxEVT_GRID_CELL_CHANGE, fn)
1723 def EVT_GRID_SELECT_CELL(win, fn):
1724 win.Connect(-1, -1, wxEVT_GRID_SELECT_CELL, fn)
1726 def EVT_GRID_EDITOR_SHOWN(win, fn):
1727 win.Connect(-1, -1, wxEVT_GRID_EDITOR_SHOWN, fn)
1729 def EVT_GRID_EDITOR_HIDDEN(win, fn):
1730 win.Connect(-1, -1, wxEVT_GRID_EDITOR_HIDDEN, fn)
1734 //---------------------------------------------------------------------------
1737 wxClassInfo::CleanUpClasses();
1738 wxClassInfo::InitializeClasses();
1741 //---------------------------------------------------------------------------
1743 %pragma(python) include="_gridextras.py";
1745 //---------------------------------------------------------------------------