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
);
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 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 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 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 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;
125 virtual wxSize
GetSize() const = 0;
127 virtual bool Activate( wxRect cell
,
128 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
)
131 virtual bool LeftClick( wxPoint cursor
, wxRect cell
,
132 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
)
134 virtual bool RightClick( wxPoint cursor
, wxRect cell
,
135 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
)
137 virtual bool StartDrag( wxPoint cursor
, wxRect cell
,
138 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
)
141 // Create DC on request
142 virtual wxDC
*GetDC();
147 bool Init(wxDataViewCellMode mode
, int align
);
153 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
156 // ---------------------------------------------------------
157 // wxDataViewProgressRenderer
158 // ---------------------------------------------------------
160 class wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
163 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
164 const wxString
&varianttype
= wxT("long"),
165 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
166 int align
= wxDVR_DEFAULT_ALIGNMENT
);
167 virtual ~wxDataViewProgressRenderer();
169 bool SetValue( const wxVariant
&value
);
170 bool GetValue( wxVariant
&value
) const;
172 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
173 virtual wxSize
GetSize() const;
180 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
183 // ---------------------------------------------------------
184 // wxDataViewIconTextRenderer
185 // ---------------------------------------------------------
187 class wxDataViewIconTextRenderer
: public wxDataViewCustomRenderer
190 wxDataViewIconTextRenderer( const wxString
&varianttype
= wxT("wxDataViewIconText"),
191 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
192 int align
= wxDVR_DEFAULT_ALIGNMENT
);
193 virtual ~wxDataViewIconTextRenderer();
195 bool SetValue( const wxVariant
&value
);
196 bool GetValue( wxVariant
&value
) const;
198 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
199 virtual wxSize
GetSize() const;
201 virtual bool HasEditorCtrl() { return true; }
202 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
203 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
206 wxDataViewIconText m_value
;
209 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
212 // ---------------------------------------------------------
213 // wxDataViewDateRenderer
214 // ---------------------------------------------------------
216 class wxDataViewDateRenderer
: public wxDataViewCustomRenderer
219 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
220 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
221 int align
= wxDVR_DEFAULT_ALIGNMENT
);
223 bool SetValue( const wxVariant
&value
);
224 bool GetValue( wxVariant
&value
) const;
226 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
227 virtual wxSize
GetSize() const;
228 virtual bool Activate( wxRect cell
,
229 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
);
235 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
238 // ---------------------------------------------------------
240 // ---------------------------------------------------------
242 class WXDLLIMPEXP_CORE wxDataViewColumn
: public wxDataViewColumnBase
245 wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*renderer
,
246 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
247 wxAlignment align
= wxALIGN_CENTER
,
248 int flags
= wxDATAVIEW_COL_RESIZABLE
);
249 wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
250 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
251 wxAlignment align
= wxALIGN_CENTER
,
252 int flags
= wxDATAVIEW_COL_RESIZABLE
);
254 virtual ~wxDataViewColumn();
259 virtual void SetTitle( const wxString
&title
);
260 virtual void SetBitmap( const wxBitmap
&bitmap
);
262 virtual void SetOwner( wxDataViewCtrl
*owner
);
264 virtual void SetAlignment( wxAlignment align
);
266 virtual void SetSortable( bool sortable
);
267 virtual void SetSortOrder( bool ascending
);
269 virtual void SetResizeable( bool resizeable
);
270 virtual void SetHidden( bool hidden
);
272 virtual void SetMinWidth( int minWidth
);
273 virtual void SetWidth( int width
);
278 virtual wxString
GetTitle() const;
279 virtual wxAlignment
GetAlignment() const;
281 virtual bool IsSortable() const;
282 virtual bool IsSortOrderAscending() const;
283 virtual bool IsResizeable() const;
284 virtual bool IsHidden() const;
286 virtual int GetWidth() const;
287 virtual int GetMinWidth() const;
290 GtkWidget
* GetGtkHandle() { return m_column
; }
293 // holds the GTK handle
296 // delayed connection to mouse events
297 friend class wxDataViewCtrl
;
298 void OnInternalIdle();
301 void Init(wxAlignment align
, int flags
, int width
);
304 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
307 WX_DECLARE_LIST(wxDataViewColumn
, wxDataViewColumnList
);
309 // ---------------------------------------------------------
311 // ---------------------------------------------------------
313 class WXDLLIMPEXP_CORE wxDataViewCtrl
: public wxDataViewCtrlBase
321 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
322 const wxPoint
& pos
= wxDefaultPosition
,
323 const wxSize
& size
= wxDefaultSize
, long style
= 0,
324 const wxValidator
& validator
= wxDefaultValidator
)
326 Create(parent
, id
, pos
, size
, style
, validator
);
329 virtual ~wxDataViewCtrl();
333 bool Create(wxWindow
*parent
, wxWindowID id
,
334 const wxPoint
& pos
= wxDefaultPosition
,
335 const wxSize
& size
= wxDefaultSize
, long style
= 0,
336 const wxValidator
& validator
= wxDefaultValidator
);
338 virtual bool AssociateModel( wxDataViewModel
*model
);
340 virtual bool AppendColumn( wxDataViewColumn
*col
);
341 virtual unsigned int GetColumnCount() const;
342 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const;
343 virtual bool DeleteColumn( wxDataViewColumn
*column
);
344 virtual bool ClearColumns();
346 virtual wxDataViewItem
GetSelection() const;
347 virtual int GetSelections( wxDataViewItemArray
& sel
) const;
348 virtual void SetSelections( const wxDataViewItemArray
& sel
);
349 virtual void Select( const wxDataViewItem
& item
);
350 virtual void Unselect( const wxDataViewItem
& item
);
351 virtual bool IsSelected( const wxDataViewItem
& item
) const;
352 virtual void SelectAll();
353 virtual void UnselectAll();
355 virtual void EnsureVisible( const wxDataViewItem
& item
,
356 const wxDataViewColumn
*column
= NULL
);
357 virtual void HitTest( const wxPoint
&point
,
358 wxDataViewItem
&item
,
359 wxDataViewColumn
*&column
) const;
360 virtual wxRect
GetItemRect( const wxDataViewItem
&item
,
361 const wxDataViewColumn
*column
= NULL
) const;
363 virtual void Expand( const wxDataViewItem
& item
);
364 virtual void Collapse( const wxDataViewItem
& item
);
366 static wxVisualAttributes
367 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
369 wxWindow
*GetMainWindow() { return (wxWindow
*) this; }
371 GtkWidget
*GtkGetTreeView() { return m_treeview
; }
372 wxDataViewCtrlInternal
* GtkGetInternal() { return m_internal
; }
375 virtual void DoSetExpanderColumn();
376 virtual void DoSetIndent();
379 friend class wxDataViewCtrlDC
;
380 friend class wxDataViewColumn
;
381 friend class wxGtkDataViewModelNotifier
;
382 GtkWidget
*m_treeview
;
383 wxDataViewModelNotifier
*m_notifier
;
384 wxDataViewCtrlInternal
*m_internal
;
385 wxDataViewColumnList m_cols
;
388 virtual void OnInternalIdle();
390 void GtkEnableSelectionEvents();
391 void GtkDisableSelectionEvents();
394 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
395 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
399 #endif // __GTKDATAVIEWCTRLH__