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