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_WITH_DECL(wxDataViewColumn
, wxDataViewColumnList
,
349 class WXDLLIMPEXP_ADV
);
351 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
,
352 public wxScrollHelperNative
354 friend class wxDataViewMainWindow
;
355 friend class wxDataViewHeaderWindowBase
;
356 friend class wxDataViewHeaderWindow
;
357 friend class wxDataViewHeaderWindowMSW
;
358 friend class wxDataViewColumn
;
361 wxDataViewCtrl() : wxScrollHelperNative(this)
363 //No sorting column at start, I think
364 m_sortingColumn
= NULL
;
368 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
369 const wxPoint
& pos
= wxDefaultPosition
,
370 const wxSize
& size
= wxDefaultSize
, long style
= 0,
371 const wxValidator
& validator
= wxDefaultValidator
)
372 : wxScrollHelperNative(this)
374 m_sortingColumn
= NULL
;
375 Create(parent
, id
, pos
, size
, style
, validator
);
378 virtual ~wxDataViewCtrl();
382 bool Create(wxWindow
*parent
, wxWindowID id
,
383 const wxPoint
& pos
= wxDefaultPosition
,
384 const wxSize
& size
= wxDefaultSize
, long style
= 0,
385 const wxValidator
& validator
= wxDefaultValidator
);
387 virtual bool AssociateModel( wxDataViewModel
*model
);
388 virtual bool AppendColumn( wxDataViewColumn
*col
);
389 virtual bool PrependColumn( wxDataViewColumn
*col
);
391 virtual void DoSetExpanderColumn();
392 virtual void DoSetIndent();
394 virtual unsigned int GetColumnCount() const;
395 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const;
396 virtual bool DeleteColumn( wxDataViewColumn
*column
);
397 virtual bool ClearColumns();
398 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const;
400 virtual wxDataViewColumn
*GetSortingColumn() const;
402 virtual wxDataViewItem
GetSelection() const;
403 virtual int GetSelections( wxDataViewItemArray
& sel
) const;
404 virtual void SetSelections( const wxDataViewItemArray
& sel
);
405 virtual void Select( const wxDataViewItem
& item
);
406 virtual void Unselect( const wxDataViewItem
& item
);
407 virtual bool IsSelected( const wxDataViewItem
& item
) const;
409 virtual void SelectAll();
410 virtual void UnselectAll();
412 virtual void EnsureVisible( const wxDataViewItem
& item
,
413 const wxDataViewColumn
*column
= NULL
);
414 virtual void HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
) const;
415 virtual wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
*column
= NULL
) const;
417 virtual void Expand( const wxDataViewItem
& item
);
418 virtual void Collapse( const wxDataViewItem
& item
);
421 virtual int GetSelections( wxArrayInt
& sel
) const;
422 virtual void SetSelections( const wxArrayInt
& sel
);
423 virtual void Select( int row
);
424 virtual void Unselect( int row
);
425 virtual bool IsSelected( int row
) const;
426 virtual void SelectRange( int from
, int to
);
427 virtual void UnselectRange( int from
, int to
);
429 virtual void EnsureVisible( int row
, int column
);
431 virtual wxDataViewItem
GetItemByRow( unsigned int row
) const;
432 virtual int GetRowByItem( const wxDataViewItem
& item
) const;
434 wxDataViewColumn
* GetSortingColumn() { return m_sortingColumn
; }
435 void SetSortingColumn( wxDataViewColumn
* column
) { m_sortingColumn
= column
; }
437 public: // utility functions not part of the API
439 // returns the "best" width for the idx-th column
440 unsigned int GetBestColumnWidth(int WXUNUSED(idx
)) const
442 return GetClientSize().GetWidth() / GetColumnCount();
445 // updates the header window after a change in a column setting
446 void OnColumnChange();
448 wxWindow
*GetMainWindow() { return (wxWindow
*) m_clientArea
; }
451 wxDataViewColumnList m_cols
;
452 wxDataViewModelNotifier
*m_notifier
;
453 wxDataViewMainWindow
*m_clientArea
;
454 wxDataViewHeaderWindow
*m_headerArea
;
455 wxDataViewColumn
* m_sortingColumn
;
458 void OnSize( wxSizeEvent
&event
);
460 // we need to return a special WM_GETDLGCODE value to process just the
461 // arrows but let the other navigation characters through
463 virtual WXLRESULT
MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
466 WX_FORWARD_TO_SCROLL_HELPER()
469 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
470 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
471 DECLARE_EVENT_TABLE()
475 #endif // __GENERICDATAVIEWCTRLH__