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