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: Santiago Palacios
8 // Copyright: (c) Michael Bedward
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GENERIC_GRID_H_
13 #define _WX_GENERIC_GRID_H_
19 #include "wx/scrolwin.h"
21 // ----------------------------------------------------------------------------
23 // ----------------------------------------------------------------------------
25 extern WXDLLIMPEXP_DATA_ADV(const char) wxGridNameStr
[];
27 // Default parameters for wxGrid
29 #define WXGRID_DEFAULT_NUMBER_ROWS 10
30 #define WXGRID_DEFAULT_NUMBER_COLS 10
31 #if defined(__WXMSW__) || defined(__WXGTK20__)
32 #define WXGRID_DEFAULT_ROW_HEIGHT 25
34 #define WXGRID_DEFAULT_ROW_HEIGHT 30
36 #define WXGRID_DEFAULT_COL_WIDTH 80
37 #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32
38 #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82
39 #define WXGRID_LABEL_EDGE_ZONE 2
40 #define WXGRID_MIN_ROW_HEIGHT 15
41 #define WXGRID_MIN_COL_WIDTH 15
42 #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16
44 // type names for grid table values
45 #define wxGRID_VALUE_STRING _T("string")
46 #define wxGRID_VALUE_BOOL _T("bool")
47 #define wxGRID_VALUE_NUMBER _T("long")
48 #define wxGRID_VALUE_FLOAT _T("double")
49 #define wxGRID_VALUE_CHOICE _T("choice")
51 #define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING
52 #define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER
54 // magic constant which tells (to some functions) to automatically calculate
55 // the appropriate size
56 #define wxGRID_AUTOSIZE (-1)
58 // many wxGrid methods work either with columns or rows, this enum is used for
59 // the parameter indicating which one should it be
66 // ----------------------------------------------------------------------------
67 // forward declarations
68 // ----------------------------------------------------------------------------
70 class WXDLLIMPEXP_FWD_ADV wxGrid
;
71 class WXDLLIMPEXP_FWD_ADV wxGridCellAttr
;
72 class WXDLLIMPEXP_FWD_ADV wxGridCellAttrProviderData
;
73 class WXDLLIMPEXP_FWD_ADV wxGridColLabelWindow
;
74 class WXDLLIMPEXP_FWD_ADV wxGridCornerLabelWindow
;
75 class WXDLLIMPEXP_FWD_ADV wxGridRowLabelWindow
;
76 class WXDLLIMPEXP_FWD_ADV wxGridWindow
;
77 class WXDLLIMPEXP_FWD_ADV wxGridTypeRegistry
;
78 class WXDLLIMPEXP_FWD_ADV wxGridSelection
;
80 class WXDLLIMPEXP_FWD_CORE wxHeaderCtrl
;
81 class WXDLLIMPEXP_FWD_CORE wxCheckBox
;
82 class WXDLLIMPEXP_FWD_CORE wxComboBox
;
83 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
85 class WXDLLIMPEXP_FWD_CORE wxSpinCtrl
;
88 class wxGridOperations
;
89 class wxGridRowOperations
;
90 class wxGridColumnOperations
;
91 class wxGridDirectionOperations
;
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
97 #define wxSafeIncRef(p) if ( p ) (p)->IncRef()
98 #define wxSafeDecRef(p) if ( p ) (p)->DecRef()
100 // ----------------------------------------------------------------------------
101 // wxGridCellWorker: common base class for wxGridCellRenderer and
104 // NB: this is more an implementation convenience than a design issue, so this
105 // class is not documented and is not public at all
106 // ----------------------------------------------------------------------------
108 class WXDLLIMPEXP_ADV wxGridCellWorker
: public wxClientDataContainer
111 wxGridCellWorker() { m_nRef
= 1; }
113 // this class is ref counted: it is created with ref count of 1, so
114 // calling DecRef() once will delete it. Calling IncRef() allows to lock
115 // it until the matching DecRef() is called
116 void IncRef() { m_nRef
++; }
117 void DecRef() { if ( --m_nRef
== 0 ) delete this; }
119 // interpret renderer parameters: arbitrary string whose interpretatin is
120 // left to the derived classes
121 virtual void SetParameters(const wxString
& params
);
124 // virtual dtor for any base class - private because only DecRef() can
126 virtual ~wxGridCellWorker();
131 // suppress the stupid gcc warning about the class having private dtor and
133 friend class wxGridCellWorkerDummyFriend
;
136 // ----------------------------------------------------------------------------
137 // wxGridCellRenderer: this class is responsible for actually drawing the cell
138 // in the grid. You may pass it to the wxGridCellAttr (below) to change the
139 // format of one given cell or to wxGrid::SetDefaultRenderer() to change the
140 // view of all cells. This is an ABC, you will normally use one of the
141 // predefined derived classes or derive your own class from it.
142 // ----------------------------------------------------------------------------
144 class WXDLLIMPEXP_ADV wxGridCellRenderer
: public wxGridCellWorker
147 // draw the given cell on the provided DC inside the given rectangle
148 // using the style specified by the attribute and the default or selected
149 // state corresponding to the isSelected value.
151 // this pure virtual function has a default implementation which will
152 // prepare the DC using the given attribute: it will draw the rectangle
153 // with the bg colour from attr and set the text colour and font
154 virtual void Draw(wxGrid
& grid
,
155 wxGridCellAttr
& attr
,
159 bool isSelected
) = 0;
161 // get the preferred size of the cell for its contents
162 virtual wxSize
GetBestSize(wxGrid
& grid
,
163 wxGridCellAttr
& attr
,
165 int row
, int col
) = 0;
167 // create a new object which is the copy of this one
168 virtual wxGridCellRenderer
*Clone() const = 0;
171 // the default renderer for the cells containing string data
172 class WXDLLIMPEXP_ADV wxGridCellStringRenderer
: public wxGridCellRenderer
176 virtual void Draw(wxGrid
& grid
,
177 wxGridCellAttr
& attr
,
183 // return the string extent
184 virtual wxSize
GetBestSize(wxGrid
& grid
,
185 wxGridCellAttr
& attr
,
189 virtual wxGridCellRenderer
*Clone() const
190 { return new wxGridCellStringRenderer
; }
193 // set the text colours before drawing
194 void SetTextColoursAndFont(const wxGrid
& grid
,
195 const wxGridCellAttr
& attr
,
199 // calc the string extent for given string/font
200 wxSize
DoGetBestSize(const wxGridCellAttr
& attr
,
202 const wxString
& text
);
205 // the default renderer for the cells containing numeric (long) data
206 class WXDLLIMPEXP_ADV wxGridCellNumberRenderer
: public wxGridCellStringRenderer
209 // draw the string right aligned
210 virtual void Draw(wxGrid
& grid
,
211 wxGridCellAttr
& attr
,
217 virtual wxSize
GetBestSize(wxGrid
& grid
,
218 wxGridCellAttr
& attr
,
222 virtual wxGridCellRenderer
*Clone() const
223 { return new wxGridCellNumberRenderer
; }
226 wxString
GetString(const wxGrid
& grid
, int row
, int col
);
229 class WXDLLIMPEXP_ADV wxGridCellFloatRenderer
: public wxGridCellStringRenderer
232 wxGridCellFloatRenderer(int width
= -1, int precision
= -1);
234 // get/change formatting parameters
235 int GetWidth() const { return m_width
; }
236 void SetWidth(int width
) { m_width
= width
; m_format
.clear(); }
237 int GetPrecision() const { return m_precision
; }
238 void SetPrecision(int precision
) { m_precision
= precision
; m_format
.clear(); }
240 // draw the string right aligned with given width/precision
241 virtual void Draw(wxGrid
& grid
,
242 wxGridCellAttr
& attr
,
248 virtual wxSize
GetBestSize(wxGrid
& grid
,
249 wxGridCellAttr
& attr
,
253 // parameters string format is "width[,precision]"
254 virtual void SetParameters(const wxString
& params
);
256 virtual wxGridCellRenderer
*Clone() const;
259 wxString
GetString(const wxGrid
& grid
, int row
, int col
);
262 // formatting parameters
269 // renderer for boolean fields
270 class WXDLLIMPEXP_ADV wxGridCellBoolRenderer
: public wxGridCellRenderer
273 // draw a check mark or nothing
274 virtual void Draw(wxGrid
& grid
,
275 wxGridCellAttr
& attr
,
281 // return the checkmark size
282 virtual wxSize
GetBestSize(wxGrid
& grid
,
283 wxGridCellAttr
& attr
,
287 virtual wxGridCellRenderer
*Clone() const
288 { return new wxGridCellBoolRenderer
; }
291 static wxSize ms_sizeCheckMark
;
294 // ----------------------------------------------------------------------------
295 // wxGridCellEditor: This class is responsible for providing and manipulating
296 // the in-place edit controls for the grid. Instances of wxGridCellEditor
297 // (actually, instances of derived classes since it is an ABC) can be
298 // associated with the cell attributes for individual cells, rows, columns, or
299 // even for the entire grid.
300 // ----------------------------------------------------------------------------
302 class WXDLLIMPEXP_ADV wxGridCellEditor
: public wxGridCellWorker
307 bool IsCreated() { return m_control
!= NULL
; }
308 wxControl
* GetControl() { return m_control
; }
309 void SetControl(wxControl
* control
) { m_control
= control
; }
311 wxGridCellAttr
* GetCellAttr() { return m_attr
; }
312 void SetCellAttr(wxGridCellAttr
* attr
) { m_attr
= attr
; }
314 // Creates the actual edit control
315 virtual void Create(wxWindow
* parent
,
317 wxEvtHandler
* evtHandler
) = 0;
319 // Size and position the edit control
320 virtual void SetSize(const wxRect
& rect
);
322 // Show or hide the edit control, use the specified attributes to set
323 // colours/fonts for it
324 virtual void Show(bool show
, wxGridCellAttr
*attr
= NULL
);
326 // Draws the part of the cell not occupied by the control: the base class
327 // version just fills it with background colour from the attribute
328 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
331 // The methods called by wxGrid when a cell is edited: first BeginEdit() is
332 // called, then EndEdit() is and if it returns true and if the change is
333 // not vetoed by a user-defined event handler, finally ApplyEdit() is called
335 // Fetch the value from the table and prepare the edit control
336 // to begin editing. Set the focus to the edit control.
337 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
) = 0;
339 // Returns false if nothing changed, otherwise returns true and return the
340 // new value in its string form in the newval output parameter.
342 // This should also store the new value in its real type internally so that
343 // it could be used by ApplyEdit().
344 virtual bool EndEdit(const wxString
& oldval
, wxString
*newval
) = 0;
346 // Complete the editing of the current cell by storing the value saved by
347 // the previous call to EndEdit() in the grid
348 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
) = 0;
351 // Reset the value in the control back to its starting value
352 virtual void Reset() = 0;
354 // return true to allow the given key to start editing: the base class
355 // version only checks that the event has no modifiers. The derived
356 // classes are supposed to do "if ( base::IsAcceptedKey() && ... )" in
357 // their IsAcceptedKey() implementation, although, of course, it is not a
358 // mandatory requirment.
360 // NB: if the key is F2 (special), editing will always start and this
361 // method will not be called at all (but StartingKey() will)
362 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
364 // If the editor is enabled by pressing keys on the grid, this will be
365 // called to let the editor do something about that first key if desired
366 virtual void StartingKey(wxKeyEvent
& event
);
368 // if the editor is enabled by clicking on the cell, this method will be
370 virtual void StartingClick();
372 // Some types of controls on some platforms may need some help
373 // with the Return key.
374 virtual void HandleReturn(wxKeyEvent
& event
);
377 virtual void Destroy();
379 // create a new object which is the copy of this one
380 virtual wxGridCellEditor
*Clone() const = 0;
382 // added GetValue so we can get the value which is in the control
383 virtual wxString
GetValue() const = 0;
386 // the dtor is private because only DecRef() can delete us
387 virtual ~wxGridCellEditor();
389 // the control we show on screen
390 wxControl
* m_control
;
392 // a temporary pointer to the attribute being edited
393 wxGridCellAttr
* m_attr
;
395 // if we change the colours/font of the control from the default ones, we
396 // must restore the default later and we save them here between calls to
397 // Show(true) and Show(false)
402 // suppress the stupid gcc warning about the class having private dtor and
404 friend class wxGridCellEditorDummyFriend
;
406 DECLARE_NO_COPY_CLASS(wxGridCellEditor
)
411 // the editor for string/text data
412 class WXDLLIMPEXP_ADV wxGridCellTextEditor
: public wxGridCellEditor
415 wxGridCellTextEditor();
417 virtual void Create(wxWindow
* parent
,
419 wxEvtHandler
* evtHandler
);
420 virtual void SetSize(const wxRect
& rect
);
422 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
424 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
425 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
426 virtual bool EndEdit(const wxString
& oldval
, wxString
*newval
);
427 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
);
429 virtual void Reset();
430 virtual void StartingKey(wxKeyEvent
& event
);
431 virtual void HandleReturn(wxKeyEvent
& event
);
433 // parameters string format is "max_width"
434 virtual void SetParameters(const wxString
& params
);
436 virtual wxGridCellEditor
*Clone() const
437 { return new wxGridCellTextEditor
; }
439 // added GetValue so we can get the value which is in the control
440 virtual wxString
GetValue() const;
443 wxTextCtrl
*Text() const { return (wxTextCtrl
*)m_control
; }
445 // parts of our virtual functions reused by the derived classes
446 void DoCreate(wxWindow
* parent
, wxWindowID id
, wxEvtHandler
* evtHandler
,
448 void DoBeginEdit(const wxString
& startValue
);
449 void DoReset(const wxString
& startValue
);
452 size_t m_maxChars
; // max number of chars allowed
455 DECLARE_NO_COPY_CLASS(wxGridCellTextEditor
)
458 // the editor for numeric (long) data
459 class WXDLLIMPEXP_ADV wxGridCellNumberEditor
: public wxGridCellTextEditor
462 // allows to specify the range - if min == max == -1, no range checking is
464 wxGridCellNumberEditor(int min
= -1, int max
= -1);
466 virtual void Create(wxWindow
* parent
,
468 wxEvtHandler
* evtHandler
);
470 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
471 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
472 virtual bool EndEdit(const wxString
& oldval
, wxString
*newval
);
473 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
);
475 virtual void Reset();
476 virtual void StartingKey(wxKeyEvent
& event
);
478 // parameters string format is "min,max"
479 virtual void SetParameters(const wxString
& params
);
481 virtual wxGridCellEditor
*Clone() const
482 { return new wxGridCellNumberEditor(m_min
, m_max
); }
484 // added GetValue so we can get the value which is in the control
485 virtual wxString
GetValue() const;
489 wxSpinCtrl
*Spin() const { return (wxSpinCtrl
*)m_control
; }
492 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
493 bool HasRange() const
496 return m_min
!= m_max
;
502 // string representation of our value
503 wxString
GetString() const
504 { return wxString::Format(_T("%ld"), m_value
); }
512 DECLARE_NO_COPY_CLASS(wxGridCellNumberEditor
)
515 // the editor for floating point numbers (double) data
516 class WXDLLIMPEXP_ADV wxGridCellFloatEditor
: public wxGridCellTextEditor
519 wxGridCellFloatEditor(int width
= -1, int precision
= -1);
521 virtual void Create(wxWindow
* parent
,
523 wxEvtHandler
* evtHandler
);
525 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
526 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
527 virtual bool EndEdit(const wxString
& oldval
, wxString
*newval
);
528 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
);
530 virtual void Reset();
531 virtual void StartingKey(wxKeyEvent
& event
);
533 virtual wxGridCellEditor
*Clone() const
534 { return new wxGridCellFloatEditor(m_width
, m_precision
); }
536 // parameters string format is "width,precision"
537 virtual void SetParameters(const wxString
& params
);
540 // string representation of our value
541 wxString
GetString() const;
548 DECLARE_NO_COPY_CLASS(wxGridCellFloatEditor
)
551 #endif // wxUSE_TEXTCTRL
555 // the editor for boolean data
556 class WXDLLIMPEXP_ADV wxGridCellBoolEditor
: public wxGridCellEditor
559 wxGridCellBoolEditor() { }
561 virtual void Create(wxWindow
* parent
,
563 wxEvtHandler
* evtHandler
);
565 virtual void SetSize(const wxRect
& rect
);
566 virtual void Show(bool show
, wxGridCellAttr
*attr
= NULL
);
568 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
569 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
570 virtual bool EndEdit(const wxString
& oldval
, wxString
*newval
);
571 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
);
573 virtual void Reset();
574 virtual void StartingClick();
575 virtual void StartingKey(wxKeyEvent
& event
);
577 virtual wxGridCellEditor
*Clone() const
578 { return new wxGridCellBoolEditor
; }
580 // added GetValue so we can get the value which is in the control, see
581 // also UseStringValues()
582 virtual wxString
GetValue() const;
584 // set the string values returned by GetValue() for the true and false
585 // states, respectively
586 static void UseStringValues(const wxString
& valueTrue
= _T("1"),
587 const wxString
& valueFalse
= wxEmptyString
);
589 // return true if the given string is equal to the string representation of
590 // true value which we currently use
591 static bool IsTrueValue(const wxString
& value
);
594 wxCheckBox
*CBox() const { return (wxCheckBox
*)m_control
; }
599 static wxString ms_stringValues
[2];
601 DECLARE_NO_COPY_CLASS(wxGridCellBoolEditor
)
604 #endif // wxUSE_CHECKBOX
608 // the editor for string data allowing to choose from the list of strings
609 class WXDLLIMPEXP_ADV wxGridCellChoiceEditor
: public wxGridCellEditor
612 // if !allowOthers, user can't type a string not in choices array
613 wxGridCellChoiceEditor(size_t count
= 0,
614 const wxString choices
[] = NULL
,
615 bool allowOthers
= false);
616 wxGridCellChoiceEditor(const wxArrayString
& choices
,
617 bool allowOthers
= false);
619 virtual void Create(wxWindow
* parent
,
621 wxEvtHandler
* evtHandler
);
623 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
625 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
626 virtual bool EndEdit(const wxString
& oldval
, wxString
*newval
);
627 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
);
629 virtual void Reset();
631 // parameters string format is "item1[,item2[...,itemN]]"
632 virtual void SetParameters(const wxString
& params
);
634 virtual wxGridCellEditor
*Clone() const;
636 // added GetValue so we can get the value which is in the control
637 virtual wxString
GetValue() const;
640 wxComboBox
*Combo() const { return (wxComboBox
*)m_control
; }
643 wxArrayString m_choices
;
646 DECLARE_NO_COPY_CLASS(wxGridCellChoiceEditor
)
649 #endif // wxUSE_COMBOBOX
651 // ----------------------------------------------------------------------------
652 // wxGridCellAttr: this class can be used to alter the cells appearance in
653 // the grid by changing their colour/font/... from default. An object of this
654 // class may be returned by wxGridTable::GetAttr().
655 // ----------------------------------------------------------------------------
657 class WXDLLIMPEXP_ADV wxGridCellAttr
: public wxClientDataContainer
671 wxGridCellAttr(wxGridCellAttr
*attrDefault
= NULL
)
675 // MB: args used to be 0,0 here but wxALIGN_LEFT is 0
676 SetAlignment(-1, -1);
679 // VZ: considering the number of members wxGridCellAttr has now, this ctor
680 // seems to be pretty useless... may be we should just remove it?
681 wxGridCellAttr(const wxColour
& colText
,
682 const wxColour
& colBack
,
686 : m_colText(colText
), m_colBack(colBack
), m_font(font
)
689 SetAlignment(hAlign
, vAlign
);
692 // creates a new copy of this object
693 wxGridCellAttr
*Clone() const;
694 void MergeWith(wxGridCellAttr
*mergefrom
);
696 // this class is ref counted: it is created with ref count of 1, so
697 // calling DecRef() once will delete it. Calling IncRef() allows to lock
698 // it until the matching DecRef() is called
699 void IncRef() { m_nRef
++; }
700 void DecRef() { if ( --m_nRef
== 0 ) delete this; }
703 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
704 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
705 void SetFont(const wxFont
& font
) { m_font
= font
; }
706 void SetAlignment(int hAlign
, int vAlign
)
711 void SetSize(int num_rows
, int num_cols
);
712 void SetOverflow(bool allow
= true)
713 { m_overflow
= allow
? Overflow
: SingleCell
; }
714 void SetReadOnly(bool isReadOnly
= true)
715 { m_isReadOnly
= isReadOnly
? ReadOnly
: ReadWrite
; }
717 // takes ownership of the pointer
718 void SetRenderer(wxGridCellRenderer
*renderer
)
719 { wxSafeDecRef(m_renderer
); m_renderer
= renderer
; }
720 void SetEditor(wxGridCellEditor
* editor
)
721 { wxSafeDecRef(m_editor
); m_editor
= editor
; }
723 void SetKind(wxAttrKind kind
) { m_attrkind
= kind
; }
726 bool HasTextColour() const { return m_colText
.Ok(); }
727 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
728 bool HasFont() const { return m_font
.Ok(); }
729 bool HasAlignment() const { return (m_hAlign
!= -1 || m_vAlign
!= -1); }
730 bool HasRenderer() const { return m_renderer
!= NULL
; }
731 bool HasEditor() const { return m_editor
!= NULL
; }
732 bool HasReadWriteMode() const { return m_isReadOnly
!= Unset
; }
733 bool HasOverflowMode() const { return m_overflow
!= UnsetOverflow
; }
734 bool HasSize() const { return m_sizeRows
!= 1 || m_sizeCols
!= 1; }
736 const wxColour
& GetTextColour() const;
737 const wxColour
& GetBackgroundColour() const;
738 const wxFont
& GetFont() const;
739 void GetAlignment(int *hAlign
, int *vAlign
) const;
740 void GetSize(int *num_rows
, int *num_cols
) const;
741 bool GetOverflow() const
742 { return m_overflow
!= SingleCell
; }
743 wxGridCellRenderer
*GetRenderer(const wxGrid
* grid
, int row
, int col
) const;
744 wxGridCellEditor
*GetEditor(const wxGrid
* grid
, int row
, int col
) const;
746 bool IsReadOnly() const { return m_isReadOnly
== wxGridCellAttr::ReadOnly
; }
748 wxAttrKind
GetKind() { return m_attrkind
; }
750 void SetDefAttr(wxGridCellAttr
* defAttr
) { m_defGridAttr
= defAttr
; }
753 // the dtor is private because only DecRef() can delete us
754 virtual ~wxGridCellAttr()
756 wxSafeDecRef(m_renderer
);
757 wxSafeDecRef(m_editor
);
768 enum wxAttrOverflowMode
775 // the common part of all ctors
776 void Init(wxGridCellAttr
*attrDefault
= NULL
);
779 // the ref count - when it goes to 0, we die
790 wxAttrOverflowMode m_overflow
;
792 wxGridCellRenderer
* m_renderer
;
793 wxGridCellEditor
* m_editor
;
794 wxGridCellAttr
* m_defGridAttr
;
796 wxAttrReadMode m_isReadOnly
;
798 wxAttrKind m_attrkind
;
800 // use Clone() instead
801 DECLARE_NO_COPY_CLASS(wxGridCellAttr
)
803 // suppress the stupid gcc warning about the class having private dtor and
805 friend class wxGridCellAttrDummyFriend
;
808 // ----------------------------------------------------------------------------
809 // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
811 // ----------------------------------------------------------------------------
813 // implementation note: we separate it from wxGridTableBase because we wish to
814 // avoid deriving a new table class if possible, and sometimes it will be
815 // enough to just derive another wxGridCellAttrProvider instead
817 // the default implementation is reasonably efficient for the generic case,
818 // but you might still wish to implement your own for some specific situations
819 // if you have performance problems with the stock one
820 class WXDLLIMPEXP_ADV wxGridCellAttrProvider
: public wxClientDataContainer
823 wxGridCellAttrProvider();
824 virtual ~wxGridCellAttrProvider();
826 // DecRef() must be called on the returned pointer
827 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
828 wxGridCellAttr::wxAttrKind kind
) const;
830 // all these functions take ownership of the pointer, don't call DecRef()
832 virtual void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
833 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
834 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
836 // these functions must be called whenever some rows/cols are deleted
837 // because the internal data must be updated then
838 void UpdateAttrRows( size_t pos
, int numRows
);
839 void UpdateAttrCols( size_t pos
, int numCols
);
844 wxGridCellAttrProviderData
*m_data
;
846 DECLARE_NO_COPY_CLASS(wxGridCellAttrProvider
)
849 // ----------------------------------------------------------------------------
850 // wxGridCellCoords: location of a cell in the grid
851 // ----------------------------------------------------------------------------
853 class WXDLLIMPEXP_ADV wxGridCellCoords
856 wxGridCellCoords() { m_row
= m_col
= -1; }
857 wxGridCellCoords( int r
, int c
) { m_row
= r
; m_col
= c
; }
859 // default copy ctor is ok
861 int GetRow() const { return m_row
; }
862 void SetRow( int n
) { m_row
= n
; }
863 int GetCol() const { return m_col
; }
864 void SetCol( int n
) { m_col
= n
; }
865 void Set( int row
, int col
) { m_row
= row
; m_col
= col
; }
867 wxGridCellCoords
& operator=( const wxGridCellCoords
& other
)
869 if ( &other
!= this )
877 bool operator==( const wxGridCellCoords
& other
) const
879 return (m_row
== other
.m_row
&& m_col
== other
.m_col
);
882 bool operator!=( const wxGridCellCoords
& other
) const
884 return (m_row
!= other
.m_row
|| m_col
!= other
.m_col
);
887 bool operator!() const
889 return (m_row
== -1 && m_col
== -1 );
898 // For comparisons...
900 extern WXDLLIMPEXP_ADV wxGridCellCoords wxGridNoCellCoords
;
901 extern WXDLLIMPEXP_ADV wxRect wxGridNoCellRect
;
903 // An array of cell coords...
905 WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellCoords
, wxGridCellCoordsArray
,
906 class WXDLLIMPEXP_ADV
);
908 // ----------------------------------------------------------------------------
909 // Grid table classes
910 // ----------------------------------------------------------------------------
912 // the abstract base class
913 class WXDLLIMPEXP_ADV wxGridTableBase
: public wxObject
,
914 public wxClientDataContainer
918 virtual ~wxGridTableBase();
920 // You must override these functions in a derived table class
923 // return the number of rows and columns in this table
924 virtual int GetNumberRows() = 0;
925 virtual int GetNumberCols() = 0;
927 // the methods above are unfortunately non-const even though they should
928 // have been const -- but changing it now is not possible any longer as it
929 // would break the existing code overriding them, so instead we provide
930 // these const synonyms which can be used from const-correct code
931 int GetRowsCount() const
932 { return const_cast<wxGridTableBase
*>(this)->GetNumberRows(); }
933 int GetColsCount() const
934 { return const_cast<wxGridTableBase
*>(this)->GetNumberCols(); }
937 virtual bool IsEmptyCell( int row
, int col
)
939 return GetValue(row
, col
).empty();
942 bool IsEmpty(const wxGridCellCoords
& coord
)
944 return IsEmptyCell(coord
.GetRow(), coord
.GetCol());
947 virtual wxString
GetValue( int row
, int col
) = 0;
948 virtual void SetValue( int row
, int col
, const wxString
& value
) = 0;
950 // Data type determination and value access
951 virtual wxString
GetTypeName( int row
, int col
);
952 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
953 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
955 virtual long GetValueAsLong( int row
, int col
);
956 virtual double GetValueAsDouble( int row
, int col
);
957 virtual bool GetValueAsBool( int row
, int col
);
959 virtual void SetValueAsLong( int row
, int col
, long value
);
960 virtual void SetValueAsDouble( int row
, int col
, double value
);
961 virtual void SetValueAsBool( int row
, int col
, bool value
);
963 // For user defined types
964 virtual void* GetValueAsCustom( int row
, int col
, const wxString
& typeName
);
965 virtual void SetValueAsCustom( int row
, int col
, const wxString
& typeName
, void* value
);
968 // Overriding these is optional
970 virtual void SetView( wxGrid
*grid
) { m_view
= grid
; }
971 virtual wxGrid
* GetView() const { return m_view
; }
973 virtual void Clear() {}
974 virtual bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
975 virtual bool AppendRows( size_t numRows
= 1 );
976 virtual bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
977 virtual bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
978 virtual bool AppendCols( size_t numCols
= 1 );
979 virtual bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
981 virtual wxString
GetRowLabelValue( int row
);
982 virtual wxString
GetColLabelValue( int col
);
983 virtual void SetRowLabelValue( int WXUNUSED(row
), const wxString
& ) {}
984 virtual void SetColLabelValue( int WXUNUSED(col
), const wxString
& ) {}
986 // Attribute handling
989 // give us the attr provider to use - we take ownership of the pointer
990 void SetAttrProvider(wxGridCellAttrProvider
*attrProvider
);
992 // get the currently used attr provider (may be NULL)
993 wxGridCellAttrProvider
*GetAttrProvider() const { return m_attrProvider
; }
995 // Does this table allow attributes? Default implementation creates
996 // a wxGridCellAttrProvider if necessary.
997 virtual bool CanHaveAttributes();
999 // by default forwarded to wxGridCellAttrProvider if any. May be
1000 // overridden to handle attributes directly in the table.
1001 virtual wxGridCellAttr
*GetAttr( int row
, int col
,
1002 wxGridCellAttr::wxAttrKind kind
);
1005 // these functions take ownership of the pointer
1006 virtual void SetAttr(wxGridCellAttr
* attr
, int row
, int col
);
1007 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
1008 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
1012 wxGridCellAttrProvider
*m_attrProvider
;
1014 DECLARE_ABSTRACT_CLASS(wxGridTableBase
)
1015 DECLARE_NO_COPY_CLASS(wxGridTableBase
)
1019 // ----------------------------------------------------------------------------
1020 // wxGridTableMessage
1021 // ----------------------------------------------------------------------------
1023 // IDs for messages sent from grid table to view
1025 enum wxGridTableRequest
1027 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
= 2000,
1028 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
,
1029 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
1030 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
1031 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
1032 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
1033 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
1034 wxGRIDTABLE_NOTIFY_COLS_DELETED
1037 class WXDLLIMPEXP_ADV wxGridTableMessage
1040 wxGridTableMessage();
1041 wxGridTableMessage( wxGridTableBase
*table
, int id
,
1045 void SetTableObject( wxGridTableBase
*table
) { m_table
= table
; }
1046 wxGridTableBase
* GetTableObject() const { return m_table
; }
1047 void SetId( int id
) { m_id
= id
; }
1048 int GetId() { return m_id
; }
1049 void SetCommandInt( int comInt1
) { m_comInt1
= comInt1
; }
1050 int GetCommandInt() { return m_comInt1
; }
1051 void SetCommandInt2( int comInt2
) { m_comInt2
= comInt2
; }
1052 int GetCommandInt2() { return m_comInt2
; }
1055 wxGridTableBase
*m_table
;
1060 DECLARE_NO_COPY_CLASS(wxGridTableMessage
)
1065 // ------ wxGridStringArray
1066 // A 2-dimensional array of strings for data values
1069 WX_DECLARE_OBJARRAY_WITH_DECL(wxArrayString
, wxGridStringArray
,
1070 class WXDLLIMPEXP_ADV
);
1074 // ------ wxGridStringTable
1076 // Simplest type of data table for a grid for small tables of strings
1077 // that are stored in memory
1080 class WXDLLIMPEXP_ADV wxGridStringTable
: public wxGridTableBase
1083 wxGridStringTable();
1084 wxGridStringTable( int numRows
, int numCols
);
1085 virtual ~wxGridStringTable();
1087 // these are pure virtual in wxGridTableBase
1089 int GetNumberRows();
1090 int GetNumberCols();
1091 wxString
GetValue( int row
, int col
);
1092 void SetValue( int row
, int col
, const wxString
& s
);
1094 // overridden functions from wxGridTableBase
1097 bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
1098 bool AppendRows( size_t numRows
= 1 );
1099 bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
1100 bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
1101 bool AppendCols( size_t numCols
= 1 );
1102 bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
1104 void SetRowLabelValue( int row
, const wxString
& );
1105 void SetColLabelValue( int col
, const wxString
& );
1106 wxString
GetRowLabelValue( int row
);
1107 wxString
GetColLabelValue( int col
);
1110 wxGridStringArray m_data
;
1112 // These only get used if you set your own labels, otherwise the
1113 // GetRow/ColLabelValue functions return wxGridTableBase defaults
1115 wxArrayString m_rowLabels
;
1116 wxArrayString m_colLabels
;
1118 DECLARE_DYNAMIC_CLASS_NO_COPY( wxGridStringTable
)
1123 // ============================================================================
1124 // Grid view classes
1125 // ============================================================================
1127 // ----------------------------------------------------------------------------
1129 // ----------------------------------------------------------------------------
1131 class WXDLLIMPEXP_ADV wxGrid
: public wxScrolledWindow
1134 // possible selection modes
1135 enum wxGridSelectionModes
1137 wxGridSelectCells
= 0, // allow selecting anything
1138 wxGridSelectRows
= 1, // allow selecting only entire rows
1139 wxGridSelectColumns
= 2, // allow selecting only entire columns
1140 wxGridSelectRowsOrColumns
= wxGridSelectRows
| wxGridSelectColumns
1143 // creation and destruction
1144 // ------------------------
1146 // ctor and Create() create the grid window, as with the other controls
1147 wxGrid() { Init(); }
1149 wxGrid(wxWindow
*parent
,
1151 const wxPoint
& pos
= wxDefaultPosition
,
1152 const wxSize
& size
= wxDefaultSize
,
1153 long style
= wxWANTS_CHARS
,
1154 const wxString
& name
= wxGridNameStr
)
1158 Create(parent
, id
, pos
, size
, style
, name
);
1161 bool Create(wxWindow
*parent
,
1163 const wxPoint
& pos
= wxDefaultPosition
,
1164 const wxSize
& size
= wxDefaultSize
,
1165 long style
= wxWANTS_CHARS
,
1166 const wxString
& name
= wxGridNameStr
);
1170 // however to initialize grid data either CreateGrid() or SetTable() must
1173 // this is basically equivalent to
1175 // SetTable(new wxGridStringTable(numRows, numCols), true, selmode)
1177 bool CreateGrid( int numRows
, int numCols
,
1178 wxGridSelectionModes selmode
= wxGridSelectCells
);
1180 bool SetTable( wxGridTableBase
*table
,
1181 bool takeOwnership
= false,
1182 wxGridSelectionModes selmode
= wxGridSelectCells
);
1184 bool ProcessTableMessage(wxGridTableMessage
&);
1186 wxGridTableBase
*GetTable() const { return m_table
; }
1189 void SetSelectionMode(wxGridSelectionModes selmode
);
1190 wxGridSelectionModes
GetSelectionMode() const;
1192 // ------ grid dimensions
1194 int GetNumberRows() const { return m_numRows
; }
1195 int GetNumberCols() const { return m_numCols
; }
1198 // ------ display update functions
1200 wxArrayInt
CalcRowLabelsExposed( const wxRegion
& reg
) const;
1202 wxArrayInt
CalcColLabelsExposed( const wxRegion
& reg
) const;
1203 wxGridCellCoordsArray
CalcCellsExposed( const wxRegion
& reg
) const;
1207 bool InsertRows(int pos
= 0, int numRows
= 1, bool updateLabels
= true)
1209 return DoModifyLines(&wxGridTableBase::InsertRows
,
1210 pos
, numRows
, updateLabels
);
1212 bool InsertCols(int pos
= 0, int numCols
= 1, bool updateLabels
= true)
1214 return DoModifyLines(&wxGridTableBase::InsertCols
,
1215 pos
, numCols
, updateLabels
);
1218 bool AppendRows(int numRows
= 1, bool updateLabels
= true)
1220 return DoAppendLines(&wxGridTableBase::AppendRows
, numRows
, updateLabels
);
1222 bool AppendCols(int numCols
= 1, bool updateLabels
= true)
1224 return DoAppendLines(&wxGridTableBase::AppendCols
, numCols
, updateLabels
);
1227 bool DeleteRows(int pos
= 0, int numRows
= 1, bool updateLabels
= true)
1229 return DoModifyLines(&wxGridTableBase::DeleteRows
,
1230 pos
, numRows
, updateLabels
);
1232 bool DeleteCols(int pos
= 0, int numCols
= 1, bool updateLabels
= true)
1234 return DoModifyLines(&wxGridTableBase::DeleteCols
,
1235 pos
, numCols
, updateLabels
);
1238 void DrawGridCellArea( wxDC
& dc
, const wxGridCellCoordsArray
& cells
);
1239 void DrawGridSpace( wxDC
& dc
);
1240 void DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& );
1241 void DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
);
1242 void DrawCell( wxDC
& dc
, const wxGridCellCoords
& );
1243 void DrawHighlight(wxDC
& dc
, const wxGridCellCoordsArray
& cells
);
1245 // this function is called when the current cell highlight must be redrawn
1246 // and may be overridden by the user
1247 virtual void DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
);
1249 virtual void DrawRowLabels( wxDC
& dc
, const wxArrayInt
& rows
);
1250 virtual void DrawRowLabel( wxDC
& dc
, int row
);
1252 virtual void DrawColLabels( wxDC
& dc
, const wxArrayInt
& cols
);
1253 virtual void DrawColLabel( wxDC
& dc
, int col
);
1255 virtual void DrawCornerLabel(wxDC
& dc
);
1257 // ------ Cell text drawing functions
1259 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
1260 int horizontalAlignment
= wxALIGN_LEFT
,
1261 int verticalAlignment
= wxALIGN_TOP
,
1262 int textOrientation
= wxHORIZONTAL
);
1264 void DrawTextRectangle( wxDC
& dc
, const wxArrayString
& lines
, const wxRect
&,
1265 int horizontalAlignment
= wxALIGN_LEFT
,
1266 int verticalAlignment
= wxALIGN_TOP
,
1267 int textOrientation
= wxHORIZONTAL
);
1270 // Split a string containing newline characters into an array of
1271 // strings and return the number of lines
1273 void StringToLines( const wxString
& value
, wxArrayString
& lines
) const;
1275 void GetTextBoxSize( const wxDC
& dc
,
1276 const wxArrayString
& lines
,
1277 long *width
, long *height
) const;
1281 // Code that does a lot of grid modification can be enclosed
1282 // between BeginBatch() and EndBatch() calls to avoid screen
1285 void BeginBatch() { m_batchCount
++; }
1288 int GetBatchCount() { return m_batchCount
; }
1290 virtual void Refresh(bool eraseb
= true, const wxRect
* rect
= NULL
);
1292 // Use this, rather than wxWindow::Refresh(), to force an
1293 // immediate repainting of the grid. Has no effect if you are
1294 // already inside a BeginBatch / EndBatch block.
1296 // This function is necessary because wxGrid has a minimal OnPaint()
1297 // handler to reduce screen flicker.
1299 void ForceRefresh();
1302 // ------ edit control functions
1304 bool IsEditable() const { return m_editable
; }
1305 void EnableEditing( bool edit
);
1307 void EnableCellEditControl( bool enable
= true );
1308 void DisableCellEditControl() { EnableCellEditControl(false); }
1309 bool CanEnableCellControl() const;
1310 bool IsCellEditControlEnabled() const;
1311 bool IsCellEditControlShown() const;
1313 bool IsCurrentCellReadOnly() const;
1315 void ShowCellEditControl();
1316 void HideCellEditControl();
1317 void SaveEditControlValue();
1320 // ------ grid location functions
1321 // Note that all of these functions work with the logical coordinates of
1322 // grid cells and labels so you will need to convert from device
1323 // coordinates for mouse events etc.
1325 wxGridCellCoords
XYToCell(int x
, int y
) const;
1326 void XYToCell(int x
, int y
, wxGridCellCoords
& coords
) const
1327 { coords
= XYToCell(x
, y
); }
1328 wxGridCellCoords
XYToCell(const wxPoint
& pos
) const
1329 { return XYToCell(pos
.x
, pos
.y
); }
1331 // these functions return the index of the row/columns corresponding to the
1332 // given logical position in pixels
1334 // if clipToMinMax is false (default, wxNOT_FOUND is returned if the
1335 // position is outside any row/column, otherwise the first/last element is
1336 // returned in this case
1337 int YToRow( int y
, bool clipToMinMax
= false ) const;
1338 int XToCol( int x
, bool clipToMinMax
= false ) const;
1340 int YToEdgeOfRow( int y
) const;
1341 int XToEdgeOfCol( int x
) const;
1343 wxRect
CellToRect( int row
, int col
) const;
1344 wxRect
CellToRect( const wxGridCellCoords
& coords
) const
1345 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
1347 int GetGridCursorRow() const { return m_currentCellCoords
.GetRow(); }
1348 int GetGridCursorCol() const { return m_currentCellCoords
.GetCol(); }
1350 // check to see if a cell is either wholly visible (the default arg) or
1351 // at least partially visible in the grid window
1353 bool IsVisible( int row
, int col
, bool wholeCellVisible
= true ) const;
1354 bool IsVisible( const wxGridCellCoords
& coords
, bool wholeCellVisible
= true ) const
1355 { return IsVisible( coords
.GetRow(), coords
.GetCol(), wholeCellVisible
); }
1356 void MakeCellVisible( int row
, int col
);
1357 void MakeCellVisible( const wxGridCellCoords
& coords
)
1358 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
1361 // ------ grid cursor movement functions
1363 void SetGridCursor(int row
, int col
) { SetCurrentCell(row
, col
); }
1364 void SetGridCursor(const wxGridCellCoords
& c
) { SetCurrentCell(c
); }
1366 void GoToCell(int row
, int col
)
1368 if ( SetCurrentCell(row
, col
) )
1369 MakeCellVisible(row
, col
);
1372 void GoToCell(const wxGridCellCoords
& coords
)
1374 if ( SetCurrentCell(coords
) )
1375 MakeCellVisible(coords
);
1378 bool MoveCursorUp( bool expandSelection
);
1379 bool MoveCursorDown( bool expandSelection
);
1380 bool MoveCursorLeft( bool expandSelection
);
1381 bool MoveCursorRight( bool expandSelection
);
1382 bool MovePageDown();
1384 bool MoveCursorUpBlock( bool expandSelection
);
1385 bool MoveCursorDownBlock( bool expandSelection
);
1386 bool MoveCursorLeftBlock( bool expandSelection
);
1387 bool MoveCursorRightBlock( bool expandSelection
);
1390 // ------ label and gridline formatting
1392 int GetDefaultRowLabelSize() const { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
1393 int GetRowLabelSize() const { return m_rowLabelWidth
; }
1394 int GetDefaultColLabelSize() const { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
1395 int GetColLabelSize() const { return m_colLabelHeight
; }
1396 wxColour
GetLabelBackgroundColour() const { return m_labelBackgroundColour
; }
1397 wxColour
GetLabelTextColour() const { return m_labelTextColour
; }
1398 wxFont
GetLabelFont() const { return m_labelFont
; }
1399 void GetRowLabelAlignment( int *horiz
, int *vert
) const;
1400 void GetColLabelAlignment( int *horiz
, int *vert
) const;
1401 int GetColLabelTextOrientation() const;
1402 wxString
GetRowLabelValue( int row
) const;
1403 wxString
GetColLabelValue( int col
) const;
1405 wxColour
GetCellHighlightColour() const { return m_cellHighlightColour
; }
1406 int GetCellHighlightPenWidth() const { return m_cellHighlightPenWidth
; }
1407 int GetCellHighlightROPenWidth() const { return m_cellHighlightROPenWidth
; }
1409 // this one will use wxHeaderCtrl for the column labels
1410 void UseNativeColHeader(bool native
= true);
1412 // this one will still draw them manually but using the native renderer
1413 // instead of using the same appearance as for the row labels
1414 void SetUseNativeColLabels( bool native
= true );
1416 void SetRowLabelSize( int width
);
1417 void SetColLabelSize( int height
);
1418 void HideRowLabels() { SetRowLabelSize( 0 ); }
1419 void HideColLabels() { SetColLabelSize( 0 ); }
1420 void SetLabelBackgroundColour( const wxColour
& );
1421 void SetLabelTextColour( const wxColour
& );
1422 void SetLabelFont( const wxFont
& );
1423 void SetRowLabelAlignment( int horiz
, int vert
);
1424 void SetColLabelAlignment( int horiz
, int vert
);
1425 void SetColLabelTextOrientation( int textOrientation
);
1426 void SetRowLabelValue( int row
, const wxString
& );
1427 void SetColLabelValue( int col
, const wxString
& );
1428 void SetCellHighlightColour( const wxColour
& );
1429 void SetCellHighlightPenWidth(int width
);
1430 void SetCellHighlightROPenWidth(int width
);
1432 void EnableDragRowSize( bool enable
= true );
1433 void DisableDragRowSize() { EnableDragRowSize( false ); }
1434 bool CanDragRowSize() const { return m_canDragRowSize
; }
1435 void EnableDragColSize( bool enable
= true );
1436 void DisableDragColSize() { EnableDragColSize( false ); }
1437 bool CanDragColSize() const { return m_canDragColSize
; }
1438 void EnableDragColMove( bool enable
= true );
1439 void DisableDragColMove() { EnableDragColMove( false ); }
1440 bool CanDragColMove() const { return m_canDragColMove
; }
1441 void EnableDragGridSize(bool enable
= true);
1442 void DisableDragGridSize() { EnableDragGridSize(false); }
1443 bool CanDragGridSize() const { return m_canDragGridSize
; }
1445 void EnableDragCell( bool enable
= true );
1446 void DisableDragCell() { EnableDragCell( false ); }
1447 bool CanDragCell() const { return m_canDragCell
; }
1453 // enable or disable drawing of the lines
1454 void EnableGridLines(bool enable
= true);
1455 bool GridLinesEnabled() const { return m_gridLinesEnabled
; }
1457 // by default grid lines stop at last column/row, but this may be changed
1458 void ClipHorzGridLines(bool clip
)
1459 { DoClipGridLines(m_gridLinesClipHorz
, clip
); }
1460 void ClipVertGridLines(bool clip
)
1461 { DoClipGridLines(m_gridLinesClipVert
, clip
); }
1462 bool AreHorzGridLinesClipped() const { return m_gridLinesClipHorz
; }
1463 bool AreVertGridLinesClipped() const { return m_gridLinesClipVert
; }
1465 // this can be used to change the global grid lines colour
1466 void SetGridLineColour(const wxColour
& col
);
1467 wxColour
GetGridLineColour() const { return m_gridLineColour
; }
1469 // these methods may be overridden to customize individual grid lines
1471 virtual wxPen
GetDefaultGridLinePen();
1472 virtual wxPen
GetRowGridLinePen(int row
);
1473 virtual wxPen
GetColGridLinePen(int col
);
1479 // this sets the specified attribute for this cell or in this row/col
1480 void SetAttr(int row
, int col
, wxGridCellAttr
*attr
);
1481 void SetRowAttr(int row
, wxGridCellAttr
*attr
);
1482 void SetColAttr(int col
, wxGridCellAttr
*attr
);
1484 // returns the attribute we may modify in place: a new one if this cell
1485 // doesn't have any yet or the existing one if it does
1487 // DecRef() must be called on the returned pointer, as usual
1488 wxGridCellAttr
*GetOrCreateCellAttr(int row
, int col
) const;
1491 // shortcuts for setting the column parameters
1493 // set the format for the data in the column: default is string
1494 void SetColFormatBool(int col
);
1495 void SetColFormatNumber(int col
);
1496 void SetColFormatFloat(int col
, int width
= -1, int precision
= -1);
1497 void SetColFormatCustom(int col
, const wxString
& typeName
);
1499 // ------ row and col formatting
1501 int GetDefaultRowSize() const;
1502 int GetRowSize( int row
) const;
1503 bool IsRowShown(int row
) const { return GetRowSize(row
) != 0; }
1504 int GetDefaultColSize() const;
1505 int GetColSize( int col
) const;
1506 bool IsColShown(int col
) const { return GetColSize(col
) != 0; }
1507 wxColour
GetDefaultCellBackgroundColour() const;
1508 wxColour
GetCellBackgroundColour( int row
, int col
) const;
1509 wxColour
GetDefaultCellTextColour() const;
1510 wxColour
GetCellTextColour( int row
, int col
) const;
1511 wxFont
GetDefaultCellFont() const;
1512 wxFont
GetCellFont( int row
, int col
) const;
1513 void GetDefaultCellAlignment( int *horiz
, int *vert
) const;
1514 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
) const;
1515 bool GetDefaultCellOverflow() const;
1516 bool GetCellOverflow( int row
, int col
) const;
1517 void GetCellSize( int row
, int col
, int *num_rows
, int *num_cols
) const;
1518 wxSize
GetCellSize(const wxGridCellCoords
& coords
)
1521 GetCellSize(coords
.GetRow(), coords
.GetCol(), &s
.x
, &s
.y
);
1525 // ------ row and col sizes
1526 void SetDefaultRowSize( int height
, bool resizeExistingRows
= false );
1527 void SetRowSize( int row
, int height
);
1528 void HideRow(int row
) { SetRowSize(row
, 0); }
1529 void ShowRow(int row
) { SetRowSize(row
, -1); }
1531 void SetDefaultColSize( int width
, bool resizeExistingCols
= false );
1532 void SetColSize( int col
, int width
);
1533 void HideCol(int col
) { SetColSize(col
, 0); }
1534 void ShowCol(int col
) { SetColSize(col
, -1); }
1537 // ------- columns (only, for now) reordering
1539 // columns index <-> positions mapping: by default, the position of the
1540 // column is the same as its index, but the columns can also be reordered
1541 // (either by calling SetColPos() explicitly or by the user dragging the
1542 // columns around) in which case their indices don't correspond to their
1543 // positions on display any longer
1545 // internally we always work with indices except for the functions which
1546 // have "Pos" in their names (and which work with columns, not pixels) and
1547 // only the display and hit testing code really cares about display
1550 // set the positions of all columns at once (this method uses the same
1551 // conventions as wxHeaderCtrl::SetColumnsOrder() for the order array)
1552 void SetColumnsOrder(const wxArrayInt
& order
);
1554 // return the column index corresponding to the given (valid) position
1555 int GetColAt(int pos
) const
1557 return m_colAt
.empty() ? pos
: m_colAt
[pos
];
1560 // reorder the columns so that the column with the given index is now shown
1561 // as the position pos
1562 void SetColPos(int idx
, int pos
);
1564 // return the position at which the column with the given index is
1565 // displayed: notice that this is a slow operation as we don't maintain the
1566 // reverse mapping currently
1567 int GetColPos(int idx
) const
1569 if ( m_colAt
.IsEmpty() )
1572 for ( int i
= 0; i
< m_numCols
; i
++ )
1574 if ( m_colAt
[i
] == idx
)
1578 wxFAIL_MSG( "invalid column index" );
1583 // reset the columns positions to the default order
1587 // automatically size the column or row to fit to its contents, if
1588 // setAsMin is true, this optimal width will also be set as minimal width
1590 void AutoSizeColumn( int col
, bool setAsMin
= true )
1591 { AutoSizeColOrRow(col
, setAsMin
, wxGRID_COLUMN
); }
1592 void AutoSizeRow( int row
, bool setAsMin
= true )
1593 { AutoSizeColOrRow(row
, setAsMin
, wxGRID_ROW
); }
1595 // auto size all columns (very ineffective for big grids!)
1596 void AutoSizeColumns( bool setAsMin
= true )
1597 { (void)SetOrCalcColumnSizes(false, setAsMin
); }
1599 void AutoSizeRows( bool setAsMin
= true )
1600 { (void)SetOrCalcRowSizes(false, setAsMin
); }
1602 // auto size the grid, that is make the columns/rows of the "right" size
1603 // and also set the grid size to just fit its contents
1606 // Note for both AutoSizeRowLabelSize and AutoSizeColLabelSize:
1607 // If col equals to wxGRID_AUTOSIZE value then function autosizes labels column
1608 // instead of data column. Note that this operation may be slow for large
1610 // autosize row height depending on label text
1611 void AutoSizeRowLabelSize( int row
);
1613 // autosize column width depending on label text
1614 void AutoSizeColLabelSize( int col
);
1616 // column won't be resized to be lesser width - this must be called during
1617 // the grid creation because it won't resize the column if it's already
1618 // narrower than the minimal width
1619 void SetColMinimalWidth( int col
, int width
);
1620 void SetRowMinimalHeight( int row
, int width
);
1622 /* These members can be used to query and modify the minimal
1623 * acceptable size of grid rows and columns. Call this function in
1624 * your code which creates the grid if you want to display cells
1625 * with a size smaller than the default acceptable minimum size.
1626 * Like the members SetColMinimalWidth and SetRowMinimalWidth,
1627 * the existing rows or columns will not be checked/resized.
1629 void SetColMinimalAcceptableWidth( int width
);
1630 void SetRowMinimalAcceptableHeight( int width
);
1631 int GetColMinimalAcceptableWidth() const;
1632 int GetRowMinimalAcceptableHeight() const;
1634 void SetDefaultCellBackgroundColour( const wxColour
& );
1635 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
1636 void SetDefaultCellTextColour( const wxColour
& );
1638 void SetCellTextColour( int row
, int col
, const wxColour
& );
1639 void SetDefaultCellFont( const wxFont
& );
1640 void SetCellFont( int row
, int col
, const wxFont
& );
1641 void SetDefaultCellAlignment( int horiz
, int vert
);
1642 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
1643 void SetDefaultCellOverflow( bool allow
);
1644 void SetCellOverflow( int row
, int col
, bool allow
);
1645 void SetCellSize( int row
, int col
, int num_rows
, int num_cols
);
1647 // takes ownership of the pointer
1648 void SetDefaultRenderer(wxGridCellRenderer
*renderer
);
1649 void SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
);
1650 wxGridCellRenderer
*GetDefaultRenderer() const;
1651 wxGridCellRenderer
* GetCellRenderer(int row
, int col
) const;
1653 // takes ownership of the pointer
1654 void SetDefaultEditor(wxGridCellEditor
*editor
);
1655 void SetCellEditor(int row
, int col
, wxGridCellEditor
*editor
);
1656 wxGridCellEditor
*GetDefaultEditor() const;
1657 wxGridCellEditor
* GetCellEditor(int row
, int col
) const;
1661 // ------ cell value accessors
1663 wxString
GetCellValue( int row
, int col
) const
1667 return m_table
->GetValue( row
, col
);
1671 return wxEmptyString
;
1675 wxString
GetCellValue( const wxGridCellCoords
& coords
) const
1676 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
1678 void SetCellValue( int row
, int col
, const wxString
& s
);
1679 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
1680 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
1682 // returns true if the cell can't be edited
1683 bool IsReadOnly(int row
, int col
) const;
1685 // make the cell editable/readonly
1686 void SetReadOnly(int row
, int col
, bool isReadOnly
= true);
1688 // ------ select blocks of cells
1690 void SelectRow( int row
, bool addToSelected
= false );
1691 void SelectCol( int col
, bool addToSelected
= false );
1693 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
,
1694 bool addToSelected
= false );
1696 void SelectBlock( const wxGridCellCoords
& topLeft
,
1697 const wxGridCellCoords
& bottomRight
,
1698 bool addToSelected
= false )
1699 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
1700 bottomRight
.GetRow(), bottomRight
.GetCol(),
1705 bool IsSelection() const;
1707 // ------ deselect blocks or cells
1709 void DeselectRow( int row
);
1710 void DeselectCol( int col
);
1711 void DeselectCell( int row
, int col
);
1713 void ClearSelection();
1715 bool IsInSelection( int row
, int col
) const;
1717 bool IsInSelection( const wxGridCellCoords
& coords
) const
1718 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
1720 wxGridCellCoordsArray
GetSelectedCells() const;
1721 wxGridCellCoordsArray
GetSelectionBlockTopLeft() const;
1722 wxGridCellCoordsArray
GetSelectionBlockBottomRight() const;
1723 wxArrayInt
GetSelectedRows() const;
1724 wxArrayInt
GetSelectedCols() const;
1726 // This function returns the rectangle that encloses the block of cells
1727 // limited by TopLeft and BottomRight cell in device coords and clipped
1728 // to the client size of the grid window.
1730 wxRect
BlockToDeviceRect( const wxGridCellCoords
& topLeft
,
1731 const wxGridCellCoords
& bottomRight
) const;
1733 // Access or update the selection fore/back colours
1734 wxColour
GetSelectionBackground() const
1735 { return m_selectionBackground
; }
1736 wxColour
GetSelectionForeground() const
1737 { return m_selectionForeground
; }
1739 void SetSelectionBackground(const wxColour
& c
) { m_selectionBackground
= c
; }
1740 void SetSelectionForeground(const wxColour
& c
) { m_selectionForeground
= c
; }
1743 // Methods for a registry for mapping data types to Renderers/Editors
1744 void RegisterDataType(const wxString
& typeName
,
1745 wxGridCellRenderer
* renderer
,
1746 wxGridCellEditor
* editor
);
1748 virtual wxGridCellEditor
* GetDefaultEditorForCell(int row
, int col
) const;
1749 wxGridCellEditor
* GetDefaultEditorForCell(const wxGridCellCoords
& c
) const
1750 { return GetDefaultEditorForCell(c
.GetRow(), c
.GetCol()); }
1751 virtual wxGridCellRenderer
* GetDefaultRendererForCell(int row
, int col
) const;
1752 virtual wxGridCellEditor
* GetDefaultEditorForType(const wxString
& typeName
) const;
1753 virtual wxGridCellRenderer
* GetDefaultRendererForType(const wxString
& typeName
) const;
1755 // grid may occupy more space than needed for its rows/columns, this
1756 // function allows to set how big this extra space is
1757 void SetMargins(int extraWidth
, int extraHeight
)
1759 m_extraWidth
= extraWidth
;
1760 m_extraHeight
= extraHeight
;
1765 // Accessors for component windows
1766 wxWindow
* GetGridWindow() const { return (wxWindow
*)m_gridWin
; }
1767 wxWindow
* GetGridRowLabelWindow() const { return (wxWindow
*)m_rowLabelWin
; }
1768 wxWindow
* GetGridColLabelWindow() const { return m_colWindow
; }
1769 wxWindow
* GetGridCornerLabelWindow() const { return (wxWindow
*)m_cornerLabelWin
; }
1771 // This one can only be called if we are using the native header window
1772 wxHeaderCtrl
*GetGridColHeader() const
1774 wxASSERT_MSG( m_useNativeHeader
, "no column header window" );
1776 // static_cast<> doesn't work without the full class declaration in
1777 // view and we prefer to avoid adding more compile-time dependencies
1778 // even at the cost of using reinterpret_cast<>
1779 return reinterpret_cast<wxHeaderCtrl
*>(m_colWindow
);
1782 // Allow adjustment of scroll increment. The default is (15, 15).
1783 void SetScrollLineX(int x
) { m_scrollLineX
= x
; }
1784 void SetScrollLineY(int y
) { m_scrollLineY
= y
; }
1785 int GetScrollLineX() const { return m_scrollLineX
; }
1786 int GetScrollLineY() const { return m_scrollLineY
; }
1788 // ------- drag and drop
1789 #if wxUSE_DRAG_AND_DROP
1790 virtual void SetDropTarget(wxDropTarget
*dropTarget
);
1791 #endif // wxUSE_DRAG_AND_DROP
1794 // ------- sorting support
1796 // wxGrid doesn't support sorting on its own but it can indicate the sort
1797 // order in the column header (currently only if native header control is
1800 // return the column currently displaying the sort indicator or wxNOT_FOUND
1802 int GetSortingColumn() const { return m_sortCol
; }
1804 // return true if this column is currently used for sorting
1805 bool IsSortingBy(int col
) const { return GetSortingColumn() == col
; }
1807 // return the current sorting order (on GetSortingColumn()): true for
1808 // ascending sort and false for descending; it doesn't make sense to call
1809 // it if GetSortingColumn() returns wxNOT_FOUND
1810 bool IsSortOrderAscending() const { return m_sortIsAscending
; }
1812 // set the sorting column (or unsets any existing one if wxNOT_FOUND) and
1813 // the order in which to sort
1814 void SetSortingColumn(int col
, bool ascending
= true);
1816 // unset any existing sorting column
1817 void UnsetSortingColumn() { SetSortingColumn(wxNOT_FOUND
); }
1819 #ifdef WXWIN_COMPATIBILITY_2_8
1820 // ------ For compatibility with previous wxGrid only...
1822 // ************************************************
1823 // ** Don't use these in new code because they **
1824 // ** are liable to disappear in a future **
1826 // ************************************************
1829 wxGrid( wxWindow
*parent
,
1830 int x
, int y
, int w
= wxDefaultCoord
, int h
= wxDefaultCoord
,
1831 long style
= wxWANTS_CHARS
,
1832 const wxString
& name
= wxPanelNameStr
)
1835 Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(w
, h
), style
, name
);
1838 void SetCellValue( const wxString
& val
, int row
, int col
)
1839 { SetCellValue( row
, col
, val
); }
1841 void UpdateDimensions()
1842 { CalcDimensions(); }
1844 int GetRows() const { return GetNumberRows(); }
1845 int GetCols() const { return GetNumberCols(); }
1846 int GetCursorRow() const { return GetGridCursorRow(); }
1847 int GetCursorColumn() const { return GetGridCursorCol(); }
1849 int GetScrollPosX() const { return 0; }
1850 int GetScrollPosY() const { return 0; }
1852 void SetScrollX( int WXUNUSED(x
) ) { }
1853 void SetScrollY( int WXUNUSED(y
) ) { }
1855 void SetColumnWidth( int col
, int width
)
1856 { SetColSize( col
, width
); }
1858 int GetColumnWidth( int col
) const
1859 { return GetColSize( col
); }
1861 void SetRowHeight( int row
, int height
)
1862 { SetRowSize( row
, height
); }
1864 // GetRowHeight() is below
1866 int GetViewHeight() const // returned num whole rows visible
1869 int GetViewWidth() const // returned num whole cols visible
1872 void SetLabelSize( int orientation
, int sz
)
1874 if ( orientation
== wxHORIZONTAL
)
1875 SetColLabelSize( sz
);
1877 SetRowLabelSize( sz
);
1880 int GetLabelSize( int orientation
) const
1882 if ( orientation
== wxHORIZONTAL
)
1883 return GetColLabelSize();
1885 return GetRowLabelSize();
1888 void SetLabelAlignment( int orientation
, int align
)
1890 if ( orientation
== wxHORIZONTAL
)
1891 SetColLabelAlignment( align
, -1 );
1893 SetRowLabelAlignment( align
, -1 );
1896 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) ) const
1899 if ( orientation
== wxHORIZONTAL
)
1901 GetColLabelAlignment( &h
, &v
);
1906 GetRowLabelAlignment( &h
, &v
);
1911 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
1913 if ( orientation
== wxHORIZONTAL
)
1914 SetColLabelValue( pos
, val
);
1916 SetRowLabelValue( pos
, val
);
1919 wxString
GetLabelValue( int orientation
, int pos
) const
1921 if ( orientation
== wxHORIZONTAL
)
1922 return GetColLabelValue( pos
);
1924 return GetRowLabelValue( pos
);
1927 wxFont
GetCellTextFont() const
1928 { return m_defaultCellAttr
->GetFont(); }
1930 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
1931 { return m_defaultCellAttr
->GetFont(); }
1933 void SetCellTextFont(const wxFont
& fnt
)
1934 { SetDefaultCellFont( fnt
); }
1936 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
1937 { SetCellFont( row
, col
, fnt
); }
1939 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
1940 { SetCellTextColour( row
, col
, val
); }
1942 void SetCellTextColour(const wxColour
& col
)
1943 { SetDefaultCellTextColour( col
); }
1945 void SetCellBackgroundColour(const wxColour
& col
)
1946 { SetDefaultCellBackgroundColour( col
); }
1948 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
1949 { SetCellBackgroundColour( row
, col
, colour
); }
1951 bool GetEditable() const { return IsEditable(); }
1952 void SetEditable( bool edit
= true ) { EnableEditing( edit
); }
1953 bool GetEditInPlace() const { return IsCellEditControlEnabled(); }
1955 void SetEditInPlace(bool WXUNUSED(edit
) = true) { }
1957 void SetCellAlignment( int align
, int row
, int col
)
1958 { SetCellAlignment(row
, col
, align
, wxALIGN_CENTER
); }
1959 void SetCellAlignment( int WXUNUSED(align
) ) {}
1960 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
1962 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
1963 wxPen
& GetDividerPen() const;
1964 void OnActivate(bool WXUNUSED(active
)) {}
1966 // ******** End of compatibility functions **********
1970 // ------ control IDs
1971 enum { wxGRID_CELLCTRL
= 2000,
1974 // ------ control types
1975 enum { wxGRID_TEXTCTRL
= 2100,
1979 #endif // WXWIN_COMPATIBILITY_2_8
1982 // override some base class functions
1983 virtual bool Enable(bool enable
= true);
1984 virtual wxWindow
*GetMainWindowOfCompositeControl()
1985 { return (wxWindow
*)m_gridWin
; }
1988 // implementation only
1989 void CancelMouseCapture();
1992 virtual wxSize
DoGetBestSize() const;
1996 wxGridWindow
*m_gridWin
;
1997 wxGridCornerLabelWindow
*m_cornerLabelWin
;
1998 wxGridRowLabelWindow
*m_rowLabelWin
;
2000 // the real type of the column window depends on m_useNativeHeader value:
2001 // if it is true, its dynamic type is wxHeaderCtrl, otherwise it is
2002 // wxGridColLabelWindow, use accessors below when the real type matters
2003 wxWindow
*m_colWindow
;
2005 wxGridColLabelWindow
*GetColLabelWindow() const
2007 wxASSERT_MSG( !m_useNativeHeader
, "no column label window" );
2009 return reinterpret_cast<wxGridColLabelWindow
*>(m_colWindow
);
2012 wxGridTableBase
*m_table
;
2018 wxGridCellCoords m_currentCellCoords
;
2020 // the corners of the block being currently selected or wxGridNoCellCoords
2021 wxGridCellCoords m_selectedBlockTopLeft
;
2022 wxGridCellCoords m_selectedBlockBottomRight
;
2024 // when selecting blocks of cells (either from the keyboard using Shift
2025 // with cursor keys, or by dragging the mouse), the selection is anchored
2026 // at m_currentCellCoords which defines one of the corners of the rectangle
2027 // being selected -- and this variable defines the other corner, i.e. it's
2028 // either m_selectedBlockTopLeft or m_selectedBlockBottomRight depending on
2029 // which of them is not m_currentCellCoords
2031 // if no block selection is in process, it is set to wxGridNoCellCoords
2032 wxGridCellCoords m_selectedBlockCorner
;
2034 wxGridSelection
*m_selection
;
2036 wxColour m_selectionBackground
;
2037 wxColour m_selectionForeground
;
2039 // NB: *never* access m_row/col arrays directly because they are created
2040 // on demand, *always* use accessor functions instead!
2042 // init the m_rowHeights/Bottoms arrays with default values
2043 void InitRowHeights();
2045 int m_defaultRowHeight
;
2046 int m_minAcceptableRowHeight
;
2047 wxArrayInt m_rowHeights
;
2048 wxArrayInt m_rowBottoms
;
2050 // init the m_colWidths/Rights arrays
2051 void InitColWidths();
2053 int m_defaultColWidth
;
2054 int m_minAcceptableColWidth
;
2055 wxArrayInt m_colWidths
;
2056 wxArrayInt m_colRights
;
2059 bool m_sortIsAscending
;
2061 bool m_useNativeHeader
,
2062 m_nativeColumnLabels
;
2064 // get the col/row coords
2065 int GetColWidth(int col
) const;
2066 int GetColLeft(int col
) const;
2067 int GetColRight(int col
) const;
2069 // this function must be public for compatibility...
2071 int GetRowHeight(int row
) const;
2074 int GetRowTop(int row
) const;
2075 int GetRowBottom(int row
) const;
2077 int m_rowLabelWidth
;
2078 int m_colLabelHeight
;
2080 // the size of the margin left to the right and bottom of the cell area
2084 wxColour m_labelBackgroundColour
;
2085 wxColour m_labelTextColour
;
2088 int m_rowLabelHorizAlign
;
2089 int m_rowLabelVertAlign
;
2090 int m_colLabelHorizAlign
;
2091 int m_colLabelVertAlign
;
2092 int m_colLabelTextOrientation
;
2094 bool m_defaultRowLabelValues
;
2095 bool m_defaultColLabelValues
;
2097 wxColour m_gridLineColour
;
2098 bool m_gridLinesEnabled
;
2099 bool m_gridLinesClipHorz
,
2100 m_gridLinesClipVert
;
2101 wxColour m_cellHighlightColour
;
2102 int m_cellHighlightPenWidth
;
2103 int m_cellHighlightROPenWidth
;
2106 // common part of AutoSizeColumn/Row() and GetBestSize()
2107 int SetOrCalcColumnSizes(bool calcOnly
, bool setAsMin
= true);
2108 int SetOrCalcRowSizes(bool calcOnly
, bool setAsMin
= true);
2110 // common part of AutoSizeColumn/Row()
2111 void AutoSizeColOrRow(int n
, bool setAsMin
, wxGridDirection direction
);
2113 // Calculate the minimum acceptable size for labels area
2114 wxCoord
CalcColOrRowLabelAreaMinSize(wxGridDirection direction
);
2116 // if a column has a minimal width, it will be the value for it in this
2118 wxLongToLongHashMap m_colMinWidths
,
2121 // get the minimal width of the given column/row
2122 int GetColMinimalWidth(int col
) const;
2123 int GetRowMinimalHeight(int col
) const;
2125 // do we have some place to store attributes in?
2126 bool CanHaveAttributes() const;
2128 // cell attribute cache (currently we only cache 1, may be will do
2129 // more/better later)
2133 wxGridCellAttr
*attr
;
2136 // invalidates the attribute cache
2137 void ClearAttrCache();
2139 // adds an attribute to cache
2140 void CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const;
2142 // looks for an attr in cache, returns true if found
2143 bool LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const;
2145 // looks for the attr in cache, if not found asks the table and caches the
2147 wxGridCellAttr
*GetCellAttr(int row
, int col
) const;
2148 wxGridCellAttr
*GetCellAttr(const wxGridCellCoords
& coords
) const
2149 { return GetCellAttr( coords
.GetRow(), coords
.GetCol() ); }
2151 // the default cell attr object for cells that don't have their own
2152 wxGridCellAttr
* m_defaultCellAttr
;
2159 wxGridTypeRegistry
* m_typeRegistry
;
2163 WXGRID_CURSOR_SELECT_CELL
,
2164 WXGRID_CURSOR_RESIZE_ROW
,
2165 WXGRID_CURSOR_RESIZE_COL
,
2166 WXGRID_CURSOR_SELECT_ROW
,
2167 WXGRID_CURSOR_SELECT_COL
,
2168 WXGRID_CURSOR_MOVE_COL
2171 // this method not only sets m_cursorMode but also sets the correct cursor
2172 // for the given mode and, if captureMouse is not false releases the mouse
2173 // if it was captured and captures it if it must be captured
2175 // for this to work, you should always use it and not set m_cursorMode
2177 void ChangeCursorMode(CursorMode mode
,
2178 wxWindow
*win
= NULL
,
2179 bool captureMouse
= true);
2181 wxWindow
*m_winCapture
; // the window which captured the mouse
2183 // this variable is used not for finding the correct current cursor but
2184 // mainly for finding out what is going to happen if the mouse starts being
2185 // dragged right now
2187 // by default it is WXGRID_CURSOR_SELECT_CELL meaning that nothing else is
2188 // going on, and it is set to one of RESIZE/SELECT/MOVE values while the
2189 // corresponding operation will be started if the user starts dragging the
2190 // mouse from the current position
2191 CursorMode m_cursorMode
;
2197 bool m_canDragRowSize
;
2198 bool m_canDragColSize
;
2199 bool m_canDragColMove
;
2200 bool m_canDragGridSize
;
2203 // the last position (horizontal or vertical depending on whether the user
2204 // is resizing a column or a row) where a row or column separator line was
2205 // dragged by the user or -1 of there is no drag operation in progress
2209 // true if a drag operation is in progress; when this is true,
2210 // m_startDragPos is valid, i.e. not wxDefaultPosition
2213 // the position (in physical coordinates) where the user started dragging
2214 // the mouse or wxDefaultPosition if mouse isn't being dragged
2216 // notice that this can be != wxDefaultPosition while m_isDragging is still
2217 // false because we wait until the mouse is moved some distance away before
2218 // setting m_isDragging to true
2219 wxPoint m_startDragPos
;
2221 bool m_waitForSlowClick
;
2223 wxGridCellCoords m_selectionStart
;
2225 wxCursor m_rowResizeCursor
;
2226 wxCursor m_colResizeCursor
;
2228 bool m_editable
; // applies to whole grid
2229 bool m_cellEditCtrlEnabled
; // is in-place edit currently shown?
2231 int m_scrollLineX
; // X scroll increment
2232 int m_scrollLineY
; // Y scroll increment
2234 void Init(); // common part of all ctors
2236 void CreateColumnWindow();
2237 void CalcDimensions();
2238 void CalcWindowSizes();
2239 bool Redimension( wxGridTableMessage
& );
2242 // generate the appropriate grid event and return -1 if it was vetoed, 1 if
2243 // it was processed (but not vetoed) and 0 if it wasn't processed
2244 int SendEvent(const wxEventType evtType
,
2247 int SendEvent(const wxEventType evtType
,
2248 const wxGridCellCoords
& coords
,
2250 { return SendEvent(evtType
, coords
.GetRow(), coords
.GetCol(), e
); }
2251 int SendEvent(const wxEventType evtType
,
2253 const wxString
& s
= wxString());
2254 int SendEvent(const wxEventType evtType
,
2255 const wxGridCellCoords
& coords
,
2256 const wxString
& s
= wxString())
2257 { return SendEvent(evtType
, coords
.GetRow(), coords
.GetCol(), s
); }
2258 int SendEvent(const wxEventType evtType
, const wxString
& s
= wxString())
2259 { return SendEvent(evtType
, m_currentCellCoords
, s
); }
2261 void OnPaint( wxPaintEvent
& );
2262 void OnSize( wxSizeEvent
& );
2263 void OnKeyDown( wxKeyEvent
& );
2264 void OnKeyUp( wxKeyEvent
& );
2265 void OnChar( wxKeyEvent
& );
2266 void OnEraseBackground( wxEraseEvent
& );
2269 bool SetCurrentCell( const wxGridCellCoords
& coords
);
2270 bool SetCurrentCell( int row
, int col
)
2271 { return SetCurrentCell( wxGridCellCoords(row
, col
) ); }
2274 // this function is called to extend the block being currently selected
2275 // from mouse and keyboard event handlers
2276 void UpdateBlockBeingSelected(int topRow
, int leftCol
,
2277 int bottomRow
, int rightCol
);
2279 void UpdateBlockBeingSelected(const wxGridCellCoords
& topLeft
,
2280 const wxGridCellCoords
& bottomRight
)
2281 { UpdateBlockBeingSelected(topLeft
.GetRow(), topLeft
.GetCol(),
2282 bottomRight
.GetRow(), bottomRight
.GetCol()); }
2284 // ------ functions to get/send data (see also public functions)
2286 bool GetModelValues();
2287 bool SetModelValues();
2289 friend class WXDLLIMPEXP_FWD_ADV wxGridSelection
;
2290 friend class wxGridRowOperations
;
2291 friend class wxGridColumnOperations
;
2293 // they call our private Process{{Corner,Col,Row}Label,GridCell}MouseEvent()
2294 friend class wxGridCornerLabelWindow
;
2295 friend class wxGridColLabelWindow
;
2296 friend class wxGridRowLabelWindow
;
2297 friend class wxGridWindow
;
2299 friend class wxGridHeaderCtrl
;
2302 // implement wxScrolledWindow method to return m_gridWin size
2303 virtual wxSize
GetSizeAvailableForScrollTarget(const wxSize
& size
);
2305 // redraw the grid lines, should be called after changing their attributes
2306 void RedrawGridLines();
2308 // common part of Clip{Horz,Vert}GridLines
2309 void DoClipGridLines(bool& var
, bool clip
);
2311 // update the sorting indicator shown in the specified column (whose index
2314 // this will use GetSortingColumn() and IsSortOrderAscending() to determine
2315 // the sorting indicator to effectively show
2316 void UpdateColumnSortingIndicator(int col
);
2318 // update the grid after changing the columns order (common part of
2319 // SetColPos() and ResetColPos())
2320 void RefreshAfterColPosChange();
2323 // return the position (not index) of the column at the given logical pixel
2326 // this always returns a valid position, even if the coordinate is out of
2327 // bounds (in which case first/last column is returned)
2328 int XToPos(int x
) const;
2331 // event handlers and their helpers
2332 // --------------------------------
2334 // process mouse drag event in WXGRID_CURSOR_SELECT_CELL mode
2335 void DoGridCellDrag(wxMouseEvent
& event
,
2336 const wxGridCellCoords
& coords
,
2339 // process row/column resizing drag event
2340 void DoGridLineDrag(wxMouseEvent
& event
, const wxGridOperations
& oper
);
2342 // process mouse drag event in the grid window
2343 void DoGridDragEvent(wxMouseEvent
& event
, const wxGridCellCoords
& coords
);
2345 // process different clicks on grid cells
2346 void DoGridCellLeftDown(wxMouseEvent
& event
,
2347 const wxGridCellCoords
& coords
,
2348 const wxPoint
& pos
);
2349 void DoGridCellLeftDClick(wxMouseEvent
& event
,
2350 const wxGridCellCoords
& coords
,
2351 const wxPoint
& pos
);
2352 void DoGridCellLeftUp(wxMouseEvent
& event
, const wxGridCellCoords
& coords
);
2354 // process movement (but not dragging) event in the grid cell area
2355 void DoGridMouseMoveEvent(wxMouseEvent
& event
,
2356 const wxGridCellCoords
& coords
,
2357 const wxPoint
& pos
);
2359 // process mouse events in the grid window
2360 void ProcessGridCellMouseEvent(wxMouseEvent
& event
);
2362 // process mouse events in the row/column labels/corner windows
2363 void ProcessRowLabelMouseEvent(wxMouseEvent
& event
);
2364 void ProcessColLabelMouseEvent(wxMouseEvent
& event
);
2365 void ProcessCornerLabelMouseEvent(wxMouseEvent
& event
);
2367 void DoColHeaderClick(int col
);
2369 void DoStartResizeCol(int col
);
2370 void DoUpdateResizeCol(int x
);
2371 void DoUpdateResizeColWidth(int w
);
2372 void DoStartMoveCol(int col
);
2374 void DoEndDragResizeRow();
2375 void DoEndDragResizeCol(wxMouseEvent
*event
= NULL
);
2376 void DoEndMoveCol(int pos
);
2379 // common implementations of methods defined for both rows and columns
2380 void DeselectLine(int line
, const wxGridOperations
& oper
);
2381 void DoEndDragResizeLine(const wxGridOperations
& oper
);
2382 int PosToLinePos(int pos
, bool clipToMinMax
,
2383 const wxGridOperations
& oper
) const;
2384 int PosToLine(int pos
, bool clipToMinMax
,
2385 const wxGridOperations
& oper
) const;
2386 int PosToEdgeOfLine(int pos
, const wxGridOperations
& oper
) const;
2388 bool DoMoveCursor(bool expandSelection
,
2389 const wxGridDirectionOperations
& diroper
);
2390 bool DoMoveCursorByPage(const wxGridDirectionOperations
& diroper
);
2391 bool DoMoveCursorByBlock(bool expandSelection
,
2392 const wxGridDirectionOperations
& diroper
);
2393 void AdvanceToNextNonEmpty(wxGridCellCoords
& coords
,
2394 const wxGridDirectionOperations
& diroper
);
2396 // common part of {Insert,Delete}{Rows,Cols}
2397 bool DoModifyLines(bool (wxGridTableBase::*funcModify
)(size_t, size_t),
2398 int pos
, int num
, bool updateLabels
);
2399 // Append{Rows,Cols} is a bit different because of one less parameter
2400 bool DoAppendLines(bool (wxGridTableBase::*funcAppend
)(size_t),
2401 int num
, bool updateLabels
);
2403 DECLARE_DYNAMIC_CLASS( wxGrid
)
2404 DECLARE_EVENT_TABLE()
2405 DECLARE_NO_COPY_CLASS(wxGrid
)
2408 // ----------------------------------------------------------------------------
2409 // wxGridUpdateLocker prevents updates to a grid during its lifetime
2410 // ----------------------------------------------------------------------------
2412 class WXDLLIMPEXP_ADV wxGridUpdateLocker
2415 // if the pointer is NULL, Create() can be called later
2416 wxGridUpdateLocker(wxGrid
*grid
= NULL
)
2421 // can be called if ctor was used with a NULL pointer, must not be called
2423 void Create(wxGrid
*grid
)
2425 wxASSERT_MSG( !m_grid
, _T("shouldn't be called more than once") );
2430 ~wxGridUpdateLocker()
2437 void Init(wxGrid
*grid
)
2441 m_grid
->BeginBatch();
2446 DECLARE_NO_COPY_CLASS(wxGridUpdateLocker
)
2449 // ----------------------------------------------------------------------------
2450 // Grid event class and event types
2451 // ----------------------------------------------------------------------------
2453 class WXDLLIMPEXP_ADV wxGridEvent
: public wxNotifyEvent
,
2454 public wxKeyboardState
2460 Init(-1, -1, -1, -1, false);
2466 int row
= -1, int col
= -1,
2467 int x
= -1, int y
= -1,
2469 const wxKeyboardState
& kbd
= wxKeyboardState())
2470 : wxNotifyEvent(type
, id
),
2471 wxKeyboardState(kbd
)
2473 Init(row
, col
, x
, y
, sel
);
2474 SetEventObject(obj
);
2477 // explicitly specifying inline allows gcc < 3.4 to
2478 // handle the deprecation attribute even in the constructor.
2479 wxDEPRECATED( inline
2487 bool shift
= false, bool alt
= false, bool meta
= false));
2489 virtual int GetRow() { return m_row
; }
2490 virtual int GetCol() { return m_col
; }
2491 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
2492 bool Selecting() { return m_selecting
; }
2494 virtual wxEvent
*Clone() const { return new wxGridEvent(*this); }
2504 void Init(int row
, int col
, int x
, int y
, bool sel
)
2513 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEvent
)
2516 class WXDLLIMPEXP_ADV wxGridSizeEvent
: public wxNotifyEvent
,
2517 public wxKeyboardState
2526 wxGridSizeEvent(int id
,
2530 int x
= -1, int y
= -1,
2531 const wxKeyboardState
& kbd
= wxKeyboardState())
2532 : wxNotifyEvent(type
, id
),
2533 wxKeyboardState(kbd
)
2535 Init(rowOrCol
, x
, y
);
2537 SetEventObject(obj
);
2540 wxDEPRECATED( inline
2541 wxGridSizeEvent(int id
,
2549 bool meta
= false) );
2551 int GetRowOrCol() { return m_rowOrCol
; }
2552 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
2554 virtual wxEvent
*Clone() const { return new wxGridSizeEvent(*this); }
2562 void Init(int rowOrCol
, int x
, int y
)
2564 m_rowOrCol
= rowOrCol
;
2569 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridSizeEvent
)
2573 class WXDLLIMPEXP_ADV wxGridRangeSelectEvent
: public wxNotifyEvent
,
2574 public wxKeyboardState
2577 wxGridRangeSelectEvent()
2580 Init(wxGridNoCellCoords
, wxGridNoCellCoords
, false);
2583 wxGridRangeSelectEvent(int id
,
2586 const wxGridCellCoords
& topLeft
,
2587 const wxGridCellCoords
& bottomRight
,
2589 const wxKeyboardState
& kbd
= wxKeyboardState())
2590 : wxNotifyEvent(type
, id
),
2591 wxKeyboardState(kbd
)
2593 Init(topLeft
, bottomRight
, sel
);
2595 SetEventObject(obj
);
2598 wxDEPRECATED( inline
2599 wxGridRangeSelectEvent(int id
,
2602 const wxGridCellCoords
& topLeft
,
2603 const wxGridCellCoords
& bottomRight
,
2608 bool meta
= false) );
2610 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
2611 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
2612 int GetTopRow() { return m_topLeft
.GetRow(); }
2613 int GetBottomRow() { return m_bottomRight
.GetRow(); }
2614 int GetLeftCol() { return m_topLeft
.GetCol(); }
2615 int GetRightCol() { return m_bottomRight
.GetCol(); }
2616 bool Selecting() { return m_selecting
; }
2618 virtual wxEvent
*Clone() const { return new wxGridRangeSelectEvent(*this); }
2621 void Init(const wxGridCellCoords
& topLeft
,
2622 const wxGridCellCoords
& bottomRight
,
2625 m_topLeft
= topLeft
;
2626 m_bottomRight
= bottomRight
;
2627 m_selecting
= selecting
;
2630 wxGridCellCoords m_topLeft
;
2631 wxGridCellCoords m_bottomRight
;
2634 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridRangeSelectEvent
)
2638 class WXDLLIMPEXP_ADV wxGridEditorCreatedEvent
: public wxCommandEvent
2641 wxGridEditorCreatedEvent()
2649 wxGridEditorCreatedEvent(int id
, wxEventType type
, wxObject
* obj
,
2650 int row
, int col
, wxControl
* ctrl
);
2652 int GetRow() { return m_row
; }
2653 int GetCol() { return m_col
; }
2654 wxControl
* GetControl() { return m_ctrl
; }
2655 void SetRow(int row
) { m_row
= row
; }
2656 void SetCol(int col
) { m_col
= col
; }
2657 void SetControl(wxControl
* ctrl
) { m_ctrl
= ctrl
; }
2659 virtual wxEvent
*Clone() const { return new wxGridEditorCreatedEvent(*this); }
2666 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEditorCreatedEvent
)
2670 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_CELL_LEFT_CLICK
;
2671 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_CELL_RIGHT_CLICK
;
2672 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_CELL_LEFT_DCLICK
;
2673 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK
;
2674 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_LABEL_LEFT_CLICK
;
2675 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK
;
2676 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK
;
2677 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK
;
2678 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_ROW_SIZE
;
2679 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_COL_SIZE
;
2680 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_RANGE_SELECT
;
2681 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_CELL_CHANGING
;
2682 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_CELL_CHANGED
;
2683 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_SELECT_CELL
;
2684 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_EDITOR_SHOWN
;
2685 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_EDITOR_HIDDEN
;
2686 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_EDITOR_CREATED
;
2687 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_CELL_BEGIN_DRAG
;
2688 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_COL_MOVE
;
2689 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_COL_SORT
;
2691 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
2692 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
2693 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
2694 typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction
)(wxGridEditorCreatedEvent
&);
2696 #define wxGridEventHandler(func) \
2697 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridEventFunction, &func)
2699 #define wxGridSizeEventHandler(func) \
2700 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridSizeEventFunction, &func)
2702 #define wxGridRangeSelectEventHandler(func) \
2703 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridRangeSelectEventFunction, &func)
2705 #define wxGridEditorCreatedEventHandler(func) \
2706 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridEditorCreatedEventFunction, &func)
2708 #define wx__DECLARE_GRIDEVT(evt, id, fn) \
2709 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEventHandler(fn))
2711 #define wx__DECLARE_GRIDSIZEEVT(evt, id, fn) \
2712 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridSizeEventHandler(fn))
2714 #define wx__DECLARE_GRIDRANGESELEVT(evt, id, fn) \
2715 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridRangeSelectEventHandler(fn))
2717 #define wx__DECLARE_GRIDEDITOREVT(evt, id, fn) \
2718 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEditorCreatedEventHandler(fn))
2720 #define EVT_GRID_CMD_CELL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_CLICK, id, fn)
2721 #define EVT_GRID_CMD_CELL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_CLICK, id, fn)
2722 #define EVT_GRID_CMD_CELL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_DCLICK, id, fn)
2723 #define EVT_GRID_CMD_CELL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_DCLICK, id, fn)
2724 #define EVT_GRID_CMD_LABEL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_CLICK, id, fn)
2725 #define EVT_GRID_CMD_LABEL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_CLICK, id, fn)
2726 #define EVT_GRID_CMD_LABEL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_DCLICK, id, fn)
2727 #define EVT_GRID_CMD_LABEL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_DCLICK, id, fn)
2728 #define EVT_GRID_CMD_ROW_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(ROW_SIZE, id, fn)
2729 #define EVT_GRID_CMD_COL_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(COL_SIZE, id, fn)
2730 #define EVT_GRID_CMD_COL_MOVE(id, fn) wx__DECLARE_GRIDEVT(COL_MOVE, id, fn)
2731 #define EVT_GRID_CMD_COL_SORT(id, fn) wx__DECLARE_GRIDEVT(COL_SORT, id, fn)
2732 #define EVT_GRID_CMD_RANGE_SELECT(id, fn) wx__DECLARE_GRIDRANGESELEVT(RANGE_SELECT, id, fn)
2733 #define EVT_GRID_CMD_CELL_CHANGING(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGING, id, fn)
2734 #define EVT_GRID_CMD_CELL_CHANGED(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGED, id, fn)
2735 #define EVT_GRID_CMD_SELECT_CELL(id, fn) wx__DECLARE_GRIDEVT(SELECT_CELL, id, fn)
2736 #define EVT_GRID_CMD_EDITOR_SHOWN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_SHOWN, id, fn)
2737 #define EVT_GRID_CMD_EDITOR_HIDDEN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_HIDDEN, id, fn)
2738 #define EVT_GRID_CMD_EDITOR_CREATED(id, fn) wx__DECLARE_GRIDEDITOREVT(EDITOR_CREATED, id, fn)
2739 #define EVT_GRID_CMD_CELL_BEGIN_DRAG(id, fn) wx__DECLARE_GRIDEVT(CELL_BEGIN_DRAG, id, fn)
2741 // same as above but for any id (exists mainly for backwards compatibility but
2742 // then it's also true that you rarely have multiple grid in the same window)
2743 #define EVT_GRID_CELL_LEFT_CLICK(fn) EVT_GRID_CMD_CELL_LEFT_CLICK(wxID_ANY, fn)
2744 #define EVT_GRID_CELL_RIGHT_CLICK(fn) EVT_GRID_CMD_CELL_RIGHT_CLICK(wxID_ANY, fn)
2745 #define EVT_GRID_CELL_LEFT_DCLICK(fn) EVT_GRID_CMD_CELL_LEFT_DCLICK(wxID_ANY, fn)
2746 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) EVT_GRID_CMD_CELL_RIGHT_DCLICK(wxID_ANY, fn)
2747 #define EVT_GRID_LABEL_LEFT_CLICK(fn) EVT_GRID_CMD_LABEL_LEFT_CLICK(wxID_ANY, fn)
2748 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_CLICK(wxID_ANY, fn)
2749 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) EVT_GRID_CMD_LABEL_LEFT_DCLICK(wxID_ANY, fn)
2750 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_DCLICK(wxID_ANY, fn)
2751 #define EVT_GRID_ROW_SIZE(fn) EVT_GRID_CMD_ROW_SIZE(wxID_ANY, fn)
2752 #define EVT_GRID_COL_SIZE(fn) EVT_GRID_CMD_COL_SIZE(wxID_ANY, fn)
2753 #define EVT_GRID_COL_MOVE(fn) EVT_GRID_CMD_COL_MOVE(wxID_ANY, fn)
2754 #define EVT_GRID_COL_SORT(fn) EVT_GRID_CMD_COL_SORT(wxID_ANY, fn)
2755 #define EVT_GRID_RANGE_SELECT(fn) EVT_GRID_CMD_RANGE_SELECT(wxID_ANY, fn)
2756 #define EVT_GRID_CELL_CHANGING(fn) EVT_GRID_CMD_CELL_CHANGING(wxID_ANY, fn)
2757 #define EVT_GRID_CELL_CHANGED(fn) EVT_GRID_CMD_CELL_CHANGED(wxID_ANY, fn)
2758 #define EVT_GRID_SELECT_CELL(fn) EVT_GRID_CMD_SELECT_CELL(wxID_ANY, fn)
2759 #define EVT_GRID_EDITOR_SHOWN(fn) EVT_GRID_CMD_EDITOR_SHOWN(wxID_ANY, fn)
2760 #define EVT_GRID_EDITOR_HIDDEN(fn) EVT_GRID_CMD_EDITOR_HIDDEN(wxID_ANY, fn)
2761 #define EVT_GRID_EDITOR_CREATED(fn) EVT_GRID_CMD_EDITOR_CREATED(wxID_ANY, fn)
2762 #define EVT_GRID_CELL_BEGIN_DRAG(fn) EVT_GRID_CMD_CELL_BEGIN_DRAG(wxID_ANY, fn)
2764 // we used to have a single wxEVT_GRID_CELL_CHANGE event but it was split into
2765 // wxEVT_GRID_CELL_CHANGING and CHANGED ones in wx 2.9.0, however the CHANGED
2766 // is basically the same as the old CHANGE event so we keep the name for
2768 #if WXWIN_COMPATIBILITY_2_8
2769 #define wxEVT_GRID_CELL_CHANGE wxEVT_GRID_CELL_CHANGED
2771 #define EVT_GRID_CMD_CELL_CHANGE EVT_GRID_CMD_CELL_CHANGED
2772 #define EVT_GRID_CELL_CHANGE EVT_GRID_CELL_CHANGED
2773 #endif // WXWIN_COMPATIBILITY_2_8
2775 #if 0 // TODO: implement these ? others ?
2777 extern const int wxEVT_GRID_CREATE_CELL
;
2778 extern const int wxEVT_GRID_CHANGE_LABELS
;
2779 extern const int wxEVT_GRID_CHANGE_SEL_LABEL
;
2781 #define EVT_GRID_CREATE_CELL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CREATE_CELL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2782 #define EVT_GRID_CHANGE_LABELS(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_LABELS, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2783 #define EVT_GRID_CHANGE_SEL_LABEL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_SEL_LABEL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2787 #endif // wxUSE_GRID
2788 #endif // _WX_GENERIC_GRID_H_