1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/dataview.h
3 // Purpose: wxDataViewCtrl GTK+2 implementation header
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef __GTKDATAVIEWCTRLH__
11 #define __GTKDATAVIEWCTRLH__
14 #include "wx/object.h"
16 #include "wx/control.h"
18 // ---------------------------------------------------------
20 // ---------------------------------------------------------
22 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl
;
23 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrlInternal
;
26 // ---------------------------------------------------------
28 // ---------------------------------------------------------
30 class WXDLLIMPEXP_ADV wxDataViewRenderer
: public wxDataViewRendererBase
33 wxDataViewRenderer( const wxString
&varianttype
,
34 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
35 int align
= wxDVR_DEFAULT_ALIGNMENT
);
37 virtual void SetMode( wxDataViewCellMode mode
);
38 virtual wxDataViewCellMode
GetMode() const;
40 virtual void SetAlignment( int align
);
41 virtual int GetAlignment() const;
44 GtkCellRenderer
* GetGtkHandle() { return m_renderer
; }
45 void GtkInitHandlers();
48 GtkCellRenderer
*m_renderer
;
51 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer
)
54 // ---------------------------------------------------------
55 // wxDataViewTextRenderer
56 // ---------------------------------------------------------
58 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewRenderer
61 wxDataViewTextRenderer( const wxString
&varianttype
= wxT("string"),
62 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
63 int align
= wxDVR_DEFAULT_ALIGNMENT
);
65 bool SetValue( const wxVariant
&value
);
66 bool GetValue( wxVariant
&value
) const;
68 void SetAlignment( int align
);
71 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
74 // ---------------------------------------------------------
75 // wxDataViewBitmapRenderer
76 // ---------------------------------------------------------
78 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewRenderer
81 wxDataViewBitmapRenderer( const wxString
&varianttype
= wxT("wxBitmap"),
82 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
83 int align
= wxDVR_DEFAULT_ALIGNMENT
);
85 bool SetValue( const wxVariant
&value
);
86 bool GetValue( wxVariant
&value
) const;
89 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
92 // ---------------------------------------------------------
93 // wxDataViewToggleRenderer
94 // ---------------------------------------------------------
96 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewRenderer
99 wxDataViewToggleRenderer( const wxString
&varianttype
= wxT("bool"),
100 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
101 int align
= wxDVR_DEFAULT_ALIGNMENT
);
103 bool SetValue( const wxVariant
&value
);
104 bool GetValue( wxVariant
&value
) const;
107 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
110 // ---------------------------------------------------------
111 // wxDataViewCustomRenderer
112 // ---------------------------------------------------------
114 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewRenderer
117 wxDataViewCustomRenderer( const wxString
&varianttype
= wxT("string"),
118 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
119 int align
= wxDVR_DEFAULT_ALIGNMENT
,
120 bool no_init
= false );
121 virtual ~wxDataViewCustomRenderer();
124 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
) = 0;
126 void RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
);
128 virtual wxSize
GetSize() const = 0;
130 virtual bool Activate( wxRect cell
,
131 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
)
134 virtual bool LeftClick( wxPoint cursor
, wxRect cell
,
135 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
)
137 virtual bool RightClick( wxPoint cursor
, wxRect cell
,
138 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
)
140 virtual bool StartDrag( wxPoint cursor
, wxRect cell
,
141 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
)
144 // Create DC on request
145 virtual wxDC
*GetDC();
150 bool Init(wxDataViewCellMode mode
, int align
);
156 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
159 // ---------------------------------------------------------
160 // wxDataViewProgressRenderer
161 // ---------------------------------------------------------
163 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
166 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
167 const wxString
&varianttype
= wxT("long"),
168 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
169 int align
= wxDVR_DEFAULT_ALIGNMENT
);
170 virtual ~wxDataViewProgressRenderer();
172 bool SetValue( const wxVariant
&value
);
173 bool GetValue( wxVariant
&value
) const;
175 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
176 virtual wxSize
GetSize() const;
183 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
186 // ---------------------------------------------------------
187 // wxDataViewIconTextRenderer
188 // ---------------------------------------------------------
190 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewCustomRenderer
193 wxDataViewIconTextRenderer( const wxString
&varianttype
= wxT("wxDataViewIconText"),
194 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
195 int align
= wxDVR_DEFAULT_ALIGNMENT
);
196 virtual ~wxDataViewIconTextRenderer();
198 bool SetValue( const wxVariant
&value
);
199 bool GetValue( wxVariant
&value
) const;
201 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
202 virtual wxSize
GetSize() const;
204 virtual bool HasEditorCtrl() { return true; }
205 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
206 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
209 wxDataViewIconText m_value
;
212 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
215 // ---------------------------------------------------------
216 // wxDataViewDateRenderer
217 // ---------------------------------------------------------
219 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewCustomRenderer
222 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
223 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
224 int align
= wxDVR_DEFAULT_ALIGNMENT
);
226 bool SetValue( const wxVariant
&value
);
227 bool GetValue( wxVariant
&value
) const;
229 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
230 virtual wxSize
GetSize() const;
231 virtual bool Activate( wxRect cell
,
232 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
);
238 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
241 // ---------------------------------------------------------
243 // ---------------------------------------------------------
245 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
248 wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*renderer
,
249 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
250 wxAlignment align
= wxALIGN_CENTER
,
251 int flags
= wxDATAVIEW_COL_RESIZABLE
);
252 wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
253 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
254 wxAlignment align
= wxALIGN_CENTER
,
255 int flags
= wxDATAVIEW_COL_RESIZABLE
);
257 virtual ~wxDataViewColumn();
262 virtual void SetTitle( const wxString
&title
);
263 virtual void SetBitmap( const wxBitmap
&bitmap
);
265 virtual void SetOwner( wxDataViewCtrl
*owner
);
267 virtual void SetAlignment( wxAlignment align
);
269 virtual void SetSortable( bool sortable
);
270 virtual void SetSortOrder( bool ascending
);
272 virtual void SetResizeable( bool resizeable
);
273 virtual void SetHidden( bool hidden
);
275 virtual void SetMinWidth( int minWidth
);
276 virtual void SetWidth( int width
);
281 virtual wxString
GetTitle() const;
282 virtual wxAlignment
GetAlignment() const;
284 virtual bool IsSortable() const;
285 virtual bool IsSortOrderAscending() const;
286 virtual bool IsResizeable() const;
287 virtual bool IsHidden() const;
289 virtual int GetWidth() const;
290 virtual int GetMinWidth() const;
293 GtkWidget
* GetGtkHandle() { return m_column
; }
294 GtkWidget
* GetConstGtkHandle() const { return m_column
; }
297 // holds the GTK handle
300 // delayed connection to mouse events
301 friend class wxDataViewCtrl
;
302 void OnInternalIdle();
305 void Init(wxAlignment align
, int flags
, int width
);
308 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
311 WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn
, wxDataViewColumnList
,
312 class WXDLLIMPEXP_ADV
);
314 // ---------------------------------------------------------
316 // ---------------------------------------------------------
318 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
326 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
327 const wxPoint
& pos
= wxDefaultPosition
,
328 const wxSize
& size
= wxDefaultSize
, long style
= 0,
329 const wxValidator
& validator
= wxDefaultValidator
)
331 Create(parent
, id
, pos
, size
, style
, validator
);
334 virtual ~wxDataViewCtrl();
338 bool Create(wxWindow
*parent
, wxWindowID id
,
339 const wxPoint
& pos
= wxDefaultPosition
,
340 const wxSize
& size
= wxDefaultSize
, long style
= 0,
341 const wxValidator
& validator
= wxDefaultValidator
);
343 virtual bool AssociateModel( wxDataViewModel
*model
);
345 virtual bool PrependColumn( wxDataViewColumn
*col
);
346 virtual bool AppendColumn( wxDataViewColumn
*col
);
347 virtual unsigned int GetColumnCount() const;
348 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const;
349 virtual bool DeleteColumn( wxDataViewColumn
*column
);
350 virtual bool ClearColumns();
351 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const;
353 virtual wxDataViewColumn
*GetSortingColumn() const;
355 virtual wxDataViewItem
GetSelection() const;
356 virtual int GetSelections( wxDataViewItemArray
& sel
) const;
357 virtual void SetSelections( const wxDataViewItemArray
& sel
);
358 virtual void Select( const wxDataViewItem
& item
);
359 virtual void Unselect( const wxDataViewItem
& item
);
360 virtual bool IsSelected( const wxDataViewItem
& item
) const;
361 virtual void SelectAll();
362 virtual void UnselectAll();
364 virtual void EnsureVisible( const wxDataViewItem
& item
,
365 const wxDataViewColumn
*column
= NULL
);
366 virtual void HitTest( const wxPoint
&point
,
367 wxDataViewItem
&item
,
368 wxDataViewColumn
*&column
) const;
369 virtual wxRect
GetItemRect( const wxDataViewItem
&item
,
370 const wxDataViewColumn
*column
= NULL
) const;
372 virtual void Expand( const wxDataViewItem
& item
);
373 virtual void Collapse( const wxDataViewItem
& item
);
375 static wxVisualAttributes
376 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
378 wxWindow
*GetMainWindow() { return (wxWindow
*) this; }
380 GtkWidget
*GtkGetTreeView() { return m_treeview
; }
381 wxDataViewCtrlInternal
* GtkGetInternal() { return m_internal
; }
384 virtual void DoSetExpanderColumn();
385 virtual void DoSetIndent();
388 friend class wxDataViewCtrlDC
;
389 friend class wxDataViewColumn
;
390 friend class wxGtkDataViewModelNotifier
;
391 GtkWidget
*m_treeview
;
392 wxDataViewModelNotifier
*m_notifier
;
393 wxDataViewCtrlInternal
*m_internal
;
394 wxDataViewColumnList m_cols
;
397 virtual void OnInternalIdle();
399 void GtkEnableSelectionEvents();
400 void GtkDisableSelectionEvents();
403 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
404 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
408 #endif // __GTKDATAVIEWCTRLH__