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"
25 #include "wx/settings.h"
26 #include "wx/dataobj.h"
30 #include "wx/stockitem.h"
31 #include "wx/calctrl.h"
32 #include "wx/popupwin.h"
33 #include "wx/listimpl.cpp"
35 #include "wx/gtk/private.h"
36 #include "wx/gtk/dc.h"
37 #include "wx/gtk/dcclient.h"
39 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 class wxDataViewCtrlInternal
;
44 wxDataViewCtrlInternal
*g_internal
= NULL
;
46 class wxGtkTreeModelNode
;
49 typedef struct _GtkWxTreeModel GtkWxTreeModel
;
52 //-----------------------------------------------------------------------------
53 // wxDataViewCtrlInternal
54 //-----------------------------------------------------------------------------
56 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
57 WX_DEFINE_LIST(ItemList
)
59 class wxDataViewCtrlInternal
62 wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
);
63 ~wxDataViewCtrlInternal();
66 GtkTreeModelFlags
get_flags();
67 gboolean
get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
);
68 GtkTreePath
*get_path( GtkTreeIter
*iter
);
69 gboolean
iter_next( GtkTreeIter
*iter
);
70 gboolean
iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
);
71 gboolean
iter_has_child( GtkTreeIter
*iter
);
72 gint
iter_n_children( GtkTreeIter
*iter
);
73 gboolean
iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
);
74 gboolean
iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
);
77 gboolean
row_draggable( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
);
78 gboolean
drag_data_delete( GtkTreeDragSource
*drag_source
, GtkTreePath
* path
);
79 gboolean
drag_data_get( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
,
80 GtkSelectionData
*selection_data
);
81 gboolean
drag_data_received( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest
,
82 GtkSelectionData
*selection_data
);
83 gboolean
row_drop_possible( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest_path
,
84 GtkSelectionData
*selection_data
);
86 // notifactions from wxDataViewModel
87 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
88 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
89 bool ItemChanged( const wxDataViewItem
&item
);
90 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
95 void SetSortOrder( GtkSortType sort_order
) { m_sort_order
= sort_order
; }
96 GtkSortType
GetSortOrder() { return m_sort_order
; }
98 void SetSortColumn( int column
) { m_sort_column
= column
; }
99 int GetSortColumn() { return m_sort_column
; }
101 void SetDataViewSortColumn( wxDataViewColumn
*column
) { m_dataview_sort_column
= column
; }
102 wxDataViewColumn
*GetDataViewSortColumn() { return m_dataview_sort_column
; }
104 bool IsSorted() { return (m_sort_column
>= 0); }
107 wxDataViewModel
* GetDataViewModel() { return m_wx_model
; }
108 wxDataViewCtrl
* GetOwner() { return m_owner
; }
109 GtkWxTreeModel
* GetGtkModel() { return m_gtk_model
; }
113 wxGtkTreeModelNode
*FindNode( const wxDataViewItem
&item
);
114 wxGtkTreeModelNode
*FindNode( GtkTreeIter
*iter
);
115 wxGtkTreeModelNode
*FindParentNode( const wxDataViewItem
&item
);
116 wxGtkTreeModelNode
*FindParentNode( GtkTreeIter
*iter
);
117 void BuildBranch( wxGtkTreeModelNode
*branch
);
120 wxGtkTreeModelNode
*m_root
;
121 wxDataViewModel
*m_wx_model
;
122 GtkWxTreeModel
*m_gtk_model
;
123 wxDataViewCtrl
*m_owner
;
124 GtkSortType m_sort_order
;
125 wxDataViewColumn
*m_dataview_sort_column
;
130 //-----------------------------------------------------------------------------
131 // wxGtkTreeModelNode
132 //-----------------------------------------------------------------------------
134 int LINKAGEMODE
wxGtkTreeModelChildCmp( void** id1
, void** id2
)
136 int ret
= g_internal
->GetDataViewModel()->Compare( *id1
, *id2
,
137 g_internal
->GetSortColumn(), (g_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
142 WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode
*, wxGtkTreeModelNodes
);
143 WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren
);
145 class wxGtkTreeModelNode
148 wxGtkTreeModelNode( wxGtkTreeModelNode
* parent
, const wxDataViewItem
&item
,
149 wxDataViewCtrlInternal
*internal
)
153 m_internal
= internal
;
156 ~wxGtkTreeModelNode()
158 size_t count
= m_nodes
.GetCount();
160 for (i
= 0; i
< count
; i
++)
162 wxGtkTreeModelNode
*child
= m_nodes
.Item( i
);
167 unsigned int AddNode( wxGtkTreeModelNode
* child
)
169 m_nodes
.Add( child
);
171 void *id
= child
->GetItem().GetID();
173 m_children
.Add( id
);
175 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
177 g_internal
= m_internal
;
178 m_children
.Sort( &wxGtkTreeModelChildCmp
);
179 return m_children
.Index( id
);
182 return m_children
.GetCount()-1;
185 unsigned int AddLeave( void* id
)
187 m_children
.Add( id
);
189 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
191 g_internal
= m_internal
;
192 m_children
.Sort( &wxGtkTreeModelChildCmp
);
193 return m_children
.Index( id
);
196 return m_children
.GetCount()-1;
199 void DeleteChild( void* id
)
201 m_children
.Remove( id
);
203 unsigned int count
= m_nodes
.GetCount();
205 for (pos
= 0; pos
< count
; pos
++)
207 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
208 if (node
->GetItem().GetID() == id
)
210 m_nodes
.RemoveAt( pos
);
218 wxGtkTreeModelNode
* GetParent()
220 wxGtkTreeModelNodes
&GetNodes()
222 wxGtkTreeModelChildren
&GetChildren()
223 { return m_children
; }
225 unsigned int GetChildCount() { return m_children
.GetCount(); }
226 unsigned int GetNodesCount() { return m_nodes
.GetCount(); }
228 wxDataViewItem
&GetItem() { return m_item
; }
229 wxDataViewCtrlInternal
*GetInternal() { return m_internal
; }
234 wxGtkTreeModelNode
*m_parent
;
235 wxGtkTreeModelNodes m_nodes
;
236 wxGtkTreeModelChildren m_children
;
237 wxDataViewItem m_item
;
238 wxDataViewCtrlInternal
*m_internal
;
242 //-----------------------------------------------------------------------------
244 //-----------------------------------------------------------------------------
246 extern bool g_blockEventsOnDrag
;
248 //-----------------------------------------------------------------------------
249 // define new GTK+ class wxGtkTreeModel
250 //-----------------------------------------------------------------------------
254 #define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ())
255 #define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel))
256 #define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
257 #define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL))
258 #define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL))
259 #define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
261 GType
gtk_wx_tree_model_get_type (void);
263 typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass
;
265 struct _GtkWxTreeModel
271 wxDataViewCtrlInternal
*internal
;
274 struct _GtkWxTreeModelClass
276 GObjectClass list_parent_class
;
279 static GtkWxTreeModel
*wxgtk_tree_model_new (void);
280 static void wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
);
281 static void wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
);
283 static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
);
284 static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
);
285 static void wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
);
286 static void wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
);
288 static void wxgtk_tree_model_finalize (GObject
*object
);
289 static GtkTreeModelFlags
wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
);
290 static gint
wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
);
291 static GType
wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
293 static gboolean
wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
296 static GtkTreePath
*wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
298 static void wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
302 static gboolean
wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
304 static gboolean
wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
306 GtkTreeIter
*parent
);
307 static gboolean
wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
309 static gint
wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
311 static gboolean
wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
315 static gboolean
wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
320 static gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
321 gint
*sort_column_id
,
323 static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
326 static void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
328 GtkTreeIterCompareFunc func
,
330 GtkDestroyNotify destroy
);
331 static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
332 GtkTreeIterCompareFunc func
,
334 GtkDestroyNotify destroy
);
335 static gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
);
338 static gboolean
wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
340 static gboolean
wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
342 static gboolean
wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
344 GtkSelectionData
*selection_data
);
345 static gboolean
wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
347 GtkSelectionData
*selection_data
);
348 static gboolean
wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
349 GtkTreePath
*dest_path
,
350 GtkSelectionData
*selection_data
);
353 static GObjectClass
*list_parent_class
= NULL
;
356 gtk_wx_tree_model_get_type (void)
358 static GType tree_model_type
= 0;
360 if (!tree_model_type
)
362 const GTypeInfo tree_model_info
=
364 sizeof (GtkWxTreeModelClass
),
365 NULL
, /* base_init */
366 NULL
, /* base_finalize */
367 (GClassInitFunc
) wxgtk_tree_model_class_init
,
368 NULL
, /* class_finalize */
369 NULL
, /* class_data */
370 sizeof (GtkWxTreeModel
),
372 (GInstanceInitFunc
) wxgtk_tree_model_init
,
375 static const GInterfaceInfo tree_model_iface_info
=
377 (GInterfaceInitFunc
) wxgtk_tree_model_tree_model_init
,
382 static const GInterfaceInfo sortable_iface_info
=
384 (GInterfaceInitFunc
) wxgtk_tree_model_sortable_init
,
389 static const GInterfaceInfo drag_source_iface_info
=
391 (GInterfaceInitFunc
) wxgtk_tree_model_drag_source_init
,
396 static const GInterfaceInfo drag_dest_iface_info
=
398 (GInterfaceInitFunc
) wxgtk_tree_model_drag_dest_init
,
403 tree_model_type
= g_type_register_static (G_TYPE_OBJECT
, "GtkWxTreeModel",
404 &tree_model_info
, (GTypeFlags
)0 );
406 g_type_add_interface_static (tree_model_type
,
408 &tree_model_iface_info
);
409 g_type_add_interface_static (tree_model_type
,
410 GTK_TYPE_TREE_SORTABLE
,
411 &sortable_iface_info
);
412 g_type_add_interface_static (tree_model_type
,
413 GTK_TYPE_TREE_DRAG_DEST
,
414 &drag_dest_iface_info
);
415 g_type_add_interface_static (tree_model_type
,
416 GTK_TYPE_TREE_DRAG_SOURCE
,
417 &drag_source_iface_info
);
420 return tree_model_type
;
423 static GtkWxTreeModel
*
424 wxgtk_tree_model_new(void)
426 GtkWxTreeModel
*retval
= (GtkWxTreeModel
*) g_object_new (GTK_TYPE_WX_TREE_MODEL
, NULL
);
431 wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
)
433 list_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
434 GObjectClass
*object_class
= (GObjectClass
*) klass
;
435 object_class
->finalize
= wxgtk_tree_model_finalize
;
439 wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
)
441 iface
->get_flags
= wxgtk_tree_model_get_flags
;
442 iface
->get_n_columns
= wxgtk_tree_model_get_n_columns
;
443 iface
->get_column_type
= wxgtk_tree_model_get_column_type
;
444 iface
->get_iter
= wxgtk_tree_model_get_iter
;
445 iface
->get_path
= wxgtk_tree_model_get_path
;
446 iface
->get_value
= wxgtk_tree_model_get_value
;
447 iface
->iter_next
= wxgtk_tree_model_iter_next
;
448 iface
->iter_children
= wxgtk_tree_model_iter_children
;
449 iface
->iter_has_child
= wxgtk_tree_model_iter_has_child
;
450 iface
->iter_n_children
= wxgtk_tree_model_iter_n_children
;
451 iface
->iter_nth_child
= wxgtk_tree_model_iter_nth_child
;
452 iface
->iter_parent
= wxgtk_tree_model_iter_parent
;
456 wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
)
458 iface
->get_sort_column_id
= wxgtk_tree_model_get_sort_column_id
;
459 iface
->set_sort_column_id
= wxgtk_tree_model_set_sort_column_id
;
460 iface
->set_sort_func
= wxgtk_tree_model_set_sort_func
;
461 iface
->set_default_sort_func
= wxgtk_tree_model_set_default_sort_func
;
462 iface
->has_default_sort_func
= wxgtk_tree_model_has_default_sort_func
;
466 wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
)
468 iface
->row_draggable
= wxgtk_tree_model_row_draggable
;
469 iface
->drag_data_delete
= wxgtk_tree_model_drag_data_delete
;
470 iface
->drag_data_get
= wxgtk_tree_model_drag_data_get
;
474 wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
)
476 iface
->drag_data_received
= wxgtk_tree_model_drag_data_received
;
477 iface
->row_drop_possible
= wxgtk_tree_model_row_drop_possible
;
481 wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
)
483 tree_model
->internal
= NULL
;
484 tree_model
->stamp
= g_random_int();
488 wxgtk_tree_model_finalize (GObject
*object
)
491 (* list_parent_class
->finalize
) (object
);
496 //-----------------------------------------------------------------------------
497 // implement callbacks from wxGtkTreeModel class by letting
498 // them call the methods of wxWidgets' wxDataViewModel
499 //-----------------------------------------------------------------------------
501 static GtkTreeModelFlags
502 wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
)
504 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
505 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), (GtkTreeModelFlags
)0 );
507 return wxtree_model
->internal
->get_flags();
511 wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
)
513 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
514 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
516 return wxtree_model
->internal
->GetDataViewModel()->GetColumnCount();
520 wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
523 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
524 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), G_TYPE_INVALID
);
526 GType gtype
= G_TYPE_INVALID
;
528 wxString wxtype
= wxtree_model
->internal
->GetDataViewModel()->GetColumnType( (unsigned int) index
);
530 if (wxtype
== wxT("string"))
531 gtype
= G_TYPE_STRING
;
534 gtype
= G_TYPE_STRING
;
535 // wxFAIL_MSG( _T("non-string columns not supported yet") );
542 wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
546 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
547 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
548 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
550 return wxtree_model
->internal
->get_iter( iter
, path
);
554 wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
557 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
558 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), NULL
);
559 g_return_val_if_fail (iter
->stamp
== GTK_WX_TREE_MODEL (wxtree_model
)->stamp
, NULL
);
561 return wxtree_model
->internal
->get_path( iter
);
565 wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
570 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
571 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
) );
573 wxDataViewModel
*model
= wxtree_model
->internal
->GetDataViewModel();
574 wxString mtype
= model
->GetColumnType( (unsigned int) column
);
575 if (mtype
== wxT("string"))
578 g_value_init( value
, G_TYPE_STRING
);
579 wxDataViewItem
item( (void*) iter
->user_data
);
580 model
->GetValue( variant
, item
, (unsigned int) column
);
582 g_value_set_string( value
, variant
.GetString().utf8_str() );
586 wxFAIL_MSG( _T("non-string columns not supported yet") );
591 wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
594 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
596 if (wxtree_model
->stamp
!= iter
->stamp
)
597 wxPrintf( "crash\n" );
599 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
600 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
602 return wxtree_model
->internal
->iter_next( iter
);
606 wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
610 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
611 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
612 g_return_val_if_fail (wxtree_model
->stamp
== parent
->stamp
, FALSE
);
614 return wxtree_model
->internal
->iter_children( iter
, parent
);
618 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
621 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
622 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
623 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
625 return wxtree_model
->internal
->iter_has_child( iter
);
629 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
632 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
633 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
634 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, 0);
636 return wxtree_model
->internal
->iter_n_children( iter
);
640 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
645 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
646 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
648 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
652 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
656 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
657 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
658 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
660 return wxtree_model
->internal
->iter_parent( iter
, child
);
663 /* drag'n'drop iface */
665 wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
668 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
669 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
671 return wxtree_model
->internal
->row_draggable( drag_source
, path
);
675 wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
678 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
679 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
681 return wxtree_model
->internal
->drag_data_delete( drag_source
, path
);
685 wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
687 GtkSelectionData
*selection_data
)
689 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
690 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
693 wxPrintf( "drag_get_data\n");
695 wxGtkString
atom_selection(gdk_atom_name(selection_data
->selection
));
696 wxPrintf( "selection %s\n", wxString::FromAscii(atom_selection
) );
698 wxGtkString
atom_target(gdk_atom_name(selection_data
->target
));
699 wxPrintf( "target %s\n", wxString::FromAscii(atom_target
) );
701 wxGtkString
atom_type(gdk_atom_name(selection_data
->type
));
702 wxPrintf( "type %s\n", wxString::FromAscii(atom_type
) );
704 wxPrintf( "format %d\n", selection_data
->format
);
707 return wxtree_model
->internal
->drag_data_get( drag_source
, path
, selection_data
);
711 wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
713 GtkSelectionData
*selection_data
)
715 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
716 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
718 return wxtree_model
->internal
->drag_data_received( drag_dest
, dest
, selection_data
);
722 wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
723 GtkTreePath
*dest_path
,
724 GtkSelectionData
*selection_data
)
726 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
727 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
729 return wxtree_model
->internal
->row_drop_possible( drag_dest
, dest_path
, selection_data
);
734 wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
735 gint
*sort_column_id
,
738 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) sortable
;
740 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
742 if (!wxtree_model
->internal
->IsSorted())
745 *sort_column_id
= -1;
752 *sort_column_id
= wxtree_model
->internal
->GetSortColumn();
755 *order
= wxtree_model
->internal
->GetSortOrder();
760 wxDataViewColumn
*gs_lastLeftClickHeader
= NULL
;
763 wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
767 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
768 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
770 tree_model
->internal
->SetDataViewSortColumn( gs_lastLeftClickHeader
);
772 if ((sort_column_id
!= (gint
) tree_model
->internal
->GetSortColumn()) ||
773 (order
!= tree_model
->internal
->GetSortOrder()))
775 tree_model
->internal
->SetSortColumn( sort_column_id
);
776 tree_model
->internal
->SetSortOrder( order
);
778 gtk_tree_sortable_sort_column_changed (sortable
);
780 tree_model
->internal
->GetDataViewModel()->Resort();
783 if (gs_lastLeftClickHeader
)
785 wxDataViewCtrl
*dv
= tree_model
->internal
->GetOwner();
786 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, dv
->GetId() );
787 event
.SetDataViewColumn( gs_lastLeftClickHeader
);
788 event
.SetModel( dv
->GetModel() );
789 dv
->HandleWindowEvent( event
);
792 gs_lastLeftClickHeader
= NULL
;
796 wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
797 gint
WXUNUSED(sort_column_id
),
798 GtkTreeIterCompareFunc func
,
799 gpointer
WXUNUSED(data
),
800 GtkDestroyNotify
WXUNUSED(destroy
) )
802 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
803 g_return_if_fail (func
!= NULL
);
806 void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
807 GtkTreeIterCompareFunc func
,
808 gpointer
WXUNUSED(data
),
809 GtkDestroyNotify
WXUNUSED(destroy
) )
811 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
812 g_return_if_fail (func
!= NULL
);
814 wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
817 gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
)
819 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
824 //-----------------------------------------------------------------------------
825 // define new GTK+ class wxGtkRendererRenderer
826 //-----------------------------------------------------------------------------
830 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
831 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
832 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
833 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
834 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
835 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
837 GType
gtk_wx_cell_renderer_get_type (void);
839 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
840 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
842 struct _GtkWxCellRenderer
844 GtkCellRenderer parent
;
847 wxDataViewCustomRenderer
*cell
;
851 struct _GtkWxCellRendererClass
853 GtkCellRendererClass cell_parent_class
;
857 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
858 static void gtk_wx_cell_renderer_init (
859 GtkWxCellRenderer
*cell
);
860 static void gtk_wx_cell_renderer_class_init(
861 GtkWxCellRendererClass
*klass
);
862 static void gtk_wx_cell_renderer_finalize (
864 static void gtk_wx_cell_renderer_get_size (
865 GtkCellRenderer
*cell
,
867 GdkRectangle
*rectangle
,
872 static void gtk_wx_cell_renderer_render (
873 GtkCellRenderer
*cell
,
876 GdkRectangle
*background_area
,
877 GdkRectangle
*cell_area
,
878 GdkRectangle
*expose_area
,
879 GtkCellRendererState flags
);
880 static gboolean
gtk_wx_cell_renderer_activate(
881 GtkCellRenderer
*cell
,
885 GdkRectangle
*background_area
,
886 GdkRectangle
*cell_area
,
887 GtkCellRendererState flags
);
888 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
889 GtkCellRenderer
*cell
,
893 GdkRectangle
*background_area
,
894 GdkRectangle
*cell_area
,
895 GtkCellRendererState flags
);
898 static GObjectClass
*cell_parent_class
= NULL
;
903 gtk_wx_cell_renderer_get_type (void)
905 static GType cell_wx_type
= 0;
909 const GTypeInfo cell_wx_info
=
911 sizeof (GtkWxCellRendererClass
),
912 NULL
, /* base_init */
913 NULL
, /* base_finalize */
914 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
915 NULL
, /* class_finalize */
916 NULL
, /* class_data */
917 sizeof (GtkWxCellRenderer
),
919 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
922 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
923 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
930 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
933 cell
->last_click
= 0;
937 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
939 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
940 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
942 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
944 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
946 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
947 cell_class
->render
= gtk_wx_cell_renderer_render
;
948 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
949 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
953 gtk_wx_cell_renderer_finalize (GObject
*object
)
956 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
960 gtk_wx_cell_renderer_new (void)
962 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
967 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
968 GtkCellRenderer
*renderer
,
969 GdkEvent
*WXUNUSED(event
),
972 GdkRectangle
*WXUNUSED(background_area
),
973 GdkRectangle
*cell_area
,
974 GtkCellRendererState
WXUNUSED(flags
) )
976 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
977 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
979 // Renderer doesn't support in-place editing
980 if (!cell
->HasEditorCtrl())
983 // An in-place editing control is still around
984 if (cell
->GetEditorCtrl())
988 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
994 rect
.x
+= cell_area
->x
;
995 rect
.y
+= cell_area
->y
;
996 // rect.width -= renderer->xpad * 2;
997 // rect.height -= renderer->ypad * 2;
999 // wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
1000 wxRect
renderrect( cell_area
->x
, cell_area
->y
, cell_area
->width
, cell_area
->height
);
1002 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
1004 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
1005 wxDataViewItem
item( (void*) iter
.user_data
);
1006 gtk_tree_path_free( treepath
);
1008 cell
->StartEditing( item
, renderrect
);
1014 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
1015 GtkWidget
*WXUNUSED(widget
),
1016 GdkRectangle
*cell_area
,
1022 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1023 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1025 wxSize size
= cell
->GetSize();
1027 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
1028 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
1035 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
1039 *x_offset
= (gint
)((renderer
->xalign
*
1040 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
1041 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
1045 *y_offset
= (gint
)((renderer
->yalign
*
1046 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
1047 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
1052 *width
= calc_width
;
1055 *height
= calc_height
;
1059 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
1062 GdkRectangle
*background_area
,
1063 GdkRectangle
*cell_area
,
1064 GdkRectangle
*expose_area
,
1065 GtkCellRendererState flags
)
1068 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1069 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1071 cell
->window
= window
;
1072 cell
->widget
= widget
;
1073 cell
->background_area
= (void*) background_area
;
1074 cell
->cell_area
= (void*) cell_area
;
1075 cell
->expose_area
= (void*) expose_area
;
1076 cell
->flags
= (int) flags
;
1079 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1085 rect
.x
+= cell_area
->x
;
1086 rect
.y
+= cell_area
->y
;
1087 rect
.width
-= renderer
->xpad
* 2;
1088 rect
.height
-= renderer
->ypad
* 2;
1091 if (gdk_rectangle_intersect (expose_area
, &rect
, &dummy
))
1093 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1094 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
1095 wxWindowDCImpl
*impl
= (wxWindowDCImpl
*) dc
->GetImpl();
1096 if (impl
->m_gdkwindow
== NULL
)
1098 impl
->m_gdkwindow
= window
;
1103 if (flags
& GTK_CELL_RENDERER_SELECTED
)
1104 state
|= wxDATAVIEW_CELL_SELECTED
;
1105 if (flags
& GTK_CELL_RENDERER_PRELIT
)
1106 state
|= wxDATAVIEW_CELL_PRELIT
;
1107 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1108 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1109 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1110 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1111 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
1112 state
|= wxDATAVIEW_CELL_FOCUSED
;
1113 cell
->Render( renderrect
, dc
, state
);
1118 gtk_wx_cell_renderer_activate(
1119 GtkCellRenderer
*renderer
,
1123 GdkRectangle
*WXUNUSED(background_area
),
1124 GdkRectangle
*cell_area
,
1125 GtkCellRendererState
WXUNUSED(flags
) )
1127 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1128 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1131 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1137 rect
.x
+= cell_area
->x
;
1138 rect
.y
+= cell_area
->y
;
1139 rect
.width
-= renderer
->xpad
* 2;
1140 rect
.height
-= renderer
->ypad
* 2;
1142 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1144 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1146 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
1149 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
1150 wxDataViewItem
item( iter
.user_data
);
1151 gtk_tree_path_free( treepath
);
1153 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1159 // activated by <ENTER>
1160 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1165 else if (event
->type
== GDK_BUTTON_PRESS
)
1167 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
1168 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
1169 ((int) button_event
->y
) - renderrect
.y
);
1172 if (button_event
->button
== 1)
1174 if (cell
->LeftClick( pt
, renderrect
, model
, item
, model_col
))
1176 // TODO: query system double-click time
1177 if (button_event
->time
- wxrenderer
->last_click
< 400)
1178 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1181 wxrenderer
->last_click
= button_event
->time
;
1189 // ---------------------------------------------------------
1190 // wxGtkDataViewModelNotifier
1191 // ---------------------------------------------------------
1193 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1196 wxGtkDataViewModelNotifier( GtkWxTreeModel
*wxgtk_model
,
1197 wxDataViewModel
*wx_model
,
1198 wxDataViewCtrl
*ctrl
);
1199 ~wxGtkDataViewModelNotifier();
1201 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1202 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1203 virtual bool ItemChanged( const wxDataViewItem
&item
);
1204 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
1205 virtual bool Cleared();
1206 virtual void Resort();
1208 void SetGtkModel( GtkWxTreeModel
*model
) { m_wxgtk_model
= model
; }
1211 GtkWxTreeModel
*m_wxgtk_model
;
1212 wxDataViewModel
*m_wx_model
;
1213 wxDataViewCtrl
*m_owner
;
1216 // ---------------------------------------------------------
1217 // wxGtkDataViewListModelNotifier
1218 // ---------------------------------------------------------
1220 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1221 GtkWxTreeModel
* wxgtk_model
, wxDataViewModel
*wx_model
,
1222 wxDataViewCtrl
*ctrl
)
1224 m_wxgtk_model
= wxgtk_model
;
1225 m_wx_model
= wx_model
;
1229 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1232 m_wxgtk_model
= NULL
;
1235 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1237 m_owner
->GtkGetInternal()->ItemAdded( parent
, item
);
1240 iter
.stamp
= m_wxgtk_model
->stamp
;
1241 iter
.user_data
= (gpointer
) item
.GetID();
1243 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1244 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1245 gtk_tree_model_row_inserted(
1246 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1247 gtk_tree_path_free (path
);
1252 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1255 iter
.stamp
= m_wxgtk_model
->stamp
;
1256 iter
.user_data
= (gpointer
) item
.GetID();
1258 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1259 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1260 gtk_tree_model_row_deleted(
1261 GTK_TREE_MODEL(m_wxgtk_model
), path
);
1262 gtk_tree_path_free (path
);
1264 m_owner
->GtkGetInternal()->ItemDeleted( parent
, item
);
1269 void wxGtkDataViewModelNotifier::Resort()
1271 m_owner
->GtkGetInternal()->Resort();
1274 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1277 iter
.stamp
= m_wxgtk_model
->stamp
;
1278 iter
.user_data
= (gpointer
) item
.GetID();
1280 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1281 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1282 gtk_tree_model_row_changed(
1283 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1284 gtk_tree_path_free (path
);
1286 m_owner
->GtkGetInternal()->ItemChanged( item
);
1291 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_col
)
1293 // This adds GTK+'s missing MVC logic for ValueChanged
1295 for (index
= 0; index
< m_owner
->GetColumnCount(); index
++)
1297 wxDataViewColumn
*column
= m_owner
->GetColumn( index
);
1298 if (column
->GetModelColumn() == model_col
)
1300 GtkTreeView
*widget
= GTK_TREE_VIEW(m_owner
->m_treeview
);
1301 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1305 iter
.stamp
= m_wxgtk_model
->stamp
;
1306 iter
.user_data
= (gpointer
) item
.GetID();
1307 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1308 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1309 GdkRectangle cell_area
;
1310 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1311 gtk_tree_path_free( path
);
1313 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1314 double d
= gtk_adjustment_get_value( hadjust
);
1315 int xdiff
= (int) d
;
1317 int ydiff
= gcolumn
->button
->allocation
.height
;
1319 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1320 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1322 m_owner
->GtkGetInternal()->ValueChanged( item
, model_col
);
1331 bool wxGtkDataViewModelNotifier::Cleared()
1333 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->m_treeview
), NULL
);
1335 // this will create a new GTK model
1336 m_owner
->GtkGetInternal()->Cleared();
1338 SetGtkModel( m_owner
->GtkGetInternal()->GetGtkModel() );
1340 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->m_treeview
), GTK_TREE_MODEL(m_wxgtk_model
) );
1345 // ---------------------------------------------------------
1346 // wxDataViewRenderer
1347 // ---------------------------------------------------------
1349 static gpointer s_user_data
= NULL
;
1352 wxgtk_cell_editable_editing_done( GtkCellEditable
*WXUNUSED(editable
),
1353 wxDataViewRenderer
*wxrenderer
)
1355 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1356 wxDataViewCtrl
*dv
= column
->GetOwner();
1357 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1358 event
.SetDataViewColumn( column
);
1359 event
.SetModel( dv
->GetModel() );
1360 wxDataViewItem
item( s_user_data
);
1361 event
.SetItem( item
);
1362 dv
->HandleWindowEvent( event
);
1366 wxgtk_renderer_editing_started( GtkCellRenderer
*WXUNUSED(cell
), GtkCellEditable
*editable
,
1367 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1369 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1370 wxDataViewCtrl
*dv
= column
->GetOwner();
1371 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1372 event
.SetDataViewColumn( column
);
1373 event
.SetModel( dv
->GetModel() );
1374 GtkTreePath
*tree_path
= gtk_tree_path_new_from_string( path
);
1376 dv
->GtkGetInternal()->get_iter( &iter
, tree_path
);
1377 gtk_tree_path_free( tree_path
);
1378 wxDataViewItem
item( iter
.user_data
);
1379 event
.SetItem( item
);
1380 dv
->HandleWindowEvent( event
);
1382 if (GTK_IS_CELL_EDITABLE(editable
))
1384 s_user_data
= iter
.user_data
;
1386 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1387 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1388 (gpointer
) wxrenderer
);
1394 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1396 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1398 wxDataViewRendererBase( varianttype
, mode
, align
)
1402 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1403 // after the m_renderer pointer has been initialized
1406 void wxDataViewRenderer::GtkInitHandlers()
1408 if (!gtk_check_version(2,6,0))
1410 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1411 G_CALLBACK (wxgtk_renderer_editing_started
),
1416 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1418 GtkCellRendererMode gtkMode
;
1421 case wxDATAVIEW_CELL_INERT
:
1422 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1425 case wxDATAVIEW_CELL_ACTIVATABLE
:
1426 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1429 case wxDATAVIEW_CELL_EDITABLE
:
1430 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1434 wxFAIL_MSG( "unknown wxDataViewCellMode value" );
1438 // This value is most often ignored in GtkTreeView
1439 GValue gvalue
= { 0, };
1440 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1441 g_value_set_enum( &gvalue
, gtkMode
);
1442 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1443 g_value_unset( &gvalue
);
1446 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1448 wxDataViewCellMode ret
;
1451 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1453 switch (g_value_get_enum(&gvalue
))
1456 wxFAIL_MSG( "unknown GtkCellRendererMode value" );
1457 // fall through (we have to return something)
1459 case GTK_CELL_RENDERER_MODE_INERT
:
1460 ret
= wxDATAVIEW_CELL_INERT
;
1463 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1464 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1467 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1468 ret
= wxDATAVIEW_CELL_EDITABLE
;
1472 g_value_unset( &gvalue
);
1477 void wxDataViewRenderer::GtkUpdateAlignment()
1479 int align
= m_alignment
;
1481 // query alignment from column ?
1485 if (GetOwner() == NULL
)
1488 align
= GetOwner()->GetAlignment();
1489 align
|= wxALIGN_CENTRE_VERTICAL
;
1492 // horizontal alignment:
1494 gfloat xalign
= 0.0;
1495 if (align
& wxALIGN_RIGHT
)
1497 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1500 GValue gvalue
= { 0, };
1501 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1502 g_value_set_float( &gvalue
, xalign
);
1503 g_object_set_property( G_OBJECT(m_renderer
), "xalign", &gvalue
);
1504 g_value_unset( &gvalue
);
1506 // vertical alignment:
1508 gfloat yalign
= 0.0;
1509 if (align
& wxALIGN_BOTTOM
)
1511 else if (align
& wxALIGN_CENTER_VERTICAL
)
1514 GValue gvalue2
= { 0, };
1515 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1516 g_value_set_float( &gvalue2
, yalign
);
1517 g_object_set_property( G_OBJECT(m_renderer
), "yalign", &gvalue2
);
1518 g_value_unset( &gvalue2
);
1521 void wxDataViewRenderer::SetAlignment( int align
)
1523 m_alignment
= align
;
1524 GtkUpdateAlignment();
1527 int wxDataViewRenderer::GetAlignment() const
1532 // ---------------------------------------------------------
1533 // wxDataViewTextRenderer
1534 // ---------------------------------------------------------
1537 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1538 gchar
*arg1
, gchar
*arg2
, gpointer user_data
);
1541 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*WXUNUSED(renderer
),
1542 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1544 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) user_data
;
1546 wxString tmp
= wxGTK_CONV_BACK_FONT(arg2
, cell
->GetOwner()->GetOwner()->GetFont());
1547 wxVariant value
= tmp
;
1548 if (!cell
->Validate( value
))
1551 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1553 GtkTreePath
*path
= gtk_tree_path_new_from_string( arg1
);
1555 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, path
);
1556 wxDataViewItem
item( (void*) iter
.user_data
);;
1557 gtk_tree_path_free( path
);
1559 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1561 model
->SetValue( value
, item
, model_col
);
1562 model
->ValueChanged( item
, model_col
);
1565 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
1567 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1569 wxDataViewRenderer( varianttype
, mode
, align
)
1571 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_text_new();
1573 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
1575 GValue gvalue
= { 0, };
1576 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1577 g_value_set_boolean( &gvalue
, true );
1578 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
1579 g_value_unset( &gvalue
);
1581 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
1587 SetAlignment(align
);
1590 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
1592 wxString tmp
= value
;
1594 GValue gvalue
= { 0, };
1595 g_value_init( &gvalue
, G_TYPE_STRING
);
1596 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( tmp
, GetOwner()->GetOwner()->GetFont() ) );
1597 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1598 g_value_unset( &gvalue
);
1603 bool wxDataViewTextRenderer::GetValue( wxVariant
&value
) const
1605 GValue gvalue
= { 0, };
1606 g_value_init( &gvalue
, G_TYPE_STRING
);
1607 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1608 wxString tmp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
), const_cast<wxDataViewTextRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
1609 g_value_unset( &gvalue
);
1616 void wxDataViewTextRenderer::SetAlignment( int align
)
1618 wxDataViewRenderer::SetAlignment(align
);
1620 if (gtk_check_version(2,10,0))
1623 // horizontal alignment:
1624 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
1625 if (align
& wxALIGN_RIGHT
)
1626 pangoAlign
= PANGO_ALIGN_RIGHT
;
1627 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1628 pangoAlign
= PANGO_ALIGN_CENTER
;
1630 GValue gvalue
= { 0, };
1631 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1632 g_value_set_enum( &gvalue
, pangoAlign
);
1633 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
1634 g_value_unset( &gvalue
);
1637 // ---------------------------------------------------------
1638 // wxDataViewTextRendererAttr
1639 // ---------------------------------------------------------
1641 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
,wxDataViewTextRenderer
)
1643 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString
&varianttype
,
1644 wxDataViewCellMode mode
, int align
) :
1645 wxDataViewTextRenderer( varianttype
, mode
, align
)
1649 // ---------------------------------------------------------
1650 // wxDataViewBitmapRenderer
1651 // ---------------------------------------------------------
1653 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
1655 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1657 wxDataViewRenderer( varianttype
, mode
, align
)
1659 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_pixbuf_new();
1662 SetAlignment(align
);
1665 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
1667 if (value
.GetType() == wxT("wxBitmap"))
1672 // This may create a Pixbuf representation in the
1673 // wxBitmap object (and it will stay there)
1674 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1676 GValue gvalue
= { 0, };
1677 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1678 g_value_set_object( &gvalue
, pixbuf
);
1679 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1680 g_value_unset( &gvalue
);
1685 if (value
.GetType() == wxT("wxIcon"))
1690 // This may create a Pixbuf representation in the
1691 // wxBitmap object (and it will stay there)
1692 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1694 GValue gvalue
= { 0, };
1695 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1696 g_value_set_object( &gvalue
, pixbuf
);
1697 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1698 g_value_unset( &gvalue
);
1706 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
1711 // ---------------------------------------------------------
1712 // wxDataViewToggleRenderer
1713 // ---------------------------------------------------------
1716 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1717 gchar
*path
, gpointer user_data
);
1720 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1721 gchar
*path
, gpointer user_data
)
1723 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
1726 GValue gvalue
= { 0, };
1727 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1728 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
1729 bool tmp
= g_value_get_boolean( &gvalue
);
1730 g_value_unset( &gvalue
);
1734 wxVariant value
= tmp
;
1735 if (!cell
->Validate( value
))
1738 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1740 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
1742 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, gtk_path
);
1743 wxDataViewItem
item( (void*) iter
.user_data
);;
1744 gtk_tree_path_free( gtk_path
);
1746 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1748 model
->SetValue( value
, item
, model_col
);
1749 model
->ValueChanged( item
, model_col
);
1752 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1754 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1755 wxDataViewCellMode mode
, int align
) :
1756 wxDataViewRenderer( varianttype
, mode
, align
)
1758 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
1760 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1762 g_signal_connect_after( m_renderer
, "toggled",
1763 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
1767 GValue gvalue
= { 0, };
1768 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1769 g_value_set_boolean( &gvalue
, false );
1770 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
1771 g_value_unset( &gvalue
);
1775 SetAlignment(align
);
1778 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1782 GValue gvalue
= { 0, };
1783 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1784 g_value_set_boolean( &gvalue
, tmp
);
1785 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1786 g_value_unset( &gvalue
);
1791 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
1793 GValue gvalue
= { 0, };
1794 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1795 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1796 bool tmp
= g_value_get_boolean( &gvalue
);
1797 g_value_unset( &gvalue
);
1804 // ---------------------------------------------------------
1805 // wxDataViewCustomRenderer
1806 // ---------------------------------------------------------
1808 class wxDataViewCtrlDCImpl
: public wxWindowDCImpl
1811 wxDataViewCtrlDCImpl( wxDC
*owner
, wxDataViewCtrl
*window
) :
1812 wxWindowDCImpl( owner
)
1814 GtkWidget
*widget
= window
->m_treeview
;
1820 m_context
= window
->GtkGetPangoDefaultContext();
1821 m_layout
= pango_layout_new( m_context
);
1822 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
1824 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
1826 // Set m_gdkwindow later
1831 class wxDataViewCtrlDC
: public wxWindowDC
1834 wxDataViewCtrlDC( wxDataViewCtrl
*window
) :
1835 wxWindowDC( new wxDataViewCtrlDCImpl( this, window
) )
1840 // ---------------------------------------------------------
1841 // wxDataViewCustomRenderer
1842 // ---------------------------------------------------------
1844 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
1846 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
1847 wxDataViewCellMode mode
, int align
,
1849 wxDataViewRenderer( varianttype
, mode
, align
)
1852 m_text_renderer
= NULL
;
1860 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
,
1861 wxRect
WXUNUSED(cell
), wxDC
*WXUNUSED(dc
), int WXUNUSED(state
) )
1864 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
1865 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
1866 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
1867 view
->GetForegroundColour();
1868 dc
->SetTextForeground(col
);
1869 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
1871 if (!m_text_renderer
)
1872 m_text_renderer
= gtk_cell_renderer_text_new();
1874 GValue gvalue
= { 0, };
1875 g_value_init( &gvalue
, G_TYPE_STRING
);
1876 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( text
, GetOwner()->GetOwner()->GetFont() ) );
1877 g_object_set_property( G_OBJECT(m_text_renderer
), "text", &gvalue
);
1878 g_value_unset( &gvalue
);
1880 ((GdkRectangle
*) cell_area
)->x
+= xoffset
;
1881 ((GdkRectangle
*) cell_area
)->width
-= xoffset
;
1883 gtk_cell_renderer_render( m_text_renderer
,
1886 (GdkRectangle
*) background_area
,
1887 (GdkRectangle
*) cell_area
,
1888 (GdkRectangle
*) expose_area
,
1889 (GtkCellRendererState
) flags
);
1891 ((GdkRectangle
*) cell_area
)->x
-= xoffset
;
1892 ((GdkRectangle
*) cell_area
)->width
+= xoffset
;
1896 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
1898 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
1899 renderer
->cell
= this;
1901 m_renderer
= (GtkCellRenderer
*) renderer
;
1904 SetAlignment(align
);
1911 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
1916 if (m_text_renderer
)
1917 gtk_object_sink( GTK_OBJECT(m_text_renderer
) );
1920 wxDC
*wxDataViewCustomRenderer::GetDC()
1924 if (GetOwner() == NULL
)
1926 if (GetOwner()->GetOwner() == NULL
)
1928 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
1934 // ---------------------------------------------------------
1935 // wxDataViewProgressRenderer
1936 // ---------------------------------------------------------
1938 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
1940 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
1941 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1942 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
1948 if (!gtk_check_version(2,6,0))
1950 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
1952 GValue gvalue
= { 0, };
1953 g_value_init( &gvalue
, G_TYPE_STRING
);
1955 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( m_label
, GetOwner()->GetOwner()->GetFont() ) );
1956 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1957 g_value_unset( &gvalue
);
1960 SetAlignment(align
);
1965 // Use custom cell code
1966 wxDataViewCustomRenderer::Init(mode
, align
);
1970 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
1974 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
1977 if (!gtk_check_version(2,6,0))
1979 gint tmp
= (long) value
;
1980 GValue gvalue
= { 0, };
1981 g_value_init( &gvalue
, G_TYPE_INT
);
1982 g_value_set_int( &gvalue
, tmp
);
1983 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
1984 g_value_unset( &gvalue
);
1989 m_value
= (long) value
;
1991 if (m_value
< 0) m_value
= 0;
1992 if (m_value
> 100) m_value
= 100;
1998 bool wxDataViewProgressRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2003 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
2005 double pct
= (double)m_value
/ 100.0;
2007 bar
.width
= (int)(cell
.width
* pct
);
2008 dc
->SetPen( *wxTRANSPARENT_PEN
);
2009 dc
->SetBrush( *wxBLUE_BRUSH
);
2010 dc
->DrawRectangle( bar
);
2012 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
2013 dc
->SetPen( *wxBLACK_PEN
);
2014 dc
->DrawRectangle( cell
);
2019 wxSize
wxDataViewProgressRenderer::GetSize() const
2021 return wxSize(40,12);
2024 // -------------------------------------
2025 // wxDataViewChoiceRenderer
2026 // -------------------------------------
2028 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
&choices
,
2029 wxDataViewCellMode mode
, int alignment
) :
2030 wxDataViewCustomRenderer( "string", mode
, alignment
, true )
2032 m_choices
= choices
;
2035 if (!gtk_check_version(2,6,0))
2037 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_combo_new();
2039 GtkListStore
*store
= gtk_list_store_new( 1, G_TYPE_STRING
);
2041 for (n
= 0; n
< m_choices
.GetCount(); n
++)
2042 gtk_list_store_insert_with_values( store
, NULL
, n
, 0, m_choices
[n
].utf8_str(), -1 );
2044 g_object_set (m_renderer
,
2050 bool editable
= (mode
& wxDATAVIEW_CELL_EDITABLE
);
2051 g_object_set (m_renderer
, "editable", editable
, NULL
);
2053 SetAlignment(alignment
);
2055 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2062 // Use custom cell code
2063 wxDataViewCustomRenderer::Init(mode
, alignment
);
2067 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
2069 RenderText( m_data
, 0, rect
, dc
, state
);
2073 wxSize
wxDataViewChoiceRenderer::GetSize() const
2075 return wxSize(70,20);
2078 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
2082 if (!gtk_check_version(2,6,0))
2084 GValue gvalue
= { 0, };
2085 g_value_init( &gvalue
, G_TYPE_STRING
);
2086 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( value
.GetString(), GetOwner()->GetOwner()->GetFont() ) );
2087 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2088 g_value_unset( &gvalue
);
2092 m_data
= value
.GetString();
2097 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
2100 if (!gtk_check_version(2,6,0))
2102 GValue gvalue
= { 0, };
2103 g_value_init( &gvalue
, G_TYPE_STRING
);
2104 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2105 wxString temp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
), const_cast<wxDataViewTextRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
2106 g_value_unset( &gvalue
);
2108 wxPrintf( "temp %s\n", temp
);
2117 void wxDataViewChoiceRenderer::SetAlignment( int align
)
2119 wxDataViewCustomRenderer::SetAlignment(align
);
2121 if (gtk_check_version(2,10,0))
2124 // horizontal alignment:
2125 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2126 if (align
& wxALIGN_RIGHT
)
2127 pangoAlign
= PANGO_ALIGN_RIGHT
;
2128 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2129 pangoAlign
= PANGO_ALIGN_CENTER
;
2131 GValue gvalue
= { 0, };
2132 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2133 g_value_set_enum( &gvalue
, pangoAlign
);
2134 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2135 g_value_unset( &gvalue
);
2138 // ---------------------------------------------------------
2139 // wxDataViewDateRenderer
2140 // ---------------------------------------------------------
2142 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
2145 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
2146 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
2147 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
2152 m_cal
= new wxCalendarCtrl( this, -1, *value
);
2153 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
2154 sizer
->Add( m_cal
, 1, wxGROW
);
2159 virtual void OnDismiss()
2163 void OnCalendar( wxCalendarEvent
&event
);
2165 wxCalendarCtrl
*m_cal
;
2166 wxDataViewModel
*m_model
;
2167 wxDataViewItem m_item
;
2171 DECLARE_EVENT_TABLE()
2174 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
2175 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
2178 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
2180 wxDateTime date
= event
.GetDate();
2181 wxVariant value
= date
;
2182 m_model
->SetValue( value
, m_item
, m_col
);
2183 m_model
->ValueChanged( m_item
, m_col
);
2187 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
2189 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
2190 wxDataViewCellMode mode
, int align
) :
2191 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2194 SetAlignment(align
);
2197 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
2199 m_date
= value
.GetDateTime();
2204 bool wxDataViewDateRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2209 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2211 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
2212 wxString tmp
= m_date
.FormatDate();
2213 RenderText( tmp
, 0, cell
, dc
, state
);
2217 wxSize
wxDataViewDateRenderer::GetSize() const
2219 wxString tmp
= m_date
.FormatDate();
2221 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
2222 return wxSize(x
,y
+d
);
2225 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
2226 const wxDataViewItem
&item
, unsigned int col
)
2229 model
->GetValue( variant
, item
, col
);
2230 wxDateTime value
= variant
.GetDateTime();
2232 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
2233 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
2234 wxPoint pos
= wxGetMousePosition();
2237 popup
->Popup( popup
->m_cal
);
2243 // ---------------------------------------------------------
2244 // wxDataViewIconTextRenderer
2245 // ---------------------------------------------------------
2247 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
2249 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
2250 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
2251 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2254 SetAlignment(align
);
2257 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2261 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
2267 bool wxDataViewIconTextRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2272 bool wxDataViewIconTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2274 const wxIcon
&icon
= m_value
.GetIcon();
2278 int yoffset
= wxMax( 0, (cell
.height
- icon
.GetHeight()) / 2 );
2279 dc
->DrawIcon( icon
, cell
.x
, cell
.y
+ yoffset
);
2280 offset
= icon
.GetWidth() + 4;
2283 RenderText( m_value
.GetText(), offset
, cell
, dc
, state
);
2288 wxSize
wxDataViewIconTextRenderer::GetSize() const
2291 if (m_value
.GetIcon().IsOk())
2292 size
.x
= 4 + m_value
.GetIcon().GetWidth();
2294 GetView()->GetTextExtent( m_value
.GetText(), &x
, &y
, &d
);
2300 wxControl
* wxDataViewIconTextRenderer::CreateEditorCtrl(
2301 wxWindow
*WXUNUSED(parent
), wxRect
WXUNUSED(labelRect
), const wxVariant
&WXUNUSED(value
) )
2306 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl(
2307 wxControl
* WXUNUSED(editor
), wxVariant
&WXUNUSED(value
) )
2312 // ---------------------------------------------------------
2314 // ---------------------------------------------------------
2318 gtk_dataview_header_button_press_callback( GtkWidget
*WXUNUSED(widget
),
2319 GdkEventButton
*gdk_event
,
2320 wxDataViewColumn
*column
)
2322 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
2325 if (gdk_event
->button
== 1)
2327 gs_lastLeftClickHeader
= column
;
2329 wxDataViewCtrl
*dv
= column
->GetOwner();
2330 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
2331 event
.SetDataViewColumn( column
);
2332 event
.SetModel( dv
->GetModel() );
2333 if (dv
->HandleWindowEvent( event
))
2337 if (gdk_event
->button
== 3)
2339 wxDataViewCtrl
*dv
= column
->GetOwner();
2340 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
2341 event
.SetDataViewColumn( column
);
2342 event
.SetModel( dv
->GetModel() );
2343 if (dv
->HandleWindowEvent( event
))
2351 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
2352 GtkCellRenderer
*cell
,
2353 GtkTreeModel
*model
,
2359 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*WXUNUSED(column
),
2360 GtkCellRenderer
*renderer
,
2361 GtkTreeModel
*model
,
2365 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2366 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2368 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2370 wxDataViewItem
item( (void*) iter
->user_data
);
2372 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
2374 if (!wx_model
->IsVirtualListModel())
2377 if (wx_model
->IsContainer( item
))
2379 if (wx_model
->HasContainerColumns( item
) || (cell
->GetOwner()->GetModelColumn() == 0))
2381 GValue gvalue
= { 0, };
2382 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2383 g_value_set_boolean( &gvalue
, TRUE
);
2384 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2385 g_value_unset( &gvalue
);
2389 GValue gvalue
= { 0, };
2390 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2391 g_value_set_boolean( &gvalue
, FALSE
);
2392 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2393 g_value_unset( &gvalue
);
2400 GValue gvalue
= { 0, };
2401 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2402 g_value_set_boolean( &gvalue
, TRUE
);
2403 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2404 g_value_unset( &gvalue
);
2410 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
2412 if (value
.GetType() != cell
->GetVariantType())
2413 wxLogError( wxT("Wrong type, required: %s but: %s"),
2414 value
.GetType().c_str(),
2415 cell
->GetVariantType().c_str() );
2417 cell
->SetValue( value
);
2419 if (cell
->GtkHasAttributes())
2421 wxDataViewItemAttr attr
;
2422 bool colour_set
= false;
2423 bool style_set
= false;
2424 bool weight_set
= false;
2426 if (wx_model
->GetAttr( item
, cell
->GetOwner()->GetModelColumn(), attr
))
2428 // this must be a GtkCellRendererText
2429 wxColour colour
= attr
.GetColour();
2432 const GdkColor
* const gcol
= colour
.GetColor();
2434 GValue gvalue
= { 0, };
2435 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2436 g_value_set_boxed( &gvalue
, gcol
);
2437 g_object_set_property( G_OBJECT(renderer
), "foreground_gdk", &gvalue
);
2438 g_value_unset( &gvalue
);
2443 if (attr
.GetItalic())
2445 GValue gvalue
= { 0, };
2446 g_value_init( &gvalue
, PANGO_TYPE_STYLE
);
2447 g_value_set_enum( &gvalue
, PANGO_STYLE_ITALIC
);
2448 g_object_set_property( G_OBJECT(renderer
), "style", &gvalue
);
2449 g_value_unset( &gvalue
);
2456 GValue gvalue
= { 0, };
2457 g_value_init( &gvalue
, PANGO_TYPE_WEIGHT
);
2458 g_value_set_enum( &gvalue
, PANGO_WEIGHT_BOLD
);
2459 g_object_set_property( G_OBJECT(renderer
), "weight", &gvalue
);
2460 g_value_unset( &gvalue
);
2468 GValue gvalue
= { 0, };
2469 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2470 g_value_set_boolean( &gvalue
, FALSE
);
2471 g_object_set_property( G_OBJECT(renderer
), "style-set", &gvalue
);
2472 g_value_unset( &gvalue
);
2477 GValue gvalue
= { 0, };
2478 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2479 g_value_set_boolean( &gvalue
, FALSE
);
2480 g_object_set_property( G_OBJECT(renderer
), "weight-set", &gvalue
);
2481 g_value_unset( &gvalue
);
2486 GValue gvalue
= { 0, };
2487 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2488 g_value_set_boolean( &gvalue
, FALSE
);
2489 g_object_set_property( G_OBJECT(renderer
), "foreground-set", &gvalue
);
2490 g_value_unset( &gvalue
);
2495 if (attr
.HasBackgroundColour())
2497 wxColour colour
= attr
.GetBackgroundColour();
2498 const GdkColor
* const gcol
= colour
.GetColor();
2500 GValue gvalue
= { 0, };
2501 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2502 g_value_set_boxed( &gvalue
, gcol
);
2503 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
2504 g_value_unset( &gvalue
);
2508 GValue gvalue
= { 0, };
2509 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2510 g_value_set_boolean( &gvalue
, FALSE
);
2511 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
2512 g_value_unset( &gvalue
);
2518 #include <wx/listimpl.cpp>
2519 WX_DEFINE_LIST(wxDataViewColumnList
)
2521 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
2522 unsigned int model_column
, int width
,
2523 wxAlignment align
, int flags
)
2524 : wxDataViewColumnBase( cell
, model_column
)
2526 Init( align
, flags
, width
);
2531 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
2532 unsigned int model_column
, int width
,
2533 wxAlignment align
, int flags
)
2534 : wxDataViewColumnBase( bitmap
, cell
, model_column
)
2536 Init( align
, flags
, width
);
2538 SetBitmap( bitmap
);
2541 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
2543 m_isConnected
= false;
2545 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) GetRenderer()->GetGtkHandle();
2546 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
2547 m_column
= (GtkWidget
*) column
;
2550 SetAlignment( align
);
2554 // Create container for icon and label
2555 GtkWidget
*box
= gtk_hbox_new( FALSE
, 1 );
2556 gtk_widget_show( box
);
2557 // gtk_container_set_border_width((GtkContainer*)box, 2);
2558 m_image
= gtk_image_new();
2559 gtk_box_pack_start(GTK_BOX(box
), m_image
, FALSE
, FALSE
, 1);
2560 m_label
= gtk_label_new("");
2561 gtk_box_pack_end( GTK_BOX(box
), GTK_WIDGET(m_label
), FALSE
, FALSE
, 1 );
2562 gtk_tree_view_column_set_widget( column
, box
);
2564 gtk_tree_view_column_pack_end( column
, renderer
, TRUE
);
2566 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
2567 wxGtkTreeCellDataFunc
, (gpointer
) GetRenderer(), NULL
);
2570 void wxDataViewColumn::OnInternalIdle()
2575 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
2577 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2580 g_signal_connect(column
->button
, "button_press_event",
2581 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
2583 m_isConnected
= true;
2588 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
2590 wxDataViewColumnBase::SetOwner( owner
);
2592 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2594 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
2597 void wxDataViewColumn::SetTitle( const wxString
&title
)
2599 wxDataViewCtrl
*ctrl
= GetOwner();
2600 gtk_label_set_text( GTK_LABEL(m_label
), ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
2601 : wxGTK_CONV_SYS(title
) );
2603 gtk_widget_hide( m_label
);
2605 gtk_widget_show( m_label
);
2608 wxString
wxDataViewColumn::GetTitle() const
2610 return wxGTK_CONV_BACK_FONT(
2611 gtk_label_get_text( GTK_LABEL(m_label
) ),
2612 GetOwner()->GetFont()
2616 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
2618 wxDataViewColumnBase::SetBitmap( bitmap
);
2622 GtkImage
*gtk_image
= GTK_IMAGE(m_image
);
2624 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
2625 if (bitmap
.GetMask())
2626 mask
= bitmap
.GetMask()->GetBitmap();
2628 if (bitmap
.HasPixbuf())
2630 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
2631 bitmap
.GetPixbuf());
2635 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
2636 bitmap
.GetPixmap(), mask
);
2638 gtk_widget_show( m_image
);
2642 gtk_widget_hide( m_image
);
2646 void wxDataViewColumn::SetHidden( bool hidden
)
2648 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
2651 void wxDataViewColumn::SetResizeable( bool resizeable
)
2653 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizeable
);
2656 void wxDataViewColumn::SetAlignment( wxAlignment align
)
2658 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2660 gfloat xalign
= 0.0;
2661 if (align
== wxALIGN_RIGHT
)
2663 if (align
== wxALIGN_CENTER_HORIZONTAL
||
2664 align
== wxALIGN_CENTER
)
2667 gtk_tree_view_column_set_alignment( column
, xalign
);
2669 if (m_renderer
&& m_renderer
->GetAlignment() == -1)
2670 m_renderer
->GtkUpdateAlignment();
2673 wxAlignment
wxDataViewColumn::GetAlignment() const
2675 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
2678 return wxALIGN_RIGHT
;
2680 return wxALIGN_CENTER_HORIZONTAL
;
2682 return wxALIGN_LEFT
;
2685 void wxDataViewColumn::SetSortable( bool sortable
)
2687 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2691 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
2695 gtk_tree_view_column_set_sort_column_id( column
, -1 );
2696 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
2697 gtk_tree_view_column_set_clickable( column
, FALSE
);
2701 bool wxDataViewColumn::IsSortable() const
2703 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2704 return gtk_tree_view_column_get_clickable( column
);
2707 void wxDataViewColumn::SetAsSortKey( bool WXUNUSED(sort
) )
2709 // it might not make sense to have this function in wxHeaderColumn at
2710 // all in fact, changing of the sort order should only be done using the
2711 // associated control API
2712 wxFAIL_MSG( "not implemented" );
2715 bool wxDataViewColumn::IsSortKey() const
2717 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2718 return gtk_tree_view_column_get_sort_indicator( column
);
2721 bool wxDataViewColumn::IsResizeable() const
2723 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2724 return gtk_tree_view_column_get_resizable( column
);
2727 bool wxDataViewColumn::IsHidden() const
2729 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2730 return !gtk_tree_view_column_get_visible( column
);
2733 void wxDataViewColumn::SetSortOrder( bool ascending
)
2735 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2738 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
2740 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
2742 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
2745 bool wxDataViewColumn::IsSortOrderAscending() const
2747 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2749 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
2752 void wxDataViewColumn::SetMinWidth( int width
)
2754 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2757 int wxDataViewColumn::GetMinWidth() const
2759 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2762 int wxDataViewColumn::GetWidth() const
2764 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2767 void wxDataViewColumn::SetWidth( int width
)
2772 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
2774 // TODO find a better calculation
2775 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), wxDVC_DEFAULT_WIDTH
);
2777 // this is unpractical for large numbers of items and disables
2778 // user resizing, which is totally unexpected
2779 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
2784 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
2786 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2790 void wxDataViewColumn::SetReorderable( bool reorderable
)
2792 gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column
), reorderable
);
2795 bool wxDataViewColumn::IsReorderable() const
2797 return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column
) );
2800 //-----------------------------------------------------------------------------
2801 // wxGtkTreeModelNode
2802 //-----------------------------------------------------------------------------
2804 void wxGtkTreeModelNode::Resort()
2806 size_t child_count
= GetChildCount();
2807 if (child_count
== 0)
2810 size_t node_count
= GetNodesCount();
2812 if (child_count
== 1)
2814 if (node_count
== 1)
2816 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
2822 wxGtkTreeModelChildren temp
;
2823 WX_APPEND_ARRAY( temp
, m_children
);
2825 g_internal
= m_internal
;
2826 m_children
.Sort( &wxGtkTreeModelChildCmp
);
2828 gint
*new_order
= new gint
[child_count
];
2831 for (pos
= 0; pos
< child_count
; pos
++)
2833 void *id
= m_children
.Item( pos
);
2834 int old_pos
= temp
.Index( id
);
2835 new_order
[pos
] = old_pos
;
2838 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
2841 iter
.user_data
= GetItem().GetID();
2842 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
2844 GtkTreePath
*path
= m_internal
->get_path( &iter
);
2846 gtk_tree_model_rows_reordered( gtk_tree_model
, path
, &iter
, new_order
);
2848 gtk_tree_path_free (path
);
2850 delete [] new_order
;
2852 for (pos
= 0; pos
< node_count
; pos
++)
2854 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
2859 //-----------------------------------------------------------------------------
2860 // wxDataViewCtrlInternal
2861 //-----------------------------------------------------------------------------
2863 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
,
2864 wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
)
2867 m_wx_model
= wx_model
;
2868 m_gtk_model
= gtk_model
;
2870 m_sort_order
= GTK_SORT_ASCENDING
;
2872 m_dataview_sort_column
= NULL
;
2874 if (!m_wx_model
->IsVirtualListModel())
2878 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
2880 g_object_unref( m_gtk_model
);
2883 void wxDataViewCtrlInternal::InitTree()
2885 wxDataViewItem item
;
2886 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
2888 BuildBranch( m_root
);
2891 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
2893 if (node
->GetChildCount() == 0)
2895 wxDataViewItemArray children
;
2896 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
2898 for (pos
= 0; pos
< count
; pos
++)
2900 wxDataViewItem child
= children
[pos
];
2902 if (m_wx_model
->IsContainer( child
))
2903 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
2905 node
->AddLeave( child
.GetID() );
2907 // Don't send any events here
2914 gboolean
wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource
*WXUNUSED(drag_source
),
2918 if (!get_iter( &iter
, path
)) return FALSE
;
2920 wxDataViewItem
item( (void*) iter
.user_data
);
2922 return m_wx_model
->IsDraggable( item
);
2926 wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource
*WXUNUSED(drag_source
),
2927 GtkTreePath
*WXUNUSED(path
))
2932 gboolean
wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource
*WXUNUSED(drag_source
),
2933 GtkTreePath
*path
, GtkSelectionData
*selection_data
)
2936 if (!get_iter( &iter
, path
)) return FALSE
;
2938 wxDataViewItem
item( (void*) iter
.user_data
);
2940 wxDataFormat
format( selection_data
->target
);
2942 size_t size
= m_wx_model
->GetDragDataSize( item
, format
);
2943 if (size
== 0) return FALSE
;
2945 void *data
= malloc( size
);
2947 m_wx_model
->GetDragData( item
, format
, data
, size
);
2949 gtk_selection_data_set( selection_data
, selection_data
->target
,
2950 8, (const guchar
*) data
, size
);
2958 wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest
*WXUNUSED(drag_dest
),
2959 GtkTreePath
*WXUNUSED(dest
),
2960 GtkSelectionData
*WXUNUSED(selection_data
))
2966 wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest
*WXUNUSED(drag_dest
),
2967 GtkTreePath
*WXUNUSED(dest_path
),
2968 GtkSelectionData
*WXUNUSED(selection_data
))
2973 // notifications from wxDataViewModel
2975 bool wxDataViewCtrlInternal::Cleared()
2983 // Create new GTK model
2984 g_object_unref( m_gtk_model
);
2985 m_gtk_model
= wxgtk_tree_model_new();
2986 m_gtk_model
->internal
= this;
2991 void wxDataViewCtrlInternal::Resort()
2993 if (!m_wx_model
->IsVirtualListModel())
2997 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
2999 if (!m_wx_model
->IsVirtualListModel())
3001 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3002 if (m_wx_model
->IsContainer( item
))
3003 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
3005 parent_node
->AddLeave( item
.GetID() );
3011 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3013 if (!m_wx_model
->IsVirtualListModel())
3015 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3016 parent_node
->DeleteChild( item
.GetID() );
3022 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
3024 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3025 event
.SetEventObject( m_owner
);
3026 event
.SetModel( m_owner
->GetModel() );
3027 event
.SetItem( item
);
3028 m_owner
->HandleWindowEvent( event
);
3033 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
3035 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3036 event
.SetEventObject( m_owner
);
3037 event
.SetModel( m_owner
->GetModel() );
3038 event
.SetColumn( col
);
3039 event
.SetDataViewColumn( GetOwner()->GetColumn(col
) );
3040 event
.SetItem( item
);
3041 m_owner
->HandleWindowEvent( event
);
3048 GtkTreeModelFlags
wxDataViewCtrlInternal::get_flags()
3050 if (m_wx_model
->IsVirtualListModel())
3051 return GTK_TREE_MODEL_LIST_ONLY
;
3053 return GTK_TREE_MODEL_ITERS_PERSIST
;
3056 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
3058 if (m_wx_model
->IsVirtualListModel())
3060 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3062 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
3064 if (i
>= wx_model
->GetLastIndex() + 1)
3067 iter
->stamp
= m_gtk_model
->stamp
;
3068 // user_data is just the index
3069 iter
->user_data
= (gpointer
) i
;
3075 int depth
= gtk_tree_path_get_depth( path
);
3077 wxGtkTreeModelNode
*node
= m_root
;
3080 for (i
= 0; i
< depth
; i
++)
3082 BuildBranch( node
);
3084 gint pos
= gtk_tree_path_get_indices (path
)[i
];
3085 if (pos
< 0) return FALSE
;
3086 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
3088 void* id
= node
->GetChildren().Item( (size_t) pos
);
3092 iter
->stamp
= m_gtk_model
->stamp
;
3093 iter
->user_data
= id
;
3097 size_t count
= node
->GetNodes().GetCount();
3099 for (pos2
= 0; pos2
< count
; pos2
++)
3101 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
3102 if (child_node
->GetItem().GetID() == id
)
3114 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
3116 GtkTreePath
*retval
= gtk_tree_path_new ();
3118 if (m_wx_model
->IsVirtualListModel())
3120 // user_data is just the index
3121 int i
= (wxUIntPtr
) iter
->user_data
;
3122 gtk_tree_path_append_index (retval
, i
);
3126 void *id
= iter
->user_data
;
3128 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
3131 int pos
= node
->GetChildren().Index( id
);
3133 gtk_tree_path_prepend_index( retval
, pos
);
3135 id
= node
->GetItem().GetID();
3136 node
= node
->GetParent();
3143 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
3145 if (m_wx_model
->IsVirtualListModel())
3147 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3149 int n
= (wxUIntPtr
) iter
->user_data
;
3154 if (n
>= (int) wx_model
->GetLastIndex())
3157 iter
->user_data
= (gpointer
) ++n
;
3161 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
3162 if( parent
== NULL
)
3165 int pos
= parent
->GetChildren().Index( iter
->user_data
);
3167 if (pos
== (int) parent
->GetChildCount()-1)
3170 iter
->stamp
= m_gtk_model
->stamp
;
3171 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
3177 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
3179 if (m_wx_model
->IsVirtualListModel())
3181 // this is a list, nodes have no children
3185 iter
->stamp
= m_gtk_model
->stamp
;
3186 iter
->user_data
= (gpointer
) -1;
3192 wxDataViewItem
item( (void*) parent
->user_data
);
3194 if (!m_wx_model
->IsContainer( item
))
3197 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3198 BuildBranch( parent_node
);
3200 if (parent_node
->GetChildCount() == 0)
3203 iter
->stamp
= m_gtk_model
->stamp
;
3204 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
3210 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
3212 if (m_wx_model
->IsVirtualListModel())
3214 // this is a list, nodes have no children
3219 wxDataViewItem
item( (void*) iter
->user_data
);
3221 bool is_container
= m_wx_model
->IsContainer( item
);
3226 wxGtkTreeModelNode
*node
= FindNode( iter
);
3227 BuildBranch( node
);
3229 return (node
->GetChildCount() > 0);
3233 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
3235 if (m_wx_model
->IsVirtualListModel())
3237 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3240 return (gint
) wx_model
->GetLastIndex() + 1;
3246 wxDataViewItem
item( (void*) iter
->user_data
);
3248 if (!m_wx_model
->IsContainer( item
))
3251 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
3252 BuildBranch( parent_node
);
3254 // wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() );
3256 return parent_node
->GetChildCount();
3260 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
3262 if (m_wx_model
->IsVirtualListModel())
3264 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3272 if (n
>= (gint
) wx_model
->GetLastIndex() + 1)
3275 iter
->stamp
= m_gtk_model
->stamp
;
3276 iter
->user_data
= (gpointer
) n
;
3283 if (parent
) id
= (void*) parent
->user_data
;
3284 wxDataViewItem
item( id
);
3286 if (!m_wx_model
->IsContainer( item
))
3289 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3290 BuildBranch( parent_node
);
3292 // wxPrintf( "iter_nth_child %d\n", n );
3294 iter
->stamp
= m_gtk_model
->stamp
;
3295 iter
->user_data
= parent_node
->GetChildren().Item( n
);
3301 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
3303 if (m_wx_model
->IsVirtualListModel())
3309 wxGtkTreeModelNode
*node
= FindParentNode( child
);
3313 iter
->stamp
= m_gtk_model
->stamp
;
3314 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
3320 static wxGtkTreeModelNode
*
3321 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3327 list
.DeleteContents( true );
3328 wxDataViewItem
it( item
);
3332 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3333 list
.Insert( pItem
);
3334 it
= model
->GetParent( it
);
3337 wxGtkTreeModelNode
* node
= treeNode
;
3338 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3340 if( node
&& node
->GetNodes().GetCount() != 0 )
3342 int len
= node
->GetNodes().GetCount();
3343 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3345 for( ; j
< len
; j
++)
3347 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3366 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
3371 wxDataViewItem
item( (void*) iter
->user_data
);
3375 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3379 wxLogDebug( "Not found %p", iter
->user_data
);
3387 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
3392 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3396 wxLogDebug( "Not found %p", item
.GetID() );
3404 static wxGtkTreeModelNode
*
3405 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3411 list
.DeleteContents( true );
3415 wxDataViewItem
it( model
->GetParent( item
) );
3418 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3419 list
.Insert( pItem
);
3420 it
= model
->GetParent( it
);
3423 wxGtkTreeModelNode
* node
= treeNode
;
3424 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3426 if( node
&& node
->GetNodes().GetCount() != 0 )
3428 int len
= node
->GetNodes().GetCount();
3429 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3431 for( ; j
< len
; j
++)
3433 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3448 //Examine whether the node is item's parent node
3449 int len
= node
->GetChildCount();
3450 for( int i
= 0; i
< len
; i
++ )
3452 if( node
->GetChildren().Item( i
) == item
.GetID() )
3458 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
3463 wxDataViewItem
item( (void*) iter
->user_data
);
3467 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3470 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
3475 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3478 //-----------------------------------------------------------------------------
3479 // wxDataViewCtrl signal callbacks
3480 //-----------------------------------------------------------------------------
3483 wxdataview_selection_changed_callback( GtkTreeSelection
* WXUNUSED(selection
), wxDataViewCtrl
*dv
)
3485 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
3488 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
3489 event
.SetItem( dv
->GetSelection() );
3490 event
.SetModel( dv
->GetModel() );
3491 dv
->HandleWindowEvent( event
);
3495 wxdataview_row_activated_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreePath
*path
,
3496 GtkTreeViewColumn
*WXUNUSED(column
), wxDataViewCtrl
*dv
)
3498 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
3501 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3502 wxDataViewItem
item( (void*) iter
.user_data
);;
3503 event
.SetItem( item
);
3504 event
.SetModel( dv
->GetModel() );
3505 dv
->HandleWindowEvent( event
);
3509 wxdataview_test_expand_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3510 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3512 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
3514 wxDataViewItem
item( (void*) iter
->user_data
);;
3515 event
.SetItem( item
);
3516 event
.SetModel( dv
->GetModel() );
3517 dv
->HandleWindowEvent( event
);
3519 return !event
.IsAllowed();
3523 wxdataview_row_expanded_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3524 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3526 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
3528 wxDataViewItem
item( (void*) iter
->user_data
);;
3529 event
.SetItem( item
);
3530 event
.SetModel( dv
->GetModel() );
3531 dv
->HandleWindowEvent( event
);
3535 wxdataview_test_collapse_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3536 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3538 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
3540 wxDataViewItem
item( (void*) iter
->user_data
);;
3541 event
.SetItem( item
);
3542 event
.SetModel( dv
->GetModel() );
3543 dv
->HandleWindowEvent( event
);
3545 return !event
.IsAllowed();
3549 wxdataview_row_collapsed_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3550 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3552 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
3554 wxDataViewItem
item( (void*) iter
->user_data
);;
3555 event
.SetItem( item
);
3556 event
.SetModel( dv
->GetModel() );
3557 dv
->HandleWindowEvent( event
);
3560 //-----------------------------------------------------------------------------
3562 //-----------------------------------------------------------------------------
3564 void wxDataViewCtrl::AddChildGTK(wxWindowGTK
* child
)
3566 GtkWidget
* treeview
= GtkGetTreeView();
3568 // Insert widget in GtkTreeView
3569 if (GTK_WIDGET_REALIZED(treeview
))
3570 gtk_widget_set_parent_window( child
->m_widget
,
3571 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
3572 gtk_widget_set_parent( child
->m_widget
, treeview
);
3576 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
3577 GtkAllocation
*WXUNUSED(gtk_alloc
),
3578 wxDataViewCtrl
*win
)
3580 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
3583 wxWindow
*child
= node
->GetData();
3586 gtk_widget_size_request( child
->m_widget
, &req
);
3588 GtkAllocation alloc
;
3589 alloc
.x
= child
->m_x
;
3590 alloc
.y
= child
->m_y
;
3591 alloc
.width
= child
->m_width
;
3592 alloc
.height
= child
->m_height
;
3593 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
3595 node
= node
->GetNext();
3600 //-----------------------------------------------------------------------------
3601 // "motion_notify_event"
3602 //-----------------------------------------------------------------------------
3605 gtk_dataview_motion_notify_callback( GtkWidget
*WXUNUSED(widget
),
3606 GdkEventMotion
*gdk_event
,
3607 wxDataViewCtrl
*dv
)
3609 if (gdk_event
->is_hint
)
3613 GdkModifierType state
;
3614 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
3619 GtkTreePath
*path
= NULL
;
3620 GtkTreeViewColumn
*column
= NULL
;
3623 if (gtk_tree_view_get_path_at_pos(
3624 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
3625 (int) gdk_event
->x
, (int) gdk_event
->y
,
3634 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3636 // wxPrintf( "mouse %d %d\n", (int) gdk_event->x, (int) gdk_event->y );
3638 gtk_tree_path_free( path
);
3646 //-----------------------------------------------------------------------------
3647 // "button_press_event"
3648 //-----------------------------------------------------------------------------
3651 gtk_dataview_button_press_callback( GtkWidget
*WXUNUSED(widget
),
3652 GdkEventButton
*gdk_event
,
3653 wxDataViewCtrl
*dv
)
3655 if ((gdk_event
->button
== 3) && (gdk_event
->type
== GDK_BUTTON_PRESS
))
3657 GtkTreePath
*path
= NULL
;
3658 GtkTreeViewColumn
*column
= NULL
;
3661 if (gtk_tree_view_get_path_at_pos(
3662 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
3663 (int) gdk_event
->x
, (int) gdk_event
->y
,
3672 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3674 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, dv
->GetId() );
3675 wxDataViewItem
item( (void*) iter
.user_data
);;
3676 event
.SetItem( item
);
3677 event
.SetModel( dv
->GetModel() );
3678 bool ret
= dv
->HandleWindowEvent( event
);
3679 gtk_tree_path_free( path
);
3688 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
3690 wxDataViewCtrl::~wxDataViewCtrl()
3693 GetModel()->RemoveNotifier( m_notifier
);
3697 // remove the model from the GtkTreeView before it gets destroyed by the
3698 // wxDataViewCtrlBase's dtor
3699 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), NULL
);
3704 void wxDataViewCtrl::Init()
3709 m_cols
.DeleteContents( true );
3712 static GtkTargetEntry gs_target
;
3714 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
3715 const wxPoint
& pos
, const wxSize
& size
,
3716 long style
, const wxValidator
& validator
)
3720 if (!PreCreation( parent
, pos
, size
) ||
3721 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
3723 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
3727 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
3728 g_object_ref(m_widget
);
3730 GtkScrolledWindowSetBorder(m_widget
, style
);
3732 m_treeview
= gtk_tree_view_new();
3733 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
3735 g_signal_connect (m_treeview
, "size_allocate",
3736 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
3738 gs_target
.target
= const_cast<char *>("UTF8_STRING");
3739 gs_target
.flags
= 0;
3740 gs_target
.info
= static_cast<guint
>(-1);
3741 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_treeview
),
3742 GDK_BUTTON1_MASK
, &gs_target
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3745 if (!gtk_check_version(2,6,0))
3747 bool fixed
= (style
& wxDV_VARIABLE_LINE_HEIGHT
) == 0;
3748 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
3752 if (style
& wxDV_MULTIPLE
)
3754 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3755 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
3758 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
3761 if (!gtk_check_version(2,10,0))
3763 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
3765 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
3766 (style
& wxDV_VERT_RULES
) != 0)
3767 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
3768 else if (style
& wxDV_VERT_RULES
)
3769 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
3770 else if (style
& wxDV_HORIZ_RULES
)
3771 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
3773 if (grid
!= GTK_TREE_VIEW_GRID_LINES_NONE
)
3774 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
3778 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_ROW_LINES
) != 0 );
3780 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
3781 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
3782 gtk_widget_show (m_treeview
);
3784 m_parent
->DoAddChild( this );
3788 GtkEnableSelectionEvents();
3790 g_signal_connect_after (m_treeview
, "row-activated",
3791 G_CALLBACK (wxdataview_row_activated_callback
), this);
3793 g_signal_connect (m_treeview
, "test-collapse-row",
3794 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
3796 g_signal_connect_after (m_treeview
, "row-collapsed",
3797 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
3799 g_signal_connect (m_treeview
, "test-expand-row",
3800 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
3802 g_signal_connect_after (m_treeview
, "row-expanded",
3803 G_CALLBACK (wxdataview_row_expanded_callback
), this);
3805 g_signal_connect (m_treeview
, "motion_notify_event",
3806 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
3808 g_signal_connect (m_treeview
, "button_press_event",
3809 G_CALLBACK (gtk_dataview_button_press_callback
), this);
3814 void wxDataViewCtrl::OnInternalIdle()
3816 wxWindow::OnInternalIdle();
3818 unsigned int cols
= GetColumnCount();
3820 for (i
= 0; i
< cols
; i
++)
3822 wxDataViewColumn
*col
= GetColumn( i
);
3823 col
->OnInternalIdle();
3827 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
3838 if (!wxDataViewCtrlBase::AssociateModel( model
))
3842 if (!gtk_check_version(2,6,0))
3844 bool fixed
= (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
) == 0) || (model
->IsVirtualListModel()));
3845 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
3849 GtkWxTreeModel
*gtk_model
= wxgtk_tree_model_new();
3850 m_internal
= new wxDataViewCtrlInternal( this, model
, gtk_model
);
3851 gtk_model
->internal
= m_internal
;
3853 m_notifier
= new wxGtkDataViewModelNotifier( gtk_model
, model
, this );
3855 model
->AddNotifier( m_notifier
);
3857 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_model
) );
3859 // unref in wxDataViewCtrlInternal
3860 // g_object_unref( gtk_model );
3865 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
3867 if (!wxDataViewCtrlBase::AppendColumn(col
))
3870 m_cols
.Append( col
);
3873 if (!gtk_check_version(2,6,0))
3875 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
3876 GTK_TREE_VIEW_COLUMN_FIXED
)
3877 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
3881 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
3882 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
3887 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
3889 if (!wxDataViewCtrlBase::PrependColumn(col
))
3892 m_cols
.Insert( col
);
3895 if (!gtk_check_version(2,6,0))
3897 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
3898 GTK_TREE_VIEW_COLUMN_FIXED
)
3899 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
3903 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
3904 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
3909 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
3911 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
3914 m_cols
.Insert( pos
, col
);
3917 if (!gtk_check_version(2,6,0))
3919 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
3920 GTK_TREE_VIEW_COLUMN_FIXED
)
3921 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
3925 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
3926 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), pos
);
3931 unsigned int wxDataViewCtrl::GetColumnCount() const
3933 return m_cols
.GetCount();
3936 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
3938 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
3942 wxDataViewColumnList::const_iterator iter
;
3943 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
3945 wxDataViewColumn
*col
= *iter
;
3946 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
3955 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
3957 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
3958 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
3960 m_cols
.DeleteObject( column
);
3965 bool wxDataViewCtrl::ClearColumns()
3967 wxDataViewColumnList::iterator iter
;
3968 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
3970 wxDataViewColumn
*col
= *iter
;
3971 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
3972 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
3980 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
3982 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetConstGtkHandle());
3984 GList
*list
= gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview
) );
3986 gint pos
= g_list_index( list
, (gconstpointer
) gtk_column
);
3988 g_list_free( list
);
3993 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
3995 return m_internal
->GetDataViewSortColumn();
3998 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4001 iter
.user_data
= item
.GetID();
4002 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4003 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
4004 gtk_tree_path_free( path
);
4007 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4010 iter
.user_data
= item
.GetID();
4011 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4012 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
4013 gtk_tree_path_free( path
);
4016 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4019 iter
.user_data
= item
.GetID();
4020 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4021 bool res
= gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview
), path
);
4022 gtk_tree_path_free( path
);
4027 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4029 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4031 if (m_windowStyle
& wxDV_MULTIPLE
)
4033 // Report the first one
4034 GtkTreeModel
*model
;
4035 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4039 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4041 m_internal
->get_iter( &iter
, path
);
4044 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4045 g_list_free( list
);
4047 return wxDataViewItem( (void*) iter
.user_data
);
4053 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
4055 wxDataViewItem
item( (void*) iter
.user_data
);
4060 return wxDataViewItem(0);
4063 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4067 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4068 if (HasFlag(wxDV_MULTIPLE
))
4070 GtkTreeModel
*model
;
4071 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4076 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4079 m_internal
->get_iter( &iter
, path
);
4081 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4083 list
= g_list_next( list
);
4088 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4089 g_list_free( list
);
4095 GtkTreeModel
*model
;
4097 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
4100 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4108 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4110 GtkDisableSelectionEvents();
4112 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4114 gtk_tree_selection_unselect_all( selection
);
4116 wxDataViewItem last_parent
;
4119 for (i
= 0; i
< sel
.GetCount(); i
++)
4121 wxDataViewItem item
= sel
[i
];
4122 wxDataViewItem parent
= GetModel()->GetParent( item
);
4125 if (parent
!= last_parent
)
4126 ExpandAncestors(item
);
4128 last_parent
= parent
;
4131 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4132 iter
.user_data
= (gpointer
) item
.GetID();
4133 gtk_tree_selection_select_iter( selection
, &iter
);
4136 GtkEnableSelectionEvents();
4139 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4141 ExpandAncestors(item
);
4143 GtkDisableSelectionEvents();
4145 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4148 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4149 iter
.user_data
= (gpointer
) item
.GetID();
4150 gtk_tree_selection_select_iter( selection
, &iter
);
4152 GtkEnableSelectionEvents();
4155 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4157 GtkDisableSelectionEvents();
4159 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4162 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4163 iter
.user_data
= (gpointer
) item
.GetID();
4164 gtk_tree_selection_unselect_iter( selection
, &iter
);
4166 GtkEnableSelectionEvents();
4169 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4171 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4174 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4175 iter
.user_data
= (gpointer
) item
.GetID();
4177 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
4180 void wxDataViewCtrl::SelectAll()
4182 GtkDisableSelectionEvents();
4184 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4186 gtk_tree_selection_select_all( selection
);
4188 GtkEnableSelectionEvents();
4191 void wxDataViewCtrl::UnselectAll()
4193 GtkDisableSelectionEvents();
4195 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4197 gtk_tree_selection_unselect_all( selection
);
4199 GtkEnableSelectionEvents();
4202 void wxDataViewCtrl::EnsureVisible(const wxDataViewItem
& item
,
4203 const wxDataViewColumn
*WXUNUSED(column
))
4205 ExpandAncestors(item
);
4208 iter
.user_data
= (gpointer
) item
.GetID();
4209 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4210 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
4211 gtk_tree_path_free( path
);
4214 void wxDataViewCtrl::HitTest(const wxPoint
& WXUNUSED(point
),
4215 wxDataViewItem
& item
,
4216 wxDataViewColumn
*& column
) const
4218 item
= wxDataViewItem(0);
4223 wxDataViewCtrl::GetItemRect(const wxDataViewItem
& WXUNUSED(item
),
4224 const wxDataViewColumn
*WXUNUSED(column
)) const
4229 void wxDataViewCtrl::DoSetExpanderColumn()
4231 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
4232 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
4235 void wxDataViewCtrl::DoSetIndent()
4239 void wxDataViewCtrl::GtkDisableSelectionEvents()
4241 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4242 g_signal_handlers_disconnect_by_func( selection
,
4243 (gpointer
) (wxdataview_selection_changed_callback
), this);
4246 void wxDataViewCtrl::GtkEnableSelectionEvents()
4248 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4249 g_signal_connect_after (selection
, "changed",
4250 G_CALLBACK (wxdataview_selection_changed_callback
), this);
4255 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
4257 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
4262 // !wxUSE_GENERICDATAVIEWCTRL
4265 // wxUSE_DATAVIEWCTRL