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 /////////////////////////////////////////////////////////////////////////////
20 #include <wx/generic/gridctrl.h>
23 //----------------------------------------------------------------------
26 %include my_typemaps.i
28 // Import some definitions of other classes, etc.
36 %pragma(python) code = "import wx"
38 //----------------------------------------------------------------------
41 // Put some wx default wxChar* values into wxStrings.
42 DECLARE_DEF_STRING(PanelNameStr);
45 //---------------------------------------------------------------------------
46 //---------------------------------------------------------------------------
47 // Macros, similar to what's in helpers.h, to aid in the creation of
48 // virtual methods that are able to make callbacks to Python. Many of these
49 // are specific to wxGrid and so are kept here to reduce the mess in helpers.h
54 #define PYCALLBACK_GCA_INTINTKIND(PCLASS, CBNAME) \
55 wxGridCellAttr* CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
56 wxGridCellAttr* rval = NULL; \
58 wxPyBeginBlockThreads(); \
59 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
61 wxGridCellAttr* ptr; \
62 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iii)", a, b, c)); \
64 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellAttr_p")) \
69 wxPyEndBlockThreads(); \
71 rval = PCLASS::CBNAME(a, b, c); \
74 wxGridCellAttr *base_##CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
75 return PCLASS::CBNAME(a, b, c); \
80 #define PYCALLBACK__GCAINTINT(PCLASS, CBNAME) \
81 void CBNAME(wxGridCellAttr *attr, int a, int b) { \
82 wxPyBeginBlockThreads(); \
84 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
85 PyObject* obj = wxPyConstructObject((void*)attr, "wxGridCellAttr", 0);\
86 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oii)", obj, a, b)); \
89 wxPyEndBlockThreads(); \
91 PCLASS::CBNAME(attr, a, b); \
93 void base_##CBNAME(wxGridCellAttr *attr, int a, int b) { \
94 PCLASS::CBNAME(attr, a, b); \
99 #define PYCALLBACK__GCAINT(PCLASS, CBNAME) \
100 void CBNAME(wxGridCellAttr *attr, int val) { \
101 wxPyBeginBlockThreads(); \
103 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
104 PyObject* obj = wxPyConstructObject((void*)attr, "wxGridCellAttr", 0);\
105 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, val)); \
108 wxPyEndBlockThreads(); \
110 PCLASS::CBNAME(attr, val); \
112 void base_##CBNAME(wxGridCellAttr *attr, int val) { \
113 PCLASS::CBNAME(attr, val); \
118 #define PYCALLBACK_INT__pure(CBNAME) \
120 wxPyBeginBlockThreads(); \
122 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
123 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
124 wxPyEndBlockThreads(); \
130 #define PYCALLBACK_BOOL_INTINT_pure(CBNAME) \
131 bool CBNAME(int a, int b) { \
132 wxPyBeginBlockThreads(); \
134 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
135 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
136 wxPyEndBlockThreads(); \
141 #define PYCALLBACK_STRING_INTINT_pure(CBNAME) \
142 wxString CBNAME(int a, int b) { \
143 wxPyBeginBlockThreads(); \
145 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
147 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
149 rval = Py2wxString(ro); \
153 wxPyEndBlockThreads(); \
158 #define PYCALLBACK__INTINTSTRING_pure(CBNAME) \
159 void CBNAME(int a, int b, const wxString& c) { \
160 wxPyBeginBlockThreads(); \
161 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
162 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,wx2PyString(c)));\
163 wxPyEndBlockThreads(); \
167 #define PYCALLBACK_STRING_INTINT(PCLASS, CBNAME) \
168 wxString CBNAME(int a, int b) { \
170 wxPyBeginBlockThreads(); \
172 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
174 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
176 rval = Py2wxString(ro); \
180 wxPyEndBlockThreads(); \
182 rval = PCLASS::CBNAME(a, b); \
185 wxString base_##CBNAME(int a, int b) { \
186 return PCLASS::CBNAME(a, b); \
190 #define PYCALLBACK_BOOL_INTINTSTRING(PCLASS, CBNAME) \
191 bool CBNAME(int a, int b, const wxString& c) { \
194 wxPyBeginBlockThreads(); \
195 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
196 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", a,b,wx2PyString(c)));\
197 wxPyEndBlockThreads(); \
199 rval = PCLASS::CBNAME(a,b,c); \
202 bool base_##CBNAME(int a, int b, const wxString& c) { \
203 return PCLASS::CBNAME(a,b,c); \
209 #define PYCALLBACK_LONG_INTINT(PCLASS, CBNAME) \
210 long CBNAME(int a, int b) { \
213 wxPyBeginBlockThreads(); \
214 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
215 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
216 wxPyEndBlockThreads(); \
218 rval = PCLASS::CBNAME(a,b); \
221 long base_##CBNAME(int a, int b) { \
222 return PCLASS::CBNAME(a,b); \
227 #define PYCALLBACK_BOOL_INTINT(PCLASS, CBNAME) \
228 bool CBNAME(int a, int b) { \
231 wxPyBeginBlockThreads(); \
232 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
233 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
234 wxPyEndBlockThreads(); \
236 rval = PCLASS::CBNAME(a,b); \
239 bool base_##CBNAME(int a, int b) { \
240 return PCLASS::CBNAME(a,b); \
245 #define PYCALLBACK_DOUBLE_INTINT(PCLASS, CBNAME) \
246 double CBNAME(int a, int b) { \
248 wxPyBeginBlockThreads(); \
250 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
252 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
254 PyObject* str = PyObject_Str(ro); \
255 rval = PyFloat_AsDouble(str); \
256 Py_DECREF(ro); Py_DECREF(str); \
259 wxPyEndBlockThreads(); \
261 rval = PCLASS::CBNAME(a, b); \
264 double base_##CBNAME(int a, int b) { \
265 return PCLASS::CBNAME(a, b); \
270 #define PYCALLBACK__(PCLASS, CBNAME) \
273 wxPyBeginBlockThreads(); \
274 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
275 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
276 wxPyEndBlockThreads(); \
280 void base_##CBNAME() { \
287 #define PYCALLBACK_BOOL_SIZETSIZET(PCLASS, CBNAME) \
288 bool CBNAME(size_t a, size_t b) { \
291 wxPyBeginBlockThreads(); \
292 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
293 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
294 wxPyEndBlockThreads(); \
296 rval = PCLASS::CBNAME(a,b); \
299 bool base_##CBNAME(size_t a, size_t b) { \
300 return PCLASS::CBNAME(a,b); \
305 #define PYCALLBACK_BOOL_SIZET(PCLASS, CBNAME) \
306 bool CBNAME(size_t a) { \
309 wxPyBeginBlockThreads(); \
310 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
311 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)", a)); \
312 wxPyEndBlockThreads(); \
314 rval = PCLASS::CBNAME(a); \
317 bool base_##CBNAME(size_t a) { \
318 return PCLASS::CBNAME(a); \
322 #define PYCALLBACK_STRING_INT(PCLASS, CBNAME) \
323 wxString CBNAME(int a) { \
325 wxPyBeginBlockThreads(); \
327 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
329 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(i)",a)); \
331 rval = Py2wxString(ro); \
335 wxPyEndBlockThreads(); \
337 rval = PCLASS::CBNAME(a); \
340 wxString base_##CBNAME(int a) { \
341 return PCLASS::CBNAME(a); \
345 #define PYCALLBACK__INTSTRING(PCLASS, CBNAME) \
346 void CBNAME(int a, const wxString& c) { \
348 wxPyBeginBlockThreads(); \
349 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
350 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", a, wx2PyString(c))); \
351 wxPyEndBlockThreads(); \
353 PCLASS::CBNAME(a,c); \
355 void base_##CBNAME(int a, const wxString& c) { \
356 PCLASS::CBNAME(a,c); \
362 #define PYCALLBACK_BOOL_(PCLASS, CBNAME) \
366 wxPyBeginBlockThreads(); \
367 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
368 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
369 wxPyEndBlockThreads(); \
371 rval = PCLASS::CBNAME(); \
374 bool base_##CBNAME() { \
375 return PCLASS::CBNAME(); \
380 #define PYCALLBACK__SIZETINT(PCLASS, CBNAME) \
381 void CBNAME(size_t a, int b) { \
383 wxPyBeginBlockThreads(); \
384 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
385 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
386 wxPyEndBlockThreads(); \
388 PCLASS::CBNAME(a,b); \
390 void base_##CBNAME(size_t a, int b) { \
391 PCLASS::CBNAME(a,b); \
397 #define PYCALLBACK__INTINTLONG(PCLASS, CBNAME) \
398 void CBNAME(int a, int b, long c) { \
400 wxPyBeginBlockThreads(); \
401 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
402 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
403 wxPyEndBlockThreads(); \
405 PCLASS::CBNAME(a,b,c); \
407 void base_##CBNAME(int a, int b, long c) { \
408 PCLASS::CBNAME(a,b,c); \
414 #define PYCALLBACK__INTINTDOUBLE(PCLASS, CBNAME) \
415 void CBNAME(int a, int b, double c) { \
417 wxPyBeginBlockThreads(); \
418 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
419 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iif)", a,b,c)); \
420 wxPyEndBlockThreads(); \
422 PCLASS::CBNAME(a,b,c); \
424 void base_##CBNAME(int a, int b, double c) { \
425 PCLASS::CBNAME(a,b,c); \
430 #define PYCALLBACK__INTINTBOOL(PCLASS, CBNAME) \
431 void CBNAME(int a, int b, bool c) { \
433 wxPyBeginBlockThreads(); \
434 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
435 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
436 wxPyEndBlockThreads(); \
438 PCLASS::CBNAME(a,b,c); \
440 void base_##CBNAME(int a, int b, bool c) { \
441 PCLASS::CBNAME(a,b,c); \
449 //---------------------------------------------------------------------------
451 class wxGridCellCoords;
452 class wxGridCellAttr;
456 #define wxGRID_VALUE_STRING "string"
457 #define wxGRID_VALUE_BOOL "bool"
458 #define wxGRID_VALUE_NUMBER "long"
459 #define wxGRID_VALUE_FLOAT "double"
460 #define wxGRID_VALUE_CHOICE "choice"
461 #define wxGRID_VALUE_TEXT "string"
462 #define wxGRID_VALUE_LONG "long"
465 wxGridCellCoords wxGridNoCellCoords;
466 wxRect wxGridNoCellRect;
470 //---------------------------------------------------------------------------
471 // wxGridCellRenderer is an ABC, and several derived classes are available.
472 // Classes implemented in Python should be derived from wxPyGridCellRenderer.
475 class wxGridCellRenderer
478 void SetParameters(const wxString& params);
482 virtual void Draw(wxGrid& grid,
483 wxGridCellAttr& attr,
487 bool isSelected) = 0;
488 virtual wxSize GetBestSize(wxGrid& grid,
489 wxGridCellAttr& attr,
491 int row, int col) = 0;
492 virtual wxGridCellRenderer *Clone() const = 0;
496 // The C++ version of wxPyGridCellRenderer
498 class wxPyGridCellRenderer : public wxGridCellRenderer
501 wxPyGridCellRenderer() : wxGridCellRenderer() {};
503 // Implement Python callback aware virtual methods
504 void Draw(wxGrid& grid, wxGridCellAttr& attr,
505 wxDC& dc, const wxRect& rect,
506 int row, int col, bool isSelected) {
507 wxPyBeginBlockThreads();
508 if (wxPyCBH_findCallback(m_myInst, "Draw")) {
509 wxPyCBH_callCallback(m_myInst,
510 Py_BuildValue("(OOOOiii)",
511 wxPyConstructObject((void*)&grid, "wxGrid", 0),
512 wxPyConstructObject((void*)&attr, "wxGridCellAttr", 0),
513 wxPyConstructObject((void*)&dc, "wxDC", 0),
514 wxPyConstructObject((void*)&rect, "wxRect", 0),
515 row, col, isSelected));
517 wxPyEndBlockThreads();
520 wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
523 wxPyBeginBlockThreads();
524 if (wxPyCBH_findCallback(m_myInst, "GetBestSize")) {
527 ro = wxPyCBH_callCallbackObj(m_myInst,
528 Py_BuildValue("(OOOii)",
529 wxPyConstructObject((void*)&grid, "wxGrid", 0),
530 wxPyConstructObject((void*)&attr, "wxGridCellAttr", 0),
531 wxPyConstructObject((void*)&dc, "wxDC", 0),
534 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p"))
539 wxPyEndBlockThreads();
544 wxGridCellRenderer *Clone() const {
545 wxGridCellRenderer* rval = NULL;
546 wxPyBeginBlockThreads();
547 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
549 wxGridCellRenderer* ptr;
550 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
552 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellRenderer_p"))
557 wxPyEndBlockThreads();
561 DEC_PYCALLBACK__STRING(SetParameters);
566 IMP_PYCALLBACK__STRING( wxPyGridCellRenderer, wxGridCellRenderer, SetParameters);
571 // Let SWIG know about it so it can create the Python version
572 class wxPyGridCellRenderer : public wxGridCellRenderer {
574 wxPyGridCellRenderer();
575 void _setCallbackInfo(PyObject* self, PyObject* _class);
576 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellRenderer)"
578 void base_SetParameters(const wxString& params);
581 //---------------------------------------------------------------------------
582 // Predefined Renderers
584 class wxGridCellStringRenderer : public wxGridCellRenderer
587 wxGridCellStringRenderer();
591 class wxGridCellNumberRenderer : public wxGridCellStringRenderer
594 wxGridCellNumberRenderer();
598 class wxGridCellFloatRenderer : public wxGridCellStringRenderer
601 wxGridCellFloatRenderer(int width = -1, int precision = -1);
603 int GetWidth() const;
604 void SetWidth(int width);
605 int GetPrecision() const;
606 void SetPrecision(int precision);
610 class wxGridCellBoolRenderer : public wxGridCellRenderer
613 wxGridCellBoolRenderer();
617 class wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
620 wxGridCellDateTimeRenderer(wxString outformat = "%c",
621 wxString informat = "%c");
625 class wxGridCellEnumRenderer : public wxGridCellStringRenderer
628 wxGridCellEnumRenderer( const wxString& choices = "" );
632 class wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer
635 wxGridCellAutoWrapStringRenderer();
639 //---------------------------------------------------------------------------
640 // wxGridCellEditor is an ABC, and several derived classes are available.
641 // Classes implemented in Python should be derived from wxPyGridCellEditor.
643 class wxGridCellEditor
647 wxControl* GetControl();
648 void SetControl(wxControl* control);
650 void SetParameters(const wxString& params);
654 virtual void Create(wxWindow* parent,
656 wxEvtHandler* evtHandler) = 0;
657 virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
658 virtual bool EndEdit(int row, int col, wxGrid* grid) = 0;
659 virtual void Reset() = 0;
660 virtual wxGridCellEditor *Clone() const = 0;
662 virtual void SetSize(const wxRect& rect);
663 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
664 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
665 virtual bool IsAcceptedKey(wxKeyEvent& event);
666 virtual void StartingKey(wxKeyEvent& event);
667 virtual void StartingClick();
668 virtual void HandleReturn(wxKeyEvent& event);
669 virtual void Destroy();
674 // The C++ version of wxPyGridCellEditor
676 class wxPyGridCellEditor : public wxGridCellEditor
679 wxPyGridCellEditor() : wxGridCellEditor() {}
681 void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) {
682 wxPyBeginBlockThreads();
683 if (wxPyCBH_findCallback(m_myInst, "Create")) {
684 wxPyCBH_callCallback(m_myInst,
685 Py_BuildValue("(OiO)",
686 wxPyConstructObject((void*)parent, "wxWindow", 0),
688 wxPyConstructObject((void*)evtHandler, "wxEvtHandler", 0)));
690 wxPyEndBlockThreads();
694 void BeginEdit(int row, int col, wxGrid* grid) {
695 wxPyBeginBlockThreads();
696 if (wxPyCBH_findCallback(m_myInst, "BeginEdit")) {
697 wxPyCBH_callCallback(m_myInst,
698 Py_BuildValue("(iiO)", row, col,
699 wxPyConstructObject((void*)grid, "wxGrid", 0)));
701 wxPyEndBlockThreads();
705 bool EndEdit(int row, int col, wxGrid* grid) {
707 wxPyBeginBlockThreads();
708 if (wxPyCBH_findCallback(m_myInst, "EndEdit")) {
709 rv = wxPyCBH_callCallback(m_myInst,
710 Py_BuildValue("(iiO)", row, col,
711 wxPyConstructObject((void*)grid, "wxGrid", 0)));
713 wxPyEndBlockThreads();
718 wxGridCellEditor*Clone() const {
719 wxGridCellEditor* rval = NULL;
720 wxPyBeginBlockThreads();
721 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
723 wxGridCellEditor* ptr;
724 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
726 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellEditor_p"))
731 wxPyEndBlockThreads();
736 void Show(bool show, wxGridCellAttr *attr) {
738 wxPyBeginBlockThreads();
739 if ((found = wxPyCBH_findCallback(m_myInst, "Show")))
740 wxPyCBH_callCallback(m_myInst,
741 Py_BuildValue("(iO)", show,
742 wxPyConstructObject((void*)attr, "wxGridCellAttr", 0)));
743 wxPyEndBlockThreads();
745 wxGridCellEditor::Show(show, attr);
747 void base_Show(bool show, wxGridCellAttr *attr) {
748 wxGridCellEditor::Show(show, attr);
752 void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
754 wxPyBeginBlockThreads();
755 if ((found = wxPyCBH_findCallback(m_myInst, "PaintBackground)")))
756 wxPyCBH_callCallback(m_myInst,
757 Py_BuildValue("(OO)",
758 wxPyConstructObject((void*)&rectCell, "wxRect", 0),
759 wxPyConstructObject((void*)attr, "wxGridCellAttr", 0)));
760 wxPyEndBlockThreads();
762 wxGridCellEditor::PaintBackground(rectCell, attr);
764 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
765 wxGridCellEditor::PaintBackground(rectCell, attr);
769 DEC_PYCALLBACK___pure(Reset);
770 DEC_PYCALLBACK__constany(SetSize, wxRect);
771 DEC_PYCALLBACK_bool_any(IsAcceptedKey, wxKeyEvent);
772 DEC_PYCALLBACK__any(StartingKey, wxKeyEvent);
773 DEC_PYCALLBACK__any(HandleReturn, wxKeyEvent);
774 DEC_PYCALLBACK__(StartingClick);
775 DEC_PYCALLBACK__(Destroy);
776 DEC_PYCALLBACK__STRING(SetParameters);
782 IMP_PYCALLBACK__STRING( wxPyGridCellEditor, wxGridCellEditor, SetParameters);
783 IMP_PYCALLBACK___pure(wxPyGridCellEditor, wxGridCellEditor, Reset);
784 IMP_PYCALLBACK__constany(wxPyGridCellEditor, wxGridCellEditor, SetSize, wxRect);
785 IMP_PYCALLBACK_bool_any(wxPyGridCellEditor, wxGridCellEditor, IsAcceptedKey, wxKeyEvent);
786 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, StartingKey, wxKeyEvent);
787 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, HandleReturn, wxKeyEvent);
788 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, StartingClick);
789 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, Destroy);
794 // Let SWIG know about it so it can create the Python version
795 class wxPyGridCellEditor : public wxGridCellEditor {
797 wxPyGridCellEditor();
798 void _setCallbackInfo(PyObject* self, PyObject* _class);
799 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellEditor)"
801 void base_SetSize(const wxRect& rect);
802 void base_Show(bool show, wxGridCellAttr *attr = NULL);
803 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
804 void base_IsAcceptedKey(wxKeyEvent& event);
805 void base_StartingKey(wxKeyEvent& event);
806 void base_StartingClick();
807 void base_HandleReturn(wxKeyEvent& event);
809 void base_SetParameters(const wxString& params);
812 //---------------------------------------------------------------------------
813 // Predefined Editors
815 class wxGridCellTextEditor : public wxGridCellEditor
818 wxGridCellTextEditor();
822 class wxGridCellNumberEditor : public wxGridCellTextEditor
825 wxGridCellNumberEditor(int min = -1, int max = -1);
829 class wxGridCellFloatEditor : public wxGridCellTextEditor
832 wxGridCellFloatEditor();
836 class wxGridCellBoolEditor : public wxGridCellEditor
839 wxGridCellBoolEditor();
842 class wxGridCellChoiceEditor : public wxGridCellEditor
845 wxGridCellChoiceEditor(int LCOUNT = 0,
846 const wxString* choices = NULL,
847 bool allowOthers = FALSE);
851 class wxGridCellEnumEditor : public wxGridCellChoiceEditor
854 wxGridCellEnumEditor( const wxString& choices = "" );
858 class wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
861 wxGridCellAutoWrapStringEditor();
866 //---------------------------------------------------------------------------
882 wxGridCellAttr(wxGridCellAttr *attrDefault = NULL);
884 wxGridCellAttr *Clone() const;
885 void MergeWith(wxGridCellAttr *mergefrom);
888 void SetTextColour(const wxColour& colText);
889 void SetBackgroundColour(const wxColour& colBack);
890 void SetFont(const wxFont& font);
891 void SetAlignment(int hAlign, int vAlign);
892 void SetReadOnly(bool isReadOnly = TRUE);
894 void SetRenderer(wxGridCellRenderer *renderer);
895 void SetEditor(wxGridCellEditor* editor);
896 void SetKind(wxAttrKind kind);
898 bool HasTextColour() const;
899 bool HasBackgroundColour() const;
900 bool HasFont() const;
901 bool HasAlignment() const;
902 bool HasRenderer() const;
903 bool HasEditor() const;
904 bool HasReadWriteMode() const;
906 wxColour GetTextColour() const;
907 wxColour GetBackgroundColour() const;
908 wxFont GetFont() const;
909 void GetAlignment(int *OUTPUT, int *OUTPUT) const;
910 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
911 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
913 bool IsReadOnly() const;
914 void SetDefAttr(wxGridCellAttr* defAttr);
917 //---------------------------------------------------------------------------
919 class wxGridCellAttrProvider
922 wxGridCellAttrProvider();
923 // ???? virtual ~wxGridCellAttrProvider();
925 wxGridCellAttr *GetAttr(int row, int col,
926 wxGridCellAttr::wxAttrKind kind) const;
927 void SetAttr(wxGridCellAttr *attr, int row, int col);
928 void SetRowAttr(wxGridCellAttr *attr, int row);
929 void SetColAttr(wxGridCellAttr *attr, int col);
931 void UpdateAttrRows( size_t pos, int numRows );
932 void UpdateAttrCols( size_t pos, int numCols );
937 // A Python-aware version
939 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
942 wxPyGridCellAttrProvider() : wxGridCellAttrProvider() {};
944 PYCALLBACK_GCA_INTINTKIND(wxGridCellAttrProvider, GetAttr);
945 PYCALLBACK__GCAINTINT(wxGridCellAttrProvider, SetAttr);
946 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetRowAttr);
947 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetColAttr);
954 // The python-aware version get's SWIGified
955 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
958 wxPyGridCellAttrProvider();
959 void _setCallbackInfo(PyObject* self, PyObject* _class);
960 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellAttrProvider)"
962 wxGridCellAttr *base_GetAttr(int row, int col,
963 wxGridCellAttr::wxAttrKind kind);
964 void base_SetAttr(wxGridCellAttr *attr, int row, int col);
965 void base_SetRowAttr(wxGridCellAttr *attr, int row);
966 void base_SetColAttr(wxGridCellAttr *attr, int col);
970 //---------------------------------------------------------------------------
971 // Grid Table Base class and Python aware version
975 class wxGridTableBase : public wxObject
978 // wxGridTableBase(); This is an ABC
979 //~wxGridTableBase();
981 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
982 wxGridCellAttrProvider *GetAttrProvider() const;
983 void SetView( wxGrid *grid );
984 wxGrid * GetView() const;
988 virtual int GetNumberRows() = 0;
989 virtual int GetNumberCols() = 0;
990 virtual bool IsEmptyCell( int row, int col ) = 0;
991 virtual wxString GetValue( int row, int col ) = 0;
992 virtual void SetValue( int row, int col, const wxString& value ) = 0;
994 // virtuals overridable in wxPyGridTableBase
995 virtual wxString GetTypeName( int row, int col );
996 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
997 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
998 virtual long GetValueAsLong( int row, int col );
999 virtual double GetValueAsDouble( int row, int col );
1000 virtual bool GetValueAsBool( int row, int col );
1001 virtual void SetValueAsLong( int row, int col, long value );
1002 virtual void SetValueAsDouble( int row, int col, double value );
1003 virtual void SetValueAsBool( int row, int col, bool value );
1005 //virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
1006 //virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
1009 virtual void Clear();
1010 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
1011 virtual bool AppendRows( size_t numRows = 1 );
1012 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
1013 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
1014 virtual bool AppendCols( size_t numCols = 1 );
1015 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
1017 virtual wxString GetRowLabelValue( int row );
1018 virtual wxString GetColLabelValue( int col );
1019 virtual void SetRowLabelValue( int row, const wxString& value );
1020 virtual void SetColLabelValue( int col, const wxString& value );
1022 virtual bool CanHaveAttributes();
1024 virtual wxGridCellAttr *GetAttr( int row, int col,
1025 wxGridCellAttr::wxAttrKind kind);
1026 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
1027 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
1028 virtual void SetColAttr(wxGridCellAttr *attr, int col);
1034 // Python-aware version
1036 class wxPyGridTableBase : public wxGridTableBase
1039 wxPyGridTableBase() : wxGridTableBase() {}
1041 PYCALLBACK_INT__pure(GetNumberRows);
1042 PYCALLBACK_INT__pure(GetNumberCols);
1043 PYCALLBACK_BOOL_INTINT_pure(IsEmptyCell);
1044 PYCALLBACK_STRING_INTINT(wxGridTableBase, GetTypeName);
1045 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanGetValueAs);
1046 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanSetValueAs);
1047 PYCALLBACK__(wxGridTableBase, Clear);
1048 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertRows);
1049 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteRows);
1050 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertCols);
1051 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteCols);
1052 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendRows);
1053 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendCols);
1054 PYCALLBACK_STRING_INT(wxGridTableBase, GetRowLabelValue);
1055 PYCALLBACK_STRING_INT(wxGridTableBase, GetColLabelValue);
1056 PYCALLBACK__INTSTRING(wxGridTableBase, SetRowLabelValue);
1057 PYCALLBACK__INTSTRING(wxGridTableBase, SetColLabelValue);
1058 PYCALLBACK_BOOL_(wxGridTableBase, CanHaveAttributes);
1059 PYCALLBACK_GCA_INTINTKIND(wxGridTableBase, GetAttr);
1060 PYCALLBACK__GCAINTINT(wxGridTableBase, SetAttr);
1061 PYCALLBACK__GCAINT(wxGridTableBase, SetRowAttr);
1062 PYCALLBACK__GCAINT(wxGridTableBase, SetColAttr);
1065 wxString GetValue(int row, int col) {
1066 wxPyBeginBlockThreads();
1068 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1070 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",row,col));
1072 rval = Py2wxString(ro);
1076 wxPyEndBlockThreads();
1080 void SetValue(int row, int col, const wxString& val) {
1081 wxPyBeginBlockThreads();
1082 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1083 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",row,col,wx2PyString(val)));
1085 wxPyEndBlockThreads();
1089 // Map the Get/Set methods for the standard non-string types to
1090 // the GetValue and SetValue python methods.
1091 long GetValueAsLong( int row, int col ) {
1093 wxPyBeginBlockThreads();
1094 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1097 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1098 if (ro && PyNumber_Check(ro)) {
1099 num = PyNumber_Int(ro);
1101 rval = PyInt_AsLong(num);
1107 wxPyEndBlockThreads();
1111 double GetValueAsDouble( int row, int col ) {
1113 wxPyBeginBlockThreads();
1114 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1117 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1118 if (ro && PyNumber_Check(ro)) {
1119 num = PyNumber_Float(ro);
1121 rval = PyFloat_AsDouble(num);
1127 wxPyEndBlockThreads();
1131 bool GetValueAsBool( int row, int col ) {
1132 return (bool)GetValueAsLong(row, col);
1135 void SetValueAsLong( int row, int col, long value ) {
1136 wxPyBeginBlockThreads();
1137 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1138 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", row, col, value));
1140 wxPyEndBlockThreads();
1143 void SetValueAsDouble( int row, int col, double value ) {
1144 wxPyBeginBlockThreads();
1145 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1146 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iid)", row, col, value));
1148 wxPyEndBlockThreads();
1151 void SetValueAsBool( int row, int col, bool value ) {
1152 SetValueAsLong( row, col, (long)value );
1161 // The python-aware version get's SWIGified
1162 class wxPyGridTableBase : public wxGridTableBase
1165 wxPyGridTableBase();
1166 void _setCallbackInfo(PyObject* self, PyObject* _class);
1167 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridTableBase)"
1169 %addmethods { void Destroy() { delete self; } }
1171 wxString base_GetTypeName( int row, int col );
1172 bool base_CanGetValueAs( int row, int col, const wxString& typeName );
1173 bool base_CanSetValueAs( int row, int col, const wxString& typeName );
1175 bool base_InsertRows( size_t pos = 0, size_t numRows = 1 );
1176 bool base_AppendRows( size_t numRows = 1 );
1177 bool base_DeleteRows( size_t pos = 0, size_t numRows = 1 );
1178 bool base_InsertCols( size_t pos = 0, size_t numCols = 1 );
1179 bool base_AppendCols( size_t numCols = 1 );
1180 bool base_DeleteCols( size_t pos = 0, size_t numCols = 1 );
1181 wxString base_GetRowLabelValue( int row );
1182 wxString base_GetColLabelValue( int col );
1183 void base_SetRowLabelValue( int row, const wxString& value );
1184 void base_SetColLabelValue( int col, const wxString& value );
1185 bool base_CanHaveAttributes();
1186 wxGridCellAttr *base_GetAttr( int row, int col,
1187 wxGridCellAttr::wxAttrKind kind );
1188 void base_SetAttr(wxGridCellAttr* attr, int row, int col);
1189 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1190 void base_SetColAttr(wxGridCellAttr *attr, int col);
1194 //---------------------------------------------------------------------------
1195 // Predefined Tables
1197 class wxGridStringTable : public wxGridTableBase
1200 wxGridStringTable( int numRows=0, int numCols=0 );
1203 //---------------------------------------------------------------------------
1204 // The Table can pass messages to the grid to tell it to update itself if
1205 // something has changed.
1207 enum wxGridTableRequest
1209 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
1210 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
1211 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
1212 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
1213 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
1214 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1215 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
1216 wxGRIDTABLE_NOTIFY_COLS_DELETED
1220 class wxGridTableMessage
1223 wxGridTableMessage( wxGridTableBase *table, int id,
1226 ~wxGridTableMessage();
1228 void SetTableObject( wxGridTableBase *table );
1229 wxGridTableBase * GetTableObject() const;
1230 void SetId( int id );
1232 void SetCommandInt( int comInt1 );
1233 int GetCommandInt();
1234 void SetCommandInt2( int comInt2 );
1235 int GetCommandInt2();
1239 //---------------------------------------------------------------------------
1241 class wxGridCellCoords
1244 wxGridCellCoords( int r=-1, int c=-1 );
1245 ~wxGridCellCoords();
1247 int GetRow() const { return m_row; }
1248 void SetRow( int n ) { m_row = n; }
1249 int GetCol() const { return m_col; }
1250 void SetCol( int n ) { m_col = n; }
1251 void Set( int row, int col ) { m_row = row; m_col = col; }
1254 PyObject* asTuple() {
1255 PyObject* tup = PyTuple_New(2);
1256 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
1257 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
1261 int __cmp__( const wxGridCellCoords& other ) {
1262 return *self != other;
1265 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
1266 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
1269 // Typemap to allow conversion of sequence objects to wxGridCellCoords...
1270 %typemap(python,in) wxGridCellCoords& (wxGridCellCoords temp) {
1272 if (! wxGridCellCoords_helper($source, &$target))
1276 // ...and here is the associated helper.
1278 bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) {
1280 // If source is an object instance then it may already be the right type
1281 if (PyInstance_Check(source)) {
1282 wxGridCellCoords* ptr;
1283 if (SWIG_GetPtrObj(source, (void **)&ptr, "_wxGridCellCoords_p"))
1288 // otherwise a 2-tuple of integers is expected
1289 else if (PySequence_Check(source) && PyObject_Length(source) == 2) {
1290 PyObject* o1 = PySequence_GetItem(source, 0);
1291 PyObject* o2 = PySequence_GetItem(source, 1);
1292 **obj = wxGridCellCoords(PyInt_AsLong(o1), PyInt_AsLong(o2));
1297 PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of integers or a wxGridCellCoords object.");
1302 //---------------------------------------------------------------------------
1303 //---------------------------------------------------------------------------
1307 // Fool SWIG into treating this enum as an int
1308 typedef int WXGRIDSELECTIONMODES;
1310 // but let the C++ code know what it really is.
1312 typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES;
1317 class wxGrid : public wxScrolledWindow
1320 wxGrid( wxWindow *parent,
1322 const wxPoint& pos = wxDefaultPosition,
1323 const wxSize& size = wxDefaultSize,
1324 long style = wxWANTS_CHARS,
1325 const wxString& name = wxPyPanelNameStr);
1327 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1329 enum wxGridSelectionModes {wxGridSelectCells,
1331 wxGridSelectColumns};
1333 bool CreateGrid( int numRows, int numCols,
1334 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1335 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1338 // ------ grid dimensions
1340 int GetNumberRows();
1341 int GetNumberCols();
1344 bool ProcessTableMessage( wxGridTableMessage& );
1347 wxGridTableBase * GetTable() const;
1348 bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE,
1349 WXGRIDSELECTIONMODES selmode =
1350 wxGrid::wxGridSelectCells );
1353 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1354 bool AppendRows( int numRows = 1, bool updateLabels=TRUE );
1355 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1356 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1357 bool AppendCols( int numCols = 1, bool updateLabels=TRUE );
1358 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1361 // this function is called when the current cell highlight must be redrawn
1362 // and may be overridden by the user
1363 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1366 // ------ Cell text drawing functions
1368 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1369 int horizontalAlignment = wxLEFT,
1370 int verticalAlignment = wxTOP );
1372 // // Split a string containing newline chararcters into an array of
1373 // // strings and return the number of lines
1375 // void StringToLines( const wxString& value, wxArrayString& lines );
1377 void GetTextBoxSize( wxDC& dc,
1378 wxArrayString& lines,
1379 long *OUTPUT, long *OUTPUT );
1383 // Code that does a lot of grid modification can be enclosed
1384 // between BeginBatch() and EndBatch() calls to avoid screen
1389 int GetBatchCount();
1390 void ForceRefresh();
1393 // ------ edit control functions
1395 bool IsEditable() { return m_editable; }
1396 void EnableEditing( bool edit );
1398 void EnableCellEditControl( bool enable = TRUE );
1399 void DisableCellEditControl();
1400 bool CanEnableCellControl() const;
1401 bool IsCellEditControlEnabled() const;
1402 bool IsCellEditControlShown() const;
1404 bool IsCurrentCellReadOnly() const;
1406 void ShowCellEditControl();
1407 void HideCellEditControl();
1408 void SaveEditControlValue();
1411 // ------ grid location functions
1412 // Note that all of these functions work with the logical coordinates of
1413 // grid cells and labels so you will need to convert from device
1414 // coordinates for mouse events etc.
1417 //void XYToCell( int x, int y, wxGridCellCoords& );
1419 %new wxGridCellCoords* XYToCell(int x, int y) {
1420 wxGridCellCoords rv;
1421 self->XYToCell(x, y, rv);
1422 return new wxGridCellCoords(rv);
1426 int YToRow( int y );
1427 int XToCol( int x );
1429 int YToEdgeOfRow( int y );
1430 int XToEdgeOfCol( int x );
1432 wxRect CellToRect( int row, int col );
1433 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1436 int GetGridCursorRow();
1437 int GetGridCursorCol();
1439 // check to see if a cell is either wholly visible (the default arg) or
1440 // at least partially visible in the grid window
1442 bool IsVisible( int row, int col, bool wholeCellVisible = TRUE );
1443 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE );
1444 void MakeCellVisible( int row, int col );
1445 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1448 // ------ grid cursor movement functions
1450 void SetGridCursor( int row, int col );
1451 bool MoveCursorUp( bool expandSelection );
1452 bool MoveCursorDown( bool expandSelection );
1453 bool MoveCursorLeft( bool expandSelection );
1454 bool MoveCursorRight( bool expandSelection );
1455 bool MovePageDown();
1457 bool MoveCursorUpBlock( bool expandSelection );
1458 bool MoveCursorDownBlock( bool expandSelection );
1459 bool MoveCursorLeftBlock( bool expandSelection );
1460 bool MoveCursorRightBlock( bool expandSelection );
1463 // ------ label and gridline formatting
1465 int GetDefaultRowLabelSize();
1466 int GetRowLabelSize();
1467 int GetDefaultColLabelSize();
1468 int GetColLabelSize();
1469 wxColour GetLabelBackgroundColour();
1470 wxColour GetLabelTextColour();
1471 wxFont GetLabelFont();
1472 void GetRowLabelAlignment( int *OUTPUT, int *OUTPUT );
1473 void GetColLabelAlignment( int *OUTPUT, int *OUTPUT );
1474 wxString GetRowLabelValue( int row );
1475 wxString GetColLabelValue( int col );
1476 wxColour GetGridLineColour();
1477 wxColour GetCellHighlightColour();
1478 int GetCellHighlightPenWidth();
1479 int GetCellHighlightROPenWidth();
1481 void SetRowLabelSize( int width );
1482 void SetColLabelSize( int height );
1483 void SetLabelBackgroundColour( const wxColour& );
1484 void SetLabelTextColour( const wxColour& );
1485 void SetLabelFont( const wxFont& );
1486 void SetRowLabelAlignment( int horiz, int vert );
1487 void SetColLabelAlignment( int horiz, int vert );
1488 void SetRowLabelValue( int row, const wxString& );
1489 void SetColLabelValue( int col, const wxString& );
1490 void SetGridLineColour( const wxColour& );
1491 void SetCellHighlightColour( const wxColour& );
1492 void SetCellHighlightPenWidth(int width);
1493 void SetCellHighlightROPenWidth(int width);
1495 void EnableDragRowSize( bool enable = TRUE );
1496 void DisableDragRowSize();
1497 bool CanDragRowSize();
1498 void EnableDragColSize( bool enable = TRUE );
1499 void DisableDragColSize();
1500 bool CanDragColSize();
1501 void EnableDragGridSize(bool enable = TRUE);
1502 void DisableDragGridSize();
1503 bool CanDragGridSize();
1505 // this sets the specified attribute for all cells in this row/col
1506 void SetRowAttr(int row, wxGridCellAttr *attr);
1507 void SetColAttr(int col, wxGridCellAttr *attr);
1509 // shortcuts for setting the column parameters
1511 // set the format for the data in the column: default is string
1512 void SetColFormatBool(int col);
1513 void SetColFormatNumber(int col);
1514 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1515 void SetColFormatCustom(int col, const wxString& typeName);
1517 void EnableGridLines( bool enable = TRUE );
1518 bool GridLinesEnabled();
1520 // ------ row and col formatting
1522 int GetDefaultRowSize();
1523 int GetRowSize( int row );
1524 int GetDefaultColSize();
1525 int GetColSize( int col );
1526 wxColour GetDefaultCellBackgroundColour();
1527 wxColour GetCellBackgroundColour( int row, int col );
1528 wxColour GetDefaultCellTextColour();
1529 wxColour GetCellTextColour( int row, int col );
1530 wxFont GetDefaultCellFont();
1531 wxFont GetCellFont( int row, int col );
1532 void GetDefaultCellAlignment( int *horiz, int *vert );
1533 void GetCellAlignment( int row, int col, int *horiz, int *vert );
1535 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
1536 void SetRowSize( int row, int height );
1537 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
1539 void SetColSize( int col, int width );
1541 // automatically size the column or row to fit to its contents, if
1542 // setAsMin is TRUE, this optimal width will also be set as minimal width
1544 void AutoSizeColumn( int col, bool setAsMin = TRUE );
1545 void AutoSizeRow( int row, bool setAsMin = TRUE );
1548 // auto size all columns (very ineffective for big grids!)
1549 void AutoSizeColumns( bool setAsMin = TRUE );
1550 void AutoSizeRows( bool setAsMin = TRUE );
1552 // auto size the grid, that is make the columns/rows of the "right" size
1553 // and also set the grid size to just fit its contents
1556 // column won't be resized to be lesser width - this must be called during
1557 // the grid creation because it won't resize the column if it's already
1558 // narrower than the minimal width
1559 void SetColMinimalWidth( int col, int width );
1560 void SetRowMinimalHeight( int row, int width );
1562 void SetDefaultCellBackgroundColour( const wxColour& );
1563 void SetCellBackgroundColour( int row, int col, const wxColour& );
1564 void SetDefaultCellTextColour( const wxColour& );
1566 void SetCellTextColour( int row, int col, const wxColour& );
1567 void SetDefaultCellFont( const wxFont& );
1568 void SetCellFont( int row, int col, const wxFont& );
1569 void SetDefaultCellAlignment( int horiz, int vert );
1570 void SetCellAlignment( int row, int col, int horiz, int vert );
1572 // takes ownership of the pointer
1573 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1574 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1575 wxGridCellRenderer *GetDefaultRenderer() const;
1576 wxGridCellRenderer* GetCellRenderer(int row, int col);
1578 // takes ownership of the pointer
1579 void SetDefaultEditor(wxGridCellEditor *editor);
1580 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1581 wxGridCellEditor *GetDefaultEditor() const;
1582 wxGridCellEditor* GetCellEditor(int row, int col);
1586 // ------ cell value accessors
1588 wxString GetCellValue( int row, int col );
1589 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1591 void SetCellValue( int row, int col, const wxString& s );
1592 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1594 // returns TRUE if the cell can't be edited
1595 bool IsReadOnly(int row, int col) const;
1597 // make the cell editable/readonly
1598 void SetReadOnly(int row, int col, bool isReadOnly = TRUE);
1600 // ------ selections of blocks of cells
1602 void SelectRow( int row, bool addToSelected = FALSE );
1603 void SelectCol( int col, bool addToSelected = FALSE );
1605 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1606 bool addToSelected = FALSE );
1607 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1608 // TODO: ??? const wxGridCellCoords& bottomRight )
1612 void ClearSelection();
1613 bool IsInSelection( int row, int col );
1614 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1617 // This function returns the rectangle that encloses the block of cells
1618 // limited by TopLeft and BottomRight cell in device coords and clipped
1619 // to the client size of the grid window.
1621 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1622 const wxGridCellCoords & bottomRight );
1625 // Access or update the selection fore/back colours
1626 wxColour GetSelectionBackground() const;
1627 wxColour GetSelectionForeground() const;
1629 void SetSelectionBackground(const wxColour& c);
1630 void SetSelectionForeground(const wxColour& c);
1633 // Methods for a registry for mapping data types to Renderers/Editors
1634 void RegisterDataType(const wxString& typeName,
1635 wxGridCellRenderer* renderer,
1636 wxGridCellEditor* editor);
1637 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1638 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1639 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1640 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1641 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1643 // grid may occupy more space than needed for its rows/columns, this
1644 // function allows to set how big this extra space is
1645 void SetMargins(int extraWidth, int extraHeight);
1648 // Accessors for component windows
1649 wxWindow* GetGridWindow();
1650 wxWindow* GetGridRowLabelWindow();
1651 wxWindow* GetGridColLabelWindow();
1652 wxWindow* GetGridCornerLabelWindow();
1658 //---------------------------------------------------------------------------
1659 //---------------------------------------------------------------------------
1660 // Grid events and stuff
1664 class wxGridEvent : public wxNotifyEvent
1667 wxGridEvent(int id, wxEventType type, wxGrid* obj,
1668 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = TRUE,
1669 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1671 virtual int GetRow();
1672 virtual int GetCol();
1673 wxPoint GetPosition();
1683 class wxGridSizeEvent : public wxNotifyEvent
1686 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
1687 int rowOrCol=-1, int x=-1, int y=-1,
1688 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1691 wxPoint GetPosition();
1700 class wxGridRangeSelectEvent : public wxNotifyEvent
1703 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
1704 const wxGridCellCoords& topLeft,
1705 const wxGridCellCoords& bottomRight,
1707 bool control=FALSE, bool shift=FALSE,
1708 bool alt=FALSE, bool meta=FALSE);
1710 wxGridCellCoords GetTopLeftCoords();
1711 wxGridCellCoords GetBottomRightCoords();
1724 class wxGridEditorCreatedEvent : public wxCommandEvent {
1726 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
1727 int row, int col, wxControl* ctrl);
1731 wxControl* GetControl();
1732 void SetRow(int row);
1733 void SetCol(int col);
1734 void SetControl(wxControl* ctrl);
1740 wxEVT_GRID_CELL_LEFT_CLICK,
1741 wxEVT_GRID_CELL_RIGHT_CLICK,
1742 wxEVT_GRID_CELL_LEFT_DCLICK,
1743 wxEVT_GRID_CELL_RIGHT_DCLICK,
1744 wxEVT_GRID_LABEL_LEFT_CLICK,
1745 wxEVT_GRID_LABEL_RIGHT_CLICK,
1746 wxEVT_GRID_LABEL_LEFT_DCLICK,
1747 wxEVT_GRID_LABEL_RIGHT_DCLICK,
1748 wxEVT_GRID_ROW_SIZE,
1749 wxEVT_GRID_COL_SIZE,
1750 wxEVT_GRID_RANGE_SELECT,
1751 wxEVT_GRID_CELL_CHANGE,
1752 wxEVT_GRID_SELECT_CELL,
1753 wxEVT_GRID_EDITOR_SHOWN,
1754 wxEVT_GRID_EDITOR_HIDDEN,
1755 wxEVT_GRID_EDITOR_CREATED,
1760 %pragma(python) code = "
1761 def EVT_GRID_CELL_LEFT_CLICK(win, fn):
1762 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_CLICK, fn)
1764 def EVT_GRID_CELL_RIGHT_CLICK(win, fn):
1765 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_CLICK, fn)
1767 def EVT_GRID_CELL_LEFT_DCLICK(win, fn):
1768 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_DCLICK, fn)
1770 def EVT_GRID_CELL_RIGHT_DCLICK(win, fn):
1771 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_DCLICK, fn)
1773 def EVT_GRID_LABEL_LEFT_CLICK(win, fn):
1774 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_CLICK, fn)
1776 def EVT_GRID_LABEL_RIGHT_CLICK(win, fn):
1777 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_CLICK, fn)
1779 def EVT_GRID_LABEL_LEFT_DCLICK(win, fn):
1780 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_DCLICK, fn)
1782 def EVT_GRID_LABEL_RIGHT_DCLICK(win, fn):
1783 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_DCLICK, fn)
1785 def EVT_GRID_ROW_SIZE(win, fn):
1786 win.Connect(-1, -1, wxEVT_GRID_ROW_SIZE, fn)
1788 def EVT_GRID_COL_SIZE(win, fn):
1789 win.Connect(-1, -1, wxEVT_GRID_COL_SIZE, fn)
1791 def EVT_GRID_RANGE_SELECT(win, fn):
1792 win.Connect(-1, -1, wxEVT_GRID_RANGE_SELECT, fn)
1794 def EVT_GRID_CELL_CHANGE(win, fn):
1795 win.Connect(-1, -1, wxEVT_GRID_CELL_CHANGE, fn)
1797 def EVT_GRID_SELECT_CELL(win, fn):
1798 win.Connect(-1, -1, wxEVT_GRID_SELECT_CELL, fn)
1800 def EVT_GRID_EDITOR_SHOWN(win, fn):
1801 win.Connect(-1, -1, wxEVT_GRID_EDITOR_SHOWN, fn)
1803 def EVT_GRID_EDITOR_HIDDEN(win, fn):
1804 win.Connect(-1, -1, wxEVT_GRID_EDITOR_HIDDEN, fn)
1806 def EVT_GRID_EDITOR_CREATED(win, fn):
1807 win.Connect(-1, -1, wxEVT_GRID_EDITOR_CREATED, fn)
1811 //---------------------------------------------------------------------------
1814 wxClassInfo::CleanUpClasses();
1815 wxClassInfo::InitializeClasses();
1818 //---------------------------------------------------------------------------
1820 %pragma(python) include="_gridextras.py";
1822 //---------------------------------------------------------------------------