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
1591 GtkTreeIter parentIter
;
1592 parentIter
.stamp
= wxgtk_model
->stamp
;
1593 parentIter
.user_data
= (gpointer
) parent
.GetID();
1594 wxGtkTreePath
parentPath(wxgtk_tree_model_get_path(
1595 GTK_TREE_MODEL(wxgtk_model
), &parentIter
));
1597 // and add the final index ourselves
1598 wxGtkTreePath
path(gtk_tree_path_copy(parentPath
));
1599 int index
= m_internal
->GetIndexOf( parent
, item
);
1600 gtk_tree_path_append_index( path
, index
);
1603 gtk_tree_model_row_deleted(
1604 GTK_TREE_MODEL(wxgtk_model
), path
);
1606 m_internal
->ItemDeleted( parent
, item
);
1608 // Did we remove the last child, causing 'parent' to become a leaf?
1609 if ( !m_wx_model
->IsContainer(parent
) )
1611 gtk_tree_model_row_has_child_toggled
1613 GTK_TREE_MODEL(wxgtk_model
),
1622 void wxGtkDataViewModelNotifier::Resort()
1624 m_internal
->Resort();
1627 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1629 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1632 iter
.stamp
= wxgtk_model
->stamp
;
1633 iter
.user_data
= (gpointer
) item
.GetID();
1635 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1636 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1637 gtk_tree_model_row_changed(
1638 GTK_TREE_MODEL(wxgtk_model
), path
, &iter
);
1640 m_internal
->ItemChanged( item
);
1645 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_column
)
1647 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1648 wxDataViewCtrl
*ctrl
= m_internal
->GetOwner();
1650 // This adds GTK+'s missing MVC logic for ValueChanged
1652 for (index
= 0; index
< ctrl
->GetColumnCount(); index
++)
1654 wxDataViewColumn
*column
= ctrl
->GetColumn( index
);
1655 if (column
->GetModelColumn() == model_column
)
1657 GtkTreeView
*widget
= GTK_TREE_VIEW(ctrl
->GtkGetTreeView());
1658 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1660 // Don't attempt to refresh not yet realized tree, it is useless
1661 // and results in GTK errors.
1662 if ( gtk_widget_get_realized(ctrl
->GtkGetTreeView()) )
1666 iter
.stamp
= wxgtk_model
->stamp
;
1667 iter
.user_data
= (gpointer
) item
.GetID();
1668 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1669 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1670 GdkRectangle cell_area
;
1671 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1673 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1674 double d
= gtk_adjustment_get_value( hadjust
);
1675 int xdiff
= (int) d
;
1677 int ydiff
= gcolumn
->button
->allocation
.height
;
1679 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1680 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1683 m_internal
->ValueChanged( item
, model_column
);
1692 bool wxGtkDataViewModelNotifier::BeforeReset()
1694 GtkWidget
*treeview
= m_internal
->GetOwner()->GtkGetTreeView();
1695 gtk_tree_view_set_model( GTK_TREE_VIEW(treeview
), NULL
);
1700 bool wxGtkDataViewModelNotifier::AfterReset()
1702 GtkWidget
*treeview
= m_internal
->GetOwner()->GtkGetTreeView();
1703 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1705 m_internal
->Cleared();
1707 gtk_tree_view_set_model( GTK_TREE_VIEW(treeview
), GTK_TREE_MODEL(wxgtk_model
) );
1712 bool wxGtkDataViewModelNotifier::Cleared()
1714 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1716 // There is no call to tell the model that everything
1717 // has been deleted so call row_deleted() for every
1720 int count
= m_internal
->iter_n_children( NULL
); // number of children of root
1722 GtkTreePath
*path
= gtk_tree_path_new_first(); // points to root
1725 for (i
= 0; i
< count
; i
++)
1726 gtk_tree_model_row_deleted( GTK_TREE_MODEL(wxgtk_model
), path
);
1728 gtk_tree_path_free( path
);
1730 m_internal
->Cleared();
1735 // ---------------------------------------------------------
1736 // wxDataViewRenderer
1737 // ---------------------------------------------------------
1739 static gpointer s_user_data
= NULL
;
1742 wxgtk_cell_editable_editing_done( GtkCellEditable
*WXUNUSED(editable
),
1743 wxDataViewRenderer
*wxrenderer
)
1745 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1746 wxDataViewCtrl
*dv
= column
->GetOwner();
1747 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1748 event
.SetDataViewColumn( column
);
1749 event
.SetModel( dv
->GetModel() );
1750 wxDataViewItem
item( s_user_data
);
1751 event
.SetItem( item
);
1752 dv
->HandleWindowEvent( event
);
1756 wxgtk_renderer_editing_started( GtkCellRenderer
*WXUNUSED(cell
), GtkCellEditable
*editable
,
1757 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1762 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1763 wxDataViewCtrl
*dv
= column
->GetOwner();
1764 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1765 event
.SetDataViewColumn( column
);
1766 event
.SetModel( dv
->GetModel() );
1767 wxDataViewItem
item(dv
->GTKPathToItem(wxGtkTreePath(path
)));
1768 event
.SetItem( item
);
1769 dv
->HandleWindowEvent( event
);
1771 if (GTK_IS_CELL_EDITABLE(editable
))
1773 s_user_data
= item
.GetID();
1775 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1776 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1777 (gpointer
) wxrenderer
);
1783 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1785 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1787 wxDataViewRendererBase( varianttype
, mode
, align
)
1792 // we haven't changed them yet
1793 m_usingDefaultAttrs
= true;
1795 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1796 // after the m_renderer pointer has been initialized
1799 void wxDataViewRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
1801 gtk_tree_view_column_pack_end( column
, m_renderer
, TRUE
/* expand */);
1804 void wxDataViewRenderer::GtkInitHandlers()
1806 if (!gtk_check_version(2,6,0))
1808 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1809 G_CALLBACK (wxgtk_renderer_editing_started
),
1814 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1816 GtkCellRendererMode gtkMode
;
1819 case wxDATAVIEW_CELL_INERT
:
1820 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1823 case wxDATAVIEW_CELL_ACTIVATABLE
:
1824 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1827 case wxDATAVIEW_CELL_EDITABLE
:
1828 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1832 wxFAIL_MSG( "unknown wxDataViewCellMode value" );
1838 // This value is most often ignored in GtkTreeView
1839 GValue gvalue
= { 0, };
1840 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1841 g_value_set_enum( &gvalue
, gtkMode
);
1842 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1843 g_value_unset( &gvalue
);
1846 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1848 wxDataViewCellMode ret
;
1851 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1853 switch (g_value_get_enum(&gvalue
))
1856 wxFAIL_MSG( "unknown GtkCellRendererMode value" );
1857 // fall through (we have to return something)
1859 case GTK_CELL_RENDERER_MODE_INERT
:
1860 ret
= wxDATAVIEW_CELL_INERT
;
1863 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1864 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1867 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1868 ret
= wxDATAVIEW_CELL_EDITABLE
;
1872 g_value_unset( &gvalue
);
1877 void wxDataViewRenderer::GtkApplyAlignment(GtkCellRenderer
*renderer
)
1879 int align
= m_alignment
;
1881 // query alignment from column ?
1885 if (GetOwner() == NULL
)
1888 align
= GetOwner()->GetAlignment();
1889 align
|= wxALIGN_CENTRE_VERTICAL
;
1892 // horizontal alignment:
1894 gfloat xalign
= 0.0;
1895 if (align
& wxALIGN_RIGHT
)
1897 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1900 GValue gvalue
= { 0, };
1901 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1902 g_value_set_float( &gvalue
, xalign
);
1903 g_object_set_property( G_OBJECT(renderer
), "xalign", &gvalue
);
1904 g_value_unset( &gvalue
);
1906 // vertical alignment:
1908 gfloat yalign
= 0.0;
1909 if (align
& wxALIGN_BOTTOM
)
1911 else if (align
& wxALIGN_CENTER_VERTICAL
)
1914 GValue gvalue2
= { 0, };
1915 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1916 g_value_set_float( &gvalue2
, yalign
);
1917 g_object_set_property( G_OBJECT(renderer
), "yalign", &gvalue2
);
1918 g_value_unset( &gvalue2
);
1921 void wxDataViewRenderer::SetAlignment( int align
)
1923 m_alignment
= align
;
1924 GtkUpdateAlignment();
1927 int wxDataViewRenderer::GetAlignment() const
1932 void wxDataViewRenderer::EnableEllipsize(wxEllipsizeMode mode
)
1935 if ( gtk_check_version(2, 6, 0) != NULL
)
1938 GtkCellRendererText
* const rend
= GtkGetTextRenderer();
1942 // we use the same values in wxEllipsizeMode as PangoEllipsizeMode so we
1943 // can just cast between them
1944 GValue gvalue
= { 0, };
1945 g_value_init( &gvalue
, PANGO_TYPE_ELLIPSIZE_MODE
);
1946 g_value_set_enum( &gvalue
, static_cast<PangoEllipsizeMode
>(mode
) );
1947 g_object_set_property( G_OBJECT(rend
), "ellipsize", &gvalue
);
1948 g_value_unset( &gvalue
);
1951 #endif // GTK 2.6/before
1954 wxEllipsizeMode
wxDataViewRenderer::GetEllipsizeMode() const
1957 if ( gtk_check_version(2, 6, 0) != NULL
)
1958 return wxELLIPSIZE_NONE
;
1960 GtkCellRendererText
* const rend
= GtkGetTextRenderer();
1962 return wxELLIPSIZE_NONE
;
1964 GValue gvalue
= { 0, };
1965 g_value_init( &gvalue
, PANGO_TYPE_ELLIPSIZE_MODE
);
1966 g_object_get_property( G_OBJECT(rend
), "ellipsize", &gvalue
);
1968 mode
= static_cast<wxEllipsizeMode
>(g_value_get_enum( &gvalue
));
1969 g_value_unset( &gvalue
);
1973 return wxELLIPSIZE_NONE
;
1974 #endif // GTK 2.6/before
1978 wxDataViewRenderer::GtkOnTextEdited(const gchar
*itempath
, const wxString
& str
)
1980 wxVariant
value(str
);
1981 if (!Validate( value
))
1985 item(GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(itempath
)));
1987 GtkOnCellChanged(value
, item
, GetOwner()->GetModelColumn());
1991 wxDataViewRenderer::GtkOnCellChanged(const wxVariant
& value
,
1992 const wxDataViewItem
& item
,
1995 wxDataViewModel
*model
= GetOwner()->GetOwner()->GetModel();
1996 model
->ChangeValue( value
, item
, col
);
1999 // ---------------------------------------------------------
2000 // wxDataViewTextRenderer
2001 // ---------------------------------------------------------
2006 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*WXUNUSED(renderer
),
2007 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
2009 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) user_data
;
2011 cell
->GtkOnTextEdited(arg1
, wxGTK_CONV_BACK_FONT(
2012 arg2
, cell
->GetOwner()->GetOwner()->GetFont()));
2020 // helper function used by wxDataViewTextRenderer and
2021 // wxDataViewCustomRenderer::RenderText(): it applies the attributes to the
2022 // given text renderer and returns true if anything was done
2023 bool GtkApplyAttr(GtkCellRendererText
*renderer
, const wxDataViewItemAttr
& attr
)
2025 bool usingDefaultAttrs
= true;
2026 if (attr
.HasColour())
2028 const GdkColor
* const gcol
= attr
.GetColour().GetColor();
2030 GValue gvalue
= { 0, };
2031 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2032 g_value_set_boxed( &gvalue
, gcol
);
2033 g_object_set_property( G_OBJECT(renderer
), "foreground_gdk", &gvalue
);
2034 g_value_unset( &gvalue
);
2036 usingDefaultAttrs
= false;
2040 GValue gvalue
= { 0, };
2041 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2042 g_value_set_boolean( &gvalue
, FALSE
);
2043 g_object_set_property( G_OBJECT(renderer
), "foreground-set", &gvalue
);
2044 g_value_unset( &gvalue
);
2047 if (attr
.GetItalic())
2049 GValue gvalue
= { 0, };
2050 g_value_init( &gvalue
, PANGO_TYPE_STYLE
);
2051 g_value_set_enum( &gvalue
, PANGO_STYLE_ITALIC
);
2052 g_object_set_property( G_OBJECT(renderer
), "style", &gvalue
);
2053 g_value_unset( &gvalue
);
2055 usingDefaultAttrs
= false;
2059 GValue gvalue
= { 0, };
2060 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2061 g_value_set_boolean( &gvalue
, FALSE
);
2062 g_object_set_property( G_OBJECT(renderer
), "style-set", &gvalue
);
2063 g_value_unset( &gvalue
);
2069 GValue gvalue
= { 0, };
2070 g_value_init( &gvalue
, PANGO_TYPE_WEIGHT
);
2071 g_value_set_enum( &gvalue
, PANGO_WEIGHT_BOLD
);
2072 g_object_set_property( G_OBJECT(renderer
), "weight", &gvalue
);
2073 g_value_unset( &gvalue
);
2075 usingDefaultAttrs
= false;
2079 GValue gvalue
= { 0, };
2080 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2081 g_value_set_boolean( &gvalue
, FALSE
);
2082 g_object_set_property( G_OBJECT(renderer
), "weight-set", &gvalue
);
2083 g_value_unset( &gvalue
);
2087 if (attr
.HasBackgroundColour())
2089 wxColour colour
= attr
.GetBackgroundColour();
2090 const GdkColor
* const gcol
= colour
.GetColor();
2092 GValue gvalue
= { 0, };
2093 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2094 g_value_set_boxed( &gvalue
, gcol
);
2095 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
2096 g_value_unset( &gvalue
);
2100 GValue gvalue
= { 0, };
2101 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2102 g_value_set_boolean( &gvalue
, FALSE
);
2103 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
2104 g_value_unset( &gvalue
);
2108 return !usingDefaultAttrs
;
2111 } // anonymous namespace
2113 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
2115 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
2117 wxDataViewRenderer( varianttype
, mode
, align
)
2119 GtkWxCellRendererText
*text_renderer
= gtk_wx_cell_renderer_text_new();
2120 text_renderer
->wx_renderer
= this;
2121 m_renderer
= (GtkCellRenderer
*) text_renderer
;
2123 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
2125 GValue gvalue
= { 0, };
2126 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2127 g_value_set_boolean( &gvalue
, true );
2128 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
2129 g_value_unset( &gvalue
);
2131 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2137 SetAlignment(align
);
2140 bool wxDataViewTextRenderer::SetTextValue(const wxString
& str
)
2142 GValue gvalue
= { 0, };
2143 g_value_init( &gvalue
, G_TYPE_STRING
);
2144 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( str
, GetOwner()->GetOwner()->GetFont() ) );
2145 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2146 g_value_unset( &gvalue
);
2151 bool wxDataViewTextRenderer::GetTextValue(wxString
& str
) const
2153 GValue gvalue
= { 0, };
2154 g_value_init( &gvalue
, G_TYPE_STRING
);
2155 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2156 str
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
), const_cast<wxDataViewTextRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
2157 g_value_unset( &gvalue
);
2162 void wxDataViewTextRenderer::SetAlignment( int align
)
2164 wxDataViewRenderer::SetAlignment(align
);
2166 if (gtk_check_version(2,10,0))
2169 // horizontal alignment:
2170 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2171 if (align
& wxALIGN_RIGHT
)
2172 pangoAlign
= PANGO_ALIGN_RIGHT
;
2173 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2174 pangoAlign
= PANGO_ALIGN_CENTER
;
2176 GValue gvalue
= { 0, };
2177 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2178 g_value_set_enum( &gvalue
, pangoAlign
);
2179 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2180 g_value_unset( &gvalue
);
2183 bool wxDataViewTextRenderer::GtkSetAttr(const wxDataViewItemAttr
& attr
)
2185 return GtkApplyAttr(GtkGetTextRenderer(), attr
);
2188 GtkCellRendererText
*wxDataViewTextRenderer::GtkGetTextRenderer() const
2190 return GTK_CELL_RENDERER_TEXT(m_renderer
);
2193 // ---------------------------------------------------------
2194 // wxDataViewBitmapRenderer
2195 // ---------------------------------------------------------
2200 // set "pixbuf" property on the given renderer
2201 void SetPixbufProp(GtkCellRenderer
*renderer
, GdkPixbuf
*pixbuf
)
2203 GValue gvalue
= { 0, };
2204 g_value_init( &gvalue
, G_TYPE_OBJECT
);
2205 g_value_set_object( &gvalue
, pixbuf
);
2206 g_object_set_property( G_OBJECT(renderer
), "pixbuf", &gvalue
);
2207 g_value_unset( &gvalue
);
2210 } // anonymous namespace
2212 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
2214 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
2216 wxDataViewRenderer( varianttype
, mode
, align
)
2218 m_renderer
= gtk_cell_renderer_pixbuf_new();
2221 SetAlignment(align
);
2224 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
2226 if (value
.GetType() == wxT("wxBitmap"))
2231 // GetPixbuf() may create a Pixbuf representation in the wxBitmap
2232 // object (and it will stay there and remain owned by wxBitmap)
2233 SetPixbufProp(m_renderer
, bitmap
.GetPixbuf());
2235 else if (value
.GetType() == wxT("wxIcon"))
2240 SetPixbufProp(m_renderer
, icon
.GetPixbuf());
2250 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2255 // ---------------------------------------------------------
2256 // wxDataViewToggleRenderer
2257 // ---------------------------------------------------------
2260 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
2261 gchar
*path
, gpointer user_data
);
2264 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
2265 gchar
*path
, gpointer user_data
)
2267 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
2270 GValue gvalue
= { 0, };
2271 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2272 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
2273 bool tmp
= g_value_get_boolean( &gvalue
);
2274 g_value_unset( &gvalue
);
2278 wxVariant value
= tmp
;
2279 if (!cell
->Validate( value
))
2282 wxDataViewCtrl
* const ctrl
= cell
->GetOwner()->GetOwner();
2283 wxDataViewModel
*model
= ctrl
->GetModel();
2285 wxDataViewItem
item(ctrl
->GTKPathToItem(wxGtkTreePath(path
)));
2287 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
2289 model
->ChangeValue( value
, item
, model_col
);
2292 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
2294 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
2295 wxDataViewCellMode mode
, int align
) :
2296 wxDataViewRenderer( varianttype
, mode
, align
)
2298 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
2300 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
2302 g_signal_connect_after( m_renderer
, "toggled",
2303 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
2307 GValue gvalue
= { 0, };
2308 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2309 g_value_set_boolean( &gvalue
, false );
2310 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
2311 g_value_unset( &gvalue
);
2315 SetAlignment(align
);
2318 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
2322 GValue gvalue
= { 0, };
2323 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2324 g_value_set_boolean( &gvalue
, tmp
);
2325 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
2326 g_value_unset( &gvalue
);
2331 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
2333 GValue gvalue
= { 0, };
2334 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2335 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
2336 bool tmp
= g_value_get_boolean( &gvalue
);
2337 g_value_unset( &gvalue
);
2344 // ---------------------------------------------------------
2345 // wxDataViewCustomRenderer
2346 // ---------------------------------------------------------
2348 class wxDataViewCtrlDCImpl
: public wxWindowDCImpl
2351 wxDataViewCtrlDCImpl( wxDC
*owner
, wxDataViewCtrl
*window
) :
2352 wxWindowDCImpl( owner
)
2354 GtkWidget
*widget
= window
->m_treeview
;
2360 m_context
= window
->GTKGetPangoDefaultContext();
2361 m_layout
= pango_layout_new( m_context
);
2362 m_fontdesc
= pango_font_description_copy(gtk_widget_get_style(widget
)->font_desc
);
2364 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
2366 // Set m_gdkwindow later
2371 class wxDataViewCtrlDC
: public wxWindowDC
2374 wxDataViewCtrlDC( wxDataViewCtrl
*window
) :
2375 wxWindowDC( new wxDataViewCtrlDCImpl( this, window
) )
2380 // ---------------------------------------------------------
2381 // wxDataViewCustomRenderer
2382 // ---------------------------------------------------------
2384 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
2386 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
2387 wxDataViewCellMode mode
,
2390 : wxDataViewCustomRendererBase( varianttype
, mode
, align
)
2393 m_text_renderer
= NULL
;
2401 void wxDataViewCustomRenderer::GtkInitTextRenderer()
2403 m_text_renderer
= GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new());
2404 g_object_ref_sink(m_text_renderer
);
2406 GtkApplyAlignment(GTK_CELL_RENDERER(m_text_renderer
));
2409 GtkCellRendererText
*wxDataViewCustomRenderer::GtkGetTextRenderer() const
2411 if ( !m_text_renderer
)
2413 // we create it on demand so need to do it even from a const function
2414 const_cast<wxDataViewCustomRenderer
*>(this)->GtkInitTextRenderer();
2417 return m_text_renderer
;
2420 void wxDataViewCustomRenderer::RenderText( const wxString
&text
,
2424 int WXUNUSED(state
) )
2427 GtkCellRendererText
* const textRenderer
= GtkGetTextRenderer();
2429 GValue gvalue
= { 0, };
2430 g_value_init( &gvalue
, G_TYPE_STRING
);
2431 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( text
, GetOwner()->GetOwner()->GetFont() ) );
2432 g_object_set_property( G_OBJECT(textRenderer
), "text", &gvalue
);
2433 g_value_unset( &gvalue
);
2435 GtkApplyAttr(textRenderer
, GetAttr());
2437 GdkRectangle cell_area
;
2438 wxRectToGDKRect(cell
, cell_area
);
2439 cell_area
.x
+= xoffset
;
2440 cell_area
.width
-= xoffset
;
2442 gtk_cell_renderer_render( GTK_CELL_RENDERER(textRenderer
),
2443 m_renderParams
.window
,
2444 m_renderParams
.widget
,
2445 m_renderParams
.background_area
,
2447 m_renderParams
.expose_area
,
2448 (GtkCellRendererState
) m_renderParams
.flags
);
2451 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
2453 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
2454 renderer
->cell
= this;
2456 m_renderer
= (GtkCellRenderer
*) renderer
;
2459 SetAlignment(align
);
2466 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
2471 if (m_text_renderer
)
2472 g_object_unref(m_text_renderer
);
2475 wxDC
*wxDataViewCustomRenderer::GetDC()
2479 if (GetOwner() == NULL
)
2481 if (GetOwner()->GetOwner() == NULL
)
2483 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
2489 // ---------------------------------------------------------
2490 // wxDataViewProgressRenderer
2491 // ---------------------------------------------------------
2493 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
2495 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
2496 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
2497 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
2503 if (!gtk_check_version(2,6,0))
2505 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
2508 SetAlignment(align
);
2511 // We can't initialize the renderer just yet because we don't have the
2512 // pointer to the column that uses this renderer yet and so attempt to
2513 // dereference GetOwner() to get the font that is used as a source of
2514 // encoding in multibyte-to-Unicode conversion in GTKSetLabel() in
2515 // non-Unicode builds would crash. So simply remember to do it later.
2516 if ( !m_label
.empty() )
2517 m_needsToSetLabel
= true;
2519 #endif // !wxUSE_UNICODE
2525 // Use custom cell code
2526 wxDataViewCustomRenderer::Init(mode
, align
);
2530 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
2534 void wxDataViewProgressRenderer::GTKSetLabel()
2536 GValue gvalue
= { 0, };
2537 g_value_init( &gvalue
, G_TYPE_STRING
);
2539 // Take care to not use GetOwner() here if the label is empty, we can be
2540 // called from ctor when GetOwner() is still NULL in this case.
2541 g_value_set_string( &gvalue
,
2542 m_label
.empty() ? ""
2543 : wxGTK_CONV_FONT(m_label
,
2544 GetOwner()->GetOwner()->GetFont())
2546 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2547 g_value_unset( &gvalue
);
2550 m_needsToSetLabel
= false;
2551 #endif // !wxUSE_UNICODE
2554 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
2557 if (!gtk_check_version(2,6,0))
2560 if ( m_needsToSetLabel
)
2562 #endif // !wxUSE_UNICODE
2564 gint tmp
= (long) value
;
2565 GValue gvalue
= { 0, };
2566 g_value_init( &gvalue
, G_TYPE_INT
);
2567 g_value_set_int( &gvalue
, tmp
);
2568 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
2569 g_value_unset( &gvalue
);
2574 m_value
= (long) value
;
2576 if (m_value
< 0) m_value
= 0;
2577 if (m_value
> 100) m_value
= 100;
2583 bool wxDataViewProgressRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2588 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
2590 double pct
= (double)m_value
/ 100.0;
2592 bar
.width
= (int)(cell
.width
* pct
);
2593 dc
->SetPen( *wxTRANSPARENT_PEN
);
2594 dc
->SetBrush( *wxBLUE_BRUSH
);
2595 dc
->DrawRectangle( bar
);
2597 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
2598 dc
->SetPen( *wxBLACK_PEN
);
2599 dc
->DrawRectangle( cell
);
2604 wxSize
wxDataViewProgressRenderer::GetSize() const
2606 return wxSize(40,12);
2609 // -------------------------------------
2610 // wxDataViewChoiceRenderer
2611 // -------------------------------------
2613 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
&choices
,
2614 wxDataViewCellMode mode
, int alignment
) :
2615 wxDataViewCustomRenderer( "string", mode
, alignment
, true )
2617 m_choices
= choices
;
2620 if (!gtk_check_version(2,6,0))
2622 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_combo_new();
2624 GtkListStore
*store
= gtk_list_store_new( 1, G_TYPE_STRING
);
2625 for (size_t n
= 0; n
< m_choices
.GetCount(); n
++)
2627 gtk_list_store_insert_with_values(
2629 static_cast<const char *>(m_choices
[n
].utf8_str()), -1 );
2632 g_object_set (m_renderer
,
2638 bool editable
= (mode
& wxDATAVIEW_CELL_EDITABLE
);
2639 g_object_set (m_renderer
, "editable", editable
, NULL
);
2641 SetAlignment(alignment
);
2643 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2650 // Use custom cell code
2651 wxDataViewCustomRenderer::Init(mode
, alignment
);
2655 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
2657 RenderText( m_data
, 0, rect
, dc
, state
);
2661 wxSize
wxDataViewChoiceRenderer::GetSize() const
2663 return wxSize(70,20);
2666 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
2670 if (!gtk_check_version(2,6,0))
2672 GValue gvalue
= { 0, };
2673 g_value_init( &gvalue
, G_TYPE_STRING
);
2674 g_value_set_string(&gvalue
,
2675 wxGTK_CONV_FONT(value
.GetString(),
2676 GetOwner()->GetOwner()->GetFont()));
2677 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2678 g_value_unset( &gvalue
);
2682 m_data
= value
.GetString();
2687 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
2690 if (!gtk_check_version(2,6,0))
2692 GValue gvalue
= { 0, };
2693 g_value_init( &gvalue
, G_TYPE_STRING
);
2694 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2695 wxString temp
= wxGTK_CONV_BACK_FONT(g_value_get_string(&gvalue
),
2696 GetOwner()->GetOwner()->GetFont());
2697 g_value_unset( &gvalue
);
2700 //wxPrintf( "temp %s\n", temp );
2701 // TODO: remove this code
2710 void wxDataViewChoiceRenderer::SetAlignment( int align
)
2712 wxDataViewCustomRenderer::SetAlignment(align
);
2714 if (gtk_check_version(2,10,0))
2717 // horizontal alignment:
2718 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2719 if (align
& wxALIGN_RIGHT
)
2720 pangoAlign
= PANGO_ALIGN_RIGHT
;
2721 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2722 pangoAlign
= PANGO_ALIGN_CENTER
;
2724 GValue gvalue
= { 0, };
2725 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2726 g_value_set_enum( &gvalue
, pangoAlign
);
2727 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2728 g_value_unset( &gvalue
);
2731 // ----------------------------------------------------------------------------
2732 // wxDataViewChoiceByIndexRenderer
2733 // ----------------------------------------------------------------------------
2735 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
2736 wxDataViewCellMode mode
, int alignment
) :
2737 wxDataViewChoiceRenderer( choices
, mode
, alignment
)
2741 void wxDataViewChoiceByIndexRenderer::GtkOnTextEdited(const gchar
*itempath
, const wxString
& str
)
2743 wxVariant
value( (long) GetChoices().Index( str
) );
2745 if (!Validate( value
))
2749 item(GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(itempath
)));
2751 GtkOnCellChanged(value
, item
, GetOwner()->GetModelColumn());
2754 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant
&value
)
2756 wxVariant string_value
= GetChoice( value
.GetLong() );
2757 return wxDataViewChoiceRenderer::SetValue( string_value
);
2760 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant
&value
) const
2762 wxVariant string_value
;
2763 if (!wxDataViewChoiceRenderer::GetValue( string_value
))
2766 value
= (long) GetChoices().Index( string_value
.GetString() );
2770 // ---------------------------------------------------------
2771 // wxDataViewDateRenderer
2772 // ---------------------------------------------------------
2774 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
2777 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
2778 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
2779 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
2784 m_cal
= new wxCalendarCtrl( this, -1, *value
);
2785 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
2786 sizer
->Add( m_cal
, 1, wxGROW
);
2791 virtual void OnDismiss()
2795 void OnCalendar( wxCalendarEvent
&event
);
2797 wxCalendarCtrl
*m_cal
;
2798 wxDataViewModel
*m_model
;
2799 wxDataViewItem m_item
;
2803 DECLARE_EVENT_TABLE()
2806 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
2807 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
2810 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
2812 m_model
->ChangeValue( event
.GetDate(), m_item
, m_col
);
2816 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
2818 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
2819 wxDataViewCellMode mode
, int align
) :
2820 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2823 SetAlignment(align
);
2826 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
2828 m_date
= value
.GetDateTime();
2833 bool wxDataViewDateRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2838 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2840 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
2841 wxString tmp
= m_date
.FormatDate();
2842 RenderText( tmp
, 0, cell
, dc
, state
);
2846 wxSize
wxDataViewDateRenderer::GetSize() const
2848 wxString tmp
= m_date
.FormatDate();
2850 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
2851 return wxSize(x
,y
+d
);
2854 bool wxDataViewDateRenderer::Activate( const wxRect
& WXUNUSED(cell
), wxDataViewModel
*model
,
2855 const wxDataViewItem
&item
, unsigned int col
)
2858 model
->GetValue( variant
, item
, col
);
2859 wxDateTime value
= variant
.GetDateTime();
2861 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
2862 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
2863 wxPoint pos
= wxGetMousePosition();
2866 popup
->Popup( popup
->m_cal
);
2872 // ---------------------------------------------------------
2873 // wxDataViewIconTextRenderer
2874 // ---------------------------------------------------------
2876 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
2878 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer
2880 const wxString
&varianttype
,
2881 wxDataViewCellMode mode
,
2884 : wxDataViewTextRenderer(varianttype
, mode
, align
)
2886 m_rendererIcon
= gtk_cell_renderer_pixbuf_new();
2889 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2893 void wxDataViewIconTextRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
2895 // add the icon renderer first
2896 gtk_tree_view_column_pack_start(column
, m_rendererIcon
, FALSE
/* !expand */);
2898 // add the text renderer too
2899 wxDataViewRenderer::GtkPackIntoColumn(column
);
2902 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
2906 SetTextValue(m_value
.GetText());
2907 SetPixbufProp(m_rendererIcon
, m_value
.GetIcon().GetPixbuf());
2912 bool wxDataViewIconTextRenderer::GetValue(wxVariant
& value
) const
2915 if ( !GetTextValue(str
) )
2918 // user doesn't have any way to edit the icon so leave it unchanged
2919 value
<< wxDataViewIconText(str
, m_value
.GetIcon());
2925 wxDataViewIconTextRenderer::GtkOnCellChanged(const wxVariant
& value
,
2926 const wxDataViewItem
& item
,
2929 // we receive just the text part of our value as it's the only one which
2930 // can be edited, but we need the full wxDataViewIconText value for the
2932 wxVariant valueIconText
;
2933 valueIconText
<< wxDataViewIconText(value
.GetString(), m_value
.GetIcon());
2934 wxDataViewTextRenderer::GtkOnCellChanged(valueIconText
, item
, col
);
2937 // ---------------------------------------------------------
2939 // ---------------------------------------------------------
2943 gtk_dataview_header_button_press_callback( GtkWidget
*WXUNUSED(widget
),
2944 GdkEventButton
*gdk_event
,
2945 wxDataViewColumn
*column
)
2947 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
2950 if (gdk_event
->button
== 1)
2952 gs_lastLeftClickHeader
= column
;
2954 wxDataViewCtrl
*dv
= column
->GetOwner();
2955 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
2956 event
.SetDataViewColumn( column
);
2957 event
.SetModel( dv
->GetModel() );
2958 if (dv
->HandleWindowEvent( event
))
2962 if (gdk_event
->button
== 3)
2964 wxDataViewCtrl
*dv
= column
->GetOwner();
2965 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
2966 event
.SetDataViewColumn( column
);
2967 event
.SetModel( dv
->GetModel() );
2968 if (dv
->HandleWindowEvent( event
))
2978 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*WXUNUSED(column
),
2979 GtkCellRenderer
*renderer
,
2980 GtkTreeModel
*model
,
2984 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2985 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2987 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2989 wxDataViewItem
item( (void*) iter
->user_data
);
2991 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
2993 if (!wx_model
->IsVirtualListModel())
2996 if (wx_model
->IsContainer( item
))
2998 visible
= wx_model
->HasContainerColumns( item
) ||
2999 (cell
->GetOwner()->GetModelColumn() == 0);
3006 GValue gvalue
= { 0, };
3007 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
3008 g_value_set_boolean( &gvalue
, visible
);
3009 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
3010 g_value_unset( &gvalue
);
3017 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
3019 if (value
.GetType() != cell
->GetVariantType())
3021 wxLogError( wxT("Wrong type, required: %s but: %s"),
3022 value
.GetType().c_str(),
3023 cell
->GetVariantType().c_str() );
3026 cell
->SetValue( value
);
3028 // deal with disabled items
3029 bool enabled
= wx_model
->IsEnabled( item
, cell
->GetOwner()->GetModelColumn() );
3031 // a) this sets the appearance to disabled grey
3032 GValue gvalue
= { 0, };
3033 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
3034 g_value_set_boolean( &gvalue
, enabled
);
3035 g_object_set_property( G_OBJECT(renderer
), "sensitive", &gvalue
);
3036 g_value_unset( &gvalue
);
3038 // b) this actually disables the control/renderer
3040 cell
->SetMode( cell
->GtkGetMode() );
3042 cell
->SetMode( wxDATAVIEW_CELL_INERT
);
3045 // deal with attributes: if the renderer doesn't support them at all, we
3046 // don't even need to query the model for them
3047 if ( !cell
->GtkSupportsAttrs() )
3050 // it can support attributes so check if this item has any
3051 wxDataViewItemAttr attr
;
3052 if ( wx_model
->GetAttr( item
, cell
->GetOwner()->GetModelColumn(), attr
)
3053 || !cell
->GtkIsUsingDefaultAttrs() )
3055 bool usingDefaultAttrs
= !cell
->GtkSetAttr(attr
);
3056 cell
->GtkSetUsingDefaultAttrs(usingDefaultAttrs
);
3058 // else: no custom attributes specified and we're already using the default
3059 // ones -- nothing to do
3065 #include <wx/listimpl.cpp>
3066 WX_DEFINE_LIST(wxDataViewColumnList
)
3068 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
3069 unsigned int model_column
, int width
,
3070 wxAlignment align
, int flags
)
3071 : wxDataViewColumnBase( cell
, model_column
)
3073 Init( align
, flags
, width
);
3078 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
3079 unsigned int model_column
, int width
,
3080 wxAlignment align
, int flags
)
3081 : wxDataViewColumnBase( bitmap
, cell
, model_column
)
3083 Init( align
, flags
, width
);
3085 SetBitmap( bitmap
);
3088 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
3090 m_isConnected
= false;
3092 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
3093 m_column
= (GtkWidget
*) column
;
3096 SetAlignment( align
);
3100 // Create container for icon and label
3101 GtkWidget
*box
= gtk_hbox_new( FALSE
, 1 );
3102 gtk_widget_show( box
);
3103 // gtk_container_set_border_width((GtkContainer*)box, 2);
3104 m_image
= gtk_image_new();
3105 gtk_box_pack_start(GTK_BOX(box
), m_image
, FALSE
, FALSE
, 1);
3106 m_label
= gtk_label_new("");
3107 gtk_box_pack_end( GTK_BOX(box
), GTK_WIDGET(m_label
), FALSE
, FALSE
, 1 );
3108 gtk_tree_view_column_set_widget( column
, box
);
3110 wxDataViewRenderer
* const colRenderer
= GetRenderer();
3111 GtkCellRenderer
* const cellRenderer
= colRenderer
->GetGtkHandle();
3113 colRenderer
->GtkPackIntoColumn(column
);
3115 gtk_tree_view_column_set_cell_data_func( column
, cellRenderer
,
3116 wxGtkTreeCellDataFunc
, (gpointer
) colRenderer
, NULL
);
3119 void wxDataViewColumn::OnInternalIdle()
3124 if (gtk_widget_get_realized(GetOwner()->m_treeview
))
3126 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3129 g_signal_connect(column
->button
, "button_press_event",
3130 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
3132 // otherwise the event will be blocked by GTK+
3133 gtk_tree_view_column_set_clickable( column
, TRUE
);
3135 m_isConnected
= true;
3140 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
3142 wxDataViewColumnBase::SetOwner( owner
);
3144 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3146 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
3149 void wxDataViewColumn::SetTitle( const wxString
&title
)
3151 wxDataViewCtrl
*ctrl
= GetOwner();
3152 gtk_label_set_text( GTK_LABEL(m_label
), ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
3153 : wxGTK_CONV_SYS(title
) );
3155 gtk_widget_hide( m_label
);
3157 gtk_widget_show( m_label
);
3160 wxString
wxDataViewColumn::GetTitle() const
3162 return wxGTK_CONV_BACK_FONT(
3163 gtk_label_get_text( GTK_LABEL(m_label
) ),
3164 GetOwner()->GetFont()
3168 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
3170 wxDataViewColumnBase::SetBitmap( bitmap
);
3174 GtkImage
*gtk_image
= GTK_IMAGE(m_image
);
3176 GdkBitmap
*mask
= NULL
;
3177 if (bitmap
.GetMask())
3178 mask
= bitmap
.GetMask()->GetBitmap();
3180 if (bitmap
.HasPixbuf())
3182 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
3183 bitmap
.GetPixbuf());
3187 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
3188 bitmap
.GetPixmap(), mask
);
3190 gtk_widget_show( m_image
);
3194 gtk_widget_hide( m_image
);
3198 void wxDataViewColumn::SetHidden( bool hidden
)
3200 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
3203 void wxDataViewColumn::SetResizeable( bool resizable
)
3205 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizable
);
3208 void wxDataViewColumn::SetAlignment( wxAlignment align
)
3210 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3212 gfloat xalign
= 0.0;
3213 if (align
== wxALIGN_RIGHT
)
3215 if (align
== wxALIGN_CENTER_HORIZONTAL
||
3216 align
== wxALIGN_CENTER
)
3219 gtk_tree_view_column_set_alignment( column
, xalign
);
3221 if (m_renderer
&& m_renderer
->GetAlignment() == -1)
3222 m_renderer
->GtkUpdateAlignment();
3225 wxAlignment
wxDataViewColumn::GetAlignment() const
3227 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
3230 return wxALIGN_RIGHT
;
3232 return wxALIGN_CENTER_HORIZONTAL
;
3234 return wxALIGN_LEFT
;
3237 void wxDataViewColumn::SetSortable( bool sortable
)
3239 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3243 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
3247 gtk_tree_view_column_set_sort_column_id( column
, -1 );
3248 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
3249 gtk_tree_view_column_set_clickable( column
, FALSE
);
3253 bool wxDataViewColumn::IsSortable() const
3255 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3256 return gtk_tree_view_column_get_clickable( column
);
3259 void wxDataViewColumn::SetAsSortKey( bool WXUNUSED(sort
) )
3261 // it might not make sense to have this function in wxHeaderColumn at
3262 // all in fact, changing of the sort order should only be done using the
3263 // associated control API
3264 wxFAIL_MSG( "not implemented" );
3267 bool wxDataViewColumn::IsSortKey() const
3269 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3270 return gtk_tree_view_column_get_sort_indicator( column
);
3273 bool wxDataViewColumn::IsResizeable() const
3275 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3276 return gtk_tree_view_column_get_resizable( column
);
3279 bool wxDataViewColumn::IsHidden() const
3281 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3282 return !gtk_tree_view_column_get_visible( column
);
3285 void wxDataViewColumn::SetSortOrder( bool ascending
)
3287 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3290 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
3292 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
3294 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
3297 bool wxDataViewColumn::IsSortOrderAscending() const
3299 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3301 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
3304 void wxDataViewColumn::SetMinWidth( int width
)
3306 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
3309 int wxDataViewColumn::GetMinWidth() const
3311 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
3314 int wxDataViewColumn::GetWidth() const
3316 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
3319 void wxDataViewColumn::SetWidth( int width
)
3321 if ( width
== wxCOL_WIDTH_AUTOSIZE
)
3323 // NB: this disables user resizing
3324 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
3328 if ( width
== wxCOL_WIDTH_DEFAULT
)
3330 // TODO find a better calculation
3331 width
= wxDVC_DEFAULT_WIDTH
;
3334 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
3335 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
3339 void wxDataViewColumn::SetReorderable( bool reorderable
)
3341 gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column
), reorderable
);
3344 bool wxDataViewColumn::IsReorderable() const
3346 return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column
) );
3349 //-----------------------------------------------------------------------------
3350 // wxGtkTreeModelNode
3351 //-----------------------------------------------------------------------------
3354 class wxGtkTreeModelChildWithPos
3362 int wxGtkTreeModelChildWithPosCmp( const void* data1
, const void* data2
, const void* user_data
)
3364 const wxGtkTreeModelChildWithPos
* child1
= (const wxGtkTreeModelChildWithPos
*) data1
;
3365 const wxGtkTreeModelChildWithPos
* child2
= (const wxGtkTreeModelChildWithPos
*) data2
;
3366 const wxDataViewCtrlInternal
*internal
= (const wxDataViewCtrlInternal
*) user_data
;
3367 int ret
= internal
->GetDataViewModel()->Compare( child1
->id
, child2
->id
,
3368 internal
->GetSortColumn(), (internal
->GetSortOrder() == GTK_SORT_DESCENDING
) );
3374 int LINKAGEMODE
wxGtkTreeModelChildPtrCmp( void*** data1
, void*** data2
)
3376 return gs_internal
->GetDataViewModel()->Compare( wxDataViewItem(**data1
), wxDataViewItem(**data2
),
3377 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
3380 WX_DEFINE_ARRAY_PTR( void**, wxGtkTreeModelChildrenPtr
);
3383 void wxGtkTreeModelNode::Resort()
3385 size_t child_count
= GetChildCount();
3386 if (child_count
== 0)
3389 size_t node_count
= GetNodesCount();
3391 if (child_count
== 1)
3393 if (node_count
== 1)
3395 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
3401 gint
*new_order
= new gint
[child_count
];
3404 // m_children has the original *void
3405 // ptrs points to these
3406 wxGtkTreeModelChildrenPtr ptrs
;
3408 for (i
= 0; i
< child_count
; i
++)
3409 ptrs
.Add( &(m_children
[i
]) );
3411 gs_internal
= m_internal
;
3412 ptrs
.Sort( &wxGtkTreeModelChildPtrCmp
);
3414 wxGtkTreeModelChildren temp
;
3415 void** base_ptr
= &(m_children
[0]);
3416 // Transfer positions to new_order array and
3418 for (i
= 0; i
< child_count
; i
++)
3420 new_order
[i
] = ptrs
[i
] - base_ptr
;
3421 temp
.Add( *ptrs
[i
] );
3424 // Transfer IDs back to m_children
3426 WX_APPEND_ARRAY( temp
, m_children
);
3431 // Build up array with IDs and original positions
3432 wxGtkTreeModelChildWithPos
* temp
= new wxGtkTreeModelChildWithPos
[child_count
];
3434 for (i
= 0; i
< child_count
; i
++)
3437 temp
[i
].id
= m_children
[i
];
3439 // Sort array keeping original positions
3440 wxQsort( temp
, child_count
, sizeof(wxGtkTreeModelChildWithPos
),
3441 &wxGtkTreeModelChildWithPosCmp
, m_internal
);
3442 // Transfer positions to new_order array and
3443 // IDs to m_children
3445 for (i
= 0; i
< child_count
; i
++)
3447 new_order
[i
] = temp
[i
].pos
;
3448 m_children
.Add( temp
[i
].id
);
3457 wxGtkTreeModelChildren temp
;
3458 WX_APPEND_ARRAY( temp
, m_children
);
3460 gs_internal
= m_internal
;
3461 m_children
.Sort( &wxGtkTreeModelChildCmp
);
3464 for (pos
= 0; pos
< child_count
; pos
++)
3466 void *id
= m_children
.Item( pos
);
3467 int old_pos
= temp
.Index( id
);
3468 new_order
[pos
] = old_pos
;
3472 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
3475 iter
.user_data
= GetItem().GetID();
3476 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
3478 gtk_tree_model_rows_reordered( gtk_tree_model
,
3479 wxGtkTreePath(m_internal
->get_path(&iter
)), &iter
, new_order
);
3481 delete [] new_order
;
3484 for (pos
= 0; pos
< node_count
; pos
++)
3486 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
3491 //-----------------------------------------------------------------------------
3492 // wxDataViewCtrlInternal
3493 //-----------------------------------------------------------------------------
3495 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
)
3498 m_wx_model
= wx_model
;
3502 m_sort_order
= GTK_SORT_ASCENDING
;
3504 m_dataview_sort_column
= NULL
;
3506 m_dragDataObject
= NULL
;
3507 m_dropDataObject
= NULL
;
3511 m_gtk_model
= wxgtk_tree_model_new();
3512 m_gtk_model
->internal
= this;
3514 m_notifier
= new wxGtkDataViewModelNotifier( wx_model
, this );
3516 wx_model
->AddNotifier( m_notifier
);
3518 // g_object_unref( gtk_model ); ???
3520 if (!m_wx_model
->IsVirtualListModel())
3523 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->GtkGetTreeView()), GTK_TREE_MODEL(m_gtk_model
) );
3526 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
3528 m_wx_model
->RemoveNotifier( m_notifier
);
3530 // remove the model from the GtkTreeView before it gets destroyed
3531 gtk_tree_view_set_model( GTK_TREE_VIEW( m_owner
->GtkGetTreeView() ), NULL
);
3533 g_object_unref( m_gtk_model
);
3535 delete m_dragDataObject
;
3536 delete m_dropDataObject
;
3539 void wxDataViewCtrlInternal::ScheduleRefresh()
3544 void wxDataViewCtrlInternal::OnInternalIdle()
3548 GtkWidget
*widget
= m_owner
->GtkGetTreeView();
3549 gtk_widget_queue_draw( widget
);
3554 void wxDataViewCtrlInternal::InitTree()
3556 wxDataViewItem item
;
3557 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
3559 BuildBranch( m_root
);
3562 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
3564 if (node
->GetChildCount() == 0)
3566 wxDataViewItemArray children
;
3567 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
3570 for (pos
= 0; pos
< count
; pos
++)
3572 wxDataViewItem child
= children
[pos
];
3574 if (m_wx_model
->IsContainer( child
))
3575 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
3577 node
->AddLeave( child
.GetID() );
3579 // Don't send any events here
3586 bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat
&format
)
3588 wxGtkString
atom_str( gdk_atom_name( format
) );
3589 m_dragSourceTargetEntryTarget
= wxCharBuffer( atom_str
);
3591 m_dragSourceTargetEntry
.target
= m_dragSourceTargetEntryTarget
.data();
3592 m_dragSourceTargetEntry
.flags
= 0;
3593 m_dragSourceTargetEntry
.info
= static_cast<guint
>(-1);
3595 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3596 GDK_BUTTON1_MASK
, &m_dragSourceTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3601 bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat
&format
)
3603 wxGtkString
atom_str( gdk_atom_name( format
) );
3604 m_dropTargetTargetEntryTarget
= wxCharBuffer( atom_str
);
3606 m_dropTargetTargetEntry
.target
= m_dropTargetTargetEntryTarget
.data();
3607 m_dropTargetTargetEntry
.flags
= 0;
3608 m_dropTargetTargetEntry
.info
= static_cast<guint
>(-1);
3610 gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3611 &m_dropTargetTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3616 gboolean
wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource
*WXUNUSED(drag_source
),
3619 delete m_dragDataObject
;
3620 m_dragDataObject
= NULL
;
3622 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3626 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3627 event
.SetEventObject( m_owner
);
3628 event
.SetItem( item
);
3629 event
.SetModel( m_wx_model
);
3631 gtk_widget_get_pointer(m_owner
->GtkGetTreeView(), &x
, &y
);
3632 event
.SetPosition(x
, y
);
3633 if (!m_owner
->HandleWindowEvent( event
))
3636 if (!event
.IsAllowed())
3639 wxDataObject
*obj
= event
.GetDataObject();
3643 m_dragDataObject
= obj
;
3649 wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource
*WXUNUSED(drag_source
),
3650 GtkTreePath
*WXUNUSED(path
))
3655 gboolean
wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource
*WXUNUSED(drag_source
),
3656 GtkTreePath
*path
, GtkSelectionData
*selection_data
)
3658 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3662 GdkAtom target
= gtk_selection_data_get_target(selection_data
);
3663 if (!m_dragDataObject
->IsSupported(target
))
3666 size_t size
= m_dragDataObject
->GetDataSize(target
);
3670 void *buf
= malloc( size
);
3672 gboolean res
= FALSE
;
3673 if (m_dragDataObject
->GetDataHere(target
, buf
))
3677 gtk_selection_data_set(selection_data
, target
,
3678 8, (const guchar
*) buf
, size
);
3687 wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3689 GtkSelectionData
*selection_data
)
3691 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3695 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
3696 event
.SetEventObject( m_owner
);
3697 event
.SetItem( item
);
3698 event
.SetModel( m_wx_model
);
3699 event
.SetDataFormat(gtk_selection_data_get_target(selection_data
));
3700 event
.SetDataSize(gtk_selection_data_get_length(selection_data
));
3701 event
.SetDataBuffer(const_cast<guchar
*>(gtk_selection_data_get_data(selection_data
)));
3702 if (!m_owner
->HandleWindowEvent( event
))
3705 if (!event
.IsAllowed())
3712 wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3714 GtkSelectionData
*selection_data
)
3716 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3720 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
3721 event
.SetEventObject( m_owner
);
3722 event
.SetItem( item
);
3723 event
.SetModel( m_wx_model
);
3724 event
.SetDataFormat(gtk_selection_data_get_target(selection_data
));
3725 if (!m_owner
->HandleWindowEvent( event
))
3728 if (!event
.IsAllowed())
3734 // notifications from wxDataViewModel
3736 bool wxDataViewCtrlInternal::Cleared()
3751 void wxDataViewCtrlInternal::Resort()
3753 if (!m_wx_model
->IsVirtualListModel())
3759 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3761 if (!m_wx_model
->IsVirtualListModel())
3763 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3764 wxASSERT_MSG(parent_node
,
3765 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3767 if (m_wx_model
->IsContainer( item
))
3768 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
3770 parent_node
->AddLeave( item
.GetID() );
3778 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3780 if (!m_wx_model
->IsVirtualListModel())
3782 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3783 wxASSERT_MSG(parent_node
,
3784 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3786 parent_node
->DeleteChild( item
.GetID() );
3794 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
3796 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3797 event
.SetEventObject( m_owner
);
3798 event
.SetModel( m_owner
->GetModel() );
3799 event
.SetItem( item
);
3800 m_owner
->HandleWindowEvent( event
);
3805 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int view_column
)
3807 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3808 event
.SetEventObject( m_owner
);
3809 event
.SetModel( m_owner
->GetModel() );
3810 event
.SetColumn( view_column
);
3811 event
.SetDataViewColumn( GetOwner()->GetColumn(view_column
) );
3812 event
.SetItem( item
);
3813 m_owner
->HandleWindowEvent( event
);
3820 GtkTreeModelFlags
wxDataViewCtrlInternal::get_flags()
3824 if ( m_wx_model
->IsListModel() )
3825 flags
|= GTK_TREE_MODEL_LIST_ONLY
;
3827 if ( !m_wx_model
->IsVirtualListModel() )
3828 flags
|= GTK_TREE_MODEL_ITERS_PERSIST
;
3830 return GtkTreeModelFlags(flags
);
3833 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
3836 if (m_wx_model
->IsVirtualListModel())
3838 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3840 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
3842 if (i
>= wx_model
->GetCount())
3845 iter
->stamp
= m_gtk_model
->stamp
;
3846 // user_data is just the index +1
3847 iter
->user_data
= (gpointer
) (i
+1);
3853 int depth
= gtk_tree_path_get_depth( path
);
3855 wxGtkTreeModelNode
*node
= m_root
;
3858 for (i
= 0; i
< depth
; i
++)
3860 BuildBranch( node
);
3862 gint pos
= gtk_tree_path_get_indices (path
)[i
];
3863 if (pos
< 0) return FALSE
;
3864 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
3866 void* id
= node
->GetChildren().Item( (size_t) pos
);
3870 iter
->stamp
= m_gtk_model
->stamp
;
3871 iter
->user_data
= id
;
3875 size_t count
= node
->GetNodes().GetCount();
3877 for (pos2
= 0; pos2
< count
; pos2
++)
3879 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
3880 if (child_node
->GetItem().GetID() == id
)
3892 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
3894 // When this is called from ItemDeleted(), the item is already
3895 // deleted in the model.
3897 GtkTreePath
*retval
= gtk_tree_path_new ();
3899 if (m_wx_model
->IsVirtualListModel())
3901 // iter is root, add nothing
3902 if (!iter
->user_data
)
3905 // user_data is just the index +1
3906 int i
= ( (wxUIntPtr
) iter
->user_data
) -1;
3907 gtk_tree_path_append_index (retval
, i
);
3911 void *id
= iter
->user_data
;
3913 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
3916 int pos
= node
->GetChildren().Index( id
);
3918 gtk_tree_path_prepend_index( retval
, pos
);
3920 id
= node
->GetItem().GetID();
3921 node
= node
->GetParent();
3928 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
3930 if (m_wx_model
->IsVirtualListModel())
3932 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3934 // user_data is just the index +1
3935 int n
= ( (wxUIntPtr
) iter
->user_data
) -1;
3939 iter
->user_data
= NULL
;
3943 if (n
>= (int) wx_model
->GetCount()-1)
3945 iter
->user_data
= NULL
;
3949 // user_data is just the index +1 (+2 because we need the next)
3950 iter
->user_data
= (gpointer
) (n
+2);
3954 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
3955 if( parent
== NULL
)
3957 iter
->user_data
= NULL
;
3961 int pos
= parent
->GetChildren().Index( iter
->user_data
);
3963 if (pos
== (int) parent
->GetChildCount()-1)
3965 iter
->user_data
= NULL
;
3969 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
3975 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
3977 if (m_wx_model
->IsVirtualListModel())
3979 // this is a list, nodes have no children
3983 iter
->stamp
= m_gtk_model
->stamp
;
3984 iter
->user_data
= (gpointer
) 1;
3992 if (m_root
->GetChildCount() == 0) return FALSE
;
3993 iter
->stamp
= m_gtk_model
->stamp
;
3994 iter
->user_data
= (gpointer
) m_root
->GetChildren().Item( 0 );
3999 wxDataViewItem item
;
4001 item
= wxDataViewItem( (void*) parent
->user_data
);
4003 if (!m_wx_model
->IsContainer( item
))
4006 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
4007 wxASSERT_MSG(parent_node
,
4008 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
4010 BuildBranch( parent_node
);
4012 if (parent_node
->GetChildCount() == 0)
4015 iter
->stamp
= m_gtk_model
->stamp
;
4016 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
4022 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
4024 if (m_wx_model
->IsVirtualListModel())
4026 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
4029 return (wx_model
->GetCount() > 0);
4031 // this is a list, nodes have no children
4037 return (m_root
->GetChildCount() > 0);
4039 wxDataViewItem
item( (void*) iter
->user_data
);
4041 bool is_container
= m_wx_model
->IsContainer( item
);
4046 wxGtkTreeModelNode
*node
= FindNode( iter
);
4048 "Did you forget a call to ItemAdded()? The iterator is unknown to the wxGtkTreeModel");
4050 BuildBranch( node
);
4052 return (node
->GetChildCount() > 0);
4056 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
4058 if (m_wx_model
->IsVirtualListModel())
4060 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
4063 return (gint
) wx_model
->GetCount();
4070 return m_root
->GetChildCount();
4072 wxDataViewItem
item( (void*) iter
->user_data
);
4074 if (!m_wx_model
->IsContainer( item
))
4077 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
4078 wxASSERT_MSG(parent_node
,
4079 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
4081 BuildBranch( parent_node
);
4083 return parent_node
->GetChildCount();
4087 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
4089 if (m_wx_model
->IsVirtualListModel())
4091 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
4099 if (n
>= (gint
) wx_model
->GetCount())
4102 iter
->stamp
= m_gtk_model
->stamp
;
4103 // user_data is just the index +1
4104 iter
->user_data
= (gpointer
) (n
+1);
4111 if (parent
) id
= (void*) parent
->user_data
;
4112 wxDataViewItem
item( id
);
4114 if (!m_wx_model
->IsContainer( item
))
4117 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
4118 wxASSERT_MSG(parent_node
,
4119 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
4121 BuildBranch( parent_node
);
4123 iter
->stamp
= m_gtk_model
->stamp
;
4124 iter
->user_data
= parent_node
->GetChildren().Item( n
);
4130 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
4132 if (m_wx_model
->IsVirtualListModel())
4138 wxGtkTreeModelNode
*node
= FindParentNode( child
);
4142 iter
->stamp
= m_gtk_model
->stamp
;
4143 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
4149 // item can be deleted already in the model
4150 int wxDataViewCtrlInternal::GetIndexOf( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
4152 if (m_wx_model
->IsVirtualListModel())
4154 return wxPtrToUInt(item
.GetID()) - 1;
4158 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
4159 wxGtkTreeModelChildren
&children
= parent_node
->GetChildren();
4161 for (j
= 0; j
< children
.GetCount(); j
++)
4163 if (children
[j
] == item
.GetID())
4171 static wxGtkTreeModelNode
*
4172 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
4178 list
.DeleteContents( true );
4179 wxDataViewItem
it( item
);
4183 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
4184 list
.Insert( pItem
);
4185 it
= model
->GetParent( it
);
4188 wxGtkTreeModelNode
* node
= treeNode
;
4189 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
4191 if( node
&& node
->GetNodes().GetCount() != 0 )
4193 int len
= node
->GetNodes().GetCount();
4194 wxGtkTreeModelNodes
&nodes
= node
->GetNodes();
4196 for( ; j
< len
; j
++)
4198 if( nodes
[j
]->GetItem() == *(n
->GetData()))
4217 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
4222 wxDataViewItem
item( (void*) iter
->user_data
);
4226 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
4231 wxLogDebug( "Not found %p", iter->user_data );
4235 // TODO: remove this code
4241 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
4246 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
4251 wxLogDebug( "Not found %p", item.GetID() );
4255 // TODO: remove this code
4261 static wxGtkTreeModelNode
*
4262 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
4268 list
.DeleteContents( true );
4272 wxDataViewItem
it( model
->GetParent( item
) );
4275 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
4276 list
.Insert( pItem
);
4277 it
= model
->GetParent( it
);
4280 wxGtkTreeModelNode
* node
= treeNode
;
4281 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
4283 if( node
&& node
->GetNodes().GetCount() != 0 )
4285 int len
= node
->GetNodes().GetCount();
4286 wxGtkTreeModelNodes nodes
= node
->GetNodes();
4288 for( ; j
< len
; j
++)
4290 if( nodes
[j
]->GetItem() == *(n
->GetData()))
4305 //Examine whether the node is item's parent node
4306 int len
= node
->GetChildCount();
4307 for( int i
= 0; i
< len
; i
++ )
4309 if( node
->GetChildren().Item( i
) == item
.GetID() )
4315 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
4320 wxDataViewItem
item( (void*) iter
->user_data
);
4324 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
4327 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
4332 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
4335 //-----------------------------------------------------------------------------
4336 // wxDataViewCtrl signal callbacks
4337 //-----------------------------------------------------------------------------
4340 wxdataview_selection_changed_callback( GtkTreeSelection
* WXUNUSED(selection
), wxDataViewCtrl
*dv
)
4342 if (!gtk_widget_get_realized(dv
->m_widget
))
4345 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
4346 event
.SetItem( dv
->GetSelection() );
4347 event
.SetModel( dv
->GetModel() );
4348 dv
->HandleWindowEvent( event
);
4352 wxdataview_row_activated_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreePath
*path
,
4353 GtkTreeViewColumn
*WXUNUSED(column
), wxDataViewCtrl
*dv
)
4355 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
4357 wxDataViewItem
item(dv
->GTKPathToItem(path
));
4358 event
.SetItem( item
);
4359 event
.SetModel( dv
->GetModel() );
4360 dv
->HandleWindowEvent( event
);
4364 wxdataview_test_expand_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4365 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4367 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
4369 wxDataViewItem
item( (void*) iter
->user_data
);;
4370 event
.SetItem( item
);
4371 event
.SetModel( dv
->GetModel() );
4372 dv
->HandleWindowEvent( event
);
4374 return !event
.IsAllowed();
4378 wxdataview_row_expanded_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4379 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4381 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
4383 wxDataViewItem
item( (void*) iter
->user_data
);;
4384 event
.SetItem( item
);
4385 event
.SetModel( dv
->GetModel() );
4386 dv
->HandleWindowEvent( event
);
4390 wxdataview_test_collapse_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4391 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4393 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
4395 wxDataViewItem
item( (void*) iter
->user_data
);;
4396 event
.SetItem( item
);
4397 event
.SetModel( dv
->GetModel() );
4398 dv
->HandleWindowEvent( event
);
4400 return !event
.IsAllowed();
4404 wxdataview_row_collapsed_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4405 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4407 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
4409 wxDataViewItem
item( (void*) iter
->user_data
);;
4410 event
.SetItem( item
);
4411 event
.SetModel( dv
->GetModel() );
4412 dv
->HandleWindowEvent( event
);
4415 //-----------------------------------------------------------------------------
4417 //-----------------------------------------------------------------------------
4419 void wxDataViewCtrl::AddChildGTK(wxWindowGTK
* child
)
4421 GtkWidget
* treeview
= GtkGetTreeView();
4423 // Insert widget in GtkTreeView
4424 if (gtk_widget_get_realized(treeview
))
4425 gtk_widget_set_parent_window( child
->m_widget
,
4426 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
4427 gtk_widget_set_parent( child
->m_widget
, treeview
);
4431 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
4432 GtkAllocation
*WXUNUSED(gtk_alloc
),
4433 wxDataViewCtrl
*win
)
4435 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
4438 wxWindow
*child
= node
->GetData();
4441 gtk_widget_size_request( child
->m_widget
, &req
);
4443 GtkAllocation alloc
;
4444 alloc
.x
= child
->m_x
;
4445 alloc
.y
= child
->m_y
;
4446 alloc
.width
= child
->m_width
;
4447 alloc
.height
= child
->m_height
;
4448 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
4450 node
= node
->GetNext();
4455 //-----------------------------------------------------------------------------
4456 // "motion_notify_event"
4457 //-----------------------------------------------------------------------------
4460 gtk_dataview_motion_notify_callback( GtkWidget
*WXUNUSED(widget
),
4461 GdkEventMotion
*gdk_event
,
4462 wxDataViewCtrl
*dv
)
4464 if (gdk_event
->is_hint
)
4468 GdkModifierType state
;
4469 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
4475 GtkTreeViewColumn
*column
= NULL
;
4478 if (gtk_tree_view_get_path_at_pos(
4479 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4480 (int) gdk_event
->x
, (int) gdk_event
->y
,
4489 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4497 //-----------------------------------------------------------------------------
4498 // "button_press_event"
4499 //-----------------------------------------------------------------------------
4502 gtk_dataview_button_press_callback( GtkWidget
*WXUNUSED(widget
),
4503 GdkEventButton
*gdk_event
,
4504 wxDataViewCtrl
*dv
)
4506 if ((gdk_event
->button
== 3) && (gdk_event
->type
== GDK_BUTTON_PRESS
))
4509 GtkTreeViewColumn
*column
= NULL
;
4512 if (gtk_tree_view_get_path_at_pos(
4513 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4514 (int) gdk_event
->x
, (int) gdk_event
->y
,
4522 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, dv
->GetId() );
4523 event
.SetItem(dv
->GTKPathToItem(path
));
4524 event
.SetModel( dv
->GetModel() );
4525 return dv
->HandleWindowEvent( event
);
4533 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
4535 wxDataViewCtrl::~wxDataViewCtrl()
4537 // Stop editing before destroying the control to remove any event handlers
4538 // which are added when editing started: if we didn't do this, the base
4539 // class dtor would assert as it checks for any leftover handlers.
4542 GtkTreeViewColumn
*col
;
4543 gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview
), NULL
, &col
);
4545 wxDataViewColumn
* const wxcol
= FromGTKColumn(col
);
4548 // This won't do anything if we're not editing it
4549 wxcol
->GetRenderer()->CancelEditing();
4558 void wxDataViewCtrl::Init()
4562 m_cols
.DeleteContents( true );
4564 m_uniformRowHeight
= -1;
4567 bool wxDataViewCtrl::Create(wxWindow
*parent
,
4572 const wxValidator
& validator
,
4573 const wxString
& name
)
4575 if (!PreCreation( parent
, pos
, size
) ||
4576 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
4578 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
4582 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
4583 g_object_ref(m_widget
);
4585 GTKScrolledWindowSetBorder(m_widget
, style
);
4587 m_treeview
= gtk_tree_view_new();
4588 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
4590 g_signal_connect (m_treeview
, "size_allocate",
4591 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
4594 if (!gtk_check_version(2,6,0))
4596 bool fixed
= (style
& wxDV_VARIABLE_LINE_HEIGHT
) == 0;
4597 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4601 if (style
& wxDV_MULTIPLE
)
4603 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4604 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
4607 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
4610 if (!gtk_check_version(2,10,0))
4612 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
4614 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
4615 (style
& wxDV_VERT_RULES
) != 0)
4616 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
4617 else if (style
& wxDV_VERT_RULES
)
4618 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
4619 else if (style
& wxDV_HORIZ_RULES
)
4620 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
4622 if (grid
!= GTK_TREE_VIEW_GRID_LINES_NONE
)
4623 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
4627 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_ROW_LINES
) != 0 );
4629 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
4630 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
4631 gtk_widget_show (m_treeview
);
4633 m_parent
->DoAddChild( this );
4637 GtkEnableSelectionEvents();
4639 g_signal_connect_after (m_treeview
, "row-activated",
4640 G_CALLBACK (wxdataview_row_activated_callback
), this);
4642 g_signal_connect (m_treeview
, "test-collapse-row",
4643 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
4645 g_signal_connect_after (m_treeview
, "row-collapsed",
4646 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
4648 g_signal_connect (m_treeview
, "test-expand-row",
4649 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
4651 g_signal_connect_after (m_treeview
, "row-expanded",
4652 G_CALLBACK (wxdataview_row_expanded_callback
), this);
4654 g_signal_connect (m_treeview
, "motion_notify_event",
4655 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
4657 g_signal_connect (m_treeview
, "button_press_event",
4658 G_CALLBACK (gtk_dataview_button_press_callback
), this);
4663 wxDataViewItem
wxDataViewCtrl::GTKPathToItem(GtkTreePath
*path
) const
4666 return wxDataViewItem(path
&& m_internal
->get_iter(&iter
, path
)
4671 void wxDataViewCtrl::OnInternalIdle()
4673 wxWindow::OnInternalIdle();
4675 m_internal
->OnInternalIdle();
4677 unsigned int cols
= GetColumnCount();
4679 for (i
= 0; i
< cols
; i
++)
4681 wxDataViewColumn
*col
= GetColumn( i
);
4682 col
->OnInternalIdle();
4685 if (m_ensureVisibleDefered
.IsOk())
4687 ExpandAncestors(m_ensureVisibleDefered
);
4689 iter
.user_data
= (gpointer
) m_ensureVisibleDefered
.GetID();
4690 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4691 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
4692 m_ensureVisibleDefered
= wxDataViewItem(0);
4696 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4698 wxDELETE(m_internal
);
4700 if (!wxDataViewCtrlBase::AssociateModel( model
))
4704 if (!gtk_check_version(2,6,0))
4706 bool fixed
= (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
) == 0) || (model
->IsVirtualListModel()));
4707 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4711 m_internal
= new wxDataViewCtrlInternal( this, model
);
4716 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4718 return m_internal
->EnableDragSource( format
);
4721 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4723 return m_internal
->EnableDropTarget( format
);
4726 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4728 if (!wxDataViewCtrlBase::AppendColumn(col
))
4731 m_cols
.Append( col
);
4734 if (!gtk_check_version(2,6,0))
4736 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4737 GTK_TREE_VIEW_COLUMN_FIXED
)
4738 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4742 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
4743 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4748 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4750 if (!wxDataViewCtrlBase::PrependColumn(col
))
4753 m_cols
.Insert( col
);
4756 if (!gtk_check_version(2,6,0))
4758 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4759 GTK_TREE_VIEW_COLUMN_FIXED
)
4760 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4764 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4765 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
4770 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4772 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4775 m_cols
.Insert( pos
, col
);
4778 if (!gtk_check_version(2,6,0))
4780 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4781 GTK_TREE_VIEW_COLUMN_FIXED
)
4782 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4786 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4787 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), pos
);
4792 unsigned int wxDataViewCtrl::GetColumnCount() const
4794 return m_cols
.GetCount();
4797 wxDataViewColumn
* wxDataViewCtrl::FromGTKColumn(GtkTreeViewColumn
*gtk_col
) const
4802 wxDataViewColumnList::const_iterator iter
;
4803 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4805 wxDataViewColumn
*col
= *iter
;
4806 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
4812 wxFAIL_MSG( "No matching column?" );
4817 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
4819 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
4821 return FromGTKColumn(gtk_col
);
4824 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4826 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4827 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
4829 m_cols
.DeleteObject( column
);
4834 bool wxDataViewCtrl::ClearColumns()
4836 wxDataViewColumnList::iterator iter
;
4837 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4839 wxDataViewColumn
*col
= *iter
;
4840 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4841 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4849 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4851 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
4853 wxGtkList
list(gtk_tree_view_get_columns(GTK_TREE_VIEW(m_treeview
)));
4855 return g_list_index( list
, (gconstpointer
) gtk_column
);
4858 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4860 return m_internal
->GetDataViewSortColumn();
4863 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4866 iter
.user_data
= item
.GetID();
4867 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4868 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
4871 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4874 iter
.user_data
= item
.GetID();
4875 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4876 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
4879 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4882 iter
.user_data
= item
.GetID();
4883 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4884 return gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview
), path
);
4887 wxDataViewItem
wxDataViewCtrl::DoGetCurrentItem() const
4889 // The tree doesn't have any current item if it hadn't been created yet but
4890 // it's arguably not an error to call this function in this case so just
4891 // return an invalid item without asserting.
4893 return wxDataViewItem();
4896 gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview
), path
.ByRef(), NULL
);
4898 return GTKPathToItem(path
);
4901 void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem
& item
)
4903 wxCHECK_RET( m_treeview
,
4904 "Current item can't be set before creating the control." );
4906 // We need to make sure the model knows about this item or the path would
4907 // be invalid and gtk_tree_view_set_cursor() would silently do nothing.
4908 ExpandAncestors(item
);
4910 // We also need to preserve the existing selection from changing.
4911 // Unfortunately the only way to do it seems to use our own selection
4912 // function and forbid any selection changes during set cursor call.
4913 wxGtkTreeSelectionLock
4914 lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview
)));
4916 // Do move the cursor now.
4918 iter
.user_data
= item
.GetID();
4919 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4921 gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview
), path
, NULL
, FALSE
);
4924 void wxDataViewCtrl::StartEditor(const wxDataViewItem
& item
, unsigned int column
)
4926 wxCHECK_RET( m_treeview
,
4927 "Current item can't be set before creating the control." );
4929 // We need to make sure the model knows about this item or the path would
4930 // be invalid and gtk_tree_view_set_cursor() would silently do nothing.
4931 ExpandAncestors(item
);
4933 wxDataViewColumn
*dvcolumn
= GetColumn(column
);
4934 wxASSERT_MSG(dvcolumn
, "Could not retrieve column");
4935 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(dvcolumn
->GetGtkHandle());
4937 // We also need to preserve the existing selection from changing.
4938 // Unfortunately the only way to do it seems to use our own selection
4939 // function and forbid any selection changes during set cursor call.
4940 wxGtkTreeSelectionLock
4941 lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview
)));
4943 // Do move the cursor now.
4945 iter
.user_data
= item
.GetID();
4946 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4948 gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview
), path
, gcolumn
, TRUE
);
4951 int wxDataViewCtrl::GetSelectedItemsCount() const
4953 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4955 return gtk_tree_selection_count_selected_rows(selection
);
4958 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4962 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4963 if (HasFlag(wxDV_MULTIPLE
))
4965 GtkTreeModel
*model
;
4966 wxGtkTreePathList
list(gtk_tree_selection_get_selected_rows(selection
, &model
));
4968 for ( GList
* current
= list
; current
; current
= g_list_next(current
) )
4970 GtkTreePath
*path
= (GtkTreePath
*) current
->data
;
4972 sel
.Add(GTKPathToItem(path
));
4978 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
4980 sel
.Add( wxDataViewItem(iter
.user_data
) );
4987 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4989 GtkDisableSelectionEvents();
4991 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4993 gtk_tree_selection_unselect_all( selection
);
4995 wxDataViewItem last_parent
;
4998 for (i
= 0; i
< sel
.GetCount(); i
++)
5000 wxDataViewItem item
= sel
[i
];
5001 wxDataViewItem parent
= GetModel()->GetParent( item
);
5004 if (parent
!= last_parent
)
5005 ExpandAncestors(item
);
5007 last_parent
= parent
;
5010 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
5011 iter
.user_data
= (gpointer
) item
.GetID();
5012 gtk_tree_selection_select_iter( selection
, &iter
);
5015 GtkEnableSelectionEvents();
5018 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
5020 ExpandAncestors(item
);
5022 GtkDisableSelectionEvents();
5024 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5027 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
5028 iter
.user_data
= (gpointer
) item
.GetID();
5029 gtk_tree_selection_select_iter( selection
, &iter
);
5031 GtkEnableSelectionEvents();
5034 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
5036 GtkDisableSelectionEvents();
5038 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5041 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
5042 iter
.user_data
= (gpointer
) item
.GetID();
5043 gtk_tree_selection_unselect_iter( selection
, &iter
);
5045 GtkEnableSelectionEvents();
5048 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
5050 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5053 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
5054 iter
.user_data
= (gpointer
) item
.GetID();
5056 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
5059 void wxDataViewCtrl::SelectAll()
5061 GtkDisableSelectionEvents();
5063 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5065 gtk_tree_selection_select_all( selection
);
5067 GtkEnableSelectionEvents();
5070 void wxDataViewCtrl::UnselectAll()
5072 GtkDisableSelectionEvents();
5074 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5076 gtk_tree_selection_unselect_all( selection
);
5078 GtkEnableSelectionEvents();
5081 void wxDataViewCtrl::EnsureVisible(const wxDataViewItem
& item
,
5082 const wxDataViewColumn
*WXUNUSED(column
))
5084 m_ensureVisibleDefered
= item
;
5085 ExpandAncestors(item
);
5088 iter
.user_data
= (gpointer
) item
.GetID();
5089 wxGtkTreePath
path(m_internal
->get_path( &iter
));
5090 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
5093 void wxDataViewCtrl::HitTest(const wxPoint
& point
,
5094 wxDataViewItem
& item
,
5095 wxDataViewColumn
*& column
) const
5097 // gtk_tree_view_get_dest_row_at_pos() is the right one. But it does not tell the column.
5098 // gtk_tree_view_get_path_at_pos() is the wrong function. It doesn't mind the header but returns column.
5099 // See http://mail.gnome.org/archives/gtkmm-list/2005-January/msg00080.html
5100 // So we have to use both of them.
5101 // Friedrich Haase 2010-9-20
5102 wxGtkTreePath path
, pathScratch
;
5103 GtkTreeViewColumn
* GtkColumn
= NULL
;
5104 GtkTreeViewDropPosition pos
= GTK_TREE_VIEW_DROP_INTO_OR_AFTER
;
5108 // cannot directly call GtkGetTreeView(), HitTest is const and so is this pointer
5109 wxDataViewCtrl
* ctrl
= (wxDataViewCtrl
*)this; // ugly workaround, ctrl is NOT const
5110 GtkTreeView
* treeView
= GTK_TREE_VIEW(ctrl
->GtkGetTreeView());
5112 // is there possibly a better suited function to get the column?
5113 gtk_tree_view_get_path_at_pos( // and this is the wrong call but it delivers the column
5115 (int) point
.x
, (int) point
.y
,
5116 pathScratch
.ByRef(),
5117 &GtkColumn
, // here we get the GtkColumn
5121 if ( GtkColumn
!= NULL
)
5123 // we got GTK column
5124 // the right call now which takes the header into account
5125 gtk_tree_view_get_dest_row_at_pos( treeView
, (int) point
.x
, (int) point
.y
, path
.ByRef(), &pos
);
5128 item
= wxDataViewItem(GTKPathToItem(path
));
5129 // else we got a GTK column but the position is not over an item, e.g. below last item
5130 for ( unsigned int i
=0, cols
=GetColumnCount(); i
<cols
; ++i
) // search the wx column
5132 wxDataViewColumn
* col
= GetColumn(i
);
5133 if ( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == GtkColumn
)
5135 column
= col
; // here we get the wx column
5140 // else no column and thus no item, both null
5144 wxDataViewCtrl::GetItemRect(const wxDataViewItem
& WXUNUSED(item
),
5145 const wxDataViewColumn
*WXUNUSED(column
)) const
5150 bool wxDataViewCtrl::SetRowHeight(int rowHeight
)
5152 m_uniformRowHeight
= rowHeight
;
5156 void wxDataViewCtrl::DoSetExpanderColumn()
5158 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
5159 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
5162 void wxDataViewCtrl::DoSetIndent()
5166 void wxDataViewCtrl::GtkDisableSelectionEvents()
5168 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5169 g_signal_handlers_disconnect_by_func( selection
,
5170 (gpointer
) (wxdataview_selection_changed_callback
), this);
5173 void wxDataViewCtrl::GtkEnableSelectionEvents()
5175 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5176 g_signal_connect_after (selection
, "changed",
5177 G_CALLBACK (wxdataview_selection_changed_callback
), this);
5180 // ----------------------------------------------------------------------------
5181 // visual attributes stuff
5182 // ----------------------------------------------------------------------------
5186 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
5188 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
5191 void wxDataViewCtrl::DoApplyWidgetStyle(GtkRcStyle
*style
)
5193 wxDataViewCtrlBase::DoApplyWidgetStyle(style
);
5194 gtk_widget_modify_style(m_treeview
, style
);
5197 #endif // !wxUSE_GENERICDATAVIEWCTRL
5199 #endif // wxUSE_DATAVIEWCTRL