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
);
102 void RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
);
105 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
109 // ---------------------------------------------------------
110 // wxDataViewTextRenderer
111 // ---------------------------------------------------------
113 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewCustomRenderer
116 wxDataViewTextRenderer( const wxString
&varianttype
= wxT("string"),
117 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
118 int align
= wxDVR_DEFAULT_ALIGNMENT
);
120 bool SetValue( const wxVariant
&value
);
121 bool GetValue( wxVariant
&value
) const;
123 bool Render( wxRect cell
, wxDC
*dc
, int state
);
124 wxSize
GetSize() const;
127 virtual bool HasEditorCtrl();
128 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
129 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
135 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
138 // ---------------------------------------------------------
139 // wxDataViewBitmapRenderer
140 // ---------------------------------------------------------
142 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewCustomRenderer
145 wxDataViewBitmapRenderer( const wxString
&varianttype
= wxT("wxBitmap"),
146 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
147 int align
= wxDVR_DEFAULT_ALIGNMENT
);
149 bool SetValue( const wxVariant
&value
);
150 bool GetValue( wxVariant
&value
) const;
152 bool Render( wxRect cell
, wxDC
*dc
, int state
);
153 wxSize
GetSize() const;
160 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
163 // ---------------------------------------------------------
164 // wxDataViewToggleRenderer
165 // ---------------------------------------------------------
167 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewCustomRenderer
170 wxDataViewToggleRenderer( const wxString
&varianttype
= wxT("bool"),
171 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
172 int align
= wxDVR_DEFAULT_ALIGNMENT
);
174 bool SetValue( const wxVariant
&value
);
175 bool GetValue( wxVariant
&value
) const;
177 bool Render( wxRect cell
, wxDC
*dc
, int state
);
178 bool Activate( wxRect cell
, wxDataViewModel
*model
, const wxDataViewItem
& item
,
180 wxSize
GetSize() const;
186 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
189 // ---------------------------------------------------------
190 // wxDataViewProgressRenderer
191 // ---------------------------------------------------------
193 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
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();
202 bool SetValue( const wxVariant
&value
);
203 bool GetValue( wxVariant
& value
) const;
205 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
206 virtual wxSize
GetSize() const;
213 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
216 // ---------------------------------------------------------
217 // wxDataViewIconTextRenderer
218 // ---------------------------------------------------------
220 class wxDataViewIconTextRenderer
: public wxDataViewCustomRenderer
223 wxDataViewIconTextRenderer( const wxString
&varianttype
= wxT("wxDataViewIconText"),
224 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
225 int align
= wxDVR_DEFAULT_ALIGNMENT
);
226 virtual ~wxDataViewIconTextRenderer();
228 bool SetValue( const wxVariant
&value
);
229 bool GetValue( wxVariant
&value
) const;
231 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
232 virtual wxSize
GetSize() const;
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
);
239 wxDataViewIconText m_value
;
242 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
245 // ---------------------------------------------------------
246 // wxDataViewDateRenderer
247 // ---------------------------------------------------------
249 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewCustomRenderer
252 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
253 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
254 int align
= wxDVR_DEFAULT_ALIGNMENT
);
256 bool SetValue( const wxVariant
&value
);
257 bool GetValue( wxVariant
& value
) const;
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
);
268 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
271 // ---------------------------------------------------------
273 // ---------------------------------------------------------
275 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
277 friend class wxDataViewHeaderWindowBase
;
278 friend class wxDataViewHeaderWindow
;
279 friend class wxDataViewHeaderWindowMSW
;
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();
294 virtual void SetTitle( const wxString
&title
)
296 virtual void SetAlignment( wxAlignment 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
);
309 virtual wxString
GetTitle() const
311 virtual wxAlignment
GetAlignment() const
313 virtual int GetWidth() const
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;
334 void Init(int width
);
336 // like SetWidth() but does not ask the header window of the
337 // wxDataViewCtrl to reflect the width-change.
338 void SetInternalWidth(int width
);
341 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
344 // ---------------------------------------------------------
346 // ---------------------------------------------------------
348 WX_DECLARE_LIST(wxDataViewColumn
, wxDataViewColumnList
);
350 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
,
351 public wxScrollHelperNative
353 friend class wxDataViewMainWindow
;
354 friend class wxDataViewHeaderWindowBase
;
355 friend class wxDataViewHeaderWindow
;
356 friend class wxDataViewHeaderWindowMSW
;
357 friend class wxDataViewColumn
;
360 wxDataViewCtrl() : wxScrollHelperNative(this)
362 //No sorting column at start, I think
363 m_sortingColumn
= NULL
;
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)
373 m_sortingColumn
= NULL
;
374 Create(parent
, id
, pos
, size
, style
, validator
);
377 virtual ~wxDataViewCtrl();
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
);
386 virtual bool AssociateModel( wxDataViewModel
*model
);
387 virtual bool AppendColumn( wxDataViewColumn
*col
);
388 virtual bool PrependColumn( wxDataViewColumn
*col
);
390 virtual void DoSetExpanderColumn();
391 virtual void DoSetIndent();
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;
399 virtual wxDataViewColumn
*GetSortingColumn() const;
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;
408 virtual void SelectAll();
409 virtual void UnselectAll();
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;
416 virtual void Expand( const wxDataViewItem
& item
);
417 virtual void Collapse( const wxDataViewItem
& item
);
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
);
428 virtual void EnsureVisible( int row
, int column
);
430 virtual wxDataViewItem
GetItemByRow( unsigned int row
) const;
431 virtual int GetRowByItem( const wxDataViewItem
& item
) const;
433 wxDataViewColumn
* GetSortingColumn() { return m_sortingColumn
; }
434 void SetSortingColumn( wxDataViewColumn
* column
) { m_sortingColumn
= column
; }
436 public: // utility functions not part of the API
438 // returns the "best" width for the idx-th column
439 unsigned int GetBestColumnWidth(int WXUNUSED(idx
)) const
441 return GetClientSize().GetWidth() / GetColumnCount();
444 // updates the header window after a change in a column setting
445 void OnColumnChange();
447 wxWindow
*GetMainWindow() { return (wxWindow
*) m_clientArea
; }
450 wxDataViewColumnList m_cols
;
451 wxDataViewModelNotifier
*m_notifier
;
452 wxDataViewMainWindow
*m_clientArea
;
453 wxDataViewHeaderWindow
*m_headerArea
;
454 wxDataViewColumn
* m_sortingColumn
;
457 void OnSize( wxSizeEvent
&event
);
459 // we need to return a special WM_GETDLGCODE value to process just the
460 // arrows but let the other navigation characters through
462 virtual WXLRESULT
MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
465 WX_FORWARD_TO_SCROLL_HELPER()
468 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
469 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
470 DECLARE_EVENT_TABLE()
474 #endif // __GENERICDATAVIEWCTRLH__