]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/grid.i
reSWIGged
[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)"
f6bcfd97
BP
955 wxGridCellChoiceEditor(int LCOUNT = 0,
956 const wxString* choices = 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;
f6bcfd97 1035 void GetAlignment(int *OUTPUT, int *OUTPUT) const;
1fded56b 1036 void GetSize(int *OUTPUT, int *OUTPUT) const;
fd512ba2 1037 bool GetOverflow() const;
f6bcfd97
BP
1038 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
1039 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
1040
1041 bool IsReadOnly() const;
1042 void SetDefAttr(wxGridCellAttr* defAttr);
1043};
1044
1045//---------------------------------------------------------------------------
1046
1047class wxGridCellAttrProvider
1048{
1049public:
d14a1e28 1050 %addtofunc wxGridCellAttrProvider "self._setOORInfo(self)"
f6bcfd97
BP
1051 wxGridCellAttrProvider();
1052 // ???? virtual ~wxGridCellAttrProvider();
33ff77f6 1053
d14a1e28 1054 %extend {
33ff77f6
RD
1055 void _setOORInfo(PyObject* _self) {
1056 self->SetClientObject(new wxPyOORClientData(_self));
1057 }
1058 }
f6bcfd97 1059
9416aa89
RD
1060 wxGridCellAttr *GetAttr(int row, int col,
1061 wxGridCellAttr::wxAttrKind kind) const;
f6bcfd97
BP
1062 void SetAttr(wxGridCellAttr *attr, int row, int col);
1063 void SetRowAttr(wxGridCellAttr *attr, int row);
1064 void SetColAttr(wxGridCellAttr *attr, int col);
1065
1066 void UpdateAttrRows( size_t pos, int numRows );
1067 void UpdateAttrCols( size_t pos, int numCols );
1068
1069};
1070
1071
1072// A Python-aware version
1073%{
1074class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1075{
1076public:
1077 wxPyGridCellAttrProvider() : wxGridCellAttrProvider() {};
1078
9416aa89 1079 PYCALLBACK_GCA_INTINTKIND(wxGridCellAttrProvider, GetAttr);
f6bcfd97
BP
1080 PYCALLBACK__GCAINTINT(wxGridCellAttrProvider, SetAttr);
1081 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetRowAttr);
1082 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetColAttr);
1083
1084 PYPRIVATE;
1085};
1086%}
1087
1088
1089// The python-aware version get's SWIGified
1090class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1091{
1092public:
d14a1e28 1093 %addtofunc wxPyGridCellAttrProvider "self._setCallbackInfo(self, PyGridCellAttrProvider)"
f6bcfd97 1094 wxPyGridCellAttrProvider();
0122b7e3 1095 void _setCallbackInfo(PyObject* self, PyObject* _class);
f6bcfd97 1096
9416aa89
RD
1097 wxGridCellAttr *base_GetAttr(int row, int col,
1098 wxGridCellAttr::wxAttrKind kind);
f6bcfd97
BP
1099 void base_SetAttr(wxGridCellAttr *attr, int row, int col);
1100 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1101 void base_SetColAttr(wxGridCellAttr *attr, int col);
1102};
1103
1104
1105//---------------------------------------------------------------------------
1106// Grid Table Base class and Python aware version
1107
1108
9416aa89 1109class wxGridTableBase : public wxObject
f6bcfd97
BP
1110{
1111public:
1112 // wxGridTableBase(); This is an ABC
1113 //~wxGridTableBase();
1114
d14a1e28 1115 %extend {
33ff77f6
RD
1116 void _setOORInfo(PyObject* _self) {
1117 self->SetClientObject(new wxPyOORClientData(_self));
1118 }
1119 }
1120
f6bcfd97
BP
1121 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
1122 wxGridCellAttrProvider *GetAttrProvider() const;
1123 void SetView( wxGrid *grid );
1124 wxGrid * GetView() const;
1125
1126
1127 // pure virtuals
d14a1e28
RD
1128 virtual int GetNumberRows();
1129 virtual int GetNumberCols();
1130 virtual bool IsEmptyCell( int row, int col );
1131 virtual wxString GetValue( int row, int col );
1132 virtual void SetValue( int row, int col, const wxString& value );
f6bcfd97
BP
1133
1134 // virtuals overridable in wxPyGridTableBase
1135 virtual wxString GetTypeName( int row, int col );
1136 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
1137 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
1138 virtual long GetValueAsLong( int row, int col );
1139 virtual double GetValueAsDouble( int row, int col );
1140 virtual bool GetValueAsBool( int row, int col );
1141 virtual void SetValueAsLong( int row, int col, long value );
1142 virtual void SetValueAsDouble( int row, int col, double value );
1143 virtual void SetValueAsBool( int row, int col, bool value );
1144
1145 //virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
1146 //virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
1147
1148
1149 virtual void Clear();
1150 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
1151 virtual bool AppendRows( size_t numRows = 1 );
1152 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
1153 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
1154 virtual bool AppendCols( size_t numCols = 1 );
1155 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
1156
1157 virtual wxString GetRowLabelValue( int row );
1158 virtual wxString GetColLabelValue( int col );
1159 virtual void SetRowLabelValue( int row, const wxString& value );
1160 virtual void SetColLabelValue( int col, const wxString& value );
1161
1162 virtual bool CanHaveAttributes();
1163
9416aa89
RD
1164 virtual wxGridCellAttr *GetAttr( int row, int col,
1165 wxGridCellAttr::wxAttrKind kind);
f6bcfd97
BP
1166 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
1167 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
1168 virtual void SetColAttr(wxGridCellAttr *attr, int col);
1169
1170};
1171
1172
1173
1174// Python-aware version
1175%{
1176class wxPyGridTableBase : public wxGridTableBase
1177{
1178public:
1179 wxPyGridTableBase() : wxGridTableBase() {}
1180
1181 PYCALLBACK_INT__pure(GetNumberRows);
1182 PYCALLBACK_INT__pure(GetNumberCols);
1183 PYCALLBACK_BOOL_INTINT_pure(IsEmptyCell);
1184 PYCALLBACK_STRING_INTINT(wxGridTableBase, GetTypeName);
1185 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanGetValueAs);
1186 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanSetValueAs);
1187 PYCALLBACK__(wxGridTableBase, Clear);
1188 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertRows);
1189 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteRows);
1190 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertCols);
1191 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteCols);
1192 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendRows);
1193 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendCols);
1194 PYCALLBACK_STRING_INT(wxGridTableBase, GetRowLabelValue);
1195 PYCALLBACK_STRING_INT(wxGridTableBase, GetColLabelValue);
1196 PYCALLBACK__INTSTRING(wxGridTableBase, SetRowLabelValue);
1197 PYCALLBACK__INTSTRING(wxGridTableBase, SetColLabelValue);
1198 PYCALLBACK_BOOL_(wxGridTableBase, CanHaveAttributes);
9416aa89 1199 PYCALLBACK_GCA_INTINTKIND(wxGridTableBase, GetAttr);
f6bcfd97
BP
1200 PYCALLBACK__GCAINTINT(wxGridTableBase, SetAttr);
1201 PYCALLBACK__GCAINT(wxGridTableBase, SetRowAttr);
1202 PYCALLBACK__GCAINT(wxGridTableBase, SetColAttr);
1203
1204
f6bcfd97 1205 wxString GetValue(int row, int col) {
4268f798 1206 wxPyBeginBlockThreads();
f6bcfd97 1207 wxString rval;
1e7ecb7b 1208 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
f6bcfd97 1209 PyObject* ro;
1e7ecb7b 1210 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",row,col));
f6bcfd97 1211 if (ro) {
a541c325 1212 rval = Py2wxString(ro);
f6bcfd97
BP
1213 Py_DECREF(ro);
1214 }
1215 }
4268f798 1216 wxPyEndBlockThreads();
f6bcfd97
BP
1217 return rval;
1218 }
1219
1220 void SetValue(int row, int col, const wxString& val) {
4268f798 1221 wxPyBeginBlockThreads();
c8bc7bb8 1222 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
a66212dc
RD
1223 PyObject* s = wx2PyString(val);
1224 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",row,col,s));
1225 Py_DECREF(s);
c8bc7bb8 1226 }
4268f798 1227 wxPyEndBlockThreads();
f6bcfd97
BP
1228 }
1229
1230
1231 // Map the Get/Set methods for the standard non-string types to
1232 // the GetValue and SetValue python methods.
1233 long GetValueAsLong( int row, int col ) {
1234 long rval = 0;
4268f798 1235 wxPyBeginBlockThreads();
1e7ecb7b 1236 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
f6bcfd97
BP
1237 PyObject* ro;
1238 PyObject* num;
1e7ecb7b 1239 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
f6bcfd97
BP
1240 if (ro && PyNumber_Check(ro)) {
1241 num = PyNumber_Int(ro);
1242 if (num) {
1243 rval = PyInt_AsLong(num);
1244 Py_DECREF(num);
1245 }
1246 Py_DECREF(ro);
1247 }
1248 }
4268f798 1249 wxPyEndBlockThreads();
f6bcfd97
BP
1250 return rval;
1251 }
1252
1253 double GetValueAsDouble( int row, int col ) {
1254 double rval = 0.0;
4268f798 1255 wxPyBeginBlockThreads();
1e7ecb7b 1256 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
f6bcfd97
BP
1257 PyObject* ro;
1258 PyObject* num;
1e7ecb7b 1259 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
f6bcfd97
BP
1260 if (ro && PyNumber_Check(ro)) {
1261 num = PyNumber_Float(ro);
1262 if (num) {
1263 rval = PyFloat_AsDouble(num);
1264 Py_DECREF(num);
1265 }
1266 Py_DECREF(ro);
1267 }
1268 }
4268f798 1269 wxPyEndBlockThreads();
f6bcfd97
BP
1270 return rval;
1271 }
1272
1273 bool GetValueAsBool( int row, int col ) {
1274 return (bool)GetValueAsLong(row, col);
1275 }
1276
1277 void SetValueAsLong( int row, int col, long value ) {
4268f798 1278 wxPyBeginBlockThreads();
1e7ecb7b
RD
1279 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1280 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", row, col, value));
f6bcfd97 1281 }
4268f798 1282 wxPyEndBlockThreads();
f6bcfd97
BP
1283 }
1284
1285 void SetValueAsDouble( int row, int col, double value ) {
4268f798 1286 wxPyBeginBlockThreads();
1e7ecb7b
RD
1287 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1288 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iid)", row, col, value));
f6bcfd97 1289 }
4268f798 1290 wxPyEndBlockThreads();
f6bcfd97
BP
1291 }
1292
1293 void SetValueAsBool( int row, int col, bool value ) {
1294 SetValueAsLong( row, col, (long)value );
1295 }
1296
1297
1298 PYPRIVATE;
1299};
1300%}
1301
1302
1303// The python-aware version get's SWIGified
1304class wxPyGridTableBase : public wxGridTableBase
1305{
1306public:
d14a1e28 1307 %addtofunc wxPyGridTableBase "self._setCallbackInfo(self, PyGridTableBase);self._setOORInfo(self)"
f6bcfd97 1308 wxPyGridTableBase();
0122b7e3 1309 void _setCallbackInfo(PyObject* self, PyObject* _class);
f6bcfd97 1310
d14a1e28 1311 %extend { void Destroy() { delete self; } }
f6bcfd97
BP
1312
1313 wxString base_GetTypeName( int row, int col );
1314 bool base_CanGetValueAs( int row, int col, const wxString& typeName );
1315 bool base_CanSetValueAs( int row, int col, const wxString& typeName );
1316 void base_Clear();
1317 bool base_InsertRows( size_t pos = 0, size_t numRows = 1 );
1318 bool base_AppendRows( size_t numRows = 1 );
1319 bool base_DeleteRows( size_t pos = 0, size_t numRows = 1 );
1320 bool base_InsertCols( size_t pos = 0, size_t numCols = 1 );
1321 bool base_AppendCols( size_t numCols = 1 );
1322 bool base_DeleteCols( size_t pos = 0, size_t numCols = 1 );
1323 wxString base_GetRowLabelValue( int row );
1324 wxString base_GetColLabelValue( int col );
1325 void base_SetRowLabelValue( int row, const wxString& value );
1326 void base_SetColLabelValue( int col, const wxString& value );
1327 bool base_CanHaveAttributes();
9416aa89
RD
1328 wxGridCellAttr *base_GetAttr( int row, int col,
1329 wxGridCellAttr::wxAttrKind kind );
f6bcfd97
BP
1330 void base_SetAttr(wxGridCellAttr* attr, int row, int col);
1331 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1332 void base_SetColAttr(wxGridCellAttr *attr, int col);
1333};
1334
1335
1336//---------------------------------------------------------------------------
1337// Predefined Tables
1338
1339class wxGridStringTable : public wxGridTableBase
1340{
1341public:
d14a1e28 1342 %addtofunc wxGridStringTable "self._setOORInfo(self)"
f6bcfd97
BP
1343 wxGridStringTable( int numRows=0, int numCols=0 );
1344};
1345
1346//---------------------------------------------------------------------------
1347// The Table can pass messages to the grid to tell it to update itself if
1348// something has changed.
1349
1350enum wxGridTableRequest
1351{
1352 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
1353 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
1354 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
1355 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
1356 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
1357 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1358 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
1359 wxGRIDTABLE_NOTIFY_COLS_DELETED
1360};
1361
1362
1363class wxGridTableMessage
1364{
1365public:
1366 wxGridTableMessage( wxGridTableBase *table, int id,
1367 int comInt1 = -1,
1368 int comInt2 = -1 );
1369 ~wxGridTableMessage();
1370
1371 void SetTableObject( wxGridTableBase *table );
1372 wxGridTableBase * GetTableObject() const;
1373 void SetId( int id );
1374 int GetId();
1375 void SetCommandInt( int comInt1 );
1376 int GetCommandInt();
1377 void SetCommandInt2( int comInt2 );
1378 int GetCommandInt2();
1379};
1380
1381
1382//---------------------------------------------------------------------------
1383
d14a1e28 1384
f6bcfd97
BP
1385class wxGridCellCoords
1386{
1387public:
1388 wxGridCellCoords( int r=-1, int c=-1 );
1389 ~wxGridCellCoords();
1390
d14a1e28
RD
1391 int GetRow() const;
1392 void SetRow( int n );
1393 int GetCol() const;
1394 void SetCol( int n );
1395 void Set( int row, int col );
f6bcfd97 1396
d14a1e28
RD
1397 bool operator==( const wxGridCellCoords& other ) const;
1398 bool operator!=( const wxGridCellCoords& other ) const;
1399
1400 %extend {
f6bcfd97
BP
1401 PyObject* asTuple() {
1402 PyObject* tup = PyTuple_New(2);
1403 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
1404 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
1405 return tup;
1406 }
f6bcfd97 1407 }
d14a1e28 1408 %pythoncode {
1e4a197e
RD
1409 def __str__(self): return str(self.asTuple())
1410 def __repr__(self): return 'wxGridCellCoords'+str(self.asTuple())
1411 def __len__(self): return len(self.asTuple())
1412 def __getitem__(self, index): return self.asTuple()[index]
1413 def __setitem__(self, index, val):
1414 if index == 0: self.SetRow(val)
1415 elif index == 1: self.SetCol(val)
1416 else: raise IndexError
d14a1e28 1417 }
1e4a197e 1418
f6bcfd97
BP
1419};
1420
1421// Typemap to allow conversion of sequence objects to wxGridCellCoords...
d14a1e28
RD
1422%typemap(in) wxGridCellCoords& (wxGridCellCoords temp) {
1423 $1 = &temp;
1424 if (! wxGridCellCoords_helper($input, &$1)) SWIG_fail;
1425}
1426%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxGridCellCoords& {
1427 $1 = wxGridCellCoords_typecheck($input);
f6bcfd97
BP
1428}
1429
d14a1e28 1430
f6bcfd97
BP
1431// ...and here is the associated helper.
1432%{
1433bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) {
1434
1435 // If source is an object instance then it may already be the right type
d14a1e28 1436 if (wxPySwigInstance_Check(source)) {
f6bcfd97 1437 wxGridCellCoords* ptr;
d14a1e28 1438 if (! wxPyConvertSwigPtr(source, (void **)&ptr, wxT("wxGridCellCoords")))
f6bcfd97
BP
1439 goto error;
1440 *obj = ptr;
dd9f7fea 1441 return True;
f6bcfd97
BP
1442 }
1443 // otherwise a 2-tuple of integers is expected
1444 else if (PySequence_Check(source) && PyObject_Length(source) == 2) {
1445 PyObject* o1 = PySequence_GetItem(source, 0);
1446 PyObject* o2 = PySequence_GetItem(source, 1);
d14a1e28
RD
1447 if (!PyNumber_Check(o1) || !PyNumber_Check(o2)) {
1448 Py_DECREF(o1);
1449 Py_DECREF(o2);
1450 goto error;
1451 }
f6bcfd97 1452 **obj = wxGridCellCoords(PyInt_AsLong(o1), PyInt_AsLong(o2));
d14a1e28
RD
1453 Py_DECREF(o1);
1454 Py_DECREF(o2);
dd9f7fea 1455 return True;
f6bcfd97
BP
1456 }
1457
1458 error:
1459 PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of integers or a wxGridCellCoords object.");
dd9f7fea 1460 return False;
f6bcfd97 1461}
f6bcfd97 1462
1e4a197e 1463
d14a1e28
RD
1464bool wxGridCellCoords_typecheck(PyObject* source) {
1465 void* ptr;
1466
1467 if (wxPySwigInstance_Check(source) &&
1468 wxPyConvertSwigPtr(source, (void **)&ptr, wxT("wxGridCellCoords")))
dd9f7fea 1469 return True;
1e4a197e 1470
d14a1e28
RD
1471 PyErr_Clear();
1472 if (PySequence_Check(source) && PySequence_Length(source) == 2)
dd9f7fea 1473 return True;
d14a1e28 1474
dd9f7fea 1475 return False;
1e4a197e 1476}
d14a1e28
RD
1477%}
1478
1e4a197e 1479
d14a1e28
RD
1480// Typemap to convert an array of cells coords to a list of tuples...
1481%typemap(out) wxGridCellCoordsArray {
1482 $result = wxGridCellCoordsArray_helper($1);
1e4a197e
RD
1483}
1484
d14a1e28
RD
1485// %typemap(ret) wxGridCellCoordsArray {
1486// delete $1;
1487// }
1488
1e4a197e
RD
1489
1490// ...and the helper function for the above typemap.
1491%{
d14a1e28 1492PyObject* wxGridCellCoordsArray_helper(const wxGridCellCoordsArray& source)
1e4a197e
RD
1493{
1494 PyObject* list = PyList_New(0);
1495 size_t idx;
d14a1e28
RD
1496 for (idx = 0; idx < source.GetCount(); idx += 1) {
1497 wxGridCellCoords& coord = source.Item(idx);
1e4a197e
RD
1498 PyObject* tup = PyTuple_New(2);
1499 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(coord.GetRow()));
1500 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(coord.GetCol()));
1501 PyList_Append(list, tup);
1502 Py_DECREF(tup);
1503 }
1504 return list;
1505}
1506%}
1507
f6bcfd97
BP
1508//---------------------------------------------------------------------------
1509//---------------------------------------------------------------------------
1510// The grid itself
1511
1512
1513// Fool SWIG into treating this enum as an int
1514typedef int WXGRIDSELECTIONMODES;
1515
1516// but let the C++ code know what it really is.
1517%{
1518typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES;
1519%}
1520
1521
1522
1523class wxGrid : public wxScrolledWindow
1524{
1525public:
d14a1e28
RD
1526 %addtofunc wxGrid "self._setOORInfo(self)"
1527
f6bcfd97
BP
1528 wxGrid( wxWindow *parent,
1529 wxWindowID id,
1530 const wxPoint& pos = wxDefaultPosition,
1531 const wxSize& size = wxDefaultSize,
1532 long style = wxWANTS_CHARS,
137b5242 1533 const wxString& name = wxPyPanelNameStr);
f6bcfd97 1534
f6bcfd97
BP
1535
1536 enum wxGridSelectionModes {wxGridSelectCells,
1537 wxGridSelectRows,
1538 wxGridSelectColumns};
1539
1540 bool CreateGrid( int numRows, int numCols,
1541 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1542 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1e6796a0 1543 WXGRIDSELECTIONMODES GetSelectionMode();
f6bcfd97
BP
1544
1545
1546 // ------ grid dimensions
1547 //
1548 int GetNumberRows();
1549 int GetNumberCols();
1550
1551
f6bcfd97
BP
1552 bool ProcessTableMessage( wxGridTableMessage& );
1553
1554
1555 wxGridTableBase * GetTable() const;
dd9f7fea 1556 bool SetTable( wxGridTableBase *table, bool takeOwnership=False,
f6bcfd97
BP
1557 WXGRIDSELECTIONMODES selmode =
1558 wxGrid::wxGridSelectCells );
1559
1560 void ClearGrid();
dd9f7fea
RD
1561 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=True );
1562 bool AppendRows( int numRows = 1, bool updateLabels=True );
1563 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=True );
1564 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=True );
1565 bool AppendCols( int numCols = 1, bool updateLabels=True );
1566 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=True );
f6bcfd97 1567
f6bcfd97
BP
1568
1569 // this function is called when the current cell highlight must be redrawn
1570 // and may be overridden by the user
1571 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1572
f6bcfd97
BP
1573
1574 // ------ Cell text drawing functions
1575 //
1576 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1577 int horizontalAlignment = wxLEFT,
1e4a197e
RD
1578 int verticalAlignment = wxTOP,
1579 int textOrientation = wxHORIZONTAL );
f6bcfd97 1580
b37c7e1d
RD
1581// // Split a string containing newline chararcters into an array of
1582// // strings and return the number of lines
1583// //
1584// void StringToLines( const wxString& value, wxArrayString& lines );
f6bcfd97
BP
1585
1586 void GetTextBoxSize( wxDC& dc,
1587 wxArrayString& lines,
1588 long *OUTPUT, long *OUTPUT );
1589
1590
1591 // ------
1592 // Code that does a lot of grid modification can be enclosed
1593 // between BeginBatch() and EndBatch() calls to avoid screen
1594 // flicker
1595 //
1596 void BeginBatch();
1597 void EndBatch();
1598 int GetBatchCount();
edf2f43e 1599 void ForceRefresh();
dd9f7fea 1600 void Refresh(bool eraseb=True, const wxRect* rect= NULL);
f6bcfd97
BP
1601
1602
1603 // ------ edit control functions
1604 //
fd512ba2 1605 bool IsEditable();
f6bcfd97
BP
1606 void EnableEditing( bool edit );
1607
dd9f7fea 1608 void EnableCellEditControl( bool enable = True );
f6bcfd97
BP
1609 void DisableCellEditControl();
1610 bool CanEnableCellControl() const;
1611 bool IsCellEditControlEnabled() const;
1612 bool IsCellEditControlShown() const;
1613
1614 bool IsCurrentCellReadOnly() const;
1615
1616 void ShowCellEditControl();
1617 void HideCellEditControl();
1618 void SaveEditControlValue();
1619
1620
1621 // ------ grid location functions
1622 // Note that all of these functions work with the logical coordinates of
1623 // grid cells and labels so you will need to convert from device
1624 // coordinates for mouse events etc.
1625 //
1626
1627 //void XYToCell( int x, int y, wxGridCellCoords& );
d14a1e28
RD
1628 %extend {
1629 wxGridCellCoords XYToCell(int x, int y) {
f6bcfd97
BP
1630 wxGridCellCoords rv;
1631 self->XYToCell(x, y, rv);
d14a1e28 1632 return rv;
f6bcfd97
BP
1633 }
1634 }
1635
1636 int YToRow( int y );
1637 int XToCol( int x );
1638
1639 int YToEdgeOfRow( int y );
1640 int XToEdgeOfCol( int x );
1641
1642 wxRect CellToRect( int row, int col );
1643 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1644
1645
1646 int GetGridCursorRow();
1647 int GetGridCursorCol();
1648
1649 // check to see if a cell is either wholly visible (the default arg) or
1650 // at least partially visible in the grid window
1651 //
dd9f7fea
RD
1652 bool IsVisible( int row, int col, bool wholeCellVisible = True );
1653 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = True );
f6bcfd97
BP
1654 void MakeCellVisible( int row, int col );
1655 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1656
1657
1658 // ------ grid cursor movement functions
1659 //
1660 void SetGridCursor( int row, int col );
1661 bool MoveCursorUp( bool expandSelection );
1662 bool MoveCursorDown( bool expandSelection );
1663 bool MoveCursorLeft( bool expandSelection );
1664 bool MoveCursorRight( bool expandSelection );
1665 bool MovePageDown();
1666 bool MovePageUp();
1667 bool MoveCursorUpBlock( bool expandSelection );
1668 bool MoveCursorDownBlock( bool expandSelection );
1669 bool MoveCursorLeftBlock( bool expandSelection );
1670 bool MoveCursorRightBlock( bool expandSelection );
1671
1672
1673 // ------ label and gridline formatting
1674 //
1675 int GetDefaultRowLabelSize();
1676 int GetRowLabelSize();
1677 int GetDefaultColLabelSize();
1678 int GetColLabelSize();
1679 wxColour GetLabelBackgroundColour();
1680 wxColour GetLabelTextColour();
1681 wxFont GetLabelFont();
1682 void GetRowLabelAlignment( int *OUTPUT, int *OUTPUT );
1683 void GetColLabelAlignment( int *OUTPUT, int *OUTPUT );
1e4a197e 1684 int GetColLabelTextOrientation();
f6bcfd97
BP
1685 wxString GetRowLabelValue( int row );
1686 wxString GetColLabelValue( int col );
1687 wxColour GetGridLineColour();
1688 wxColour GetCellHighlightColour();
9416aa89
RD
1689 int GetCellHighlightPenWidth();
1690 int GetCellHighlightROPenWidth();
f6bcfd97
BP
1691
1692 void SetRowLabelSize( int width );
1693 void SetColLabelSize( int height );
1694 void SetLabelBackgroundColour( const wxColour& );
1695 void SetLabelTextColour( const wxColour& );
1696 void SetLabelFont( const wxFont& );
1697 void SetRowLabelAlignment( int horiz, int vert );
1698 void SetColLabelAlignment( int horiz, int vert );
1e4a197e 1699 void SetColLabelTextOrientation( int textOrientation );
f6bcfd97
BP
1700 void SetRowLabelValue( int row, const wxString& );
1701 void SetColLabelValue( int col, const wxString& );
1702 void SetGridLineColour( const wxColour& );
1703 void SetCellHighlightColour( const wxColour& );
9416aa89
RD
1704 void SetCellHighlightPenWidth(int width);
1705 void SetCellHighlightROPenWidth(int width);
f6bcfd97 1706
dd9f7fea 1707 void EnableDragRowSize( bool enable = True );
f6bcfd97
BP
1708 void DisableDragRowSize();
1709 bool CanDragRowSize();
dd9f7fea 1710 void EnableDragColSize( bool enable = True );
f6bcfd97
BP
1711 void DisableDragColSize();
1712 bool CanDragColSize();
dd9f7fea 1713 void EnableDragGridSize(bool enable = True);
f6bcfd97
BP
1714 void DisableDragGridSize();
1715 bool CanDragGridSize();
1716
1717 // this sets the specified attribute for all cells in this row/col
fd512ba2 1718 void SetAttr(int row, int col, wxGridCellAttr *attr);
f6bcfd97
BP
1719 void SetRowAttr(int row, wxGridCellAttr *attr);
1720 void SetColAttr(int col, wxGridCellAttr *attr);
1721
1722 // shortcuts for setting the column parameters
1723
1724 // set the format for the data in the column: default is string
1725 void SetColFormatBool(int col);
1726 void SetColFormatNumber(int col);
1727 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1728 void SetColFormatCustom(int col, const wxString& typeName);
1729
dd9f7fea 1730 void EnableGridLines( bool enable = True );
f6bcfd97
BP
1731 bool GridLinesEnabled();
1732
1733 // ------ row and col formatting
1734 //
1735 int GetDefaultRowSize();
1736 int GetRowSize( int row );
1737 int GetDefaultColSize();
1738 int GetColSize( int col );
1739 wxColour GetDefaultCellBackgroundColour();
1740 wxColour GetCellBackgroundColour( int row, int col );
1741 wxColour GetDefaultCellTextColour();
1742 wxColour GetCellTextColour( int row, int col );
1743 wxFont GetDefaultCellFont();
1744 wxFont GetCellFont( int row, int col );
1fded56b
RD
1745 void GetDefaultCellAlignment( int *OUTPUT, int *OUTPUT );
1746 void GetCellAlignment( int row, int col, int *OUTPUT, int *OUTPUT );
fd512ba2
RD
1747 bool GetDefaultCellOverflow();
1748 bool GetCellOverflow( int row, int col );
1749 void GetCellSize( int row, int col, int *OUTPUT, int *OUTPUT );
f6bcfd97 1750
dd9f7fea 1751 void SetDefaultRowSize( int height, bool resizeExistingRows = False );
f6bcfd97 1752 void SetRowSize( int row, int height );
dd9f7fea 1753 void SetDefaultColSize( int width, bool resizeExistingCols = False );
f6bcfd97
BP
1754
1755 void SetColSize( int col, int width );
1756
1757 // automatically size the column or row to fit to its contents, if
dd9f7fea 1758 // setAsMin is True, this optimal width will also be set as minimal width
f6bcfd97 1759 // for this column
dd9f7fea
RD
1760 void AutoSizeColumn( int col, bool setAsMin = True );
1761 void AutoSizeRow( int row, bool setAsMin = True );
f6bcfd97
BP
1762
1763
1764 // auto size all columns (very ineffective for big grids!)
dd9f7fea
RD
1765 void AutoSizeColumns( bool setAsMin = True );
1766 void AutoSizeRows( bool setAsMin = True );
f6bcfd97
BP
1767
1768 // auto size the grid, that is make the columns/rows of the "right" size
1769 // and also set the grid size to just fit its contents
1770 void AutoSize();
1771
1e4a197e
RD
1772 // autosize row height depending on label text
1773 void AutoSizeRowLabelSize( int row );
1774
1775 // autosize column width depending on label text
1776 void AutoSizeColLabelSize( int col );
1777
1778
f6bcfd97
BP
1779 // column won't be resized to be lesser width - this must be called during
1780 // the grid creation because it won't resize the column if it's already
1781 // narrower than the minimal width
1782 void SetColMinimalWidth( int col, int width );
1783 void SetRowMinimalHeight( int row, int width );
1784
1fded56b
RD
1785 void SetColMinimalAcceptableWidth( int width );
1786 void SetRowMinimalAcceptableHeight( int width );
1787 int GetColMinimalAcceptableWidth() const;
1788 int GetRowMinimalAcceptableHeight() const;
1789
f6bcfd97
BP
1790 void SetDefaultCellBackgroundColour( const wxColour& );
1791 void SetCellBackgroundColour( int row, int col, const wxColour& );
1792 void SetDefaultCellTextColour( const wxColour& );
1793
1794 void SetCellTextColour( int row, int col, const wxColour& );
1795 void SetDefaultCellFont( const wxFont& );
1796 void SetCellFont( int row, int col, const wxFont& );
1797 void SetDefaultCellAlignment( int horiz, int vert );
1798 void SetCellAlignment( int row, int col, int horiz, int vert );
fd512ba2
RD
1799 void SetDefaultCellOverflow( bool allow );
1800 void SetCellOverflow( int row, int col, bool allow );
1801 void SetCellSize( int row, int col, int num_rows, int num_cols );
f6bcfd97
BP
1802
1803 // takes ownership of the pointer
1804 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1805 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1806 wxGridCellRenderer *GetDefaultRenderer() const;
1807 wxGridCellRenderer* GetCellRenderer(int row, int col);
1808
1809 // takes ownership of the pointer
1810 void SetDefaultEditor(wxGridCellEditor *editor);
1811 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1812 wxGridCellEditor *GetDefaultEditor() const;
1813 wxGridCellEditor* GetCellEditor(int row, int col);
1814
1815
1816
1817 // ------ cell value accessors
1818 //
1819 wxString GetCellValue( int row, int col );
1820 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1821
1822 void SetCellValue( int row, int col, const wxString& s );
1823 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1824
dd9f7fea 1825 // returns True if the cell can't be edited
f6bcfd97
BP
1826 bool IsReadOnly(int row, int col) const;
1827
1828 // make the cell editable/readonly
dd9f7fea 1829 void SetReadOnly(int row, int col, bool isReadOnly = True);
f6bcfd97
BP
1830
1831 // ------ selections of blocks of cells
1832 //
dd9f7fea
RD
1833 void SelectRow( int row, bool addToSelected = False );
1834 void SelectCol( int col, bool addToSelected = False );
f6bcfd97 1835
c368d904 1836 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
dd9f7fea 1837 bool addToSelected = False );
f6bcfd97
BP
1838 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1839 // TODO: ??? const wxGridCellCoords& bottomRight )
1840
1841 void SelectAll();
1842 bool IsSelection();
1843 void ClearSelection();
1844 bool IsInSelection( int row, int col );
1845 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1846
1e4a197e
RD
1847 const wxGridCellCoordsArray GetSelectedCells() const;
1848 const wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
1849 const wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
1850 const wxArrayInt GetSelectedRows() const;
1851 const wxArrayInt GetSelectedCols() const;
1852
1853 void DeselectRow( int row );
1854 void DeselectCol( int col );
1855 void DeselectCell( int row, int col );
1e6796a0 1856
f6bcfd97
BP
1857
1858 // This function returns the rectangle that encloses the block of cells
1859 // limited by TopLeft and BottomRight cell in device coords and clipped
1860 // to the client size of the grid window.
1861 //
1862 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1863 const wxGridCellCoords & bottomRight );
1864
1865
1866 // Access or update the selection fore/back colours
1867 wxColour GetSelectionBackground() const;
1868 wxColour GetSelectionForeground() const;
1869
1870 void SetSelectionBackground(const wxColour& c);
1871 void SetSelectionForeground(const wxColour& c);
1872
1873
1874 // Methods for a registry for mapping data types to Renderers/Editors
1875 void RegisterDataType(const wxString& typeName,
1876 wxGridCellRenderer* renderer,
1877 wxGridCellEditor* editor);
1878 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1879 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1880 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1881 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1882 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1883
1884 // grid may occupy more space than needed for its rows/columns, this
1885 // function allows to set how big this extra space is
1886 void SetMargins(int extraWidth, int extraHeight);
9416aa89
RD
1887
1888
1889 // Accessors for component windows
1890 wxWindow* GetGridWindow();
1891 wxWindow* GetGridRowLabelWindow();
1892 wxWindow* GetGridColLabelWindow();
1893 wxWindow* GetGridCornerLabelWindow();
1894
1895
f6bcfd97
BP
1896};
1897
1898
1899//---------------------------------------------------------------------------
1900//---------------------------------------------------------------------------
1901// Grid events and stuff
1902
1903
1904
1905class wxGridEvent : public wxNotifyEvent
1906{
1907public:
1908 wxGridEvent(int id, wxEventType type, wxGrid* obj,
dd9f7fea
RD
1909 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = True,
1910 bool control=False, bool shift=False, bool alt=False, bool meta=False);
f6bcfd97
BP
1911
1912 virtual int GetRow();
1913 virtual int GetCol();
1914 wxPoint GetPosition();
1915 bool Selecting();
1916 bool ControlDown();
1917 bool MetaDown();
1918 bool ShiftDown();
1919 bool AltDown();
1920
1921};
1922
1923
1924class wxGridSizeEvent : public wxNotifyEvent
1925{
1926public:
1927 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
1928 int rowOrCol=-1, int x=-1, int y=-1,
dd9f7fea 1929 bool control=False, bool shift=False, bool alt=False, bool meta=False);
f6bcfd97
BP
1930
1931 int GetRowOrCol();
1932 wxPoint GetPosition();
1933 bool ControlDown();
1934 bool MetaDown();
1935 bool ShiftDown();
1936 bool AltDown();
1937
1938};
1939
1940
1941class wxGridRangeSelectEvent : public wxNotifyEvent
1942{
1943public:
1944 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
1945 const wxGridCellCoords& topLeft,
1946 const wxGridCellCoords& bottomRight,
dd9f7fea
RD
1947 bool sel = True,
1948 bool control=False, bool shift=False,
1949 bool alt=False, bool meta=False);
f6bcfd97
BP
1950
1951 wxGridCellCoords GetTopLeftCoords();
1952 wxGridCellCoords GetBottomRightCoords();
1953 int GetTopRow();
1954 int GetBottomRow();
1955 int GetLeftCol();
1956 int GetRightCol();
1957 bool Selecting();
1958 bool ControlDown();
1959 bool MetaDown();
1960 bool ShiftDown();
1961 bool AltDown();
1962};
1963
bf7945ce
RD
1964
1965class wxGridEditorCreatedEvent : public wxCommandEvent {
1966public:
1967 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
1968 int row, int col, wxControl* ctrl);
1969
1970 int GetRow();
1971 int GetCol();
1972 wxControl* GetControl();
1973 void SetRow(int row);
1974 void SetCol(int col);
1975 void SetControl(wxControl* ctrl);
1976};
1977
1978
1979
d14a1e28
RD
1980%constant wxEventType wxEVT_GRID_CELL_LEFT_CLICK;
1981%constant wxEventType wxEVT_GRID_CELL_RIGHT_CLICK;
1982%constant wxEventType wxEVT_GRID_CELL_LEFT_DCLICK;
1983%constant wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK;
1984%constant wxEventType wxEVT_GRID_LABEL_LEFT_CLICK;
1985%constant wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK;
1986%constant wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK;
1987%constant wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK;
1988%constant wxEventType wxEVT_GRID_ROW_SIZE;
1989%constant wxEventType wxEVT_GRID_COL_SIZE;
1990%constant wxEventType wxEVT_GRID_RANGE_SELECT;
1991%constant wxEventType wxEVT_GRID_CELL_CHANGE;
1992%constant wxEventType wxEVT_GRID_SELECT_CELL;
1993%constant wxEventType wxEVT_GRID_EDITOR_SHOWN;
1994%constant wxEventType wxEVT_GRID_EDITOR_HIDDEN;
1995%constant wxEventType wxEVT_GRID_EDITOR_CREATED;
1996
1997
1998
1999%pythoncode {
2000EVT_GRID_CELL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_CLICK )
2001EVT_GRID_CELL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_CLICK )
2002EVT_GRID_CELL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_DCLICK )
2003EVT_GRID_CELL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_DCLICK )
2004EVT_GRID_LABEL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_CLICK )
2005EVT_GRID_LABEL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_CLICK )
2006EVT_GRID_LABEL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_DCLICK )
2007EVT_GRID_LABEL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_DCLICK )
2008EVT_GRID_ROW_SIZE = wx.PyEventBinder( wxEVT_GRID_ROW_SIZE )
2009EVT_GRID_COL_SIZE = wx.PyEventBinder( wxEVT_GRID_COL_SIZE )
2010EVT_GRID_RANGE_SELECT = wx.PyEventBinder( wxEVT_GRID_RANGE_SELECT )
2011EVT_GRID_CELL_CHANGE = wx.PyEventBinder( wxEVT_GRID_CELL_CHANGE )
2012EVT_GRID_SELECT_CELL = wx.PyEventBinder( wxEVT_GRID_SELECT_CELL )
2013EVT_GRID_EDITOR_SHOWN = wx.PyEventBinder( wxEVT_GRID_EDITOR_SHOWN )
2014EVT_GRID_EDITOR_HIDDEN = wx.PyEventBinder( wxEVT_GRID_EDITOR_HIDDEN )
2015EVT_GRID_EDITOR_CREATED = wx.PyEventBinder( wxEVT_GRID_EDITOR_CREATED )
2016}
f6bcfd97
BP
2017
2018//---------------------------------------------------------------------------
2019
e508a2b6 2020%init %{
e508a2b6
RD
2021%}
2022
2023//---------------------------------------------------------------------------
f6bcfd97
BP
2024//---------------------------------------------------------------------------
2025