]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/grid.i
Use the OOR typemap for wxTreeCtrls too.
[wxWidgets.git] / wxPython / src / grid.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: grid.i
3 // Purpose: SWIG definitions for the new wxGrid and related classes
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 17-March-2000
8 // RCS-ID: $Id$
9 // Copyright: (c) 2000 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 %module grid
14
15 #ifndef OLD_GRID
16
17 %{
18 #include "export.h"
19 #include <wx/grid.h>
20 #include <wx/generic/gridctrl.h>
21 %}
22
23 //----------------------------------------------------------------------
24
25 %include typemaps.i
26 %include my_typemaps.i
27
28 // Import some definitions of other classes, etc.
29 %import _defs.i
30 %import misc.i
31 %import gdi.i
32 %import windows.i
33 %import controls.i
34 %import events.i
35
36 %pragma(python) code = "import wx"
37
38 //----------------------------------------------------------------------
39
40 %{
41 // Put some wx default wxChar* values into wxStrings.
42 DECLARE_DEF_STRING(PanelNameStr);
43 %}
44
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
50 // a bit.
51
52
53 %{
54 #define PYCALLBACK_GCA_INTINTKIND(PCLASS, CBNAME) \
55 wxGridCellAttr* CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
56 wxGridCellAttr* rval = NULL; \
57 bool found; \
58 wxPyBeginBlockThreads(); \
59 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
60 PyObject* ro; \
61 wxGridCellAttr* ptr; \
62 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iii)", a, b, c)); \
63 if (ro) { \
64 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellAttr_p")) \
65 rval = ptr; \
66 Py_DECREF(ro); \
67 } \
68 } \
69 wxPyEndBlockThreads(); \
70 if (! found) \
71 rval = PCLASS::CBNAME(a, b, c); \
72 return rval; \
73 } \
74 wxGridCellAttr *base_##CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
75 return PCLASS::CBNAME(a, b, c); \
76 }
77
78
79
80 #define PYCALLBACK__GCAINTINT(PCLASS, CBNAME) \
81 void CBNAME(wxGridCellAttr *attr, int a, int b) { \
82 wxPyBeginBlockThreads(); \
83 bool found; \
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)); \
87 Py_DECREF(obj); \
88 } \
89 wxPyEndBlockThreads(); \
90 if (! found) \
91 PCLASS::CBNAME(attr, a, b); \
92 } \
93 void base_##CBNAME(wxGridCellAttr *attr, int a, int b) { \
94 PCLASS::CBNAME(attr, a, b); \
95 }
96
97
98
99 #define PYCALLBACK__GCAINT(PCLASS, CBNAME) \
100 void CBNAME(wxGridCellAttr *attr, int val) { \
101 wxPyBeginBlockThreads(); \
102 bool found; \
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)); \
106 Py_DECREF(obj); \
107 } \
108 wxPyEndBlockThreads(); \
109 if (! found) \
110 PCLASS::CBNAME(attr, val); \
111 } \
112 void base_##CBNAME(wxGridCellAttr *attr, int val) { \
113 PCLASS::CBNAME(attr, val); \
114 }
115
116
117
118 #define PYCALLBACK_INT__pure(CBNAME) \
119 int CBNAME() { \
120 wxPyBeginBlockThreads(); \
121 int rval = 0; \
122 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
123 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
124 wxPyEndBlockThreads(); \
125 return rval; \
126 }
127
128
129
130 #define PYCALLBACK_BOOL_INTINT_pure(CBNAME) \
131 bool CBNAME(int a, int b) { \
132 wxPyBeginBlockThreads(); \
133 bool rval = 0; \
134 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
135 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
136 wxPyEndBlockThreads(); \
137 return rval; \
138 }
139
140
141 #define PYCALLBACK_STRING_INTINT_pure(CBNAME) \
142 wxString CBNAME(int a, int b) { \
143 wxPyBeginBlockThreads(); \
144 wxString rval; \
145 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
146 PyObject* ro; \
147 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
148 if (ro) { \
149 rval = Py2wxString(ro); \
150 Py_DECREF(ro); \
151 } \
152 } \
153 wxPyEndBlockThreads(); \
154 return rval; \
155 }
156
157
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(); \
164 }
165
166
167 #define PYCALLBACK_STRING_INTINT(PCLASS, CBNAME) \
168 wxString CBNAME(int a, int b) { \
169 bool found; \
170 wxPyBeginBlockThreads(); \
171 wxString rval; \
172 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
173 PyObject* ro; \
174 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
175 if (ro) { \
176 rval = Py2wxString(ro); \
177 Py_DECREF(ro); \
178 } \
179 } \
180 wxPyEndBlockThreads(); \
181 if (! found) \
182 rval = PCLASS::CBNAME(a, b); \
183 return rval; \
184 } \
185 wxString base_##CBNAME(int a, int b) { \
186 return PCLASS::CBNAME(a, b); \
187 }
188
189
190 #define PYCALLBACK_BOOL_INTINTSTRING(PCLASS, CBNAME) \
191 bool CBNAME(int a, int b, const wxString& c) { \
192 bool rval = 0; \
193 bool found; \
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(); \
198 if (! found) \
199 rval = PCLASS::CBNAME(a,b,c); \
200 return rval; \
201 } \
202 bool base_##CBNAME(int a, int b, const wxString& c) { \
203 return PCLASS::CBNAME(a,b,c); \
204 }
205
206
207
208
209 #define PYCALLBACK_LONG_INTINT(PCLASS, CBNAME) \
210 long CBNAME(int a, int b) { \
211 long rval; \
212 bool found; \
213 wxPyBeginBlockThreads(); \
214 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
215 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
216 wxPyEndBlockThreads(); \
217 if (! found) \
218 rval = PCLASS::CBNAME(a,b); \
219 return rval; \
220 } \
221 long base_##CBNAME(int a, int b) { \
222 return PCLASS::CBNAME(a,b); \
223 }
224
225
226
227 #define PYCALLBACK_BOOL_INTINT(PCLASS, CBNAME) \
228 bool CBNAME(int a, int b) { \
229 bool rval = 0; \
230 bool found; \
231 wxPyBeginBlockThreads(); \
232 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
233 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
234 wxPyEndBlockThreads(); \
235 if (! found) \
236 rval = PCLASS::CBNAME(a,b); \
237 return rval; \
238 } \
239 bool base_##CBNAME(int a, int b) { \
240 return PCLASS::CBNAME(a,b); \
241 }
242
243
244
245 #define PYCALLBACK_DOUBLE_INTINT(PCLASS, CBNAME) \
246 double CBNAME(int a, int b) { \
247 bool found; \
248 wxPyBeginBlockThreads(); \
249 double rval; \
250 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
251 PyObject* ro; \
252 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
253 if (ro) { \
254 PyObject* str = PyObject_Str(ro); \
255 rval = PyFloat_AsDouble(str); \
256 Py_DECREF(ro); Py_DECREF(str); \
257 } \
258 } \
259 wxPyEndBlockThreads(); \
260 if (! found) \
261 rval = PCLASS::CBNAME(a, b); \
262 return rval; \
263 } \
264 double base_##CBNAME(int a, int b) { \
265 return PCLASS::CBNAME(a, b); \
266 }
267
268
269
270 #define PYCALLBACK__(PCLASS, CBNAME) \
271 void CBNAME() { \
272 bool found; \
273 wxPyBeginBlockThreads(); \
274 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
275 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
276 wxPyEndBlockThreads(); \
277 if (! found) \
278 PCLASS::CBNAME(); \
279 } \
280 void base_##CBNAME() { \
281 PCLASS::CBNAME(); \
282 }
283
284
285
286
287 #define PYCALLBACK_BOOL_SIZETSIZET(PCLASS, CBNAME) \
288 bool CBNAME(size_t a, size_t b) { \
289 bool rval = 0; \
290 bool found; \
291 wxPyBeginBlockThreads(); \
292 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
293 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
294 wxPyEndBlockThreads(); \
295 if (! found) \
296 rval = PCLASS::CBNAME(a,b); \
297 return rval; \
298 } \
299 bool base_##CBNAME(size_t a, size_t b) { \
300 return PCLASS::CBNAME(a,b); \
301 }
302
303
304
305 #define PYCALLBACK_BOOL_SIZET(PCLASS, CBNAME) \
306 bool CBNAME(size_t a) { \
307 bool rval = 0; \
308 bool found; \
309 wxPyBeginBlockThreads(); \
310 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
311 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)", a)); \
312 wxPyEndBlockThreads(); \
313 if (! found) \
314 rval = PCLASS::CBNAME(a); \
315 return rval; \
316 } \
317 bool base_##CBNAME(size_t a) { \
318 return PCLASS::CBNAME(a); \
319 }
320
321
322 #define PYCALLBACK_STRING_INT(PCLASS, CBNAME) \
323 wxString CBNAME(int a) { \
324 bool found; \
325 wxPyBeginBlockThreads(); \
326 wxString rval; \
327 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
328 PyObject* ro; \
329 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(i)",a)); \
330 if (ro) { \
331 rval = Py2wxString(ro); \
332 Py_DECREF(ro); \
333 } \
334 } \
335 wxPyEndBlockThreads(); \
336 if (! found) \
337 rval = PCLASS::CBNAME(a); \
338 return rval; \
339 } \
340 wxString base_##CBNAME(int a) { \
341 return PCLASS::CBNAME(a); \
342 }
343
344
345 #define PYCALLBACK__INTSTRING(PCLASS, CBNAME) \
346 void CBNAME(int a, const wxString& c) { \
347 bool found; \
348 wxPyBeginBlockThreads(); \
349 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
350 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", a, wx2PyString(c))); \
351 wxPyEndBlockThreads(); \
352 if (! found) \
353 PCLASS::CBNAME(a,c); \
354 } \
355 void base_##CBNAME(int a, const wxString& c) { \
356 PCLASS::CBNAME(a,c); \
357 }
358
359
360
361
362 #define PYCALLBACK_BOOL_(PCLASS, CBNAME) \
363 bool CBNAME() { \
364 bool rval = 0; \
365 bool found; \
366 wxPyBeginBlockThreads(); \
367 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
368 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
369 wxPyEndBlockThreads(); \
370 if (! found) \
371 rval = PCLASS::CBNAME(); \
372 return rval; \
373 } \
374 bool base_##CBNAME() { \
375 return PCLASS::CBNAME(); \
376 }
377
378
379
380 #define PYCALLBACK__SIZETINT(PCLASS, CBNAME) \
381 void CBNAME(size_t a, int b) { \
382 bool found; \
383 wxPyBeginBlockThreads(); \
384 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
385 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
386 wxPyEndBlockThreads(); \
387 if (! found) \
388 PCLASS::CBNAME(a,b); \
389 } \
390 void base_##CBNAME(size_t a, int b) { \
391 PCLASS::CBNAME(a,b); \
392 }
393
394
395
396
397 #define PYCALLBACK__INTINTLONG(PCLASS, CBNAME) \
398 void CBNAME(int a, int b, long c) { \
399 bool found; \
400 wxPyBeginBlockThreads(); \
401 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
402 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
403 wxPyEndBlockThreads(); \
404 if (! found) \
405 PCLASS::CBNAME(a,b,c); \
406 } \
407 void base_##CBNAME(int a, int b, long c) { \
408 PCLASS::CBNAME(a,b,c); \
409 }
410
411
412
413
414 #define PYCALLBACK__INTINTDOUBLE(PCLASS, CBNAME) \
415 void CBNAME(int a, int b, double c) { \
416 bool found; \
417 wxPyBeginBlockThreads(); \
418 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
419 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iif)", a,b,c)); \
420 wxPyEndBlockThreads(); \
421 if (! found) \
422 PCLASS::CBNAME(a,b,c); \
423 } \
424 void base_##CBNAME(int a, int b, double c) { \
425 PCLASS::CBNAME(a,b,c); \
426 }
427
428
429
430 #define PYCALLBACK__INTINTBOOL(PCLASS, CBNAME) \
431 void CBNAME(int a, int b, bool c) { \
432 bool found; \
433 wxPyBeginBlockThreads(); \
434 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
435 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
436 wxPyEndBlockThreads(); \
437 if (! found) \
438 PCLASS::CBNAME(a,b,c); \
439 } \
440 void base_##CBNAME(int a, int b, bool c) { \
441 PCLASS::CBNAME(a,b,c); \
442 }
443
444
445
446
447 %}
448
449 //---------------------------------------------------------------------------
450
451 class wxGridCellCoords;
452 class wxGridCellAttr;
453
454
455
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"
463
464 %readonly
465 wxGridCellCoords wxGridNoCellCoords;
466 wxRect wxGridNoCellRect;
467 %readwrite
468
469
470 //---------------------------------------------------------------------------
471 // wxGridCellRenderer is an ABC, and several derived classes are available.
472 // Classes implemented in Python should be derived from wxPyGridCellRenderer.
473
474
475 class wxGridCellRenderer
476 {
477 public:
478 void SetParameters(const wxString& params);
479 void IncRef();
480 void DecRef();
481
482 virtual void Draw(wxGrid& grid,
483 wxGridCellAttr& attr,
484 wxDC& dc,
485 const wxRect& rect,
486 int row, int col,
487 bool isSelected) = 0;
488 virtual wxSize GetBestSize(wxGrid& grid,
489 wxGridCellAttr& attr,
490 wxDC& dc,
491 int row, int col) = 0;
492 virtual wxGridCellRenderer *Clone() const = 0;
493 };
494
495
496 // The C++ version of wxPyGridCellRenderer
497 %{
498 class wxPyGridCellRenderer : public wxGridCellRenderer
499 {
500 public:
501 wxPyGridCellRenderer() : wxGridCellRenderer() {};
502
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));
516 }
517 wxPyEndBlockThreads();
518 }
519
520 wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
521 int row, int col) {
522 wxSize rval;
523 wxPyBeginBlockThreads();
524 if (wxPyCBH_findCallback(m_myInst, "GetBestSize")) {
525 PyObject* ro;
526 wxSize* ptr;
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),
532 row, col));
533 if (ro) {
534 const char* errmsg = "GetBestSize should return a 2-tuple of integers or a wxSize object.";
535 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p")) {
536 rval = *ptr;
537 }
538 else if (PySequence_Check(ro) && PyObject_Length(ro) == 2) {
539 PyObject* o1 = PySequence_GetItem(ro, 0);
540 PyObject* o2 = PySequence_GetItem(ro, 1);
541 if (PyNumber_Check(o1) && PyNumber_Check(o2))
542 rval = wxSize(PyInt_AsLong(o1), PyInt_AsLong(o2));
543 else
544 PyErr_SetString(PyExc_TypeError, errmsg);
545 Py_DECREF(o1);
546 Py_DECREF(o2);
547 }
548 else {
549 PyErr_SetString(PyExc_TypeError, errmsg);
550 }
551 Py_DECREF(ro);
552 }
553 }
554 wxPyEndBlockThreads();
555 return rval;
556 }
557
558
559 wxGridCellRenderer *Clone() const {
560 wxGridCellRenderer* rval = NULL;
561 wxPyBeginBlockThreads();
562 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
563 PyObject* ro;
564 wxGridCellRenderer* ptr;
565 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
566 if (ro) {
567 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellRenderer_p"))
568 rval = ptr;
569 Py_DECREF(ro);
570 }
571 }
572 wxPyEndBlockThreads();
573 return rval;
574 }
575
576 DEC_PYCALLBACK__STRING(SetParameters);
577
578 PYPRIVATE;
579 };
580
581 IMP_PYCALLBACK__STRING( wxPyGridCellRenderer, wxGridCellRenderer, SetParameters);
582
583 %}
584
585
586 // Let SWIG know about it so it can create the Python version
587 class wxPyGridCellRenderer : public wxGridCellRenderer {
588 public:
589 wxPyGridCellRenderer();
590 void _setCallbackInfo(PyObject* self, PyObject* _class);
591 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellRenderer)"
592
593 void base_SetParameters(const wxString& params);
594 };
595
596 //---------------------------------------------------------------------------
597 // Predefined Renderers
598
599 class wxGridCellStringRenderer : public wxGridCellRenderer
600 {
601 public:
602 wxGridCellStringRenderer();
603 };
604
605
606 class wxGridCellNumberRenderer : public wxGridCellStringRenderer
607 {
608 public:
609 wxGridCellNumberRenderer();
610 };
611
612
613 class wxGridCellFloatRenderer : public wxGridCellStringRenderer
614 {
615 public:
616 wxGridCellFloatRenderer(int width = -1, int precision = -1);
617
618 int GetWidth() const;
619 void SetWidth(int width);
620 int GetPrecision() const;
621 void SetPrecision(int precision);
622 };
623
624
625 class wxGridCellBoolRenderer : public wxGridCellRenderer
626 {
627 public:
628 wxGridCellBoolRenderer();
629 };
630
631
632 class wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
633 {
634 public:
635 wxGridCellDateTimeRenderer(wxString outformat = "%c",
636 wxString informat = "%c");
637 };
638
639
640 class wxGridCellEnumRenderer : public wxGridCellStringRenderer
641 {
642 public:
643 wxGridCellEnumRenderer( const wxString& choices = "" );
644 };
645
646
647 class wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer
648 {
649 public:
650 wxGridCellAutoWrapStringRenderer();
651 };
652
653
654 //---------------------------------------------------------------------------
655 // wxGridCellEditor is an ABC, and several derived classes are available.
656 // Classes implemented in Python should be derived from wxPyGridCellEditor.
657
658 class wxGridCellEditor
659 {
660 public:
661 bool IsCreated();
662 wxControl* GetControl();
663 void SetControl(wxControl* control);
664
665 void SetParameters(const wxString& params);
666 void IncRef();
667 void DecRef();
668
669 virtual void Create(wxWindow* parent,
670 wxWindowID id,
671 wxEvtHandler* evtHandler) = 0;
672 virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
673 virtual bool EndEdit(int row, int col, wxGrid* grid) = 0;
674 virtual void Reset() = 0;
675 virtual wxGridCellEditor *Clone() const = 0;
676
677 virtual void SetSize(const wxRect& rect);
678 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
679 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
680 virtual bool IsAcceptedKey(wxKeyEvent& event);
681 virtual void StartingKey(wxKeyEvent& event);
682 virtual void StartingClick();
683 virtual void HandleReturn(wxKeyEvent& event);
684 virtual void Destroy();
685
686 };
687
688
689 // The C++ version of wxPyGridCellEditor
690 %{
691 class wxPyGridCellEditor : public wxGridCellEditor
692 {
693 public:
694 wxPyGridCellEditor() : wxGridCellEditor() {}
695
696 void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) {
697 wxPyBeginBlockThreads();
698 if (wxPyCBH_findCallback(m_myInst, "Create")) {
699 wxPyCBH_callCallback(m_myInst,
700 Py_BuildValue("(OiO)",
701 wxPyConstructObject((void*)parent, "wxWindow", 0),
702 id,
703 wxPyConstructObject((void*)evtHandler, "wxEvtHandler", 0)));
704 }
705 wxPyEndBlockThreads();
706 }
707
708
709 void BeginEdit(int row, int col, wxGrid* grid) {
710 wxPyBeginBlockThreads();
711 if (wxPyCBH_findCallback(m_myInst, "BeginEdit")) {
712 wxPyCBH_callCallback(m_myInst,
713 Py_BuildValue("(iiO)", row, col,
714 wxPyConstructObject((void*)grid, "wxGrid", 0)));
715 }
716 wxPyEndBlockThreads();
717 }
718
719
720 bool EndEdit(int row, int col, wxGrid* grid) {
721 bool rv = FALSE;
722 wxPyBeginBlockThreads();
723 if (wxPyCBH_findCallback(m_myInst, "EndEdit")) {
724 rv = wxPyCBH_callCallback(m_myInst,
725 Py_BuildValue("(iiO)", row, col,
726 wxPyConstructObject((void*)grid, "wxGrid", 0)));
727 }
728 wxPyEndBlockThreads();
729 return rv;
730 }
731
732
733 wxGridCellEditor*Clone() const {
734 wxGridCellEditor* rval = NULL;
735 wxPyBeginBlockThreads();
736 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
737 PyObject* ro;
738 wxGridCellEditor* ptr;
739 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
740 if (ro) {
741 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellEditor_p"))
742 rval = ptr;
743 Py_DECREF(ro);
744 }
745 }
746 wxPyEndBlockThreads();
747 return rval;
748 }
749
750
751 void Show(bool show, wxGridCellAttr *attr) {
752 bool found;
753 wxPyBeginBlockThreads();
754 if ((found = wxPyCBH_findCallback(m_myInst, "Show")))
755 wxPyCBH_callCallback(m_myInst,
756 Py_BuildValue("(iO)", show,
757 wxPyConstructObject((void*)attr, "wxGridCellAttr", 0)));
758 wxPyEndBlockThreads();
759 if (! found)
760 wxGridCellEditor::Show(show, attr);
761 }
762 void base_Show(bool show, wxGridCellAttr *attr) {
763 wxGridCellEditor::Show(show, attr);
764 }
765
766
767 void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
768 bool found; \
769 wxPyBeginBlockThreads();
770 if ((found = wxPyCBH_findCallback(m_myInst, "PaintBackground)")))
771 wxPyCBH_callCallback(m_myInst,
772 Py_BuildValue("(OO)",
773 wxPyConstructObject((void*)&rectCell, "wxRect", 0),
774 wxPyConstructObject((void*)attr, "wxGridCellAttr", 0)));
775 wxPyEndBlockThreads();
776 if (! found)
777 wxGridCellEditor::PaintBackground(rectCell, attr);
778 }
779 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
780 wxGridCellEditor::PaintBackground(rectCell, attr);
781 }
782
783
784 DEC_PYCALLBACK___pure(Reset);
785 DEC_PYCALLBACK__constany(SetSize, wxRect);
786 DEC_PYCALLBACK_bool_any(IsAcceptedKey, wxKeyEvent);
787 DEC_PYCALLBACK__any(StartingKey, wxKeyEvent);
788 DEC_PYCALLBACK__any(HandleReturn, wxKeyEvent);
789 DEC_PYCALLBACK__(StartingClick);
790 DEC_PYCALLBACK__(Destroy);
791 DEC_PYCALLBACK__STRING(SetParameters);
792
793 PYPRIVATE;
794 };
795
796
797 IMP_PYCALLBACK__STRING( wxPyGridCellEditor, wxGridCellEditor, SetParameters);
798 IMP_PYCALLBACK___pure(wxPyGridCellEditor, wxGridCellEditor, Reset);
799 IMP_PYCALLBACK__constany(wxPyGridCellEditor, wxGridCellEditor, SetSize, wxRect);
800 IMP_PYCALLBACK_bool_any(wxPyGridCellEditor, wxGridCellEditor, IsAcceptedKey, wxKeyEvent);
801 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, StartingKey, wxKeyEvent);
802 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, HandleReturn, wxKeyEvent);
803 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, StartingClick);
804 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, Destroy);
805
806 %}
807
808
809 // Let SWIG know about it so it can create the Python version
810 class wxPyGridCellEditor : public wxGridCellEditor {
811 public:
812 wxPyGridCellEditor();
813 void _setCallbackInfo(PyObject* self, PyObject* _class);
814 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellEditor)"
815
816 void base_SetSize(const wxRect& rect);
817 void base_Show(bool show, wxGridCellAttr *attr = NULL);
818 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
819 void base_IsAcceptedKey(wxKeyEvent& event);
820 void base_StartingKey(wxKeyEvent& event);
821 void base_StartingClick();
822 void base_HandleReturn(wxKeyEvent& event);
823 void base_Destroy();
824 void base_SetParameters(const wxString& params);
825 };
826
827 //---------------------------------------------------------------------------
828 // Predefined Editors
829
830 class wxGridCellTextEditor : public wxGridCellEditor
831 {
832 public:
833 wxGridCellTextEditor();
834 };
835
836
837 class wxGridCellNumberEditor : public wxGridCellTextEditor
838 {
839 public:
840 wxGridCellNumberEditor(int min = -1, int max = -1);
841 };
842
843
844 class wxGridCellFloatEditor : public wxGridCellTextEditor
845 {
846 public:
847 wxGridCellFloatEditor();
848 };
849
850
851 class wxGridCellBoolEditor : public wxGridCellEditor
852 {
853 public:
854 wxGridCellBoolEditor();
855 };
856
857 class wxGridCellChoiceEditor : public wxGridCellEditor
858 {
859 public:
860 wxGridCellChoiceEditor(int LCOUNT = 0,
861 const wxString* choices = NULL,
862 bool allowOthers = FALSE);
863 };
864
865
866 class wxGridCellEnumEditor : public wxGridCellChoiceEditor
867 {
868 public:
869 wxGridCellEnumEditor( const wxString& choices = "" );
870 };
871
872
873 class wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
874 {
875 public:
876 wxGridCellAutoWrapStringEditor();
877 };
878
879
880
881 //---------------------------------------------------------------------------
882
883
884 class wxGridCellAttr
885 {
886 public:
887 enum wxAttrKind
888 {
889 Any,
890 Default,
891 Cell,
892 Row,
893 Col,
894 Merged
895 };
896
897 wxGridCellAttr(wxGridCellAttr *attrDefault = NULL);
898
899 wxGridCellAttr *Clone() const;
900 void MergeWith(wxGridCellAttr *mergefrom);
901 void IncRef();
902 void DecRef();
903 void SetTextColour(const wxColour& colText);
904 void SetBackgroundColour(const wxColour& colBack);
905 void SetFont(const wxFont& font);
906 void SetAlignment(int hAlign, int vAlign);
907 void SetReadOnly(bool isReadOnly = TRUE);
908
909 void SetRenderer(wxGridCellRenderer *renderer);
910 void SetEditor(wxGridCellEditor* editor);
911 void SetKind(wxAttrKind kind);
912
913 bool HasTextColour() const;
914 bool HasBackgroundColour() const;
915 bool HasFont() const;
916 bool HasAlignment() const;
917 bool HasRenderer() const;
918 bool HasEditor() const;
919 bool HasReadWriteMode() const;
920
921 wxColour GetTextColour() const;
922 wxColour GetBackgroundColour() const;
923 wxFont GetFont() const;
924 void GetAlignment(int *OUTPUT, int *OUTPUT) const;
925 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
926 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
927
928 bool IsReadOnly() const;
929 void SetDefAttr(wxGridCellAttr* defAttr);
930 };
931
932 //---------------------------------------------------------------------------
933
934 class wxGridCellAttrProvider
935 {
936 public:
937 wxGridCellAttrProvider();
938 // ???? virtual ~wxGridCellAttrProvider();
939
940 wxGridCellAttr *GetAttr(int row, int col,
941 wxGridCellAttr::wxAttrKind kind) const;
942 void SetAttr(wxGridCellAttr *attr, int row, int col);
943 void SetRowAttr(wxGridCellAttr *attr, int row);
944 void SetColAttr(wxGridCellAttr *attr, int col);
945
946 void UpdateAttrRows( size_t pos, int numRows );
947 void UpdateAttrCols( size_t pos, int numCols );
948
949 };
950
951
952 // A Python-aware version
953 %{
954 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
955 {
956 public:
957 wxPyGridCellAttrProvider() : wxGridCellAttrProvider() {};
958
959 PYCALLBACK_GCA_INTINTKIND(wxGridCellAttrProvider, GetAttr);
960 PYCALLBACK__GCAINTINT(wxGridCellAttrProvider, SetAttr);
961 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetRowAttr);
962 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetColAttr);
963
964 PYPRIVATE;
965 };
966 %}
967
968
969 // The python-aware version get's SWIGified
970 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
971 {
972 public:
973 wxPyGridCellAttrProvider();
974 void _setCallbackInfo(PyObject* self, PyObject* _class);
975 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellAttrProvider)"
976
977 wxGridCellAttr *base_GetAttr(int row, int col,
978 wxGridCellAttr::wxAttrKind kind);
979 void base_SetAttr(wxGridCellAttr *attr, int row, int col);
980 void base_SetRowAttr(wxGridCellAttr *attr, int row);
981 void base_SetColAttr(wxGridCellAttr *attr, int col);
982 };
983
984
985 //---------------------------------------------------------------------------
986 // Grid Table Base class and Python aware version
987
988
989
990 class wxGridTableBase : public wxObject
991 {
992 public:
993 // wxGridTableBase(); This is an ABC
994 //~wxGridTableBase();
995
996 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
997 wxGridCellAttrProvider *GetAttrProvider() const;
998 void SetView( wxGrid *grid );
999 wxGrid * GetView() const;
1000
1001
1002 // pure virtuals
1003 virtual int GetNumberRows() = 0;
1004 virtual int GetNumberCols() = 0;
1005 virtual bool IsEmptyCell( int row, int col ) = 0;
1006 virtual wxString GetValue( int row, int col ) = 0;
1007 virtual void SetValue( int row, int col, const wxString& value ) = 0;
1008
1009 // virtuals overridable in wxPyGridTableBase
1010 virtual wxString GetTypeName( int row, int col );
1011 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
1012 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
1013 virtual long GetValueAsLong( int row, int col );
1014 virtual double GetValueAsDouble( int row, int col );
1015 virtual bool GetValueAsBool( int row, int col );
1016 virtual void SetValueAsLong( int row, int col, long value );
1017 virtual void SetValueAsDouble( int row, int col, double value );
1018 virtual void SetValueAsBool( int row, int col, bool value );
1019
1020 //virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
1021 //virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
1022
1023
1024 virtual void Clear();
1025 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
1026 virtual bool AppendRows( size_t numRows = 1 );
1027 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
1028 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
1029 virtual bool AppendCols( size_t numCols = 1 );
1030 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
1031
1032 virtual wxString GetRowLabelValue( int row );
1033 virtual wxString GetColLabelValue( int col );
1034 virtual void SetRowLabelValue( int row, const wxString& value );
1035 virtual void SetColLabelValue( int col, const wxString& value );
1036
1037 virtual bool CanHaveAttributes();
1038
1039 virtual wxGridCellAttr *GetAttr( int row, int col,
1040 wxGridCellAttr::wxAttrKind kind);
1041 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
1042 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
1043 virtual void SetColAttr(wxGridCellAttr *attr, int col);
1044
1045 };
1046
1047
1048
1049 // Python-aware version
1050 %{
1051 class wxPyGridTableBase : public wxGridTableBase
1052 {
1053 public:
1054 wxPyGridTableBase() : wxGridTableBase() {}
1055
1056 PYCALLBACK_INT__pure(GetNumberRows);
1057 PYCALLBACK_INT__pure(GetNumberCols);
1058 PYCALLBACK_BOOL_INTINT_pure(IsEmptyCell);
1059 PYCALLBACK_STRING_INTINT(wxGridTableBase, GetTypeName);
1060 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanGetValueAs);
1061 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanSetValueAs);
1062 PYCALLBACK__(wxGridTableBase, Clear);
1063 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertRows);
1064 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteRows);
1065 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertCols);
1066 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteCols);
1067 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendRows);
1068 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendCols);
1069 PYCALLBACK_STRING_INT(wxGridTableBase, GetRowLabelValue);
1070 PYCALLBACK_STRING_INT(wxGridTableBase, GetColLabelValue);
1071 PYCALLBACK__INTSTRING(wxGridTableBase, SetRowLabelValue);
1072 PYCALLBACK__INTSTRING(wxGridTableBase, SetColLabelValue);
1073 PYCALLBACK_BOOL_(wxGridTableBase, CanHaveAttributes);
1074 PYCALLBACK_GCA_INTINTKIND(wxGridTableBase, GetAttr);
1075 PYCALLBACK__GCAINTINT(wxGridTableBase, SetAttr);
1076 PYCALLBACK__GCAINT(wxGridTableBase, SetRowAttr);
1077 PYCALLBACK__GCAINT(wxGridTableBase, SetColAttr);
1078
1079
1080 wxString GetValue(int row, int col) {
1081 wxPyBeginBlockThreads();
1082 wxString rval;
1083 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1084 PyObject* ro;
1085 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",row,col));
1086 if (ro) {
1087 rval = Py2wxString(ro);
1088 Py_DECREF(ro);
1089 }
1090 }
1091 wxPyEndBlockThreads();
1092 return rval;
1093 }
1094
1095 void SetValue(int row, int col, const wxString& val) {
1096 wxPyBeginBlockThreads();
1097 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1098 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",row,col,wx2PyString(val)));
1099 }
1100 wxPyEndBlockThreads();
1101 }
1102
1103
1104 // Map the Get/Set methods for the standard non-string types to
1105 // the GetValue and SetValue python methods.
1106 long GetValueAsLong( int row, int col ) {
1107 long rval = 0;
1108 wxPyBeginBlockThreads();
1109 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1110 PyObject* ro;
1111 PyObject* num;
1112 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1113 if (ro && PyNumber_Check(ro)) {
1114 num = PyNumber_Int(ro);
1115 if (num) {
1116 rval = PyInt_AsLong(num);
1117 Py_DECREF(num);
1118 }
1119 Py_DECREF(ro);
1120 }
1121 }
1122 wxPyEndBlockThreads();
1123 return rval;
1124 }
1125
1126 double GetValueAsDouble( int row, int col ) {
1127 double rval = 0.0;
1128 wxPyBeginBlockThreads();
1129 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1130 PyObject* ro;
1131 PyObject* num;
1132 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1133 if (ro && PyNumber_Check(ro)) {
1134 num = PyNumber_Float(ro);
1135 if (num) {
1136 rval = PyFloat_AsDouble(num);
1137 Py_DECREF(num);
1138 }
1139 Py_DECREF(ro);
1140 }
1141 }
1142 wxPyEndBlockThreads();
1143 return rval;
1144 }
1145
1146 bool GetValueAsBool( int row, int col ) {
1147 return (bool)GetValueAsLong(row, col);
1148 }
1149
1150 void SetValueAsLong( int row, int col, long value ) {
1151 wxPyBeginBlockThreads();
1152 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1153 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", row, col, value));
1154 }
1155 wxPyEndBlockThreads();
1156 }
1157
1158 void SetValueAsDouble( int row, int col, double value ) {
1159 wxPyBeginBlockThreads();
1160 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1161 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iid)", row, col, value));
1162 }
1163 wxPyEndBlockThreads();
1164 }
1165
1166 void SetValueAsBool( int row, int col, bool value ) {
1167 SetValueAsLong( row, col, (long)value );
1168 }
1169
1170
1171 PYPRIVATE;
1172 };
1173 %}
1174
1175
1176 // The python-aware version get's SWIGified
1177 class wxPyGridTableBase : public wxGridTableBase
1178 {
1179 public:
1180 wxPyGridTableBase();
1181 void _setCallbackInfo(PyObject* self, PyObject* _class);
1182 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridTableBase)"
1183
1184 %addmethods { void Destroy() { delete self; } }
1185
1186 wxString base_GetTypeName( int row, int col );
1187 bool base_CanGetValueAs( int row, int col, const wxString& typeName );
1188 bool base_CanSetValueAs( int row, int col, const wxString& typeName );
1189 void base_Clear();
1190 bool base_InsertRows( size_t pos = 0, size_t numRows = 1 );
1191 bool base_AppendRows( size_t numRows = 1 );
1192 bool base_DeleteRows( size_t pos = 0, size_t numRows = 1 );
1193 bool base_InsertCols( size_t pos = 0, size_t numCols = 1 );
1194 bool base_AppendCols( size_t numCols = 1 );
1195 bool base_DeleteCols( size_t pos = 0, size_t numCols = 1 );
1196 wxString base_GetRowLabelValue( int row );
1197 wxString base_GetColLabelValue( int col );
1198 void base_SetRowLabelValue( int row, const wxString& value );
1199 void base_SetColLabelValue( int col, const wxString& value );
1200 bool base_CanHaveAttributes();
1201 wxGridCellAttr *base_GetAttr( int row, int col,
1202 wxGridCellAttr::wxAttrKind kind );
1203 void base_SetAttr(wxGridCellAttr* attr, int row, int col);
1204 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1205 void base_SetColAttr(wxGridCellAttr *attr, int col);
1206 };
1207
1208
1209 //---------------------------------------------------------------------------
1210 // Predefined Tables
1211
1212 class wxGridStringTable : public wxGridTableBase
1213 {
1214 public:
1215 wxGridStringTable( int numRows=0, int numCols=0 );
1216 };
1217
1218 //---------------------------------------------------------------------------
1219 // The Table can pass messages to the grid to tell it to update itself if
1220 // something has changed.
1221
1222 enum wxGridTableRequest
1223 {
1224 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
1225 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
1226 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
1227 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
1228 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
1229 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1230 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
1231 wxGRIDTABLE_NOTIFY_COLS_DELETED
1232 };
1233
1234
1235 class wxGridTableMessage
1236 {
1237 public:
1238 wxGridTableMessage( wxGridTableBase *table, int id,
1239 int comInt1 = -1,
1240 int comInt2 = -1 );
1241 ~wxGridTableMessage();
1242
1243 void SetTableObject( wxGridTableBase *table );
1244 wxGridTableBase * GetTableObject() const;
1245 void SetId( int id );
1246 int GetId();
1247 void SetCommandInt( int comInt1 );
1248 int GetCommandInt();
1249 void SetCommandInt2( int comInt2 );
1250 int GetCommandInt2();
1251 };
1252
1253
1254 //---------------------------------------------------------------------------
1255
1256 class wxGridCellCoords
1257 {
1258 public:
1259 wxGridCellCoords( int r=-1, int c=-1 );
1260 ~wxGridCellCoords();
1261
1262 int GetRow() const { return m_row; }
1263 void SetRow( int n ) { m_row = n; }
1264 int GetCol() const { return m_col; }
1265 void SetCol( int n ) { m_col = n; }
1266 void Set( int row, int col ) { m_row = row; m_col = col; }
1267
1268 %addmethods {
1269 PyObject* asTuple() {
1270 PyObject* tup = PyTuple_New(2);
1271 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
1272 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
1273 return tup;
1274 }
1275
1276 int __cmp__( const wxGridCellCoords& other ) {
1277 return *self != other;
1278 }
1279 }
1280 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
1281 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
1282 };
1283
1284 // Typemap to allow conversion of sequence objects to wxGridCellCoords...
1285 %typemap(python,in) wxGridCellCoords& (wxGridCellCoords temp) {
1286 $target = &temp;
1287 if (! wxGridCellCoords_helper($source, &$target))
1288 return NULL;
1289 }
1290
1291 // ...and here is the associated helper.
1292 %{
1293 bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) {
1294
1295 // If source is an object instance then it may already be the right type
1296 if (PyInstance_Check(source)) {
1297 wxGridCellCoords* ptr;
1298 if (SWIG_GetPtrObj(source, (void **)&ptr, "_wxGridCellCoords_p"))
1299 goto error;
1300 *obj = ptr;
1301 return TRUE;
1302 }
1303 // otherwise a 2-tuple of integers is expected
1304 else if (PySequence_Check(source) && PyObject_Length(source) == 2) {
1305 PyObject* o1 = PySequence_GetItem(source, 0);
1306 PyObject* o2 = PySequence_GetItem(source, 1);
1307 **obj = wxGridCellCoords(PyInt_AsLong(o1), PyInt_AsLong(o2));
1308 return TRUE;
1309 }
1310
1311 error:
1312 PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of integers or a wxGridCellCoords object.");
1313 return FALSE;
1314 }
1315 %}
1316
1317 //---------------------------------------------------------------------------
1318 //---------------------------------------------------------------------------
1319 // The grid itself
1320
1321
1322 // Fool SWIG into treating this enum as an int
1323 typedef int WXGRIDSELECTIONMODES;
1324
1325 // but let the C++ code know what it really is.
1326 %{
1327 typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES;
1328 %}
1329
1330
1331
1332 class wxGrid : public wxScrolledWindow
1333 {
1334 public:
1335 wxGrid( wxWindow *parent,
1336 wxWindowID id,
1337 const wxPoint& pos = wxDefaultPosition,
1338 const wxSize& size = wxDefaultSize,
1339 long style = wxWANTS_CHARS,
1340 const wxString& name = wxPyPanelNameStr);
1341
1342 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1343
1344 enum wxGridSelectionModes {wxGridSelectCells,
1345 wxGridSelectRows,
1346 wxGridSelectColumns};
1347
1348 bool CreateGrid( int numRows, int numCols,
1349 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1350 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1351
1352
1353 // ------ grid dimensions
1354 //
1355 int GetNumberRows();
1356 int GetNumberCols();
1357
1358
1359 bool ProcessTableMessage( wxGridTableMessage& );
1360
1361
1362 wxGridTableBase * GetTable() const;
1363 bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE,
1364 WXGRIDSELECTIONMODES selmode =
1365 wxGrid::wxGridSelectCells );
1366
1367 void ClearGrid();
1368 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1369 bool AppendRows( int numRows = 1, bool updateLabels=TRUE );
1370 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1371 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1372 bool AppendCols( int numCols = 1, bool updateLabels=TRUE );
1373 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1374
1375
1376 // this function is called when the current cell highlight must be redrawn
1377 // and may be overridden by the user
1378 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1379
1380
1381 // ------ Cell text drawing functions
1382 //
1383 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1384 int horizontalAlignment = wxLEFT,
1385 int verticalAlignment = wxTOP );
1386
1387 // // Split a string containing newline chararcters into an array of
1388 // // strings and return the number of lines
1389 // //
1390 // void StringToLines( const wxString& value, wxArrayString& lines );
1391
1392 void GetTextBoxSize( wxDC& dc,
1393 wxArrayString& lines,
1394 long *OUTPUT, long *OUTPUT );
1395
1396
1397 // ------
1398 // Code that does a lot of grid modification can be enclosed
1399 // between BeginBatch() and EndBatch() calls to avoid screen
1400 // flicker
1401 //
1402 void BeginBatch();
1403 void EndBatch();
1404 int GetBatchCount();
1405 void ForceRefresh();
1406
1407
1408 // ------ edit control functions
1409 //
1410 bool IsEditable() { return m_editable; }
1411 void EnableEditing( bool edit );
1412
1413 void EnableCellEditControl( bool enable = TRUE );
1414 void DisableCellEditControl();
1415 bool CanEnableCellControl() const;
1416 bool IsCellEditControlEnabled() const;
1417 bool IsCellEditControlShown() const;
1418
1419 bool IsCurrentCellReadOnly() const;
1420
1421 void ShowCellEditControl();
1422 void HideCellEditControl();
1423 void SaveEditControlValue();
1424
1425
1426 // ------ grid location functions
1427 // Note that all of these functions work with the logical coordinates of
1428 // grid cells and labels so you will need to convert from device
1429 // coordinates for mouse events etc.
1430 //
1431
1432 //void XYToCell( int x, int y, wxGridCellCoords& );
1433 %addmethods {
1434 %new wxGridCellCoords* XYToCell(int x, int y) {
1435 wxGridCellCoords rv;
1436 self->XYToCell(x, y, rv);
1437 return new wxGridCellCoords(rv);
1438 }
1439 }
1440
1441 int YToRow( int y );
1442 int XToCol( int x );
1443
1444 int YToEdgeOfRow( int y );
1445 int XToEdgeOfCol( int x );
1446
1447 wxRect CellToRect( int row, int col );
1448 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1449
1450
1451 int GetGridCursorRow();
1452 int GetGridCursorCol();
1453
1454 // check to see if a cell is either wholly visible (the default arg) or
1455 // at least partially visible in the grid window
1456 //
1457 bool IsVisible( int row, int col, bool wholeCellVisible = TRUE );
1458 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE );
1459 void MakeCellVisible( int row, int col );
1460 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1461
1462
1463 // ------ grid cursor movement functions
1464 //
1465 void SetGridCursor( int row, int col );
1466 bool MoveCursorUp( bool expandSelection );
1467 bool MoveCursorDown( bool expandSelection );
1468 bool MoveCursorLeft( bool expandSelection );
1469 bool MoveCursorRight( bool expandSelection );
1470 bool MovePageDown();
1471 bool MovePageUp();
1472 bool MoveCursorUpBlock( bool expandSelection );
1473 bool MoveCursorDownBlock( bool expandSelection );
1474 bool MoveCursorLeftBlock( bool expandSelection );
1475 bool MoveCursorRightBlock( bool expandSelection );
1476
1477
1478 // ------ label and gridline formatting
1479 //
1480 int GetDefaultRowLabelSize();
1481 int GetRowLabelSize();
1482 int GetDefaultColLabelSize();
1483 int GetColLabelSize();
1484 wxColour GetLabelBackgroundColour();
1485 wxColour GetLabelTextColour();
1486 wxFont GetLabelFont();
1487 void GetRowLabelAlignment( int *OUTPUT, int *OUTPUT );
1488 void GetColLabelAlignment( int *OUTPUT, int *OUTPUT );
1489 wxString GetRowLabelValue( int row );
1490 wxString GetColLabelValue( int col );
1491 wxColour GetGridLineColour();
1492 wxColour GetCellHighlightColour();
1493 int GetCellHighlightPenWidth();
1494 int GetCellHighlightROPenWidth();
1495
1496 void SetRowLabelSize( int width );
1497 void SetColLabelSize( int height );
1498 void SetLabelBackgroundColour( const wxColour& );
1499 void SetLabelTextColour( const wxColour& );
1500 void SetLabelFont( const wxFont& );
1501 void SetRowLabelAlignment( int horiz, int vert );
1502 void SetColLabelAlignment( int horiz, int vert );
1503 void SetRowLabelValue( int row, const wxString& );
1504 void SetColLabelValue( int col, const wxString& );
1505 void SetGridLineColour( const wxColour& );
1506 void SetCellHighlightColour( const wxColour& );
1507 void SetCellHighlightPenWidth(int width);
1508 void SetCellHighlightROPenWidth(int width);
1509
1510 void EnableDragRowSize( bool enable = TRUE );
1511 void DisableDragRowSize();
1512 bool CanDragRowSize();
1513 void EnableDragColSize( bool enable = TRUE );
1514 void DisableDragColSize();
1515 bool CanDragColSize();
1516 void EnableDragGridSize(bool enable = TRUE);
1517 void DisableDragGridSize();
1518 bool CanDragGridSize();
1519
1520 // this sets the specified attribute for all cells in this row/col
1521 void SetRowAttr(int row, wxGridCellAttr *attr);
1522 void SetColAttr(int col, wxGridCellAttr *attr);
1523
1524 // shortcuts for setting the column parameters
1525
1526 // set the format for the data in the column: default is string
1527 void SetColFormatBool(int col);
1528 void SetColFormatNumber(int col);
1529 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1530 void SetColFormatCustom(int col, const wxString& typeName);
1531
1532 void EnableGridLines( bool enable = TRUE );
1533 bool GridLinesEnabled();
1534
1535 // ------ row and col formatting
1536 //
1537 int GetDefaultRowSize();
1538 int GetRowSize( int row );
1539 int GetDefaultColSize();
1540 int GetColSize( int col );
1541 wxColour GetDefaultCellBackgroundColour();
1542 wxColour GetCellBackgroundColour( int row, int col );
1543 wxColour GetDefaultCellTextColour();
1544 wxColour GetCellTextColour( int row, int col );
1545 wxFont GetDefaultCellFont();
1546 wxFont GetCellFont( int row, int col );
1547 void GetDefaultCellAlignment( int *horiz, int *vert );
1548 void GetCellAlignment( int row, int col, int *horiz, int *vert );
1549
1550 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
1551 void SetRowSize( int row, int height );
1552 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
1553
1554 void SetColSize( int col, int width );
1555
1556 // automatically size the column or row to fit to its contents, if
1557 // setAsMin is TRUE, this optimal width will also be set as minimal width
1558 // for this column
1559 void AutoSizeColumn( int col, bool setAsMin = TRUE );
1560 void AutoSizeRow( int row, bool setAsMin = TRUE );
1561
1562
1563 // auto size all columns (very ineffective for big grids!)
1564 void AutoSizeColumns( bool setAsMin = TRUE );
1565 void AutoSizeRows( bool setAsMin = TRUE );
1566
1567 // auto size the grid, that is make the columns/rows of the "right" size
1568 // and also set the grid size to just fit its contents
1569 void AutoSize();
1570
1571 // column won't be resized to be lesser width - this must be called during
1572 // the grid creation because it won't resize the column if it's already
1573 // narrower than the minimal width
1574 void SetColMinimalWidth( int col, int width );
1575 void SetRowMinimalHeight( int row, int width );
1576
1577 void SetDefaultCellBackgroundColour( const wxColour& );
1578 void SetCellBackgroundColour( int row, int col, const wxColour& );
1579 void SetDefaultCellTextColour( const wxColour& );
1580
1581 void SetCellTextColour( int row, int col, const wxColour& );
1582 void SetDefaultCellFont( const wxFont& );
1583 void SetCellFont( int row, int col, const wxFont& );
1584 void SetDefaultCellAlignment( int horiz, int vert );
1585 void SetCellAlignment( int row, int col, int horiz, int vert );
1586
1587 // takes ownership of the pointer
1588 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1589 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1590 wxGridCellRenderer *GetDefaultRenderer() const;
1591 wxGridCellRenderer* GetCellRenderer(int row, int col);
1592
1593 // takes ownership of the pointer
1594 void SetDefaultEditor(wxGridCellEditor *editor);
1595 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1596 wxGridCellEditor *GetDefaultEditor() const;
1597 wxGridCellEditor* GetCellEditor(int row, int col);
1598
1599
1600
1601 // ------ cell value accessors
1602 //
1603 wxString GetCellValue( int row, int col );
1604 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1605
1606 void SetCellValue( int row, int col, const wxString& s );
1607 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1608
1609 // returns TRUE if the cell can't be edited
1610 bool IsReadOnly(int row, int col) const;
1611
1612 // make the cell editable/readonly
1613 void SetReadOnly(int row, int col, bool isReadOnly = TRUE);
1614
1615 // ------ selections of blocks of cells
1616 //
1617 void SelectRow( int row, bool addToSelected = FALSE );
1618 void SelectCol( int col, bool addToSelected = FALSE );
1619
1620 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1621 bool addToSelected = FALSE );
1622 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1623 // TODO: ??? const wxGridCellCoords& bottomRight )
1624
1625 void SelectAll();
1626 bool IsSelection();
1627 void ClearSelection();
1628 bool IsInSelection( int row, int col );
1629 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1630
1631
1632 // This function returns the rectangle that encloses the block of cells
1633 // limited by TopLeft and BottomRight cell in device coords and clipped
1634 // to the client size of the grid window.
1635 //
1636 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1637 const wxGridCellCoords & bottomRight );
1638
1639
1640 // Access or update the selection fore/back colours
1641 wxColour GetSelectionBackground() const;
1642 wxColour GetSelectionForeground() const;
1643
1644 void SetSelectionBackground(const wxColour& c);
1645 void SetSelectionForeground(const wxColour& c);
1646
1647
1648 // Methods for a registry for mapping data types to Renderers/Editors
1649 void RegisterDataType(const wxString& typeName,
1650 wxGridCellRenderer* renderer,
1651 wxGridCellEditor* editor);
1652 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1653 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1654 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1655 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1656 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1657
1658 // grid may occupy more space than needed for its rows/columns, this
1659 // function allows to set how big this extra space is
1660 void SetMargins(int extraWidth, int extraHeight);
1661
1662
1663 // Accessors for component windows
1664 wxWindow* GetGridWindow();
1665 wxWindow* GetGridRowLabelWindow();
1666 wxWindow* GetGridColLabelWindow();
1667 wxWindow* GetGridCornerLabelWindow();
1668
1669
1670 };
1671
1672
1673 //---------------------------------------------------------------------------
1674 //---------------------------------------------------------------------------
1675 // Grid events and stuff
1676
1677
1678
1679 class wxGridEvent : public wxNotifyEvent
1680 {
1681 public:
1682 wxGridEvent(int id, wxEventType type, wxGrid* obj,
1683 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = TRUE,
1684 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1685
1686 virtual int GetRow();
1687 virtual int GetCol();
1688 wxPoint GetPosition();
1689 bool Selecting();
1690 bool ControlDown();
1691 bool MetaDown();
1692 bool ShiftDown();
1693 bool AltDown();
1694
1695 };
1696
1697
1698 class wxGridSizeEvent : public wxNotifyEvent
1699 {
1700 public:
1701 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
1702 int rowOrCol=-1, int x=-1, int y=-1,
1703 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1704
1705 int GetRowOrCol();
1706 wxPoint GetPosition();
1707 bool ControlDown();
1708 bool MetaDown();
1709 bool ShiftDown();
1710 bool AltDown();
1711
1712 };
1713
1714
1715 class wxGridRangeSelectEvent : public wxNotifyEvent
1716 {
1717 public:
1718 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
1719 const wxGridCellCoords& topLeft,
1720 const wxGridCellCoords& bottomRight,
1721 bool sel = TRUE,
1722 bool control=FALSE, bool shift=FALSE,
1723 bool alt=FALSE, bool meta=FALSE);
1724
1725 wxGridCellCoords GetTopLeftCoords();
1726 wxGridCellCoords GetBottomRightCoords();
1727 int GetTopRow();
1728 int GetBottomRow();
1729 int GetLeftCol();
1730 int GetRightCol();
1731 bool Selecting();
1732 bool ControlDown();
1733 bool MetaDown();
1734 bool ShiftDown();
1735 bool AltDown();
1736 };
1737
1738
1739 class wxGridEditorCreatedEvent : public wxCommandEvent {
1740 public:
1741 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
1742 int row, int col, wxControl* ctrl);
1743
1744 int GetRow();
1745 int GetCol();
1746 wxControl* GetControl();
1747 void SetRow(int row);
1748 void SetCol(int col);
1749 void SetControl(wxControl* ctrl);
1750 };
1751
1752
1753
1754 enum {
1755 wxEVT_GRID_CELL_LEFT_CLICK,
1756 wxEVT_GRID_CELL_RIGHT_CLICK,
1757 wxEVT_GRID_CELL_LEFT_DCLICK,
1758 wxEVT_GRID_CELL_RIGHT_DCLICK,
1759 wxEVT_GRID_LABEL_LEFT_CLICK,
1760 wxEVT_GRID_LABEL_RIGHT_CLICK,
1761 wxEVT_GRID_LABEL_LEFT_DCLICK,
1762 wxEVT_GRID_LABEL_RIGHT_DCLICK,
1763 wxEVT_GRID_ROW_SIZE,
1764 wxEVT_GRID_COL_SIZE,
1765 wxEVT_GRID_RANGE_SELECT,
1766 wxEVT_GRID_CELL_CHANGE,
1767 wxEVT_GRID_SELECT_CELL,
1768 wxEVT_GRID_EDITOR_SHOWN,
1769 wxEVT_GRID_EDITOR_HIDDEN,
1770 wxEVT_GRID_EDITOR_CREATED,
1771 };
1772
1773
1774
1775 %pragma(python) code = "
1776 def EVT_GRID_CELL_LEFT_CLICK(win, fn):
1777 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_CLICK, fn)
1778
1779 def EVT_GRID_CELL_RIGHT_CLICK(win, fn):
1780 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_CLICK, fn)
1781
1782 def EVT_GRID_CELL_LEFT_DCLICK(win, fn):
1783 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_DCLICK, fn)
1784
1785 def EVT_GRID_CELL_RIGHT_DCLICK(win, fn):
1786 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_DCLICK, fn)
1787
1788 def EVT_GRID_LABEL_LEFT_CLICK(win, fn):
1789 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_CLICK, fn)
1790
1791 def EVT_GRID_LABEL_RIGHT_CLICK(win, fn):
1792 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_CLICK, fn)
1793
1794 def EVT_GRID_LABEL_LEFT_DCLICK(win, fn):
1795 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_DCLICK, fn)
1796
1797 def EVT_GRID_LABEL_RIGHT_DCLICK(win, fn):
1798 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_DCLICK, fn)
1799
1800 def EVT_GRID_ROW_SIZE(win, fn):
1801 win.Connect(-1, -1, wxEVT_GRID_ROW_SIZE, fn)
1802
1803 def EVT_GRID_COL_SIZE(win, fn):
1804 win.Connect(-1, -1, wxEVT_GRID_COL_SIZE, fn)
1805
1806 def EVT_GRID_RANGE_SELECT(win, fn):
1807 win.Connect(-1, -1, wxEVT_GRID_RANGE_SELECT, fn)
1808
1809 def EVT_GRID_CELL_CHANGE(win, fn):
1810 win.Connect(-1, -1, wxEVT_GRID_CELL_CHANGE, fn)
1811
1812 def EVT_GRID_SELECT_CELL(win, fn):
1813 win.Connect(-1, -1, wxEVT_GRID_SELECT_CELL, fn)
1814
1815 def EVT_GRID_EDITOR_SHOWN(win, fn):
1816 win.Connect(-1, -1, wxEVT_GRID_EDITOR_SHOWN, fn)
1817
1818 def EVT_GRID_EDITOR_HIDDEN(win, fn):
1819 win.Connect(-1, -1, wxEVT_GRID_EDITOR_HIDDEN, fn)
1820
1821 def EVT_GRID_EDITOR_CREATED(win, fn):
1822 win.Connect(-1, -1, wxEVT_GRID_EDITOR_CREATED, fn)
1823
1824 "
1825
1826 //---------------------------------------------------------------------------
1827
1828 %init %{
1829 wxClassInfo::CleanUpClasses();
1830 wxClassInfo::InitializeClasses();
1831 %}
1832
1833 //---------------------------------------------------------------------------
1834
1835 %pragma(python) include="_gridextras.py";
1836
1837 //---------------------------------------------------------------------------
1838
1839
1840 #endif