1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG definitions for the new wxGrid and related classes
7 // Created: 17-March-2000
9 // Copyright: (c) 1998 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_p"), \
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_p"), \
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);
455 virtual void Draw(wxGrid& grid,
456 wxGridCellAttr& attr,
460 bool isSelected) = 0;
461 virtual wxSize GetBestSize(wxGrid& grid,
462 wxGridCellAttr& attr,
464 int row, int col) = 0;
465 virtual wxGridCellRenderer *Clone() const = 0;
469 // The C++ version of wxPyGridCellRenderer
471 class wxPyGridCellRenderer : public wxGridCellRenderer
474 wxPyGridCellRenderer() : wxGridCellRenderer() {};
476 // Implement Python callback aware virtual methods
477 void Draw(wxGrid& grid, wxGridCellAttr& attr,
478 wxDC& dc, const wxRect& rect,
479 int row, int col, bool isSelected) {
480 bool doSave = wxPyRestoreThread();
481 if (m_myInst.findCallback("Draw")) {
482 m_myInst.callCallback(
483 Py_BuildValue("(OOOOiii)",
484 wxPyConstructObject((void*)&grid, "wxGrid"),
485 wxPyConstructObject((void*)&attr, "wxGridCellAttr"),
486 wxPyConstructObject((void*)&dc, "wxDC"),
487 wxPyConstructObject((void*)&rect, "wxRect"),
488 row, col, isSelected));
490 wxPySaveThread(doSave);
493 wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
496 bool doSave = wxPyRestoreThread();
497 if (m_myInst.findCallback("GetBestSize")) {
500 ro = m_myInst.callCallbackObj(
501 Py_BuildValue("(OOOii)",
502 wxPyConstructObject((void*)&grid, "wxGrid"),
503 wxPyConstructObject((void*)&attr, "wxGridCellAttr"),
504 wxPyConstructObject((void*)&dc, "wxDC"),
507 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p"))
512 wxPySaveThread(doSave);
517 wxGridCellRenderer *Clone() const {
518 wxGridCellRenderer* rval = NULL;
519 bool doSave = wxPyRestoreThread();
520 if (m_myInst.findCallback("Clone")) {
522 wxGridCellRenderer* ptr;
523 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
525 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellRenderer_p"))
530 wxPySaveThread(doSave);
534 DEC_PYCALLBACK__STRING(SetParameters);
539 IMP_PYCALLBACK__STRING( wxPyGridCellRenderer, wxGridCellRenderer, SetParameters);
544 // Let SWIG know about it so it can create the Python version
545 class wxPyGridCellRenderer : public wxGridCellRenderer {
547 wxPyGridCellRenderer();
548 void _setSelf(PyObject* self, PyObject* _class);
549 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyGridCellRenderer)"
551 void base_SetParameters(const wxString& params);
554 //---------------------------------------------------------------------------
555 // Predefined Renderers
557 class wxGridCellStringRenderer : public wxGridCellRenderer
560 wxGridCellStringRenderer();
564 class wxGridCellNumberRenderer : public wxGridCellStringRenderer
567 wxGridCellNumberRenderer();
571 class wxGridCellFloatRenderer : public wxGridCellStringRenderer
574 wxGridCellFloatRenderer(int width = -1, int precision = -1);
576 int GetWidth() const;
577 void SetWidth(int width);
578 int GetPrecision() const;
579 void SetPrecision(int precision);
583 class wxGridCellBoolRenderer : public wxGridCellRenderer
586 wxGridCellBoolRenderer();
591 //---------------------------------------------------------------------------
592 // wxGridCellEditor is an ABC, and several derived classes are available.
593 // Classes implemented in Python should be derived from wxPyGridCellEditor.
595 class wxGridCellEditor
599 wxControl* GetControl();
600 void SetControl(wxControl* control);
602 void SetParameters(const wxString& params);
604 virtual void Create(wxWindow* parent,
606 wxEvtHandler* evtHandler) = 0;
607 virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
608 virtual bool EndEdit(int row, int col, wxGrid* grid) = 0;
609 virtual void Reset() = 0;
610 virtual wxGridCellEditor *Clone() const = 0;
612 virtual void SetSize(const wxRect& rect);
613 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
614 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
615 virtual void StartingKey(wxKeyEvent& event);
616 virtual void StartingClick();
617 virtual void HandleReturn(wxKeyEvent& event);
618 virtual void Destroy();
623 // The C++ version of wxPyGridCellEditor
625 class wxPyGridCellEditor : public wxGridCellEditor
628 wxPyGridCellEditor() : wxGridCellEditor() {}
630 void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) {
631 bool doSave = wxPyRestoreThread();
632 if (m_myInst.findCallback("Create")) {
633 m_myInst.callCallback(
634 Py_BuildValue("(OiO)",
635 wxPyConstructObject((void*)parent, "wxWindow"),
637 wxPyConstructObject((void*)evtHandler, "wxEvtHandler")));
639 wxPySaveThread(doSave);
643 void BeginEdit(int row, int col, wxGrid* grid) {
644 bool doSave = wxPyRestoreThread();
645 if (m_myInst.findCallback("BeginEdit")) {
646 m_myInst.callCallback(
647 Py_BuildValue("(iiO)", row, col,
648 wxPyConstructObject((void*)grid, "wxGrid")));
650 wxPySaveThread(doSave);
654 bool EndEdit(int row, int col, wxGrid* grid) {
656 bool doSave = wxPyRestoreThread();
657 if (m_myInst.findCallback("EndEdit")) {
658 rv = m_myInst.callCallback(
659 Py_BuildValue("(iiO)", row, col,
660 wxPyConstructObject((void*)grid, "wxGrid")));
662 wxPySaveThread(doSave);
667 wxGridCellEditor *Clone() const {
668 wxGridCellEditor* rval = NULL;
669 bool doSave = wxPyRestoreThread();
670 if (m_myInst.findCallback("Clone")) {
672 wxGridCellEditor* ptr;
673 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
675 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellEditor_p"))
680 wxPySaveThread(doSave);
685 void Show(bool show, wxGridCellAttr *attr) {
686 bool doSave = wxPyRestoreThread();
687 if (m_myInst.findCallback("Show"))
688 m_myInst.callCallback(
689 Py_BuildValue("(iO)", show,
690 wxPyConstructObject((void*)attr, "_wxGridCellAttr_p")));
692 wxGridCellEditor::Show(show, attr);
693 wxPySaveThread(doSave);
695 void base_Show(bool show, wxGridCellAttr *attr) {
696 wxGridCellEditor::Show(show, attr);
700 void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
701 bool doSave = wxPyRestoreThread();
702 if (m_myInst.findCallback("PaintBackground"))
703 m_myInst.callCallback(
704 Py_BuildValue("(OO)",
705 wxPyConstructObject((void*)&rectCell, "_wxRect_p"),
706 wxPyConstructObject((void*)attr, "_wxGridCellAttr_p")));
708 wxGridCellEditor::PaintBackground(rectCell, attr);
709 wxPySaveThread(doSave);
711 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
712 wxGridCellEditor::PaintBackground(rectCell, attr);
716 DEC_PYCALLBACK___pure(Reset);
717 DEC_PYCALLBACK__constany(SetSize, wxRect);
718 DEC_PYCALLBACK__any(StartingKey, wxKeyEvent);
719 DEC_PYCALLBACK__any(HandleReturn, wxKeyEvent);
720 DEC_PYCALLBACK__(StartingClick);
721 DEC_PYCALLBACK__(Destroy);
722 DEC_PYCALLBACK__STRING(SetParameters);
728 IMP_PYCALLBACK__STRING( wxPyGridCellEditor, wxGridCellEditor, SetParameters);
729 IMP_PYCALLBACK___pure(wxPyGridCellEditor, wxGridCellEditor, Reset);
730 IMP_PYCALLBACK__constany(wxPyGridCellEditor, wxGridCellEditor, SetSize, wxRect);
731 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, StartingKey, wxKeyEvent);
732 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, HandleReturn, wxKeyEvent);
733 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, StartingClick);
734 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, Destroy);
739 // Let SWIG know about it so it can create the Python version
740 class wxPyGridCellEditor : public wxGridCellEditor {
742 wxPyGridCellEditor();
743 void _setSelf(PyObject* self, PyObject* _class);
744 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyGridCellEditor)"
746 void base_SetSize(const wxRect& rect);
747 void base_Show(bool show, wxGridCellAttr *attr = NULL);
748 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
749 void base_StartingKey(wxKeyEvent& event);
750 void base_StartingClick();
751 void base_HandleReturn(wxKeyEvent& event);
753 void base_SetParameters(const wxString& params);
756 //---------------------------------------------------------------------------
757 // Predefined Editors
759 class wxGridCellTextEditor : public wxGridCellEditor
762 wxGridCellTextEditor();
766 class wxGridCellNumberEditor : public wxGridCellTextEditor
769 wxGridCellNumberEditor(int min = -1, int max = -1);
773 class wxGridCellFloatEditor : public wxGridCellTextEditor
776 wxGridCellFloatEditor();
780 class wxGridCellBoolEditor : public wxGridCellEditor
783 wxGridCellBoolEditor();
786 class wxGridCellChoiceEditor : public wxGridCellEditor
789 wxGridCellChoiceEditor(int LCOUNT = 0,
790 const wxString* choices = NULL,
791 bool allowOthers = FALSE);
794 wxGridCellChoiceEditor(PyObject* choices,
795 bool allowOthers = FALSE) {
797 const char** temp = string_LIST_helper(choices);
799 int count = PyList_Size(choices);
800 wxGridCellChoiceEditor* ret;
801 ret = new wxGridCellChoiceEditor(count, temp, allowOthers);
811 //---------------------------------------------------------------------------
819 wxGridCellAttr *Clone() const;
822 void SetTextColour(const wxColour& colText);
823 void SetBackgroundColour(const wxColour& colBack);
824 void SetFont(const wxFont& font);
825 void SetAlignment(int hAlign, int vAlign);
826 void SetReadOnly(bool isReadOnly = TRUE);
828 void SetRenderer(wxGridCellRenderer *renderer);
829 void SetEditor(wxGridCellEditor* editor);
831 bool HasTextColour() const;
832 bool HasBackgroundColour() const;
833 bool HasFont() const;
834 bool HasAlignment() const;
835 bool HasRenderer() const;
836 bool HasEditor() const;
838 const wxColour& GetTextColour() const;
839 const wxColour& GetBackgroundColour() const;
840 const wxFont& GetFont() const;
841 void GetAlignment(int *OUTPUT, int *OUTPUT) const;
842 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
843 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
845 bool IsReadOnly() const;
846 void SetDefAttr(wxGridCellAttr* defAttr);
849 //---------------------------------------------------------------------------
851 class wxGridCellAttrProvider
854 wxGridCellAttrProvider();
855 // ???? virtual ~wxGridCellAttrProvider();
857 wxGridCellAttr *GetAttr(int row, int col) const;
858 void SetAttr(wxGridCellAttr *attr, int row, int col);
859 void SetRowAttr(wxGridCellAttr *attr, int row);
860 void SetColAttr(wxGridCellAttr *attr, int col);
862 void UpdateAttrRows( size_t pos, int numRows );
863 void UpdateAttrCols( size_t pos, int numCols );
868 // A Python-aware version
870 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
873 wxPyGridCellAttrProvider() : wxGridCellAttrProvider() {};
875 PYCALLBACK_GCA_INTINT(wxGridCellAttrProvider, GetAttr);
876 PYCALLBACK__GCAINTINT(wxGridCellAttrProvider, SetAttr);
877 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetRowAttr);
878 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetColAttr);
885 // The python-aware version get's SWIGified
886 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
889 wxPyGridCellAttrProvider();
890 void _setSelf(PyObject* self, PyObject* _class);
891 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyGridCellAttrProvider)"
893 wxGridCellAttr *base_GetAttr(int row, int col);
894 void base_SetAttr(wxGridCellAttr *attr, int row, int col);
895 void base_SetRowAttr(wxGridCellAttr *attr, int row);
896 void base_SetColAttr(wxGridCellAttr *attr, int col);
900 //---------------------------------------------------------------------------
901 // Grid Table Base class and Python aware version
905 class wxGridTableBase
908 // wxGridTableBase(); This is an ABC
909 //~wxGridTableBase();
911 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
912 wxGridCellAttrProvider *GetAttrProvider() const;
913 void SetView( wxGrid *grid );
914 wxGrid * GetView() const;
918 virtual int GetNumberRows() = 0;
919 virtual int GetNumberCols() = 0;
920 virtual bool IsEmptyCell( int row, int col ) = 0;
921 virtual wxString GetValue( int row, int col ) = 0;
922 virtual void SetValue( int row, int col, const wxString& value ) = 0;
924 // virtuals overridable in wxPyGridTableBase
925 virtual wxString GetTypeName( int row, int col );
926 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
927 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
928 virtual long GetValueAsLong( int row, int col );
929 virtual double GetValueAsDouble( int row, int col );
930 virtual bool GetValueAsBool( int row, int col );
931 virtual void SetValueAsLong( int row, int col, long value );
932 virtual void SetValueAsDouble( int row, int col, double value );
933 virtual void SetValueAsBool( int row, int col, bool value );
935 //virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
936 //virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
939 virtual void Clear();
940 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
941 virtual bool AppendRows( size_t numRows = 1 );
942 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
943 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
944 virtual bool AppendCols( size_t numCols = 1 );
945 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
947 virtual wxString GetRowLabelValue( int row );
948 virtual wxString GetColLabelValue( int col );
949 virtual void SetRowLabelValue( int row, const wxString& value );
950 virtual void SetColLabelValue( int col, const wxString& value );
952 virtual bool CanHaveAttributes();
954 virtual wxGridCellAttr *GetAttr( int row, int col );
955 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
956 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
957 virtual void SetColAttr(wxGridCellAttr *attr, int col);
963 // Python-aware version
965 class wxPyGridTableBase : public wxGridTableBase
968 wxPyGridTableBase() : wxGridTableBase() {}
970 PYCALLBACK_INT__pure(GetNumberRows);
971 PYCALLBACK_INT__pure(GetNumberCols);
972 PYCALLBACK_BOOL_INTINT_pure(IsEmptyCell);
973 PYCALLBACK_STRING_INTINT(wxGridTableBase, GetTypeName);
974 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanGetValueAs);
975 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanSetValueAs);
976 PYCALLBACK__(wxGridTableBase, Clear);
977 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertRows);
978 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteRows);
979 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertCols);
980 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteCols);
981 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendRows);
982 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendCols);
983 PYCALLBACK_STRING_INT(wxGridTableBase, GetRowLabelValue);
984 PYCALLBACK_STRING_INT(wxGridTableBase, GetColLabelValue);
985 PYCALLBACK__INTSTRING(wxGridTableBase, SetRowLabelValue);
986 PYCALLBACK__INTSTRING(wxGridTableBase, SetColLabelValue);
987 PYCALLBACK_BOOL_(wxGridTableBase, CanHaveAttributes);
988 PYCALLBACK_GCA_INTINT(wxGridTableBase, GetAttr);
989 PYCALLBACK__GCAINTINT(wxGridTableBase, SetAttr);
990 PYCALLBACK__GCAINT(wxGridTableBase, SetRowAttr);
991 PYCALLBACK__GCAINT(wxGridTableBase, SetColAttr);
995 wxString GetValue(int row, int col) {
996 bool doSave = wxPyRestoreThread();
998 if (m_myInst.findCallback("GetValue")) {
1000 ro = m_myInst.callCallbackObj(Py_BuildValue("(ii)",row,col));
1002 rval = PyString_AsString(PyObject_Str(ro));
1006 wxPySaveThread(doSave);
1010 void SetValue(int row, int col, const wxString& val) {
1011 bool doSave = wxPyRestoreThread();
1012 if (m_myInst.findCallback("SetValue"))
1013 m_myInst.callCallback(Py_BuildValue("(iis)",row,col,val.c_str()));
1014 wxPySaveThread(doSave);
1018 // Map the Get/Set methods for the standard non-string types to
1019 // the GetValue and SetValue python methods.
1020 long GetValueAsLong( int row, int col ) {
1022 bool doSave = wxPyRestoreThread();
1023 if (m_myInst.findCallback("GetValue")) {
1026 ro = m_myInst.callCallbackObj(Py_BuildValue("(ii)", row, col));
1027 if (ro && PyNumber_Check(ro)) {
1028 num = PyNumber_Int(ro);
1030 rval = PyInt_AsLong(num);
1036 wxPySaveThread(doSave);
1040 double GetValueAsDouble( int row, int col ) {
1042 bool doSave = wxPyRestoreThread();
1043 if (m_myInst.findCallback("GetValue")) {
1046 ro = m_myInst.callCallbackObj(Py_BuildValue("(ii)", row, col));
1047 if (ro && PyNumber_Check(ro)) {
1048 num = PyNumber_Float(ro);
1050 rval = PyFloat_AsDouble(num);
1056 wxPySaveThread(doSave);
1060 bool GetValueAsBool( int row, int col ) {
1061 return (bool)GetValueAsLong(row, col);
1064 void SetValueAsLong( int row, int col, long value ) {
1065 bool doSave = wxPyRestoreThread();
1066 if (m_myInst.findCallback("SetValue")) {
1067 m_myInst.callCallback(Py_BuildValue("(iii)", row, col, value));
1069 wxPySaveThread(doSave);
1072 void SetValueAsDouble( int row, int col, double value ) {
1073 bool doSave = wxPyRestoreThread();
1074 if (m_myInst.findCallback("SetValue")) {
1075 m_myInst.callCallback(Py_BuildValue("(iid)", row, col, value));
1077 wxPySaveThread(doSave);
1080 void SetValueAsBool( int row, int col, bool value ) {
1081 SetValueAsLong( row, col, (long)value );
1090 // The python-aware version get's SWIGified
1091 class wxPyGridTableBase : public wxGridTableBase
1094 wxPyGridTableBase();
1095 void _setSelf(PyObject* self, PyObject* _class);
1096 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyGridTableBase)"
1098 %addmethods { void Destroy() { delete self; } }
1100 wxString base_GetTypeName( int row, int col );
1101 bool base_CanGetValueAs( int row, int col, const wxString& typeName );
1102 bool base_CanSetValueAs( int row, int col, const wxString& typeName );
1104 bool base_InsertRows( size_t pos = 0, size_t numRows = 1 );
1105 bool base_AppendRows( size_t numRows = 1 );
1106 bool base_DeleteRows( size_t pos = 0, size_t numRows = 1 );
1107 bool base_InsertCols( size_t pos = 0, size_t numCols = 1 );
1108 bool base_AppendCols( size_t numCols = 1 );
1109 bool base_DeleteCols( size_t pos = 0, size_t numCols = 1 );
1110 wxString base_GetRowLabelValue( int row );
1111 wxString base_GetColLabelValue( int col );
1112 void base_SetRowLabelValue( int row, const wxString& value );
1113 void base_SetColLabelValue( int col, const wxString& value );
1114 bool base_CanHaveAttributes();
1115 wxGridCellAttr *base_GetAttr( int row, int col );
1116 void base_SetAttr(wxGridCellAttr* attr, int row, int col);
1117 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1118 void base_SetColAttr(wxGridCellAttr *attr, int col);
1122 //---------------------------------------------------------------------------
1123 // Predefined Tables
1125 class wxGridStringTable : public wxGridTableBase
1128 wxGridStringTable( int numRows=0, int numCols=0 );
1131 //---------------------------------------------------------------------------
1132 // The Table can pass messages to the grid to tell it to update itself if
1133 // something has changed.
1135 enum wxGridTableRequest
1137 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
1138 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
1139 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
1140 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
1141 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
1142 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1143 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
1144 wxGRIDTABLE_NOTIFY_COLS_DELETED
1148 class wxGridTableMessage
1151 wxGridTableMessage( wxGridTableBase *table, int id,
1154 ~wxGridTableMessage();
1156 void SetTableObject( wxGridTableBase *table );
1157 wxGridTableBase * GetTableObject() const;
1158 void SetId( int id );
1160 void SetCommandInt( int comInt1 );
1161 int GetCommandInt();
1162 void SetCommandInt2( int comInt2 );
1163 int GetCommandInt2();
1167 //---------------------------------------------------------------------------
1169 class wxGridCellCoords
1172 wxGridCellCoords( int r=-1, int c=-1 );
1173 ~wxGridCellCoords();
1175 int GetRow() const { return m_row; }
1176 void SetRow( int n ) { m_row = n; }
1177 int GetCol() const { return m_col; }
1178 void SetCol( int n ) { m_col = n; }
1179 void Set( int row, int col ) { m_row = row; m_col = col; }
1182 PyObject* asTuple() {
1183 PyObject* tup = PyTuple_New(2);
1184 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
1185 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
1189 int __cmp__( const wxGridCellCoords& other ) {
1190 return *self != other;
1193 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
1194 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
1197 // Typemap to allow conversion of sequence objects to wxGridCellCoords...
1198 %typemap(python,in) wxGridCellCoords& (wxGridCellCoords temp) {
1200 if (! wxGridCellCoords_helper($source, &$target))
1204 // ...and here is the associated helper.
1206 bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) {
1208 // If source is an object instance then it may already be the right type
1209 if (PyInstance_Check(source)) {
1210 wxGridCellCoords* ptr;
1211 if (SWIG_GetPtrObj(source, (void **)&ptr, "_wxGridCellCoords_p"))
1216 // otherwise a 2-tuple of integers is expected
1217 else if (PySequence_Check(source) && PyObject_Length(source) == 2) {
1218 PyObject* o1 = PySequence_GetItem(source, 0);
1219 PyObject* o2 = PySequence_GetItem(source, 1);
1220 **obj = wxGridCellCoords(PyInt_AsLong(o1), PyInt_AsLong(o2));
1225 PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of integers or a wxGridCellCoords object.");
1230 //---------------------------------------------------------------------------
1231 //---------------------------------------------------------------------------
1235 // Fool SWIG into treating this enum as an int
1236 typedef int WXGRIDSELECTIONMODES;
1238 // but let the C++ code know what it really is.
1240 typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES;
1245 class wxGrid : public wxScrolledWindow
1248 wxGrid( wxWindow *parent,
1250 const wxPoint& pos = wxDefaultPosition,
1251 const wxSize& size = wxDefaultSize,
1252 long style = wxWANTS_CHARS,
1253 const char* name = wxPanelNameStr );
1257 enum wxGridSelectionModes {wxGridSelectCells,
1259 wxGridSelectColumns};
1261 bool CreateGrid( int numRows, int numCols,
1262 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1263 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1266 // ------ grid dimensions
1268 int GetNumberRows();
1269 int GetNumberCols();
1272 // ------ display update functions
1274 void CalcRowLabelsExposed( wxRegion& reg );
1276 void CalcColLabelsExposed( wxRegion& reg );
1277 void CalcCellsExposed( wxRegion& reg );
1280 #ifdef NOTNEEDED // ????
1281 // ------ event handlers
1283 void ProcessRowLabelMouseEvent( wxMouseEvent& event );
1284 void ProcessColLabelMouseEvent( wxMouseEvent& event );
1285 void ProcessCornerLabelMouseEvent( wxMouseEvent& event );
1286 void ProcessGridCellMouseEvent( wxMouseEvent& event );
1287 void DoEndDragResizeRow();
1288 void DoEndDragResizeCol();
1291 bool ProcessTableMessage( wxGridTableMessage& );
1294 wxGridTableBase * GetTable() const;
1295 bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE,
1296 WXGRIDSELECTIONMODES selmode =
1297 wxGrid::wxGridSelectCells );
1300 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1301 bool AppendRows( int numRows = 1, bool updateLabels=TRUE );
1302 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1303 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1304 bool AppendCols( int numCols = 1, bool updateLabels=TRUE );
1305 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1307 #ifdef NOTNEEDED // ????
1308 void DrawGridCellArea( wxDC& dc );
1309 void DrawGridSpace( wxDC& dc );
1310 void DrawCellBorder( wxDC& dc, const wxGridCellCoords& );
1311 void DrawAllGridLines( wxDC& dc, const wxRegion & reg );
1312 void DrawCell( wxDC& dc, const wxGridCellCoords& );
1313 void DrawHighlight(wxDC& dc);
1316 // this function is called when the current cell highlight must be redrawn
1317 // and may be overridden by the user
1318 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1320 #ifdef NOTNEEDED // ????
1321 void DrawRowLabels( wxDC& dc );
1322 void DrawRowLabel( wxDC& dc, int row );
1324 void DrawColLabels( wxDC& dc );
1325 void DrawColLabel( wxDC& dc, int col );
1328 // ------ Cell text drawing functions
1330 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1331 int horizontalAlignment = wxLEFT,
1332 int verticalAlignment = wxTOP );
1334 // Split a string containing newline chararcters into an array of
1335 // strings and return the number of lines
1337 void StringToLines( const wxString& value, wxArrayString& lines );
1339 void GetTextBoxSize( wxDC& dc,
1340 wxArrayString& lines,
1341 long *width, long *height );
1345 // Code that does a lot of grid modification can be enclosed
1346 // between BeginBatch() and EndBatch() calls to avoid screen
1351 int GetBatchCount();
1354 // ------ edit control functions
1356 bool IsEditable() { return m_editable; }
1357 void EnableEditing( bool edit );
1359 void EnableCellEditControl( bool enable = TRUE );
1360 void DisableCellEditControl();
1361 bool CanEnableCellControl() const;
1362 bool IsCellEditControlEnabled() const;
1363 bool IsCellEditControlShown() const;
1365 bool IsCurrentCellReadOnly() const;
1367 void ShowCellEditControl();
1368 void HideCellEditControl();
1369 void SaveEditControlValue();
1372 // ------ grid location functions
1373 // Note that all of these functions work with the logical coordinates of
1374 // grid cells and labels so you will need to convert from device
1375 // coordinates for mouse events etc.
1378 //void XYToCell( int x, int y, wxGridCellCoords& );
1380 %new wxGridCellCoords* XYToCell(int x, int y) {
1381 wxGridCellCoords rv;
1382 self->XYToCell(x, y, rv);
1383 return new wxGridCellCoords(rv);
1387 int YToRow( int y );
1388 int XToCol( int x );
1390 int YToEdgeOfRow( int y );
1391 int XToEdgeOfCol( int x );
1393 wxRect CellToRect( int row, int col );
1394 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1397 int GetGridCursorRow();
1398 int GetGridCursorCol();
1400 // check to see if a cell is either wholly visible (the default arg) or
1401 // at least partially visible in the grid window
1403 bool IsVisible( int row, int col, bool wholeCellVisible = TRUE );
1404 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE );
1405 void MakeCellVisible( int row, int col );
1406 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1409 // ------ grid cursor movement functions
1411 void SetGridCursor( int row, int col );
1412 bool MoveCursorUp( bool expandSelection );
1413 bool MoveCursorDown( bool expandSelection );
1414 bool MoveCursorLeft( bool expandSelection );
1415 bool MoveCursorRight( bool expandSelection );
1416 bool MovePageDown();
1418 bool MoveCursorUpBlock( bool expandSelection );
1419 bool MoveCursorDownBlock( bool expandSelection );
1420 bool MoveCursorLeftBlock( bool expandSelection );
1421 bool MoveCursorRightBlock( bool expandSelection );
1424 // ------ label and gridline formatting
1426 int GetDefaultRowLabelSize();
1427 int GetRowLabelSize();
1428 int GetDefaultColLabelSize();
1429 int GetColLabelSize();
1430 wxColour GetLabelBackgroundColour();
1431 wxColour GetLabelTextColour();
1432 wxFont GetLabelFont();
1433 void GetRowLabelAlignment( int *OUTPUT, int *OUTPUT );
1434 void GetColLabelAlignment( int *OUTPUT, int *OUTPUT );
1435 wxString GetRowLabelValue( int row );
1436 wxString GetColLabelValue( int col );
1437 wxColour GetGridLineColour();
1438 wxColour GetCellHighlightColour();
1440 void SetRowLabelSize( int width );
1441 void SetColLabelSize( int height );
1442 void SetLabelBackgroundColour( const wxColour& );
1443 void SetLabelTextColour( const wxColour& );
1444 void SetLabelFont( const wxFont& );
1445 void SetRowLabelAlignment( int horiz, int vert );
1446 void SetColLabelAlignment( int horiz, int vert );
1447 void SetRowLabelValue( int row, const wxString& );
1448 void SetColLabelValue( int col, const wxString& );
1449 void SetGridLineColour( const wxColour& );
1450 void SetCellHighlightColour( const wxColour& );
1452 void EnableDragRowSize( bool enable = TRUE );
1453 void DisableDragRowSize();
1454 bool CanDragRowSize();
1455 void EnableDragColSize( bool enable = TRUE );
1456 void DisableDragColSize();
1457 bool CanDragColSize();
1458 void EnableDragGridSize(bool enable = TRUE);
1459 void DisableDragGridSize();
1460 bool CanDragGridSize();
1462 // this sets the specified attribute for all cells in this row/col
1463 void SetRowAttr(int row, wxGridCellAttr *attr);
1464 void SetColAttr(int col, wxGridCellAttr *attr);
1466 // shortcuts for setting the column parameters
1468 // set the format for the data in the column: default is string
1469 void SetColFormatBool(int col);
1470 void SetColFormatNumber(int col);
1471 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1472 void SetColFormatCustom(int col, const wxString& typeName);
1474 void EnableGridLines( bool enable = TRUE );
1475 bool GridLinesEnabled();
1477 // ------ row and col formatting
1479 int GetDefaultRowSize();
1480 int GetRowSize( int row );
1481 int GetDefaultColSize();
1482 int GetColSize( int col );
1483 wxColour GetDefaultCellBackgroundColour();
1484 wxColour GetCellBackgroundColour( int row, int col );
1485 wxColour GetDefaultCellTextColour();
1486 wxColour GetCellTextColour( int row, int col );
1487 wxFont GetDefaultCellFont();
1488 wxFont GetCellFont( int row, int col );
1489 void GetDefaultCellAlignment( int *horiz, int *vert );
1490 void GetCellAlignment( int row, int col, int *horiz, int *vert );
1492 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
1493 void SetRowSize( int row, int height );
1494 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
1496 void SetColSize( int col, int width );
1498 // automatically size the column or row to fit to its contents, if
1499 // setAsMin is TRUE, this optimal width will also be set as minimal width
1501 void AutoSizeColumn( int col, bool setAsMin = TRUE );
1502 void AutoSizeRow( int row, bool setAsMin = TRUE );
1505 // auto size all columns (very ineffective for big grids!)
1506 void AutoSizeColumns( bool setAsMin = TRUE );
1507 void AutoSizeRows( bool setAsMin = TRUE );
1509 // auto size the grid, that is make the columns/rows of the "right" size
1510 // and also set the grid size to just fit its contents
1513 // column won't be resized to be lesser width - this must be called during
1514 // the grid creation because it won't resize the column if it's already
1515 // narrower than the minimal width
1516 void SetColMinimalWidth( int col, int width );
1517 void SetRowMinimalHeight( int row, int width );
1519 void SetDefaultCellBackgroundColour( const wxColour& );
1520 void SetCellBackgroundColour( int row, int col, const wxColour& );
1521 void SetDefaultCellTextColour( const wxColour& );
1523 void SetCellTextColour( int row, int col, const wxColour& );
1524 void SetDefaultCellFont( const wxFont& );
1525 void SetCellFont( int row, int col, const wxFont& );
1526 void SetDefaultCellAlignment( int horiz, int vert );
1527 void SetCellAlignment( int row, int col, int horiz, int vert );
1529 // takes ownership of the pointer
1530 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1531 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1532 wxGridCellRenderer *GetDefaultRenderer() const;
1533 wxGridCellRenderer* GetCellRenderer(int row, int col);
1535 // takes ownership of the pointer
1536 void SetDefaultEditor(wxGridCellEditor *editor);
1537 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1538 wxGridCellEditor *GetDefaultEditor() const;
1539 wxGridCellEditor* GetCellEditor(int row, int col);
1543 // ------ cell value accessors
1545 wxString GetCellValue( int row, int col );
1546 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1548 void SetCellValue( int row, int col, const wxString& s );
1549 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1551 // returns TRUE if the cell can't be edited
1552 bool IsReadOnly(int row, int col) const;
1554 // make the cell editable/readonly
1555 void SetReadOnly(int row, int col, bool isReadOnly = TRUE);
1557 // ------ selections of blocks of cells
1559 void SelectRow( int row, bool addToSelected = FALSE );
1560 void SelectCol( int col, bool addToSelected = FALSE );
1562 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol );
1563 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1564 // TODO: ??? const wxGridCellCoords& bottomRight )
1568 void ClearSelection();
1569 bool IsInSelection( int row, int col );
1570 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1573 // This function returns the rectangle that encloses the block of cells
1574 // limited by TopLeft and BottomRight cell in device coords and clipped
1575 // to the client size of the grid window.
1577 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1578 const wxGridCellCoords & bottomRight );
1580 // This function returns the rectangle that encloses the selected cells
1581 // in device coords and clipped to the client size of the grid window.
1583 wxRect SelectionToDeviceRect();
1585 // Access or update the selection fore/back colours
1586 wxColour GetSelectionBackground() const;
1587 wxColour GetSelectionForeground() const;
1589 void SetSelectionBackground(const wxColour& c);
1590 void SetSelectionForeground(const wxColour& c);
1593 // Methods for a registry for mapping data types to Renderers/Editors
1594 void RegisterDataType(const wxString& typeName,
1595 wxGridCellRenderer* renderer,
1596 wxGridCellEditor* editor);
1597 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1598 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1599 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1600 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1601 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1603 // grid may occupy more space than needed for its rows/columns, this
1604 // function allows to set how big this extra space is
1605 void SetMargins(int extraWidth, int extraHeight);
1609 //---------------------------------------------------------------------------
1610 //---------------------------------------------------------------------------
1611 // Grid events and stuff
1615 class wxGridEvent : public wxNotifyEvent
1618 wxGridEvent(int id, wxEventType type, wxGrid* obj,
1619 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = TRUE,
1620 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1622 virtual int GetRow();
1623 virtual int GetCol();
1624 wxPoint GetPosition();
1634 class wxGridSizeEvent : public wxNotifyEvent
1637 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
1638 int rowOrCol=-1, int x=-1, int y=-1,
1639 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1642 wxPoint GetPosition();
1651 class wxGridRangeSelectEvent : public wxNotifyEvent
1654 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
1655 const wxGridCellCoords& topLeft,
1656 const wxGridCellCoords& bottomRight,
1658 bool control=FALSE, bool shift=FALSE,
1659 bool alt=FALSE, bool meta=FALSE);
1661 wxGridCellCoords GetTopLeftCoords();
1662 wxGridCellCoords GetBottomRightCoords();
1675 wxEVT_GRID_CELL_LEFT_CLICK,
1676 wxEVT_GRID_CELL_RIGHT_CLICK,
1677 wxEVT_GRID_CELL_LEFT_DCLICK,
1678 wxEVT_GRID_CELL_RIGHT_DCLICK,
1679 wxEVT_GRID_LABEL_LEFT_CLICK,
1680 wxEVT_GRID_LABEL_RIGHT_CLICK,
1681 wxEVT_GRID_LABEL_LEFT_DCLICK,
1682 wxEVT_GRID_LABEL_RIGHT_DCLICK,
1683 wxEVT_GRID_ROW_SIZE,
1684 wxEVT_GRID_COL_SIZE,
1685 wxEVT_GRID_RANGE_SELECT,
1686 wxEVT_GRID_CELL_CHANGE,
1687 wxEVT_GRID_SELECT_CELL,
1688 wxEVT_GRID_EDITOR_SHOWN,
1689 wxEVT_GRID_EDITOR_HIDDEN,
1694 %pragma(python) code = "
1695 def EVT_GRID_CELL_LEFT_CLICK(win, fn):
1696 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_CLICK, fn)
1698 def EVT_GRID_CELL_RIGHT_CLICK(win, fn):
1699 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_CLICK, fn)
1701 def EVT_GRID_CELL_LEFT_DCLICK(win, fn):
1702 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_DCLICK, fn)
1704 def EVT_GRID_CELL_RIGHT_DCLICK(win, fn):
1705 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_DCLICK, fn)
1707 def EVT_GRID_LABEL_LEFT_CLICK(win, fn):
1708 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_CLICK, fn)
1710 def EVT_GRID_LABEL_RIGHT_CLICK(win, fn):
1711 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_CLICK, fn)
1713 def EVT_GRID_LABEL_LEFT_DCLICK(win, fn):
1714 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_DCLICK, fn)
1716 def EVT_GRID_LABEL_RIGHT_DCLICK(win, fn):
1717 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_DCLICK, fn)
1719 def EVT_GRID_ROW_SIZE(win, fn):
1720 win.Connect(-1, -1, wxEVT_GRID_ROW_SIZE, fn)
1722 def EVT_GRID_COL_SIZE(win, fn):
1723 win.Connect(-1, -1, wxEVT_GRID_COL_SIZE, fn)
1725 def EVT_GRID_RANGE_SELECT(win, fn):
1726 win.Connect(-1, -1, wxEVT_GRID_RANGE_SELECT, fn)
1728 def EVT_GRID_CELL_CHANGE(win, fn):
1729 win.Connect(-1, -1, wxEVT_GRID_CELL_CHANGE, fn)
1731 def EVT_GRID_SELECT_CELL(win, fn):
1732 win.Connect(-1, -1, wxEVT_GRID_SELECT_CELL, fn)
1734 def EVT_GRID_EDITOR_SHOWN(win, fn):
1735 win.Connect(-1, -1, wxEVT_GRID_EDITOR_SHOWN, fn)
1737 def EVT_GRID_EDITOR_HIDDEN(win, fn):
1738 win.Connect(-1, -1, wxEVT_GRID_EDITOR_HIDDEN, fn)
1742 //---------------------------------------------------------------------------
1744 %pragma(python) include="_gridextras.py";
1746 //---------------------------------------------------------------------------