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