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 void 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
);
370 void InsertNode( wxGtkTreeModelNode
* child
, unsigned pos
)
372 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
378 void *id
= child
->GetItem().GetID();
380 // Insert into m_nodes so that the order of nodes in m_nodes is the
381 // same as the order of their corresponding IDs in m_children:
382 const unsigned int count
= m_nodes
.GetCount();
383 bool inserted
= false;
384 for (unsigned i
= 0; i
< count
; i
++)
386 wxGtkTreeModelNode
*node
= m_nodes
[i
];
387 int posInChildren
= m_children
.Index(node
->GetItem().GetID());
388 if ( (unsigned)posInChildren
>= pos
)
390 m_nodes
.Insert(child
, i
);
398 m_children
.Insert( id
, pos
);
401 void AddLeaf( void* id
)
403 InsertLeaf(id
, m_children
.size());
406 void InsertLeaf( void* id
, unsigned pos
)
408 m_children
.Insert( id
, pos
);
410 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
412 gs_internal
= m_internal
;
413 m_children
.Sort( &wxGtkTreeModelChildCmp
);
417 void DeleteChild( void* id
)
419 m_children
.Remove( id
);
421 unsigned int count
= m_nodes
.GetCount();
423 for (pos
= 0; pos
< count
; pos
++)
425 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
426 if (node
->GetItem().GetID() == id
)
428 m_nodes
.RemoveAt( pos
);
435 wxGtkTreeModelNode
* GetParent()
437 wxGtkTreeModelNodes
&GetNodes()
439 wxGtkTreeModelChildren
&GetChildren()
440 { return m_children
; }
442 unsigned int GetChildCount() const { return m_children
.GetCount(); }
443 unsigned int GetNodesCount() const { return m_nodes
.GetCount(); }
445 wxDataViewItem
&GetItem() { return m_item
; }
446 wxDataViewCtrlInternal
*GetInternal() { return m_internal
; }
451 wxGtkTreeModelNode
*m_parent
;
452 wxGtkTreeModelNodes m_nodes
;
453 wxGtkTreeModelChildren m_children
;
454 wxDataViewItem m_item
;
455 wxDataViewCtrlInternal
*m_internal
;
459 //-----------------------------------------------------------------------------
461 //-----------------------------------------------------------------------------
463 extern bool g_blockEventsOnDrag
;
465 //-----------------------------------------------------------------------------
466 // define new GTK+ class wxGtkTreeModel
467 //-----------------------------------------------------------------------------
471 #define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ())
472 #define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel))
473 #define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
474 #define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL))
475 #define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL))
476 #define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
478 GType
gtk_wx_tree_model_get_type (void);
480 typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass
;
482 struct _GtkWxTreeModel
488 wxDataViewCtrlInternal
*internal
;
491 struct _GtkWxTreeModelClass
493 GObjectClass list_parent_class
;
496 static GtkWxTreeModel
*wxgtk_tree_model_new (void);
497 static void wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
);
498 static void wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
);
500 static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
);
501 static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
);
502 static void wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
);
503 static void wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
);
505 static void wxgtk_tree_model_finalize (GObject
*object
);
506 static GtkTreeModelFlags
wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
);
507 static gint
wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
);
508 static GType
wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
510 static gboolean
wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
513 static GtkTreePath
*wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
515 static void wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
519 static gboolean
wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
521 static gboolean
wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
523 GtkTreeIter
*parent
);
524 static gboolean
wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
526 static gint
wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
528 static gboolean
wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
532 static gboolean
wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
537 static gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
538 gint
*sort_column_id
,
540 static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
543 static void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
545 GtkTreeIterCompareFunc func
,
547 GDestroyNotify destroy
);
548 static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
549 GtkTreeIterCompareFunc func
,
551 GDestroyNotify destroy
);
552 static gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
);
555 static gboolean
wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
557 static gboolean
wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
559 static gboolean
wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
561 GtkSelectionData
*selection_data
);
562 static gboolean
wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
564 GtkSelectionData
*selection_data
);
565 static gboolean
wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
566 GtkTreePath
*dest_path
,
567 GtkSelectionData
*selection_data
);
570 static GObjectClass
*list_parent_class
= NULL
;
573 gtk_wx_tree_model_get_type (void)
575 static GType tree_model_type
= 0;
577 if (!tree_model_type
)
579 const GTypeInfo tree_model_info
=
581 sizeof (GtkWxTreeModelClass
),
582 NULL
, /* base_init */
583 NULL
, /* base_finalize */
584 (GClassInitFunc
) wxgtk_tree_model_class_init
,
585 NULL
, /* class_finalize */
586 NULL
, /* class_data */
587 sizeof (GtkWxTreeModel
),
589 (GInstanceInitFunc
) wxgtk_tree_model_init
,
592 static const GInterfaceInfo tree_model_iface_info
=
594 (GInterfaceInitFunc
) wxgtk_tree_model_tree_model_init
,
599 static const GInterfaceInfo sortable_iface_info
=
601 (GInterfaceInitFunc
) wxgtk_tree_model_sortable_init
,
606 static const GInterfaceInfo drag_source_iface_info
=
608 (GInterfaceInitFunc
) wxgtk_tree_model_drag_source_init
,
613 static const GInterfaceInfo drag_dest_iface_info
=
615 (GInterfaceInitFunc
) wxgtk_tree_model_drag_dest_init
,
620 tree_model_type
= g_type_register_static (G_TYPE_OBJECT
, "GtkWxTreeModel",
621 &tree_model_info
, (GTypeFlags
)0 );
623 g_type_add_interface_static (tree_model_type
,
625 &tree_model_iface_info
);
626 g_type_add_interface_static (tree_model_type
,
627 GTK_TYPE_TREE_SORTABLE
,
628 &sortable_iface_info
);
629 g_type_add_interface_static (tree_model_type
,
630 GTK_TYPE_TREE_DRAG_DEST
,
631 &drag_dest_iface_info
);
632 g_type_add_interface_static (tree_model_type
,
633 GTK_TYPE_TREE_DRAG_SOURCE
,
634 &drag_source_iface_info
);
637 return tree_model_type
;
640 static GtkWxTreeModel
*
641 wxgtk_tree_model_new(void)
643 GtkWxTreeModel
*retval
= (GtkWxTreeModel
*) g_object_new (GTK_TYPE_WX_TREE_MODEL
, NULL
);
648 wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
)
650 list_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
651 GObjectClass
*object_class
= (GObjectClass
*) klass
;
652 object_class
->finalize
= wxgtk_tree_model_finalize
;
656 wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
)
658 iface
->get_flags
= wxgtk_tree_model_get_flags
;
659 iface
->get_n_columns
= wxgtk_tree_model_get_n_columns
;
660 iface
->get_column_type
= wxgtk_tree_model_get_column_type
;
661 iface
->get_iter
= wxgtk_tree_model_get_iter
;
662 iface
->get_path
= wxgtk_tree_model_get_path
;
663 iface
->get_value
= wxgtk_tree_model_get_value
;
664 iface
->iter_next
= wxgtk_tree_model_iter_next
;
665 iface
->iter_children
= wxgtk_tree_model_iter_children
;
666 iface
->iter_has_child
= wxgtk_tree_model_iter_has_child
;
667 iface
->iter_n_children
= wxgtk_tree_model_iter_n_children
;
668 iface
->iter_nth_child
= wxgtk_tree_model_iter_nth_child
;
669 iface
->iter_parent
= wxgtk_tree_model_iter_parent
;
673 wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
)
675 iface
->get_sort_column_id
= wxgtk_tree_model_get_sort_column_id
;
676 iface
->set_sort_column_id
= wxgtk_tree_model_set_sort_column_id
;
677 iface
->set_sort_func
= wxgtk_tree_model_set_sort_func
;
678 iface
->set_default_sort_func
= wxgtk_tree_model_set_default_sort_func
;
679 iface
->has_default_sort_func
= wxgtk_tree_model_has_default_sort_func
;
683 wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
)
685 iface
->row_draggable
= wxgtk_tree_model_row_draggable
;
686 iface
->drag_data_delete
= wxgtk_tree_model_drag_data_delete
;
687 iface
->drag_data_get
= wxgtk_tree_model_drag_data_get
;
691 wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
)
693 iface
->drag_data_received
= wxgtk_tree_model_drag_data_received
;
694 iface
->row_drop_possible
= wxgtk_tree_model_row_drop_possible
;
698 wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
)
700 tree_model
->internal
= NULL
;
701 tree_model
->stamp
= g_random_int();
705 wxgtk_tree_model_finalize (GObject
*object
)
708 (* list_parent_class
->finalize
) (object
);
713 //-----------------------------------------------------------------------------
714 // implement callbacks from wxGtkTreeModel class by letting
715 // them call the methods of wxWidgets' wxDataViewModel
716 //-----------------------------------------------------------------------------
718 static GtkTreeModelFlags
719 wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
)
721 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
722 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), (GtkTreeModelFlags
)0 );
724 return wxtree_model
->internal
->get_flags();
728 wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
)
730 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
731 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
733 return wxtree_model
->internal
->GetDataViewModel()->GetColumnCount();
737 wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
740 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
741 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), G_TYPE_INVALID
);
743 GType gtype
= G_TYPE_INVALID
;
745 wxString wxtype
= wxtree_model
->internal
->GetDataViewModel()->GetColumnType( (unsigned int) index
);
747 if (wxtype
== wxT("string"))
748 gtype
= G_TYPE_STRING
;
751 gtype
= G_TYPE_POINTER
;
752 // wxFAIL_MSG( wxT("non-string columns not supported for searching yet") );
759 wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
763 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
764 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
765 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
767 return wxtree_model
->internal
->get_iter( iter
, path
);
771 wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
774 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
775 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), NULL
);
776 g_return_val_if_fail (iter
->stamp
== GTK_WX_TREE_MODEL (wxtree_model
)->stamp
, NULL
);
778 return wxtree_model
->internal
->get_path( iter
);
782 wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
787 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
788 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
) );
790 wxDataViewModel
*model
= wxtree_model
->internal
->GetDataViewModel();
791 wxString mtype
= model
->GetColumnType( (unsigned int) column
);
792 if (mtype
== wxT("string"))
795 g_value_init( value
, G_TYPE_STRING
);
796 wxDataViewItem
item( (void*) iter
->user_data
);
797 model
->GetValue( variant
, item
, (unsigned int) column
);
799 g_value_set_string( value
, variant
.GetString().utf8_str() );
803 wxFAIL_MSG( wxT("non-string columns not supported yet") );
808 wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
811 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
813 // This happens when clearing the view by calling .._set_model( NULL );
814 if (iter
->stamp
== 0) return FALSE
;
816 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
817 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
819 return wxtree_model
->internal
->iter_next( iter
);
823 wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
827 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
828 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
831 g_return_val_if_fail (wxtree_model
->stamp
== parent
->stamp
, FALSE
);
834 return wxtree_model
->internal
->iter_children( iter
, parent
);
838 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
841 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
842 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
843 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
845 return wxtree_model
->internal
->iter_has_child( iter
);
849 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
852 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
853 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
854 g_return_val_if_fail ( !iter
|| wxtree_model
->stamp
== iter
->stamp
, 0);
856 return wxtree_model
->internal
->iter_n_children( iter
);
860 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
865 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
866 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
868 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
872 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
876 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
877 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
878 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
880 return wxtree_model
->internal
->iter_parent( iter
, child
);
883 /* drag'n'drop iface */
885 wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
888 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
889 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
891 return wxtree_model
->internal
->row_draggable( drag_source
, path
);
895 wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
898 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
899 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
901 return wxtree_model
->internal
->drag_data_delete( drag_source
, path
);
905 wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
907 GtkSelectionData
*selection_data
)
909 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
910 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
913 wxPrintf( "drag_get_data\n");
915 wxGtkString
atom_selection(gdk_atom_name(selection_data
->selection
));
916 wxPrintf( "selection %s\n", wxString::FromAscii(atom_selection
) );
918 wxGtkString
atom_target(gdk_atom_name(selection_data
->target
));
919 wxPrintf( "target %s\n", wxString::FromAscii(atom_target
) );
921 wxGtkString
atom_type(gdk_atom_name(selection_data
->type
));
922 wxPrintf( "type %s\n", wxString::FromAscii(atom_type
) );
924 wxPrintf( "format %d\n", selection_data
->format
);
927 return wxtree_model
->internal
->drag_data_get( drag_source
, path
, selection_data
);
931 wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
933 GtkSelectionData
*selection_data
)
935 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
936 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
938 return wxtree_model
->internal
->drag_data_received( drag_dest
, dest
, selection_data
);
942 wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
943 GtkTreePath
*dest_path
,
944 GtkSelectionData
*selection_data
)
946 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
947 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
949 return wxtree_model
->internal
->row_drop_possible( drag_dest
, dest_path
, selection_data
);
954 wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
955 gint
*sort_column_id
,
958 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) sortable
;
960 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
962 if (!wxtree_model
->internal
->IsSorted())
965 *sort_column_id
= -1;
972 *sort_column_id
= wxtree_model
->internal
->GetSortColumn();
975 *order
= wxtree_model
->internal
->GetSortOrder();
980 wxDataViewColumn
*gs_lastLeftClickHeader
= NULL
;
983 wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
987 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
988 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
990 tree_model
->internal
->SetDataViewSortColumn( gs_lastLeftClickHeader
);
992 if ((sort_column_id
!= (gint
) tree_model
->internal
->GetSortColumn()) ||
993 (order
!= tree_model
->internal
->GetSortOrder()))
995 tree_model
->internal
->SetSortColumn( sort_column_id
);
996 tree_model
->internal
->SetSortOrder( order
);
998 gtk_tree_sortable_sort_column_changed (sortable
);
1000 tree_model
->internal
->GetDataViewModel()->Resort();
1003 if (gs_lastLeftClickHeader
)
1005 wxDataViewCtrl
*dv
= tree_model
->internal
->GetOwner();
1006 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, dv
->GetId() );
1007 event
.SetDataViewColumn( gs_lastLeftClickHeader
);
1008 event
.SetModel( dv
->GetModel() );
1009 dv
->HandleWindowEvent( event
);
1012 gs_lastLeftClickHeader
= NULL
;
1016 wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
1017 gint
WXUNUSED(sort_column_id
),
1018 GtkTreeIterCompareFunc func
,
1019 gpointer
WXUNUSED(data
),
1020 GDestroyNotify
WXUNUSED(destroy
))
1022 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
1023 g_return_if_fail (func
!= NULL
);
1027 wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
1028 GtkTreeIterCompareFunc func
,
1029 gpointer
WXUNUSED(data
),
1030 GDestroyNotify
WXUNUSED(destroy
))
1032 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
1033 g_return_if_fail (func
!= NULL
);
1035 //wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
1036 // TODO: remove this code
1040 wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
)
1042 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
1047 //-----------------------------------------------------------------------------
1048 // define new GTK+ class GtkWxRendererText
1049 //-----------------------------------------------------------------------------
1053 #define GTK_TYPE_WX_CELL_RENDERER_TEXT (gtk_wx_cell_renderer_text_get_type ())
1054 #define GTK_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererText))
1055 #define GTK_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
1056 #define GTK_IS_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT))
1057 #define GTK_IS_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT))
1058 #define GTK_WX_CELL_RENDERER_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
1060 GType
gtk_wx_cell_renderer_text_get_type (void);
1062 typedef struct _GtkWxCellRendererText GtkWxCellRendererText
;
1063 typedef struct _GtkWxCellRendererTextClass GtkWxCellRendererTextClass
;
1065 struct _GtkWxCellRendererText
1067 GtkCellRendererText parent
;
1069 wxDataViewRenderer
*wx_renderer
;
1072 struct _GtkWxCellRendererTextClass
1074 GtkCellRendererTextClass cell_parent_class
;
1078 static GtkWxCellRendererText
*gtk_wx_cell_renderer_text_new (void);
1079 static void gtk_wx_cell_renderer_text_init (
1080 GtkWxCellRendererText
*cell
);
1081 static void gtk_wx_cell_renderer_text_class_init(
1082 GtkWxCellRendererTextClass
*klass
);
1083 static void gtk_wx_cell_renderer_text_finalize (
1085 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
1086 GtkCellRenderer
*cell
,
1090 GdkRectangle
*background_area
,
1091 GdkRectangle
*cell_area
,
1092 GtkCellRendererState flags
);
1095 static GObjectClass
*text_cell_parent_class
= NULL
;
1100 gtk_wx_cell_renderer_text_get_type (void)
1102 static GType cell_wx_type
= 0;
1106 const GTypeInfo cell_wx_info
=
1108 sizeof (GtkWxCellRendererTextClass
),
1109 NULL
, /* base_init */
1110 NULL
, /* base_finalize */
1111 (GClassInitFunc
) gtk_wx_cell_renderer_text_class_init
,
1112 NULL
, /* class_finalize */
1113 NULL
, /* class_data */
1114 sizeof (GtkWxCellRendererText
),
1115 0, /* n_preallocs */
1116 (GInstanceInitFunc
) gtk_wx_cell_renderer_text_init
,
1119 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER_TEXT
,
1120 "GtkWxCellRendererText", &cell_wx_info
, (GTypeFlags
)0 );
1123 return cell_wx_type
;
1127 gtk_wx_cell_renderer_text_init (GtkWxCellRendererText
*cell
)
1129 cell
->wx_renderer
= NULL
;
1133 gtk_wx_cell_renderer_text_class_init (GtkWxCellRendererTextClass
*klass
)
1135 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1136 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
1138 text_cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
1140 object_class
->finalize
= gtk_wx_cell_renderer_text_finalize
;
1142 cell_class
->start_editing
= gtk_wx_cell_renderer_text_start_editing
;
1146 gtk_wx_cell_renderer_text_finalize (GObject
*object
)
1149 (* G_OBJECT_CLASS (text_cell_parent_class
)->finalize
) (object
);
1152 GtkWxCellRendererText
*
1153 gtk_wx_cell_renderer_text_new (void)
1155 return (GtkWxCellRendererText
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER_TEXT
, NULL
);
1158 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
1159 GtkCellRenderer
*gtk_renderer
,
1160 GdkEvent
*gdk_event
,
1163 GdkRectangle
*background_area
,
1164 GdkRectangle
*cell_area
,
1165 GtkCellRendererState flags
)
1167 GtkWxCellRendererText
*wxgtk_renderer
= (GtkWxCellRendererText
*) gtk_renderer
;
1168 wxDataViewRenderer
*wx_renderer
= wxgtk_renderer
->wx_renderer
;
1169 wxDataViewColumn
*column
= wx_renderer
->GetOwner();
1172 item(column
->GetOwner()->GTKPathToItem(wxGtkTreePath(path
)));
1174 wxDataViewCtrl
*dv
= column
->GetOwner();
1175 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, dv
->GetId() );
1176 event
.SetDataViewColumn( column
);
1177 event
.SetModel( dv
->GetModel() );
1178 event
.SetColumn( column
->GetModelColumn() );
1179 event
.SetItem( item
);
1180 dv
->HandleWindowEvent( event
);
1182 if (event
.IsAllowed())
1183 return GTK_CELL_RENDERER_CLASS(text_cell_parent_class
)->
1184 start_editing( gtk_renderer
, gdk_event
, widget
, path
, background_area
, cell_area
, flags
);
1189 //-----------------------------------------------------------------------------
1190 // define new GTK+ class GtkWxCellRenderer
1191 //-----------------------------------------------------------------------------
1195 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
1196 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
1197 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
1198 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
1199 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
1200 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
1202 GType
gtk_wx_cell_renderer_get_type (void);
1204 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
1205 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
1207 struct _GtkWxCellRenderer
1209 GtkCellRenderer parent
;
1212 wxDataViewCustomRenderer
*cell
;
1216 struct _GtkWxCellRendererClass
1218 GtkCellRendererClass cell_parent_class
;
1222 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
1223 static void gtk_wx_cell_renderer_init (
1224 GtkWxCellRenderer
*cell
);
1225 static void gtk_wx_cell_renderer_class_init(
1226 GtkWxCellRendererClass
*klass
);
1227 static void gtk_wx_cell_renderer_finalize (
1229 static void gtk_wx_cell_renderer_get_size (
1230 GtkCellRenderer
*cell
,
1232 GdkRectangle
*rectangle
,
1237 static void gtk_wx_cell_renderer_render (
1238 GtkCellRenderer
*cell
,
1241 GdkRectangle
*background_area
,
1242 GdkRectangle
*cell_area
,
1243 GdkRectangle
*expose_area
,
1244 GtkCellRendererState flags
);
1245 static gboolean
gtk_wx_cell_renderer_activate(
1246 GtkCellRenderer
*cell
,
1250 GdkRectangle
*background_area
,
1251 GdkRectangle
*cell_area
,
1252 GtkCellRendererState flags
);
1253 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1254 GtkCellRenderer
*cell
,
1258 GdkRectangle
*background_area
,
1259 GdkRectangle
*cell_area
,
1260 GtkCellRendererState flags
);
1263 static GObjectClass
*cell_parent_class
= NULL
;
1268 gtk_wx_cell_renderer_get_type (void)
1270 static GType cell_wx_type
= 0;
1274 const GTypeInfo cell_wx_info
=
1276 sizeof (GtkWxCellRendererClass
),
1277 NULL
, /* base_init */
1278 NULL
, /* base_finalize */
1279 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
1280 NULL
, /* class_finalize */
1281 NULL
, /* class_data */
1282 sizeof (GtkWxCellRenderer
),
1283 0, /* n_preallocs */
1284 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
1287 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
1288 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
1291 return cell_wx_type
;
1295 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
1298 cell
->last_click
= 0;
1302 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
1304 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1305 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
1307 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
1309 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
1311 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
1312 cell_class
->render
= gtk_wx_cell_renderer_render
;
1313 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
1314 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
1318 gtk_wx_cell_renderer_finalize (GObject
*object
)
1321 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
1325 gtk_wx_cell_renderer_new (void)
1327 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
1330 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1331 GtkCellRenderer
*renderer
,
1332 GdkEvent
*WXUNUSED(event
),
1335 GdkRectangle
*WXUNUSED(background_area
),
1336 GdkRectangle
*cell_area
,
1337 GtkCellRendererState
WXUNUSED(flags
) )
1339 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1340 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1342 // Renderer doesn't support in-place editing
1343 if (!cell
->HasEditorCtrl())
1346 // An in-place editing control is still around
1347 if (cell
->GetEditorCtrl())
1351 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1357 rect
.x
+= cell_area
->x
;
1358 rect
.y
+= cell_area
->y
;
1359 // rect.width -= renderer->xpad * 2;
1360 // rect.height -= renderer->ypad * 2;
1362 // wxRect renderrect(wxRectFromGDKRect(&rect));
1363 wxRect
renderrect(wxRectFromGDKRect(cell_area
));
1366 item(cell
->GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(path
)));
1368 cell
->StartEditing( item
, renderrect
);
1374 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
1375 GtkWidget
*WXUNUSED(widget
),
1376 GdkRectangle
*cell_area
,
1382 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1383 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1385 wxSize size
= cell
->GetSize();
1387 wxDataViewCtrl
* const ctrl
= cell
->GetOwner()->GetOwner();
1389 // Uniform row height, if specified, overrides the value returned by the
1391 if ( !ctrl
->HasFlag(wxDV_VARIABLE_LINE_HEIGHT
) )
1393 const int uniformHeight
= ctrl
->GTKGetUniformRowHeight();
1394 if ( uniformHeight
> 0 )
1395 size
.y
= uniformHeight
;
1399 gtk_cell_renderer_get_padding(renderer
, &xpad
, &ypad
);
1400 int calc_width
= xpad
* 2 + size
.x
;
1401 int calc_height
= ypad
* 2 + size
.y
;
1408 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
1410 float xalign
, yalign
;
1411 gtk_cell_renderer_get_alignment(renderer
, &xalign
, &yalign
);
1414 *x_offset
= int(xalign
* (cell_area
->width
- calc_width
- 2 * xpad
));
1415 *x_offset
= MAX(*x_offset
, 0) + xpad
;
1419 *y_offset
= int(yalign
* (cell_area
->height
- calc_height
- 2 * ypad
));
1420 *y_offset
= MAX(*y_offset
, 0) + ypad
;
1425 *width
= calc_width
;
1428 *height
= calc_height
;
1432 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
1435 GdkRectangle
*background_area
,
1436 GdkRectangle
*cell_area
,
1437 GdkRectangle
*expose_area
,
1438 GtkCellRendererState flags
)
1441 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1442 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1444 cell
->GTKStashRenderParams(window
, widget
,
1445 background_area
, expose_area
, flags
);
1447 wxRect
rect(wxRectFromGDKRect(cell_area
));
1449 gtk_cell_renderer_get_padding(renderer
, &xpad
, &ypad
);
1450 rect
= rect
.Deflate(xpad
, ypad
);
1452 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
1453 wxWindowDCImpl
*impl
= (wxWindowDCImpl
*) dc
->GetImpl();
1455 // Reinitialize wxWindowDC's GDK window if drawing occurs into a different
1456 // window such as a DnD drop window.
1457 if (window
!= impl
->m_gdkwindow
)
1460 impl
->m_gdkwindow
= window
;
1465 if (flags
& GTK_CELL_RENDERER_SELECTED
)
1466 state
|= wxDATAVIEW_CELL_SELECTED
;
1467 if (flags
& GTK_CELL_RENDERER_PRELIT
)
1468 state
|= wxDATAVIEW_CELL_PRELIT
;
1469 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1470 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1471 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1472 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1473 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
1474 state
|= wxDATAVIEW_CELL_FOCUSED
;
1475 cell
->WXCallRender( rect
, dc
, state
);
1479 gtk_wx_cell_renderer_activate(
1480 GtkCellRenderer
*renderer
,
1484 GdkRectangle
*WXUNUSED(background_area
),
1485 GdkRectangle
*cell_area
,
1486 GtkCellRendererState
WXUNUSED(flags
) )
1488 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1489 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1492 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1498 rect
.x
+= cell_area
->x
;
1499 rect
.y
+= cell_area
->y
;
1501 gtk_cell_renderer_get_padding(renderer
, &xpad
, &ypad
);
1502 rect
.width
-= xpad
* 2;
1503 rect
.height
-= ypad
* 2;
1505 wxRect
renderrect(wxRectFromGDKRect(&rect
));
1507 wxDataViewCtrl
* const ctrl
= cell
->GetOwner()->GetOwner();
1508 wxDataViewModel
*model
= ctrl
->GetModel();
1510 wxDataViewItem
item(ctrl
->GTKPathToItem(wxGtkTreePath(path
)));
1512 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1518 // activated by <ENTER>
1519 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1524 else if (event
->type
== GDK_BUTTON_PRESS
)
1526 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
1527 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
1528 ((int) button_event
->y
) - renderrect
.y
);
1531 if (button_event
->button
== 1)
1533 if (cell
->LeftClick( pt
, renderrect
, model
, item
, model_col
))
1535 // TODO: query system double-click time
1536 if (button_event
->time
- wxrenderer
->last_click
< 400)
1537 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1540 wxrenderer
->last_click
= button_event
->time
;
1548 // ---------------------------------------------------------
1549 // wxGtkDataViewModelNotifier
1550 // ---------------------------------------------------------
1552 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1555 wxGtkDataViewModelNotifier( wxDataViewModel
*wx_model
, wxDataViewCtrlInternal
*internal
);
1556 ~wxGtkDataViewModelNotifier();
1558 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1559 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1560 virtual bool ItemChanged( const wxDataViewItem
&item
);
1561 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int model_column
);
1562 virtual bool Cleared();
1563 virtual void Resort();
1564 virtual bool BeforeReset();
1565 virtual bool AfterReset();
1567 void UpdateLastCount();
1570 wxDataViewModel
*m_wx_model
;
1571 wxDataViewCtrlInternal
*m_internal
;
1574 // ---------------------------------------------------------
1575 // wxGtkDataViewListModelNotifier
1576 // ---------------------------------------------------------
1578 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1579 wxDataViewModel
*wx_model
, wxDataViewCtrlInternal
*internal
)
1581 m_wx_model
= wx_model
;
1582 m_internal
= internal
;
1585 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1591 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1593 m_internal
->ItemAdded( parent
, item
);
1594 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1597 iter
.stamp
= wxgtk_model
->stamp
;
1598 iter
.user_data
= item
.GetID();
1600 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1601 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1602 gtk_tree_model_row_inserted(
1603 GTK_TREE_MODEL(wxgtk_model
), path
, &iter
);
1608 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1610 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1612 // using _get_path for a deleted item cannot be
1615 iter
.stamp
= wxgtk_model
->stamp
;
1616 iter
.user_data
= (gpointer
) item
.GetID();
1617 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1618 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1620 // so get the path from the parent
1621 GtkTreeIter parentIter
;
1622 parentIter
.stamp
= wxgtk_model
->stamp
;
1623 parentIter
.user_data
= (gpointer
) parent
.GetID();
1624 wxGtkTreePath
parentPath(wxgtk_tree_model_get_path(
1625 GTK_TREE_MODEL(wxgtk_model
), &parentIter
));
1627 // and add the final index ourselves
1628 wxGtkTreePath
path(gtk_tree_path_copy(parentPath
));
1629 int index
= m_internal
->GetIndexOf( parent
, item
);
1630 gtk_tree_path_append_index( path
, index
);
1633 gtk_tree_model_row_deleted(
1634 GTK_TREE_MODEL(wxgtk_model
), path
);
1636 m_internal
->ItemDeleted( parent
, item
);
1638 // Did we remove the last child, causing 'parent' to become a leaf?
1639 if ( !m_wx_model
->IsContainer(parent
) )
1641 gtk_tree_model_row_has_child_toggled
1643 GTK_TREE_MODEL(wxgtk_model
),
1652 void wxGtkDataViewModelNotifier::Resort()
1654 m_internal
->Resort();
1657 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1659 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1662 iter
.stamp
= wxgtk_model
->stamp
;
1663 iter
.user_data
= (gpointer
) item
.GetID();
1665 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1666 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1667 gtk_tree_model_row_changed(
1668 GTK_TREE_MODEL(wxgtk_model
), path
, &iter
);
1670 m_internal
->ItemChanged( item
);
1675 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_column
)
1677 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1678 wxDataViewCtrl
*ctrl
= m_internal
->GetOwner();
1680 // This adds GTK+'s missing MVC logic for ValueChanged
1682 for (index
= 0; index
< ctrl
->GetColumnCount(); index
++)
1684 wxDataViewColumn
*column
= ctrl
->GetColumn( index
);
1685 if (column
->GetModelColumn() == model_column
)
1687 GtkTreeView
*widget
= GTK_TREE_VIEW(ctrl
->GtkGetTreeView());
1688 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1690 // Don't attempt to refresh not yet realized tree, it is useless
1691 // and results in GTK errors.
1692 if ( gtk_widget_get_realized(ctrl
->GtkGetTreeView()) )
1696 iter
.stamp
= wxgtk_model
->stamp
;
1697 iter
.user_data
= (gpointer
) item
.GetID();
1698 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1699 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1700 GdkRectangle cell_area
;
1701 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1703 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1704 double d
= gtk_adjustment_get_value( hadjust
);
1705 int xdiff
= (int) d
;
1707 int ydiff
= gcolumn
->button
->allocation
.height
;
1709 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1710 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1713 m_internal
->ValueChanged( item
, model_column
);
1722 bool wxGtkDataViewModelNotifier::BeforeReset()
1724 GtkWidget
*treeview
= m_internal
->GetOwner()->GtkGetTreeView();
1725 gtk_tree_view_set_model( GTK_TREE_VIEW(treeview
), NULL
);
1730 bool wxGtkDataViewModelNotifier::AfterReset()
1732 GtkWidget
*treeview
= m_internal
->GetOwner()->GtkGetTreeView();
1733 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1735 m_internal
->Cleared();
1737 gtk_tree_view_set_model( GTK_TREE_VIEW(treeview
), GTK_TREE_MODEL(wxgtk_model
) );
1742 bool wxGtkDataViewModelNotifier::Cleared()
1744 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1746 // There is no call to tell the model that everything
1747 // has been deleted so call row_deleted() for every
1750 int count
= m_internal
->iter_n_children( NULL
); // number of children of root
1752 GtkTreePath
*path
= gtk_tree_path_new_first(); // points to root
1755 for (i
= 0; i
< count
; i
++)
1756 gtk_tree_model_row_deleted( GTK_TREE_MODEL(wxgtk_model
), path
);
1758 gtk_tree_path_free( path
);
1760 m_internal
->Cleared();
1765 // ---------------------------------------------------------
1766 // wxDataViewRenderer
1767 // ---------------------------------------------------------
1769 static gpointer s_user_data
= NULL
;
1772 wxgtk_cell_editable_editing_done( GtkCellEditable
*WXUNUSED(editable
),
1773 wxDataViewRenderer
*wxrenderer
)
1775 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1776 wxDataViewCtrl
*dv
= column
->GetOwner();
1777 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1778 event
.SetDataViewColumn( column
);
1779 event
.SetModel( dv
->GetModel() );
1780 wxDataViewItem
item( s_user_data
);
1781 event
.SetItem( item
);
1782 dv
->HandleWindowEvent( event
);
1786 wxgtk_renderer_editing_started( GtkCellRenderer
*WXUNUSED(cell
), GtkCellEditable
*editable
,
1787 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1792 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1793 wxDataViewCtrl
*dv
= column
->GetOwner();
1794 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1795 event
.SetDataViewColumn( column
);
1796 event
.SetModel( dv
->GetModel() );
1797 wxDataViewItem
item(dv
->GTKPathToItem(wxGtkTreePath(path
)));
1798 event
.SetItem( item
);
1799 dv
->HandleWindowEvent( event
);
1801 if (GTK_IS_CELL_EDITABLE(editable
))
1803 s_user_data
= item
.GetID();
1805 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1806 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1807 (gpointer
) wxrenderer
);
1813 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1815 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1817 wxDataViewRendererBase( varianttype
, mode
, align
)
1822 // we haven't changed them yet
1823 m_usingDefaultAttrs
= true;
1825 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1826 // after the m_renderer pointer has been initialized
1829 void wxDataViewRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
1831 gtk_tree_view_column_pack_end( column
, m_renderer
, TRUE
/* expand */);
1834 void wxDataViewRenderer::GtkInitHandlers()
1836 if (!gtk_check_version(2,6,0))
1838 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1839 G_CALLBACK (wxgtk_renderer_editing_started
),
1844 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1846 GtkCellRendererMode gtkMode
;
1849 case wxDATAVIEW_CELL_INERT
:
1850 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1853 case wxDATAVIEW_CELL_ACTIVATABLE
:
1854 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1857 case wxDATAVIEW_CELL_EDITABLE
:
1858 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1862 wxFAIL_MSG( "unknown wxDataViewCellMode value" );
1868 // This value is most often ignored in GtkTreeView
1869 GValue gvalue
= { 0, };
1870 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1871 g_value_set_enum( &gvalue
, gtkMode
);
1872 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1873 g_value_unset( &gvalue
);
1876 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1878 wxDataViewCellMode ret
;
1881 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1883 switch (g_value_get_enum(&gvalue
))
1886 wxFAIL_MSG( "unknown GtkCellRendererMode value" );
1887 // fall through (we have to return something)
1889 case GTK_CELL_RENDERER_MODE_INERT
:
1890 ret
= wxDATAVIEW_CELL_INERT
;
1893 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1894 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1897 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1898 ret
= wxDATAVIEW_CELL_EDITABLE
;
1902 g_value_unset( &gvalue
);
1907 void wxDataViewRenderer::GtkApplyAlignment(GtkCellRenderer
*renderer
)
1909 int align
= m_alignment
;
1911 // query alignment from column ?
1915 if (GetOwner() == NULL
)
1918 align
= GetOwner()->GetAlignment();
1919 align
|= wxALIGN_CENTRE_VERTICAL
;
1922 // horizontal alignment:
1924 gfloat xalign
= 0.0;
1925 if (align
& wxALIGN_RIGHT
)
1927 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1930 GValue gvalue
= { 0, };
1931 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1932 g_value_set_float( &gvalue
, xalign
);
1933 g_object_set_property( G_OBJECT(renderer
), "xalign", &gvalue
);
1934 g_value_unset( &gvalue
);
1936 // vertical alignment:
1938 gfloat yalign
= 0.0;
1939 if (align
& wxALIGN_BOTTOM
)
1941 else if (align
& wxALIGN_CENTER_VERTICAL
)
1944 GValue gvalue2
= { 0, };
1945 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1946 g_value_set_float( &gvalue2
, yalign
);
1947 g_object_set_property( G_OBJECT(renderer
), "yalign", &gvalue2
);
1948 g_value_unset( &gvalue2
);
1951 void wxDataViewRenderer::SetAlignment( int align
)
1953 m_alignment
= align
;
1954 GtkUpdateAlignment();
1957 int wxDataViewRenderer::GetAlignment() const
1962 void wxDataViewRenderer::EnableEllipsize(wxEllipsizeMode mode
)
1965 if ( gtk_check_version(2, 6, 0) != NULL
)
1968 GtkCellRendererText
* const rend
= GtkGetTextRenderer();
1972 // we use the same values in wxEllipsizeMode as PangoEllipsizeMode so we
1973 // can just cast between them
1974 GValue gvalue
= { 0, };
1975 g_value_init( &gvalue
, PANGO_TYPE_ELLIPSIZE_MODE
);
1976 g_value_set_enum( &gvalue
, static_cast<PangoEllipsizeMode
>(mode
) );
1977 g_object_set_property( G_OBJECT(rend
), "ellipsize", &gvalue
);
1978 g_value_unset( &gvalue
);
1981 #endif // GTK 2.6/before
1984 wxEllipsizeMode
wxDataViewRenderer::GetEllipsizeMode() const
1987 if ( gtk_check_version(2, 6, 0) != NULL
)
1988 return wxELLIPSIZE_NONE
;
1990 GtkCellRendererText
* const rend
= GtkGetTextRenderer();
1992 return wxELLIPSIZE_NONE
;
1994 GValue gvalue
= { 0, };
1995 g_value_init( &gvalue
, PANGO_TYPE_ELLIPSIZE_MODE
);
1996 g_object_get_property( G_OBJECT(rend
), "ellipsize", &gvalue
);
1998 mode
= static_cast<wxEllipsizeMode
>(g_value_get_enum( &gvalue
));
1999 g_value_unset( &gvalue
);
2003 return wxELLIPSIZE_NONE
;
2004 #endif // GTK 2.6/before
2008 wxDataViewRenderer::GtkOnTextEdited(const char *itempath
, const wxString
& str
)
2010 wxVariant
value(str
);
2011 if (!Validate( value
))
2015 item(GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(itempath
)));
2017 GtkOnCellChanged(value
, item
, GetOwner()->GetModelColumn());
2021 wxDataViewRenderer::GtkOnCellChanged(const wxVariant
& value
,
2022 const wxDataViewItem
& item
,
2025 wxDataViewModel
*model
= GetOwner()->GetOwner()->GetModel();
2026 model
->ChangeValue( value
, item
, col
);
2029 // ---------------------------------------------------------
2030 // wxDataViewTextRenderer
2031 // ---------------------------------------------------------
2036 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*WXUNUSED(renderer
),
2037 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
2039 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) user_data
;
2041 cell
->GtkOnTextEdited(arg1
, wxGTK_CONV_BACK_FONT(
2042 arg2
, cell
->GetOwner()->GetOwner()->GetFont()));
2050 // helper function used by wxDataViewTextRenderer and
2051 // wxDataViewCustomRenderer::RenderText(): it applies the attributes to the
2052 // given text renderer and returns true if anything was done
2053 bool GtkApplyAttr(GtkCellRendererText
*renderer
, const wxDataViewItemAttr
& attr
)
2055 bool usingDefaultAttrs
= true;
2056 if (attr
.HasColour())
2058 const GdkColor
* const gcol
= attr
.GetColour().GetColor();
2060 GValue gvalue
= { 0, };
2061 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2062 g_value_set_boxed( &gvalue
, gcol
);
2063 g_object_set_property( G_OBJECT(renderer
), "foreground_gdk", &gvalue
);
2064 g_value_unset( &gvalue
);
2066 usingDefaultAttrs
= false;
2070 GValue gvalue
= { 0, };
2071 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2072 g_value_set_boolean( &gvalue
, FALSE
);
2073 g_object_set_property( G_OBJECT(renderer
), "foreground-set", &gvalue
);
2074 g_value_unset( &gvalue
);
2077 if (attr
.GetItalic())
2079 GValue gvalue
= { 0, };
2080 g_value_init( &gvalue
, PANGO_TYPE_STYLE
);
2081 g_value_set_enum( &gvalue
, PANGO_STYLE_ITALIC
);
2082 g_object_set_property( G_OBJECT(renderer
), "style", &gvalue
);
2083 g_value_unset( &gvalue
);
2085 usingDefaultAttrs
= false;
2089 GValue gvalue
= { 0, };
2090 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2091 g_value_set_boolean( &gvalue
, FALSE
);
2092 g_object_set_property( G_OBJECT(renderer
), "style-set", &gvalue
);
2093 g_value_unset( &gvalue
);
2099 GValue gvalue
= { 0, };
2100 g_value_init( &gvalue
, PANGO_TYPE_WEIGHT
);
2101 g_value_set_enum( &gvalue
, PANGO_WEIGHT_BOLD
);
2102 g_object_set_property( G_OBJECT(renderer
), "weight", &gvalue
);
2103 g_value_unset( &gvalue
);
2105 usingDefaultAttrs
= false;
2109 GValue gvalue
= { 0, };
2110 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2111 g_value_set_boolean( &gvalue
, FALSE
);
2112 g_object_set_property( G_OBJECT(renderer
), "weight-set", &gvalue
);
2113 g_value_unset( &gvalue
);
2117 if (attr
.HasBackgroundColour())
2119 wxColour colour
= attr
.GetBackgroundColour();
2120 const GdkColor
* const gcol
= colour
.GetColor();
2122 GValue gvalue
= { 0, };
2123 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2124 g_value_set_boxed( &gvalue
, gcol
);
2125 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
2126 g_value_unset( &gvalue
);
2130 GValue gvalue
= { 0, };
2131 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2132 g_value_set_boolean( &gvalue
, FALSE
);
2133 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
2134 g_value_unset( &gvalue
);
2138 return !usingDefaultAttrs
;
2141 } // anonymous namespace
2143 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
2145 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
2147 wxDataViewRenderer( varianttype
, mode
, align
)
2149 GtkWxCellRendererText
*text_renderer
= gtk_wx_cell_renderer_text_new();
2150 text_renderer
->wx_renderer
= this;
2151 m_renderer
= (GtkCellRenderer
*) text_renderer
;
2153 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
2155 GValue gvalue
= { 0, };
2156 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2157 g_value_set_boolean( &gvalue
, true );
2158 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
2159 g_value_unset( &gvalue
);
2161 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2167 SetAlignment(align
);
2170 bool wxDataViewTextRenderer::SetTextValue(const wxString
& str
)
2172 GValue gvalue
= { 0, };
2173 g_value_init( &gvalue
, G_TYPE_STRING
);
2174 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( str
, GetOwner()->GetOwner()->GetFont() ) );
2175 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2176 g_value_unset( &gvalue
);
2181 bool wxDataViewTextRenderer::GetTextValue(wxString
& str
) const
2183 GValue gvalue
= { 0, };
2184 g_value_init( &gvalue
, G_TYPE_STRING
);
2185 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2186 str
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
), const_cast<wxDataViewTextRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
2187 g_value_unset( &gvalue
);
2192 void wxDataViewTextRenderer::SetAlignment( int align
)
2194 wxDataViewRenderer::SetAlignment(align
);
2196 if (gtk_check_version(2,10,0))
2199 // horizontal alignment:
2200 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2201 if (align
& wxALIGN_RIGHT
)
2202 pangoAlign
= PANGO_ALIGN_RIGHT
;
2203 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2204 pangoAlign
= PANGO_ALIGN_CENTER
;
2206 GValue gvalue
= { 0, };
2207 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2208 g_value_set_enum( &gvalue
, pangoAlign
);
2209 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2210 g_value_unset( &gvalue
);
2213 bool wxDataViewTextRenderer::GtkSetAttr(const wxDataViewItemAttr
& attr
)
2215 return GtkApplyAttr(GtkGetTextRenderer(), attr
);
2218 GtkCellRendererText
*wxDataViewTextRenderer::GtkGetTextRenderer() const
2220 return GTK_CELL_RENDERER_TEXT(m_renderer
);
2223 // ---------------------------------------------------------
2224 // wxDataViewBitmapRenderer
2225 // ---------------------------------------------------------
2230 // set "pixbuf" property on the given renderer
2231 void SetPixbufProp(GtkCellRenderer
*renderer
, GdkPixbuf
*pixbuf
)
2233 GValue gvalue
= { 0, };
2234 g_value_init( &gvalue
, G_TYPE_OBJECT
);
2235 g_value_set_object( &gvalue
, pixbuf
);
2236 g_object_set_property( G_OBJECT(renderer
), "pixbuf", &gvalue
);
2237 g_value_unset( &gvalue
);
2240 } // anonymous namespace
2242 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
2244 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
2246 wxDataViewRenderer( varianttype
, mode
, align
)
2248 m_renderer
= gtk_cell_renderer_pixbuf_new();
2251 SetAlignment(align
);
2254 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
2256 if (value
.GetType() == wxT("wxBitmap"))
2261 // GetPixbuf() may create a Pixbuf representation in the wxBitmap
2262 // object (and it will stay there and remain owned by wxBitmap)
2263 SetPixbufProp(m_renderer
, bitmap
.GetPixbuf());
2265 else if (value
.GetType() == wxT("wxIcon"))
2270 SetPixbufProp(m_renderer
, icon
.GetPixbuf());
2280 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2285 // ---------------------------------------------------------
2286 // wxDataViewToggleRenderer
2287 // ---------------------------------------------------------
2290 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
2291 gchar
*path
, gpointer user_data
);
2294 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
2295 gchar
*path
, gpointer user_data
)
2297 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
2300 GValue gvalue
= { 0, };
2301 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2302 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
2303 bool tmp
= g_value_get_boolean( &gvalue
);
2304 g_value_unset( &gvalue
);
2308 wxVariant value
= tmp
;
2309 if (!cell
->Validate( value
))
2312 wxDataViewCtrl
* const ctrl
= cell
->GetOwner()->GetOwner();
2313 wxDataViewModel
*model
= ctrl
->GetModel();
2315 wxDataViewItem
item(ctrl
->GTKPathToItem(wxGtkTreePath(path
)));
2317 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
2319 model
->ChangeValue( value
, item
, model_col
);
2322 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
2324 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
2325 wxDataViewCellMode mode
, int align
) :
2326 wxDataViewRenderer( varianttype
, mode
, align
)
2328 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
2330 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
2332 g_signal_connect_after( m_renderer
, "toggled",
2333 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
2337 GValue gvalue
= { 0, };
2338 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2339 g_value_set_boolean( &gvalue
, false );
2340 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
2341 g_value_unset( &gvalue
);
2345 SetAlignment(align
);
2348 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
2352 GValue gvalue
= { 0, };
2353 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2354 g_value_set_boolean( &gvalue
, tmp
);
2355 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
2356 g_value_unset( &gvalue
);
2361 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
2363 GValue gvalue
= { 0, };
2364 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2365 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
2366 bool tmp
= g_value_get_boolean( &gvalue
);
2367 g_value_unset( &gvalue
);
2374 // ---------------------------------------------------------
2375 // wxDataViewCustomRenderer
2376 // ---------------------------------------------------------
2378 class wxDataViewCtrlDCImpl
: public wxWindowDCImpl
2381 wxDataViewCtrlDCImpl( wxDC
*owner
, wxDataViewCtrl
*window
) :
2382 wxWindowDCImpl( owner
)
2384 GtkWidget
*widget
= window
->m_treeview
;
2390 m_context
= window
->GTKGetPangoDefaultContext();
2391 m_layout
= pango_layout_new( m_context
);
2392 m_fontdesc
= pango_font_description_copy(gtk_widget_get_style(widget
)->font_desc
);
2394 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
2396 // Set m_gdkwindow later
2401 class wxDataViewCtrlDC
: public wxWindowDC
2404 wxDataViewCtrlDC( wxDataViewCtrl
*window
) :
2405 wxWindowDC( new wxDataViewCtrlDCImpl( this, window
) )
2410 // ---------------------------------------------------------
2411 // wxDataViewCustomRenderer
2412 // ---------------------------------------------------------
2414 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
2416 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
2417 wxDataViewCellMode mode
,
2420 : wxDataViewCustomRendererBase( varianttype
, mode
, align
)
2423 m_text_renderer
= NULL
;
2431 void wxDataViewCustomRenderer::GtkInitTextRenderer()
2433 m_text_renderer
= GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new());
2434 g_object_ref_sink(m_text_renderer
);
2436 GtkApplyAlignment(GTK_CELL_RENDERER(m_text_renderer
));
2439 GtkCellRendererText
*wxDataViewCustomRenderer::GtkGetTextRenderer() const
2441 if ( !m_text_renderer
)
2443 // we create it on demand so need to do it even from a const function
2444 const_cast<wxDataViewCustomRenderer
*>(this)->GtkInitTextRenderer();
2447 return m_text_renderer
;
2450 void wxDataViewCustomRenderer::RenderText( const wxString
&text
,
2454 int WXUNUSED(state
) )
2457 GtkCellRendererText
* const textRenderer
= GtkGetTextRenderer();
2459 GValue gvalue
= { 0, };
2460 g_value_init( &gvalue
, G_TYPE_STRING
);
2461 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( text
, GetOwner()->GetOwner()->GetFont() ) );
2462 g_object_set_property( G_OBJECT(textRenderer
), "text", &gvalue
);
2463 g_value_unset( &gvalue
);
2465 GtkApplyAttr(textRenderer
, GetAttr());
2467 GdkRectangle cell_area
;
2468 wxRectToGDKRect(cell
, cell_area
);
2469 cell_area
.x
+= xoffset
;
2470 cell_area
.width
-= xoffset
;
2472 gtk_cell_renderer_render( GTK_CELL_RENDERER(textRenderer
),
2473 m_renderParams
.window
,
2474 m_renderParams
.widget
,
2475 m_renderParams
.background_area
,
2477 m_renderParams
.expose_area
,
2478 (GtkCellRendererState
) m_renderParams
.flags
);
2481 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
2483 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
2484 renderer
->cell
= this;
2486 m_renderer
= (GtkCellRenderer
*) renderer
;
2489 SetAlignment(align
);
2496 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
2501 if (m_text_renderer
)
2502 g_object_unref(m_text_renderer
);
2505 wxDC
*wxDataViewCustomRenderer::GetDC()
2509 if (GetOwner() == NULL
)
2511 if (GetOwner()->GetOwner() == NULL
)
2513 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
2519 // ---------------------------------------------------------
2520 // wxDataViewProgressRenderer
2521 // ---------------------------------------------------------
2523 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
2525 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
2526 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
2527 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
2533 if (!gtk_check_version(2,6,0))
2535 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
2538 SetAlignment(align
);
2541 // We can't initialize the renderer just yet because we don't have the
2542 // pointer to the column that uses this renderer yet and so attempt to
2543 // dereference GetOwner() to get the font that is used as a source of
2544 // encoding in multibyte-to-Unicode conversion in GTKSetLabel() in
2545 // non-Unicode builds would crash. So simply remember to do it later.
2546 if ( !m_label
.empty() )
2547 m_needsToSetLabel
= true;
2549 #endif // !wxUSE_UNICODE
2555 // Use custom cell code
2556 wxDataViewCustomRenderer::Init(mode
, align
);
2560 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
2564 void wxDataViewProgressRenderer::GTKSetLabel()
2566 GValue gvalue
= { 0, };
2567 g_value_init( &gvalue
, G_TYPE_STRING
);
2569 // Take care to not use GetOwner() here if the label is empty, we can be
2570 // called from ctor when GetOwner() is still NULL in this case.
2571 g_value_set_string( &gvalue
,
2572 m_label
.empty() ? ""
2573 : wxGTK_CONV_FONT(m_label
,
2574 GetOwner()->GetOwner()->GetFont())
2576 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2577 g_value_unset( &gvalue
);
2580 m_needsToSetLabel
= false;
2581 #endif // !wxUSE_UNICODE
2584 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
2587 if (!gtk_check_version(2,6,0))
2590 if ( m_needsToSetLabel
)
2592 #endif // !wxUSE_UNICODE
2594 gint tmp
= (long) value
;
2595 GValue gvalue
= { 0, };
2596 g_value_init( &gvalue
, G_TYPE_INT
);
2597 g_value_set_int( &gvalue
, tmp
);
2598 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
2599 g_value_unset( &gvalue
);
2604 m_value
= (long) value
;
2606 if (m_value
< 0) m_value
= 0;
2607 if (m_value
> 100) m_value
= 100;
2613 bool wxDataViewProgressRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2618 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
2620 double pct
= (double)m_value
/ 100.0;
2622 bar
.width
= (int)(cell
.width
* pct
);
2623 dc
->SetPen( *wxTRANSPARENT_PEN
);
2624 dc
->SetBrush( *wxBLUE_BRUSH
);
2625 dc
->DrawRectangle( bar
);
2627 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
2628 dc
->SetPen( *wxBLACK_PEN
);
2629 dc
->DrawRectangle( cell
);
2634 wxSize
wxDataViewProgressRenderer::GetSize() const
2636 return wxSize(40,12);
2639 // -------------------------------------
2640 // wxDataViewChoiceRenderer
2641 // -------------------------------------
2643 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
&choices
,
2644 wxDataViewCellMode mode
, int alignment
) :
2645 wxDataViewCustomRenderer( "string", mode
, alignment
, true )
2647 m_choices
= choices
;
2650 if (!gtk_check_version(2,6,0))
2652 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_combo_new();
2654 GtkListStore
*store
= gtk_list_store_new( 1, G_TYPE_STRING
);
2655 for (size_t n
= 0; n
< m_choices
.GetCount(); n
++)
2657 gtk_list_store_insert_with_values(
2659 static_cast<const char *>(m_choices
[n
].utf8_str()), -1 );
2662 g_object_set (m_renderer
,
2668 bool editable
= (mode
& wxDATAVIEW_CELL_EDITABLE
);
2669 g_object_set (m_renderer
, "editable", editable
, NULL
);
2671 SetAlignment(alignment
);
2673 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2680 // Use custom cell code
2681 wxDataViewCustomRenderer::Init(mode
, alignment
);
2685 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
2687 RenderText( m_data
, 0, rect
, dc
, state
);
2691 wxSize
wxDataViewChoiceRenderer::GetSize() const
2693 return wxSize(70,20);
2696 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
2700 if (!gtk_check_version(2,6,0))
2702 GValue gvalue
= { 0, };
2703 g_value_init( &gvalue
, G_TYPE_STRING
);
2704 g_value_set_string(&gvalue
,
2705 wxGTK_CONV_FONT(value
.GetString(),
2706 GetOwner()->GetOwner()->GetFont()));
2707 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2708 g_value_unset( &gvalue
);
2712 m_data
= value
.GetString();
2717 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
2720 if (!gtk_check_version(2,6,0))
2722 GValue gvalue
= { 0, };
2723 g_value_init( &gvalue
, G_TYPE_STRING
);
2724 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2725 wxString temp
= wxGTK_CONV_BACK_FONT(g_value_get_string(&gvalue
),
2726 GetOwner()->GetOwner()->GetFont());
2727 g_value_unset( &gvalue
);
2730 //wxPrintf( "temp %s\n", temp );
2731 // TODO: remove this code
2740 void wxDataViewChoiceRenderer::SetAlignment( int align
)
2742 wxDataViewCustomRenderer::SetAlignment(align
);
2744 if (gtk_check_version(2,10,0))
2747 // horizontal alignment:
2748 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2749 if (align
& wxALIGN_RIGHT
)
2750 pangoAlign
= PANGO_ALIGN_RIGHT
;
2751 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2752 pangoAlign
= PANGO_ALIGN_CENTER
;
2754 GValue gvalue
= { 0, };
2755 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2756 g_value_set_enum( &gvalue
, pangoAlign
);
2757 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2758 g_value_unset( &gvalue
);
2761 // ----------------------------------------------------------------------------
2762 // wxDataViewChoiceByIndexRenderer
2763 // ----------------------------------------------------------------------------
2765 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
2766 wxDataViewCellMode mode
, int alignment
) :
2767 wxDataViewChoiceRenderer( choices
, mode
, alignment
)
2771 void wxDataViewChoiceByIndexRenderer::GtkOnTextEdited(const char *itempath
, const wxString
& str
)
2773 wxVariant
value( (long) GetChoices().Index( str
) );
2775 if (!Validate( value
))
2779 item(GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(itempath
)));
2781 GtkOnCellChanged(value
, item
, GetOwner()->GetModelColumn());
2784 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant
&value
)
2786 wxVariant string_value
= GetChoice( value
.GetLong() );
2787 return wxDataViewChoiceRenderer::SetValue( string_value
);
2790 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant
&value
) const
2792 wxVariant string_value
;
2793 if (!wxDataViewChoiceRenderer::GetValue( string_value
))
2796 value
= (long) GetChoices().Index( string_value
.GetString() );
2800 // ---------------------------------------------------------
2801 // wxDataViewDateRenderer
2802 // ---------------------------------------------------------
2804 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
2807 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
2808 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
2809 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
2814 m_cal
= new wxCalendarCtrl( this, -1, *value
);
2815 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
2816 sizer
->Add( m_cal
, 1, wxGROW
);
2821 virtual void OnDismiss()
2825 void OnCalendar( wxCalendarEvent
&event
);
2827 wxCalendarCtrl
*m_cal
;
2828 wxDataViewModel
*m_model
;
2829 wxDataViewItem m_item
;
2833 DECLARE_EVENT_TABLE()
2836 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
2837 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
2840 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
2842 m_model
->ChangeValue( event
.GetDate(), m_item
, m_col
);
2846 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
2848 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
2849 wxDataViewCellMode mode
, int align
) :
2850 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2853 SetAlignment(align
);
2856 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
2858 m_date
= value
.GetDateTime();
2863 bool wxDataViewDateRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2868 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2870 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
2871 wxString tmp
= m_date
.FormatDate();
2872 RenderText( tmp
, 0, cell
, dc
, state
);
2876 wxSize
wxDataViewDateRenderer::GetSize() const
2878 wxString tmp
= m_date
.FormatDate();
2880 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
2881 return wxSize(x
,y
+d
);
2884 bool wxDataViewDateRenderer::Activate( const wxRect
& WXUNUSED(cell
), wxDataViewModel
*model
,
2885 const wxDataViewItem
&item
, unsigned int col
)
2888 model
->GetValue( variant
, item
, col
);
2889 wxDateTime value
= variant
.GetDateTime();
2891 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
2892 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
2893 wxPoint pos
= wxGetMousePosition();
2896 popup
->Popup( popup
->m_cal
);
2902 // ---------------------------------------------------------
2903 // wxDataViewIconTextRenderer
2904 // ---------------------------------------------------------
2906 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
2908 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer
2910 const wxString
&varianttype
,
2911 wxDataViewCellMode mode
,
2914 : wxDataViewTextRenderer(varianttype
, mode
, align
)
2916 m_rendererIcon
= gtk_cell_renderer_pixbuf_new();
2919 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2923 void wxDataViewIconTextRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
2925 // add the icon renderer first
2926 gtk_tree_view_column_pack_start(column
, m_rendererIcon
, FALSE
/* !expand */);
2928 // add the text renderer too
2929 wxDataViewRenderer::GtkPackIntoColumn(column
);
2932 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
2936 SetTextValue(m_value
.GetText());
2937 SetPixbufProp(m_rendererIcon
, m_value
.GetIcon().GetPixbuf());
2942 bool wxDataViewIconTextRenderer::GetValue(wxVariant
& value
) const
2945 if ( !GetTextValue(str
) )
2948 // user doesn't have any way to edit the icon so leave it unchanged
2949 value
<< wxDataViewIconText(str
, m_value
.GetIcon());
2955 wxDataViewIconTextRenderer::GtkOnCellChanged(const wxVariant
& value
,
2956 const wxDataViewItem
& item
,
2959 // we receive just the text part of our value as it's the only one which
2960 // can be edited, but we need the full wxDataViewIconText value for the
2962 wxVariant valueIconText
;
2963 valueIconText
<< wxDataViewIconText(value
.GetString(), m_value
.GetIcon());
2964 wxDataViewTextRenderer::GtkOnCellChanged(valueIconText
, item
, col
);
2967 // ---------------------------------------------------------
2969 // ---------------------------------------------------------
2973 gtk_dataview_header_button_press_callback( GtkWidget
*WXUNUSED(widget
),
2974 GdkEventButton
*gdk_event
,
2975 wxDataViewColumn
*column
)
2977 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
2980 if (gdk_event
->button
== 1)
2982 gs_lastLeftClickHeader
= column
;
2984 wxDataViewCtrl
*dv
= column
->GetOwner();
2985 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
2986 event
.SetDataViewColumn( column
);
2987 event
.SetModel( dv
->GetModel() );
2988 if (dv
->HandleWindowEvent( event
))
2992 if (gdk_event
->button
== 3)
2994 wxDataViewCtrl
*dv
= column
->GetOwner();
2995 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
2996 event
.SetDataViewColumn( column
);
2997 event
.SetModel( dv
->GetModel() );
2998 if (dv
->HandleWindowEvent( event
))
3008 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*WXUNUSED(column
),
3009 GtkCellRenderer
*renderer
,
3010 GtkTreeModel
*model
,
3014 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
3015 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
3017 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
3019 wxDataViewItem
item( (void*) iter
->user_data
);
3021 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
3023 if (!wx_model
->IsVirtualListModel())
3026 if (wx_model
->IsContainer( item
))
3028 visible
= wx_model
->HasContainerColumns( item
) ||
3029 (cell
->GetOwner()->GetModelColumn() == 0);
3036 GValue gvalue
= { 0, };
3037 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
3038 g_value_set_boolean( &gvalue
, visible
);
3039 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
3040 g_value_unset( &gvalue
);
3047 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
3049 if (value
.GetType() != cell
->GetVariantType())
3051 wxLogError( wxT("Wrong type, required: %s but: %s"),
3052 value
.GetType().c_str(),
3053 cell
->GetVariantType().c_str() );
3056 cell
->SetValue( value
);
3058 // deal with disabled items
3059 bool enabled
= wx_model
->IsEnabled( item
, cell
->GetOwner()->GetModelColumn() );
3061 // a) this sets the appearance to disabled grey
3062 GValue gvalue
= { 0, };
3063 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
3064 g_value_set_boolean( &gvalue
, enabled
);
3065 g_object_set_property( G_OBJECT(renderer
), "sensitive", &gvalue
);
3066 g_value_unset( &gvalue
);
3068 // b) this actually disables the control/renderer
3070 cell
->SetMode( cell
->GtkGetMode() );
3072 cell
->SetMode( wxDATAVIEW_CELL_INERT
);
3075 // deal with attributes: if the renderer doesn't support them at all, we
3076 // don't even need to query the model for them
3077 if ( !cell
->GtkSupportsAttrs() )
3080 // it can support attributes so check if this item has any
3081 wxDataViewItemAttr attr
;
3082 if ( wx_model
->GetAttr( item
, cell
->GetOwner()->GetModelColumn(), attr
)
3083 || !cell
->GtkIsUsingDefaultAttrs() )
3085 bool usingDefaultAttrs
= !cell
->GtkSetAttr(attr
);
3086 cell
->GtkSetUsingDefaultAttrs(usingDefaultAttrs
);
3088 // else: no custom attributes specified and we're already using the default
3089 // ones -- nothing to do
3095 #include <wx/listimpl.cpp>
3096 WX_DEFINE_LIST(wxDataViewColumnList
)
3098 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
3099 unsigned int model_column
, int width
,
3100 wxAlignment align
, int flags
)
3101 : wxDataViewColumnBase( cell
, model_column
)
3103 Init( align
, flags
, width
);
3108 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
3109 unsigned int model_column
, int width
,
3110 wxAlignment align
, int flags
)
3111 : wxDataViewColumnBase( bitmap
, cell
, model_column
)
3113 Init( align
, flags
, width
);
3115 SetBitmap( bitmap
);
3118 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
3120 m_isConnected
= false;
3122 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
3123 m_column
= (GtkWidget
*) column
;
3126 SetAlignment( align
);
3130 // Create container for icon and label
3131 GtkWidget
*box
= gtk_hbox_new( FALSE
, 1 );
3132 gtk_widget_show( box
);
3133 // gtk_container_set_border_width((GtkContainer*)box, 2);
3134 m_image
= gtk_image_new();
3135 gtk_box_pack_start(GTK_BOX(box
), m_image
, FALSE
, FALSE
, 1);
3136 m_label
= gtk_label_new("");
3137 gtk_box_pack_end( GTK_BOX(box
), GTK_WIDGET(m_label
), FALSE
, FALSE
, 1 );
3138 gtk_tree_view_column_set_widget( column
, box
);
3140 wxDataViewRenderer
* const colRenderer
= GetRenderer();
3141 GtkCellRenderer
* const cellRenderer
= colRenderer
->GetGtkHandle();
3143 colRenderer
->GtkPackIntoColumn(column
);
3145 gtk_tree_view_column_set_cell_data_func( column
, cellRenderer
,
3146 wxGtkTreeCellDataFunc
, (gpointer
) colRenderer
, NULL
);
3149 void wxDataViewColumn::OnInternalIdle()
3154 if (gtk_widget_get_realized(GetOwner()->m_treeview
))
3156 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3159 g_signal_connect(column
->button
, "button_press_event",
3160 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
3162 // otherwise the event will be blocked by GTK+
3163 gtk_tree_view_column_set_clickable( column
, TRUE
);
3165 m_isConnected
= true;
3170 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
3172 wxDataViewColumnBase::SetOwner( owner
);
3174 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3176 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
3179 void wxDataViewColumn::SetTitle( const wxString
&title
)
3181 wxDataViewCtrl
*ctrl
= GetOwner();
3182 gtk_label_set_text( GTK_LABEL(m_label
), ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
3183 : wxGTK_CONV_SYS(title
) );
3185 gtk_widget_hide( m_label
);
3187 gtk_widget_show( m_label
);
3190 wxString
wxDataViewColumn::GetTitle() const
3192 return wxGTK_CONV_BACK_FONT(
3193 gtk_label_get_text( GTK_LABEL(m_label
) ),
3194 GetOwner()->GetFont()
3198 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
3200 wxDataViewColumnBase::SetBitmap( bitmap
);
3204 GtkImage
*gtk_image
= GTK_IMAGE(m_image
);
3206 GdkBitmap
*mask
= NULL
;
3207 if (bitmap
.GetMask())
3208 mask
= bitmap
.GetMask()->GetBitmap();
3210 if (bitmap
.HasPixbuf())
3212 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
3213 bitmap
.GetPixbuf());
3217 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
3218 bitmap
.GetPixmap(), mask
);
3220 gtk_widget_show( m_image
);
3224 gtk_widget_hide( m_image
);
3228 void wxDataViewColumn::SetHidden( bool hidden
)
3230 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
3233 void wxDataViewColumn::SetResizeable( bool resizable
)
3235 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizable
);
3238 void wxDataViewColumn::SetAlignment( wxAlignment align
)
3240 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3242 gfloat xalign
= 0.0;
3243 if (align
== wxALIGN_RIGHT
)
3245 if (align
== wxALIGN_CENTER_HORIZONTAL
||
3246 align
== wxALIGN_CENTER
)
3249 gtk_tree_view_column_set_alignment( column
, xalign
);
3251 if (m_renderer
&& m_renderer
->GetAlignment() == -1)
3252 m_renderer
->GtkUpdateAlignment();
3255 wxAlignment
wxDataViewColumn::GetAlignment() const
3257 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
3260 return wxALIGN_RIGHT
;
3262 return wxALIGN_CENTER_HORIZONTAL
;
3264 return wxALIGN_LEFT
;
3267 void wxDataViewColumn::SetSortable( bool sortable
)
3269 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3273 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
3277 gtk_tree_view_column_set_sort_column_id( column
, -1 );
3278 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
3279 gtk_tree_view_column_set_clickable( column
, FALSE
);
3283 bool wxDataViewColumn::IsSortable() const
3285 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3286 return gtk_tree_view_column_get_clickable( column
);
3289 void wxDataViewColumn::SetAsSortKey( bool WXUNUSED(sort
) )
3291 // it might not make sense to have this function in wxHeaderColumn at
3292 // all in fact, changing of the sort order should only be done using the
3293 // associated control API
3294 wxFAIL_MSG( "not implemented" );
3297 bool wxDataViewColumn::IsSortKey() const
3299 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3300 return gtk_tree_view_column_get_sort_indicator( column
);
3303 bool wxDataViewColumn::IsResizeable() const
3305 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3306 return gtk_tree_view_column_get_resizable( column
);
3309 bool wxDataViewColumn::IsHidden() const
3311 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3312 return !gtk_tree_view_column_get_visible( column
);
3315 void wxDataViewColumn::SetSortOrder( bool ascending
)
3317 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3320 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
3322 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
3324 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
3327 bool wxDataViewColumn::IsSortOrderAscending() const
3329 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3331 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
3334 void wxDataViewColumn::SetMinWidth( int width
)
3336 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
3339 int wxDataViewColumn::GetMinWidth() const
3341 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
3344 int wxDataViewColumn::GetWidth() const
3346 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
3349 void wxDataViewColumn::SetWidth( int width
)
3351 if ( width
== wxCOL_WIDTH_AUTOSIZE
)
3353 // NB: this disables user resizing
3354 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
3358 if ( width
== wxCOL_WIDTH_DEFAULT
)
3360 // TODO find a better calculation
3361 width
= wxDVC_DEFAULT_WIDTH
;
3364 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
3365 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
3369 void wxDataViewColumn::SetReorderable( bool reorderable
)
3371 gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column
), reorderable
);
3374 bool wxDataViewColumn::IsReorderable() const
3376 return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column
) );
3379 //-----------------------------------------------------------------------------
3380 // wxGtkTreeModelNode
3381 //-----------------------------------------------------------------------------
3384 class wxGtkTreeModelChildWithPos
3392 int wxGtkTreeModelChildWithPosCmp( const void* data1
, const void* data2
, const void* user_data
)
3394 const wxGtkTreeModelChildWithPos
* child1
= (const wxGtkTreeModelChildWithPos
*) data1
;
3395 const wxGtkTreeModelChildWithPos
* child2
= (const wxGtkTreeModelChildWithPos
*) data2
;
3396 const wxDataViewCtrlInternal
*internal
= (const wxDataViewCtrlInternal
*) user_data
;
3397 int ret
= internal
->GetDataViewModel()->Compare( child1
->id
, child2
->id
,
3398 internal
->GetSortColumn(), (internal
->GetSortOrder() == GTK_SORT_DESCENDING
) );
3404 int LINKAGEMODE
wxGtkTreeModelChildPtrCmp( void*** data1
, void*** data2
)
3406 return gs_internal
->GetDataViewModel()->Compare( wxDataViewItem(**data1
), wxDataViewItem(**data2
),
3407 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
3410 WX_DEFINE_ARRAY_PTR( void**, wxGtkTreeModelChildrenPtr
);
3413 void wxGtkTreeModelNode::Resort()
3415 size_t child_count
= GetChildCount();
3416 if (child_count
== 0)
3419 size_t node_count
= GetNodesCount();
3421 if (child_count
== 1)
3423 if (node_count
== 1)
3425 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
3431 gint
*new_order
= new gint
[child_count
];
3434 // m_children has the original *void
3435 // ptrs points to these
3436 wxGtkTreeModelChildrenPtr ptrs
;
3438 for (i
= 0; i
< child_count
; i
++)
3439 ptrs
.Add( &(m_children
[i
]) );
3441 gs_internal
= m_internal
;
3442 ptrs
.Sort( &wxGtkTreeModelChildPtrCmp
);
3444 wxGtkTreeModelChildren temp
;
3445 void** base_ptr
= &(m_children
[0]);
3446 // Transfer positions to new_order array and
3448 for (i
= 0; i
< child_count
; i
++)
3450 new_order
[i
] = ptrs
[i
] - base_ptr
;
3451 temp
.Add( *ptrs
[i
] );
3454 // Transfer IDs back to m_children
3456 WX_APPEND_ARRAY( temp
, m_children
);
3461 // Build up array with IDs and original positions
3462 wxGtkTreeModelChildWithPos
* temp
= new wxGtkTreeModelChildWithPos
[child_count
];
3464 for (i
= 0; i
< child_count
; i
++)
3467 temp
[i
].id
= m_children
[i
];
3469 // Sort array keeping original positions
3470 wxQsort( temp
, child_count
, sizeof(wxGtkTreeModelChildWithPos
),
3471 &wxGtkTreeModelChildWithPosCmp
, m_internal
);
3472 // Transfer positions to new_order array and
3473 // IDs to m_children
3475 for (i
= 0; i
< child_count
; i
++)
3477 new_order
[i
] = temp
[i
].pos
;
3478 m_children
.Add( temp
[i
].id
);
3487 wxGtkTreeModelChildren temp
;
3488 WX_APPEND_ARRAY( temp
, m_children
);
3490 gs_internal
= m_internal
;
3491 m_children
.Sort( &wxGtkTreeModelChildCmp
);
3494 for (pos
= 0; pos
< child_count
; pos
++)
3496 void *id
= m_children
.Item( pos
);
3497 int old_pos
= temp
.Index( id
);
3498 new_order
[pos
] = old_pos
;
3502 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
3505 iter
.user_data
= GetItem().GetID();
3506 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
3508 gtk_tree_model_rows_reordered( gtk_tree_model
,
3509 wxGtkTreePath(m_internal
->get_path(&iter
)), &iter
, new_order
);
3511 delete [] new_order
;
3514 for (pos
= 0; pos
< node_count
; pos
++)
3516 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
3521 //-----------------------------------------------------------------------------
3522 // wxDataViewCtrlInternal
3523 //-----------------------------------------------------------------------------
3525 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
)
3528 m_wx_model
= wx_model
;
3532 m_sort_order
= GTK_SORT_ASCENDING
;
3534 m_dataview_sort_column
= NULL
;
3536 m_dragDataObject
= NULL
;
3537 m_dropDataObject
= NULL
;
3541 m_gtk_model
= wxgtk_tree_model_new();
3542 m_gtk_model
->internal
= this;
3544 m_notifier
= new wxGtkDataViewModelNotifier( wx_model
, this );
3546 wx_model
->AddNotifier( m_notifier
);
3548 // g_object_unref( gtk_model ); ???
3550 if (!m_wx_model
->IsVirtualListModel())
3553 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->GtkGetTreeView()), GTK_TREE_MODEL(m_gtk_model
) );
3556 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
3558 m_wx_model
->RemoveNotifier( m_notifier
);
3560 // remove the model from the GtkTreeView before it gets destroyed
3561 gtk_tree_view_set_model( GTK_TREE_VIEW( m_owner
->GtkGetTreeView() ), NULL
);
3563 g_object_unref( m_gtk_model
);
3565 delete m_dragDataObject
;
3566 delete m_dropDataObject
;
3569 void wxDataViewCtrlInternal::ScheduleRefresh()
3574 void wxDataViewCtrlInternal::OnInternalIdle()
3578 GtkWidget
*widget
= m_owner
->GtkGetTreeView();
3579 gtk_widget_queue_draw( widget
);
3584 void wxDataViewCtrlInternal::InitTree()
3586 wxDataViewItem item
;
3587 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
3589 BuildBranch( m_root
);
3592 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
3594 if (node
->GetChildCount() == 0)
3596 wxDataViewItemArray children
;
3597 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
3600 for (pos
= 0; pos
< count
; pos
++)
3602 wxDataViewItem child
= children
[pos
];
3604 if (m_wx_model
->IsContainer( child
))
3605 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
3607 node
->AddLeaf( child
.GetID() );
3609 // Don't send any events here
3616 bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat
&format
)
3618 wxGtkString
atom_str( gdk_atom_name( format
) );
3619 m_dragSourceTargetEntryTarget
= wxCharBuffer( atom_str
);
3621 m_dragSourceTargetEntry
.target
= m_dragSourceTargetEntryTarget
.data();
3622 m_dragSourceTargetEntry
.flags
= 0;
3623 m_dragSourceTargetEntry
.info
= static_cast<guint
>(-1);
3625 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3626 GDK_BUTTON1_MASK
, &m_dragSourceTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3631 bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat
&format
)
3633 wxGtkString
atom_str( gdk_atom_name( format
) );
3634 m_dropTargetTargetEntryTarget
= wxCharBuffer( atom_str
);
3636 m_dropTargetTargetEntry
.target
= m_dropTargetTargetEntryTarget
.data();
3637 m_dropTargetTargetEntry
.flags
= 0;
3638 m_dropTargetTargetEntry
.info
= static_cast<guint
>(-1);
3640 gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3641 &m_dropTargetTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3646 gboolean
wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource
*WXUNUSED(drag_source
),
3649 delete m_dragDataObject
;
3650 m_dragDataObject
= NULL
;
3652 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3656 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3657 event
.SetEventObject( m_owner
);
3658 event
.SetItem( item
);
3659 event
.SetModel( m_wx_model
);
3661 gtk_widget_get_pointer(m_owner
->GtkGetTreeView(), &x
, &y
);
3662 event
.SetPosition(x
, y
);
3663 if (!m_owner
->HandleWindowEvent( event
))
3666 if (!event
.IsAllowed())
3669 wxDataObject
*obj
= event
.GetDataObject();
3673 m_dragDataObject
= obj
;
3679 wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource
*WXUNUSED(drag_source
),
3680 GtkTreePath
*WXUNUSED(path
))
3685 gboolean
wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource
*WXUNUSED(drag_source
),
3686 GtkTreePath
*path
, GtkSelectionData
*selection_data
)
3688 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3692 GdkAtom target
= gtk_selection_data_get_target(selection_data
);
3693 if (!m_dragDataObject
->IsSupported(target
))
3696 size_t size
= m_dragDataObject
->GetDataSize(target
);
3700 void *buf
= malloc( size
);
3702 gboolean res
= FALSE
;
3703 if (m_dragDataObject
->GetDataHere(target
, buf
))
3707 gtk_selection_data_set(selection_data
, target
,
3708 8, (const guchar
*) buf
, size
);
3717 wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3719 GtkSelectionData
*selection_data
)
3721 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3725 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
3726 event
.SetEventObject( m_owner
);
3727 event
.SetItem( item
);
3728 event
.SetModel( m_wx_model
);
3729 event
.SetDataFormat(gtk_selection_data_get_target(selection_data
));
3730 event
.SetDataSize(gtk_selection_data_get_length(selection_data
));
3731 event
.SetDataBuffer(const_cast<guchar
*>(gtk_selection_data_get_data(selection_data
)));
3732 if (!m_owner
->HandleWindowEvent( event
))
3735 if (!event
.IsAllowed())
3742 wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3744 GtkSelectionData
*selection_data
)
3746 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3750 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
3751 event
.SetEventObject( m_owner
);
3752 event
.SetItem( item
);
3753 event
.SetModel( m_wx_model
);
3754 event
.SetDataFormat(gtk_selection_data_get_target(selection_data
));
3755 if (!m_owner
->HandleWindowEvent( event
))
3758 if (!event
.IsAllowed())
3764 // notifications from wxDataViewModel
3766 bool wxDataViewCtrlInternal::Cleared()
3781 void wxDataViewCtrlInternal::Resort()
3783 if (!m_wx_model
->IsVirtualListModel())
3789 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3791 if (!m_wx_model
->IsVirtualListModel())
3793 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3794 wxCHECK_MSG(parent_node
, false,
3795 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3797 wxDataViewItemArray siblings
;
3798 m_wx_model
->GetChildren(parent
, siblings
);
3799 int itemPos
= siblings
.Index(item
, /*fromEnd=*/true);
3800 wxCHECK_MSG( itemPos
!= wxNOT_FOUND
, false, "adding non-existent item?" );
3802 if (m_wx_model
->IsContainer( item
))
3803 parent_node
->InsertNode( new wxGtkTreeModelNode( parent_node
, item
, this ), itemPos
);
3805 parent_node
->InsertLeaf( item
.GetID(), itemPos
);
3813 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3815 if (!m_wx_model
->IsVirtualListModel())
3817 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3818 wxASSERT_MSG(parent_node
,
3819 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3821 parent_node
->DeleteChild( item
.GetID() );
3829 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
3831 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3832 event
.SetEventObject( m_owner
);
3833 event
.SetModel( m_owner
->GetModel() );
3834 event
.SetItem( item
);
3835 m_owner
->HandleWindowEvent( event
);
3840 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int view_column
)
3842 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3843 event
.SetEventObject( m_owner
);
3844 event
.SetModel( m_owner
->GetModel() );
3845 event
.SetColumn( view_column
);
3846 event
.SetDataViewColumn( GetOwner()->GetColumn(view_column
) );
3847 event
.SetItem( item
);
3848 m_owner
->HandleWindowEvent( event
);
3855 GtkTreeModelFlags
wxDataViewCtrlInternal::get_flags()
3859 if ( m_wx_model
->IsListModel() )
3860 flags
|= GTK_TREE_MODEL_LIST_ONLY
;
3862 if ( !m_wx_model
->IsVirtualListModel() )
3863 flags
|= GTK_TREE_MODEL_ITERS_PERSIST
;
3865 return GtkTreeModelFlags(flags
);
3868 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
3871 if (m_wx_model
->IsVirtualListModel())
3873 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3875 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
3877 if (i
>= wx_model
->GetCount())
3880 iter
->stamp
= m_gtk_model
->stamp
;
3881 // user_data is just the index +1
3882 iter
->user_data
= (gpointer
) (i
+1);
3888 int depth
= gtk_tree_path_get_depth( path
);
3890 wxGtkTreeModelNode
*node
= m_root
;
3893 for (i
= 0; i
< depth
; i
++)
3895 BuildBranch( node
);
3897 gint pos
= gtk_tree_path_get_indices (path
)[i
];
3898 if (pos
< 0) return FALSE
;
3899 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
3901 void* id
= node
->GetChildren().Item( (size_t) pos
);
3905 iter
->stamp
= m_gtk_model
->stamp
;
3906 iter
->user_data
= id
;
3910 size_t count
= node
->GetNodes().GetCount();
3912 for (pos2
= 0; pos2
< count
; pos2
++)
3914 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
3915 if (child_node
->GetItem().GetID() == id
)
3927 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
3929 // When this is called from ItemDeleted(), the item is already
3930 // deleted in the model.
3932 GtkTreePath
*retval
= gtk_tree_path_new ();
3934 if (m_wx_model
->IsVirtualListModel())
3936 // iter is root, add nothing
3937 if (!iter
->user_data
)
3940 // user_data is just the index +1
3941 int i
= ( (wxUIntPtr
) iter
->user_data
) -1;
3942 gtk_tree_path_append_index (retval
, i
);
3946 void *id
= iter
->user_data
;
3948 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
3951 int pos
= node
->GetChildren().Index( id
);
3953 gtk_tree_path_prepend_index( retval
, pos
);
3955 id
= node
->GetItem().GetID();
3956 node
= node
->GetParent();
3963 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
3965 if (m_wx_model
->IsVirtualListModel())
3967 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3969 // user_data is just the index +1
3970 int n
= ( (wxUIntPtr
) iter
->user_data
) -1;
3974 iter
->user_data
= NULL
;
3978 if (n
>= (int) wx_model
->GetCount()-1)
3980 iter
->user_data
= NULL
;
3984 // user_data is just the index +1 (+2 because we need the next)
3985 iter
->user_data
= (gpointer
) (n
+2);
3989 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
3990 if( parent
== NULL
)
3992 iter
->user_data
= NULL
;
3996 int pos
= parent
->GetChildren().Index( iter
->user_data
);
3998 if (pos
== (int) parent
->GetChildCount()-1)
4000 iter
->user_data
= NULL
;
4004 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
4010 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
4012 if (m_wx_model
->IsVirtualListModel())
4014 // this is a list, nodes have no children
4018 iter
->stamp
= m_gtk_model
->stamp
;
4019 iter
->user_data
= (gpointer
) 1;
4027 if (m_root
->GetChildCount() == 0) return FALSE
;
4028 iter
->stamp
= m_gtk_model
->stamp
;
4029 iter
->user_data
= (gpointer
) m_root
->GetChildren().Item( 0 );
4034 wxDataViewItem item
;
4036 item
= wxDataViewItem( (void*) parent
->user_data
);
4038 if (!m_wx_model
->IsContainer( item
))
4041 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
4042 wxASSERT_MSG(parent_node
,
4043 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
4045 BuildBranch( parent_node
);
4047 if (parent_node
->GetChildCount() == 0)
4050 iter
->stamp
= m_gtk_model
->stamp
;
4051 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
4057 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
4059 if (m_wx_model
->IsVirtualListModel())
4061 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
4064 return (wx_model
->GetCount() > 0);
4066 // this is a list, nodes have no children
4072 return (m_root
->GetChildCount() > 0);
4074 wxDataViewItem
item( (void*) iter
->user_data
);
4076 bool is_container
= m_wx_model
->IsContainer( item
);
4081 wxGtkTreeModelNode
*node
= FindNode( iter
);
4083 "Did you forget a call to ItemAdded()? The iterator is unknown to the wxGtkTreeModel");
4085 BuildBranch( node
);
4087 return (node
->GetChildCount() > 0);
4091 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
4093 if (m_wx_model
->IsVirtualListModel())
4095 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
4098 return (gint
) wx_model
->GetCount();
4105 return m_root
->GetChildCount();
4107 wxDataViewItem
item( (void*) iter
->user_data
);
4109 if (!m_wx_model
->IsContainer( item
))
4112 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
4113 wxASSERT_MSG(parent_node
,
4114 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
4116 BuildBranch( parent_node
);
4118 return parent_node
->GetChildCount();
4122 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
4124 if (m_wx_model
->IsVirtualListModel())
4126 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
4134 if (n
>= (gint
) wx_model
->GetCount())
4137 iter
->stamp
= m_gtk_model
->stamp
;
4138 // user_data is just the index +1
4139 iter
->user_data
= (gpointer
) (n
+1);
4146 if (parent
) id
= (void*) parent
->user_data
;
4147 wxDataViewItem
item( id
);
4149 if (!m_wx_model
->IsContainer( item
))
4152 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
4153 wxASSERT_MSG(parent_node
,
4154 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
4156 BuildBranch( parent_node
);
4158 iter
->stamp
= m_gtk_model
->stamp
;
4159 iter
->user_data
= parent_node
->GetChildren().Item( n
);
4165 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
4167 if (m_wx_model
->IsVirtualListModel())
4173 wxGtkTreeModelNode
*node
= FindParentNode( child
);
4177 iter
->stamp
= m_gtk_model
->stamp
;
4178 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
4184 // item can be deleted already in the model
4185 int wxDataViewCtrlInternal::GetIndexOf( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
4187 if (m_wx_model
->IsVirtualListModel())
4189 return wxPtrToUInt(item
.GetID()) - 1;
4193 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
4194 wxGtkTreeModelChildren
&children
= parent_node
->GetChildren();
4196 for (j
= 0; j
< children
.GetCount(); j
++)
4198 if (children
[j
] == item
.GetID())
4206 static wxGtkTreeModelNode
*
4207 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
4213 list
.DeleteContents( true );
4214 wxDataViewItem
it( item
);
4218 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
4219 list
.Insert( pItem
);
4220 it
= model
->GetParent( it
);
4223 wxGtkTreeModelNode
* node
= treeNode
;
4224 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
4226 if( node
&& node
->GetNodes().GetCount() != 0 )
4228 int len
= node
->GetNodes().GetCount();
4229 wxGtkTreeModelNodes
&nodes
= node
->GetNodes();
4231 for( ; j
< len
; j
++)
4233 if( nodes
[j
]->GetItem() == *(n
->GetData()))
4252 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
4257 wxDataViewItem
item( (void*) iter
->user_data
);
4261 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
4266 wxLogDebug( "Not found %p", iter->user_data );
4270 // TODO: remove this code
4276 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
4281 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
4286 wxLogDebug( "Not found %p", item.GetID() );
4290 // TODO: remove this code
4296 static wxGtkTreeModelNode
*
4297 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
4303 list
.DeleteContents( true );
4307 wxDataViewItem
it( model
->GetParent( item
) );
4310 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
4311 list
.Insert( pItem
);
4312 it
= model
->GetParent( it
);
4315 wxGtkTreeModelNode
* node
= treeNode
;
4316 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
4318 if( node
&& node
->GetNodes().GetCount() != 0 )
4320 int len
= node
->GetNodes().GetCount();
4321 wxGtkTreeModelNodes nodes
= node
->GetNodes();
4323 for( ; j
< len
; j
++)
4325 if( nodes
[j
]->GetItem() == *(n
->GetData()))
4340 //Examine whether the node is item's parent node
4341 int len
= node
->GetChildCount();
4342 for( int i
= 0; i
< len
; i
++ )
4344 if( node
->GetChildren().Item( i
) == item
.GetID() )
4350 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
4355 wxDataViewItem
item( (void*) iter
->user_data
);
4359 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
4362 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
4367 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
4370 //-----------------------------------------------------------------------------
4371 // wxDataViewCtrl signal callbacks
4372 //-----------------------------------------------------------------------------
4375 wxdataview_selection_changed_callback( GtkTreeSelection
* WXUNUSED(selection
), wxDataViewCtrl
*dv
)
4377 if (!gtk_widget_get_realized(dv
->m_widget
))
4380 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
4381 event
.SetItem( dv
->GetSelection() );
4382 event
.SetModel( dv
->GetModel() );
4383 dv
->HandleWindowEvent( event
);
4387 wxdataview_row_activated_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreePath
*path
,
4388 GtkTreeViewColumn
*WXUNUSED(column
), wxDataViewCtrl
*dv
)
4390 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
4392 wxDataViewItem
item(dv
->GTKPathToItem(path
));
4393 event
.SetItem( item
);
4394 event
.SetModel( dv
->GetModel() );
4395 dv
->HandleWindowEvent( event
);
4399 wxdataview_test_expand_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4400 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4402 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
4404 wxDataViewItem
item( (void*) iter
->user_data
);;
4405 event
.SetItem( item
);
4406 event
.SetModel( dv
->GetModel() );
4407 dv
->HandleWindowEvent( event
);
4409 return !event
.IsAllowed();
4413 wxdataview_row_expanded_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4414 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4416 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
4418 wxDataViewItem
item( (void*) iter
->user_data
);;
4419 event
.SetItem( item
);
4420 event
.SetModel( dv
->GetModel() );
4421 dv
->HandleWindowEvent( event
);
4425 wxdataview_test_collapse_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4426 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4428 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
4430 wxDataViewItem
item( (void*) iter
->user_data
);;
4431 event
.SetItem( item
);
4432 event
.SetModel( dv
->GetModel() );
4433 dv
->HandleWindowEvent( event
);
4435 return !event
.IsAllowed();
4439 wxdataview_row_collapsed_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4440 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4442 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
4444 wxDataViewItem
item( (void*) iter
->user_data
);;
4445 event
.SetItem( item
);
4446 event
.SetModel( dv
->GetModel() );
4447 dv
->HandleWindowEvent( event
);
4450 //-----------------------------------------------------------------------------
4452 //-----------------------------------------------------------------------------
4454 void wxDataViewCtrl::AddChildGTK(wxWindowGTK
* child
)
4456 GtkWidget
* treeview
= GtkGetTreeView();
4458 // Insert widget in GtkTreeView
4459 if (gtk_widget_get_realized(treeview
))
4460 gtk_widget_set_parent_window( child
->m_widget
,
4461 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
4462 gtk_widget_set_parent( child
->m_widget
, treeview
);
4466 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
4467 GtkAllocation
*WXUNUSED(gtk_alloc
),
4468 wxDataViewCtrl
*win
)
4470 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
4473 wxWindow
*child
= node
->GetData();
4476 gtk_widget_size_request( child
->m_widget
, &req
);
4478 GtkAllocation alloc
;
4479 alloc
.x
= child
->m_x
;
4480 alloc
.y
= child
->m_y
;
4481 alloc
.width
= child
->m_width
;
4482 alloc
.height
= child
->m_height
;
4483 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
4485 node
= node
->GetNext();
4490 //-----------------------------------------------------------------------------
4491 // "motion_notify_event"
4492 //-----------------------------------------------------------------------------
4495 gtk_dataview_motion_notify_callback( GtkWidget
*WXUNUSED(widget
),
4496 GdkEventMotion
*gdk_event
,
4497 wxDataViewCtrl
*dv
)
4499 if (gdk_event
->is_hint
)
4503 GdkModifierType state
;
4504 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
4510 GtkTreeViewColumn
*column
= NULL
;
4513 if (gtk_tree_view_get_path_at_pos(
4514 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4515 (int) gdk_event
->x
, (int) gdk_event
->y
,
4524 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4532 //-----------------------------------------------------------------------------
4533 // "button_press_event"
4534 //-----------------------------------------------------------------------------
4537 gtk_dataview_button_press_callback( GtkWidget
*WXUNUSED(widget
),
4538 GdkEventButton
*gdk_event
,
4539 wxDataViewCtrl
*dv
)
4541 if ((gdk_event
->button
== 3) && (gdk_event
->type
== GDK_BUTTON_PRESS
))
4544 GtkTreeViewColumn
*column
= NULL
;
4547 if (gtk_tree_view_get_path_at_pos(
4548 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4549 (int) gdk_event
->x
, (int) gdk_event
->y
,
4557 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, dv
->GetId() );
4558 event
.SetItem(dv
->GTKPathToItem(path
));
4559 event
.SetModel( dv
->GetModel() );
4560 return dv
->HandleWindowEvent( event
);
4568 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
4570 wxDataViewCtrl::~wxDataViewCtrl()
4572 // Stop editing before destroying the control to remove any event handlers
4573 // which are added when editing started: if we didn't do this, the base
4574 // class dtor would assert as it checks for any leftover handlers.
4577 GtkTreeViewColumn
*col
;
4578 gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview
), NULL
, &col
);
4580 wxDataViewColumn
* const wxcol
= FromGTKColumn(col
);
4583 // This won't do anything if we're not editing it
4584 wxcol
->GetRenderer()->CancelEditing();
4593 void wxDataViewCtrl::Init()
4597 m_cols
.DeleteContents( true );
4599 m_uniformRowHeight
= -1;
4602 bool wxDataViewCtrl::Create(wxWindow
*parent
,
4607 const wxValidator
& validator
,
4608 const wxString
& name
)
4610 if (!PreCreation( parent
, pos
, size
) ||
4611 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
4613 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
4617 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
4618 g_object_ref(m_widget
);
4620 GTKScrolledWindowSetBorder(m_widget
, style
);
4622 m_treeview
= gtk_tree_view_new();
4623 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
4625 g_signal_connect (m_treeview
, "size_allocate",
4626 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
4629 if (!gtk_check_version(2,6,0))
4631 bool fixed
= (style
& wxDV_VARIABLE_LINE_HEIGHT
) == 0;
4632 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4636 if (style
& wxDV_MULTIPLE
)
4638 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4639 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
4642 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
4645 if (!gtk_check_version(2,10,0))
4647 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
4649 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
4650 (style
& wxDV_VERT_RULES
) != 0)
4651 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
4652 else if (style
& wxDV_VERT_RULES
)
4653 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
4654 else if (style
& wxDV_HORIZ_RULES
)
4655 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
4657 if (grid
!= GTK_TREE_VIEW_GRID_LINES_NONE
)
4658 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
4662 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_ROW_LINES
) != 0 );
4664 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
4665 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
4666 gtk_widget_show (m_treeview
);
4668 m_parent
->DoAddChild( this );
4672 GtkEnableSelectionEvents();
4674 g_signal_connect_after (m_treeview
, "row-activated",
4675 G_CALLBACK (wxdataview_row_activated_callback
), this);
4677 g_signal_connect (m_treeview
, "test-collapse-row",
4678 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
4680 g_signal_connect_after (m_treeview
, "row-collapsed",
4681 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
4683 g_signal_connect (m_treeview
, "test-expand-row",
4684 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
4686 g_signal_connect_after (m_treeview
, "row-expanded",
4687 G_CALLBACK (wxdataview_row_expanded_callback
), this);
4689 g_signal_connect (m_treeview
, "motion_notify_event",
4690 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
4692 g_signal_connect (m_treeview
, "button_press_event",
4693 G_CALLBACK (gtk_dataview_button_press_callback
), this);
4698 wxDataViewItem
wxDataViewCtrl::GTKPathToItem(GtkTreePath
*path
) const
4701 return wxDataViewItem(path
&& m_internal
->get_iter(&iter
, path
)
4706 void wxDataViewCtrl::OnInternalIdle()
4708 wxWindow::OnInternalIdle();
4710 m_internal
->OnInternalIdle();
4712 unsigned int cols
= GetColumnCount();
4714 for (i
= 0; i
< cols
; i
++)
4716 wxDataViewColumn
*col
= GetColumn( i
);
4717 col
->OnInternalIdle();
4720 if (m_ensureVisibleDefered
.IsOk())
4722 ExpandAncestors(m_ensureVisibleDefered
);
4724 iter
.user_data
= (gpointer
) m_ensureVisibleDefered
.GetID();
4725 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4726 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
4727 m_ensureVisibleDefered
= wxDataViewItem(0);
4731 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4733 wxDELETE(m_internal
);
4735 if (!wxDataViewCtrlBase::AssociateModel( model
))
4739 if (!gtk_check_version(2,6,0))
4741 bool fixed
= (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
) == 0) || (model
->IsVirtualListModel()));
4742 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4746 m_internal
= new wxDataViewCtrlInternal( this, model
);
4751 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4753 return m_internal
->EnableDragSource( format
);
4756 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4758 return m_internal
->EnableDropTarget( format
);
4761 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4763 if (!wxDataViewCtrlBase::AppendColumn(col
))
4766 m_cols
.Append( col
);
4769 if (!gtk_check_version(2,6,0))
4771 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4772 GTK_TREE_VIEW_COLUMN_FIXED
)
4773 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4777 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
4778 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4783 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4785 if (!wxDataViewCtrlBase::PrependColumn(col
))
4788 m_cols
.Insert( col
);
4791 if (!gtk_check_version(2,6,0))
4793 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4794 GTK_TREE_VIEW_COLUMN_FIXED
)
4795 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4799 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4800 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
4805 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4807 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4810 m_cols
.Insert( pos
, col
);
4813 if (!gtk_check_version(2,6,0))
4815 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4816 GTK_TREE_VIEW_COLUMN_FIXED
)
4817 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4821 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4822 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), pos
);
4827 unsigned int wxDataViewCtrl::GetColumnCount() const
4829 return m_cols
.GetCount();
4832 wxDataViewColumn
* wxDataViewCtrl::FromGTKColumn(GtkTreeViewColumn
*gtk_col
) const
4837 wxDataViewColumnList::const_iterator iter
;
4838 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4840 wxDataViewColumn
*col
= *iter
;
4841 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
4847 wxFAIL_MSG( "No matching column?" );
4852 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
4854 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
4856 return FromGTKColumn(gtk_col
);
4859 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4861 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4862 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
4864 m_cols
.DeleteObject( column
);
4869 bool wxDataViewCtrl::ClearColumns()
4871 wxDataViewColumnList::iterator iter
;
4872 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4874 wxDataViewColumn
*col
= *iter
;
4875 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4876 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4884 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4886 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
4888 wxGtkList
list(gtk_tree_view_get_columns(GTK_TREE_VIEW(m_treeview
)));
4890 return g_list_index( list
, (gconstpointer
) gtk_column
);
4893 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4895 return m_internal
->GetDataViewSortColumn();
4898 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4901 iter
.user_data
= item
.GetID();
4902 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4903 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
4906 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4909 iter
.user_data
= item
.GetID();
4910 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4911 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
4914 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4917 iter
.user_data
= item
.GetID();
4918 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4919 return gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview
), path
);
4922 wxDataViewItem
wxDataViewCtrl::DoGetCurrentItem() const
4924 // The tree doesn't have any current item if it hadn't been created yet but
4925 // it's arguably not an error to call this function in this case so just
4926 // return an invalid item without asserting.
4928 return wxDataViewItem();
4931 gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview
), path
.ByRef(), NULL
);
4933 return GTKPathToItem(path
);
4936 void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem
& item
)
4938 wxCHECK_RET( m_treeview
,
4939 "Current item can't be set before creating the control." );
4941 // We need to make sure the model knows about this item or the path would
4942 // be invalid and gtk_tree_view_set_cursor() would silently do nothing.
4943 ExpandAncestors(item
);
4945 // We also need to preserve the existing selection from changing.
4946 // Unfortunately the only way to do it seems to use our own selection
4947 // function and forbid any selection changes during set cursor call.
4948 wxGtkTreeSelectionLock
4949 lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview
)));
4951 // Do move the cursor now.
4953 iter
.user_data
= item
.GetID();
4954 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4956 gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview
), path
, NULL
, FALSE
);
4959 void wxDataViewCtrl::StartEditor(const wxDataViewItem
& item
, unsigned int column
)
4961 wxCHECK_RET( m_treeview
,
4962 "Current item can't be set before creating the control." );
4964 // We need to make sure the model knows about this item or the path would
4965 // be invalid and gtk_tree_view_set_cursor() would silently do nothing.
4966 ExpandAncestors(item
);
4968 wxDataViewColumn
*dvcolumn
= GetColumn(column
);
4969 wxASSERT_MSG(dvcolumn
, "Could not retrieve column");
4970 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(dvcolumn
->GetGtkHandle());
4972 // We also need to preserve the existing selection from changing.
4973 // Unfortunately the only way to do it seems to use our own selection
4974 // function and forbid any selection changes during set cursor call.
4975 wxGtkTreeSelectionLock
4976 lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview
)));
4978 // Do move the cursor now.
4980 iter
.user_data
= item
.GetID();
4981 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4983 gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview
), path
, gcolumn
, TRUE
);
4986 int wxDataViewCtrl::GetSelectedItemsCount() const
4988 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4990 return gtk_tree_selection_count_selected_rows(selection
);
4993 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4997 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4998 if (HasFlag(wxDV_MULTIPLE
))
5000 GtkTreeModel
*model
;
5001 wxGtkTreePathList
list(gtk_tree_selection_get_selected_rows(selection
, &model
));
5003 for ( GList
* current
= list
; current
; current
= g_list_next(current
) )
5005 GtkTreePath
*path
= (GtkTreePath
*) current
->data
;
5007 sel
.Add(GTKPathToItem(path
));
5013 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
5015 sel
.Add( wxDataViewItem(iter
.user_data
) );
5022 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
5024 GtkDisableSelectionEvents();
5026 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5028 gtk_tree_selection_unselect_all( selection
);
5030 wxDataViewItem last_parent
;
5033 for (i
= 0; i
< sel
.GetCount(); i
++)
5035 wxDataViewItem item
= sel
[i
];
5036 wxDataViewItem parent
= GetModel()->GetParent( item
);
5039 if (parent
!= last_parent
)
5040 ExpandAncestors(item
);
5042 last_parent
= parent
;
5045 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
5046 iter
.user_data
= (gpointer
) item
.GetID();
5047 gtk_tree_selection_select_iter( selection
, &iter
);
5050 GtkEnableSelectionEvents();
5053 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
5055 ExpandAncestors(item
);
5057 GtkDisableSelectionEvents();
5059 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5062 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
5063 iter
.user_data
= (gpointer
) item
.GetID();
5064 gtk_tree_selection_select_iter( selection
, &iter
);
5066 GtkEnableSelectionEvents();
5069 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
5071 GtkDisableSelectionEvents();
5073 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5076 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
5077 iter
.user_data
= (gpointer
) item
.GetID();
5078 gtk_tree_selection_unselect_iter( selection
, &iter
);
5080 GtkEnableSelectionEvents();
5083 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
5085 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5088 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
5089 iter
.user_data
= (gpointer
) item
.GetID();
5091 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
5094 void wxDataViewCtrl::SelectAll()
5096 GtkDisableSelectionEvents();
5098 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5100 gtk_tree_selection_select_all( selection
);
5102 GtkEnableSelectionEvents();
5105 void wxDataViewCtrl::UnselectAll()
5107 GtkDisableSelectionEvents();
5109 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5111 gtk_tree_selection_unselect_all( selection
);
5113 GtkEnableSelectionEvents();
5116 void wxDataViewCtrl::EnsureVisible(const wxDataViewItem
& item
,
5117 const wxDataViewColumn
*WXUNUSED(column
))
5119 m_ensureVisibleDefered
= item
;
5120 ExpandAncestors(item
);
5123 iter
.user_data
= (gpointer
) item
.GetID();
5124 wxGtkTreePath
path(m_internal
->get_path( &iter
));
5125 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
5128 void wxDataViewCtrl::HitTest(const wxPoint
& point
,
5129 wxDataViewItem
& item
,
5130 wxDataViewColumn
*& column
) const
5132 // gtk_tree_view_get_dest_row_at_pos() is the right one. But it does not tell the column.
5133 // gtk_tree_view_get_path_at_pos() is the wrong function. It doesn't mind the header but returns column.
5134 // See http://mail.gnome.org/archives/gtkmm-list/2005-January/msg00080.html
5135 // So we have to use both of them.
5136 // Friedrich Haase 2010-9-20
5137 wxGtkTreePath path
, pathScratch
;
5138 GtkTreeViewColumn
* GtkColumn
= NULL
;
5139 GtkTreeViewDropPosition pos
= GTK_TREE_VIEW_DROP_INTO_OR_AFTER
;
5143 // cannot directly call GtkGetTreeView(), HitTest is const and so is this pointer
5144 wxDataViewCtrl
* ctrl
= (wxDataViewCtrl
*)this; // ugly workaround, ctrl is NOT const
5145 GtkTreeView
* treeView
= GTK_TREE_VIEW(ctrl
->GtkGetTreeView());
5147 // is there possibly a better suited function to get the column?
5148 gtk_tree_view_get_path_at_pos( // and this is the wrong call but it delivers the column
5150 (int) point
.x
, (int) point
.y
,
5151 pathScratch
.ByRef(),
5152 &GtkColumn
, // here we get the GtkColumn
5156 if ( GtkColumn
!= NULL
)
5158 // we got GTK column
5159 // the right call now which takes the header into account
5160 gtk_tree_view_get_dest_row_at_pos( treeView
, (int) point
.x
, (int) point
.y
, path
.ByRef(), &pos
);
5163 item
= wxDataViewItem(GTKPathToItem(path
));
5164 // else we got a GTK column but the position is not over an item, e.g. below last item
5165 for ( unsigned int i
=0, cols
=GetColumnCount(); i
<cols
; ++i
) // search the wx column
5167 wxDataViewColumn
* col
= GetColumn(i
);
5168 if ( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == GtkColumn
)
5170 column
= col
; // here we get the wx column
5175 // else no column and thus no item, both null
5179 wxDataViewCtrl::GetItemRect(const wxDataViewItem
& WXUNUSED(item
),
5180 const wxDataViewColumn
*WXUNUSED(column
)) const
5185 bool wxDataViewCtrl::SetRowHeight(int rowHeight
)
5187 m_uniformRowHeight
= rowHeight
;
5191 void wxDataViewCtrl::DoSetExpanderColumn()
5193 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
5194 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
5197 void wxDataViewCtrl::DoSetIndent()
5201 void wxDataViewCtrl::GtkDisableSelectionEvents()
5203 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5204 g_signal_handlers_disconnect_by_func( selection
,
5205 (gpointer
) (wxdataview_selection_changed_callback
), this);
5208 void wxDataViewCtrl::GtkEnableSelectionEvents()
5210 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5211 g_signal_connect_after (selection
, "changed",
5212 G_CALLBACK (wxdataview_selection_changed_callback
), this);
5215 // ----------------------------------------------------------------------------
5216 // visual attributes stuff
5217 // ----------------------------------------------------------------------------
5221 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
5223 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
5226 void wxDataViewCtrl::DoApplyWidgetStyle(GtkRcStyle
*style
)
5228 wxDataViewCtrlBase::DoApplyWidgetStyle(style
);
5229 gtk_widget_modify_style(m_treeview
, style
);
5232 #endif // !wxUSE_GENERICDATAVIEWCTRL
5234 #endif // wxUSE_DATAVIEWCTRL