]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/src/grid.i
Added wrappers and demo for RichTextCtrl
[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
1633 enum wxGridSelectionModes {
1634 wxGridSelectCells,
1635 wxGridSelectRows,
1636 wxGridSelectColumns
1637 };
1638 %pythoncode {
1639 SelectCells = wxGridSelectCells
1640 SelectRows = wxGridSelectRows
1641 SelectColumns = wxGridSelectColumns
1642 }
1643
1644 bool CreateGrid( int numRows, int numCols,
1645 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1646 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1647 WXGRIDSELECTIONMODES GetSelectionMode();
1648
1649
1650 // ------ grid dimensions
1651 //
1652 int GetNumberRows();
1653 int GetNumberCols();
1654
1655
1656 bool ProcessTableMessage( wxGridTableMessage& );
1657
1658
1659 wxGridTableBase * GetTable() const;
1660
1661 %disownarg(wxGridTableBase *);
1662 bool SetTable( wxGridTableBase *table, bool takeOwnership=false,
1663 WXGRIDSELECTIONMODES selmode =
1664 wxGrid::wxGridSelectCells );
1665 %cleardisown(wxGridTableBase *);
1666
1667 void ClearGrid();
1668 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=true );
1669 bool AppendRows( int numRows = 1, bool updateLabels=true );
1670 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=true );
1671 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=true );
1672 bool AppendCols( int numCols = 1, bool updateLabels=true );
1673 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=true );
1674
1675
1676 // this function is called when the current cell highlight must be redrawn
1677 // and may be overridden by the user
1678 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1679
1680
1681 // ------ Cell text drawing functions
1682 //
1683 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1684 int horizontalAlignment = wxLEFT,
1685 int verticalAlignment = wxTOP,
1686 int textOrientation = wxHORIZONTAL );
1687
1688// // Split a string containing newline chararcters into an array of
1689// // strings and return the number of lines
1690// //
1691// void StringToLines( const wxString& value, wxArrayString& lines );
1692
1693 DocDeclA(
1694 void, GetTextBoxSize( wxDC& dc, wxArrayString& lines,
1695 long *OUTPUT, long *OUTPUT ),
1696 "GetTextBoxSize(DC dc, list lines) -> (width, height)");
1697
1698
1699 // ------
1700 // Code that does a lot of grid modification can be enclosed
1701 // between BeginBatch() and EndBatch() calls to avoid screen
1702 // flicker
1703 //
1704 void BeginBatch();
1705 void EndBatch();
1706 int GetBatchCount();
1707 void ForceRefresh();
1708
1709
1710 // ------ edit control functions
1711 //
1712 bool IsEditable();
1713 void EnableEditing( bool edit );
1714
1715 void EnableCellEditControl( bool enable = true );
1716 void DisableCellEditControl();
1717 bool CanEnableCellControl() const;
1718 bool IsCellEditControlEnabled() const;
1719 bool IsCellEditControlShown() const;
1720
1721 bool IsCurrentCellReadOnly() const;
1722
1723 void ShowCellEditControl();
1724 void HideCellEditControl();
1725 void SaveEditControlValue();
1726
1727
1728 // ------ grid location functions
1729 // Note that all of these functions work with the logical coordinates of
1730 // grid cells and labels so you will need to convert from device
1731 // coordinates for mouse events etc.
1732 //
1733
1734 //void XYToCell( int x, int y, wxGridCellCoords& );
1735 %extend {
1736 wxGridCellCoords XYToCell(int x, int y) {
1737 wxGridCellCoords rv;
1738 self->XYToCell(x, y, rv);
1739 return rv;
1740 }
1741 }
1742
1743 int YToRow( int y );
1744 int XToCol( int x );
1745
1746 int YToEdgeOfRow( int y );
1747 int XToEdgeOfCol( int x );
1748
1749 wxRect CellToRect( int row, int col );
1750 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1751
1752
1753 int GetGridCursorRow();
1754 int GetGridCursorCol();
1755
1756 // check to see if a cell is either wholly visible (the default arg) or
1757 // at least partially visible in the grid window
1758 //
1759 bool IsVisible( int row, int col, bool wholeCellVisible = true );
1760 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = true );
1761 void MakeCellVisible( int row, int col );
1762 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1763
1764
1765 // ------ grid cursor movement functions
1766 //
1767 void SetGridCursor( int row, int col );
1768 bool MoveCursorUp( bool expandSelection );
1769 bool MoveCursorDown( bool expandSelection );
1770 bool MoveCursorLeft( bool expandSelection );
1771 bool MoveCursorRight( bool expandSelection );
1772 bool MovePageDown();
1773 bool MovePageUp();
1774 bool MoveCursorUpBlock( bool expandSelection );
1775 bool MoveCursorDownBlock( bool expandSelection );
1776 bool MoveCursorLeftBlock( bool expandSelection );
1777 bool MoveCursorRightBlock( bool expandSelection );
1778
1779
1780 // ------ label and gridline formatting
1781 //
1782 int GetDefaultRowLabelSize();
1783 int GetRowLabelSize();
1784 int GetDefaultColLabelSize();
1785 int GetColLabelSize();
1786 wxColour GetLabelBackgroundColour();
1787 wxColour GetLabelTextColour();
1788 wxFont GetLabelFont();
1789
1790 DocDeclA(
1791 void, GetRowLabelAlignment( int *OUTPUT, int *OUTPUT ),
1792 "GetRowLabelAlignment() -> (horiz, vert)");
1793
1794 DocDeclA(
1795 void, GetColLabelAlignment( int *OUTPUT, int *OUTPUT ),
1796 "GetColLabelAlignment() -> (horiz, vert)");
1797
1798 int GetColLabelTextOrientation();
1799 wxString GetRowLabelValue( int row );
1800 wxString GetColLabelValue( int col );
1801 wxColour GetGridLineColour();
1802 wxColour GetCellHighlightColour();
1803 int GetCellHighlightPenWidth();
1804 int GetCellHighlightROPenWidth();
1805
1806 void SetRowLabelSize( int width );
1807 void SetColLabelSize( int height );
1808 void SetLabelBackgroundColour( const wxColour& );
1809 void SetLabelTextColour( const wxColour& );
1810 void SetLabelFont( const wxFont& );
1811 void SetRowLabelAlignment( int horiz, int vert );
1812 void SetColLabelAlignment( int horiz, int vert );
1813 void SetColLabelTextOrientation( int textOrientation );
1814 void SetRowLabelValue( int row, const wxString& );
1815 void SetColLabelValue( int col, const wxString& );
1816 void SetGridLineColour( const wxColour& );
1817 void SetCellHighlightColour( const wxColour& );
1818 void SetCellHighlightPenWidth(int width);
1819 void SetCellHighlightROPenWidth(int width);
1820
1821 void EnableDragRowSize( bool enable = true );
1822 void DisableDragRowSize();
1823 bool CanDragRowSize();
1824 void EnableDragColSize( bool enable = true );
1825 void DisableDragColSize();
1826 bool CanDragColSize();
1827 void EnableDragGridSize(bool enable = true);
1828 void DisableDragGridSize();
1829 bool CanDragGridSize();
1830
1831 void EnableDragCell( bool enable = true );
1832 void DisableDragCell();
1833 bool CanDragCell();
1834
1835 // this sets the specified attribute for all cells in this row/col
1836 void SetAttr(int row, int col, wxGridCellAttr *attr);
1837 void SetRowAttr(int row, wxGridCellAttr *attr);
1838 void SetColAttr(int col, wxGridCellAttr *attr);
1839
1840 // returns the attribute we may modify in place: a new one if this cell
1841 // doesn't have any yet or the existing one if it does
1842 //
1843 // DecRef() must be called on the returned pointer, as usual
1844 wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const;
1845
1846
1847 // shortcuts for setting the column parameters
1848
1849 // set the format for the data in the column: default is string
1850 void SetColFormatBool(int col);
1851 void SetColFormatNumber(int col);
1852 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1853 void SetColFormatCustom(int col, const wxString& typeName);
1854
1855 void EnableGridLines( bool enable = true );
1856 bool GridLinesEnabled();
1857
1858 // ------ row and col formatting
1859 //
1860 int GetDefaultRowSize();
1861 int GetRowSize( int row );
1862 int GetDefaultColSize();
1863 int GetColSize( int col );
1864 wxColour GetDefaultCellBackgroundColour();
1865 wxColour GetCellBackgroundColour( int row, int col );
1866 wxColour GetDefaultCellTextColour();
1867 wxColour GetCellTextColour( int row, int col );
1868 wxFont GetDefaultCellFont();
1869 wxFont GetCellFont( int row, int col );
1870
1871 DocDeclA(
1872 void, GetDefaultCellAlignment( int *OUTPUT, int *OUTPUT ),
1873 "GetDefaultCellAlignment() -> (horiz, vert)");
1874
1875 DocDeclA(
1876 void, GetCellAlignment( int row, int col, int *OUTPUT, int *OUTPUT ),
1877 "GetCellAlignment() -> (horiz, vert)");
1878
1879 bool GetDefaultCellOverflow();
1880 bool GetCellOverflow( int row, int col );
1881
1882 DocDeclA(
1883 void, GetCellSize( int row, int col, int *OUTPUT, int *OUTPUT ),
1884 "GetCellSize(int row, int col) -> (num_rows, num_cols)");
1885
1886 void SetDefaultRowSize( int height, bool resizeExistingRows = false );
1887 void SetRowSize( int row, int height );
1888 void SetDefaultColSize( int width, bool resizeExistingCols = false );
1889
1890 void SetColSize( int col, int width );
1891
1892 // automatically size the column or row to fit to its contents, if
1893 // setAsMin is True, this optimal width will also be set as minimal width
1894 // for this column
1895 void AutoSizeColumn( int col, bool setAsMin = true );
1896 void AutoSizeRow( int row, bool setAsMin = true );
1897
1898
1899 // auto size all columns (very ineffective for big grids!)
1900 void AutoSizeColumns( bool setAsMin = true );
1901 void AutoSizeRows( bool setAsMin = true );
1902
1903 // auto size the grid, that is make the columns/rows of the "right" size
1904 // and also set the grid size to just fit its contents
1905 void AutoSize();
1906
1907 // autosize row height depending on label text
1908 void AutoSizeRowLabelSize( int row );
1909
1910 // autosize column width depending on label text
1911 void AutoSizeColLabelSize( int col );
1912
1913
1914 // column won't be resized to be lesser width - this must be called during
1915 // the grid creation because it won't resize the column if it's already
1916 // narrower than the minimal width
1917 void SetColMinimalWidth( int col, int width );
1918 void SetRowMinimalHeight( int row, int width );
1919
1920 void SetColMinimalAcceptableWidth( int width );
1921 void SetRowMinimalAcceptableHeight( int width );
1922 int GetColMinimalAcceptableWidth() const;
1923 int GetRowMinimalAcceptableHeight() const;
1924
1925 void SetDefaultCellBackgroundColour( const wxColour& );
1926 void SetCellBackgroundColour( int row, int col, const wxColour& );
1927 void SetDefaultCellTextColour( const wxColour& );
1928
1929 void SetCellTextColour( int row, int col, const wxColour& );
1930 void SetDefaultCellFont( const wxFont& );
1931 void SetCellFont( int row, int col, const wxFont& );
1932 void SetDefaultCellAlignment( int horiz, int vert );
1933 void SetCellAlignment( int row, int col, int horiz, int vert );
1934 void SetDefaultCellOverflow( bool allow );
1935 void SetCellOverflow( int row, int col, bool allow );
1936 void SetCellSize( int row, int col, int num_rows, int num_cols );
1937
1938 // takes ownership of the pointer
1939 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1940 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1941 wxGridCellRenderer *GetDefaultRenderer() const;
1942 wxGridCellRenderer* GetCellRenderer(int row, int col);
1943
1944 // takes ownership of the pointer
1945 void SetDefaultEditor(wxGridCellEditor *editor);
1946 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1947 wxGridCellEditor *GetDefaultEditor() const;
1948 wxGridCellEditor* GetCellEditor(int row, int col);
1949
1950
1951
1952 // ------ cell value accessors
1953 //
1954 wxString GetCellValue( int row, int col );
1955 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1956
1957 void SetCellValue( int row, int col, const wxString& s );
1958 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1959
1960 // returns True if the cell can't be edited
1961 bool IsReadOnly(int row, int col) const;
1962
1963 // make the cell editable/readonly
1964 void SetReadOnly(int row, int col, bool isReadOnly = true);
1965
1966 // ------ selections of blocks of cells
1967 //
1968 void SelectRow( int row, bool addToSelected = false );
1969 void SelectCol( int col, bool addToSelected = false );
1970
1971 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1972 bool addToSelected = false );
1973 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1974 // TODO: ??? const wxGridCellCoords& bottomRight )
1975
1976 void SelectAll();
1977 bool IsSelection();
1978 void ClearSelection();
1979 bool IsInSelection( int row, int col );
1980 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1981
1982 const wxGridCellCoordsArray GetSelectedCells() const;
1983 const wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
1984 const wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
1985 const wxArrayInt GetSelectedRows() const;
1986 const wxArrayInt GetSelectedCols() const;
1987
1988 void DeselectRow( int row );
1989 void DeselectCol( int col );
1990 void DeselectCell( int row, int col );
1991
1992
1993 // This function returns the rectangle that encloses the block of cells
1994 // limited by TopLeft and BottomRight cell in device coords and clipped
1995 // to the client size of the grid window.
1996 //
1997 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1998 const wxGridCellCoords & bottomRight );
1999
2000
2001 // Access or update the selection fore/back colours
2002 wxColour GetSelectionBackground() const;
2003 wxColour GetSelectionForeground() const;
2004
2005 void SetSelectionBackground(const wxColour& c);
2006 void SetSelectionForeground(const wxColour& c);
2007
2008
2009 // Methods for a registry for mapping data types to Renderers/Editors
2010 void RegisterDataType(const wxString& typeName,
2011 wxGridCellRenderer* renderer,
2012 wxGridCellEditor* editor);
2013 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
2014 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
2015 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
2016 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
2017 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
2018
2019 // grid may occupy more space than needed for its rows/columns, this
2020 // function allows to set how big this extra space is
2021 void SetMargins(int extraWidth, int extraHeight);
2022
2023
2024 // Accessors for component windows
2025 wxWindow* GetGridWindow();
2026 wxWindow* GetGridRowLabelWindow();
2027 wxWindow* GetGridColLabelWindow();
2028 wxWindow* GetGridCornerLabelWindow();
2029
2030 // Allow adjustment of scroll increment. The default is (15, 15).
2031 void SetScrollLineX(int x);
2032 void SetScrollLineY(int y);
2033 int GetScrollLineX() const;
2034 int GetScrollLineY() const;
2035
2036 int GetScrollX(int x) const;
2037 int GetScrollY(int y) const;
2038
2039 static wxVisualAttributes
2040 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
2041};
2042
2043
2044//---------------------------------------------------------------------------
2045//---------------------------------------------------------------------------
2046// Grid events and stuff
2047
2048
2049
2050class wxGridEvent : public wxNotifyEvent
2051{
2052public:
2053 wxGridEvent(int id, wxEventType type, wxGrid* obj,
2054 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = true,
2055 bool control=false, bool shift=false, bool alt=false, bool meta=false);
2056
2057 virtual int GetRow();
2058 virtual int GetCol();
2059 wxPoint GetPosition();
2060 bool Selecting();
2061 bool ControlDown();
2062 bool MetaDown();
2063 bool ShiftDown();
2064 bool AltDown();
2065 bool CmdDown();
2066};
2067
2068
2069class wxGridSizeEvent : public wxNotifyEvent
2070{
2071public:
2072 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
2073 int rowOrCol=-1, int x=-1, int y=-1,
2074 bool control=false, bool shift=false, bool alt=false, bool meta=false);
2075
2076 int GetRowOrCol();
2077 wxPoint GetPosition();
2078 bool ControlDown();
2079 bool MetaDown();
2080 bool ShiftDown();
2081 bool AltDown();
2082 bool CmdDown();
2083};
2084
2085
2086class wxGridRangeSelectEvent : public wxNotifyEvent
2087{
2088public:
2089 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
2090 const wxGridCellCoords& topLeft,
2091 const wxGridCellCoords& bottomRight,
2092 bool sel = true,
2093 bool control=false, bool shift=false,
2094 bool alt=false, bool meta=false);
2095
2096 wxGridCellCoords GetTopLeftCoords();
2097 wxGridCellCoords GetBottomRightCoords();
2098 int GetTopRow();
2099 int GetBottomRow();
2100 int GetLeftCol();
2101 int GetRightCol();
2102 bool Selecting();
2103 bool ControlDown();
2104 bool MetaDown();
2105 bool ShiftDown();
2106 bool AltDown();
2107 bool CmdDown();
2108};
2109
2110
2111class wxGridEditorCreatedEvent : public wxCommandEvent {
2112public:
2113 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
2114 int row, int col, wxControl* ctrl);
2115
2116 int GetRow();
2117 int GetCol();
2118 wxControl* GetControl();
2119 void SetRow(int row);
2120 void SetCol(int col);
2121 void SetControl(wxControl* ctrl);
2122};
2123
2124
2125
2126%constant wxEventType wxEVT_GRID_CELL_LEFT_CLICK;
2127%constant wxEventType wxEVT_GRID_CELL_RIGHT_CLICK;
2128%constant wxEventType wxEVT_GRID_CELL_LEFT_DCLICK;
2129%constant wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK;
2130%constant wxEventType wxEVT_GRID_LABEL_LEFT_CLICK;
2131%constant wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK;
2132%constant wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK;
2133%constant wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK;
2134%constant wxEventType wxEVT_GRID_ROW_SIZE;
2135%constant wxEventType wxEVT_GRID_COL_SIZE;
2136%constant wxEventType wxEVT_GRID_RANGE_SELECT;
2137%constant wxEventType wxEVT_GRID_CELL_CHANGE;
2138%constant wxEventType wxEVT_GRID_SELECT_CELL;
2139%constant wxEventType wxEVT_GRID_EDITOR_SHOWN;
2140%constant wxEventType wxEVT_GRID_EDITOR_HIDDEN;
2141%constant wxEventType wxEVT_GRID_EDITOR_CREATED;
2142%constant wxEventType wxEVT_GRID_CELL_BEGIN_DRAG;
2143
2144
2145
2146%pythoncode {
2147EVT_GRID_CELL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_CLICK )
2148EVT_GRID_CELL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_CLICK )
2149EVT_GRID_CELL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_DCLICK )
2150EVT_GRID_CELL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_DCLICK )
2151EVT_GRID_LABEL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_CLICK )
2152EVT_GRID_LABEL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_CLICK )
2153EVT_GRID_LABEL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_DCLICK )
2154EVT_GRID_LABEL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_DCLICK )
2155EVT_GRID_ROW_SIZE = wx.PyEventBinder( wxEVT_GRID_ROW_SIZE )
2156EVT_GRID_COL_SIZE = wx.PyEventBinder( wxEVT_GRID_COL_SIZE )
2157EVT_GRID_RANGE_SELECT = wx.PyEventBinder( wxEVT_GRID_RANGE_SELECT )
2158EVT_GRID_CELL_CHANGE = wx.PyEventBinder( wxEVT_GRID_CELL_CHANGE )
2159EVT_GRID_SELECT_CELL = wx.PyEventBinder( wxEVT_GRID_SELECT_CELL )
2160EVT_GRID_EDITOR_SHOWN = wx.PyEventBinder( wxEVT_GRID_EDITOR_SHOWN )
2161EVT_GRID_EDITOR_HIDDEN = wx.PyEventBinder( wxEVT_GRID_EDITOR_HIDDEN )
2162EVT_GRID_EDITOR_CREATED = wx.PyEventBinder( wxEVT_GRID_EDITOR_CREATED )
2163EVT_GRID_CELL_BEGIN_DRAG = wx.PyEventBinder( wxEVT_GRID_CELL_BEGIN_DRAG )
2164
2165
2166%# The same as above but with the ability to specify an identifier
2167EVT_GRID_CMD_CELL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_CLICK, 1 )
2168EVT_GRID_CMD_CELL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_CLICK, 1 )
2169EVT_GRID_CMD_CELL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_DCLICK, 1 )
2170EVT_GRID_CMD_CELL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_DCLICK, 1 )
2171EVT_GRID_CMD_LABEL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_CLICK, 1 )
2172EVT_GRID_CMD_LABEL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_CLICK, 1 )
2173EVT_GRID_CMD_LABEL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_DCLICK, 1 )
2174EVT_GRID_CMD_LABEL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_DCLICK, 1 )
2175EVT_GRID_CMD_ROW_SIZE = wx.PyEventBinder( wxEVT_GRID_ROW_SIZE, 1 )
2176EVT_GRID_CMD_COL_SIZE = wx.PyEventBinder( wxEVT_GRID_COL_SIZE, 1 )
2177EVT_GRID_CMD_RANGE_SELECT = wx.PyEventBinder( wxEVT_GRID_RANGE_SELECT, 1 )
2178EVT_GRID_CMD_CELL_CHANGE = wx.PyEventBinder( wxEVT_GRID_CELL_CHANGE, 1 )
2179EVT_GRID_CMD_SELECT_CELL = wx.PyEventBinder( wxEVT_GRID_SELECT_CELL, 1 )
2180EVT_GRID_CMD_EDITOR_SHOWN = wx.PyEventBinder( wxEVT_GRID_EDITOR_SHOWN, 1 )
2181EVT_GRID_CMD_EDITOR_HIDDEN = wx.PyEventBinder( wxEVT_GRID_EDITOR_HIDDEN, 1 )
2182EVT_GRID_CMD_EDITOR_CREATED = wx.PyEventBinder( wxEVT_GRID_EDITOR_CREATED, 1 )
2183EVT_GRID_CMD_CELL_BEGIN_DRAG = wx.PyEventBinder( wxEVT_GRID_CELL_BEGIN_DRAG, 1 )
2184
2185}
2186
2187//---------------------------------------------------------------------------
2188
2189%init %{
2190%}
2191
2192//---------------------------------------------------------------------------
2193//---------------------------------------------------------------------------
2194