]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/grid.h
added and documented wxWindow::RemoveEventHandler()
[wxWidgets.git] / include / wx / generic / grid.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/grid.h
3 // Purpose: wxGrid and related classes
4 // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
5 // Modified by:
6 // Created: 1/08/1999
7 // RCS-ID: $Id$
8 // Copyright: (c) Michael Bedward
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/defs.h"
13
14 #if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
15 #include "wx/generic/gridg.h"
16 #else
17
18 #ifndef __WXGRID_H__
19 #define __WXGRID_H__
20
21 #ifdef __GNUG__
22 #pragma interface "grid.h"
23 #endif
24
25 #include "wx/hash.h"
26 #include "wx/panel.h"
27 #include "wx/scrolwin.h"
28 #include "wx/string.h"
29 #include "wx/scrolbar.h"
30 #include "wx/event.h"
31 #include "wx/combobox.h"
32 #include "wx/dynarray.h"
33 #include "wx/timer.h"
34
35 // ----------------------------------------------------------------------------
36 // constants
37 // ----------------------------------------------------------------------------
38
39 // Default parameters for wxGrid
40 //
41 #define WXGRID_DEFAULT_NUMBER_ROWS 10
42 #define WXGRID_DEFAULT_NUMBER_COLS 10
43 #ifdef __WXMSW__
44 #define WXGRID_DEFAULT_ROW_HEIGHT 25
45 #else
46 #define WXGRID_DEFAULT_ROW_HEIGHT 30
47 #endif // __WXMSW__
48 #define WXGRID_DEFAULT_COL_WIDTH 80
49 #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32
50 #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82
51 #define WXGRID_LABEL_EDGE_ZONE 2
52 #define WXGRID_MIN_ROW_HEIGHT 15
53 #define WXGRID_MIN_COL_WIDTH 15
54 #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16
55
56 // type names for grid table values
57 #define wxGRID_VALUE_STRING _T("string")
58 #define wxGRID_VALUE_BOOL _T("bool")
59 #define wxGRID_VALUE_NUMBER _T("long")
60 #define wxGRID_VALUE_FLOAT _T("double")
61 #define wxGRID_VALUE_CHOICE _T("choice")
62
63 #define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING
64 #define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER
65
66 // ----------------------------------------------------------------------------
67 // forward declarations
68 // ----------------------------------------------------------------------------
69
70 class WXDLLEXPORT wxGrid;
71 class WXDLLEXPORT wxGridCellAttr;
72 class WXDLLEXPORT wxGridCellAttrProviderData;
73 class WXDLLEXPORT wxGridColLabelWindow;
74 class WXDLLEXPORT wxGridCornerLabelWindow;
75 class WXDLLEXPORT wxGridRowLabelWindow;
76 class WXDLLEXPORT wxGridTableBase;
77 class WXDLLEXPORT wxGridWindow;
78 class WXDLLEXPORT wxGridTypeRegistry;
79 class WXDLLEXPORT wxGridSelection;
80
81 class WXDLLEXPORT wxCheckBox;
82 class WXDLLEXPORT wxComboBox;
83 class WXDLLEXPORT wxTextCtrl;
84 class WXDLLEXPORT wxSpinCtrl;
85
86 // ----------------------------------------------------------------------------
87 // macros
88 // ----------------------------------------------------------------------------
89
90 #define wxSafeIncRef(p) if ( p ) (p)->IncRef()
91 #define wxSafeDecRef(p) if ( p ) (p)->DecRef()
92
93 // ----------------------------------------------------------------------------
94 // wxGridCellWorker: common base class for wxGridCellRenderer and
95 // wxGridCellEditor
96 //
97 // NB: this is more an implementation convenience than a design issue, so this
98 // class is not documented and is not public at all
99 // ----------------------------------------------------------------------------
100
101 class WXDLLEXPORT wxGridCellWorker
102 {
103 public:
104 wxGridCellWorker() { m_nRef = 1; }
105
106 // this class is ref counted: it is created with ref count of 1, so
107 // calling DecRef() once will delete it. Calling IncRef() allows to lock
108 // it until the matching DecRef() is called
109 void IncRef() { m_nRef++; }
110 void DecRef() { if ( !--m_nRef ) delete this; }
111
112 // interpret renderer parameters: arbitrary string whose interpretatin is
113 // left to the derived classes
114 virtual void SetParameters(const wxString& params);
115
116 protected:
117 // virtual dtor for any base class - private because only DecRef() can
118 // delete us
119 virtual ~wxGridCellWorker();
120
121 private:
122 size_t m_nRef;
123
124 // suppress the stupid gcc warning about the class having private dtor and
125 // no friends
126 friend class wxGridCellWorkerDummyFriend;
127 };
128
129 // ----------------------------------------------------------------------------
130 // wxGridCellRenderer: this class is responsible for actually drawing the cell
131 // in the grid. You may pass it to the wxGridCellAttr (below) to change the
132 // format of one given cell or to wxGrid::SetDefaultRenderer() to change the
133 // view of all cells. This is an ABC, you will normally use one of the
134 // predefined derived classes or derive your own class from it.
135 // ----------------------------------------------------------------------------
136
137 class WXDLLEXPORT wxGridCellRenderer : public wxGridCellWorker
138 {
139 public:
140 // draw the given cell on the provided DC inside the given rectangle
141 // using the style specified by the attribute and the default or selected
142 // state corresponding to the isSelected value.
143 //
144 // this pure virtual function has a default implementation which will
145 // prepare the DC using the given attribute: it will draw the rectangle
146 // with the bg colour from attr and set the text colour and font
147 virtual void Draw(wxGrid& grid,
148 wxGridCellAttr& attr,
149 wxDC& dc,
150 const wxRect& rect,
151 int row, int col,
152 bool isSelected) = 0;
153
154 // get the preferred size of the cell for its contents
155 virtual wxSize GetBestSize(wxGrid& grid,
156 wxGridCellAttr& attr,
157 wxDC& dc,
158 int row, int col) = 0;
159
160 // create a new object which is the copy of this one
161 virtual wxGridCellRenderer *Clone() const = 0;
162 };
163
164 // the default renderer for the cells containing string data
165 class WXDLLEXPORT wxGridCellStringRenderer : public wxGridCellRenderer
166 {
167 public:
168 // draw the string
169 virtual void Draw(wxGrid& grid,
170 wxGridCellAttr& attr,
171 wxDC& dc,
172 const wxRect& rect,
173 int row, int col,
174 bool isSelected);
175
176 // return the string extent
177 virtual wxSize GetBestSize(wxGrid& grid,
178 wxGridCellAttr& attr,
179 wxDC& dc,
180 int row, int col);
181
182 virtual wxGridCellRenderer *Clone() const
183 { return new wxGridCellStringRenderer; }
184
185 protected:
186 // set the text colours before drawing
187 void SetTextColoursAndFont(wxGrid& grid,
188 wxGridCellAttr& attr,
189 wxDC& dc,
190 bool isSelected);
191
192 // calc the string extent for given string/font
193 wxSize DoGetBestSize(wxGridCellAttr& attr,
194 wxDC& dc,
195 const wxString& text);
196 };
197
198 // the default renderer for the cells containing numeric (long) data
199 class WXDLLEXPORT wxGridCellNumberRenderer : public wxGridCellStringRenderer
200 {
201 public:
202 // draw the string right aligned
203 virtual void Draw(wxGrid& grid,
204 wxGridCellAttr& attr,
205 wxDC& dc,
206 const wxRect& rect,
207 int row, int col,
208 bool isSelected);
209
210 virtual wxSize GetBestSize(wxGrid& grid,
211 wxGridCellAttr& attr,
212 wxDC& dc,
213 int row, int col);
214
215 virtual wxGridCellRenderer *Clone() const
216 { return new wxGridCellNumberRenderer; }
217
218 protected:
219 wxString GetString(wxGrid& grid, int row, int col);
220 };
221
222 class WXDLLEXPORT wxGridCellFloatRenderer : public wxGridCellStringRenderer
223 {
224 public:
225 wxGridCellFloatRenderer(int width = -1, int precision = -1);
226
227 // get/change formatting parameters
228 int GetWidth() const { return m_width; }
229 void SetWidth(int width) { m_width = width; m_format.clear(); }
230 int GetPrecision() const { return m_precision; }
231 void SetPrecision(int precision) { m_precision = precision; m_format.clear(); }
232
233 // draw the string right aligned with given width/precision
234 virtual void Draw(wxGrid& grid,
235 wxGridCellAttr& attr,
236 wxDC& dc,
237 const wxRect& rect,
238 int row, int col,
239 bool isSelected);
240
241 virtual wxSize GetBestSize(wxGrid& grid,
242 wxGridCellAttr& attr,
243 wxDC& dc,
244 int row, int col);
245
246 // parameters string format is "width[,precision]"
247 virtual void SetParameters(const wxString& params);
248
249 virtual wxGridCellRenderer *Clone() const;
250
251 protected:
252 wxString GetString(wxGrid& grid, int row, int col);
253
254 private:
255 // formatting parameters
256 int m_width,
257 m_precision;
258
259 wxString m_format;
260 };
261
262 // renderer for boolean fields
263 class WXDLLEXPORT wxGridCellBoolRenderer : public wxGridCellRenderer
264 {
265 public:
266 // draw a check mark or nothing
267 virtual void Draw(wxGrid& grid,
268 wxGridCellAttr& attr,
269 wxDC& dc,
270 const wxRect& rect,
271 int row, int col,
272 bool isSelected);
273
274 // return the checkmark size
275 virtual wxSize GetBestSize(wxGrid& grid,
276 wxGridCellAttr& attr,
277 wxDC& dc,
278 int row, int col);
279
280 virtual wxGridCellRenderer *Clone() const
281 { return new wxGridCellBoolRenderer; }
282
283 private:
284 static wxSize ms_sizeCheckMark;
285 };
286
287 // ----------------------------------------------------------------------------
288 // wxGridCellEditor: This class is responsible for providing and manipulating
289 // the in-place edit controls for the grid. Instances of wxGridCellEditor
290 // (actually, instances of derived classes since it is an ABC) can be
291 // associated with the cell attributes for individual cells, rows, columns, or
292 // even for the entire grid.
293 // ----------------------------------------------------------------------------
294
295 class WXDLLEXPORT wxGridCellEditor : public wxGridCellWorker
296 {
297 public:
298 wxGridCellEditor();
299
300 bool IsCreated() { return m_control != NULL; }
301 wxControl* GetControl() { return m_control; }
302 void SetControl(wxControl* control) { m_control = control; }
303
304 // Creates the actual edit control
305 virtual void Create(wxWindow* parent,
306 wxWindowID id,
307 wxEvtHandler* evtHandler) = 0;
308
309 // Size and position the edit control
310 virtual void SetSize(const wxRect& rect);
311
312 // Show or hide the edit control, use the specified attributes to set
313 // colours/fonts for it
314 virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL);
315
316 // Draws the part of the cell not occupied by the control: the base class
317 // version just fills it with background colour from the attribute
318 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
319
320 // Fetch the value from the table and prepare the edit control
321 // to begin editing. Set the focus to the edit control.
322 virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
323
324 // Complete the editing of the current cell. Returns true if the value has
325 // changed. If necessary, the control may be destroyed.
326 virtual bool EndEdit(int row, int col, wxGrid* grid) = 0;
327
328 // Reset the value in the control back to its starting value
329 virtual void Reset() = 0;
330
331 // return TRUE to allow the given key to start editing: the base class
332 // version only checks that the event has no modifiers. The derived
333 // classes are supposed to do "if ( base::IsAcceptedKey() && ... )" in
334 // their IsAcceptedKey() implementation, although, of course, it is not a
335 // mandatory requirment.
336 //
337 // NB: if the key is F2 (special), editing will always start and this
338 // method will not be called at all (but StartingKey() will)
339 virtual bool IsAcceptedKey(wxKeyEvent& event);
340
341 // If the editor is enabled by pressing keys on the grid, this will be
342 // called to let the editor do something about that first key if desired
343 virtual void StartingKey(wxKeyEvent& event);
344
345 // if the editor is enabled by clicking on the cell, this method will be
346 // called
347 virtual void StartingClick();
348
349 // Some types of controls on some platforms may need some help
350 // with the Return key.
351 virtual void HandleReturn(wxKeyEvent& event);
352
353 // Final cleanup
354 virtual void Destroy();
355
356 // create a new object which is the copy of this one
357 virtual wxGridCellEditor *Clone() const = 0;
358
359 protected:
360 // the dtor is private because only DecRef() can delete us
361 virtual ~wxGridCellEditor();
362
363 // the control we show on screen
364 wxControl* m_control;
365
366 // if we change the colours/font of the control from the default ones, we
367 // must restore the default later and we save them here between calls to
368 // Show(TRUE) and Show(FALSE)
369 wxColour m_colFgOld,
370 m_colBgOld;
371 wxFont m_fontOld;
372
373 // suppress the stupid gcc warning about the class having private dtor and
374 // no friends
375 friend class wxGridCellEditorDummyFriend;
376 };
377
378 #if wxUSE_TEXTCTRL
379
380 // the editor for string/text data
381 class WXDLLEXPORT wxGridCellTextEditor : public wxGridCellEditor
382 {
383 public:
384 wxGridCellTextEditor();
385
386 virtual void Create(wxWindow* parent,
387 wxWindowID id,
388 wxEvtHandler* evtHandler);
389 virtual void SetSize(const wxRect& rect);
390
391 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
392
393 virtual bool IsAcceptedKey(wxKeyEvent& event);
394 virtual void BeginEdit(int row, int col, wxGrid* grid);
395 virtual bool EndEdit(int row, int col, wxGrid* grid);
396
397 virtual void Reset();
398 virtual void StartingKey(wxKeyEvent& event);
399 virtual void HandleReturn(wxKeyEvent& event);
400
401 // parameters string format is "max_width"
402 virtual void SetParameters(const wxString& params);
403
404 virtual wxGridCellEditor *Clone() const
405 { return new wxGridCellTextEditor; }
406
407 protected:
408 wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; }
409
410 // parts of our virtual functions reused by the derived classes
411 void DoBeginEdit(const wxString& startValue);
412 void DoReset(const wxString& startValue);
413
414 private:
415 size_t m_maxChars; // max number of chars allowed
416 wxString m_startValue;
417 };
418
419 // the editor for numeric (long) data
420 class WXDLLEXPORT wxGridCellNumberEditor : public wxGridCellTextEditor
421 {
422 public:
423 // allows to specify the range - if min == max == -1, no range checking is
424 // done
425 wxGridCellNumberEditor(int min = -1, int max = -1);
426
427 virtual void Create(wxWindow* parent,
428 wxWindowID id,
429 wxEvtHandler* evtHandler);
430
431 virtual bool IsAcceptedKey(wxKeyEvent& event);
432 virtual void BeginEdit(int row, int col, wxGrid* grid);
433 virtual bool EndEdit(int row, int col, wxGrid* grid);
434
435 virtual void Reset();
436 virtual void StartingKey(wxKeyEvent& event);
437
438 // parameters string format is "min,max"
439 virtual void SetParameters(const wxString& params);
440
441 virtual wxGridCellEditor *Clone() const
442 { return new wxGridCellNumberEditor(m_min, m_max); }
443
444 protected:
445 wxSpinCtrl *Spin() const { return (wxSpinCtrl *)m_control; }
446
447 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
448 bool HasRange() const { return m_min != m_max; }
449
450 // string representation of m_valueOld
451 wxString GetString() const
452 { return wxString::Format(_T("%ld"), m_valueOld); }
453
454 private:
455 int m_min,
456 m_max;
457
458 long m_valueOld;
459 };
460
461 // the editor for floating point numbers (double) data
462 class WXDLLEXPORT wxGridCellFloatEditor : public wxGridCellTextEditor
463 {
464 public:
465 wxGridCellFloatEditor(int width = -1, int precision = -1);
466
467 virtual void Create(wxWindow* parent,
468 wxWindowID id,
469 wxEvtHandler* evtHandler);
470
471 virtual bool IsAcceptedKey(wxKeyEvent& event);
472 virtual void BeginEdit(int row, int col, wxGrid* grid);
473 virtual bool EndEdit(int row, int col, wxGrid* grid);
474
475 virtual void Reset();
476 virtual void StartingKey(wxKeyEvent& event);
477
478 virtual wxGridCellEditor *Clone() const
479 { return new wxGridCellFloatEditor; }
480
481 // parameters string format is "width,precision"
482 virtual void SetParameters(const wxString& params);
483
484 protected:
485 // string representation of m_valueOld
486 wxString GetString() const;
487
488 private:
489 int m_width,
490 m_precision;
491 double m_valueOld;
492 };
493
494 #endif // wxUSE_TEXTCTRL
495
496 #if wxUSE_CHECKBOX
497
498 // the editor for boolean data
499 class WXDLLEXPORT wxGridCellBoolEditor : public wxGridCellEditor
500 {
501 public:
502 virtual void Create(wxWindow* parent,
503 wxWindowID id,
504 wxEvtHandler* evtHandler);
505
506 virtual void SetSize(const wxRect& rect);
507 virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL);
508
509 virtual bool IsAcceptedKey(wxKeyEvent& event);
510 virtual void BeginEdit(int row, int col, wxGrid* grid);
511 virtual bool EndEdit(int row, int col, wxGrid* grid);
512
513 virtual void Reset();
514 virtual void StartingClick();
515
516 virtual wxGridCellEditor *Clone() const
517 { return new wxGridCellBoolEditor; }
518
519 protected:
520 wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
521
522 private:
523 bool m_startValue;
524 };
525
526 #endif // wxUSE_CHECKBOX
527
528 #if wxUSE_COMBOBOX
529
530 // the editor for string data allowing to choose from the list of strings
531 class WXDLLEXPORT wxGridCellChoiceEditor : public wxGridCellEditor
532 {
533 public:
534 // if !allowOthers, user can't type a string not in choices array
535 wxGridCellChoiceEditor(size_t count = 0,
536 const wxString choices[] = NULL,
537 bool allowOthers = FALSE);
538
539 virtual void Create(wxWindow* parent,
540 wxWindowID id,
541 wxEvtHandler* evtHandler);
542
543 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
544
545 virtual void BeginEdit(int row, int col, wxGrid* grid);
546 virtual bool EndEdit(int row, int col, wxGrid* grid);
547
548 virtual void Reset();
549
550 // parameters string format is "item1[,item2[...,itemN]]"
551 virtual void SetParameters(const wxString& params);
552
553 virtual wxGridCellEditor *Clone() const;
554
555 protected:
556 wxComboBox *Combo() const { return (wxComboBox *)m_control; }
557
558 private:
559 wxString m_startValue;
560 wxArrayString m_choices;
561 bool m_allowOthers;
562 };
563
564 #endif // wxUSE_COMBOBOX
565
566 // ----------------------------------------------------------------------------
567 // wxGridCellAttr: this class can be used to alter the cells appearance in
568 // the grid by changing their colour/font/... from default. An object of this
569 // class may be returned by wxGridTable::GetAttr().
570 // ----------------------------------------------------------------------------
571
572 class WXDLLEXPORT wxGridCellAttr
573 {
574 public:
575 enum wxAttrKind
576 {
577 Any,
578 Default,
579 Cell,
580 Row,
581 Col,
582 Merged
583 };
584
585 // ctors
586 wxGridCellAttr(wxGridCellAttr *attrDefault = NULL)
587 {
588 Init(attrDefault);
589
590 // MB: args used to be 0,0 here but wxALIGN_LEFT is 0
591 SetAlignment(-1, -1);
592 }
593
594 // VZ: considering the number of members wxGridCellAttr has now, this ctor
595 // seems to be pretty useless... may be we should just remove it?
596 wxGridCellAttr(const wxColour& colText,
597 const wxColour& colBack,
598 const wxFont& font,
599 int hAlign,
600 int vAlign)
601 : m_colText(colText), m_colBack(colBack), m_font(font)
602 {
603 Init();
604 SetAlignment(hAlign, vAlign);
605 }
606
607 // creates a new copy of this object
608 wxGridCellAttr *Clone() const;
609 void MergeWith(wxGridCellAttr *mergefrom);
610
611 // this class is ref counted: it is created with ref count of 1, so
612 // calling DecRef() once will delete it. Calling IncRef() allows to lock
613 // it until the matching DecRef() is called
614 void IncRef() { m_nRef++; }
615 void DecRef() { if ( !--m_nRef ) delete this; }
616
617 // setters
618 void SetTextColour(const wxColour& colText) { m_colText = colText; }
619 void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; }
620 void SetFont(const wxFont& font) { m_font = font; }
621 void SetAlignment(int hAlign, int vAlign)
622 {
623 m_hAlign = hAlign;
624 m_vAlign = vAlign;
625 }
626 void SetReadOnly(bool isReadOnly = TRUE)
627 { m_isReadOnly = isReadOnly ? ReadOnly : ReadWrite; }
628
629 // takes ownership of the pointer
630 void SetRenderer(wxGridCellRenderer *renderer)
631 { wxSafeDecRef(m_renderer); m_renderer = renderer; }
632 void SetEditor(wxGridCellEditor* editor)
633 { wxSafeDecRef(m_editor); m_editor = editor; }
634
635 void SetKind(wxAttrKind kind) { m_attrkind = kind; }
636
637 // accessors
638 bool HasTextColour() const { return m_colText.Ok(); }
639 bool HasBackgroundColour() const { return m_colBack.Ok(); }
640 bool HasFont() const { return m_font.Ok(); }
641 bool HasAlignment() const { return (m_hAlign != -1 || m_vAlign != -1); }
642 bool HasRenderer() const { return m_renderer != NULL; }
643 bool HasEditor() const { return m_editor != NULL; }
644 bool HasReadWriteMode() const { return m_isReadOnly != Unset; }
645
646 const wxColour& GetTextColour() const;
647 const wxColour& GetBackgroundColour() const;
648 const wxFont& GetFont() const;
649 void GetAlignment(int *hAlign, int *vAlign) const;
650 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
651 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
652
653 bool IsReadOnly() const { return m_isReadOnly == wxGridCellAttr::ReadOnly; }
654
655 wxAttrKind GetKind() { return m_attrkind; }
656
657 void SetDefAttr(wxGridCellAttr* defAttr) { m_defGridAttr = defAttr; }
658
659 private:
660 enum wxAttrReadMode
661 {
662 Unset = -1,
663 ReadWrite,
664 ReadOnly
665 };
666
667 // the common part of all ctors
668 void Init(wxGridCellAttr *attrDefault = NULL);
669
670 // the dtor is private because only DecRef() can delete us
671 ~wxGridCellAttr()
672 {
673 wxSafeDecRef(m_renderer);
674 wxSafeDecRef(m_editor);
675 }
676
677 // the ref count - when it goes to 0, we die
678 size_t m_nRef;
679
680 wxColour m_colText,
681 m_colBack;
682 wxFont m_font;
683 int m_hAlign,
684 m_vAlign;
685
686 wxGridCellRenderer* m_renderer;
687 wxGridCellEditor* m_editor;
688 wxGridCellAttr* m_defGridAttr;
689
690 wxAttrReadMode m_isReadOnly;
691
692 wxAttrKind m_attrkind;
693
694 // use Clone() instead
695 DECLARE_NO_COPY_CLASS(wxGridCellAttr)
696
697 // suppress the stupid gcc warning about the class having private dtor and
698 // no friends
699 friend class wxGridCellAttrDummyFriend;
700 };
701
702 // ----------------------------------------------------------------------------
703 // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
704 // cell attributes.
705 // ----------------------------------------------------------------------------
706
707 // implementation note: we separate it from wxGridTableBase because we wish to
708 // avoid deriving a new table class if possible, and sometimes it will be
709 // enough to just derive another wxGridCellAttrProvider instead
710 //
711 // the default implementation is reasonably efficient for the generic case,
712 // but you might still wish to implement your own for some specific situations
713 // if you have performance problems with the stock one
714 class WXDLLEXPORT wxGridCellAttrProvider
715 {
716 public:
717 wxGridCellAttrProvider();
718 virtual ~wxGridCellAttrProvider();
719
720 // DecRef() must be called on the returned pointer
721 virtual wxGridCellAttr *GetAttr(int row, int col,
722 wxGridCellAttr::wxAttrKind kind ) const;
723
724 // all these functions take ownership of the pointer, don't call DecRef()
725 // on it
726 virtual void SetAttr(wxGridCellAttr *attr, int row, int col);
727 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
728 virtual void SetColAttr(wxGridCellAttr *attr, int col);
729
730 // these functions must be called whenever some rows/cols are deleted
731 // because the internal data must be updated then
732 void UpdateAttrRows( size_t pos, int numRows );
733 void UpdateAttrCols( size_t pos, int numCols );
734
735 private:
736 void InitData();
737
738 wxGridCellAttrProviderData *m_data;
739 };
740
741 //////////////////////////////////////////////////////////////////////
742 //
743 // Grid table classes
744 //
745 //////////////////////////////////////////////////////////////////////
746
747
748 class WXDLLEXPORT wxGridTableBase : public wxObject
749 {
750 public:
751 wxGridTableBase();
752 virtual ~wxGridTableBase();
753
754 // You must override these functions in a derived table class
755 //
756 virtual int GetNumberRows() = 0;
757 virtual int GetNumberCols() = 0;
758 virtual bool IsEmptyCell( int row, int col ) = 0;
759 virtual wxString GetValue( int row, int col ) = 0;
760 virtual void SetValue( int row, int col, const wxString& value ) = 0;
761
762 // Data type determination and value access
763 virtual wxString GetTypeName( int row, int col );
764 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
765 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
766
767 virtual long GetValueAsLong( int row, int col );
768 virtual double GetValueAsDouble( int row, int col );
769 virtual bool GetValueAsBool( int row, int col );
770
771 virtual void SetValueAsLong( int row, int col, long value );
772 virtual void SetValueAsDouble( int row, int col, double value );
773 virtual void SetValueAsBool( int row, int col, bool value );
774
775 // For user defined types
776 virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
777 virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
778
779
780 // Overriding these is optional
781 //
782 virtual void SetView( wxGrid *grid ) { m_view = grid; }
783 virtual wxGrid * GetView() const { return m_view; }
784
785 virtual void Clear() {}
786 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
787 virtual bool AppendRows( size_t numRows = 1 );
788 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
789 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
790 virtual bool AppendCols( size_t numCols = 1 );
791 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
792
793 virtual wxString GetRowLabelValue( int row );
794 virtual wxString GetColLabelValue( int col );
795 virtual void SetRowLabelValue( int WXUNUSED(row), const wxString& ) {}
796 virtual void SetColLabelValue( int WXUNUSED(col), const wxString& ) {}
797
798 // Attribute handling
799 //
800
801 // give us the attr provider to use - we take ownership of the pointer
802 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
803
804 // get the currently used attr provider (may be NULL)
805 wxGridCellAttrProvider *GetAttrProvider() const { return m_attrProvider; }
806
807 // Does this table allow attributes? Default implementation creates
808 // a wxGridCellAttrProvider if necessary.
809 virtual bool CanHaveAttributes();
810
811 // by default forwarded to wxGridCellAttrProvider if any. May be
812 // overridden to handle attributes directly in the table.
813 virtual wxGridCellAttr *GetAttr( int row, int col,
814 wxGridCellAttr::wxAttrKind kind );
815
816
817 // these functions take ownership of the pointer
818 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
819 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
820 virtual void SetColAttr(wxGridCellAttr *attr, int col);
821
822 private:
823 wxGrid * m_view;
824 wxGridCellAttrProvider *m_attrProvider;
825
826 DECLARE_ABSTRACT_CLASS( wxGridTableBase );
827 };
828
829
830 // ----------------------------------------------------------------------------
831 // wxGridTableMessage
832 // ----------------------------------------------------------------------------
833
834 // IDs for messages sent from grid table to view
835 //
836 enum wxGridTableRequest
837 {
838 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
839 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
840 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
841 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
842 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
843 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
844 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
845 wxGRIDTABLE_NOTIFY_COLS_DELETED
846 };
847
848 class WXDLLEXPORT wxGridTableMessage
849 {
850 public:
851 wxGridTableMessage();
852 wxGridTableMessage( wxGridTableBase *table, int id,
853 int comInt1 = -1,
854 int comInt2 = -1 );
855
856 void SetTableObject( wxGridTableBase *table ) { m_table = table; }
857 wxGridTableBase * GetTableObject() const { return m_table; }
858 void SetId( int id ) { m_id = id; }
859 int GetId() { return m_id; }
860 void SetCommandInt( int comInt1 ) { m_comInt1 = comInt1; }
861 int GetCommandInt() { return m_comInt1; }
862 void SetCommandInt2( int comInt2 ) { m_comInt2 = comInt2; }
863 int GetCommandInt2() { return m_comInt2; }
864
865 private:
866 wxGridTableBase *m_table;
867 int m_id;
868 int m_comInt1;
869 int m_comInt2;
870 };
871
872
873
874 // ------ wxGridStringArray
875 // A 2-dimensional array of strings for data values
876 //
877
878 WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString, wxGridStringArray);
879
880
881
882 // ------ wxGridStringTable
883 //
884 // Simplest type of data table for a grid for small tables of strings
885 // that are stored in memory
886 //
887
888 class WXDLLEXPORT wxGridStringTable : public wxGridTableBase
889 {
890 public:
891 wxGridStringTable();
892 wxGridStringTable( int numRows, int numCols );
893 ~wxGridStringTable();
894
895 // these are pure virtual in wxGridTableBase
896 //
897 int GetNumberRows();
898 int GetNumberCols();
899 wxString GetValue( int row, int col );
900 void SetValue( int row, int col, const wxString& s );
901 bool IsEmptyCell( int row, int col );
902
903 // overridden functions from wxGridTableBase
904 //
905 void Clear();
906 bool InsertRows( size_t pos = 0, size_t numRows = 1 );
907 bool AppendRows( size_t numRows = 1 );
908 bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
909 bool InsertCols( size_t pos = 0, size_t numCols = 1 );
910 bool AppendCols( size_t numCols = 1 );
911 bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
912
913 void SetRowLabelValue( int row, const wxString& );
914 void SetColLabelValue( int col, const wxString& );
915 wxString GetRowLabelValue( int row );
916 wxString GetColLabelValue( int col );
917
918 private:
919 wxGridStringArray m_data;
920
921 // These only get used if you set your own labels, otherwise the
922 // GetRow/ColLabelValue functions return wxGridTableBase defaults
923 //
924 wxArrayString m_rowLabels;
925 wxArrayString m_colLabels;
926
927 DECLARE_DYNAMIC_CLASS( wxGridStringTable )
928 };
929
930
931
932 // ============================================================================
933 // Grid view classes
934 // ============================================================================
935
936 // ----------------------------------------------------------------------------
937 // wxGridCellCoords: location of a cell in the grid
938 // ----------------------------------------------------------------------------
939
940 class WXDLLEXPORT wxGridCellCoords
941 {
942 public:
943 wxGridCellCoords() { m_row = m_col = -1; }
944 wxGridCellCoords( int r, int c ) { m_row = r; m_col = c; }
945
946 // default copy ctor is ok
947
948 int GetRow() const { return m_row; }
949 void SetRow( int n ) { m_row = n; }
950 int GetCol() const { return m_col; }
951 void SetCol( int n ) { m_col = n; }
952 void Set( int row, int col ) { m_row = row; m_col = col; }
953
954 wxGridCellCoords& operator=( const wxGridCellCoords& other )
955 {
956 if ( &other != this )
957 {
958 m_row=other.m_row;
959 m_col=other.m_col;
960 }
961 return *this;
962 }
963
964 bool operator==( const wxGridCellCoords& other ) const
965 {
966 return (m_row == other.m_row && m_col == other.m_col);
967 }
968
969 bool operator!=( const wxGridCellCoords& other ) const
970 {
971 return (m_row != other.m_row || m_col != other.m_col);
972 }
973
974 bool operator!() const
975 {
976 return (m_row == -1 && m_col == -1 );
977 }
978
979 private:
980 int m_row;
981 int m_col;
982 };
983
984
985 // For comparisons...
986 //
987 extern WXDLLEXPORT wxGridCellCoords wxGridNoCellCoords;
988 extern WXDLLEXPORT wxRect wxGridNoCellRect;
989
990 // An array of cell coords...
991 //
992 WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords, wxGridCellCoordsArray);
993
994 // ----------------------------------------------------------------------------
995 // wxGrid
996 // ----------------------------------------------------------------------------
997
998 class WXDLLEXPORT wxGrid : public wxScrolledWindow
999 {
1000 public:
1001 wxGrid()
1002 {
1003 Create();
1004 }
1005
1006 wxGrid( wxWindow *parent,
1007 wxWindowID id,
1008 const wxPoint& pos = wxDefaultPosition,
1009 const wxSize& size = wxDefaultSize,
1010 long style = wxWANTS_CHARS,
1011 const wxString& name = wxPanelNameStr );
1012
1013 ~wxGrid();
1014
1015 enum wxGridSelectionModes {wxGridSelectCells,
1016 wxGridSelectRows,
1017 wxGridSelectColumns};
1018
1019 bool CreateGrid( int numRows, int numCols,
1020 wxGrid::wxGridSelectionModes selmode =
1021 wxGrid::wxGridSelectCells );
1022
1023 void SetSelectionMode(wxGrid::wxGridSelectionModes selmode);
1024
1025 // ------ grid dimensions
1026 //
1027 int GetNumberRows() { return m_numRows; }
1028 int GetNumberCols() { return m_numCols; }
1029
1030
1031 // ------ display update functions
1032 //
1033 wxArrayInt CalcRowLabelsExposed( const wxRegion& reg );
1034
1035 wxArrayInt CalcColLabelsExposed( const wxRegion& reg );
1036 wxGridCellCoordsArray CalcCellsExposed( const wxRegion& reg );
1037
1038
1039 // ------ event handlers
1040 //
1041 void ProcessRowLabelMouseEvent( wxMouseEvent& event );
1042 void ProcessColLabelMouseEvent( wxMouseEvent& event );
1043 void ProcessCornerLabelMouseEvent( wxMouseEvent& event );
1044 void ProcessGridCellMouseEvent( wxMouseEvent& event );
1045 bool ProcessTableMessage( wxGridTableMessage& );
1046
1047 void DoEndDragResizeRow();
1048 void DoEndDragResizeCol();
1049
1050 wxGridTableBase * GetTable() const { return m_table; }
1051 bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE,
1052 wxGrid::wxGridSelectionModes selmode =
1053 wxGrid::wxGridSelectCells );
1054
1055 void ClearGrid();
1056 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1057 bool AppendRows( int numRows = 1, bool updateLabels=TRUE );
1058 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1059 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1060 bool AppendCols( int numCols = 1, bool updateLabels=TRUE );
1061 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1062
1063 void DrawGridCellArea( wxDC& dc , const wxGridCellCoordsArray& cells );
1064 void DrawGridSpace( wxDC& dc );
1065 void DrawCellBorder( wxDC& dc, const wxGridCellCoords& );
1066 void DrawAllGridLines( wxDC& dc, const wxRegion & reg );
1067 void DrawCell( wxDC& dc, const wxGridCellCoords& );
1068 void DrawHighlight(wxDC& dc, const wxGridCellCoordsArray& cells);
1069
1070 // this function is called when the current cell highlight must be redrawn
1071 // and may be overridden by the user
1072 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1073
1074 void DrawRowLabels( wxDC& dc, const wxArrayInt& rows );
1075 void DrawRowLabel( wxDC& dc, int row );
1076
1077 void DrawColLabels( wxDC& dc, const wxArrayInt& cols );
1078 void DrawColLabel( wxDC& dc, int col );
1079
1080
1081 // ------ Cell text drawing functions
1082 //
1083 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1084 int horizontalAlignment = wxALIGN_LEFT,
1085 int verticalAlignment = wxALIGN_TOP );
1086
1087 void DrawTextRectangle( wxDC& dc, const wxArrayString& lines, const wxRect&,
1088 int horizontalAlignment = wxALIGN_LEFT,
1089 int verticalAlignment = wxALIGN_TOP );
1090
1091
1092 // Split a string containing newline chararcters into an array of
1093 // strings and return the number of lines
1094 //
1095 void StringToLines( const wxString& value, wxArrayString& lines );
1096
1097 void GetTextBoxSize( wxDC& dc,
1098 const wxArrayString& lines,
1099 long *width, long *height );
1100
1101
1102 // ------
1103 // Code that does a lot of grid modification can be enclosed
1104 // between BeginBatch() and EndBatch() calls to avoid screen
1105 // flicker
1106 //
1107 void BeginBatch() { m_batchCount++; }
1108 void EndBatch();
1109
1110 int GetBatchCount() { return m_batchCount; }
1111
1112 // Use this, rather than wxWindow::Refresh(), to force an
1113 // immediate repainting of the grid. Has no effect if you are
1114 // already inside a BeginBatch / EndBatch block.
1115 //
1116 // This function is necessary because wxGrid has a minimal OnPaint()
1117 // handler to reduce screen flicker.
1118 //
1119 void ForceRefresh();
1120
1121
1122 // ------ edit control functions
1123 //
1124 bool IsEditable() { return m_editable; }
1125 void EnableEditing( bool edit );
1126
1127 void EnableCellEditControl( bool enable = TRUE );
1128 void DisableCellEditControl() { EnableCellEditControl(FALSE); }
1129 bool CanEnableCellControl() const;
1130 bool IsCellEditControlEnabled() const;
1131 bool IsCellEditControlShown() const;
1132
1133 bool IsCurrentCellReadOnly() const;
1134
1135 void ShowCellEditControl();
1136 void HideCellEditControl();
1137 void SaveEditControlValue();
1138
1139
1140 // ------ grid location functions
1141 // Note that all of these functions work with the logical coordinates of
1142 // grid cells and labels so you will need to convert from device
1143 // coordinates for mouse events etc.
1144 //
1145 void XYToCell( int x, int y, wxGridCellCoords& );
1146 int YToRow( int y );
1147 int XToCol( int x );
1148
1149 int YToEdgeOfRow( int y );
1150 int XToEdgeOfCol( int x );
1151
1152 wxRect CellToRect( int row, int col );
1153 wxRect CellToRect( const wxGridCellCoords& coords )
1154 { return CellToRect( coords.GetRow(), coords.GetCol() ); }
1155
1156 int GetGridCursorRow() { return m_currentCellCoords.GetRow(); }
1157 int GetGridCursorCol() { return m_currentCellCoords.GetCol(); }
1158
1159 // check to see if a cell is either wholly visible (the default arg) or
1160 // at least partially visible in the grid window
1161 //
1162 bool IsVisible( int row, int col, bool wholeCellVisible = TRUE );
1163 bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE )
1164 { return IsVisible( coords.GetRow(), coords.GetCol(), wholeCellVisible ); }
1165 void MakeCellVisible( int row, int col );
1166 void MakeCellVisible( const wxGridCellCoords& coords )
1167 { MakeCellVisible( coords.GetRow(), coords.GetCol() ); }
1168
1169
1170 // ------ grid cursor movement functions
1171 //
1172 void SetGridCursor( int row, int col )
1173 { SetCurrentCell( wxGridCellCoords(row, col) ); }
1174
1175 bool MoveCursorUp( bool expandSelection );
1176 bool MoveCursorDown( bool expandSelection );
1177 bool MoveCursorLeft( bool expandSelection );
1178 bool MoveCursorRight( bool expandSelection );
1179 bool MovePageDown();
1180 bool MovePageUp();
1181 bool MoveCursorUpBlock( bool expandSelection );
1182 bool MoveCursorDownBlock( bool expandSelection );
1183 bool MoveCursorLeftBlock( bool expandSelection );
1184 bool MoveCursorRightBlock( bool expandSelection );
1185
1186
1187 // ------ label and gridline formatting
1188 //
1189 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH; }
1190 int GetRowLabelSize() { return m_rowLabelWidth; }
1191 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT; }
1192 int GetColLabelSize() { return m_colLabelHeight; }
1193 wxColour GetLabelBackgroundColour() { return m_labelBackgroundColour; }
1194 wxColour GetLabelTextColour() { return m_labelTextColour; }
1195 wxFont GetLabelFont() { return m_labelFont; }
1196 void GetRowLabelAlignment( int *horiz, int *vert );
1197 void GetColLabelAlignment( int *horiz, int *vert );
1198 wxString GetRowLabelValue( int row );
1199 wxString GetColLabelValue( int col );
1200 wxColour GetGridLineColour() { return m_gridLineColour; }
1201 wxColour GetCellHighlightColour() { return m_cellHighlightColour; }
1202 int GetCellHighlightPenWidth() { return m_cellHighlightPenWidth; }
1203 int GetCellHighlightROPenWidth() { return m_cellHighlightROPenWidth; }
1204
1205 void SetRowLabelSize( int width );
1206 void SetColLabelSize( int height );
1207 void SetLabelBackgroundColour( const wxColour& );
1208 void SetLabelTextColour( const wxColour& );
1209 void SetLabelFont( const wxFont& );
1210 void SetRowLabelAlignment( int horiz, int vert );
1211 void SetColLabelAlignment( int horiz, int vert );
1212 void SetRowLabelValue( int row, const wxString& );
1213 void SetColLabelValue( int col, const wxString& );
1214 void SetGridLineColour( const wxColour& );
1215 void SetCellHighlightColour( const wxColour& );
1216 void SetCellHighlightPenWidth(int width);
1217 void SetCellHighlightROPenWidth(int width);
1218
1219 void EnableDragRowSize( bool enable = TRUE );
1220 void DisableDragRowSize() { EnableDragRowSize( FALSE ); }
1221 bool CanDragRowSize() { return m_canDragRowSize; }
1222 void EnableDragColSize( bool enable = TRUE );
1223 void DisableDragColSize() { EnableDragColSize( FALSE ); }
1224 bool CanDragColSize() { return m_canDragColSize; }
1225 void EnableDragGridSize(bool enable = TRUE);
1226 void DisableDragGridSize() { EnableDragGridSize(FALSE); }
1227 bool CanDragGridSize() { return m_canDragGridSize; }
1228
1229 // this sets the specified attribute for all cells in this row/col
1230 void SetRowAttr(int row, wxGridCellAttr *attr);
1231 void SetColAttr(int col, wxGridCellAttr *attr);
1232
1233 // shortcuts for setting the column parameters
1234
1235 // set the format for the data in the column: default is string
1236 void SetColFormatBool(int col);
1237 void SetColFormatNumber(int col);
1238 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1239 void SetColFormatCustom(int col, const wxString& typeName);
1240
1241 void EnableGridLines( bool enable = TRUE );
1242 bool GridLinesEnabled() { return m_gridLinesEnabled; }
1243
1244 // ------ row and col formatting
1245 //
1246 int GetDefaultRowSize();
1247 int GetRowSize( int row );
1248 int GetDefaultColSize();
1249 int GetColSize( int col );
1250 wxColour GetDefaultCellBackgroundColour();
1251 wxColour GetCellBackgroundColour( int row, int col );
1252 wxColour GetDefaultCellTextColour();
1253 wxColour GetCellTextColour( int row, int col );
1254 wxFont GetDefaultCellFont();
1255 wxFont GetCellFont( int row, int col );
1256 void GetDefaultCellAlignment( int *horiz, int *vert );
1257 void GetCellAlignment( int row, int col, int *horiz, int *vert );
1258
1259 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
1260 void SetRowSize( int row, int height );
1261 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
1262
1263 void SetColSize( int col, int width );
1264
1265 // automatically size the column or row to fit to its contents, if
1266 // setAsMin is TRUE, this optimal width will also be set as minimal width
1267 // for this column
1268 void AutoSizeColumn( int col, bool setAsMin = TRUE )
1269 { AutoSizeColOrRow(col, setAsMin, TRUE); }
1270 void AutoSizeRow( int row, bool setAsMin = TRUE )
1271 { AutoSizeColOrRow(row, setAsMin, FALSE); }
1272
1273 // auto size all columns (very ineffective for big grids!)
1274 void AutoSizeColumns( bool setAsMin = TRUE )
1275 { (void)SetOrCalcColumnSizes(FALSE, setAsMin); }
1276
1277 void AutoSizeRows( bool setAsMin = TRUE )
1278 { (void)SetOrCalcRowSizes(FALSE, setAsMin); }
1279
1280 // auto size the grid, that is make the columns/rows of the "right" size
1281 // and also set the grid size to just fit its contents
1282 void AutoSize();
1283
1284 // column won't be resized to be lesser width - this must be called during
1285 // the grid creation because it won't resize the column if it's already
1286 // narrower than the minimal width
1287 void SetColMinimalWidth( int col, int width );
1288 void SetRowMinimalHeight( int row, int width );
1289
1290 void SetDefaultCellBackgroundColour( const wxColour& );
1291 void SetCellBackgroundColour( int row, int col, const wxColour& );
1292 void SetDefaultCellTextColour( const wxColour& );
1293
1294 void SetCellTextColour( int row, int col, const wxColour& );
1295 void SetDefaultCellFont( const wxFont& );
1296 void SetCellFont( int row, int col, const wxFont& );
1297 void SetDefaultCellAlignment( int horiz, int vert );
1298 void SetCellAlignment( int row, int col, int horiz, int vert );
1299
1300 // takes ownership of the pointer
1301 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1302 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1303 wxGridCellRenderer *GetDefaultRenderer() const;
1304 wxGridCellRenderer* GetCellRenderer(int row, int col);
1305
1306 // takes ownership of the pointer
1307 void SetDefaultEditor(wxGridCellEditor *editor);
1308 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1309 wxGridCellEditor *GetDefaultEditor() const;
1310 wxGridCellEditor* GetCellEditor(int row, int col);
1311
1312
1313
1314 // ------ cell value accessors
1315 //
1316 wxString GetCellValue( int row, int col )
1317 {
1318 if ( m_table )
1319 {
1320 return m_table->GetValue( row, col );
1321 }
1322 else
1323 {
1324 return wxEmptyString;
1325 }
1326 }
1327
1328 wxString GetCellValue( const wxGridCellCoords& coords )
1329 { return GetCellValue( coords.GetRow(), coords.GetCol() ); }
1330
1331 void SetCellValue( int row, int col, const wxString& s );
1332 void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1333 { SetCellValue( coords.GetRow(), coords.GetCol(), s ); }
1334
1335 // returns TRUE if the cell can't be edited
1336 bool IsReadOnly(int row, int col) const;
1337
1338 // make the cell editable/readonly
1339 void SetReadOnly(int row, int col, bool isReadOnly = TRUE);
1340
1341 // ------ selections of blocks of cells
1342 //
1343 void SelectRow( int row, bool addToSelected = FALSE );
1344 void SelectCol( int col, bool addToSelected = FALSE );
1345
1346 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1347 bool addToSelected = FALSE );
1348
1349 void SelectBlock( const wxGridCellCoords& topLeft,
1350 const wxGridCellCoords& bottomRight,
1351 bool addToSelected = FALSE )
1352 { SelectBlock( topLeft.GetRow(), topLeft.GetCol(),
1353 bottomRight.GetRow(), bottomRight.GetCol(),
1354 addToSelected ); }
1355
1356 void SelectAll();
1357
1358 bool IsSelection();
1359
1360 // ------ deselection
1361 //
1362 void DeselectRow( int row );
1363 void DeselectCol( int col );
1364 void DeselectCell( int row, int col );
1365
1366 void ClearSelection();
1367
1368 bool IsInSelection( int row, int col );
1369
1370 bool IsInSelection( const wxGridCellCoords& coords )
1371 { return IsInSelection( coords.GetRow(), coords.GetCol() ); }
1372
1373
1374 // This function returns the rectangle that encloses the block of cells
1375 // limited by TopLeft and BottomRight cell in device coords and clipped
1376 // to the client size of the grid window.
1377 //
1378 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1379 const wxGridCellCoords & bottomRight );
1380
1381 // Access or update the selection fore/back colours
1382 wxColour GetSelectionBackground() const
1383 { return m_selectionBackground; }
1384 wxColour GetSelectionForeground() const
1385 { return m_selectionForeground; }
1386
1387 void SetSelectionBackground(const wxColour& c) { m_selectionBackground = c; }
1388 void SetSelectionForeground(const wxColour& c) { m_selectionForeground = c; }
1389
1390
1391 // Methods for a registry for mapping data types to Renderers/Editors
1392 void RegisterDataType(const wxString& typeName,
1393 wxGridCellRenderer* renderer,
1394 wxGridCellEditor* editor);
1395 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1396 wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1397 { return GetDefaultEditorForCell(c.GetRow(), c.GetCol()); }
1398 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1399 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1400 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1401
1402 // grid may occupy more space than needed for its rows/columns, this
1403 // function allows to set how big this extra space is
1404 void SetMargins(int extraWidth, int extraHeight)
1405 {
1406 m_extraWidth = extraWidth;
1407 m_extraHeight = extraHeight;
1408 }
1409
1410 // Accessors for component windows
1411 wxWindow* GetGridWindow() { return (wxWindow*)m_gridWin; }
1412 wxWindow* GetGridRowLabelWindow() { return (wxWindow*)m_rowLabelWin; }
1413 wxWindow* GetGridColLabelWindow() { return (wxWindow*)m_colLabelWin; }
1414 wxWindow* GetGridCornerLabelWindow() { return (wxWindow*)m_cornerLabelWin; }
1415
1416
1417
1418 // ------ For compatibility with previous wxGrid only...
1419 //
1420 // ************************************************
1421 // ** Don't use these in new code because they **
1422 // ** are liable to disappear in a future **
1423 // ** revision **
1424 // ************************************************
1425 //
1426
1427 wxGrid( wxWindow *parent,
1428 int x, int y, int w = -1, int h = -1,
1429 long style = wxWANTS_CHARS,
1430 const wxString& name = wxPanelNameStr )
1431 : wxScrolledWindow( parent, -1, wxPoint(x,y), wxSize(w,h),
1432 (style|wxWANTS_CHARS), name )
1433 {
1434 Create();
1435 }
1436
1437 void SetCellValue( const wxString& val, int row, int col )
1438 { SetCellValue( row, col, val ); }
1439
1440 void UpdateDimensions()
1441 { CalcDimensions(); }
1442
1443 int GetRows() { return GetNumberRows(); }
1444 int GetCols() { return GetNumberCols(); }
1445 int GetCursorRow() { return GetGridCursorRow(); }
1446 int GetCursorColumn() { return GetGridCursorCol(); }
1447
1448 int GetScrollPosX() { return 0; }
1449 int GetScrollPosY() { return 0; }
1450
1451 void SetScrollX( int WXUNUSED(x) ) { }
1452 void SetScrollY( int WXUNUSED(y) ) { }
1453
1454 void SetColumnWidth( int col, int width )
1455 { SetColSize( col, width ); }
1456
1457 int GetColumnWidth( int col )
1458 { return GetColSize( col ); }
1459
1460 void SetRowHeight( int row, int height )
1461 { SetRowSize( row, height ); }
1462
1463 // GetRowHeight() is below
1464
1465 int GetViewHeight() // returned num whole rows visible
1466 { return 0; }
1467
1468 int GetViewWidth() // returned num whole cols visible
1469 { return 0; }
1470
1471 void SetLabelSize( int orientation, int sz )
1472 {
1473 if ( orientation == wxHORIZONTAL )
1474 SetColLabelSize( sz );
1475 else
1476 SetRowLabelSize( sz );
1477 }
1478
1479 int GetLabelSize( int orientation )
1480 {
1481 if ( orientation == wxHORIZONTAL )
1482 return GetColLabelSize();
1483 else
1484 return GetRowLabelSize();
1485 }
1486
1487 void SetLabelAlignment( int orientation, int align )
1488 {
1489 if ( orientation == wxHORIZONTAL )
1490 SetColLabelAlignment( align, -1 );
1491 else
1492 SetRowLabelAlignment( align, -1 );
1493 }
1494
1495 int GetLabelAlignment( int orientation, int WXUNUSED(align) )
1496 {
1497 int h, v;
1498 if ( orientation == wxHORIZONTAL )
1499 {
1500 GetColLabelAlignment( &h, &v );
1501 return h;
1502 }
1503 else
1504 {
1505 GetRowLabelAlignment( &h, &v );
1506 return h;
1507 }
1508 }
1509
1510 void SetLabelValue( int orientation, const wxString& val, int pos )
1511 {
1512 if ( orientation == wxHORIZONTAL )
1513 SetColLabelValue( pos, val );
1514 else
1515 SetRowLabelValue( pos, val );
1516 }
1517
1518 wxString GetLabelValue( int orientation, int pos)
1519 {
1520 if ( orientation == wxHORIZONTAL )
1521 return GetColLabelValue( pos );
1522 else
1523 return GetRowLabelValue( pos );
1524 }
1525
1526 wxFont GetCellTextFont() const
1527 { return m_defaultCellAttr->GetFont(); }
1528
1529 wxFont GetCellTextFont(int WXUNUSED(row), int WXUNUSED(col)) const
1530 { return m_defaultCellAttr->GetFont(); }
1531
1532 void SetCellTextFont(const wxFont& fnt)
1533 { SetDefaultCellFont( fnt ); }
1534
1535 void SetCellTextFont(const wxFont& fnt, int row, int col)
1536 { SetCellFont( row, col, fnt ); }
1537
1538 void SetCellTextColour(const wxColour& val, int row, int col)
1539 { SetCellTextColour( row, col, val ); }
1540
1541 void SetCellTextColour(const wxColour& col)
1542 { SetDefaultCellTextColour( col ); }
1543
1544 void SetCellBackgroundColour(const wxColour& col)
1545 { SetDefaultCellBackgroundColour( col ); }
1546
1547 void SetCellBackgroundColour(const wxColour& colour, int row, int col)
1548 { SetCellBackgroundColour( row, col, colour ); }
1549
1550 bool GetEditable() { return IsEditable(); }
1551 void SetEditable( bool edit = TRUE ) { EnableEditing( edit ); }
1552 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
1553
1554 void SetEditInPlace(bool WXUNUSED(edit) = TRUE) { }
1555
1556 void SetCellAlignment( int align, int row, int col)
1557 { SetCellAlignment(row, col, align, wxALIGN_CENTER); }
1558 void SetCellAlignment( int WXUNUSED(align) ) {}
1559 void SetCellBitmap(wxBitmap *WXUNUSED(bitmap), int WXUNUSED(row), int WXUNUSED(col))
1560 { }
1561 void SetDividerPen(const wxPen& WXUNUSED(pen)) { }
1562 wxPen& GetDividerPen() const;
1563 void OnActivate(bool WXUNUSED(active)) {}
1564
1565 // ******** End of compatibility functions **********
1566
1567
1568
1569 // ------ control IDs
1570 enum { wxGRID_CELLCTRL = 2000,
1571 wxGRID_TOPCTRL };
1572
1573 // ------ control types
1574 enum { wxGRID_TEXTCTRL = 2100,
1575 wxGRID_CHECKBOX,
1576 wxGRID_CHOICE,
1577 wxGRID_COMBOBOX };
1578
1579 // overridden wxWindow methods
1580 virtual void Fit();
1581
1582 protected:
1583 virtual wxSize DoGetBestSize() const;
1584
1585 bool m_created;
1586
1587 wxGridWindow *m_gridWin;
1588 wxGridRowLabelWindow *m_rowLabelWin;
1589 wxGridColLabelWindow *m_colLabelWin;
1590 wxGridCornerLabelWindow *m_cornerLabelWin;
1591
1592 wxGridTableBase *m_table;
1593 bool m_ownTable;
1594
1595 int m_numRows;
1596 int m_numCols;
1597
1598 wxGridCellCoords m_currentCellCoords;
1599
1600 wxGridCellCoords m_selectingTopLeft;
1601 wxGridCellCoords m_selectingBottomRight;
1602 wxGridCellCoords m_selectingKeyboard;
1603 wxGridSelection *m_selection;
1604 wxColour m_selectionBackground;
1605 wxColour m_selectionForeground;
1606
1607 // NB: *never* access m_row/col arrays directly because they are created
1608 // on demand, *always* use accessor functions instead!
1609
1610 // init the m_rowHeights/Bottoms arrays with default values
1611 void InitRowHeights();
1612
1613 int m_defaultRowHeight;
1614 wxArrayInt m_rowHeights;
1615 wxArrayInt m_rowBottoms;
1616
1617 // init the m_colWidths/Rights arrays
1618 void InitColWidths();
1619
1620 int m_defaultColWidth;
1621 wxArrayInt m_colWidths;
1622 wxArrayInt m_colRights;
1623
1624 // get the col/row coords
1625 int GetColWidth(int col) const;
1626 int GetColLeft(int col) const;
1627 int GetColRight(int col) const;
1628
1629 // this function must be public for compatibility...
1630 public:
1631 int GetRowHeight(int row) const;
1632 protected:
1633
1634 int GetRowTop(int row) const;
1635 int GetRowBottom(int row) const;
1636
1637 int m_rowLabelWidth;
1638 int m_colLabelHeight;
1639
1640 // the size of the margin left to the right and bottom of the cell area
1641 int m_extraWidth,
1642 m_extraHeight;
1643
1644 wxColour m_labelBackgroundColour;
1645 wxColour m_labelTextColour;
1646 wxFont m_labelFont;
1647
1648 int m_rowLabelHorizAlign;
1649 int m_rowLabelVertAlign;
1650 int m_colLabelHorizAlign;
1651 int m_colLabelVertAlign;
1652
1653 bool m_defaultRowLabelValues;
1654 bool m_defaultColLabelValues;
1655
1656 wxColour m_gridLineColour;
1657 bool m_gridLinesEnabled;
1658 wxColour m_cellHighlightColour;
1659 int m_cellHighlightPenWidth;
1660 int m_cellHighlightROPenWidth;
1661
1662
1663 // common part of AutoSizeColumn/Row() and GetBestSize()
1664 int SetOrCalcColumnSizes(bool calcOnly, bool setAsMin = TRUE);
1665 int SetOrCalcRowSizes(bool calcOnly, bool setAsMin = TRUE);
1666
1667 // common part of AutoSizeColumn/Row()
1668 void AutoSizeColOrRow(int n, bool setAsMin, bool column /* or row? */);
1669
1670 // if a column has a minimal width, it will be the value for it in this
1671 // hash table
1672 wxHashTableLong m_colMinWidths,
1673 m_rowMinHeights;
1674
1675 // get the minimal width of the given column/row
1676 int GetColMinimalWidth(int col) const;
1677 int GetRowMinimalHeight(int col) const;
1678
1679 // do we have some place to store attributes in?
1680 bool CanHaveAttributes();
1681
1682 // returns the attribute we may modify in place: a new one if this cell
1683 // doesn't have any yet or the existing one if it does
1684 //
1685 // DecRef() must be called on the returned pointer, as usual
1686 wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const;
1687
1688 // cell attribute cache (currently we only cache 1, may be will do
1689 // more/better later)
1690 struct CachedAttr
1691 {
1692 int row, col;
1693 wxGridCellAttr *attr;
1694 } m_attrCache;
1695
1696 // invalidates the attribute cache
1697 void ClearAttrCache();
1698
1699 // adds an attribute to cache
1700 void CacheAttr(int row, int col, wxGridCellAttr *attr) const;
1701
1702 // looks for an attr in cache, returns TRUE if found
1703 bool LookupAttr(int row, int col, wxGridCellAttr **attr) const;
1704
1705 // looks for the attr in cache, if not found asks the table and caches the
1706 // result
1707 wxGridCellAttr *GetCellAttr(int row, int col) const;
1708 wxGridCellAttr *GetCellAttr(const wxGridCellCoords& coords )
1709 { return GetCellAttr( coords.GetRow(), coords.GetCol() ); }
1710
1711 // the default cell attr object for cells that don't have their own
1712 wxGridCellAttr* m_defaultCellAttr;
1713
1714
1715 bool m_inOnKeyDown;
1716 int m_batchCount;
1717
1718
1719 wxGridTypeRegistry* m_typeRegistry;
1720
1721 enum CursorMode
1722 {
1723 WXGRID_CURSOR_SELECT_CELL,
1724 WXGRID_CURSOR_RESIZE_ROW,
1725 WXGRID_CURSOR_RESIZE_COL,
1726 WXGRID_CURSOR_SELECT_ROW,
1727 WXGRID_CURSOR_SELECT_COL
1728 };
1729
1730 // this method not only sets m_cursorMode but also sets the correct cursor
1731 // for the given mode and, if captureMouse is not FALSE releases the mouse
1732 // if it was captured and captures it if it must be captured
1733 //
1734 // for this to work, you should always use it and not set m_cursorMode
1735 // directly!
1736 void ChangeCursorMode(CursorMode mode,
1737 wxWindow *win = (wxWindow *)NULL,
1738 bool captureMouse = TRUE);
1739
1740 wxWindow *m_winCapture; // the window which captured the mouse
1741 CursorMode m_cursorMode;
1742
1743 bool m_canDragRowSize;
1744 bool m_canDragColSize;
1745 bool m_canDragGridSize;
1746 int m_dragLastPos;
1747 int m_dragRowOrCol;
1748 bool m_isDragging;
1749 wxPoint m_startDragPos;
1750
1751 bool m_waitForSlowClick;
1752
1753 wxGridCellCoords m_selectionStart;
1754
1755 wxCursor m_rowResizeCursor;
1756 wxCursor m_colResizeCursor;
1757
1758 bool m_editable; // applies to whole grid
1759 bool m_cellEditCtrlEnabled; // is in-place edit currently shown?
1760
1761
1762 void Create();
1763 void Init();
1764 void CalcDimensions();
1765 void CalcWindowSizes();
1766 bool Redimension( wxGridTableMessage& );
1767
1768
1769 int SendEvent( const wxEventType, int row, int col, wxMouseEvent& );
1770 int SendEvent( const wxEventType, int row, int col );
1771 int SendEvent( const wxEventType type)
1772 {
1773 return SendEvent(type,
1774 m_currentCellCoords.GetRow(),
1775 m_currentCellCoords.GetCol());
1776 }
1777
1778 void OnPaint( wxPaintEvent& );
1779 void OnSize( wxSizeEvent& );
1780 void OnKeyDown( wxKeyEvent& );
1781 void OnKeyUp( wxKeyEvent& );
1782 void OnEraseBackground( wxEraseEvent& );
1783
1784
1785 void SetCurrentCell( const wxGridCellCoords& coords );
1786 void SetCurrentCell( int row, int col )
1787 { SetCurrentCell( wxGridCellCoords(row, col) ); }
1788
1789 void HighlightBlock( int topRow, int leftCol, int bottomRow, int rightCol );
1790
1791 void HighlightBlock( const wxGridCellCoords& topLeft,
1792 const wxGridCellCoords& bottomRight )
1793 { HighlightBlock( topLeft.GetRow(), topLeft.GetCol(),
1794 bottomRight.GetRow(), bottomRight.GetCol() ); }
1795
1796 // ------ functions to get/send data (see also public functions)
1797 //
1798 bool GetModelValues();
1799 bool SetModelValues();
1800
1801 friend class wxGridSelection;
1802
1803 DECLARE_DYNAMIC_CLASS( wxGrid )
1804 DECLARE_EVENT_TABLE()
1805 };
1806
1807 // ----------------------------------------------------------------------------
1808 // Grid event class and event types
1809 // ----------------------------------------------------------------------------
1810
1811 class WXDLLEXPORT wxGridEvent : public wxNotifyEvent
1812 {
1813 public:
1814 wxGridEvent()
1815 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
1816 m_selecting(0), m_control(0), m_meta(0), m_shift(0), m_alt(0)
1817 {
1818 }
1819
1820 wxGridEvent(int id, wxEventType type, wxObject* obj,
1821 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = TRUE,
1822 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1823
1824 virtual int GetRow() { return m_row; }
1825 virtual int GetCol() { return m_col; }
1826 wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
1827 bool Selecting() { return m_selecting; }
1828 bool ControlDown() { return m_control; }
1829 bool MetaDown() { return m_meta; }
1830 bool ShiftDown() { return m_shift; }
1831 bool AltDown() { return m_alt; }
1832
1833 protected:
1834 int m_row;
1835 int m_col;
1836 int m_x;
1837 int m_y;
1838 bool m_selecting;
1839 bool m_control;
1840 bool m_meta;
1841 bool m_shift;
1842 bool m_alt;
1843
1844 DECLARE_DYNAMIC_CLASS(wxGridEvent)
1845 };
1846
1847 class WXDLLEXPORT wxGridSizeEvent : public wxNotifyEvent
1848 {
1849 public:
1850 wxGridSizeEvent()
1851 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
1852 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1853 {
1854 }
1855
1856 wxGridSizeEvent(int id, wxEventType type, wxObject* obj,
1857 int rowOrCol=-1, int x=-1, int y=-1,
1858 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1859
1860 int GetRowOrCol() { return m_rowOrCol; }
1861 wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
1862 bool ControlDown() { return m_control; }
1863 bool MetaDown() { return m_meta; }
1864 bool ShiftDown() { return m_shift; }
1865 bool AltDown() { return m_alt; }
1866
1867 protected:
1868 int m_rowOrCol;
1869 int m_x;
1870 int m_y;
1871 bool m_control;
1872 bool m_meta;
1873 bool m_shift;
1874 bool m_alt;
1875
1876 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent)
1877 };
1878
1879
1880 class WXDLLEXPORT wxGridRangeSelectEvent : public wxNotifyEvent
1881 {
1882 public:
1883 wxGridRangeSelectEvent()
1884 : wxNotifyEvent()
1885 {
1886 m_topLeft = wxGridNoCellCoords;
1887 m_bottomRight = wxGridNoCellCoords;
1888 m_selecting = FALSE;
1889 m_control = FALSE;
1890 m_meta = FALSE;
1891 m_shift = FALSE;
1892 m_alt = FALSE;
1893 }
1894
1895 wxGridRangeSelectEvent(int id, wxEventType type, wxObject* obj,
1896 const wxGridCellCoords& topLeft,
1897 const wxGridCellCoords& bottomRight,
1898 bool sel = TRUE,
1899 bool control=FALSE, bool shift=FALSE,
1900 bool alt=FALSE, bool meta=FALSE);
1901
1902 wxGridCellCoords GetTopLeftCoords() { return m_topLeft; }
1903 wxGridCellCoords GetBottomRightCoords() { return m_bottomRight; }
1904 int GetTopRow() { return m_topLeft.GetRow(); }
1905 int GetBottomRow() { return m_bottomRight.GetRow(); }
1906 int GetLeftCol() { return m_topLeft.GetCol(); }
1907 int GetRightCol() { return m_bottomRight.GetCol(); }
1908 bool Selecting() { return m_selecting; }
1909 bool ControlDown() { return m_control; }
1910 bool MetaDown() { return m_meta; }
1911 bool ShiftDown() { return m_shift; }
1912 bool AltDown() { return m_alt; }
1913
1914 protected:
1915 wxGridCellCoords m_topLeft;
1916 wxGridCellCoords m_bottomRight;
1917 bool m_selecting;
1918 bool m_control;
1919 bool m_meta;
1920 bool m_shift;
1921 bool m_alt;
1922
1923 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent)
1924 };
1925
1926
1927 class WXDLLEXPORT wxGridEditorCreatedEvent : public wxCommandEvent {
1928 public:
1929 wxGridEditorCreatedEvent()
1930 : wxCommandEvent()
1931 {
1932 m_row = 0;
1933 m_col = 0;
1934 m_ctrl = NULL;
1935 }
1936
1937 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
1938 int row, int col, wxControl* ctrl);
1939
1940 int GetRow() { return m_row; }
1941 int GetCol() { return m_col; }
1942 wxControl* GetControl() { return m_ctrl; }
1943 void SetRow(int row) { m_row = row; }
1944 void SetCol(int col) { m_col = col; }
1945 void SetControl(wxControl* ctrl) { m_ctrl = ctrl; }
1946
1947 private:
1948 int m_row;
1949 int m_col;
1950 wxControl* m_ctrl;
1951
1952 DECLARE_DYNAMIC_CLASS(wxGridEditorCreatedEvent)
1953 };
1954
1955
1956 BEGIN_DECLARE_EVENT_TYPES()
1957 DECLARE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_CLICK, 1580)
1958 DECLARE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_CLICK, 1581)
1959 DECLARE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_DCLICK, 1582)
1960 DECLARE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_DCLICK, 1583)
1961 DECLARE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_CLICK, 1584)
1962 DECLARE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_CLICK, 1585)
1963 DECLARE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_DCLICK, 1586)
1964 DECLARE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_DCLICK, 1587)
1965 DECLARE_EVENT_TYPE(wxEVT_GRID_ROW_SIZE, 1588)
1966 DECLARE_EVENT_TYPE(wxEVT_GRID_COL_SIZE, 1589)
1967 DECLARE_EVENT_TYPE(wxEVT_GRID_RANGE_SELECT, 1590)
1968 DECLARE_EVENT_TYPE(wxEVT_GRID_CELL_CHANGE, 1591)
1969 DECLARE_EVENT_TYPE(wxEVT_GRID_SELECT_CELL, 1592)
1970 DECLARE_EVENT_TYPE(wxEVT_GRID_EDITOR_SHOWN, 1593)
1971 DECLARE_EVENT_TYPE(wxEVT_GRID_EDITOR_HIDDEN, 1594)
1972 DECLARE_EVENT_TYPE(wxEVT_GRID_EDITOR_CREATED, 1595)
1973 END_DECLARE_EVENT_TYPES()
1974
1975
1976 typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&);
1977 typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&);
1978 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&);
1979 typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction)(wxGridEditorCreatedEvent&);
1980
1981 #define EVT_GRID_CELL_LEFT_CLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1982 #define EVT_GRID_CELL_RIGHT_CLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1983 #define EVT_GRID_CELL_LEFT_DCLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1984 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1985 #define EVT_GRID_LABEL_LEFT_CLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1986 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1987 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1988 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1989 #define EVT_GRID_ROW_SIZE(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL ),
1990 #define EVT_GRID_COL_SIZE(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL ),
1991 #define EVT_GRID_RANGE_SELECT(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL ),
1992 #define EVT_GRID_CELL_CHANGE(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1993 #define EVT_GRID_SELECT_CELL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1994 #define EVT_GRID_EDITOR_SHOWN(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_EDITOR_SHOWN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1995 #define EVT_GRID_EDITOR_HIDDEN(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_EDITOR_HIDDEN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1996 #define EVT_GRID_EDITOR_CREATED(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_EDITOR_CREATED, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEditorCreatedEventFunction) &fn, NULL ),
1997
1998
1999 #if 0 // TODO: implement these ? others ?
2000
2001 extern const int wxEVT_GRID_CREATE_CELL;
2002 extern const int wxEVT_GRID_CHANGE_LABELS;
2003 extern const int wxEVT_GRID_CHANGE_SEL_LABEL;
2004
2005 #define EVT_GRID_CREATE_CELL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
2006 #define EVT_GRID_CHANGE_LABELS(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
2007 #define EVT_GRID_CHANGE_SEL_LABEL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
2008
2009 #endif
2010
2011 #endif // #ifndef __WXGRID_H__
2012
2013 #endif // ifndef wxUSE_NEW_GRID