1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG definitions for the new wxGrid and related classes
7 // Created: 17-March-2000
9 // Copyright: (c) 2000 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
22 //----------------------------------------------------------------------
25 %include my_typemaps.i
27 // Import some definitions of other classes, etc.
35 %pragma(python) code = "import wx"
37 //---------------------------------------------------------------------------
38 //---------------------------------------------------------------------------
39 // Macros, similar to what's in helpers.h, to aid in the creation of
40 // virtual methods that are able to make callbacks to Python. Many of these
41 // are specific to wxGrid and so are kept here to reduce the mess in helpers.h
46 #define PYCALLBACK_GCA_INTINT(PCLASS, CBNAME) \
47 wxGridCellAttr* CBNAME(int a, int b) { \
48 wxGridCellAttr* rval = NULL; \
49 bool doSave = wxPyRestoreThread(); \
50 if (m_myInst.findCallback(#CBNAME)) { \
52 wxGridCellAttr* ptr; \
53 ro = m_myInst.callCallbackObj(Py_BuildValue("(ii)", a, b)); \
55 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellAttr_p")) \
61 rval = PCLASS::CBNAME(a, b); \
62 wxPySaveThread(doSave); \
65 wxGridCellAttr *base_##CBNAME(int a, int b) { \
66 return PCLASS::CBNAME(a, b); \
71 #define PYCALLBACK__GCAINTINT(PCLASS, CBNAME) \
72 void CBNAME(wxGridCellAttr *attr, int a, int b) { \
73 bool doSave = wxPyRestoreThread(); \
74 if (m_myInst.findCallback(#CBNAME)) \
75 m_myInst.callCallback( \
76 Py_BuildValue("(Oii)", \
77 wxPyConstructObject((void*)attr, "wxGridCellAttr"), \
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 (m_myInst.findCallback(#CBNAME)) \
93 m_myInst.callCallback( \
94 Py_BuildValue("(Oi)", \
95 wxPyConstructObject((void*)attr, "wxGridCellAttr"), \
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 (m_myInst.findCallback(#CBNAME)) \
112 rval = m_myInst.callCallback(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 (m_myInst.findCallback(#CBNAME)) \
124 rval = m_myInst.callCallback(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 (m_myInst.findCallback(#CBNAME)) { \
137 ro = m_myInst.callCallbackObj(Py_BuildValue("(ii)",a,b)); \
139 rval = PyString_AsString(PyObject_Str(ro)); \
143 wxPySaveThread(doSave); \
149 #define PYCALLBACK__INTINTSTRING_pure(CBNAME) \
150 void CBNAME(int a, int b, const wxString& c) { \
151 bool doSave = wxPyRestoreThread(); \
152 if (m_myInst.findCallback(#CBNAME)) \
153 m_myInst.callCallback(Py_BuildValue("(iis)",a,b,c.c_str())); \
154 wxPySaveThread(doSave); \
158 #define PYCALLBACK_STRING_INTINT(PCLASS, CBNAME) \
159 wxString CBNAME(int a, int b) { \
160 bool doSave = wxPyRestoreThread(); \
162 if (m_myInst.findCallback(#CBNAME)) { \
164 ro = m_myInst.callCallbackObj(Py_BuildValue("(ii)",a,b)); \
166 rval = PyString_AsString(PyObject_Str(ro)); \
170 rval = PCLASS::CBNAME(a, b); \
171 wxPySaveThread(doSave); \
174 wxString base_##CBNAME(int a, int b) { \
175 return PCLASS::CBNAME(a, b); \
180 #define PYCALLBACK_BOOL_INTINTSTRING(PCLASS, CBNAME) \
181 bool CBNAME(int a, int b, const wxString& c) { \
183 bool doSave = wxPyRestoreThread(); \
184 if (m_myInst.findCallback(#CBNAME)) \
185 rval = m_myInst.callCallback(Py_BuildValue("(iis)", a,b,c.c_str())); \
187 rval = PCLASS::CBNAME(a,b,c); \
188 wxPySaveThread(doSave); \
191 bool base_##CBNAME(int a, int b, const wxString& c) { \
192 return PCLASS::CBNAME(a,b,c); \
198 #define PYCALLBACK_LONG_INTINT(PCLASS, CBNAME) \
199 long CBNAME(int a, int b) { \
201 bool doSave = wxPyRestoreThread(); \
202 if (m_myInst.findCallback(#CBNAME)) \
203 rval = m_myInst.callCallback(Py_BuildValue("(ii)", a,b)); \
205 rval = PCLASS::CBNAME(a,b); \
206 wxPySaveThread(doSave); \
209 long base_##CBNAME(int a, int b) { \
210 return PCLASS::CBNAME(a,b); \
215 #define PYCALLBACK_BOOL_INTINT(PCLASS, CBNAME) \
216 bool CBNAME(int a, int b) { \
218 bool doSave = wxPyRestoreThread(); \
219 if (m_myInst.findCallback(#CBNAME)) \
220 rval = m_myInst.callCallback(Py_BuildValue("(ii)", a,b)); \
222 rval = PCLASS::CBNAME(a,b); \
223 wxPySaveThread(doSave); \
226 bool base_##CBNAME(int a, int b) { \
227 return PCLASS::CBNAME(a,b); \
232 #define PYCALLBACK_DOUBLE_INTINT(PCLASS, CBNAME) \
233 double CBNAME(int a, int b) { \
234 bool doSave = wxPyRestoreThread(); \
236 if (m_myInst.findCallback(#CBNAME)) { \
238 ro = m_myInst.callCallbackObj(Py_BuildValue("(ii)",a,b)); \
240 rval = PyFloat_AsDouble(PyObject_Str(ro)); \
244 rval = PCLASS::CBNAME(a, b); \
245 wxPySaveThread(doSave); \
248 double base_##CBNAME(int a, int b) { \
249 return PCLASS::CBNAME(a, b); \
254 #define PYCALLBACK__(PCLASS, CBNAME) \
256 bool doSave = wxPyRestoreThread(); \
257 if (m_myInst.findCallback(#CBNAME)) \
258 m_myInst.callCallback(Py_BuildValue("()")); \
261 wxPySaveThread(doSave); \
263 void base_##CBNAME() { \
270 #define PYCALLBACK_BOOL_SIZETSIZET(PCLASS, CBNAME) \
271 bool CBNAME(size_t a, size_t b) { \
273 bool doSave = wxPyRestoreThread(); \
274 if (m_myInst.findCallback(#CBNAME)) \
275 rval = m_myInst.callCallback(Py_BuildValue("(ii)", a,b)); \
277 rval = PCLASS::CBNAME(a,b); \
278 wxPySaveThread(doSave); \
281 bool base_##CBNAME(size_t a, size_t b) { \
282 return PCLASS::CBNAME(a,b); \
287 #define PYCALLBACK_BOOL_SIZET(PCLASS, CBNAME) \
288 bool CBNAME(size_t a) { \
290 bool doSave = wxPyRestoreThread(); \
291 if (m_myInst.findCallback(#CBNAME)) \
292 rval = m_myInst.callCallback(Py_BuildValue("(i)", a)); \
294 rval = PCLASS::CBNAME(a); \
295 wxPySaveThread(doSave); \
298 bool base_##CBNAME(size_t a) { \
299 return PCLASS::CBNAME(a); \
304 #define PYCALLBACK_STRING_INT(PCLASS, CBNAME) \
305 wxString CBNAME(int a) { \
306 bool doSave = wxPyRestoreThread(); \
308 if (m_myInst.findCallback(#CBNAME)) { \
310 ro = m_myInst.callCallbackObj(Py_BuildValue("(i)",a)); \
312 rval = PyString_AsString(PyObject_Str(ro)); \
316 rval = PCLASS::CBNAME(a); \
317 wxPySaveThread(doSave); \
320 wxString base_##CBNAME(int a) { \
321 return PCLASS::CBNAME(a); \
326 #define PYCALLBACK__INTSTRING(PCLASS, CBNAME) \
327 void CBNAME(int a, const wxString& c) { \
328 bool doSave = wxPyRestoreThread(); \
329 if (m_myInst.findCallback(#CBNAME)) \
330 m_myInst.callCallback(Py_BuildValue("(is)", a,c.c_str())); \
332 PCLASS::CBNAME(a,c); \
333 wxPySaveThread(doSave); \
335 void base_##CBNAME(int a, const wxString& c) { \
336 PCLASS::CBNAME(a,c); \
342 #define PYCALLBACK_BOOL_(PCLASS, CBNAME) \
345 bool doSave = wxPyRestoreThread(); \
346 if (m_myInst.findCallback(#CBNAME)) \
347 rval = m_myInst.callCallback(Py_BuildValue("()")); \
349 rval = PCLASS::CBNAME(); \
350 wxPySaveThread(doSave); \
353 bool base_##CBNAME() { \
354 return PCLASS::CBNAME(); \
359 #define PYCALLBACK__SIZETINT(PCLASS, CBNAME) \
360 void CBNAME(size_t a, int b) { \
361 bool doSave = wxPyRestoreThread(); \
362 if (m_myInst.findCallback(#CBNAME)) \
363 m_myInst.callCallback(Py_BuildValue("(ii)", a,b)); \
365 PCLASS::CBNAME(a,b); \
366 wxPySaveThread(doSave); \
368 void base_##CBNAME(size_t a, int b) { \
369 PCLASS::CBNAME(a,b); \
375 #define PYCALLBACK__INTINTLONG(PCLASS, CBNAME) \
376 void CBNAME(int a, int b, long c) { \
377 bool doSave = wxPyRestoreThread(); \
378 if (m_myInst.findCallback(#CBNAME)) \
379 m_myInst.callCallback(Py_BuildValue("(iii)", a,b,c)); \
381 PCLASS::CBNAME(a,b,c); \
382 wxPySaveThread(doSave); \
384 void base_##CBNAME(int a, int b, long c) { \
385 PCLASS::CBNAME(a,b,c); \
391 #define PYCALLBACK__INTINTDOUBLE(PCLASS, CBNAME) \
392 void CBNAME(int a, int b, double c) { \
393 bool doSave = wxPyRestoreThread(); \
394 if (m_myInst.findCallback(#CBNAME)) \
395 m_myInst.callCallback(Py_BuildValue("(iif)", a,b,c)); \
397 PCLASS::CBNAME(a,b,c); \
398 wxPySaveThread(doSave); \
400 void base_##CBNAME(int a, int b, double c) { \
401 PCLASS::CBNAME(a,b,c); \
406 #define PYCALLBACK__INTINTBOOL(PCLASS, CBNAME) \
407 void CBNAME(int a, int b, bool c) { \
408 bool doSave = wxPyRestoreThread(); \
409 if (m_myInst.findCallback(#CBNAME)) \
410 m_myInst.callCallback(Py_BuildValue("(iii)", a,b,c)); \
412 PCLASS::CBNAME(a,b,c); \
413 wxPySaveThread(doSave); \
415 void base_##CBNAME(int a, int b, bool c) { \
416 PCLASS::CBNAME(a,b,c); \
424 //---------------------------------------------------------------------------
426 class wxGridCellCoords;
427 class wxGridCellAttr;
431 #define wxGRID_VALUE_STRING "string"
432 #define wxGRID_VALUE_BOOL "bool"
433 #define wxGRID_VALUE_NUMBER "long"
434 #define wxGRID_VALUE_FLOAT "double"
435 #define wxGRID_VALUE_CHOICE "choice"
436 #define wxGRID_VALUE_TEXT "string"
437 #define wxGRID_VALUE_LONG "long"
440 wxGridCellCoords wxGridNoCellCoords;
441 wxRect wxGridNoCellRect;
445 //---------------------------------------------------------------------------
446 // wxGridCellRenderer is an ABC, and several derived classes are available.
447 // Classes implemented in Python should be derived from wxPyGridCellRenderer.
450 class wxGridCellRenderer
453 void SetParameters(const wxString& params);
457 virtual void Draw(wxGrid& grid,
458 wxGridCellAttr& attr,
462 bool isSelected) = 0;
463 virtual wxSize GetBestSize(wxGrid& grid,
464 wxGridCellAttr& attr,
466 int row, int col) = 0;
467 virtual wxGridCellRenderer *Clone() const = 0;
471 // The C++ version of wxPyGridCellRenderer
473 class wxPyGridCellRenderer : public wxGridCellRenderer
476 wxPyGridCellRenderer() : wxGridCellRenderer() {};
478 // Implement Python callback aware virtual methods
479 void Draw(wxGrid& grid, wxGridCellAttr& attr,
480 wxDC& dc, const wxRect& rect,
481 int row, int col, bool isSelected) {
482 bool doSave = wxPyRestoreThread();
483 if (m_myInst.findCallback("Draw")) {
484 m_myInst.callCallback(
485 Py_BuildValue("(OOOOiii)",
486 wxPyConstructObject((void*)&grid, "wxGrid"),
487 wxPyConstructObject((void*)&attr, "wxGridCellAttr"),
488 wxPyConstructObject((void*)&dc, "wxDC"),
489 wxPyConstructObject((void*)&rect, "wxRect"),
490 row, col, isSelected));
492 wxPySaveThread(doSave);
495 wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
498 bool doSave = wxPyRestoreThread();
499 if (m_myInst.findCallback("GetBestSize")) {
502 ro = m_myInst.callCallbackObj(
503 Py_BuildValue("(OOOii)",
504 wxPyConstructObject((void*)&grid, "wxGrid"),
505 wxPyConstructObject((void*)&attr, "wxGridCellAttr"),
506 wxPyConstructObject((void*)&dc, "wxDC"),
509 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p"))
514 wxPySaveThread(doSave);
519 wxGridCellRenderer *Clone() const {
520 wxGridCellRenderer* rval = NULL;
521 bool doSave = wxPyRestoreThread();
522 if (m_myInst.findCallback("Clone")) {
524 wxGridCellRenderer* ptr;
525 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
527 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellRenderer_p"))
532 wxPySaveThread(doSave);
536 DEC_PYCALLBACK__STRING(SetParameters);
541 IMP_PYCALLBACK__STRING( wxPyGridCellRenderer, wxGridCellRenderer, SetParameters);
546 // Let SWIG know about it so it can create the Python version
547 class wxPyGridCellRenderer : public wxGridCellRenderer {
549 wxPyGridCellRenderer();
550 void _setSelf(PyObject* self, PyObject* _class);
551 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyGridCellRenderer)"
553 void base_SetParameters(const wxString& params);
556 //---------------------------------------------------------------------------
557 // Predefined Renderers
559 class wxGridCellStringRenderer : public wxGridCellRenderer
562 wxGridCellStringRenderer();
566 class wxGridCellNumberRenderer : public wxGridCellStringRenderer
569 wxGridCellNumberRenderer();
573 class wxGridCellFloatRenderer : public wxGridCellStringRenderer
576 wxGridCellFloatRenderer(int width = -1, int precision = -1);
578 int GetWidth() const;
579 void SetWidth(int width);
580 int GetPrecision() const;
581 void SetPrecision(int precision);
585 class wxGridCellBoolRenderer : public wxGridCellRenderer
588 wxGridCellBoolRenderer();
593 //---------------------------------------------------------------------------
594 // wxGridCellEditor is an ABC, and several derived classes are available.
595 // Classes implemented in Python should be derived from wxPyGridCellEditor.
597 class wxGridCellEditor
601 wxControl* GetControl();
602 void SetControl(wxControl* control);
604 void SetParameters(const wxString& params);
608 virtual void Create(wxWindow* parent,
610 wxEvtHandler* evtHandler) = 0;
611 virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
612 virtual bool EndEdit(int row, int col, wxGrid* grid) = 0;
613 virtual void Reset() = 0;
614 virtual wxGridCellEditor *Clone() const = 0;
616 virtual void SetSize(const wxRect& rect);
617 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
618 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
619 virtual bool IsAcceptedKey(wxKeyEvent& event);
620 virtual void StartingKey(wxKeyEvent& event);
621 virtual void StartingClick();
622 virtual void HandleReturn(wxKeyEvent& event);
623 virtual void Destroy();
628 // The C++ version of wxPyGridCellEditor
630 class wxPyGridCellEditor : public wxGridCellEditor
633 wxPyGridCellEditor() : wxGridCellEditor() {}
635 void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) {
636 bool doSave = wxPyRestoreThread();
637 if (m_myInst.findCallback("Create")) {
638 m_myInst.callCallback(
639 Py_BuildValue("(OiO)",
640 wxPyConstructObject((void*)parent, "wxWindow"),
642 wxPyConstructObject((void*)evtHandler, "wxEvtHandler")));
644 wxPySaveThread(doSave);
648 void BeginEdit(int row, int col, wxGrid* grid) {
649 bool doSave = wxPyRestoreThread();
650 if (m_myInst.findCallback("BeginEdit")) {
651 m_myInst.callCallback(
652 Py_BuildValue("(iiO)", row, col,
653 wxPyConstructObject((void*)grid, "wxGrid")));
655 wxPySaveThread(doSave);
659 bool EndEdit(int row, int col, wxGrid* grid) {
661 bool doSave = wxPyRestoreThread();
662 if (m_myInst.findCallback("EndEdit")) {
663 rv = m_myInst.callCallback(
664 Py_BuildValue("(iiO)", row, col,
665 wxPyConstructObject((void*)grid, "wxGrid")));
667 wxPySaveThread(doSave);
672 wxGridCellEditor*Clone() const {
673 wxGridCellEditor* rval = NULL;
674 bool doSave = wxPyRestoreThread();
675 if (m_myInst.findCallback("Clone")) {
677 wxGridCellEditor* ptr;
678 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
680 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellEditor_p"))
685 wxPySaveThread(doSave);
690 void Show(bool show, wxGridCellAttr *attr) {
691 bool doSave = wxPyRestoreThread();
692 if (m_myInst.findCallback("Show"))
693 m_myInst.callCallback(
694 Py_BuildValue("(iO)", show,
695 wxPyConstructObject((void*)attr, "wxGridCellAttr")));
697 wxGridCellEditor::Show(show, attr);
698 wxPySaveThread(doSave);
700 void base_Show(bool show, wxGridCellAttr *attr) {
701 wxGridCellEditor::Show(show, attr);
705 void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
706 bool doSave = wxPyRestoreThread();
707 if (m_myInst.findCallback("PaintBackground"))
708 m_myInst.callCallback(
709 Py_BuildValue("(OO)",
710 wxPyConstructObject((void*)&rectCell, "wxRect"),
711 wxPyConstructObject((void*)attr, "wxGridCellAttr")));
713 wxGridCellEditor::PaintBackground(rectCell, attr);
714 wxPySaveThread(doSave);
716 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
717 wxGridCellEditor::PaintBackground(rectCell, attr);
721 DEC_PYCALLBACK___pure(Reset);
722 DEC_PYCALLBACK__constany(SetSize, wxRect);
723 DEC_PYCALLBACK_bool_any(IsAcceptedKey, wxKeyEvent);
724 DEC_PYCALLBACK__any(StartingKey, wxKeyEvent);
725 DEC_PYCALLBACK__any(HandleReturn, wxKeyEvent);
726 DEC_PYCALLBACK__(StartingClick);
727 DEC_PYCALLBACK__(Destroy);
728 DEC_PYCALLBACK__STRING(SetParameters);
734 IMP_PYCALLBACK__STRING( wxPyGridCellEditor, wxGridCellEditor, SetParameters);
735 IMP_PYCALLBACK___pure(wxPyGridCellEditor, wxGridCellEditor, Reset);
736 IMP_PYCALLBACK__constany(wxPyGridCellEditor, wxGridCellEditor, SetSize, wxRect);
737 IMP_PYCALLBACK_bool_any(wxPyGridCellEditor, wxGridCellEditor, IsAcceptedKey, wxKeyEvent);
738 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, StartingKey, wxKeyEvent);
739 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, HandleReturn, wxKeyEvent);
740 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, StartingClick);
741 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, Destroy);
746 // Let SWIG know about it so it can create the Python version
747 class wxPyGridCellEditor : public wxGridCellEditor {
749 wxPyGridCellEditor();
750 void _setSelf(PyObject* self, PyObject* _class);
751 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyGridCellEditor)"
753 void base_SetSize(const wxRect& rect);
754 void base_Show(bool show, wxGridCellAttr *attr = NULL);
755 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
756 void base_IsAcceptedKey(wxKeyEvent& event);
757 void base_StartingKey(wxKeyEvent& event);
758 void base_StartingClick();
759 void base_HandleReturn(wxKeyEvent& event);
761 void base_SetParameters(const wxString& params);
764 //---------------------------------------------------------------------------
765 // Predefined Editors
767 class wxGridCellTextEditor : public wxGridCellEditor
770 wxGridCellTextEditor();
774 class wxGridCellNumberEditor : public wxGridCellTextEditor
777 wxGridCellNumberEditor(int min = -1, int max = -1);
781 class wxGridCellFloatEditor : public wxGridCellTextEditor
784 wxGridCellFloatEditor();
788 class wxGridCellBoolEditor : public wxGridCellEditor
791 wxGridCellBoolEditor();
794 class wxGridCellChoiceEditor : public wxGridCellEditor
797 wxGridCellChoiceEditor(int LCOUNT = 0,
798 const wxString* choices = NULL,
799 bool allowOthers = FALSE);
802 //---------------------------------------------------------------------------
810 wxGridCellAttr *Clone() const;
813 void SetTextColour(const wxColour& colText);
814 void SetBackgroundColour(const wxColour& colBack);
815 void SetFont(const wxFont& font);
816 void SetAlignment(int hAlign, int vAlign);
817 void SetReadOnly(bool isReadOnly = TRUE);
819 void SetRenderer(wxGridCellRenderer *renderer);
820 void SetEditor(wxGridCellEditor* editor);
822 bool HasTextColour() const;
823 bool HasBackgroundColour() const;
824 bool HasFont() const;
825 bool HasAlignment() const;
826 bool HasRenderer() const;
827 bool HasEditor() const;
829 const wxColour& GetTextColour() const;
830 const wxColour& GetBackgroundColour() const;
831 const wxFont& GetFont() const;
832 void GetAlignment(int *OUTPUT, int *OUTPUT) const;
833 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
834 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
836 bool IsReadOnly() const;
837 void SetDefAttr(wxGridCellAttr* defAttr);
840 //---------------------------------------------------------------------------
842 class wxGridCellAttrProvider
845 wxGridCellAttrProvider();
846 // ???? virtual ~wxGridCellAttrProvider();
848 wxGridCellAttr *GetAttr(int row, int col) const;
849 void SetAttr(wxGridCellAttr *attr, int row, int col);
850 void SetRowAttr(wxGridCellAttr *attr, int row);
851 void SetColAttr(wxGridCellAttr *attr, int col);
853 void UpdateAttrRows( size_t pos, int numRows );
854 void UpdateAttrCols( size_t pos, int numCols );
859 // A Python-aware version
861 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
864 wxPyGridCellAttrProvider() : wxGridCellAttrProvider() {};
866 PYCALLBACK_GCA_INTINT(wxGridCellAttrProvider, GetAttr);
867 PYCALLBACK__GCAINTINT(wxGridCellAttrProvider, SetAttr);
868 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetRowAttr);
869 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetColAttr);
876 // The python-aware version get's SWIGified
877 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
880 wxPyGridCellAttrProvider();
881 void _setSelf(PyObject* self, PyObject* _class);
882 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyGridCellAttrProvider)"
884 wxGridCellAttr *base_GetAttr(int row, int col);
885 void base_SetAttr(wxGridCellAttr *attr, int row, int col);
886 void base_SetRowAttr(wxGridCellAttr *attr, int row);
887 void base_SetColAttr(wxGridCellAttr *attr, int col);
891 //---------------------------------------------------------------------------
892 // Grid Table Base class and Python aware version
896 class wxGridTableBase
899 // wxGridTableBase(); This is an ABC
900 //~wxGridTableBase();
902 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
903 wxGridCellAttrProvider *GetAttrProvider() const;
904 void SetView( wxGrid *grid );
905 wxGrid * GetView() const;
909 virtual int GetNumberRows() = 0;
910 virtual int GetNumberCols() = 0;
911 virtual bool IsEmptyCell( int row, int col ) = 0;
912 virtual wxString GetValue( int row, int col ) = 0;
913 virtual void SetValue( int row, int col, const wxString& value ) = 0;
915 // virtuals overridable in wxPyGridTableBase
916 virtual wxString GetTypeName( int row, int col );
917 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
918 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
919 virtual long GetValueAsLong( int row, int col );
920 virtual double GetValueAsDouble( int row, int col );
921 virtual bool GetValueAsBool( int row, int col );
922 virtual void SetValueAsLong( int row, int col, long value );
923 virtual void SetValueAsDouble( int row, int col, double value );
924 virtual void SetValueAsBool( int row, int col, bool value );
926 //virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
927 //virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
930 virtual void Clear();
931 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
932 virtual bool AppendRows( size_t numRows = 1 );
933 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
934 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
935 virtual bool AppendCols( size_t numCols = 1 );
936 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
938 virtual wxString GetRowLabelValue( int row );
939 virtual wxString GetColLabelValue( int col );
940 virtual void SetRowLabelValue( int row, const wxString& value );
941 virtual void SetColLabelValue( int col, const wxString& value );
943 virtual bool CanHaveAttributes();
945 virtual wxGridCellAttr *GetAttr( int row, int col );
946 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
947 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
948 virtual void SetColAttr(wxGridCellAttr *attr, int col);
954 // Python-aware version
956 class wxPyGridTableBase : public wxGridTableBase
959 wxPyGridTableBase() : wxGridTableBase() {}
961 PYCALLBACK_INT__pure(GetNumberRows);
962 PYCALLBACK_INT__pure(GetNumberCols);
963 PYCALLBACK_BOOL_INTINT_pure(IsEmptyCell);
964 PYCALLBACK_STRING_INTINT(wxGridTableBase, GetTypeName);
965 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanGetValueAs);
966 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanSetValueAs);
967 PYCALLBACK__(wxGridTableBase, Clear);
968 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertRows);
969 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteRows);
970 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertCols);
971 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteCols);
972 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendRows);
973 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendCols);
974 PYCALLBACK_STRING_INT(wxGridTableBase, GetRowLabelValue);
975 PYCALLBACK_STRING_INT(wxGridTableBase, GetColLabelValue);
976 PYCALLBACK__INTSTRING(wxGridTableBase, SetRowLabelValue);
977 PYCALLBACK__INTSTRING(wxGridTableBase, SetColLabelValue);
978 PYCALLBACK_BOOL_(wxGridTableBase, CanHaveAttributes);
979 PYCALLBACK_GCA_INTINT(wxGridTableBase, GetAttr);
980 PYCALLBACK__GCAINTINT(wxGridTableBase, SetAttr);
981 PYCALLBACK__GCAINT(wxGridTableBase, SetRowAttr);
982 PYCALLBACK__GCAINT(wxGridTableBase, SetColAttr);
986 wxString GetValue(int row, int col) {
987 bool doSave = wxPyRestoreThread();
989 if (m_myInst.findCallback("GetValue")) {
991 ro = m_myInst.callCallbackObj(Py_BuildValue("(ii)",row,col));
993 rval = PyString_AsString(PyObject_Str(ro));
997 wxPySaveThread(doSave);
1001 void SetValue(int row, int col, const wxString& val) {
1002 bool doSave = wxPyRestoreThread();
1003 if (m_myInst.findCallback("SetValue"))
1004 m_myInst.callCallback(Py_BuildValue("(iis)",row,col,val.c_str()));
1005 wxPySaveThread(doSave);
1009 // Map the Get/Set methods for the standard non-string types to
1010 // the GetValue and SetValue python methods.
1011 long GetValueAsLong( int row, int col ) {
1013 bool doSave = wxPyRestoreThread();
1014 if (m_myInst.findCallback("GetValue")) {
1017 ro = m_myInst.callCallbackObj(Py_BuildValue("(ii)", row, col));
1018 if (ro && PyNumber_Check(ro)) {
1019 num = PyNumber_Int(ro);
1021 rval = PyInt_AsLong(num);
1027 wxPySaveThread(doSave);
1031 double GetValueAsDouble( int row, int col ) {
1033 bool doSave = wxPyRestoreThread();
1034 if (m_myInst.findCallback("GetValue")) {
1037 ro = m_myInst.callCallbackObj(Py_BuildValue("(ii)", row, col));
1038 if (ro && PyNumber_Check(ro)) {
1039 num = PyNumber_Float(ro);
1041 rval = PyFloat_AsDouble(num);
1047 wxPySaveThread(doSave);
1051 bool GetValueAsBool( int row, int col ) {
1052 return (bool)GetValueAsLong(row, col);
1055 void SetValueAsLong( int row, int col, long value ) {
1056 bool doSave = wxPyRestoreThread();
1057 if (m_myInst.findCallback("SetValue")) {
1058 m_myInst.callCallback(Py_BuildValue("(iii)", row, col, value));
1060 wxPySaveThread(doSave);
1063 void SetValueAsDouble( int row, int col, double value ) {
1064 bool doSave = wxPyRestoreThread();
1065 if (m_myInst.findCallback("SetValue")) {
1066 m_myInst.callCallback(Py_BuildValue("(iid)", row, col, value));
1068 wxPySaveThread(doSave);
1071 void SetValueAsBool( int row, int col, bool value ) {
1072 SetValueAsLong( row, col, (long)value );
1081 // The python-aware version get's SWIGified
1082 class wxPyGridTableBase : public wxGridTableBase
1085 wxPyGridTableBase();
1086 void _setSelf(PyObject* self, PyObject* _class);
1087 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyGridTableBase)"
1089 %addmethods { void Destroy() { delete self; } }
1091 wxString base_GetTypeName( int row, int col );
1092 bool base_CanGetValueAs( int row, int col, const wxString& typeName );
1093 bool base_CanSetValueAs( int row, int col, const wxString& typeName );
1095 bool base_InsertRows( size_t pos = 0, size_t numRows = 1 );
1096 bool base_AppendRows( size_t numRows = 1 );
1097 bool base_DeleteRows( size_t pos = 0, size_t numRows = 1 );
1098 bool base_InsertCols( size_t pos = 0, size_t numCols = 1 );
1099 bool base_AppendCols( size_t numCols = 1 );
1100 bool base_DeleteCols( size_t pos = 0, size_t numCols = 1 );
1101 wxString base_GetRowLabelValue( int row );
1102 wxString base_GetColLabelValue( int col );
1103 void base_SetRowLabelValue( int row, const wxString& value );
1104 void base_SetColLabelValue( int col, const wxString& value );
1105 bool base_CanHaveAttributes();
1106 wxGridCellAttr *base_GetAttr( int row, int col );
1107 void base_SetAttr(wxGridCellAttr* attr, int row, int col);
1108 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1109 void base_SetColAttr(wxGridCellAttr *attr, int col);
1113 //---------------------------------------------------------------------------
1114 // Predefined Tables
1116 class wxGridStringTable : public wxGridTableBase
1119 wxGridStringTable( int numRows=0, int numCols=0 );
1122 //---------------------------------------------------------------------------
1123 // The Table can pass messages to the grid to tell it to update itself if
1124 // something has changed.
1126 enum wxGridTableRequest
1128 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
1129 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
1130 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
1131 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
1132 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
1133 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1134 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
1135 wxGRIDTABLE_NOTIFY_COLS_DELETED
1139 class wxGridTableMessage
1142 wxGridTableMessage( wxGridTableBase *table, int id,
1145 ~wxGridTableMessage();
1147 void SetTableObject( wxGridTableBase *table );
1148 wxGridTableBase * GetTableObject() const;
1149 void SetId( int id );
1151 void SetCommandInt( int comInt1 );
1152 int GetCommandInt();
1153 void SetCommandInt2( int comInt2 );
1154 int GetCommandInt2();
1158 //---------------------------------------------------------------------------
1160 class wxGridCellCoords
1163 wxGridCellCoords( int r=-1, int c=-1 );
1164 ~wxGridCellCoords();
1166 int GetRow() const { return m_row; }
1167 void SetRow( int n ) { m_row = n; }
1168 int GetCol() const { return m_col; }
1169 void SetCol( int n ) { m_col = n; }
1170 void Set( int row, int col ) { m_row = row; m_col = col; }
1173 PyObject* asTuple() {
1174 PyObject* tup = PyTuple_New(2);
1175 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
1176 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
1180 int __cmp__( const wxGridCellCoords& other ) {
1181 return *self != other;
1184 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
1185 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
1188 // Typemap to allow conversion of sequence objects to wxGridCellCoords...
1189 %typemap(python,in) wxGridCellCoords& (wxGridCellCoords temp) {
1191 if (! wxGridCellCoords_helper($source, &$target))
1195 // ...and here is the associated helper.
1197 bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) {
1199 // If source is an object instance then it may already be the right type
1200 if (PyInstance_Check(source)) {
1201 wxGridCellCoords* ptr;
1202 if (SWIG_GetPtrObj(source, (void **)&ptr, "_wxGridCellCoords_p"))
1207 // otherwise a 2-tuple of integers is expected
1208 else if (PySequence_Check(source) && PyObject_Length(source) == 2) {
1209 PyObject* o1 = PySequence_GetItem(source, 0);
1210 PyObject* o2 = PySequence_GetItem(source, 1);
1211 **obj = wxGridCellCoords(PyInt_AsLong(o1), PyInt_AsLong(o2));
1216 PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of integers or a wxGridCellCoords object.");
1221 //---------------------------------------------------------------------------
1222 //---------------------------------------------------------------------------
1226 // Fool SWIG into treating this enum as an int
1227 typedef int WXGRIDSELECTIONMODES;
1229 // but let the C++ code know what it really is.
1231 typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES;
1236 class wxGrid : public wxScrolledWindow
1239 wxGrid( wxWindow *parent,
1241 const wxPoint& pos = wxDefaultPosition,
1242 const wxSize& size = wxDefaultSize,
1243 long style = wxWANTS_CHARS,
1244 const char* name = wxPanelNameStr );
1248 enum wxGridSelectionModes {wxGridSelectCells,
1250 wxGridSelectColumns};
1252 bool CreateGrid( int numRows, int numCols,
1253 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1254 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1257 // ------ grid dimensions
1259 int GetNumberRows();
1260 int GetNumberCols();
1264 #ifdef NOTNEEDED // ????
1265 // ------ display update functions
1267 void CalcRowLabelsExposed( wxRegion& reg );
1268 void CalcColLabelsExposed( wxRegion& reg );
1269 void CalcCellsExposed( wxRegion& reg );
1271 // ------ event handlers
1273 void ProcessRowLabelMouseEvent( wxMouseEvent& event );
1274 void ProcessColLabelMouseEvent( wxMouseEvent& event );
1275 void ProcessCornerLabelMouseEvent( wxMouseEvent& event );
1276 void ProcessGridCellMouseEvent( wxMouseEvent& event );
1277 void DoEndDragResizeRow();
1278 void DoEndDragResizeCol();
1281 bool ProcessTableMessage( wxGridTableMessage& );
1284 wxGridTableBase * GetTable() const;
1285 bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE,
1286 WXGRIDSELECTIONMODES selmode =
1287 wxGrid::wxGridSelectCells );
1290 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1291 bool AppendRows( int numRows = 1, bool updateLabels=TRUE );
1292 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1293 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1294 bool AppendCols( int numCols = 1, bool updateLabels=TRUE );
1295 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1297 #ifdef NOTNEEDED // ????
1298 void DrawGridCellArea( wxDC& dc );
1299 void DrawGridSpace( wxDC& dc );
1300 void DrawCellBorder( wxDC& dc, const wxGridCellCoords& );
1301 void DrawAllGridLines( wxDC& dc, const wxRegion & reg );
1302 void DrawCell( wxDC& dc, const wxGridCellCoords& );
1303 void DrawHighlight(wxDC& dc);
1306 // this function is called when the current cell highlight must be redrawn
1307 // and may be overridden by the user
1308 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1310 #ifdef NOTNEEDED // ????
1311 void DrawRowLabels( wxDC& dc );
1312 void DrawRowLabel( wxDC& dc, int row );
1314 void DrawColLabels( wxDC& dc );
1315 void DrawColLabel( wxDC& dc, int col );
1318 // ------ Cell text drawing functions
1320 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1321 int horizontalAlignment = wxLEFT,
1322 int verticalAlignment = wxTOP );
1324 // Split a string containing newline chararcters into an array of
1325 // strings and return the number of lines
1327 void StringToLines( const wxString& value, wxArrayString& lines );
1329 void GetTextBoxSize( wxDC& dc,
1330 wxArrayString& lines,
1331 long *OUTPUT, long *OUTPUT );
1335 // Code that does a lot of grid modification can be enclosed
1336 // between BeginBatch() and EndBatch() calls to avoid screen
1341 int GetBatchCount();
1344 // ------ edit control functions
1346 bool IsEditable() { return m_editable; }
1347 void EnableEditing( bool edit );
1349 void EnableCellEditControl( bool enable = TRUE );
1350 void DisableCellEditControl();
1351 bool CanEnableCellControl() const;
1352 bool IsCellEditControlEnabled() const;
1353 bool IsCellEditControlShown() const;
1355 bool IsCurrentCellReadOnly() const;
1357 void ShowCellEditControl();
1358 void HideCellEditControl();
1359 void SaveEditControlValue();
1362 // ------ grid location functions
1363 // Note that all of these functions work with the logical coordinates of
1364 // grid cells and labels so you will need to convert from device
1365 // coordinates for mouse events etc.
1368 //void XYToCell( int x, int y, wxGridCellCoords& );
1370 %new wxGridCellCoords* XYToCell(int x, int y) {
1371 wxGridCellCoords rv;
1372 self->XYToCell(x, y, rv);
1373 return new wxGridCellCoords(rv);
1377 int YToRow( int y );
1378 int XToCol( int x );
1380 int YToEdgeOfRow( int y );
1381 int XToEdgeOfCol( int x );
1383 wxRect CellToRect( int row, int col );
1384 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1387 int GetGridCursorRow();
1388 int GetGridCursorCol();
1390 // check to see if a cell is either wholly visible (the default arg) or
1391 // at least partially visible in the grid window
1393 bool IsVisible( int row, int col, bool wholeCellVisible = TRUE );
1394 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE );
1395 void MakeCellVisible( int row, int col );
1396 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1399 // ------ grid cursor movement functions
1401 void SetGridCursor( int row, int col );
1402 bool MoveCursorUp( bool expandSelection );
1403 bool MoveCursorDown( bool expandSelection );
1404 bool MoveCursorLeft( bool expandSelection );
1405 bool MoveCursorRight( bool expandSelection );
1406 bool MovePageDown();
1408 bool MoveCursorUpBlock( bool expandSelection );
1409 bool MoveCursorDownBlock( bool expandSelection );
1410 bool MoveCursorLeftBlock( bool expandSelection );
1411 bool MoveCursorRightBlock( bool expandSelection );
1414 // ------ label and gridline formatting
1416 int GetDefaultRowLabelSize();
1417 int GetRowLabelSize();
1418 int GetDefaultColLabelSize();
1419 int GetColLabelSize();
1420 wxColour GetLabelBackgroundColour();
1421 wxColour GetLabelTextColour();
1422 wxFont GetLabelFont();
1423 void GetRowLabelAlignment( int *OUTPUT, int *OUTPUT );
1424 void GetColLabelAlignment( int *OUTPUT, int *OUTPUT );
1425 wxString GetRowLabelValue( int row );
1426 wxString GetColLabelValue( int col );
1427 wxColour GetGridLineColour();
1428 wxColour GetCellHighlightColour();
1430 void SetRowLabelSize( int width );
1431 void SetColLabelSize( int height );
1432 void SetLabelBackgroundColour( const wxColour& );
1433 void SetLabelTextColour( const wxColour& );
1434 void SetLabelFont( const wxFont& );
1435 void SetRowLabelAlignment( int horiz, int vert );
1436 void SetColLabelAlignment( int horiz, int vert );
1437 void SetRowLabelValue( int row, const wxString& );
1438 void SetColLabelValue( int col, const wxString& );
1439 void SetGridLineColour( const wxColour& );
1440 void SetCellHighlightColour( const wxColour& );
1442 void EnableDragRowSize( bool enable = TRUE );
1443 void DisableDragRowSize();
1444 bool CanDragRowSize();
1445 void EnableDragColSize( bool enable = TRUE );
1446 void DisableDragColSize();
1447 bool CanDragColSize();
1448 void EnableDragGridSize(bool enable = TRUE);
1449 void DisableDragGridSize();
1450 bool CanDragGridSize();
1452 // this sets the specified attribute for all cells in this row/col
1453 void SetRowAttr(int row, wxGridCellAttr *attr);
1454 void SetColAttr(int col, wxGridCellAttr *attr);
1456 // shortcuts for setting the column parameters
1458 // set the format for the data in the column: default is string
1459 void SetColFormatBool(int col);
1460 void SetColFormatNumber(int col);
1461 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1462 void SetColFormatCustom(int col, const wxString& typeName);
1464 void EnableGridLines( bool enable = TRUE );
1465 bool GridLinesEnabled();
1467 // ------ row and col formatting
1469 int GetDefaultRowSize();
1470 int GetRowSize( int row );
1471 int GetDefaultColSize();
1472 int GetColSize( int col );
1473 wxColour GetDefaultCellBackgroundColour();
1474 wxColour GetCellBackgroundColour( int row, int col );
1475 wxColour GetDefaultCellTextColour();
1476 wxColour GetCellTextColour( int row, int col );
1477 wxFont GetDefaultCellFont();
1478 wxFont GetCellFont( int row, int col );
1479 void GetDefaultCellAlignment( int *horiz, int *vert );
1480 void GetCellAlignment( int row, int col, int *horiz, int *vert );
1482 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
1483 void SetRowSize( int row, int height );
1484 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
1486 void SetColSize( int col, int width );
1488 // automatically size the column or row to fit to its contents, if
1489 // setAsMin is TRUE, this optimal width will also be set as minimal width
1491 void AutoSizeColumn( int col, bool setAsMin = TRUE );
1492 void AutoSizeRow( int row, bool setAsMin = TRUE );
1495 // auto size all columns (very ineffective for big grids!)
1496 void AutoSizeColumns( bool setAsMin = TRUE );
1497 void AutoSizeRows( bool setAsMin = TRUE );
1499 // auto size the grid, that is make the columns/rows of the "right" size
1500 // and also set the grid size to just fit its contents
1503 // column won't be resized to be lesser width - this must be called during
1504 // the grid creation because it won't resize the column if it's already
1505 // narrower than the minimal width
1506 void SetColMinimalWidth( int col, int width );
1507 void SetRowMinimalHeight( int row, int width );
1509 void SetDefaultCellBackgroundColour( const wxColour& );
1510 void SetCellBackgroundColour( int row, int col, const wxColour& );
1511 void SetDefaultCellTextColour( const wxColour& );
1513 void SetCellTextColour( int row, int col, const wxColour& );
1514 void SetDefaultCellFont( const wxFont& );
1515 void SetCellFont( int row, int col, const wxFont& );
1516 void SetDefaultCellAlignment( int horiz, int vert );
1517 void SetCellAlignment( int row, int col, int horiz, int vert );
1519 // takes ownership of the pointer
1520 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1521 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1522 wxGridCellRenderer *GetDefaultRenderer() const;
1523 wxGridCellRenderer* GetCellRenderer(int row, int col);
1525 // takes ownership of the pointer
1526 void SetDefaultEditor(wxGridCellEditor *editor);
1527 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1528 wxGridCellEditor *GetDefaultEditor() const;
1529 wxGridCellEditor* GetCellEditor(int row, int col);
1533 // ------ cell value accessors
1535 wxString GetCellValue( int row, int col );
1536 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1538 void SetCellValue( int row, int col, const wxString& s );
1539 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1541 // returns TRUE if the cell can't be edited
1542 bool IsReadOnly(int row, int col) const;
1544 // make the cell editable/readonly
1545 void SetReadOnly(int row, int col, bool isReadOnly = TRUE);
1547 // ------ selections of blocks of cells
1549 void SelectRow( int row, bool addToSelected = FALSE );
1550 void SelectCol( int col, bool addToSelected = FALSE );
1552 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1553 bool addToSelected = FALSE );
1554 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1555 // TODO: ??? const wxGridCellCoords& bottomRight )
1559 void ClearSelection();
1560 bool IsInSelection( int row, int col );
1561 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1564 // This function returns the rectangle that encloses the block of cells
1565 // limited by TopLeft and BottomRight cell in device coords and clipped
1566 // to the client size of the grid window.
1568 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1569 const wxGridCellCoords & bottomRight );
1572 // Access or update the selection fore/back colours
1573 wxColour GetSelectionBackground() const;
1574 wxColour GetSelectionForeground() const;
1576 void SetSelectionBackground(const wxColour& c);
1577 void SetSelectionForeground(const wxColour& c);
1580 // Methods for a registry for mapping data types to Renderers/Editors
1581 void RegisterDataType(const wxString& typeName,
1582 wxGridCellRenderer* renderer,
1583 wxGridCellEditor* editor);
1584 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1585 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1586 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1587 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1588 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1590 // grid may occupy more space than needed for its rows/columns, this
1591 // function allows to set how big this extra space is
1592 void SetMargins(int extraWidth, int extraHeight);
1596 //---------------------------------------------------------------------------
1597 //---------------------------------------------------------------------------
1598 // Grid events and stuff
1602 class wxGridEvent : public wxNotifyEvent
1605 wxGridEvent(int id, wxEventType type, wxGrid* obj,
1606 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = TRUE,
1607 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1609 virtual int GetRow();
1610 virtual int GetCol();
1611 wxPoint GetPosition();
1621 class wxGridSizeEvent : public wxNotifyEvent
1624 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
1625 int rowOrCol=-1, int x=-1, int y=-1,
1626 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1629 wxPoint GetPosition();
1638 class wxGridRangeSelectEvent : public wxNotifyEvent
1641 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
1642 const wxGridCellCoords& topLeft,
1643 const wxGridCellCoords& bottomRight,
1645 bool control=FALSE, bool shift=FALSE,
1646 bool alt=FALSE, bool meta=FALSE);
1648 wxGridCellCoords GetTopLeftCoords();
1649 wxGridCellCoords GetBottomRightCoords();
1662 wxEVT_GRID_CELL_LEFT_CLICK,
1663 wxEVT_GRID_CELL_RIGHT_CLICK,
1664 wxEVT_GRID_CELL_LEFT_DCLICK,
1665 wxEVT_GRID_CELL_RIGHT_DCLICK,
1666 wxEVT_GRID_LABEL_LEFT_CLICK,
1667 wxEVT_GRID_LABEL_RIGHT_CLICK,
1668 wxEVT_GRID_LABEL_LEFT_DCLICK,
1669 wxEVT_GRID_LABEL_RIGHT_DCLICK,
1670 wxEVT_GRID_ROW_SIZE,
1671 wxEVT_GRID_COL_SIZE,
1672 wxEVT_GRID_RANGE_SELECT,
1673 wxEVT_GRID_CELL_CHANGE,
1674 wxEVT_GRID_SELECT_CELL,
1675 wxEVT_GRID_EDITOR_SHOWN,
1676 wxEVT_GRID_EDITOR_HIDDEN,
1681 %pragma(python) code = "
1682 def EVT_GRID_CELL_LEFT_CLICK(win, fn):
1683 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_CLICK, fn)
1685 def EVT_GRID_CELL_RIGHT_CLICK(win, fn):
1686 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_CLICK, fn)
1688 def EVT_GRID_CELL_LEFT_DCLICK(win, fn):
1689 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_DCLICK, fn)
1691 def EVT_GRID_CELL_RIGHT_DCLICK(win, fn):
1692 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_DCLICK, fn)
1694 def EVT_GRID_LABEL_LEFT_CLICK(win, fn):
1695 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_CLICK, fn)
1697 def EVT_GRID_LABEL_RIGHT_CLICK(win, fn):
1698 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_CLICK, fn)
1700 def EVT_GRID_LABEL_LEFT_DCLICK(win, fn):
1701 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_DCLICK, fn)
1703 def EVT_GRID_LABEL_RIGHT_DCLICK(win, fn):
1704 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_DCLICK, fn)
1706 def EVT_GRID_ROW_SIZE(win, fn):
1707 win.Connect(-1, -1, wxEVT_GRID_ROW_SIZE, fn)
1709 def EVT_GRID_COL_SIZE(win, fn):
1710 win.Connect(-1, -1, wxEVT_GRID_COL_SIZE, fn)
1712 def EVT_GRID_RANGE_SELECT(win, fn):
1713 win.Connect(-1, -1, wxEVT_GRID_RANGE_SELECT, fn)
1715 def EVT_GRID_CELL_CHANGE(win, fn):
1716 win.Connect(-1, -1, wxEVT_GRID_CELL_CHANGE, fn)
1718 def EVT_GRID_SELECT_CELL(win, fn):
1719 win.Connect(-1, -1, wxEVT_GRID_SELECT_CELL, fn)
1721 def EVT_GRID_EDITOR_SHOWN(win, fn):
1722 win.Connect(-1, -1, wxEVT_GRID_EDITOR_SHOWN, fn)
1724 def EVT_GRID_EDITOR_HIDDEN(win, fn):
1725 win.Connect(-1, -1, wxEVT_GRID_EDITOR_HIDDEN, fn)
1729 //---------------------------------------------------------------------------
1731 %pragma(python) include="_gridextras.py";
1733 //---------------------------------------------------------------------------