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() const { 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() const;
138 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
,
139 const wxVariant
&value
);
140 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
146 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
149 // ---------------------------------------------------------
150 // wxDataViewTextRendererAttr
151 // ---------------------------------------------------------
153 class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr
: public wxDataViewTextRenderer
156 wxDataViewTextRendererAttr( const wxString
&varianttype
= wxT("string"),
157 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
158 int align
= wxDVR_DEFAULT_ALIGNMENT
);
160 bool Render( wxRect cell
, wxDC
*dc
, int state
);
163 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr
)
166 // ---------------------------------------------------------
167 // wxDataViewBitmapRenderer
168 // ---------------------------------------------------------
170 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewCustomRenderer
173 wxDataViewBitmapRenderer( const wxString
&varianttype
= wxT("wxBitmap"),
174 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
175 int align
= wxDVR_DEFAULT_ALIGNMENT
);
177 bool SetValue( const wxVariant
&value
);
178 bool GetValue( wxVariant
&value
) const;
180 bool Render( wxRect cell
, wxDC
*dc
, int state
);
181 wxSize
GetSize() const;
188 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
191 // ---------------------------------------------------------
192 // wxDataViewToggleRenderer
193 // ---------------------------------------------------------
195 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewCustomRenderer
198 wxDataViewToggleRenderer( const wxString
&varianttype
= wxT("bool"),
199 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
200 int align
= wxDVR_DEFAULT_ALIGNMENT
);
202 bool SetValue( const wxVariant
&value
);
203 bool GetValue( wxVariant
&value
) const;
205 bool Render( wxRect cell
, wxDC
*dc
, int state
);
206 bool Activate( wxRect cell
, wxDataViewModel
*model
, const wxDataViewItem
& item
,
208 wxSize
GetSize() const;
214 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
217 // ---------------------------------------------------------
218 // wxDataViewProgressRenderer
219 // ---------------------------------------------------------
221 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
224 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
225 const wxString
&varianttype
= wxT("long"),
226 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
227 int align
= wxDVR_DEFAULT_ALIGNMENT
);
228 virtual ~wxDataViewProgressRenderer();
230 bool SetValue( const wxVariant
&value
);
231 bool GetValue( wxVariant
& value
) const;
233 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
234 virtual wxSize
GetSize() const;
241 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
244 // ---------------------------------------------------------
245 // wxDataViewIconTextRenderer
246 // ---------------------------------------------------------
248 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewCustomRenderer
251 wxDataViewIconTextRenderer( const wxString
&varianttype
= wxT("wxDataViewIconText"),
252 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
253 int align
= wxDVR_DEFAULT_ALIGNMENT
);
254 virtual ~wxDataViewIconTextRenderer();
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;
262 virtual bool HasEditorCtrl() const { return true; }
263 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
,
264 const wxVariant
&value
);
265 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
268 wxDataViewIconText m_value
;
271 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
274 // ---------------------------------------------------------
275 // wxDataViewDateRenderer
276 // ---------------------------------------------------------
278 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewCustomRenderer
281 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
282 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
283 int align
= wxDVR_DEFAULT_ALIGNMENT
);
285 bool SetValue( const wxVariant
&value
);
286 bool GetValue( wxVariant
& value
) const;
288 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
289 virtual wxSize
GetSize() const;
290 virtual bool Activate( wxRect cell
,
291 wxDataViewModel
*model
,
292 const wxDataViewItem
& item
,
299 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
302 // ---------------------------------------------------------
304 // ---------------------------------------------------------
306 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
309 wxDataViewColumn(const wxString
& title
,
310 wxDataViewRenderer
*renderer
,
311 unsigned int model_column
,
312 int width
= wxDVC_DEFAULT_WIDTH
,
313 wxAlignment align
= wxALIGN_CENTER
,
314 int flags
= wxDATAVIEW_COL_RESIZABLE
)
315 : wxDataViewColumnBase(renderer
, model_column
),
318 Init(width
, align
, flags
);
321 wxDataViewColumn(const wxBitmap
& bitmap
,
322 wxDataViewRenderer
*renderer
,
323 unsigned int model_column
,
324 int width
= wxDVC_DEFAULT_WIDTH
,
325 wxAlignment align
= wxALIGN_CENTER
,
326 int flags
= wxDATAVIEW_COL_RESIZABLE
)
327 : wxDataViewColumnBase(bitmap
, renderer
, model_column
)
329 Init(width
, align
, flags
);
332 // implement wxHeaderColumnBase methods
333 virtual void SetTitle(const wxString
& title
) { m_title
= title
; }
334 virtual wxString
GetTitle() const { return m_title
; }
336 virtual void SetWidth(int width
) { m_width
= width
; }
337 virtual int GetWidth() const { return m_width
; }
339 virtual void SetMinWidth(int minWidth
) { m_minWidth
= minWidth
; }
340 virtual int GetMinWidth() const { return m_minWidth
; }
342 virtual void SetAlignment(wxAlignment align
) { m_align
= align
; }
343 virtual wxAlignment
GetAlignment() const { return m_align
; }
345 virtual void SetFlags(int flags
) { m_flags
= flags
; }
346 virtual int GetFlags() const { return m_flags
; }
348 virtual void SetAsSortKey(bool sort
= true) { m_sort
= sort
; }
349 virtual bool IsSortKey() const { return m_sort
; }
351 virtual void SetSortOrder(bool ascending
) { m_sortAscending
= ascending
; }
352 virtual bool IsSortOrderAscending() const { return m_sortAscending
; }
355 // common part of all ctors
356 void Init(int width
, wxAlignment align
, int flags
)
358 m_width
= width
== wxCOL_WIDTH_DEFAULT
? wxDVC_DEFAULT_WIDTH
: width
;
363 m_sortAscending
= true;
374 friend class wxDataViewHeaderWindowBase
;
375 friend class wxDataViewHeaderWindow
;
376 friend class wxDataViewHeaderWindowMSW
;
379 // ---------------------------------------------------------
381 // ---------------------------------------------------------
383 WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn
, wxDataViewColumnList
,
384 class WXDLLIMPEXP_ADV
);
386 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
,
387 public wxScrollHelper
389 friend class wxDataViewMainWindow
;
390 friend class wxDataViewHeaderWindowBase
;
391 friend class wxDataViewHeaderWindow
;
392 friend class wxDataViewHeaderWindowMSW
;
393 friend class wxDataViewColumn
;
396 wxDataViewCtrl() : wxScrollHelper(this)
401 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
402 const wxPoint
& pos
= wxDefaultPosition
,
403 const wxSize
& size
= wxDefaultSize
, long style
= 0,
404 const wxValidator
& validator
= wxDefaultValidator
)
405 : wxScrollHelper(this)
407 Create(parent
, id
, pos
, size
, style
, validator
);
410 virtual ~wxDataViewCtrl();
414 bool Create(wxWindow
*parent
, wxWindowID id
,
415 const wxPoint
& pos
= wxDefaultPosition
,
416 const wxSize
& size
= wxDefaultSize
, long style
= 0,
417 const wxValidator
& validator
= wxDefaultValidator
);
419 virtual bool AssociateModel( wxDataViewModel
*model
);
421 virtual bool AppendColumn( wxDataViewColumn
*col
);
422 virtual bool PrependColumn( wxDataViewColumn
*col
);
423 virtual bool InsertColumn( unsigned int pos
, wxDataViewColumn
*col
);
425 virtual void DoSetExpanderColumn();
426 virtual void DoSetIndent();
428 virtual unsigned int GetColumnCount() const;
429 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const;
430 virtual bool DeleteColumn( wxDataViewColumn
*column
);
431 virtual bool ClearColumns();
432 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const;
434 virtual wxDataViewColumn
*GetSortingColumn() const;
436 virtual wxDataViewItem
GetSelection() const;
437 virtual int GetSelections( wxDataViewItemArray
& sel
) const;
438 virtual void SetSelections( const wxDataViewItemArray
& sel
);
439 virtual void Select( const wxDataViewItem
& item
);
440 virtual void Unselect( const wxDataViewItem
& item
);
441 virtual bool IsSelected( const wxDataViewItem
& item
) const;
443 virtual void SelectAll();
444 virtual void UnselectAll();
446 virtual void EnsureVisible( const wxDataViewItem
& item
,
447 const wxDataViewColumn
*column
= NULL
);
448 virtual void HitTest( const wxPoint
& point
, wxDataViewItem
& item
,
449 wxDataViewColumn
* &column
) const;
450 virtual wxRect
GetItemRect( const wxDataViewItem
& item
,
451 const wxDataViewColumn
*column
= NULL
) const;
453 virtual void Expand( const wxDataViewItem
& item
);
454 virtual void Collapse( const wxDataViewItem
& item
);
455 virtual bool IsExpanded( const wxDataViewItem
& item
) const;
457 virtual void SetFocus();
459 #if wxUSE_DRAG_AND_DROP
460 virtual bool EnableDragSource( const wxDataFormat
&format
);
461 virtual bool EnableDropTarget( const wxDataFormat
&format
);
462 #endif // wxUSE_DRAG_AND_DROP
464 virtual wxBorder
GetDefaultBorder() const;
466 void StartEditor( const wxDataViewItem
& item
, unsigned int column
);
469 virtual int GetSelections( wxArrayInt
& sel
) const;
470 virtual void SetSelections( const wxArrayInt
& sel
);
471 virtual void Select( int row
);
472 virtual void Unselect( int row
);
473 virtual bool IsSelected( int row
) const;
474 virtual void SelectRange( int from
, int to
);
475 virtual void UnselectRange( int from
, int to
);
477 virtual void EnsureVisible( int row
, int column
);
479 virtual wxDataViewItem
GetItemByRow( unsigned int row
) const;
480 virtual int GetRowByItem( const wxDataViewItem
& item
) const;
482 int GetSortingColumnIndex() const { return m_sortingColumnIdx
; }
483 void SetSortingColumnIndex(int idx
) { m_sortingColumnIdx
= idx
; }
485 public: // utility functions not part of the API
487 // returns the "best" width for the idx-th column
488 unsigned int GetBestColumnWidth(int WXUNUSED(idx
)) const
490 return GetClientSize().GetWidth() / GetColumnCount();
493 // called by header window after reorder
494 void ColumnMoved( wxDataViewColumn
* col
, unsigned int new_pos
);
496 // update the display after a change to an individual column
497 void OnColumnChange(unsigned int idx
);
499 // update after a change to the number of columns
500 void OnColumnsCountChanged();
502 wxWindow
*GetMainWindow() { return (wxWindow
*) m_clientArea
; }
504 // return the index of the given column in m_cols
505 int GetColumnIndex(const wxDataViewColumn
*column
) const;
507 // return the column displayed at the given position in the control
508 wxDataViewColumn
*GetColumnAt(unsigned int pos
) const;
511 wxDataViewColumnList m_cols
;
512 wxDataViewModelNotifier
*m_notifier
;
513 wxDataViewMainWindow
*m_clientArea
;
514 wxDataViewHeaderWindow
*m_headerArea
;
516 // the index of the column currently used for sorting or -1
517 int m_sortingColumnIdx
;
520 void OnSize( wxSizeEvent
&event
);
521 virtual wxSize
GetSizeAvailableForScrollTarget(const wxSize
& size
);
523 // we need to return a special WM_GETDLGCODE value to process just the
524 // arrows but let the other navigation characters through
526 virtual WXLRESULT
MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
529 WX_FORWARD_TO_SCROLL_HELPER()
532 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
533 wxDECLARE_NO_COPY_CLASS(wxDataViewCtrl
);
534 DECLARE_EVENT_TABLE()
538 #endif // __GENERICDATAVIEWCTRLH__