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_CORE wxDataViewCtrl
;
25 // ---------------------------------------------------------
27 // ---------------------------------------------------------
29 class wxDataViewRenderer
: public wxDataViewRendererBase
32 wxDataViewRenderer( const wxString
&varianttype
,
33 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
34 int align
= wxDVR_DEFAULT_ALIGNMENT
);
37 GtkCellRenderer
* GetGtkHandle() { return m_renderer
; }
39 virtual void SetMode( wxDataViewCellMode mode
);
40 virtual wxDataViewCellMode
GetMode() const;
42 virtual void SetAlignment( int align
);
43 virtual int GetAlignment() const;
46 GtkCellRenderer
*m_renderer
;
49 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer
)
52 // ---------------------------------------------------------
53 // wxDataViewTextRenderer
54 // ---------------------------------------------------------
56 class 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 // wxDataViewBitmapRenderer
74 // ---------------------------------------------------------
76 class wxDataViewBitmapRenderer
: public wxDataViewRenderer
79 wxDataViewBitmapRenderer( const wxString
&varianttype
= wxT("wxBitmap"),
80 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
81 int align
= wxDVR_DEFAULT_ALIGNMENT
);
83 bool SetValue( const wxVariant
&value
);
84 bool GetValue( wxVariant
&value
) const;
87 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
90 // ---------------------------------------------------------
91 // wxDataViewToggleRenderer
92 // ---------------------------------------------------------
94 class wxDataViewToggleRenderer
: public wxDataViewRenderer
97 wxDataViewToggleRenderer( const wxString
&varianttype
= wxT("bool"),
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(wxDataViewToggleRenderer
)
108 // ---------------------------------------------------------
109 // wxDataViewCustomRenderer
110 // ---------------------------------------------------------
112 class wxDataViewCustomRenderer
: public wxDataViewRenderer
115 wxDataViewCustomRenderer( const wxString
&varianttype
= wxT("string"),
116 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
117 int align
= wxDVR_DEFAULT_ALIGNMENT
,
118 bool no_init
= false );
119 virtual ~wxDataViewCustomRenderer();
122 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
) = 0;
123 virtual wxSize
GetSize() const = 0;
125 virtual bool Activate( wxRect cell
,
126 wxDataViewListModel
*model
, unsigned int col
, unsigned int row
)
129 virtual bool LeftClick( wxPoint cursor
, wxRect cell
,
130 wxDataViewListModel
*model
, unsigned int col
, unsigned int row
)
132 virtual bool RightClick( wxPoint cursor
, wxRect cell
,
133 wxDataViewListModel
*model
, unsigned int col
, unsigned int row
)
135 virtual bool StartDrag( wxPoint cursor
, wxRect cell
,
136 wxDataViewListModel
*model
, unsigned int col
, unsigned int row
)
139 // Create DC on request
140 virtual wxDC
*GetDC();
145 bool Init(wxDataViewCellMode mode
, int align
);
151 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
154 // ---------------------------------------------------------
155 // wxDataViewProgressRenderer
156 // ---------------------------------------------------------
158 class wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
161 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
162 const wxString
&varianttype
= wxT("long"),
163 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
164 int align
= wxDVR_DEFAULT_ALIGNMENT
);
165 virtual ~wxDataViewProgressRenderer();
167 bool SetValue( const wxVariant
&value
);
168 bool GetValue( wxVariant
&value
) const;
170 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
171 virtual wxSize
GetSize() const;
178 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
181 // ---------------------------------------------------------
182 // wxDataViewDateRenderer
183 // ---------------------------------------------------------
185 class wxDataViewDateRenderer
: public wxDataViewCustomRenderer
188 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
189 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
190 int align
= wxDVR_DEFAULT_ALIGNMENT
);
192 bool SetValue( const wxVariant
&value
);
193 bool GetValue( wxVariant
&value
) const;
195 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
196 virtual wxSize
GetSize() const;
197 virtual bool Activate( wxRect cell
,
198 wxDataViewListModel
*model
, unsigned int col
, unsigned int row
);
204 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
207 // ---------------------------------------------------------
209 // ---------------------------------------------------------
211 class WXDLLIMPEXP_CORE wxDataViewColumn
: public wxDataViewColumnBase
214 wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*renderer
,
215 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
216 wxAlignment align
= wxALIGN_CENTER
,
217 int flags
= wxDATAVIEW_COL_RESIZABLE
);
218 wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
219 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
220 wxAlignment align
= wxALIGN_CENTER
,
221 int flags
= wxDATAVIEW_COL_RESIZABLE
);
223 virtual ~wxDataViewColumn();
228 virtual void SetTitle( const wxString
&title
);
229 virtual void SetBitmap( const wxBitmap
&bitmap
);
231 virtual void SetOwner( wxDataViewCtrl
*owner
);
233 virtual void SetAlignment( wxAlignment align
);
235 virtual void SetSortable( bool sortable
);
236 virtual void SetSortOrder( bool ascending
);
238 virtual void SetResizeable( bool resizeable
);
239 virtual void SetHidden( bool hidden
);
241 virtual void SetMinWidth( int minWidth
);
242 virtual void SetWidth( int width
);
247 virtual wxString
GetTitle() const;
248 virtual wxAlignment
GetAlignment() const;
250 virtual bool IsSortable() const;
251 virtual bool IsSortOrderAscending() const;
252 virtual bool IsResizeable() const;
253 virtual bool IsHidden() const;
255 virtual int GetWidth() const;
256 virtual int GetMinWidth() const;
259 GtkWidget
* GetGtkHandle() { return m_column
; }
262 // holds the GTK handle
265 // delayed connection to mouse events
266 friend class wxDataViewCtrl
;
267 void OnInternalIdle();
270 void Init(wxAlignment align
, int flags
, int width
);
273 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
276 // ---------------------------------------------------------
278 // ---------------------------------------------------------
280 class WXDLLIMPEXP_CORE wxDataViewCtrl
: public wxDataViewCtrlBase
288 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
289 const wxPoint
& pos
= wxDefaultPosition
,
290 const wxSize
& size
= wxDefaultSize
, long style
= 0,
291 const wxValidator
& validator
= wxDefaultValidator
)
293 Create(parent
, id
, pos
, size
, style
, validator
);
296 virtual ~wxDataViewCtrl();
300 bool Create(wxWindow
*parent
, wxWindowID id
,
301 const wxPoint
& pos
= wxDefaultPosition
,
302 const wxSize
& size
= wxDefaultSize
, long style
= 0,
303 const wxValidator
& validator
= wxDefaultValidator
);
305 virtual bool AssociateModel( wxDataViewListModel
*model
);
306 virtual bool AppendColumn( wxDataViewColumn
*col
);
308 virtual void SetSelection( int row
); // -1 for unselect
309 virtual void SetSelectionRange( unsigned int from
, unsigned int to
);
310 virtual void SetSelections( const wxArrayInt
& aSelections
);
311 virtual void Unselect( unsigned int row
);
313 virtual bool IsSelected( unsigned int row
) const;
314 virtual int GetSelection() const;
315 virtual int GetSelections(wxArrayInt
& aSelections
) const;
317 static wxVisualAttributes
318 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
320 GtkWidget
*GtkGetTreeView() { return m_treeview
; }
321 wxWindow
*GetMainWindow() { return (wxWindow
*) this; }
324 friend class wxDataViewCtrlDC
;
325 friend class wxDataViewColumn
;
326 friend class wxGtkDataViewListModelNotifier
;
327 GtkWidget
*m_treeview
;
328 wxDataViewListModelNotifier
*m_notifier
;
330 virtual void OnInternalIdle();
332 void GtkEnableSelectionEvents();
333 void GtkDisableSelectionEvents();
336 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
337 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
341 #endif // __GTKDATAVIEWCTRLH__