]>
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 | %{ | |
9416aa89 RD |
46 | #define PYCALLBACK_GCA_INTINTKIND(PCLASS, CBNAME) \ |
47 | wxGridCellAttr* CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \ | |
48 | wxGridCellAttr* rval = NULL; \ | |
49 | bool doSave = wxPyRestoreThread(); \ | |
50 | if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \ | |
51 | PyObject* ro; \ | |
52 | wxGridCellAttr* ptr; \ | |
53 | ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iii)", a, b, c)); \ | |
54 | if (ro) { \ | |
f6bcfd97 | 55 | if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellAttr_p")) \ |
9416aa89 RD |
56 | rval = ptr; \ |
57 | Py_DECREF(ro); \ | |
58 | } \ | |
59 | } \ | |
60 | else \ | |
61 | rval = PCLASS::CBNAME(a, b, c); \ | |
62 | wxPySaveThread(doSave); \ | |
63 | return rval; \ | |
64 | } \ | |
65 | wxGridCellAttr *base_##CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \ | |
66 | return PCLASS::CBNAME(a, b, c); \ | |
f6bcfd97 BP |
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: | |
9416aa89 RD |
812 | enum wxAttrKind |
813 | { | |
814 | Any, | |
815 | Default, | |
816 | Cell, | |
817 | Row, | |
818 | Col, | |
819 | Merged | |
820 | }; | |
821 | ||
f6bcfd97 BP |
822 | wxGridCellAttr(); |
823 | ||
824 | wxGridCellAttr *Clone() const; | |
9416aa89 | 825 | void MergeWith(wxGridCellAttr *mergefrom); |
f6bcfd97 BP |
826 | void IncRef(); |
827 | void DecRef(); | |
828 | void SetTextColour(const wxColour& colText); | |
829 | void SetBackgroundColour(const wxColour& colBack); | |
830 | void SetFont(const wxFont& font); | |
831 | void SetAlignment(int hAlign, int vAlign); | |
832 | void SetReadOnly(bool isReadOnly = TRUE); | |
833 | ||
834 | void SetRenderer(wxGridCellRenderer *renderer); | |
835 | void SetEditor(wxGridCellEditor* editor); | |
9416aa89 | 836 | void SetKind(wxAttrKind kind); |
f6bcfd97 BP |
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; | |
9416aa89 | 844 | bool HasReadWriteMode() const; |
f6bcfd97 BP |
845 | |
846 | const wxColour& GetTextColour() const; | |
847 | const wxColour& GetBackgroundColour() const; | |
848 | const wxFont& GetFont() const; | |
849 | void GetAlignment(int *OUTPUT, int *OUTPUT) const; | |
850 | wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const; | |
851 | wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const; | |
852 | ||
853 | bool IsReadOnly() const; | |
854 | void SetDefAttr(wxGridCellAttr* defAttr); | |
855 | }; | |
856 | ||
857 | //--------------------------------------------------------------------------- | |
858 | ||
859 | class wxGridCellAttrProvider | |
860 | { | |
861 | public: | |
862 | wxGridCellAttrProvider(); | |
863 | // ???? virtual ~wxGridCellAttrProvider(); | |
864 | ||
9416aa89 RD |
865 | wxGridCellAttr *GetAttr(int row, int col, |
866 | wxGridCellAttr::wxAttrKind kind) const; | |
f6bcfd97 BP |
867 | void SetAttr(wxGridCellAttr *attr, int row, int col); |
868 | void SetRowAttr(wxGridCellAttr *attr, int row); | |
869 | void SetColAttr(wxGridCellAttr *attr, int col); | |
870 | ||
871 | void UpdateAttrRows( size_t pos, int numRows ); | |
872 | void UpdateAttrCols( size_t pos, int numCols ); | |
873 | ||
874 | }; | |
875 | ||
876 | ||
877 | // A Python-aware version | |
878 | %{ | |
879 | class wxPyGridCellAttrProvider : public wxGridCellAttrProvider | |
880 | { | |
881 | public: | |
882 | wxPyGridCellAttrProvider() : wxGridCellAttrProvider() {}; | |
883 | ||
9416aa89 | 884 | PYCALLBACK_GCA_INTINTKIND(wxGridCellAttrProvider, GetAttr); |
f6bcfd97 BP |
885 | PYCALLBACK__GCAINTINT(wxGridCellAttrProvider, SetAttr); |
886 | PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetRowAttr); | |
887 | PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetColAttr); | |
888 | ||
889 | PYPRIVATE; | |
890 | }; | |
891 | %} | |
892 | ||
893 | ||
894 | // The python-aware version get's SWIGified | |
895 | class wxPyGridCellAttrProvider : public wxGridCellAttrProvider | |
896 | { | |
897 | public: | |
898 | wxPyGridCellAttrProvider(); | |
899 | void _setSelf(PyObject* self, PyObject* _class); | |
900 | %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyGridCellAttrProvider)" | |
901 | ||
9416aa89 RD |
902 | wxGridCellAttr *base_GetAttr(int row, int col, |
903 | wxGridCellAttr::wxAttrKind kind); | |
f6bcfd97 BP |
904 | void base_SetAttr(wxGridCellAttr *attr, int row, int col); |
905 | void base_SetRowAttr(wxGridCellAttr *attr, int row); | |
906 | void base_SetColAttr(wxGridCellAttr *attr, int col); | |
907 | }; | |
908 | ||
909 | ||
910 | //--------------------------------------------------------------------------- | |
911 | // Grid Table Base class and Python aware version | |
912 | ||
913 | ||
914 | ||
9416aa89 | 915 | class wxGridTableBase : public wxObject |
f6bcfd97 BP |
916 | { |
917 | public: | |
918 | // wxGridTableBase(); This is an ABC | |
919 | //~wxGridTableBase(); | |
920 | ||
921 | void SetAttrProvider(wxGridCellAttrProvider *attrProvider); | |
922 | wxGridCellAttrProvider *GetAttrProvider() const; | |
923 | void SetView( wxGrid *grid ); | |
924 | wxGrid * GetView() const; | |
925 | ||
926 | ||
927 | // pure virtuals | |
928 | virtual int GetNumberRows() = 0; | |
929 | virtual int GetNumberCols() = 0; | |
930 | virtual bool IsEmptyCell( int row, int col ) = 0; | |
931 | virtual wxString GetValue( int row, int col ) = 0; | |
932 | virtual void SetValue( int row, int col, const wxString& value ) = 0; | |
933 | ||
934 | // virtuals overridable in wxPyGridTableBase | |
935 | virtual wxString GetTypeName( int row, int col ); | |
936 | virtual bool CanGetValueAs( int row, int col, const wxString& typeName ); | |
937 | virtual bool CanSetValueAs( int row, int col, const wxString& typeName ); | |
938 | virtual long GetValueAsLong( int row, int col ); | |
939 | virtual double GetValueAsDouble( int row, int col ); | |
940 | virtual bool GetValueAsBool( int row, int col ); | |
941 | virtual void SetValueAsLong( int row, int col, long value ); | |
942 | virtual void SetValueAsDouble( int row, int col, double value ); | |
943 | virtual void SetValueAsBool( int row, int col, bool value ); | |
944 | ||
945 | //virtual void* GetValueAsCustom( int row, int col, const wxString& typeName ); | |
946 | //virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value ); | |
947 | ||
948 | ||
949 | virtual void Clear(); | |
950 | virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 ); | |
951 | virtual bool AppendRows( size_t numRows = 1 ); | |
952 | virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 ); | |
953 | virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 ); | |
954 | virtual bool AppendCols( size_t numCols = 1 ); | |
955 | virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 ); | |
956 | ||
957 | virtual wxString GetRowLabelValue( int row ); | |
958 | virtual wxString GetColLabelValue( int col ); | |
959 | virtual void SetRowLabelValue( int row, const wxString& value ); | |
960 | virtual void SetColLabelValue( int col, const wxString& value ); | |
961 | ||
962 | virtual bool CanHaveAttributes(); | |
963 | ||
9416aa89 RD |
964 | virtual wxGridCellAttr *GetAttr( int row, int col, |
965 | wxGridCellAttr::wxAttrKind kind); | |
f6bcfd97 BP |
966 | virtual void SetAttr(wxGridCellAttr* attr, int row, int col); |
967 | virtual void SetRowAttr(wxGridCellAttr *attr, int row); | |
968 | virtual void SetColAttr(wxGridCellAttr *attr, int col); | |
969 | ||
970 | }; | |
971 | ||
972 | ||
973 | ||
974 | // Python-aware version | |
975 | %{ | |
976 | class wxPyGridTableBase : public wxGridTableBase | |
977 | { | |
978 | public: | |
979 | wxPyGridTableBase() : wxGridTableBase() {} | |
980 | ||
981 | PYCALLBACK_INT__pure(GetNumberRows); | |
982 | PYCALLBACK_INT__pure(GetNumberCols); | |
983 | PYCALLBACK_BOOL_INTINT_pure(IsEmptyCell); | |
984 | PYCALLBACK_STRING_INTINT(wxGridTableBase, GetTypeName); | |
985 | PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanGetValueAs); | |
986 | PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanSetValueAs); | |
987 | PYCALLBACK__(wxGridTableBase, Clear); | |
988 | PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertRows); | |
989 | PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteRows); | |
990 | PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertCols); | |
991 | PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteCols); | |
992 | PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendRows); | |
993 | PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendCols); | |
994 | PYCALLBACK_STRING_INT(wxGridTableBase, GetRowLabelValue); | |
995 | PYCALLBACK_STRING_INT(wxGridTableBase, GetColLabelValue); | |
996 | PYCALLBACK__INTSTRING(wxGridTableBase, SetRowLabelValue); | |
997 | PYCALLBACK__INTSTRING(wxGridTableBase, SetColLabelValue); | |
998 | PYCALLBACK_BOOL_(wxGridTableBase, CanHaveAttributes); | |
9416aa89 | 999 | PYCALLBACK_GCA_INTINTKIND(wxGridTableBase, GetAttr); |
f6bcfd97 BP |
1000 | PYCALLBACK__GCAINTINT(wxGridTableBase, SetAttr); |
1001 | PYCALLBACK__GCAINT(wxGridTableBase, SetRowAttr); | |
1002 | PYCALLBACK__GCAINT(wxGridTableBase, SetColAttr); | |
1003 | ||
1004 | ||
f6bcfd97 BP |
1005 | wxString GetValue(int row, int col) { |
1006 | bool doSave = wxPyRestoreThread(); | |
1007 | wxString rval; | |
1e7ecb7b | 1008 | if (wxPyCBH_findCallback(m_myInst, "GetValue")) { |
f6bcfd97 | 1009 | PyObject* ro; |
1e7ecb7b | 1010 | ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",row,col)); |
f6bcfd97 | 1011 | if (ro) { |
de20db99 RD |
1012 | PyObject* str = PyObject_Str(ro); |
1013 | rval = PyString_AsString(str); | |
f6bcfd97 | 1014 | Py_DECREF(ro); |
de20db99 | 1015 | Py_DECREF(str); |
f6bcfd97 BP |
1016 | } |
1017 | } | |
1018 | wxPySaveThread(doSave); | |
1019 | return rval; | |
1020 | } | |
1021 | ||
1022 | void SetValue(int row, int col, const wxString& val) { | |
1023 | bool doSave = wxPyRestoreThread(); | |
1e7ecb7b RD |
1024 | if (wxPyCBH_findCallback(m_myInst, "SetValue")) |
1025 | wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iis)",row,col,val.c_str())); | |
f6bcfd97 BP |
1026 | wxPySaveThread(doSave); |
1027 | } | |
1028 | ||
1029 | ||
1030 | // Map the Get/Set methods for the standard non-string types to | |
1031 | // the GetValue and SetValue python methods. | |
1032 | long GetValueAsLong( int row, int col ) { | |
1033 | long rval = 0; | |
1034 | bool doSave = wxPyRestoreThread(); | |
1e7ecb7b | 1035 | if (wxPyCBH_findCallback(m_myInst, "GetValue")) { |
f6bcfd97 BP |
1036 | PyObject* ro; |
1037 | PyObject* num; | |
1e7ecb7b | 1038 | ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col)); |
f6bcfd97 BP |
1039 | if (ro && PyNumber_Check(ro)) { |
1040 | num = PyNumber_Int(ro); | |
1041 | if (num) { | |
1042 | rval = PyInt_AsLong(num); | |
1043 | Py_DECREF(num); | |
1044 | } | |
1045 | Py_DECREF(ro); | |
1046 | } | |
1047 | } | |
1048 | wxPySaveThread(doSave); | |
1049 | return rval; | |
1050 | } | |
1051 | ||
1052 | double GetValueAsDouble( int row, int col ) { | |
1053 | double rval = 0.0; | |
1054 | bool doSave = wxPyRestoreThread(); | |
1e7ecb7b | 1055 | if (wxPyCBH_findCallback(m_myInst, "GetValue")) { |
f6bcfd97 BP |
1056 | PyObject* ro; |
1057 | PyObject* num; | |
1e7ecb7b | 1058 | ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col)); |
f6bcfd97 BP |
1059 | if (ro && PyNumber_Check(ro)) { |
1060 | num = PyNumber_Float(ro); | |
1061 | if (num) { | |
1062 | rval = PyFloat_AsDouble(num); | |
1063 | Py_DECREF(num); | |
1064 | } | |
1065 | Py_DECREF(ro); | |
1066 | } | |
1067 | } | |
1068 | wxPySaveThread(doSave); | |
1069 | return rval; | |
1070 | } | |
1071 | ||
1072 | bool GetValueAsBool( int row, int col ) { | |
1073 | return (bool)GetValueAsLong(row, col); | |
1074 | } | |
1075 | ||
1076 | void SetValueAsLong( int row, int col, long value ) { | |
1077 | bool doSave = wxPyRestoreThread(); | |
1e7ecb7b RD |
1078 | if (wxPyCBH_findCallback(m_myInst, "SetValue")) { |
1079 | wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", row, col, value)); | |
f6bcfd97 BP |
1080 | } |
1081 | wxPySaveThread(doSave); | |
1082 | } | |
1083 | ||
1084 | void SetValueAsDouble( int row, int col, double value ) { | |
1085 | bool doSave = wxPyRestoreThread(); | |
1e7ecb7b RD |
1086 | if (wxPyCBH_findCallback(m_myInst, "SetValue")) { |
1087 | wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iid)", row, col, value)); | |
f6bcfd97 BP |
1088 | } |
1089 | wxPySaveThread(doSave); | |
1090 | } | |
1091 | ||
1092 | void SetValueAsBool( int row, int col, bool value ) { | |
1093 | SetValueAsLong( row, col, (long)value ); | |
1094 | } | |
1095 | ||
1096 | ||
1097 | PYPRIVATE; | |
1098 | }; | |
1099 | %} | |
1100 | ||
1101 | ||
1102 | // The python-aware version get's SWIGified | |
1103 | class wxPyGridTableBase : public wxGridTableBase | |
1104 | { | |
1105 | public: | |
1106 | wxPyGridTableBase(); | |
1107 | void _setSelf(PyObject* self, PyObject* _class); | |
1108 | %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyGridTableBase)" | |
1109 | ||
1110 | %addmethods { void Destroy() { delete self; } } | |
1111 | ||
1112 | wxString base_GetTypeName( int row, int col ); | |
1113 | bool base_CanGetValueAs( int row, int col, const wxString& typeName ); | |
1114 | bool base_CanSetValueAs( int row, int col, const wxString& typeName ); | |
1115 | void base_Clear(); | |
1116 | bool base_InsertRows( size_t pos = 0, size_t numRows = 1 ); | |
1117 | bool base_AppendRows( size_t numRows = 1 ); | |
1118 | bool base_DeleteRows( size_t pos = 0, size_t numRows = 1 ); | |
1119 | bool base_InsertCols( size_t pos = 0, size_t numCols = 1 ); | |
1120 | bool base_AppendCols( size_t numCols = 1 ); | |
1121 | bool base_DeleteCols( size_t pos = 0, size_t numCols = 1 ); | |
1122 | wxString base_GetRowLabelValue( int row ); | |
1123 | wxString base_GetColLabelValue( int col ); | |
1124 | void base_SetRowLabelValue( int row, const wxString& value ); | |
1125 | void base_SetColLabelValue( int col, const wxString& value ); | |
1126 | bool base_CanHaveAttributes(); | |
9416aa89 RD |
1127 | wxGridCellAttr *base_GetAttr( int row, int col, |
1128 | wxGridCellAttr::wxAttrKind kind ); | |
f6bcfd97 BP |
1129 | void base_SetAttr(wxGridCellAttr* attr, int row, int col); |
1130 | void base_SetRowAttr(wxGridCellAttr *attr, int row); | |
1131 | void base_SetColAttr(wxGridCellAttr *attr, int col); | |
1132 | }; | |
1133 | ||
1134 | ||
1135 | //--------------------------------------------------------------------------- | |
1136 | // Predefined Tables | |
1137 | ||
1138 | class wxGridStringTable : public wxGridTableBase | |
1139 | { | |
1140 | public: | |
1141 | wxGridStringTable( int numRows=0, int numCols=0 ); | |
1142 | }; | |
1143 | ||
1144 | //--------------------------------------------------------------------------- | |
1145 | // The Table can pass messages to the grid to tell it to update itself if | |
1146 | // something has changed. | |
1147 | ||
1148 | enum wxGridTableRequest | |
1149 | { | |
1150 | wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000, | |
1151 | wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES, | |
1152 | wxGRIDTABLE_NOTIFY_ROWS_INSERTED, | |
1153 | wxGRIDTABLE_NOTIFY_ROWS_APPENDED, | |
1154 | wxGRIDTABLE_NOTIFY_ROWS_DELETED, | |
1155 | wxGRIDTABLE_NOTIFY_COLS_INSERTED, | |
1156 | wxGRIDTABLE_NOTIFY_COLS_APPENDED, | |
1157 | wxGRIDTABLE_NOTIFY_COLS_DELETED | |
1158 | }; | |
1159 | ||
1160 | ||
1161 | class wxGridTableMessage | |
1162 | { | |
1163 | public: | |
1164 | wxGridTableMessage( wxGridTableBase *table, int id, | |
1165 | int comInt1 = -1, | |
1166 | int comInt2 = -1 ); | |
1167 | ~wxGridTableMessage(); | |
1168 | ||
1169 | void SetTableObject( wxGridTableBase *table ); | |
1170 | wxGridTableBase * GetTableObject() const; | |
1171 | void SetId( int id ); | |
1172 | int GetId(); | |
1173 | void SetCommandInt( int comInt1 ); | |
1174 | int GetCommandInt(); | |
1175 | void SetCommandInt2( int comInt2 ); | |
1176 | int GetCommandInt2(); | |
1177 | }; | |
1178 | ||
1179 | ||
1180 | //--------------------------------------------------------------------------- | |
1181 | ||
1182 | class wxGridCellCoords | |
1183 | { | |
1184 | public: | |
1185 | wxGridCellCoords( int r=-1, int c=-1 ); | |
1186 | ~wxGridCellCoords(); | |
1187 | ||
1188 | int GetRow() const { return m_row; } | |
1189 | void SetRow( int n ) { m_row = n; } | |
1190 | int GetCol() const { return m_col; } | |
1191 | void SetCol( int n ) { m_col = n; } | |
1192 | void Set( int row, int col ) { m_row = row; m_col = col; } | |
1193 | ||
1194 | %addmethods { | |
1195 | PyObject* asTuple() { | |
1196 | PyObject* tup = PyTuple_New(2); | |
1197 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow())); | |
1198 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol())); | |
1199 | return tup; | |
1200 | } | |
1201 | ||
1202 | int __cmp__( const wxGridCellCoords& other ) { | |
1203 | return *self != other; | |
1204 | } | |
1205 | } | |
1206 | %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())" | |
1207 | %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())" | |
1208 | }; | |
1209 | ||
1210 | // Typemap to allow conversion of sequence objects to wxGridCellCoords... | |
1211 | %typemap(python,in) wxGridCellCoords& (wxGridCellCoords temp) { | |
1212 | $target = &temp; | |
1213 | if (! wxGridCellCoords_helper($source, &$target)) | |
1214 | return NULL; | |
1215 | } | |
1216 | ||
1217 | // ...and here is the associated helper. | |
1218 | %{ | |
1219 | bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) { | |
1220 | ||
1221 | // If source is an object instance then it may already be the right type | |
1222 | if (PyInstance_Check(source)) { | |
1223 | wxGridCellCoords* ptr; | |
1224 | if (SWIG_GetPtrObj(source, (void **)&ptr, "_wxGridCellCoords_p")) | |
1225 | goto error; | |
1226 | *obj = ptr; | |
1227 | return TRUE; | |
1228 | } | |
1229 | // otherwise a 2-tuple of integers is expected | |
1230 | else if (PySequence_Check(source) && PyObject_Length(source) == 2) { | |
1231 | PyObject* o1 = PySequence_GetItem(source, 0); | |
1232 | PyObject* o2 = PySequence_GetItem(source, 1); | |
1233 | **obj = wxGridCellCoords(PyInt_AsLong(o1), PyInt_AsLong(o2)); | |
1234 | return TRUE; | |
1235 | } | |
1236 | ||
1237 | error: | |
1238 | PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of integers or a wxGridCellCoords object."); | |
1239 | return FALSE; | |
1240 | } | |
1241 | %} | |
1242 | ||
1243 | //--------------------------------------------------------------------------- | |
1244 | //--------------------------------------------------------------------------- | |
1245 | // The grid itself | |
1246 | ||
1247 | ||
1248 | // Fool SWIG into treating this enum as an int | |
1249 | typedef int WXGRIDSELECTIONMODES; | |
1250 | ||
1251 | // but let the C++ code know what it really is. | |
1252 | %{ | |
1253 | typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES; | |
1254 | %} | |
1255 | ||
1256 | ||
1257 | ||
1258 | class wxGrid : public wxScrolledWindow | |
1259 | { | |
1260 | public: | |
1261 | wxGrid( wxWindow *parent, | |
1262 | wxWindowID id, | |
1263 | const wxPoint& pos = wxDefaultPosition, | |
1264 | const wxSize& size = wxDefaultSize, | |
1265 | long style = wxWANTS_CHARS, | |
1266 | const char* name = wxPanelNameStr ); | |
1267 | ||
1268 | //~wxGrid(); | |
1269 | ||
1270 | enum wxGridSelectionModes {wxGridSelectCells, | |
1271 | wxGridSelectRows, | |
1272 | wxGridSelectColumns}; | |
1273 | ||
1274 | bool CreateGrid( int numRows, int numCols, | |
1275 | WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells ); | |
1276 | void SetSelectionMode(WXGRIDSELECTIONMODES selmode); | |
1277 | ||
1278 | ||
1279 | // ------ grid dimensions | |
1280 | // | |
1281 | int GetNumberRows(); | |
1282 | int GetNumberCols(); | |
1283 | ||
1284 | ||
1285 | ||
1286 | #ifdef NOTNEEDED // ???? | |
1287 | // ------ display update functions | |
1288 | // | |
1289 | void CalcRowLabelsExposed( wxRegion& reg ); | |
1290 | void CalcColLabelsExposed( wxRegion& reg ); | |
1291 | void CalcCellsExposed( wxRegion& reg ); | |
1292 | ||
1293 | // ------ event handlers | |
1294 | // | |
1295 | void ProcessRowLabelMouseEvent( wxMouseEvent& event ); | |
1296 | void ProcessColLabelMouseEvent( wxMouseEvent& event ); | |
1297 | void ProcessCornerLabelMouseEvent( wxMouseEvent& event ); | |
1298 | void ProcessGridCellMouseEvent( wxMouseEvent& event ); | |
1299 | void DoEndDragResizeRow(); | |
1300 | void DoEndDragResizeCol(); | |
1301 | #endif | |
1302 | ||
1303 | bool ProcessTableMessage( wxGridTableMessage& ); | |
1304 | ||
1305 | ||
1306 | wxGridTableBase * GetTable() const; | |
1307 | bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE, | |
1308 | WXGRIDSELECTIONMODES selmode = | |
1309 | wxGrid::wxGridSelectCells ); | |
1310 | ||
1311 | void ClearGrid(); | |
1312 | bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE ); | |
1313 | bool AppendRows( int numRows = 1, bool updateLabels=TRUE ); | |
1314 | bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE ); | |
1315 | bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE ); | |
1316 | bool AppendCols( int numCols = 1, bool updateLabels=TRUE ); | |
1317 | bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE ); | |
1318 | ||
1319 | #ifdef NOTNEEDED // ???? | |
1320 | void DrawGridCellArea( wxDC& dc ); | |
1321 | void DrawGridSpace( wxDC& dc ); | |
1322 | void DrawCellBorder( wxDC& dc, const wxGridCellCoords& ); | |
1323 | void DrawAllGridLines( wxDC& dc, const wxRegion & reg ); | |
1324 | void DrawCell( wxDC& dc, const wxGridCellCoords& ); | |
1325 | void DrawHighlight(wxDC& dc); | |
1326 | #endif | |
1327 | ||
1328 | // this function is called when the current cell highlight must be redrawn | |
1329 | // and may be overridden by the user | |
1330 | virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr ); | |
1331 | ||
1332 | #ifdef NOTNEEDED // ???? | |
1333 | void DrawRowLabels( wxDC& dc ); | |
1334 | void DrawRowLabel( wxDC& dc, int row ); | |
1335 | ||
1336 | void DrawColLabels( wxDC& dc ); | |
1337 | void DrawColLabel( wxDC& dc, int col ); | |
1338 | #endif | |
1339 | ||
1340 | // ------ Cell text drawing functions | |
1341 | // | |
1342 | void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&, | |
1343 | int horizontalAlignment = wxLEFT, | |
1344 | int verticalAlignment = wxTOP ); | |
1345 | ||
1346 | // Split a string containing newline chararcters into an array of | |
1347 | // strings and return the number of lines | |
1348 | // | |
1349 | void StringToLines( const wxString& value, wxArrayString& lines ); | |
1350 | ||
1351 | void GetTextBoxSize( wxDC& dc, | |
1352 | wxArrayString& lines, | |
1353 | long *OUTPUT, long *OUTPUT ); | |
1354 | ||
1355 | ||
1356 | // ------ | |
1357 | // Code that does a lot of grid modification can be enclosed | |
1358 | // between BeginBatch() and EndBatch() calls to avoid screen | |
1359 | // flicker | |
1360 | // | |
1361 | void BeginBatch(); | |
1362 | void EndBatch(); | |
1363 | int GetBatchCount(); | |
edf2f43e | 1364 | void ForceRefresh(); |
f6bcfd97 BP |
1365 | |
1366 | ||
1367 | // ------ edit control functions | |
1368 | // | |
1369 | bool IsEditable() { return m_editable; } | |
1370 | void EnableEditing( bool edit ); | |
1371 | ||
1372 | void EnableCellEditControl( bool enable = TRUE ); | |
1373 | void DisableCellEditControl(); | |
1374 | bool CanEnableCellControl() const; | |
1375 | bool IsCellEditControlEnabled() const; | |
1376 | bool IsCellEditControlShown() const; | |
1377 | ||
1378 | bool IsCurrentCellReadOnly() const; | |
1379 | ||
1380 | void ShowCellEditControl(); | |
1381 | void HideCellEditControl(); | |
1382 | void SaveEditControlValue(); | |
1383 | ||
1384 | ||
1385 | // ------ grid location functions | |
1386 | // Note that all of these functions work with the logical coordinates of | |
1387 | // grid cells and labels so you will need to convert from device | |
1388 | // coordinates for mouse events etc. | |
1389 | // | |
1390 | ||
1391 | //void XYToCell( int x, int y, wxGridCellCoords& ); | |
1392 | %addmethods { | |
1393 | %new wxGridCellCoords* XYToCell(int x, int y) { | |
1394 | wxGridCellCoords rv; | |
1395 | self->XYToCell(x, y, rv); | |
1396 | return new wxGridCellCoords(rv); | |
1397 | } | |
1398 | } | |
1399 | ||
1400 | int YToRow( int y ); | |
1401 | int XToCol( int x ); | |
1402 | ||
1403 | int YToEdgeOfRow( int y ); | |
1404 | int XToEdgeOfCol( int x ); | |
1405 | ||
1406 | wxRect CellToRect( int row, int col ); | |
1407 | // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords ); | |
1408 | ||
1409 | ||
1410 | int GetGridCursorRow(); | |
1411 | int GetGridCursorCol(); | |
1412 | ||
1413 | // check to see if a cell is either wholly visible (the default arg) or | |
1414 | // at least partially visible in the grid window | |
1415 | // | |
1416 | bool IsVisible( int row, int col, bool wholeCellVisible = TRUE ); | |
1417 | // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE ); | |
1418 | void MakeCellVisible( int row, int col ); | |
1419 | // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords ); | |
1420 | ||
1421 | ||
1422 | // ------ grid cursor movement functions | |
1423 | // | |
1424 | void SetGridCursor( int row, int col ); | |
1425 | bool MoveCursorUp( bool expandSelection ); | |
1426 | bool MoveCursorDown( bool expandSelection ); | |
1427 | bool MoveCursorLeft( bool expandSelection ); | |
1428 | bool MoveCursorRight( bool expandSelection ); | |
1429 | bool MovePageDown(); | |
1430 | bool MovePageUp(); | |
1431 | bool MoveCursorUpBlock( bool expandSelection ); | |
1432 | bool MoveCursorDownBlock( bool expandSelection ); | |
1433 | bool MoveCursorLeftBlock( bool expandSelection ); | |
1434 | bool MoveCursorRightBlock( bool expandSelection ); | |
1435 | ||
1436 | ||
1437 | // ------ label and gridline formatting | |
1438 | // | |
1439 | int GetDefaultRowLabelSize(); | |
1440 | int GetRowLabelSize(); | |
1441 | int GetDefaultColLabelSize(); | |
1442 | int GetColLabelSize(); | |
1443 | wxColour GetLabelBackgroundColour(); | |
1444 | wxColour GetLabelTextColour(); | |
1445 | wxFont GetLabelFont(); | |
1446 | void GetRowLabelAlignment( int *OUTPUT, int *OUTPUT ); | |
1447 | void GetColLabelAlignment( int *OUTPUT, int *OUTPUT ); | |
1448 | wxString GetRowLabelValue( int row ); | |
1449 | wxString GetColLabelValue( int col ); | |
1450 | wxColour GetGridLineColour(); | |
1451 | wxColour GetCellHighlightColour(); | |
9416aa89 RD |
1452 | int GetCellHighlightPenWidth(); |
1453 | int GetCellHighlightROPenWidth(); | |
f6bcfd97 BP |
1454 | |
1455 | void SetRowLabelSize( int width ); | |
1456 | void SetColLabelSize( int height ); | |
1457 | void SetLabelBackgroundColour( const wxColour& ); | |
1458 | void SetLabelTextColour( const wxColour& ); | |
1459 | void SetLabelFont( const wxFont& ); | |
1460 | void SetRowLabelAlignment( int horiz, int vert ); | |
1461 | void SetColLabelAlignment( int horiz, int vert ); | |
1462 | void SetRowLabelValue( int row, const wxString& ); | |
1463 | void SetColLabelValue( int col, const wxString& ); | |
1464 | void SetGridLineColour( const wxColour& ); | |
1465 | void SetCellHighlightColour( const wxColour& ); | |
9416aa89 RD |
1466 | void SetCellHighlightPenWidth(int width); |
1467 | void SetCellHighlightROPenWidth(int width); | |
f6bcfd97 BP |
1468 | |
1469 | void EnableDragRowSize( bool enable = TRUE ); | |
1470 | void DisableDragRowSize(); | |
1471 | bool CanDragRowSize(); | |
1472 | void EnableDragColSize( bool enable = TRUE ); | |
1473 | void DisableDragColSize(); | |
1474 | bool CanDragColSize(); | |
1475 | void EnableDragGridSize(bool enable = TRUE); | |
1476 | void DisableDragGridSize(); | |
1477 | bool CanDragGridSize(); | |
1478 | ||
1479 | // this sets the specified attribute for all cells in this row/col | |
1480 | void SetRowAttr(int row, wxGridCellAttr *attr); | |
1481 | void SetColAttr(int col, wxGridCellAttr *attr); | |
1482 | ||
1483 | // shortcuts for setting the column parameters | |
1484 | ||
1485 | // set the format for the data in the column: default is string | |
1486 | void SetColFormatBool(int col); | |
1487 | void SetColFormatNumber(int col); | |
1488 | void SetColFormatFloat(int col, int width = -1, int precision = -1); | |
1489 | void SetColFormatCustom(int col, const wxString& typeName); | |
1490 | ||
1491 | void EnableGridLines( bool enable = TRUE ); | |
1492 | bool GridLinesEnabled(); | |
1493 | ||
1494 | // ------ row and col formatting | |
1495 | // | |
1496 | int GetDefaultRowSize(); | |
1497 | int GetRowSize( int row ); | |
1498 | int GetDefaultColSize(); | |
1499 | int GetColSize( int col ); | |
1500 | wxColour GetDefaultCellBackgroundColour(); | |
1501 | wxColour GetCellBackgroundColour( int row, int col ); | |
1502 | wxColour GetDefaultCellTextColour(); | |
1503 | wxColour GetCellTextColour( int row, int col ); | |
1504 | wxFont GetDefaultCellFont(); | |
1505 | wxFont GetCellFont( int row, int col ); | |
1506 | void GetDefaultCellAlignment( int *horiz, int *vert ); | |
1507 | void GetCellAlignment( int row, int col, int *horiz, int *vert ); | |
1508 | ||
1509 | void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE ); | |
1510 | void SetRowSize( int row, int height ); | |
1511 | void SetDefaultColSize( int width, bool resizeExistingCols = FALSE ); | |
1512 | ||
1513 | void SetColSize( int col, int width ); | |
1514 | ||
1515 | // automatically size the column or row to fit to its contents, if | |
1516 | // setAsMin is TRUE, this optimal width will also be set as minimal width | |
1517 | // for this column | |
1518 | void AutoSizeColumn( int col, bool setAsMin = TRUE ); | |
1519 | void AutoSizeRow( int row, bool setAsMin = TRUE ); | |
1520 | ||
1521 | ||
1522 | // auto size all columns (very ineffective for big grids!) | |
1523 | void AutoSizeColumns( bool setAsMin = TRUE ); | |
1524 | void AutoSizeRows( bool setAsMin = TRUE ); | |
1525 | ||
1526 | // auto size the grid, that is make the columns/rows of the "right" size | |
1527 | // and also set the grid size to just fit its contents | |
1528 | void AutoSize(); | |
1529 | ||
1530 | // column won't be resized to be lesser width - this must be called during | |
1531 | // the grid creation because it won't resize the column if it's already | |
1532 | // narrower than the minimal width | |
1533 | void SetColMinimalWidth( int col, int width ); | |
1534 | void SetRowMinimalHeight( int row, int width ); | |
1535 | ||
1536 | void SetDefaultCellBackgroundColour( const wxColour& ); | |
1537 | void SetCellBackgroundColour( int row, int col, const wxColour& ); | |
1538 | void SetDefaultCellTextColour( const wxColour& ); | |
1539 | ||
1540 | void SetCellTextColour( int row, int col, const wxColour& ); | |
1541 | void SetDefaultCellFont( const wxFont& ); | |
1542 | void SetCellFont( int row, int col, const wxFont& ); | |
1543 | void SetDefaultCellAlignment( int horiz, int vert ); | |
1544 | void SetCellAlignment( int row, int col, int horiz, int vert ); | |
1545 | ||
1546 | // takes ownership of the pointer | |
1547 | void SetDefaultRenderer(wxGridCellRenderer *renderer); | |
1548 | void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer); | |
1549 | wxGridCellRenderer *GetDefaultRenderer() const; | |
1550 | wxGridCellRenderer* GetCellRenderer(int row, int col); | |
1551 | ||
1552 | // takes ownership of the pointer | |
1553 | void SetDefaultEditor(wxGridCellEditor *editor); | |
1554 | void SetCellEditor(int row, int col, wxGridCellEditor *editor); | |
1555 | wxGridCellEditor *GetDefaultEditor() const; | |
1556 | wxGridCellEditor* GetCellEditor(int row, int col); | |
1557 | ||
1558 | ||
1559 | ||
1560 | // ------ cell value accessors | |
1561 | // | |
1562 | wxString GetCellValue( int row, int col ); | |
1563 | // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords ) | |
1564 | ||
1565 | void SetCellValue( int row, int col, const wxString& s ); | |
1566 | // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s ) | |
1567 | ||
1568 | // returns TRUE if the cell can't be edited | |
1569 | bool IsReadOnly(int row, int col) const; | |
1570 | ||
1571 | // make the cell editable/readonly | |
1572 | void SetReadOnly(int row, int col, bool isReadOnly = TRUE); | |
1573 | ||
1574 | // ------ selections of blocks of cells | |
1575 | // | |
1576 | void SelectRow( int row, bool addToSelected = FALSE ); | |
1577 | void SelectCol( int col, bool addToSelected = FALSE ); | |
1578 | ||
c368d904 RD |
1579 | void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol, |
1580 | bool addToSelected = FALSE ); | |
f6bcfd97 BP |
1581 | // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft, |
1582 | // TODO: ??? const wxGridCellCoords& bottomRight ) | |
1583 | ||
1584 | void SelectAll(); | |
1585 | bool IsSelection(); | |
1586 | void ClearSelection(); | |
1587 | bool IsInSelection( int row, int col ); | |
1588 | // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords ) | |
1589 | ||
1590 | ||
1591 | // This function returns the rectangle that encloses the block of cells | |
1592 | // limited by TopLeft and BottomRight cell in device coords and clipped | |
1593 | // to the client size of the grid window. | |
1594 | // | |
1595 | wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft, | |
1596 | const wxGridCellCoords & bottomRight ); | |
1597 | ||
1598 | ||
1599 | // Access or update the selection fore/back colours | |
1600 | wxColour GetSelectionBackground() const; | |
1601 | wxColour GetSelectionForeground() const; | |
1602 | ||
1603 | void SetSelectionBackground(const wxColour& c); | |
1604 | void SetSelectionForeground(const wxColour& c); | |
1605 | ||
1606 | ||
1607 | // Methods for a registry for mapping data types to Renderers/Editors | |
1608 | void RegisterDataType(const wxString& typeName, | |
1609 | wxGridCellRenderer* renderer, | |
1610 | wxGridCellEditor* editor); | |
1611 | wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const; | |
1612 | // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const | |
1613 | wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const; | |
1614 | wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const; | |
1615 | wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const; | |
1616 | ||
1617 | // grid may occupy more space than needed for its rows/columns, this | |
1618 | // function allows to set how big this extra space is | |
1619 | void SetMargins(int extraWidth, int extraHeight); | |
9416aa89 RD |
1620 | |
1621 | ||
1622 | // Accessors for component windows | |
1623 | wxWindow* GetGridWindow(); | |
1624 | wxWindow* GetGridRowLabelWindow(); | |
1625 | wxWindow* GetGridColLabelWindow(); | |
1626 | wxWindow* GetGridCornerLabelWindow(); | |
1627 | ||
1628 | ||
f6bcfd97 BP |
1629 | }; |
1630 | ||
1631 | ||
1632 | //--------------------------------------------------------------------------- | |
1633 | //--------------------------------------------------------------------------- | |
1634 | // Grid events and stuff | |
1635 | ||
1636 | ||
1637 | ||
1638 | class wxGridEvent : public wxNotifyEvent | |
1639 | { | |
1640 | public: | |
1641 | wxGridEvent(int id, wxEventType type, wxGrid* obj, | |
1642 | int row=-1, int col=-1, int x=-1, int y=-1, bool sel = TRUE, | |
1643 | bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE); | |
1644 | ||
1645 | virtual int GetRow(); | |
1646 | virtual int GetCol(); | |
1647 | wxPoint GetPosition(); | |
1648 | bool Selecting(); | |
1649 | bool ControlDown(); | |
1650 | bool MetaDown(); | |
1651 | bool ShiftDown(); | |
1652 | bool AltDown(); | |
1653 | ||
1654 | }; | |
1655 | ||
1656 | ||
1657 | class wxGridSizeEvent : public wxNotifyEvent | |
1658 | { | |
1659 | public: | |
1660 | wxGridSizeEvent(int id, wxEventType type, wxGrid* obj, | |
1661 | int rowOrCol=-1, int x=-1, int y=-1, | |
1662 | bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE); | |
1663 | ||
1664 | int GetRowOrCol(); | |
1665 | wxPoint GetPosition(); | |
1666 | bool ControlDown(); | |
1667 | bool MetaDown(); | |
1668 | bool ShiftDown(); | |
1669 | bool AltDown(); | |
1670 | ||
1671 | }; | |
1672 | ||
1673 | ||
1674 | class wxGridRangeSelectEvent : public wxNotifyEvent | |
1675 | { | |
1676 | public: | |
1677 | wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj, | |
1678 | const wxGridCellCoords& topLeft, | |
1679 | const wxGridCellCoords& bottomRight, | |
1680 | bool sel = TRUE, | |
1681 | bool control=FALSE, bool shift=FALSE, | |
1682 | bool alt=FALSE, bool meta=FALSE); | |
1683 | ||
1684 | wxGridCellCoords GetTopLeftCoords(); | |
1685 | wxGridCellCoords GetBottomRightCoords(); | |
1686 | int GetTopRow(); | |
1687 | int GetBottomRow(); | |
1688 | int GetLeftCol(); | |
1689 | int GetRightCol(); | |
1690 | bool Selecting(); | |
1691 | bool ControlDown(); | |
1692 | bool MetaDown(); | |
1693 | bool ShiftDown(); | |
1694 | bool AltDown(); | |
1695 | }; | |
1696 | ||
bf7945ce RD |
1697 | |
1698 | class wxGridEditorCreatedEvent : public wxCommandEvent { | |
1699 | public: | |
1700 | wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj, | |
1701 | int row, int col, wxControl* ctrl); | |
1702 | ||
1703 | int GetRow(); | |
1704 | int GetCol(); | |
1705 | wxControl* GetControl(); | |
1706 | void SetRow(int row); | |
1707 | void SetCol(int col); | |
1708 | void SetControl(wxControl* ctrl); | |
1709 | }; | |
1710 | ||
1711 | ||
1712 | ||
f6bcfd97 BP |
1713 | enum { |
1714 | wxEVT_GRID_CELL_LEFT_CLICK, | |
1715 | wxEVT_GRID_CELL_RIGHT_CLICK, | |
1716 | wxEVT_GRID_CELL_LEFT_DCLICK, | |
1717 | wxEVT_GRID_CELL_RIGHT_DCLICK, | |
1718 | wxEVT_GRID_LABEL_LEFT_CLICK, | |
1719 | wxEVT_GRID_LABEL_RIGHT_CLICK, | |
1720 | wxEVT_GRID_LABEL_LEFT_DCLICK, | |
1721 | wxEVT_GRID_LABEL_RIGHT_DCLICK, | |
1722 | wxEVT_GRID_ROW_SIZE, | |
1723 | wxEVT_GRID_COL_SIZE, | |
1724 | wxEVT_GRID_RANGE_SELECT, | |
1725 | wxEVT_GRID_CELL_CHANGE, | |
1726 | wxEVT_GRID_SELECT_CELL, | |
1727 | wxEVT_GRID_EDITOR_SHOWN, | |
1728 | wxEVT_GRID_EDITOR_HIDDEN, | |
bf7945ce | 1729 | wxEVT_GRID_EDITOR_CREATED, |
f6bcfd97 BP |
1730 | }; |
1731 | ||
1732 | ||
1733 | ||
1734 | %pragma(python) code = " | |
1735 | def EVT_GRID_CELL_LEFT_CLICK(win, fn): | |
1736 | win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_CLICK, fn) | |
1737 | ||
1738 | def EVT_GRID_CELL_RIGHT_CLICK(win, fn): | |
1739 | win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_CLICK, fn) | |
1740 | ||
1741 | def EVT_GRID_CELL_LEFT_DCLICK(win, fn): | |
1742 | win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_DCLICK, fn) | |
1743 | ||
1744 | def EVT_GRID_CELL_RIGHT_DCLICK(win, fn): | |
1745 | win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_DCLICK, fn) | |
1746 | ||
1747 | def EVT_GRID_LABEL_LEFT_CLICK(win, fn): | |
1748 | win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_CLICK, fn) | |
1749 | ||
1750 | def EVT_GRID_LABEL_RIGHT_CLICK(win, fn): | |
1751 | win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_CLICK, fn) | |
1752 | ||
1753 | def EVT_GRID_LABEL_LEFT_DCLICK(win, fn): | |
1754 | win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_DCLICK, fn) | |
1755 | ||
1756 | def EVT_GRID_LABEL_RIGHT_DCLICK(win, fn): | |
1757 | win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_DCLICK, fn) | |
1758 | ||
1759 | def EVT_GRID_ROW_SIZE(win, fn): | |
1760 | win.Connect(-1, -1, wxEVT_GRID_ROW_SIZE, fn) | |
1761 | ||
1762 | def EVT_GRID_COL_SIZE(win, fn): | |
1763 | win.Connect(-1, -1, wxEVT_GRID_COL_SIZE, fn) | |
1764 | ||
1765 | def EVT_GRID_RANGE_SELECT(win, fn): | |
1766 | win.Connect(-1, -1, wxEVT_GRID_RANGE_SELECT, fn) | |
1767 | ||
1768 | def EVT_GRID_CELL_CHANGE(win, fn): | |
1769 | win.Connect(-1, -1, wxEVT_GRID_CELL_CHANGE, fn) | |
1770 | ||
1771 | def EVT_GRID_SELECT_CELL(win, fn): | |
1772 | win.Connect(-1, -1, wxEVT_GRID_SELECT_CELL, fn) | |
1773 | ||
1774 | def EVT_GRID_EDITOR_SHOWN(win, fn): | |
1775 | win.Connect(-1, -1, wxEVT_GRID_EDITOR_SHOWN, fn) | |
1776 | ||
1777 | def EVT_GRID_EDITOR_HIDDEN(win, fn): | |
1778 | win.Connect(-1, -1, wxEVT_GRID_EDITOR_HIDDEN, fn) | |
1779 | ||
bf7945ce RD |
1780 | def EVT_GRID_EDITOR_CREATED(win, fn): |
1781 | win.Connect(-1, -1, wxEVT_GRID_EDITOR_CREATED, fn) | |
1782 | ||
f6bcfd97 BP |
1783 | " |
1784 | ||
1785 | //--------------------------------------------------------------------------- | |
1786 | ||
e508a2b6 RD |
1787 | %init %{ |
1788 | wxClassInfo::CleanUpClasses(); | |
1789 | wxClassInfo::InitializeClasses(); | |
1790 | %} | |
1791 | ||
1792 | //--------------------------------------------------------------------------- | |
1793 | ||
f6bcfd97 BP |
1794 | %pragma(python) include="_gridextras.py"; |
1795 | ||
1796 | //--------------------------------------------------------------------------- | |
1797 | ||
1798 | ||
1799 | #endif |