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