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_ADV wxDataViewCtrl
;
23 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrlInternal
;
26 // ---------------------------------------------------------
28 // ---------------------------------------------------------
30 class WXDLLIMPEXP_ADV 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 WXDLLIMPEXP_ADV 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 WXDLLIMPEXP_ADV 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 WXDLLIMPEXP_ADV 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 WXDLLIMPEXP_ADV 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;
126 void RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
);
128 virtual wxSize
GetSize() const = 0;
130 virtual bool Activate( wxRect cell
,
131 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
)
134 virtual bool LeftClick( wxPoint cursor
, wxRect cell
,
135 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
)
137 virtual bool RightClick( wxPoint cursor
, wxRect cell
,
138 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
)
140 virtual bool StartDrag( wxPoint cursor
, wxRect cell
,
141 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
)
144 // Create DC on request
145 virtual wxDC
*GetDC();
150 bool Init(wxDataViewCellMode mode
, int align
);
156 // Internal, temporay for RenderText.
157 GtkCellRenderer
*m_text_renderer
;
160 void *background_area
;
166 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
169 // ---------------------------------------------------------
170 // wxDataViewProgressRenderer
171 // ---------------------------------------------------------
173 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
176 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
177 const wxString
&varianttype
= wxT("long"),
178 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
179 int align
= wxDVR_DEFAULT_ALIGNMENT
);
180 virtual ~wxDataViewProgressRenderer();
182 bool SetValue( const wxVariant
&value
);
183 bool GetValue( wxVariant
&value
) const;
185 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
186 virtual wxSize
GetSize() const;
193 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
196 // ---------------------------------------------------------
197 // wxDataViewIconTextRenderer
198 // ---------------------------------------------------------
200 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewCustomRenderer
203 wxDataViewIconTextRenderer( const wxString
&varianttype
= wxT("wxDataViewIconText"),
204 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
205 int align
= wxDVR_DEFAULT_ALIGNMENT
);
206 virtual ~wxDataViewIconTextRenderer();
208 bool SetValue( const wxVariant
&value
);
209 bool GetValue( wxVariant
&value
) const;
211 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
212 virtual wxSize
GetSize() const;
214 virtual bool HasEditorCtrl() { return true; }
215 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
216 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
219 wxDataViewIconText m_value
;
222 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
225 // ---------------------------------------------------------
226 // wxDataViewDateRenderer
227 // ---------------------------------------------------------
229 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewCustomRenderer
232 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
233 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
234 int align
= wxDVR_DEFAULT_ALIGNMENT
);
236 bool SetValue( const wxVariant
&value
);
237 bool GetValue( wxVariant
&value
) const;
239 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
240 virtual wxSize
GetSize() const;
241 virtual bool Activate( wxRect cell
,
242 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
);
248 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
251 // ---------------------------------------------------------
253 // ---------------------------------------------------------
255 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
258 wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*renderer
,
259 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
260 wxAlignment align
= wxALIGN_CENTER
,
261 int flags
= wxDATAVIEW_COL_RESIZABLE
);
262 wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
263 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
264 wxAlignment align
= wxALIGN_CENTER
,
265 int flags
= wxDATAVIEW_COL_RESIZABLE
);
267 virtual ~wxDataViewColumn();
272 virtual void SetTitle( const wxString
&title
);
273 virtual void SetBitmap( const wxBitmap
&bitmap
);
275 virtual void SetOwner( wxDataViewCtrl
*owner
);
277 virtual void SetAlignment( wxAlignment align
);
279 virtual void SetSortable( bool sortable
);
280 virtual void SetSortOrder( bool ascending
);
282 virtual void SetResizeable( bool resizeable
);
283 virtual void SetHidden( bool hidden
);
285 virtual void SetMinWidth( int minWidth
);
286 virtual void SetWidth( int width
);
291 virtual wxString
GetTitle() const;
292 virtual wxAlignment
GetAlignment() const;
294 virtual bool IsSortable() const;
295 virtual bool IsSortOrderAscending() const;
296 virtual bool IsResizeable() const;
297 virtual bool IsHidden() const;
299 virtual int GetWidth() const;
300 virtual int GetMinWidth() const;
303 GtkWidget
* GetGtkHandle() { return m_column
; }
304 GtkWidget
* GetConstGtkHandle() const { return m_column
; }
307 // holds the GTK handle
310 // delayed connection to mouse events
311 friend class wxDataViewCtrl
;
312 void OnInternalIdle();
315 void Init(wxAlignment align
, int flags
, int width
);
318 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
321 WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn
, wxDataViewColumnList
,
322 class WXDLLIMPEXP_ADV
);
324 // ---------------------------------------------------------
326 // ---------------------------------------------------------
328 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
336 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
337 const wxPoint
& pos
= wxDefaultPosition
,
338 const wxSize
& size
= wxDefaultSize
, long style
= 0,
339 const wxValidator
& validator
= wxDefaultValidator
)
341 Create(parent
, id
, pos
, size
, style
, validator
);
344 virtual ~wxDataViewCtrl();
348 bool Create(wxWindow
*parent
, wxWindowID id
,
349 const wxPoint
& pos
= wxDefaultPosition
,
350 const wxSize
& size
= wxDefaultSize
, long style
= 0,
351 const wxValidator
& validator
= wxDefaultValidator
);
353 virtual bool AssociateModel( wxDataViewModel
*model
);
355 virtual bool PrependColumn( wxDataViewColumn
*col
);
356 virtual bool AppendColumn( wxDataViewColumn
*col
);
357 virtual unsigned int GetColumnCount() const;
358 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const;
359 virtual bool DeleteColumn( wxDataViewColumn
*column
);
360 virtual bool ClearColumns();
361 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const;
363 virtual wxDataViewColumn
*GetSortingColumn() const;
365 virtual wxDataViewItem
GetSelection() const;
366 virtual int GetSelections( wxDataViewItemArray
& sel
) const;
367 virtual void SetSelections( const wxDataViewItemArray
& sel
);
368 virtual void Select( const wxDataViewItem
& item
);
369 virtual void Unselect( const wxDataViewItem
& item
);
370 virtual bool IsSelected( const wxDataViewItem
& item
) const;
371 virtual void SelectAll();
372 virtual void UnselectAll();
374 virtual void EnsureVisible( const wxDataViewItem
& item
,
375 const wxDataViewColumn
*column
= NULL
);
376 virtual void HitTest( const wxPoint
&point
,
377 wxDataViewItem
&item
,
378 wxDataViewColumn
*&column
) const;
379 virtual wxRect
GetItemRect( const wxDataViewItem
&item
,
380 const wxDataViewColumn
*column
= NULL
) const;
382 virtual void Expand( const wxDataViewItem
& item
);
383 virtual void Collapse( const wxDataViewItem
& item
);
385 static wxVisualAttributes
386 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
388 wxWindow
*GetMainWindow() { return (wxWindow
*) this; }
390 GtkWidget
*GtkGetTreeView() { return m_treeview
; }
391 wxDataViewCtrlInternal
* GtkGetInternal() { return m_internal
; }
394 virtual void DoSetExpanderColumn();
395 virtual void DoSetIndent();
398 friend class wxDataViewCtrlDC
;
399 friend class wxDataViewColumn
;
400 friend class wxGtkDataViewModelNotifier
;
401 GtkWidget
*m_treeview
;
402 wxDataViewModelNotifier
*m_notifier
;
403 wxDataViewCtrlInternal
*m_internal
;
404 wxDataViewColumnList m_cols
;
407 virtual void OnInternalIdle();
409 void GtkEnableSelectionEvents();
410 void GtkDisableSelectionEvents();
413 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
414 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
418 #endif // __GTKDATAVIEWCTRLH__