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