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