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