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