1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/dataview.h
3 // Purpose: wxDataViewCtrl generic implementation header
4 // Author: Robert Roebling
5 // Modified By: Bo Yang
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef __GENERICDATAVIEWCTRLH__
11 #define __GENERICDATAVIEWCTRLH__
14 #include "wx/object.h"
16 #include "wx/control.h"
17 #include "wx/scrolwin.h"
19 #include "wx/vector.h"
21 class WXDLLIMPEXP_FWD_ADV wxDataViewMainWindow
;
22 class WXDLLIMPEXP_FWD_ADV wxDataViewHeaderWindow
;
24 // ---------------------------------------------------------
26 // ---------------------------------------------------------
28 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
31 wxDataViewColumn(const wxString
& title
,
32 wxDataViewRenderer
*renderer
,
33 unsigned int model_column
,
34 int width
= wxDVC_DEFAULT_WIDTH
,
35 wxAlignment align
= wxALIGN_CENTER
,
36 int flags
= wxDATAVIEW_COL_RESIZABLE
)
37 : wxDataViewColumnBase(renderer
, model_column
),
40 Init(width
, align
, flags
);
43 wxDataViewColumn(const wxBitmap
& bitmap
,
44 wxDataViewRenderer
*renderer
,
45 unsigned int model_column
,
46 int width
= wxDVC_DEFAULT_WIDTH
,
47 wxAlignment align
= wxALIGN_CENTER
,
48 int flags
= wxDATAVIEW_COL_RESIZABLE
)
49 : wxDataViewColumnBase(bitmap
, renderer
, model_column
)
51 Init(width
, align
, flags
);
54 // implement wxHeaderColumnBase methods
55 virtual void SetTitle(const wxString
& title
) { m_title
= title
; UpdateDisplay(); }
56 virtual wxString
GetTitle() const { return m_title
; }
58 virtual void SetWidth(int width
) { m_width
= width
; UpdateDisplay(); }
59 virtual int GetWidth() const;
61 virtual void SetMinWidth(int minWidth
) { m_minWidth
= minWidth
; UpdateDisplay(); }
62 virtual int GetMinWidth() const { return m_minWidth
; }
64 virtual void SetAlignment(wxAlignment align
) { m_align
= align
; UpdateDisplay(); }
65 virtual wxAlignment
GetAlignment() const { return m_align
; }
67 virtual void SetFlags(int flags
) { m_flags
= flags
; UpdateDisplay(); }
68 virtual int GetFlags() const { return m_flags
; }
70 virtual bool IsSortKey() const { return m_sort
; }
72 virtual void UnsetAsSortKey();
74 virtual void SetSortOrder(bool ascending
);
76 virtual bool IsSortOrderAscending() const { return m_sortAscending
; }
78 virtual void SetBitmap( const wxBitmap
& bitmap
) { wxDataViewColumnBase::SetBitmap(bitmap
); UpdateDisplay(); }
82 // common part of all ctors
83 void Init(int width
, wxAlignment align
, int flags
);
95 friend class wxDataViewHeaderWindowBase
;
96 friend class wxDataViewHeaderWindow
;
97 friend class wxDataViewHeaderWindowMSW
;
100 // ---------------------------------------------------------
102 // ---------------------------------------------------------
104 WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn
, wxDataViewColumnList
,
105 class WXDLLIMPEXP_ADV
);
107 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
,
108 public wxScrollHelper
110 friend class wxDataViewMainWindow
;
111 friend class wxDataViewHeaderWindowBase
;
112 friend class wxDataViewHeaderWindow
;
113 friend class wxDataViewHeaderWindowMSW
;
114 friend class wxDataViewColumn
;
117 wxDataViewCtrl() : wxScrollHelper(this)
122 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
123 const wxPoint
& pos
= wxDefaultPosition
,
124 const wxSize
& size
= wxDefaultSize
, long style
= 0,
125 const wxValidator
& validator
= wxDefaultValidator
,
126 const wxString
& name
= wxDataViewCtrlNameStr
)
127 : wxScrollHelper(this)
129 Create(parent
, id
, pos
, size
, style
, validator
, name
);
132 virtual ~wxDataViewCtrl();
136 bool Create(wxWindow
*parent
, wxWindowID id
,
137 const wxPoint
& pos
= wxDefaultPosition
,
138 const wxSize
& size
= wxDefaultSize
, long style
= 0,
139 const wxValidator
& validator
= wxDefaultValidator
,
140 const wxString
& name
= wxDataViewCtrlNameStr
);
142 virtual bool AssociateModel( wxDataViewModel
*model
);
144 virtual bool AppendColumn( wxDataViewColumn
*col
);
145 virtual bool PrependColumn( wxDataViewColumn
*col
);
146 virtual bool InsertColumn( unsigned int pos
, wxDataViewColumn
*col
);
148 virtual void DoSetExpanderColumn();
149 virtual void DoSetIndent();
151 virtual unsigned int GetColumnCount() const;
152 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const;
153 virtual bool DeleteColumn( wxDataViewColumn
*column
);
154 virtual bool ClearColumns();
155 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const;
157 virtual wxDataViewColumn
*GetSortingColumn() const;
159 virtual int GetSelectedItemsCount() const;
160 virtual int GetSelections( wxDataViewItemArray
& sel
) const;
161 virtual void SetSelections( const wxDataViewItemArray
& sel
);
162 virtual void Select( const wxDataViewItem
& item
);
163 virtual void Unselect( const wxDataViewItem
& item
);
164 virtual bool IsSelected( const wxDataViewItem
& item
) const;
166 virtual void SelectAll();
167 virtual void UnselectAll();
169 virtual void EnsureVisible( const wxDataViewItem
& item
,
170 const wxDataViewColumn
*column
= NULL
);
171 virtual void HitTest( const wxPoint
& point
, wxDataViewItem
& item
,
172 wxDataViewColumn
* &column
) const;
173 virtual wxRect
GetItemRect( const wxDataViewItem
& item
,
174 const wxDataViewColumn
*column
= NULL
) const;
176 virtual bool SetRowHeight( int rowHeight
);
178 virtual void Expand( const wxDataViewItem
& item
);
179 virtual void Collapse( const wxDataViewItem
& item
);
180 virtual bool IsExpanded( const wxDataViewItem
& item
) const;
182 virtual void SetFocus();
184 virtual bool SetFont(const wxFont
& font
);
186 #if wxUSE_DRAG_AND_DROP
187 virtual bool EnableDragSource( const wxDataFormat
&format
);
188 virtual bool EnableDropTarget( const wxDataFormat
&format
);
189 #endif // wxUSE_DRAG_AND_DROP
191 virtual wxBorder
GetDefaultBorder() const;
193 virtual void EditItem(const wxDataViewItem
& item
, const wxDataViewColumn
*column
);
195 // These methods are specific to generic wxDataViewCtrl implementation and
196 // should not be used in portable code.
197 wxColour
GetAlternateRowColour() const { return m_alternateRowColour
; }
198 void SetAlternateRowColour(const wxColour
& colour
);
201 virtual void EnsureVisible( int row
, int column
);
203 // Notice that row here may be invalid (i.e. >= GetRowCount()), this is not
204 // an error and this function simply returns an invalid item in this case.
205 virtual wxDataViewItem
GetItemByRow( unsigned int row
) const;
206 virtual int GetRowByItem( const wxDataViewItem
& item
) const;
208 int GetSortingColumnIndex() const { return m_sortingColumnIdx
; }
209 void SetSortingColumnIndex(int idx
) { m_sortingColumnIdx
= idx
; }
211 public: // utility functions not part of the API
213 // returns the "best" width for the idx-th column
214 unsigned int GetBestColumnWidth(int idx
) const;
216 // called by header window after reorder
217 void ColumnMoved( wxDataViewColumn
* col
, unsigned int new_pos
);
219 // update the display after a change to an individual column
220 void OnColumnChange(unsigned int idx
);
222 // update after a change to the number of columns
223 void OnColumnsCountChanged();
225 wxWindow
*GetMainWindow() { return (wxWindow
*) m_clientArea
; }
227 // return the index of the given column in m_cols
228 int GetColumnIndex(const wxDataViewColumn
*column
) const;
230 // Return the index of the column having the given model index.
231 int GetModelColumnIndex(unsigned int model_column
) const;
233 // return the column displayed at the given position in the control
234 wxDataViewColumn
*GetColumnAt(unsigned int pos
) const;
236 virtual wxDataViewColumn
*GetCurrentColumn() const;
238 virtual void OnInternalIdle();
241 virtual wxDataViewItem
DoGetCurrentItem() const;
242 virtual void DoSetCurrentItem(const wxDataViewItem
& item
);
244 void InvalidateColBestWidths();
245 void InvalidateColBestWidth(int idx
);
246 void UpdateColWidths();
248 wxDataViewColumnList m_cols
;
249 // cached column best widths information, values are for
250 // respective columns from m_cols and the arrays have same size
251 struct CachedColWidthInfo
253 CachedColWidthInfo() : width(0), dirty(true) {}
254 int width
; // cached width or 0 if not computed
255 bool dirty
; // column was invalidated, header needs updating
257 wxVector
<CachedColWidthInfo
> m_colsBestWidths
;
258 // This indicates that at least one entry in m_colsBestWidths has 'dirty'
259 // flag set. It's cheaper to check one flag in OnInternalIdle() than to
260 // iterate over m_colsBestWidths to check if anything needs to be done.
263 wxDataViewModelNotifier
*m_notifier
;
264 wxDataViewMainWindow
*m_clientArea
;
265 wxDataViewHeaderWindow
*m_headerArea
;
267 // user defined color to draw row lines, may be invalid
268 wxColour m_alternateRowColour
;
270 // the index of the column currently used for sorting or -1
271 int m_sortingColumnIdx
;
274 void OnSize( wxSizeEvent
&event
);
275 virtual wxSize
GetSizeAvailableForScrollTarget(const wxSize
& size
);
277 // we need to return a special WM_GETDLGCODE value to process just the
278 // arrows but let the other navigation characters through
280 virtual WXLRESULT
MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
283 WX_FORWARD_TO_SCROLL_HELPER()
286 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
287 wxDECLARE_NO_COPY_CLASS(wxDataViewCtrl
);
288 DECLARE_EVENT_TABLE()
292 #endif // __GENERICDATAVIEWCTRLH__