]>
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 | ||
5d9e1605 | 71 | virtual void SetAsSortKey(bool sort = true) { m_sort = sort; UpdateDisplay(); } |
e2bfe673 VZ |
72 | virtual bool IsSortKey() const { return m_sort; } |
73 | ||
5d9e1605 | 74 | virtual void SetSortOrder(bool ascending) { m_sortAscending = ascending; UpdateDisplay(); } |
e2bfe673 | 75 | virtual bool IsSortOrderAscending() const { return m_sortAscending; } |
4ed7af08 | 76 | |
5d9e1605 RR |
77 | virtual void SetBitmap( const wxBitmap& bitmap ) { wxDataViewColumnBase::SetBitmap(bitmap); UpdateDisplay(); } |
78 | ||
79 | ||
56873923 | 80 | private: |
e2bfe673 | 81 | // common part of all ctors |
5d9e1605 | 82 | void Init(int width, wxAlignment align, int flags); |
ce00f59b | 83 | |
5d9e1605 | 84 | void UpdateDisplay(); |
e2bfe673 | 85 | |
e2bfe673 VZ |
86 | wxString m_title; |
87 | int m_width, | |
88 | m_minWidth; | |
89 | wxAlignment m_align; | |
90 | int m_flags; | |
91 | bool m_sort, | |
92 | m_sortAscending; | |
93 | ||
56873923 VZ |
94 | friend class wxDataViewHeaderWindowBase; |
95 | friend class wxDataViewHeaderWindow; | |
96 | friend class wxDataViewHeaderWindowMSW; | |
4ed7af08 RR |
97 | }; |
98 | ||
f554a14b | 99 | // --------------------------------------------------------- |
4ed7af08 | 100 | // wxDataViewCtrl |
f554a14b | 101 | // --------------------------------------------------------- |
4ed7af08 | 102 | |
4660b556 VZ |
103 | WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn, wxDataViewColumnList, |
104 | class WXDLLIMPEXP_ADV); | |
afebb87b | 105 | |
938161a6 VZ |
106 | class WXDLLIMPEXP_ADV wxDataViewCtrl : public wxDataViewCtrlBase, |
107 | public wxScrollHelper | |
4ed7af08 | 108 | { |
87f0efe2 RR |
109 | friend class wxDataViewMainWindow; |
110 | friend class wxDataViewHeaderWindowBase; | |
111 | friend class wxDataViewHeaderWindow; | |
112 | friend class wxDataViewHeaderWindowMSW; | |
9861f022 | 113 | friend class wxDataViewColumn; |
87f0efe2 | 114 | |
4ed7af08 | 115 | public: |
938161a6 | 116 | wxDataViewCtrl() : wxScrollHelper(this) |
4ed7af08 RR |
117 | { |
118 | Init(); | |
119 | } | |
f554a14b | 120 | |
4ed7af08 RR |
121 | wxDataViewCtrl( wxWindow *parent, wxWindowID id, |
122 | const wxPoint& pos = wxDefaultPosition, | |
123 | const wxSize& size = wxDefaultSize, long style = 0, | |
62e9285a | 124 | const wxValidator& validator = wxDefaultValidator, |
346f3fd6 | 125 | const wxString& name = wxDataViewCtrlNameStr ) |
938161a6 | 126 | : wxScrollHelper(this) |
4ed7af08 | 127 | { |
62e9285a | 128 | Create(parent, id, pos, size, style, validator, name); |
4ed7af08 RR |
129 | } |
130 | ||
131 | virtual ~wxDataViewCtrl(); | |
132 | ||
133 | void Init(); | |
134 | ||
135 | bool Create(wxWindow *parent, wxWindowID id, | |
bc4f1ff2 FM |
136 | const wxPoint& pos = wxDefaultPosition, |
137 | const wxSize& size = wxDefaultSize, long style = 0, | |
62e9285a VZ |
138 | const wxValidator& validator = wxDefaultValidator, |
139 | const wxString& name = wxDataViewCtrlNameStr); | |
4ed7af08 | 140 | |
aba9bfd0 | 141 | virtual bool AssociateModel( wxDataViewModel *model ); |
e2bfe673 | 142 | |
4ed7af08 | 143 | virtual bool AppendColumn( wxDataViewColumn *col ); |
736fe67c | 144 | virtual bool PrependColumn( wxDataViewColumn *col ); |
19723525 | 145 | virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col ); |
f554a14b | 146 | |
3b6280be RR |
147 | virtual void DoSetExpanderColumn(); |
148 | virtual void DoSetIndent(); | |
149 | ||
afebb87b RR |
150 | virtual unsigned int GetColumnCount() const; |
151 | virtual wxDataViewColumn* GetColumn( unsigned int pos ) const; | |
152 | virtual bool DeleteColumn( wxDataViewColumn *column ); | |
153 | virtual bool ClearColumns(); | |
453091c2 | 154 | virtual int GetColumnPosition( const wxDataViewColumn *column ) const; |
afebb87b | 155 | |
21f47fb9 | 156 | virtual wxDataViewColumn *GetSortingColumn() const; |
e2bfe673 | 157 | |
fbda518c | 158 | virtual wxDataViewItem GetSelection() const; |
b7e9f8b1 RR |
159 | virtual int GetSelections( wxDataViewItemArray & sel ) const; |
160 | virtual void SetSelections( const wxDataViewItemArray & sel ); | |
161 | virtual void Select( const wxDataViewItem & item ); | |
162 | virtual void Unselect( const wxDataViewItem & item ); | |
163 | virtual bool IsSelected( const wxDataViewItem & item ) const; | |
164 | ||
66e09788 RR |
165 | virtual void SelectAll(); |
166 | virtual void UnselectAll(); | |
167 | ||
168 | virtual void EnsureVisible( const wxDataViewItem & item, | |
fbda518c | 169 | const wxDataViewColumn *column = NULL ); |
03647350 | 170 | virtual void HitTest( const wxPoint & point, wxDataViewItem & item, |
bc4f1ff2 | 171 | wxDataViewColumn* &column ) const; |
03647350 | 172 | virtual wxRect GetItemRect( const wxDataViewItem & item, |
bc4f1ff2 | 173 | const wxDataViewColumn *column = NULL ) const; |
66e09788 | 174 | |
bbfd4548 VZ |
175 | virtual bool SetRowHeight( int rowHeight ); |
176 | ||
afebb87b RR |
177 | virtual void Expand( const wxDataViewItem & item ); |
178 | virtual void Collapse( const wxDataViewItem & item ); | |
739a8399 | 179 | virtual bool IsExpanded( const wxDataViewItem & item ) const; |
e2bfe673 | 180 | |
788432e3 | 181 | virtual void SetFocus(); |
9adeb77a VZ |
182 | |
183 | #if wxUSE_DRAG_AND_DROP | |
821baf7d RR |
184 | virtual bool EnableDragSource( const wxDataFormat &format ); |
185 | virtual bool EnableDropTarget( const wxDataFormat &format ); | |
9adeb77a | 186 | #endif // wxUSE_DRAG_AND_DROP |
afebb87b | 187 | |
3fdf86f9 RR |
188 | virtual wxBorder GetDefaultBorder() const; |
189 | ||
eeea3b03 | 190 | virtual void StartEditor( const wxDataViewItem & item, unsigned int column ); |
c937344c | 191 | |
66e09788 | 192 | protected: |
e2bfe673 | 193 | virtual int GetSelections( wxArrayInt & sel ) const; |
b7e9f8b1 RR |
194 | virtual void SetSelections( const wxArrayInt & sel ); |
195 | virtual void Select( int row ); | |
196 | virtual void Unselect( int row ); | |
197 | virtual bool IsSelected( int row ) const; | |
198 | virtual void SelectRange( int from, int to ); | |
199 | virtual void UnselectRange( int from, int to ); | |
200 | ||
fbda518c | 201 | virtual void EnsureVisible( int row, int column ); |
b7e9f8b1 RR |
202 | |
203 | virtual wxDataViewItem GetItemByRow( unsigned int row ) const; | |
204 | virtual int GetRowByItem( const wxDataViewItem & item ) const; | |
205 | ||
46234a03 VZ |
206 | int GetSortingColumnIndex() const { return m_sortingColumnIdx; } |
207 | void SetSortingColumnIndex(int idx) { m_sortingColumnIdx = idx; } | |
6ff7eee7 | 208 | |
9861f022 RR |
209 | public: // utility functions not part of the API |
210 | ||
87f0efe2 | 211 | // returns the "best" width for the idx-th column |
d0154e3a | 212 | unsigned int GetBestColumnWidth(int idx) const; |
87f0efe2 | 213 | |
fc8c1a15 RR |
214 | // called by header window after reorder |
215 | void ColumnMoved( wxDataViewColumn* col, unsigned int new_pos ); | |
216 | ||
aef252d9 VZ |
217 | // update the display after a change to an individual column |
218 | void OnColumnChange(unsigned int idx); | |
219 | ||
220 | // update after a change to the number of columns | |
221 | void OnColumnsCountChanged(); | |
87f0efe2 | 222 | |
1e510b1e | 223 | wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; } |
99d471a5 | 224 | |
702f5349 VZ |
225 | // return the index of the given column in m_cols |
226 | int GetColumnIndex(const wxDataViewColumn *column) const; | |
227 | ||
228 | // return the column displayed at the given position in the control | |
229 | wxDataViewColumn *GetColumnAt(unsigned int pos) const; | |
230 | ||
4ed7af08 | 231 | private: |
80ce465c VZ |
232 | virtual wxDataViewItem DoGetCurrentItem() const; |
233 | virtual void DoSetCurrentItem(const wxDataViewItem& item); | |
234 | ||
d0154e3a VS |
235 | void InvalidateColBestWidths(); |
236 | void InvalidateColBestWidth(int idx); | |
237 | ||
ad386793 | 238 | wxDataViewColumnList m_cols; |
d0154e3a VS |
239 | // cached column best widths or 0 if not computed, values are for |
240 | // respective columns from m_cols and the arrays have same size | |
241 | wxVector<int> m_colsBestWidths; | |
ad386793 RR |
242 | wxDataViewModelNotifier *m_notifier; |
243 | wxDataViewMainWindow *m_clientArea; | |
244 | wxDataViewHeaderWindow *m_headerArea; | |
46234a03 VZ |
245 | |
246 | // the index of the column currently used for sorting or -1 | |
247 | int m_sortingColumnIdx; | |
f554a14b | 248 | |
4ed7af08 | 249 | private: |
4b3feaa7 | 250 | void OnSize( wxSizeEvent &event ); |
2571a33f | 251 | virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size); |
f554a14b | 252 | |
4ed7af08 RR |
253 | // we need to return a special WM_GETDLGCODE value to process just the |
254 | // arrows but let the other navigation characters through | |
255 | #ifdef __WXMSW__ | |
256 | virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); | |
257 | #endif // __WXMSW__ | |
258 | ||
259 | WX_FORWARD_TO_SCROLL_HELPER() | |
4b3feaa7 | 260 | |
4ed7af08 RR |
261 | private: |
262 | DECLARE_DYNAMIC_CLASS(wxDataViewCtrl) | |
c0c133e1 | 263 | wxDECLARE_NO_COPY_CLASS(wxDataViewCtrl); |
4b3feaa7 | 264 | DECLARE_EVENT_TABLE() |
4ed7af08 RR |
265 | }; |
266 | ||
267 | ||
268 | #endif // __GENERICDATAVIEWCTRLH__ |