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