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
);
45 virtual int GetAlignment() const;
47 virtual void SetMode( wxDataViewCellMode mode
)
49 virtual wxDataViewCellMode
GetMode() const
52 virtual bool Activate( wxRect
WXUNUSED(cell
),
53 wxDataViewModel
*WXUNUSED(model
),
54 const wxDataViewItem
& WXUNUSED(item
),
55 unsigned int WXUNUSED(col
) )
58 virtual bool LeftClick( wxPoint
WXUNUSED(cursor
),
59 wxRect
WXUNUSED(cell
),
60 wxDataViewModel
*WXUNUSED(model
),
61 const wxDataViewItem
& WXUNUSED(item
),
62 unsigned int WXUNUSED(col
) )
64 virtual bool RightClick( wxPoint
WXUNUSED(cursor
),
65 wxRect
WXUNUSED(cell
),
66 wxDataViewModel
*WXUNUSED(model
),
67 const wxDataViewItem
& WXUNUSED(item
),
68 unsigned int WXUNUSED(col
) )
70 virtual bool StartDrag( wxPoint
WXUNUSED(cursor
),
71 wxRect
WXUNUSED(cell
),
72 wxDataViewModel
*WXUNUSED(model
),
73 const wxDataViewItem
& WXUNUSED(item
),
74 unsigned int WXUNUSED(col
) )
77 // Create DC on request
78 virtual wxDC
*GetDC();
80 void SetHasAttr( bool set
) { m_hasAttr
= set
; }
81 void SetAttr( const wxDataViewItemAttr
&attr
) { m_attr
= attr
; }
82 bool GetWantsAttr() { return m_wantsAttr
; }
85 int CalculateAlignment() const;
90 wxDataViewCellMode m_mode
;
95 wxDataViewItemAttr m_attr
;
98 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer
)
101 // ---------------------------------------------------------
102 // wxDataViewCustomRenderer
103 // ---------------------------------------------------------
105 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewRenderer
108 wxDataViewCustomRenderer( const wxString
&varianttype
= wxT("string"),
109 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
110 int align
= wxDVR_DEFAULT_ALIGNMENT
);
112 void RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
);
115 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
119 // ---------------------------------------------------------
120 // wxDataViewTextRenderer
121 // ---------------------------------------------------------
123 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewCustomRenderer
126 wxDataViewTextRenderer( const wxString
&varianttype
= wxT("string"),
127 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
128 int align
= wxDVR_DEFAULT_ALIGNMENT
);
130 bool SetValue( const wxVariant
&value
);
131 bool GetValue( wxVariant
&value
) const;
133 bool Render( wxRect cell
, wxDC
*dc
, int state
);
134 wxSize
GetSize() const;
137 virtual bool HasEditorCtrl();
138 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
139 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
145 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
148 // ---------------------------------------------------------
149 // wxDataViewTextRendererAttr
150 // ---------------------------------------------------------
152 class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr
: public wxDataViewTextRenderer
155 wxDataViewTextRendererAttr( const wxString
&varianttype
= wxT("string"),
156 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
157 int align
= wxDVR_DEFAULT_ALIGNMENT
);
159 bool Render( wxRect cell
, wxDC
*dc
, int state
);
162 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr
)
165 // ---------------------------------------------------------
166 // wxDataViewBitmapRenderer
167 // ---------------------------------------------------------
169 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewCustomRenderer
172 wxDataViewBitmapRenderer( const wxString
&varianttype
= wxT("wxBitmap"),
173 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
174 int align
= wxDVR_DEFAULT_ALIGNMENT
);
176 bool SetValue( const wxVariant
&value
);
177 bool GetValue( wxVariant
&value
) const;
179 bool Render( wxRect cell
, wxDC
*dc
, int state
);
180 wxSize
GetSize() const;
187 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
190 // ---------------------------------------------------------
191 // wxDataViewToggleRenderer
192 // ---------------------------------------------------------
194 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewCustomRenderer
197 wxDataViewToggleRenderer( const wxString
&varianttype
= wxT("bool"),
198 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
199 int align
= wxDVR_DEFAULT_ALIGNMENT
);
201 bool SetValue( const wxVariant
&value
);
202 bool GetValue( wxVariant
&value
) const;
204 bool Render( wxRect cell
, wxDC
*dc
, int state
);
205 bool Activate( wxRect cell
, wxDataViewModel
*model
, const wxDataViewItem
& item
,
207 wxSize
GetSize() const;
213 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
216 // ---------------------------------------------------------
217 // wxDataViewProgressRenderer
218 // ---------------------------------------------------------
220 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
223 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
224 const wxString
&varianttype
= wxT("long"),
225 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
226 int align
= wxDVR_DEFAULT_ALIGNMENT
);
227 virtual ~wxDataViewProgressRenderer();
229 bool SetValue( const wxVariant
&value
);
230 bool GetValue( wxVariant
& value
) const;
232 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
233 virtual wxSize
GetSize() const;
240 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
243 // ---------------------------------------------------------
244 // wxDataViewIconTextRenderer
245 // ---------------------------------------------------------
247 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewCustomRenderer
250 wxDataViewIconTextRenderer( const wxString
&varianttype
= wxT("wxDataViewIconText"),
251 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
252 int align
= wxDVR_DEFAULT_ALIGNMENT
);
253 virtual ~wxDataViewIconTextRenderer();
255 bool SetValue( const wxVariant
&value
);
256 bool GetValue( wxVariant
&value
) const;
258 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
259 virtual wxSize
GetSize() const;
261 virtual bool HasEditorCtrl() { return true; }
262 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
263 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
266 wxDataViewIconText m_value
;
269 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
272 // ---------------------------------------------------------
273 // wxDataViewDateRenderer
274 // ---------------------------------------------------------
276 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewCustomRenderer
279 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
280 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
281 int align
= wxDVR_DEFAULT_ALIGNMENT
);
283 bool SetValue( const wxVariant
&value
);
284 bool GetValue( wxVariant
& value
) const;
286 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
287 virtual wxSize
GetSize() const;
288 virtual bool Activate( wxRect cell
,
289 wxDataViewModel
*model
, const wxDataViewItem
& item
, unsigned int col
);
295 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
298 // ---------------------------------------------------------
300 // ---------------------------------------------------------
302 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
305 wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*renderer
,
306 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
307 wxAlignment align
= wxALIGN_CENTER
,
308 int flags
= wxDATAVIEW_COL_RESIZABLE
);
309 wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
310 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
311 wxAlignment align
= wxALIGN_CENTER
,
312 int flags
= wxDATAVIEW_COL_RESIZABLE
);
314 // override some methods to notify the owner about changes
315 virtual void SetFlags(int flags
);
316 virtual void SetWidth(int width
);
317 virtual void SetSortOrder(bool ascending
);
319 // override this one to return our default width for columns whose width
320 // was not explicitly set
321 virtual int GetWidth() const;
324 // like SetWidth() but does not ask the header window of the
325 // wxDataViewCtrl to reflect the width-change.
326 void SetInternalWidth(int width
);
328 friend class wxDataViewHeaderWindowBase
;
329 friend class wxDataViewHeaderWindow
;
330 friend class wxDataViewHeaderWindowMSW
;
332 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
335 // ---------------------------------------------------------
337 // ---------------------------------------------------------
339 WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn
, wxDataViewColumnList
,
340 class WXDLLIMPEXP_ADV
);
342 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
,
343 public wxScrollHelperNative
345 friend class wxDataViewMainWindow
;
346 friend class wxDataViewHeaderWindowBase
;
347 friend class wxDataViewHeaderWindow
;
348 friend class wxDataViewHeaderWindowMSW
;
349 friend class wxDataViewColumn
;
352 wxDataViewCtrl() : wxScrollHelperNative(this)
357 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
358 const wxPoint
& pos
= wxDefaultPosition
,
359 const wxSize
& size
= wxDefaultSize
, long style
= 0,
360 const wxValidator
& validator
= wxDefaultValidator
)
361 : wxScrollHelperNative(this)
363 Create(parent
, id
, pos
, size
, style
, validator
);
366 virtual ~wxDataViewCtrl();
370 bool Create(wxWindow
*parent
, wxWindowID id
,
371 const wxPoint
& pos
= wxDefaultPosition
,
372 const wxSize
& size
= wxDefaultSize
, long style
= 0,
373 const wxValidator
& validator
= wxDefaultValidator
);
375 virtual bool AssociateModel( wxDataViewModel
*model
);
377 virtual bool AppendColumn( wxDataViewColumn
*col
);
378 virtual bool PrependColumn( wxDataViewColumn
*col
);
379 virtual bool InsertColumn( unsigned int pos
, wxDataViewColumn
*col
);
381 virtual void DoSetExpanderColumn();
382 virtual void DoSetIndent();
384 virtual unsigned int GetColumnCount() const;
385 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const;
386 virtual bool DeleteColumn( wxDataViewColumn
*column
);
387 virtual bool ClearColumns();
388 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const;
390 virtual wxDataViewColumn
*GetSortingColumn() const;
392 virtual wxDataViewItem
GetSelection() const;
393 virtual int GetSelections( wxDataViewItemArray
& sel
) const;
394 virtual void SetSelections( const wxDataViewItemArray
& sel
);
395 virtual void Select( const wxDataViewItem
& item
);
396 virtual void Unselect( const wxDataViewItem
& item
);
397 virtual bool IsSelected( const wxDataViewItem
& item
) const;
399 virtual void SelectAll();
400 virtual void UnselectAll();
402 virtual void EnsureVisible( const wxDataViewItem
& item
,
403 const wxDataViewColumn
*column
= NULL
);
404 virtual void HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
) const;
405 virtual wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
*column
= NULL
) const;
407 virtual void Expand( const wxDataViewItem
& item
);
408 virtual void Collapse( const wxDataViewItem
& item
);
410 virtual void SetFocus();
413 virtual int GetSelections( wxArrayInt
& sel
) const;
414 virtual void SetSelections( const wxArrayInt
& sel
);
415 virtual void Select( int row
);
416 virtual void Unselect( int row
);
417 virtual bool IsSelected( int row
) const;
418 virtual void SelectRange( int from
, int to
);
419 virtual void UnselectRange( int from
, int to
);
421 virtual void EnsureVisible( int row
, int column
);
423 virtual wxDataViewItem
GetItemByRow( unsigned int row
) const;
424 virtual int GetRowByItem( const wxDataViewItem
& item
) const;
426 wxDataViewColumn
* GetSortingColumn() { return m_sortingColumn
; }
427 void SetSortingColumn( wxDataViewColumn
* column
) { m_sortingColumn
= column
; }
429 public: // utility functions not part of the API
431 // returns the "best" width for the idx-th column
432 unsigned int GetBestColumnWidth(int WXUNUSED(idx
)) const
434 return GetClientSize().GetWidth() / GetColumnCount();
437 // called by header window after reorder
438 void ColumnMoved( wxDataViewColumn
* col
, unsigned int new_pos
);
440 // updates the header window after a change in a column setting
441 void OnColumnChange();
443 wxWindow
*GetMainWindow() { return (wxWindow
*) m_clientArea
; }
446 wxDataViewColumnList m_cols
;
447 wxDataViewModelNotifier
*m_notifier
;
448 wxDataViewMainWindow
*m_clientArea
;
449 wxDataViewHeaderWindow
*m_headerArea
;
450 wxDataViewColumn
*m_sortingColumn
;
453 void OnSize( wxSizeEvent
&event
);
454 virtual wxSize
GetSizeAvailableForScrollTarget(const wxSize
& size
);
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__