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