]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/grid.i
Reworked how stock objects are initialized. They now have an
[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 choices = 0,
956 const wxString* choices_array = 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
1036 DocDeclA(
1037 void, GetAlignment(int *OUTPUT, int *OUTPUT) const,
1038 "GetAlignment() -> (hAlign, vAlign)");
1039
1040 DocDeclA(
1041 void, GetSize(int *OUTPUT, int *OUTPUT) const,
1042 "GetSize() -> (num_rows, num_cols)");
1043
1044 bool GetOverflow() const;
1045 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
1046 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
1047
1048 bool IsReadOnly() const;
1049 void SetDefAttr(wxGridCellAttr* defAttr);
1050 };
1051
1052 //---------------------------------------------------------------------------
1053
1054 class wxGridCellAttrProvider
1055 {
1056 public:
1057 %addtofunc wxGridCellAttrProvider "self._setOORInfo(self)"
1058 wxGridCellAttrProvider();
1059 // ???? virtual ~wxGridCellAttrProvider();
1060
1061 %extend {
1062 void _setOORInfo(PyObject* _self) {
1063 self->SetClientObject(new wxPyOORClientData(_self));
1064 }
1065 }
1066
1067 wxGridCellAttr *GetAttr(int row, int col,
1068 wxGridCellAttr::wxAttrKind kind) const;
1069 void SetAttr(wxGridCellAttr *attr, int row, int col);
1070 void SetRowAttr(wxGridCellAttr *attr, int row);
1071 void SetColAttr(wxGridCellAttr *attr, int col);
1072
1073 void UpdateAttrRows( size_t pos, int numRows );
1074 void UpdateAttrCols( size_t pos, int numCols );
1075
1076 };
1077
1078
1079 // A Python-aware version
1080 %{
1081 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1082 {
1083 public:
1084 wxPyGridCellAttrProvider() : wxGridCellAttrProvider() {};
1085
1086 PYCALLBACK_GCA_INTINTKIND(wxGridCellAttrProvider, GetAttr);
1087 PYCALLBACK__GCAINTINT(wxGridCellAttrProvider, SetAttr);
1088 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetRowAttr);
1089 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetColAttr);
1090
1091 PYPRIVATE;
1092 };
1093 %}
1094
1095
1096 // The python-aware version get's SWIGified
1097 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1098 {
1099 public:
1100 %addtofunc wxPyGridCellAttrProvider "self._setCallbackInfo(self, PyGridCellAttrProvider)"
1101 wxPyGridCellAttrProvider();
1102 void _setCallbackInfo(PyObject* self, PyObject* _class);
1103
1104 wxGridCellAttr *base_GetAttr(int row, int col,
1105 wxGridCellAttr::wxAttrKind kind);
1106 void base_SetAttr(wxGridCellAttr *attr, int row, int col);
1107 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1108 void base_SetColAttr(wxGridCellAttr *attr, int col);
1109 };
1110
1111
1112 //---------------------------------------------------------------------------
1113 // Grid Table Base class and Python aware version
1114
1115
1116 class wxGridTableBase : public wxObject
1117 {
1118 public:
1119 // wxGridTableBase(); This is an ABC
1120 //~wxGridTableBase();
1121
1122 %extend {
1123 void _setOORInfo(PyObject* _self) {
1124 self->SetClientObject(new wxPyOORClientData(_self));
1125 }
1126 }
1127
1128 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
1129 wxGridCellAttrProvider *GetAttrProvider() const;
1130 void SetView( wxGrid *grid );
1131 wxGrid * GetView() const;
1132
1133
1134 // pure virtuals
1135 virtual int GetNumberRows();
1136 virtual int GetNumberCols();
1137 virtual bool IsEmptyCell( int row, int col );
1138 virtual wxString GetValue( int row, int col );
1139 virtual void SetValue( int row, int col, const wxString& value );
1140
1141 // virtuals overridable in wxPyGridTableBase
1142 virtual wxString GetTypeName( int row, int col );
1143 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
1144 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
1145 virtual long GetValueAsLong( int row, int col );
1146 virtual double GetValueAsDouble( int row, int col );
1147 virtual bool GetValueAsBool( int row, int col );
1148 virtual void SetValueAsLong( int row, int col, long value );
1149 virtual void SetValueAsDouble( int row, int col, double value );
1150 virtual void SetValueAsBool( int row, int col, bool value );
1151
1152 //virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
1153 //virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
1154
1155
1156 virtual void Clear();
1157 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
1158 virtual bool AppendRows( size_t numRows = 1 );
1159 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
1160 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
1161 virtual bool AppendCols( size_t numCols = 1 );
1162 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
1163
1164 virtual wxString GetRowLabelValue( int row );
1165 virtual wxString GetColLabelValue( int col );
1166 virtual void SetRowLabelValue( int row, const wxString& value );
1167 virtual void SetColLabelValue( int col, const wxString& value );
1168
1169 virtual bool CanHaveAttributes();
1170
1171 virtual wxGridCellAttr *GetAttr( int row, int col,
1172 wxGridCellAttr::wxAttrKind kind);
1173 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
1174 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
1175 virtual void SetColAttr(wxGridCellAttr *attr, int col);
1176
1177 };
1178
1179
1180
1181 // Python-aware version
1182 %{
1183 class wxPyGridTableBase : public wxGridTableBase
1184 {
1185 public:
1186 wxPyGridTableBase() : wxGridTableBase() {}
1187
1188 PYCALLBACK_INT__pure(GetNumberRows);
1189 PYCALLBACK_INT__pure(GetNumberCols);
1190 PYCALLBACK_BOOL_INTINT_pure(IsEmptyCell);
1191 PYCALLBACK_STRING_INTINT(wxGridTableBase, GetTypeName);
1192 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanGetValueAs);
1193 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanSetValueAs);
1194 PYCALLBACK__(wxGridTableBase, Clear);
1195 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertRows);
1196 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteRows);
1197 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertCols);
1198 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteCols);
1199 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendRows);
1200 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendCols);
1201 PYCALLBACK_STRING_INT(wxGridTableBase, GetRowLabelValue);
1202 PYCALLBACK_STRING_INT(wxGridTableBase, GetColLabelValue);
1203 PYCALLBACK__INTSTRING(wxGridTableBase, SetRowLabelValue);
1204 PYCALLBACK__INTSTRING(wxGridTableBase, SetColLabelValue);
1205 PYCALLBACK_BOOL_(wxGridTableBase, CanHaveAttributes);
1206 PYCALLBACK_GCA_INTINTKIND(wxGridTableBase, GetAttr);
1207 PYCALLBACK__GCAINTINT(wxGridTableBase, SetAttr);
1208 PYCALLBACK__GCAINT(wxGridTableBase, SetRowAttr);
1209 PYCALLBACK__GCAINT(wxGridTableBase, SetColAttr);
1210
1211
1212 wxString GetValue(int row, int col) {
1213 wxPyBeginBlockThreads();
1214 wxString rval;
1215 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1216 PyObject* ro;
1217 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",row,col));
1218 if (ro) {
1219 rval = Py2wxString(ro);
1220 Py_DECREF(ro);
1221 }
1222 }
1223 wxPyEndBlockThreads();
1224 return rval;
1225 }
1226
1227 void SetValue(int row, int col, const wxString& val) {
1228 wxPyBeginBlockThreads();
1229 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1230 PyObject* s = wx2PyString(val);
1231 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",row,col,s));
1232 Py_DECREF(s);
1233 }
1234 wxPyEndBlockThreads();
1235 }
1236
1237
1238 // Map the Get/Set methods for the standard non-string types to
1239 // the GetValue and SetValue python methods.
1240 long GetValueAsLong( int row, int col ) {
1241 long rval = 0;
1242 wxPyBeginBlockThreads();
1243 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1244 PyObject* ro;
1245 PyObject* num;
1246 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1247 if (ro && PyNumber_Check(ro)) {
1248 num = PyNumber_Int(ro);
1249 if (num) {
1250 rval = PyInt_AsLong(num);
1251 Py_DECREF(num);
1252 }
1253 Py_DECREF(ro);
1254 }
1255 }
1256 wxPyEndBlockThreads();
1257 return rval;
1258 }
1259
1260 double GetValueAsDouble( int row, int col ) {
1261 double rval = 0.0;
1262 wxPyBeginBlockThreads();
1263 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1264 PyObject* ro;
1265 PyObject* num;
1266 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1267 if (ro && PyNumber_Check(ro)) {
1268 num = PyNumber_Float(ro);
1269 if (num) {
1270 rval = PyFloat_AsDouble(num);
1271 Py_DECREF(num);
1272 }
1273 Py_DECREF(ro);
1274 }
1275 }
1276 wxPyEndBlockThreads();
1277 return rval;
1278 }
1279
1280 bool GetValueAsBool( int row, int col ) {
1281 return (bool)GetValueAsLong(row, col);
1282 }
1283
1284 void SetValueAsLong( int row, int col, long value ) {
1285 wxPyBeginBlockThreads();
1286 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1287 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", row, col, value));
1288 }
1289 wxPyEndBlockThreads();
1290 }
1291
1292 void SetValueAsDouble( int row, int col, double value ) {
1293 wxPyBeginBlockThreads();
1294 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1295 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iid)", row, col, value));
1296 }
1297 wxPyEndBlockThreads();
1298 }
1299
1300 void SetValueAsBool( int row, int col, bool value ) {
1301 SetValueAsLong( row, col, (long)value );
1302 }
1303
1304
1305 PYPRIVATE;
1306 };
1307 %}
1308
1309
1310 // The python-aware version get's SWIGified
1311 class wxPyGridTableBase : public wxGridTableBase
1312 {
1313 public:
1314 %addtofunc wxPyGridTableBase "self._setCallbackInfo(self, PyGridTableBase);self._setOORInfo(self)"
1315 wxPyGridTableBase();
1316 void _setCallbackInfo(PyObject* self, PyObject* _class);
1317
1318 %extend { void Destroy() { delete self; } }
1319
1320 wxString base_GetTypeName( int row, int col );
1321 bool base_CanGetValueAs( int row, int col, const wxString& typeName );
1322 bool base_CanSetValueAs( int row, int col, const wxString& typeName );
1323 void base_Clear();
1324 bool base_InsertRows( size_t pos = 0, size_t numRows = 1 );
1325 bool base_AppendRows( size_t numRows = 1 );
1326 bool base_DeleteRows( size_t pos = 0, size_t numRows = 1 );
1327 bool base_InsertCols( size_t pos = 0, size_t numCols = 1 );
1328 bool base_AppendCols( size_t numCols = 1 );
1329 bool base_DeleteCols( size_t pos = 0, size_t numCols = 1 );
1330 wxString base_GetRowLabelValue( int row );
1331 wxString base_GetColLabelValue( int col );
1332 void base_SetRowLabelValue( int row, const wxString& value );
1333 void base_SetColLabelValue( int col, const wxString& value );
1334 bool base_CanHaveAttributes();
1335 wxGridCellAttr *base_GetAttr( int row, int col,
1336 wxGridCellAttr::wxAttrKind kind );
1337 void base_SetAttr(wxGridCellAttr* attr, int row, int col);
1338 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1339 void base_SetColAttr(wxGridCellAttr *attr, int col);
1340 };
1341
1342
1343 //---------------------------------------------------------------------------
1344 // Predefined Tables
1345
1346 class wxGridStringTable : public wxGridTableBase
1347 {
1348 public:
1349 %addtofunc wxGridStringTable "self._setOORInfo(self)"
1350 wxGridStringTable( int numRows=0, int numCols=0 );
1351 };
1352
1353 //---------------------------------------------------------------------------
1354 // The Table can pass messages to the grid to tell it to update itself if
1355 // something has changed.
1356
1357 enum wxGridTableRequest
1358 {
1359 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
1360 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
1361 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
1362 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
1363 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
1364 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1365 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
1366 wxGRIDTABLE_NOTIFY_COLS_DELETED
1367 };
1368
1369
1370 class wxGridTableMessage
1371 {
1372 public:
1373 wxGridTableMessage( wxGridTableBase *table, int id,
1374 int comInt1 = -1,
1375 int comInt2 = -1 );
1376 ~wxGridTableMessage();
1377
1378 void SetTableObject( wxGridTableBase *table );
1379 wxGridTableBase * GetTableObject() const;
1380 void SetId( int id );
1381 int GetId();
1382 void SetCommandInt( int comInt1 );
1383 int GetCommandInt();
1384 void SetCommandInt2( int comInt2 );
1385 int GetCommandInt2();
1386 };
1387
1388
1389 //---------------------------------------------------------------------------
1390
1391
1392 class wxGridCellCoords
1393 {
1394 public:
1395 wxGridCellCoords( int r=-1, int c=-1 );
1396 ~wxGridCellCoords();
1397
1398 int GetRow() const;
1399 void SetRow( int n );
1400 int GetCol() const;
1401 void SetCol( int n );
1402 void Set( int row, int col );
1403
1404 bool operator==( const wxGridCellCoords& other ) const;
1405 bool operator!=( const wxGridCellCoords& other ) const;
1406
1407 %extend {
1408 PyObject* asTuple() {
1409 PyObject* tup = PyTuple_New(2);
1410 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
1411 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
1412 return tup;
1413 }
1414 }
1415 %pythoncode {
1416 def __str__(self): return str(self.asTuple())
1417 def __repr__(self): return 'wxGridCellCoords'+str(self.asTuple())
1418 def __len__(self): return len(self.asTuple())
1419 def __getitem__(self, index): return self.asTuple()[index]
1420 def __setitem__(self, index, val):
1421 if index == 0: self.SetRow(val)
1422 elif index == 1: self.SetCol(val)
1423 else: raise IndexError
1424 }
1425
1426 };
1427
1428 // Typemap to allow conversion of sequence objects to wxGridCellCoords...
1429 %typemap(in) wxGridCellCoords& (wxGridCellCoords temp) {
1430 $1 = &temp;
1431 if (! wxGridCellCoords_helper($input, &$1)) SWIG_fail;
1432 }
1433 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxGridCellCoords& {
1434 $1 = wxGridCellCoords_typecheck($input);
1435 }
1436
1437
1438 // ...and here is the associated helper.
1439 %{
1440 bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) {
1441
1442 // If source is an object instance then it may already be the right type
1443 if (wxPySwigInstance_Check(source)) {
1444 wxGridCellCoords* ptr;
1445 if (! wxPyConvertSwigPtr(source, (void **)&ptr, wxT("wxGridCellCoords")))
1446 goto error;
1447 *obj = ptr;
1448 return True;
1449 }
1450 // otherwise a 2-tuple of integers is expected
1451 else if (PySequence_Check(source) && PyObject_Length(source) == 2) {
1452 PyObject* o1 = PySequence_GetItem(source, 0);
1453 PyObject* o2 = PySequence_GetItem(source, 1);
1454 if (!PyNumber_Check(o1) || !PyNumber_Check(o2)) {
1455 Py_DECREF(o1);
1456 Py_DECREF(o2);
1457 goto error;
1458 }
1459 **obj = wxGridCellCoords(PyInt_AsLong(o1), PyInt_AsLong(o2));
1460 Py_DECREF(o1);
1461 Py_DECREF(o2);
1462 return True;
1463 }
1464
1465 error:
1466 PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of integers or a wxGridCellCoords object.");
1467 return False;
1468 }
1469
1470
1471 bool wxGridCellCoords_typecheck(PyObject* source) {
1472 void* ptr;
1473
1474 if (wxPySwigInstance_Check(source) &&
1475 wxPyConvertSwigPtr(source, (void **)&ptr, wxT("wxGridCellCoords")))
1476 return True;
1477
1478 PyErr_Clear();
1479 if (PySequence_Check(source) && PySequence_Length(source) == 2)
1480 return True;
1481
1482 return False;
1483 }
1484 %}
1485
1486
1487 // Typemap to convert an array of cells coords to a list of tuples...
1488 %typemap(out) wxGridCellCoordsArray {
1489 $result = wxGridCellCoordsArray_helper($1);
1490 }
1491
1492 // %typemap(ret) wxGridCellCoordsArray {
1493 // delete $1;
1494 // }
1495
1496
1497 // ...and the helper function for the above typemap.
1498 %{
1499 PyObject* wxGridCellCoordsArray_helper(const wxGridCellCoordsArray& source)
1500 {
1501 PyObject* list = PyList_New(0);
1502 size_t idx;
1503 for (idx = 0; idx < source.GetCount(); idx += 1) {
1504 wxGridCellCoords& coord = source.Item(idx);
1505 PyObject* tup = PyTuple_New(2);
1506 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(coord.GetRow()));
1507 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(coord.GetCol()));
1508 PyList_Append(list, tup);
1509 Py_DECREF(tup);
1510 }
1511 return list;
1512 }
1513 %}
1514
1515 //---------------------------------------------------------------------------
1516 //---------------------------------------------------------------------------
1517 // The grid itself
1518
1519
1520 // Fool SWIG into treating this enum as an int
1521 typedef int WXGRIDSELECTIONMODES;
1522
1523 // but let the C++ code know what it really is.
1524 %{
1525 typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES;
1526 %}
1527
1528
1529
1530 class wxGrid : public wxScrolledWindow
1531 {
1532 public:
1533 %addtofunc wxGrid "self._setOORInfo(self)"
1534
1535 wxGrid( wxWindow *parent,
1536 wxWindowID id,
1537 const wxPoint& pos = wxDefaultPosition,
1538 const wxSize& size = wxDefaultSize,
1539 long style = wxWANTS_CHARS,
1540 const wxString& name = wxPyPanelNameStr);
1541
1542
1543 enum wxGridSelectionModes {wxGridSelectCells,
1544 wxGridSelectRows,
1545 wxGridSelectColumns};
1546
1547 bool CreateGrid( int numRows, int numCols,
1548 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1549 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1550 WXGRIDSELECTIONMODES GetSelectionMode();
1551
1552
1553 // ------ grid dimensions
1554 //
1555 int GetNumberRows();
1556 int GetNumberCols();
1557
1558
1559 bool ProcessTableMessage( wxGridTableMessage& );
1560
1561
1562 wxGridTableBase * GetTable() const;
1563 bool SetTable( wxGridTableBase *table, bool takeOwnership=False,
1564 WXGRIDSELECTIONMODES selmode =
1565 wxGrid::wxGridSelectCells );
1566
1567 void ClearGrid();
1568 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=True );
1569 bool AppendRows( int numRows = 1, bool updateLabels=True );
1570 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=True );
1571 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=True );
1572 bool AppendCols( int numCols = 1, bool updateLabels=True );
1573 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=True );
1574
1575
1576 // this function is called when the current cell highlight must be redrawn
1577 // and may be overridden by the user
1578 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1579
1580
1581 // ------ Cell text drawing functions
1582 //
1583 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1584 int horizontalAlignment = wxLEFT,
1585 int verticalAlignment = wxTOP,
1586 int textOrientation = wxHORIZONTAL );
1587
1588 // // Split a string containing newline chararcters into an array of
1589 // // strings and return the number of lines
1590 // //
1591 // void StringToLines( const wxString& value, wxArrayString& lines );
1592
1593 DocDeclA(
1594 void, GetTextBoxSize( wxDC& dc, wxArrayString& lines,
1595 long *OUTPUT, long *OUTPUT ),
1596 "GetTextBoxSize(DC dc, list lines) -> (width, height)");
1597
1598
1599 // ------
1600 // Code that does a lot of grid modification can be enclosed
1601 // between BeginBatch() and EndBatch() calls to avoid screen
1602 // flicker
1603 //
1604 void BeginBatch();
1605 void EndBatch();
1606 int GetBatchCount();
1607 void ForceRefresh();
1608 void Refresh(bool eraseb=True, const wxRect* rect= NULL);
1609
1610
1611 // ------ edit control functions
1612 //
1613 bool IsEditable();
1614 void EnableEditing( bool edit );
1615
1616 void EnableCellEditControl( bool enable = True );
1617 void DisableCellEditControl();
1618 bool CanEnableCellControl() const;
1619 bool IsCellEditControlEnabled() const;
1620 bool IsCellEditControlShown() const;
1621
1622 bool IsCurrentCellReadOnly() const;
1623
1624 void ShowCellEditControl();
1625 void HideCellEditControl();
1626 void SaveEditControlValue();
1627
1628
1629 // ------ grid location functions
1630 // Note that all of these functions work with the logical coordinates of
1631 // grid cells and labels so you will need to convert from device
1632 // coordinates for mouse events etc.
1633 //
1634
1635 //void XYToCell( int x, int y, wxGridCellCoords& );
1636 %extend {
1637 wxGridCellCoords XYToCell(int x, int y) {
1638 wxGridCellCoords rv;
1639 self->XYToCell(x, y, rv);
1640 return rv;
1641 }
1642 }
1643
1644 int YToRow( int y );
1645 int XToCol( int x );
1646
1647 int YToEdgeOfRow( int y );
1648 int XToEdgeOfCol( int x );
1649
1650 wxRect CellToRect( int row, int col );
1651 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1652
1653
1654 int GetGridCursorRow();
1655 int GetGridCursorCol();
1656
1657 // check to see if a cell is either wholly visible (the default arg) or
1658 // at least partially visible in the grid window
1659 //
1660 bool IsVisible( int row, int col, bool wholeCellVisible = True );
1661 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = True );
1662 void MakeCellVisible( int row, int col );
1663 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1664
1665
1666 // ------ grid cursor movement functions
1667 //
1668 void SetGridCursor( int row, int col );
1669 bool MoveCursorUp( bool expandSelection );
1670 bool MoveCursorDown( bool expandSelection );
1671 bool MoveCursorLeft( bool expandSelection );
1672 bool MoveCursorRight( bool expandSelection );
1673 bool MovePageDown();
1674 bool MovePageUp();
1675 bool MoveCursorUpBlock( bool expandSelection );
1676 bool MoveCursorDownBlock( bool expandSelection );
1677 bool MoveCursorLeftBlock( bool expandSelection );
1678 bool MoveCursorRightBlock( bool expandSelection );
1679
1680
1681 // ------ label and gridline formatting
1682 //
1683 int GetDefaultRowLabelSize();
1684 int GetRowLabelSize();
1685 int GetDefaultColLabelSize();
1686 int GetColLabelSize();
1687 wxColour GetLabelBackgroundColour();
1688 wxColour GetLabelTextColour();
1689 wxFont GetLabelFont();
1690
1691 DocDeclA(
1692 void, GetRowLabelAlignment( int *OUTPUT, int *OUTPUT ),
1693 "GetRowLabelAlignment() -> (horiz, vert)");
1694
1695 DocDeclA(
1696 void, GetColLabelAlignment( int *OUTPUT, int *OUTPUT ),
1697 "GetColLabelAlignment() -> (horiz, vert)");
1698
1699 int GetColLabelTextOrientation();
1700 wxString GetRowLabelValue( int row );
1701 wxString GetColLabelValue( int col );
1702 wxColour GetGridLineColour();
1703 wxColour GetCellHighlightColour();
1704 int GetCellHighlightPenWidth();
1705 int GetCellHighlightROPenWidth();
1706
1707 void SetRowLabelSize( int width );
1708 void SetColLabelSize( int height );
1709 void SetLabelBackgroundColour( const wxColour& );
1710 void SetLabelTextColour( const wxColour& );
1711 void SetLabelFont( const wxFont& );
1712 void SetRowLabelAlignment( int horiz, int vert );
1713 void SetColLabelAlignment( int horiz, int vert );
1714 void SetColLabelTextOrientation( int textOrientation );
1715 void SetRowLabelValue( int row, const wxString& );
1716 void SetColLabelValue( int col, const wxString& );
1717 void SetGridLineColour( const wxColour& );
1718 void SetCellHighlightColour( const wxColour& );
1719 void SetCellHighlightPenWidth(int width);
1720 void SetCellHighlightROPenWidth(int width);
1721
1722 void EnableDragRowSize( bool enable = True );
1723 void DisableDragRowSize();
1724 bool CanDragRowSize();
1725 void EnableDragColSize( bool enable = True );
1726 void DisableDragColSize();
1727 bool CanDragColSize();
1728 void EnableDragGridSize(bool enable = True);
1729 void DisableDragGridSize();
1730 bool CanDragGridSize();
1731
1732 // this sets the specified attribute for all cells in this row/col
1733 void SetAttr(int row, int col, wxGridCellAttr *attr);
1734 void SetRowAttr(int row, wxGridCellAttr *attr);
1735 void SetColAttr(int col, wxGridCellAttr *attr);
1736
1737 // shortcuts for setting the column parameters
1738
1739 // set the format for the data in the column: default is string
1740 void SetColFormatBool(int col);
1741 void SetColFormatNumber(int col);
1742 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1743 void SetColFormatCustom(int col, const wxString& typeName);
1744
1745 void EnableGridLines( bool enable = True );
1746 bool GridLinesEnabled();
1747
1748 // ------ row and col formatting
1749 //
1750 int GetDefaultRowSize();
1751 int GetRowSize( int row );
1752 int GetDefaultColSize();
1753 int GetColSize( int col );
1754 wxColour GetDefaultCellBackgroundColour();
1755 wxColour GetCellBackgroundColour( int row, int col );
1756 wxColour GetDefaultCellTextColour();
1757 wxColour GetCellTextColour( int row, int col );
1758 wxFont GetDefaultCellFont();
1759 wxFont GetCellFont( int row, int col );
1760
1761 DocDeclA(
1762 void, GetDefaultCellAlignment( int *OUTPUT, int *OUTPUT ),
1763 "GetDefaultCellAlignment() -> (horiz, vert)");
1764
1765 DocDeclA(
1766 void, GetCellAlignment( int row, int col, int *OUTPUT, int *OUTPUT ),
1767 "GetCellAlignment() -> (horiz, vert)");
1768
1769 bool GetDefaultCellOverflow();
1770 bool GetCellOverflow( int row, int col );
1771
1772 DocDeclA(
1773 void, GetCellSize( int row, int col, int *OUTPUT, int *OUTPUT ),
1774 "GetCellSize(int row, int col) -> (num_rows, num_cols)");
1775
1776 void SetDefaultRowSize( int height, bool resizeExistingRows = False );
1777 void SetRowSize( int row, int height );
1778 void SetDefaultColSize( int width, bool resizeExistingCols = False );
1779
1780 void SetColSize( int col, int width );
1781
1782 // automatically size the column or row to fit to its contents, if
1783 // setAsMin is True, this optimal width will also be set as minimal width
1784 // for this column
1785 void AutoSizeColumn( int col, bool setAsMin = True );
1786 void AutoSizeRow( int row, bool setAsMin = True );
1787
1788
1789 // auto size all columns (very ineffective for big grids!)
1790 void AutoSizeColumns( bool setAsMin = True );
1791 void AutoSizeRows( bool setAsMin = True );
1792
1793 // auto size the grid, that is make the columns/rows of the "right" size
1794 // and also set the grid size to just fit its contents
1795 void AutoSize();
1796
1797 // autosize row height depending on label text
1798 void AutoSizeRowLabelSize( int row );
1799
1800 // autosize column width depending on label text
1801 void AutoSizeColLabelSize( int col );
1802
1803
1804 // column won't be resized to be lesser width - this must be called during
1805 // the grid creation because it won't resize the column if it's already
1806 // narrower than the minimal width
1807 void SetColMinimalWidth( int col, int width );
1808 void SetRowMinimalHeight( int row, int width );
1809
1810 void SetColMinimalAcceptableWidth( int width );
1811 void SetRowMinimalAcceptableHeight( int width );
1812 int GetColMinimalAcceptableWidth() const;
1813 int GetRowMinimalAcceptableHeight() const;
1814
1815 void SetDefaultCellBackgroundColour( const wxColour& );
1816 void SetCellBackgroundColour( int row, int col, const wxColour& );
1817 void SetDefaultCellTextColour( const wxColour& );
1818
1819 void SetCellTextColour( int row, int col, const wxColour& );
1820 void SetDefaultCellFont( const wxFont& );
1821 void SetCellFont( int row, int col, const wxFont& );
1822 void SetDefaultCellAlignment( int horiz, int vert );
1823 void SetCellAlignment( int row, int col, int horiz, int vert );
1824 void SetDefaultCellOverflow( bool allow );
1825 void SetCellOverflow( int row, int col, bool allow );
1826 void SetCellSize( int row, int col, int num_rows, int num_cols );
1827
1828 // takes ownership of the pointer
1829 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1830 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1831 wxGridCellRenderer *GetDefaultRenderer() const;
1832 wxGridCellRenderer* GetCellRenderer(int row, int col);
1833
1834 // takes ownership of the pointer
1835 void SetDefaultEditor(wxGridCellEditor *editor);
1836 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1837 wxGridCellEditor *GetDefaultEditor() const;
1838 wxGridCellEditor* GetCellEditor(int row, int col);
1839
1840
1841
1842 // ------ cell value accessors
1843 //
1844 wxString GetCellValue( int row, int col );
1845 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1846
1847 void SetCellValue( int row, int col, const wxString& s );
1848 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1849
1850 // returns True if the cell can't be edited
1851 bool IsReadOnly(int row, int col) const;
1852
1853 // make the cell editable/readonly
1854 void SetReadOnly(int row, int col, bool isReadOnly = True);
1855
1856 // ------ selections of blocks of cells
1857 //
1858 void SelectRow( int row, bool addToSelected = False );
1859 void SelectCol( int col, bool addToSelected = False );
1860
1861 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1862 bool addToSelected = False );
1863 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1864 // TODO: ??? const wxGridCellCoords& bottomRight )
1865
1866 void SelectAll();
1867 bool IsSelection();
1868 void ClearSelection();
1869 bool IsInSelection( int row, int col );
1870 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1871
1872 const wxGridCellCoordsArray GetSelectedCells() const;
1873 const wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
1874 const wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
1875 const wxArrayInt GetSelectedRows() const;
1876 const wxArrayInt GetSelectedCols() const;
1877
1878 void DeselectRow( int row );
1879 void DeselectCol( int col );
1880 void DeselectCell( int row, int col );
1881
1882
1883 // This function returns the rectangle that encloses the block of cells
1884 // limited by TopLeft and BottomRight cell in device coords and clipped
1885 // to the client size of the grid window.
1886 //
1887 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1888 const wxGridCellCoords & bottomRight );
1889
1890
1891 // Access or update the selection fore/back colours
1892 wxColour GetSelectionBackground() const;
1893 wxColour GetSelectionForeground() const;
1894
1895 void SetSelectionBackground(const wxColour& c);
1896 void SetSelectionForeground(const wxColour& c);
1897
1898
1899 // Methods for a registry for mapping data types to Renderers/Editors
1900 void RegisterDataType(const wxString& typeName,
1901 wxGridCellRenderer* renderer,
1902 wxGridCellEditor* editor);
1903 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1904 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1905 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1906 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1907 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1908
1909 // grid may occupy more space than needed for its rows/columns, this
1910 // function allows to set how big this extra space is
1911 void SetMargins(int extraWidth, int extraHeight);
1912
1913
1914 // Accessors for component windows
1915 wxWindow* GetGridWindow();
1916 wxWindow* GetGridRowLabelWindow();
1917 wxWindow* GetGridColLabelWindow();
1918 wxWindow* GetGridCornerLabelWindow();
1919
1920
1921 };
1922
1923
1924 //---------------------------------------------------------------------------
1925 //---------------------------------------------------------------------------
1926 // Grid events and stuff
1927
1928
1929
1930 class wxGridEvent : public wxNotifyEvent
1931 {
1932 public:
1933 wxGridEvent(int id, wxEventType type, wxGrid* obj,
1934 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = True,
1935 bool control=False, bool shift=False, bool alt=False, bool meta=False);
1936
1937 virtual int GetRow();
1938 virtual int GetCol();
1939 wxPoint GetPosition();
1940 bool Selecting();
1941 bool ControlDown();
1942 bool MetaDown();
1943 bool ShiftDown();
1944 bool AltDown();
1945
1946 };
1947
1948
1949 class wxGridSizeEvent : public wxNotifyEvent
1950 {
1951 public:
1952 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
1953 int rowOrCol=-1, int x=-1, int y=-1,
1954 bool control=False, bool shift=False, bool alt=False, bool meta=False);
1955
1956 int GetRowOrCol();
1957 wxPoint GetPosition();
1958 bool ControlDown();
1959 bool MetaDown();
1960 bool ShiftDown();
1961 bool AltDown();
1962
1963 };
1964
1965
1966 class wxGridRangeSelectEvent : public wxNotifyEvent
1967 {
1968 public:
1969 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
1970 const wxGridCellCoords& topLeft,
1971 const wxGridCellCoords& bottomRight,
1972 bool sel = True,
1973 bool control=False, bool shift=False,
1974 bool alt=False, bool meta=False);
1975
1976 wxGridCellCoords GetTopLeftCoords();
1977 wxGridCellCoords GetBottomRightCoords();
1978 int GetTopRow();
1979 int GetBottomRow();
1980 int GetLeftCol();
1981 int GetRightCol();
1982 bool Selecting();
1983 bool ControlDown();
1984 bool MetaDown();
1985 bool ShiftDown();
1986 bool AltDown();
1987 };
1988
1989
1990 class wxGridEditorCreatedEvent : public wxCommandEvent {
1991 public:
1992 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
1993 int row, int col, wxControl* ctrl);
1994
1995 int GetRow();
1996 int GetCol();
1997 wxControl* GetControl();
1998 void SetRow(int row);
1999 void SetCol(int col);
2000 void SetControl(wxControl* ctrl);
2001 };
2002
2003
2004
2005 %constant wxEventType wxEVT_GRID_CELL_LEFT_CLICK;
2006 %constant wxEventType wxEVT_GRID_CELL_RIGHT_CLICK;
2007 %constant wxEventType wxEVT_GRID_CELL_LEFT_DCLICK;
2008 %constant wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK;
2009 %constant wxEventType wxEVT_GRID_LABEL_LEFT_CLICK;
2010 %constant wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK;
2011 %constant wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK;
2012 %constant wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK;
2013 %constant wxEventType wxEVT_GRID_ROW_SIZE;
2014 %constant wxEventType wxEVT_GRID_COL_SIZE;
2015 %constant wxEventType wxEVT_GRID_RANGE_SELECT;
2016 %constant wxEventType wxEVT_GRID_CELL_CHANGE;
2017 %constant wxEventType wxEVT_GRID_SELECT_CELL;
2018 %constant wxEventType wxEVT_GRID_EDITOR_SHOWN;
2019 %constant wxEventType wxEVT_GRID_EDITOR_HIDDEN;
2020 %constant wxEventType wxEVT_GRID_EDITOR_CREATED;
2021
2022
2023
2024 %pythoncode {
2025 EVT_GRID_CELL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_CLICK )
2026 EVT_GRID_CELL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_CLICK )
2027 EVT_GRID_CELL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_DCLICK )
2028 EVT_GRID_CELL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_DCLICK )
2029 EVT_GRID_LABEL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_CLICK )
2030 EVT_GRID_LABEL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_CLICK )
2031 EVT_GRID_LABEL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_DCLICK )
2032 EVT_GRID_LABEL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_DCLICK )
2033 EVT_GRID_ROW_SIZE = wx.PyEventBinder( wxEVT_GRID_ROW_SIZE )
2034 EVT_GRID_COL_SIZE = wx.PyEventBinder( wxEVT_GRID_COL_SIZE )
2035 EVT_GRID_RANGE_SELECT = wx.PyEventBinder( wxEVT_GRID_RANGE_SELECT )
2036 EVT_GRID_CELL_CHANGE = wx.PyEventBinder( wxEVT_GRID_CELL_CHANGE )
2037 EVT_GRID_SELECT_CELL = wx.PyEventBinder( wxEVT_GRID_SELECT_CELL )
2038 EVT_GRID_EDITOR_SHOWN = wx.PyEventBinder( wxEVT_GRID_EDITOR_SHOWN )
2039 EVT_GRID_EDITOR_HIDDEN = wx.PyEventBinder( wxEVT_GRID_EDITOR_HIDDEN )
2040 EVT_GRID_EDITOR_CREATED = wx.PyEventBinder( wxEVT_GRID_EDITOR_CREATED )
2041 }
2042
2043 //---------------------------------------------------------------------------
2044
2045 %init %{
2046 %}
2047
2048 //---------------------------------------------------------------------------
2049 //---------------------------------------------------------------------------
2050