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