]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/dataview.h
Use correct reload flags on all platforms to avoid compilation errors
[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 void SetAsSortKey(bool sort = true) { m_sort = sort; UpdateDisplay(); }
72 virtual bool IsSortKey() const { return m_sort; }
73
74 virtual void SetSortOrder(bool ascending) { m_sortAscending = ascending; UpdateDisplay(); }
75 virtual bool IsSortOrderAscending() const { return m_sortAscending; }
76
77 virtual void SetBitmap( const wxBitmap& bitmap ) { wxDataViewColumnBase::SetBitmap(bitmap); UpdateDisplay(); }
78
79
80 private:
81 // common part of all ctors
82 void Init(int width, wxAlignment align, int flags);
83
84 void UpdateDisplay();
85
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
94 friend class wxDataViewHeaderWindowBase;
95 friend class wxDataViewHeaderWindow;
96 friend class wxDataViewHeaderWindowMSW;
97 };
98
99 // ---------------------------------------------------------
100 // wxDataViewCtrl
101 // ---------------------------------------------------------
102
103 WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn, wxDataViewColumnList,
104 class WXDLLIMPEXP_ADV);
105
106 class WXDLLIMPEXP_ADV wxDataViewCtrl : public wxDataViewCtrlBase,
107 public wxScrollHelper
108 {
109 friend class wxDataViewMainWindow;
110 friend class wxDataViewHeaderWindowBase;
111 friend class wxDataViewHeaderWindow;
112 friend class wxDataViewHeaderWindowMSW;
113 friend class wxDataViewColumn;
114
115 public:
116 wxDataViewCtrl() : wxScrollHelper(this)
117 {
118 Init();
119 }
120
121 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
122 const wxPoint& pos = wxDefaultPosition,
123 const wxSize& size = wxDefaultSize, long style = 0,
124 const wxValidator& validator = wxDefaultValidator,
125 const wxString& name = wxDataViewCtrlNameStr )
126 : wxScrollHelper(this)
127 {
128 Create(parent, id, pos, size, style, validator, name);
129 }
130
131 virtual ~wxDataViewCtrl();
132
133 void Init();
134
135 bool Create(wxWindow *parent, wxWindowID id,
136 const wxPoint& pos = wxDefaultPosition,
137 const wxSize& size = wxDefaultSize, long style = 0,
138 const wxValidator& validator = wxDefaultValidator,
139 const wxString& name = wxDataViewCtrlNameStr);
140
141 virtual bool AssociateModel( wxDataViewModel *model );
142
143 virtual bool AppendColumn( wxDataViewColumn *col );
144 virtual bool PrependColumn( wxDataViewColumn *col );
145 virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col );
146
147 virtual void DoSetExpanderColumn();
148 virtual void DoSetIndent();
149
150 virtual unsigned int GetColumnCount() const;
151 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const;
152 virtual bool DeleteColumn( wxDataViewColumn *column );
153 virtual bool ClearColumns();
154 virtual int GetColumnPosition( const wxDataViewColumn *column ) const;
155
156 virtual wxDataViewColumn *GetSortingColumn() const;
157
158 virtual wxDataViewItem GetSelection() const;
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
165 virtual void SelectAll();
166 virtual void UnselectAll();
167
168 virtual void EnsureVisible( const wxDataViewItem & item,
169 const wxDataViewColumn *column = NULL );
170 virtual void HitTest( const wxPoint & point, wxDataViewItem & item,
171 wxDataViewColumn* &column ) const;
172 virtual wxRect GetItemRect( const wxDataViewItem & item,
173 const wxDataViewColumn *column = NULL ) const;
174
175 virtual void Expand( const wxDataViewItem & item );
176 virtual void Collapse( const wxDataViewItem & item );
177 virtual bool IsExpanded( const wxDataViewItem & item ) const;
178
179 virtual void SetFocus();
180
181 #if wxUSE_DRAG_AND_DROP
182 virtual bool EnableDragSource( const wxDataFormat &format );
183 virtual bool EnableDropTarget( const wxDataFormat &format );
184 #endif // wxUSE_DRAG_AND_DROP
185
186 virtual wxBorder GetDefaultBorder() const;
187
188 void StartEditor( const wxDataViewItem & item, unsigned int column );
189
190 protected:
191 virtual int GetSelections( wxArrayInt & sel ) const;
192 virtual void SetSelections( const wxArrayInt & sel );
193 virtual void Select( int row );
194 virtual void Unselect( int row );
195 virtual bool IsSelected( int row ) const;
196 virtual void SelectRange( int from, int to );
197 virtual void UnselectRange( int from, int to );
198
199 virtual void EnsureVisible( int row, int column );
200
201 virtual wxDataViewItem GetItemByRow( unsigned int row ) const;
202 virtual int GetRowByItem( const wxDataViewItem & item ) const;
203
204 int GetSortingColumnIndex() const { return m_sortingColumnIdx; }
205 void SetSortingColumnIndex(int idx) { m_sortingColumnIdx = idx; }
206
207 public: // utility functions not part of the API
208
209 // returns the "best" width for the idx-th column
210 unsigned int GetBestColumnWidth(int idx) const;
211
212 // called by header window after reorder
213 void ColumnMoved( wxDataViewColumn* col, unsigned int new_pos );
214
215 // update the display after a change to an individual column
216 void OnColumnChange(unsigned int idx);
217
218 // update after a change to the number of columns
219 void OnColumnsCountChanged();
220
221 wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; }
222
223 // return the index of the given column in m_cols
224 int GetColumnIndex(const wxDataViewColumn *column) const;
225
226 // return the column displayed at the given position in the control
227 wxDataViewColumn *GetColumnAt(unsigned int pos) const;
228
229 private:
230 virtual wxDataViewItem DoGetCurrentItem() const;
231 virtual void DoSetCurrentItem(const wxDataViewItem& item);
232
233 void InvalidateColBestWidths();
234 void InvalidateColBestWidth(int idx);
235
236 wxDataViewColumnList m_cols;
237 // cached column best widths or 0 if not computed, values are for
238 // respective columns from m_cols and the arrays have same size
239 wxVector<int> m_colsBestWidths;
240 wxDataViewModelNotifier *m_notifier;
241 wxDataViewMainWindow *m_clientArea;
242 wxDataViewHeaderWindow *m_headerArea;
243
244 // the index of the column currently used for sorting or -1
245 int m_sortingColumnIdx;
246
247 private:
248 void OnSize( wxSizeEvent &event );
249 virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size);
250
251 // we need to return a special WM_GETDLGCODE value to process just the
252 // arrows but let the other navigation characters through
253 #ifdef __WXMSW__
254 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
255 #endif // __WXMSW__
256
257 WX_FORWARD_TO_SCROLL_HELPER()
258
259 private:
260 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
261 wxDECLARE_NO_COPY_CLASS(wxDataViewCtrl);
262 DECLARE_EVENT_TABLE()
263 };
264
265
266 #endif // __GENERICDATAVIEWCTRLH__