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();
46 virtual bool GtkHasAttributes() { return false; }
49 GtkCellRenderer
*m_renderer
;
52 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer
)
55 // ---------------------------------------------------------
56 // wxDataViewTextRenderer
57 // ---------------------------------------------------------
59 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewRenderer
62 wxDataViewTextRenderer( const wxString
&varianttype
= wxT("string"),
63 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
64 int align
= wxDVR_DEFAULT_ALIGNMENT
);
66 bool SetValue( const wxVariant
&value
);
67 bool GetValue( wxVariant
&value
) const;
69 void SetAlignment( int align
);
72 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
75 // ---------------------------------------------------------
76 // wxDataViewTextRendererAttr
77 // ---------------------------------------------------------
79 class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr
: public wxDataViewTextRenderer
82 wxDataViewTextRendererAttr( const wxString
&varianttype
= wxT("string"),
83 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
84 int align
= wxDVR_DEFAULT_ALIGNMENT
);
87 bool GtkHasAttributes() { return true; }
90 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr
)
93 // ---------------------------------------------------------
94 // wxDataViewBitmapRenderer
95 // ---------------------------------------------------------
97 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewRenderer
100 wxDataViewBitmapRenderer( const wxString
&varianttype
= wxT("wxBitmap"),
101 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
102 int align
= wxDVR_DEFAULT_ALIGNMENT
);
104 bool SetValue( const wxVariant
&value
);
105 bool GetValue( wxVariant
&value
) const;
108 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
111 // ---------------------------------------------------------
112 // wxDataViewToggleRenderer
113 // ---------------------------------------------------------
115 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewRenderer
118 wxDataViewToggleRenderer( const wxString
&varianttype
= wxT("bool"),
119 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
120 int align
= wxDVR_DEFAULT_ALIGNMENT
);
122 bool SetValue( const wxVariant
&value
);
123 bool GetValue( wxVariant
&value
) const;
126 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
129 // ---------------------------------------------------------
130 // wxDataViewCustomRenderer
131 // ---------------------------------------------------------
133 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewRenderer
136 wxDataViewCustomRenderer( const wxString
&varianttype
= wxT("string"),
137 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
138 int align
= wxDVR_DEFAULT_ALIGNMENT
,
139 bool no_init
= false );
140 virtual ~wxDataViewCustomRenderer();
143 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
) = 0;
145 void RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
);
147 virtual wxSize
GetSize() const = 0;
149 virtual bool Activate( wxRect cell
,
150 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
)
153 virtual bool LeftClick( wxPoint cursor
, wxRect cell
,
154 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
)
156 virtual bool RightClick( wxPoint cursor
, wxRect cell
,
157 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
)
159 virtual bool StartDrag( wxPoint cursor
, wxRect cell
,
160 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
)
163 // Create DC on request
164 virtual wxDC
*GetDC();
169 bool Init(wxDataViewCellMode mode
, int align
);
175 // Internal, temporay for RenderText.
176 GtkCellRenderer
*m_text_renderer
;
179 void *background_area
;
185 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
188 // ---------------------------------------------------------
189 // wxDataViewProgressRenderer
190 // ---------------------------------------------------------
192 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
195 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
196 const wxString
&varianttype
= wxT("long"),
197 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
198 int align
= wxDVR_DEFAULT_ALIGNMENT
);
199 virtual ~wxDataViewProgressRenderer();
201 bool SetValue( const wxVariant
&value
);
202 bool GetValue( wxVariant
&value
) const;
204 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
205 virtual wxSize
GetSize() const;
212 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
215 // ---------------------------------------------------------
216 // wxDataViewIconTextRenderer
217 // ---------------------------------------------------------
219 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewCustomRenderer
222 wxDataViewIconTextRenderer( const wxString
&varianttype
= wxT("wxDataViewIconText"),
223 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
224 int align
= wxDVR_DEFAULT_ALIGNMENT
);
225 virtual ~wxDataViewIconTextRenderer();
227 bool SetValue( const wxVariant
&value
);
228 bool GetValue( wxVariant
&value
) const;
230 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
231 virtual wxSize
GetSize() const;
233 virtual bool HasEditorCtrl() { return true; }
234 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
235 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
238 wxDataViewIconText m_value
;
241 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
244 // ---------------------------------------------------------
245 // wxDataViewDateRenderer
246 // ---------------------------------------------------------
248 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewCustomRenderer
251 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
252 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
253 int align
= wxDVR_DEFAULT_ALIGNMENT
);
255 bool SetValue( const wxVariant
&value
);
256 bool GetValue( wxVariant
&value
) const;
258 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
259 virtual wxSize
GetSize() const;
260 virtual bool Activate( wxRect cell
,
261 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
);
267 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
270 // ---------------------------------------------------------
272 // ---------------------------------------------------------
274 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
277 wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*renderer
,
278 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
279 wxAlignment align
= wxALIGN_CENTER
,
280 int flags
= wxDATAVIEW_COL_RESIZABLE
);
281 wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
282 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
283 wxAlignment align
= wxALIGN_CENTER
,
284 int flags
= wxDATAVIEW_COL_RESIZABLE
);
286 virtual ~wxDataViewColumn();
291 virtual void SetTitle( const wxString
&title
);
292 virtual void SetBitmap( const wxBitmap
&bitmap
);
294 virtual void SetOwner( wxDataViewCtrl
*owner
);
296 virtual void SetAlignment( wxAlignment align
);
298 virtual void SetSortable( bool sortable
);
299 virtual void SetSortOrder( bool ascending
);
301 virtual void SetResizeable( bool resizeable
);
302 virtual void SetHidden( bool hidden
);
304 virtual void SetMinWidth( int minWidth
);
305 virtual void SetWidth( int width
);
310 virtual wxString
GetTitle() const;
311 virtual wxAlignment
GetAlignment() const;
313 virtual bool IsSortable() const;
314 virtual bool IsSortOrderAscending() const;
315 virtual bool IsResizeable() const;
316 virtual bool IsHidden() const;
318 virtual int GetWidth() const;
319 virtual int GetMinWidth() 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
; }
413 virtual void DoSetExpanderColumn();
414 virtual void DoSetIndent();
417 friend class wxDataViewCtrlDC
;
418 friend class wxDataViewColumn
;
419 friend class wxGtkDataViewModelNotifier
;
420 GtkWidget
*m_treeview
;
421 wxDataViewModelNotifier
*m_notifier
;
422 wxDataViewCtrlInternal
*m_internal
;
423 wxDataViewColumnList m_cols
;
426 virtual void OnInternalIdle();
428 void GtkEnableSelectionEvents();
429 void GtkDisableSelectionEvents();
432 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
433 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
437 #endif // __GTKDATAVIEWCTRLH__