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 _WX_GTKDATAVIEWCTRL_H_
11 #define _WX_GTKDATAVIEWCTRL_H_
15 // ---------------------------------------------------------
17 // ---------------------------------------------------------
19 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl
;
20 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrlInternal
;
23 // ---------------------------------------------------------
25 // ---------------------------------------------------------
27 class WXDLLIMPEXP_ADV wxDataViewRenderer
: public wxDataViewRendererBase
30 wxDataViewRenderer( const wxString
&varianttype
,
31 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
32 int align
= wxDVR_DEFAULT_ALIGNMENT
);
34 virtual void SetMode( wxDataViewCellMode mode
);
35 virtual wxDataViewCellMode
GetMode() const;
37 virtual void SetAlignment( int align
);
38 virtual int GetAlignment() const;
41 GtkCellRenderer
* GetGtkHandle() { return m_renderer
; }
42 void GtkInitHandlers();
43 virtual bool GtkHasAttributes() { return false; }
46 GtkCellRenderer
*m_renderer
;
49 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer
)
52 // ---------------------------------------------------------
53 // wxDataViewTextRenderer
54 // ---------------------------------------------------------
56 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewRenderer
59 wxDataViewTextRenderer( const wxString
&varianttype
= wxT("string"),
60 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
61 int align
= wxDVR_DEFAULT_ALIGNMENT
);
63 bool SetValue( const wxVariant
&value
);
64 bool GetValue( wxVariant
&value
) const;
66 void SetAlignment( int align
);
69 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
72 // ---------------------------------------------------------
73 // wxDataViewTextRendererAttr
74 // ---------------------------------------------------------
76 class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr
: public wxDataViewTextRenderer
79 wxDataViewTextRendererAttr( const wxString
&varianttype
= wxT("string"),
80 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
81 int align
= wxDVR_DEFAULT_ALIGNMENT
);
84 bool GtkHasAttributes() { return true; }
87 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr
)
90 // ---------------------------------------------------------
91 // wxDataViewBitmapRenderer
92 // ---------------------------------------------------------
94 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewRenderer
97 wxDataViewBitmapRenderer( const wxString
&varianttype
= wxT("wxBitmap"),
98 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
99 int align
= wxDVR_DEFAULT_ALIGNMENT
);
101 bool SetValue( const wxVariant
&value
);
102 bool GetValue( wxVariant
&value
) const;
105 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
108 // ---------------------------------------------------------
109 // wxDataViewToggleRenderer
110 // ---------------------------------------------------------
112 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewRenderer
115 wxDataViewToggleRenderer( const wxString
&varianttype
= wxT("bool"),
116 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
117 int align
= wxDVR_DEFAULT_ALIGNMENT
);
119 bool SetValue( const wxVariant
&value
);
120 bool GetValue( wxVariant
&value
) const;
123 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
126 // ---------------------------------------------------------
127 // wxDataViewCustomRenderer
128 // ---------------------------------------------------------
130 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewRenderer
133 wxDataViewCustomRenderer( const wxString
&varianttype
= wxT("string"),
134 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
135 int align
= wxDVR_DEFAULT_ALIGNMENT
,
136 bool no_init
= false );
137 virtual ~wxDataViewCustomRenderer();
140 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
) = 0;
142 void RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
);
144 virtual wxSize
GetSize() const = 0;
146 virtual bool Activate( wxRect
WXUNUSED(cell
),
147 wxDataViewModel
*WXUNUSED(model
), const wxDataViewItem
&WXUNUSED(item
), unsigned int WXUNUSED(col
) )
150 virtual bool LeftClick( wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
),
151 wxDataViewModel
*WXUNUSED(model
), const wxDataViewItem
&WXUNUSED(item
), unsigned int WXUNUSED(col
) )
153 virtual bool StartDrag( wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
),
154 wxDataViewModel
*WXUNUSED(model
), const wxDataViewItem
&WXUNUSED(item
), unsigned int WXUNUSED(col
) )
157 // Create DC on request
158 virtual wxDC
*GetDC();
163 bool Init(wxDataViewCellMode mode
, int align
);
169 // Internal, temporay for RenderText.
170 GtkCellRenderer
*m_text_renderer
;
173 void *background_area
;
179 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
182 // ---------------------------------------------------------
183 // wxDataViewProgressRenderer
184 // ---------------------------------------------------------
186 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
189 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
190 const wxString
&varianttype
= wxT("long"),
191 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
192 int align
= wxDVR_DEFAULT_ALIGNMENT
);
193 virtual ~wxDataViewProgressRenderer();
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;
206 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
209 // ---------------------------------------------------------
210 // wxDataViewIconTextRenderer
211 // ---------------------------------------------------------
213 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewCustomRenderer
216 wxDataViewIconTextRenderer( const wxString
&varianttype
= wxT("wxDataViewIconText"),
217 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
218 int align
= wxDVR_DEFAULT_ALIGNMENT
);
219 virtual ~wxDataViewIconTextRenderer();
221 bool SetValue( const wxVariant
&value
);
222 bool GetValue( wxVariant
&value
) const;
224 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
225 virtual wxSize
GetSize() const;
227 virtual bool HasEditorCtrl() { return true; }
228 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
229 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
232 wxDataViewIconText m_value
;
235 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
238 // ---------------------------------------------------------
239 // wxDataViewDateRenderer
240 // ---------------------------------------------------------
242 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewCustomRenderer
245 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
246 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
247 int align
= wxDVR_DEFAULT_ALIGNMENT
);
249 bool SetValue( const wxVariant
&value
);
250 bool GetValue( wxVariant
&value
) const;
252 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
253 virtual wxSize
GetSize() const;
254 virtual bool Activate( wxRect cell
,
255 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
);
261 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
264 // ---------------------------------------------------------
266 // ---------------------------------------------------------
268 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
271 wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*renderer
,
272 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
273 wxAlignment align
= wxALIGN_CENTER
,
274 int flags
= wxDATAVIEW_COL_RESIZABLE
);
275 wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
276 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
277 wxAlignment align
= wxALIGN_CENTER
,
278 int flags
= wxDATAVIEW_COL_RESIZABLE
);
280 virtual ~wxDataViewColumn();
285 virtual void SetTitle( const wxString
&title
);
286 virtual void SetBitmap( const wxBitmap
&bitmap
);
288 virtual void SetOwner( wxDataViewCtrl
*owner
);
290 virtual void SetAlignment( wxAlignment align
);
292 virtual void SetSortable( bool sortable
);
293 virtual void SetSortOrder( bool ascending
);
295 virtual void SetResizeable( bool resizeable
);
296 virtual void SetHidden( bool hidden
);
298 virtual void SetMinWidth( int minWidth
);
299 virtual void SetWidth( int width
);
301 virtual void SetReorderable( bool reorderable
);
305 virtual wxString
GetTitle() const;
306 virtual wxAlignment
GetAlignment() const;
308 virtual bool IsSortable() const;
309 virtual bool IsSortOrderAscending() const;
310 virtual bool IsResizeable() const;
311 virtual bool IsHidden() const;
313 virtual int GetWidth() const;
314 virtual int GetMinWidth() const;
316 virtual bool IsReorderable() const;
319 GtkWidget
* GetGtkHandle() { return m_column
; }
320 GtkWidget
* GetConstGtkHandle() const { return m_column
; }
323 // holds the GTK handle
326 // delayed connection to mouse events
327 friend class wxDataViewCtrl
;
328 void OnInternalIdle();
331 void Init(wxAlignment align
, int flags
, int width
);
334 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
337 WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn
, wxDataViewColumnList
,
338 class WXDLLIMPEXP_ADV
);
340 // ---------------------------------------------------------
342 // ---------------------------------------------------------
344 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
352 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
353 const wxPoint
& pos
= wxDefaultPosition
,
354 const wxSize
& size
= wxDefaultSize
, long style
= 0,
355 const wxValidator
& validator
= wxDefaultValidator
)
357 Create(parent
, id
, pos
, size
, style
, validator
);
360 virtual ~wxDataViewCtrl();
364 bool Create(wxWindow
*parent
, wxWindowID id
,
365 const wxPoint
& pos
= wxDefaultPosition
,
366 const wxSize
& size
= wxDefaultSize
, long style
= 0,
367 const wxValidator
& validator
= wxDefaultValidator
);
369 virtual bool AssociateModel( wxDataViewModel
*model
);
371 virtual bool PrependColumn( wxDataViewColumn
*col
);
372 virtual bool AppendColumn( wxDataViewColumn
*col
);
373 virtual unsigned int GetColumnCount() const;
374 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const;
375 virtual bool DeleteColumn( wxDataViewColumn
*column
);
376 virtual bool ClearColumns();
377 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const;
379 virtual wxDataViewColumn
*GetSortingColumn() const;
381 virtual wxDataViewItem
GetSelection() const;
382 virtual int GetSelections( wxDataViewItemArray
& sel
) const;
383 virtual void SetSelections( const wxDataViewItemArray
& sel
);
384 virtual void Select( const wxDataViewItem
& item
);
385 virtual void Unselect( const wxDataViewItem
& item
);
386 virtual bool IsSelected( const wxDataViewItem
& item
) const;
387 virtual void SelectAll();
388 virtual void UnselectAll();
390 virtual void EnsureVisible( const wxDataViewItem
& item
,
391 const wxDataViewColumn
*column
= NULL
);
392 virtual void HitTest( const wxPoint
&point
,
393 wxDataViewItem
&item
,
394 wxDataViewColumn
*&column
) const;
395 virtual wxRect
GetItemRect( const wxDataViewItem
&item
,
396 const wxDataViewColumn
*column
= NULL
) const;
398 virtual void Expand( const wxDataViewItem
& item
);
399 virtual void Collapse( const wxDataViewItem
& item
);
401 static wxVisualAttributes
402 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
404 wxWindow
*GetMainWindow() { return (wxWindow
*) this; }
406 GtkWidget
*GtkGetTreeView() { return m_treeview
; }
407 wxDataViewCtrlInternal
* GtkGetInternal() { return m_internal
; }
409 virtual void OnInternalIdle();
412 virtual void DoSetExpanderColumn();
413 virtual void DoSetIndent();
416 friend class wxDataViewCtrlDCImpl
;
417 friend class wxDataViewColumn
;
418 friend class wxGtkDataViewModelNotifier
;
419 friend class wxDataViewCtrlInternal
;
421 GtkWidget
*m_treeview
;
422 wxDataViewModelNotifier
*m_notifier
;
423 wxDataViewCtrlInternal
*m_internal
;
424 wxDataViewColumnList m_cols
;
426 void GtkEnableSelectionEvents();
427 void GtkDisableSelectionEvents();
429 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
430 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
434 #endif // _WX_GTKDATAVIEWCTRL_H_