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