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