]>
Commit | Line | Data |
---|---|---|
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 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifndef __GENERICDATAVIEWCTRLH__ | |
11 | #define __GENERICDATAVIEWCTRLH__ | |
12 | ||
13 | #include "wx/defs.h" | |
14 | #include "wx/object.h" | |
15 | #include "wx/list.h" | |
16 | #include "wx/control.h" | |
17 | #include "wx/scrolwin.h" | |
18 | #include "wx/icon.h" | |
19 | #include "wx/vector.h" | |
20 | ||
21 | class WXDLLIMPEXP_FWD_ADV wxDataViewMainWindow; | |
22 | class WXDLLIMPEXP_FWD_ADV wxDataViewHeaderWindow; | |
23 | ||
24 | // --------------------------------------------------------- | |
25 | // wxDataViewColumn | |
26 | // --------------------------------------------------------- | |
27 | ||
28 | class WXDLLIMPEXP_ADV wxDataViewColumn : public wxDataViewColumnBase | |
29 | { | |
30 | public: | |
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 | |
55 | virtual void SetTitle(const wxString& title) { m_title = title; UpdateDisplay(); } | |
56 | virtual wxString GetTitle() const { return m_title; } | |
57 | ||
58 | virtual void SetWidth(int width) { m_width = width; UpdateDisplay(); } | |
59 | virtual int GetWidth() const; | |
60 | ||
61 | virtual void SetMinWidth(int minWidth) { m_minWidth = minWidth; UpdateDisplay(); } | |
62 | virtual int GetMinWidth() const { return m_minWidth; } | |
63 | ||
64 | virtual void SetAlignment(wxAlignment align) { m_align = align; UpdateDisplay(); } | |
65 | virtual wxAlignment GetAlignment() const { return m_align; } | |
66 | ||
67 | virtual void SetFlags(int flags) { m_flags = flags; UpdateDisplay(); } | |
68 | virtual int GetFlags() const { return m_flags; } | |
69 | ||
70 | virtual bool IsSortKey() const { return m_sort; } | |
71 | ||
72 | virtual void UnsetAsSortKey(); | |
73 | ||
74 | virtual void SetSortOrder(bool ascending); | |
75 | ||
76 | virtual bool IsSortOrderAscending() const { return m_sortAscending; } | |
77 | ||
78 | virtual void SetBitmap( const wxBitmap& bitmap ) { wxDataViewColumnBase::SetBitmap(bitmap); UpdateDisplay(); } | |
79 | ||
80 | ||
81 | private: | |
82 | // common part of all ctors | |
83 | void Init(int width, wxAlignment align, int flags); | |
84 | ||
85 | void UpdateDisplay(); | |
86 | ||
87 | wxString m_title; | |
88 | int m_width, | |
89 | m_minWidth; | |
90 | wxAlignment m_align; | |
91 | int m_flags; | |
92 | bool m_sort, | |
93 | m_sortAscending; | |
94 | ||
95 | friend class wxDataViewHeaderWindowBase; | |
96 | friend class wxDataViewHeaderWindow; | |
97 | friend class wxDataViewHeaderWindowMSW; | |
98 | }; | |
99 | ||
100 | // --------------------------------------------------------- | |
101 | // wxDataViewCtrl | |
102 | // --------------------------------------------------------- | |
103 | ||
104 | WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn, wxDataViewColumnList, | |
105 | class WXDLLIMPEXP_ADV); | |
106 | ||
107 | class WXDLLIMPEXP_ADV wxDataViewCtrl : public wxDataViewCtrlBase, | |
108 | public wxScrollHelper | |
109 | { | |
110 | friend class wxDataViewMainWindow; | |
111 | friend class wxDataViewHeaderWindowBase; | |
112 | friend class wxDataViewHeaderWindow; | |
113 | friend class wxDataViewHeaderWindowMSW; | |
114 | friend class wxDataViewColumn; | |
115 | ||
116 | public: | |
117 | wxDataViewCtrl() : wxScrollHelper(this) | |
118 | { | |
119 | Init(); | |
120 | } | |
121 | ||
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) | |
128 | { | |
129 | Create(parent, id, pos, size, style, validator, name); | |
130 | } | |
131 | ||
132 | virtual ~wxDataViewCtrl(); | |
133 | ||
134 | void Init(); | |
135 | ||
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); | |
141 | ||
142 | virtual bool AssociateModel( wxDataViewModel *model ); | |
143 | ||
144 | virtual bool AppendColumn( wxDataViewColumn *col ); | |
145 | virtual bool PrependColumn( wxDataViewColumn *col ); | |
146 | virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col ); | |
147 | ||
148 | virtual void DoSetExpanderColumn(); | |
149 | virtual void DoSetIndent(); | |
150 | ||
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; | |
156 | ||
157 | virtual wxDataViewColumn *GetSortingColumn() const; | |
158 | ||
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; | |
165 | ||
166 | virtual void SelectAll(); | |
167 | virtual void UnselectAll(); | |
168 | ||
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; | |
175 | ||
176 | virtual bool SetRowHeight( int rowHeight ); | |
177 | ||
178 | virtual void Expand( const wxDataViewItem & item ); | |
179 | virtual void Collapse( const wxDataViewItem & item ); | |
180 | virtual bool IsExpanded( const wxDataViewItem & item ) const; | |
181 | ||
182 | virtual void SetFocus(); | |
183 | ||
184 | virtual bool SetFont(const wxFont & font); | |
185 | ||
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 | |
190 | ||
191 | virtual wxBorder GetDefaultBorder() const; | |
192 | ||
193 | virtual void EditItem(const wxDataViewItem& item, const wxDataViewColumn *column); | |
194 | ||
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); | |
199 | ||
200 | protected: | |
201 | virtual void EnsureVisible( int row, int column ); | |
202 | ||
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; | |
207 | ||
208 | int GetSortingColumnIndex() const { return m_sortingColumnIdx; } | |
209 | void SetSortingColumnIndex(int idx) { m_sortingColumnIdx = idx; } | |
210 | ||
211 | public: // utility functions not part of the API | |
212 | ||
213 | // returns the "best" width for the idx-th column | |
214 | unsigned int GetBestColumnWidth(int idx) const; | |
215 | ||
216 | // called by header window after reorder | |
217 | void ColumnMoved( wxDataViewColumn* col, unsigned int new_pos ); | |
218 | ||
219 | // update the display after a change to an individual column | |
220 | void OnColumnChange(unsigned int idx); | |
221 | ||
222 | // update after a change to the number of columns | |
223 | void OnColumnsCountChanged(); | |
224 | ||
225 | wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; } | |
226 | ||
227 | // return the index of the given column in m_cols | |
228 | int GetColumnIndex(const wxDataViewColumn *column) const; | |
229 | ||
230 | // Return the index of the column having the given model index. | |
231 | int GetModelColumnIndex(unsigned int model_column) const; | |
232 | ||
233 | // return the column displayed at the given position in the control | |
234 | wxDataViewColumn *GetColumnAt(unsigned int pos) const; | |
235 | ||
236 | virtual wxDataViewColumn *GetCurrentColumn() const; | |
237 | ||
238 | virtual void OnInternalIdle(); | |
239 | ||
240 | private: | |
241 | virtual wxDataViewItem DoGetCurrentItem() const; | |
242 | virtual void DoSetCurrentItem(const wxDataViewItem& item); | |
243 | ||
244 | void InvalidateColBestWidths(); | |
245 | void InvalidateColBestWidth(int idx); | |
246 | void UpdateColWidths(); | |
247 | ||
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 | |
252 | { | |
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 | |
256 | }; | |
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. | |
261 | bool m_colsDirty; | |
262 | ||
263 | wxDataViewModelNotifier *m_notifier; | |
264 | wxDataViewMainWindow *m_clientArea; | |
265 | wxDataViewHeaderWindow *m_headerArea; | |
266 | ||
267 | // user defined color to draw row lines, may be invalid | |
268 | wxColour m_alternateRowColour; | |
269 | ||
270 | // the index of the column currently used for sorting or -1 | |
271 | int m_sortingColumnIdx; | |
272 | ||
273 | private: | |
274 | void OnSize( wxSizeEvent &event ); | |
275 | virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size); | |
276 | ||
277 | // we need to return a special WM_GETDLGCODE value to process just the | |
278 | // arrows but let the other navigation characters through | |
279 | #ifdef __WXMSW__ | |
280 | virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); | |
281 | #endif // __WXMSW__ | |
282 | ||
283 | WX_FORWARD_TO_SCROLL_HELPER() | |
284 | ||
285 | private: | |
286 | DECLARE_DYNAMIC_CLASS(wxDataViewCtrl) | |
287 | wxDECLARE_NO_COPY_CLASS(wxDataViewCtrl); | |
288 | DECLARE_EVENT_TABLE() | |
289 | }; | |
290 | ||
291 | ||
292 | #endif // __GENERICDATAVIEWCTRLH__ |