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