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