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 );
1270 enum wxGridSelectionModes {wxGridSelectCells,
1272 wxGridSelectColumns};
1274 bool CreateGrid( int numRows, int numCols,
1275 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1276 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1279 // ------ grid dimensions
1281 int GetNumberRows();
1282 int GetNumberCols();
1286 #ifdef NOTNEEDED // ????
1287 // ------ display update functions
1289 void CalcRowLabelsExposed( wxRegion& reg );
1290 void CalcColLabelsExposed( wxRegion& reg );
1291 void CalcCellsExposed( wxRegion& reg );
1293 // ------ event handlers
1295 void ProcessRowLabelMouseEvent( wxMouseEvent& event );
1296 void ProcessColLabelMouseEvent( wxMouseEvent& event );
1297 void ProcessCornerLabelMouseEvent( wxMouseEvent& event );
1298 void ProcessGridCellMouseEvent( wxMouseEvent& event );
1299 void DoEndDragResizeRow();
1300 void DoEndDragResizeCol();
1303 bool ProcessTableMessage( wxGridTableMessage& );
1306 wxGridTableBase * GetTable() const;
1307 bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE,
1308 WXGRIDSELECTIONMODES selmode =
1309 wxGrid::wxGridSelectCells );
1312 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1313 bool AppendRows( int numRows = 1, bool updateLabels=TRUE );
1314 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1315 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1316 bool AppendCols( int numCols = 1, bool updateLabels=TRUE );
1317 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1319 #ifdef NOTNEEDED // ????
1320 void DrawGridCellArea( wxDC& dc );
1321 void DrawGridSpace( wxDC& dc );
1322 void DrawCellBorder( wxDC& dc, const wxGridCellCoords& );
1323 void DrawAllGridLines( wxDC& dc, const wxRegion & reg );
1324 void DrawCell( wxDC& dc, const wxGridCellCoords& );
1325 void DrawHighlight(wxDC& dc);
1328 // this function is called when the current cell highlight must be redrawn
1329 // and may be overridden by the user
1330 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1332 #ifdef NOTNEEDED // ????
1333 void DrawRowLabels( wxDC& dc );
1334 void DrawRowLabel( wxDC& dc, int row );
1336 void DrawColLabels( wxDC& dc );
1337 void DrawColLabel( wxDC& dc, int col );
1340 // ------ Cell text drawing functions
1342 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1343 int horizontalAlignment = wxLEFT,
1344 int verticalAlignment = wxTOP );
1346 // Split a string containing newline chararcters into an array of
1347 // strings and return the number of lines
1349 void StringToLines( const wxString& value, wxArrayString& lines );
1351 void GetTextBoxSize( wxDC& dc,
1352 wxArrayString& lines,
1353 long *OUTPUT, long *OUTPUT );
1357 // Code that does a lot of grid modification can be enclosed
1358 // between BeginBatch() and EndBatch() calls to avoid screen
1363 int GetBatchCount();
1366 // ------ edit control functions
1368 bool IsEditable() { return m_editable; }
1369 void EnableEditing( bool edit );
1371 void EnableCellEditControl( bool enable = TRUE );
1372 void DisableCellEditControl();
1373 bool CanEnableCellControl() const;
1374 bool IsCellEditControlEnabled() const;
1375 bool IsCellEditControlShown() const;
1377 bool IsCurrentCellReadOnly() const;
1379 void ShowCellEditControl();
1380 void HideCellEditControl();
1381 void SaveEditControlValue();
1384 // ------ grid location functions
1385 // Note that all of these functions work with the logical coordinates of
1386 // grid cells and labels so you will need to convert from device
1387 // coordinates for mouse events etc.
1390 //void XYToCell( int x, int y, wxGridCellCoords& );
1392 %new wxGridCellCoords* XYToCell(int x, int y) {
1393 wxGridCellCoords rv;
1394 self->XYToCell(x, y, rv);
1395 return new wxGridCellCoords(rv);
1399 int YToRow( int y );
1400 int XToCol( int x );
1402 int YToEdgeOfRow( int y );
1403 int XToEdgeOfCol( int x );
1405 wxRect CellToRect( int row, int col );
1406 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1409 int GetGridCursorRow();
1410 int GetGridCursorCol();
1412 // check to see if a cell is either wholly visible (the default arg) or
1413 // at least partially visible in the grid window
1415 bool IsVisible( int row, int col, bool wholeCellVisible = TRUE );
1416 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE );
1417 void MakeCellVisible( int row, int col );
1418 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1421 // ------ grid cursor movement functions
1423 void SetGridCursor( int row, int col );
1424 bool MoveCursorUp( bool expandSelection );
1425 bool MoveCursorDown( bool expandSelection );
1426 bool MoveCursorLeft( bool expandSelection );
1427 bool MoveCursorRight( bool expandSelection );
1428 bool MovePageDown();
1430 bool MoveCursorUpBlock( bool expandSelection );
1431 bool MoveCursorDownBlock( bool expandSelection );
1432 bool MoveCursorLeftBlock( bool expandSelection );
1433 bool MoveCursorRightBlock( bool expandSelection );
1436 // ------ label and gridline formatting
1438 int GetDefaultRowLabelSize();
1439 int GetRowLabelSize();
1440 int GetDefaultColLabelSize();
1441 int GetColLabelSize();
1442 wxColour GetLabelBackgroundColour();
1443 wxColour GetLabelTextColour();
1444 wxFont GetLabelFont();
1445 void GetRowLabelAlignment( int *OUTPUT, int *OUTPUT );
1446 void GetColLabelAlignment( int *OUTPUT, int *OUTPUT );
1447 wxString GetRowLabelValue( int row );
1448 wxString GetColLabelValue( int col );
1449 wxColour GetGridLineColour();
1450 wxColour GetCellHighlightColour();
1451 int GetCellHighlightPenWidth();
1452 int GetCellHighlightROPenWidth();
1454 void SetRowLabelSize( int width );
1455 void SetColLabelSize( int height );
1456 void SetLabelBackgroundColour( const wxColour& );
1457 void SetLabelTextColour( const wxColour& );
1458 void SetLabelFont( const wxFont& );
1459 void SetRowLabelAlignment( int horiz, int vert );
1460 void SetColLabelAlignment( int horiz, int vert );
1461 void SetRowLabelValue( int row, const wxString& );
1462 void SetColLabelValue( int col, const wxString& );
1463 void SetGridLineColour( const wxColour& );
1464 void SetCellHighlightColour( const wxColour& );
1465 void SetCellHighlightPenWidth(int width);
1466 void SetCellHighlightROPenWidth(int width);
1468 void EnableDragRowSize( bool enable = TRUE );
1469 void DisableDragRowSize();
1470 bool CanDragRowSize();
1471 void EnableDragColSize( bool enable = TRUE );
1472 void DisableDragColSize();
1473 bool CanDragColSize();
1474 void EnableDragGridSize(bool enable = TRUE);
1475 void DisableDragGridSize();
1476 bool CanDragGridSize();
1478 // this sets the specified attribute for all cells in this row/col
1479 void SetRowAttr(int row, wxGridCellAttr *attr);
1480 void SetColAttr(int col, wxGridCellAttr *attr);
1482 // shortcuts for setting the column parameters
1484 // set the format for the data in the column: default is string
1485 void SetColFormatBool(int col);
1486 void SetColFormatNumber(int col);
1487 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1488 void SetColFormatCustom(int col, const wxString& typeName);
1490 void EnableGridLines( bool enable = TRUE );
1491 bool GridLinesEnabled();
1493 // ------ row and col formatting
1495 int GetDefaultRowSize();
1496 int GetRowSize( int row );
1497 int GetDefaultColSize();
1498 int GetColSize( int col );
1499 wxColour GetDefaultCellBackgroundColour();
1500 wxColour GetCellBackgroundColour( int row, int col );
1501 wxColour GetDefaultCellTextColour();
1502 wxColour GetCellTextColour( int row, int col );
1503 wxFont GetDefaultCellFont();
1504 wxFont GetCellFont( int row, int col );
1505 void GetDefaultCellAlignment( int *horiz, int *vert );
1506 void GetCellAlignment( int row, int col, int *horiz, int *vert );
1508 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
1509 void SetRowSize( int row, int height );
1510 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
1512 void SetColSize( int col, int width );
1514 // automatically size the column or row to fit to its contents, if
1515 // setAsMin is TRUE, this optimal width will also be set as minimal width
1517 void AutoSizeColumn( int col, bool setAsMin = TRUE );
1518 void AutoSizeRow( int row, bool setAsMin = TRUE );
1521 // auto size all columns (very ineffective for big grids!)
1522 void AutoSizeColumns( bool setAsMin = TRUE );
1523 void AutoSizeRows( bool setAsMin = TRUE );
1525 // auto size the grid, that is make the columns/rows of the "right" size
1526 // and also set the grid size to just fit its contents
1529 // column won't be resized to be lesser width - this must be called during
1530 // the grid creation because it won't resize the column if it's already
1531 // narrower than the minimal width
1532 void SetColMinimalWidth( int col, int width );
1533 void SetRowMinimalHeight( int row, int width );
1535 void SetDefaultCellBackgroundColour( const wxColour& );
1536 void SetCellBackgroundColour( int row, int col, const wxColour& );
1537 void SetDefaultCellTextColour( const wxColour& );
1539 void SetCellTextColour( int row, int col, const wxColour& );
1540 void SetDefaultCellFont( const wxFont& );
1541 void SetCellFont( int row, int col, const wxFont& );
1542 void SetDefaultCellAlignment( int horiz, int vert );
1543 void SetCellAlignment( int row, int col, int horiz, int vert );
1545 // takes ownership of the pointer
1546 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1547 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1548 wxGridCellRenderer *GetDefaultRenderer() const;
1549 wxGridCellRenderer* GetCellRenderer(int row, int col);
1551 // takes ownership of the pointer
1552 void SetDefaultEditor(wxGridCellEditor *editor);
1553 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1554 wxGridCellEditor *GetDefaultEditor() const;
1555 wxGridCellEditor* GetCellEditor(int row, int col);
1559 // ------ cell value accessors
1561 wxString GetCellValue( int row, int col );
1562 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1564 void SetCellValue( int row, int col, const wxString& s );
1565 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1567 // returns TRUE if the cell can't be edited
1568 bool IsReadOnly(int row, int col) const;
1570 // make the cell editable/readonly
1571 void SetReadOnly(int row, int col, bool isReadOnly = TRUE);
1573 // ------ selections of blocks of cells
1575 void SelectRow( int row, bool addToSelected = FALSE );
1576 void SelectCol( int col, bool addToSelected = FALSE );
1578 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1579 bool addToSelected = FALSE );
1580 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1581 // TODO: ??? const wxGridCellCoords& bottomRight )
1585 void ClearSelection();
1586 bool IsInSelection( int row, int col );
1587 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1590 // This function returns the rectangle that encloses the block of cells
1591 // limited by TopLeft and BottomRight cell in device coords and clipped
1592 // to the client size of the grid window.
1594 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1595 const wxGridCellCoords & bottomRight );
1598 // Access or update the selection fore/back colours
1599 wxColour GetSelectionBackground() const;
1600 wxColour GetSelectionForeground() const;
1602 void SetSelectionBackground(const wxColour& c);
1603 void SetSelectionForeground(const wxColour& c);
1606 // Methods for a registry for mapping data types to Renderers/Editors
1607 void RegisterDataType(const wxString& typeName,
1608 wxGridCellRenderer* renderer,
1609 wxGridCellEditor* editor);
1610 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1611 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1612 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1613 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1614 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1616 // grid may occupy more space than needed for its rows/columns, this
1617 // function allows to set how big this extra space is
1618 void SetMargins(int extraWidth, int extraHeight);
1621 // Accessors for component windows
1622 wxWindow* GetGridWindow();
1623 wxWindow* GetGridRowLabelWindow();
1624 wxWindow* GetGridColLabelWindow();
1625 wxWindow* GetGridCornerLabelWindow();
1631 //---------------------------------------------------------------------------
1632 //---------------------------------------------------------------------------
1633 // Grid events and stuff
1637 class wxGridEvent : public wxNotifyEvent
1640 wxGridEvent(int id, wxEventType type, wxGrid* obj,
1641 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = TRUE,
1642 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1644 virtual int GetRow();
1645 virtual int GetCol();
1646 wxPoint GetPosition();
1656 class wxGridSizeEvent : public wxNotifyEvent
1659 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
1660 int rowOrCol=-1, int x=-1, int y=-1,
1661 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1664 wxPoint GetPosition();
1673 class wxGridRangeSelectEvent : public wxNotifyEvent
1676 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
1677 const wxGridCellCoords& topLeft,
1678 const wxGridCellCoords& bottomRight,
1680 bool control=FALSE, bool shift=FALSE,
1681 bool alt=FALSE, bool meta=FALSE);
1683 wxGridCellCoords GetTopLeftCoords();
1684 wxGridCellCoords GetBottomRightCoords();
1697 class wxGridEditorCreatedEvent : public wxCommandEvent {
1699 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
1700 int row, int col, wxControl* ctrl);
1704 wxControl* GetControl();
1705 void SetRow(int row);
1706 void SetCol(int col);
1707 void SetControl(wxControl* ctrl);
1713 wxEVT_GRID_CELL_LEFT_CLICK,
1714 wxEVT_GRID_CELL_RIGHT_CLICK,
1715 wxEVT_GRID_CELL_LEFT_DCLICK,
1716 wxEVT_GRID_CELL_RIGHT_DCLICK,
1717 wxEVT_GRID_LABEL_LEFT_CLICK,
1718 wxEVT_GRID_LABEL_RIGHT_CLICK,
1719 wxEVT_GRID_LABEL_LEFT_DCLICK,
1720 wxEVT_GRID_LABEL_RIGHT_DCLICK,
1721 wxEVT_GRID_ROW_SIZE,
1722 wxEVT_GRID_COL_SIZE,
1723 wxEVT_GRID_RANGE_SELECT,
1724 wxEVT_GRID_CELL_CHANGE,
1725 wxEVT_GRID_SELECT_CELL,
1726 wxEVT_GRID_EDITOR_SHOWN,
1727 wxEVT_GRID_EDITOR_HIDDEN,
1728 wxEVT_GRID_EDITOR_CREATED,
1733 %pragma(python) code = "
1734 def EVT_GRID_CELL_LEFT_CLICK(win, fn):
1735 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_CLICK, fn)
1737 def EVT_GRID_CELL_RIGHT_CLICK(win, fn):
1738 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_CLICK, fn)
1740 def EVT_GRID_CELL_LEFT_DCLICK(win, fn):
1741 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_DCLICK, fn)
1743 def EVT_GRID_CELL_RIGHT_DCLICK(win, fn):
1744 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_DCLICK, fn)
1746 def EVT_GRID_LABEL_LEFT_CLICK(win, fn):
1747 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_CLICK, fn)
1749 def EVT_GRID_LABEL_RIGHT_CLICK(win, fn):
1750 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_CLICK, fn)
1752 def EVT_GRID_LABEL_LEFT_DCLICK(win, fn):
1753 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_DCLICK, fn)
1755 def EVT_GRID_LABEL_RIGHT_DCLICK(win, fn):
1756 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_DCLICK, fn)
1758 def EVT_GRID_ROW_SIZE(win, fn):
1759 win.Connect(-1, -1, wxEVT_GRID_ROW_SIZE, fn)
1761 def EVT_GRID_COL_SIZE(win, fn):
1762 win.Connect(-1, -1, wxEVT_GRID_COL_SIZE, fn)
1764 def EVT_GRID_RANGE_SELECT(win, fn):
1765 win.Connect(-1, -1, wxEVT_GRID_RANGE_SELECT, fn)
1767 def EVT_GRID_CELL_CHANGE(win, fn):
1768 win.Connect(-1, -1, wxEVT_GRID_CELL_CHANGE, fn)
1770 def EVT_GRID_SELECT_CELL(win, fn):
1771 win.Connect(-1, -1, wxEVT_GRID_SELECT_CELL, fn)
1773 def EVT_GRID_EDITOR_SHOWN(win, fn):
1774 win.Connect(-1, -1, wxEVT_GRID_EDITOR_SHOWN, fn)
1776 def EVT_GRID_EDITOR_HIDDEN(win, fn):
1777 win.Connect(-1, -1, wxEVT_GRID_EDITOR_HIDDEN, fn)
1779 def EVT_GRID_EDITOR_CREATED(win, fn):
1780 win.Connect(-1, -1, wxEVT_GRID_EDITOR_CREATED, fn)
1784 //---------------------------------------------------------------------------
1787 wxClassInfo::CleanUpClasses();
1788 wxClassInfo::InitializeClasses();
1791 //---------------------------------------------------------------------------
1793 %pragma(python) include="_gridextras.py";
1795 //---------------------------------------------------------------------------