]>
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" |
4ed7af08 | 20 | |
b5dbe15d VS |
21 | class WXDLLIMPEXP_FWD_ADV wxDataViewMainWindow; |
22 | class WXDLLIMPEXP_FWD_ADV wxDataViewHeaderWindow; | |
4ed7af08 | 23 | |
f554a14b | 24 | // --------------------------------------------------------- |
4ed7af08 | 25 | // wxDataViewColumn |
f554a14b | 26 | // --------------------------------------------------------- |
4ed7af08 | 27 | |
56873923 | 28 | class WXDLLIMPEXP_ADV wxDataViewColumn : public wxDataViewColumnBase |
4ed7af08 RR |
29 | { |
30 | public: | |
e2bfe673 VZ |
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), | |
38 | m_title(title) | |
39 | { | |
40 | Init(width, align, flags); | |
41 | } | |
42 | ||
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) | |
50 | { | |
51 | Init(width, align, flags); | |
52 | } | |
53 | ||
54 | // implement wxHeaderColumnBase methods | |
5d9e1605 | 55 | virtual void SetTitle(const wxString& title) { m_title = title; UpdateDisplay(); } |
e2bfe673 VZ |
56 | virtual wxString GetTitle() const { return m_title; } |
57 | ||
5d9e1605 | 58 | virtual void SetWidth(int width) { m_width = width; UpdateDisplay(); } |
e2bfe673 VZ |
59 | virtual int GetWidth() const { return m_width; } |
60 | ||
5d9e1605 | 61 | virtual void SetMinWidth(int minWidth) { m_minWidth = minWidth; UpdateDisplay(); } |
e2bfe673 VZ |
62 | virtual int GetMinWidth() const { return m_minWidth; } |
63 | ||
5d9e1605 | 64 | virtual void SetAlignment(wxAlignment align) { m_align = align; UpdateDisplay(); } |
e2bfe673 VZ |
65 | virtual wxAlignment GetAlignment() const { return m_align; } |
66 | ||
5d9e1605 | 67 | virtual void SetFlags(int flags) { m_flags = flags; UpdateDisplay(); } |
e2bfe673 VZ |
68 | virtual int GetFlags() const { return m_flags; } |
69 | ||
5d9e1605 | 70 | virtual void SetAsSortKey(bool sort = true) { m_sort = sort; UpdateDisplay(); } |
e2bfe673 VZ |
71 | virtual bool IsSortKey() const { return m_sort; } |
72 | ||
5d9e1605 | 73 | virtual void SetSortOrder(bool ascending) { m_sortAscending = ascending; UpdateDisplay(); } |
e2bfe673 | 74 | virtual bool IsSortOrderAscending() const { return m_sortAscending; } |
4ed7af08 | 75 | |
5d9e1605 RR |
76 | virtual void SetBitmap( const wxBitmap& bitmap ) { wxDataViewColumnBase::SetBitmap(bitmap); UpdateDisplay(); } |
77 | ||
78 | ||
56873923 | 79 | private: |
e2bfe673 | 80 | // common part of all ctors |
5d9e1605 | 81 | void Init(int width, wxAlignment align, int flags); |
ce00f59b | 82 | |
5d9e1605 | 83 | void UpdateDisplay(); |
e2bfe673 | 84 | |
e2bfe673 VZ |
85 | wxString m_title; |
86 | int m_width, | |
87 | m_minWidth; | |
88 | wxAlignment m_align; | |
89 | int m_flags; | |
90 | bool m_sort, | |
91 | m_sortAscending; | |
92 | ||
56873923 VZ |
93 | friend class wxDataViewHeaderWindowBase; |
94 | friend class wxDataViewHeaderWindow; | |
95 | friend class wxDataViewHeaderWindowMSW; | |
4ed7af08 RR |
96 | }; |
97 | ||
f554a14b | 98 | // --------------------------------------------------------- |
4ed7af08 | 99 | // wxDataViewCtrl |
f554a14b | 100 | // --------------------------------------------------------- |
4ed7af08 | 101 | |
4660b556 VZ |
102 | WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn, wxDataViewColumnList, |
103 | class WXDLLIMPEXP_ADV); | |
afebb87b | 104 | |
938161a6 VZ |
105 | class WXDLLIMPEXP_ADV wxDataViewCtrl : public wxDataViewCtrlBase, |
106 | public wxScrollHelper | |
4ed7af08 | 107 | { |
87f0efe2 RR |
108 | friend class wxDataViewMainWindow; |
109 | friend class wxDataViewHeaderWindowBase; | |
110 | friend class wxDataViewHeaderWindow; | |
111 | friend class wxDataViewHeaderWindowMSW; | |
9861f022 | 112 | friend class wxDataViewColumn; |
87f0efe2 | 113 | |
4ed7af08 | 114 | public: |
938161a6 | 115 | wxDataViewCtrl() : wxScrollHelper(this) |
4ed7af08 RR |
116 | { |
117 | Init(); | |
118 | } | |
f554a14b | 119 | |
4ed7af08 RR |
120 | wxDataViewCtrl( wxWindow *parent, wxWindowID id, |
121 | const wxPoint& pos = wxDefaultPosition, | |
122 | const wxSize& size = wxDefaultSize, long style = 0, | |
62e9285a | 123 | const wxValidator& validator = wxDefaultValidator, |
346f3fd6 | 124 | const wxString& name = wxDataViewCtrlNameStr ) |
938161a6 | 125 | : wxScrollHelper(this) |
4ed7af08 | 126 | { |
62e9285a | 127 | Create(parent, id, pos, size, style, validator, name); |
4ed7af08 RR |
128 | } |
129 | ||
130 | virtual ~wxDataViewCtrl(); | |
131 | ||
132 | void Init(); | |
133 | ||
134 | bool Create(wxWindow *parent, wxWindowID id, | |
bc4f1ff2 FM |
135 | const wxPoint& pos = wxDefaultPosition, |
136 | const wxSize& size = wxDefaultSize, long style = 0, | |
62e9285a VZ |
137 | const wxValidator& validator = wxDefaultValidator, |
138 | const wxString& name = wxDataViewCtrlNameStr); | |
4ed7af08 | 139 | |
aba9bfd0 | 140 | virtual bool AssociateModel( wxDataViewModel *model ); |
e2bfe673 | 141 | |
4ed7af08 | 142 | virtual bool AppendColumn( wxDataViewColumn *col ); |
736fe67c | 143 | virtual bool PrependColumn( wxDataViewColumn *col ); |
19723525 | 144 | virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col ); |
f554a14b | 145 | |
3b6280be RR |
146 | virtual void DoSetExpanderColumn(); |
147 | virtual void DoSetIndent(); | |
148 | ||
afebb87b RR |
149 | virtual unsigned int GetColumnCount() const; |
150 | virtual wxDataViewColumn* GetColumn( unsigned int pos ) const; | |
151 | virtual bool DeleteColumn( wxDataViewColumn *column ); | |
152 | virtual bool ClearColumns(); | |
453091c2 | 153 | virtual int GetColumnPosition( const wxDataViewColumn *column ) const; |
afebb87b | 154 | |
21f47fb9 | 155 | virtual wxDataViewColumn *GetSortingColumn() const; |
e2bfe673 | 156 | |
fbda518c | 157 | virtual wxDataViewItem GetSelection() const; |
b7e9f8b1 RR |
158 | virtual int GetSelections( wxDataViewItemArray & sel ) const; |
159 | virtual void SetSelections( const wxDataViewItemArray & sel ); | |
160 | virtual void Select( const wxDataViewItem & item ); | |
161 | virtual void Unselect( const wxDataViewItem & item ); | |
162 | virtual bool IsSelected( const wxDataViewItem & item ) const; | |
163 | ||
66e09788 RR |
164 | virtual void SelectAll(); |
165 | virtual void UnselectAll(); | |
166 | ||
167 | virtual void EnsureVisible( const wxDataViewItem & item, | |
fbda518c | 168 | const wxDataViewColumn *column = NULL ); |
03647350 | 169 | virtual void HitTest( const wxPoint & point, wxDataViewItem & item, |
bc4f1ff2 | 170 | wxDataViewColumn* &column ) const; |
03647350 | 171 | virtual wxRect GetItemRect( const wxDataViewItem & item, |
bc4f1ff2 | 172 | const wxDataViewColumn *column = NULL ) const; |
66e09788 | 173 | |
afebb87b RR |
174 | virtual void Expand( const wxDataViewItem & item ); |
175 | virtual void Collapse( const wxDataViewItem & item ); | |
739a8399 | 176 | virtual bool IsExpanded( const wxDataViewItem & item ) const; |
e2bfe673 | 177 | |
788432e3 | 178 | virtual void SetFocus(); |
9adeb77a VZ |
179 | |
180 | #if wxUSE_DRAG_AND_DROP | |
821baf7d RR |
181 | virtual bool EnableDragSource( const wxDataFormat &format ); |
182 | virtual bool EnableDropTarget( const wxDataFormat &format ); | |
9adeb77a | 183 | #endif // wxUSE_DRAG_AND_DROP |
afebb87b | 184 | |
3fdf86f9 RR |
185 | virtual wxBorder GetDefaultBorder() const; |
186 | ||
c937344c RR |
187 | void StartEditor( const wxDataViewItem & item, unsigned int column ); |
188 | ||
66e09788 | 189 | protected: |
e2bfe673 | 190 | virtual int GetSelections( wxArrayInt & sel ) const; |
b7e9f8b1 RR |
191 | virtual void SetSelections( const wxArrayInt & sel ); |
192 | virtual void Select( int row ); | |
193 | virtual void Unselect( int row ); | |
194 | virtual bool IsSelected( int row ) const; | |
195 | virtual void SelectRange( int from, int to ); | |
196 | virtual void UnselectRange( int from, int to ); | |
197 | ||
fbda518c | 198 | virtual void EnsureVisible( int row, int column ); |
b7e9f8b1 RR |
199 | |
200 | virtual wxDataViewItem GetItemByRow( unsigned int row ) const; | |
201 | virtual int GetRowByItem( const wxDataViewItem & item ) const; | |
202 | ||
46234a03 VZ |
203 | int GetSortingColumnIndex() const { return m_sortingColumnIdx; } |
204 | void SetSortingColumnIndex(int idx) { m_sortingColumnIdx = idx; } | |
6ff7eee7 | 205 | |
9861f022 RR |
206 | public: // utility functions not part of the API |
207 | ||
87f0efe2 | 208 | // returns the "best" width for the idx-th column |
9861f022 | 209 | unsigned int GetBestColumnWidth(int WXUNUSED(idx)) const |
87f0efe2 | 210 | { |
9861f022 | 211 | return GetClientSize().GetWidth() / GetColumnCount(); |
87f0efe2 RR |
212 | } |
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 | ||
ad386793 RR |
235 | wxDataViewColumnList m_cols; |
236 | wxDataViewModelNotifier *m_notifier; | |
237 | wxDataViewMainWindow *m_clientArea; | |
238 | wxDataViewHeaderWindow *m_headerArea; | |
46234a03 VZ |
239 | |
240 | // the index of the column currently used for sorting or -1 | |
241 | int m_sortingColumnIdx; | |
f554a14b | 242 | |
4ed7af08 | 243 | private: |
4b3feaa7 | 244 | void OnSize( wxSizeEvent &event ); |
2571a33f | 245 | virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size); |
f554a14b | 246 | |
4ed7af08 RR |
247 | // we need to return a special WM_GETDLGCODE value to process just the |
248 | // arrows but let the other navigation characters through | |
249 | #ifdef __WXMSW__ | |
250 | virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); | |
251 | #endif // __WXMSW__ | |
252 | ||
253 | WX_FORWARD_TO_SCROLL_HELPER() | |
4b3feaa7 | 254 | |
4ed7af08 RR |
255 | private: |
256 | DECLARE_DYNAMIC_CLASS(wxDataViewCtrl) | |
c0c133e1 | 257 | wxDECLARE_NO_COPY_CLASS(wxDataViewCtrl); |
4b3feaa7 | 258 | DECLARE_EVENT_TABLE() |
4ed7af08 RR |
259 | }; |
260 | ||
261 | ||
262 | #endif // __GENERICDATAVIEWCTRLH__ |