1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/dataview.cpp
3 // Purpose: wxDataViewCtrl GTK+2 implementation
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if wxUSE_DATAVIEWCTRL
15 #include "wx/dataview.h"
17 #ifndef wxUSE_GENERICDATAVIEWCTRL
21 #include "wx/dcclient.h"
23 #include "wx/settings.h"
27 #include "wx/stockitem.h"
28 #include "wx/calctrl.h"
29 #include "wx/popupwin.h"
30 #include "wx/listimpl.cpp"
32 #include "wx/gtk/private.h"
33 #include "wx/gtk/dc.h"
34 #include "wx/gtk/dcclient.h"
36 #include "wx/gtk/private/gdkconv.h"
37 #include "wx/gtk/private/list.h"
38 using namespace wxGTKImpl
;
40 class wxGtkDataViewModelNotifier
;
42 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 static wxDataViewCtrlInternal
*gs_internal
= NULL
;
47 class wxGtkTreeModelNode
;
50 typedef struct _GtkWxTreeModel GtkWxTreeModel
;
53 // ----------------------------------------------------------------------------
54 // wxGtkTreePath: self-destroying GtkTreePath
55 // ----------------------------------------------------------------------------
57 // Usually this object is initialized with the associated GtkTreePath
58 // immediately when it's constructed but it can also be changed later either by
59 // using Assign() or by getting the pointer to the internally stored pointer
60 // value using ByRef(). The latter should be avoided but is very convenient
61 // when using GTK functions with GtkTreePath output parameters.
65 // Ctor takes ownership of the given path and will free it if non-NULL.
66 wxGtkTreePath(GtkTreePath
*path
= NULL
) : m_path(path
) { }
68 // Creates a tree path for the given string path.
69 wxGtkTreePath(const gchar
*strpath
)
70 : m_path(gtk_tree_path_new_from_string(strpath
))
74 // Set the stored pointer if not done by ctor.
75 void Assign(GtkTreePath
*path
)
77 wxASSERT_MSG( !m_path
, "shouldn't be already initialized" );
82 // Return the pointer to the internally stored pointer. This should only be
83 // used to initialize the object by passing it to some GTK function.
86 wxASSERT_MSG( !m_path
, "shouldn't be already initialized" );
92 operator GtkTreePath
*() const { return m_path
; }
94 ~wxGtkTreePath() { if ( m_path
) gtk_tree_path_free(m_path
); }
99 wxDECLARE_NO_COPY_CLASS(wxGtkTreePath
);
102 // ----------------------------------------------------------------------------
103 // wxGtkTreePathList: self-destroying list of GtkTreePath objects.
104 // ----------------------------------------------------------------------------
106 class wxGtkTreePathList
: public wxGtkList
109 // Ctor takes ownership of the list.
110 explicit wxGtkTreePathList(GList
* list
)
117 // Delete the list contents, wxGtkList will delete the list itself.
118 g_list_foreach(m_list
, (GFunc
)gtk_tree_path_free
, NULL
);
122 // ----------------------------------------------------------------------------
123 // wxGtkTreeSelectionLock: prevent selection from changing during the
124 // lifetime of this object
125 // ----------------------------------------------------------------------------
127 // Implementation note: it could be expected that setting the selection
128 // function in this class ctor and resetting it back to the old value in its
129 // dtor would work. However currently gtk_tree_selection_get_select_function()
130 // can't be passed NULL (see https://bugzilla.gnome.org/show_bug.cgi?id=626276)
131 // so we can't do this. Instead, we always use the selection function (which
132 // imposes extra overhead, albeit minimal one, on all selection operations) and
133 // just set/reset the flag telling it whether it should allow or forbid the
136 // Also notice that currently only a single object of this class may exist at
137 // any given moment. It's just simpler like this and we don't need anything
141 gboolean
wxdataview_selection_func(GtkTreeSelection
* WXUNUSED(selection
),
142 GtkTreeModel
* WXUNUSED(model
),
143 GtkTreePath
* WXUNUSED(path
),
144 gboolean
WXUNUSED(path_currently_selected
),
150 class wxGtkTreeSelectionLock
153 wxGtkTreeSelectionLock(GtkTreeSelection
*selection
)
154 : m_selection(selection
)
156 wxASSERT_MSG( !ms_instance
, "this class is not reentrant currently" );
160 CheckCurrentSelectionFunc(NULL
);
162 // Pass some non-NULL pointer as "data" for the callback, it doesn't
163 // matter what it is as long as it's non-NULL.
164 gtk_tree_selection_set_select_function(selection
,
165 wxdataview_selection_func
,
170 ~wxGtkTreeSelectionLock()
172 CheckCurrentSelectionFunc(wxdataview_selection_func
);
174 gtk_tree_selection_set_select_function(m_selection
,
175 wxdataview_selection_func
,
183 void CheckCurrentSelectionFunc(GtkTreeSelectionFunc func
)
185 // We can only use gtk_tree_selection_get_select_function() with 2.14+
186 // so check for its availability both during compile- and run-time.
187 #if GTK_CHECK_VERSION(2, 14, 0)
188 if ( gtk_check_version(2, 14, 0) != NULL
)
191 // If this assert is triggered, it means the code elsewhere has called
192 // gtk_tree_selection_set_select_function() but currently doing this
193 // breaks this class so the code here needs to be changed.
196 gtk_tree_selection_get_select_function(m_selection
) == func
,
197 "selection function has changed unexpectedly, review this code!"
204 static wxGtkTreeSelectionLock
*ms_instance
;
206 GtkTreeSelection
* const m_selection
;
208 wxDECLARE_NO_COPY_CLASS(wxGtkTreeSelectionLock
);
211 wxGtkTreeSelectionLock
*wxGtkTreeSelectionLock::ms_instance
= NULL
;
213 //-----------------------------------------------------------------------------
214 // wxDataViewCtrlInternal
215 //-----------------------------------------------------------------------------
217 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
218 WX_DEFINE_LIST(ItemList
)
220 class wxDataViewCtrlInternal
223 wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
);
224 ~wxDataViewCtrlInternal();
227 GtkTreeModelFlags
get_flags();
228 gboolean
get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
);
229 GtkTreePath
*get_path( GtkTreeIter
*iter
);
230 gboolean
iter_next( GtkTreeIter
*iter
);
231 gboolean
iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
);
232 gboolean
iter_has_child( GtkTreeIter
*iter
);
233 gint
iter_n_children( GtkTreeIter
*iter
);
234 gboolean
iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
);
235 gboolean
iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
);
239 bool EnableDragSource( const wxDataFormat
&format
);
240 bool EnableDropTarget( const wxDataFormat
&format
);
242 gboolean
row_draggable( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
);
243 gboolean
drag_data_delete( GtkTreeDragSource
*drag_source
, GtkTreePath
* path
);
244 gboolean
drag_data_get( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
,
245 GtkSelectionData
*selection_data
);
246 gboolean
drag_data_received( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest
,
247 GtkSelectionData
*selection_data
);
248 gboolean
row_drop_possible( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest_path
,
249 GtkSelectionData
*selection_data
);
251 // notifactions from wxDataViewModel
252 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
253 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
254 bool ItemChanged( const wxDataViewItem
&item
);
255 bool ValueChanged( const wxDataViewItem
&item
, unsigned int model_column
);
262 void SetSortOrder( GtkSortType sort_order
) { m_sort_order
= sort_order
; }
263 GtkSortType
GetSortOrder() const { return m_sort_order
; }
265 void SetSortColumn( int column
) { m_sort_column
= column
; }
266 int GetSortColumn() const { return m_sort_column
; }
268 void SetDataViewSortColumn( wxDataViewColumn
*column
) { m_dataview_sort_column
= column
; }
269 wxDataViewColumn
*GetDataViewSortColumn() { return m_dataview_sort_column
; }
271 bool IsSorted() { return (m_sort_column
>= 0); }
274 wxDataViewModel
* GetDataViewModel() { return m_wx_model
; }
275 const wxDataViewModel
* GetDataViewModel() const { return m_wx_model
; }
276 wxDataViewCtrl
* GetOwner() { return m_owner
; }
277 GtkWxTreeModel
* GetGtkModel() { return m_gtk_model
; }
279 // item can be deleted already in the model
280 int GetIndexOf( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
282 virtual void OnInternalIdle();
286 void ScheduleRefresh();
288 wxGtkTreeModelNode
*FindNode( const wxDataViewItem
&item
);
289 wxGtkTreeModelNode
*FindNode( GtkTreeIter
*iter
);
290 wxGtkTreeModelNode
*FindParentNode( const wxDataViewItem
&item
);
291 wxGtkTreeModelNode
*FindParentNode( GtkTreeIter
*iter
);
292 void BuildBranch( wxGtkTreeModelNode
*branch
);
295 wxGtkTreeModelNode
*m_root
;
296 wxDataViewModel
*m_wx_model
;
297 GtkWxTreeModel
*m_gtk_model
;
298 wxDataViewCtrl
*m_owner
;
299 GtkSortType m_sort_order
;
300 wxDataViewColumn
*m_dataview_sort_column
;
303 GtkTargetEntry m_dragSourceTargetEntry
;
304 wxCharBuffer m_dragSourceTargetEntryTarget
;
305 wxDataObject
*m_dragDataObject
;
307 GtkTargetEntry m_dropTargetTargetEntry
;
308 wxCharBuffer m_dropTargetTargetEntryTarget
;
309 wxDataObject
*m_dropDataObject
;
311 wxGtkDataViewModelNotifier
*m_notifier
;
317 //-----------------------------------------------------------------------------
318 // wxGtkTreeModelNode
319 //-----------------------------------------------------------------------------
322 int LINKAGEMODE
wxGtkTreeModelChildCmp( void** id1
, void** id2
)
324 int ret
= gs_internal
->GetDataViewModel()->Compare( wxDataViewItem(*id1
), wxDataViewItem(*id2
),
325 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
330 WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode
*, wxGtkTreeModelNodes
);
331 WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren
);
333 class wxGtkTreeModelNode
336 wxGtkTreeModelNode( wxGtkTreeModelNode
* parent
, const wxDataViewItem
&item
,
337 wxDataViewCtrlInternal
*internal
)
341 m_internal
= internal
;
344 ~wxGtkTreeModelNode()
346 size_t count
= m_nodes
.GetCount();
348 for (i
= 0; i
< count
; i
++)
350 wxGtkTreeModelNode
*child
= m_nodes
.Item( i
);
355 unsigned int AddNode( wxGtkTreeModelNode
* child
)
357 m_nodes
.Add( child
);
359 void *id
= child
->GetItem().GetID();
361 m_children
.Add( id
);
363 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
365 gs_internal
= m_internal
;
366 m_children
.Sort( &wxGtkTreeModelChildCmp
);
367 return m_children
.Index( id
);
370 return m_children
.GetCount()-1;
373 unsigned int AddLeave( void* id
)
375 m_children
.Add( id
);
377 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
379 gs_internal
= m_internal
;
380 m_children
.Sort( &wxGtkTreeModelChildCmp
);
381 return m_children
.Index( id
);
384 return m_children
.GetCount()-1;
387 void DeleteChild( void* id
)
389 m_children
.Remove( id
);
391 unsigned int count
= m_nodes
.GetCount();
393 for (pos
= 0; pos
< count
; pos
++)
395 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
396 if (node
->GetItem().GetID() == id
)
398 m_nodes
.RemoveAt( pos
);
405 wxGtkTreeModelNode
* GetParent()
407 wxGtkTreeModelNodes
&GetNodes()
409 wxGtkTreeModelChildren
&GetChildren()
410 { return m_children
; }
412 unsigned int GetChildCount() const { return m_children
.GetCount(); }
413 unsigned int GetNodesCount() const { return m_nodes
.GetCount(); }
415 wxDataViewItem
&GetItem() { return m_item
; }
416 wxDataViewCtrlInternal
*GetInternal() { return m_internal
; }
421 wxGtkTreeModelNode
*m_parent
;
422 wxGtkTreeModelNodes m_nodes
;
423 wxGtkTreeModelChildren m_children
;
424 wxDataViewItem m_item
;
425 wxDataViewCtrlInternal
*m_internal
;
429 //-----------------------------------------------------------------------------
431 //-----------------------------------------------------------------------------
433 extern bool g_blockEventsOnDrag
;
435 //-----------------------------------------------------------------------------
436 // define new GTK+ class wxGtkTreeModel
437 //-----------------------------------------------------------------------------
441 #define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ())
442 #define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel))
443 #define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
444 #define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL))
445 #define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL))
446 #define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
448 GType
gtk_wx_tree_model_get_type (void);
450 typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass
;
452 struct _GtkWxTreeModel
458 wxDataViewCtrlInternal
*internal
;
461 struct _GtkWxTreeModelClass
463 GObjectClass list_parent_class
;
466 static GtkWxTreeModel
*wxgtk_tree_model_new (void);
467 static void wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
);
468 static void wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
);
470 static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
);
471 static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
);
472 static void wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
);
473 static void wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
);
475 static void wxgtk_tree_model_finalize (GObject
*object
);
476 static GtkTreeModelFlags
wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
);
477 static gint
wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
);
478 static GType
wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
480 static gboolean
wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
483 static GtkTreePath
*wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
485 static void wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
489 static gboolean
wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
491 static gboolean
wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
493 GtkTreeIter
*parent
);
494 static gboolean
wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
496 static gint
wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
498 static gboolean
wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
502 static gboolean
wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
507 static gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
508 gint
*sort_column_id
,
510 static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
513 static void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
515 GtkTreeIterCompareFunc func
,
517 GDestroyNotify destroy
);
518 static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
519 GtkTreeIterCompareFunc func
,
521 GDestroyNotify destroy
);
522 static gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
);
525 static gboolean
wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
527 static gboolean
wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
529 static gboolean
wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
531 GtkSelectionData
*selection_data
);
532 static gboolean
wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
534 GtkSelectionData
*selection_data
);
535 static gboolean
wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
536 GtkTreePath
*dest_path
,
537 GtkSelectionData
*selection_data
);
540 static GObjectClass
*list_parent_class
= NULL
;
543 gtk_wx_tree_model_get_type (void)
545 static GType tree_model_type
= 0;
547 if (!tree_model_type
)
549 const GTypeInfo tree_model_info
=
551 sizeof (GtkWxTreeModelClass
),
552 NULL
, /* base_init */
553 NULL
, /* base_finalize */
554 (GClassInitFunc
) wxgtk_tree_model_class_init
,
555 NULL
, /* class_finalize */
556 NULL
, /* class_data */
557 sizeof (GtkWxTreeModel
),
559 (GInstanceInitFunc
) wxgtk_tree_model_init
,
562 static const GInterfaceInfo tree_model_iface_info
=
564 (GInterfaceInitFunc
) wxgtk_tree_model_tree_model_init
,
569 static const GInterfaceInfo sortable_iface_info
=
571 (GInterfaceInitFunc
) wxgtk_tree_model_sortable_init
,
576 static const GInterfaceInfo drag_source_iface_info
=
578 (GInterfaceInitFunc
) wxgtk_tree_model_drag_source_init
,
583 static const GInterfaceInfo drag_dest_iface_info
=
585 (GInterfaceInitFunc
) wxgtk_tree_model_drag_dest_init
,
590 tree_model_type
= g_type_register_static (G_TYPE_OBJECT
, "GtkWxTreeModel",
591 &tree_model_info
, (GTypeFlags
)0 );
593 g_type_add_interface_static (tree_model_type
,
595 &tree_model_iface_info
);
596 g_type_add_interface_static (tree_model_type
,
597 GTK_TYPE_TREE_SORTABLE
,
598 &sortable_iface_info
);
599 g_type_add_interface_static (tree_model_type
,
600 GTK_TYPE_TREE_DRAG_DEST
,
601 &drag_dest_iface_info
);
602 g_type_add_interface_static (tree_model_type
,
603 GTK_TYPE_TREE_DRAG_SOURCE
,
604 &drag_source_iface_info
);
607 return tree_model_type
;
610 static GtkWxTreeModel
*
611 wxgtk_tree_model_new(void)
613 GtkWxTreeModel
*retval
= (GtkWxTreeModel
*) g_object_new (GTK_TYPE_WX_TREE_MODEL
, NULL
);
618 wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
)
620 list_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
621 GObjectClass
*object_class
= (GObjectClass
*) klass
;
622 object_class
->finalize
= wxgtk_tree_model_finalize
;
626 wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
)
628 iface
->get_flags
= wxgtk_tree_model_get_flags
;
629 iface
->get_n_columns
= wxgtk_tree_model_get_n_columns
;
630 iface
->get_column_type
= wxgtk_tree_model_get_column_type
;
631 iface
->get_iter
= wxgtk_tree_model_get_iter
;
632 iface
->get_path
= wxgtk_tree_model_get_path
;
633 iface
->get_value
= wxgtk_tree_model_get_value
;
634 iface
->iter_next
= wxgtk_tree_model_iter_next
;
635 iface
->iter_children
= wxgtk_tree_model_iter_children
;
636 iface
->iter_has_child
= wxgtk_tree_model_iter_has_child
;
637 iface
->iter_n_children
= wxgtk_tree_model_iter_n_children
;
638 iface
->iter_nth_child
= wxgtk_tree_model_iter_nth_child
;
639 iface
->iter_parent
= wxgtk_tree_model_iter_parent
;
643 wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
)
645 iface
->get_sort_column_id
= wxgtk_tree_model_get_sort_column_id
;
646 iface
->set_sort_column_id
= wxgtk_tree_model_set_sort_column_id
;
647 iface
->set_sort_func
= wxgtk_tree_model_set_sort_func
;
648 iface
->set_default_sort_func
= wxgtk_tree_model_set_default_sort_func
;
649 iface
->has_default_sort_func
= wxgtk_tree_model_has_default_sort_func
;
653 wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
)
655 iface
->row_draggable
= wxgtk_tree_model_row_draggable
;
656 iface
->drag_data_delete
= wxgtk_tree_model_drag_data_delete
;
657 iface
->drag_data_get
= wxgtk_tree_model_drag_data_get
;
661 wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
)
663 iface
->drag_data_received
= wxgtk_tree_model_drag_data_received
;
664 iface
->row_drop_possible
= wxgtk_tree_model_row_drop_possible
;
668 wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
)
670 tree_model
->internal
= NULL
;
671 tree_model
->stamp
= g_random_int();
675 wxgtk_tree_model_finalize (GObject
*object
)
678 (* list_parent_class
->finalize
) (object
);
683 //-----------------------------------------------------------------------------
684 // implement callbacks from wxGtkTreeModel class by letting
685 // them call the methods of wxWidgets' wxDataViewModel
686 //-----------------------------------------------------------------------------
688 static GtkTreeModelFlags
689 wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
)
691 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
692 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), (GtkTreeModelFlags
)0 );
694 return wxtree_model
->internal
->get_flags();
698 wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
)
700 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
701 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
703 return wxtree_model
->internal
->GetDataViewModel()->GetColumnCount();
707 wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
710 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
711 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), G_TYPE_INVALID
);
713 GType gtype
= G_TYPE_INVALID
;
715 wxString wxtype
= wxtree_model
->internal
->GetDataViewModel()->GetColumnType( (unsigned int) index
);
717 if (wxtype
== wxT("string"))
718 gtype
= G_TYPE_STRING
;
721 gtype
= G_TYPE_POINTER
;
722 // wxFAIL_MSG( wxT("non-string columns not supported for searching yet") );
729 wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
733 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
734 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
735 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
737 return wxtree_model
->internal
->get_iter( iter
, path
);
741 wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
744 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
745 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), NULL
);
746 g_return_val_if_fail (iter
->stamp
== GTK_WX_TREE_MODEL (wxtree_model
)->stamp
, NULL
);
748 return wxtree_model
->internal
->get_path( iter
);
752 wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
757 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
758 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
) );
760 wxDataViewModel
*model
= wxtree_model
->internal
->GetDataViewModel();
761 wxString mtype
= model
->GetColumnType( (unsigned int) column
);
762 if (mtype
== wxT("string"))
765 g_value_init( value
, G_TYPE_STRING
);
766 wxDataViewItem
item( (void*) iter
->user_data
);
767 model
->GetValue( variant
, item
, (unsigned int) column
);
769 g_value_set_string( value
, variant
.GetString().utf8_str() );
773 wxFAIL_MSG( wxT("non-string columns not supported yet") );
778 wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
781 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
783 // This happens when clearing the view by calling .._set_model( NULL );
784 if (iter
->stamp
== 0) return FALSE
;
786 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
787 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
789 return wxtree_model
->internal
->iter_next( iter
);
793 wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
797 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
798 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
801 g_return_val_if_fail (wxtree_model
->stamp
== parent
->stamp
, FALSE
);
804 return wxtree_model
->internal
->iter_children( iter
, parent
);
808 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
811 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
812 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
813 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
815 return wxtree_model
->internal
->iter_has_child( iter
);
819 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
822 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
823 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
824 g_return_val_if_fail ( !iter
|| wxtree_model
->stamp
== iter
->stamp
, 0);
826 return wxtree_model
->internal
->iter_n_children( iter
);
830 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
835 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
836 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
838 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
842 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
846 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
847 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
848 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
850 return wxtree_model
->internal
->iter_parent( iter
, child
);
853 /* drag'n'drop iface */
855 wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
858 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
859 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
861 return wxtree_model
->internal
->row_draggable( drag_source
, path
);
865 wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
868 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
869 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
871 return wxtree_model
->internal
->drag_data_delete( drag_source
, path
);
875 wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
877 GtkSelectionData
*selection_data
)
879 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
880 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
883 wxPrintf( "drag_get_data\n");
885 wxGtkString
atom_selection(gdk_atom_name(selection_data
->selection
));
886 wxPrintf( "selection %s\n", wxString::FromAscii(atom_selection
) );
888 wxGtkString
atom_target(gdk_atom_name(selection_data
->target
));
889 wxPrintf( "target %s\n", wxString::FromAscii(atom_target
) );
891 wxGtkString
atom_type(gdk_atom_name(selection_data
->type
));
892 wxPrintf( "type %s\n", wxString::FromAscii(atom_type
) );
894 wxPrintf( "format %d\n", selection_data
->format
);
897 return wxtree_model
->internal
->drag_data_get( drag_source
, path
, selection_data
);
901 wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
903 GtkSelectionData
*selection_data
)
905 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
906 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
908 return wxtree_model
->internal
->drag_data_received( drag_dest
, dest
, selection_data
);
912 wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
913 GtkTreePath
*dest_path
,
914 GtkSelectionData
*selection_data
)
916 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
917 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
919 return wxtree_model
->internal
->row_drop_possible( drag_dest
, dest_path
, selection_data
);
924 wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
925 gint
*sort_column_id
,
928 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) sortable
;
930 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
932 if (!wxtree_model
->internal
->IsSorted())
935 *sort_column_id
= -1;
942 *sort_column_id
= wxtree_model
->internal
->GetSortColumn();
945 *order
= wxtree_model
->internal
->GetSortOrder();
950 wxDataViewColumn
*gs_lastLeftClickHeader
= NULL
;
953 wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
957 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
958 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
960 tree_model
->internal
->SetDataViewSortColumn( gs_lastLeftClickHeader
);
962 if ((sort_column_id
!= (gint
) tree_model
->internal
->GetSortColumn()) ||
963 (order
!= tree_model
->internal
->GetSortOrder()))
965 tree_model
->internal
->SetSortColumn( sort_column_id
);
966 tree_model
->internal
->SetSortOrder( order
);
968 gtk_tree_sortable_sort_column_changed (sortable
);
970 tree_model
->internal
->GetDataViewModel()->Resort();
973 if (gs_lastLeftClickHeader
)
975 wxDataViewCtrl
*dv
= tree_model
->internal
->GetOwner();
976 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, dv
->GetId() );
977 event
.SetDataViewColumn( gs_lastLeftClickHeader
);
978 event
.SetModel( dv
->GetModel() );
979 dv
->HandleWindowEvent( event
);
982 gs_lastLeftClickHeader
= NULL
;
986 wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
987 gint
WXUNUSED(sort_column_id
),
988 GtkTreeIterCompareFunc func
,
989 gpointer
WXUNUSED(data
),
990 GDestroyNotify
WXUNUSED(destroy
))
992 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
993 g_return_if_fail (func
!= NULL
);
997 wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
998 GtkTreeIterCompareFunc func
,
999 gpointer
WXUNUSED(data
),
1000 GDestroyNotify
WXUNUSED(destroy
))
1002 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
1003 g_return_if_fail (func
!= NULL
);
1005 //wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
1006 // TODO: remove this code
1010 wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
)
1012 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
1017 //-----------------------------------------------------------------------------
1018 // define new GTK+ class GtkWxRendererText
1019 //-----------------------------------------------------------------------------
1023 #define GTK_TYPE_WX_CELL_RENDERER_TEXT (gtk_wx_cell_renderer_text_get_type ())
1024 #define GTK_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererText))
1025 #define GTK_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
1026 #define GTK_IS_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT))
1027 #define GTK_IS_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT))
1028 #define GTK_WX_CELL_RENDERER_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
1030 GType
gtk_wx_cell_renderer_text_get_type (void);
1032 typedef struct _GtkWxCellRendererText GtkWxCellRendererText
;
1033 typedef struct _GtkWxCellRendererTextClass GtkWxCellRendererTextClass
;
1035 struct _GtkWxCellRendererText
1037 GtkCellRendererText parent
;
1039 wxDataViewRenderer
*wx_renderer
;
1042 struct _GtkWxCellRendererTextClass
1044 GtkCellRendererTextClass cell_parent_class
;
1048 static GtkWxCellRendererText
*gtk_wx_cell_renderer_text_new (void);
1049 static void gtk_wx_cell_renderer_text_init (
1050 GtkWxCellRendererText
*cell
);
1051 static void gtk_wx_cell_renderer_text_class_init(
1052 GtkWxCellRendererTextClass
*klass
);
1053 static void gtk_wx_cell_renderer_text_finalize (
1055 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
1056 GtkCellRenderer
*cell
,
1060 GdkRectangle
*background_area
,
1061 GdkRectangle
*cell_area
,
1062 GtkCellRendererState flags
);
1065 static GObjectClass
*text_cell_parent_class
= NULL
;
1070 gtk_wx_cell_renderer_text_get_type (void)
1072 static GType cell_wx_type
= 0;
1076 const GTypeInfo cell_wx_info
=
1078 sizeof (GtkWxCellRendererTextClass
),
1079 NULL
, /* base_init */
1080 NULL
, /* base_finalize */
1081 (GClassInitFunc
) gtk_wx_cell_renderer_text_class_init
,
1082 NULL
, /* class_finalize */
1083 NULL
, /* class_data */
1084 sizeof (GtkWxCellRendererText
),
1085 0, /* n_preallocs */
1086 (GInstanceInitFunc
) gtk_wx_cell_renderer_text_init
,
1089 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER_TEXT
,
1090 "GtkWxCellRendererText", &cell_wx_info
, (GTypeFlags
)0 );
1093 return cell_wx_type
;
1097 gtk_wx_cell_renderer_text_init (GtkWxCellRendererText
*cell
)
1099 cell
->wx_renderer
= NULL
;
1103 gtk_wx_cell_renderer_text_class_init (GtkWxCellRendererTextClass
*klass
)
1105 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1106 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
1108 text_cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
1110 object_class
->finalize
= gtk_wx_cell_renderer_text_finalize
;
1112 cell_class
->start_editing
= gtk_wx_cell_renderer_text_start_editing
;
1116 gtk_wx_cell_renderer_text_finalize (GObject
*object
)
1119 (* G_OBJECT_CLASS (text_cell_parent_class
)->finalize
) (object
);
1122 GtkWxCellRendererText
*
1123 gtk_wx_cell_renderer_text_new (void)
1125 return (GtkWxCellRendererText
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER_TEXT
, NULL
);
1128 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
1129 GtkCellRenderer
*gtk_renderer
,
1130 GdkEvent
*gdk_event
,
1133 GdkRectangle
*background_area
,
1134 GdkRectangle
*cell_area
,
1135 GtkCellRendererState flags
)
1137 GtkWxCellRendererText
*wxgtk_renderer
= (GtkWxCellRendererText
*) gtk_renderer
;
1138 wxDataViewRenderer
*wx_renderer
= wxgtk_renderer
->wx_renderer
;
1139 wxDataViewColumn
*column
= wx_renderer
->GetOwner();
1142 item(column
->GetOwner()->GTKPathToItem(wxGtkTreePath(path
)));
1144 wxDataViewCtrl
*dv
= column
->GetOwner();
1145 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, dv
->GetId() );
1146 event
.SetDataViewColumn( column
);
1147 event
.SetModel( dv
->GetModel() );
1148 event
.SetColumn( column
->GetModelColumn() );
1149 event
.SetItem( item
);
1150 dv
->HandleWindowEvent( event
);
1152 if (event
.IsAllowed())
1153 return GTK_CELL_RENDERER_CLASS(text_cell_parent_class
)->
1154 start_editing( gtk_renderer
, gdk_event
, widget
, path
, background_area
, cell_area
, flags
);
1159 //-----------------------------------------------------------------------------
1160 // define new GTK+ class GtkWxCellRenderer
1161 //-----------------------------------------------------------------------------
1165 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
1166 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
1167 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
1168 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
1169 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
1170 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
1172 GType
gtk_wx_cell_renderer_get_type (void);
1174 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
1175 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
1177 struct _GtkWxCellRenderer
1179 GtkCellRenderer parent
;
1182 wxDataViewCustomRenderer
*cell
;
1186 struct _GtkWxCellRendererClass
1188 GtkCellRendererClass cell_parent_class
;
1192 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
1193 static void gtk_wx_cell_renderer_init (
1194 GtkWxCellRenderer
*cell
);
1195 static void gtk_wx_cell_renderer_class_init(
1196 GtkWxCellRendererClass
*klass
);
1197 static void gtk_wx_cell_renderer_finalize (
1199 static void gtk_wx_cell_renderer_get_size (
1200 GtkCellRenderer
*cell
,
1202 GdkRectangle
*rectangle
,
1207 static void gtk_wx_cell_renderer_render (
1208 GtkCellRenderer
*cell
,
1211 GdkRectangle
*background_area
,
1212 GdkRectangle
*cell_area
,
1213 GdkRectangle
*expose_area
,
1214 GtkCellRendererState flags
);
1215 static gboolean
gtk_wx_cell_renderer_activate(
1216 GtkCellRenderer
*cell
,
1220 GdkRectangle
*background_area
,
1221 GdkRectangle
*cell_area
,
1222 GtkCellRendererState flags
);
1223 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1224 GtkCellRenderer
*cell
,
1228 GdkRectangle
*background_area
,
1229 GdkRectangle
*cell_area
,
1230 GtkCellRendererState flags
);
1233 static GObjectClass
*cell_parent_class
= NULL
;
1238 gtk_wx_cell_renderer_get_type (void)
1240 static GType cell_wx_type
= 0;
1244 const GTypeInfo cell_wx_info
=
1246 sizeof (GtkWxCellRendererClass
),
1247 NULL
, /* base_init */
1248 NULL
, /* base_finalize */
1249 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
1250 NULL
, /* class_finalize */
1251 NULL
, /* class_data */
1252 sizeof (GtkWxCellRenderer
),
1253 0, /* n_preallocs */
1254 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
1257 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
1258 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
1261 return cell_wx_type
;
1265 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
1268 cell
->last_click
= 0;
1272 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
1274 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1275 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
1277 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
1279 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
1281 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
1282 cell_class
->render
= gtk_wx_cell_renderer_render
;
1283 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
1284 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
1288 gtk_wx_cell_renderer_finalize (GObject
*object
)
1291 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
1295 gtk_wx_cell_renderer_new (void)
1297 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
1300 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1301 GtkCellRenderer
*renderer
,
1302 GdkEvent
*WXUNUSED(event
),
1305 GdkRectangle
*WXUNUSED(background_area
),
1306 GdkRectangle
*cell_area
,
1307 GtkCellRendererState
WXUNUSED(flags
) )
1309 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1310 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1312 // Renderer doesn't support in-place editing
1313 if (!cell
->HasEditorCtrl())
1316 // An in-place editing control is still around
1317 if (cell
->GetEditorCtrl())
1321 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1327 rect
.x
+= cell_area
->x
;
1328 rect
.y
+= cell_area
->y
;
1329 // rect.width -= renderer->xpad * 2;
1330 // rect.height -= renderer->ypad * 2;
1332 // wxRect renderrect(wxRectFromGDKRect(&rect));
1333 wxRect
renderrect(wxRectFromGDKRect(cell_area
));
1336 item(cell
->GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(path
)));
1338 cell
->StartEditing( item
, renderrect
);
1344 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
1345 GtkWidget
*WXUNUSED(widget
),
1346 GdkRectangle
*cell_area
,
1352 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1353 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1355 wxSize size
= cell
->GetSize();
1357 wxDataViewCtrl
* const ctrl
= cell
->GetOwner()->GetOwner();
1359 // Uniform row height, if specified, overrides the value returned by the
1361 if ( !ctrl
->HasFlag(wxDV_VARIABLE_LINE_HEIGHT
) )
1363 const int uniformHeight
= ctrl
->GTKGetUniformRowHeight();
1364 if ( uniformHeight
> 0 )
1365 size
.y
= uniformHeight
;
1369 gtk_cell_renderer_get_padding(renderer
, &xpad
, &ypad
);
1370 int calc_width
= xpad
* 2 + size
.x
;
1371 int calc_height
= ypad
* 2 + size
.y
;
1378 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
1380 float xalign
, yalign
;
1381 gtk_cell_renderer_get_alignment(renderer
, &xalign
, &yalign
);
1384 *x_offset
= int(xalign
* (cell_area
->width
- calc_width
- 2 * xpad
));
1385 *x_offset
= MAX(*x_offset
, 0) + xpad
;
1389 *y_offset
= int(yalign
* (cell_area
->height
- calc_height
- 2 * ypad
));
1390 *y_offset
= MAX(*y_offset
, 0) + ypad
;
1395 *width
= calc_width
;
1398 *height
= calc_height
;
1402 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
1405 GdkRectangle
*background_area
,
1406 GdkRectangle
*cell_area
,
1407 GdkRectangle
*expose_area
,
1408 GtkCellRendererState flags
)
1411 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1412 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1414 cell
->GTKStashRenderParams(window
, widget
,
1415 background_area
, expose_area
, flags
);
1417 wxRect
rect(wxRectFromGDKRect(cell_area
));
1419 gtk_cell_renderer_get_padding(renderer
, &xpad
, &ypad
);
1420 rect
= rect
.Deflate(xpad
, ypad
);
1422 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
1423 wxWindowDCImpl
*impl
= (wxWindowDCImpl
*) dc
->GetImpl();
1425 // Reinitialize wxWindowDC's GDK window if drawing occurs into a different
1426 // window such as a DnD drop window.
1427 if (window
!= impl
->m_gdkwindow
)
1430 impl
->m_gdkwindow
= window
;
1435 if (flags
& GTK_CELL_RENDERER_SELECTED
)
1436 state
|= wxDATAVIEW_CELL_SELECTED
;
1437 if (flags
& GTK_CELL_RENDERER_PRELIT
)
1438 state
|= wxDATAVIEW_CELL_PRELIT
;
1439 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1440 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1441 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1442 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1443 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
1444 state
|= wxDATAVIEW_CELL_FOCUSED
;
1445 cell
->WXCallRender( rect
, dc
, state
);
1449 gtk_wx_cell_renderer_activate(
1450 GtkCellRenderer
*renderer
,
1454 GdkRectangle
*WXUNUSED(background_area
),
1455 GdkRectangle
*cell_area
,
1456 GtkCellRendererState
WXUNUSED(flags
) )
1458 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1459 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1462 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1468 rect
.x
+= cell_area
->x
;
1469 rect
.y
+= cell_area
->y
;
1471 gtk_cell_renderer_get_padding(renderer
, &xpad
, &ypad
);
1472 rect
.width
-= xpad
* 2;
1473 rect
.height
-= ypad
* 2;
1475 wxRect
renderrect(wxRectFromGDKRect(&rect
));
1477 wxDataViewCtrl
* const ctrl
= cell
->GetOwner()->GetOwner();
1478 wxDataViewModel
*model
= ctrl
->GetModel();
1480 wxDataViewItem
item(ctrl
->GTKPathToItem(wxGtkTreePath(path
)));
1482 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1488 // activated by <ENTER>
1489 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1494 else if (event
->type
== GDK_BUTTON_PRESS
)
1496 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
1497 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
1498 ((int) button_event
->y
) - renderrect
.y
);
1501 if (button_event
->button
== 1)
1503 if (cell
->LeftClick( pt
, renderrect
, model
, item
, model_col
))
1505 // TODO: query system double-click time
1506 if (button_event
->time
- wxrenderer
->last_click
< 400)
1507 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1510 wxrenderer
->last_click
= button_event
->time
;
1518 // ---------------------------------------------------------
1519 // wxGtkDataViewModelNotifier
1520 // ---------------------------------------------------------
1522 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1525 wxGtkDataViewModelNotifier( wxDataViewModel
*wx_model
, wxDataViewCtrlInternal
*internal
);
1526 ~wxGtkDataViewModelNotifier();
1528 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1529 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1530 virtual bool ItemChanged( const wxDataViewItem
&item
);
1531 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int model_column
);
1532 virtual bool Cleared();
1533 virtual void Resort();
1534 virtual bool BeforeReset();
1535 virtual bool AfterReset();
1537 void UpdateLastCount();
1540 wxDataViewModel
*m_wx_model
;
1541 wxDataViewCtrlInternal
*m_internal
;
1544 // ---------------------------------------------------------
1545 // wxGtkDataViewListModelNotifier
1546 // ---------------------------------------------------------
1548 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1549 wxDataViewModel
*wx_model
, wxDataViewCtrlInternal
*internal
)
1551 m_wx_model
= wx_model
;
1552 m_internal
= internal
;
1555 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1561 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1563 m_internal
->ItemAdded( parent
, item
);
1564 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1567 iter
.stamp
= wxgtk_model
->stamp
;
1568 iter
.user_data
= item
.GetID();
1570 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1571 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1572 gtk_tree_model_row_inserted(
1573 GTK_TREE_MODEL(wxgtk_model
), path
, &iter
);
1578 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1580 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1582 // using _get_path for a deleted item cannot be
1585 iter
.stamp
= wxgtk_model
->stamp
;
1586 iter
.user_data
= (gpointer
) item
.GetID();
1587 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1588 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1590 // so get the path from the parent
1592 iter
.stamp
= wxgtk_model
->stamp
;
1593 iter
.user_data
= (gpointer
) parent
.GetID();
1594 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1595 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1596 // and add the final index ourselves
1597 int index
= m_internal
->GetIndexOf( parent
, item
);
1598 gtk_tree_path_append_index( path
, index
);
1601 gtk_tree_model_row_deleted(
1602 GTK_TREE_MODEL(wxgtk_model
), path
);
1604 m_internal
->ItemDeleted( parent
, item
);
1609 void wxGtkDataViewModelNotifier::Resort()
1611 m_internal
->Resort();
1614 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1616 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1619 iter
.stamp
= wxgtk_model
->stamp
;
1620 iter
.user_data
= (gpointer
) item
.GetID();
1622 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1623 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1624 gtk_tree_model_row_changed(
1625 GTK_TREE_MODEL(wxgtk_model
), path
, &iter
);
1627 m_internal
->ItemChanged( item
);
1632 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_column
)
1634 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1635 wxDataViewCtrl
*ctrl
= m_internal
->GetOwner();
1637 // This adds GTK+'s missing MVC logic for ValueChanged
1639 for (index
= 0; index
< ctrl
->GetColumnCount(); index
++)
1641 wxDataViewColumn
*column
= ctrl
->GetColumn( index
);
1642 if (column
->GetModelColumn() == model_column
)
1644 GtkTreeView
*widget
= GTK_TREE_VIEW(ctrl
->GtkGetTreeView());
1645 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1649 iter
.stamp
= wxgtk_model
->stamp
;
1650 iter
.user_data
= (gpointer
) item
.GetID();
1651 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1652 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1653 GdkRectangle cell_area
;
1654 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1656 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1657 double d
= gtk_adjustment_get_value( hadjust
);
1658 int xdiff
= (int) d
;
1660 int ydiff
= gcolumn
->button
->allocation
.height
;
1662 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1663 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1665 m_internal
->ValueChanged( item
, model_column
);
1674 bool wxGtkDataViewModelNotifier::BeforeReset()
1676 GtkWidget
*treeview
= m_internal
->GetOwner()->GtkGetTreeView();
1677 gtk_tree_view_set_model( GTK_TREE_VIEW(treeview
), NULL
);
1682 bool wxGtkDataViewModelNotifier::AfterReset()
1684 GtkWidget
*treeview
= m_internal
->GetOwner()->GtkGetTreeView();
1685 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1687 m_internal
->Cleared();
1689 gtk_tree_view_set_model( GTK_TREE_VIEW(treeview
), GTK_TREE_MODEL(wxgtk_model
) );
1694 bool wxGtkDataViewModelNotifier::Cleared()
1696 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1698 // There is no call to tell the model that everything
1699 // has been deleted so call row_deleted() for every
1702 int count
= m_internal
->iter_n_children( NULL
); // number of children of root
1704 GtkTreePath
*path
= gtk_tree_path_new_first(); // points to root
1707 for (i
= 0; i
< count
; i
++)
1708 gtk_tree_model_row_deleted( GTK_TREE_MODEL(wxgtk_model
), path
);
1710 gtk_tree_path_free( path
);
1712 m_internal
->Cleared();
1717 // ---------------------------------------------------------
1718 // wxDataViewRenderer
1719 // ---------------------------------------------------------
1721 static gpointer s_user_data
= NULL
;
1724 wxgtk_cell_editable_editing_done( GtkCellEditable
*WXUNUSED(editable
),
1725 wxDataViewRenderer
*wxrenderer
)
1727 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1728 wxDataViewCtrl
*dv
= column
->GetOwner();
1729 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1730 event
.SetDataViewColumn( column
);
1731 event
.SetModel( dv
->GetModel() );
1732 wxDataViewItem
item( s_user_data
);
1733 event
.SetItem( item
);
1734 dv
->HandleWindowEvent( event
);
1738 wxgtk_renderer_editing_started( GtkCellRenderer
*WXUNUSED(cell
), GtkCellEditable
*editable
,
1739 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1744 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1745 wxDataViewCtrl
*dv
= column
->GetOwner();
1746 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1747 event
.SetDataViewColumn( column
);
1748 event
.SetModel( dv
->GetModel() );
1749 wxDataViewItem
item(dv
->GTKPathToItem(wxGtkTreePath(path
)));
1750 event
.SetItem( item
);
1751 dv
->HandleWindowEvent( event
);
1753 if (GTK_IS_CELL_EDITABLE(editable
))
1755 s_user_data
= item
.GetID();
1757 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1758 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1759 (gpointer
) wxrenderer
);
1765 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1767 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1769 wxDataViewRendererBase( varianttype
, mode
, align
)
1774 // we haven't changed them yet
1775 m_usingDefaultAttrs
= true;
1777 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1778 // after the m_renderer pointer has been initialized
1781 void wxDataViewRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
1783 gtk_tree_view_column_pack_end( column
, m_renderer
, TRUE
/* expand */);
1786 void wxDataViewRenderer::GtkInitHandlers()
1788 if (!gtk_check_version(2,6,0))
1790 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1791 G_CALLBACK (wxgtk_renderer_editing_started
),
1796 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1798 GtkCellRendererMode gtkMode
;
1801 case wxDATAVIEW_CELL_INERT
:
1802 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1805 case wxDATAVIEW_CELL_ACTIVATABLE
:
1806 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1809 case wxDATAVIEW_CELL_EDITABLE
:
1810 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1814 wxFAIL_MSG( "unknown wxDataViewCellMode value" );
1820 // This value is most often ignored in GtkTreeView
1821 GValue gvalue
= { 0, };
1822 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1823 g_value_set_enum( &gvalue
, gtkMode
);
1824 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1825 g_value_unset( &gvalue
);
1828 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1830 wxDataViewCellMode ret
;
1833 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1835 switch (g_value_get_enum(&gvalue
))
1838 wxFAIL_MSG( "unknown GtkCellRendererMode value" );
1839 // fall through (we have to return something)
1841 case GTK_CELL_RENDERER_MODE_INERT
:
1842 ret
= wxDATAVIEW_CELL_INERT
;
1845 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1846 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1849 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1850 ret
= wxDATAVIEW_CELL_EDITABLE
;
1854 g_value_unset( &gvalue
);
1859 void wxDataViewRenderer::GtkApplyAlignment(GtkCellRenderer
*renderer
)
1861 int align
= m_alignment
;
1863 // query alignment from column ?
1867 if (GetOwner() == NULL
)
1870 align
= GetOwner()->GetAlignment();
1871 align
|= wxALIGN_CENTRE_VERTICAL
;
1874 // horizontal alignment:
1876 gfloat xalign
= 0.0;
1877 if (align
& wxALIGN_RIGHT
)
1879 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1882 GValue gvalue
= { 0, };
1883 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1884 g_value_set_float( &gvalue
, xalign
);
1885 g_object_set_property( G_OBJECT(renderer
), "xalign", &gvalue
);
1886 g_value_unset( &gvalue
);
1888 // vertical alignment:
1890 gfloat yalign
= 0.0;
1891 if (align
& wxALIGN_BOTTOM
)
1893 else if (align
& wxALIGN_CENTER_VERTICAL
)
1896 GValue gvalue2
= { 0, };
1897 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1898 g_value_set_float( &gvalue2
, yalign
);
1899 g_object_set_property( G_OBJECT(renderer
), "yalign", &gvalue2
);
1900 g_value_unset( &gvalue2
);
1903 void wxDataViewRenderer::SetAlignment( int align
)
1905 m_alignment
= align
;
1906 GtkUpdateAlignment();
1909 int wxDataViewRenderer::GetAlignment() const
1914 void wxDataViewRenderer::EnableEllipsize(wxEllipsizeMode mode
)
1917 if ( gtk_check_version(2, 6, 0) != NULL
)
1920 GtkCellRendererText
* const rend
= GtkGetTextRenderer();
1924 // we use the same values in wxEllipsizeMode as PangoEllipsizeMode so we
1925 // can just cast between them
1926 GValue gvalue
= { 0, };
1927 g_value_init( &gvalue
, PANGO_TYPE_ELLIPSIZE_MODE
);
1928 g_value_set_enum( &gvalue
, static_cast<PangoEllipsizeMode
>(mode
) );
1929 g_object_set_property( G_OBJECT(rend
), "ellipsize", &gvalue
);
1930 g_value_unset( &gvalue
);
1933 #endif // GTK 2.6/before
1936 wxEllipsizeMode
wxDataViewRenderer::GetEllipsizeMode() const
1939 if ( gtk_check_version(2, 6, 0) != NULL
)
1940 return wxELLIPSIZE_NONE
;
1942 GtkCellRendererText
* const rend
= GtkGetTextRenderer();
1944 return wxELLIPSIZE_NONE
;
1946 GValue gvalue
= { 0, };
1947 g_value_init( &gvalue
, PANGO_TYPE_ELLIPSIZE_MODE
);
1948 g_object_get_property( G_OBJECT(rend
), "ellipsize", &gvalue
);
1950 mode
= static_cast<wxEllipsizeMode
>(g_value_get_enum( &gvalue
));
1951 g_value_unset( &gvalue
);
1955 return wxELLIPSIZE_NONE
;
1956 #endif // GTK 2.6/before
1960 wxDataViewRenderer::GtkOnTextEdited(const gchar
*itempath
, const wxString
& str
)
1962 wxVariant
value(str
);
1963 if (!Validate( value
))
1967 item(GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(itempath
)));
1969 GtkOnCellChanged(value
, item
, GetOwner()->GetModelColumn());
1973 wxDataViewRenderer::GtkOnCellChanged(const wxVariant
& value
,
1974 const wxDataViewItem
& item
,
1977 wxDataViewModel
*model
= GetOwner()->GetOwner()->GetModel();
1978 model
->ChangeValue( value
, item
, col
);
1981 // ---------------------------------------------------------
1982 // wxDataViewTextRenderer
1983 // ---------------------------------------------------------
1988 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*WXUNUSED(renderer
),
1989 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1991 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) user_data
;
1993 cell
->GtkOnTextEdited(arg1
, wxGTK_CONV_BACK_FONT(
1994 arg2
, cell
->GetOwner()->GetOwner()->GetFont()));
2002 // helper function used by wxDataViewTextRenderer and
2003 // wxDataViewCustomRenderer::RenderText(): it applies the attributes to the
2004 // given text renderer and returns true if anything was done
2005 bool GtkApplyAttr(GtkCellRendererText
*renderer
, const wxDataViewItemAttr
& attr
)
2007 bool usingDefaultAttrs
= true;
2008 if (attr
.HasColour())
2010 const GdkColor
* const gcol
= attr
.GetColour().GetColor();
2012 GValue gvalue
= { 0, };
2013 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2014 g_value_set_boxed( &gvalue
, gcol
);
2015 g_object_set_property( G_OBJECT(renderer
), "foreground_gdk", &gvalue
);
2016 g_value_unset( &gvalue
);
2018 usingDefaultAttrs
= false;
2022 GValue gvalue
= { 0, };
2023 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2024 g_value_set_boolean( &gvalue
, FALSE
);
2025 g_object_set_property( G_OBJECT(renderer
), "foreground-set", &gvalue
);
2026 g_value_unset( &gvalue
);
2029 if (attr
.GetItalic())
2031 GValue gvalue
= { 0, };
2032 g_value_init( &gvalue
, PANGO_TYPE_STYLE
);
2033 g_value_set_enum( &gvalue
, PANGO_STYLE_ITALIC
);
2034 g_object_set_property( G_OBJECT(renderer
), "style", &gvalue
);
2035 g_value_unset( &gvalue
);
2037 usingDefaultAttrs
= false;
2041 GValue gvalue
= { 0, };
2042 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2043 g_value_set_boolean( &gvalue
, FALSE
);
2044 g_object_set_property( G_OBJECT(renderer
), "style-set", &gvalue
);
2045 g_value_unset( &gvalue
);
2051 GValue gvalue
= { 0, };
2052 g_value_init( &gvalue
, PANGO_TYPE_WEIGHT
);
2053 g_value_set_enum( &gvalue
, PANGO_WEIGHT_BOLD
);
2054 g_object_set_property( G_OBJECT(renderer
), "weight", &gvalue
);
2055 g_value_unset( &gvalue
);
2057 usingDefaultAttrs
= false;
2061 GValue gvalue
= { 0, };
2062 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2063 g_value_set_boolean( &gvalue
, FALSE
);
2064 g_object_set_property( G_OBJECT(renderer
), "weight-set", &gvalue
);
2065 g_value_unset( &gvalue
);
2069 if (attr
.HasBackgroundColour())
2071 wxColour colour
= attr
.GetBackgroundColour();
2072 const GdkColor
* const gcol
= colour
.GetColor();
2074 GValue gvalue
= { 0, };
2075 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2076 g_value_set_boxed( &gvalue
, gcol
);
2077 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
2078 g_value_unset( &gvalue
);
2082 GValue gvalue
= { 0, };
2083 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2084 g_value_set_boolean( &gvalue
, FALSE
);
2085 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
2086 g_value_unset( &gvalue
);
2090 return !usingDefaultAttrs
;
2093 } // anonymous namespace
2095 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
2097 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
2099 wxDataViewRenderer( varianttype
, mode
, align
)
2101 GtkWxCellRendererText
*text_renderer
= gtk_wx_cell_renderer_text_new();
2102 text_renderer
->wx_renderer
= this;
2103 m_renderer
= (GtkCellRenderer
*) text_renderer
;
2105 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
2107 GValue gvalue
= { 0, };
2108 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2109 g_value_set_boolean( &gvalue
, true );
2110 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
2111 g_value_unset( &gvalue
);
2113 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2119 SetAlignment(align
);
2122 bool wxDataViewTextRenderer::SetTextValue(const wxString
& str
)
2124 GValue gvalue
= { 0, };
2125 g_value_init( &gvalue
, G_TYPE_STRING
);
2126 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( str
, GetOwner()->GetOwner()->GetFont() ) );
2127 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2128 g_value_unset( &gvalue
);
2133 bool wxDataViewTextRenderer::GetTextValue(wxString
& str
) const
2135 GValue gvalue
= { 0, };
2136 g_value_init( &gvalue
, G_TYPE_STRING
);
2137 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2138 str
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
), const_cast<wxDataViewTextRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
2139 g_value_unset( &gvalue
);
2144 void wxDataViewTextRenderer::SetAlignment( int align
)
2146 wxDataViewRenderer::SetAlignment(align
);
2148 if (gtk_check_version(2,10,0))
2151 // horizontal alignment:
2152 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2153 if (align
& wxALIGN_RIGHT
)
2154 pangoAlign
= PANGO_ALIGN_RIGHT
;
2155 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2156 pangoAlign
= PANGO_ALIGN_CENTER
;
2158 GValue gvalue
= { 0, };
2159 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2160 g_value_set_enum( &gvalue
, pangoAlign
);
2161 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2162 g_value_unset( &gvalue
);
2165 bool wxDataViewTextRenderer::GtkSetAttr(const wxDataViewItemAttr
& attr
)
2167 return GtkApplyAttr(GtkGetTextRenderer(), attr
);
2170 GtkCellRendererText
*wxDataViewTextRenderer::GtkGetTextRenderer() const
2172 return GTK_CELL_RENDERER_TEXT(m_renderer
);
2175 // ---------------------------------------------------------
2176 // wxDataViewBitmapRenderer
2177 // ---------------------------------------------------------
2182 // set "pixbuf" property on the given renderer
2183 void SetPixbufProp(GtkCellRenderer
*renderer
, GdkPixbuf
*pixbuf
)
2185 GValue gvalue
= { 0, };
2186 g_value_init( &gvalue
, G_TYPE_OBJECT
);
2187 g_value_set_object( &gvalue
, pixbuf
);
2188 g_object_set_property( G_OBJECT(renderer
), "pixbuf", &gvalue
);
2189 g_value_unset( &gvalue
);
2192 } // anonymous namespace
2194 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
2196 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
2198 wxDataViewRenderer( varianttype
, mode
, align
)
2200 m_renderer
= gtk_cell_renderer_pixbuf_new();
2203 SetAlignment(align
);
2206 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
2208 if (value
.GetType() == wxT("wxBitmap"))
2213 // GetPixbuf() may create a Pixbuf representation in the wxBitmap
2214 // object (and it will stay there and remain owned by wxBitmap)
2215 SetPixbufProp(m_renderer
, bitmap
.GetPixbuf());
2217 else if (value
.GetType() == wxT("wxIcon"))
2222 SetPixbufProp(m_renderer
, icon
.GetPixbuf());
2232 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2237 // ---------------------------------------------------------
2238 // wxDataViewToggleRenderer
2239 // ---------------------------------------------------------
2242 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
2243 gchar
*path
, gpointer user_data
);
2246 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
2247 gchar
*path
, gpointer user_data
)
2249 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
2252 GValue gvalue
= { 0, };
2253 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2254 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
2255 bool tmp
= g_value_get_boolean( &gvalue
);
2256 g_value_unset( &gvalue
);
2260 wxVariant value
= tmp
;
2261 if (!cell
->Validate( value
))
2264 wxDataViewCtrl
* const ctrl
= cell
->GetOwner()->GetOwner();
2265 wxDataViewModel
*model
= ctrl
->GetModel();
2267 wxDataViewItem
item(ctrl
->GTKPathToItem(wxGtkTreePath(path
)));
2269 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
2271 model
->ChangeValue( value
, item
, model_col
);
2274 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
2276 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
2277 wxDataViewCellMode mode
, int align
) :
2278 wxDataViewRenderer( varianttype
, mode
, align
)
2280 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
2282 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
2284 g_signal_connect_after( m_renderer
, "toggled",
2285 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
2289 GValue gvalue
= { 0, };
2290 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2291 g_value_set_boolean( &gvalue
, false );
2292 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
2293 g_value_unset( &gvalue
);
2297 SetAlignment(align
);
2300 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
2304 GValue gvalue
= { 0, };
2305 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2306 g_value_set_boolean( &gvalue
, tmp
);
2307 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
2308 g_value_unset( &gvalue
);
2313 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
2315 GValue gvalue
= { 0, };
2316 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2317 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
2318 bool tmp
= g_value_get_boolean( &gvalue
);
2319 g_value_unset( &gvalue
);
2326 // ---------------------------------------------------------
2327 // wxDataViewCustomRenderer
2328 // ---------------------------------------------------------
2330 class wxDataViewCtrlDCImpl
: public wxWindowDCImpl
2333 wxDataViewCtrlDCImpl( wxDC
*owner
, wxDataViewCtrl
*window
) :
2334 wxWindowDCImpl( owner
)
2336 GtkWidget
*widget
= window
->m_treeview
;
2342 m_context
= window
->GTKGetPangoDefaultContext();
2343 m_layout
= pango_layout_new( m_context
);
2344 m_fontdesc
= pango_font_description_copy(gtk_widget_get_style(widget
)->font_desc
);
2346 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
2348 // Set m_gdkwindow later
2353 class wxDataViewCtrlDC
: public wxWindowDC
2356 wxDataViewCtrlDC( wxDataViewCtrl
*window
) :
2357 wxWindowDC( new wxDataViewCtrlDCImpl( this, window
) )
2362 // ---------------------------------------------------------
2363 // wxDataViewCustomRenderer
2364 // ---------------------------------------------------------
2366 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
2368 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
2369 wxDataViewCellMode mode
,
2372 : wxDataViewCustomRendererBase( varianttype
, mode
, align
)
2375 m_text_renderer
= NULL
;
2383 void wxDataViewCustomRenderer::GtkInitTextRenderer()
2385 m_text_renderer
= GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new());
2386 g_object_ref_sink(m_text_renderer
);
2388 GtkApplyAlignment(GTK_CELL_RENDERER(m_text_renderer
));
2391 GtkCellRendererText
*wxDataViewCustomRenderer::GtkGetTextRenderer() const
2393 if ( !m_text_renderer
)
2395 // we create it on demand so need to do it even from a const function
2396 const_cast<wxDataViewCustomRenderer
*>(this)->GtkInitTextRenderer();
2399 return m_text_renderer
;
2402 void wxDataViewCustomRenderer::RenderText( const wxString
&text
,
2406 int WXUNUSED(state
) )
2409 GtkCellRendererText
* const textRenderer
= GtkGetTextRenderer();
2411 GValue gvalue
= { 0, };
2412 g_value_init( &gvalue
, G_TYPE_STRING
);
2413 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( text
, GetOwner()->GetOwner()->GetFont() ) );
2414 g_object_set_property( G_OBJECT(textRenderer
), "text", &gvalue
);
2415 g_value_unset( &gvalue
);
2417 GtkApplyAttr(textRenderer
, GetAttr());
2419 GdkRectangle cell_area
;
2420 wxRectToGDKRect(cell
, cell_area
);
2421 cell_area
.x
+= xoffset
;
2422 cell_area
.width
-= xoffset
;
2424 gtk_cell_renderer_render( GTK_CELL_RENDERER(textRenderer
),
2425 m_renderParams
.window
,
2426 m_renderParams
.widget
,
2427 m_renderParams
.background_area
,
2429 m_renderParams
.expose_area
,
2430 (GtkCellRendererState
) m_renderParams
.flags
);
2433 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
2435 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
2436 renderer
->cell
= this;
2438 m_renderer
= (GtkCellRenderer
*) renderer
;
2441 SetAlignment(align
);
2448 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
2453 if (m_text_renderer
)
2454 g_object_unref(m_text_renderer
);
2457 wxDC
*wxDataViewCustomRenderer::GetDC()
2461 if (GetOwner() == NULL
)
2463 if (GetOwner()->GetOwner() == NULL
)
2465 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
2471 // ---------------------------------------------------------
2472 // wxDataViewProgressRenderer
2473 // ---------------------------------------------------------
2475 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
2477 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
2478 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
2479 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
2485 if (!gtk_check_version(2,6,0))
2487 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
2490 SetAlignment(align
);
2493 // We can't initialize the renderer just yet because we don't have the
2494 // pointer to the column that uses this renderer yet and so attempt to
2495 // dereference GetOwner() to get the font that is used as a source of
2496 // encoding in multibyte-to-Unicode conversion in GTKSetLabel() in
2497 // non-Unicode builds would crash. So simply remember to do it later.
2498 if ( !m_label
.empty() )
2499 m_needsToSetLabel
= true;
2501 #endif // !wxUSE_UNICODE
2507 // Use custom cell code
2508 wxDataViewCustomRenderer::Init(mode
, align
);
2512 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
2516 void wxDataViewProgressRenderer::GTKSetLabel()
2518 GValue gvalue
= { 0, };
2519 g_value_init( &gvalue
, G_TYPE_STRING
);
2521 // Take care to not use GetOwner() here if the label is empty, we can be
2522 // called from ctor when GetOwner() is still NULL in this case.
2523 g_value_set_string( &gvalue
,
2524 m_label
.empty() ? ""
2525 : wxGTK_CONV_FONT(m_label
,
2526 GetOwner()->GetOwner()->GetFont())
2528 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2529 g_value_unset( &gvalue
);
2532 m_needsToSetLabel
= false;
2533 #endif // !wxUSE_UNICODE
2536 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
2539 if (!gtk_check_version(2,6,0))
2542 if ( m_needsToSetLabel
)
2544 #endif // !wxUSE_UNICODE
2546 gint tmp
= (long) value
;
2547 GValue gvalue
= { 0, };
2548 g_value_init( &gvalue
, G_TYPE_INT
);
2549 g_value_set_int( &gvalue
, tmp
);
2550 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
2551 g_value_unset( &gvalue
);
2556 m_value
= (long) value
;
2558 if (m_value
< 0) m_value
= 0;
2559 if (m_value
> 100) m_value
= 100;
2565 bool wxDataViewProgressRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2570 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
2572 double pct
= (double)m_value
/ 100.0;
2574 bar
.width
= (int)(cell
.width
* pct
);
2575 dc
->SetPen( *wxTRANSPARENT_PEN
);
2576 dc
->SetBrush( *wxBLUE_BRUSH
);
2577 dc
->DrawRectangle( bar
);
2579 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
2580 dc
->SetPen( *wxBLACK_PEN
);
2581 dc
->DrawRectangle( cell
);
2586 wxSize
wxDataViewProgressRenderer::GetSize() const
2588 return wxSize(40,12);
2591 // -------------------------------------
2592 // wxDataViewChoiceRenderer
2593 // -------------------------------------
2595 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
&choices
,
2596 wxDataViewCellMode mode
, int alignment
) :
2597 wxDataViewCustomRenderer( "string", mode
, alignment
, true )
2599 m_choices
= choices
;
2602 if (!gtk_check_version(2,6,0))
2604 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_combo_new();
2606 GtkListStore
*store
= gtk_list_store_new( 1, G_TYPE_STRING
);
2607 for (size_t n
= 0; n
< m_choices
.GetCount(); n
++)
2609 gtk_list_store_insert_with_values(
2611 static_cast<const char *>(m_choices
[n
].utf8_str()), -1 );
2614 g_object_set (m_renderer
,
2620 bool editable
= (mode
& wxDATAVIEW_CELL_EDITABLE
);
2621 g_object_set (m_renderer
, "editable", editable
, NULL
);
2623 SetAlignment(alignment
);
2625 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2632 // Use custom cell code
2633 wxDataViewCustomRenderer::Init(mode
, alignment
);
2637 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
2639 RenderText( m_data
, 0, rect
, dc
, state
);
2643 wxSize
wxDataViewChoiceRenderer::GetSize() const
2645 return wxSize(70,20);
2648 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
2652 if (!gtk_check_version(2,6,0))
2654 GValue gvalue
= { 0, };
2655 g_value_init( &gvalue
, G_TYPE_STRING
);
2656 g_value_set_string(&gvalue
,
2657 wxGTK_CONV_FONT(value
.GetString(),
2658 GetOwner()->GetOwner()->GetFont()));
2659 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2660 g_value_unset( &gvalue
);
2664 m_data
= value
.GetString();
2669 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
2672 if (!gtk_check_version(2,6,0))
2674 GValue gvalue
= { 0, };
2675 g_value_init( &gvalue
, G_TYPE_STRING
);
2676 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2677 wxString temp
= wxGTK_CONV_BACK_FONT(g_value_get_string(&gvalue
),
2678 GetOwner()->GetOwner()->GetFont());
2679 g_value_unset( &gvalue
);
2682 //wxPrintf( "temp %s\n", temp );
2683 // TODO: remove this code
2692 void wxDataViewChoiceRenderer::SetAlignment( int align
)
2694 wxDataViewCustomRenderer::SetAlignment(align
);
2696 if (gtk_check_version(2,10,0))
2699 // horizontal alignment:
2700 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2701 if (align
& wxALIGN_RIGHT
)
2702 pangoAlign
= PANGO_ALIGN_RIGHT
;
2703 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2704 pangoAlign
= PANGO_ALIGN_CENTER
;
2706 GValue gvalue
= { 0, };
2707 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2708 g_value_set_enum( &gvalue
, pangoAlign
);
2709 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2710 g_value_unset( &gvalue
);
2713 // ----------------------------------------------------------------------------
2714 // wxDataViewChoiceByIndexRenderer
2715 // ----------------------------------------------------------------------------
2717 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
2718 wxDataViewCellMode mode
, int alignment
) :
2719 wxDataViewChoiceRenderer( choices
, mode
, alignment
)
2723 void wxDataViewChoiceByIndexRenderer::GtkOnTextEdited(const gchar
*itempath
, const wxString
& str
)
2725 wxVariant
value( (long) GetChoices().Index( str
) );
2727 if (!Validate( value
))
2731 item(GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(itempath
)));
2733 GtkOnCellChanged(value
, item
, GetOwner()->GetModelColumn());
2736 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant
&value
)
2738 wxVariant string_value
= GetChoice( value
.GetLong() );
2739 return wxDataViewChoiceRenderer::SetValue( string_value
);
2742 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant
&value
) const
2744 wxVariant string_value
;
2745 if (!wxDataViewChoiceRenderer::GetValue( string_value
))
2748 value
= (long) GetChoices().Index( string_value
.GetString() );
2752 // ---------------------------------------------------------
2753 // wxDataViewDateRenderer
2754 // ---------------------------------------------------------
2756 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
2759 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
2760 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
2761 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
2766 m_cal
= new wxCalendarCtrl( this, -1, *value
);
2767 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
2768 sizer
->Add( m_cal
, 1, wxGROW
);
2773 virtual void OnDismiss()
2777 void OnCalendar( wxCalendarEvent
&event
);
2779 wxCalendarCtrl
*m_cal
;
2780 wxDataViewModel
*m_model
;
2781 wxDataViewItem m_item
;
2785 DECLARE_EVENT_TABLE()
2788 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
2789 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
2792 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
2794 m_model
->ChangeValue( event
.GetDate(), m_item
, m_col
);
2798 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
2800 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
2801 wxDataViewCellMode mode
, int align
) :
2802 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2805 SetAlignment(align
);
2808 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
2810 m_date
= value
.GetDateTime();
2815 bool wxDataViewDateRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2820 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2822 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
2823 wxString tmp
= m_date
.FormatDate();
2824 RenderText( tmp
, 0, cell
, dc
, state
);
2828 wxSize
wxDataViewDateRenderer::GetSize() const
2830 wxString tmp
= m_date
.FormatDate();
2832 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
2833 return wxSize(x
,y
+d
);
2836 bool wxDataViewDateRenderer::Activate( const wxRect
& WXUNUSED(cell
), wxDataViewModel
*model
,
2837 const wxDataViewItem
&item
, unsigned int col
)
2840 model
->GetValue( variant
, item
, col
);
2841 wxDateTime value
= variant
.GetDateTime();
2843 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
2844 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
2845 wxPoint pos
= wxGetMousePosition();
2848 popup
->Popup( popup
->m_cal
);
2854 // ---------------------------------------------------------
2855 // wxDataViewIconTextRenderer
2856 // ---------------------------------------------------------
2858 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
2860 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer
2862 const wxString
&varianttype
,
2863 wxDataViewCellMode mode
,
2866 : wxDataViewTextRenderer(varianttype
, mode
, align
)
2868 m_rendererIcon
= gtk_cell_renderer_pixbuf_new();
2871 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2875 void wxDataViewIconTextRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
2877 // add the icon renderer first
2878 gtk_tree_view_column_pack_start(column
, m_rendererIcon
, FALSE
/* !expand */);
2880 // add the text renderer too
2881 wxDataViewRenderer::GtkPackIntoColumn(column
);
2884 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
2888 SetTextValue(m_value
.GetText());
2889 SetPixbufProp(m_rendererIcon
, m_value
.GetIcon().GetPixbuf());
2894 bool wxDataViewIconTextRenderer::GetValue(wxVariant
& value
) const
2897 if ( !GetTextValue(str
) )
2900 // user doesn't have any way to edit the icon so leave it unchanged
2901 value
<< wxDataViewIconText(str
, m_value
.GetIcon());
2907 wxDataViewIconTextRenderer::GtkOnCellChanged(const wxVariant
& value
,
2908 const wxDataViewItem
& item
,
2911 // we receive just the text part of our value as it's the only one which
2912 // can be edited, but we need the full wxDataViewIconText value for the
2914 wxVariant valueIconText
;
2915 valueIconText
<< wxDataViewIconText(value
.GetString(), m_value
.GetIcon());
2916 wxDataViewTextRenderer::GtkOnCellChanged(valueIconText
, item
, col
);
2919 // ---------------------------------------------------------
2921 // ---------------------------------------------------------
2925 gtk_dataview_header_button_press_callback( GtkWidget
*WXUNUSED(widget
),
2926 GdkEventButton
*gdk_event
,
2927 wxDataViewColumn
*column
)
2929 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
2932 if (gdk_event
->button
== 1)
2934 gs_lastLeftClickHeader
= column
;
2936 wxDataViewCtrl
*dv
= column
->GetOwner();
2937 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
2938 event
.SetDataViewColumn( column
);
2939 event
.SetModel( dv
->GetModel() );
2940 if (dv
->HandleWindowEvent( event
))
2944 if (gdk_event
->button
== 3)
2946 wxDataViewCtrl
*dv
= column
->GetOwner();
2947 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
2948 event
.SetDataViewColumn( column
);
2949 event
.SetModel( dv
->GetModel() );
2950 if (dv
->HandleWindowEvent( event
))
2960 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*WXUNUSED(column
),
2961 GtkCellRenderer
*renderer
,
2962 GtkTreeModel
*model
,
2966 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2967 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2969 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2971 wxDataViewItem
item( (void*) iter
->user_data
);
2973 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
2975 if (!wx_model
->IsVirtualListModel())
2978 if (wx_model
->IsContainer( item
))
2980 visible
= wx_model
->HasContainerColumns( item
) ||
2981 (cell
->GetOwner()->GetModelColumn() == 0);
2988 GValue gvalue
= { 0, };
2989 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2990 g_value_set_boolean( &gvalue
, visible
);
2991 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2992 g_value_unset( &gvalue
);
2999 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
3001 if (value
.GetType() != cell
->GetVariantType())
3003 wxLogError( wxT("Wrong type, required: %s but: %s"),
3004 value
.GetType().c_str(),
3005 cell
->GetVariantType().c_str() );
3008 cell
->SetValue( value
);
3010 // deal with disabled items
3011 bool enabled
= wx_model
->IsEnabled( item
, cell
->GetOwner()->GetModelColumn() );
3013 // a) this sets the appearance to disabled grey
3014 GValue gvalue
= { 0, };
3015 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
3016 g_value_set_boolean( &gvalue
, enabled
);
3017 g_object_set_property( G_OBJECT(renderer
), "sensitive", &gvalue
);
3018 g_value_unset( &gvalue
);
3020 // b) this actually disables the control/renderer
3022 cell
->SetMode( cell
->GtkGetMode() );
3024 cell
->SetMode( wxDATAVIEW_CELL_INERT
);
3027 // deal with attributes: if the renderer doesn't support them at all, we
3028 // don't even need to query the model for them
3029 if ( !cell
->GtkSupportsAttrs() )
3032 // it can support attributes so check if this item has any
3033 wxDataViewItemAttr attr
;
3034 if ( wx_model
->GetAttr( item
, cell
->GetOwner()->GetModelColumn(), attr
)
3035 || !cell
->GtkIsUsingDefaultAttrs() )
3037 bool usingDefaultAttrs
= !cell
->GtkSetAttr(attr
);
3038 cell
->GtkSetUsingDefaultAttrs(usingDefaultAttrs
);
3040 // else: no custom attributes specified and we're already using the default
3041 // ones -- nothing to do
3047 #include <wx/listimpl.cpp>
3048 WX_DEFINE_LIST(wxDataViewColumnList
)
3050 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
3051 unsigned int model_column
, int width
,
3052 wxAlignment align
, int flags
)
3053 : wxDataViewColumnBase( cell
, model_column
)
3055 Init( align
, flags
, width
);
3060 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
3061 unsigned int model_column
, int width
,
3062 wxAlignment align
, int flags
)
3063 : wxDataViewColumnBase( bitmap
, cell
, model_column
)
3065 Init( align
, flags
, width
);
3067 SetBitmap( bitmap
);
3070 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
3072 m_isConnected
= false;
3074 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
3075 m_column
= (GtkWidget
*) column
;
3078 SetAlignment( align
);
3082 // Create container for icon and label
3083 GtkWidget
*box
= gtk_hbox_new( FALSE
, 1 );
3084 gtk_widget_show( box
);
3085 // gtk_container_set_border_width((GtkContainer*)box, 2);
3086 m_image
= gtk_image_new();
3087 gtk_box_pack_start(GTK_BOX(box
), m_image
, FALSE
, FALSE
, 1);
3088 m_label
= gtk_label_new("");
3089 gtk_box_pack_end( GTK_BOX(box
), GTK_WIDGET(m_label
), FALSE
, FALSE
, 1 );
3090 gtk_tree_view_column_set_widget( column
, box
);
3092 wxDataViewRenderer
* const colRenderer
= GetRenderer();
3093 GtkCellRenderer
* const cellRenderer
= colRenderer
->GetGtkHandle();
3095 colRenderer
->GtkPackIntoColumn(column
);
3097 gtk_tree_view_column_set_cell_data_func( column
, cellRenderer
,
3098 wxGtkTreeCellDataFunc
, (gpointer
) colRenderer
, NULL
);
3101 void wxDataViewColumn::OnInternalIdle()
3106 if (gtk_widget_get_realized(GetOwner()->m_treeview
))
3108 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3111 g_signal_connect(column
->button
, "button_press_event",
3112 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
3114 // otherwise the event will be blocked by GTK+
3115 gtk_tree_view_column_set_clickable( column
, TRUE
);
3117 m_isConnected
= true;
3122 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
3124 wxDataViewColumnBase::SetOwner( owner
);
3126 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3128 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
3131 void wxDataViewColumn::SetTitle( const wxString
&title
)
3133 wxDataViewCtrl
*ctrl
= GetOwner();
3134 gtk_label_set_text( GTK_LABEL(m_label
), ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
3135 : wxGTK_CONV_SYS(title
) );
3137 gtk_widget_hide( m_label
);
3139 gtk_widget_show( m_label
);
3142 wxString
wxDataViewColumn::GetTitle() const
3144 return wxGTK_CONV_BACK_FONT(
3145 gtk_label_get_text( GTK_LABEL(m_label
) ),
3146 GetOwner()->GetFont()
3150 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
3152 wxDataViewColumnBase::SetBitmap( bitmap
);
3156 GtkImage
*gtk_image
= GTK_IMAGE(m_image
);
3158 GdkBitmap
*mask
= NULL
;
3159 if (bitmap
.GetMask())
3160 mask
= bitmap
.GetMask()->GetBitmap();
3162 if (bitmap
.HasPixbuf())
3164 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
3165 bitmap
.GetPixbuf());
3169 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
3170 bitmap
.GetPixmap(), mask
);
3172 gtk_widget_show( m_image
);
3176 gtk_widget_hide( m_image
);
3180 void wxDataViewColumn::SetHidden( bool hidden
)
3182 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
3185 void wxDataViewColumn::SetResizeable( bool resizable
)
3187 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizable
);
3190 void wxDataViewColumn::SetAlignment( wxAlignment align
)
3192 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3194 gfloat xalign
= 0.0;
3195 if (align
== wxALIGN_RIGHT
)
3197 if (align
== wxALIGN_CENTER_HORIZONTAL
||
3198 align
== wxALIGN_CENTER
)
3201 gtk_tree_view_column_set_alignment( column
, xalign
);
3203 if (m_renderer
&& m_renderer
->GetAlignment() == -1)
3204 m_renderer
->GtkUpdateAlignment();
3207 wxAlignment
wxDataViewColumn::GetAlignment() const
3209 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
3212 return wxALIGN_RIGHT
;
3214 return wxALIGN_CENTER_HORIZONTAL
;
3216 return wxALIGN_LEFT
;
3219 void wxDataViewColumn::SetSortable( bool sortable
)
3221 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3225 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
3229 gtk_tree_view_column_set_sort_column_id( column
, -1 );
3230 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
3231 gtk_tree_view_column_set_clickable( column
, FALSE
);
3235 bool wxDataViewColumn::IsSortable() const
3237 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3238 return gtk_tree_view_column_get_clickable( column
);
3241 void wxDataViewColumn::SetAsSortKey( bool WXUNUSED(sort
) )
3243 // it might not make sense to have this function in wxHeaderColumn at
3244 // all in fact, changing of the sort order should only be done using the
3245 // associated control API
3246 wxFAIL_MSG( "not implemented" );
3249 bool wxDataViewColumn::IsSortKey() const
3251 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3252 return gtk_tree_view_column_get_sort_indicator( column
);
3255 bool wxDataViewColumn::IsResizeable() const
3257 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3258 return gtk_tree_view_column_get_resizable( column
);
3261 bool wxDataViewColumn::IsHidden() const
3263 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3264 return !gtk_tree_view_column_get_visible( column
);
3267 void wxDataViewColumn::SetSortOrder( bool ascending
)
3269 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3272 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
3274 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
3276 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
3279 bool wxDataViewColumn::IsSortOrderAscending() const
3281 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3283 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
3286 void wxDataViewColumn::SetMinWidth( int width
)
3288 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
3291 int wxDataViewColumn::GetMinWidth() const
3293 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
3296 int wxDataViewColumn::GetWidth() const
3298 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
3301 void wxDataViewColumn::SetWidth( int width
)
3303 if ( width
== wxCOL_WIDTH_AUTOSIZE
)
3305 // NB: this disables user resizing
3306 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
3310 if ( width
== wxCOL_WIDTH_DEFAULT
)
3312 // TODO find a better calculation
3313 width
= wxDVC_DEFAULT_WIDTH
;
3316 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
3317 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
3321 void wxDataViewColumn::SetReorderable( bool reorderable
)
3323 gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column
), reorderable
);
3326 bool wxDataViewColumn::IsReorderable() const
3328 return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column
) );
3331 //-----------------------------------------------------------------------------
3332 // wxGtkTreeModelNode
3333 //-----------------------------------------------------------------------------
3336 class wxGtkTreeModelChildWithPos
3344 int wxGtkTreeModelChildWithPosCmp( const void* data1
, const void* data2
, const void* user_data
)
3346 const wxGtkTreeModelChildWithPos
* child1
= (const wxGtkTreeModelChildWithPos
*) data1
;
3347 const wxGtkTreeModelChildWithPos
* child2
= (const wxGtkTreeModelChildWithPos
*) data2
;
3348 const wxDataViewCtrlInternal
*internal
= (const wxDataViewCtrlInternal
*) user_data
;
3349 int ret
= internal
->GetDataViewModel()->Compare( child1
->id
, child2
->id
,
3350 internal
->GetSortColumn(), (internal
->GetSortOrder() == GTK_SORT_DESCENDING
) );
3356 int LINKAGEMODE
wxGtkTreeModelChildPtrCmp( void*** data1
, void*** data2
)
3358 return gs_internal
->GetDataViewModel()->Compare( wxDataViewItem(**data1
), wxDataViewItem(**data2
),
3359 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
3362 WX_DEFINE_ARRAY_PTR( void**, wxGtkTreeModelChildrenPtr
);
3365 void wxGtkTreeModelNode::Resort()
3367 size_t child_count
= GetChildCount();
3368 if (child_count
== 0)
3371 size_t node_count
= GetNodesCount();
3373 if (child_count
== 1)
3375 if (node_count
== 1)
3377 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
3383 gint
*new_order
= new gint
[child_count
];
3386 // m_children has the original *void
3387 // ptrs points to these
3388 wxGtkTreeModelChildrenPtr ptrs
;
3390 for (i
= 0; i
< child_count
; i
++)
3391 ptrs
.Add( &(m_children
[i
]) );
3393 gs_internal
= m_internal
;
3394 ptrs
.Sort( &wxGtkTreeModelChildPtrCmp
);
3396 wxGtkTreeModelChildren temp
;
3397 void** base_ptr
= &(m_children
[0]);
3398 // Transfer positions to new_order array and
3400 for (i
= 0; i
< child_count
; i
++)
3402 new_order
[i
] = ptrs
[i
] - base_ptr
;
3403 temp
.Add( *ptrs
[i
] );
3406 // Transfer IDs back to m_children
3408 WX_APPEND_ARRAY( temp
, m_children
);
3413 // Build up array with IDs and original positions
3414 wxGtkTreeModelChildWithPos
* temp
= new wxGtkTreeModelChildWithPos
[child_count
];
3416 for (i
= 0; i
< child_count
; i
++)
3419 temp
[i
].id
= m_children
[i
];
3421 // Sort array keeping original positions
3422 wxQsort( temp
, child_count
, sizeof(wxGtkTreeModelChildWithPos
),
3423 &wxGtkTreeModelChildWithPosCmp
, m_internal
);
3424 // Transfer positions to new_order array and
3425 // IDs to m_children
3427 for (i
= 0; i
< child_count
; i
++)
3429 new_order
[i
] = temp
[i
].pos
;
3430 m_children
.Add( temp
[i
].id
);
3439 wxGtkTreeModelChildren temp
;
3440 WX_APPEND_ARRAY( temp
, m_children
);
3442 gs_internal
= m_internal
;
3443 m_children
.Sort( &wxGtkTreeModelChildCmp
);
3446 for (pos
= 0; pos
< child_count
; pos
++)
3448 void *id
= m_children
.Item( pos
);
3449 int old_pos
= temp
.Index( id
);
3450 new_order
[pos
] = old_pos
;
3454 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
3457 iter
.user_data
= GetItem().GetID();
3458 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
3460 gtk_tree_model_rows_reordered( gtk_tree_model
,
3461 wxGtkTreePath(m_internal
->get_path(&iter
)), &iter
, new_order
);
3463 delete [] new_order
;
3466 for (pos
= 0; pos
< node_count
; pos
++)
3468 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
3473 //-----------------------------------------------------------------------------
3474 // wxDataViewCtrlInternal
3475 //-----------------------------------------------------------------------------
3477 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
)
3480 m_wx_model
= wx_model
;
3484 m_sort_order
= GTK_SORT_ASCENDING
;
3486 m_dataview_sort_column
= NULL
;
3488 m_dragDataObject
= NULL
;
3489 m_dropDataObject
= NULL
;
3493 m_gtk_model
= wxgtk_tree_model_new();
3494 m_gtk_model
->internal
= this;
3496 m_notifier
= new wxGtkDataViewModelNotifier( wx_model
, this );
3498 wx_model
->AddNotifier( m_notifier
);
3500 // g_object_unref( gtk_model ); ???
3502 if (!m_wx_model
->IsVirtualListModel())
3505 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->GtkGetTreeView()), GTK_TREE_MODEL(m_gtk_model
) );
3508 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
3510 m_wx_model
->RemoveNotifier( m_notifier
);
3512 // remove the model from the GtkTreeView before it gets destroyed
3513 gtk_tree_view_set_model( GTK_TREE_VIEW( m_owner
->GtkGetTreeView() ), NULL
);
3515 g_object_unref( m_gtk_model
);
3517 delete m_dragDataObject
;
3518 delete m_dropDataObject
;
3521 void wxDataViewCtrlInternal::ScheduleRefresh()
3526 void wxDataViewCtrlInternal::OnInternalIdle()
3530 GtkWidget
*widget
= m_owner
->GtkGetTreeView();
3531 gtk_widget_queue_draw( widget
);
3536 void wxDataViewCtrlInternal::InitTree()
3538 wxDataViewItem item
;
3539 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
3541 BuildBranch( m_root
);
3544 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
3546 if (node
->GetChildCount() == 0)
3548 wxDataViewItemArray children
;
3549 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
3552 for (pos
= 0; pos
< count
; pos
++)
3554 wxDataViewItem child
= children
[pos
];
3556 if (m_wx_model
->IsContainer( child
))
3557 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
3559 node
->AddLeave( child
.GetID() );
3561 // Don't send any events here
3568 bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat
&format
)
3570 wxGtkString
atom_str( gdk_atom_name( format
) );
3571 m_dragSourceTargetEntryTarget
= wxCharBuffer( atom_str
);
3573 m_dragSourceTargetEntry
.target
= m_dragSourceTargetEntryTarget
.data();
3574 m_dragSourceTargetEntry
.flags
= 0;
3575 m_dragSourceTargetEntry
.info
= static_cast<guint
>(-1);
3577 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3578 GDK_BUTTON1_MASK
, &m_dragSourceTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3583 bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat
&format
)
3585 wxGtkString
atom_str( gdk_atom_name( format
) );
3586 m_dropTargetTargetEntryTarget
= wxCharBuffer( atom_str
);
3588 m_dropTargetTargetEntry
.target
= m_dropTargetTargetEntryTarget
.data();
3589 m_dropTargetTargetEntry
.flags
= 0;
3590 m_dropTargetTargetEntry
.info
= static_cast<guint
>(-1);
3592 gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3593 &m_dropTargetTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3598 gboolean
wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource
*WXUNUSED(drag_source
),
3601 delete m_dragDataObject
;
3602 m_dragDataObject
= NULL
;
3604 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3608 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3609 event
.SetEventObject( m_owner
);
3610 event
.SetItem( item
);
3611 event
.SetModel( m_wx_model
);
3613 gtk_widget_get_pointer(m_owner
->GtkGetTreeView(), &x
, &y
);
3614 event
.SetPosition(x
, y
);
3615 if (!m_owner
->HandleWindowEvent( event
))
3618 if (!event
.IsAllowed())
3621 wxDataObject
*obj
= event
.GetDataObject();
3625 m_dragDataObject
= obj
;
3631 wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource
*WXUNUSED(drag_source
),
3632 GtkTreePath
*WXUNUSED(path
))
3637 gboolean
wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource
*WXUNUSED(drag_source
),
3638 GtkTreePath
*path
, GtkSelectionData
*selection_data
)
3640 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3644 GdkAtom target
= gtk_selection_data_get_target(selection_data
);
3645 if (!m_dragDataObject
->IsSupported(target
))
3648 size_t size
= m_dragDataObject
->GetDataSize(target
);
3652 void *buf
= malloc( size
);
3654 gboolean res
= FALSE
;
3655 if (m_dragDataObject
->GetDataHere(target
, buf
))
3659 gtk_selection_data_set(selection_data
, target
,
3660 8, (const guchar
*) buf
, size
);
3669 wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3671 GtkSelectionData
*selection_data
)
3673 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3677 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
3678 event
.SetEventObject( m_owner
);
3679 event
.SetItem( item
);
3680 event
.SetModel( m_wx_model
);
3681 event
.SetDataFormat(gtk_selection_data_get_target(selection_data
));
3682 event
.SetDataSize(gtk_selection_data_get_length(selection_data
));
3683 event
.SetDataBuffer(const_cast<guchar
*>(gtk_selection_data_get_data(selection_data
)));
3684 if (!m_owner
->HandleWindowEvent( event
))
3687 if (!event
.IsAllowed())
3694 wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3696 GtkSelectionData
*selection_data
)
3698 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3702 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
3703 event
.SetEventObject( m_owner
);
3704 event
.SetItem( item
);
3705 event
.SetModel( m_wx_model
);
3706 event
.SetDataFormat(gtk_selection_data_get_target(selection_data
));
3707 if (!m_owner
->HandleWindowEvent( event
))
3710 if (!event
.IsAllowed())
3716 // notifications from wxDataViewModel
3718 bool wxDataViewCtrlInternal::Cleared()
3733 void wxDataViewCtrlInternal::Resort()
3735 if (!m_wx_model
->IsVirtualListModel())
3741 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3743 if (!m_wx_model
->IsVirtualListModel())
3745 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3746 wxASSERT_MSG(parent_node
,
3747 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3749 if (m_wx_model
->IsContainer( item
))
3750 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
3752 parent_node
->AddLeave( item
.GetID() );
3760 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3762 if (!m_wx_model
->IsVirtualListModel())
3764 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3765 wxASSERT_MSG(parent_node
,
3766 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3768 parent_node
->DeleteChild( item
.GetID() );
3776 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
3778 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3779 event
.SetEventObject( m_owner
);
3780 event
.SetModel( m_owner
->GetModel() );
3781 event
.SetItem( item
);
3782 m_owner
->HandleWindowEvent( event
);
3787 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int view_column
)
3789 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3790 event
.SetEventObject( m_owner
);
3791 event
.SetModel( m_owner
->GetModel() );
3792 event
.SetColumn( view_column
);
3793 event
.SetDataViewColumn( GetOwner()->GetColumn(view_column
) );
3794 event
.SetItem( item
);
3795 m_owner
->HandleWindowEvent( event
);
3802 GtkTreeModelFlags
wxDataViewCtrlInternal::get_flags()
3806 if ( m_wx_model
->IsListModel() )
3807 flags
|= GTK_TREE_MODEL_LIST_ONLY
;
3809 if ( !m_wx_model
->IsVirtualListModel() )
3810 flags
|= GTK_TREE_MODEL_ITERS_PERSIST
;
3812 return GtkTreeModelFlags(flags
);
3815 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
3818 if (m_wx_model
->IsVirtualListModel())
3820 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3822 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
3824 if (i
>= wx_model
->GetCount())
3827 iter
->stamp
= m_gtk_model
->stamp
;
3828 // user_data is just the index +1
3829 iter
->user_data
= (gpointer
) (i
+1);
3835 int depth
= gtk_tree_path_get_depth( path
);
3837 wxGtkTreeModelNode
*node
= m_root
;
3840 for (i
= 0; i
< depth
; i
++)
3842 BuildBranch( node
);
3844 gint pos
= gtk_tree_path_get_indices (path
)[i
];
3845 if (pos
< 0) return FALSE
;
3846 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
3848 void* id
= node
->GetChildren().Item( (size_t) pos
);
3852 iter
->stamp
= m_gtk_model
->stamp
;
3853 iter
->user_data
= id
;
3857 size_t count
= node
->GetNodes().GetCount();
3859 for (pos2
= 0; pos2
< count
; pos2
++)
3861 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
3862 if (child_node
->GetItem().GetID() == id
)
3874 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
3876 // When this is called from ItemDeleted(), the item is already
3877 // deleted in the model.
3879 GtkTreePath
*retval
= gtk_tree_path_new ();
3881 if (m_wx_model
->IsVirtualListModel())
3883 // iter is root, add nothing
3884 if (!iter
->user_data
)
3887 // user_data is just the index +1
3888 int i
= ( (wxUIntPtr
) iter
->user_data
) -1;
3889 gtk_tree_path_append_index (retval
, i
);
3893 void *id
= iter
->user_data
;
3895 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
3898 int pos
= node
->GetChildren().Index( id
);
3900 gtk_tree_path_prepend_index( retval
, pos
);
3902 id
= node
->GetItem().GetID();
3903 node
= node
->GetParent();
3910 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
3912 if (m_wx_model
->IsVirtualListModel())
3914 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3916 // user_data is just the index +1
3917 int n
= ( (wxUIntPtr
) iter
->user_data
) -1;
3921 iter
->user_data
= NULL
;
3925 if (n
>= (int) wx_model
->GetCount()-1)
3927 iter
->user_data
= NULL
;
3931 // user_data is just the index +1 (+2 because we need the next)
3932 iter
->user_data
= (gpointer
) (n
+2);
3936 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
3937 if( parent
== NULL
)
3939 iter
->user_data
= NULL
;
3943 int pos
= parent
->GetChildren().Index( iter
->user_data
);
3945 if (pos
== (int) parent
->GetChildCount()-1)
3947 iter
->user_data
= NULL
;
3951 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
3957 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
3959 if (m_wx_model
->IsVirtualListModel())
3961 // this is a list, nodes have no children
3965 iter
->stamp
= m_gtk_model
->stamp
;
3966 iter
->user_data
= (gpointer
) 1;
3974 if (m_root
->GetChildCount() == 0) return FALSE
;
3975 iter
->stamp
= m_gtk_model
->stamp
;
3976 iter
->user_data
= (gpointer
) m_root
->GetChildren().Item( 0 );
3981 wxDataViewItem item
;
3983 item
= wxDataViewItem( (void*) parent
->user_data
);
3985 if (!m_wx_model
->IsContainer( item
))
3988 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3989 wxASSERT_MSG(parent_node
,
3990 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3992 BuildBranch( parent_node
);
3994 if (parent_node
->GetChildCount() == 0)
3997 iter
->stamp
= m_gtk_model
->stamp
;
3998 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
4004 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
4006 if (m_wx_model
->IsVirtualListModel())
4008 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
4011 return (wx_model
->GetCount() > 0);
4013 // this is a list, nodes have no children
4019 return (m_root
->GetChildCount() > 0);
4021 wxDataViewItem
item( (void*) iter
->user_data
);
4023 bool is_container
= m_wx_model
->IsContainer( item
);
4028 wxGtkTreeModelNode
*node
= FindNode( iter
);
4030 "Did you forget a call to ItemAdded()? The iterator is unknown to the wxGtkTreeModel");
4032 BuildBranch( node
);
4034 return (node
->GetChildCount() > 0);
4038 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
4040 if (m_wx_model
->IsVirtualListModel())
4042 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
4045 return (gint
) wx_model
->GetCount();
4052 return m_root
->GetChildCount();
4054 wxDataViewItem
item( (void*) iter
->user_data
);
4056 if (!m_wx_model
->IsContainer( item
))
4059 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
4060 wxASSERT_MSG(parent_node
,
4061 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
4063 BuildBranch( parent_node
);
4065 return parent_node
->GetChildCount();
4069 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
4071 if (m_wx_model
->IsVirtualListModel())
4073 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
4081 if (n
>= (gint
) wx_model
->GetCount())
4084 iter
->stamp
= m_gtk_model
->stamp
;
4085 // user_data is just the index +1
4086 iter
->user_data
= (gpointer
) (n
+1);
4093 if (parent
) id
= (void*) parent
->user_data
;
4094 wxDataViewItem
item( id
);
4096 if (!m_wx_model
->IsContainer( item
))
4099 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
4100 wxASSERT_MSG(parent_node
,
4101 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
4103 BuildBranch( parent_node
);
4105 iter
->stamp
= m_gtk_model
->stamp
;
4106 iter
->user_data
= parent_node
->GetChildren().Item( n
);
4112 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
4114 if (m_wx_model
->IsVirtualListModel())
4120 wxGtkTreeModelNode
*node
= FindParentNode( child
);
4124 iter
->stamp
= m_gtk_model
->stamp
;
4125 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
4131 // item can be deleted already in the model
4132 int wxDataViewCtrlInternal::GetIndexOf( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
4134 if (m_wx_model
->IsVirtualListModel())
4136 return wxPtrToUInt(item
.GetID()) - 1;
4140 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
4141 wxGtkTreeModelChildren
&children
= parent_node
->GetChildren();
4143 for (j
= 0; j
< children
.GetCount(); j
++)
4145 if (children
[j
] == item
.GetID())
4153 static wxGtkTreeModelNode
*
4154 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
4160 list
.DeleteContents( true );
4161 wxDataViewItem
it( item
);
4165 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
4166 list
.Insert( pItem
);
4167 it
= model
->GetParent( it
);
4170 wxGtkTreeModelNode
* node
= treeNode
;
4171 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
4173 if( node
&& node
->GetNodes().GetCount() != 0 )
4175 int len
= node
->GetNodes().GetCount();
4176 wxGtkTreeModelNodes
&nodes
= node
->GetNodes();
4178 for( ; j
< len
; j
++)
4180 if( nodes
[j
]->GetItem() == *(n
->GetData()))
4199 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
4204 wxDataViewItem
item( (void*) iter
->user_data
);
4208 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
4213 wxLogDebug( "Not found %p", iter->user_data );
4217 // TODO: remove this code
4223 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
4228 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
4233 wxLogDebug( "Not found %p", item.GetID() );
4237 // TODO: remove this code
4243 static wxGtkTreeModelNode
*
4244 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
4250 list
.DeleteContents( true );
4254 wxDataViewItem
it( model
->GetParent( item
) );
4257 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
4258 list
.Insert( pItem
);
4259 it
= model
->GetParent( it
);
4262 wxGtkTreeModelNode
* node
= treeNode
;
4263 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
4265 if( node
&& node
->GetNodes().GetCount() != 0 )
4267 int len
= node
->GetNodes().GetCount();
4268 wxGtkTreeModelNodes nodes
= node
->GetNodes();
4270 for( ; j
< len
; j
++)
4272 if( nodes
[j
]->GetItem() == *(n
->GetData()))
4287 //Examine whether the node is item's parent node
4288 int len
= node
->GetChildCount();
4289 for( int i
= 0; i
< len
; i
++ )
4291 if( node
->GetChildren().Item( i
) == item
.GetID() )
4297 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
4302 wxDataViewItem
item( (void*) iter
->user_data
);
4306 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
4309 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
4314 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
4317 //-----------------------------------------------------------------------------
4318 // wxDataViewCtrl signal callbacks
4319 //-----------------------------------------------------------------------------
4322 wxdataview_selection_changed_callback( GtkTreeSelection
* WXUNUSED(selection
), wxDataViewCtrl
*dv
)
4324 if (!gtk_widget_get_realized(dv
->m_widget
))
4327 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
4328 event
.SetItem( dv
->GetSelection() );
4329 event
.SetModel( dv
->GetModel() );
4330 dv
->HandleWindowEvent( event
);
4334 wxdataview_row_activated_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreePath
*path
,
4335 GtkTreeViewColumn
*WXUNUSED(column
), wxDataViewCtrl
*dv
)
4337 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
4339 wxDataViewItem
item(dv
->GTKPathToItem(path
));
4340 event
.SetItem( item
);
4341 event
.SetModel( dv
->GetModel() );
4342 dv
->HandleWindowEvent( event
);
4346 wxdataview_test_expand_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4347 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4349 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
4351 wxDataViewItem
item( (void*) iter
->user_data
);;
4352 event
.SetItem( item
);
4353 event
.SetModel( dv
->GetModel() );
4354 dv
->HandleWindowEvent( event
);
4356 return !event
.IsAllowed();
4360 wxdataview_row_expanded_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4361 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4363 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
4365 wxDataViewItem
item( (void*) iter
->user_data
);;
4366 event
.SetItem( item
);
4367 event
.SetModel( dv
->GetModel() );
4368 dv
->HandleWindowEvent( event
);
4372 wxdataview_test_collapse_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4373 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4375 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
4377 wxDataViewItem
item( (void*) iter
->user_data
);;
4378 event
.SetItem( item
);
4379 event
.SetModel( dv
->GetModel() );
4380 dv
->HandleWindowEvent( event
);
4382 return !event
.IsAllowed();
4386 wxdataview_row_collapsed_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4387 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4389 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
4391 wxDataViewItem
item( (void*) iter
->user_data
);;
4392 event
.SetItem( item
);
4393 event
.SetModel( dv
->GetModel() );
4394 dv
->HandleWindowEvent( event
);
4397 //-----------------------------------------------------------------------------
4399 //-----------------------------------------------------------------------------
4401 void wxDataViewCtrl::AddChildGTK(wxWindowGTK
* child
)
4403 GtkWidget
* treeview
= GtkGetTreeView();
4405 // Insert widget in GtkTreeView
4406 if (gtk_widget_get_realized(treeview
))
4407 gtk_widget_set_parent_window( child
->m_widget
,
4408 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
4409 gtk_widget_set_parent( child
->m_widget
, treeview
);
4413 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
4414 GtkAllocation
*WXUNUSED(gtk_alloc
),
4415 wxDataViewCtrl
*win
)
4417 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
4420 wxWindow
*child
= node
->GetData();
4423 gtk_widget_size_request( child
->m_widget
, &req
);
4425 GtkAllocation alloc
;
4426 alloc
.x
= child
->m_x
;
4427 alloc
.y
= child
->m_y
;
4428 alloc
.width
= child
->m_width
;
4429 alloc
.height
= child
->m_height
;
4430 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
4432 node
= node
->GetNext();
4437 //-----------------------------------------------------------------------------
4438 // "motion_notify_event"
4439 //-----------------------------------------------------------------------------
4442 gtk_dataview_motion_notify_callback( GtkWidget
*WXUNUSED(widget
),
4443 GdkEventMotion
*gdk_event
,
4444 wxDataViewCtrl
*dv
)
4446 if (gdk_event
->is_hint
)
4450 GdkModifierType state
;
4451 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
4457 GtkTreeViewColumn
*column
= NULL
;
4460 if (gtk_tree_view_get_path_at_pos(
4461 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4462 (int) gdk_event
->x
, (int) gdk_event
->y
,
4471 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4479 //-----------------------------------------------------------------------------
4480 // "button_press_event"
4481 //-----------------------------------------------------------------------------
4484 gtk_dataview_button_press_callback( GtkWidget
*WXUNUSED(widget
),
4485 GdkEventButton
*gdk_event
,
4486 wxDataViewCtrl
*dv
)
4488 if ((gdk_event
->button
== 3) && (gdk_event
->type
== GDK_BUTTON_PRESS
))
4491 GtkTreeViewColumn
*column
= NULL
;
4494 if (gtk_tree_view_get_path_at_pos(
4495 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4496 (int) gdk_event
->x
, (int) gdk_event
->y
,
4504 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, dv
->GetId() );
4505 event
.SetItem(dv
->GTKPathToItem(path
));
4506 event
.SetModel( dv
->GetModel() );
4507 return dv
->HandleWindowEvent( event
);
4515 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
4517 wxDataViewCtrl::~wxDataViewCtrl()
4519 // Stop editing before destroying the control to remove any event handlers
4520 // which are added when editing started: if we didn't do this, the base
4521 // class dtor would assert as it checks for any leftover handlers.
4524 GtkTreeViewColumn
*col
;
4525 gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview
), NULL
, &col
);
4527 wxDataViewColumn
* const wxcol
= FromGTKColumn(col
);
4530 // This won't do anything if we're not editing it
4531 wxcol
->GetRenderer()->CancelEditing();
4540 void wxDataViewCtrl::Init()
4544 m_cols
.DeleteContents( true );
4546 m_uniformRowHeight
= -1;
4549 bool wxDataViewCtrl::Create(wxWindow
*parent
,
4554 const wxValidator
& validator
,
4555 const wxString
& name
)
4557 if (!PreCreation( parent
, pos
, size
) ||
4558 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
4560 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
4564 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
4565 g_object_ref(m_widget
);
4567 GTKScrolledWindowSetBorder(m_widget
, style
);
4569 m_treeview
= gtk_tree_view_new();
4570 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
4572 g_signal_connect (m_treeview
, "size_allocate",
4573 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
4576 if (!gtk_check_version(2,6,0))
4578 bool fixed
= (style
& wxDV_VARIABLE_LINE_HEIGHT
) == 0;
4579 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4583 if (style
& wxDV_MULTIPLE
)
4585 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4586 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
4589 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
4592 if (!gtk_check_version(2,10,0))
4594 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
4596 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
4597 (style
& wxDV_VERT_RULES
) != 0)
4598 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
4599 else if (style
& wxDV_VERT_RULES
)
4600 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
4601 else if (style
& wxDV_HORIZ_RULES
)
4602 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
4604 if (grid
!= GTK_TREE_VIEW_GRID_LINES_NONE
)
4605 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
4609 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_ROW_LINES
) != 0 );
4611 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
4612 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
4613 gtk_widget_show (m_treeview
);
4615 m_parent
->DoAddChild( this );
4619 GtkEnableSelectionEvents();
4621 g_signal_connect_after (m_treeview
, "row-activated",
4622 G_CALLBACK (wxdataview_row_activated_callback
), this);
4624 g_signal_connect (m_treeview
, "test-collapse-row",
4625 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
4627 g_signal_connect_after (m_treeview
, "row-collapsed",
4628 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
4630 g_signal_connect (m_treeview
, "test-expand-row",
4631 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
4633 g_signal_connect_after (m_treeview
, "row-expanded",
4634 G_CALLBACK (wxdataview_row_expanded_callback
), this);
4636 g_signal_connect (m_treeview
, "motion_notify_event",
4637 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
4639 g_signal_connect (m_treeview
, "button_press_event",
4640 G_CALLBACK (gtk_dataview_button_press_callback
), this);
4645 wxDataViewItem
wxDataViewCtrl::GTKPathToItem(GtkTreePath
*path
) const
4648 return wxDataViewItem(path
&& m_internal
->get_iter(&iter
, path
)
4653 void wxDataViewCtrl::OnInternalIdle()
4655 wxWindow::OnInternalIdle();
4657 m_internal
->OnInternalIdle();
4659 unsigned int cols
= GetColumnCount();
4661 for (i
= 0; i
< cols
; i
++)
4663 wxDataViewColumn
*col
= GetColumn( i
);
4664 col
->OnInternalIdle();
4667 if (m_ensureVisibleDefered
.IsOk())
4669 ExpandAncestors(m_ensureVisibleDefered
);
4671 iter
.user_data
= (gpointer
) m_ensureVisibleDefered
.GetID();
4672 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4673 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
4674 m_ensureVisibleDefered
= wxDataViewItem(0);
4678 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4680 wxDELETE(m_internal
);
4682 if (!wxDataViewCtrlBase::AssociateModel( model
))
4686 if (!gtk_check_version(2,6,0))
4688 bool fixed
= (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
) == 0) || (model
->IsVirtualListModel()));
4689 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4693 m_internal
= new wxDataViewCtrlInternal( this, model
);
4698 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4700 return m_internal
->EnableDragSource( format
);
4703 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4705 return m_internal
->EnableDropTarget( format
);
4708 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4710 if (!wxDataViewCtrlBase::AppendColumn(col
))
4713 m_cols
.Append( col
);
4716 if (!gtk_check_version(2,6,0))
4718 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4719 GTK_TREE_VIEW_COLUMN_FIXED
)
4720 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4724 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
4725 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4730 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4732 if (!wxDataViewCtrlBase::PrependColumn(col
))
4735 m_cols
.Insert( col
);
4738 if (!gtk_check_version(2,6,0))
4740 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4741 GTK_TREE_VIEW_COLUMN_FIXED
)
4742 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4746 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4747 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
4752 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4754 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4757 m_cols
.Insert( pos
, col
);
4760 if (!gtk_check_version(2,6,0))
4762 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4763 GTK_TREE_VIEW_COLUMN_FIXED
)
4764 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4768 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4769 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), pos
);
4774 unsigned int wxDataViewCtrl::GetColumnCount() const
4776 return m_cols
.GetCount();
4779 wxDataViewColumn
* wxDataViewCtrl::FromGTKColumn(GtkTreeViewColumn
*gtk_col
) const
4784 wxDataViewColumnList::const_iterator iter
;
4785 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4787 wxDataViewColumn
*col
= *iter
;
4788 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
4794 wxFAIL_MSG( "No matching column?" );
4799 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
4801 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
4803 return FromGTKColumn(gtk_col
);
4806 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4808 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4809 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
4811 m_cols
.DeleteObject( column
);
4816 bool wxDataViewCtrl::ClearColumns()
4818 wxDataViewColumnList::iterator iter
;
4819 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4821 wxDataViewColumn
*col
= *iter
;
4822 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4823 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4831 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4833 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
4835 wxGtkList
list(gtk_tree_view_get_columns(GTK_TREE_VIEW(m_treeview
)));
4837 return g_list_index( list
, (gconstpointer
) gtk_column
);
4840 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4842 return m_internal
->GetDataViewSortColumn();
4845 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4848 iter
.user_data
= item
.GetID();
4849 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4850 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
4853 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4856 iter
.user_data
= item
.GetID();
4857 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4858 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
4861 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4864 iter
.user_data
= item
.GetID();
4865 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4866 return gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview
), path
);
4869 wxDataViewItem
wxDataViewCtrl::DoGetCurrentItem() const
4871 // The tree doesn't have any current item if it hadn't been created yet but
4872 // it's arguably not an error to call this function in this case so just
4873 // return an invalid item without asserting.
4875 return wxDataViewItem();
4878 gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview
), path
.ByRef(), NULL
);
4880 return GTKPathToItem(path
);
4883 void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem
& item
)
4885 wxCHECK_RET( m_treeview
,
4886 "Current item can't be set before creating the control." );
4888 // We need to make sure the model knows about this item or the path would
4889 // be invalid and gtk_tree_view_set_cursor() would silently do nothing.
4890 ExpandAncestors(item
);
4892 // We also need to preserve the existing selection from changing.
4893 // Unfortunately the only way to do it seems to use our own selection
4894 // function and forbid any selection changes during set cursor call.
4895 wxGtkTreeSelectionLock
4896 lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview
)));
4898 // Do move the cursor now.
4900 iter
.user_data
= item
.GetID();
4901 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4903 gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview
), path
, NULL
, FALSE
);
4906 void wxDataViewCtrl::StartEditor(const wxDataViewItem
& item
, unsigned int column
)
4908 wxCHECK_RET( m_treeview
,
4909 "Current item can't be set before creating the control." );
4911 // We need to make sure the model knows about this item or the path would
4912 // be invalid and gtk_tree_view_set_cursor() would silently do nothing.
4913 ExpandAncestors(item
);
4915 wxDataViewColumn
*dvcolumn
= GetColumn(column
);
4916 wxASSERT_MSG(dvcolumn
, "Could not retrieve column");
4917 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(dvcolumn
->GetGtkHandle());
4919 // We also need to preserve the existing selection from changing.
4920 // Unfortunately the only way to do it seems to use our own selection
4921 // function and forbid any selection changes during set cursor call.
4922 wxGtkTreeSelectionLock
4923 lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview
)));
4925 // Do move the cursor now.
4927 iter
.user_data
= item
.GetID();
4928 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4930 gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview
), path
, gcolumn
, TRUE
);
4933 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4935 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4937 if (m_windowStyle
& wxDV_MULTIPLE
)
4939 // Report the first one
4940 GtkTreeModel
*model
;
4941 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4945 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4946 wxDataViewItem
item(GTKPathToItem(path
));
4949 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4950 g_list_free( list
);
4958 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
4960 wxDataViewItem
item( iter
.user_data
);
4965 return wxDataViewItem(0);
4968 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4972 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4973 if (HasFlag(wxDV_MULTIPLE
))
4975 GtkTreeModel
*model
;
4976 wxGtkTreePathList
list(gtk_tree_selection_get_selected_rows(selection
, &model
));
4979 for ( GList
* current
= list
; current
; current
= g_list_next(current
) )
4981 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4983 sel
.Add(GTKPathToItem(path
));
4991 GtkTreeModel
*model
;
4993 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
4996 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
5004 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
5006 GtkDisableSelectionEvents();
5008 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5010 gtk_tree_selection_unselect_all( selection
);
5012 wxDataViewItem last_parent
;
5015 for (i
= 0; i
< sel
.GetCount(); i
++)
5017 wxDataViewItem item
= sel
[i
];
5018 wxDataViewItem parent
= GetModel()->GetParent( item
);
5021 if (parent
!= last_parent
)
5022 ExpandAncestors(item
);
5024 last_parent
= parent
;
5027 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
5028 iter
.user_data
= (gpointer
) item
.GetID();
5029 gtk_tree_selection_select_iter( selection
, &iter
);
5032 GtkEnableSelectionEvents();
5035 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
5037 ExpandAncestors(item
);
5039 GtkDisableSelectionEvents();
5041 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5044 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
5045 iter
.user_data
= (gpointer
) item
.GetID();
5046 gtk_tree_selection_select_iter( selection
, &iter
);
5048 GtkEnableSelectionEvents();
5051 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
5053 GtkDisableSelectionEvents();
5055 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5058 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
5059 iter
.user_data
= (gpointer
) item
.GetID();
5060 gtk_tree_selection_unselect_iter( selection
, &iter
);
5062 GtkEnableSelectionEvents();
5065 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
5067 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5070 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
5071 iter
.user_data
= (gpointer
) item
.GetID();
5073 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
5076 void wxDataViewCtrl::SelectAll()
5078 GtkDisableSelectionEvents();
5080 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5082 gtk_tree_selection_select_all( selection
);
5084 GtkEnableSelectionEvents();
5087 void wxDataViewCtrl::UnselectAll()
5089 GtkDisableSelectionEvents();
5091 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5093 gtk_tree_selection_unselect_all( selection
);
5095 GtkEnableSelectionEvents();
5098 void wxDataViewCtrl::EnsureVisible(const wxDataViewItem
& item
,
5099 const wxDataViewColumn
*WXUNUSED(column
))
5101 m_ensureVisibleDefered
= item
;
5102 ExpandAncestors(item
);
5105 iter
.user_data
= (gpointer
) item
.GetID();
5106 wxGtkTreePath
path(m_internal
->get_path( &iter
));
5107 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
5110 void wxDataViewCtrl::HitTest(const wxPoint
& point
,
5111 wxDataViewItem
& item
,
5112 wxDataViewColumn
*& column
) const
5114 // gtk_tree_view_get_dest_row_at_pos() is the right one. But it does not tell the column.
5115 // gtk_tree_view_get_path_at_pos() is the wrong function. It doesn't mind the header but returns column.
5116 // See http://mail.gnome.org/archives/gtkmm-list/2005-January/msg00080.html
5117 // So we have to use both of them.
5118 // Friedrich Haase 2010-9-20
5119 wxGtkTreePath path
, pathScratch
;
5120 GtkTreeViewColumn
* GtkColumn
= NULL
;
5121 GtkTreeViewDropPosition pos
= GTK_TREE_VIEW_DROP_INTO_OR_AFTER
;
5125 // cannot directly call GtkGetTreeView(), HitTest is const and so is this pointer
5126 wxDataViewCtrl
* ctrl
= (wxDataViewCtrl
*)this; // ugly workaround, ctrl is NOT const
5127 GtkTreeView
* treeView
= GTK_TREE_VIEW(ctrl
->GtkGetTreeView());
5129 // is there possibly a better suited function to get the column?
5130 gtk_tree_view_get_path_at_pos( // and this is the wrong call but it delivers the column
5132 (int) point
.x
, (int) point
.y
,
5133 pathScratch
.ByRef(),
5134 &GtkColumn
, // here we get the GtkColumn
5138 if ( GtkColumn
!= NULL
)
5140 // we got GTK column
5141 // the right call now which takes the header into account
5142 gtk_tree_view_get_dest_row_at_pos( treeView
, (int) point
.x
, (int) point
.y
, path
.ByRef(), &pos
);
5145 item
= wxDataViewItem(GTKPathToItem(path
));
5146 // else we got a GTK column but the position is not over an item, e.g. below last item
5147 for ( unsigned int i
=0, cols
=GetColumnCount(); i
<cols
; ++i
) // search the wx column
5149 wxDataViewColumn
* col
= GetColumn(i
);
5150 if ( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == GtkColumn
)
5152 column
= col
; // here we get the wx column
5157 // else no column and thus no item, both null
5161 wxDataViewCtrl::GetItemRect(const wxDataViewItem
& WXUNUSED(item
),
5162 const wxDataViewColumn
*WXUNUSED(column
)) const
5167 bool wxDataViewCtrl::SetRowHeight(int rowHeight
)
5169 m_uniformRowHeight
= rowHeight
;
5173 void wxDataViewCtrl::DoSetExpanderColumn()
5175 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
5176 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
5179 void wxDataViewCtrl::DoSetIndent()
5183 void wxDataViewCtrl::GtkDisableSelectionEvents()
5185 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5186 g_signal_handlers_disconnect_by_func( selection
,
5187 (gpointer
) (wxdataview_selection_changed_callback
), this);
5190 void wxDataViewCtrl::GtkEnableSelectionEvents()
5192 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5193 g_signal_connect_after (selection
, "changed",
5194 G_CALLBACK (wxdataview_selection_changed_callback
), this);
5197 // ----------------------------------------------------------------------------
5198 // visual attributes stuff
5199 // ----------------------------------------------------------------------------
5203 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
5205 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
5208 void wxDataViewCtrl::DoApplyWidgetStyle(GtkRcStyle
*style
)
5210 wxDataViewCtrlBase::DoApplyWidgetStyle(style
);
5211 gtk_widget_modify_style(m_treeview
, style
);
5214 #endif // !wxUSE_GENERICDATAVIEWCTRL
5216 #endif // wxUSE_DATAVIEWCTRL