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/popupwin.h"
29 #include "wx/listimpl.cpp"
31 #include "wx/gtk/private.h"
32 #include "wx/gtk/dc.h"
33 #include "wx/gtk/dcclient.h"
35 #include "wx/gtk/private/gdkconv.h"
36 #include "wx/gtk/private/list.h"
37 #include "wx/gtk/private/event.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
;
1215 struct _GtkWxCellRendererClass
1217 GtkCellRendererClass cell_parent_class
;
1221 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
1222 static void gtk_wx_cell_renderer_init (
1223 GtkWxCellRenderer
*cell
);
1224 static void gtk_wx_cell_renderer_class_init(
1225 GtkWxCellRendererClass
*klass
);
1226 static void gtk_wx_cell_renderer_finalize (
1228 static void gtk_wx_cell_renderer_get_size (
1229 GtkCellRenderer
*cell
,
1231 GdkRectangle
*rectangle
,
1236 static void gtk_wx_cell_renderer_render (
1237 GtkCellRenderer
*cell
,
1240 GdkRectangle
*background_area
,
1241 GdkRectangle
*cell_area
,
1242 GdkRectangle
*expose_area
,
1243 GtkCellRendererState flags
);
1244 static gboolean
gtk_wx_cell_renderer_activate(
1245 GtkCellRenderer
*cell
,
1249 GdkRectangle
*background_area
,
1250 GdkRectangle
*cell_area
,
1251 GtkCellRendererState flags
);
1252 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1253 GtkCellRenderer
*cell
,
1257 GdkRectangle
*background_area
,
1258 GdkRectangle
*cell_area
,
1259 GtkCellRendererState flags
);
1262 static GObjectClass
*cell_parent_class
= NULL
;
1267 gtk_wx_cell_renderer_get_type (void)
1269 static GType cell_wx_type
= 0;
1273 const GTypeInfo cell_wx_info
=
1275 sizeof (GtkWxCellRendererClass
),
1276 NULL
, /* base_init */
1277 NULL
, /* base_finalize */
1278 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
1279 NULL
, /* class_finalize */
1280 NULL
, /* class_data */
1281 sizeof (GtkWxCellRenderer
),
1282 0, /* n_preallocs */
1283 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
1286 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
1287 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
1290 return cell_wx_type
;
1294 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
1300 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
1302 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1303 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
1305 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
1307 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
1309 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
1310 cell_class
->render
= gtk_wx_cell_renderer_render
;
1311 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
1312 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
1316 gtk_wx_cell_renderer_finalize (GObject
*object
)
1319 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
1323 gtk_wx_cell_renderer_new (void)
1325 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
1328 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1329 GtkCellRenderer
*renderer
,
1330 GdkEvent
*WXUNUSED(event
),
1333 GdkRectangle
*WXUNUSED(background_area
),
1334 GdkRectangle
*cell_area
,
1335 GtkCellRendererState
WXUNUSED(flags
) )
1337 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1338 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1340 // Renderer doesn't support in-place editing
1341 if (!cell
->HasEditorCtrl())
1344 // An in-place editing control is still around
1345 if (cell
->GetEditorCtrl())
1349 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1355 rect
.x
+= cell_area
->x
;
1356 rect
.y
+= cell_area
->y
;
1357 // rect.width -= renderer->xpad * 2;
1358 // rect.height -= renderer->ypad * 2;
1360 // wxRect renderrect(wxRectFromGDKRect(&rect));
1361 wxRect
renderrect(wxRectFromGDKRect(cell_area
));
1364 item(cell
->GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(path
)));
1366 cell
->StartEditing( item
, renderrect
);
1372 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
1373 GtkWidget
*WXUNUSED(widget
),
1374 GdkRectangle
*cell_area
,
1380 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1381 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1383 wxSize size
= cell
->GetSize();
1385 wxDataViewCtrl
* const ctrl
= cell
->GetOwner()->GetOwner();
1387 // Uniform row height, if specified, overrides the value returned by the
1389 if ( !ctrl
->HasFlag(wxDV_VARIABLE_LINE_HEIGHT
) )
1391 const int uniformHeight
= ctrl
->GTKGetUniformRowHeight();
1392 if ( uniformHeight
> 0 )
1393 size
.y
= uniformHeight
;
1397 gtk_cell_renderer_get_padding(renderer
, &xpad
, &ypad
);
1398 int calc_width
= xpad
* 2 + size
.x
;
1399 int calc_height
= ypad
* 2 + size
.y
;
1406 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
1408 float xalign
, yalign
;
1409 gtk_cell_renderer_get_alignment(renderer
, &xalign
, &yalign
);
1412 *x_offset
= int(xalign
* (cell_area
->width
- calc_width
- 2 * xpad
));
1413 *x_offset
= MAX(*x_offset
, 0) + xpad
;
1417 *y_offset
= int(yalign
* (cell_area
->height
- calc_height
- 2 * ypad
));
1418 *y_offset
= MAX(*y_offset
, 0) + ypad
;
1423 *width
= calc_width
;
1426 *height
= calc_height
;
1430 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
1433 GdkRectangle
*background_area
,
1434 GdkRectangle
*cell_area
,
1435 GdkRectangle
*expose_area
,
1436 GtkCellRendererState flags
)
1439 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1440 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1442 cell
->GTKStashRenderParams(window
, widget
,
1443 background_area
, expose_area
, flags
);
1445 wxRect
rect(wxRectFromGDKRect(cell_area
));
1447 gtk_cell_renderer_get_padding(renderer
, &xpad
, &ypad
);
1448 rect
= rect
.Deflate(xpad
, ypad
);
1450 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
1451 wxWindowDCImpl
*impl
= (wxWindowDCImpl
*) dc
->GetImpl();
1453 // Reinitialize wxWindowDC's GDK window if drawing occurs into a different
1454 // window such as a DnD drop window.
1455 if (window
!= impl
->m_gdkwindow
)
1458 impl
->m_gdkwindow
= window
;
1463 if (flags
& GTK_CELL_RENDERER_SELECTED
)
1464 state
|= wxDATAVIEW_CELL_SELECTED
;
1465 if (flags
& GTK_CELL_RENDERER_PRELIT
)
1466 state
|= wxDATAVIEW_CELL_PRELIT
;
1467 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1468 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1469 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1470 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1471 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
1472 state
|= wxDATAVIEW_CELL_FOCUSED
;
1473 cell
->WXCallRender( rect
, dc
, state
);
1477 gtk_wx_cell_renderer_activate(
1478 GtkCellRenderer
*renderer
,
1482 GdkRectangle
*WXUNUSED(background_area
),
1483 GdkRectangle
*cell_area
,
1484 GtkCellRendererState
WXUNUSED(flags
) )
1486 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1487 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1490 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1496 rect
.x
+= cell_area
->x
;
1497 rect
.y
+= cell_area
->y
;
1499 gtk_cell_renderer_get_padding(renderer
, &xpad
, &ypad
);
1500 rect
.width
-= xpad
* 2;
1501 rect
.height
-= ypad
* 2;
1503 wxRect
renderrect(wxRectFromGDKRect(&rect
));
1505 wxDataViewCtrl
* const ctrl
= cell
->GetOwner()->GetOwner();
1506 wxDataViewModel
*model
= ctrl
->GetModel();
1508 wxDataViewItem
item(ctrl
->GTKPathToItem(wxGtkTreePath(path
)));
1510 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1514 // activated by <ENTER>
1515 return cell
->ActivateCell(renderrect
, model
, item
, model_col
, NULL
);
1517 else if ( event
->type
== GDK_BUTTON_PRESS
)
1519 GdkEventButton
*button_event
= (GdkEventButton
*)event
;
1520 if ( button_event
->button
== 1 )
1522 wxMouseEvent
mouse_event(wxEVT_LEFT_DOWN
);
1523 InitMouseEvent(ctrl
, mouse_event
, button_event
);
1525 mouse_event
.m_x
-= renderrect
.x
;
1526 mouse_event
.m_y
-= renderrect
.y
;
1528 return cell
->ActivateCell(renderrect
, model
, item
, model_col
, &mouse_event
);
1532 wxLogDebug("unexpected event type in gtk_wx_cell_renderer_activate()");
1536 // ---------------------------------------------------------
1537 // wxGtkDataViewModelNotifier
1538 // ---------------------------------------------------------
1540 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1543 wxGtkDataViewModelNotifier( wxDataViewModel
*wx_model
, wxDataViewCtrlInternal
*internal
);
1544 ~wxGtkDataViewModelNotifier();
1546 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1547 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1548 virtual bool ItemChanged( const wxDataViewItem
&item
);
1549 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int model_column
);
1550 virtual bool Cleared();
1551 virtual void Resort();
1552 virtual bool BeforeReset();
1553 virtual bool AfterReset();
1555 void UpdateLastCount();
1558 wxDataViewModel
*m_wx_model
;
1559 wxDataViewCtrlInternal
*m_internal
;
1562 // ---------------------------------------------------------
1563 // wxGtkDataViewListModelNotifier
1564 // ---------------------------------------------------------
1566 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1567 wxDataViewModel
*wx_model
, wxDataViewCtrlInternal
*internal
)
1569 m_wx_model
= wx_model
;
1570 m_internal
= internal
;
1573 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1579 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1581 m_internal
->ItemAdded( parent
, item
);
1582 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1585 iter
.stamp
= wxgtk_model
->stamp
;
1586 iter
.user_data
= item
.GetID();
1588 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1589 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1590 gtk_tree_model_row_inserted(
1591 GTK_TREE_MODEL(wxgtk_model
), path
, &iter
);
1596 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1598 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1600 // using _get_path for a deleted item cannot be
1603 iter
.stamp
= wxgtk_model
->stamp
;
1604 iter
.user_data
= (gpointer
) item
.GetID();
1605 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1606 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1608 // so get the path from the parent
1609 GtkTreeIter parentIter
;
1610 parentIter
.stamp
= wxgtk_model
->stamp
;
1611 parentIter
.user_data
= (gpointer
) parent
.GetID();
1612 wxGtkTreePath
parentPath(wxgtk_tree_model_get_path(
1613 GTK_TREE_MODEL(wxgtk_model
), &parentIter
));
1615 // and add the final index ourselves
1616 wxGtkTreePath
path(gtk_tree_path_copy(parentPath
));
1617 int index
= m_internal
->GetIndexOf( parent
, item
);
1618 gtk_tree_path_append_index( path
, index
);
1621 gtk_tree_model_row_deleted(
1622 GTK_TREE_MODEL(wxgtk_model
), path
);
1624 m_internal
->ItemDeleted( parent
, item
);
1626 // Did we remove the last child, causing 'parent' to become a leaf?
1627 if ( !m_wx_model
->IsContainer(parent
) )
1629 gtk_tree_model_row_has_child_toggled
1631 GTK_TREE_MODEL(wxgtk_model
),
1640 void wxGtkDataViewModelNotifier::Resort()
1642 m_internal
->Resort();
1645 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1647 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1650 iter
.stamp
= wxgtk_model
->stamp
;
1651 iter
.user_data
= (gpointer
) item
.GetID();
1653 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1654 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1655 gtk_tree_model_row_changed(
1656 GTK_TREE_MODEL(wxgtk_model
), path
, &iter
);
1658 m_internal
->ItemChanged( item
);
1663 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_column
)
1665 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1666 wxDataViewCtrl
*ctrl
= m_internal
->GetOwner();
1668 // This adds GTK+'s missing MVC logic for ValueChanged
1670 for (index
= 0; index
< ctrl
->GetColumnCount(); index
++)
1672 wxDataViewColumn
*column
= ctrl
->GetColumn( index
);
1673 if (column
->GetModelColumn() == model_column
)
1675 GtkTreeView
*widget
= GTK_TREE_VIEW(ctrl
->GtkGetTreeView());
1676 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1678 // Don't attempt to refresh not yet realized tree, it is useless
1679 // and results in GTK errors.
1680 if ( gtk_widget_get_realized(ctrl
->GtkGetTreeView()) )
1684 iter
.stamp
= wxgtk_model
->stamp
;
1685 iter
.user_data
= (gpointer
) item
.GetID();
1686 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1687 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1688 GdkRectangle cell_area
;
1689 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1691 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1692 double d
= gtk_adjustment_get_value( hadjust
);
1693 int xdiff
= (int) d
;
1695 int ydiff
= gcolumn
->button
->allocation
.height
;
1697 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1698 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1701 m_internal
->ValueChanged( item
, model_column
);
1710 bool wxGtkDataViewModelNotifier::BeforeReset()
1712 GtkWidget
*treeview
= m_internal
->GetOwner()->GtkGetTreeView();
1713 gtk_tree_view_set_model( GTK_TREE_VIEW(treeview
), NULL
);
1718 bool wxGtkDataViewModelNotifier::AfterReset()
1720 GtkWidget
*treeview
= m_internal
->GetOwner()->GtkGetTreeView();
1721 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1723 m_internal
->Cleared();
1725 gtk_tree_view_set_model( GTK_TREE_VIEW(treeview
), GTK_TREE_MODEL(wxgtk_model
) );
1730 bool wxGtkDataViewModelNotifier::Cleared()
1732 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1734 // There is no call to tell the model that everything
1735 // has been deleted so call row_deleted() for every
1738 int count
= m_internal
->iter_n_children( NULL
); // number of children of root
1740 GtkTreePath
*path
= gtk_tree_path_new_first(); // points to root
1743 for (i
= 0; i
< count
; i
++)
1744 gtk_tree_model_row_deleted( GTK_TREE_MODEL(wxgtk_model
), path
);
1746 gtk_tree_path_free( path
);
1748 m_internal
->Cleared();
1753 // ---------------------------------------------------------
1754 // wxDataViewRenderer
1755 // ---------------------------------------------------------
1757 static gpointer s_user_data
= NULL
;
1760 wxgtk_cell_editable_editing_done( GtkCellEditable
*WXUNUSED(editable
),
1761 wxDataViewRenderer
*wxrenderer
)
1763 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1764 wxDataViewCtrl
*dv
= column
->GetOwner();
1765 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1766 event
.SetDataViewColumn( column
);
1767 event
.SetModel( dv
->GetModel() );
1768 wxDataViewItem
item( s_user_data
);
1769 event
.SetItem( item
);
1770 dv
->HandleWindowEvent( event
);
1774 wxgtk_renderer_editing_started( GtkCellRenderer
*WXUNUSED(cell
), GtkCellEditable
*editable
,
1775 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1780 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1781 wxDataViewCtrl
*dv
= column
->GetOwner();
1782 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1783 event
.SetDataViewColumn( column
);
1784 event
.SetModel( dv
->GetModel() );
1785 wxDataViewItem
item(dv
->GTKPathToItem(wxGtkTreePath(path
)));
1786 event
.SetItem( item
);
1787 dv
->HandleWindowEvent( event
);
1789 if (GTK_IS_CELL_EDITABLE(editable
))
1791 s_user_data
= item
.GetID();
1793 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1794 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1795 (gpointer
) wxrenderer
);
1801 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1803 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1805 wxDataViewRendererBase( varianttype
, mode
, align
)
1810 // we haven't changed them yet
1811 m_usingDefaultAttrs
= true;
1813 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1814 // after the m_renderer pointer has been initialized
1817 void wxDataViewRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
1819 gtk_tree_view_column_pack_end( column
, m_renderer
, TRUE
/* expand */);
1822 void wxDataViewRenderer::GtkInitHandlers()
1824 if (!gtk_check_version(2,6,0))
1826 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1827 G_CALLBACK (wxgtk_renderer_editing_started
),
1832 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1834 GtkCellRendererMode gtkMode
;
1837 case wxDATAVIEW_CELL_INERT
:
1838 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1841 case wxDATAVIEW_CELL_ACTIVATABLE
:
1842 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1845 case wxDATAVIEW_CELL_EDITABLE
:
1846 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1850 wxFAIL_MSG( "unknown wxDataViewCellMode value" );
1856 // This value is most often ignored in GtkTreeView
1857 GValue gvalue
= { 0, };
1858 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1859 g_value_set_enum( &gvalue
, gtkMode
);
1860 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1861 g_value_unset( &gvalue
);
1864 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1866 wxDataViewCellMode ret
;
1869 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1871 switch (g_value_get_enum(&gvalue
))
1874 wxFAIL_MSG( "unknown GtkCellRendererMode value" );
1875 // fall through (we have to return something)
1877 case GTK_CELL_RENDERER_MODE_INERT
:
1878 ret
= wxDATAVIEW_CELL_INERT
;
1881 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1882 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1885 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1886 ret
= wxDATAVIEW_CELL_EDITABLE
;
1890 g_value_unset( &gvalue
);
1895 void wxDataViewRenderer::GtkApplyAlignment(GtkCellRenderer
*renderer
)
1897 int align
= m_alignment
;
1899 // query alignment from column ?
1903 if (GetOwner() == NULL
)
1906 align
= GetOwner()->GetAlignment();
1907 align
|= wxALIGN_CENTRE_VERTICAL
;
1910 // horizontal alignment:
1912 gfloat xalign
= 0.0;
1913 if (align
& wxALIGN_RIGHT
)
1915 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1918 GValue gvalue
= { 0, };
1919 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1920 g_value_set_float( &gvalue
, xalign
);
1921 g_object_set_property( G_OBJECT(renderer
), "xalign", &gvalue
);
1922 g_value_unset( &gvalue
);
1924 // vertical alignment:
1926 gfloat yalign
= 0.0;
1927 if (align
& wxALIGN_BOTTOM
)
1929 else if (align
& wxALIGN_CENTER_VERTICAL
)
1932 GValue gvalue2
= { 0, };
1933 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1934 g_value_set_float( &gvalue2
, yalign
);
1935 g_object_set_property( G_OBJECT(renderer
), "yalign", &gvalue2
);
1936 g_value_unset( &gvalue2
);
1939 void wxDataViewRenderer::SetAlignment( int align
)
1941 m_alignment
= align
;
1942 GtkUpdateAlignment();
1945 int wxDataViewRenderer::GetAlignment() const
1950 void wxDataViewRenderer::EnableEllipsize(wxEllipsizeMode mode
)
1953 if ( gtk_check_version(2, 6, 0) != NULL
)
1956 GtkCellRendererText
* const rend
= GtkGetTextRenderer();
1960 // we use the same values in wxEllipsizeMode as PangoEllipsizeMode so we
1961 // can just cast between them
1962 GValue gvalue
= { 0, };
1963 g_value_init( &gvalue
, PANGO_TYPE_ELLIPSIZE_MODE
);
1964 g_value_set_enum( &gvalue
, static_cast<PangoEllipsizeMode
>(mode
) );
1965 g_object_set_property( G_OBJECT(rend
), "ellipsize", &gvalue
);
1966 g_value_unset( &gvalue
);
1969 #endif // GTK 2.6/before
1972 wxEllipsizeMode
wxDataViewRenderer::GetEllipsizeMode() const
1975 if ( gtk_check_version(2, 6, 0) != NULL
)
1976 return wxELLIPSIZE_NONE
;
1978 GtkCellRendererText
* const rend
= GtkGetTextRenderer();
1980 return wxELLIPSIZE_NONE
;
1982 GValue gvalue
= { 0, };
1983 g_value_init( &gvalue
, PANGO_TYPE_ELLIPSIZE_MODE
);
1984 g_object_get_property( G_OBJECT(rend
), "ellipsize", &gvalue
);
1986 mode
= static_cast<wxEllipsizeMode
>(g_value_get_enum( &gvalue
));
1987 g_value_unset( &gvalue
);
1991 return wxELLIPSIZE_NONE
;
1992 #endif // GTK 2.6/before
1996 wxDataViewRenderer::GtkOnTextEdited(const char *itempath
, const wxString
& str
)
1998 wxVariant
value(str
);
1999 if (!Validate( value
))
2003 item(GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(itempath
)));
2005 GtkOnCellChanged(value
, item
, GetOwner()->GetModelColumn());
2009 wxDataViewRenderer::GtkOnCellChanged(const wxVariant
& value
,
2010 const wxDataViewItem
& item
,
2013 wxDataViewModel
*model
= GetOwner()->GetOwner()->GetModel();
2014 model
->ChangeValue( value
, item
, col
);
2017 // ---------------------------------------------------------
2018 // wxDataViewTextRenderer
2019 // ---------------------------------------------------------
2024 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*WXUNUSED(renderer
),
2025 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
2027 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) user_data
;
2029 cell
->GtkOnTextEdited(arg1
, wxGTK_CONV_BACK_FONT(
2030 arg2
, cell
->GetOwner()->GetOwner()->GetFont()));
2038 // helper function used by wxDataViewTextRenderer and
2039 // wxDataViewCustomRenderer::RenderText(): it applies the attributes to the
2040 // given text renderer and returns true if anything was done
2041 bool GtkApplyAttr(GtkCellRendererText
*renderer
, const wxDataViewItemAttr
& attr
)
2043 bool usingDefaultAttrs
= true;
2044 if (attr
.HasColour())
2046 const GdkColor
* const gcol
= attr
.GetColour().GetColor();
2048 GValue gvalue
= { 0, };
2049 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2050 g_value_set_boxed( &gvalue
, gcol
);
2051 g_object_set_property( G_OBJECT(renderer
), "foreground_gdk", &gvalue
);
2052 g_value_unset( &gvalue
);
2054 usingDefaultAttrs
= false;
2058 GValue gvalue
= { 0, };
2059 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2060 g_value_set_boolean( &gvalue
, FALSE
);
2061 g_object_set_property( G_OBJECT(renderer
), "foreground-set", &gvalue
);
2062 g_value_unset( &gvalue
);
2065 if (attr
.GetItalic())
2067 GValue gvalue
= { 0, };
2068 g_value_init( &gvalue
, PANGO_TYPE_STYLE
);
2069 g_value_set_enum( &gvalue
, PANGO_STYLE_ITALIC
);
2070 g_object_set_property( G_OBJECT(renderer
), "style", &gvalue
);
2071 g_value_unset( &gvalue
);
2073 usingDefaultAttrs
= false;
2077 GValue gvalue
= { 0, };
2078 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2079 g_value_set_boolean( &gvalue
, FALSE
);
2080 g_object_set_property( G_OBJECT(renderer
), "style-set", &gvalue
);
2081 g_value_unset( &gvalue
);
2087 GValue gvalue
= { 0, };
2088 g_value_init( &gvalue
, PANGO_TYPE_WEIGHT
);
2089 g_value_set_enum( &gvalue
, PANGO_WEIGHT_BOLD
);
2090 g_object_set_property( G_OBJECT(renderer
), "weight", &gvalue
);
2091 g_value_unset( &gvalue
);
2093 usingDefaultAttrs
= false;
2097 GValue gvalue
= { 0, };
2098 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2099 g_value_set_boolean( &gvalue
, FALSE
);
2100 g_object_set_property( G_OBJECT(renderer
), "weight-set", &gvalue
);
2101 g_value_unset( &gvalue
);
2105 if (attr
.HasBackgroundColour())
2107 wxColour colour
= attr
.GetBackgroundColour();
2108 const GdkColor
* const gcol
= colour
.GetColor();
2110 GValue gvalue
= { 0, };
2111 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2112 g_value_set_boxed( &gvalue
, gcol
);
2113 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
2114 g_value_unset( &gvalue
);
2118 GValue gvalue
= { 0, };
2119 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2120 g_value_set_boolean( &gvalue
, FALSE
);
2121 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
2122 g_value_unset( &gvalue
);
2126 return !usingDefaultAttrs
;
2129 } // anonymous namespace
2131 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
2133 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
2135 wxDataViewRenderer( varianttype
, mode
, align
)
2137 GtkWxCellRendererText
*text_renderer
= gtk_wx_cell_renderer_text_new();
2138 text_renderer
->wx_renderer
= this;
2139 m_renderer
= (GtkCellRenderer
*) text_renderer
;
2141 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
2143 GValue gvalue
= { 0, };
2144 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2145 g_value_set_boolean( &gvalue
, true );
2146 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
2147 g_value_unset( &gvalue
);
2149 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2155 SetAlignment(align
);
2158 bool wxDataViewTextRenderer::SetTextValue(const wxString
& str
)
2160 GValue gvalue
= { 0, };
2161 g_value_init( &gvalue
, G_TYPE_STRING
);
2162 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( str
, GetOwner()->GetOwner()->GetFont() ) );
2163 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2164 g_value_unset( &gvalue
);
2169 bool wxDataViewTextRenderer::GetTextValue(wxString
& str
) const
2171 GValue gvalue
= { 0, };
2172 g_value_init( &gvalue
, G_TYPE_STRING
);
2173 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2174 str
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
), const_cast<wxDataViewTextRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
2175 g_value_unset( &gvalue
);
2180 void wxDataViewTextRenderer::SetAlignment( int align
)
2182 wxDataViewRenderer::SetAlignment(align
);
2184 if (gtk_check_version(2,10,0))
2187 // horizontal alignment:
2188 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2189 if (align
& wxALIGN_RIGHT
)
2190 pangoAlign
= PANGO_ALIGN_RIGHT
;
2191 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2192 pangoAlign
= PANGO_ALIGN_CENTER
;
2194 GValue gvalue
= { 0, };
2195 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2196 g_value_set_enum( &gvalue
, pangoAlign
);
2197 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2198 g_value_unset( &gvalue
);
2201 bool wxDataViewTextRenderer::GtkSetAttr(const wxDataViewItemAttr
& attr
)
2203 return GtkApplyAttr(GtkGetTextRenderer(), attr
);
2206 GtkCellRendererText
*wxDataViewTextRenderer::GtkGetTextRenderer() const
2208 return GTK_CELL_RENDERER_TEXT(m_renderer
);
2211 // ---------------------------------------------------------
2212 // wxDataViewBitmapRenderer
2213 // ---------------------------------------------------------
2218 // set "pixbuf" property on the given renderer
2219 void SetPixbufProp(GtkCellRenderer
*renderer
, GdkPixbuf
*pixbuf
)
2221 GValue gvalue
= { 0, };
2222 g_value_init( &gvalue
, G_TYPE_OBJECT
);
2223 g_value_set_object( &gvalue
, pixbuf
);
2224 g_object_set_property( G_OBJECT(renderer
), "pixbuf", &gvalue
);
2225 g_value_unset( &gvalue
);
2228 } // anonymous namespace
2230 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
2232 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
2234 wxDataViewRenderer( varianttype
, mode
, align
)
2236 m_renderer
= gtk_cell_renderer_pixbuf_new();
2239 SetAlignment(align
);
2242 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
2244 if (value
.GetType() == wxT("wxBitmap"))
2249 // GetPixbuf() may create a Pixbuf representation in the wxBitmap
2250 // object (and it will stay there and remain owned by wxBitmap)
2251 SetPixbufProp(m_renderer
, bitmap
.GetPixbuf());
2253 else if (value
.GetType() == wxT("wxIcon"))
2258 SetPixbufProp(m_renderer
, icon
.GetPixbuf());
2268 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2273 // ---------------------------------------------------------
2274 // wxDataViewToggleRenderer
2275 // ---------------------------------------------------------
2278 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
2279 gchar
*path
, gpointer user_data
);
2282 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
2283 gchar
*path
, gpointer user_data
)
2285 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
2288 GValue gvalue
= { 0, };
2289 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2290 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
2291 bool tmp
= g_value_get_boolean( &gvalue
);
2292 g_value_unset( &gvalue
);
2296 wxVariant value
= tmp
;
2297 if (!cell
->Validate( value
))
2300 wxDataViewCtrl
* const ctrl
= cell
->GetOwner()->GetOwner();
2301 wxDataViewModel
*model
= ctrl
->GetModel();
2303 wxDataViewItem
item(ctrl
->GTKPathToItem(wxGtkTreePath(path
)));
2305 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
2307 model
->ChangeValue( value
, item
, model_col
);
2310 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
2312 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
2313 wxDataViewCellMode mode
, int align
) :
2314 wxDataViewRenderer( varianttype
, mode
, align
)
2316 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
2318 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
2320 g_signal_connect_after( m_renderer
, "toggled",
2321 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
2325 GValue gvalue
= { 0, };
2326 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2327 g_value_set_boolean( &gvalue
, false );
2328 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
2329 g_value_unset( &gvalue
);
2333 SetAlignment(align
);
2336 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
2340 GValue gvalue
= { 0, };
2341 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2342 g_value_set_boolean( &gvalue
, tmp
);
2343 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
2344 g_value_unset( &gvalue
);
2349 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
2351 GValue gvalue
= { 0, };
2352 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2353 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
2354 bool tmp
= g_value_get_boolean( &gvalue
);
2355 g_value_unset( &gvalue
);
2362 // ---------------------------------------------------------
2363 // wxDataViewCustomRenderer
2364 // ---------------------------------------------------------
2366 class wxDataViewCtrlDCImpl
: public wxWindowDCImpl
2369 wxDataViewCtrlDCImpl( wxDC
*owner
, wxDataViewCtrl
*window
) :
2370 wxWindowDCImpl( owner
)
2372 GtkWidget
*widget
= window
->m_treeview
;
2378 m_context
= window
->GTKGetPangoDefaultContext();
2379 m_layout
= pango_layout_new( m_context
);
2380 m_fontdesc
= pango_font_description_copy(gtk_widget_get_style(widget
)->font_desc
);
2382 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
2384 // Set m_gdkwindow later
2389 class wxDataViewCtrlDC
: public wxWindowDC
2392 wxDataViewCtrlDC( wxDataViewCtrl
*window
) :
2393 wxWindowDC( new wxDataViewCtrlDCImpl( this, window
) )
2398 // ---------------------------------------------------------
2399 // wxDataViewCustomRenderer
2400 // ---------------------------------------------------------
2402 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
2404 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
2405 wxDataViewCellMode mode
,
2408 : wxDataViewCustomRendererBase( varianttype
, mode
, align
)
2411 m_text_renderer
= NULL
;
2419 void wxDataViewCustomRenderer::GtkInitTextRenderer()
2421 m_text_renderer
= GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new());
2422 g_object_ref_sink(m_text_renderer
);
2424 GtkApplyAlignment(GTK_CELL_RENDERER(m_text_renderer
));
2427 GtkCellRendererText
*wxDataViewCustomRenderer::GtkGetTextRenderer() const
2429 if ( !m_text_renderer
)
2431 // we create it on demand so need to do it even from a const function
2432 const_cast<wxDataViewCustomRenderer
*>(this)->GtkInitTextRenderer();
2435 return m_text_renderer
;
2438 void wxDataViewCustomRenderer::RenderText( const wxString
&text
,
2442 int WXUNUSED(state
) )
2445 GtkCellRendererText
* const textRenderer
= GtkGetTextRenderer();
2447 GValue gvalue
= { 0, };
2448 g_value_init( &gvalue
, G_TYPE_STRING
);
2449 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( text
, GetOwner()->GetOwner()->GetFont() ) );
2450 g_object_set_property( G_OBJECT(textRenderer
), "text", &gvalue
);
2451 g_value_unset( &gvalue
);
2453 GtkApplyAttr(textRenderer
, GetAttr());
2455 GdkRectangle cell_area
;
2456 wxRectToGDKRect(cell
, cell_area
);
2457 cell_area
.x
+= xoffset
;
2458 cell_area
.width
-= xoffset
;
2460 gtk_cell_renderer_render( GTK_CELL_RENDERER(textRenderer
),
2461 m_renderParams
.window
,
2462 m_renderParams
.widget
,
2463 m_renderParams
.background_area
,
2465 m_renderParams
.expose_area
,
2466 (GtkCellRendererState
) m_renderParams
.flags
);
2469 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
2471 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
2472 renderer
->cell
= this;
2474 m_renderer
= (GtkCellRenderer
*) renderer
;
2477 SetAlignment(align
);
2484 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
2489 if (m_text_renderer
)
2490 g_object_unref(m_text_renderer
);
2493 wxDC
*wxDataViewCustomRenderer::GetDC()
2497 if (GetOwner() == NULL
)
2499 if (GetOwner()->GetOwner() == NULL
)
2501 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
2507 // ---------------------------------------------------------
2508 // wxDataViewProgressRenderer
2509 // ---------------------------------------------------------
2511 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
2513 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
2514 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
2515 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
2521 if (!gtk_check_version(2,6,0))
2523 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
2526 SetAlignment(align
);
2529 // We can't initialize the renderer just yet because we don't have the
2530 // pointer to the column that uses this renderer yet and so attempt to
2531 // dereference GetOwner() to get the font that is used as a source of
2532 // encoding in multibyte-to-Unicode conversion in GTKSetLabel() in
2533 // non-Unicode builds would crash. So simply remember to do it later.
2534 if ( !m_label
.empty() )
2535 m_needsToSetLabel
= true;
2537 #endif // !wxUSE_UNICODE
2543 // Use custom cell code
2544 wxDataViewCustomRenderer::Init(mode
, align
);
2548 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
2552 void wxDataViewProgressRenderer::GTKSetLabel()
2554 GValue gvalue
= { 0, };
2555 g_value_init( &gvalue
, G_TYPE_STRING
);
2557 // Take care to not use GetOwner() here if the label is empty, we can be
2558 // called from ctor when GetOwner() is still NULL in this case.
2559 g_value_set_string( &gvalue
,
2560 m_label
.empty() ? ""
2561 : wxGTK_CONV_FONT(m_label
,
2562 GetOwner()->GetOwner()->GetFont())
2564 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2565 g_value_unset( &gvalue
);
2568 m_needsToSetLabel
= false;
2569 #endif // !wxUSE_UNICODE
2572 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
2575 if (!gtk_check_version(2,6,0))
2578 if ( m_needsToSetLabel
)
2580 #endif // !wxUSE_UNICODE
2582 gint tmp
= (long) value
;
2583 GValue gvalue
= { 0, };
2584 g_value_init( &gvalue
, G_TYPE_INT
);
2585 g_value_set_int( &gvalue
, tmp
);
2586 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
2587 g_value_unset( &gvalue
);
2592 m_value
= (long) value
;
2594 if (m_value
< 0) m_value
= 0;
2595 if (m_value
> 100) m_value
= 100;
2601 bool wxDataViewProgressRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2606 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
2608 double pct
= (double)m_value
/ 100.0;
2610 bar
.width
= (int)(cell
.width
* pct
);
2611 dc
->SetPen( *wxTRANSPARENT_PEN
);
2612 dc
->SetBrush( *wxBLUE_BRUSH
);
2613 dc
->DrawRectangle( bar
);
2615 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
2616 dc
->SetPen( *wxBLACK_PEN
);
2617 dc
->DrawRectangle( cell
);
2622 wxSize
wxDataViewProgressRenderer::GetSize() const
2624 return wxSize(40,12);
2627 // -------------------------------------
2628 // wxDataViewChoiceRenderer
2629 // -------------------------------------
2631 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
&choices
,
2632 wxDataViewCellMode mode
, int alignment
) :
2633 wxDataViewCustomRenderer( "string", mode
, alignment
, true )
2635 m_choices
= choices
;
2638 if (!gtk_check_version(2,6,0))
2640 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_combo_new();
2642 GtkListStore
*store
= gtk_list_store_new( 1, G_TYPE_STRING
);
2643 for (size_t n
= 0; n
< m_choices
.GetCount(); n
++)
2645 gtk_list_store_insert_with_values(
2647 static_cast<const char *>(m_choices
[n
].utf8_str()), -1 );
2650 g_object_set (m_renderer
,
2656 bool editable
= (mode
& wxDATAVIEW_CELL_EDITABLE
);
2657 g_object_set (m_renderer
, "editable", editable
, NULL
);
2659 SetAlignment(alignment
);
2661 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2668 // Use custom cell code
2669 wxDataViewCustomRenderer::Init(mode
, alignment
);
2673 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
2675 RenderText( m_data
, 0, rect
, dc
, state
);
2679 wxSize
wxDataViewChoiceRenderer::GetSize() const
2681 return wxSize(70,20);
2684 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
2688 if (!gtk_check_version(2,6,0))
2690 GValue gvalue
= { 0, };
2691 g_value_init( &gvalue
, G_TYPE_STRING
);
2692 g_value_set_string(&gvalue
,
2693 wxGTK_CONV_FONT(value
.GetString(),
2694 GetOwner()->GetOwner()->GetFont()));
2695 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2696 g_value_unset( &gvalue
);
2700 m_data
= value
.GetString();
2705 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
2708 if (!gtk_check_version(2,6,0))
2710 GValue gvalue
= { 0, };
2711 g_value_init( &gvalue
, G_TYPE_STRING
);
2712 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2713 wxString temp
= wxGTK_CONV_BACK_FONT(g_value_get_string(&gvalue
),
2714 GetOwner()->GetOwner()->GetFont());
2715 g_value_unset( &gvalue
);
2718 //wxPrintf( "temp %s\n", temp );
2719 // TODO: remove this code
2728 void wxDataViewChoiceRenderer::SetAlignment( int align
)
2730 wxDataViewCustomRenderer::SetAlignment(align
);
2732 if (gtk_check_version(2,10,0))
2735 // horizontal alignment:
2736 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2737 if (align
& wxALIGN_RIGHT
)
2738 pangoAlign
= PANGO_ALIGN_RIGHT
;
2739 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2740 pangoAlign
= PANGO_ALIGN_CENTER
;
2742 GValue gvalue
= { 0, };
2743 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2744 g_value_set_enum( &gvalue
, pangoAlign
);
2745 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2746 g_value_unset( &gvalue
);
2749 // ----------------------------------------------------------------------------
2750 // wxDataViewChoiceByIndexRenderer
2751 // ----------------------------------------------------------------------------
2753 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
2754 wxDataViewCellMode mode
, int alignment
) :
2755 wxDataViewChoiceRenderer( choices
, mode
, alignment
)
2759 void wxDataViewChoiceByIndexRenderer::GtkOnTextEdited(const char *itempath
, const wxString
& str
)
2761 wxVariant
value( (long) GetChoices().Index( str
) );
2763 if (!Validate( value
))
2767 item(GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(itempath
)));
2769 GtkOnCellChanged(value
, item
, GetOwner()->GetModelColumn());
2772 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant
&value
)
2774 wxVariant string_value
= GetChoice( value
.GetLong() );
2775 return wxDataViewChoiceRenderer::SetValue( string_value
);
2778 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant
&value
) const
2780 wxVariant string_value
;
2781 if (!wxDataViewChoiceRenderer::GetValue( string_value
))
2784 value
= (long) GetChoices().Index( string_value
.GetString() );
2788 // ---------------------------------------------------------
2789 // wxDataViewIconTextRenderer
2790 // ---------------------------------------------------------
2792 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
2794 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer
2796 const wxString
&varianttype
,
2797 wxDataViewCellMode mode
,
2800 : wxDataViewTextRenderer(varianttype
, mode
, align
)
2802 m_rendererIcon
= gtk_cell_renderer_pixbuf_new();
2805 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2809 void wxDataViewIconTextRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
2811 // add the icon renderer first
2812 gtk_tree_view_column_pack_start(column
, m_rendererIcon
, FALSE
/* !expand */);
2814 // add the text renderer too
2815 wxDataViewRenderer::GtkPackIntoColumn(column
);
2818 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
2822 SetTextValue(m_value
.GetText());
2823 SetPixbufProp(m_rendererIcon
, m_value
.GetIcon().GetPixbuf());
2828 bool wxDataViewIconTextRenderer::GetValue(wxVariant
& value
) const
2831 if ( !GetTextValue(str
) )
2834 // user doesn't have any way to edit the icon so leave it unchanged
2835 value
<< wxDataViewIconText(str
, m_value
.GetIcon());
2841 wxDataViewIconTextRenderer::GtkOnCellChanged(const wxVariant
& value
,
2842 const wxDataViewItem
& item
,
2845 // we receive just the text part of our value as it's the only one which
2846 // can be edited, but we need the full wxDataViewIconText value for the
2848 wxVariant valueIconText
;
2849 valueIconText
<< wxDataViewIconText(value
.GetString(), m_value
.GetIcon());
2850 wxDataViewTextRenderer::GtkOnCellChanged(valueIconText
, item
, col
);
2853 // ---------------------------------------------------------
2855 // ---------------------------------------------------------
2859 gtk_dataview_header_button_press_callback( GtkWidget
*WXUNUSED(widget
),
2860 GdkEventButton
*gdk_event
,
2861 wxDataViewColumn
*column
)
2863 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
2866 if (gdk_event
->button
== 1)
2868 gs_lastLeftClickHeader
= column
;
2870 wxDataViewCtrl
*dv
= column
->GetOwner();
2871 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
2872 event
.SetDataViewColumn( column
);
2873 event
.SetModel( dv
->GetModel() );
2874 if (dv
->HandleWindowEvent( event
))
2878 if (gdk_event
->button
== 3)
2880 wxDataViewCtrl
*dv
= column
->GetOwner();
2881 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
2882 event
.SetDataViewColumn( column
);
2883 event
.SetModel( dv
->GetModel() );
2884 if (dv
->HandleWindowEvent( event
))
2894 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*WXUNUSED(column
),
2895 GtkCellRenderer
*renderer
,
2896 GtkTreeModel
*model
,
2900 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2901 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2903 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2905 wxDataViewItem
item( (void*) iter
->user_data
);
2907 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
2909 if (!wx_model
->IsVirtualListModel())
2912 if (wx_model
->IsContainer( item
))
2914 visible
= wx_model
->HasContainerColumns( item
) ||
2915 (cell
->GetOwner()->GetModelColumn() == 0);
2922 GValue gvalue
= { 0, };
2923 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2924 g_value_set_boolean( &gvalue
, visible
);
2925 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2926 g_value_unset( &gvalue
);
2933 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
2935 if (value
.GetType() != cell
->GetVariantType())
2937 wxLogError( wxT("Wrong type, required: %s but: %s"),
2938 value
.GetType().c_str(),
2939 cell
->GetVariantType().c_str() );
2942 cell
->SetValue( value
);
2944 // deal with disabled items
2945 bool enabled
= wx_model
->IsEnabled( item
, cell
->GetOwner()->GetModelColumn() );
2947 // a) this sets the appearance to disabled grey
2948 GValue gvalue
= { 0, };
2949 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2950 g_value_set_boolean( &gvalue
, enabled
);
2951 g_object_set_property( G_OBJECT(renderer
), "sensitive", &gvalue
);
2952 g_value_unset( &gvalue
);
2954 // b) this actually disables the control/renderer
2956 cell
->SetMode( cell
->GtkGetMode() );
2958 cell
->SetMode( wxDATAVIEW_CELL_INERT
);
2961 // deal with attributes: if the renderer doesn't support them at all, we
2962 // don't even need to query the model for them
2963 if ( !cell
->GtkSupportsAttrs() )
2966 // it can support attributes so check if this item has any
2967 wxDataViewItemAttr attr
;
2968 if ( wx_model
->GetAttr( item
, cell
->GetOwner()->GetModelColumn(), attr
)
2969 || !cell
->GtkIsUsingDefaultAttrs() )
2971 bool usingDefaultAttrs
= !cell
->GtkSetAttr(attr
);
2972 cell
->GtkSetUsingDefaultAttrs(usingDefaultAttrs
);
2974 // else: no custom attributes specified and we're already using the default
2975 // ones -- nothing to do
2981 #include <wx/listimpl.cpp>
2982 WX_DEFINE_LIST(wxDataViewColumnList
)
2984 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
2985 unsigned int model_column
, int width
,
2986 wxAlignment align
, int flags
)
2987 : wxDataViewColumnBase( cell
, model_column
)
2989 Init( align
, flags
, width
);
2994 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
2995 unsigned int model_column
, int width
,
2996 wxAlignment align
, int flags
)
2997 : wxDataViewColumnBase( bitmap
, cell
, model_column
)
2999 Init( align
, flags
, width
);
3001 SetBitmap( bitmap
);
3004 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
3006 m_isConnected
= false;
3008 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
3009 m_column
= (GtkWidget
*) column
;
3012 SetAlignment( align
);
3016 // Create container for icon and label
3017 GtkWidget
*box
= gtk_hbox_new( FALSE
, 1 );
3018 gtk_widget_show( box
);
3019 // gtk_container_set_border_width((GtkContainer*)box, 2);
3020 m_image
= gtk_image_new();
3021 gtk_box_pack_start(GTK_BOX(box
), m_image
, FALSE
, FALSE
, 1);
3022 m_label
= gtk_label_new("");
3023 gtk_box_pack_end( GTK_BOX(box
), GTK_WIDGET(m_label
), FALSE
, FALSE
, 1 );
3024 gtk_tree_view_column_set_widget( column
, box
);
3026 wxDataViewRenderer
* const colRenderer
= GetRenderer();
3027 GtkCellRenderer
* const cellRenderer
= colRenderer
->GetGtkHandle();
3029 colRenderer
->GtkPackIntoColumn(column
);
3031 gtk_tree_view_column_set_cell_data_func( column
, cellRenderer
,
3032 wxGtkTreeCellDataFunc
, (gpointer
) colRenderer
, NULL
);
3035 void wxDataViewColumn::OnInternalIdle()
3040 if (gtk_widget_get_realized(GetOwner()->m_treeview
))
3042 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3045 g_signal_connect(column
->button
, "button_press_event",
3046 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
3048 // otherwise the event will be blocked by GTK+
3049 gtk_tree_view_column_set_clickable( column
, TRUE
);
3051 m_isConnected
= true;
3056 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
3058 wxDataViewColumnBase::SetOwner( owner
);
3060 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3062 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
3065 void wxDataViewColumn::SetTitle( const wxString
&title
)
3067 wxDataViewCtrl
*ctrl
= GetOwner();
3068 gtk_label_set_text( GTK_LABEL(m_label
), ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
3069 : wxGTK_CONV_SYS(title
) );
3071 gtk_widget_hide( m_label
);
3073 gtk_widget_show( m_label
);
3076 wxString
wxDataViewColumn::GetTitle() const
3078 return wxGTK_CONV_BACK_FONT(
3079 gtk_label_get_text( GTK_LABEL(m_label
) ),
3080 GetOwner()->GetFont()
3084 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
3086 wxDataViewColumnBase::SetBitmap( bitmap
);
3090 GtkImage
*gtk_image
= GTK_IMAGE(m_image
);
3092 GdkBitmap
*mask
= NULL
;
3093 if (bitmap
.GetMask())
3094 mask
= bitmap
.GetMask()->GetBitmap();
3096 if (bitmap
.HasPixbuf())
3098 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
3099 bitmap
.GetPixbuf());
3103 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
3104 bitmap
.GetPixmap(), mask
);
3106 gtk_widget_show( m_image
);
3110 gtk_widget_hide( m_image
);
3114 void wxDataViewColumn::SetHidden( bool hidden
)
3116 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
3119 void wxDataViewColumn::SetResizeable( bool resizable
)
3121 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizable
);
3124 void wxDataViewColumn::SetAlignment( wxAlignment align
)
3126 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3128 gfloat xalign
= 0.0;
3129 if (align
== wxALIGN_RIGHT
)
3131 if (align
== wxALIGN_CENTER_HORIZONTAL
||
3132 align
== wxALIGN_CENTER
)
3135 gtk_tree_view_column_set_alignment( column
, xalign
);
3137 if (m_renderer
&& m_renderer
->GetAlignment() == -1)
3138 m_renderer
->GtkUpdateAlignment();
3141 wxAlignment
wxDataViewColumn::GetAlignment() const
3143 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
3146 return wxALIGN_RIGHT
;
3148 return wxALIGN_CENTER_HORIZONTAL
;
3150 return wxALIGN_LEFT
;
3153 void wxDataViewColumn::SetSortable( bool sortable
)
3155 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3159 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
3163 gtk_tree_view_column_set_sort_column_id( column
, -1 );
3164 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
3165 gtk_tree_view_column_set_clickable( column
, FALSE
);
3169 bool wxDataViewColumn::IsSortable() const
3171 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3172 return gtk_tree_view_column_get_clickable( column
);
3175 bool wxDataViewColumn::IsSortKey() const
3177 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3178 return gtk_tree_view_column_get_sort_indicator( column
);
3181 bool wxDataViewColumn::IsResizeable() const
3183 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3184 return gtk_tree_view_column_get_resizable( column
);
3187 bool wxDataViewColumn::IsHidden() const
3189 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3190 return !gtk_tree_view_column_get_visible( column
);
3193 void wxDataViewColumn::SetSortOrder( bool ascending
)
3195 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3198 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
3200 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
3202 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
3205 bool wxDataViewColumn::IsSortOrderAscending() const
3207 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3209 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
3212 void wxDataViewColumn::SetMinWidth( int width
)
3214 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
3217 int wxDataViewColumn::GetMinWidth() const
3219 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
3222 int wxDataViewColumn::GetWidth() const
3224 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
3227 void wxDataViewColumn::SetWidth( int width
)
3229 if ( width
== wxCOL_WIDTH_AUTOSIZE
)
3231 // NB: this disables user resizing
3232 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
3236 if ( width
== wxCOL_WIDTH_DEFAULT
)
3238 // TODO find a better calculation
3239 width
= wxDVC_DEFAULT_WIDTH
;
3242 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
3243 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
3247 void wxDataViewColumn::SetReorderable( bool reorderable
)
3249 gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column
), reorderable
);
3252 bool wxDataViewColumn::IsReorderable() const
3254 return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column
) );
3257 //-----------------------------------------------------------------------------
3258 // wxGtkTreeModelNode
3259 //-----------------------------------------------------------------------------
3262 class wxGtkTreeModelChildWithPos
3270 int wxGtkTreeModelChildWithPosCmp( const void* data1
, const void* data2
, const void* user_data
)
3272 const wxGtkTreeModelChildWithPos
* child1
= (const wxGtkTreeModelChildWithPos
*) data1
;
3273 const wxGtkTreeModelChildWithPos
* child2
= (const wxGtkTreeModelChildWithPos
*) data2
;
3274 const wxDataViewCtrlInternal
*internal
= (const wxDataViewCtrlInternal
*) user_data
;
3275 int ret
= internal
->GetDataViewModel()->Compare( child1
->id
, child2
->id
,
3276 internal
->GetSortColumn(), (internal
->GetSortOrder() == GTK_SORT_DESCENDING
) );
3282 int LINKAGEMODE
wxGtkTreeModelChildPtrCmp( void*** data1
, void*** data2
)
3284 return gs_internal
->GetDataViewModel()->Compare( wxDataViewItem(**data1
), wxDataViewItem(**data2
),
3285 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
3288 WX_DEFINE_ARRAY_PTR( void**, wxGtkTreeModelChildrenPtr
);
3291 void wxGtkTreeModelNode::Resort()
3293 size_t child_count
= GetChildCount();
3294 if (child_count
== 0)
3297 size_t node_count
= GetNodesCount();
3299 if (child_count
== 1)
3301 if (node_count
== 1)
3303 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
3309 gint
*new_order
= new gint
[child_count
];
3312 // m_children has the original *void
3313 // ptrs points to these
3314 wxGtkTreeModelChildrenPtr ptrs
;
3316 for (i
= 0; i
< child_count
; i
++)
3317 ptrs
.Add( &(m_children
[i
]) );
3319 gs_internal
= m_internal
;
3320 ptrs
.Sort( &wxGtkTreeModelChildPtrCmp
);
3322 wxGtkTreeModelChildren temp
;
3323 void** base_ptr
= &(m_children
[0]);
3324 // Transfer positions to new_order array and
3326 for (i
= 0; i
< child_count
; i
++)
3328 new_order
[i
] = ptrs
[i
] - base_ptr
;
3329 temp
.Add( *ptrs
[i
] );
3332 // Transfer IDs back to m_children
3334 WX_APPEND_ARRAY( temp
, m_children
);
3339 // Build up array with IDs and original positions
3340 wxGtkTreeModelChildWithPos
* temp
= new wxGtkTreeModelChildWithPos
[child_count
];
3342 for (i
= 0; i
< child_count
; i
++)
3345 temp
[i
].id
= m_children
[i
];
3347 // Sort array keeping original positions
3348 wxQsort( temp
, child_count
, sizeof(wxGtkTreeModelChildWithPos
),
3349 &wxGtkTreeModelChildWithPosCmp
, m_internal
);
3350 // Transfer positions to new_order array and
3351 // IDs to m_children
3353 for (i
= 0; i
< child_count
; i
++)
3355 new_order
[i
] = temp
[i
].pos
;
3356 m_children
.Add( temp
[i
].id
);
3365 wxGtkTreeModelChildren temp
;
3366 WX_APPEND_ARRAY( temp
, m_children
);
3368 gs_internal
= m_internal
;
3369 m_children
.Sort( &wxGtkTreeModelChildCmp
);
3372 for (pos
= 0; pos
< child_count
; pos
++)
3374 void *id
= m_children
.Item( pos
);
3375 int old_pos
= temp
.Index( id
);
3376 new_order
[pos
] = old_pos
;
3380 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
3383 iter
.user_data
= GetItem().GetID();
3384 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
3386 gtk_tree_model_rows_reordered( gtk_tree_model
,
3387 wxGtkTreePath(m_internal
->get_path(&iter
)), &iter
, new_order
);
3389 delete [] new_order
;
3392 for (pos
= 0; pos
< node_count
; pos
++)
3394 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
3399 //-----------------------------------------------------------------------------
3400 // wxDataViewCtrlInternal
3401 //-----------------------------------------------------------------------------
3403 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
)
3406 m_wx_model
= wx_model
;
3410 m_sort_order
= GTK_SORT_ASCENDING
;
3412 m_dataview_sort_column
= NULL
;
3414 m_dragDataObject
= NULL
;
3415 m_dropDataObject
= NULL
;
3419 m_gtk_model
= wxgtk_tree_model_new();
3420 m_gtk_model
->internal
= this;
3422 m_notifier
= new wxGtkDataViewModelNotifier( wx_model
, this );
3424 wx_model
->AddNotifier( m_notifier
);
3426 // g_object_unref( gtk_model ); ???
3428 if (!m_wx_model
->IsVirtualListModel())
3431 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->GtkGetTreeView()), GTK_TREE_MODEL(m_gtk_model
) );
3434 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
3436 m_wx_model
->RemoveNotifier( m_notifier
);
3438 // remove the model from the GtkTreeView before it gets destroyed
3439 gtk_tree_view_set_model( GTK_TREE_VIEW( m_owner
->GtkGetTreeView() ), NULL
);
3441 g_object_unref( m_gtk_model
);
3443 delete m_dragDataObject
;
3444 delete m_dropDataObject
;
3447 void wxDataViewCtrlInternal::ScheduleRefresh()
3452 void wxDataViewCtrlInternal::OnInternalIdle()
3456 GtkWidget
*widget
= m_owner
->GtkGetTreeView();
3457 gtk_widget_queue_draw( widget
);
3462 void wxDataViewCtrlInternal::InitTree()
3464 wxDataViewItem item
;
3465 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
3467 BuildBranch( m_root
);
3470 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
3472 if (node
->GetChildCount() == 0)
3474 wxDataViewItemArray children
;
3475 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
3478 for (pos
= 0; pos
< count
; pos
++)
3480 wxDataViewItem child
= children
[pos
];
3482 if (m_wx_model
->IsContainer( child
))
3483 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
3485 node
->AddLeaf( child
.GetID() );
3487 // Don't send any events here
3494 bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat
&format
)
3496 wxGtkString
atom_str( gdk_atom_name( format
) );
3497 m_dragSourceTargetEntryTarget
= wxCharBuffer( atom_str
);
3499 m_dragSourceTargetEntry
.target
= m_dragSourceTargetEntryTarget
.data();
3500 m_dragSourceTargetEntry
.flags
= 0;
3501 m_dragSourceTargetEntry
.info
= static_cast<guint
>(-1);
3503 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3504 GDK_BUTTON1_MASK
, &m_dragSourceTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3509 bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat
&format
)
3511 wxGtkString
atom_str( gdk_atom_name( format
) );
3512 m_dropTargetTargetEntryTarget
= wxCharBuffer( atom_str
);
3514 m_dropTargetTargetEntry
.target
= m_dropTargetTargetEntryTarget
.data();
3515 m_dropTargetTargetEntry
.flags
= 0;
3516 m_dropTargetTargetEntry
.info
= static_cast<guint
>(-1);
3518 gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3519 &m_dropTargetTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3524 gboolean
wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource
*WXUNUSED(drag_source
),
3527 delete m_dragDataObject
;
3528 m_dragDataObject
= NULL
;
3530 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3534 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3535 event
.SetEventObject( m_owner
);
3536 event
.SetItem( item
);
3537 event
.SetModel( m_wx_model
);
3539 gtk_widget_get_pointer(m_owner
->GtkGetTreeView(), &x
, &y
);
3540 event
.SetPosition(x
, y
);
3541 if (!m_owner
->HandleWindowEvent( event
))
3544 if (!event
.IsAllowed())
3547 wxDataObject
*obj
= event
.GetDataObject();
3551 m_dragDataObject
= obj
;
3557 wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource
*WXUNUSED(drag_source
),
3558 GtkTreePath
*WXUNUSED(path
))
3563 gboolean
wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource
*WXUNUSED(drag_source
),
3564 GtkTreePath
*path
, GtkSelectionData
*selection_data
)
3566 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3570 GdkAtom target
= gtk_selection_data_get_target(selection_data
);
3571 if (!m_dragDataObject
->IsSupported(target
))
3574 size_t size
= m_dragDataObject
->GetDataSize(target
);
3578 void *buf
= malloc( size
);
3580 gboolean res
= FALSE
;
3581 if (m_dragDataObject
->GetDataHere(target
, buf
))
3585 gtk_selection_data_set(selection_data
, target
,
3586 8, (const guchar
*) buf
, size
);
3595 wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3597 GtkSelectionData
*selection_data
)
3599 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3603 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
3604 event
.SetEventObject( m_owner
);
3605 event
.SetItem( item
);
3606 event
.SetModel( m_wx_model
);
3607 event
.SetDataFormat(gtk_selection_data_get_target(selection_data
));
3608 event
.SetDataSize(gtk_selection_data_get_length(selection_data
));
3609 event
.SetDataBuffer(const_cast<guchar
*>(gtk_selection_data_get_data(selection_data
)));
3610 if (!m_owner
->HandleWindowEvent( event
))
3613 if (!event
.IsAllowed())
3620 wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3622 GtkSelectionData
*selection_data
)
3624 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3628 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
3629 event
.SetEventObject( m_owner
);
3630 event
.SetItem( item
);
3631 event
.SetModel( m_wx_model
);
3632 event
.SetDataFormat(gtk_selection_data_get_target(selection_data
));
3633 if (!m_owner
->HandleWindowEvent( event
))
3636 if (!event
.IsAllowed())
3642 // notifications from wxDataViewModel
3644 bool wxDataViewCtrlInternal::Cleared()
3659 void wxDataViewCtrlInternal::Resort()
3661 if (!m_wx_model
->IsVirtualListModel())
3667 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3669 if (!m_wx_model
->IsVirtualListModel())
3671 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3672 wxCHECK_MSG(parent_node
, false,
3673 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3675 wxDataViewItemArray siblings
;
3676 m_wx_model
->GetChildren(parent
, siblings
);
3677 int itemPos
= siblings
.Index(item
, /*fromEnd=*/true);
3678 wxCHECK_MSG( itemPos
!= wxNOT_FOUND
, false, "adding non-existent item?" );
3680 if (m_wx_model
->IsContainer( item
))
3681 parent_node
->InsertNode( new wxGtkTreeModelNode( parent_node
, item
, this ), itemPos
);
3683 parent_node
->InsertLeaf( item
.GetID(), itemPos
);
3691 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3693 if (!m_wx_model
->IsVirtualListModel())
3695 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3696 wxASSERT_MSG(parent_node
,
3697 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3699 parent_node
->DeleteChild( item
.GetID() );
3707 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
3709 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3710 event
.SetEventObject( m_owner
);
3711 event
.SetModel( m_owner
->GetModel() );
3712 event
.SetItem( item
);
3713 m_owner
->HandleWindowEvent( event
);
3718 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int view_column
)
3720 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3721 event
.SetEventObject( m_owner
);
3722 event
.SetModel( m_owner
->GetModel() );
3723 event
.SetColumn( view_column
);
3724 event
.SetDataViewColumn( GetOwner()->GetColumn(view_column
) );
3725 event
.SetItem( item
);
3726 m_owner
->HandleWindowEvent( event
);
3733 GtkTreeModelFlags
wxDataViewCtrlInternal::get_flags()
3737 if ( m_wx_model
->IsListModel() )
3738 flags
|= GTK_TREE_MODEL_LIST_ONLY
;
3740 if ( !m_wx_model
->IsVirtualListModel() )
3741 flags
|= GTK_TREE_MODEL_ITERS_PERSIST
;
3743 return GtkTreeModelFlags(flags
);
3746 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
3749 if (m_wx_model
->IsVirtualListModel())
3751 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3753 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
3755 if (i
>= wx_model
->GetCount())
3758 iter
->stamp
= m_gtk_model
->stamp
;
3759 // user_data is just the index +1
3760 iter
->user_data
= (gpointer
) (i
+1);
3766 int depth
= gtk_tree_path_get_depth( path
);
3768 wxGtkTreeModelNode
*node
= m_root
;
3771 for (i
= 0; i
< depth
; i
++)
3773 BuildBranch( node
);
3775 gint pos
= gtk_tree_path_get_indices (path
)[i
];
3776 if (pos
< 0) return FALSE
;
3777 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
3779 void* id
= node
->GetChildren().Item( (size_t) pos
);
3783 iter
->stamp
= m_gtk_model
->stamp
;
3784 iter
->user_data
= id
;
3788 size_t count
= node
->GetNodes().GetCount();
3790 for (pos2
= 0; pos2
< count
; pos2
++)
3792 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
3793 if (child_node
->GetItem().GetID() == id
)
3805 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
3807 // When this is called from ItemDeleted(), the item is already
3808 // deleted in the model.
3810 GtkTreePath
*retval
= gtk_tree_path_new ();
3812 if (m_wx_model
->IsVirtualListModel())
3814 // iter is root, add nothing
3815 if (!iter
->user_data
)
3818 // user_data is just the index +1
3819 int i
= ( (wxUIntPtr
) iter
->user_data
) -1;
3820 gtk_tree_path_append_index (retval
, i
);
3824 void *id
= iter
->user_data
;
3826 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
3829 int pos
= node
->GetChildren().Index( id
);
3831 gtk_tree_path_prepend_index( retval
, pos
);
3833 id
= node
->GetItem().GetID();
3834 node
= node
->GetParent();
3841 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
3843 if (m_wx_model
->IsVirtualListModel())
3845 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3847 // user_data is just the index +1
3848 int n
= ( (wxUIntPtr
) iter
->user_data
) -1;
3852 iter
->user_data
= NULL
;
3856 if (n
>= (int) wx_model
->GetCount()-1)
3858 iter
->user_data
= NULL
;
3862 // user_data is just the index +1 (+2 because we need the next)
3863 iter
->user_data
= (gpointer
) (n
+2);
3867 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
3868 if( parent
== NULL
)
3870 iter
->user_data
= NULL
;
3874 int pos
= parent
->GetChildren().Index( iter
->user_data
);
3876 if (pos
== (int) parent
->GetChildCount()-1)
3878 iter
->user_data
= NULL
;
3882 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
3888 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
3890 if (m_wx_model
->IsVirtualListModel())
3892 // this is a list, nodes have no children
3896 iter
->stamp
= m_gtk_model
->stamp
;
3897 iter
->user_data
= (gpointer
) 1;
3905 if (m_root
->GetChildCount() == 0) return FALSE
;
3906 iter
->stamp
= m_gtk_model
->stamp
;
3907 iter
->user_data
= (gpointer
) m_root
->GetChildren().Item( 0 );
3912 wxDataViewItem item
;
3914 item
= wxDataViewItem( (void*) parent
->user_data
);
3916 if (!m_wx_model
->IsContainer( item
))
3919 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3920 wxASSERT_MSG(parent_node
,
3921 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3923 BuildBranch( parent_node
);
3925 if (parent_node
->GetChildCount() == 0)
3928 iter
->stamp
= m_gtk_model
->stamp
;
3929 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
3935 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
3937 if (m_wx_model
->IsVirtualListModel())
3939 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3942 return (wx_model
->GetCount() > 0);
3944 // this is a list, nodes have no children
3950 return (m_root
->GetChildCount() > 0);
3952 wxDataViewItem
item( (void*) iter
->user_data
);
3954 bool is_container
= m_wx_model
->IsContainer( item
);
3959 wxGtkTreeModelNode
*node
= FindNode( iter
);
3961 "Did you forget a call to ItemAdded()? The iterator is unknown to the wxGtkTreeModel");
3963 BuildBranch( node
);
3965 return (node
->GetChildCount() > 0);
3969 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
3971 if (m_wx_model
->IsVirtualListModel())
3973 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3976 return (gint
) wx_model
->GetCount();
3983 return m_root
->GetChildCount();
3985 wxDataViewItem
item( (void*) iter
->user_data
);
3987 if (!m_wx_model
->IsContainer( item
))
3990 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
3991 wxASSERT_MSG(parent_node
,
3992 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3994 BuildBranch( parent_node
);
3996 return parent_node
->GetChildCount();
4000 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
4002 if (m_wx_model
->IsVirtualListModel())
4004 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
4012 if (n
>= (gint
) wx_model
->GetCount())
4015 iter
->stamp
= m_gtk_model
->stamp
;
4016 // user_data is just the index +1
4017 iter
->user_data
= (gpointer
) (n
+1);
4024 if (parent
) id
= (void*) parent
->user_data
;
4025 wxDataViewItem
item( id
);
4027 if (!m_wx_model
->IsContainer( item
))
4030 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
4031 wxASSERT_MSG(parent_node
,
4032 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
4034 BuildBranch( parent_node
);
4036 iter
->stamp
= m_gtk_model
->stamp
;
4037 iter
->user_data
= parent_node
->GetChildren().Item( n
);
4043 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
4045 if (m_wx_model
->IsVirtualListModel())
4051 wxGtkTreeModelNode
*node
= FindParentNode( child
);
4055 iter
->stamp
= m_gtk_model
->stamp
;
4056 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
4062 // item can be deleted already in the model
4063 int wxDataViewCtrlInternal::GetIndexOf( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
4065 if (m_wx_model
->IsVirtualListModel())
4067 return wxPtrToUInt(item
.GetID()) - 1;
4071 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
4072 wxGtkTreeModelChildren
&children
= parent_node
->GetChildren();
4074 for (j
= 0; j
< children
.GetCount(); j
++)
4076 if (children
[j
] == item
.GetID())
4084 static wxGtkTreeModelNode
*
4085 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
4091 list
.DeleteContents( true );
4092 wxDataViewItem
it( item
);
4096 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
4097 list
.Insert( pItem
);
4098 it
= model
->GetParent( it
);
4101 wxGtkTreeModelNode
* node
= treeNode
;
4102 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
4104 if( node
&& node
->GetNodes().GetCount() != 0 )
4106 int len
= node
->GetNodes().GetCount();
4107 wxGtkTreeModelNodes
&nodes
= node
->GetNodes();
4109 for( ; j
< len
; j
++)
4111 if( nodes
[j
]->GetItem() == *(n
->GetData()))
4130 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
4135 wxDataViewItem
item( (void*) iter
->user_data
);
4139 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
4144 wxLogDebug( "Not found %p", iter->user_data );
4148 // TODO: remove this code
4154 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
4159 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
4164 wxLogDebug( "Not found %p", item.GetID() );
4168 // TODO: remove this code
4174 static wxGtkTreeModelNode
*
4175 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
4181 list
.DeleteContents( true );
4185 wxDataViewItem
it( model
->GetParent( item
) );
4188 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
4189 list
.Insert( pItem
);
4190 it
= model
->GetParent( it
);
4193 wxGtkTreeModelNode
* node
= treeNode
;
4194 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
4196 if( node
&& node
->GetNodes().GetCount() != 0 )
4198 int len
= node
->GetNodes().GetCount();
4199 wxGtkTreeModelNodes nodes
= node
->GetNodes();
4201 for( ; j
< len
; j
++)
4203 if( nodes
[j
]->GetItem() == *(n
->GetData()))
4218 //Examine whether the node is item's parent node
4219 int len
= node
->GetChildCount();
4220 for( int i
= 0; i
< len
; i
++ )
4222 if( node
->GetChildren().Item( i
) == item
.GetID() )
4228 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
4233 wxDataViewItem
item( (void*) iter
->user_data
);
4237 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
4240 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
4245 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
4248 //-----------------------------------------------------------------------------
4249 // wxDataViewCtrl signal callbacks
4250 //-----------------------------------------------------------------------------
4253 wxdataview_selection_changed_callback( GtkTreeSelection
* WXUNUSED(selection
), wxDataViewCtrl
*dv
)
4255 if (!gtk_widget_get_realized(dv
->m_widget
))
4258 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
4259 event
.SetItem( dv
->GetSelection() );
4260 event
.SetModel( dv
->GetModel() );
4261 dv
->HandleWindowEvent( event
);
4265 wxdataview_row_activated_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreePath
*path
,
4266 GtkTreeViewColumn
*WXUNUSED(column
), wxDataViewCtrl
*dv
)
4268 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
4270 wxDataViewItem
item(dv
->GTKPathToItem(path
));
4271 event
.SetItem( item
);
4272 event
.SetModel( dv
->GetModel() );
4273 dv
->HandleWindowEvent( event
);
4277 wxdataview_test_expand_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4278 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4280 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
4282 wxDataViewItem
item( (void*) iter
->user_data
);;
4283 event
.SetItem( item
);
4284 event
.SetModel( dv
->GetModel() );
4285 dv
->HandleWindowEvent( event
);
4287 return !event
.IsAllowed();
4291 wxdataview_row_expanded_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4292 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4294 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
4296 wxDataViewItem
item( (void*) iter
->user_data
);;
4297 event
.SetItem( item
);
4298 event
.SetModel( dv
->GetModel() );
4299 dv
->HandleWindowEvent( event
);
4303 wxdataview_test_collapse_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4304 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4306 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
4308 wxDataViewItem
item( (void*) iter
->user_data
);;
4309 event
.SetItem( item
);
4310 event
.SetModel( dv
->GetModel() );
4311 dv
->HandleWindowEvent( event
);
4313 return !event
.IsAllowed();
4317 wxdataview_row_collapsed_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4318 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4320 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
4322 wxDataViewItem
item( (void*) iter
->user_data
);;
4323 event
.SetItem( item
);
4324 event
.SetModel( dv
->GetModel() );
4325 dv
->HandleWindowEvent( event
);
4328 //-----------------------------------------------------------------------------
4330 //-----------------------------------------------------------------------------
4332 void wxDataViewCtrl::AddChildGTK(wxWindowGTK
* child
)
4334 GtkWidget
* treeview
= GtkGetTreeView();
4336 // Insert widget in GtkTreeView
4337 if (gtk_widget_get_realized(treeview
))
4338 gtk_widget_set_parent_window( child
->m_widget
,
4339 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
4340 gtk_widget_set_parent( child
->m_widget
, treeview
);
4344 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
4345 GtkAllocation
*WXUNUSED(gtk_alloc
),
4346 wxDataViewCtrl
*win
)
4348 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
4351 wxWindow
*child
= node
->GetData();
4354 gtk_widget_size_request( child
->m_widget
, &req
);
4356 GtkAllocation alloc
;
4357 alloc
.x
= child
->m_x
;
4358 alloc
.y
= child
->m_y
;
4359 alloc
.width
= child
->m_width
;
4360 alloc
.height
= child
->m_height
;
4361 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
4363 node
= node
->GetNext();
4368 //-----------------------------------------------------------------------------
4369 // "motion_notify_event"
4370 //-----------------------------------------------------------------------------
4373 gtk_dataview_motion_notify_callback( GtkWidget
*WXUNUSED(widget
),
4374 GdkEventMotion
*gdk_event
,
4375 wxDataViewCtrl
*dv
)
4377 if (gdk_event
->is_hint
)
4381 GdkModifierType state
;
4382 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
4388 GtkTreeViewColumn
*column
= NULL
;
4391 if (gtk_tree_view_get_path_at_pos(
4392 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4393 (int) gdk_event
->x
, (int) gdk_event
->y
,
4402 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4410 //-----------------------------------------------------------------------------
4411 // "button_press_event"
4412 //-----------------------------------------------------------------------------
4415 gtk_dataview_button_press_callback( GtkWidget
*WXUNUSED(widget
),
4416 GdkEventButton
*gdk_event
,
4417 wxDataViewCtrl
*dv
)
4419 if ((gdk_event
->button
== 3) && (gdk_event
->type
== GDK_BUTTON_PRESS
))
4422 GtkTreeViewColumn
*column
= NULL
;
4425 gtk_tree_view_get_path_at_pos
4427 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4428 (int) gdk_event
->x
, (int) gdk_event
->y
,
4435 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, dv
->GetId() );
4437 event
.SetItem(dv
->GTKPathToItem(path
));
4438 event
.SetModel( dv
->GetModel() );
4439 return dv
->HandleWindowEvent( event
);
4445 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
4447 wxDataViewCtrl::~wxDataViewCtrl()
4449 // Stop editing before destroying the control to remove any event handlers
4450 // which are added when editing started: if we didn't do this, the base
4451 // class dtor would assert as it checks for any leftover handlers.
4454 GtkTreeViewColumn
*col
;
4455 gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview
), NULL
, &col
);
4457 wxDataViewColumn
* const wxcol
= FromGTKColumn(col
);
4460 // This won't do anything if we're not editing it
4461 wxcol
->GetRenderer()->CancelEditing();
4470 void wxDataViewCtrl::Init()
4474 m_cols
.DeleteContents( true );
4476 m_uniformRowHeight
= -1;
4479 bool wxDataViewCtrl::Create(wxWindow
*parent
,
4484 const wxValidator
& validator
,
4485 const wxString
& name
)
4487 if (!PreCreation( parent
, pos
, size
) ||
4488 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
4490 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
4494 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
4495 g_object_ref(m_widget
);
4497 GTKScrolledWindowSetBorder(m_widget
, style
);
4499 m_treeview
= gtk_tree_view_new();
4500 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
4502 m_focusWidget
= GTK_WIDGET(m_treeview
);
4504 g_signal_connect (m_treeview
, "size_allocate",
4505 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
4508 if (!gtk_check_version(2,6,0))
4510 bool fixed
= (style
& wxDV_VARIABLE_LINE_HEIGHT
) == 0;
4511 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4515 if (style
& wxDV_MULTIPLE
)
4517 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4518 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
4521 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
4524 if (!gtk_check_version(2,10,0))
4526 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
4528 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
4529 (style
& wxDV_VERT_RULES
) != 0)
4530 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
4531 else if (style
& wxDV_VERT_RULES
)
4532 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
4533 else if (style
& wxDV_HORIZ_RULES
)
4534 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
4536 if (grid
!= GTK_TREE_VIEW_GRID_LINES_NONE
)
4537 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
4541 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_ROW_LINES
) != 0 );
4543 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
4544 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
4545 gtk_widget_show (m_treeview
);
4547 m_parent
->DoAddChild( this );
4551 GtkEnableSelectionEvents();
4553 g_signal_connect_after (m_treeview
, "row-activated",
4554 G_CALLBACK (wxdataview_row_activated_callback
), this);
4556 g_signal_connect (m_treeview
, "test-collapse-row",
4557 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
4559 g_signal_connect_after (m_treeview
, "row-collapsed",
4560 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
4562 g_signal_connect (m_treeview
, "test-expand-row",
4563 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
4565 g_signal_connect_after (m_treeview
, "row-expanded",
4566 G_CALLBACK (wxdataview_row_expanded_callback
), this);
4568 g_signal_connect (m_treeview
, "motion_notify_event",
4569 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
4571 g_signal_connect (m_treeview
, "button_press_event",
4572 G_CALLBACK (gtk_dataview_button_press_callback
), this);
4577 wxDataViewItem
wxDataViewCtrl::GTKPathToItem(GtkTreePath
*path
) const
4580 return wxDataViewItem(path
&& m_internal
->get_iter(&iter
, path
)
4585 void wxDataViewCtrl::OnInternalIdle()
4587 wxWindow::OnInternalIdle();
4589 m_internal
->OnInternalIdle();
4591 unsigned int cols
= GetColumnCount();
4593 for (i
= 0; i
< cols
; i
++)
4595 wxDataViewColumn
*col
= GetColumn( i
);
4596 col
->OnInternalIdle();
4599 if (m_ensureVisibleDefered
.IsOk())
4601 ExpandAncestors(m_ensureVisibleDefered
);
4603 iter
.user_data
= (gpointer
) m_ensureVisibleDefered
.GetID();
4604 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4605 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
4606 m_ensureVisibleDefered
= wxDataViewItem(0);
4610 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4612 wxDELETE(m_internal
);
4614 if (!wxDataViewCtrlBase::AssociateModel( model
))
4618 if (!gtk_check_version(2,6,0))
4620 bool fixed
= (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
) == 0) || (model
->IsVirtualListModel()));
4621 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4625 m_internal
= new wxDataViewCtrlInternal( this, model
);
4630 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4632 return m_internal
->EnableDragSource( format
);
4635 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4637 return m_internal
->EnableDropTarget( format
);
4640 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4642 if (!wxDataViewCtrlBase::AppendColumn(col
))
4645 m_cols
.Append( col
);
4648 if (!gtk_check_version(2,6,0))
4650 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4651 GTK_TREE_VIEW_COLUMN_FIXED
)
4652 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4656 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
4657 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4662 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4664 if (!wxDataViewCtrlBase::PrependColumn(col
))
4667 m_cols
.Insert( col
);
4670 if (!gtk_check_version(2,6,0))
4672 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4673 GTK_TREE_VIEW_COLUMN_FIXED
)
4674 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4678 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4679 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
4684 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4686 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4689 m_cols
.Insert( pos
, col
);
4692 if (!gtk_check_version(2,6,0))
4694 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4695 GTK_TREE_VIEW_COLUMN_FIXED
)
4696 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4700 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4701 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), pos
);
4706 unsigned int wxDataViewCtrl::GetColumnCount() const
4708 return m_cols
.GetCount();
4711 wxDataViewColumn
* wxDataViewCtrl::FromGTKColumn(GtkTreeViewColumn
*gtk_col
) const
4716 wxDataViewColumnList::const_iterator iter
;
4717 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4719 wxDataViewColumn
*col
= *iter
;
4720 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
4726 wxFAIL_MSG( "No matching column?" );
4731 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
4733 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
4735 return FromGTKColumn(gtk_col
);
4738 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4740 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4741 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
4743 m_cols
.DeleteObject( column
);
4748 bool wxDataViewCtrl::ClearColumns()
4750 wxDataViewColumnList::iterator iter
;
4751 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4753 wxDataViewColumn
*col
= *iter
;
4754 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4755 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4763 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4765 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
4767 wxGtkList
list(gtk_tree_view_get_columns(GTK_TREE_VIEW(m_treeview
)));
4769 return g_list_index( list
, (gconstpointer
) gtk_column
);
4772 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4774 return m_internal
->GetDataViewSortColumn();
4777 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4780 iter
.user_data
= item
.GetID();
4781 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4782 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
4785 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4788 iter
.user_data
= item
.GetID();
4789 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4790 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
4793 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4796 iter
.user_data
= item
.GetID();
4797 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4798 return gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview
), path
);
4801 wxDataViewItem
wxDataViewCtrl::DoGetCurrentItem() const
4803 // The tree doesn't have any current item if it hadn't been created yet but
4804 // it's arguably not an error to call this function in this case so just
4805 // return an invalid item without asserting.
4807 return wxDataViewItem();
4810 gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview
), path
.ByRef(), NULL
);
4812 return GTKPathToItem(path
);
4815 void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem
& item
)
4817 wxCHECK_RET( m_treeview
,
4818 "Current item can't be set before creating the control." );
4820 // We need to make sure the model knows about this item or the path would
4821 // be invalid and gtk_tree_view_set_cursor() would silently do nothing.
4822 ExpandAncestors(item
);
4824 // We also need to preserve the existing selection from changing.
4825 // Unfortunately the only way to do it seems to use our own selection
4826 // function and forbid any selection changes during set cursor call.
4827 wxGtkTreeSelectionLock
4828 lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview
)));
4830 // Do move the cursor now.
4832 iter
.user_data
= item
.GetID();
4833 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4835 gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview
), path
, NULL
, FALSE
);
4838 void wxDataViewCtrl::StartEditor(const wxDataViewItem
& item
, unsigned int column
)
4840 wxCHECK_RET( m_treeview
,
4841 "Current item can't be set before creating the control." );
4843 // We need to make sure the model knows about this item or the path would
4844 // be invalid and gtk_tree_view_set_cursor() would silently do nothing.
4845 ExpandAncestors(item
);
4847 wxDataViewColumn
*dvcolumn
= GetColumn(column
);
4848 wxASSERT_MSG(dvcolumn
, "Could not retrieve column");
4849 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(dvcolumn
->GetGtkHandle());
4851 // We also need to preserve the existing selection from changing.
4852 // Unfortunately the only way to do it seems to use our own selection
4853 // function and forbid any selection changes during set cursor call.
4854 wxGtkTreeSelectionLock
4855 lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview
)));
4857 // Do move the cursor now.
4859 iter
.user_data
= item
.GetID();
4860 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4862 gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview
), path
, gcolumn
, TRUE
);
4865 int wxDataViewCtrl::GetSelectedItemsCount() const
4867 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4869 return gtk_tree_selection_count_selected_rows(selection
);
4872 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4876 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4877 if (HasFlag(wxDV_MULTIPLE
))
4879 GtkTreeModel
*model
;
4880 wxGtkTreePathList
list(gtk_tree_selection_get_selected_rows(selection
, &model
));
4882 for ( GList
* current
= list
; current
; current
= g_list_next(current
) )
4884 GtkTreePath
*path
= (GtkTreePath
*) current
->data
;
4886 sel
.Add(GTKPathToItem(path
));
4892 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
4894 sel
.Add( wxDataViewItem(iter
.user_data
) );
4901 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4903 GtkDisableSelectionEvents();
4905 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4907 gtk_tree_selection_unselect_all( selection
);
4909 wxDataViewItem last_parent
;
4912 for (i
= 0; i
< sel
.GetCount(); i
++)
4914 wxDataViewItem item
= sel
[i
];
4915 wxDataViewItem parent
= GetModel()->GetParent( item
);
4918 if (parent
!= last_parent
)
4919 ExpandAncestors(item
);
4921 last_parent
= parent
;
4924 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4925 iter
.user_data
= (gpointer
) item
.GetID();
4926 gtk_tree_selection_select_iter( selection
, &iter
);
4929 GtkEnableSelectionEvents();
4932 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4934 ExpandAncestors(item
);
4936 GtkDisableSelectionEvents();
4938 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4941 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4942 iter
.user_data
= (gpointer
) item
.GetID();
4943 gtk_tree_selection_select_iter( selection
, &iter
);
4945 GtkEnableSelectionEvents();
4948 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4950 GtkDisableSelectionEvents();
4952 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4955 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4956 iter
.user_data
= (gpointer
) item
.GetID();
4957 gtk_tree_selection_unselect_iter( selection
, &iter
);
4959 GtkEnableSelectionEvents();
4962 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4964 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4967 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4968 iter
.user_data
= (gpointer
) item
.GetID();
4970 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
4973 void wxDataViewCtrl::SelectAll()
4975 GtkDisableSelectionEvents();
4977 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4979 gtk_tree_selection_select_all( selection
);
4981 GtkEnableSelectionEvents();
4984 void wxDataViewCtrl::UnselectAll()
4986 GtkDisableSelectionEvents();
4988 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4990 gtk_tree_selection_unselect_all( selection
);
4992 GtkEnableSelectionEvents();
4995 void wxDataViewCtrl::EnsureVisible(const wxDataViewItem
& item
,
4996 const wxDataViewColumn
*WXUNUSED(column
))
4998 m_ensureVisibleDefered
= item
;
4999 ExpandAncestors(item
);
5002 iter
.user_data
= (gpointer
) item
.GetID();
5003 wxGtkTreePath
path(m_internal
->get_path( &iter
));
5004 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
5007 void wxDataViewCtrl::HitTest(const wxPoint
& point
,
5008 wxDataViewItem
& item
,
5009 wxDataViewColumn
*& column
) const
5011 // gtk_tree_view_get_dest_row_at_pos() is the right one. But it does not tell the column.
5012 // gtk_tree_view_get_path_at_pos() is the wrong function. It doesn't mind the header but returns column.
5013 // See http://mail.gnome.org/archives/gtkmm-list/2005-January/msg00080.html
5014 // So we have to use both of them.
5015 // Friedrich Haase 2010-9-20
5016 wxGtkTreePath path
, pathScratch
;
5017 GtkTreeViewColumn
* GtkColumn
= NULL
;
5018 GtkTreeViewDropPosition pos
= GTK_TREE_VIEW_DROP_INTO_OR_AFTER
;
5022 // cannot directly call GtkGetTreeView(), HitTest is const and so is this pointer
5023 wxDataViewCtrl
* ctrl
= (wxDataViewCtrl
*)this; // ugly workaround, ctrl is NOT const
5024 GtkTreeView
* treeView
= GTK_TREE_VIEW(ctrl
->GtkGetTreeView());
5026 // is there possibly a better suited function to get the column?
5027 gtk_tree_view_get_path_at_pos( // and this is the wrong call but it delivers the column
5029 (int) point
.x
, (int) point
.y
,
5030 pathScratch
.ByRef(),
5031 &GtkColumn
, // here we get the GtkColumn
5035 if ( GtkColumn
!= NULL
)
5037 // we got GTK column
5038 // the right call now which takes the header into account
5039 gtk_tree_view_get_dest_row_at_pos( treeView
, (int) point
.x
, (int) point
.y
, path
.ByRef(), &pos
);
5042 item
= wxDataViewItem(GTKPathToItem(path
));
5043 // else we got a GTK column but the position is not over an item, e.g. below last item
5044 for ( unsigned int i
=0, cols
=GetColumnCount(); i
<cols
; ++i
) // search the wx column
5046 wxDataViewColumn
* col
= GetColumn(i
);
5047 if ( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == GtkColumn
)
5049 column
= col
; // here we get the wx column
5054 // else no column and thus no item, both null
5058 wxDataViewCtrl::GetItemRect(const wxDataViewItem
& WXUNUSED(item
),
5059 const wxDataViewColumn
*WXUNUSED(column
)) const
5064 bool wxDataViewCtrl::SetRowHeight(int rowHeight
)
5066 m_uniformRowHeight
= rowHeight
;
5070 void wxDataViewCtrl::DoSetExpanderColumn()
5072 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
5073 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
5076 void wxDataViewCtrl::DoSetIndent()
5080 void wxDataViewCtrl::GtkDisableSelectionEvents()
5082 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5083 g_signal_handlers_disconnect_by_func( selection
,
5084 (gpointer
) (wxdataview_selection_changed_callback
), this);
5087 void wxDataViewCtrl::GtkEnableSelectionEvents()
5089 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5090 g_signal_connect_after (selection
, "changed",
5091 G_CALLBACK (wxdataview_selection_changed_callback
), this);
5094 // ----------------------------------------------------------------------------
5095 // visual attributes stuff
5096 // ----------------------------------------------------------------------------
5100 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
5102 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
5105 void wxDataViewCtrl::DoApplyWidgetStyle(GtkRcStyle
*style
)
5107 wxDataViewCtrlBase::DoApplyWidgetStyle(style
);
5108 gtk_widget_modify_style(m_treeview
, style
);
5111 #endif // !wxUSE_GENERICDATAVIEWCTRL
5113 #endif // wxUSE_DATAVIEWCTRL