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();
82 void SetHasAttr( bool set
) { m_hasAttr
= set
; }
83 void SetAttr( const wxDataViewItemAttr
&attr
) { m_attr
= attr
; }
84 bool GetWantsAttr() { return m_wantsAttr
; }
89 wxDataViewCellMode m_mode
;
94 wxDataViewItemAttr m_attr
;
97 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer
)
100 // ---------------------------------------------------------
101 // wxDataViewCustomRenderer
102 // ---------------------------------------------------------
104 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewRenderer
107 wxDataViewCustomRenderer( const wxString
&varianttype
= wxT("string"),
108 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
109 int align
= wxDVR_DEFAULT_ALIGNMENT
);
111 void RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
);
114 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
118 // ---------------------------------------------------------
119 // wxDataViewTextRenderer
120 // ---------------------------------------------------------
122 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewCustomRenderer
125 wxDataViewTextRenderer( const wxString
&varianttype
= wxT("string"),
126 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
127 int align
= wxDVR_DEFAULT_ALIGNMENT
);
129 bool SetValue( const wxVariant
&value
);
130 bool GetValue( wxVariant
&value
) const;
132 bool Render( wxRect cell
, wxDC
*dc
, int state
);
133 wxSize
GetSize() const;
136 virtual bool HasEditorCtrl();
137 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
138 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
144 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
147 // ---------------------------------------------------------
148 // wxDataViewTextRendererAttr
149 // ---------------------------------------------------------
151 class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr
: public wxDataViewTextRenderer
154 wxDataViewTextRendererAttr( const wxString
&varianttype
= wxT("string"),
155 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
156 int align
= wxDVR_DEFAULT_ALIGNMENT
);
158 bool Render( wxRect cell
, wxDC
*dc
, int state
);
161 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr
)
164 // ---------------------------------------------------------
165 // wxDataViewBitmapRenderer
166 // ---------------------------------------------------------
168 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewCustomRenderer
171 wxDataViewBitmapRenderer( const wxString
&varianttype
= wxT("wxBitmap"),
172 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
173 int align
= wxDVR_DEFAULT_ALIGNMENT
);
175 bool SetValue( const wxVariant
&value
);
176 bool GetValue( wxVariant
&value
) const;
178 bool Render( wxRect cell
, wxDC
*dc
, int state
);
179 wxSize
GetSize() const;
186 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
189 // ---------------------------------------------------------
190 // wxDataViewToggleRenderer
191 // ---------------------------------------------------------
193 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewCustomRenderer
196 wxDataViewToggleRenderer( const wxString
&varianttype
= wxT("bool"),
197 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
198 int align
= wxDVR_DEFAULT_ALIGNMENT
);
200 bool SetValue( const wxVariant
&value
);
201 bool GetValue( wxVariant
&value
) const;
203 bool Render( wxRect cell
, wxDC
*dc
, int state
);
204 bool Activate( wxRect cell
, wxDataViewModel
*model
, const wxDataViewItem
& item
,
206 wxSize
GetSize() const;
212 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
215 // ---------------------------------------------------------
216 // wxDataViewProgressRenderer
217 // ---------------------------------------------------------
219 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
222 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
223 const wxString
&varianttype
= wxT("long"),
224 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
225 int align
= wxDVR_DEFAULT_ALIGNMENT
);
226 virtual ~wxDataViewProgressRenderer();
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;
239 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
242 // ---------------------------------------------------------
243 // wxDataViewIconTextRenderer
244 // ---------------------------------------------------------
246 class wxDataViewIconTextRenderer
: public wxDataViewCustomRenderer
249 wxDataViewIconTextRenderer( const wxString
&varianttype
= wxT("wxDataViewIconText"),
250 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
251 int align
= wxDVR_DEFAULT_ALIGNMENT
);
252 virtual ~wxDataViewIconTextRenderer();
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;
260 virtual bool HasEditorCtrl() { return true; }
261 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
262 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
265 wxDataViewIconText m_value
;
268 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
271 // ---------------------------------------------------------
272 // wxDataViewDateRenderer
273 // ---------------------------------------------------------
275 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewCustomRenderer
278 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
279 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
280 int align
= wxDVR_DEFAULT_ALIGNMENT
);
282 bool SetValue( const wxVariant
&value
);
283 bool GetValue( wxVariant
& value
) const;
285 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
286 virtual wxSize
GetSize() const;
287 virtual bool Activate( wxRect cell
,
288 wxDataViewModel
*model
, const wxDataViewItem
& item
, unsigned int col
);
294 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
297 // ---------------------------------------------------------
299 // ---------------------------------------------------------
301 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
303 friend class wxDataViewHeaderWindowBase
;
304 friend class wxDataViewHeaderWindow
;
305 friend class wxDataViewHeaderWindowMSW
;
308 wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*renderer
,
309 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
310 wxAlignment align
= wxALIGN_CENTER
,
311 int flags
= wxDATAVIEW_COL_RESIZABLE
);
312 wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
313 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
314 wxAlignment align
= wxALIGN_CENTER
,
315 int flags
= wxDATAVIEW_COL_RESIZABLE
);
316 virtual ~wxDataViewColumn();
320 virtual void SetTitle( const wxString
&title
)
322 virtual void SetAlignment( wxAlignment align
)
324 virtual void SetMinWidth( int minWidth
)
325 { m_minWidth
=minWidth
; }
326 virtual void SetWidth( int width
);
327 virtual void SetSortable( bool sortable
);
328 virtual void SetResizeable( bool resizeable
);
329 virtual void SetHidden( bool hidden
);
330 virtual void SetSortOrder( bool ascending
);
331 virtual void SetReorderable( bool reorderable
);
335 virtual wxString
GetTitle() const
337 virtual wxAlignment
GetAlignment() const
339 virtual int GetWidth() const
341 virtual int GetMinWidth() const
342 { return m_minWidth
; }
343 virtual bool IsSortable() const
344 { return (m_flags
& wxDATAVIEW_COL_SORTABLE
) != 0; }
345 virtual bool IsResizeable() const
346 { return (m_flags
& wxDATAVIEW_COL_RESIZABLE
) != 0; }
347 virtual bool IsHidden() const
348 { return (m_flags
& wxDATAVIEW_COL_HIDDEN
) != 0; }
349 virtual bool IsSortOrderAscending() const;
350 virtual bool IsReorderable() const
351 { return (m_flags
& wxDATAVIEW_COL_REORDERABLE
) != 0; }
362 void Init(int width
);
364 // like SetWidth() but does not ask the header window of the
365 // wxDataViewCtrl to reflect the width-change.
366 void SetInternalWidth(int width
);
369 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
372 // ---------------------------------------------------------
374 // ---------------------------------------------------------
376 WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn
, wxDataViewColumnList
,
377 class WXDLLIMPEXP_ADV
);
379 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
,
380 public wxScrollHelperNative
382 friend class wxDataViewMainWindow
;
383 friend class wxDataViewHeaderWindowBase
;
384 friend class wxDataViewHeaderWindow
;
385 friend class wxDataViewHeaderWindowMSW
;
386 friend class wxDataViewColumn
;
389 wxDataViewCtrl() : wxScrollHelperNative(this)
391 //No sorting column at start, I think
392 m_sortingColumn
= NULL
;
396 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
397 const wxPoint
& pos
= wxDefaultPosition
,
398 const wxSize
& size
= wxDefaultSize
, long style
= 0,
399 const wxValidator
& validator
= wxDefaultValidator
)
400 : wxScrollHelperNative(this)
402 m_sortingColumn
= NULL
;
403 Create(parent
, id
, pos
, size
, style
, validator
);
406 virtual ~wxDataViewCtrl();
410 bool Create(wxWindow
*parent
, wxWindowID id
,
411 const wxPoint
& pos
= wxDefaultPosition
,
412 const wxSize
& size
= wxDefaultSize
, long style
= 0,
413 const wxValidator
& validator
= wxDefaultValidator
);
415 virtual bool AssociateModel( wxDataViewModel
*model
);
416 virtual bool AppendColumn( wxDataViewColumn
*col
);
417 virtual bool PrependColumn( wxDataViewColumn
*col
);
419 virtual void DoSetExpanderColumn();
420 virtual void DoSetIndent();
422 virtual unsigned int GetColumnCount() const;
423 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const;
424 virtual bool DeleteColumn( wxDataViewColumn
*column
);
425 virtual bool ClearColumns();
426 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const;
428 virtual wxDataViewColumn
*GetSortingColumn() const;
430 virtual wxDataViewItem
GetSelection() const;
431 virtual int GetSelections( wxDataViewItemArray
& sel
) const;
432 virtual void SetSelections( const wxDataViewItemArray
& sel
);
433 virtual void Select( const wxDataViewItem
& item
);
434 virtual void Unselect( const wxDataViewItem
& item
);
435 virtual bool IsSelected( const wxDataViewItem
& item
) const;
437 virtual void SelectAll();
438 virtual void UnselectAll();
440 virtual void EnsureVisible( const wxDataViewItem
& item
,
441 const wxDataViewColumn
*column
= NULL
);
442 virtual void HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
) const;
443 virtual wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
*column
= NULL
) const;
445 virtual void Expand( const wxDataViewItem
& item
);
446 virtual void Collapse( const wxDataViewItem
& item
);
449 virtual int GetSelections( wxArrayInt
& sel
) const;
450 virtual void SetSelections( const wxArrayInt
& sel
);
451 virtual void Select( int row
);
452 virtual void Unselect( int row
);
453 virtual bool IsSelected( int row
) const;
454 virtual void SelectRange( int from
, int to
);
455 virtual void UnselectRange( int from
, int to
);
457 virtual void EnsureVisible( int row
, int column
);
459 virtual wxDataViewItem
GetItemByRow( unsigned int row
) const;
460 virtual int GetRowByItem( const wxDataViewItem
& item
) const;
462 wxDataViewColumn
* GetSortingColumn() { return m_sortingColumn
; }
463 void SetSortingColumn( wxDataViewColumn
* column
) { m_sortingColumn
= column
; }
465 public: // utility functions not part of the API
467 // returns the "best" width for the idx-th column
468 unsigned int GetBestColumnWidth(int WXUNUSED(idx
)) const
470 return GetClientSize().GetWidth() / GetColumnCount();
473 // called by header window after reorder
474 void ColumnMoved( wxDataViewColumn
* col
, unsigned int new_pos
);
476 // updates the header window after a change in a column setting
477 void OnColumnChange();
479 wxWindow
*GetMainWindow() { return (wxWindow
*) m_clientArea
; }
482 wxDataViewColumnList m_cols
;
483 wxDataViewModelNotifier
*m_notifier
;
484 wxDataViewMainWindow
*m_clientArea
;
485 wxDataViewHeaderWindow
*m_headerArea
;
486 wxDataViewColumn
*m_sortingColumn
;
489 void OnSize( wxSizeEvent
&event
);
491 // we need to return a special WM_GETDLGCODE value to process just the
492 // arrows but let the other navigation characters through
494 virtual WXLRESULT
MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
497 WX_FORWARD_TO_SCROLL_HELPER()
500 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
501 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
502 DECLARE_EVENT_TABLE()
506 #endif // __GENERICDATAVIEWCTRLH__