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 // wxDataViewDateRenderer
216 // ---------------------------------------------------------
218 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewCustomRenderer
221 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
222 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
223 int align
= wxDVR_DEFAULT_ALIGNMENT
);
225 bool SetValue( const wxVariant
&value
);
226 bool GetValue( wxVariant
& value
) const;
228 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
229 virtual wxSize
GetSize() const;
230 virtual bool Activate( wxRect cell
,
231 wxDataViewModel
*model
, const wxDataViewItem
& item
, unsigned int col
);
237 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
240 // ---------------------------------------------------------
242 // ---------------------------------------------------------
244 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
246 friend class wxDataViewHeaderWindowBase
;
247 friend class wxDataViewHeaderWindow
;
248 friend class wxDataViewHeaderWindowMSW
;
251 wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*renderer
,
252 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
253 wxAlignment align
= wxALIGN_CENTER
,
254 int flags
= wxDATAVIEW_COL_RESIZABLE
);
255 wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
256 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
257 wxAlignment align
= wxALIGN_CENTER
,
258 int flags
= wxDATAVIEW_COL_RESIZABLE
);
259 virtual ~wxDataViewColumn();
263 virtual void SetTitle( const wxString
&title
)
265 virtual void SetAlignment( wxAlignment align
)
267 virtual void SetMinWidth( int minWidth
)
268 { m_minWidth
=minWidth
; }
269 virtual void SetWidth( int width
);
270 virtual void SetSortable( bool sortable
);
271 virtual void SetResizeable( bool resizeable
);
272 virtual void SetHidden( bool hidden
);
273 virtual void SetSortOrder( bool ascending
);
278 virtual wxString
GetTitle() const
280 virtual wxAlignment
GetAlignment() const
282 virtual int GetWidth() const
284 virtual int GetMinWidth() const
285 { return m_minWidth
; }
286 virtual bool IsSortable() const
287 { return (m_flags
& wxDATAVIEW_COL_SORTABLE
) != 0; }
288 virtual bool IsResizeable() const
289 { return (m_flags
& wxDATAVIEW_COL_RESIZABLE
) != 0; }
290 virtual bool IsHidden() const
291 { return (m_flags
& wxDATAVIEW_COL_HIDDEN
) != 0; }
292 virtual bool IsSortOrderAscending() const;
303 void Init(int width
);
305 // like SetWidth() but does not ask the header window of the
306 // wxDataViewCtrl to reflect the width-change.
307 void SetInternalWidth(int width
);
310 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
313 // ---------------------------------------------------------
315 // ---------------------------------------------------------
317 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
,
318 public wxScrollHelperNative
320 friend class wxDataViewMainWindow
;
321 friend class wxDataViewHeaderWindowBase
;
322 friend class wxDataViewHeaderWindow
;
323 friend class wxDataViewHeaderWindowMSW
;
324 friend class wxDataViewColumn
;
327 wxDataViewCtrl() : wxScrollHelperNative(this)
333 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
334 const wxPoint
& pos
= wxDefaultPosition
,
335 const wxSize
& size
= wxDefaultSize
, long style
= 0,
336 const wxValidator
& validator
= wxDefaultValidator
)
337 : wxScrollHelperNative(this)
339 Create(parent
, id
, pos
, size
, style
, validator
);
342 virtual ~wxDataViewCtrl();
346 bool Create(wxWindow
*parent
, wxWindowID id
,
347 const wxPoint
& pos
= wxDefaultPosition
,
348 const wxSize
& size
= wxDefaultSize
, long style
= 0,
349 const wxValidator
& validator
= wxDefaultValidator
);
351 virtual bool AssociateModel( wxDataViewModel
*model
);
352 virtual bool AppendColumn( wxDataViewColumn
*col
);
354 virtual void DoSetExpanderColumn();
355 virtual void DoSetIndent();
357 virtual wxDataViewItem
GetSelection();
358 virtual int GetSelections( wxDataViewItemArray
& sel
) const;
359 virtual void SetSelections( const wxDataViewItemArray
& sel
);
360 virtual void Select( const wxDataViewItem
& item
);
361 virtual void Unselect( const wxDataViewItem
& item
);
362 virtual bool IsSelected( const wxDataViewItem
& item
) const;
364 virtual void SelectAll();
365 virtual void UnselectAll();
367 virtual void EnsureVisible( const wxDataViewItem
& item
,
368 wxDataViewColumn
*column
= NULL
);
369 virtual void HitTest( const wxPoint
& point
, wxDataViewItem
& item
, unsigned int & column
) const;
370 virtual wxRect
GetItemRect( const wxDataViewItem
& item
, unsigned int column
) const;
373 virtual int GetSelections( wxArrayInt
& sel
) const;
374 virtual void SetSelections( const wxArrayInt
& sel
);
375 virtual void Select( int row
);
376 virtual void Unselect( int row
);
377 virtual bool IsSelected( int row
) const;
378 virtual void SelectRange( int from
, int to
);
379 virtual void UnselectRange( int from
, int to
);
381 virtual void EnsureVisible( int row
);
383 virtual wxDataViewItem
GetItemByRow( unsigned int row
) const;
384 virtual int GetRowByItem( const wxDataViewItem
& item
) const;
386 unsigned int GetSortingColumn() { return m_sortingColumn
; }
387 void SetSortingColumn( unsigned int column
) { m_sortingColumn
= column
; }
389 public: // utility functions not part of the API
391 // returns the "best" width for the idx-th column
392 unsigned int GetBestColumnWidth(int WXUNUSED(idx
)) const
394 return GetClientSize().GetWidth() / GetColumnCount();
397 // updates the header window after a change in a column setting
398 void OnColumnChange();
400 wxWindow
*GetMainWindow() { return (wxWindow
*) m_clientArea
; }
403 wxDataViewModelNotifier
*m_notifier
;
404 wxDataViewMainWindow
*m_clientArea
;
405 wxDataViewHeaderWindow
*m_headerArea
;
406 unsigned int m_sortingColumn
;
409 void OnSize( wxSizeEvent
&event
);
411 // we need to return a special WM_GETDLGCODE value to process just the
412 // arrows but let the other navigation characters through
414 virtual WXLRESULT
MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
417 WX_FORWARD_TO_SCROLL_HELPER()
420 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
421 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
422 DECLARE_EVENT_TABLE()
426 #endif // __GENERICDATAVIEWCTRLH__