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_ADV wxDataViewCtrl
;
25 class WXDLLIMPEXP_ADV wxDataViewMainWindow
;
26 class WXDLLIMPEXP_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 wxDataViewListModel
*WXUNUSED(model
),
55 unsigned int WXUNUSED(col
),
56 unsigned int WXUNUSED(row
) )
59 virtual bool LeftClick( wxPoint
WXUNUSED(cursor
),
60 wxRect
WXUNUSED(cell
),
61 wxDataViewListModel
*WXUNUSED(model
),
62 unsigned int WXUNUSED(col
),
63 unsigned int WXUNUSED(row
) )
65 virtual bool RightClick( wxPoint
WXUNUSED(cursor
),
66 wxRect
WXUNUSED(cell
),
67 wxDataViewListModel
*WXUNUSED(model
),
68 unsigned int WXUNUSED(col
),
69 unsigned int WXUNUSED(row
) )
71 virtual bool StartDrag( wxPoint
WXUNUSED(cursor
),
72 wxRect
WXUNUSED(cell
),
73 wxDataViewListModel
*WXUNUSED(model
),
74 unsigned int WXUNUSED(col
),
75 unsigned int WXUNUSED(row
) )
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
)
105 // ---------------------------------------------------------
106 // wxDataViewTextRenderer
107 // ---------------------------------------------------------
109 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewCustomRenderer
112 wxDataViewTextRenderer( const wxString
&varianttype
= wxT("string"),
113 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
114 int align
= wxDVR_DEFAULT_ALIGNMENT
);
116 bool SetValue( const wxVariant
&value
);
117 bool GetValue( wxVariant
&value
) const;
119 bool Render( wxRect cell
, wxDC
*dc
, int state
);
120 wxSize
GetSize() const;
126 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
129 // ---------------------------------------------------------
130 // wxDataViewBitmapRenderer
131 // ---------------------------------------------------------
133 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewCustomRenderer
136 wxDataViewBitmapRenderer( const wxString
&varianttype
= wxT("wxBitmap"),
137 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
138 int align
= wxDVR_DEFAULT_ALIGNMENT
);
140 bool SetValue( const wxVariant
&value
);
141 bool GetValue( wxVariant
&value
) const;
143 bool Render( wxRect cell
, wxDC
*dc
, int state
);
144 wxSize
GetSize() const;
151 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
154 // ---------------------------------------------------------
155 // wxDataViewToggleRenderer
156 // ---------------------------------------------------------
158 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewCustomRenderer
161 wxDataViewToggleRenderer( const wxString
&varianttype
= wxT("bool"),
162 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
163 int align
= wxDVR_DEFAULT_ALIGNMENT
);
165 bool SetValue( const wxVariant
&value
);
166 bool GetValue( wxVariant
&value
) const;
168 bool Render( wxRect cell
, wxDC
*dc
, int state
);
169 bool Activate( wxRect cell
, wxDataViewListModel
*model
, unsigned int col
,
171 wxSize
GetSize() const;
177 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
180 // ---------------------------------------------------------
181 // wxDataViewProgressRenderer
182 // ---------------------------------------------------------
184 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
187 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
188 const wxString
&varianttype
= wxT("long"),
189 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
190 int align
= wxDVR_DEFAULT_ALIGNMENT
);
191 virtual ~wxDataViewProgressRenderer();
193 bool SetValue( const wxVariant
&value
);
194 bool GetValue( wxVariant
& value
) const;
196 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
197 virtual wxSize
GetSize() const;
204 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
207 // ---------------------------------------------------------
208 // wxDataViewDateRenderer
209 // ---------------------------------------------------------
211 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewCustomRenderer
214 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
215 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
216 int align
= wxDVR_DEFAULT_ALIGNMENT
);
218 bool SetValue( const wxVariant
&value
);
219 bool GetValue( wxVariant
& value
) const;
221 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
222 virtual wxSize
GetSize() const;
223 virtual bool Activate( wxRect cell
,
224 wxDataViewListModel
*model
, unsigned int col
, unsigned int row
);
230 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
233 // ---------------------------------------------------------
235 // ---------------------------------------------------------
237 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
239 friend class wxDataViewHeaderWindowBase
;
240 friend class wxDataViewHeaderWindow
;
241 friend class wxDataViewHeaderWindowMSW
;
244 wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*renderer
,
245 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
246 wxAlignment align
= wxALIGN_CENTER
,
247 int flags
= wxDATAVIEW_COL_RESIZABLE
);
248 wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
249 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
250 wxAlignment align
= wxALIGN_CENTER
,
251 int flags
= wxDATAVIEW_COL_RESIZABLE
);
252 virtual ~wxDataViewColumn();
256 virtual void SetTitle( const wxString
&title
)
258 virtual void SetAlignment( wxAlignment align
)
260 virtual void SetMinWidth( int minWidth
)
261 { m_minWidth
=minWidth
; }
262 virtual void SetWidth( int width
);
263 virtual void SetSortable( bool sortable
);
264 virtual void SetResizeable( bool resizeable
);
265 virtual void SetHidden( bool hidden
);
266 virtual void SetSortOrder( bool ascending
);
271 virtual wxString
GetTitle() const
273 virtual wxAlignment
GetAlignment() const
275 virtual int GetWidth() const
277 virtual int GetMinWidth() const
278 { return m_minWidth
; }
279 virtual bool IsSortable() const
280 { return (m_flags
& wxDATAVIEW_COL_SORTABLE
) != 0; }
281 virtual bool IsResizeable() const
282 { return (m_flags
& wxDATAVIEW_COL_RESIZABLE
) != 0; }
283 virtual bool IsHidden() const
284 { return (m_flags
& wxDATAVIEW_COL_HIDDEN
) != 0; }
285 virtual bool IsSortOrderAscending() const;
295 void Init(int width
);
297 // like SetWidth() but does not ask the header window of the
298 // wxDataViewCtrl to reflect the width-change.
299 void SetInternalWidth(int width
);
302 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
305 // ---------------------------------------------------------
307 // ---------------------------------------------------------
309 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
,
310 public wxScrollHelperNative
312 friend class wxDataViewMainWindow
;
313 friend class wxDataViewHeaderWindowBase
;
314 friend class wxDataViewHeaderWindow
;
315 friend class wxDataViewHeaderWindowMSW
;
316 friend class wxDataViewColumn
;
319 wxDataViewCtrl() : wxScrollHelperNative(this)
324 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
325 const wxPoint
& pos
= wxDefaultPosition
,
326 const wxSize
& size
= wxDefaultSize
, long style
= 0,
327 const wxValidator
& validator
= wxDefaultValidator
)
328 : wxScrollHelperNative(this)
330 Create(parent
, id
, pos
, size
, style
, validator
);
333 virtual ~wxDataViewCtrl();
337 bool Create(wxWindow
*parent
, wxWindowID id
,
338 const wxPoint
& pos
= wxDefaultPosition
,
339 const wxSize
& size
= wxDefaultSize
, long style
= 0,
340 const wxValidator
& validator
= wxDefaultValidator
);
342 virtual bool AssociateModel( wxDataViewListModel
*model
);
343 virtual bool AppendColumn( wxDataViewColumn
*col
);
345 virtual void SetSelection( int row
); // -1 for unselect
346 virtual void SetSelectionRange( unsigned int from
, unsigned int to
);
347 virtual void SetSelections( const wxArrayInt
& aSelections
);
348 virtual void Unselect( unsigned int row
);
350 virtual bool IsSelected( unsigned int row
) const;
351 virtual int GetSelection() const;
352 virtual int GetSelections(wxArrayInt
& aSelections
) const;
354 public: // utility functions not part of the API
356 // returns the "best" width for the idx-th column
357 unsigned int GetBestColumnWidth(int WXUNUSED(idx
)) const
359 return GetClientSize().GetWidth() / GetColumnCount();
362 // updates the header window after a change in a column setting
363 void OnColumnChange();
366 wxDataViewListModelNotifier
*m_notifier
;
367 wxDataViewMainWindow
*m_clientArea
;
368 wxDataViewHeaderWindow
*m_headerArea
;
371 void OnSize( wxSizeEvent
&event
);
373 // we need to return a special WM_GETDLGCODE value to process just the
374 // arrows but let the other navigation characters through
376 virtual WXLRESULT
MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
379 WX_FORWARD_TO_SCROLL_HELPER()
382 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
383 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
384 DECLARE_EVENT_TABLE()
388 #endif // __GENERICDATAVIEWCTRLH__