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; }
44 void GtkUpdateAlignment();
47 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 // wxDataViewTextRendererAttr
76 // ---------------------------------------------------------
78 class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr
: public wxDataViewTextRenderer
81 wxDataViewTextRendererAttr( const wxString
&varianttype
= wxT("string"),
82 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
83 int align
= wxDVR_DEFAULT_ALIGNMENT
);
86 bool GtkHasAttributes() { return true; }
89 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr
)
92 // ---------------------------------------------------------
93 // wxDataViewBitmapRenderer
94 // ---------------------------------------------------------
96 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewRenderer
99 wxDataViewBitmapRenderer( const wxString
&varianttype
= wxT("wxBitmap"),
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(wxDataViewBitmapRenderer
)
110 // ---------------------------------------------------------
111 // wxDataViewToggleRenderer
112 // ---------------------------------------------------------
114 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewRenderer
117 wxDataViewToggleRenderer( const wxString
&varianttype
= wxT("bool"),
118 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
119 int align
= wxDVR_DEFAULT_ALIGNMENT
);
121 bool SetValue( const wxVariant
&value
);
122 bool GetValue( wxVariant
&value
) const;
125 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
128 // ---------------------------------------------------------
129 // wxDataViewCustomRenderer
130 // ---------------------------------------------------------
132 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewRenderer
135 wxDataViewCustomRenderer( const wxString
&varianttype
= wxT("string"),
136 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
137 int align
= wxDVR_DEFAULT_ALIGNMENT
,
138 bool no_init
= false );
139 virtual ~wxDataViewCustomRenderer();
142 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
) = 0;
144 void RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
);
146 virtual wxSize
GetSize() const = 0;
148 virtual bool Activate( wxRect
WXUNUSED(cell
),
149 wxDataViewModel
*WXUNUSED(model
), const wxDataViewItem
&WXUNUSED(item
), unsigned int WXUNUSED(col
) )
152 virtual bool LeftClick( wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
),
153 wxDataViewModel
*WXUNUSED(model
), const wxDataViewItem
&WXUNUSED(item
), unsigned int WXUNUSED(col
) )
155 virtual bool StartDrag( wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
),
156 wxDataViewModel
*WXUNUSED(model
), const wxDataViewItem
&WXUNUSED(item
), unsigned int WXUNUSED(col
) )
159 // Create DC on request
160 virtual wxDC
*GetDC();
165 bool Init(wxDataViewCellMode mode
, int align
);
171 // Internal, temporay for RenderText.
172 GtkCellRenderer
*m_text_renderer
;
175 void *background_area
;
181 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
184 // ---------------------------------------------------------
185 // wxDataViewProgressRenderer
186 // ---------------------------------------------------------
188 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
191 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
192 const wxString
&varianttype
= wxT("long"),
193 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
194 int align
= wxDVR_DEFAULT_ALIGNMENT
);
195 virtual ~wxDataViewProgressRenderer();
197 bool SetValue( const wxVariant
&value
);
198 bool GetValue( wxVariant
&value
) const;
200 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
201 virtual wxSize
GetSize() const;
208 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
211 // ---------------------------------------------------------
212 // wxDataViewIconTextRenderer
213 // ---------------------------------------------------------
215 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewCustomRenderer
218 wxDataViewIconTextRenderer( const wxString
&varianttype
= wxT("wxDataViewIconText"),
219 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
220 int align
= wxDVR_DEFAULT_ALIGNMENT
);
221 virtual ~wxDataViewIconTextRenderer();
223 bool SetValue( const wxVariant
&value
);
224 bool GetValue( wxVariant
&value
) const;
226 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
227 virtual wxSize
GetSize() const;
229 virtual bool HasEditorCtrl() { return true; }
230 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
231 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
234 wxDataViewIconText m_value
;
237 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
240 // ---------------------------------------------------------
241 // wxDataViewDateRenderer
242 // ---------------------------------------------------------
244 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewCustomRenderer
247 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
248 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
249 int align
= wxDVR_DEFAULT_ALIGNMENT
);
251 bool SetValue( const wxVariant
&value
);
252 bool GetValue( wxVariant
&value
) const;
254 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
255 virtual wxSize
GetSize() const;
256 virtual bool Activate( wxRect cell
,
257 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
);
263 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
266 // -------------------------------------
267 // wxDataViewChoiceRenderer
268 // -------------------------------------
270 class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer
: public wxDataViewCustomRenderer
273 wxDataViewChoiceRenderer( const wxArrayString
&choices
,
274 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
275 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
276 virtual bool Render( wxRect rect
, wxDC
*dc
, int state
);
277 virtual wxSize
GetSize() const;
278 virtual bool SetValue( const wxVariant
&value
);
279 virtual bool GetValue( wxVariant
&value
) const;
281 void SetAlignment( int align
);
283 wxArrayString m_choices
;
287 // ---------------------------------------------------------
289 // ---------------------------------------------------------
291 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
294 wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*renderer
,
295 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
296 wxAlignment align
= wxALIGN_CENTER
,
297 int flags
= wxDATAVIEW_COL_RESIZABLE
);
298 wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
299 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
300 wxAlignment align
= wxALIGN_CENTER
,
301 int flags
= wxDATAVIEW_COL_RESIZABLE
);
306 virtual void SetTitle( const wxString
&title
);
307 virtual void SetBitmap( const wxBitmap
&bitmap
);
309 virtual void SetOwner( wxDataViewCtrl
*owner
);
311 virtual void SetAlignment( wxAlignment align
);
313 virtual void SetSortable( bool sortable
);
314 virtual void SetSortOrder( bool ascending
);
315 virtual void SetAsSortKey(bool sort
= true);
317 virtual void SetResizeable( bool resizeable
);
318 virtual void SetHidden( bool hidden
);
320 virtual void SetMinWidth( int minWidth
);
321 virtual void SetWidth( int width
);
323 virtual void SetReorderable( bool reorderable
);
325 virtual void SetFlags(int flags
) { SetIndividualFlags(flags
); }
329 virtual wxString
GetTitle() const;
330 virtual wxAlignment
GetAlignment() const;
332 virtual bool IsSortable() const;
333 virtual bool IsSortOrderAscending() const;
334 virtual bool IsSortKey() const = 0;
336 virtual bool IsResizeable() const;
337 virtual bool IsHidden() const;
339 virtual int GetWidth() const;
340 virtual int GetMinWidth() const;
342 virtual bool IsReorderable() const;
344 virtual int GetFlags() const { return GetFromIndividualFlags(); }
347 GtkWidget
* GetGtkHandle() { return m_column
; }
348 GtkWidget
* GetConstGtkHandle() const { return m_column
; }
351 // holds the GTK handle
354 // holds GTK handles for title/bitmap in the header
358 // delayed connection to mouse events
359 friend class wxDataViewCtrl
;
360 void OnInternalIdle();
363 void Init(wxAlignment align
, int flags
, int width
);
366 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
369 WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn
, wxDataViewColumnList
,
370 class WXDLLIMPEXP_ADV
);
372 // ---------------------------------------------------------
374 // ---------------------------------------------------------
376 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
384 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
385 const wxPoint
& pos
= wxDefaultPosition
,
386 const wxSize
& size
= wxDefaultSize
, long style
= 0,
387 const wxValidator
& validator
= wxDefaultValidator
)
389 Create(parent
, id
, pos
, size
, style
, validator
);
392 virtual ~wxDataViewCtrl();
396 bool Create(wxWindow
*parent
, wxWindowID id
,
397 const wxPoint
& pos
= wxDefaultPosition
,
398 const wxSize
& size
= wxDefaultSize
, long style
= 0,
399 const wxValidator
& validator
= wxDefaultValidator
);
401 virtual bool AssociateModel( wxDataViewModel
*model
);
403 virtual bool PrependColumn( wxDataViewColumn
*col
);
404 virtual bool AppendColumn( wxDataViewColumn
*col
);
405 virtual bool InsertColumn( unsigned int pos
, wxDataViewColumn
*col
);
407 virtual unsigned int GetColumnCount() const;
408 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const;
409 virtual bool DeleteColumn( wxDataViewColumn
*column
);
410 virtual bool ClearColumns();
411 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const;
413 virtual wxDataViewColumn
*GetSortingColumn() const;
415 virtual wxDataViewItem
GetSelection() const;
416 virtual int GetSelections( wxDataViewItemArray
& sel
) const;
417 virtual void SetSelections( const wxDataViewItemArray
& sel
);
418 virtual void Select( const wxDataViewItem
& item
);
419 virtual void Unselect( const wxDataViewItem
& item
);
420 virtual bool IsSelected( const wxDataViewItem
& item
) const;
421 virtual void SelectAll();
422 virtual void UnselectAll();
424 virtual void EnsureVisible( const wxDataViewItem
& item
,
425 const wxDataViewColumn
*column
= NULL
);
426 virtual void HitTest( const wxPoint
&point
,
427 wxDataViewItem
&item
,
428 wxDataViewColumn
*&column
) const;
429 virtual wxRect
GetItemRect( const wxDataViewItem
&item
,
430 const wxDataViewColumn
*column
= NULL
) const;
432 virtual void Expand( const wxDataViewItem
& item
);
433 virtual void Collapse( const wxDataViewItem
& item
);
435 static wxVisualAttributes
436 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
438 wxWindow
*GetMainWindow() { return (wxWindow
*) this; }
440 GtkWidget
*GtkGetTreeView() { return m_treeview
; }
441 wxDataViewCtrlInternal
* GtkGetInternal() { return m_internal
; }
443 virtual void OnInternalIdle();
446 virtual void DoSetExpanderColumn();
447 virtual void DoSetIndent();
450 friend class wxDataViewCtrlDCImpl
;
451 friend class wxDataViewColumn
;
452 friend class wxGtkDataViewModelNotifier
;
453 friend class wxDataViewCtrlInternal
;
455 GtkWidget
*m_treeview
;
456 wxDataViewModelNotifier
*m_notifier
;
457 wxDataViewCtrlInternal
*m_internal
;
458 wxDataViewColumnList m_cols
;
460 virtual void AddChildGTK(wxWindowGTK
* child
);
461 void GtkEnableSelectionEvents();
462 void GtkDisableSelectionEvents();
464 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
465 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
469 #endif // _WX_GTKDATAVIEWCTRL_H_