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 wxChar
) 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 wxCheckBox
;
81 class WXDLLIMPEXP_FWD_CORE wxComboBox
;
82 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
84 class WXDLLIMPEXP_FWD_CORE wxSpinCtrl
;
87 class wxGridOperations
;
88 class wxGridRowOperations
;
89 class wxGridColumnOperations
;
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
95 #define wxSafeIncRef(p) if ( p ) (p)->IncRef()
96 #define wxSafeDecRef(p) if ( p ) (p)->DecRef()
98 // ----------------------------------------------------------------------------
99 // wxGridCellWorker: common base class for wxGridCellRenderer and
102 // NB: this is more an implementation convenience than a design issue, so this
103 // class is not documented and is not public at all
104 // ----------------------------------------------------------------------------
106 class WXDLLIMPEXP_ADV wxGridCellWorker
: public wxClientDataContainer
109 wxGridCellWorker() { m_nRef
= 1; }
111 // this class is ref counted: it is created with ref count of 1, so
112 // calling DecRef() once will delete it. Calling IncRef() allows to lock
113 // it until the matching DecRef() is called
114 void IncRef() { m_nRef
++; }
115 void DecRef() { if ( --m_nRef
== 0 ) delete this; }
117 // interpret renderer parameters: arbitrary string whose interpretatin is
118 // left to the derived classes
119 virtual void SetParameters(const wxString
& params
);
122 // virtual dtor for any base class - private because only DecRef() can
124 virtual ~wxGridCellWorker();
129 // suppress the stupid gcc warning about the class having private dtor and
131 friend class wxGridCellWorkerDummyFriend
;
134 // ----------------------------------------------------------------------------
135 // wxGridCellRenderer: this class is responsible for actually drawing the cell
136 // in the grid. You may pass it to the wxGridCellAttr (below) to change the
137 // format of one given cell or to wxGrid::SetDefaultRenderer() to change the
138 // view of all cells. This is an ABC, you will normally use one of the
139 // predefined derived classes or derive your own class from it.
140 // ----------------------------------------------------------------------------
142 class WXDLLIMPEXP_ADV wxGridCellRenderer
: public wxGridCellWorker
145 // draw the given cell on the provided DC inside the given rectangle
146 // using the style specified by the attribute and the default or selected
147 // state corresponding to the isSelected value.
149 // this pure virtual function has a default implementation which will
150 // prepare the DC using the given attribute: it will draw the rectangle
151 // with the bg colour from attr and set the text colour and font
152 virtual void Draw(wxGrid
& grid
,
153 wxGridCellAttr
& attr
,
157 bool isSelected
) = 0;
159 // get the preferred size of the cell for its contents
160 virtual wxSize
GetBestSize(wxGrid
& grid
,
161 wxGridCellAttr
& attr
,
163 int row
, int col
) = 0;
165 // create a new object which is the copy of this one
166 virtual wxGridCellRenderer
*Clone() const = 0;
169 // the default renderer for the cells containing string data
170 class WXDLLIMPEXP_ADV wxGridCellStringRenderer
: public wxGridCellRenderer
174 virtual void Draw(wxGrid
& grid
,
175 wxGridCellAttr
& attr
,
181 // return the string extent
182 virtual wxSize
GetBestSize(wxGrid
& grid
,
183 wxGridCellAttr
& attr
,
187 virtual wxGridCellRenderer
*Clone() const
188 { return new wxGridCellStringRenderer
; }
191 // set the text colours before drawing
192 void SetTextColoursAndFont(const wxGrid
& grid
,
193 const wxGridCellAttr
& attr
,
197 // calc the string extent for given string/font
198 wxSize
DoGetBestSize(const wxGridCellAttr
& attr
,
200 const wxString
& text
);
203 // the default renderer for the cells containing numeric (long) data
204 class WXDLLIMPEXP_ADV wxGridCellNumberRenderer
: public wxGridCellStringRenderer
207 // draw the string right aligned
208 virtual void Draw(wxGrid
& grid
,
209 wxGridCellAttr
& attr
,
215 virtual wxSize
GetBestSize(wxGrid
& grid
,
216 wxGridCellAttr
& attr
,
220 virtual wxGridCellRenderer
*Clone() const
221 { return new wxGridCellNumberRenderer
; }
224 wxString
GetString(const wxGrid
& grid
, int row
, int col
);
227 class WXDLLIMPEXP_ADV wxGridCellFloatRenderer
: public wxGridCellStringRenderer
230 wxGridCellFloatRenderer(int width
= -1, int precision
= -1);
232 // get/change formatting parameters
233 int GetWidth() const { return m_width
; }
234 void SetWidth(int width
) { m_width
= width
; m_format
.clear(); }
235 int GetPrecision() const { return m_precision
; }
236 void SetPrecision(int precision
) { m_precision
= precision
; m_format
.clear(); }
238 // draw the string right aligned with given width/precision
239 virtual void Draw(wxGrid
& grid
,
240 wxGridCellAttr
& attr
,
246 virtual wxSize
GetBestSize(wxGrid
& grid
,
247 wxGridCellAttr
& attr
,
251 // parameters string format is "width[,precision]"
252 virtual void SetParameters(const wxString
& params
);
254 virtual wxGridCellRenderer
*Clone() const;
257 wxString
GetString(const wxGrid
& grid
, int row
, int col
);
260 // formatting parameters
267 // renderer for boolean fields
268 class WXDLLIMPEXP_ADV wxGridCellBoolRenderer
: public wxGridCellRenderer
271 // draw a check mark or nothing
272 virtual void Draw(wxGrid
& grid
,
273 wxGridCellAttr
& attr
,
279 // return the checkmark size
280 virtual wxSize
GetBestSize(wxGrid
& grid
,
281 wxGridCellAttr
& attr
,
285 virtual wxGridCellRenderer
*Clone() const
286 { return new wxGridCellBoolRenderer
; }
289 static wxSize ms_sizeCheckMark
;
292 // ----------------------------------------------------------------------------
293 // wxGridCellEditor: This class is responsible for providing and manipulating
294 // the in-place edit controls for the grid. Instances of wxGridCellEditor
295 // (actually, instances of derived classes since it is an ABC) can be
296 // associated with the cell attributes for individual cells, rows, columns, or
297 // even for the entire grid.
298 // ----------------------------------------------------------------------------
300 class WXDLLIMPEXP_ADV wxGridCellEditor
: public wxGridCellWorker
305 bool IsCreated() { return m_control
!= NULL
; }
306 wxControl
* GetControl() { return m_control
; }
307 void SetControl(wxControl
* control
) { m_control
= control
; }
309 wxGridCellAttr
* GetCellAttr() { return m_attr
; }
310 void SetCellAttr(wxGridCellAttr
* attr
) { m_attr
= attr
; }
312 // Creates the actual edit control
313 virtual void Create(wxWindow
* parent
,
315 wxEvtHandler
* evtHandler
) = 0;
317 // Size and position the edit control
318 virtual void SetSize(const wxRect
& rect
);
320 // Show or hide the edit control, use the specified attributes to set
321 // colours/fonts for it
322 virtual void Show(bool show
, wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
);
324 // Draws the part of the cell not occupied by the control: the base class
325 // version just fills it with background colour from the attribute
326 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
328 // Fetch the value from the table and prepare the edit control
329 // to begin editing. Set the focus to the edit control.
330 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
) = 0;
332 // Complete the editing of the current cell. Returns true if the value has
333 // changed. If necessary, the control may be destroyed.
334 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
) = 0;
336 // Reset the value in the control back to its starting value
337 virtual void Reset() = 0;
339 // return true to allow the given key to start editing: the base class
340 // version only checks that the event has no modifiers. The derived
341 // classes are supposed to do "if ( base::IsAcceptedKey() && ... )" in
342 // their IsAcceptedKey() implementation, although, of course, it is not a
343 // mandatory requirment.
345 // NB: if the key is F2 (special), editing will always start and this
346 // method will not be called at all (but StartingKey() will)
347 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
349 // If the editor is enabled by pressing keys on the grid, this will be
350 // called to let the editor do something about that first key if desired
351 virtual void StartingKey(wxKeyEvent
& event
);
353 // if the editor is enabled by clicking on the cell, this method will be
355 virtual void StartingClick();
357 // Some types of controls on some platforms may need some help
358 // with the Return key.
359 virtual void HandleReturn(wxKeyEvent
& event
);
362 virtual void Destroy();
364 // create a new object which is the copy of this one
365 virtual wxGridCellEditor
*Clone() const = 0;
367 // added GetValue so we can get the value which is in the control
368 virtual wxString
GetValue() const = 0;
371 // the dtor is private because only DecRef() can delete us
372 virtual ~wxGridCellEditor();
374 // the control we show on screen
375 wxControl
* m_control
;
377 // a temporary pointer to the attribute being edited
378 wxGridCellAttr
* m_attr
;
380 // if we change the colours/font of the control from the default ones, we
381 // must restore the default later and we save them here between calls to
382 // Show(true) and Show(false)
387 // suppress the stupid gcc warning about the class having private dtor and
389 friend class wxGridCellEditorDummyFriend
;
391 DECLARE_NO_COPY_CLASS(wxGridCellEditor
)
396 // the editor for string/text data
397 class WXDLLIMPEXP_ADV wxGridCellTextEditor
: public wxGridCellEditor
400 wxGridCellTextEditor();
402 virtual void Create(wxWindow
* parent
,
404 wxEvtHandler
* evtHandler
);
405 virtual void SetSize(const wxRect
& rect
);
407 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
409 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
410 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
411 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
413 virtual void Reset();
414 virtual void StartingKey(wxKeyEvent
& event
);
415 virtual void HandleReturn(wxKeyEvent
& event
);
417 // parameters string format is "max_width"
418 virtual void SetParameters(const wxString
& params
);
420 virtual wxGridCellEditor
*Clone() const
421 { return new wxGridCellTextEditor
; }
423 // added GetValue so we can get the value which is in the control
424 virtual wxString
GetValue() const;
427 wxTextCtrl
*Text() const { return (wxTextCtrl
*)m_control
; }
429 // parts of our virtual functions reused by the derived classes
430 void DoCreate(wxWindow
* parent
, wxWindowID id
, wxEvtHandler
* evtHandler
,
432 void DoBeginEdit(const wxString
& startValue
);
433 void DoReset(const wxString
& startValue
);
436 size_t m_maxChars
; // max number of chars allowed
437 wxString m_startValue
;
439 DECLARE_NO_COPY_CLASS(wxGridCellTextEditor
)
442 // the editor for numeric (long) data
443 class WXDLLIMPEXP_ADV wxGridCellNumberEditor
: public wxGridCellTextEditor
446 // allows to specify the range - if min == max == -1, no range checking is
448 wxGridCellNumberEditor(int min
= -1, int max
= -1);
450 virtual void Create(wxWindow
* parent
,
452 wxEvtHandler
* evtHandler
);
454 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
455 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
456 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
458 virtual void Reset();
459 virtual void StartingKey(wxKeyEvent
& event
);
461 // parameters string format is "min,max"
462 virtual void SetParameters(const wxString
& params
);
464 virtual wxGridCellEditor
*Clone() const
465 { return new wxGridCellNumberEditor(m_min
, m_max
); }
467 // added GetValue so we can get the value which is in the control
468 virtual wxString
GetValue() const;
472 wxSpinCtrl
*Spin() const { return (wxSpinCtrl
*)m_control
; }
475 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
476 bool HasRange() const
479 return m_min
!= m_max
;
485 // string representation of m_valueOld
486 wxString
GetString() const
487 { return wxString::Format(_T("%ld"), m_valueOld
); }
495 DECLARE_NO_COPY_CLASS(wxGridCellNumberEditor
)
498 // the editor for floating point numbers (double) data
499 class WXDLLIMPEXP_ADV wxGridCellFloatEditor
: public wxGridCellTextEditor
502 wxGridCellFloatEditor(int width
= -1, int precision
= -1);
504 virtual void Create(wxWindow
* parent
,
506 wxEvtHandler
* evtHandler
);
508 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
509 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
510 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
512 virtual void Reset();
513 virtual void StartingKey(wxKeyEvent
& event
);
515 virtual wxGridCellEditor
*Clone() const
516 { return new wxGridCellFloatEditor(m_width
, m_precision
); }
518 // parameters string format is "width,precision"
519 virtual void SetParameters(const wxString
& params
);
522 // string representation of m_valueOld
523 wxString
GetString() const;
530 DECLARE_NO_COPY_CLASS(wxGridCellFloatEditor
)
533 #endif // wxUSE_TEXTCTRL
537 // the editor for boolean data
538 class WXDLLIMPEXP_ADV wxGridCellBoolEditor
: public wxGridCellEditor
541 wxGridCellBoolEditor() { }
543 virtual void Create(wxWindow
* parent
,
545 wxEvtHandler
* evtHandler
);
547 virtual void SetSize(const wxRect
& rect
);
548 virtual void Show(bool show
, wxGridCellAttr
*attr
= NULL
);
550 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
551 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
552 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
554 virtual void Reset();
555 virtual void StartingClick();
556 virtual void StartingKey(wxKeyEvent
& event
);
558 virtual wxGridCellEditor
*Clone() const
559 { return new wxGridCellBoolEditor
; }
561 // added GetValue so we can get the value which is in the control, see
562 // also UseStringValues()
563 virtual wxString
GetValue() const;
565 // set the string values returned by GetValue() for the true and false
566 // states, respectively
567 static void UseStringValues(const wxString
& valueTrue
= _T("1"),
568 const wxString
& valueFalse
= wxEmptyString
);
570 // return true if the given string is equal to the string representation of
571 // true value which we currently use
572 static bool IsTrueValue(const wxString
& value
);
575 wxCheckBox
*CBox() const { return (wxCheckBox
*)m_control
; }
580 static wxString ms_stringValues
[2];
582 DECLARE_NO_COPY_CLASS(wxGridCellBoolEditor
)
585 #endif // wxUSE_CHECKBOX
589 // the editor for string data allowing to choose from the list of strings
590 class WXDLLIMPEXP_ADV wxGridCellChoiceEditor
: public wxGridCellEditor
593 // if !allowOthers, user can't type a string not in choices array
594 wxGridCellChoiceEditor(size_t count
= 0,
595 const wxString choices
[] = NULL
,
596 bool allowOthers
= false);
597 wxGridCellChoiceEditor(const wxArrayString
& choices
,
598 bool allowOthers
= false);
600 virtual void Create(wxWindow
* parent
,
602 wxEvtHandler
* evtHandler
);
604 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
606 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
607 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
609 virtual void Reset();
611 // parameters string format is "item1[,item2[...,itemN]]"
612 virtual void SetParameters(const wxString
& params
);
614 virtual wxGridCellEditor
*Clone() const;
616 // added GetValue so we can get the value which is in the control
617 virtual wxString
GetValue() const;
620 wxComboBox
*Combo() const { return (wxComboBox
*)m_control
; }
622 // DJC - (MAPTEK) you at least need access to m_choices if you
623 // wish to override this class
625 wxString m_startValue
;
626 wxArrayString m_choices
;
629 DECLARE_NO_COPY_CLASS(wxGridCellChoiceEditor
)
632 #endif // wxUSE_COMBOBOX
634 // ----------------------------------------------------------------------------
635 // wxGridCellAttr: this class can be used to alter the cells appearance in
636 // the grid by changing their colour/font/... from default. An object of this
637 // class may be returned by wxGridTable::GetAttr().
638 // ----------------------------------------------------------------------------
640 class WXDLLIMPEXP_ADV wxGridCellAttr
: public wxClientDataContainer
654 wxGridCellAttr(wxGridCellAttr
*attrDefault
= NULL
)
658 // MB: args used to be 0,0 here but wxALIGN_LEFT is 0
659 SetAlignment(-1, -1);
662 // VZ: considering the number of members wxGridCellAttr has now, this ctor
663 // seems to be pretty useless... may be we should just remove it?
664 wxGridCellAttr(const wxColour
& colText
,
665 const wxColour
& colBack
,
669 : m_colText(colText
), m_colBack(colBack
), m_font(font
)
672 SetAlignment(hAlign
, vAlign
);
675 // creates a new copy of this object
676 wxGridCellAttr
*Clone() const;
677 void MergeWith(wxGridCellAttr
*mergefrom
);
679 // this class is ref counted: it is created with ref count of 1, so
680 // calling DecRef() once will delete it. Calling IncRef() allows to lock
681 // it until the matching DecRef() is called
682 void IncRef() { m_nRef
++; }
683 void DecRef() { if ( --m_nRef
== 0 ) delete this; }
686 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
687 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
688 void SetFont(const wxFont
& font
) { m_font
= font
; }
689 void SetAlignment(int hAlign
, int vAlign
)
694 void SetSize(int num_rows
, int num_cols
);
695 void SetOverflow(bool allow
= true)
696 { m_overflow
= allow
? Overflow
: SingleCell
; }
697 void SetReadOnly(bool isReadOnly
= true)
698 { m_isReadOnly
= isReadOnly
? ReadOnly
: ReadWrite
; }
700 // takes ownership of the pointer
701 void SetRenderer(wxGridCellRenderer
*renderer
)
702 { wxSafeDecRef(m_renderer
); m_renderer
= renderer
; }
703 void SetEditor(wxGridCellEditor
* editor
)
704 { wxSafeDecRef(m_editor
); m_editor
= editor
; }
706 void SetKind(wxAttrKind kind
) { m_attrkind
= kind
; }
709 bool HasTextColour() const { return m_colText
.Ok(); }
710 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
711 bool HasFont() const { return m_font
.Ok(); }
712 bool HasAlignment() const { return (m_hAlign
!= -1 || m_vAlign
!= -1); }
713 bool HasRenderer() const { return m_renderer
!= NULL
; }
714 bool HasEditor() const { return m_editor
!= NULL
; }
715 bool HasReadWriteMode() const { return m_isReadOnly
!= Unset
; }
716 bool HasOverflowMode() const { return m_overflow
!= UnsetOverflow
; }
717 bool HasSize() const { return m_sizeRows
!= 1 || m_sizeCols
!= 1; }
719 const wxColour
& GetTextColour() const;
720 const wxColour
& GetBackgroundColour() const;
721 const wxFont
& GetFont() const;
722 void GetAlignment(int *hAlign
, int *vAlign
) const;
723 void GetSize(int *num_rows
, int *num_cols
) const;
724 bool GetOverflow() const
725 { return m_overflow
!= SingleCell
; }
726 wxGridCellRenderer
*GetRenderer(const wxGrid
* grid
, int row
, int col
) const;
727 wxGridCellEditor
*GetEditor(const wxGrid
* grid
, int row
, int col
) const;
729 bool IsReadOnly() const { return m_isReadOnly
== wxGridCellAttr::ReadOnly
; }
731 wxAttrKind
GetKind() { return m_attrkind
; }
733 void SetDefAttr(wxGridCellAttr
* defAttr
) { m_defGridAttr
= defAttr
; }
736 // the dtor is private because only DecRef() can delete us
737 virtual ~wxGridCellAttr()
739 wxSafeDecRef(m_renderer
);
740 wxSafeDecRef(m_editor
);
751 enum wxAttrOverflowMode
758 // the common part of all ctors
759 void Init(wxGridCellAttr
*attrDefault
= NULL
);
762 // the ref count - when it goes to 0, we die
773 wxAttrOverflowMode m_overflow
;
775 wxGridCellRenderer
* m_renderer
;
776 wxGridCellEditor
* m_editor
;
777 wxGridCellAttr
* m_defGridAttr
;
779 wxAttrReadMode m_isReadOnly
;
781 wxAttrKind m_attrkind
;
783 // use Clone() instead
784 DECLARE_NO_COPY_CLASS(wxGridCellAttr
)
786 // suppress the stupid gcc warning about the class having private dtor and
788 friend class wxGridCellAttrDummyFriend
;
791 // ----------------------------------------------------------------------------
792 // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
794 // ----------------------------------------------------------------------------
796 // implementation note: we separate it from wxGridTableBase because we wish to
797 // avoid deriving a new table class if possible, and sometimes it will be
798 // enough to just derive another wxGridCellAttrProvider instead
800 // the default implementation is reasonably efficient for the generic case,
801 // but you might still wish to implement your own for some specific situations
802 // if you have performance problems with the stock one
803 class WXDLLIMPEXP_ADV wxGridCellAttrProvider
: public wxClientDataContainer
806 wxGridCellAttrProvider();
807 virtual ~wxGridCellAttrProvider();
809 // DecRef() must be called on the returned pointer
810 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
811 wxGridCellAttr::wxAttrKind kind
) const;
813 // all these functions take ownership of the pointer, don't call DecRef()
815 virtual void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
816 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
817 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
819 // these functions must be called whenever some rows/cols are deleted
820 // because the internal data must be updated then
821 void UpdateAttrRows( size_t pos
, int numRows
);
822 void UpdateAttrCols( size_t pos
, int numCols
);
827 wxGridCellAttrProviderData
*m_data
;
829 DECLARE_NO_COPY_CLASS(wxGridCellAttrProvider
)
832 //////////////////////////////////////////////////////////////////////
834 // Grid table classes
836 //////////////////////////////////////////////////////////////////////
839 class WXDLLIMPEXP_ADV wxGridTableBase
: public wxObject
, public wxClientDataContainer
843 virtual ~wxGridTableBase();
845 // You must override these functions in a derived table class
847 virtual int GetNumberRows() = 0;
848 virtual int GetNumberCols() = 0;
849 virtual bool IsEmptyCell( int row
, int col
) = 0;
850 virtual wxString
GetValue( int row
, int col
) = 0;
851 virtual void SetValue( int row
, int col
, const wxString
& value
) = 0;
853 // Data type determination and value access
854 virtual wxString
GetTypeName( int row
, int col
);
855 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
856 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
858 virtual long GetValueAsLong( int row
, int col
);
859 virtual double GetValueAsDouble( int row
, int col
);
860 virtual bool GetValueAsBool( int row
, int col
);
862 virtual void SetValueAsLong( int row
, int col
, long value
);
863 virtual void SetValueAsDouble( int row
, int col
, double value
);
864 virtual void SetValueAsBool( int row
, int col
, bool value
);
866 // For user defined types
867 virtual void* GetValueAsCustom( int row
, int col
, const wxString
& typeName
);
868 virtual void SetValueAsCustom( int row
, int col
, const wxString
& typeName
, void* value
);
871 // Overriding these is optional
873 virtual void SetView( wxGrid
*grid
) { m_view
= grid
; }
874 virtual wxGrid
* GetView() const { return m_view
; }
876 virtual void Clear() {}
877 virtual bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
878 virtual bool AppendRows( size_t numRows
= 1 );
879 virtual bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
880 virtual bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
881 virtual bool AppendCols( size_t numCols
= 1 );
882 virtual bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
884 virtual wxString
GetRowLabelValue( int row
);
885 virtual wxString
GetColLabelValue( int col
);
886 virtual void SetRowLabelValue( int WXUNUSED(row
), const wxString
& ) {}
887 virtual void SetColLabelValue( int WXUNUSED(col
), const wxString
& ) {}
889 // Attribute handling
892 // give us the attr provider to use - we take ownership of the pointer
893 void SetAttrProvider(wxGridCellAttrProvider
*attrProvider
);
895 // get the currently used attr provider (may be NULL)
896 wxGridCellAttrProvider
*GetAttrProvider() const { return m_attrProvider
; }
898 // Does this table allow attributes? Default implementation creates
899 // a wxGridCellAttrProvider if necessary.
900 virtual bool CanHaveAttributes();
902 // by default forwarded to wxGridCellAttrProvider if any. May be
903 // overridden to handle attributes directly in the table.
904 virtual wxGridCellAttr
*GetAttr( int row
, int col
,
905 wxGridCellAttr::wxAttrKind kind
);
908 // these functions take ownership of the pointer
909 virtual void SetAttr(wxGridCellAttr
* attr
, int row
, int col
);
910 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
911 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
915 wxGridCellAttrProvider
*m_attrProvider
;
917 DECLARE_ABSTRACT_CLASS(wxGridTableBase
)
918 DECLARE_NO_COPY_CLASS(wxGridTableBase
)
922 // ----------------------------------------------------------------------------
923 // wxGridTableMessage
924 // ----------------------------------------------------------------------------
926 // IDs for messages sent from grid table to view
928 enum wxGridTableRequest
930 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
= 2000,
931 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
,
932 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
933 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
934 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
935 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
936 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
937 wxGRIDTABLE_NOTIFY_COLS_DELETED
940 class WXDLLIMPEXP_ADV wxGridTableMessage
943 wxGridTableMessage();
944 wxGridTableMessage( wxGridTableBase
*table
, int id
,
948 void SetTableObject( wxGridTableBase
*table
) { m_table
= table
; }
949 wxGridTableBase
* GetTableObject() const { return m_table
; }
950 void SetId( int id
) { m_id
= id
; }
951 int GetId() { return m_id
; }
952 void SetCommandInt( int comInt1
) { m_comInt1
= comInt1
; }
953 int GetCommandInt() { return m_comInt1
; }
954 void SetCommandInt2( int comInt2
) { m_comInt2
= comInt2
; }
955 int GetCommandInt2() { return m_comInt2
; }
958 wxGridTableBase
*m_table
;
963 DECLARE_NO_COPY_CLASS(wxGridTableMessage
)
968 // ------ wxGridStringArray
969 // A 2-dimensional array of strings for data values
972 WX_DECLARE_OBJARRAY_WITH_DECL(wxArrayString
, wxGridStringArray
,
973 class WXDLLIMPEXP_ADV
);
977 // ------ wxGridStringTable
979 // Simplest type of data table for a grid for small tables of strings
980 // that are stored in memory
983 class WXDLLIMPEXP_ADV wxGridStringTable
: public wxGridTableBase
987 wxGridStringTable( int numRows
, int numCols
);
988 virtual ~wxGridStringTable();
990 // these are pure virtual in wxGridTableBase
994 wxString
GetValue( int row
, int col
);
995 void SetValue( int row
, int col
, const wxString
& s
);
996 bool IsEmptyCell( int row
, int col
);
998 // overridden functions from wxGridTableBase
1001 bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
1002 bool AppendRows( size_t numRows
= 1 );
1003 bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
1004 bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
1005 bool AppendCols( size_t numCols
= 1 );
1006 bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
1008 void SetRowLabelValue( int row
, const wxString
& );
1009 void SetColLabelValue( int col
, const wxString
& );
1010 wxString
GetRowLabelValue( int row
);
1011 wxString
GetColLabelValue( int col
);
1014 wxGridStringArray m_data
;
1016 // These only get used if you set your own labels, otherwise the
1017 // GetRow/ColLabelValue functions return wxGridTableBase defaults
1019 wxArrayString m_rowLabels
;
1020 wxArrayString m_colLabels
;
1022 DECLARE_DYNAMIC_CLASS_NO_COPY( wxGridStringTable
)
1027 // ============================================================================
1028 // Grid view classes
1029 // ============================================================================
1031 // ----------------------------------------------------------------------------
1032 // wxGridCellCoords: location of a cell in the grid
1033 // ----------------------------------------------------------------------------
1035 class WXDLLIMPEXP_ADV wxGridCellCoords
1038 wxGridCellCoords() { m_row
= m_col
= -1; }
1039 wxGridCellCoords( int r
, int c
) { m_row
= r
; m_col
= c
; }
1041 // default copy ctor is ok
1043 int GetRow() const { return m_row
; }
1044 void SetRow( int n
) { m_row
= n
; }
1045 int GetCol() const { return m_col
; }
1046 void SetCol( int n
) { m_col
= n
; }
1047 void Set( int row
, int col
) { m_row
= row
; m_col
= col
; }
1049 wxGridCellCoords
& operator=( const wxGridCellCoords
& other
)
1051 if ( &other
!= this )
1059 bool operator==( const wxGridCellCoords
& other
) const
1061 return (m_row
== other
.m_row
&& m_col
== other
.m_col
);
1064 bool operator!=( const wxGridCellCoords
& other
) const
1066 return (m_row
!= other
.m_row
|| m_col
!= other
.m_col
);
1069 bool operator!() const
1071 return (m_row
== -1 && m_col
== -1 );
1080 // For comparisons...
1082 extern WXDLLIMPEXP_ADV wxGridCellCoords wxGridNoCellCoords
;
1083 extern WXDLLIMPEXP_ADV wxRect wxGridNoCellRect
;
1085 // An array of cell coords...
1087 WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellCoords
, wxGridCellCoordsArray
,
1088 class WXDLLIMPEXP_ADV
);
1090 // ----------------------------------------------------------------------------
1092 // ----------------------------------------------------------------------------
1094 class WXDLLIMPEXP_ADV wxGrid
: public wxScrolledWindow
1097 // possible selection modes
1098 enum wxGridSelectionModes
1100 wxGridSelectCells
= 0, // allow selecting anything
1101 wxGridSelectRows
= 1, // allow selecting only entire rows
1102 wxGridSelectColumns
= 2, // allow selecting only entire columns
1103 wxGridSelectRowsOrColumns
= wxGridSelectRows
| wxGridSelectColumns
1106 // creation and destruction
1107 // ------------------------
1109 // ctor and Create() create the grid window, as with the other controls
1112 wxGrid(wxWindow
*parent
,
1114 const wxPoint
& pos
= wxDefaultPosition
,
1115 const wxSize
& size
= wxDefaultSize
,
1116 long style
= wxWANTS_CHARS
,
1117 const wxString
& name
= wxGridNameStr
);
1119 bool Create(wxWindow
*parent
,
1121 const wxPoint
& pos
= wxDefaultPosition
,
1122 const wxSize
& size
= wxDefaultSize
,
1123 long style
= wxWANTS_CHARS
,
1124 const wxString
& name
= wxGridNameStr
);
1128 // however to initialize grid data either CreateGrid() or SetTable() must
1131 // this is basically equivalent to
1133 // SetTable(new wxGridStringTable(numRows, numCols), true, selmode)
1135 bool CreateGrid( int numRows
, int numCols
,
1136 wxGridSelectionModes selmode
= wxGridSelectCells
);
1138 bool SetTable( wxGridTableBase
*table
,
1139 bool takeOwnership
= false,
1140 wxGridSelectionModes selmode
= wxGridSelectCells
);
1143 void SetSelectionMode(wxGridSelectionModes selmode
);
1144 wxGridSelectionModes
GetSelectionMode() const;
1146 // ------ grid dimensions
1148 int GetNumberRows() const { return m_numRows
; }
1149 int GetNumberCols() const { return m_numCols
; }
1152 // ------ display update functions
1154 wxArrayInt
CalcRowLabelsExposed( const wxRegion
& reg
) const;
1156 wxArrayInt
CalcColLabelsExposed( const wxRegion
& reg
) const;
1157 wxGridCellCoordsArray
CalcCellsExposed( const wxRegion
& reg
) const;
1160 // ------ event handlers
1162 void ProcessRowLabelMouseEvent( wxMouseEvent
& event
);
1163 void ProcessColLabelMouseEvent( wxMouseEvent
& event
);
1164 void ProcessCornerLabelMouseEvent( wxMouseEvent
& event
);
1165 void ProcessGridCellMouseEvent( wxMouseEvent
& event
);
1166 bool ProcessTableMessage( wxGridTableMessage
& );
1168 void DoEndDragResizeRow();
1169 void DoEndDragResizeCol();
1170 void DoEndDragMoveCol();
1172 wxGridTableBase
* GetTable() const { return m_table
; }
1175 bool InsertRows( int pos
= 0, int numRows
= 1, bool updateLabels
= true );
1176 bool AppendRows( int numRows
= 1, bool updateLabels
= true );
1177 bool DeleteRows( int pos
= 0, int numRows
= 1, bool updateLabels
= true );
1178 bool InsertCols( int pos
= 0, int numCols
= 1, bool updateLabels
= true );
1179 bool AppendCols( int numCols
= 1, bool updateLabels
= true );
1180 bool DeleteCols( int pos
= 0, int numCols
= 1, bool updateLabels
= true );
1182 void DrawGridCellArea( wxDC
& dc
, const wxGridCellCoordsArray
& cells
);
1183 void DrawGridSpace( wxDC
& dc
);
1184 void DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& );
1185 void DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
);
1186 void DrawCell( wxDC
& dc
, const wxGridCellCoords
& );
1187 void DrawHighlight(wxDC
& dc
, const wxGridCellCoordsArray
& cells
);
1189 // this function is called when the current cell highlight must be redrawn
1190 // and may be overridden by the user
1191 virtual void DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
);
1193 virtual void DrawRowLabels( wxDC
& dc
, const wxArrayInt
& rows
);
1194 virtual void DrawRowLabel( wxDC
& dc
, int row
);
1196 virtual void DrawColLabels( wxDC
& dc
, const wxArrayInt
& cols
);
1197 virtual void DrawColLabel( wxDC
& dc
, int col
);
1199 virtual void DrawCornerLabel(wxDC
& dc
);
1201 // ------ Cell text drawing functions
1203 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
1204 int horizontalAlignment
= wxALIGN_LEFT
,
1205 int verticalAlignment
= wxALIGN_TOP
,
1206 int textOrientation
= wxHORIZONTAL
);
1208 void DrawTextRectangle( wxDC
& dc
, const wxArrayString
& lines
, const wxRect
&,
1209 int horizontalAlignment
= wxALIGN_LEFT
,
1210 int verticalAlignment
= wxALIGN_TOP
,
1211 int textOrientation
= wxHORIZONTAL
);
1214 // Split a string containing newline characters into an array of
1215 // strings and return the number of lines
1217 void StringToLines( const wxString
& value
, wxArrayString
& lines
) const;
1219 void GetTextBoxSize( const wxDC
& dc
,
1220 const wxArrayString
& lines
,
1221 long *width
, long *height
) const;
1225 // Code that does a lot of grid modification can be enclosed
1226 // between BeginBatch() and EndBatch() calls to avoid screen
1229 void BeginBatch() { m_batchCount
++; }
1232 int GetBatchCount() { return m_batchCount
; }
1234 virtual void Refresh(bool eraseb
= true,
1235 const wxRect
* rect
= (const wxRect
*) NULL
);
1237 // Use this, rather than wxWindow::Refresh(), to force an
1238 // immediate repainting of the grid. Has no effect if you are
1239 // already inside a BeginBatch / EndBatch block.
1241 // This function is necessary because wxGrid has a minimal OnPaint()
1242 // handler to reduce screen flicker.
1244 void ForceRefresh();
1247 // ------ edit control functions
1249 bool IsEditable() const { return m_editable
; }
1250 void EnableEditing( bool edit
);
1252 void EnableCellEditControl( bool enable
= true );
1253 void DisableCellEditControl() { EnableCellEditControl(false); }
1254 bool CanEnableCellControl() const;
1255 bool IsCellEditControlEnabled() const;
1256 bool IsCellEditControlShown() const;
1258 bool IsCurrentCellReadOnly() const;
1260 void ShowCellEditControl();
1261 void HideCellEditControl();
1262 void SaveEditControlValue();
1265 // ------ grid location functions
1266 // Note that all of these functions work with the logical coordinates of
1267 // grid cells and labels so you will need to convert from device
1268 // coordinates for mouse events etc.
1270 void XYToCell( int x
, int y
, wxGridCellCoords
& ) const;
1271 int YToRow( int y
, bool clipToMinMax
= false ) const;
1272 int XToCol( int x
, bool clipToMinMax
= false ) const;
1274 int YToEdgeOfRow( int y
) const;
1275 int XToEdgeOfCol( int x
) const;
1277 wxRect
CellToRect( int row
, int col
) const;
1278 wxRect
CellToRect( const wxGridCellCoords
& coords
) const
1279 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
1281 int GetGridCursorRow() const { return m_currentCellCoords
.GetRow(); }
1282 int GetGridCursorCol() const { return m_currentCellCoords
.GetCol(); }
1284 // check to see if a cell is either wholly visible (the default arg) or
1285 // at least partially visible in the grid window
1287 bool IsVisible( int row
, int col
, bool wholeCellVisible
= true ) const;
1288 bool IsVisible( const wxGridCellCoords
& coords
, bool wholeCellVisible
= true ) const
1289 { return IsVisible( coords
.GetRow(), coords
.GetCol(), wholeCellVisible
); }
1290 void MakeCellVisible( int row
, int col
);
1291 void MakeCellVisible( const wxGridCellCoords
& coords
)
1292 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
1295 // ------ grid cursor movement functions
1297 void SetGridCursor( int row
, int col
)
1298 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
1300 bool MoveCursorUp( bool expandSelection
);
1301 bool MoveCursorDown( bool expandSelection
);
1302 bool MoveCursorLeft( bool expandSelection
);
1303 bool MoveCursorRight( bool expandSelection
);
1304 bool MovePageDown();
1306 bool MoveCursorUpBlock( bool expandSelection
);
1307 bool MoveCursorDownBlock( bool expandSelection
);
1308 bool MoveCursorLeftBlock( bool expandSelection
);
1309 bool MoveCursorRightBlock( bool expandSelection
);
1312 // ------ label and gridline formatting
1314 int GetDefaultRowLabelSize() const { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
1315 int GetRowLabelSize() const { return m_rowLabelWidth
; }
1316 int GetDefaultColLabelSize() const { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
1317 int GetColLabelSize() const { return m_colLabelHeight
; }
1318 wxColour
GetLabelBackgroundColour() const { return m_labelBackgroundColour
; }
1319 wxColour
GetLabelTextColour() const { return m_labelTextColour
; }
1320 wxFont
GetLabelFont() const { return m_labelFont
; }
1321 void GetRowLabelAlignment( int *horiz
, int *vert
) const;
1322 void GetColLabelAlignment( int *horiz
, int *vert
) const;
1323 int GetColLabelTextOrientation() const;
1324 wxString
GetRowLabelValue( int row
) const;
1325 wxString
GetColLabelValue( int col
) const;
1326 wxColour
GetGridLineColour() const { return m_gridLineColour
; }
1328 // these methods may be overridden to customize individual grid lines
1330 virtual wxPen
GetDefaultGridLinePen();
1331 virtual wxPen
GetRowGridLinePen(int row
);
1332 virtual wxPen
GetColGridLinePen(int col
);
1333 wxColour
GetCellHighlightColour() const { return m_cellHighlightColour
; }
1334 int GetCellHighlightPenWidth() const { return m_cellHighlightPenWidth
; }
1335 int GetCellHighlightROPenWidth() const { return m_cellHighlightROPenWidth
; }
1337 void SetUseNativeColLabels( bool native
= true );
1338 void SetRowLabelSize( int width
);
1339 void SetColLabelSize( int height
);
1340 void HideRowLabels() { SetRowLabelSize( 0 ); }
1341 void HideColLabels() { SetColLabelSize( 0 ); }
1342 void SetLabelBackgroundColour( const wxColour
& );
1343 void SetLabelTextColour( const wxColour
& );
1344 void SetLabelFont( const wxFont
& );
1345 void SetRowLabelAlignment( int horiz
, int vert
);
1346 void SetColLabelAlignment( int horiz
, int vert
);
1347 void SetColLabelTextOrientation( int textOrientation
);
1348 void SetRowLabelValue( int row
, const wxString
& );
1349 void SetColLabelValue( int col
, const wxString
& );
1350 void SetGridLineColour( const wxColour
& );
1351 void SetCellHighlightColour( const wxColour
& );
1352 void SetCellHighlightPenWidth(int width
);
1353 void SetCellHighlightROPenWidth(int width
);
1355 void EnableDragRowSize( bool enable
= true );
1356 void DisableDragRowSize() { EnableDragRowSize( false ); }
1357 bool CanDragRowSize() const { return m_canDragRowSize
; }
1358 void EnableDragColSize( bool enable
= true );
1359 void DisableDragColSize() { EnableDragColSize( false ); }
1360 bool CanDragColSize() const { return m_canDragColSize
; }
1361 void EnableDragColMove( bool enable
= true );
1362 void DisableDragColMove() { EnableDragColMove( false ); }
1363 bool CanDragColMove() const { return m_canDragColMove
; }
1364 void EnableDragGridSize(bool enable
= true);
1365 void DisableDragGridSize() { EnableDragGridSize(false); }
1366 bool CanDragGridSize() const { return m_canDragGridSize
; }
1368 void EnableDragCell( bool enable
= true );
1369 void DisableDragCell() { EnableDragCell( false ); }
1370 bool CanDragCell() const { return m_canDragCell
; }
1372 // this sets the specified attribute for this cell or in this row/col
1373 void SetAttr(int row
, int col
, wxGridCellAttr
*attr
);
1374 void SetRowAttr(int row
, wxGridCellAttr
*attr
);
1375 void SetColAttr(int col
, wxGridCellAttr
*attr
);
1377 // returns the attribute we may modify in place: a new one if this cell
1378 // doesn't have any yet or the existing one if it does
1380 // DecRef() must be called on the returned pointer, as usual
1381 wxGridCellAttr
*GetOrCreateCellAttr(int row
, int col
) const;
1384 // shortcuts for setting the column parameters
1386 // set the format for the data in the column: default is string
1387 void SetColFormatBool(int col
);
1388 void SetColFormatNumber(int col
);
1389 void SetColFormatFloat(int col
, int width
= -1, int precision
= -1);
1390 void SetColFormatCustom(int col
, const wxString
& typeName
);
1392 void EnableGridLines( bool enable
= true );
1393 bool GridLinesEnabled() const { return m_gridLinesEnabled
; }
1395 // ------ row and col formatting
1397 int GetDefaultRowSize() const;
1398 int GetRowSize( int row
) const;
1399 int GetDefaultColSize() const;
1400 int GetColSize( int col
) const;
1401 wxColour
GetDefaultCellBackgroundColour() const;
1402 wxColour
GetCellBackgroundColour( int row
, int col
) const;
1403 wxColour
GetDefaultCellTextColour() const;
1404 wxColour
GetCellTextColour( int row
, int col
) const;
1405 wxFont
GetDefaultCellFont() const;
1406 wxFont
GetCellFont( int row
, int col
) const;
1407 void GetDefaultCellAlignment( int *horiz
, int *vert
) const;
1408 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
) const;
1409 bool GetDefaultCellOverflow() const;
1410 bool GetCellOverflow( int row
, int col
) const;
1411 void GetCellSize( int row
, int col
, int *num_rows
, int *num_cols
) const;
1412 wxSize
GetCellSize(const wxGridCellCoords
& coords
)
1415 GetCellSize(coords
.GetRow(), coords
.GetCol(), &s
.x
, &s
.y
);
1419 void SetDefaultRowSize( int height
, bool resizeExistingRows
= false );
1420 void SetRowSize( int row
, int height
);
1421 void SetDefaultColSize( int width
, bool resizeExistingCols
= false );
1423 void SetColSize( int col
, int width
);
1426 int GetColAt( int colPos
) const
1428 if ( m_colAt
.IsEmpty() )
1431 return m_colAt
[colPos
];
1434 void SetColPos( int colID
, int newPos
);
1436 int GetColPos( int colID
) const
1438 if ( m_colAt
.IsEmpty() )
1442 for ( int i
= 0; i
< m_numCols
; i
++ )
1444 if ( m_colAt
[i
] == colID
)
1452 // automatically size the column or row to fit to its contents, if
1453 // setAsMin is true, this optimal width will also be set as minimal width
1455 void AutoSizeColumn( int col
, bool setAsMin
= true )
1456 { AutoSizeColOrRow(col
, setAsMin
, wxGRID_COLUMN
); }
1457 void AutoSizeRow( int row
, bool setAsMin
= true )
1458 { AutoSizeColOrRow(row
, setAsMin
, wxGRID_ROW
); }
1460 // auto size all columns (very ineffective for big grids!)
1461 void AutoSizeColumns( bool setAsMin
= true )
1462 { (void)SetOrCalcColumnSizes(false, setAsMin
); }
1464 void AutoSizeRows( bool setAsMin
= true )
1465 { (void)SetOrCalcRowSizes(false, setAsMin
); }
1467 // auto size the grid, that is make the columns/rows of the "right" size
1468 // and also set the grid size to just fit its contents
1471 // Note for both AutoSizeRowLabelSize and AutoSizeColLabelSize:
1472 // If col equals to wxGRID_AUTOSIZE value then function autosizes labels column
1473 // instead of data column. Note that this operation may be slow for large
1475 // autosize row height depending on label text
1476 void AutoSizeRowLabelSize( int row
);
1478 // autosize column width depending on label text
1479 void AutoSizeColLabelSize( int col
);
1481 // column won't be resized to be lesser width - this must be called during
1482 // the grid creation because it won't resize the column if it's already
1483 // narrower than the minimal width
1484 void SetColMinimalWidth( int col
, int width
);
1485 void SetRowMinimalHeight( int row
, int width
);
1487 /* These members can be used to query and modify the minimal
1488 * acceptable size of grid rows and columns. Call this function in
1489 * your code which creates the grid if you want to display cells
1490 * with a size smaller than the default acceptable minimum size.
1491 * Like the members SetColMinimalWidth and SetRowMinimalWidth,
1492 * the existing rows or columns will not be checked/resized.
1494 void SetColMinimalAcceptableWidth( int width
);
1495 void SetRowMinimalAcceptableHeight( int width
);
1496 int GetColMinimalAcceptableWidth() const;
1497 int GetRowMinimalAcceptableHeight() const;
1499 void SetDefaultCellBackgroundColour( const wxColour
& );
1500 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
1501 void SetDefaultCellTextColour( const wxColour
& );
1503 void SetCellTextColour( int row
, int col
, const wxColour
& );
1504 void SetDefaultCellFont( const wxFont
& );
1505 void SetCellFont( int row
, int col
, const wxFont
& );
1506 void SetDefaultCellAlignment( int horiz
, int vert
);
1507 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
1508 void SetDefaultCellOverflow( bool allow
);
1509 void SetCellOverflow( int row
, int col
, bool allow
);
1510 void SetCellSize( int row
, int col
, int num_rows
, int num_cols
);
1512 // takes ownership of the pointer
1513 void SetDefaultRenderer(wxGridCellRenderer
*renderer
);
1514 void SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
);
1515 wxGridCellRenderer
*GetDefaultRenderer() const;
1516 wxGridCellRenderer
* GetCellRenderer(int row
, int col
) const;
1518 // takes ownership of the pointer
1519 void SetDefaultEditor(wxGridCellEditor
*editor
);
1520 void SetCellEditor(int row
, int col
, wxGridCellEditor
*editor
);
1521 wxGridCellEditor
*GetDefaultEditor() const;
1522 wxGridCellEditor
* GetCellEditor(int row
, int col
) const;
1526 // ------ cell value accessors
1528 wxString
GetCellValue( int row
, int col
) const
1532 return m_table
->GetValue( row
, col
);
1536 return wxEmptyString
;
1540 wxString
GetCellValue( const wxGridCellCoords
& coords
) const
1541 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
1543 void SetCellValue( int row
, int col
, const wxString
& s
);
1544 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
1545 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
1547 // returns true if the cell can't be edited
1548 bool IsReadOnly(int row
, int col
) const;
1550 // make the cell editable/readonly
1551 void SetReadOnly(int row
, int col
, bool isReadOnly
= true);
1553 // ------ select blocks of cells
1555 void SelectRow( int row
, bool addToSelected
= false );
1556 void SelectCol( int col
, bool addToSelected
= false );
1558 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
,
1559 bool addToSelected
= false );
1561 void SelectBlock( const wxGridCellCoords
& topLeft
,
1562 const wxGridCellCoords
& bottomRight
,
1563 bool addToSelected
= false )
1564 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
1565 bottomRight
.GetRow(), bottomRight
.GetCol(),
1570 bool IsSelection() const;
1572 // ------ deselect blocks or cells
1574 void DeselectRow( int row
);
1575 void DeselectCol( int col
);
1576 void DeselectCell( int row
, int col
);
1578 void ClearSelection();
1580 bool IsInSelection( int row
, int col
) const;
1582 bool IsInSelection( const wxGridCellCoords
& coords
) const
1583 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
1585 wxGridCellCoordsArray
GetSelectedCells() const;
1586 wxGridCellCoordsArray
GetSelectionBlockTopLeft() const;
1587 wxGridCellCoordsArray
GetSelectionBlockBottomRight() const;
1588 wxArrayInt
GetSelectedRows() const;
1589 wxArrayInt
GetSelectedCols() const;
1591 // This function returns the rectangle that encloses the block of cells
1592 // limited by TopLeft and BottomRight cell in device coords and clipped
1593 // to the client size of the grid window.
1595 wxRect
BlockToDeviceRect( const wxGridCellCoords
& topLeft
,
1596 const wxGridCellCoords
& bottomRight
) const;
1598 // Access or update the selection fore/back colours
1599 wxColour
GetSelectionBackground() const
1600 { return m_selectionBackground
; }
1601 wxColour
GetSelectionForeground() const
1602 { return m_selectionForeground
; }
1604 void SetSelectionBackground(const wxColour
& c
) { m_selectionBackground
= c
; }
1605 void SetSelectionForeground(const wxColour
& c
) { m_selectionForeground
= c
; }
1608 // Methods for a registry for mapping data types to Renderers/Editors
1609 void RegisterDataType(const wxString
& typeName
,
1610 wxGridCellRenderer
* renderer
,
1611 wxGridCellEditor
* editor
);
1613 virtual wxGridCellEditor
* GetDefaultEditorForCell(int row
, int col
) const;
1614 wxGridCellEditor
* GetDefaultEditorForCell(const wxGridCellCoords
& c
) const
1615 { return GetDefaultEditorForCell(c
.GetRow(), c
.GetCol()); }
1616 virtual wxGridCellRenderer
* GetDefaultRendererForCell(int row
, int col
) const;
1617 virtual wxGridCellEditor
* GetDefaultEditorForType(const wxString
& typeName
) const;
1618 virtual wxGridCellRenderer
* GetDefaultRendererForType(const wxString
& typeName
) const;
1620 // grid may occupy more space than needed for its rows/columns, this
1621 // function allows to set how big this extra space is
1622 void SetMargins(int extraWidth
, int extraHeight
)
1624 m_extraWidth
= extraWidth
;
1625 m_extraHeight
= extraHeight
;
1630 // Accessors for component windows
1631 wxWindow
* GetGridWindow() const { return (wxWindow
*)m_gridWin
; }
1632 wxWindow
* GetGridRowLabelWindow() const { return (wxWindow
*)m_rowLabelWin
; }
1633 wxWindow
* GetGridColLabelWindow() const { return (wxWindow
*)m_colLabelWin
; }
1634 wxWindow
* GetGridCornerLabelWindow() const { return (wxWindow
*)m_cornerLabelWin
; }
1636 // Allow adjustment of scroll increment. The default is (15, 15).
1637 void SetScrollLineX(int x
) { m_scrollLineX
= x
; }
1638 void SetScrollLineY(int y
) { m_scrollLineY
= y
; }
1639 int GetScrollLineX() const { return m_scrollLineX
; }
1640 int GetScrollLineY() const { return m_scrollLineY
; }
1642 // ------- drag and drop
1643 #if wxUSE_DRAG_AND_DROP
1644 virtual void SetDropTarget(wxDropTarget
*dropTarget
);
1645 #endif // wxUSE_DRAG_AND_DROP
1648 #ifdef WXWIN_COMPATIBILITY_2_8
1649 // ------ For compatibility with previous wxGrid only...
1651 // ************************************************
1652 // ** Don't use these in new code because they **
1653 // ** are liable to disappear in a future **
1655 // ************************************************
1658 wxGrid( wxWindow
*parent
,
1659 int x
, int y
, int w
= wxDefaultCoord
, int h
= wxDefaultCoord
,
1660 long style
= wxWANTS_CHARS
,
1661 const wxString
& name
= wxPanelNameStr
)
1662 : wxScrolledWindow( parent
, wxID_ANY
, wxPoint(x
,y
), wxSize(w
,h
),
1663 (style
|wxWANTS_CHARS
), name
)
1669 void SetCellValue( const wxString
& val
, int row
, int col
)
1670 { SetCellValue( row
, col
, val
); }
1672 void UpdateDimensions()
1673 { CalcDimensions(); }
1675 int GetRows() const { return GetNumberRows(); }
1676 int GetCols() const { return GetNumberCols(); }
1677 int GetCursorRow() const { return GetGridCursorRow(); }
1678 int GetCursorColumn() const { return GetGridCursorCol(); }
1680 int GetScrollPosX() const { return 0; }
1681 int GetScrollPosY() const { return 0; }
1683 void SetScrollX( int WXUNUSED(x
) ) { }
1684 void SetScrollY( int WXUNUSED(y
) ) { }
1686 void SetColumnWidth( int col
, int width
)
1687 { SetColSize( col
, width
); }
1689 int GetColumnWidth( int col
) const
1690 { return GetColSize( col
); }
1692 void SetRowHeight( int row
, int height
)
1693 { SetRowSize( row
, height
); }
1695 // GetRowHeight() is below
1697 int GetViewHeight() const // returned num whole rows visible
1700 int GetViewWidth() const // returned num whole cols visible
1703 void SetLabelSize( int orientation
, int sz
)
1705 if ( orientation
== wxHORIZONTAL
)
1706 SetColLabelSize( sz
);
1708 SetRowLabelSize( sz
);
1711 int GetLabelSize( int orientation
) const
1713 if ( orientation
== wxHORIZONTAL
)
1714 return GetColLabelSize();
1716 return GetRowLabelSize();
1719 void SetLabelAlignment( int orientation
, int align
)
1721 if ( orientation
== wxHORIZONTAL
)
1722 SetColLabelAlignment( align
, -1 );
1724 SetRowLabelAlignment( align
, -1 );
1727 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) ) const
1730 if ( orientation
== wxHORIZONTAL
)
1732 GetColLabelAlignment( &h
, &v
);
1737 GetRowLabelAlignment( &h
, &v
);
1742 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
1744 if ( orientation
== wxHORIZONTAL
)
1745 SetColLabelValue( pos
, val
);
1747 SetRowLabelValue( pos
, val
);
1750 wxString
GetLabelValue( int orientation
, int pos
) const
1752 if ( orientation
== wxHORIZONTAL
)
1753 return GetColLabelValue( pos
);
1755 return GetRowLabelValue( pos
);
1758 wxFont
GetCellTextFont() const
1759 { return m_defaultCellAttr
->GetFont(); }
1761 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
1762 { return m_defaultCellAttr
->GetFont(); }
1764 void SetCellTextFont(const wxFont
& fnt
)
1765 { SetDefaultCellFont( fnt
); }
1767 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
1768 { SetCellFont( row
, col
, fnt
); }
1770 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
1771 { SetCellTextColour( row
, col
, val
); }
1773 void SetCellTextColour(const wxColour
& col
)
1774 { SetDefaultCellTextColour( col
); }
1776 void SetCellBackgroundColour(const wxColour
& col
)
1777 { SetDefaultCellBackgroundColour( col
); }
1779 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
1780 { SetCellBackgroundColour( row
, col
, colour
); }
1782 bool GetEditable() const { return IsEditable(); }
1783 void SetEditable( bool edit
= true ) { EnableEditing( edit
); }
1784 bool GetEditInPlace() const { return IsCellEditControlEnabled(); }
1786 void SetEditInPlace(bool WXUNUSED(edit
) = true) { }
1788 void SetCellAlignment( int align
, int row
, int col
)
1789 { SetCellAlignment(row
, col
, align
, wxALIGN_CENTER
); }
1790 void SetCellAlignment( int WXUNUSED(align
) ) {}
1791 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
1793 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
1794 wxPen
& GetDividerPen() const;
1795 void OnActivate(bool WXUNUSED(active
)) {}
1797 // ******** End of compatibility functions **********
1801 // ------ control IDs
1802 enum { wxGRID_CELLCTRL
= 2000,
1805 // ------ control types
1806 enum { wxGRID_TEXTCTRL
= 2100,
1810 #endif // WXWIN_COMPATIBILITY_2_8
1813 // override some base class functions
1814 virtual bool Enable(bool enable
= true);
1815 virtual wxWindow
*GetMainWindowOfCompositeControl()
1816 { return (wxWindow
*)m_gridWin
; }
1819 // implementation only
1820 void CancelMouseCapture();
1823 virtual wxSize
DoGetBestSize() const;
1827 wxGridWindow
*m_gridWin
;
1828 wxGridRowLabelWindow
*m_rowLabelWin
;
1829 wxGridColLabelWindow
*m_colLabelWin
;
1830 wxGridCornerLabelWindow
*m_cornerLabelWin
;
1832 wxGridTableBase
*m_table
;
1838 wxGridCellCoords m_currentCellCoords
;
1840 wxGridCellCoords m_selectingTopLeft
;
1841 wxGridCellCoords m_selectingBottomRight
;
1842 wxGridCellCoords m_selectingKeyboard
;
1843 wxGridSelection
*m_selection
;
1844 wxColour m_selectionBackground
;
1845 wxColour m_selectionForeground
;
1847 // NB: *never* access m_row/col arrays directly because they are created
1848 // on demand, *always* use accessor functions instead!
1850 // init the m_rowHeights/Bottoms arrays with default values
1851 void InitRowHeights();
1853 int m_defaultRowHeight
;
1854 int m_minAcceptableRowHeight
;
1855 wxArrayInt m_rowHeights
;
1856 wxArrayInt m_rowBottoms
;
1858 // init the m_colWidths/Rights arrays
1859 void InitColWidths();
1861 int m_defaultColWidth
;
1862 int m_minAcceptableColWidth
;
1863 wxArrayInt m_colWidths
;
1864 wxArrayInt m_colRights
;
1866 bool m_nativeColumnLabels
;
1868 // get the col/row coords
1869 int GetColWidth(int col
) const;
1870 int GetColLeft(int col
) const;
1871 int GetColRight(int col
) const;
1873 // this function must be public for compatibility...
1875 int GetRowHeight(int row
) const;
1878 int GetRowTop(int row
) const;
1879 int GetRowBottom(int row
) const;
1881 int m_rowLabelWidth
;
1882 int m_colLabelHeight
;
1884 // the size of the margin left to the right and bottom of the cell area
1888 wxColour m_labelBackgroundColour
;
1889 wxColour m_labelTextColour
;
1892 int m_rowLabelHorizAlign
;
1893 int m_rowLabelVertAlign
;
1894 int m_colLabelHorizAlign
;
1895 int m_colLabelVertAlign
;
1896 int m_colLabelTextOrientation
;
1898 bool m_defaultRowLabelValues
;
1899 bool m_defaultColLabelValues
;
1901 wxColour m_gridLineColour
;
1902 bool m_gridLinesEnabled
;
1903 wxColour m_cellHighlightColour
;
1904 int m_cellHighlightPenWidth
;
1905 int m_cellHighlightROPenWidth
;
1908 // common part of AutoSizeColumn/Row() and GetBestSize()
1909 int SetOrCalcColumnSizes(bool calcOnly
, bool setAsMin
= true);
1910 int SetOrCalcRowSizes(bool calcOnly
, bool setAsMin
= true);
1912 // common part of AutoSizeColumn/Row()
1913 void AutoSizeColOrRow(int n
, bool setAsMin
, wxGridDirection direction
);
1915 // Calculate the minimum acceptable size for labels area
1916 wxCoord
CalcColOrRowLabelAreaMinSize(wxGridDirection direction
);
1918 // if a column has a minimal width, it will be the value for it in this
1920 wxLongToLongHashMap m_colMinWidths
,
1923 // get the minimal width of the given column/row
1924 int GetColMinimalWidth(int col
) const;
1925 int GetRowMinimalHeight(int col
) const;
1927 // do we have some place to store attributes in?
1928 bool CanHaveAttributes() const;
1930 // cell attribute cache (currently we only cache 1, may be will do
1931 // more/better later)
1935 wxGridCellAttr
*attr
;
1938 // invalidates the attribute cache
1939 void ClearAttrCache();
1941 // adds an attribute to cache
1942 void CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const;
1944 // looks for an attr in cache, returns true if found
1945 bool LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const;
1947 // looks for the attr in cache, if not found asks the table and caches the
1949 wxGridCellAttr
*GetCellAttr(int row
, int col
) const;
1950 wxGridCellAttr
*GetCellAttr(const wxGridCellCoords
& coords
) const
1951 { return GetCellAttr( coords
.GetRow(), coords
.GetCol() ); }
1953 // the default cell attr object for cells that don't have their own
1954 wxGridCellAttr
* m_defaultCellAttr
;
1961 wxGridTypeRegistry
* m_typeRegistry
;
1965 WXGRID_CURSOR_SELECT_CELL
,
1966 WXGRID_CURSOR_RESIZE_ROW
,
1967 WXGRID_CURSOR_RESIZE_COL
,
1968 WXGRID_CURSOR_SELECT_ROW
,
1969 WXGRID_CURSOR_SELECT_COL
,
1970 WXGRID_CURSOR_MOVE_COL
1973 // this method not only sets m_cursorMode but also sets the correct cursor
1974 // for the given mode and, if captureMouse is not false releases the mouse
1975 // if it was captured and captures it if it must be captured
1977 // for this to work, you should always use it and not set m_cursorMode
1979 void ChangeCursorMode(CursorMode mode
,
1980 wxWindow
*win
= (wxWindow
*)NULL
,
1981 bool captureMouse
= true);
1983 wxWindow
*m_winCapture
; // the window which captured the mouse
1984 CursorMode m_cursorMode
;
1990 bool m_canDragRowSize
;
1991 bool m_canDragColSize
;
1992 bool m_canDragColMove
;
1993 bool m_canDragGridSize
;
1996 // the last position (horizontal or vertical depending on whether the user
1997 // is resizing a column or a row) where a row or column separator line was
1998 // dragged by the user or -1 of there is no drag operation in progress
2003 wxPoint m_startDragPos
;
2005 bool m_waitForSlowClick
;
2007 wxGridCellCoords m_selectionStart
;
2009 wxCursor m_rowResizeCursor
;
2010 wxCursor m_colResizeCursor
;
2012 bool m_editable
; // applies to whole grid
2013 bool m_cellEditCtrlEnabled
; // is in-place edit currently shown?
2015 int m_scrollLineX
; // X scroll increment
2016 int m_scrollLineY
; // Y scroll increment
2021 void CalcDimensions();
2022 void CalcWindowSizes();
2023 bool Redimension( wxGridTableMessage
& );
2026 int SendEvent( const wxEventType
, int row
, int col
, wxMouseEvent
& );
2027 int SendEvent( const wxEventType
, int row
, int col
);
2028 int SendEvent( const wxEventType type
)
2030 return SendEvent(type
,
2031 m_currentCellCoords
.GetRow(),
2032 m_currentCellCoords
.GetCol());
2035 void OnPaint( wxPaintEvent
& );
2036 void OnSize( wxSizeEvent
& );
2037 void OnKeyDown( wxKeyEvent
& );
2038 void OnKeyUp( wxKeyEvent
& );
2039 void OnChar( wxKeyEvent
& );
2040 void OnEraseBackground( wxEraseEvent
& );
2043 void SetCurrentCell( const wxGridCellCoords
& coords
);
2044 void SetCurrentCell( int row
, int col
)
2045 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
2047 void HighlightBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
);
2049 void HighlightBlock( const wxGridCellCoords
& topLeft
,
2050 const wxGridCellCoords
& bottomRight
)
2051 { HighlightBlock( topLeft
.GetRow(), topLeft
.GetCol(),
2052 bottomRight
.GetRow(), bottomRight
.GetCol() ); }
2054 // ------ functions to get/send data (see also public functions)
2056 bool GetModelValues();
2057 bool SetModelValues();
2059 friend class WXDLLIMPEXP_FWD_ADV wxGridSelection
;
2060 friend class wxGridRowOperations
;
2061 friend class wxGridColumnOperations
;
2064 // implement wxScrolledWindow method to return m_gridWin size
2065 virtual wxSize
GetSizeAvailableForScrollTarget(const wxSize
& size
);
2068 // common implementations of methods defined for both rows and columns
2069 void DeselectLine(int line
, const wxGridOperations
& oper
);
2070 void DoEndDragResizeLine(const wxGridOperations
& oper
);
2071 int PosToLine(int pos
, bool clipToMinMax
,
2072 const wxGridOperations
& oper
) const;
2075 DECLARE_DYNAMIC_CLASS( wxGrid
)
2076 DECLARE_EVENT_TABLE()
2077 DECLARE_NO_COPY_CLASS(wxGrid
)
2080 // ----------------------------------------------------------------------------
2081 // wxGridUpdateLocker prevents updates to a grid during its lifetime
2082 // ----------------------------------------------------------------------------
2084 class WXDLLIMPEXP_ADV wxGridUpdateLocker
2087 // if the pointer is NULL, Create() can be called later
2088 wxGridUpdateLocker(wxGrid
*grid
= NULL
)
2093 // can be called if ctor was used with a NULL pointer, must not be called
2095 void Create(wxGrid
*grid
)
2097 wxASSERT_MSG( !m_grid
, _T("shouldn't be called more than once") );
2102 ~wxGridUpdateLocker()
2109 void Init(wxGrid
*grid
)
2113 m_grid
->BeginBatch();
2118 DECLARE_NO_COPY_CLASS(wxGridUpdateLocker
)
2121 // ----------------------------------------------------------------------------
2122 // Grid event class and event types
2123 // ----------------------------------------------------------------------------
2125 class WXDLLIMPEXP_ADV wxGridEvent
: public wxNotifyEvent
2129 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
2130 m_selecting(0), m_control(0), m_meta(0), m_shift(0), m_alt(0)
2134 wxGridEvent(int id
, wxEventType type
, wxObject
* obj
,
2135 int row
=-1, int col
=-1, int x
=-1, int y
=-1, bool sel
= true,
2136 bool control
= false, bool shift
= false, bool alt
= false, bool meta
= false);
2138 virtual int GetRow() { return m_row
; }
2139 virtual int GetCol() { return m_col
; }
2140 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
2141 bool Selecting() { return m_selecting
; }
2142 bool ControlDown() { return m_control
; }
2143 bool MetaDown() { return m_meta
; }
2144 bool ShiftDown() { return m_shift
; }
2145 bool AltDown() { return m_alt
; }
2148 #if defined(__WXMAC__) || defined(__WXCOCOA__)
2151 return ControlDown();
2155 virtual wxEvent
*Clone() const { return new wxGridEvent(*this); }
2168 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEvent
)
2171 class WXDLLIMPEXP_ADV wxGridSizeEvent
: public wxNotifyEvent
2175 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
2176 m_control(0), m_meta(0), m_shift(0), m_alt(0)
2180 wxGridSizeEvent(int id
, wxEventType type
, wxObject
* obj
,
2181 int rowOrCol
=-1, int x
=-1, int y
=-1,
2182 bool control
= false, bool shift
= false, bool alt
= false, bool meta
= false);
2184 int GetRowOrCol() { return m_rowOrCol
; }
2185 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
2186 bool ControlDown() { return m_control
; }
2187 bool MetaDown() { return m_meta
; }
2188 bool ShiftDown() { return m_shift
; }
2189 bool AltDown() { return m_alt
; }
2192 #if defined(__WXMAC__) || defined(__WXCOCOA__)
2195 return ControlDown();
2199 virtual wxEvent
*Clone() const { return new wxGridSizeEvent(*this); }
2210 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridSizeEvent
)
2214 class WXDLLIMPEXP_ADV wxGridRangeSelectEvent
: public wxNotifyEvent
2217 wxGridRangeSelectEvent()
2220 m_topLeft
= wxGridNoCellCoords
;
2221 m_bottomRight
= wxGridNoCellCoords
;
2222 m_selecting
= false;
2229 wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
2230 const wxGridCellCoords
& topLeft
,
2231 const wxGridCellCoords
& bottomRight
,
2233 bool control
= false, bool shift
= false,
2234 bool alt
= false, bool meta
= false);
2236 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
2237 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
2238 int GetTopRow() { return m_topLeft
.GetRow(); }
2239 int GetBottomRow() { return m_bottomRight
.GetRow(); }
2240 int GetLeftCol() { return m_topLeft
.GetCol(); }
2241 int GetRightCol() { return m_bottomRight
.GetCol(); }
2242 bool Selecting() { return m_selecting
; }
2243 bool ControlDown() { return m_control
; }
2244 bool MetaDown() { return m_meta
; }
2245 bool ShiftDown() { return m_shift
; }
2246 bool AltDown() { return m_alt
; }
2249 #if defined(__WXMAC__) || defined(__WXCOCOA__)
2252 return ControlDown();
2256 virtual wxEvent
*Clone() const { return new wxGridRangeSelectEvent(*this); }
2259 wxGridCellCoords m_topLeft
;
2260 wxGridCellCoords m_bottomRight
;
2267 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridRangeSelectEvent
)
2271 class WXDLLIMPEXP_ADV wxGridEditorCreatedEvent
: public wxCommandEvent
{
2273 wxGridEditorCreatedEvent()
2281 wxGridEditorCreatedEvent(int id
, wxEventType type
, wxObject
* obj
,
2282 int row
, int col
, wxControl
* ctrl
);
2284 int GetRow() { return m_row
; }
2285 int GetCol() { return m_col
; }
2286 wxControl
* GetControl() { return m_ctrl
; }
2287 void SetRow(int row
) { m_row
= row
; }
2288 void SetCol(int col
) { m_col
= col
; }
2289 void SetControl(wxControl
* ctrl
) { m_ctrl
= ctrl
; }
2291 virtual wxEvent
*Clone() const { return new wxGridEditorCreatedEvent(*this); }
2298 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEditorCreatedEvent
)
2302 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_CELL_LEFT_CLICK
;
2303 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_CELL_RIGHT_CLICK
;
2304 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_CELL_LEFT_DCLICK
;
2305 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK
;
2306 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_LABEL_LEFT_CLICK
;
2307 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK
;
2308 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK
;
2309 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK
;
2310 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_ROW_SIZE
;
2311 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_COL_SIZE
;
2312 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_RANGE_SELECT
;
2313 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_CELL_CHANGE
;
2314 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_SELECT_CELL
;
2315 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_EDITOR_SHOWN
;
2316 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_EDITOR_HIDDEN
;
2317 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_EDITOR_CREATED
;
2318 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_CELL_BEGIN_DRAG
;
2319 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_COL_MOVE
;
2322 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
2323 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
2324 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
2325 typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction
)(wxGridEditorCreatedEvent
&);
2327 #define wxGridEventHandler(func) \
2328 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridEventFunction, &func)
2330 #define wxGridSizeEventHandler(func) \
2331 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridSizeEventFunction, &func)
2333 #define wxGridRangeSelectEventHandler(func) \
2334 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridRangeSelectEventFunction, &func)
2336 #define wxGridEditorCreatedEventHandler(func) \
2337 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridEditorCreatedEventFunction, &func)
2339 #define wx__DECLARE_GRIDEVT(evt, id, fn) \
2340 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEventHandler(fn))
2342 #define wx__DECLARE_GRIDSIZEEVT(evt, id, fn) \
2343 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridSizeEventHandler(fn))
2345 #define wx__DECLARE_GRIDRANGESELEVT(evt, id, fn) \
2346 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridRangeSelectEventHandler(fn))
2348 #define wx__DECLARE_GRIDEDITOREVT(evt, id, fn) \
2349 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEditorCreatedEventHandler(fn))
2351 #define EVT_GRID_CMD_CELL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_CLICK, id, fn)
2352 #define EVT_GRID_CMD_CELL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_CLICK, id, fn)
2353 #define EVT_GRID_CMD_CELL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_DCLICK, id, fn)
2354 #define EVT_GRID_CMD_CELL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_DCLICK, id, fn)
2355 #define EVT_GRID_CMD_LABEL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_CLICK, id, fn)
2356 #define EVT_GRID_CMD_LABEL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_CLICK, id, fn)
2357 #define EVT_GRID_CMD_LABEL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_DCLICK, id, fn)
2358 #define EVT_GRID_CMD_LABEL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_DCLICK, id, fn)
2359 #define EVT_GRID_CMD_ROW_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(ROW_SIZE, id, fn)
2360 #define EVT_GRID_CMD_COL_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(COL_SIZE, id, fn)
2361 #define EVT_GRID_CMD_COL_MOVE(id, fn) wx__DECLARE_GRIDEVT(COL_MOVE, id, fn)
2362 #define EVT_GRID_CMD_RANGE_SELECT(id, fn) wx__DECLARE_GRIDRANGESELEVT(RANGE_SELECT, id, fn)
2363 #define EVT_GRID_CMD_CELL_CHANGE(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGE, id, fn)
2364 #define EVT_GRID_CMD_SELECT_CELL(id, fn) wx__DECLARE_GRIDEVT(SELECT_CELL, id, fn)
2365 #define EVT_GRID_CMD_EDITOR_SHOWN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_SHOWN, id, fn)
2366 #define EVT_GRID_CMD_EDITOR_HIDDEN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_HIDDEN, id, fn)
2367 #define EVT_GRID_CMD_EDITOR_CREATED(id, fn) wx__DECLARE_GRIDEDITOREVT(EDITOR_CREATED, id, fn)
2368 #define EVT_GRID_CMD_CELL_BEGIN_DRAG(id, fn) wx__DECLARE_GRIDEVT(CELL_BEGIN_DRAG, id, fn)
2370 // same as above but for any id (exists mainly for backwards compatibility but
2371 // then it's also true that you rarely have multiple grid in the same window)
2372 #define EVT_GRID_CELL_LEFT_CLICK(fn) EVT_GRID_CMD_CELL_LEFT_CLICK(wxID_ANY, fn)
2373 #define EVT_GRID_CELL_RIGHT_CLICK(fn) EVT_GRID_CMD_CELL_RIGHT_CLICK(wxID_ANY, fn)
2374 #define EVT_GRID_CELL_LEFT_DCLICK(fn) EVT_GRID_CMD_CELL_LEFT_DCLICK(wxID_ANY, fn)
2375 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) EVT_GRID_CMD_CELL_RIGHT_DCLICK(wxID_ANY, fn)
2376 #define EVT_GRID_LABEL_LEFT_CLICK(fn) EVT_GRID_CMD_LABEL_LEFT_CLICK(wxID_ANY, fn)
2377 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_CLICK(wxID_ANY, fn)
2378 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) EVT_GRID_CMD_LABEL_LEFT_DCLICK(wxID_ANY, fn)
2379 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_DCLICK(wxID_ANY, fn)
2380 #define EVT_GRID_ROW_SIZE(fn) EVT_GRID_CMD_ROW_SIZE(wxID_ANY, fn)
2381 #define EVT_GRID_COL_SIZE(fn) EVT_GRID_CMD_COL_SIZE(wxID_ANY, fn)
2382 #define EVT_GRID_COL_MOVE(fn) EVT_GRID_CMD_COL_MOVE(wxID_ANY, fn)
2383 #define EVT_GRID_RANGE_SELECT(fn) EVT_GRID_CMD_RANGE_SELECT(wxID_ANY, fn)
2384 #define EVT_GRID_CELL_CHANGE(fn) EVT_GRID_CMD_CELL_CHANGE(wxID_ANY, fn)
2385 #define EVT_GRID_SELECT_CELL(fn) EVT_GRID_CMD_SELECT_CELL(wxID_ANY, fn)
2386 #define EVT_GRID_EDITOR_SHOWN(fn) EVT_GRID_CMD_EDITOR_SHOWN(wxID_ANY, fn)
2387 #define EVT_GRID_EDITOR_HIDDEN(fn) EVT_GRID_CMD_EDITOR_HIDDEN(wxID_ANY, fn)
2388 #define EVT_GRID_EDITOR_CREATED(fn) EVT_GRID_CMD_EDITOR_CREATED(wxID_ANY, fn)
2389 #define EVT_GRID_CELL_BEGIN_DRAG(fn) EVT_GRID_CMD_CELL_BEGIN_DRAG(wxID_ANY, fn)
2391 #if 0 // TODO: implement these ? others ?
2393 extern const int wxEVT_GRID_CREATE_CELL
;
2394 extern const int wxEVT_GRID_CHANGE_LABELS
;
2395 extern const int wxEVT_GRID_CHANGE_SEL_LABEL
;
2397 #define EVT_GRID_CREATE_CELL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CREATE_CELL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2398 #define EVT_GRID_CHANGE_LABELS(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_LABELS, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2399 #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 ),
2403 #endif // wxUSE_GRID
2404 #endif // _WX_GENERIC_GRID_H_