1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/dataview.h
3 // Purpose: wxDataViewCtrl generic implementation header
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef __GENERICDATAVIEWCTRLH__
11 #define __GENERICDATAVIEWCTRLH__
14 #include "wx/object.h"
16 #include "wx/control.h"
17 #include "wx/scrolwin.h"
20 // ---------------------------------------------------------
22 // ---------------------------------------------------------
24 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl
;
25 class WXDLLIMPEXP_FWD_ADV wxDataViewMainWindow
;
26 class WXDLLIMPEXP_FWD_ADV wxDataViewHeaderWindow
;
28 // ---------------------------------------------------------
30 // ---------------------------------------------------------
32 class WXDLLIMPEXP_ADV wxDataViewRenderer
: public wxDataViewRendererBase
35 wxDataViewRenderer( const wxString
&varianttype
,
36 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
37 int align
= wxDVR_DEFAULT_ALIGNMENT
);
38 virtual ~wxDataViewRenderer();
40 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
) = 0;
41 virtual wxSize
GetSize() const = 0;
43 virtual void SetAlignment( int align
)
45 virtual int GetAlignment() const
48 virtual void SetMode( wxDataViewCellMode mode
)
50 virtual wxDataViewCellMode
GetMode() const
53 virtual bool Activate( wxRect
WXUNUSED(cell
),
54 wxDataViewModel
*WXUNUSED(model
),
55 const wxDataViewItem
& WXUNUSED(item
),
56 unsigned int WXUNUSED(col
) )
59 virtual bool LeftClick( wxPoint
WXUNUSED(cursor
),
60 wxRect
WXUNUSED(cell
),
61 wxDataViewModel
*WXUNUSED(model
),
62 const wxDataViewItem
& WXUNUSED(item
),
63 unsigned int WXUNUSED(col
) )
65 virtual bool RightClick( wxPoint
WXUNUSED(cursor
),
66 wxRect
WXUNUSED(cell
),
67 wxDataViewModel
*WXUNUSED(model
),
68 const wxDataViewItem
& WXUNUSED(item
),
69 unsigned int WXUNUSED(col
) )
71 virtual bool StartDrag( wxPoint
WXUNUSED(cursor
),
72 wxRect
WXUNUSED(cell
),
73 wxDataViewModel
*WXUNUSED(model
),
74 const wxDataViewItem
& WXUNUSED(item
),
75 unsigned int WXUNUSED(col
) )
78 // Create DC on request
79 virtual wxDC
*GetDC();
84 wxDataViewCellMode m_mode
;
87 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer
)
90 // ---------------------------------------------------------
91 // wxDataViewCustomRenderer
92 // ---------------------------------------------------------
94 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewRenderer
97 wxDataViewCustomRenderer( const wxString
&varianttype
= wxT("string"),
98 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
99 int align
= wxDVR_DEFAULT_ALIGNMENT
);
102 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
106 // ---------------------------------------------------------
107 // wxDataViewTextRenderer
108 // ---------------------------------------------------------
110 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewCustomRenderer
113 wxDataViewTextRenderer( const wxString
&varianttype
= wxT("string"),
114 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
115 int align
= wxDVR_DEFAULT_ALIGNMENT
);
117 bool SetValue( const wxVariant
&value
);
118 bool GetValue( wxVariant
&value
) const;
120 bool Render( wxRect cell
, wxDC
*dc
, int state
);
121 wxSize
GetSize() const;
124 virtual bool HasEditorCtrl();
125 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
126 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
132 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
135 // ---------------------------------------------------------
136 // wxDataViewBitmapRenderer
137 // ---------------------------------------------------------
139 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewCustomRenderer
142 wxDataViewBitmapRenderer( const wxString
&varianttype
= wxT("wxBitmap"),
143 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
144 int align
= wxDVR_DEFAULT_ALIGNMENT
);
146 bool SetValue( const wxVariant
&value
);
147 bool GetValue( wxVariant
&value
) const;
149 bool Render( wxRect cell
, wxDC
*dc
, int state
);
150 wxSize
GetSize() const;
157 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
160 // ---------------------------------------------------------
161 // wxDataViewToggleRenderer
162 // ---------------------------------------------------------
164 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewCustomRenderer
167 wxDataViewToggleRenderer( const wxString
&varianttype
= wxT("bool"),
168 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
169 int align
= wxDVR_DEFAULT_ALIGNMENT
);
171 bool SetValue( const wxVariant
&value
);
172 bool GetValue( wxVariant
&value
) const;
174 bool Render( wxRect cell
, wxDC
*dc
, int state
);
175 bool Activate( wxRect cell
, wxDataViewModel
*model
, const wxDataViewItem
& item
,
177 wxSize
GetSize() const;
183 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
186 // ---------------------------------------------------------
187 // wxDataViewProgressRenderer
188 // ---------------------------------------------------------
190 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
193 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
194 const wxString
&varianttype
= wxT("long"),
195 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
196 int align
= wxDVR_DEFAULT_ALIGNMENT
);
197 virtual ~wxDataViewProgressRenderer();
199 bool SetValue( const wxVariant
&value
);
200 bool GetValue( wxVariant
& value
) const;
202 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
203 virtual wxSize
GetSize() const;
210 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
213 // ---------------------------------------------------------
214 // wxDataViewDateRenderer
215 // ---------------------------------------------------------
217 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewCustomRenderer
220 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
221 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
222 int align
= wxDVR_DEFAULT_ALIGNMENT
);
224 bool SetValue( const wxVariant
&value
);
225 bool GetValue( wxVariant
& value
) const;
227 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
228 virtual wxSize
GetSize() const;
229 virtual bool Activate( wxRect cell
,
230 wxDataViewModel
*model
, const wxDataViewItem
& item
, unsigned int col
);
236 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
239 // ---------------------------------------------------------
241 // ---------------------------------------------------------
243 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
245 friend class wxDataViewHeaderWindowBase
;
246 friend class wxDataViewHeaderWindow
;
247 friend class wxDataViewHeaderWindowMSW
;
250 wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*renderer
,
251 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
252 wxAlignment align
= wxALIGN_CENTER
,
253 int flags
= wxDATAVIEW_COL_RESIZABLE
);
254 wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
255 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
256 wxAlignment align
= wxALIGN_CENTER
,
257 int flags
= wxDATAVIEW_COL_RESIZABLE
);
258 virtual ~wxDataViewColumn();
262 virtual void SetTitle( const wxString
&title
)
264 virtual void SetAlignment( wxAlignment align
)
266 virtual void SetMinWidth( int minWidth
)
267 { m_minWidth
=minWidth
; }
268 virtual void SetWidth( int width
);
269 virtual void SetSortable( bool sortable
);
270 virtual void SetResizeable( bool resizeable
);
271 virtual void SetHidden( bool hidden
);
272 virtual void SetSortOrder( bool ascending
);
277 virtual wxString
GetTitle() const
279 virtual wxAlignment
GetAlignment() const
281 virtual int GetWidth() const
283 virtual int GetMinWidth() const
284 { return m_minWidth
; }
285 virtual bool IsSortable() const
286 { return (m_flags
& wxDATAVIEW_COL_SORTABLE
) != 0; }
287 virtual bool IsResizeable() const
288 { return (m_flags
& wxDATAVIEW_COL_RESIZABLE
) != 0; }
289 virtual bool IsHidden() const
290 { return (m_flags
& wxDATAVIEW_COL_HIDDEN
) != 0; }
291 virtual bool IsSortOrderAscending() const;
302 void Init(int width
);
304 // like SetWidth() but does not ask the header window of the
305 // wxDataViewCtrl to reflect the width-change.
306 void SetInternalWidth(int width
);
309 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
312 // ---------------------------------------------------------
314 // ---------------------------------------------------------
316 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
,
317 public wxScrollHelperNative
319 friend class wxDataViewMainWindow
;
320 friend class wxDataViewHeaderWindowBase
;
321 friend class wxDataViewHeaderWindow
;
322 friend class wxDataViewHeaderWindowMSW
;
323 friend class wxDataViewColumn
;
326 wxDataViewCtrl() : wxScrollHelperNative(this)
331 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
332 const wxPoint
& pos
= wxDefaultPosition
,
333 const wxSize
& size
= wxDefaultSize
, long style
= 0,
334 const wxValidator
& validator
= wxDefaultValidator
)
335 : wxScrollHelperNative(this)
337 Create(parent
, id
, pos
, size
, style
, validator
);
340 virtual ~wxDataViewCtrl();
344 bool Create(wxWindow
*parent
, wxWindowID id
,
345 const wxPoint
& pos
= wxDefaultPosition
,
346 const wxSize
& size
= wxDefaultSize
, long style
= 0,
347 const wxValidator
& validator
= wxDefaultValidator
);
349 virtual bool AssociateModel( wxDataViewModel
*model
);
350 virtual bool AppendColumn( wxDataViewColumn
*col
);
352 virtual void DoSetExpanderColumn();
353 virtual void DoSetIndent();
355 virtual wxDataViewItem
GetSelection() ;
357 /********************selection code*********************
358 virtual void SetSelection( int row ); // -1 for unselect
359 virtual void SetSelectionRange( unsigned int from, unsigned int to );
360 virtual void SetSelections( const wxArrayInt& aSelections);
361 virtual void Unselect( unsigned int row );
363 virtual bool IsSelected( unsigned int row ) const;
364 virtual int GetSelection() const;
365 virtual int GetSelections(wxArrayInt& aSelections) const;
366 *****************************************************/
368 public: // utility functions not part of the API
370 // returns the "best" width for the idx-th column
371 unsigned int GetBestColumnWidth(int WXUNUSED(idx
)) const
373 return GetClientSize().GetWidth() / GetColumnCount();
376 // updates the header window after a change in a column setting
377 void OnColumnChange();
379 wxWindow
*GetMainWindow() { return (wxWindow
*) m_clientArea
; }
382 wxDataViewModelNotifier
*m_notifier
;
383 wxDataViewMainWindow
*m_clientArea
;
384 wxDataViewHeaderWindow
*m_headerArea
;
387 void OnSize( wxSizeEvent
&event
);
389 // we need to return a special WM_GETDLGCODE value to process just the
390 // arrows but let the other navigation characters through
392 virtual WXLRESULT
MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
395 WX_FORWARD_TO_SCROLL_HELPER()
398 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
399 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
400 DECLARE_EVENT_TABLE()
404 #endif // __GENERICDATAVIEWCTRLH__