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