]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/grid.i
fixed TABs handling
[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, $owner); }
49 %typemap(out) wxGridCellEditor* { $result = wxPyMake_wxGridCellEditor($1, $owner); }
50 %typemap(out) wxGridCellAttr* { $result = wxPyMake_wxGridCellAttr($1, $owner); }
51 %typemap(out) wxGridCellAttrProvider* { $result = wxPyMake_wxGridCellAttrProvider($1, $owner); }
52 %typemap(out) wxGridTableBase* { $result = wxPyMake_wxGridTableBase($1, $owner); }
53
54
55 %{
56
57 #define wxPyMake_TEMPLATE(TYPE) \
58 PyObject* wxPyMake_##TYPE(TYPE* source, bool setThisOwn) { \
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), 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 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,false); \
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,false); \
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 %rename(GRID_DEFAULT_NUMBER_ROWS) WXGRID_DEFAULT_NUMBER_ROWS;
525 %rename(GRID_DEFAULT_NUMBER_COLS) WXGRID_DEFAULT_NUMBER_COLS;
526 %rename(GRID_DEFAULT_ROW_HEIGHT) WXGRID_DEFAULT_ROW_HEIGHT;
527 %rename(GRID_DEFAULT_COL_WIDTH) WXGRID_DEFAULT_COL_WIDTH;
528 %rename(GRID_DEFAULT_COL_LABEL_HEIGHT) WXGRID_DEFAULT_COL_LABEL_HEIGHT;
529 %rename(GRID_DEFAULT_ROW_LABEL_WIDTH) WXGRID_DEFAULT_ROW_LABEL_WIDTH;
530 %rename(GRID_LABEL_EDGE_ZONE) WXGRID_LABEL_EDGE_ZONE;
531 %rename(GRID_MIN_ROW_HEIGHT) WXGRID_MIN_ROW_HEIGHT;
532 %rename(GRID_MIN_COL_WIDTH) WXGRID_MIN_COL_WIDTH;
533 %rename(GRID_DEFAULT_SCROLLBAR_WIDTH) WXGRID_DEFAULT_SCROLLBAR_WIDTH;
534
535 enum {
536 WXGRID_DEFAULT_NUMBER_ROWS,
537 WXGRID_DEFAULT_NUMBER_COLS,
538 WXGRID_DEFAULT_ROW_HEIGHT,
539 WXGRID_DEFAULT_COL_WIDTH,
540 WXGRID_DEFAULT_COL_LABEL_HEIGHT,
541 WXGRID_DEFAULT_ROW_LABEL_WIDTH,
542 WXGRID_LABEL_EDGE_ZONE,
543 WXGRID_MIN_ROW_HEIGHT,
544 WXGRID_MIN_COL_WIDTH,
545 WXGRID_DEFAULT_SCROLLBAR_WIDTH
546 };
547
548
549 //---------------------------------------------------------------------------
550 // wxGridCellRenderer is an ABC, and several derived classes are available.
551 // Classes implemented in Python should be derived from wxPyGridCellRenderer.
552
553
554 class wxGridCellRenderer
555 {
556 public:
557 %extend {
558 void _setOORInfo(PyObject* _self) {
559 self->SetClientObject(new wxPyOORClientData(_self));
560 }
561 }
562
563 void SetParameters(const wxString& params);
564 void IncRef();
565 void DecRef();
566
567 virtual void Draw(wxGrid& grid,
568 wxGridCellAttr& attr,
569 wxDC& dc,
570 const wxRect& rect,
571 int row, int col,
572 bool isSelected);
573 virtual wxSize GetBestSize(wxGrid& grid,
574 wxGridCellAttr& attr,
575 wxDC& dc,
576 int row, int col);
577 virtual wxGridCellRenderer *Clone() const;
578 };
579
580
581 // The C++ version of wxPyGridCellRenderer
582 %{
583 class wxPyGridCellRenderer : public wxGridCellRenderer
584 {
585 public:
586 wxPyGridCellRenderer() : wxGridCellRenderer() {};
587
588 // Implement Python callback aware virtual methods
589 void Draw(wxGrid& grid, wxGridCellAttr& attr,
590 wxDC& dc, const wxRect& rect,
591 int row, int col, bool isSelected) {
592 bool blocked = wxPyBeginBlockThreads();
593 if (wxPyCBH_findCallback(m_myInst, "Draw")) {
594 PyObject* go = wxPyMake_wxObject(&grid,false);
595 PyObject* dco = wxPyMake_wxObject(&dc,false);
596 PyObject* ao = wxPyMake_wxGridCellAttr(&attr,false);
597 PyObject* ro = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
598
599 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOOOiii)", go, ao, dco, ro,
600 row, col, isSelected));
601 Py_DECREF(go);
602 Py_DECREF(ao);
603 Py_DECREF(dco);
604 Py_DECREF(ro);
605 }
606 wxPyEndBlockThreads(blocked);
607 }
608
609 wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
610 int row, int col) {
611 wxSize rval;
612 bool blocked = wxPyBeginBlockThreads();
613 if (wxPyCBH_findCallback(m_myInst, "GetBestSize")) {
614 PyObject* ro;
615 wxSize* ptr;
616 PyObject* go = wxPyMake_wxObject(&grid,false);
617 PyObject* dco = wxPyMake_wxObject(&dc,false);
618 PyObject* ao = wxPyMake_wxGridCellAttr(&attr,false);
619
620 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OOOii)",
621 go, ao, dco,
622 row, col));
623 Py_DECREF(go);
624 Py_DECREF(ao);
625 Py_DECREF(dco);
626
627 if (ro) {
628 const char* errmsg = "GetBestSize should return a 2-tuple of integers or a wxSize object.";
629 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxSize"))) {
630 rval = *ptr;
631 }
632 else if (PySequence_Check(ro) && PyObject_Length(ro) == 2) {
633 PyObject* o1 = PySequence_GetItem(ro, 0);
634 PyObject* o2 = PySequence_GetItem(ro, 1);
635 if (PyNumber_Check(o1) && PyNumber_Check(o2))
636 rval = wxSize(PyInt_AsLong(o1), PyInt_AsLong(o2));
637 else
638 PyErr_SetString(PyExc_TypeError, errmsg);
639 Py_DECREF(o1);
640 Py_DECREF(o2);
641 }
642 else {
643 PyErr_SetString(PyExc_TypeError, errmsg);
644 }
645 Py_DECREF(ro);
646 }
647 }
648 wxPyEndBlockThreads(blocked);
649 return rval;
650 }
651
652
653 wxGridCellRenderer *Clone() const {
654 wxGridCellRenderer* rval = NULL;
655 bool blocked = wxPyBeginBlockThreads();
656 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
657 PyObject* ro;
658 wxGridCellRenderer* ptr;
659 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
660 if (ro) {
661 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxGridCellRenderer")))
662 rval = ptr;
663 Py_DECREF(ro);
664 }
665 }
666 wxPyEndBlockThreads(blocked);
667 return rval;
668 }
669
670 DEC_PYCALLBACK__STRING(SetParameters);
671
672 PYPRIVATE;
673 };
674
675 IMP_PYCALLBACK__STRING( wxPyGridCellRenderer, wxGridCellRenderer, SetParameters);
676
677 %}
678
679
680 // Let SWIG know about it so it can create the Python version
681 class wxPyGridCellRenderer : public wxGridCellRenderer {
682 public:
683 %pythonAppend wxPyGridCellRenderer "self._setCallbackInfo(self, PyGridCellRenderer);self._setOORInfo(self)"
684
685 wxPyGridCellRenderer();
686 void _setCallbackInfo(PyObject* self, PyObject* _class);
687
688 void base_SetParameters(const wxString& params);
689 };
690
691 //---------------------------------------------------------------------------
692 // Predefined Renderers
693
694 class wxGridCellStringRenderer : public wxGridCellRenderer
695 {
696 public:
697 %pythonAppend wxGridCellStringRenderer "self._setOORInfo(self)"
698 wxGridCellStringRenderer();
699 };
700
701
702 class wxGridCellNumberRenderer : public wxGridCellStringRenderer
703 {
704 public:
705 %pythonAppend wxGridCellNumberRenderer "self._setOORInfo(self)"
706 wxGridCellNumberRenderer();
707 };
708
709
710 class wxGridCellFloatRenderer : public wxGridCellStringRenderer
711 {
712 public:
713 %pythonAppend wxGridCellFloatRenderer "self._setOORInfo(self)"
714 wxGridCellFloatRenderer(int width = -1, int precision = -1);
715
716 int GetWidth() const;
717 void SetWidth(int width);
718 int GetPrecision() const;
719 void SetPrecision(int precision);
720 };
721
722
723 class wxGridCellBoolRenderer : public wxGridCellRenderer
724 {
725 public:
726 %pythonAppend wxGridCellBoolRenderer "self._setOORInfo(self)"
727 wxGridCellBoolRenderer();
728 };
729
730
731 class wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
732 {
733 public:
734 %pythonAppend wxGridCellDateTimeRenderer "self._setOORInfo(self)"
735 wxGridCellDateTimeRenderer(wxString outformat = wxPyDateTimeFormatStr,
736 wxString informat = wxPyDateTimeFormatStr);
737 };
738
739
740 class wxGridCellEnumRenderer : public wxGridCellStringRenderer
741 {
742 public:
743 %pythonAppend wxGridCellEnumRenderer "self._setOORInfo(self)"
744 wxGridCellEnumRenderer( const wxString& choices = wxPyEmptyString );
745 };
746
747
748 class wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer
749 {
750 public:
751 %pythonAppend wxGridCellAutoWrapStringRenderer "self._setOORInfo(self)"
752 wxGridCellAutoWrapStringRenderer();
753 };
754
755
756 //---------------------------------------------------------------------------
757 // wxGridCellEditor is an ABC, and several derived classes are available.
758 // Classes implemented in Python should be derived from wxPyGridCellEditor.
759
760 class wxGridCellEditor
761 {
762 public:
763 %extend {
764 void _setOORInfo(PyObject* _self) {
765 self->SetClientObject(new wxPyOORClientData(_self));
766 }
767 }
768
769 bool IsCreated();
770 wxControl* GetControl();
771 void SetControl(wxControl* control);
772
773 wxGridCellAttr* GetCellAttr();
774 void SetCellAttr(wxGridCellAttr* attr);
775
776 void SetParameters(const wxString& params);
777 void IncRef();
778 void DecRef();
779
780 virtual void Create(wxWindow* parent,
781 wxWindowID id,
782 wxEvtHandler* evtHandler);
783 virtual void BeginEdit(int row, int col, wxGrid* grid);
784 virtual bool EndEdit(int row, int col, wxGrid* grid);
785 virtual void Reset();
786 virtual wxGridCellEditor *Clone() const;
787
788 virtual void SetSize(const wxRect& rect);
789 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
790 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
791 virtual bool IsAcceptedKey(wxKeyEvent& event);
792 virtual void StartingKey(wxKeyEvent& event);
793 virtual void StartingClick();
794 virtual void HandleReturn(wxKeyEvent& event);
795 virtual void Destroy();
796
797 };
798
799
800 // The C++ version of wxPyGridCellEditor
801 %{
802 class wxPyGridCellEditor : public wxGridCellEditor
803 {
804 public:
805 wxPyGridCellEditor() : wxGridCellEditor() {}
806
807 void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) {
808 bool blocked = wxPyBeginBlockThreads();
809 if (wxPyCBH_findCallback(m_myInst, "Create")) {
810 PyObject* po = wxPyMake_wxObject(parent,false);
811 PyObject* eo = wxPyMake_wxObject(evtHandler,false);
812
813 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OiO)", po, id, eo));
814 Py_DECREF(po);
815 Py_DECREF(eo);
816 }
817 wxPyEndBlockThreads(blocked);
818 }
819
820
821 void BeginEdit(int row, int col, wxGrid* grid) {
822 bool blocked = wxPyBeginBlockThreads();
823 if (wxPyCBH_findCallback(m_myInst, "BeginEdit")) {
824 PyObject* go = wxPyMake_wxObject(grid,false);
825 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", row, col, go));
826 Py_DECREF(go);
827 }
828 wxPyEndBlockThreads(blocked);
829 }
830
831
832 bool EndEdit(int row, int col, wxGrid* grid) {
833 bool rv = False;
834 bool blocked = wxPyBeginBlockThreads();
835 if (wxPyCBH_findCallback(m_myInst, "EndEdit")) {
836 PyObject* go = wxPyMake_wxObject(grid,false);
837 rv = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", row, col, go));
838 Py_DECREF(go);
839 }
840 wxPyEndBlockThreads(blocked);
841 return rv;
842 }
843
844
845 wxGridCellEditor* Clone() const {
846 wxGridCellEditor* rval = NULL;
847 bool blocked = wxPyBeginBlockThreads();
848 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
849 PyObject* ro;
850 wxGridCellEditor* ptr;
851 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
852 if (ro) {
853 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxGridCellEditor")))
854 rval = ptr;
855 Py_DECREF(ro);
856 }
857 }
858 wxPyEndBlockThreads(blocked);
859 return rval;
860 }
861
862
863 void Show(bool show, wxGridCellAttr *attr) {
864 bool found;
865 bool blocked = wxPyBeginBlockThreads();
866 if ((found = wxPyCBH_findCallback(m_myInst, "Show"))) {
867 PyObject* ao = wxPyMake_wxGridCellAttr(attr,false);
868 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", show, ao));
869 Py_DECREF(ao);
870 }
871 wxPyEndBlockThreads(blocked);
872 if (! found)
873 wxGridCellEditor::Show(show, attr);
874 }
875 void base_Show(bool show, wxGridCellAttr *attr) {
876 wxGridCellEditor::Show(show, attr);
877 }
878
879
880 void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
881 bool found;
882 bool blocked = wxPyBeginBlockThreads();
883 if ((found = wxPyCBH_findCallback(m_myInst, "PaintBackground)"))) {
884 PyObject* ao = wxPyMake_wxGridCellAttr(attr,false);
885 PyObject* ro = wxPyConstructObject((void*)&rectCell, wxT("wxRect"), 0);
886
887 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", ro, ao));
888
889 Py_DECREF(ro);
890 Py_DECREF(ao);
891 }
892 wxPyEndBlockThreads(blocked);
893 if (! found)
894 wxGridCellEditor::PaintBackground(rectCell, attr);
895 }
896 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
897 wxGridCellEditor::PaintBackground(rectCell, attr);
898 }
899
900
901 DEC_PYCALLBACK___pure(Reset);
902 DEC_PYCALLBACK__constany(SetSize, wxRect);
903 DEC_PYCALLBACK_bool_any(IsAcceptedKey, wxKeyEvent);
904 DEC_PYCALLBACK__any(StartingKey, wxKeyEvent);
905 DEC_PYCALLBACK__any(HandleReturn, wxKeyEvent);
906 DEC_PYCALLBACK__(StartingClick);
907 DEC_PYCALLBACK__(Destroy);
908 DEC_PYCALLBACK__STRING(SetParameters);
909 DEC_PYCALLBACK_STRING__constpure(GetValue);
910
911 PYPRIVATE;
912 };
913
914
915 IMP_PYCALLBACK__STRING( wxPyGridCellEditor, wxGridCellEditor, SetParameters);
916 IMP_PYCALLBACK___pure(wxPyGridCellEditor, wxGridCellEditor, Reset);
917 IMP_PYCALLBACK__constany(wxPyGridCellEditor, wxGridCellEditor, SetSize, wxRect);
918 IMP_PYCALLBACK_bool_any(wxPyGridCellEditor, wxGridCellEditor, IsAcceptedKey, wxKeyEvent);
919 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, StartingKey, wxKeyEvent);
920 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, HandleReturn, wxKeyEvent);
921 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, StartingClick);
922 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, Destroy);
923 IMP_PYCALLBACK_STRING__constpure(wxPyGridCellEditor, wxGridCellEditor, GetValue);
924
925 %}
926
927
928 // Let SWIG know about it so it can create the Python version
929 class wxPyGridCellEditor : public wxGridCellEditor {
930 public:
931 %pythonAppend wxPyGridCellEditor "self._setCallbackInfo(self, PyGridCellEditor);self._setOORInfo(self)"
932
933 wxPyGridCellEditor();
934 void _setCallbackInfo(PyObject* self, PyObject* _class);
935
936 void base_SetSize(const wxRect& rect);
937 void base_Show(bool show, wxGridCellAttr *attr = NULL);
938 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
939 bool base_IsAcceptedKey(wxKeyEvent& event);
940 void base_StartingKey(wxKeyEvent& event);
941 void base_StartingClick();
942 void base_HandleReturn(wxKeyEvent& event);
943 void base_Destroy();
944 void base_SetParameters(const wxString& params);
945 };
946
947 //---------------------------------------------------------------------------
948 // Predefined Editors
949
950 class wxGridCellTextEditor : public wxGridCellEditor
951 {
952 public:
953 %pythonAppend wxGridCellTextEditor "self._setOORInfo(self)"
954 wxGridCellTextEditor();
955 virtual wxString GetValue();
956 };
957
958
959 class wxGridCellNumberEditor : public wxGridCellTextEditor
960 {
961 public:
962 %pythonAppend wxGridCellNumberEditor "self._setOORInfo(self)"
963 wxGridCellNumberEditor(int min = -1, int max = -1);
964 virtual wxString GetValue();
965 };
966
967
968 class wxGridCellFloatEditor : public wxGridCellTextEditor
969 {
970 public:
971 %pythonAppend wxGridCellFloatEditor "self._setOORInfo(self)"
972 wxGridCellFloatEditor(int width = -1, int precision = -1);
973 virtual wxString GetValue();
974 };
975
976
977 class wxGridCellBoolEditor : public wxGridCellEditor
978 {
979 public:
980 %pythonAppend wxGridCellBoolEditor "self._setOORInfo(self)"
981 wxGridCellBoolEditor();
982 virtual wxString GetValue();
983 };
984
985 class wxGridCellChoiceEditor : public wxGridCellEditor
986 {
987 public:
988 %pythonAppend wxGridCellChoiceEditor "self._setOORInfo(self)"
989 wxGridCellChoiceEditor(int choices = 0,
990 const wxString* choices_array = NULL,
991 bool allowOthers = False);
992 virtual wxString GetValue();
993 };
994
995
996 class wxGridCellEnumEditor : public wxGridCellChoiceEditor
997 {
998 public:
999 %pythonAppend wxGridCellEnumEditor "self._setOORInfo(self)"
1000 wxGridCellEnumEditor( const wxString& choices = wxPyEmptyString );
1001 virtual wxString GetValue();
1002 };
1003
1004
1005 class wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
1006 {
1007 public:
1008 %pythonAppend wxGridCellAutoWrapStringEditor "self._setOORInfo(self)"
1009 wxGridCellAutoWrapStringEditor();
1010 virtual wxString GetValue();
1011 };
1012
1013
1014
1015 //---------------------------------------------------------------------------
1016
1017
1018 class wxGridCellAttr
1019 {
1020 public:
1021 enum wxAttrKind
1022 {
1023 Any,
1024 Default,
1025 Cell,
1026 Row,
1027 Col,
1028 Merged
1029 };
1030
1031 %extend {
1032 void _setOORInfo(PyObject* _self) {
1033 self->SetClientObject(new wxPyOORClientData(_self));
1034 }
1035 }
1036
1037 %pythonAppend wxGridCellAttr "self._setOORInfo(self)"
1038
1039 wxGridCellAttr(wxGridCellAttr *attrDefault = NULL);
1040
1041 wxGridCellAttr *Clone() const;
1042 void MergeWith(wxGridCellAttr *mergefrom);
1043 void IncRef();
1044 void DecRef();
1045 void SetTextColour(const wxColour& colText);
1046 void SetBackgroundColour(const wxColour& colBack);
1047 void SetFont(const wxFont& font);
1048 void SetAlignment(int hAlign, int vAlign);
1049 void SetSize(int num_rows, int num_cols);
1050 void SetOverflow( bool allow = True );
1051 void SetReadOnly(bool isReadOnly = True);
1052
1053 void SetRenderer(wxGridCellRenderer *renderer);
1054 void SetEditor(wxGridCellEditor* editor);
1055 void SetKind(wxAttrKind kind);
1056
1057 bool HasTextColour() const;
1058 bool HasBackgroundColour() const;
1059 bool HasFont() const;
1060 bool HasAlignment() const;
1061 bool HasRenderer() const;
1062 bool HasEditor() const;
1063 bool HasReadWriteMode() const;
1064 bool HasOverflowMode() const;
1065
1066 wxColour GetTextColour() const;
1067 wxColour GetBackgroundColour() const;
1068 wxFont GetFont() const;
1069
1070 DocDeclA(
1071 void, GetAlignment(int *OUTPUT, int *OUTPUT) const,
1072 "GetAlignment() -> (hAlign, vAlign)");
1073
1074 DocDeclA(
1075 void, GetSize(int *OUTPUT, int *OUTPUT) const,
1076 "GetSize() -> (num_rows, num_cols)");
1077
1078 bool GetOverflow() const;
1079 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
1080 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
1081
1082 bool IsReadOnly() const;
1083 wxAttrKind GetKind();
1084 void SetDefAttr(wxGridCellAttr* defAttr);
1085 };
1086
1087 //---------------------------------------------------------------------------
1088
1089 class wxGridCellAttrProvider
1090 {
1091 public:
1092 %pythonAppend wxGridCellAttrProvider "self._setOORInfo(self)"
1093 wxGridCellAttrProvider();
1094 // ???? virtual ~wxGridCellAttrProvider();
1095
1096 %extend {
1097 void _setOORInfo(PyObject* _self) {
1098 self->SetClientObject(new wxPyOORClientData(_self));
1099 }
1100 }
1101
1102 wxGridCellAttr *GetAttr(int row, int col,
1103 wxGridCellAttr::wxAttrKind kind) const;
1104 void SetAttr(wxGridCellAttr *attr, int row, int col);
1105 void SetRowAttr(wxGridCellAttr *attr, int row);
1106 void SetColAttr(wxGridCellAttr *attr, int col);
1107
1108 void UpdateAttrRows( size_t pos, int numRows );
1109 void UpdateAttrCols( size_t pos, int numCols );
1110
1111 };
1112
1113
1114 // A Python-aware version
1115 %{
1116 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1117 {
1118 public:
1119 wxPyGridCellAttrProvider() : wxGridCellAttrProvider() {};
1120
1121 PYCALLBACK_GCA_INTINTKIND(wxGridCellAttrProvider, GetAttr);
1122 PYCALLBACK__GCAINTINT(wxGridCellAttrProvider, SetAttr);
1123 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetRowAttr);
1124 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetColAttr);
1125
1126 PYPRIVATE;
1127 };
1128 %}
1129
1130
1131 // The python-aware version get's SWIGified
1132 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1133 {
1134 public:
1135 %pythonAppend wxPyGridCellAttrProvider "self._setCallbackInfo(self, PyGridCellAttrProvider)"
1136 wxPyGridCellAttrProvider();
1137 void _setCallbackInfo(PyObject* self, PyObject* _class);
1138
1139 wxGridCellAttr *base_GetAttr(int row, int col,
1140 wxGridCellAttr::wxAttrKind kind);
1141 void base_SetAttr(wxGridCellAttr *attr, int row, int col);
1142 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1143 void base_SetColAttr(wxGridCellAttr *attr, int col);
1144 };
1145
1146
1147 //---------------------------------------------------------------------------
1148 // Grid Table Base class and Python aware version
1149
1150
1151 class wxGridTableBase : public wxObject
1152 {
1153 public:
1154 // wxGridTableBase(); This is an ABC
1155 //~wxGridTableBase();
1156
1157 %extend {
1158 void _setOORInfo(PyObject* _self) {
1159 self->SetClientObject(new wxPyOORClientData(_self));
1160 }
1161 }
1162
1163 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
1164 wxGridCellAttrProvider *GetAttrProvider() const;
1165 void SetView( wxGrid *grid );
1166 wxGrid * GetView() const;
1167
1168
1169 // pure virtuals
1170 virtual int GetNumberRows();
1171 virtual int GetNumberCols();
1172 virtual bool IsEmptyCell( int row, int col );
1173 virtual wxString GetValue( int row, int col );
1174 virtual void SetValue( int row, int col, const wxString& value );
1175
1176 // virtuals overridable in wxPyGridTableBase
1177 virtual wxString GetTypeName( int row, int col );
1178 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
1179 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
1180 virtual long GetValueAsLong( int row, int col );
1181 virtual double GetValueAsDouble( int row, int col );
1182 virtual bool GetValueAsBool( int row, int col );
1183 virtual void SetValueAsLong( int row, int col, long value );
1184 virtual void SetValueAsDouble( int row, int col, double value );
1185 virtual void SetValueAsBool( int row, int col, bool value );
1186
1187 //virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
1188 //virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
1189
1190
1191 virtual void Clear();
1192 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
1193 virtual bool AppendRows( size_t numRows = 1 );
1194 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
1195 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
1196 virtual bool AppendCols( size_t numCols = 1 );
1197 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
1198
1199 virtual wxString GetRowLabelValue( int row );
1200 virtual wxString GetColLabelValue( int col );
1201 virtual void SetRowLabelValue( int row, const wxString& value );
1202 virtual void SetColLabelValue( int col, const wxString& value );
1203
1204 virtual bool CanHaveAttributes();
1205
1206 virtual wxGridCellAttr *GetAttr( int row, int col,
1207 wxGridCellAttr::wxAttrKind kind);
1208 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
1209 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
1210 virtual void SetColAttr(wxGridCellAttr *attr, int col);
1211
1212 };
1213
1214
1215
1216 // Python-aware version
1217 %{
1218 class wxPyGridTableBase : public wxGridTableBase
1219 {
1220 public:
1221 wxPyGridTableBase() : wxGridTableBase() {}
1222
1223 PYCALLBACK_INT__pure(GetNumberRows);
1224 PYCALLBACK_INT__pure(GetNumberCols);
1225 PYCALLBACK_BOOL_INTINT_pure(IsEmptyCell);
1226 PYCALLBACK_STRING_INTINT(wxGridTableBase, GetTypeName);
1227 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanGetValueAs);
1228 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanSetValueAs);
1229 PYCALLBACK__(wxGridTableBase, Clear);
1230 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertRows);
1231 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteRows);
1232 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertCols);
1233 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteCols);
1234 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendRows);
1235 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendCols);
1236 PYCALLBACK_STRING_INT(wxGridTableBase, GetRowLabelValue);
1237 PYCALLBACK_STRING_INT(wxGridTableBase, GetColLabelValue);
1238 PYCALLBACK__INTSTRING(wxGridTableBase, SetRowLabelValue);
1239 PYCALLBACK__INTSTRING(wxGridTableBase, SetColLabelValue);
1240 PYCALLBACK_BOOL_(wxGridTableBase, CanHaveAttributes);
1241 PYCALLBACK_GCA_INTINTKIND(wxGridTableBase, GetAttr);
1242 PYCALLBACK__GCAINTINT(wxGridTableBase, SetAttr);
1243 PYCALLBACK__GCAINT(wxGridTableBase, SetRowAttr);
1244 PYCALLBACK__GCAINT(wxGridTableBase, SetColAttr);
1245
1246
1247 wxString GetValue(int row, int col) {
1248 bool blocked = wxPyBeginBlockThreads();
1249 wxString rval;
1250 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1251 PyObject* ro;
1252 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",row,col));
1253 if (ro) {
1254 if (!PyString_Check(ro) && !PyUnicode_Check(ro)) {
1255 PyObject* old = ro;
1256 ro = PyObject_Str(ro);
1257 Py_DECREF(old);
1258 }
1259 rval = Py2wxString(ro);
1260 Py_DECREF(ro);
1261 }
1262 }
1263 wxPyEndBlockThreads(blocked);
1264 return rval;
1265 }
1266
1267 void SetValue(int row, int col, const wxString& val) {
1268 bool blocked = wxPyBeginBlockThreads();
1269 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1270 PyObject* s = wx2PyString(val);
1271 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",row,col,s));
1272 Py_DECREF(s);
1273 }
1274 wxPyEndBlockThreads(blocked);
1275 }
1276
1277
1278 // Map the Get/Set methods for the standard non-string types to
1279 // the GetValue and SetValue python methods.
1280 long GetValueAsLong( int row, int col ) {
1281 long rval = 0;
1282 bool blocked = wxPyBeginBlockThreads();
1283 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1284 PyObject* ro;
1285 PyObject* num;
1286 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1287 if (ro && PyNumber_Check(ro)) {
1288 num = PyNumber_Int(ro);
1289 if (num) {
1290 rval = PyInt_AsLong(num);
1291 Py_DECREF(num);
1292 }
1293 Py_DECREF(ro);
1294 }
1295 }
1296 wxPyEndBlockThreads(blocked);
1297 return rval;
1298 }
1299
1300 double GetValueAsDouble( int row, int col ) {
1301 double rval = 0.0;
1302 bool blocked = wxPyBeginBlockThreads();
1303 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1304 PyObject* ro;
1305 PyObject* num;
1306 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1307 if (ro && PyNumber_Check(ro)) {
1308 num = PyNumber_Float(ro);
1309 if (num) {
1310 rval = PyFloat_AsDouble(num);
1311 Py_DECREF(num);
1312 }
1313 Py_DECREF(ro);
1314 }
1315 }
1316 wxPyEndBlockThreads(blocked);
1317 return rval;
1318 }
1319
1320 bool GetValueAsBool( int row, int col ) {
1321 return (bool)GetValueAsLong(row, col);
1322 }
1323
1324 void SetValueAsLong( int row, int col, long value ) {
1325 bool blocked = wxPyBeginBlockThreads();
1326 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1327 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", row, col, value));
1328 }
1329 wxPyEndBlockThreads(blocked);
1330 }
1331
1332 void SetValueAsDouble( int row, int col, double value ) {
1333 bool blocked = wxPyBeginBlockThreads();
1334 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1335 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iid)", row, col, value));
1336 }
1337 wxPyEndBlockThreads(blocked);
1338 }
1339
1340 void SetValueAsBool( int row, int col, bool value ) {
1341 SetValueAsLong( row, col, (long)value );
1342 }
1343
1344
1345 PYPRIVATE;
1346 };
1347 %}
1348
1349
1350 // The python-aware version get's SWIGified
1351 class wxPyGridTableBase : public wxGridTableBase
1352 {
1353 public:
1354 %pythonAppend wxPyGridTableBase "self._setCallbackInfo(self, PyGridTableBase);self._setOORInfo(self)"
1355 wxPyGridTableBase();
1356 void _setCallbackInfo(PyObject* self, PyObject* _class);
1357
1358 %extend { void Destroy() { delete self; } }
1359
1360 wxString base_GetTypeName( int row, int col );
1361 bool base_CanGetValueAs( int row, int col, const wxString& typeName );
1362 bool base_CanSetValueAs( int row, int col, const wxString& typeName );
1363 void base_Clear();
1364 bool base_InsertRows( size_t pos = 0, size_t numRows = 1 );
1365 bool base_AppendRows( size_t numRows = 1 );
1366 bool base_DeleteRows( size_t pos = 0, size_t numRows = 1 );
1367 bool base_InsertCols( size_t pos = 0, size_t numCols = 1 );
1368 bool base_AppendCols( size_t numCols = 1 );
1369 bool base_DeleteCols( size_t pos = 0, size_t numCols = 1 );
1370 wxString base_GetRowLabelValue( int row );
1371 wxString base_GetColLabelValue( int col );
1372 void base_SetRowLabelValue( int row, const wxString& value );
1373 void base_SetColLabelValue( int col, const wxString& value );
1374 bool base_CanHaveAttributes();
1375 wxGridCellAttr *base_GetAttr( int row, int col,
1376 wxGridCellAttr::wxAttrKind kind );
1377 void base_SetAttr(wxGridCellAttr* attr, int row, int col);
1378 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1379 void base_SetColAttr(wxGridCellAttr *attr, int col);
1380 };
1381
1382
1383 //---------------------------------------------------------------------------
1384 // Predefined Tables
1385
1386 class wxGridStringTable : public wxGridTableBase
1387 {
1388 public:
1389 %pythonAppend wxGridStringTable "self._setOORInfo(self)"
1390 wxGridStringTable( int numRows=0, int numCols=0 );
1391 };
1392
1393 //---------------------------------------------------------------------------
1394 // The Table can pass messages to the grid to tell it to update itself if
1395 // something has changed.
1396
1397 enum wxGridTableRequest
1398 {
1399 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
1400 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
1401 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
1402 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
1403 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
1404 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1405 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
1406 wxGRIDTABLE_NOTIFY_COLS_DELETED
1407 };
1408
1409
1410 class wxGridTableMessage
1411 {
1412 public:
1413 wxGridTableMessage( wxGridTableBase *table, int id,
1414 int comInt1 = -1,
1415 int comInt2 = -1 );
1416 ~wxGridTableMessage();
1417
1418 void SetTableObject( wxGridTableBase *table );
1419 wxGridTableBase * GetTableObject() const;
1420 void SetId( int id );
1421 int GetId();
1422 void SetCommandInt( int comInt1 );
1423 int GetCommandInt();
1424 void SetCommandInt2( int comInt2 );
1425 int GetCommandInt2();
1426 };
1427
1428
1429 //---------------------------------------------------------------------------
1430
1431
1432 // Typemap to allow conversion of sequence objects to wxGridCellCoords...
1433 %typemap(in) wxGridCellCoords& (wxGridCellCoords temp) {
1434 $1 = &temp;
1435 if (! wxGridCellCoords_helper($input, &$1)) SWIG_fail;
1436 }
1437 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxGridCellCoords& {
1438 $1 = wxGridCellCoords_typecheck($input);
1439 }
1440
1441
1442 // ...and here is the associated helper.
1443 %{
1444 bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) {
1445
1446 if (source == Py_None) {
1447 **obj = wxGridCellCoords(-1,-1);
1448 return True;
1449 }
1450
1451 // If source is an object instance then it may already be the right type
1452 if (wxPySwigInstance_Check(source)) {
1453 wxGridCellCoords* ptr;
1454 if (! wxPyConvertSwigPtr(source, (void **)&ptr, wxT("wxGridCellCoords")))
1455 goto error;
1456 *obj = ptr;
1457 return True;
1458 }
1459 // otherwise a 2-tuple of integers is expected
1460 else if (PySequence_Check(source) && PyObject_Length(source) == 2) {
1461 PyObject* o1 = PySequence_GetItem(source, 0);
1462 PyObject* o2 = PySequence_GetItem(source, 1);
1463 if (!PyNumber_Check(o1) || !PyNumber_Check(o2)) {
1464 Py_DECREF(o1);
1465 Py_DECREF(o2);
1466 goto error;
1467 }
1468 **obj = wxGridCellCoords(PyInt_AsLong(o1), PyInt_AsLong(o2));
1469 Py_DECREF(o1);
1470 Py_DECREF(o2);
1471 return True;
1472 }
1473
1474 error:
1475 PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of integers or a wxGridCellCoords object.");
1476 return False;
1477 }
1478
1479
1480 bool wxGridCellCoords_typecheck(PyObject* source) {
1481 void* ptr;
1482
1483 if (wxPySwigInstance_Check(source) &&
1484 wxPyConvertSwigPtr(source, (void **)&ptr, wxT("wxGridCellCoords")))
1485 return True;
1486
1487 PyErr_Clear();
1488 if (PySequence_Check(source) && PySequence_Length(source) == 2)
1489 return True;
1490
1491 return False;
1492 }
1493 %}
1494
1495
1496 // Typemap to convert an array of cells coords to a list of tuples...
1497 %typemap(out) wxGridCellCoordsArray {
1498 $result = wxGridCellCoordsArray_helper($1);
1499 }
1500
1501 // %typemap(ret) wxGridCellCoordsArray {
1502 // delete $1;
1503 // }
1504
1505
1506 // ...and the helper function for the above typemap.
1507 %{
1508 PyObject* wxGridCellCoordsArray_helper(const wxGridCellCoordsArray& source)
1509 {
1510 PyObject* list = PyList_New(0);
1511 size_t idx;
1512 for (idx = 0; idx < source.GetCount(); idx += 1) {
1513 wxGridCellCoords& coord = source.Item(idx);
1514 PyObject* tup = PyTuple_New(2);
1515 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(coord.GetRow()));
1516 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(coord.GetCol()));
1517 PyList_Append(list, tup);
1518 Py_DECREF(tup);
1519 }
1520 return list;
1521 }
1522 %}
1523
1524
1525
1526
1527
1528 class wxGridCellCoords
1529 {
1530 public:
1531 wxGridCellCoords( int r=-1, int c=-1 );
1532 ~wxGridCellCoords();
1533
1534 int GetRow() const;
1535 void SetRow( int n );
1536 int GetCol() const;
1537 void SetCol( int n );
1538 void Set( int row, int col );
1539
1540 bool operator==( const wxGridCellCoords& other ) const;
1541 bool operator!=( const wxGridCellCoords& other ) const;
1542
1543 %extend {
1544 PyObject* Get() {
1545 PyObject* tup = PyTuple_New(2);
1546 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
1547 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
1548 return tup;
1549 }
1550 }
1551 %pythoncode {
1552 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
1553 def __str__(self): return str(self.Get())
1554 def __repr__(self): return 'wxGridCellCoords'+str(self.Get())
1555 def __len__(self): return len(self.Get())
1556 def __getitem__(self, index): return self.asTuple()[index]
1557 def __setitem__(self, index, val):
1558 if index == 0: self.SetRow(val)
1559 elif index == 1: self.SetCol(val)
1560 else: raise IndexError
1561 }
1562
1563 };
1564
1565
1566 //---------------------------------------------------------------------------
1567 //---------------------------------------------------------------------------
1568 // The grid itself
1569
1570
1571 // Fool SWIG into treating this enum as an int
1572 typedef int WXGRIDSELECTIONMODES;
1573
1574 // but let the C++ code know what it really is.
1575 %{
1576 typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES;
1577 %}
1578
1579
1580
1581 MustHaveApp(wxGrid);
1582
1583 class wxGrid : public wxScrolledWindow
1584 {
1585 public:
1586 %pythonAppend wxGrid "self._setOORInfo(self)"
1587
1588 wxGrid( wxWindow *parent,
1589 wxWindowID id=-1,
1590 const wxPoint& pos = wxDefaultPosition,
1591 const wxSize& size = wxDefaultSize,
1592 long style = wxWANTS_CHARS,
1593 const wxString& name = wxPyPanelNameStr);
1594
1595 %name(PreGrid) wxGrid();
1596
1597
1598 bool Create( wxWindow *parent,
1599 wxWindowID id=-1,
1600 const wxPoint& pos = wxDefaultPosition,
1601 const wxSize& size = wxDefaultSize,
1602 long style = wxWANTS_CHARS,
1603 const wxString& name = wxPyPanelNameStr );
1604
1605
1606 enum wxGridSelectionModes {
1607 wxGridSelectCells,
1608 wxGridSelectRows,
1609 wxGridSelectColumns
1610 };
1611 %pythoncode {
1612 SelectCells = wxGridSelectCells
1613 SelectRows = wxGridSelectRows
1614 SelectColumns = wxGridSelectColumns
1615 }
1616
1617 bool CreateGrid( int numRows, int numCols,
1618 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1619 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1620 WXGRIDSELECTIONMODES GetSelectionMode();
1621
1622
1623 // ------ grid dimensions
1624 //
1625 int GetNumberRows();
1626 int GetNumberCols();
1627
1628
1629 bool ProcessTableMessage( wxGridTableMessage& );
1630
1631
1632 wxGridTableBase * GetTable() const;
1633 bool SetTable( wxGridTableBase *table, bool takeOwnership=False,
1634 WXGRIDSELECTIONMODES selmode =
1635 wxGrid::wxGridSelectCells );
1636
1637 void ClearGrid();
1638 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=True );
1639 bool AppendRows( int numRows = 1, bool updateLabels=True );
1640 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=True );
1641 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=True );
1642 bool AppendCols( int numCols = 1, bool updateLabels=True );
1643 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=True );
1644
1645
1646 // this function is called when the current cell highlight must be redrawn
1647 // and may be overridden by the user
1648 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1649
1650
1651 // ------ Cell text drawing functions
1652 //
1653 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1654 int horizontalAlignment = wxLEFT,
1655 int verticalAlignment = wxTOP,
1656 int textOrientation = wxHORIZONTAL );
1657
1658 // // Split a string containing newline chararcters into an array of
1659 // // strings and return the number of lines
1660 // //
1661 // void StringToLines( const wxString& value, wxArrayString& lines );
1662
1663 DocDeclA(
1664 void, GetTextBoxSize( wxDC& dc, wxArrayString& lines,
1665 long *OUTPUT, long *OUTPUT ),
1666 "GetTextBoxSize(DC dc, list lines) -> (width, height)");
1667
1668
1669 // ------
1670 // Code that does a lot of grid modification can be enclosed
1671 // between BeginBatch() and EndBatch() calls to avoid screen
1672 // flicker
1673 //
1674 void BeginBatch();
1675 void EndBatch();
1676 int GetBatchCount();
1677 void ForceRefresh();
1678
1679
1680 // ------ edit control functions
1681 //
1682 bool IsEditable();
1683 void EnableEditing( bool edit );
1684
1685 void EnableCellEditControl( bool enable = True );
1686 void DisableCellEditControl();
1687 bool CanEnableCellControl() const;
1688 bool IsCellEditControlEnabled() const;
1689 bool IsCellEditControlShown() const;
1690
1691 bool IsCurrentCellReadOnly() const;
1692
1693 void ShowCellEditControl();
1694 void HideCellEditControl();
1695 void SaveEditControlValue();
1696
1697
1698 // ------ grid location functions
1699 // Note that all of these functions work with the logical coordinates of
1700 // grid cells and labels so you will need to convert from device
1701 // coordinates for mouse events etc.
1702 //
1703
1704 //void XYToCell( int x, int y, wxGridCellCoords& );
1705 %extend {
1706 wxGridCellCoords XYToCell(int x, int y) {
1707 wxGridCellCoords rv;
1708 self->XYToCell(x, y, rv);
1709 return rv;
1710 }
1711 }
1712
1713 int YToRow( int y );
1714 int XToCol( int x );
1715
1716 int YToEdgeOfRow( int y );
1717 int XToEdgeOfCol( int x );
1718
1719 wxRect CellToRect( int row, int col );
1720 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1721
1722
1723 int GetGridCursorRow();
1724 int GetGridCursorCol();
1725
1726 // check to see if a cell is either wholly visible (the default arg) or
1727 // at least partially visible in the grid window
1728 //
1729 bool IsVisible( int row, int col, bool wholeCellVisible = True );
1730 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = True );
1731 void MakeCellVisible( int row, int col );
1732 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1733
1734
1735 // ------ grid cursor movement functions
1736 //
1737 void SetGridCursor( int row, int col );
1738 bool MoveCursorUp( bool expandSelection );
1739 bool MoveCursorDown( bool expandSelection );
1740 bool MoveCursorLeft( bool expandSelection );
1741 bool MoveCursorRight( bool expandSelection );
1742 bool MovePageDown();
1743 bool MovePageUp();
1744 bool MoveCursorUpBlock( bool expandSelection );
1745 bool MoveCursorDownBlock( bool expandSelection );
1746 bool MoveCursorLeftBlock( bool expandSelection );
1747 bool MoveCursorRightBlock( bool expandSelection );
1748
1749
1750 // ------ label and gridline formatting
1751 //
1752 int GetDefaultRowLabelSize();
1753 int GetRowLabelSize();
1754 int GetDefaultColLabelSize();
1755 int GetColLabelSize();
1756 wxColour GetLabelBackgroundColour();
1757 wxColour GetLabelTextColour();
1758 wxFont GetLabelFont();
1759
1760 DocDeclA(
1761 void, GetRowLabelAlignment( int *OUTPUT, int *OUTPUT ),
1762 "GetRowLabelAlignment() -> (horiz, vert)");
1763
1764 DocDeclA(
1765 void, GetColLabelAlignment( int *OUTPUT, int *OUTPUT ),
1766 "GetColLabelAlignment() -> (horiz, vert)");
1767
1768 int GetColLabelTextOrientation();
1769 wxString GetRowLabelValue( int row );
1770 wxString GetColLabelValue( int col );
1771 wxColour GetGridLineColour();
1772 wxColour GetCellHighlightColour();
1773 int GetCellHighlightPenWidth();
1774 int GetCellHighlightROPenWidth();
1775
1776 void SetRowLabelSize( int width );
1777 void SetColLabelSize( int height );
1778 void SetLabelBackgroundColour( const wxColour& );
1779 void SetLabelTextColour( const wxColour& );
1780 void SetLabelFont( const wxFont& );
1781 void SetRowLabelAlignment( int horiz, int vert );
1782 void SetColLabelAlignment( int horiz, int vert );
1783 void SetColLabelTextOrientation( int textOrientation );
1784 void SetRowLabelValue( int row, const wxString& );
1785 void SetColLabelValue( int col, const wxString& );
1786 void SetGridLineColour( const wxColour& );
1787 void SetCellHighlightColour( const wxColour& );
1788 void SetCellHighlightPenWidth(int width);
1789 void SetCellHighlightROPenWidth(int width);
1790
1791 void EnableDragRowSize( bool enable = True );
1792 void DisableDragRowSize();
1793 bool CanDragRowSize();
1794 void EnableDragColSize( bool enable = True );
1795 void DisableDragColSize();
1796 bool CanDragColSize();
1797 void EnableDragGridSize(bool enable = True);
1798 void DisableDragGridSize();
1799 bool CanDragGridSize();
1800
1801 // this sets the specified attribute for all cells in this row/col
1802 void SetAttr(int row, int col, wxGridCellAttr *attr);
1803 void SetRowAttr(int row, wxGridCellAttr *attr);
1804 void SetColAttr(int col, wxGridCellAttr *attr);
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
1990 static wxVisualAttributes
1991 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
1992 };
1993
1994
1995 //---------------------------------------------------------------------------
1996 //---------------------------------------------------------------------------
1997 // Grid events and stuff
1998
1999
2000
2001 class wxGridEvent : public wxNotifyEvent
2002 {
2003 public:
2004 wxGridEvent(int id, wxEventType type, wxGrid* obj,
2005 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = True,
2006 bool control=False, bool shift=False, bool alt=False, bool meta=False);
2007
2008 virtual int GetRow();
2009 virtual int GetCol();
2010 wxPoint GetPosition();
2011 bool Selecting();
2012 bool ControlDown();
2013 bool MetaDown();
2014 bool ShiftDown();
2015 bool AltDown();
2016
2017 };
2018
2019
2020 class wxGridSizeEvent : public wxNotifyEvent
2021 {
2022 public:
2023 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
2024 int rowOrCol=-1, int x=-1, int y=-1,
2025 bool control=False, bool shift=False, bool alt=False, bool meta=False);
2026
2027 int GetRowOrCol();
2028 wxPoint GetPosition();
2029 bool ControlDown();
2030 bool MetaDown();
2031 bool ShiftDown();
2032 bool AltDown();
2033
2034 };
2035
2036
2037 class wxGridRangeSelectEvent : public wxNotifyEvent
2038 {
2039 public:
2040 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
2041 const wxGridCellCoords& topLeft,
2042 const wxGridCellCoords& bottomRight,
2043 bool sel = True,
2044 bool control=False, bool shift=False,
2045 bool alt=False, bool meta=False);
2046
2047 wxGridCellCoords GetTopLeftCoords();
2048 wxGridCellCoords GetBottomRightCoords();
2049 int GetTopRow();
2050 int GetBottomRow();
2051 int GetLeftCol();
2052 int GetRightCol();
2053 bool Selecting();
2054 bool ControlDown();
2055 bool MetaDown();
2056 bool ShiftDown();
2057 bool AltDown();
2058 };
2059
2060
2061 class wxGridEditorCreatedEvent : public wxCommandEvent {
2062 public:
2063 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
2064 int row, int col, wxControl* ctrl);
2065
2066 int GetRow();
2067 int GetCol();
2068 wxControl* GetControl();
2069 void SetRow(int row);
2070 void SetCol(int col);
2071 void SetControl(wxControl* ctrl);
2072 };
2073
2074
2075
2076 %constant wxEventType wxEVT_GRID_CELL_LEFT_CLICK;
2077 %constant wxEventType wxEVT_GRID_CELL_RIGHT_CLICK;
2078 %constant wxEventType wxEVT_GRID_CELL_LEFT_DCLICK;
2079 %constant wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK;
2080 %constant wxEventType wxEVT_GRID_LABEL_LEFT_CLICK;
2081 %constant wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK;
2082 %constant wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK;
2083 %constant wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK;
2084 %constant wxEventType wxEVT_GRID_ROW_SIZE;
2085 %constant wxEventType wxEVT_GRID_COL_SIZE;
2086 %constant wxEventType wxEVT_GRID_RANGE_SELECT;
2087 %constant wxEventType wxEVT_GRID_CELL_CHANGE;
2088 %constant wxEventType wxEVT_GRID_SELECT_CELL;
2089 %constant wxEventType wxEVT_GRID_EDITOR_SHOWN;
2090 %constant wxEventType wxEVT_GRID_EDITOR_HIDDEN;
2091 %constant wxEventType wxEVT_GRID_EDITOR_CREATED;
2092
2093
2094
2095 %pythoncode {
2096 EVT_GRID_CELL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_CLICK )
2097 EVT_GRID_CELL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_CLICK )
2098 EVT_GRID_CELL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_DCLICK )
2099 EVT_GRID_CELL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_DCLICK )
2100 EVT_GRID_LABEL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_CLICK )
2101 EVT_GRID_LABEL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_CLICK )
2102 EVT_GRID_LABEL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_DCLICK )
2103 EVT_GRID_LABEL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_DCLICK )
2104 EVT_GRID_ROW_SIZE = wx.PyEventBinder( wxEVT_GRID_ROW_SIZE )
2105 EVT_GRID_COL_SIZE = wx.PyEventBinder( wxEVT_GRID_COL_SIZE )
2106 EVT_GRID_RANGE_SELECT = wx.PyEventBinder( wxEVT_GRID_RANGE_SELECT )
2107 EVT_GRID_CELL_CHANGE = wx.PyEventBinder( wxEVT_GRID_CELL_CHANGE )
2108 EVT_GRID_SELECT_CELL = wx.PyEventBinder( wxEVT_GRID_SELECT_CELL )
2109 EVT_GRID_EDITOR_SHOWN = wx.PyEventBinder( wxEVT_GRID_EDITOR_SHOWN )
2110 EVT_GRID_EDITOR_HIDDEN = wx.PyEventBinder( wxEVT_GRID_EDITOR_HIDDEN )
2111 EVT_GRID_EDITOR_CREATED = wx.PyEventBinder( wxEVT_GRID_EDITOR_CREATED )
2112
2113
2114 %# The same as above but with the ability to specify an identifier
2115 EVT_GRID_CMD_CELL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_CLICK, 1 )
2116 EVT_GRID_CMD_CELL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_CLICK, 1 )
2117 EVT_GRID_CMD_CELL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_DCLICK, 1 )
2118 EVT_GRID_CMD_CELL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_DCLICK, 1 )
2119 EVT_GRID_CMD_LABEL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_CLICK, 1 )
2120 EVT_GRID_CMD_LABEL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_CLICK, 1 )
2121 EVT_GRID_CMD_LABEL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_DCLICK, 1 )
2122 EVT_GRID_CMD_LABEL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_DCLICK, 1 )
2123 EVT_GRID_CMD_ROW_SIZE = wx.PyEventBinder( wxEVT_GRID_ROW_SIZE, 1 )
2124 EVT_GRID_CMD_COL_SIZE = wx.PyEventBinder( wxEVT_GRID_COL_SIZE, 1 )
2125 EVT_GRID_CMD_RANGE_SELECT = wx.PyEventBinder( wxEVT_GRID_RANGE_SELECT, 1 )
2126 EVT_GRID_CMD_CELL_CHANGE = wx.PyEventBinder( wxEVT_GRID_CELL_CHANGE, 1 )
2127 EVT_GRID_CMD_SELECT_CELL = wx.PyEventBinder( wxEVT_GRID_SELECT_CELL, 1 )
2128 EVT_GRID_CMD_EDITOR_SHOWN = wx.PyEventBinder( wxEVT_GRID_EDITOR_SHOWN, 1 )
2129 EVT_GRID_CMD_EDITOR_HIDDEN = wx.PyEventBinder( wxEVT_GRID_EDITOR_HIDDEN, 1 )
2130 EVT_GRID_CMD_EDITOR_CREATED = wx.PyEventBinder( wxEVT_GRID_EDITOR_CREATED, 1 )
2131 }
2132
2133 //---------------------------------------------------------------------------
2134
2135 %init %{
2136 %}
2137
2138 //---------------------------------------------------------------------------
2139 //---------------------------------------------------------------------------
2140