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