]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/src/grid.i
applied patch 1378261
[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
38%include _grid_rename.i
39
40MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
41MAKE_CONST_WXSTRING_NOSWIG(PanelNameStr);
42MAKE_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) \
57PyObject* 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
82wxPyMake_TEMPLATE(wxGridCellRenderer)
83wxPyMake_TEMPLATE(wxGridCellEditor)
84wxPyMake_TEMPLATE(wxGridCellAttr)
85wxPyMake_TEMPLATE(wxGridCellAttrProvider)
86wxPyMake_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
446class wxGridCellCoords;
447class 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;
461const wxGridCellCoords wxGridNoCellCoords;
462const 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
479enum {
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
501class wxGridCellWorker
502{
503public:
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
526class 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%{
545class wxPyGridCellRenderer : public wxGridCellRenderer
546{
547public:
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
637IMP_PYCALLBACK__STRING( wxPyGridCellRenderer, wxGridCellRenderer, SetParameters);
638
639%}
640
641
642// Let SWIG know about it so it can create the Python version
643class wxPyGridCellRenderer : public wxGridCellRenderer {
644public:
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
657class wxGridCellStringRenderer : public wxGridCellRenderer
658{
659public:
660 %pythonAppend wxGridCellStringRenderer "self._setOORInfo(self)"
661 wxGridCellStringRenderer();
662};
663
664
665class wxGridCellNumberRenderer : public wxGridCellStringRenderer
666{
667public:
668 %pythonAppend wxGridCellNumberRenderer "self._setOORInfo(self)"
669 wxGridCellNumberRenderer();
670};
671
672
673class wxGridCellFloatRenderer : public wxGridCellStringRenderer
674{
675public:
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
686class wxGridCellBoolRenderer : public wxGridCellRenderer
687{
688public:
689 %pythonAppend wxGridCellBoolRenderer "self._setOORInfo(self)"
690 wxGridCellBoolRenderer();
691};
692
693
694class wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
695{
696public:
697 %pythonAppend wxGridCellDateTimeRenderer "self._setOORInfo(self)"
698 wxGridCellDateTimeRenderer(wxString outformat = wxPyDefaultDateTimeFormat,
699 wxString informat = wxPyDefaultDateTimeFormat);
700};
701
702
703class wxGridCellEnumRenderer : public wxGridCellStringRenderer
704{
705public:
706 %pythonAppend wxGridCellEnumRenderer "self._setOORInfo(self)"
707 wxGridCellEnumRenderer( const wxString& choices = wxPyEmptyString );
708};
709
710
711class wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer
712{
713public:
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
723class wxGridCellEditor : public wxGridCellWorker
724{
725public:
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%{
757class wxPyGridCellEditor : public wxGridCellEditor
758{
759public:
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
864IMP_PYCALLBACK__STRING( wxPyGridCellEditor, wxGridCellEditor, SetParameters);
865IMP_PYCALLBACK___pure(wxPyGridCellEditor, wxGridCellEditor, Reset);
866IMP_PYCALLBACK__constany(wxPyGridCellEditor, wxGridCellEditor, SetSize, wxRect);
867IMP_PYCALLBACK_bool_any(wxPyGridCellEditor, wxGridCellEditor, IsAcceptedKey, wxKeyEvent);
868IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, StartingKey, wxKeyEvent);
869IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, HandleReturn, wxKeyEvent);
870IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, StartingClick);
871IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, Destroy);
872IMP_PYCALLBACK_STRING__constpure(wxPyGridCellEditor, wxGridCellEditor, GetValue);
873
874%}
875
876
877// Let SWIG know about it so it can create the Python version
878class wxPyGridCellEditor : public wxGridCellEditor {
879public:
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
909class wxGridCellTextEditor : public wxGridCellEditor
910{
911public:
912 %pythonAppend wxGridCellTextEditor "self._setOORInfo(self)"
913 wxGridCellTextEditor();
914 virtual wxString GetValue();
915};
916
917
918class wxGridCellNumberEditor : public wxGridCellTextEditor
919{
920public:
921 %pythonAppend wxGridCellNumberEditor "self._setOORInfo(self)"
922 wxGridCellNumberEditor(int min = -1, int max = -1);
923 virtual wxString GetValue();
924};
925
926
927class wxGridCellFloatEditor : public wxGridCellTextEditor
928{
929public:
930 %pythonAppend wxGridCellFloatEditor "self._setOORInfo(self)"
931 wxGridCellFloatEditor(int width = -1, int precision = -1);
932 virtual wxString GetValue();
933};
934
935
936class wxGridCellBoolEditor : public wxGridCellEditor
937{
938public:
939 %pythonAppend wxGridCellBoolEditor "self._setOORInfo(self)"
940 wxGridCellBoolEditor();
941 virtual wxString GetValue();
942};
943
944class wxGridCellChoiceEditor : public wxGridCellEditor
945{
946public:
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
955class wxGridCellEnumEditor : public wxGridCellChoiceEditor
956{
957public:
958 %pythonAppend wxGridCellEnumEditor "self._setOORInfo(self)"
959 wxGridCellEnumEditor( const wxString& choices = wxPyEmptyString );
960 virtual wxString GetValue();
961};
962
963
964class wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
965{
966public:
967 %pythonAppend wxGridCellAutoWrapStringEditor "self._setOORInfo(self)"
968 wxGridCellAutoWrapStringEditor();
969 virtual wxString GetValue();
970};
971
972
973
974//---------------------------------------------------------------------------
975
976
977class wxGridCellAttr
978{
979public:
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
1058class wxGridCellAttrProvider
1059{
1060public:
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%{
1086class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1087{
1088public:
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
1102class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1103{
1104public:
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
1126class wxGridTableBase : public wxObject
1127{
1128public:
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%{
1194class wxPyGridTableBase : public wxGridTableBase
1195{
1196public:
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
1327class wxPyGridTableBase : public wxGridTableBase
1328{
1329public:
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
1383class wxGridStringTable : public wxGridTableBase
1384{
1385public:
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
1394enum 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
1407class wxGridTableMessage
1408{
1409public:
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%{
1441bool 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
1477bool 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%{
1505PyObject* 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
1525class wxGridCellCoords
1526{
1527public:
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
1594typedef int WXGRIDSELECTIONMODES;
1595
1596// but let the C++ code know what it really is.
1597%{
1598typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES;
1599%}
1600
1601
1602
1603MustHaveApp(wxGrid);
1604
1605class wxGrid : public wxScrolledWindow
1606{
1607public:
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 bool SetTable( wxGridTableBase *table, bool takeOwnership=false,
1663 WXGRIDSELECTIONMODES selmode =
1664 wxGrid::wxGridSelectCells );
1665
1666 void ClearGrid();
1667 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=true );
1668 bool AppendRows( int numRows = 1, bool updateLabels=true );
1669 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=true );
1670 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=true );
1671 bool AppendCols( int numCols = 1, bool updateLabels=true );
1672 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=true );
1673
1674
1675 // this function is called when the current cell highlight must be redrawn
1676 // and may be overridden by the user
1677 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1678
1679
1680 // ------ Cell text drawing functions
1681 //
1682 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1683 int horizontalAlignment = wxLEFT,
1684 int verticalAlignment = wxTOP,
1685 int textOrientation = wxHORIZONTAL );
1686
1687// // Split a string containing newline chararcters into an array of
1688// // strings and return the number of lines
1689// //
1690// void StringToLines( const wxString& value, wxArrayString& lines );
1691
1692 DocDeclA(
1693 void, GetTextBoxSize( wxDC& dc, wxArrayString& lines,
1694 long *OUTPUT, long *OUTPUT ),
1695 "GetTextBoxSize(DC dc, list lines) -> (width, height)");
1696
1697
1698 // ------
1699 // Code that does a lot of grid modification can be enclosed
1700 // between BeginBatch() and EndBatch() calls to avoid screen
1701 // flicker
1702 //
1703 void BeginBatch();
1704 void EndBatch();
1705 int GetBatchCount();
1706 void ForceRefresh();
1707
1708
1709 // ------ edit control functions
1710 //
1711 bool IsEditable();
1712 void EnableEditing( bool edit );
1713
1714 void EnableCellEditControl( bool enable = true );
1715 void DisableCellEditControl();
1716 bool CanEnableCellControl() const;
1717 bool IsCellEditControlEnabled() const;
1718 bool IsCellEditControlShown() const;
1719
1720 bool IsCurrentCellReadOnly() const;
1721
1722 void ShowCellEditControl();
1723 void HideCellEditControl();
1724 void SaveEditControlValue();
1725
1726
1727 // ------ grid location functions
1728 // Note that all of these functions work with the logical coordinates of
1729 // grid cells and labels so you will need to convert from device
1730 // coordinates for mouse events etc.
1731 //
1732
1733 //void XYToCell( int x, int y, wxGridCellCoords& );
1734 %extend {
1735 wxGridCellCoords XYToCell(int x, int y) {
1736 wxGridCellCoords rv;
1737 self->XYToCell(x, y, rv);
1738 return rv;
1739 }
1740 }
1741
1742 int YToRow( int y );
1743 int XToCol( int x );
1744
1745 int YToEdgeOfRow( int y );
1746 int XToEdgeOfCol( int x );
1747
1748 wxRect CellToRect( int row, int col );
1749 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1750
1751
1752 int GetGridCursorRow();
1753 int GetGridCursorCol();
1754
1755 // check to see if a cell is either wholly visible (the default arg) or
1756 // at least partially visible in the grid window
1757 //
1758 bool IsVisible( int row, int col, bool wholeCellVisible = true );
1759 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = true );
1760 void MakeCellVisible( int row, int col );
1761 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1762
1763
1764 // ------ grid cursor movement functions
1765 //
1766 void SetGridCursor( int row, int col );
1767 bool MoveCursorUp( bool expandSelection );
1768 bool MoveCursorDown( bool expandSelection );
1769 bool MoveCursorLeft( bool expandSelection );
1770 bool MoveCursorRight( bool expandSelection );
1771 bool MovePageDown();
1772 bool MovePageUp();
1773 bool MoveCursorUpBlock( bool expandSelection );
1774 bool MoveCursorDownBlock( bool expandSelection );
1775 bool MoveCursorLeftBlock( bool expandSelection );
1776 bool MoveCursorRightBlock( bool expandSelection );
1777
1778
1779 // ------ label and gridline formatting
1780 //
1781 int GetDefaultRowLabelSize();
1782 int GetRowLabelSize();
1783 int GetDefaultColLabelSize();
1784 int GetColLabelSize();
1785 wxColour GetLabelBackgroundColour();
1786 wxColour GetLabelTextColour();
1787 wxFont GetLabelFont();
1788
1789 DocDeclA(
1790 void, GetRowLabelAlignment( int *OUTPUT, int *OUTPUT ),
1791 "GetRowLabelAlignment() -> (horiz, vert)");
1792
1793 DocDeclA(
1794 void, GetColLabelAlignment( int *OUTPUT, int *OUTPUT ),
1795 "GetColLabelAlignment() -> (horiz, vert)");
1796
1797 int GetColLabelTextOrientation();
1798 wxString GetRowLabelValue( int row );
1799 wxString GetColLabelValue( int col );
1800 wxColour GetGridLineColour();
1801 wxColour GetCellHighlightColour();
1802 int GetCellHighlightPenWidth();
1803 int GetCellHighlightROPenWidth();
1804
1805 void SetRowLabelSize( int width );
1806 void SetColLabelSize( int height );
1807 void SetLabelBackgroundColour( const wxColour& );
1808 void SetLabelTextColour( const wxColour& );
1809 void SetLabelFont( const wxFont& );
1810 void SetRowLabelAlignment( int horiz, int vert );
1811 void SetColLabelAlignment( int horiz, int vert );
1812 void SetColLabelTextOrientation( int textOrientation );
1813 void SetRowLabelValue( int row, const wxString& );
1814 void SetColLabelValue( int col, const wxString& );
1815 void SetGridLineColour( const wxColour& );
1816 void SetCellHighlightColour( const wxColour& );
1817 void SetCellHighlightPenWidth(int width);
1818 void SetCellHighlightROPenWidth(int width);
1819
1820 void EnableDragRowSize( bool enable = true );
1821 void DisableDragRowSize();
1822 bool CanDragRowSize();
1823 void EnableDragColSize( bool enable = true );
1824 void DisableDragColSize();
1825 bool CanDragColSize();
1826 void EnableDragGridSize(bool enable = true);
1827 void DisableDragGridSize();
1828 bool CanDragGridSize();
1829
1830 void EnableDragCell( bool enable = true );
1831 void DisableDragCell();
1832 bool CanDragCell();
1833
1834 // this sets the specified attribute for all cells in this row/col
1835 void SetAttr(int row, int col, wxGridCellAttr *attr);
1836 void SetRowAttr(int row, wxGridCellAttr *attr);
1837 void SetColAttr(int col, wxGridCellAttr *attr);
1838
1839 // returns the attribute we may modify in place: a new one if this cell
1840 // doesn't have any yet or the existing one if it does
1841 //
1842 // DecRef() must be called on the returned pointer, as usual
1843 wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const;
1844
1845
1846 // shortcuts for setting the column parameters
1847
1848 // set the format for the data in the column: default is string
1849 void SetColFormatBool(int col);
1850 void SetColFormatNumber(int col);
1851 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1852 void SetColFormatCustom(int col, const wxString& typeName);
1853
1854 void EnableGridLines( bool enable = true );
1855 bool GridLinesEnabled();
1856
1857 // ------ row and col formatting
1858 //
1859 int GetDefaultRowSize();
1860 int GetRowSize( int row );
1861 int GetDefaultColSize();
1862 int GetColSize( int col );
1863 wxColour GetDefaultCellBackgroundColour();
1864 wxColour GetCellBackgroundColour( int row, int col );
1865 wxColour GetDefaultCellTextColour();
1866 wxColour GetCellTextColour( int row, int col );
1867 wxFont GetDefaultCellFont();
1868 wxFont GetCellFont( int row, int col );
1869
1870 DocDeclA(
1871 void, GetDefaultCellAlignment( int *OUTPUT, int *OUTPUT ),
1872 "GetDefaultCellAlignment() -> (horiz, vert)");
1873
1874 DocDeclA(
1875 void, GetCellAlignment( int row, int col, int *OUTPUT, int *OUTPUT ),
1876 "GetCellAlignment() -> (horiz, vert)");
1877
1878 bool GetDefaultCellOverflow();
1879 bool GetCellOverflow( int row, int col );
1880
1881 DocDeclA(
1882 void, GetCellSize( int row, int col, int *OUTPUT, int *OUTPUT ),
1883 "GetCellSize(int row, int col) -> (num_rows, num_cols)");
1884
1885 void SetDefaultRowSize( int height, bool resizeExistingRows = false );
1886 void SetRowSize( int row, int height );
1887 void SetDefaultColSize( int width, bool resizeExistingCols = false );
1888
1889 void SetColSize( int col, int width );
1890
1891 // automatically size the column or row to fit to its contents, if
1892 // setAsMin is True, this optimal width will also be set as minimal width
1893 // for this column
1894 void AutoSizeColumn( int col, bool setAsMin = true );
1895 void AutoSizeRow( int row, bool setAsMin = true );
1896
1897
1898 // auto size all columns (very ineffective for big grids!)
1899 void AutoSizeColumns( bool setAsMin = true );
1900 void AutoSizeRows( bool setAsMin = true );
1901
1902 // auto size the grid, that is make the columns/rows of the "right" size
1903 // and also set the grid size to just fit its contents
1904 void AutoSize();
1905
1906 // autosize row height depending on label text
1907 void AutoSizeRowLabelSize( int row );
1908
1909 // autosize column width depending on label text
1910 void AutoSizeColLabelSize( int col );
1911
1912
1913 // column won't be resized to be lesser width - this must be called during
1914 // the grid creation because it won't resize the column if it's already
1915 // narrower than the minimal width
1916 void SetColMinimalWidth( int col, int width );
1917 void SetRowMinimalHeight( int row, int width );
1918
1919 void SetColMinimalAcceptableWidth( int width );
1920 void SetRowMinimalAcceptableHeight( int width );
1921 int GetColMinimalAcceptableWidth() const;
1922 int GetRowMinimalAcceptableHeight() const;
1923
1924 void SetDefaultCellBackgroundColour( const wxColour& );
1925 void SetCellBackgroundColour( int row, int col, const wxColour& );
1926 void SetDefaultCellTextColour( const wxColour& );
1927
1928 void SetCellTextColour( int row, int col, const wxColour& );
1929 void SetDefaultCellFont( const wxFont& );
1930 void SetCellFont( int row, int col, const wxFont& );
1931 void SetDefaultCellAlignment( int horiz, int vert );
1932 void SetCellAlignment( int row, int col, int horiz, int vert );
1933 void SetDefaultCellOverflow( bool allow );
1934 void SetCellOverflow( int row, int col, bool allow );
1935 void SetCellSize( int row, int col, int num_rows, int num_cols );
1936
1937 // takes ownership of the pointer
1938 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1939 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1940 wxGridCellRenderer *GetDefaultRenderer() const;
1941 wxGridCellRenderer* GetCellRenderer(int row, int col);
1942
1943 // takes ownership of the pointer
1944 void SetDefaultEditor(wxGridCellEditor *editor);
1945 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1946 wxGridCellEditor *GetDefaultEditor() const;
1947 wxGridCellEditor* GetCellEditor(int row, int col);
1948
1949
1950
1951 // ------ cell value accessors
1952 //
1953 wxString GetCellValue( int row, int col );
1954 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1955
1956 void SetCellValue( int row, int col, const wxString& s );
1957 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1958
1959 // returns True if the cell can't be edited
1960 bool IsReadOnly(int row, int col) const;
1961
1962 // make the cell editable/readonly
1963 void SetReadOnly(int row, int col, bool isReadOnly = true);
1964
1965 // ------ selections of blocks of cells
1966 //
1967 void SelectRow( int row, bool addToSelected = false );
1968 void SelectCol( int col, bool addToSelected = false );
1969
1970 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1971 bool addToSelected = false );
1972 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1973 // TODO: ??? const wxGridCellCoords& bottomRight )
1974
1975 void SelectAll();
1976 bool IsSelection();
1977 void ClearSelection();
1978 bool IsInSelection( int row, int col );
1979 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1980
1981 const wxGridCellCoordsArray GetSelectedCells() const;
1982 const wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
1983 const wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
1984 const wxArrayInt GetSelectedRows() const;
1985 const wxArrayInt GetSelectedCols() const;
1986
1987 void DeselectRow( int row );
1988 void DeselectCol( int col );
1989 void DeselectCell( int row, int col );
1990
1991
1992 // This function returns the rectangle that encloses the block of cells
1993 // limited by TopLeft and BottomRight cell in device coords and clipped
1994 // to the client size of the grid window.
1995 //
1996 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1997 const wxGridCellCoords & bottomRight );
1998
1999
2000 // Access or update the selection fore/back colours
2001 wxColour GetSelectionBackground() const;
2002 wxColour GetSelectionForeground() const;
2003
2004 void SetSelectionBackground(const wxColour& c);
2005 void SetSelectionForeground(const wxColour& c);
2006
2007
2008 // Methods for a registry for mapping data types to Renderers/Editors
2009 void RegisterDataType(const wxString& typeName,
2010 wxGridCellRenderer* renderer,
2011 wxGridCellEditor* editor);
2012 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
2013 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
2014 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
2015 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
2016 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
2017
2018 // grid may occupy more space than needed for its rows/columns, this
2019 // function allows to set how big this extra space is
2020 void SetMargins(int extraWidth, int extraHeight);
2021
2022
2023 // Accessors for component windows
2024 wxWindow* GetGridWindow();
2025 wxWindow* GetGridRowLabelWindow();
2026 wxWindow* GetGridColLabelWindow();
2027 wxWindow* GetGridCornerLabelWindow();
2028
2029 // Allow adjustment of scroll increment. The default is (15, 15).
2030 void SetScrollLineX(int x);
2031 void SetScrollLineY(int y);
2032 int GetScrollLineX() const;
2033 int GetScrollLineY() const;
2034
2035 int GetScrollX(int x) const;
2036 int GetScrollY(int y) const;
2037
2038 static wxVisualAttributes
2039 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
2040};
2041
2042
2043//---------------------------------------------------------------------------
2044//---------------------------------------------------------------------------
2045// Grid events and stuff
2046
2047
2048
2049class wxGridEvent : public wxNotifyEvent
2050{
2051public:
2052 wxGridEvent(int id, wxEventType type, wxGrid* obj,
2053 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = true,
2054 bool control=false, bool shift=false, bool alt=false, bool meta=false);
2055
2056 virtual int GetRow();
2057 virtual int GetCol();
2058 wxPoint GetPosition();
2059 bool Selecting();
2060 bool ControlDown();
2061 bool MetaDown();
2062 bool ShiftDown();
2063 bool AltDown();
2064
2065};
2066
2067
2068class wxGridSizeEvent : public wxNotifyEvent
2069{
2070public:
2071 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
2072 int rowOrCol=-1, int x=-1, int y=-1,
2073 bool control=false, bool shift=false, bool alt=false, bool meta=false);
2074
2075 int GetRowOrCol();
2076 wxPoint GetPosition();
2077 bool ControlDown();
2078 bool MetaDown();
2079 bool ShiftDown();
2080 bool AltDown();
2081
2082};
2083
2084
2085class wxGridRangeSelectEvent : public wxNotifyEvent
2086{
2087public:
2088 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
2089 const wxGridCellCoords& topLeft,
2090 const wxGridCellCoords& bottomRight,
2091 bool sel = true,
2092 bool control=false, bool shift=false,
2093 bool alt=false, bool meta=false);
2094
2095 wxGridCellCoords GetTopLeftCoords();
2096 wxGridCellCoords GetBottomRightCoords();
2097 int GetTopRow();
2098 int GetBottomRow();
2099 int GetLeftCol();
2100 int GetRightCol();
2101 bool Selecting();
2102 bool ControlDown();
2103 bool MetaDown();
2104 bool ShiftDown();
2105 bool AltDown();
2106};
2107
2108
2109class wxGridEditorCreatedEvent : public wxCommandEvent {
2110public:
2111 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
2112 int row, int col, wxControl* ctrl);
2113
2114 int GetRow();
2115 int GetCol();
2116 wxControl* GetControl();
2117 void SetRow(int row);
2118 void SetCol(int col);
2119 void SetControl(wxControl* ctrl);
2120};
2121
2122
2123
2124%constant wxEventType wxEVT_GRID_CELL_LEFT_CLICK;
2125%constant wxEventType wxEVT_GRID_CELL_RIGHT_CLICK;
2126%constant wxEventType wxEVT_GRID_CELL_LEFT_DCLICK;
2127%constant wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK;
2128%constant wxEventType wxEVT_GRID_LABEL_LEFT_CLICK;
2129%constant wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK;
2130%constant wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK;
2131%constant wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK;
2132%constant wxEventType wxEVT_GRID_ROW_SIZE;
2133%constant wxEventType wxEVT_GRID_COL_SIZE;
2134%constant wxEventType wxEVT_GRID_RANGE_SELECT;
2135%constant wxEventType wxEVT_GRID_CELL_CHANGE;
2136%constant wxEventType wxEVT_GRID_SELECT_CELL;
2137%constant wxEventType wxEVT_GRID_EDITOR_SHOWN;
2138%constant wxEventType wxEVT_GRID_EDITOR_HIDDEN;
2139%constant wxEventType wxEVT_GRID_EDITOR_CREATED;
2140%constant wxEventType wxEVT_GRID_CELL_BEGIN_DRAG;
2141
2142
2143
2144%pythoncode {
2145EVT_GRID_CELL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_CLICK )
2146EVT_GRID_CELL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_CLICK )
2147EVT_GRID_CELL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_DCLICK )
2148EVT_GRID_CELL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_DCLICK )
2149EVT_GRID_LABEL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_CLICK )
2150EVT_GRID_LABEL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_CLICK )
2151EVT_GRID_LABEL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_DCLICK )
2152EVT_GRID_LABEL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_DCLICK )
2153EVT_GRID_ROW_SIZE = wx.PyEventBinder( wxEVT_GRID_ROW_SIZE )
2154EVT_GRID_COL_SIZE = wx.PyEventBinder( wxEVT_GRID_COL_SIZE )
2155EVT_GRID_RANGE_SELECT = wx.PyEventBinder( wxEVT_GRID_RANGE_SELECT )
2156EVT_GRID_CELL_CHANGE = wx.PyEventBinder( wxEVT_GRID_CELL_CHANGE )
2157EVT_GRID_SELECT_CELL = wx.PyEventBinder( wxEVT_GRID_SELECT_CELL )
2158EVT_GRID_EDITOR_SHOWN = wx.PyEventBinder( wxEVT_GRID_EDITOR_SHOWN )
2159EVT_GRID_EDITOR_HIDDEN = wx.PyEventBinder( wxEVT_GRID_EDITOR_HIDDEN )
2160EVT_GRID_EDITOR_CREATED = wx.PyEventBinder( wxEVT_GRID_EDITOR_CREATED )
2161EVT_GRID_CELL_BEGIN_DRAG = wx.PyEventBinder( wxEVT_GRID_CELL_BEGIN_DRAG )
2162
2163
2164%# The same as above but with the ability to specify an identifier
2165EVT_GRID_CMD_CELL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_CLICK, 1 )
2166EVT_GRID_CMD_CELL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_CLICK, 1 )
2167EVT_GRID_CMD_CELL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_DCLICK, 1 )
2168EVT_GRID_CMD_CELL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_DCLICK, 1 )
2169EVT_GRID_CMD_LABEL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_CLICK, 1 )
2170EVT_GRID_CMD_LABEL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_CLICK, 1 )
2171EVT_GRID_CMD_LABEL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_DCLICK, 1 )
2172EVT_GRID_CMD_LABEL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_DCLICK, 1 )
2173EVT_GRID_CMD_ROW_SIZE = wx.PyEventBinder( wxEVT_GRID_ROW_SIZE, 1 )
2174EVT_GRID_CMD_COL_SIZE = wx.PyEventBinder( wxEVT_GRID_COL_SIZE, 1 )
2175EVT_GRID_CMD_RANGE_SELECT = wx.PyEventBinder( wxEVT_GRID_RANGE_SELECT, 1 )
2176EVT_GRID_CMD_CELL_CHANGE = wx.PyEventBinder( wxEVT_GRID_CELL_CHANGE, 1 )
2177EVT_GRID_CMD_SELECT_CELL = wx.PyEventBinder( wxEVT_GRID_SELECT_CELL, 1 )
2178EVT_GRID_CMD_EDITOR_SHOWN = wx.PyEventBinder( wxEVT_GRID_EDITOR_SHOWN, 1 )
2179EVT_GRID_CMD_EDITOR_HIDDEN = wx.PyEventBinder( wxEVT_GRID_EDITOR_HIDDEN, 1 )
2180EVT_GRID_CMD_EDITOR_CREATED = wx.PyEventBinder( wxEVT_GRID_EDITOR_CREATED, 1 )
2181EVT_GRID_CMD_CELL_BEGIN_DRAG = wx.PyEventBinder( wxEVT_GRID_CELL_BEGIN_DRAG, 1 )
2182
2183}
2184
2185//---------------------------------------------------------------------------
2186
2187%init %{
2188%}
2189
2190//---------------------------------------------------------------------------
2191//---------------------------------------------------------------------------
2192