]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/dataview.h
add HDF_SORTUP/DOWN definitions
[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
21 // ---------------------------------------------------------
22 // classes
23 // ---------------------------------------------------------
24
25 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
26 class WXDLLIMPEXP_FWD_ADV wxDataViewMainWindow;
27 class WXDLLIMPEXP_FWD_ADV wxDataViewHeaderWindow;
28
29 // ---------------------------------------------------------
30 // wxDataViewRenderer
31 // ---------------------------------------------------------
32
33 class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase
34 {
35 public:
36 wxDataViewRenderer( const wxString &varianttype,
37 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
38 int align = wxDVR_DEFAULT_ALIGNMENT );
39 virtual ~wxDataViewRenderer();
40
41 virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0;
42 virtual wxSize GetSize() const = 0;
43
44 virtual void SetAlignment( int align )
45 { m_align=align; }
46 virtual int GetAlignment() const
47 { return m_align; }
48
49 virtual void SetMode( wxDataViewCellMode mode )
50 { m_mode=mode; }
51 virtual wxDataViewCellMode GetMode() const
52 { return m_mode; }
53
54 virtual bool Activate( wxRect WXUNUSED(cell),
55 wxDataViewModel *WXUNUSED(model),
56 const wxDataViewItem & WXUNUSED(item),
57 unsigned int WXUNUSED(col) )
58 { return false; }
59
60 virtual bool LeftClick( wxPoint WXUNUSED(cursor),
61 wxRect WXUNUSED(cell),
62 wxDataViewModel *WXUNUSED(model),
63 const wxDataViewItem & WXUNUSED(item),
64 unsigned int WXUNUSED(col) )
65 { return false; }
66 virtual bool RightClick( wxPoint WXUNUSED(cursor),
67 wxRect WXUNUSED(cell),
68 wxDataViewModel *WXUNUSED(model),
69 const wxDataViewItem & WXUNUSED(item),
70 unsigned int WXUNUSED(col) )
71 { return false; }
72 virtual bool StartDrag( wxPoint WXUNUSED(cursor),
73 wxRect WXUNUSED(cell),
74 wxDataViewModel *WXUNUSED(model),
75 const wxDataViewItem & WXUNUSED(item),
76 unsigned int WXUNUSED(col) )
77 { return false; }
78
79 // Create DC on request
80 virtual wxDC *GetDC();
81
82 private:
83 wxDC *m_dc;
84 int m_align;
85 wxDataViewCellMode m_mode;
86
87 protected:
88 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
89 };
90
91 // ---------------------------------------------------------
92 // wxDataViewCustomRenderer
93 // ---------------------------------------------------------
94
95 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
96 {
97 public:
98 wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"),
99 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
100 int align = wxDVR_DEFAULT_ALIGNMENT );
101
102 void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state );
103
104 protected:
105 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
106 };
107
108
109 // ---------------------------------------------------------
110 // wxDataViewTextRenderer
111 // ---------------------------------------------------------
112
113 class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewCustomRenderer
114 {
115 public:
116 wxDataViewTextRenderer( const wxString &varianttype = wxT("string"),
117 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
118 int align = wxDVR_DEFAULT_ALIGNMENT );
119
120 bool SetValue( const wxVariant &value );
121 bool GetValue( wxVariant &value ) const;
122
123 bool Render( wxRect cell, wxDC *dc, int state );
124 wxSize GetSize() const;
125
126 // in-place editing
127 virtual bool HasEditorCtrl();
128 virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
129 virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
130
131 private:
132 wxString m_text;
133
134 protected:
135 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
136 };
137
138 // ---------------------------------------------------------
139 // wxDataViewBitmapRenderer
140 // ---------------------------------------------------------
141
142 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewCustomRenderer
143 {
144 public:
145 wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"),
146 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
147 int align = wxDVR_DEFAULT_ALIGNMENT );
148
149 bool SetValue( const wxVariant &value );
150 bool GetValue( wxVariant &value ) const;
151
152 bool Render( wxRect cell, wxDC *dc, int state );
153 wxSize GetSize() const;
154
155 private:
156 wxIcon m_icon;
157 wxBitmap m_bitmap;
158
159 protected:
160 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
161 };
162
163 // ---------------------------------------------------------
164 // wxDataViewToggleRenderer
165 // ---------------------------------------------------------
166
167 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewCustomRenderer
168 {
169 public:
170 wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"),
171 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
172 int align = wxDVR_DEFAULT_ALIGNMENT );
173
174 bool SetValue( const wxVariant &value );
175 bool GetValue( wxVariant &value ) const;
176
177 bool Render( wxRect cell, wxDC *dc, int state );
178 bool Activate( wxRect cell, wxDataViewModel *model, const wxDataViewItem & item,
179 unsigned int col );
180 wxSize GetSize() const;
181
182 private:
183 bool m_toggle;
184
185 protected:
186 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
187 };
188
189 // ---------------------------------------------------------
190 // wxDataViewProgressRenderer
191 // ---------------------------------------------------------
192
193 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
194 {
195 public:
196 wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
197 const wxString &varianttype = wxT("long"),
198 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
199 int align = wxDVR_DEFAULT_ALIGNMENT );
200 virtual ~wxDataViewProgressRenderer();
201
202 bool SetValue( const wxVariant &value );
203 bool GetValue( wxVariant& value ) const;
204
205 virtual bool Render( wxRect cell, wxDC *dc, int state );
206 virtual wxSize GetSize() const;
207
208 private:
209 wxString m_label;
210 int m_value;
211
212 protected:
213 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
214 };
215
216 // ---------------------------------------------------------
217 // wxDataViewIconTextRenderer
218 // ---------------------------------------------------------
219
220 class wxDataViewIconTextRenderer: public wxDataViewCustomRenderer
221 {
222 public:
223 wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"),
224 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
225 int align = wxDVR_DEFAULT_ALIGNMENT );
226 virtual ~wxDataViewIconTextRenderer();
227
228 bool SetValue( const wxVariant &value );
229 bool GetValue( wxVariant &value ) const;
230
231 virtual bool Render( wxRect cell, wxDC *dc, int state );
232 virtual wxSize GetSize() const;
233
234 virtual bool HasEditorCtrl() { return true; }
235 virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
236 virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
237
238 private:
239 wxDataViewIconText m_value;
240
241 protected:
242 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
243 };
244
245 // ---------------------------------------------------------
246 // wxDataViewDateRenderer
247 // ---------------------------------------------------------
248
249 class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
250 {
251 public:
252 wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
253 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
254 int align = wxDVR_DEFAULT_ALIGNMENT );
255
256 bool SetValue( const wxVariant &value );
257 bool GetValue( wxVariant& value ) const;
258
259 virtual bool Render( wxRect cell, wxDC *dc, int state );
260 virtual wxSize GetSize() const;
261 virtual bool Activate( wxRect cell,
262 wxDataViewModel *model, const wxDataViewItem & item, unsigned int col );
263
264 private:
265 wxDateTime m_date;
266
267 protected:
268 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
269 };
270
271 // ---------------------------------------------------------
272 // wxDataViewColumn
273 // ---------------------------------------------------------
274
275 class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
276 {
277 friend class wxDataViewHeaderWindowBase;
278 friend class wxDataViewHeaderWindow;
279 friend class wxDataViewHeaderWindowMSW;
280
281 public:
282 wxDataViewColumn( const wxString &title, wxDataViewRenderer *renderer,
283 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
284 wxAlignment align = wxALIGN_CENTER,
285 int flags = wxDATAVIEW_COL_RESIZABLE );
286 wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
287 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
288 wxAlignment align = wxALIGN_CENTER,
289 int flags = wxDATAVIEW_COL_RESIZABLE );
290 virtual ~wxDataViewColumn();
291
292 // setters:
293
294 virtual void SetTitle( const wxString &title )
295 { m_title=title; }
296 virtual void SetAlignment( wxAlignment align )
297 { m_align=align; }
298 virtual void SetMinWidth( int minWidth )
299 { m_minWidth=minWidth; }
300 virtual void SetWidth( int width );
301 virtual void SetSortable( bool sortable );
302 virtual void SetResizeable( bool resizeable );
303 virtual void SetHidden( bool hidden );
304 virtual void SetSortOrder( bool ascending );
305
306
307 // getters:
308
309 virtual wxString GetTitle() const
310 { return m_title; }
311 virtual wxAlignment GetAlignment() const
312 { return m_align; }
313 virtual int GetWidth() const
314 { return m_width; }
315 virtual int GetMinWidth() const
316 { return m_minWidth; }
317 virtual bool IsSortable() const
318 { return (m_flags & wxDATAVIEW_COL_SORTABLE) != 0; }
319 virtual bool IsResizeable() const
320 { return (m_flags & wxDATAVIEW_COL_RESIZABLE) != 0; }
321 virtual bool IsHidden() const
322 { return (m_flags & wxDATAVIEW_COL_HIDDEN) != 0; }
323 virtual bool IsSortOrderAscending() const;
324
325
326 private:
327 int m_width;
328 int m_minWidth;
329 int m_flags;
330 wxAlignment m_align;
331 wxString m_title;
332 bool m_ascending;
333
334 void Init(int width);
335
336 // like SetWidth() but does not ask the header window of the
337 // wxDataViewCtrl to reflect the width-change.
338 void SetInternalWidth(int width);
339
340 protected:
341 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
342 };
343
344 // ---------------------------------------------------------
345 // wxDataViewCtrl
346 // ---------------------------------------------------------
347
348 WX_DECLARE_LIST(wxDataViewColumn, wxDataViewColumnList );
349
350 class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase,
351 public wxScrollHelperNative
352 {
353 friend class wxDataViewMainWindow;
354 friend class wxDataViewHeaderWindowBase;
355 friend class wxDataViewHeaderWindow;
356 friend class wxDataViewHeaderWindowMSW;
357 friend class wxDataViewColumn;
358
359 public:
360 wxDataViewCtrl() : wxScrollHelperNative(this)
361 {
362 //No sorting column at start, I think
363 m_sortingColumn = NULL;
364 Init();
365 }
366
367 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
368 const wxPoint& pos = wxDefaultPosition,
369 const wxSize& size = wxDefaultSize, long style = 0,
370 const wxValidator& validator = wxDefaultValidator )
371 : wxScrollHelperNative(this)
372 {
373 m_sortingColumn = NULL;
374 Create(parent, id, pos, size, style, validator );
375 }
376
377 virtual ~wxDataViewCtrl();
378
379 void Init();
380
381 bool Create(wxWindow *parent, wxWindowID id,
382 const wxPoint& pos = wxDefaultPosition,
383 const wxSize& size = wxDefaultSize, long style = 0,
384 const wxValidator& validator = wxDefaultValidator );
385
386 virtual bool AssociateModel( wxDataViewModel *model );
387 virtual bool AppendColumn( wxDataViewColumn *col );
388 virtual bool PrependColumn( wxDataViewColumn *col );
389
390 virtual void DoSetExpanderColumn();
391 virtual void DoSetIndent();
392
393 virtual unsigned int GetColumnCount() const;
394 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const;
395 virtual bool DeleteColumn( wxDataViewColumn *column );
396 virtual bool ClearColumns();
397 virtual int GetColumnPosition( const wxDataViewColumn *column ) const;
398
399 virtual wxDataViewColumn *GetSortingColumn() const;
400
401 virtual wxDataViewItem GetSelection() const;
402 virtual int GetSelections( wxDataViewItemArray & sel ) const;
403 virtual void SetSelections( const wxDataViewItemArray & sel );
404 virtual void Select( const wxDataViewItem & item );
405 virtual void Unselect( const wxDataViewItem & item );
406 virtual bool IsSelected( const wxDataViewItem & item ) const;
407
408 virtual void SelectAll();
409 virtual void UnselectAll();
410
411 virtual void EnsureVisible( const wxDataViewItem & item,
412 const wxDataViewColumn *column = NULL );
413 virtual void HitTest( const wxPoint & point, wxDataViewItem & item, wxDataViewColumn* &column ) const;
414 virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const;
415
416 virtual void Expand( const wxDataViewItem & item );
417 virtual void Collapse( const wxDataViewItem & item );
418
419 protected:
420 virtual int GetSelections( wxArrayInt & sel ) const;
421 virtual void SetSelections( const wxArrayInt & sel );
422 virtual void Select( int row );
423 virtual void Unselect( int row );
424 virtual bool IsSelected( int row ) const;
425 virtual void SelectRange( int from, int to );
426 virtual void UnselectRange( int from, int to );
427
428 virtual void EnsureVisible( int row, int column );
429
430 virtual wxDataViewItem GetItemByRow( unsigned int row ) const;
431 virtual int GetRowByItem( const wxDataViewItem & item ) const;
432
433 wxDataViewColumn* GetSortingColumn() { return m_sortingColumn; }
434 void SetSortingColumn( wxDataViewColumn* column ) { m_sortingColumn = column; }
435
436 public: // utility functions not part of the API
437
438 // returns the "best" width for the idx-th column
439 unsigned int GetBestColumnWidth(int WXUNUSED(idx)) const
440 {
441 return GetClientSize().GetWidth() / GetColumnCount();
442 }
443
444 // updates the header window after a change in a column setting
445 void OnColumnChange();
446
447 wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; }
448
449 private:
450 wxDataViewColumnList m_cols;
451 wxDataViewModelNotifier *m_notifier;
452 wxDataViewMainWindow *m_clientArea;
453 wxDataViewHeaderWindow *m_headerArea;
454 wxDataViewColumn* m_sortingColumn;
455
456 private:
457 void OnSize( wxSizeEvent &event );
458
459 // we need to return a special WM_GETDLGCODE value to process just the
460 // arrows but let the other navigation characters through
461 #ifdef __WXMSW__
462 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
463 #endif // __WXMSW__
464
465 WX_FORWARD_TO_SCROLL_HELPER()
466
467 private:
468 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
469 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
470 DECLARE_EVENT_TABLE()
471 };
472
473
474 #endif // __GENERICDATAVIEWCTRLH__