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