1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/dataview.h
3 // Purpose: wxDataViewCtrl generic implementation header
4 // Author: Robert Roebling
5 // Modified By: Bo Yang
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef __GENERICDATAVIEWCTRLH__
12 #define __GENERICDATAVIEWCTRLH__
15 #include "wx/object.h"
17 #include "wx/control.h"
18 #include "wx/scrolwin.h"
21 // ---------------------------------------------------------
23 // ---------------------------------------------------------
25 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl
;
26 class WXDLLIMPEXP_FWD_ADV wxDataViewMainWindow
;
27 class WXDLLIMPEXP_FWD_ADV wxDataViewHeaderWindow
;
29 // ---------------------------------------------------------
31 // ---------------------------------------------------------
33 class WXDLLIMPEXP_ADV wxDataViewRenderer
: public wxDataViewRendererBase
36 wxDataViewRenderer( const wxString
&varianttype
,
37 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
38 int align
= wxDVR_DEFAULT_ALIGNMENT
);
39 virtual ~wxDataViewRenderer();
41 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
) = 0;
42 virtual wxSize
GetSize() const = 0;
44 virtual void SetAlignment( int align
)
46 virtual int GetAlignment() const
49 virtual void SetMode( wxDataViewCellMode mode
)
51 virtual wxDataViewCellMode
GetMode() const
54 virtual bool Activate( wxRect
WXUNUSED(cell
),
55 wxDataViewModel
*WXUNUSED(model
),
56 const wxDataViewItem
& WXUNUSED(item
),
57 unsigned int WXUNUSED(col
) )
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
) )
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
) )
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
) )
79 // Create DC on request
80 virtual wxDC
*GetDC();
85 wxDataViewCellMode m_mode
;
88 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer
)
91 // ---------------------------------------------------------
92 // wxDataViewCustomRenderer
93 // ---------------------------------------------------------
95 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewRenderer
98 wxDataViewCustomRenderer( const wxString
&varianttype
= wxT("string"),
99 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
100 int align
= wxDVR_DEFAULT_ALIGNMENT
);
103 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
107 // ---------------------------------------------------------
108 // wxDataViewTextRenderer
109 // ---------------------------------------------------------
111 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewCustomRenderer
114 wxDataViewTextRenderer( const wxString
&varianttype
= wxT("string"),
115 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
116 int align
= wxDVR_DEFAULT_ALIGNMENT
);
118 bool SetValue( const wxVariant
&value
);
119 bool GetValue( wxVariant
&value
) const;
121 bool Render( wxRect cell
, wxDC
*dc
, int state
);
122 wxSize
GetSize() const;
125 virtual bool HasEditorCtrl();
126 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
127 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
133 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
136 // ---------------------------------------------------------
137 // wxDataViewBitmapRenderer
138 // ---------------------------------------------------------
140 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewCustomRenderer
143 wxDataViewBitmapRenderer( const wxString
&varianttype
= wxT("wxBitmap"),
144 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
145 int align
= wxDVR_DEFAULT_ALIGNMENT
);
147 bool SetValue( const wxVariant
&value
);
148 bool GetValue( wxVariant
&value
) const;
150 bool Render( wxRect cell
, wxDC
*dc
, int state
);
151 wxSize
GetSize() const;
158 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
161 // ---------------------------------------------------------
162 // wxDataViewToggleRenderer
163 // ---------------------------------------------------------
165 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewCustomRenderer
168 wxDataViewToggleRenderer( const wxString
&varianttype
= wxT("bool"),
169 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
170 int align
= wxDVR_DEFAULT_ALIGNMENT
);
172 bool SetValue( const wxVariant
&value
);
173 bool GetValue( wxVariant
&value
) const;
175 bool Render( wxRect cell
, wxDC
*dc
, int state
);
176 bool Activate( wxRect cell
, wxDataViewModel
*model
, const wxDataViewItem
& item
,
178 wxSize
GetSize() const;
184 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
187 // ---------------------------------------------------------
188 // wxDataViewProgressRenderer
189 // ---------------------------------------------------------
191 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
194 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
195 const wxString
&varianttype
= wxT("long"),
196 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
197 int align
= wxDVR_DEFAULT_ALIGNMENT
);
198 virtual ~wxDataViewProgressRenderer();
200 bool SetValue( const wxVariant
&value
);
201 bool GetValue( wxVariant
& value
) const;
203 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
204 virtual wxSize
GetSize() const;
211 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
214 // ---------------------------------------------------------
215 // wxDataViewIconTextRenderer
216 // ---------------------------------------------------------
218 class wxDataViewIconTextRenderer
: public wxDataViewCustomRenderer
221 wxDataViewIconTextRenderer( const wxString
&varianttype
= wxT("wxDataViewIconText"),
222 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
223 int align
= wxDVR_DEFAULT_ALIGNMENT
);
224 virtual ~wxDataViewIconTextRenderer();
226 bool SetValue( const wxVariant
&value
);
227 bool GetValue( wxVariant
&value
) const;
229 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
230 virtual wxSize
GetSize() const;
232 virtual bool HasEditorCtrl() { return true; }
233 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
234 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
237 wxDataViewIconText m_value
;
240 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
243 // ---------------------------------------------------------
244 // wxDataViewDateRenderer
245 // ---------------------------------------------------------
247 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewCustomRenderer
250 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
251 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
252 int align
= wxDVR_DEFAULT_ALIGNMENT
);
254 bool SetValue( const wxVariant
&value
);
255 bool GetValue( wxVariant
& value
) const;
257 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
258 virtual wxSize
GetSize() const;
259 virtual bool Activate( wxRect cell
,
260 wxDataViewModel
*model
, const wxDataViewItem
& item
, unsigned int col
);
266 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
269 // ---------------------------------------------------------
271 // ---------------------------------------------------------
273 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
275 friend class wxDataViewHeaderWindowBase
;
276 friend class wxDataViewHeaderWindow
;
277 friend class wxDataViewHeaderWindowMSW
;
280 wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*renderer
,
281 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
282 wxAlignment align
= wxALIGN_CENTER
,
283 int flags
= wxDATAVIEW_COL_RESIZABLE
);
284 wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
285 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
286 wxAlignment align
= wxALIGN_CENTER
,
287 int flags
= wxDATAVIEW_COL_RESIZABLE
);
288 virtual ~wxDataViewColumn();
292 virtual void SetTitle( const wxString
&title
)
294 virtual void SetAlignment( wxAlignment align
)
296 virtual void SetMinWidth( int minWidth
)
297 { m_minWidth
=minWidth
; }
298 virtual void SetWidth( int width
);
299 virtual void SetSortable( bool sortable
);
300 virtual void SetResizeable( bool resizeable
);
301 virtual void SetHidden( bool hidden
);
302 virtual void SetSortOrder( bool ascending
);
307 virtual wxString
GetTitle() const
309 virtual wxAlignment
GetAlignment() const
311 virtual int GetWidth() const
313 virtual int GetMinWidth() const
314 { return m_minWidth
; }
315 virtual bool IsSortable() const
316 { return (m_flags
& wxDATAVIEW_COL_SORTABLE
) != 0; }
317 virtual bool IsResizeable() const
318 { return (m_flags
& wxDATAVIEW_COL_RESIZABLE
) != 0; }
319 virtual bool IsHidden() const
320 { return (m_flags
& wxDATAVIEW_COL_HIDDEN
) != 0; }
321 virtual bool IsSortOrderAscending() const;
332 void Init(int width
);
334 // like SetWidth() but does not ask the header window of the
335 // wxDataViewCtrl to reflect the width-change.
336 void SetInternalWidth(int width
);
339 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
342 // ---------------------------------------------------------
344 // ---------------------------------------------------------
346 WX_DECLARE_LIST(wxDataViewColumn
, wxDataViewColumnList
);
348 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
,
349 public wxScrollHelperNative
351 friend class wxDataViewMainWindow
;
352 friend class wxDataViewHeaderWindowBase
;
353 friend class wxDataViewHeaderWindow
;
354 friend class wxDataViewHeaderWindowMSW
;
355 friend class wxDataViewColumn
;
358 wxDataViewCtrl() : wxScrollHelperNative(this)
360 //No sorting column at start, I think
361 m_sortingColumn
= NULL
;
365 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
366 const wxPoint
& pos
= wxDefaultPosition
,
367 const wxSize
& size
= wxDefaultSize
, long style
= 0,
368 const wxValidator
& validator
= wxDefaultValidator
)
369 : wxScrollHelperNative(this)
371 m_sortingColumn
= NULL
;
372 Create(parent
, id
, pos
, size
, style
, validator
);
375 virtual ~wxDataViewCtrl();
379 bool Create(wxWindow
*parent
, wxWindowID id
,
380 const wxPoint
& pos
= wxDefaultPosition
,
381 const wxSize
& size
= wxDefaultSize
, long style
= 0,
382 const wxValidator
& validator
= wxDefaultValidator
);
384 virtual bool AssociateModel( wxDataViewModel
*model
);
385 virtual bool AppendColumn( wxDataViewColumn
*col
);
387 virtual void DoSetExpanderColumn();
388 virtual void DoSetIndent();
390 virtual unsigned int GetColumnCount() const;
391 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const;
392 virtual bool DeleteColumn( wxDataViewColumn
*column
);
393 virtual bool ClearColumns();
394 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const;
396 virtual wxDataViewColumn
*GetSortingColumn() const;
398 virtual wxDataViewItem
GetSelection() const;
399 virtual int GetSelections( wxDataViewItemArray
& sel
) const;
400 virtual void SetSelections( const wxDataViewItemArray
& sel
);
401 virtual void Select( const wxDataViewItem
& item
);
402 virtual void Unselect( const wxDataViewItem
& item
);
403 virtual bool IsSelected( const wxDataViewItem
& item
) const;
405 virtual void SelectAll();
406 virtual void UnselectAll();
408 virtual void EnsureVisible( const wxDataViewItem
& item
,
409 const wxDataViewColumn
*column
= NULL
);
410 virtual void HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
) const;
411 virtual wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
*column
= NULL
) const;
413 virtual void Expand( const wxDataViewItem
& item
);
414 virtual void Collapse( const wxDataViewItem
& item
);
417 virtual int GetSelections( wxArrayInt
& sel
) const;
418 virtual void SetSelections( const wxArrayInt
& sel
);
419 virtual void Select( int row
);
420 virtual void Unselect( int row
);
421 virtual bool IsSelected( int row
) const;
422 virtual void SelectRange( int from
, int to
);
423 virtual void UnselectRange( int from
, int to
);
425 virtual void EnsureVisible( int row
, int column
);
427 virtual wxDataViewItem
GetItemByRow( unsigned int row
) const;
428 virtual int GetRowByItem( const wxDataViewItem
& item
) const;
430 wxDataViewColumn
* GetSortingColumn() { return m_sortingColumn
; }
431 void SetSortingColumn( wxDataViewColumn
* column
) { m_sortingColumn
= column
; }
433 public: // utility functions not part of the API
435 // returns the "best" width for the idx-th column
436 unsigned int GetBestColumnWidth(int WXUNUSED(idx
)) const
438 return GetClientSize().GetWidth() / GetColumnCount();
441 // updates the header window after a change in a column setting
442 void OnColumnChange();
444 wxWindow
*GetMainWindow() { return (wxWindow
*) m_clientArea
; }
447 wxDataViewColumnList m_cols
;
448 wxDataViewModelNotifier
*m_notifier
;
449 wxDataViewMainWindow
*m_clientArea
;
450 wxDataViewHeaderWindow
*m_headerArea
;
451 wxDataViewColumn
* m_sortingColumn
;
454 void OnSize( wxSizeEvent
&event
);
456 // we need to return a special WM_GETDLGCODE value to process just the
457 // arrows but let the other navigation characters through
459 virtual WXLRESULT
MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
462 WX_FORWARD_TO_SCROLL_HELPER()
465 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
466 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
467 DECLARE_EVENT_TABLE()
471 #endif // __GENERICDATAVIEWCTRLH__