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
);
309 virtual wxDataViewItem
GetSelection() const;
310 virtual int GetSelections( wxDataViewItemArray
& sel
) const;
311 virtual void SetSelections( const wxDataViewItemArray
& sel
);
312 virtual void Select( const wxDataViewItem
& item
);
313 virtual void Unselect( const wxDataViewItem
& item
);
314 virtual bool IsSelected( const wxDataViewItem
& item
) const;
315 virtual void SelectAll();
316 virtual void UnselectAll();
318 virtual void EnsureVisible( const wxDataViewItem
& item
,
319 const wxDataViewColumn
*column
= NULL
);
320 virtual void HitTest( const wxPoint
&point
,
321 wxDataViewItem
&item
,
322 wxDataViewColumn
*&column
) const;
323 virtual wxRect
GetItemRect( const wxDataViewItem
&item
,
324 const wxDataViewColumn
*column
= NULL
) const;
327 static wxVisualAttributes
328 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
330 wxWindow
*GetMainWindow() { return (wxWindow
*) this; }
332 GtkWidget
*GtkGetTreeView() { return m_treeview
; }
333 wxDataViewCtrlInternal
* GtkGetInternal() { return m_internal
; }
336 virtual void DoSetExpanderColumn();
337 virtual void DoSetIndent();
340 friend class wxDataViewCtrlDC
;
341 friend class wxDataViewColumn
;
342 friend class wxGtkDataViewModelNotifier
;
343 GtkWidget
*m_treeview
;
344 wxDataViewModelNotifier
*m_notifier
;
345 wxDataViewCtrlInternal
*m_internal
;
348 virtual void OnInternalIdle();
350 void GtkEnableSelectionEvents();
351 void GtkDisableSelectionEvents();
354 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
355 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
359 #endif // __GTKDATAVIEWCTRLH__