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 void GtkUpdateAlignment();
45 bool GtkIsUsingDefaultAttrs() const { return m_usingDefaultAttrs
; }
46 void GtkSetUsingDefaultAttrs(bool def
) { m_usingDefaultAttrs
= def
; }
49 GtkCellRenderer
*m_renderer
;
52 // true if we hadn't changed any visual attributes or restored them since
54 bool m_usingDefaultAttrs
;
57 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer
)
60 // ---------------------------------------------------------
61 // wxDataViewTextRenderer
62 // ---------------------------------------------------------
64 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewRenderer
67 wxDataViewTextRenderer( const wxString
&varianttype
= wxT("string"),
68 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
69 int align
= wxDVR_DEFAULT_ALIGNMENT
);
71 bool SetValue( const wxVariant
&value
);
72 bool GetValue( wxVariant
&value
) const;
74 void SetAlignment( int align
);
77 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
80 // ---------------------------------------------------------
81 // wxDataViewBitmapRenderer
82 // ---------------------------------------------------------
84 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewRenderer
87 wxDataViewBitmapRenderer( const wxString
&varianttype
= wxT("wxBitmap"),
88 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
89 int align
= wxDVR_DEFAULT_ALIGNMENT
);
91 bool SetValue( const wxVariant
&value
);
92 bool GetValue( wxVariant
&value
) const;
95 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
98 // ---------------------------------------------------------
99 // wxDataViewToggleRenderer
100 // ---------------------------------------------------------
102 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewRenderer
105 wxDataViewToggleRenderer( const wxString
&varianttype
= wxT("bool"),
106 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
107 int align
= wxDVR_DEFAULT_ALIGNMENT
);
109 bool SetValue( const wxVariant
&value
);
110 bool GetValue( wxVariant
&value
) const;
113 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
116 // ---------------------------------------------------------
117 // wxDataViewCustomRenderer
118 // ---------------------------------------------------------
120 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewRenderer
123 wxDataViewCustomRenderer( const wxString
&varianttype
= wxT("string"),
124 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
125 int align
= wxDVR_DEFAULT_ALIGNMENT
,
126 bool no_init
= false );
127 virtual ~wxDataViewCustomRenderer();
130 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
) = 0;
132 void RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
);
134 virtual wxSize
GetSize() const = 0;
136 virtual bool Activate( wxRect
WXUNUSED(cell
),
137 wxDataViewModel
*WXUNUSED(model
), const wxDataViewItem
&WXUNUSED(item
), unsigned int WXUNUSED(col
) )
140 virtual bool LeftClick( wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
),
141 wxDataViewModel
*WXUNUSED(model
), const wxDataViewItem
&WXUNUSED(item
), unsigned int WXUNUSED(col
) )
143 virtual bool StartDrag( wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
),
144 wxDataViewModel
*WXUNUSED(model
), const wxDataViewItem
&WXUNUSED(item
), unsigned int WXUNUSED(col
) )
147 // Create DC on request
148 virtual wxDC
*GetDC();
153 bool Init(wxDataViewCellMode mode
, int align
);
159 // Internal, temporay for RenderText.
160 GtkCellRenderer
*m_text_renderer
;
163 void *background_area
;
169 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
172 // ---------------------------------------------------------
173 // wxDataViewProgressRenderer
174 // ---------------------------------------------------------
176 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
179 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
180 const wxString
&varianttype
= wxT("long"),
181 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
182 int align
= wxDVR_DEFAULT_ALIGNMENT
);
183 virtual ~wxDataViewProgressRenderer();
185 bool SetValue( const wxVariant
&value
);
186 bool GetValue( wxVariant
&value
) const;
188 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
189 virtual wxSize
GetSize() const;
196 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
199 // ---------------------------------------------------------
200 // wxDataViewIconTextRenderer
201 // ---------------------------------------------------------
203 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewCustomRenderer
206 wxDataViewIconTextRenderer( const wxString
&varianttype
= wxT("wxDataViewIconText"),
207 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
208 int align
= wxDVR_DEFAULT_ALIGNMENT
);
209 virtual ~wxDataViewIconTextRenderer();
211 bool SetValue( const wxVariant
&value
);
212 bool GetValue( wxVariant
&value
) const;
214 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
215 virtual wxSize
GetSize() const;
217 virtual bool HasEditorCtrl() const { return true; }
218 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
219 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
222 wxDataViewIconText m_value
;
225 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
228 // ---------------------------------------------------------
229 // wxDataViewDateRenderer
230 // ---------------------------------------------------------
232 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewCustomRenderer
235 wxDataViewDateRenderer( const wxString
&varianttype
= wxT("datetime"),
236 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
237 int align
= wxDVR_DEFAULT_ALIGNMENT
);
239 bool SetValue( const wxVariant
&value
);
240 bool GetValue( wxVariant
&value
) const;
242 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
243 virtual wxSize
GetSize() const;
244 virtual bool Activate( wxRect cell
,
245 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
);
251 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
254 // -------------------------------------
255 // wxDataViewChoiceRenderer
256 // -------------------------------------
258 class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer
: public wxDataViewCustomRenderer
261 wxDataViewChoiceRenderer( const wxArrayString
&choices
,
262 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
263 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
264 virtual bool Render( wxRect rect
, wxDC
*dc
, int state
);
265 virtual wxSize
GetSize() const;
266 virtual bool SetValue( const wxVariant
&value
);
267 virtual bool GetValue( wxVariant
&value
) const;
269 void SetAlignment( int align
);
271 wxArrayString m_choices
;
275 // ---------------------------------------------------------
277 // ---------------------------------------------------------
279 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
282 wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*renderer
,
283 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
284 wxAlignment align
= wxALIGN_CENTER
,
285 int flags
= wxDATAVIEW_COL_RESIZABLE
);
286 wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
287 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
288 wxAlignment align
= wxALIGN_CENTER
,
289 int flags
= wxDATAVIEW_COL_RESIZABLE
);
294 virtual void SetTitle( const wxString
&title
);
295 virtual void SetBitmap( const wxBitmap
&bitmap
);
297 virtual void SetOwner( wxDataViewCtrl
*owner
);
299 virtual void SetAlignment( wxAlignment align
);
301 virtual void SetSortable( bool sortable
);
302 virtual void SetSortOrder( bool ascending
);
303 virtual void SetAsSortKey(bool sort
= true);
305 virtual void SetResizeable( bool resizeable
);
306 virtual void SetHidden( bool hidden
);
308 virtual void SetMinWidth( int minWidth
);
309 virtual void SetWidth( int width
);
311 virtual void SetReorderable( bool reorderable
);
313 virtual void SetFlags(int flags
) { SetIndividualFlags(flags
); }
317 virtual wxString
GetTitle() const;
318 virtual wxAlignment
GetAlignment() const;
320 virtual bool IsSortable() const;
321 virtual bool IsSortOrderAscending() const;
322 virtual bool IsSortKey() const;
324 virtual bool IsResizeable() const;
325 virtual bool IsHidden() const;
327 virtual int GetWidth() const;
328 virtual int GetMinWidth() const;
330 virtual bool IsReorderable() const;
332 virtual int GetFlags() const { return GetFromIndividualFlags(); }
335 GtkWidget
* GetGtkHandle() { return m_column
; }
336 GtkWidget
* GetConstGtkHandle() const { return m_column
; }
339 // holds the GTK handle
342 // holds GTK handles for title/bitmap in the header
346 // delayed connection to mouse events
347 friend class wxDataViewCtrl
;
348 void OnInternalIdle();
351 void Init(wxAlignment align
, int flags
, int width
);
354 WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn
, wxDataViewColumnList
,
355 class WXDLLIMPEXP_ADV
);
357 // ---------------------------------------------------------
359 // ---------------------------------------------------------
361 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
369 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
370 const wxPoint
& pos
= wxDefaultPosition
,
371 const wxSize
& size
= wxDefaultSize
, long style
= 0,
372 const wxValidator
& validator
= wxDefaultValidator
)
374 Create(parent
, id
, pos
, size
, style
, validator
);
377 virtual ~wxDataViewCtrl();
381 bool Create(wxWindow
*parent
, wxWindowID id
,
382 const wxPoint
& pos
= wxDefaultPosition
,
383 const wxSize
& size
= wxDefaultSize
, long style
= 0,
384 const wxValidator
& validator
= wxDefaultValidator
);
386 virtual bool AssociateModel( wxDataViewModel
*model
);
388 virtual bool PrependColumn( wxDataViewColumn
*col
);
389 virtual bool AppendColumn( wxDataViewColumn
*col
);
390 virtual bool InsertColumn( unsigned int pos
, wxDataViewColumn
*col
);
392 virtual unsigned int GetColumnCount() const;
393 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const;
394 virtual bool DeleteColumn( wxDataViewColumn
*column
);
395 virtual bool ClearColumns();
396 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const;
398 virtual wxDataViewColumn
*GetSortingColumn() const;
400 virtual wxDataViewItem
GetSelection() const;
401 virtual int GetSelections( wxDataViewItemArray
& sel
) const;
402 virtual void SetSelections( const wxDataViewItemArray
& sel
);
403 virtual void Select( const wxDataViewItem
& item
);
404 virtual void Unselect( const wxDataViewItem
& item
);
405 virtual bool IsSelected( const wxDataViewItem
& item
) const;
406 virtual void SelectAll();
407 virtual void UnselectAll();
409 virtual void EnsureVisible( const wxDataViewItem
& item
,
410 const wxDataViewColumn
*column
= NULL
);
411 virtual void HitTest( const wxPoint
&point
,
412 wxDataViewItem
&item
,
413 wxDataViewColumn
*&column
) const;
414 virtual wxRect
GetItemRect( const wxDataViewItem
&item
,
415 const wxDataViewColumn
*column
= NULL
) const;
417 virtual void Expand( const wxDataViewItem
& item
);
418 virtual void Collapse( const wxDataViewItem
& item
);
419 virtual bool IsExpanded( const wxDataViewItem
& item
) const;
421 virtual bool EnableDragSource( const wxDataFormat
&format
);
422 virtual bool EnableDropTarget( const wxDataFormat
&format
);
424 static wxVisualAttributes
425 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
427 wxWindow
*GetMainWindow() { return (wxWindow
*) this; }
429 GtkWidget
*GtkGetTreeView() { return m_treeview
; }
430 wxDataViewCtrlInternal
* GtkGetInternal() { return m_internal
; }
432 virtual void OnInternalIdle();
435 virtual void DoSetExpanderColumn();
436 virtual void DoSetIndent();
438 virtual void DoApplyWidgetStyle(GtkRcStyle
*style
);
441 friend class wxDataViewCtrlDCImpl
;
442 friend class wxDataViewColumn
;
443 friend class wxGtkDataViewModelNotifier
;
444 friend class wxDataViewCtrlInternal
;
446 GtkWidget
*m_treeview
;
447 wxDataViewModelNotifier
*m_notifier
;
448 wxDataViewCtrlInternal
*m_internal
;
449 wxDataViewColumnList m_cols
;
451 virtual void AddChildGTK(wxWindowGTK
* child
);
452 void GtkEnableSelectionEvents();
453 void GtkDisableSelectionEvents();
455 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
456 wxDECLARE_NO_COPY_CLASS(wxDataViewCtrl
);
460 #endif // _WX_GTKDATAVIEWCTRL_H_