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 RightClick( wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
),
154 wxDataViewModel
*WXUNUSED(model
), const wxDataViewItem
&WXUNUSED(item
), unsigned int WXUNUSED(col
) )
156 virtual bool StartDrag( wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
),
157 wxDataViewModel
*WXUNUSED(model
), const wxDataViewItem
&WXUNUSED(item
), unsigned int WXUNUSED(col
) )
160 // Create DC on request
161 virtual wxDC
*GetDC();
166 bool Init(wxDataViewCellMode mode
, int align
);
172 // Internal, temporay for RenderText.
173 GtkCellRenderer
*m_text_renderer
;
176 void *background_area
;
182 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
185 // ---------------------------------------------------------
186 // wxDataViewProgressRenderer
187 // ---------------------------------------------------------
189 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
192 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
193 const wxString
&varianttype
= wxT("long"),
194 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
195 int align
= wxDVR_DEFAULT_ALIGNMENT
);
196 virtual ~wxDataViewProgressRenderer();
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;
209 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
212 // ---------------------------------------------------------
213 // wxDataViewIconTextRenderer
214 // ---------------------------------------------------------
216 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewCustomRenderer
219 wxDataViewIconTextRenderer( const wxString
&varianttype
= wxT("wxDataViewIconText"),
220 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
221 int align
= wxDVR_DEFAULT_ALIGNMENT
);
222 virtual ~wxDataViewIconTextRenderer();
224 bool SetValue( const wxVariant
&value
);
225 bool GetValue( wxVariant
&value
) const;
227 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
228 virtual wxSize
GetSize() const;
230 virtual bool HasEditorCtrl() { return true; }
231 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
232 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
235 wxDataViewIconText m_value
;
238 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
241 // ---------------------------------------------------------
242 // wxDataViewDateRenderer
243 // ---------------------------------------------------------
245 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewCustomRenderer
248 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
249 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
250 int align
= wxDVR_DEFAULT_ALIGNMENT
);
252 bool SetValue( const wxVariant
&value
);
253 bool GetValue( wxVariant
&value
) const;
255 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
256 virtual wxSize
GetSize() const;
257 virtual bool Activate( wxRect cell
,
258 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
);
264 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
267 // ---------------------------------------------------------
269 // ---------------------------------------------------------
271 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
274 wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*renderer
,
275 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
276 wxAlignment align
= wxALIGN_CENTER
,
277 int flags
= wxDATAVIEW_COL_RESIZABLE
);
278 wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
279 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
280 wxAlignment align
= wxALIGN_CENTER
,
281 int flags
= wxDATAVIEW_COL_RESIZABLE
);
283 virtual ~wxDataViewColumn();
288 virtual void SetTitle( const wxString
&title
);
289 virtual void SetBitmap( const wxBitmap
&bitmap
);
291 virtual void SetOwner( wxDataViewCtrl
*owner
);
293 virtual void SetAlignment( wxAlignment align
);
295 virtual void SetSortable( bool sortable
);
296 virtual void SetSortOrder( bool ascending
);
298 virtual void SetResizeable( bool resizeable
);
299 virtual void SetHidden( bool hidden
);
301 virtual void SetMinWidth( int minWidth
);
302 virtual void SetWidth( int width
);
304 virtual void SetReorderable( bool reorderable
);
308 virtual wxString
GetTitle() const;
309 virtual wxAlignment
GetAlignment() const;
311 virtual bool IsSortable() const;
312 virtual bool IsSortOrderAscending() const;
313 virtual bool IsResizeable() const;
314 virtual bool IsHidden() const;
316 virtual int GetWidth() const;
317 virtual int GetMinWidth() const;
319 virtual bool IsReorderable() const;
322 GtkWidget
* GetGtkHandle() { return m_column
; }
323 GtkWidget
* GetConstGtkHandle() const { return m_column
; }
326 // holds the GTK handle
329 // delayed connection to mouse events
330 friend class wxDataViewCtrl
;
331 void OnInternalIdle();
334 void Init(wxAlignment align
, int flags
, int width
);
337 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
340 WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn
, wxDataViewColumnList
,
341 class WXDLLIMPEXP_ADV
);
343 // ---------------------------------------------------------
345 // ---------------------------------------------------------
347 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
355 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
356 const wxPoint
& pos
= wxDefaultPosition
,
357 const wxSize
& size
= wxDefaultSize
, long style
= 0,
358 const wxValidator
& validator
= wxDefaultValidator
)
360 Create(parent
, id
, pos
, size
, style
, validator
);
363 virtual ~wxDataViewCtrl();
367 bool Create(wxWindow
*parent
, wxWindowID id
,
368 const wxPoint
& pos
= wxDefaultPosition
,
369 const wxSize
& size
= wxDefaultSize
, long style
= 0,
370 const wxValidator
& validator
= wxDefaultValidator
);
372 virtual bool AssociateModel( wxDataViewModel
*model
);
374 virtual bool PrependColumn( wxDataViewColumn
*col
);
375 virtual bool AppendColumn( wxDataViewColumn
*col
);
376 virtual unsigned int GetColumnCount() const;
377 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const;
378 virtual bool DeleteColumn( wxDataViewColumn
*column
);
379 virtual bool ClearColumns();
380 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const;
382 virtual wxDataViewColumn
*GetSortingColumn() const;
384 virtual wxDataViewItem
GetSelection() const;
385 virtual int GetSelections( wxDataViewItemArray
& sel
) const;
386 virtual void SetSelections( const wxDataViewItemArray
& sel
);
387 virtual void Select( const wxDataViewItem
& item
);
388 virtual void Unselect( const wxDataViewItem
& item
);
389 virtual bool IsSelected( const wxDataViewItem
& item
) const;
390 virtual void SelectAll();
391 virtual void UnselectAll();
393 virtual void EnsureVisible( const wxDataViewItem
& item
,
394 const wxDataViewColumn
*column
= NULL
);
395 virtual void HitTest( const wxPoint
&point
,
396 wxDataViewItem
&item
,
397 wxDataViewColumn
*&column
) const;
398 virtual wxRect
GetItemRect( const wxDataViewItem
&item
,
399 const wxDataViewColumn
*column
= NULL
) const;
401 virtual void Expand( const wxDataViewItem
& item
);
402 virtual void Collapse( const wxDataViewItem
& item
);
404 static wxVisualAttributes
405 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
407 wxWindow
*GetMainWindow() { return (wxWindow
*) this; }
409 GtkWidget
*GtkGetTreeView() { return m_treeview
; }
410 wxDataViewCtrlInternal
* GtkGetInternal() { return m_internal
; }
412 virtual void OnInternalIdle();
415 virtual void DoSetExpanderColumn();
416 virtual void DoSetIndent();
419 friend class wxDataViewCtrlDCImpl
;
420 friend class wxDataViewColumn
;
421 friend class wxGtkDataViewModelNotifier
;
422 friend class wxDataViewCtrlInternal
;
424 GtkWidget
*m_treeview
;
425 wxDataViewModelNotifier
*m_notifier
;
426 wxDataViewCtrlInternal
*m_internal
;
427 wxDataViewColumnList m_cols
;
429 void GtkEnableSelectionEvents();
430 void GtkDisableSelectionEvents();
432 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
433 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
437 #endif // _WX_GTKDATAVIEWCTRL_H_