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