]>
Commit | Line | Data |
---|---|---|
4ed7af08 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/generic/dataview.h | |
3 | // Purpose: wxDataViewCtrl generic implementation header | |
4 | // Author: Robert Roebling | |
b7e9f8b1 | 5 | // Modified By: Bo Yang |
4ed7af08 RR |
6 | // Id: $Id$ |
7 | // Copyright: (c) 1998 Robert Roebling | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef __GENERICDATAVIEWCTRLH__ | |
12 | #define __GENERICDATAVIEWCTRLH__ | |
13 | ||
14 | #include "wx/defs.h" | |
15 | #include "wx/object.h" | |
16 | #include "wx/list.h" | |
17 | #include "wx/control.h" | |
9d14de69 | 18 | #include "wx/scrolwin.h" |
2586d4a1 | 19 | #include "wx/icon.h" |
d0154e3a | 20 | #include "wx/vector.h" |
4ed7af08 | 21 | |
b5dbe15d VS |
22 | class WXDLLIMPEXP_FWD_ADV wxDataViewMainWindow; |
23 | class WXDLLIMPEXP_FWD_ADV wxDataViewHeaderWindow; | |
4ed7af08 | 24 | |
f554a14b | 25 | // --------------------------------------------------------- |
4ed7af08 | 26 | // wxDataViewColumn |
f554a14b | 27 | // --------------------------------------------------------- |
4ed7af08 | 28 | |
56873923 | 29 | class WXDLLIMPEXP_ADV wxDataViewColumn : public wxDataViewColumnBase |
4ed7af08 RR |
30 | { |
31 | public: | |
e2bfe673 VZ |
32 | wxDataViewColumn(const wxString& title, |
33 | wxDataViewRenderer *renderer, | |
34 | unsigned int model_column, | |
35 | int width = wxDVC_DEFAULT_WIDTH, | |
36 | wxAlignment align = wxALIGN_CENTER, | |
37 | int flags = wxDATAVIEW_COL_RESIZABLE) | |
38 | : wxDataViewColumnBase(renderer, model_column), | |
39 | m_title(title) | |
40 | { | |
41 | Init(width, align, flags); | |
42 | } | |
43 | ||
44 | wxDataViewColumn(const wxBitmap& bitmap, | |
45 | wxDataViewRenderer *renderer, | |
46 | unsigned int model_column, | |
47 | int width = wxDVC_DEFAULT_WIDTH, | |
48 | wxAlignment align = wxALIGN_CENTER, | |
49 | int flags = wxDATAVIEW_COL_RESIZABLE) | |
50 | : wxDataViewColumnBase(bitmap, renderer, model_column) | |
51 | { | |
52 | Init(width, align, flags); | |
53 | } | |
54 | ||
55 | // implement wxHeaderColumnBase methods | |
5d9e1605 | 56 | virtual void SetTitle(const wxString& title) { m_title = title; UpdateDisplay(); } |
e2bfe673 VZ |
57 | virtual wxString GetTitle() const { return m_title; } |
58 | ||
5d9e1605 | 59 | virtual void SetWidth(int width) { m_width = width; UpdateDisplay(); } |
d0154e3a | 60 | virtual int GetWidth() const; |
e2bfe673 | 61 | |
5d9e1605 | 62 | virtual void SetMinWidth(int minWidth) { m_minWidth = minWidth; UpdateDisplay(); } |
e2bfe673 VZ |
63 | virtual int GetMinWidth() const { return m_minWidth; } |
64 | ||
5d9e1605 | 65 | virtual void SetAlignment(wxAlignment align) { m_align = align; UpdateDisplay(); } |
e2bfe673 VZ |
66 | virtual wxAlignment GetAlignment() const { return m_align; } |
67 | ||
5d9e1605 | 68 | virtual void SetFlags(int flags) { m_flags = flags; UpdateDisplay(); } |
e2bfe673 VZ |
69 | virtual int GetFlags() const { return m_flags; } |
70 | ||
e2bfe673 VZ |
71 | virtual bool IsSortKey() const { return m_sort; } |
72 | ||
732a176c | 73 | virtual void UnsetAsSortKey(); |
aadbdd16 | 74 | |
15b8afdc | 75 | virtual void SetSortOrder(bool ascending); |
aadbdd16 | 76 | |
e2bfe673 | 77 | virtual bool IsSortOrderAscending() const { return m_sortAscending; } |
4ed7af08 | 78 | |
5d9e1605 RR |
79 | virtual void SetBitmap( const wxBitmap& bitmap ) { wxDataViewColumnBase::SetBitmap(bitmap); UpdateDisplay(); } |
80 | ||
81 | ||
56873923 | 82 | private: |
e2bfe673 | 83 | // common part of all ctors |
5d9e1605 | 84 | void Init(int width, wxAlignment align, int flags); |
ce00f59b | 85 | |
5d9e1605 | 86 | void UpdateDisplay(); |
e2bfe673 | 87 | |
e2bfe673 VZ |
88 | wxString m_title; |
89 | int m_width, | |
90 | m_minWidth; | |
91 | wxAlignment m_align; | |
92 | int m_flags; | |
93 | bool m_sort, | |
94 | m_sortAscending; | |
95 | ||
56873923 VZ |
96 | friend class wxDataViewHeaderWindowBase; |
97 | friend class wxDataViewHeaderWindow; | |
98 | friend class wxDataViewHeaderWindowMSW; | |
4ed7af08 RR |
99 | }; |
100 | ||
f554a14b | 101 | // --------------------------------------------------------- |
4ed7af08 | 102 | // wxDataViewCtrl |
f554a14b | 103 | // --------------------------------------------------------- |
4ed7af08 | 104 | |
4660b556 VZ |
105 | WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn, wxDataViewColumnList, |
106 | class WXDLLIMPEXP_ADV); | |
afebb87b | 107 | |
938161a6 VZ |
108 | class WXDLLIMPEXP_ADV wxDataViewCtrl : public wxDataViewCtrlBase, |
109 | public wxScrollHelper | |
4ed7af08 | 110 | { |
87f0efe2 RR |
111 | friend class wxDataViewMainWindow; |
112 | friend class wxDataViewHeaderWindowBase; | |
113 | friend class wxDataViewHeaderWindow; | |
114 | friend class wxDataViewHeaderWindowMSW; | |
9861f022 | 115 | friend class wxDataViewColumn; |
87f0efe2 | 116 | |
4ed7af08 | 117 | public: |
938161a6 | 118 | wxDataViewCtrl() : wxScrollHelper(this) |
4ed7af08 RR |
119 | { |
120 | Init(); | |
121 | } | |
f554a14b | 122 | |
4ed7af08 RR |
123 | wxDataViewCtrl( wxWindow *parent, wxWindowID id, |
124 | const wxPoint& pos = wxDefaultPosition, | |
125 | const wxSize& size = wxDefaultSize, long style = 0, | |
62e9285a | 126 | const wxValidator& validator = wxDefaultValidator, |
346f3fd6 | 127 | const wxString& name = wxDataViewCtrlNameStr ) |
938161a6 | 128 | : wxScrollHelper(this) |
4ed7af08 | 129 | { |
62e9285a | 130 | Create(parent, id, pos, size, style, validator, name); |
4ed7af08 RR |
131 | } |
132 | ||
133 | virtual ~wxDataViewCtrl(); | |
134 | ||
135 | void Init(); | |
136 | ||
137 | bool Create(wxWindow *parent, wxWindowID id, | |
bc4f1ff2 FM |
138 | const wxPoint& pos = wxDefaultPosition, |
139 | const wxSize& size = wxDefaultSize, long style = 0, | |
62e9285a VZ |
140 | const wxValidator& validator = wxDefaultValidator, |
141 | const wxString& name = wxDataViewCtrlNameStr); | |
4ed7af08 | 142 | |
aba9bfd0 | 143 | virtual bool AssociateModel( wxDataViewModel *model ); |
e2bfe673 | 144 | |
4ed7af08 | 145 | virtual bool AppendColumn( wxDataViewColumn *col ); |
736fe67c | 146 | virtual bool PrependColumn( wxDataViewColumn *col ); |
19723525 | 147 | virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col ); |
f554a14b | 148 | |
3b6280be RR |
149 | virtual void DoSetExpanderColumn(); |
150 | virtual void DoSetIndent(); | |
151 | ||
afebb87b RR |
152 | virtual unsigned int GetColumnCount() const; |
153 | virtual wxDataViewColumn* GetColumn( unsigned int pos ) const; | |
154 | virtual bool DeleteColumn( wxDataViewColumn *column ); | |
155 | virtual bool ClearColumns(); | |
453091c2 | 156 | virtual int GetColumnPosition( const wxDataViewColumn *column ) const; |
afebb87b | 157 | |
21f47fb9 | 158 | virtual wxDataViewColumn *GetSortingColumn() const; |
e2bfe673 | 159 | |
fa93d732 | 160 | virtual int GetSelectedItemsCount() const; |
b7e9f8b1 RR |
161 | virtual int GetSelections( wxDataViewItemArray & sel ) const; |
162 | virtual void SetSelections( const wxDataViewItemArray & sel ); | |
163 | virtual void Select( const wxDataViewItem & item ); | |
164 | virtual void Unselect( const wxDataViewItem & item ); | |
165 | virtual bool IsSelected( const wxDataViewItem & item ) const; | |
166 | ||
66e09788 RR |
167 | virtual void SelectAll(); |
168 | virtual void UnselectAll(); | |
169 | ||
170 | virtual void EnsureVisible( const wxDataViewItem & item, | |
fbda518c | 171 | const wxDataViewColumn *column = NULL ); |
03647350 | 172 | virtual void HitTest( const wxPoint & point, wxDataViewItem & item, |
bc4f1ff2 | 173 | wxDataViewColumn* &column ) const; |
03647350 | 174 | virtual wxRect GetItemRect( const wxDataViewItem & item, |
bc4f1ff2 | 175 | const wxDataViewColumn *column = NULL ) const; |
66e09788 | 176 | |
bbfd4548 VZ |
177 | virtual bool SetRowHeight( int rowHeight ); |
178 | ||
afebb87b RR |
179 | virtual void Expand( const wxDataViewItem & item ); |
180 | virtual void Collapse( const wxDataViewItem & item ); | |
739a8399 | 181 | virtual bool IsExpanded( const wxDataViewItem & item ) const; |
e2bfe673 | 182 | |
788432e3 | 183 | virtual void SetFocus(); |
9adeb77a | 184 | |
1af67319 VZ |
185 | virtual bool SetFont(const wxFont & font); |
186 | ||
9adeb77a | 187 | #if wxUSE_DRAG_AND_DROP |
821baf7d RR |
188 | virtual bool EnableDragSource( const wxDataFormat &format ); |
189 | virtual bool EnableDropTarget( const wxDataFormat &format ); | |
9adeb77a | 190 | #endif // wxUSE_DRAG_AND_DROP |
afebb87b | 191 | |
3fdf86f9 RR |
192 | virtual wxBorder GetDefaultBorder() const; |
193 | ||
907f09f4 | 194 | virtual void EditItem(const wxDataViewItem& item, const wxDataViewColumn *column); |
c937344c | 195 | |
4bdc891f VZ |
196 | // These methods are specific to generic wxDataViewCtrl implementation and |
197 | // should not be used in portable code. | |
198 | wxColour GetAlternateRowColour() const { return m_alternateRowColour; } | |
199 | void SetAlternateRowColour(const wxColour& colour); | |
200 | ||
66e09788 | 201 | protected: |
fbda518c | 202 | virtual void EnsureVisible( int row, int column ); |
b7e9f8b1 | 203 | |
b0272c60 VZ |
204 | // Notice that row here may be invalid (i.e. >= GetRowCount()), this is not |
205 | // an error and this function simply returns an invalid item in this case. | |
b7e9f8b1 RR |
206 | virtual wxDataViewItem GetItemByRow( unsigned int row ) const; |
207 | virtual int GetRowByItem( const wxDataViewItem & item ) const; | |
208 | ||
46234a03 VZ |
209 | int GetSortingColumnIndex() const { return m_sortingColumnIdx; } |
210 | void SetSortingColumnIndex(int idx) { m_sortingColumnIdx = idx; } | |
6ff7eee7 | 211 | |
9861f022 RR |
212 | public: // utility functions not part of the API |
213 | ||
87f0efe2 | 214 | // returns the "best" width for the idx-th column |
d0154e3a | 215 | unsigned int GetBestColumnWidth(int idx) const; |
87f0efe2 | 216 | |
fc8c1a15 RR |
217 | // called by header window after reorder |
218 | void ColumnMoved( wxDataViewColumn* col, unsigned int new_pos ); | |
219 | ||
aef252d9 VZ |
220 | // update the display after a change to an individual column |
221 | void OnColumnChange(unsigned int idx); | |
222 | ||
223 | // update after a change to the number of columns | |
224 | void OnColumnsCountChanged(); | |
87f0efe2 | 225 | |
1e510b1e | 226 | wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; } |
99d471a5 | 227 | |
702f5349 VZ |
228 | // return the index of the given column in m_cols |
229 | int GetColumnIndex(const wxDataViewColumn *column) const; | |
230 | ||
231 | // return the column displayed at the given position in the control | |
232 | wxDataViewColumn *GetColumnAt(unsigned int pos) const; | |
233 | ||
ee1377e1 VS |
234 | virtual wxDataViewColumn *GetCurrentColumn() const; |
235 | ||
bed74e48 VS |
236 | virtual void OnInternalIdle(); |
237 | ||
4ed7af08 | 238 | private: |
80ce465c VZ |
239 | virtual wxDataViewItem DoGetCurrentItem() const; |
240 | virtual void DoSetCurrentItem(const wxDataViewItem& item); | |
241 | ||
bed74e48 VS |
242 | void InvalidateColBestWidths(); |
243 | void InvalidateColBestWidth(int idx); | |
244 | void UpdateColWidths(); | |
d0154e3a | 245 | |
ad386793 | 246 | wxDataViewColumnList m_cols; |
840fc4d1 | 247 | // cached column best widths information, values are for |
d0154e3a | 248 | // respective columns from m_cols and the arrays have same size |
840fc4d1 VS |
249 | struct CachedColWidthInfo |
250 | { | |
251 | CachedColWidthInfo() : width(0), dirty(true) {} | |
252 | int width; // cached width or 0 if not computed | |
253 | bool dirty; // column was invalidated, header needs updating | |
254 | }; | |
255 | wxVector<CachedColWidthInfo> m_colsBestWidths; | |
256 | // This indicates that at least one entry in m_colsBestWidths has 'dirty' | |
257 | // flag set. It's cheaper to check one flag in OnInternalIdle() than to | |
258 | // iterate over m_colsBestWidths to check if anything needs to be done. | |
bed74e48 VS |
259 | bool m_colsDirty; |
260 | ||
ad386793 RR |
261 | wxDataViewModelNotifier *m_notifier; |
262 | wxDataViewMainWindow *m_clientArea; | |
263 | wxDataViewHeaderWindow *m_headerArea; | |
46234a03 | 264 | |
4bdc891f VZ |
265 | // user defined color to draw row lines, may be invalid |
266 | wxColour m_alternateRowColour; | |
267 | ||
46234a03 VZ |
268 | // the index of the column currently used for sorting or -1 |
269 | int m_sortingColumnIdx; | |
f554a14b | 270 | |
4ed7af08 | 271 | private: |
4b3feaa7 | 272 | void OnSize( wxSizeEvent &event ); |
2571a33f | 273 | virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size); |
f554a14b | 274 | |
4ed7af08 RR |
275 | // we need to return a special WM_GETDLGCODE value to process just the |
276 | // arrows but let the other navigation characters through | |
277 | #ifdef __WXMSW__ | |
278 | virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); | |
279 | #endif // __WXMSW__ | |
280 | ||
281 | WX_FORWARD_TO_SCROLL_HELPER() | |
4b3feaa7 | 282 | |
4ed7af08 RR |
283 | private: |
284 | DECLARE_DYNAMIC_CLASS(wxDataViewCtrl) | |
c0c133e1 | 285 | wxDECLARE_NO_COPY_CLASS(wxDataViewCtrl); |
4b3feaa7 | 286 | DECLARE_EVENT_TABLE() |
4ed7af08 RR |
287 | }; |
288 | ||
289 | ||
290 | #endif // __GENERICDATAVIEWCTRLH__ |