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