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_INTINTKIND(PCLASS, CBNAME) \
47 wxGridCellAttr* CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
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("(iii)", a, b, c)); \
55 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellAttr_p")) \
61 rval = PCLASS::CBNAME(a, b, c); \
62 wxPySaveThread(doSave); \
65 wxGridCellAttr *base_##CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
66 return PCLASS::CBNAME(a, b, c); \
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 //---------------------------------------------------------------------------
824 wxGridCellAttr *Clone() const;
825 void MergeWith(wxGridCellAttr *mergefrom);
828 void SetTextColour(const wxColour& colText);
829 void SetBackgroundColour(const wxColour& colBack);
830 void SetFont(const wxFont& font);
831 void SetAlignment(int hAlign, int vAlign);
832 void SetReadOnly(bool isReadOnly = TRUE);
834 void SetRenderer(wxGridCellRenderer *renderer);
835 void SetEditor(wxGridCellEditor* editor);
836 void SetKind(wxAttrKind kind);
838 bool HasTextColour() const;
839 bool HasBackgroundColour() const;
840 bool HasFont() const;
841 bool HasAlignment() const;
842 bool HasRenderer() const;
843 bool HasEditor() const;
844 bool HasReadWriteMode() const;
846 const wxColour& GetTextColour() const;
847 const wxColour& GetBackgroundColour() const;
848 const wxFont& GetFont() const;
849 void GetAlignment(int *OUTPUT, int *OUTPUT) const;
850 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
851 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
853 bool IsReadOnly() const;
854 void SetDefAttr(wxGridCellAttr* defAttr);
857 //---------------------------------------------------------------------------
859 class wxGridCellAttrProvider
862 wxGridCellAttrProvider();
863 // ???? virtual ~wxGridCellAttrProvider();
865 wxGridCellAttr *GetAttr(int row, int col,
866 wxGridCellAttr::wxAttrKind kind) const;
867 void SetAttr(wxGridCellAttr *attr, int row, int col);
868 void SetRowAttr(wxGridCellAttr *attr, int row);
869 void SetColAttr(wxGridCellAttr *attr, int col);
871 void UpdateAttrRows( size_t pos, int numRows );
872 void UpdateAttrCols( size_t pos, int numCols );
877 // A Python-aware version
879 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
882 wxPyGridCellAttrProvider() : wxGridCellAttrProvider() {};
884 PYCALLBACK_GCA_INTINTKIND(wxGridCellAttrProvider, GetAttr);
885 PYCALLBACK__GCAINTINT(wxGridCellAttrProvider, SetAttr);
886 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetRowAttr);
887 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetColAttr);
894 // The python-aware version get's SWIGified
895 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
898 wxPyGridCellAttrProvider();
899 void _setSelf(PyObject* self, PyObject* _class);
900 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyGridCellAttrProvider)"
902 wxGridCellAttr *base_GetAttr(int row, int col,
903 wxGridCellAttr::wxAttrKind kind);
904 void base_SetAttr(wxGridCellAttr *attr, int row, int col);
905 void base_SetRowAttr(wxGridCellAttr *attr, int row);
906 void base_SetColAttr(wxGridCellAttr *attr, int col);
910 //---------------------------------------------------------------------------
911 // Grid Table Base class and Python aware version
915 class wxGridTableBase : public wxObject
918 // wxGridTableBase(); This is an ABC
919 //~wxGridTableBase();
921 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
922 wxGridCellAttrProvider *GetAttrProvider() const;
923 void SetView( wxGrid *grid );
924 wxGrid * GetView() const;
928 virtual int GetNumberRows() = 0;
929 virtual int GetNumberCols() = 0;
930 virtual bool IsEmptyCell( int row, int col ) = 0;
931 virtual wxString GetValue( int row, int col ) = 0;
932 virtual void SetValue( int row, int col, const wxString& value ) = 0;
934 // virtuals overridable in wxPyGridTableBase
935 virtual wxString GetTypeName( int row, int col );
936 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
937 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
938 virtual long GetValueAsLong( int row, int col );
939 virtual double GetValueAsDouble( int row, int col );
940 virtual bool GetValueAsBool( int row, int col );
941 virtual void SetValueAsLong( int row, int col, long value );
942 virtual void SetValueAsDouble( int row, int col, double value );
943 virtual void SetValueAsBool( int row, int col, bool value );
945 //virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
946 //virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
949 virtual void Clear();
950 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
951 virtual bool AppendRows( size_t numRows = 1 );
952 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
953 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
954 virtual bool AppendCols( size_t numCols = 1 );
955 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
957 virtual wxString GetRowLabelValue( int row );
958 virtual wxString GetColLabelValue( int col );
959 virtual void SetRowLabelValue( int row, const wxString& value );
960 virtual void SetColLabelValue( int col, const wxString& value );
962 virtual bool CanHaveAttributes();
964 virtual wxGridCellAttr *GetAttr( int row, int col,
965 wxGridCellAttr::wxAttrKind kind);
966 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
967 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
968 virtual void SetColAttr(wxGridCellAttr *attr, int col);
974 // Python-aware version
976 class wxPyGridTableBase : public wxGridTableBase
979 wxPyGridTableBase() : wxGridTableBase() {}
981 PYCALLBACK_INT__pure(GetNumberRows);
982 PYCALLBACK_INT__pure(GetNumberCols);
983 PYCALLBACK_BOOL_INTINT_pure(IsEmptyCell);
984 PYCALLBACK_STRING_INTINT(wxGridTableBase, GetTypeName);
985 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanGetValueAs);
986 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanSetValueAs);
987 PYCALLBACK__(wxGridTableBase, Clear);
988 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertRows);
989 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteRows);
990 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertCols);
991 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteCols);
992 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendRows);
993 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendCols);
994 PYCALLBACK_STRING_INT(wxGridTableBase, GetRowLabelValue);
995 PYCALLBACK_STRING_INT(wxGridTableBase, GetColLabelValue);
996 PYCALLBACK__INTSTRING(wxGridTableBase, SetRowLabelValue);
997 PYCALLBACK__INTSTRING(wxGridTableBase, SetColLabelValue);
998 PYCALLBACK_BOOL_(wxGridTableBase, CanHaveAttributes);
999 PYCALLBACK_GCA_INTINTKIND(wxGridTableBase, GetAttr);
1000 PYCALLBACK__GCAINTINT(wxGridTableBase, SetAttr);
1001 PYCALLBACK__GCAINT(wxGridTableBase, SetRowAttr);
1002 PYCALLBACK__GCAINT(wxGridTableBase, SetColAttr);
1005 wxString GetValue(int row, int col) {
1006 bool doSave = wxPyRestoreThread();
1008 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1010 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",row,col));
1012 PyObject* str = PyObject_Str(ro);
1013 rval = PyString_AsString(str);
1018 wxPySaveThread(doSave);
1022 void SetValue(int row, int col, const wxString& val) {
1023 bool doSave = wxPyRestoreThread();
1024 if (wxPyCBH_findCallback(m_myInst, "SetValue"))
1025 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iis)",row,col,val.c_str()));
1026 wxPySaveThread(doSave);
1030 // Map the Get/Set methods for the standard non-string types to
1031 // the GetValue and SetValue python methods.
1032 long GetValueAsLong( int row, int col ) {
1034 bool doSave = wxPyRestoreThread();
1035 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1038 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1039 if (ro && PyNumber_Check(ro)) {
1040 num = PyNumber_Int(ro);
1042 rval = PyInt_AsLong(num);
1048 wxPySaveThread(doSave);
1052 double GetValueAsDouble( int row, int col ) {
1054 bool doSave = wxPyRestoreThread();
1055 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1058 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1059 if (ro && PyNumber_Check(ro)) {
1060 num = PyNumber_Float(ro);
1062 rval = PyFloat_AsDouble(num);
1068 wxPySaveThread(doSave);
1072 bool GetValueAsBool( int row, int col ) {
1073 return (bool)GetValueAsLong(row, col);
1076 void SetValueAsLong( int row, int col, long value ) {
1077 bool doSave = wxPyRestoreThread();
1078 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1079 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", row, col, value));
1081 wxPySaveThread(doSave);
1084 void SetValueAsDouble( int row, int col, double value ) {
1085 bool doSave = wxPyRestoreThread();
1086 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1087 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iid)", row, col, value));
1089 wxPySaveThread(doSave);
1092 void SetValueAsBool( int row, int col, bool value ) {
1093 SetValueAsLong( row, col, (long)value );
1102 // The python-aware version get's SWIGified
1103 class wxPyGridTableBase : public wxGridTableBase
1106 wxPyGridTableBase();
1107 void _setSelf(PyObject* self, PyObject* _class);
1108 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyGridTableBase)"
1110 %addmethods { void Destroy() { delete self; } }
1112 wxString base_GetTypeName( int row, int col );
1113 bool base_CanGetValueAs( int row, int col, const wxString& typeName );
1114 bool base_CanSetValueAs( int row, int col, const wxString& typeName );
1116 bool base_InsertRows( size_t pos = 0, size_t numRows = 1 );
1117 bool base_AppendRows( size_t numRows = 1 );
1118 bool base_DeleteRows( size_t pos = 0, size_t numRows = 1 );
1119 bool base_InsertCols( size_t pos = 0, size_t numCols = 1 );
1120 bool base_AppendCols( size_t numCols = 1 );
1121 bool base_DeleteCols( size_t pos = 0, size_t numCols = 1 );
1122 wxString base_GetRowLabelValue( int row );
1123 wxString base_GetColLabelValue( int col );
1124 void base_SetRowLabelValue( int row, const wxString& value );
1125 void base_SetColLabelValue( int col, const wxString& value );
1126 bool base_CanHaveAttributes();
1127 wxGridCellAttr *base_GetAttr( int row, int col,
1128 wxGridCellAttr::wxAttrKind kind );
1129 void base_SetAttr(wxGridCellAttr* attr, int row, int col);
1130 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1131 void base_SetColAttr(wxGridCellAttr *attr, int col);
1135 //---------------------------------------------------------------------------
1136 // Predefined Tables
1138 class wxGridStringTable : public wxGridTableBase
1141 wxGridStringTable( int numRows=0, int numCols=0 );
1144 //---------------------------------------------------------------------------
1145 // The Table can pass messages to the grid to tell it to update itself if
1146 // something has changed.
1148 enum wxGridTableRequest
1150 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
1151 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
1152 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
1153 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
1154 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
1155 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1156 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
1157 wxGRIDTABLE_NOTIFY_COLS_DELETED
1161 class wxGridTableMessage
1164 wxGridTableMessage( wxGridTableBase *table, int id,
1167 ~wxGridTableMessage();
1169 void SetTableObject( wxGridTableBase *table );
1170 wxGridTableBase * GetTableObject() const;
1171 void SetId( int id );
1173 void SetCommandInt( int comInt1 );
1174 int GetCommandInt();
1175 void SetCommandInt2( int comInt2 );
1176 int GetCommandInt2();
1180 //---------------------------------------------------------------------------
1182 class wxGridCellCoords
1185 wxGridCellCoords( int r=-1, int c=-1 );
1186 ~wxGridCellCoords();
1188 int GetRow() const { return m_row; }
1189 void SetRow( int n ) { m_row = n; }
1190 int GetCol() const { return m_col; }
1191 void SetCol( int n ) { m_col = n; }
1192 void Set( int row, int col ) { m_row = row; m_col = col; }
1195 PyObject* asTuple() {
1196 PyObject* tup = PyTuple_New(2);
1197 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
1198 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
1202 int __cmp__( const wxGridCellCoords& other ) {
1203 return *self != other;
1206 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
1207 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
1210 // Typemap to allow conversion of sequence objects to wxGridCellCoords...
1211 %typemap(python,in) wxGridCellCoords& (wxGridCellCoords temp) {
1213 if (! wxGridCellCoords_helper($source, &$target))
1217 // ...and here is the associated helper.
1219 bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) {
1221 // If source is an object instance then it may already be the right type
1222 if (PyInstance_Check(source)) {
1223 wxGridCellCoords* ptr;
1224 if (SWIG_GetPtrObj(source, (void **)&ptr, "_wxGridCellCoords_p"))
1229 // otherwise a 2-tuple of integers is expected
1230 else if (PySequence_Check(source) && PyObject_Length(source) == 2) {
1231 PyObject* o1 = PySequence_GetItem(source, 0);
1232 PyObject* o2 = PySequence_GetItem(source, 1);
1233 **obj = wxGridCellCoords(PyInt_AsLong(o1), PyInt_AsLong(o2));
1238 PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of integers or a wxGridCellCoords object.");
1243 //---------------------------------------------------------------------------
1244 //---------------------------------------------------------------------------
1248 // Fool SWIG into treating this enum as an int
1249 typedef int WXGRIDSELECTIONMODES;
1251 // but let the C++ code know what it really is.
1253 typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES;
1258 class wxGrid : public wxScrolledWindow
1261 wxGrid( wxWindow *parent,
1263 const wxPoint& pos = wxDefaultPosition,
1264 const wxSize& size = wxDefaultSize,
1265 long style = wxWANTS_CHARS,
1266 const char* name = wxPanelNameStr );
1269 enum wxGridSelectionModes {wxGridSelectCells,
1271 wxGridSelectColumns};
1273 bool CreateGrid( int numRows, int numCols,
1274 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1275 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1278 // ------ grid dimensions
1280 int GetNumberRows();
1281 int GetNumberCols();
1284 bool ProcessTableMessage( wxGridTableMessage& );
1287 wxGridTableBase * GetTable() const;
1288 bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE,
1289 WXGRIDSELECTIONMODES selmode =
1290 wxGrid::wxGridSelectCells );
1293 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1294 bool AppendRows( int numRows = 1, bool updateLabels=TRUE );
1295 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1296 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1297 bool AppendCols( int numCols = 1, bool updateLabels=TRUE );
1298 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1301 // this function is called when the current cell highlight must be redrawn
1302 // and may be overridden by the user
1303 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1306 // ------ Cell text drawing functions
1308 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1309 int horizontalAlignment = wxLEFT,
1310 int verticalAlignment = wxTOP );
1312 // Split a string containing newline chararcters into an array of
1313 // strings and return the number of lines
1315 void StringToLines( const wxString& value, wxArrayString& lines );
1317 void GetTextBoxSize( wxDC& dc,
1318 wxArrayString& lines,
1319 long *OUTPUT, long *OUTPUT );
1323 // Code that does a lot of grid modification can be enclosed
1324 // between BeginBatch() and EndBatch() calls to avoid screen
1329 int GetBatchCount();
1330 void ForceRefresh();
1333 // ------ edit control functions
1335 bool IsEditable() { return m_editable; }
1336 void EnableEditing( bool edit );
1338 void EnableCellEditControl( bool enable = TRUE );
1339 void DisableCellEditControl();
1340 bool CanEnableCellControl() const;
1341 bool IsCellEditControlEnabled() const;
1342 bool IsCellEditControlShown() const;
1344 bool IsCurrentCellReadOnly() const;
1346 void ShowCellEditControl();
1347 void HideCellEditControl();
1348 void SaveEditControlValue();
1351 // ------ grid location functions
1352 // Note that all of these functions work with the logical coordinates of
1353 // grid cells and labels so you will need to convert from device
1354 // coordinates for mouse events etc.
1357 //void XYToCell( int x, int y, wxGridCellCoords& );
1359 %new wxGridCellCoords* XYToCell(int x, int y) {
1360 wxGridCellCoords rv;
1361 self->XYToCell(x, y, rv);
1362 return new wxGridCellCoords(rv);
1366 int YToRow( int y );
1367 int XToCol( int x );
1369 int YToEdgeOfRow( int y );
1370 int XToEdgeOfCol( int x );
1372 wxRect CellToRect( int row, int col );
1373 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1376 int GetGridCursorRow();
1377 int GetGridCursorCol();
1379 // check to see if a cell is either wholly visible (the default arg) or
1380 // at least partially visible in the grid window
1382 bool IsVisible( int row, int col, bool wholeCellVisible = TRUE );
1383 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE );
1384 void MakeCellVisible( int row, int col );
1385 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1388 // ------ grid cursor movement functions
1390 void SetGridCursor( int row, int col );
1391 bool MoveCursorUp( bool expandSelection );
1392 bool MoveCursorDown( bool expandSelection );
1393 bool MoveCursorLeft( bool expandSelection );
1394 bool MoveCursorRight( bool expandSelection );
1395 bool MovePageDown();
1397 bool MoveCursorUpBlock( bool expandSelection );
1398 bool MoveCursorDownBlock( bool expandSelection );
1399 bool MoveCursorLeftBlock( bool expandSelection );
1400 bool MoveCursorRightBlock( bool expandSelection );
1403 // ------ label and gridline formatting
1405 int GetDefaultRowLabelSize();
1406 int GetRowLabelSize();
1407 int GetDefaultColLabelSize();
1408 int GetColLabelSize();
1409 wxColour GetLabelBackgroundColour();
1410 wxColour GetLabelTextColour();
1411 wxFont GetLabelFont();
1412 void GetRowLabelAlignment( int *OUTPUT, int *OUTPUT );
1413 void GetColLabelAlignment( int *OUTPUT, int *OUTPUT );
1414 wxString GetRowLabelValue( int row );
1415 wxString GetColLabelValue( int col );
1416 wxColour GetGridLineColour();
1417 wxColour GetCellHighlightColour();
1418 int GetCellHighlightPenWidth();
1419 int GetCellHighlightROPenWidth();
1421 void SetRowLabelSize( int width );
1422 void SetColLabelSize( int height );
1423 void SetLabelBackgroundColour( const wxColour& );
1424 void SetLabelTextColour( const wxColour& );
1425 void SetLabelFont( const wxFont& );
1426 void SetRowLabelAlignment( int horiz, int vert );
1427 void SetColLabelAlignment( int horiz, int vert );
1428 void SetRowLabelValue( int row, const wxString& );
1429 void SetColLabelValue( int col, const wxString& );
1430 void SetGridLineColour( const wxColour& );
1431 void SetCellHighlightColour( const wxColour& );
1432 void SetCellHighlightPenWidth(int width);
1433 void SetCellHighlightROPenWidth(int width);
1435 void EnableDragRowSize( bool enable = TRUE );
1436 void DisableDragRowSize();
1437 bool CanDragRowSize();
1438 void EnableDragColSize( bool enable = TRUE );
1439 void DisableDragColSize();
1440 bool CanDragColSize();
1441 void EnableDragGridSize(bool enable = TRUE);
1442 void DisableDragGridSize();
1443 bool CanDragGridSize();
1445 // this sets the specified attribute for all cells in this row/col
1446 void SetRowAttr(int row, wxGridCellAttr *attr);
1447 void SetColAttr(int col, wxGridCellAttr *attr);
1449 // shortcuts for setting the column parameters
1451 // set the format for the data in the column: default is string
1452 void SetColFormatBool(int col);
1453 void SetColFormatNumber(int col);
1454 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1455 void SetColFormatCustom(int col, const wxString& typeName);
1457 void EnableGridLines( bool enable = TRUE );
1458 bool GridLinesEnabled();
1460 // ------ row and col formatting
1462 int GetDefaultRowSize();
1463 int GetRowSize( int row );
1464 int GetDefaultColSize();
1465 int GetColSize( int col );
1466 wxColour GetDefaultCellBackgroundColour();
1467 wxColour GetCellBackgroundColour( int row, int col );
1468 wxColour GetDefaultCellTextColour();
1469 wxColour GetCellTextColour( int row, int col );
1470 wxFont GetDefaultCellFont();
1471 wxFont GetCellFont( int row, int col );
1472 void GetDefaultCellAlignment( int *horiz, int *vert );
1473 void GetCellAlignment( int row, int col, int *horiz, int *vert );
1475 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
1476 void SetRowSize( int row, int height );
1477 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
1479 void SetColSize( int col, int width );
1481 // automatically size the column or row to fit to its contents, if
1482 // setAsMin is TRUE, this optimal width will also be set as minimal width
1484 void AutoSizeColumn( int col, bool setAsMin = TRUE );
1485 void AutoSizeRow( int row, bool setAsMin = TRUE );
1488 // auto size all columns (very ineffective for big grids!)
1489 void AutoSizeColumns( bool setAsMin = TRUE );
1490 void AutoSizeRows( bool setAsMin = TRUE );
1492 // auto size the grid, that is make the columns/rows of the "right" size
1493 // and also set the grid size to just fit its contents
1496 // column won't be resized to be lesser width - this must be called during
1497 // the grid creation because it won't resize the column if it's already
1498 // narrower than the minimal width
1499 void SetColMinimalWidth( int col, int width );
1500 void SetRowMinimalHeight( int row, int width );
1502 void SetDefaultCellBackgroundColour( const wxColour& );
1503 void SetCellBackgroundColour( int row, int col, const wxColour& );
1504 void SetDefaultCellTextColour( const wxColour& );
1506 void SetCellTextColour( int row, int col, const wxColour& );
1507 void SetDefaultCellFont( const wxFont& );
1508 void SetCellFont( int row, int col, const wxFont& );
1509 void SetDefaultCellAlignment( int horiz, int vert );
1510 void SetCellAlignment( int row, int col, int horiz, int vert );
1512 // takes ownership of the pointer
1513 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1514 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1515 wxGridCellRenderer *GetDefaultRenderer() const;
1516 wxGridCellRenderer* GetCellRenderer(int row, int col);
1518 // takes ownership of the pointer
1519 void SetDefaultEditor(wxGridCellEditor *editor);
1520 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1521 wxGridCellEditor *GetDefaultEditor() const;
1522 wxGridCellEditor* GetCellEditor(int row, int col);
1526 // ------ cell value accessors
1528 wxString GetCellValue( int row, int col );
1529 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1531 void SetCellValue( int row, int col, const wxString& s );
1532 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1534 // returns TRUE if the cell can't be edited
1535 bool IsReadOnly(int row, int col) const;
1537 // make the cell editable/readonly
1538 void SetReadOnly(int row, int col, bool isReadOnly = TRUE);
1540 // ------ selections of blocks of cells
1542 void SelectRow( int row, bool addToSelected = FALSE );
1543 void SelectCol( int col, bool addToSelected = FALSE );
1545 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1546 bool addToSelected = FALSE );
1547 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1548 // TODO: ??? const wxGridCellCoords& bottomRight )
1552 void ClearSelection();
1553 bool IsInSelection( int row, int col );
1554 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1557 // This function returns the rectangle that encloses the block of cells
1558 // limited by TopLeft and BottomRight cell in device coords and clipped
1559 // to the client size of the grid window.
1561 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1562 const wxGridCellCoords & bottomRight );
1565 // Access or update the selection fore/back colours
1566 wxColour GetSelectionBackground() const;
1567 wxColour GetSelectionForeground() const;
1569 void SetSelectionBackground(const wxColour& c);
1570 void SetSelectionForeground(const wxColour& c);
1573 // Methods for a registry for mapping data types to Renderers/Editors
1574 void RegisterDataType(const wxString& typeName,
1575 wxGridCellRenderer* renderer,
1576 wxGridCellEditor* editor);
1577 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1578 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1579 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1580 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1581 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1583 // grid may occupy more space than needed for its rows/columns, this
1584 // function allows to set how big this extra space is
1585 void SetMargins(int extraWidth, int extraHeight);
1588 // Accessors for component windows
1589 wxWindow* GetGridWindow();
1590 wxWindow* GetGridRowLabelWindow();
1591 wxWindow* GetGridColLabelWindow();
1592 wxWindow* GetGridCornerLabelWindow();
1598 //---------------------------------------------------------------------------
1599 //---------------------------------------------------------------------------
1600 // Grid events and stuff
1604 class wxGridEvent : public wxNotifyEvent
1607 wxGridEvent(int id, wxEventType type, wxGrid* obj,
1608 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = TRUE,
1609 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1611 virtual int GetRow();
1612 virtual int GetCol();
1613 wxPoint GetPosition();
1623 class wxGridSizeEvent : public wxNotifyEvent
1626 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
1627 int rowOrCol=-1, int x=-1, int y=-1,
1628 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1631 wxPoint GetPosition();
1640 class wxGridRangeSelectEvent : public wxNotifyEvent
1643 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
1644 const wxGridCellCoords& topLeft,
1645 const wxGridCellCoords& bottomRight,
1647 bool control=FALSE, bool shift=FALSE,
1648 bool alt=FALSE, bool meta=FALSE);
1650 wxGridCellCoords GetTopLeftCoords();
1651 wxGridCellCoords GetBottomRightCoords();
1664 class wxGridEditorCreatedEvent : public wxCommandEvent {
1666 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
1667 int row, int col, wxControl* ctrl);
1671 wxControl* GetControl();
1672 void SetRow(int row);
1673 void SetCol(int col);
1674 void SetControl(wxControl* ctrl);
1680 wxEVT_GRID_CELL_LEFT_CLICK,
1681 wxEVT_GRID_CELL_RIGHT_CLICK,
1682 wxEVT_GRID_CELL_LEFT_DCLICK,
1683 wxEVT_GRID_CELL_RIGHT_DCLICK,
1684 wxEVT_GRID_LABEL_LEFT_CLICK,
1685 wxEVT_GRID_LABEL_RIGHT_CLICK,
1686 wxEVT_GRID_LABEL_LEFT_DCLICK,
1687 wxEVT_GRID_LABEL_RIGHT_DCLICK,
1688 wxEVT_GRID_ROW_SIZE,
1689 wxEVT_GRID_COL_SIZE,
1690 wxEVT_GRID_RANGE_SELECT,
1691 wxEVT_GRID_CELL_CHANGE,
1692 wxEVT_GRID_SELECT_CELL,
1693 wxEVT_GRID_EDITOR_SHOWN,
1694 wxEVT_GRID_EDITOR_HIDDEN,
1695 wxEVT_GRID_EDITOR_CREATED,
1700 %pragma(python) code = "
1701 def EVT_GRID_CELL_LEFT_CLICK(win, fn):
1702 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_CLICK, fn)
1704 def EVT_GRID_CELL_RIGHT_CLICK(win, fn):
1705 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_CLICK, fn)
1707 def EVT_GRID_CELL_LEFT_DCLICK(win, fn):
1708 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_DCLICK, fn)
1710 def EVT_GRID_CELL_RIGHT_DCLICK(win, fn):
1711 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_DCLICK, fn)
1713 def EVT_GRID_LABEL_LEFT_CLICK(win, fn):
1714 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_CLICK, fn)
1716 def EVT_GRID_LABEL_RIGHT_CLICK(win, fn):
1717 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_CLICK, fn)
1719 def EVT_GRID_LABEL_LEFT_DCLICK(win, fn):
1720 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_DCLICK, fn)
1722 def EVT_GRID_LABEL_RIGHT_DCLICK(win, fn):
1723 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_DCLICK, fn)
1725 def EVT_GRID_ROW_SIZE(win, fn):
1726 win.Connect(-1, -1, wxEVT_GRID_ROW_SIZE, fn)
1728 def EVT_GRID_COL_SIZE(win, fn):
1729 win.Connect(-1, -1, wxEVT_GRID_COL_SIZE, fn)
1731 def EVT_GRID_RANGE_SELECT(win, fn):
1732 win.Connect(-1, -1, wxEVT_GRID_RANGE_SELECT, fn)
1734 def EVT_GRID_CELL_CHANGE(win, fn):
1735 win.Connect(-1, -1, wxEVT_GRID_CELL_CHANGE, fn)
1737 def EVT_GRID_SELECT_CELL(win, fn):
1738 win.Connect(-1, -1, wxEVT_GRID_SELECT_CELL, fn)
1740 def EVT_GRID_EDITOR_SHOWN(win, fn):
1741 win.Connect(-1, -1, wxEVT_GRID_EDITOR_SHOWN, fn)
1743 def EVT_GRID_EDITOR_HIDDEN(win, fn):
1744 win.Connect(-1, -1, wxEVT_GRID_EDITOR_HIDDEN, fn)
1746 def EVT_GRID_EDITOR_CREATED(win, fn):
1747 win.Connect(-1, -1, wxEVT_GRID_EDITOR_CREATED, fn)
1751 //---------------------------------------------------------------------------
1754 wxClassInfo::CleanUpClasses();
1755 wxClassInfo::InitializeClasses();
1758 //---------------------------------------------------------------------------
1760 %pragma(python) include="_gridextras.py";
1762 //---------------------------------------------------------------------------