Most of FM's wxDataViewCtrl patch.
[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 // Id: $Id$
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
20 // ---------------------------------------------------------
21 // classes
22 // ---------------------------------------------------------
23
24 class WXDLLIMPEXP_ADV wxDataViewCtrl;
25 class WXDLLIMPEXP_ADV wxDataViewMainWindow;
26 class WXDLLIMPEXP_ADV wxDataViewHeaderWindow;
27
28 // ---------------------------------------------------------
29 // wxDataViewRenderer
30 // ---------------------------------------------------------
31
32 class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase
33 {
34 public:
35 wxDataViewRenderer( const wxString &varianttype,
36 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT );
37 virtual ~wxDataViewRenderer();
38
39 virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0;
40 virtual wxSize GetSize() = 0;
41
42 virtual bool Activate( wxRect WXUNUSED(cell),
43 wxDataViewListModel *WXUNUSED(model),
44 unsigned int WXUNUSED(col),
45 unsigned int WXUNUSED(row) )
46 { return false; }
47
48 virtual bool LeftClick( wxPoint WXUNUSED(cursor),
49 wxRect WXUNUSED(cell),
50 wxDataViewListModel *WXUNUSED(model),
51 unsigned int WXUNUSED(col),
52 unsigned int WXUNUSED(row) )
53 { return false; }
54 virtual bool RightClick( wxPoint WXUNUSED(cursor),
55 wxRect WXUNUSED(cell),
56 wxDataViewListModel *WXUNUSED(model),
57 unsigned int WXUNUSED(col),
58 unsigned int WXUNUSED(row) )
59 { return false; }
60 virtual bool StartDrag( wxPoint WXUNUSED(cursor),
61 wxRect WXUNUSED(cell),
62 wxDataViewListModel *WXUNUSED(model),
63 unsigned int WXUNUSED(col),
64 unsigned int WXUNUSED(row) )
65 { return false; }
66
67 // Create DC on request
68 virtual wxDC *GetDC();
69
70 private:
71 wxDC *m_dc;
72
73 protected:
74 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
75 };
76
77 // ---------------------------------------------------------
78 // wxDataViewCustomRenderer
79 // ---------------------------------------------------------
80
81 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
82 {
83 public:
84 wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"),
85 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT );
86
87 protected:
88 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
89 };
90
91 // ---------------------------------------------------------
92 // wxDataViewTextRenderer
93 // ---------------------------------------------------------
94
95 class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewCustomRenderer
96 {
97 public:
98 wxDataViewTextRenderer( const wxString &varianttype = wxT("string"),
99 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT );
100
101 bool SetValue( const wxVariant &value );
102 bool GetValue( wxVariant &value );
103
104 bool Render( wxRect cell, wxDC *dc, int state );
105 wxSize GetSize();
106
107 private:
108 wxString m_text;
109
110 protected:
111 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
112 };
113
114 // ---------------------------------------------------------
115 // wxDataViewBitmapRenderer
116 // ---------------------------------------------------------
117
118 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewCustomRenderer
119 {
120 public:
121 wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"),
122 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT );
123
124 bool SetValue( const wxVariant &value );
125 bool GetValue( wxVariant &value );
126
127 bool Render( wxRect cell, wxDC *dc, int state );
128 wxSize GetSize();
129
130 private:
131 wxIcon m_icon;
132 wxBitmap m_bitmap;
133
134 protected:
135 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
136 };
137
138 // ---------------------------------------------------------
139 // wxDataViewToggleRenderer
140 // ---------------------------------------------------------
141
142 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewCustomRenderer
143 {
144 public:
145 wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"),
146 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT );
147
148 bool SetValue( const wxVariant &value );
149 bool GetValue( wxVariant &value );
150
151 bool Render( wxRect cell, wxDC *dc, int state );
152 bool Activate( wxRect cell, wxDataViewListModel *model, unsigned int col,
153 unsigned int row );
154 wxSize GetSize();
155
156 private:
157 bool m_toggle;
158
159 protected:
160 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
161 };
162
163 // ---------------------------------------------------------
164 // wxDataViewProgressRenderer
165 // ---------------------------------------------------------
166
167 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
168 {
169 public:
170 wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
171 const wxString &varianttype = wxT("long"),
172 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT );
173 virtual ~wxDataViewProgressRenderer();
174
175 bool SetValue( const wxVariant &value );
176
177 virtual bool Render( wxRect cell, wxDC *dc, int state );
178 virtual wxSize GetSize();
179
180 private:
181 wxString m_label;
182 int m_value;
183
184 protected:
185 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
186 };
187
188 // ---------------------------------------------------------
189 // wxDataViewDateRenderer
190 // ---------------------------------------------------------
191
192 class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
193 {
194 public:
195 wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
196 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE );
197
198 bool SetValue( const wxVariant &value );
199
200 virtual bool Render( wxRect cell, wxDC *dc, int state );
201 virtual wxSize GetSize();
202 virtual bool Activate( wxRect cell,
203 wxDataViewListModel *model, unsigned int col, unsigned int row );
204
205 private:
206 wxDateTime m_date;
207
208 protected:
209 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
210 };
211
212 // ---------------------------------------------------------
213 // wxDataViewColumn
214 // ---------------------------------------------------------
215
216 class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
217 {
218 friend class wxDataViewHeaderWindowBase;
219 friend class wxDataViewHeaderWindow;
220 friend class wxDataViewHeaderWindowMSW;
221
222 public:
223 wxDataViewColumn( const wxString &title, wxDataViewRenderer *renderer,
224 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
225 wxAlignment align = wxALIGN_CENTER,
226 int flags = wxDATAVIEW_COL_RESIZABLE );
227 wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
228 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
229 wxAlignment align = wxALIGN_CENTER,
230 int flags = wxDATAVIEW_COL_RESIZABLE );
231 virtual ~wxDataViewColumn();
232
233 virtual void SetTitle( const wxString &title );
234 virtual void SetBitmap( const wxBitmap &bitmap );
235
236 virtual void SetAlignment( wxAlignment align )
237 { m_align=align; }
238 wxAlignment GetAlignment() const
239 { return m_align; }
240
241 virtual void SetSortable( bool sortable );
242 virtual void SetSortOrder( bool ascending );
243 virtual bool IsSortOrderAscending() const;
244
245 virtual int GetWidth() const;
246
247 protected:
248
249 void SetWidth(int w)
250 { m_width=w; }
251
252 private:
253 int m_width;
254 int m_fixedWidth;
255 wxAlignment m_align;
256
257 void Init(int width);
258
259 protected:
260 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
261 };
262
263 // ---------------------------------------------------------
264 // wxDataViewCtrl
265 // ---------------------------------------------------------
266
267 class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase,
268 public wxScrollHelperNative
269 {
270 friend class wxDataViewMainWindow;
271 friend class wxDataViewHeaderWindowBase;
272 friend class wxDataViewHeaderWindow;
273 friend class wxDataViewHeaderWindowMSW;
274
275 public:
276 wxDataViewCtrl() : wxScrollHelperNative(this)
277 {
278 Init();
279 }
280
281 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
282 const wxPoint& pos = wxDefaultPosition,
283 const wxSize& size = wxDefaultSize, long style = 0,
284 const wxValidator& validator = wxDefaultValidator )
285 : wxScrollHelperNative(this)
286 {
287 Create(parent, id, pos, size, style, validator );
288 }
289
290 virtual ~wxDataViewCtrl();
291
292 void Init();
293
294 bool Create(wxWindow *parent, wxWindowID id,
295 const wxPoint& pos = wxDefaultPosition,
296 const wxSize& size = wxDefaultSize, long style = 0,
297 const wxValidator& validator = wxDefaultValidator );
298
299 virtual bool AssociateModel( wxDataViewListModel *model );
300 virtual bool AppendColumn( wxDataViewColumn *col );
301
302 virtual void SetSelection( int row ); // -1 for unselect
303 virtual void SetSelectionRange( unsigned int from, unsigned int to );
304 virtual void SetSelections( const wxArrayInt& aSelections);
305 virtual void Unselect( unsigned int row );
306
307 virtual bool IsSelected( unsigned int row ) const;
308 virtual int GetSelection() const;
309 virtual int GetSelections(wxArrayInt& aSelections) const;
310
311 // returns the "best" width for the idx-th column
312 unsigned int GetBestColumnWidth(int WXUNUSED(idx))
313 {
314 return GetClientSize().GetWidth() / GetNumberOfColumns();
315 }
316
317
318 private:
319 wxDataViewListModelNotifier *m_notifier;
320 wxDataViewMainWindow *m_clientArea;
321 wxDataViewHeaderWindow *m_headerArea;
322
323 private:
324 void OnSize( wxSizeEvent &event );
325
326 // we need to return a special WM_GETDLGCODE value to process just the
327 // arrows but let the other navigation characters through
328 #ifdef __WXMSW__
329 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
330 #endif // __WXMSW__
331
332 WX_FORWARD_TO_SCROLL_HELPER()
333
334 private:
335 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
336 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
337 DECLARE_EVENT_TABLE()
338 };
339
340
341 #endif // __GENERICDATAVIEWCTRLH__