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
;
22 typedef struct _GtkTreeViewColumn GtkTreeViewColumn
;
24 // ---------------------------------------------------------
26 // ---------------------------------------------------------
28 class WXDLLIMPEXP_ADV wxDataViewRenderer
: public wxDataViewRendererBase
31 wxDataViewRenderer( const wxString
&varianttype
,
32 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
33 int align
= wxDVR_DEFAULT_ALIGNMENT
);
35 virtual void SetMode( wxDataViewCellMode mode
);
36 virtual wxDataViewCellMode
GetMode() const;
38 virtual void SetAlignment( int align
);
39 virtual int GetAlignment() const;
42 // GTK-specific implementation
43 // ---------------------------
45 // pack the GTK cell renderers used by this renderer to the given column
47 // by default only a single m_renderer is used but some renderers use more
48 // than one GTK cell renderer
49 virtual void GtkPackIntoColumn(GtkTreeViewColumn
*column
);
51 // called when the cell value was edited by user with the new value
53 // it validates the new value and notifies the model about the change by
54 // calling GtkOnCellChanged() if it was accepted
55 void GtkOnTextEdited(const gchar
*itempath
, const wxString
& value
);
57 GtkCellRenderer
* GetGtkHandle() { return m_renderer
; }
58 void GtkInitHandlers();
59 void GtkUpdateAlignment();
61 bool GtkIsUsingDefaultAttrs() const { return m_usingDefaultAttrs
; }
62 void GtkSetUsingDefaultAttrs(bool def
) { m_usingDefaultAttrs
= def
; }
65 virtual void GtkOnCellChanged(const wxVariant
& value
,
66 const wxDataViewItem
& item
,
70 GtkCellRenderer
*m_renderer
;
73 // true if we hadn't changed any visual attributes or restored them since
75 bool m_usingDefaultAttrs
;
78 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer
)
81 // ---------------------------------------------------------
82 // wxDataViewTextRenderer
83 // ---------------------------------------------------------
85 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewRenderer
88 wxDataViewTextRenderer( const wxString
&varianttype
= wxT("string"),
89 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
90 int align
= wxDVR_DEFAULT_ALIGNMENT
);
92 virtual bool SetValue( const wxVariant
&value
)
94 return SetTextValue(value
);
97 virtual bool GetValue( wxVariant
&value
) const
100 if ( !GetTextValue(str
) )
108 virtual void SetAlignment( int align
);
111 // implementation of Set/GetValue()
112 bool SetTextValue(const wxString
& str
);
113 bool GetTextValue(wxString
& str
) const;
116 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
119 // ---------------------------------------------------------
120 // wxDataViewBitmapRenderer
121 // ---------------------------------------------------------
123 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewRenderer
126 wxDataViewBitmapRenderer( const wxString
&varianttype
= wxT("wxBitmap"),
127 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
128 int align
= wxDVR_DEFAULT_ALIGNMENT
);
130 bool SetValue( const wxVariant
&value
);
131 bool GetValue( wxVariant
&value
) const;
134 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
137 // ---------------------------------------------------------
138 // wxDataViewToggleRenderer
139 // ---------------------------------------------------------
141 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewRenderer
144 wxDataViewToggleRenderer( const wxString
&varianttype
= wxT("bool"),
145 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
146 int align
= wxDVR_DEFAULT_ALIGNMENT
);
148 bool SetValue( const wxVariant
&value
);
149 bool GetValue( wxVariant
&value
) const;
152 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
155 // ---------------------------------------------------------
156 // wxDataViewCustomRenderer
157 // ---------------------------------------------------------
159 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewRenderer
162 wxDataViewCustomRenderer( const wxString
&varianttype
= wxT("string"),
163 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
164 int align
= wxDVR_DEFAULT_ALIGNMENT
,
165 bool no_init
= false );
166 virtual ~wxDataViewCustomRenderer();
169 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
) = 0;
171 void RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
);
173 virtual wxSize
GetSize() const = 0;
175 virtual bool Activate( wxRect
WXUNUSED(cell
),
176 wxDataViewModel
*WXUNUSED(model
), const wxDataViewItem
&WXUNUSED(item
), unsigned int WXUNUSED(col
) )
179 virtual bool LeftClick( wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
),
180 wxDataViewModel
*WXUNUSED(model
), const wxDataViewItem
&WXUNUSED(item
), unsigned int WXUNUSED(col
) )
182 virtual bool StartDrag( wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
),
183 wxDataViewModel
*WXUNUSED(model
), const wxDataViewItem
&WXUNUSED(item
), unsigned int WXUNUSED(col
) )
186 // Create DC on request
187 virtual wxDC
*GetDC();
192 bool Init(wxDataViewCellMode mode
, int align
);
198 // Internal, temporary for RenderText.
199 GtkCellRenderer
*m_text_renderer
;
202 void *background_area
;
208 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
211 // ---------------------------------------------------------
212 // wxDataViewProgressRenderer
213 // ---------------------------------------------------------
215 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
218 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
219 const wxString
&varianttype
= wxT("long"),
220 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
221 int align
= wxDVR_DEFAULT_ALIGNMENT
);
222 virtual ~wxDataViewProgressRenderer();
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;
235 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
238 // ---------------------------------------------------------
239 // wxDataViewIconTextRenderer
240 // ---------------------------------------------------------
242 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewTextRenderer
245 wxDataViewIconTextRenderer( const wxString
&varianttype
= wxT("wxDataViewIconText"),
246 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
247 int align
= wxDVR_DEFAULT_ALIGNMENT
);
248 virtual ~wxDataViewIconTextRenderer();
250 bool SetValue( const wxVariant
&value
);
251 bool GetValue( wxVariant
&value
) const;
253 virtual void GtkPackIntoColumn(GtkTreeViewColumn
*column
);
256 virtual void GtkOnCellChanged(const wxVariant
& value
,
257 const wxDataViewItem
& item
,
261 wxDataViewIconText m_value
;
263 // we use the base class m_renderer for the text and this one for the icon
264 GtkCellRenderer
*m_rendererIcon
;
266 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
269 // ---------------------------------------------------------
270 // wxDataViewDateRenderer
271 // ---------------------------------------------------------
273 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewCustomRenderer
276 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
277 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
278 int align
= wxDVR_DEFAULT_ALIGNMENT
);
280 bool SetValue( const wxVariant
&value
);
281 bool GetValue( wxVariant
&value
) const;
283 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
284 virtual wxSize
GetSize() const;
285 virtual bool Activate( wxRect cell
,
286 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
);
292 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
295 // -------------------------------------
296 // wxDataViewChoiceRenderer
297 // -------------------------------------
299 class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer
: public wxDataViewCustomRenderer
302 wxDataViewChoiceRenderer( const wxArrayString
&choices
,
303 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
304 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
305 virtual bool Render( wxRect rect
, wxDC
*dc
, int state
);
306 virtual wxSize
GetSize() const;
307 virtual bool SetValue( const wxVariant
&value
);
308 virtual bool GetValue( wxVariant
&value
) const;
310 void SetAlignment( int align
);
312 wxArrayString m_choices
;
316 // ---------------------------------------------------------
318 // ---------------------------------------------------------
320 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
323 wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*renderer
,
324 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
325 wxAlignment align
= wxALIGN_CENTER
,
326 int flags
= wxDATAVIEW_COL_RESIZABLE
);
327 wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
328 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
329 wxAlignment align
= wxALIGN_CENTER
,
330 int flags
= wxDATAVIEW_COL_RESIZABLE
);
335 virtual void SetTitle( const wxString
&title
);
336 virtual void SetBitmap( const wxBitmap
&bitmap
);
338 virtual void SetOwner( wxDataViewCtrl
*owner
);
340 virtual void SetAlignment( wxAlignment align
);
342 virtual void SetSortable( bool sortable
);
343 virtual void SetSortOrder( bool ascending
);
344 virtual void SetAsSortKey(bool sort
= true);
346 virtual void SetResizeable( bool resizeable
);
347 virtual void SetHidden( bool hidden
);
349 virtual void SetMinWidth( int minWidth
);
350 virtual void SetWidth( int width
);
352 virtual void SetReorderable( bool reorderable
);
354 virtual void SetFlags(int flags
) { SetIndividualFlags(flags
); }
358 virtual wxString
GetTitle() const;
359 virtual wxAlignment
GetAlignment() const;
361 virtual bool IsSortable() const;
362 virtual bool IsSortOrderAscending() const;
363 virtual bool IsSortKey() const;
365 virtual bool IsResizeable() const;
366 virtual bool IsHidden() const;
368 virtual int GetWidth() const;
369 virtual int GetMinWidth() const;
371 virtual bool IsReorderable() const;
373 virtual int GetFlags() const { return GetFromIndividualFlags(); }
376 GtkWidget
* GetGtkHandle() { return m_column
; }
377 GtkWidget
* GetConstGtkHandle() const { return m_column
; }
380 // holds the GTK handle
383 // holds GTK handles for title/bitmap in the header
387 // delayed connection to mouse events
388 friend class wxDataViewCtrl
;
389 void OnInternalIdle();
392 void Init(wxAlignment align
, int flags
, int width
);
395 WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn
, wxDataViewColumnList
,
396 class WXDLLIMPEXP_ADV
);
398 // ---------------------------------------------------------
400 // ---------------------------------------------------------
402 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
410 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
411 const wxPoint
& pos
= wxDefaultPosition
,
412 const wxSize
& size
= wxDefaultSize
, long style
= 0,
413 const wxValidator
& validator
= wxDefaultValidator
)
415 Create(parent
, id
, pos
, size
, style
, validator
);
418 virtual ~wxDataViewCtrl();
422 bool Create(wxWindow
*parent
, wxWindowID id
,
423 const wxPoint
& pos
= wxDefaultPosition
,
424 const wxSize
& size
= wxDefaultSize
, long style
= 0,
425 const wxValidator
& validator
= wxDefaultValidator
);
427 virtual bool AssociateModel( wxDataViewModel
*model
);
429 virtual bool PrependColumn( wxDataViewColumn
*col
);
430 virtual bool AppendColumn( wxDataViewColumn
*col
);
431 virtual bool InsertColumn( unsigned int pos
, wxDataViewColumn
*col
);
433 virtual unsigned int GetColumnCount() const;
434 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const;
435 virtual bool DeleteColumn( wxDataViewColumn
*column
);
436 virtual bool ClearColumns();
437 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const;
439 virtual wxDataViewColumn
*GetSortingColumn() const;
441 virtual wxDataViewItem
GetSelection() const;
442 virtual int GetSelections( wxDataViewItemArray
& sel
) const;
443 virtual void SetSelections( const wxDataViewItemArray
& sel
);
444 virtual void Select( const wxDataViewItem
& item
);
445 virtual void Unselect( const wxDataViewItem
& item
);
446 virtual bool IsSelected( const wxDataViewItem
& item
) const;
447 virtual void SelectAll();
448 virtual void UnselectAll();
450 virtual void EnsureVisible( const wxDataViewItem
& item
,
451 const wxDataViewColumn
*column
= NULL
);
452 virtual void HitTest( const wxPoint
&point
,
453 wxDataViewItem
&item
,
454 wxDataViewColumn
*&column
) const;
455 virtual wxRect
GetItemRect( const wxDataViewItem
&item
,
456 const wxDataViewColumn
*column
= NULL
) const;
458 virtual void Expand( const wxDataViewItem
& item
);
459 virtual void Collapse( const wxDataViewItem
& item
);
460 virtual bool IsExpanded( const wxDataViewItem
& item
) const;
462 virtual bool EnableDragSource( const wxDataFormat
&format
);
463 virtual bool EnableDropTarget( const wxDataFormat
&format
);
465 static wxVisualAttributes
466 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
468 wxWindow
*GetMainWindow() { return (wxWindow
*) this; }
470 GtkWidget
*GtkGetTreeView() { return m_treeview
; }
471 wxDataViewCtrlInternal
* GtkGetInternal() { return m_internal
; }
473 virtual void OnInternalIdle();
476 virtual void DoSetExpanderColumn();
477 virtual void DoSetIndent();
479 virtual void DoApplyWidgetStyle(GtkRcStyle
*style
);
482 friend class wxDataViewCtrlDCImpl
;
483 friend class wxDataViewColumn
;
484 friend class wxGtkDataViewModelNotifier
;
485 friend class wxDataViewCtrlInternal
;
487 GtkWidget
*m_treeview
;
488 wxDataViewModelNotifier
*m_notifier
;
489 wxDataViewCtrlInternal
*m_internal
;
490 wxDataViewColumnList m_cols
;
492 virtual void AddChildGTK(wxWindowGTK
* child
);
493 void GtkEnableSelectionEvents();
494 void GtkDisableSelectionEvents();
496 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
497 wxDECLARE_NO_COPY_CLASS(wxDataViewCtrl
);
501 #endif // _WX_GTKDATAVIEWCTRL_H_