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_CORE wxDataViewCtrl
;
23 class WXDLLIMPEXP_FWD_CORE wxDataViewCtrlInternal
;
26 // ---------------------------------------------------------
28 // ---------------------------------------------------------
30 class wxDataViewRenderer
: public wxDataViewRendererBase
33 wxDataViewRenderer( const wxString
&varianttype
,
34 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
35 int align
= wxDVR_DEFAULT_ALIGNMENT
);
38 GtkCellRenderer
* GetGtkHandle() { return m_renderer
; }
40 virtual void SetMode( wxDataViewCellMode mode
);
41 virtual wxDataViewCellMode
GetMode() const;
43 virtual void SetAlignment( int align
);
44 virtual int GetAlignment() const;
47 GtkCellRenderer
*m_renderer
;
50 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer
)
53 // ---------------------------------------------------------
54 // wxDataViewTextRenderer
55 // ---------------------------------------------------------
57 class wxDataViewTextRenderer
: public wxDataViewRenderer
60 wxDataViewTextRenderer( const wxString
&varianttype
= wxT("string"),
61 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
62 int align
= wxDVR_DEFAULT_ALIGNMENT
);
64 bool SetValue( const wxVariant
&value
);
65 bool GetValue( wxVariant
&value
) const;
67 void SetAlignment( int align
);
70 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
73 // ---------------------------------------------------------
74 // wxDataViewBitmapRenderer
75 // ---------------------------------------------------------
77 class wxDataViewBitmapRenderer
: public wxDataViewRenderer
80 wxDataViewBitmapRenderer( const wxString
&varianttype
= wxT("wxBitmap"),
81 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
82 int align
= wxDVR_DEFAULT_ALIGNMENT
);
84 bool SetValue( const wxVariant
&value
);
85 bool GetValue( wxVariant
&value
) const;
88 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
91 // ---------------------------------------------------------
92 // wxDataViewToggleRenderer
93 // ---------------------------------------------------------
95 class wxDataViewToggleRenderer
: public wxDataViewRenderer
98 wxDataViewToggleRenderer( const wxString
&varianttype
= wxT("bool"),
99 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
100 int align
= wxDVR_DEFAULT_ALIGNMENT
);
102 bool SetValue( const wxVariant
&value
);
103 bool GetValue( wxVariant
&value
) const;
106 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
109 // ---------------------------------------------------------
110 // wxDataViewCustomRenderer
111 // ---------------------------------------------------------
113 class wxDataViewCustomRenderer
: public wxDataViewRenderer
116 wxDataViewCustomRenderer( const wxString
&varianttype
= wxT("string"),
117 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
118 int align
= wxDVR_DEFAULT_ALIGNMENT
,
119 bool no_init
= false );
120 virtual ~wxDataViewCustomRenderer();
123 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
) = 0;
124 virtual wxSize
GetSize() const = 0;
126 virtual bool Activate( wxRect cell
,
127 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
)
130 virtual bool LeftClick( wxPoint cursor
, wxRect cell
,
131 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
)
133 virtual bool RightClick( wxPoint cursor
, wxRect cell
,
134 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
)
136 virtual bool StartDrag( wxPoint cursor
, wxRect cell
,
137 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
)
140 // Create DC on request
141 virtual wxDC
*GetDC();
146 bool Init(wxDataViewCellMode mode
, int align
);
152 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
155 // ---------------------------------------------------------
156 // wxDataViewProgressRenderer
157 // ---------------------------------------------------------
159 class wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
162 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
163 const wxString
&varianttype
= wxT("long"),
164 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
165 int align
= wxDVR_DEFAULT_ALIGNMENT
);
166 virtual ~wxDataViewProgressRenderer();
168 bool SetValue( const wxVariant
&value
);
169 bool GetValue( wxVariant
&value
) const;
171 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
172 virtual wxSize
GetSize() const;
179 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
182 // ---------------------------------------------------------
183 // wxDataViewDateRenderer
184 // ---------------------------------------------------------
186 class wxDataViewDateRenderer
: public wxDataViewCustomRenderer
189 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
190 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
191 int align
= wxDVR_DEFAULT_ALIGNMENT
);
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;
198 virtual bool Activate( wxRect cell
,
199 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
);
205 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
208 // ---------------------------------------------------------
210 // ---------------------------------------------------------
212 class WXDLLIMPEXP_CORE wxDataViewColumn
: public wxDataViewColumnBase
215 wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*renderer
,
216 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
217 wxAlignment align
= wxALIGN_CENTER
,
218 int flags
= wxDATAVIEW_COL_RESIZABLE
);
219 wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
220 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
221 wxAlignment align
= wxALIGN_CENTER
,
222 int flags
= wxDATAVIEW_COL_RESIZABLE
);
224 virtual ~wxDataViewColumn();
229 virtual void SetTitle( const wxString
&title
);
230 virtual void SetBitmap( const wxBitmap
&bitmap
);
232 virtual void SetOwner( wxDataViewCtrl
*owner
);
234 virtual void SetAlignment( wxAlignment align
);
236 virtual void SetSortable( bool sortable
);
237 virtual void SetSortOrder( bool ascending
);
239 virtual void SetResizeable( bool resizeable
);
240 virtual void SetHidden( bool hidden
);
242 virtual void SetMinWidth( int minWidth
);
243 virtual void SetWidth( int width
);
248 virtual wxString
GetTitle() const;
249 virtual wxAlignment
GetAlignment() const;
251 virtual bool IsSortable() const;
252 virtual bool IsSortOrderAscending() const;
253 virtual bool IsResizeable() const;
254 virtual bool IsHidden() const;
256 virtual int GetWidth() const;
257 virtual int GetMinWidth() const;
260 GtkWidget
* GetGtkHandle() { return m_column
; }
263 // holds the GTK handle
266 // delayed connection to mouse events
267 friend class wxDataViewCtrl
;
268 void OnInternalIdle();
271 void Init(wxAlignment align
, int flags
, int width
);
274 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
277 // ---------------------------------------------------------
279 // ---------------------------------------------------------
281 class WXDLLIMPEXP_CORE wxDataViewCtrl
: public wxDataViewCtrlBase
289 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
290 const wxPoint
& pos
= wxDefaultPosition
,
291 const wxSize
& size
= wxDefaultSize
, long style
= 0,
292 const wxValidator
& validator
= wxDefaultValidator
)
294 Create(parent
, id
, pos
, size
, style
, validator
);
297 virtual ~wxDataViewCtrl();
301 bool Create(wxWindow
*parent
, wxWindowID id
,
302 const wxPoint
& pos
= wxDefaultPosition
,
303 const wxSize
& size
= wxDefaultSize
, long style
= 0,
304 const wxValidator
& validator
= wxDefaultValidator
);
306 virtual bool AssociateModel( wxDataViewModel
*model
);
307 virtual bool AppendColumn( wxDataViewColumn
*col
);
310 virtual wxDataViewItem
GetSelection();
313 static wxVisualAttributes
314 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
316 wxWindow
*GetMainWindow() { return (wxWindow
*) this; }
318 GtkWidget
*GtkGetTreeView() { return m_treeview
; }
319 wxDataViewCtrlInternal
* GtkGetInternal() { return m_internal
; }
322 virtual void DoSetExpanderColumn();
323 virtual void DoSetIndent();
326 friend class wxDataViewCtrlDC
;
327 friend class wxDataViewColumn
;
328 friend class wxGtkDataViewModelNotifier
;
329 GtkWidget
*m_treeview
;
330 wxDataViewModelNotifier
*m_notifier
;
331 wxDataViewCtrlInternal
*m_internal
;
334 virtual void OnInternalIdle();
336 void GtkEnableSelectionEvents();
337 void GtkDisableSelectionEvents();
340 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
341 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
345 #endif // __GTKDATAVIEWCTRLH__