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;
41 virtual void EnableEllipsize(wxEllipsizeMode mode
= wxELLIPSIZE_MIDDLE
);
42 virtual wxEllipsizeMode
GetEllipsizeMode() const;
44 // GTK-specific implementation
45 // ---------------------------
47 // pack the GTK cell renderers used by this renderer to the given column
49 // by default only a single m_renderer is used but some renderers use more
50 // than one GTK cell renderer
51 virtual void GtkPackIntoColumn(GtkTreeViewColumn
*column
);
53 // called when the cell value was edited by user with the new value
55 // it validates the new value and notifies the model about the change by
56 // calling GtkOnCellChanged() if it was accepted
57 void GtkOnTextEdited(const gchar
*itempath
, const wxString
& value
);
59 GtkCellRenderer
* GetGtkHandle() { return m_renderer
; }
60 void GtkInitHandlers();
61 void GtkUpdateAlignment();
63 bool GtkIsUsingDefaultAttrs() const { return m_usingDefaultAttrs
; }
64 void GtkSetUsingDefaultAttrs(bool def
) { m_usingDefaultAttrs
= def
; }
67 virtual void GtkOnCellChanged(const wxVariant
& value
,
68 const wxDataViewItem
& item
,
72 GtkCellRenderer
*m_renderer
;
75 // true if we hadn't changed any visual attributes or restored them since
77 bool m_usingDefaultAttrs
;
80 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer
)
83 // ---------------------------------------------------------
84 // wxDataViewTextRenderer
85 // ---------------------------------------------------------
87 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewRenderer
90 wxDataViewTextRenderer( const wxString
&varianttype
= wxT("string"),
91 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
92 int align
= wxDVR_DEFAULT_ALIGNMENT
);
94 virtual bool SetValue( const wxVariant
&value
)
96 return SetTextValue(value
);
99 virtual bool GetValue( wxVariant
&value
) const
102 if ( !GetTextValue(str
) )
110 virtual void SetAlignment( int align
);
113 // implementation of Set/GetValue()
114 bool SetTextValue(const wxString
& str
);
115 bool GetTextValue(wxString
& str
) const;
118 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
121 // ---------------------------------------------------------
122 // wxDataViewBitmapRenderer
123 // ---------------------------------------------------------
125 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewRenderer
128 wxDataViewBitmapRenderer( const wxString
&varianttype
= wxT("wxBitmap"),
129 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
130 int align
= wxDVR_DEFAULT_ALIGNMENT
);
132 bool SetValue( const wxVariant
&value
);
133 bool GetValue( wxVariant
&value
) const;
136 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
139 // ---------------------------------------------------------
140 // wxDataViewToggleRenderer
141 // ---------------------------------------------------------
143 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewRenderer
146 wxDataViewToggleRenderer( const wxString
&varianttype
= wxT("bool"),
147 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
148 int align
= wxDVR_DEFAULT_ALIGNMENT
);
150 bool SetValue( const wxVariant
&value
);
151 bool GetValue( wxVariant
&value
) const;
154 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
157 // ---------------------------------------------------------
158 // wxDataViewCustomRenderer
159 // ---------------------------------------------------------
161 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewRenderer
164 wxDataViewCustomRenderer( const wxString
&varianttype
= wxT("string"),
165 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
166 int align
= wxDVR_DEFAULT_ALIGNMENT
,
167 bool no_init
= false );
168 virtual ~wxDataViewCustomRenderer();
171 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
) = 0;
173 void RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
);
175 virtual wxSize
GetSize() const = 0;
177 virtual bool Activate( wxRect
WXUNUSED(cell
),
178 wxDataViewModel
*WXUNUSED(model
), const wxDataViewItem
&WXUNUSED(item
), unsigned int WXUNUSED(col
) )
181 virtual bool LeftClick( wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
),
182 wxDataViewModel
*WXUNUSED(model
), const wxDataViewItem
&WXUNUSED(item
), unsigned int WXUNUSED(col
) )
184 virtual bool StartDrag( wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
),
185 wxDataViewModel
*WXUNUSED(model
), const wxDataViewItem
&WXUNUSED(item
), unsigned int WXUNUSED(col
) )
188 // Create DC on request
189 virtual wxDC
*GetDC();
194 bool Init(wxDataViewCellMode mode
, int align
);
200 // Internal, temporary for RenderText.
201 GtkCellRenderer
*m_text_renderer
;
204 void *background_area
;
210 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
213 // ---------------------------------------------------------
214 // wxDataViewProgressRenderer
215 // ---------------------------------------------------------
217 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
220 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
221 const wxString
&varianttype
= wxT("long"),
222 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
223 int align
= wxDVR_DEFAULT_ALIGNMENT
);
224 virtual ~wxDataViewProgressRenderer();
226 bool SetValue( const wxVariant
&value
);
227 bool GetValue( wxVariant
&value
) const;
229 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
230 virtual wxSize
GetSize() const;
237 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
240 // ---------------------------------------------------------
241 // wxDataViewIconTextRenderer
242 // ---------------------------------------------------------
244 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewTextRenderer
247 wxDataViewIconTextRenderer( const wxString
&varianttype
= wxT("wxDataViewIconText"),
248 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
249 int align
= wxDVR_DEFAULT_ALIGNMENT
);
250 virtual ~wxDataViewIconTextRenderer();
252 bool SetValue( const wxVariant
&value
);
253 bool GetValue( wxVariant
&value
) const;
255 virtual void GtkPackIntoColumn(GtkTreeViewColumn
*column
);
258 virtual void GtkOnCellChanged(const wxVariant
& value
,
259 const wxDataViewItem
& item
,
263 wxDataViewIconText m_value
;
265 // we use the base class m_renderer for the text and this one for the icon
266 GtkCellRenderer
*m_rendererIcon
;
268 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
271 // ---------------------------------------------------------
272 // wxDataViewDateRenderer
273 // ---------------------------------------------------------
275 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewCustomRenderer
278 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
279 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
280 int align
= wxDVR_DEFAULT_ALIGNMENT
);
282 bool SetValue( const wxVariant
&value
);
283 bool GetValue( wxVariant
&value
) const;
285 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
286 virtual wxSize
GetSize() const;
287 virtual bool Activate( wxRect cell
,
288 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
);
294 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
297 // -------------------------------------
298 // wxDataViewChoiceRenderer
299 // -------------------------------------
301 class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer
: public wxDataViewCustomRenderer
304 wxDataViewChoiceRenderer( const wxArrayString
&choices
,
305 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
306 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
307 virtual bool Render( wxRect rect
, wxDC
*dc
, int state
);
308 virtual wxSize
GetSize() const;
309 virtual bool SetValue( const wxVariant
&value
);
310 virtual bool GetValue( wxVariant
&value
) const;
312 void SetAlignment( int align
);
314 wxArrayString m_choices
;
318 // ---------------------------------------------------------
320 // ---------------------------------------------------------
322 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
325 wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*renderer
,
326 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
327 wxAlignment align
= wxALIGN_CENTER
,
328 int flags
= wxDATAVIEW_COL_RESIZABLE
);
329 wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
330 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
331 wxAlignment align
= wxALIGN_CENTER
,
332 int flags
= wxDATAVIEW_COL_RESIZABLE
);
337 virtual void SetTitle( const wxString
&title
);
338 virtual void SetBitmap( const wxBitmap
&bitmap
);
340 virtual void SetOwner( wxDataViewCtrl
*owner
);
342 virtual void SetAlignment( wxAlignment align
);
344 virtual void SetSortable( bool sortable
);
345 virtual void SetSortOrder( bool ascending
);
346 virtual void SetAsSortKey(bool sort
= true);
348 virtual void SetResizeable( bool resizeable
);
349 virtual void SetHidden( bool hidden
);
351 virtual void SetMinWidth( int minWidth
);
352 virtual void SetWidth( int width
);
354 virtual void SetReorderable( bool reorderable
);
356 virtual void SetFlags(int flags
) { SetIndividualFlags(flags
); }
360 virtual wxString
GetTitle() const;
361 virtual wxAlignment
GetAlignment() const;
363 virtual bool IsSortable() const;
364 virtual bool IsSortOrderAscending() const;
365 virtual bool IsSortKey() const;
367 virtual bool IsResizeable() const;
368 virtual bool IsHidden() const;
370 virtual int GetWidth() const;
371 virtual int GetMinWidth() const;
373 virtual bool IsReorderable() const;
375 virtual int GetFlags() const { return GetFromIndividualFlags(); }
378 GtkWidget
* GetGtkHandle() { return m_column
; }
379 GtkWidget
* GetConstGtkHandle() const { return m_column
; }
382 // holds the GTK handle
385 // holds GTK handles for title/bitmap in the header
389 // delayed connection to mouse events
390 friend class wxDataViewCtrl
;
391 void OnInternalIdle();
394 void Init(wxAlignment align
, int flags
, int width
);
397 WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn
, wxDataViewColumnList
,
398 class WXDLLIMPEXP_ADV
);
400 // ---------------------------------------------------------
402 // ---------------------------------------------------------
404 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
412 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
413 const wxPoint
& pos
= wxDefaultPosition
,
414 const wxSize
& size
= wxDefaultSize
, long style
= 0,
415 const wxValidator
& validator
= wxDefaultValidator
)
419 Create(parent
, id
, pos
, size
, style
, validator
);
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 ~wxDataViewCtrl();
429 virtual bool AssociateModel( wxDataViewModel
*model
);
431 virtual bool PrependColumn( wxDataViewColumn
*col
);
432 virtual bool AppendColumn( wxDataViewColumn
*col
);
433 virtual bool InsertColumn( unsigned int pos
, wxDataViewColumn
*col
);
435 virtual unsigned int GetColumnCount() const;
436 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const;
437 virtual bool DeleteColumn( wxDataViewColumn
*column
);
438 virtual bool ClearColumns();
439 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const;
441 virtual wxDataViewColumn
*GetSortingColumn() const;
443 virtual wxDataViewItem
GetSelection() const;
444 virtual int GetSelections( wxDataViewItemArray
& sel
) const;
445 virtual void SetSelections( const wxDataViewItemArray
& sel
);
446 virtual void Select( const wxDataViewItem
& item
);
447 virtual void Unselect( const wxDataViewItem
& item
);
448 virtual bool IsSelected( const wxDataViewItem
& item
) const;
449 virtual void SelectAll();
450 virtual void UnselectAll();
452 virtual void EnsureVisible( const wxDataViewItem
& item
,
453 const wxDataViewColumn
*column
= NULL
);
454 virtual void HitTest( const wxPoint
&point
,
455 wxDataViewItem
&item
,
456 wxDataViewColumn
*&column
) const;
457 virtual wxRect
GetItemRect( const wxDataViewItem
&item
,
458 const wxDataViewColumn
*column
= NULL
) const;
460 virtual void Expand( const wxDataViewItem
& item
);
461 virtual void Collapse( const wxDataViewItem
& item
);
462 virtual bool IsExpanded( const wxDataViewItem
& item
) const;
464 virtual bool EnableDragSource( const wxDataFormat
&format
);
465 virtual bool EnableDropTarget( const wxDataFormat
&format
);
467 static wxVisualAttributes
468 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
470 wxWindow
*GetMainWindow() { return (wxWindow
*) this; }
472 GtkWidget
*GtkGetTreeView() { return m_treeview
; }
473 wxDataViewCtrlInternal
* GtkGetInternal() { return m_internal
; }
475 virtual void OnInternalIdle();
478 virtual void DoSetExpanderColumn();
479 virtual void DoSetIndent();
481 virtual void DoApplyWidgetStyle(GtkRcStyle
*style
);
486 friend class wxDataViewCtrlDCImpl
;
487 friend class wxDataViewColumn
;
488 friend class wxGtkDataViewModelNotifier
;
489 friend class wxDataViewCtrlInternal
;
491 GtkWidget
*m_treeview
;
492 wxDataViewModelNotifier
*m_notifier
;
493 wxDataViewCtrlInternal
*m_internal
;
494 wxDataViewColumnList m_cols
;
496 virtual void AddChildGTK(wxWindowGTK
* child
);
497 void GtkEnableSelectionEvents();
498 void GtkDisableSelectionEvents();
500 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
501 wxDECLARE_NO_COPY_CLASS(wxDataViewCtrl
);
505 #endif // _WX_GTKDATAVIEWCTRL_H_