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 //-----------------------------------------------------------------------------
29 // wxDataViewEditorCtrlEvtHandler
30 //-----------------------------------------------------------------------------
32 class wxDataViewEditorCtrlEvtHandler
: public wxEvtHandler
35 wxDataViewEditorCtrlEvtHandler( wxControl
*editor
, wxDataViewRenderer
*owner
);
37 void AcceptChangesAndFinish();
40 void OnChar( wxKeyEvent
&event
);
41 void OnKillFocus( wxFocusEvent
&event
);
44 wxDataViewRenderer
*m_owner
;
45 wxControl
*m_editorCtrl
;
52 // ---------------------------------------------------------
54 // ---------------------------------------------------------
56 class WXDLLIMPEXP_ADV wxDataViewRenderer
: public wxDataViewRendererBase
59 wxDataViewRenderer( const wxString
&varianttype
,
60 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
61 int align
= wxDVR_DEFAULT_ALIGNMENT
);
62 virtual ~wxDataViewRenderer();
64 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
) = 0;
65 virtual wxSize
GetSize() const = 0;
67 virtual void SetAlignment( int align
)
69 virtual int GetAlignment() const
72 virtual void SetMode( wxDataViewCellMode mode
)
74 virtual wxDataViewCellMode
GetMode() const
77 virtual bool Activate( wxRect
WXUNUSED(cell
),
78 wxDataViewListModel
*WXUNUSED(model
),
79 unsigned int WXUNUSED(col
),
80 unsigned int WXUNUSED(row
) )
83 virtual bool LeftClick( wxPoint
WXUNUSED(cursor
),
84 wxRect
WXUNUSED(cell
),
85 wxDataViewListModel
*WXUNUSED(model
),
86 unsigned int WXUNUSED(col
),
87 unsigned int WXUNUSED(row
) )
89 virtual bool RightClick( wxPoint
WXUNUSED(cursor
),
90 wxRect
WXUNUSED(cell
),
91 wxDataViewListModel
*WXUNUSED(model
),
92 unsigned int WXUNUSED(col
),
93 unsigned int WXUNUSED(row
) )
95 virtual bool StartDrag( wxPoint
WXUNUSED(cursor
),
96 wxRect
WXUNUSED(cell
),
97 wxDataViewListModel
*WXUNUSED(model
),
98 unsigned int WXUNUSED(col
),
99 unsigned int WXUNUSED(row
) )
102 // Create DC on request
103 virtual wxDC
*GetDC();
106 virtual bool HasEditorCtrl()
108 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
110 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
113 virtual bool StartEditing( unsigned int row
, wxRect labelRect
);
114 virtual void CancelEditing();
115 virtual bool FinishEditing();
120 wxDataViewCellMode m_mode
;
121 wxControl
*m_editorCtrl
;
122 unsigned int m_row
; // for m_editorCtrl
125 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer
)
128 // ---------------------------------------------------------
129 // wxDataViewCustomRenderer
130 // ---------------------------------------------------------
132 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewRenderer
135 wxDataViewCustomRenderer( const wxString
&varianttype
= wxT("string"),
136 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
137 int align
= wxDVR_DEFAULT_ALIGNMENT
);
140 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
144 // ---------------------------------------------------------
145 // wxDataViewTextRenderer
146 // ---------------------------------------------------------
148 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewCustomRenderer
151 wxDataViewTextRenderer( const wxString
&varianttype
= wxT("string"),
152 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
153 int align
= wxDVR_DEFAULT_ALIGNMENT
);
155 bool SetValue( const wxVariant
&value
);
156 bool GetValue( wxVariant
&value
) const;
158 bool Render( wxRect cell
, wxDC
*dc
, int state
);
159 wxSize
GetSize() const;
162 virtual bool HasEditorCtrl();
163 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
164 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
170 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
173 // ---------------------------------------------------------
174 // wxDataViewBitmapRenderer
175 // ---------------------------------------------------------
177 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewCustomRenderer
180 wxDataViewBitmapRenderer( const wxString
&varianttype
= wxT("wxBitmap"),
181 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
182 int align
= wxDVR_DEFAULT_ALIGNMENT
);
184 bool SetValue( const wxVariant
&value
);
185 bool GetValue( wxVariant
&value
) const;
187 bool Render( wxRect cell
, wxDC
*dc
, int state
);
188 wxSize
GetSize() const;
195 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
198 // ---------------------------------------------------------
199 // wxDataViewToggleRenderer
200 // ---------------------------------------------------------
202 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewCustomRenderer
205 wxDataViewToggleRenderer( const wxString
&varianttype
= wxT("bool"),
206 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
207 int align
= wxDVR_DEFAULT_ALIGNMENT
);
209 bool SetValue( const wxVariant
&value
);
210 bool GetValue( wxVariant
&value
) const;
212 bool Render( wxRect cell
, wxDC
*dc
, int state
);
213 bool Activate( wxRect cell
, wxDataViewListModel
*model
, unsigned int col
,
215 wxSize
GetSize() const;
221 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
224 // ---------------------------------------------------------
225 // wxDataViewProgressRenderer
226 // ---------------------------------------------------------
228 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
231 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
232 const wxString
&varianttype
= wxT("long"),
233 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
234 int align
= wxDVR_DEFAULT_ALIGNMENT
);
235 virtual ~wxDataViewProgressRenderer();
237 bool SetValue( const wxVariant
&value
);
238 bool GetValue( wxVariant
& value
) const;
240 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
241 virtual wxSize
GetSize() const;
248 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
251 // ---------------------------------------------------------
252 // wxDataViewDateRenderer
253 // ---------------------------------------------------------
255 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewCustomRenderer
258 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
259 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
260 int align
= wxDVR_DEFAULT_ALIGNMENT
);
262 bool SetValue( const wxVariant
&value
);
263 bool GetValue( wxVariant
& value
) const;
265 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
266 virtual wxSize
GetSize() const;
267 virtual bool Activate( wxRect cell
,
268 wxDataViewListModel
*model
, unsigned int col
, unsigned int row
);
274 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
277 // ---------------------------------------------------------
279 // ---------------------------------------------------------
281 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
283 friend class wxDataViewHeaderWindowBase
;
284 friend class wxDataViewHeaderWindow
;
285 friend class wxDataViewHeaderWindowMSW
;
288 wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*renderer
,
289 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
290 wxAlignment align
= wxALIGN_CENTER
,
291 int flags
= wxDATAVIEW_COL_RESIZABLE
);
292 wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
293 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
294 wxAlignment align
= wxALIGN_CENTER
,
295 int flags
= wxDATAVIEW_COL_RESIZABLE
);
296 virtual ~wxDataViewColumn();
300 virtual void SetTitle( const wxString
&title
)
302 virtual void SetAlignment( wxAlignment align
)
304 virtual void SetMinWidth( int minWidth
)
305 { m_minWidth
=minWidth
; }
306 virtual void SetWidth( int width
);
307 virtual void SetSortable( bool sortable
);
308 virtual void SetResizeable( bool resizeable
);
309 virtual void SetHidden( bool hidden
);
310 virtual void SetSortOrder( bool ascending
);
315 virtual wxString
GetTitle() const
317 virtual wxAlignment
GetAlignment() const
319 virtual int GetWidth() const
321 virtual int GetMinWidth() const
322 { return m_minWidth
; }
323 virtual bool IsSortable() const
324 { return (m_flags
& wxDATAVIEW_COL_SORTABLE
) != 0; }
325 virtual bool IsResizeable() const
326 { return (m_flags
& wxDATAVIEW_COL_RESIZABLE
) != 0; }
327 virtual bool IsHidden() const
328 { return (m_flags
& wxDATAVIEW_COL_HIDDEN
) != 0; }
329 virtual bool IsSortOrderAscending() const;
339 void Init(int width
);
341 // like SetWidth() but does not ask the header window of the
342 // wxDataViewCtrl to reflect the width-change.
343 void SetInternalWidth(int width
);
346 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
349 // ---------------------------------------------------------
351 // ---------------------------------------------------------
353 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
,
354 public wxScrollHelperNative
356 friend class wxDataViewMainWindow
;
357 friend class wxDataViewHeaderWindowBase
;
358 friend class wxDataViewHeaderWindow
;
359 friend class wxDataViewHeaderWindowMSW
;
360 friend class wxDataViewColumn
;
363 wxDataViewCtrl() : wxScrollHelperNative(this)
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 Create(parent
, id
, pos
, size
, style
, validator
);
377 virtual ~wxDataViewCtrl();
381 bool Create(wxWindow
*parent
, wxWindowID id
,
382 const wxPoint
& pos
= wxDefaultPosition
,
383 const wxSize
& size
= wxDefaultSize
, long style
= 0,
384 const wxValidator
& validator
= wxDefaultValidator
);
386 virtual bool AssociateModel( wxDataViewListModel
*model
);
387 virtual bool AppendColumn( wxDataViewColumn
*col
);
389 virtual void SetSelection( int row
); // -1 for unselect
390 virtual void SetSelectionRange( unsigned int from
, unsigned int to
);
391 virtual void SetSelections( const wxArrayInt
& aSelections
);
392 virtual void Unselect( unsigned int row
);
394 virtual bool IsSelected( unsigned int row
) const;
395 virtual int GetSelection() const;
396 virtual int GetSelections(wxArrayInt
& aSelections
) const;
398 public: // utility functions not part of the API
400 // returns the "best" width for the idx-th column
401 unsigned int GetBestColumnWidth(int WXUNUSED(idx
)) const
403 return GetClientSize().GetWidth() / GetColumnCount();
406 // updates the header window after a change in a column setting
407 void OnColumnChange();
409 wxDataViewMainWindow
* GetMainWindow() { return m_clientArea
; }
412 wxDataViewListModelNotifier
*m_notifier
;
413 wxDataViewMainWindow
*m_clientArea
;
414 wxDataViewHeaderWindow
*m_headerArea
;
417 void OnSize( wxSizeEvent
&event
);
419 // we need to return a special WM_GETDLGCODE value to process just the
420 // arrows but let the other navigation characters through
422 virtual WXLRESULT
MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
425 WX_FORWARD_TO_SCROLL_HELPER()
428 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
429 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
430 DECLARE_EVENT_TABLE()
434 #endif // __GENERICDATAVIEWCTRLH__