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