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