]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/dataview.h
supporting clang memory management annotations
[wxWidgets.git] / include / wx / generic / dataview.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/dataview.h
3 // Purpose: wxDataViewCtrl generic implementation header
4 // Author: Robert Roebling
5 // Modified By: Bo Yang
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"
18 #include "wx/scrolwin.h"
19 #include "wx/icon.h"
20 #include "wx/vector.h"
21
22 class WXDLLIMPEXP_FWD_ADV wxDataViewMainWindow;
23 class WXDLLIMPEXP_FWD_ADV wxDataViewHeaderWindow;
24
25 // ---------------------------------------------------------
26 // wxDataViewColumn
27 // ---------------------------------------------------------
28
29 class WXDLLIMPEXP_ADV wxDataViewColumn : public wxDataViewColumnBase
30 {
31 public:
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
56 virtual void SetTitle(const wxString& title) { m_title = title; UpdateDisplay(); }
57 virtual wxString GetTitle() const { return m_title; }
58
59 virtual void SetWidth(int width) { m_width = width; UpdateDisplay(); }
60 virtual int GetWidth() const;
61
62 virtual void SetMinWidth(int minWidth) { m_minWidth = minWidth; UpdateDisplay(); }
63 virtual int GetMinWidth() const { return m_minWidth; }
64
65 virtual void SetAlignment(wxAlignment align) { m_align = align; UpdateDisplay(); }
66 virtual wxAlignment GetAlignment() const { return m_align; }
67
68 virtual void SetFlags(int flags) { m_flags = flags; UpdateDisplay(); }
69 virtual int GetFlags() const { return m_flags; }
70
71 virtual bool IsSortKey() const { return m_sort; }
72
73 virtual void UnsetAsSortKey() { m_sort = false; UpdateDisplay(); }
74
75 virtual void SetSortOrder(bool ascending);
76
77 virtual bool IsSortOrderAscending() const { return m_sortAscending; }
78
79 virtual void SetBitmap( const wxBitmap& bitmap ) { wxDataViewColumnBase::SetBitmap(bitmap); UpdateDisplay(); }
80
81
82 private:
83 // common part of all ctors
84 void Init(int width, wxAlignment align, int flags);
85
86 void UpdateDisplay();
87
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
96 friend class wxDataViewHeaderWindowBase;
97 friend class wxDataViewHeaderWindow;
98 friend class wxDataViewHeaderWindowMSW;
99 };
100
101 // ---------------------------------------------------------
102 // wxDataViewCtrl
103 // ---------------------------------------------------------
104
105 WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn, wxDataViewColumnList,
106 class WXDLLIMPEXP_ADV);
107
108 class WXDLLIMPEXP_ADV wxDataViewCtrl : public wxDataViewCtrlBase,
109 public wxScrollHelper
110 {
111 friend class wxDataViewMainWindow;
112 friend class wxDataViewHeaderWindowBase;
113 friend class wxDataViewHeaderWindow;
114 friend class wxDataViewHeaderWindowMSW;
115 friend class wxDataViewColumn;
116
117 public:
118 wxDataViewCtrl() : wxScrollHelper(this)
119 {
120 Init();
121 }
122
123 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
124 const wxPoint& pos = wxDefaultPosition,
125 const wxSize& size = wxDefaultSize, long style = 0,
126 const wxValidator& validator = wxDefaultValidator,
127 const wxString& name = wxDataViewCtrlNameStr )
128 : wxScrollHelper(this)
129 {
130 Create(parent, id, pos, size, style, validator, name);
131 }
132
133 virtual ~wxDataViewCtrl();
134
135 void Init();
136
137 bool Create(wxWindow *parent, wxWindowID id,
138 const wxPoint& pos = wxDefaultPosition,
139 const wxSize& size = wxDefaultSize, long style = 0,
140 const wxValidator& validator = wxDefaultValidator,
141 const wxString& name = wxDataViewCtrlNameStr);
142
143 virtual bool AssociateModel( wxDataViewModel *model );
144
145 virtual bool AppendColumn( wxDataViewColumn *col );
146 virtual bool PrependColumn( wxDataViewColumn *col );
147 virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col );
148
149 virtual void DoSetExpanderColumn();
150 virtual void DoSetIndent();
151
152 virtual unsigned int GetColumnCount() const;
153 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const;
154 virtual bool DeleteColumn( wxDataViewColumn *column );
155 virtual bool ClearColumns();
156 virtual int GetColumnPosition( const wxDataViewColumn *column ) const;
157
158 virtual wxDataViewColumn *GetSortingColumn() const;
159
160 virtual int GetSelectedItemsCount() const;
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
167 virtual void SelectAll();
168 virtual void UnselectAll();
169
170 virtual void EnsureVisible( const wxDataViewItem & item,
171 const wxDataViewColumn *column = NULL );
172 virtual void HitTest( const wxPoint & point, wxDataViewItem & item,
173 wxDataViewColumn* &column ) const;
174 virtual wxRect GetItemRect( const wxDataViewItem & item,
175 const wxDataViewColumn *column = NULL ) const;
176
177 virtual bool SetRowHeight( int rowHeight );
178
179 virtual void Expand( const wxDataViewItem & item );
180 virtual void Collapse( const wxDataViewItem & item );
181 virtual bool IsExpanded( const wxDataViewItem & item ) const;
182
183 virtual void SetFocus();
184
185 #if wxUSE_DRAG_AND_DROP
186 virtual bool EnableDragSource( const wxDataFormat &format );
187 virtual bool EnableDropTarget( const wxDataFormat &format );
188 #endif // wxUSE_DRAG_AND_DROP
189
190 virtual wxBorder GetDefaultBorder() const;
191
192 virtual void EditItem(const wxDataViewItem& item, const wxDataViewColumn *column);
193
194 // These methods are specific to generic wxDataViewCtrl implementation and
195 // should not be used in portable code.
196 wxColour GetAlternateRowColour() const { return m_alternateRowColour; }
197 void SetAlternateRowColour(const wxColour& colour);
198
199 protected:
200 virtual void EnsureVisible( int row, int column );
201
202 // Notice that row here may be invalid (i.e. >= GetRowCount()), this is not
203 // an error and this function simply returns an invalid item in this case.
204 virtual wxDataViewItem GetItemByRow( unsigned int row ) const;
205 virtual int GetRowByItem( const wxDataViewItem & item ) const;
206
207 int GetSortingColumnIndex() const { return m_sortingColumnIdx; }
208 void SetSortingColumnIndex(int idx) { m_sortingColumnIdx = idx; }
209
210 public: // utility functions not part of the API
211
212 // returns the "best" width for the idx-th column
213 unsigned int GetBestColumnWidth(int idx) const;
214
215 // called by header window after reorder
216 void ColumnMoved( wxDataViewColumn* col, unsigned int new_pos );
217
218 // update the display after a change to an individual column
219 void OnColumnChange(unsigned int idx);
220
221 // update after a change to the number of columns
222 void OnColumnsCountChanged();
223
224 wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; }
225
226 // return the index of the given column in m_cols
227 int GetColumnIndex(const wxDataViewColumn *column) const;
228
229 // return the column displayed at the given position in the control
230 wxDataViewColumn *GetColumnAt(unsigned int pos) const;
231
232 virtual wxDataViewColumn *GetCurrentColumn() const;
233
234 virtual void OnInternalIdle();
235
236 private:
237 virtual wxDataViewItem DoGetCurrentItem() const;
238 virtual void DoSetCurrentItem(const wxDataViewItem& item);
239
240 void InvalidateColBestWidths();
241 void InvalidateColBestWidth(int idx);
242 void UpdateColWidths();
243
244 wxDataViewColumnList m_cols;
245 // cached column best widths information, values are for
246 // respective columns from m_cols and the arrays have same size
247 struct CachedColWidthInfo
248 {
249 CachedColWidthInfo() : width(0), dirty(true) {}
250 int width; // cached width or 0 if not computed
251 bool dirty; // column was invalidated, header needs updating
252 };
253 wxVector<CachedColWidthInfo> m_colsBestWidths;
254 // This indicates that at least one entry in m_colsBestWidths has 'dirty'
255 // flag set. It's cheaper to check one flag in OnInternalIdle() than to
256 // iterate over m_colsBestWidths to check if anything needs to be done.
257 bool m_colsDirty;
258
259 wxDataViewModelNotifier *m_notifier;
260 wxDataViewMainWindow *m_clientArea;
261 wxDataViewHeaderWindow *m_headerArea;
262
263 // user defined color to draw row lines, may be invalid
264 wxColour m_alternateRowColour;
265
266 // the index of the column currently used for sorting or -1
267 int m_sortingColumnIdx;
268
269 private:
270 void OnSize( wxSizeEvent &event );
271 virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size);
272
273 // we need to return a special WM_GETDLGCODE value to process just the
274 // arrows but let the other navigation characters through
275 #ifdef __WXMSW__
276 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
277 #endif // __WXMSW__
278
279 WX_FORWARD_TO_SCROLL_HELPER()
280
281 private:
282 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
283 wxDECLARE_NO_COPY_CLASS(wxDataViewCtrl);
284 DECLARE_EVENT_TABLE()
285 };
286
287
288 #endif // __GENERICDATAVIEWCTRLH__