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