1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/dataview.cpp
3 // Purpose: wxDataViewCtrl GTK+2 implementation
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if wxUSE_DATAVIEWCTRL
15 #include "wx/dataview.h"
17 #ifndef wxUSE_GENERICDATAVIEWCTRL
21 #include "wx/dcclient.h"
23 #include "wx/settings.h"
27 #include "wx/stockitem.h"
28 #include "wx/calctrl.h"
29 #include "wx/popupwin.h"
30 #include "wx/listimpl.cpp"
32 #include "wx/gtk/private.h"
33 #include "wx/gtk/dc.h"
34 #include "wx/gtk/dcclient.h"
36 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 static wxDataViewCtrlInternal
*gs_internal
= NULL
;
41 class wxGtkTreeModelNode
;
44 typedef struct _GtkWxTreeModel GtkWxTreeModel
;
47 //-----------------------------------------------------------------------------
48 // wxDataViewCtrlInternal
49 //-----------------------------------------------------------------------------
51 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
52 WX_DEFINE_LIST(ItemList
)
54 class WXDLLIMPEXP_ADV wxDataViewCtrlInternal
57 wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
);
58 ~wxDataViewCtrlInternal();
61 GtkTreeModelFlags
get_flags();
62 gboolean
get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
);
63 GtkTreePath
*get_path( GtkTreeIter
*iter
);
64 gboolean
iter_next( GtkTreeIter
*iter
);
65 gboolean
iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
);
66 gboolean
iter_has_child( GtkTreeIter
*iter
);
67 gint
iter_n_children( GtkTreeIter
*iter
);
68 gboolean
iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
);
69 gboolean
iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
);
73 bool EnableDragSource( const wxDataFormat
&format
);
74 bool EnableDropTarget( const wxDataFormat
&format
);
76 gboolean
row_draggable( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
);
77 gboolean
drag_data_delete( GtkTreeDragSource
*drag_source
, GtkTreePath
* path
);
78 gboolean
drag_data_get( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
,
79 GtkSelectionData
*selection_data
);
80 gboolean
drag_data_received( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest
,
81 GtkSelectionData
*selection_data
);
82 gboolean
row_drop_possible( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest_path
,
83 GtkSelectionData
*selection_data
);
85 // notifactions from wxDataViewModel
86 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
87 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
88 bool ItemChanged( const wxDataViewItem
&item
);
89 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
94 void SetSortOrder( GtkSortType sort_order
) { m_sort_order
= sort_order
; }
95 GtkSortType
GetSortOrder() const { return m_sort_order
; }
97 void SetSortColumn( int column
) { m_sort_column
= column
; }
98 int GetSortColumn() const { return m_sort_column
; }
100 void SetDataViewSortColumn( wxDataViewColumn
*column
) { m_dataview_sort_column
= column
; }
101 wxDataViewColumn
*GetDataViewSortColumn() { return m_dataview_sort_column
; }
103 bool IsSorted() { return (m_sort_column
>= 0); }
106 wxDataViewModel
* GetDataViewModel() { return m_wx_model
; }
107 const wxDataViewModel
* GetDataViewModel() const { 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
;
128 GtkTargetEntry m_dragSourceTargetEntry
;
129 wxCharBuffer m_dragSourceTargetEntryTarget
;
130 wxDataObject
*m_dragDataObject
;
132 GtkTargetEntry m_dropTargetTargetEntry
;
133 wxCharBuffer m_dropTargetTargetEntryTarget
;
134 wxDataObject
*m_dropDataObject
;
138 //-----------------------------------------------------------------------------
139 // wxGtkTreeModelNode
140 //-----------------------------------------------------------------------------
143 int LINKAGEMODE
wxGtkTreeModelChildCmp( void** id1
, void** id2
)
145 int ret
= gs_internal
->GetDataViewModel()->Compare( *id1
, *id2
,
146 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
151 WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode
*, wxGtkTreeModelNodes
);
152 WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren
);
154 class wxGtkTreeModelNode
157 wxGtkTreeModelNode( wxGtkTreeModelNode
* parent
, const wxDataViewItem
&item
,
158 wxDataViewCtrlInternal
*internal
)
162 m_internal
= internal
;
165 ~wxGtkTreeModelNode()
167 size_t count
= m_nodes
.GetCount();
169 for (i
= 0; i
< count
; i
++)
171 wxGtkTreeModelNode
*child
= m_nodes
.Item( i
);
176 unsigned int AddNode( wxGtkTreeModelNode
* child
)
178 m_nodes
.Add( child
);
180 void *id
= child
->GetItem().GetID();
182 m_children
.Add( id
);
184 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
186 gs_internal
= m_internal
;
187 m_children
.Sort( &wxGtkTreeModelChildCmp
);
188 return m_children
.Index( id
);
191 return m_children
.GetCount()-1;
194 unsigned int AddLeave( void* id
)
196 m_children
.Add( id
);
198 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
200 gs_internal
= m_internal
;
201 m_children
.Sort( &wxGtkTreeModelChildCmp
);
202 return m_children
.Index( id
);
205 return m_children
.GetCount()-1;
208 void DeleteChild( void* id
)
210 m_children
.Remove( id
);
212 unsigned int count
= m_nodes
.GetCount();
214 for (pos
= 0; pos
< count
; pos
++)
216 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
217 if (node
->GetItem().GetID() == id
)
219 m_nodes
.RemoveAt( pos
);
226 wxGtkTreeModelNode
* GetParent()
228 wxGtkTreeModelNodes
&GetNodes()
230 wxGtkTreeModelChildren
&GetChildren()
231 { return m_children
; }
233 unsigned int GetChildCount() const { return m_children
.GetCount(); }
234 unsigned int GetNodesCount() const { return m_nodes
.GetCount(); }
236 wxDataViewItem
&GetItem() { return m_item
; }
237 wxDataViewCtrlInternal
*GetInternal() { return m_internal
; }
242 wxGtkTreeModelNode
*m_parent
;
243 wxGtkTreeModelNodes m_nodes
;
244 wxGtkTreeModelChildren m_children
;
245 wxDataViewItem m_item
;
246 wxDataViewCtrlInternal
*m_internal
;
250 //-----------------------------------------------------------------------------
252 //-----------------------------------------------------------------------------
254 extern bool g_blockEventsOnDrag
;
256 //-----------------------------------------------------------------------------
257 // define new GTK+ class wxGtkTreeModel
258 //-----------------------------------------------------------------------------
262 #define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ())
263 #define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel))
264 #define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
265 #define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL))
266 #define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL))
267 #define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
269 GType
gtk_wx_tree_model_get_type (void);
271 typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass
;
273 struct _GtkWxTreeModel
279 wxDataViewCtrlInternal
*internal
;
282 struct _GtkWxTreeModelClass
284 GObjectClass list_parent_class
;
287 static GtkWxTreeModel
*wxgtk_tree_model_new (void);
288 static void wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
);
289 static void wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
);
291 static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
);
292 static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
);
293 static void wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
);
294 static void wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
);
296 static void wxgtk_tree_model_finalize (GObject
*object
);
297 static GtkTreeModelFlags
wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
);
298 static gint
wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
);
299 static GType
wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
301 static gboolean
wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
304 static GtkTreePath
*wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
306 static void wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
310 static gboolean
wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
312 static gboolean
wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
314 GtkTreeIter
*parent
);
315 static gboolean
wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
317 static gint
wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
319 static gboolean
wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
323 static gboolean
wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
328 static gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
329 gint
*sort_column_id
,
331 static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
334 static void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
336 GtkTreeIterCompareFunc func
,
338 GtkDestroyNotify destroy
);
339 static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
340 GtkTreeIterCompareFunc func
,
342 GtkDestroyNotify destroy
);
343 static gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
);
346 static gboolean
wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
348 static gboolean
wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
350 static gboolean
wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
352 GtkSelectionData
*selection_data
);
353 static gboolean
wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
355 GtkSelectionData
*selection_data
);
356 static gboolean
wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
357 GtkTreePath
*dest_path
,
358 GtkSelectionData
*selection_data
);
361 static GObjectClass
*list_parent_class
= NULL
;
364 gtk_wx_tree_model_get_type (void)
366 static GType tree_model_type
= 0;
368 if (!tree_model_type
)
370 const GTypeInfo tree_model_info
=
372 sizeof (GtkWxTreeModelClass
),
373 NULL
, /* base_init */
374 NULL
, /* base_finalize */
375 (GClassInitFunc
) wxgtk_tree_model_class_init
,
376 NULL
, /* class_finalize */
377 NULL
, /* class_data */
378 sizeof (GtkWxTreeModel
),
380 (GInstanceInitFunc
) wxgtk_tree_model_init
,
383 static const GInterfaceInfo tree_model_iface_info
=
385 (GInterfaceInitFunc
) wxgtk_tree_model_tree_model_init
,
390 static const GInterfaceInfo sortable_iface_info
=
392 (GInterfaceInitFunc
) wxgtk_tree_model_sortable_init
,
397 static const GInterfaceInfo drag_source_iface_info
=
399 (GInterfaceInitFunc
) wxgtk_tree_model_drag_source_init
,
404 static const GInterfaceInfo drag_dest_iface_info
=
406 (GInterfaceInitFunc
) wxgtk_tree_model_drag_dest_init
,
411 tree_model_type
= g_type_register_static (G_TYPE_OBJECT
, "GtkWxTreeModel",
412 &tree_model_info
, (GTypeFlags
)0 );
414 g_type_add_interface_static (tree_model_type
,
416 &tree_model_iface_info
);
417 g_type_add_interface_static (tree_model_type
,
418 GTK_TYPE_TREE_SORTABLE
,
419 &sortable_iface_info
);
420 g_type_add_interface_static (tree_model_type
,
421 GTK_TYPE_TREE_DRAG_DEST
,
422 &drag_dest_iface_info
);
423 g_type_add_interface_static (tree_model_type
,
424 GTK_TYPE_TREE_DRAG_SOURCE
,
425 &drag_source_iface_info
);
428 return tree_model_type
;
431 static GtkWxTreeModel
*
432 wxgtk_tree_model_new(void)
434 GtkWxTreeModel
*retval
= (GtkWxTreeModel
*) g_object_new (GTK_TYPE_WX_TREE_MODEL
, NULL
);
439 wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
)
441 list_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
442 GObjectClass
*object_class
= (GObjectClass
*) klass
;
443 object_class
->finalize
= wxgtk_tree_model_finalize
;
447 wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
)
449 iface
->get_flags
= wxgtk_tree_model_get_flags
;
450 iface
->get_n_columns
= wxgtk_tree_model_get_n_columns
;
451 iface
->get_column_type
= wxgtk_tree_model_get_column_type
;
452 iface
->get_iter
= wxgtk_tree_model_get_iter
;
453 iface
->get_path
= wxgtk_tree_model_get_path
;
454 iface
->get_value
= wxgtk_tree_model_get_value
;
455 iface
->iter_next
= wxgtk_tree_model_iter_next
;
456 iface
->iter_children
= wxgtk_tree_model_iter_children
;
457 iface
->iter_has_child
= wxgtk_tree_model_iter_has_child
;
458 iface
->iter_n_children
= wxgtk_tree_model_iter_n_children
;
459 iface
->iter_nth_child
= wxgtk_tree_model_iter_nth_child
;
460 iface
->iter_parent
= wxgtk_tree_model_iter_parent
;
464 wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
)
466 iface
->get_sort_column_id
= wxgtk_tree_model_get_sort_column_id
;
467 iface
->set_sort_column_id
= wxgtk_tree_model_set_sort_column_id
;
468 iface
->set_sort_func
= wxgtk_tree_model_set_sort_func
;
469 iface
->set_default_sort_func
= wxgtk_tree_model_set_default_sort_func
;
470 iface
->has_default_sort_func
= wxgtk_tree_model_has_default_sort_func
;
474 wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
)
476 iface
->row_draggable
= wxgtk_tree_model_row_draggable
;
477 iface
->drag_data_delete
= wxgtk_tree_model_drag_data_delete
;
478 iface
->drag_data_get
= wxgtk_tree_model_drag_data_get
;
482 wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
)
484 iface
->drag_data_received
= wxgtk_tree_model_drag_data_received
;
485 iface
->row_drop_possible
= wxgtk_tree_model_row_drop_possible
;
489 wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
)
491 tree_model
->internal
= NULL
;
492 tree_model
->stamp
= g_random_int();
496 wxgtk_tree_model_finalize (GObject
*object
)
499 (* list_parent_class
->finalize
) (object
);
504 //-----------------------------------------------------------------------------
505 // implement callbacks from wxGtkTreeModel class by letting
506 // them call the methods of wxWidgets' wxDataViewModel
507 //-----------------------------------------------------------------------------
509 static GtkTreeModelFlags
510 wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
)
512 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
513 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), (GtkTreeModelFlags
)0 );
515 return wxtree_model
->internal
->get_flags();
519 wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
)
521 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
522 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
524 return wxtree_model
->internal
->GetDataViewModel()->GetColumnCount();
528 wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
531 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
532 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), G_TYPE_INVALID
);
534 GType gtype
= G_TYPE_INVALID
;
536 wxString wxtype
= wxtree_model
->internal
->GetDataViewModel()->GetColumnType( (unsigned int) index
);
538 if (wxtype
== wxT("string"))
539 gtype
= G_TYPE_STRING
;
542 gtype
= G_TYPE_STRING
;
543 // wxFAIL_MSG( wxT("non-string columns not supported yet") );
550 wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
554 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
555 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
556 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
558 return wxtree_model
->internal
->get_iter( iter
, path
);
562 wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
565 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
566 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), NULL
);
567 g_return_val_if_fail (iter
->stamp
== GTK_WX_TREE_MODEL (wxtree_model
)->stamp
, NULL
);
569 return wxtree_model
->internal
->get_path( iter
);
573 wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
578 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
579 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
) );
581 wxDataViewModel
*model
= wxtree_model
->internal
->GetDataViewModel();
582 wxString mtype
= model
->GetColumnType( (unsigned int) column
);
583 if (mtype
== wxT("string"))
586 g_value_init( value
, G_TYPE_STRING
);
587 wxDataViewItem
item( (void*) iter
->user_data
);
588 model
->GetValue( variant
, item
, (unsigned int) column
);
590 g_value_set_string( value
, variant
.GetString().utf8_str() );
594 wxFAIL_MSG( wxT("non-string columns not supported yet") );
599 wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
602 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
604 // This happens when clearing the view by calling .._set_model( NULL );
605 if (iter
->stamp
== 0) return FALSE
;
607 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
608 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
610 return wxtree_model
->internal
->iter_next( iter
);
614 wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
618 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
619 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
620 g_return_val_if_fail (wxtree_model
->stamp
== parent
->stamp
, FALSE
);
622 return wxtree_model
->internal
->iter_children( iter
, parent
);
626 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
629 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
630 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
631 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
633 return wxtree_model
->internal
->iter_has_child( iter
);
637 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
640 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
641 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
642 g_return_val_if_fail ( !iter
|| wxtree_model
->stamp
== iter
->stamp
, 0);
644 return wxtree_model
->internal
->iter_n_children( iter
);
648 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
653 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
654 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
656 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
660 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
664 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
665 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
666 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
668 return wxtree_model
->internal
->iter_parent( iter
, child
);
671 /* drag'n'drop iface */
673 wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
676 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
677 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
679 return wxtree_model
->internal
->row_draggable( drag_source
, path
);
683 wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
686 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
687 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
689 return wxtree_model
->internal
->drag_data_delete( drag_source
, path
);
693 wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
695 GtkSelectionData
*selection_data
)
697 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
698 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
701 wxPrintf( "drag_get_data\n");
703 wxGtkString
atom_selection(gdk_atom_name(selection_data
->selection
));
704 wxPrintf( "selection %s\n", wxString::FromAscii(atom_selection
) );
706 wxGtkString
atom_target(gdk_atom_name(selection_data
->target
));
707 wxPrintf( "target %s\n", wxString::FromAscii(atom_target
) );
709 wxGtkString
atom_type(gdk_atom_name(selection_data
->type
));
710 wxPrintf( "type %s\n", wxString::FromAscii(atom_type
) );
712 wxPrintf( "format %d\n", selection_data
->format
);
715 return wxtree_model
->internal
->drag_data_get( drag_source
, path
, selection_data
);
719 wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
721 GtkSelectionData
*selection_data
)
723 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
724 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
726 return wxtree_model
->internal
->drag_data_received( drag_dest
, dest
, selection_data
);
730 wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
731 GtkTreePath
*dest_path
,
732 GtkSelectionData
*selection_data
)
734 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
735 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
737 return wxtree_model
->internal
->row_drop_possible( drag_dest
, dest_path
, selection_data
);
742 wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
743 gint
*sort_column_id
,
746 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) sortable
;
748 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
750 if (!wxtree_model
->internal
->IsSorted())
753 *sort_column_id
= -1;
760 *sort_column_id
= wxtree_model
->internal
->GetSortColumn();
763 *order
= wxtree_model
->internal
->GetSortOrder();
768 wxDataViewColumn
*gs_lastLeftClickHeader
= NULL
;
771 wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
775 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
776 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
778 tree_model
->internal
->SetDataViewSortColumn( gs_lastLeftClickHeader
);
780 if ((sort_column_id
!= (gint
) tree_model
->internal
->GetSortColumn()) ||
781 (order
!= tree_model
->internal
->GetSortOrder()))
783 tree_model
->internal
->SetSortColumn( sort_column_id
);
784 tree_model
->internal
->SetSortOrder( order
);
786 gtk_tree_sortable_sort_column_changed (sortable
);
788 tree_model
->internal
->GetDataViewModel()->Resort();
791 if (gs_lastLeftClickHeader
)
793 wxDataViewCtrl
*dv
= tree_model
->internal
->GetOwner();
794 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, dv
->GetId() );
795 event
.SetDataViewColumn( gs_lastLeftClickHeader
);
796 event
.SetModel( dv
->GetModel() );
797 dv
->HandleWindowEvent( event
);
800 gs_lastLeftClickHeader
= NULL
;
804 wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
805 gint
WXUNUSED(sort_column_id
),
806 GtkTreeIterCompareFunc func
,
807 gpointer
WXUNUSED(data
),
808 GtkDestroyNotify
WXUNUSED(destroy
))
810 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
811 g_return_if_fail (func
!= NULL
);
815 wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
816 GtkTreeIterCompareFunc func
,
817 gpointer
WXUNUSED(data
),
818 GtkDestroyNotify
WXUNUSED(destroy
))
820 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
821 g_return_if_fail (func
!= NULL
);
823 //wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
824 // TODO: remove this code
828 wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
)
830 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
835 //-----------------------------------------------------------------------------
836 // define new GTK+ class GtkWxRendererText
837 //-----------------------------------------------------------------------------
841 #define GTK_TYPE_WX_CELL_RENDERER_TEXT (gtk_wx_cell_renderer_text_get_type ())
842 #define GTK_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererText))
843 #define GTK_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
844 #define GTK_IS_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT))
845 #define GTK_IS_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT))
846 #define GTK_WX_CELL_RENDERER_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
848 GType
gtk_wx_cell_renderer_text_get_type (void);
850 typedef struct _GtkWxCellRendererText GtkWxCellRendererText
;
851 typedef struct _GtkWxCellRendererTextClass GtkWxCellRendererTextClass
;
853 struct _GtkWxCellRendererText
855 GtkCellRendererText parent
;
857 wxDataViewRenderer
*wx_renderer
;
860 struct _GtkWxCellRendererTextClass
862 GtkCellRendererTextClass cell_parent_class
;
866 static GtkWxCellRendererText
*gtk_wx_cell_renderer_text_new (void);
867 static void gtk_wx_cell_renderer_text_init (
868 GtkWxCellRendererText
*cell
);
869 static void gtk_wx_cell_renderer_text_class_init(
870 GtkWxCellRendererTextClass
*klass
);
871 static void gtk_wx_cell_renderer_text_finalize (
873 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
874 GtkCellRenderer
*cell
,
878 GdkRectangle
*background_area
,
879 GdkRectangle
*cell_area
,
880 GtkCellRendererState flags
);
883 static GObjectClass
*text_cell_parent_class
= NULL
;
888 gtk_wx_cell_renderer_text_get_type (void)
890 static GType cell_wx_type
= 0;
894 const GTypeInfo cell_wx_info
=
896 sizeof (GtkWxCellRendererTextClass
),
897 NULL
, /* base_init */
898 NULL
, /* base_finalize */
899 (GClassInitFunc
) gtk_wx_cell_renderer_text_class_init
,
900 NULL
, /* class_finalize */
901 NULL
, /* class_data */
902 sizeof (GtkWxCellRendererText
),
904 (GInstanceInitFunc
) gtk_wx_cell_renderer_text_init
,
907 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER_TEXT
,
908 "GtkWxCellRendererText", &cell_wx_info
, (GTypeFlags
)0 );
915 gtk_wx_cell_renderer_text_init (GtkWxCellRendererText
*cell
)
917 cell
->wx_renderer
= NULL
;
921 gtk_wx_cell_renderer_text_class_init (GtkWxCellRendererTextClass
*klass
)
923 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
924 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
926 text_cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
928 object_class
->finalize
= gtk_wx_cell_renderer_text_finalize
;
930 cell_class
->start_editing
= gtk_wx_cell_renderer_text_start_editing
;
934 gtk_wx_cell_renderer_text_finalize (GObject
*object
)
937 (* G_OBJECT_CLASS (text_cell_parent_class
)->finalize
) (object
);
940 GtkWxCellRendererText
*
941 gtk_wx_cell_renderer_text_new (void)
943 return (GtkWxCellRendererText
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER_TEXT
, NULL
);
946 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
947 GtkCellRenderer
*gtk_renderer
,
951 GdkRectangle
*background_area
,
952 GdkRectangle
*cell_area
,
953 GtkCellRendererState flags
)
955 GtkWxCellRendererText
*wxgtk_renderer
= (GtkWxCellRendererText
*) gtk_renderer
;
956 wxDataViewRenderer
*wx_renderer
= wxgtk_renderer
->wx_renderer
;
958 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
960 wx_renderer
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
961 wxDataViewItem
item( (void*) iter
.user_data
);;
962 gtk_tree_path_free( treepath
);
964 wxDataViewColumn
*column
= wx_renderer
->GetOwner();
965 wxDataViewCtrl
*dv
= column
->GetOwner();
966 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, dv
->GetId() );
967 event
.SetDataViewColumn( column
);
968 event
.SetModel( dv
->GetModel() );
969 event
.SetColumn( wx_renderer
->GetOwner()->GetModelColumn() );
970 event
.SetItem( item
);
971 dv
->HandleWindowEvent( event
);
973 if (event
.IsAllowed())
974 return GTK_CELL_RENDERER_CLASS(text_cell_parent_class
)->
975 start_editing( gtk_renderer
, gdk_event
, widget
, path
, background_area
, cell_area
, flags
);
980 //-----------------------------------------------------------------------------
981 // define new GTK+ class GtkWxCellRenderer
982 //-----------------------------------------------------------------------------
986 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
987 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
988 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
989 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
990 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
991 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
993 GType
gtk_wx_cell_renderer_get_type (void);
995 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
996 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
998 struct _GtkWxCellRenderer
1000 GtkCellRenderer parent
;
1003 wxDataViewCustomRenderer
*cell
;
1007 struct _GtkWxCellRendererClass
1009 GtkCellRendererClass cell_parent_class
;
1013 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
1014 static void gtk_wx_cell_renderer_init (
1015 GtkWxCellRenderer
*cell
);
1016 static void gtk_wx_cell_renderer_class_init(
1017 GtkWxCellRendererClass
*klass
);
1018 static void gtk_wx_cell_renderer_finalize (
1020 static void gtk_wx_cell_renderer_get_size (
1021 GtkCellRenderer
*cell
,
1023 GdkRectangle
*rectangle
,
1028 static void gtk_wx_cell_renderer_render (
1029 GtkCellRenderer
*cell
,
1032 GdkRectangle
*background_area
,
1033 GdkRectangle
*cell_area
,
1034 GdkRectangle
*expose_area
,
1035 GtkCellRendererState flags
);
1036 static gboolean
gtk_wx_cell_renderer_activate(
1037 GtkCellRenderer
*cell
,
1041 GdkRectangle
*background_area
,
1042 GdkRectangle
*cell_area
,
1043 GtkCellRendererState flags
);
1044 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1045 GtkCellRenderer
*cell
,
1049 GdkRectangle
*background_area
,
1050 GdkRectangle
*cell_area
,
1051 GtkCellRendererState flags
);
1054 static GObjectClass
*cell_parent_class
= NULL
;
1059 gtk_wx_cell_renderer_get_type (void)
1061 static GType cell_wx_type
= 0;
1065 const GTypeInfo cell_wx_info
=
1067 sizeof (GtkWxCellRendererClass
),
1068 NULL
, /* base_init */
1069 NULL
, /* base_finalize */
1070 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
1071 NULL
, /* class_finalize */
1072 NULL
, /* class_data */
1073 sizeof (GtkWxCellRenderer
),
1074 0, /* n_preallocs */
1075 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
1078 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
1079 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
1082 return cell_wx_type
;
1086 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
1089 cell
->last_click
= 0;
1093 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
1095 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1096 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
1098 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
1100 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
1102 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
1103 cell_class
->render
= gtk_wx_cell_renderer_render
;
1104 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
1105 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
1109 gtk_wx_cell_renderer_finalize (GObject
*object
)
1112 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
1116 gtk_wx_cell_renderer_new (void)
1118 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
1121 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1122 GtkCellRenderer
*renderer
,
1123 GdkEvent
*WXUNUSED(event
),
1126 GdkRectangle
*WXUNUSED(background_area
),
1127 GdkRectangle
*cell_area
,
1128 GtkCellRendererState
WXUNUSED(flags
) )
1130 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1131 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1133 // Renderer doesn't support in-place editing
1134 if (!cell
->HasEditorCtrl())
1137 // An in-place editing control is still around
1138 if (cell
->GetEditorCtrl())
1142 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1148 rect
.x
+= cell_area
->x
;
1149 rect
.y
+= cell_area
->y
;
1150 // rect.width -= renderer->xpad * 2;
1151 // rect.height -= renderer->ypad * 2;
1153 // wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
1154 wxRect
renderrect( cell_area
->x
, cell_area
->y
, cell_area
->width
, cell_area
->height
);
1156 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
1158 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
1159 wxDataViewItem
item( (void*) iter
.user_data
);
1160 gtk_tree_path_free( treepath
);
1162 cell
->StartEditing( item
, renderrect
);
1168 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
1169 GtkWidget
*WXUNUSED(widget
),
1170 GdkRectangle
*cell_area
,
1176 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1177 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1179 wxSize size
= cell
->GetSize();
1181 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
1182 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
1189 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
1193 *x_offset
= (gint
)((renderer
->xalign
*
1194 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
1195 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
1199 *y_offset
= (gint
)((renderer
->yalign
*
1200 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
1201 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
1206 *width
= calc_width
;
1209 *height
= calc_height
;
1213 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
1216 GdkRectangle
*background_area
,
1217 GdkRectangle
*cell_area
,
1218 GdkRectangle
*expose_area
,
1219 GtkCellRendererState flags
)
1222 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1223 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1225 cell
->window
= window
;
1226 cell
->widget
= widget
;
1227 cell
->background_area
= (void*) background_area
;
1228 cell
->cell_area
= (void*) cell_area
;
1229 cell
->expose_area
= (void*) expose_area
;
1230 cell
->flags
= (int) flags
;
1233 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1239 rect
.x
+= cell_area
->x
;
1240 rect
.y
+= cell_area
->y
;
1241 rect
.width
-= renderer
->xpad
* 2;
1242 rect
.height
-= renderer
->ypad
* 2;
1245 if (gdk_rectangle_intersect (expose_area
, &rect
, &dummy
))
1247 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1248 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
1249 wxWindowDCImpl
*impl
= (wxWindowDCImpl
*) dc
->GetImpl();
1251 // Reinitialize wxWindowDC's GDK window if drawing occurs into a different
1252 // window such as a DnD drop window.
1253 if (window
!= impl
->m_gdkwindow
)
1256 impl
->m_gdkwindow
= window
;
1261 if (flags
& GTK_CELL_RENDERER_SELECTED
)
1262 state
|= wxDATAVIEW_CELL_SELECTED
;
1263 if (flags
& GTK_CELL_RENDERER_PRELIT
)
1264 state
|= wxDATAVIEW_CELL_PRELIT
;
1265 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1266 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1267 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1268 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1269 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
1270 state
|= wxDATAVIEW_CELL_FOCUSED
;
1271 cell
->Render( renderrect
, dc
, state
);
1276 gtk_wx_cell_renderer_activate(
1277 GtkCellRenderer
*renderer
,
1281 GdkRectangle
*WXUNUSED(background_area
),
1282 GdkRectangle
*cell_area
,
1283 GtkCellRendererState
WXUNUSED(flags
) )
1285 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1286 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1289 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1295 rect
.x
+= cell_area
->x
;
1296 rect
.y
+= cell_area
->y
;
1297 rect
.width
-= renderer
->xpad
* 2;
1298 rect
.height
-= renderer
->ypad
* 2;
1300 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1302 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1304 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
1307 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
1308 wxDataViewItem
item( iter
.user_data
);
1309 gtk_tree_path_free( treepath
);
1311 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1317 // activated by <ENTER>
1318 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1323 else if (event
->type
== GDK_BUTTON_PRESS
)
1325 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
1326 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
1327 ((int) button_event
->y
) - renderrect
.y
);
1330 if (button_event
->button
== 1)
1332 if (cell
->LeftClick( pt
, renderrect
, model
, item
, model_col
))
1334 // TODO: query system double-click time
1335 if (button_event
->time
- wxrenderer
->last_click
< 400)
1336 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1339 wxrenderer
->last_click
= button_event
->time
;
1347 // ---------------------------------------------------------
1348 // wxGtkDataViewModelNotifier
1349 // ---------------------------------------------------------
1351 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1354 wxGtkDataViewModelNotifier( GtkWxTreeModel
*wxgtk_model
,
1355 wxDataViewModel
*wx_model
,
1356 wxDataViewCtrl
*ctrl
);
1357 ~wxGtkDataViewModelNotifier();
1359 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1360 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1361 virtual bool ItemChanged( const wxDataViewItem
&item
);
1362 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
1363 virtual bool Cleared();
1364 virtual void Resort();
1366 void SetGtkModel( GtkWxTreeModel
*model
) { m_wxgtk_model
= model
; }
1369 GtkWxTreeModel
*m_wxgtk_model
;
1370 wxDataViewModel
*m_wx_model
;
1371 wxDataViewCtrl
*m_owner
;
1374 // ---------------------------------------------------------
1375 // wxGtkDataViewListModelNotifier
1376 // ---------------------------------------------------------
1378 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1379 GtkWxTreeModel
* wxgtk_model
, wxDataViewModel
*wx_model
,
1380 wxDataViewCtrl
*ctrl
)
1382 m_wxgtk_model
= wxgtk_model
;
1383 m_wx_model
= wx_model
;
1387 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1390 m_wxgtk_model
= NULL
;
1393 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1395 m_owner
->GtkGetInternal()->ItemAdded( parent
, item
);
1398 iter
.stamp
= m_wxgtk_model
->stamp
;
1399 iter
.user_data
= (gpointer
) item
.GetID();
1401 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1402 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1403 gtk_tree_model_row_inserted(
1404 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1405 gtk_tree_path_free (path
);
1410 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1413 iter
.stamp
= m_wxgtk_model
->stamp
;
1414 iter
.user_data
= (gpointer
) item
.GetID();
1416 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1417 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1418 gtk_tree_model_row_deleted(
1419 GTK_TREE_MODEL(m_wxgtk_model
), path
);
1420 gtk_tree_path_free (path
);
1422 m_owner
->GtkGetInternal()->ItemDeleted( parent
, item
);
1427 void wxGtkDataViewModelNotifier::Resort()
1429 m_owner
->GtkGetInternal()->Resort();
1432 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1435 iter
.stamp
= m_wxgtk_model
->stamp
;
1436 iter
.user_data
= (gpointer
) item
.GetID();
1438 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1439 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1440 gtk_tree_model_row_changed(
1441 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1442 gtk_tree_path_free (path
);
1444 m_owner
->GtkGetInternal()->ItemChanged( item
);
1449 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_col
)
1451 // This adds GTK+'s missing MVC logic for ValueChanged
1453 for (index
= 0; index
< m_owner
->GetColumnCount(); index
++)
1455 wxDataViewColumn
*column
= m_owner
->GetColumn( index
);
1456 if (column
->GetModelColumn() == model_col
)
1458 GtkTreeView
*widget
= GTK_TREE_VIEW(m_owner
->m_treeview
);
1459 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1463 iter
.stamp
= m_wxgtk_model
->stamp
;
1464 iter
.user_data
= (gpointer
) item
.GetID();
1465 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1466 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1467 GdkRectangle cell_area
;
1468 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1469 gtk_tree_path_free( path
);
1471 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1472 double d
= gtk_adjustment_get_value( hadjust
);
1473 int xdiff
= (int) d
;
1475 int ydiff
= gcolumn
->button
->allocation
.height
;
1477 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1478 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1480 m_owner
->GtkGetInternal()->ValueChanged( item
, model_col
);
1489 bool wxGtkDataViewModelNotifier::Cleared()
1491 m_owner
->GtkGetInternal()->Cleared();
1496 // ---------------------------------------------------------
1497 // wxDataViewRenderer
1498 // ---------------------------------------------------------
1500 static gpointer s_user_data
= NULL
;
1503 wxgtk_cell_editable_editing_done( GtkCellEditable
*WXUNUSED(editable
),
1504 wxDataViewRenderer
*wxrenderer
)
1506 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1507 wxDataViewCtrl
*dv
= column
->GetOwner();
1508 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1509 event
.SetDataViewColumn( column
);
1510 event
.SetModel( dv
->GetModel() );
1511 wxDataViewItem
item( s_user_data
);
1512 event
.SetItem( item
);
1513 dv
->HandleWindowEvent( event
);
1517 wxgtk_renderer_editing_started( GtkCellRenderer
*WXUNUSED(cell
), GtkCellEditable
*editable
,
1518 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1523 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1524 wxDataViewCtrl
*dv
= column
->GetOwner();
1525 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1526 event
.SetDataViewColumn( column
);
1527 event
.SetModel( dv
->GetModel() );
1528 GtkTreePath
*tree_path
= gtk_tree_path_new_from_string( path
);
1530 dv
->GtkGetInternal()->get_iter( &iter
, tree_path
);
1531 gtk_tree_path_free( tree_path
);
1532 wxDataViewItem
item( iter
.user_data
);
1533 event
.SetItem( item
);
1534 dv
->HandleWindowEvent( event
);
1536 if (GTK_IS_CELL_EDITABLE(editable
))
1538 s_user_data
= iter
.user_data
;
1540 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1541 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1542 (gpointer
) wxrenderer
);
1548 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1550 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1552 wxDataViewRendererBase( varianttype
, mode
, align
)
1556 // we haven't changed them yet
1557 m_usingDefaultAttrs
= true;
1559 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1560 // after the m_renderer pointer has been initialized
1563 void wxDataViewRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
1565 gtk_tree_view_column_pack_end( column
, m_renderer
, TRUE
/* expand */);
1568 void wxDataViewRenderer::GtkInitHandlers()
1570 if (!gtk_check_version(2,6,0))
1572 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1573 G_CALLBACK (wxgtk_renderer_editing_started
),
1578 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1580 GtkCellRendererMode gtkMode
;
1583 case wxDATAVIEW_CELL_INERT
:
1584 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1587 case wxDATAVIEW_CELL_ACTIVATABLE
:
1588 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1591 case wxDATAVIEW_CELL_EDITABLE
:
1592 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1596 wxFAIL_MSG( "unknown wxDataViewCellMode value" );
1600 // This value is most often ignored in GtkTreeView
1601 GValue gvalue
= { 0, };
1602 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1603 g_value_set_enum( &gvalue
, gtkMode
);
1604 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1605 g_value_unset( &gvalue
);
1608 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1610 wxDataViewCellMode ret
;
1613 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1615 switch (g_value_get_enum(&gvalue
))
1618 wxFAIL_MSG( "unknown GtkCellRendererMode value" );
1619 // fall through (we have to return something)
1621 case GTK_CELL_RENDERER_MODE_INERT
:
1622 ret
= wxDATAVIEW_CELL_INERT
;
1625 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1626 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1629 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1630 ret
= wxDATAVIEW_CELL_EDITABLE
;
1634 g_value_unset( &gvalue
);
1639 void wxDataViewRenderer::GtkUpdateAlignment()
1641 int align
= m_alignment
;
1643 // query alignment from column ?
1647 if (GetOwner() == NULL
)
1650 align
= GetOwner()->GetAlignment();
1651 align
|= wxALIGN_CENTRE_VERTICAL
;
1654 // horizontal alignment:
1656 gfloat xalign
= 0.0;
1657 if (align
& wxALIGN_RIGHT
)
1659 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1662 GValue gvalue
= { 0, };
1663 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1664 g_value_set_float( &gvalue
, xalign
);
1665 g_object_set_property( G_OBJECT(m_renderer
), "xalign", &gvalue
);
1666 g_value_unset( &gvalue
);
1668 // vertical alignment:
1670 gfloat yalign
= 0.0;
1671 if (align
& wxALIGN_BOTTOM
)
1673 else if (align
& wxALIGN_CENTER_VERTICAL
)
1676 GValue gvalue2
= { 0, };
1677 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1678 g_value_set_float( &gvalue2
, yalign
);
1679 g_object_set_property( G_OBJECT(m_renderer
), "yalign", &gvalue2
);
1680 g_value_unset( &gvalue2
);
1683 void wxDataViewRenderer::SetAlignment( int align
)
1685 m_alignment
= align
;
1686 GtkUpdateAlignment();
1689 int wxDataViewRenderer::GetAlignment() const
1695 wxDataViewRenderer::GtkOnTextEdited(const gchar
*itempath
, const wxString
& str
)
1697 wxVariant
value(str
);
1698 if (!Validate( value
))
1701 GtkTreePath
*path
= gtk_tree_path_new_from_string( itempath
);
1703 GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, path
);
1704 wxDataViewItem
item( (void*) iter
.user_data
);;
1705 gtk_tree_path_free( path
);
1707 GtkOnCellChanged(value
, item
, GetOwner()->GetModelColumn());
1711 wxDataViewRenderer::GtkOnCellChanged(const wxVariant
& value
,
1712 const wxDataViewItem
& item
,
1715 wxDataViewModel
*model
= GetOwner()->GetOwner()->GetModel();
1716 model
->SetValue( value
, item
, col
);
1717 model
->ValueChanged( item
, col
);
1720 // ---------------------------------------------------------
1721 // wxDataViewTextRenderer
1722 // ---------------------------------------------------------
1727 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*WXUNUSED(renderer
),
1728 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1730 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) user_data
;
1732 cell
->GtkOnTextEdited(arg1
, wxGTK_CONV_BACK_FONT(
1733 arg2
, cell
->GetOwner()->GetOwner()->GetFont()));
1738 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
1740 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1742 wxDataViewRenderer( varianttype
, mode
, align
)
1744 GtkWxCellRendererText
*text_renderer
= gtk_wx_cell_renderer_text_new();
1745 text_renderer
->wx_renderer
= this;
1746 m_renderer
= (GtkCellRenderer
*) text_renderer
;
1748 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
1750 GValue gvalue
= { 0, };
1751 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1752 g_value_set_boolean( &gvalue
, true );
1753 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
1754 g_value_unset( &gvalue
);
1756 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
1762 SetAlignment(align
);
1765 bool wxDataViewTextRenderer::SetTextValue(const wxString
& str
)
1767 GValue gvalue
= { 0, };
1768 g_value_init( &gvalue
, G_TYPE_STRING
);
1769 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( str
, GetOwner()->GetOwner()->GetFont() ) );
1770 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1771 g_value_unset( &gvalue
);
1776 bool wxDataViewTextRenderer::GetTextValue(wxString
& str
) const
1778 GValue gvalue
= { 0, };
1779 g_value_init( &gvalue
, G_TYPE_STRING
);
1780 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1781 str
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
), const_cast<wxDataViewTextRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
1782 g_value_unset( &gvalue
);
1787 void wxDataViewTextRenderer::SetAlignment( int align
)
1789 wxDataViewRenderer::SetAlignment(align
);
1791 if (gtk_check_version(2,10,0))
1794 // horizontal alignment:
1795 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
1796 if (align
& wxALIGN_RIGHT
)
1797 pangoAlign
= PANGO_ALIGN_RIGHT
;
1798 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1799 pangoAlign
= PANGO_ALIGN_CENTER
;
1801 GValue gvalue
= { 0, };
1802 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1803 g_value_set_enum( &gvalue
, pangoAlign
);
1804 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
1805 g_value_unset( &gvalue
);
1808 // ---------------------------------------------------------
1809 // wxDataViewBitmapRenderer
1810 // ---------------------------------------------------------
1815 // set "pixbuf" property on the given renderer
1816 void SetPixbufProp(GtkCellRenderer
*renderer
, GdkPixbuf
*pixbuf
)
1818 GValue gvalue
= { 0, };
1819 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1820 g_value_set_object( &gvalue
, pixbuf
);
1821 g_object_set_property( G_OBJECT(renderer
), "pixbuf", &gvalue
);
1822 g_value_unset( &gvalue
);
1825 } // anonymous namespace
1827 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
1829 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1831 wxDataViewRenderer( varianttype
, mode
, align
)
1833 m_renderer
= gtk_cell_renderer_pixbuf_new();
1836 SetAlignment(align
);
1839 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
1841 if (value
.GetType() == wxT("wxBitmap"))
1846 // GetPixbuf() may create a Pixbuf representation in the wxBitmap
1847 // object (and it will stay there and remain owned by wxBitmap)
1848 SetPixbufProp(m_renderer
, bitmap
.GetPixbuf());
1850 else if (value
.GetType() == wxT("wxIcon"))
1855 SetPixbufProp(m_renderer
, icon
.GetPixbuf());
1865 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
1870 // ---------------------------------------------------------
1871 // wxDataViewToggleRenderer
1872 // ---------------------------------------------------------
1875 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1876 gchar
*path
, gpointer user_data
);
1879 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1880 gchar
*path
, gpointer user_data
)
1882 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
1885 GValue gvalue
= { 0, };
1886 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1887 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
1888 bool tmp
= g_value_get_boolean( &gvalue
);
1889 g_value_unset( &gvalue
);
1893 wxVariant value
= tmp
;
1894 if (!cell
->Validate( value
))
1897 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1899 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
1901 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, gtk_path
);
1902 wxDataViewItem
item( (void*) iter
.user_data
);;
1903 gtk_tree_path_free( gtk_path
);
1905 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1907 model
->SetValue( value
, item
, model_col
);
1908 model
->ValueChanged( item
, model_col
);
1911 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1913 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1914 wxDataViewCellMode mode
, int align
) :
1915 wxDataViewRenderer( varianttype
, mode
, align
)
1917 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
1919 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1921 g_signal_connect_after( m_renderer
, "toggled",
1922 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
1926 GValue gvalue
= { 0, };
1927 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1928 g_value_set_boolean( &gvalue
, false );
1929 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
1930 g_value_unset( &gvalue
);
1934 SetAlignment(align
);
1937 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1941 GValue gvalue
= { 0, };
1942 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1943 g_value_set_boolean( &gvalue
, tmp
);
1944 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1945 g_value_unset( &gvalue
);
1950 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
1952 GValue gvalue
= { 0, };
1953 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1954 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1955 bool tmp
= g_value_get_boolean( &gvalue
);
1956 g_value_unset( &gvalue
);
1963 // ---------------------------------------------------------
1964 // wxDataViewCustomRenderer
1965 // ---------------------------------------------------------
1967 class wxDataViewCtrlDCImpl
: public wxWindowDCImpl
1970 wxDataViewCtrlDCImpl( wxDC
*owner
, wxDataViewCtrl
*window
) :
1971 wxWindowDCImpl( owner
)
1973 GtkWidget
*widget
= window
->m_treeview
;
1979 m_context
= window
->GTKGetPangoDefaultContext();
1980 m_layout
= pango_layout_new( m_context
);
1981 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
1983 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
1985 // Set m_gdkwindow later
1990 class wxDataViewCtrlDC
: public wxWindowDC
1993 wxDataViewCtrlDC( wxDataViewCtrl
*window
) :
1994 wxWindowDC( new wxDataViewCtrlDCImpl( this, window
) )
1999 // ---------------------------------------------------------
2000 // wxDataViewCustomRenderer
2001 // ---------------------------------------------------------
2003 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
2005 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
2006 wxDataViewCellMode mode
, int align
,
2008 wxDataViewRenderer( varianttype
, mode
, align
)
2011 m_text_renderer
= NULL
;
2019 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
,
2020 wxRect
WXUNUSED(cell
), wxDC
*WXUNUSED(dc
), int WXUNUSED(state
) )
2023 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
2024 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
2025 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
2026 view
->GetForegroundColour();
2027 dc
->SetTextForeground(col
);
2028 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
2030 if (!m_text_renderer
)
2031 m_text_renderer
= gtk_cell_renderer_text_new();
2033 GValue gvalue
= { 0, };
2034 g_value_init( &gvalue
, G_TYPE_STRING
);
2035 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( text
, GetOwner()->GetOwner()->GetFont() ) );
2036 g_object_set_property( G_OBJECT(m_text_renderer
), "text", &gvalue
);
2037 g_value_unset( &gvalue
);
2039 ((GdkRectangle
*) cell_area
)->x
+= xoffset
;
2040 ((GdkRectangle
*) cell_area
)->width
-= xoffset
;
2042 gtk_cell_renderer_render( m_text_renderer
,
2045 (GdkRectangle
*) background_area
,
2046 (GdkRectangle
*) cell_area
,
2047 (GdkRectangle
*) expose_area
,
2048 (GtkCellRendererState
) flags
);
2050 ((GdkRectangle
*) cell_area
)->x
-= xoffset
;
2051 ((GdkRectangle
*) cell_area
)->width
+= xoffset
;
2055 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
2057 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
2058 renderer
->cell
= this;
2060 m_renderer
= (GtkCellRenderer
*) renderer
;
2063 SetAlignment(align
);
2070 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
2075 if (m_text_renderer
)
2076 gtk_object_sink( GTK_OBJECT(m_text_renderer
) );
2079 wxDC
*wxDataViewCustomRenderer::GetDC()
2083 if (GetOwner() == NULL
)
2085 if (GetOwner()->GetOwner() == NULL
)
2087 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
2093 // ---------------------------------------------------------
2094 // wxDataViewProgressRenderer
2095 // ---------------------------------------------------------
2097 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
2099 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
2100 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
2101 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
2107 if (!gtk_check_version(2,6,0))
2109 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
2111 GValue gvalue
= { 0, };
2112 g_value_init( &gvalue
, G_TYPE_STRING
);
2114 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( m_label
, GetOwner()->GetOwner()->GetFont() ) );
2115 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2116 g_value_unset( &gvalue
);
2119 SetAlignment(align
);
2124 // Use custom cell code
2125 wxDataViewCustomRenderer::Init(mode
, align
);
2129 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
2133 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
2136 if (!gtk_check_version(2,6,0))
2138 gint tmp
= (long) value
;
2139 GValue gvalue
= { 0, };
2140 g_value_init( &gvalue
, G_TYPE_INT
);
2141 g_value_set_int( &gvalue
, tmp
);
2142 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
2143 g_value_unset( &gvalue
);
2148 m_value
= (long) value
;
2150 if (m_value
< 0) m_value
= 0;
2151 if (m_value
> 100) m_value
= 100;
2157 bool wxDataViewProgressRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2162 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
2164 double pct
= (double)m_value
/ 100.0;
2166 bar
.width
= (int)(cell
.width
* pct
);
2167 dc
->SetPen( *wxTRANSPARENT_PEN
);
2168 dc
->SetBrush( *wxBLUE_BRUSH
);
2169 dc
->DrawRectangle( bar
);
2171 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
2172 dc
->SetPen( *wxBLACK_PEN
);
2173 dc
->DrawRectangle( cell
);
2178 wxSize
wxDataViewProgressRenderer::GetSize() const
2180 return wxSize(40,12);
2183 // -------------------------------------
2184 // wxDataViewChoiceRenderer
2185 // -------------------------------------
2187 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
&choices
,
2188 wxDataViewCellMode mode
, int alignment
) :
2189 wxDataViewCustomRenderer( "string", mode
, alignment
, true )
2191 m_choices
= choices
;
2194 if (!gtk_check_version(2,6,0))
2196 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_combo_new();
2198 GtkListStore
*store
= gtk_list_store_new( 1, G_TYPE_STRING
);
2199 for (size_t n
= 0; n
< m_choices
.GetCount(); n
++)
2201 gtk_list_store_insert_with_values(
2203 static_cast<const char *>(m_choices
[n
].utf8_str()), -1 );
2206 g_object_set (m_renderer
,
2212 bool editable
= (mode
& wxDATAVIEW_CELL_EDITABLE
);
2213 g_object_set (m_renderer
, "editable", editable
, NULL
);
2215 SetAlignment(alignment
);
2217 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2224 // Use custom cell code
2225 wxDataViewCustomRenderer::Init(mode
, alignment
);
2229 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
2231 RenderText( m_data
, 0, rect
, dc
, state
);
2235 wxSize
wxDataViewChoiceRenderer::GetSize() const
2237 return wxSize(70,20);
2240 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
2244 if (!gtk_check_version(2,6,0))
2246 GValue gvalue
= { 0, };
2247 g_value_init( &gvalue
, G_TYPE_STRING
);
2248 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( value
.GetString(), GetOwner()->GetOwner()->GetFont() ) );
2249 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2250 g_value_unset( &gvalue
);
2254 m_data
= value
.GetString();
2259 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
2262 if (!gtk_check_version(2,6,0))
2264 GValue gvalue
= { 0, };
2265 g_value_init( &gvalue
, G_TYPE_STRING
);
2266 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2267 wxString temp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
),
2268 const_cast<wxDataViewChoiceRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
2269 g_value_unset( &gvalue
);
2272 //wxPrintf( "temp %s\n", temp );
2273 // TODO: remove this code
2282 void wxDataViewChoiceRenderer::SetAlignment( int align
)
2284 wxDataViewCustomRenderer::SetAlignment(align
);
2286 if (gtk_check_version(2,10,0))
2289 // horizontal alignment:
2290 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2291 if (align
& wxALIGN_RIGHT
)
2292 pangoAlign
= PANGO_ALIGN_RIGHT
;
2293 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2294 pangoAlign
= PANGO_ALIGN_CENTER
;
2296 GValue gvalue
= { 0, };
2297 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2298 g_value_set_enum( &gvalue
, pangoAlign
);
2299 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2300 g_value_unset( &gvalue
);
2303 // ---------------------------------------------------------
2304 // wxDataViewDateRenderer
2305 // ---------------------------------------------------------
2307 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
2310 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
2311 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
2312 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
2317 m_cal
= new wxCalendarCtrl( this, -1, *value
);
2318 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
2319 sizer
->Add( m_cal
, 1, wxGROW
);
2324 virtual void OnDismiss()
2328 void OnCalendar( wxCalendarEvent
&event
);
2330 wxCalendarCtrl
*m_cal
;
2331 wxDataViewModel
*m_model
;
2332 wxDataViewItem m_item
;
2336 DECLARE_EVENT_TABLE()
2339 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
2340 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
2343 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
2345 wxDateTime date
= event
.GetDate();
2346 wxVariant value
= date
;
2347 m_model
->SetValue( value
, m_item
, m_col
);
2348 m_model
->ValueChanged( m_item
, m_col
);
2352 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
2354 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
2355 wxDataViewCellMode mode
, int align
) :
2356 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2359 SetAlignment(align
);
2362 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
2364 m_date
= value
.GetDateTime();
2369 bool wxDataViewDateRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2374 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2376 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
2377 wxString tmp
= m_date
.FormatDate();
2378 RenderText( tmp
, 0, cell
, dc
, state
);
2382 wxSize
wxDataViewDateRenderer::GetSize() const
2384 wxString tmp
= m_date
.FormatDate();
2386 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
2387 return wxSize(x
,y
+d
);
2390 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
2391 const wxDataViewItem
&item
, unsigned int col
)
2394 model
->GetValue( variant
, item
, col
);
2395 wxDateTime value
= variant
.GetDateTime();
2397 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
2398 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
2399 wxPoint pos
= wxGetMousePosition();
2402 popup
->Popup( popup
->m_cal
);
2408 // ---------------------------------------------------------
2409 // wxDataViewIconTextRenderer
2410 // ---------------------------------------------------------
2412 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
2414 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer
2416 const wxString
&varianttype
,
2417 wxDataViewCellMode mode
,
2420 : wxDataViewTextRenderer(varianttype
, mode
, align
)
2422 m_rendererIcon
= gtk_cell_renderer_pixbuf_new();
2425 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2429 void wxDataViewIconTextRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
2431 // add the icon renderer first
2432 gtk_tree_view_column_pack_start(column
, m_rendererIcon
, FALSE
/* !expand */);
2434 // add the text renderer too
2435 wxDataViewRenderer::GtkPackIntoColumn(column
);
2438 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
2442 SetTextValue(m_value
.GetText());
2443 SetPixbufProp(m_rendererIcon
, m_value
.GetIcon().GetPixbuf());
2448 bool wxDataViewIconTextRenderer::GetValue(wxVariant
& value
) const
2451 if ( !GetTextValue(str
) )
2454 // user doesn't have any way to edit the icon so leave it unchanged
2455 value
<< wxDataViewIconText(str
, m_value
.GetIcon());
2461 wxDataViewIconTextRenderer::GtkOnCellChanged(const wxVariant
& value
,
2462 const wxDataViewItem
& item
,
2465 // we receive just the text part of our value as it's the only one which
2466 // can be edited, but we need the full wxDataViewIconText value for the
2468 wxVariant valueIconText
;
2469 valueIconText
<< wxDataViewIconText(value
.GetString(), m_value
.GetIcon());
2470 wxDataViewTextRenderer::GtkOnCellChanged(valueIconText
, item
, col
);
2473 // ---------------------------------------------------------
2475 // ---------------------------------------------------------
2479 gtk_dataview_header_button_press_callback( GtkWidget
*WXUNUSED(widget
),
2480 GdkEventButton
*gdk_event
,
2481 wxDataViewColumn
*column
)
2483 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
2486 if (gdk_event
->button
== 1)
2488 gs_lastLeftClickHeader
= column
;
2490 wxDataViewCtrl
*dv
= column
->GetOwner();
2491 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
2492 event
.SetDataViewColumn( column
);
2493 event
.SetModel( dv
->GetModel() );
2494 if (dv
->HandleWindowEvent( event
))
2498 if (gdk_event
->button
== 3)
2500 wxDataViewCtrl
*dv
= column
->GetOwner();
2501 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
2502 event
.SetDataViewColumn( column
);
2503 event
.SetModel( dv
->GetModel() );
2504 if (dv
->HandleWindowEvent( event
))
2514 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*WXUNUSED(column
),
2515 GtkCellRenderer
*renderer
,
2516 GtkTreeModel
*model
,
2520 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2521 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2523 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2525 wxDataViewItem
item( (void*) iter
->user_data
);
2527 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
2529 if (!wx_model
->IsVirtualListModel())
2532 if (wx_model
->IsContainer( item
))
2534 visible
= wx_model
->HasContainerColumns( item
) ||
2535 (cell
->GetOwner()->GetModelColumn() == 0);
2542 GValue gvalue
= { 0, };
2543 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2544 g_value_set_boolean( &gvalue
, visible
);
2545 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2546 g_value_unset( &gvalue
);
2553 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
2555 if (value
.GetType() != cell
->GetVariantType())
2557 wxLogError( wxT("Wrong type, required: %s but: %s"),
2558 value
.GetType().c_str(),
2559 cell
->GetVariantType().c_str() );
2562 cell
->SetValue( value
);
2565 // deal with attributes
2566 wxDataViewItemAttr attr
;
2567 if ( !wx_model
->GetAttr( item
, cell
->GetOwner()->GetModelColumn(), attr
)
2568 && cell
->GtkIsUsingDefaultAttrs() )
2570 // no custom attributes specified and we're already using the default
2571 // ones -- nothing to do
2575 bool usingDefaultAttrs
= true;
2576 if (attr
.HasColour())
2578 const GdkColor
* const gcol
= attr
.GetColour().GetColor();
2580 GValue gvalue
= { 0, };
2581 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2582 g_value_set_boxed( &gvalue
, gcol
);
2583 g_object_set_property( G_OBJECT(renderer
), "foreground_gdk", &gvalue
);
2584 g_value_unset( &gvalue
);
2586 usingDefaultAttrs
= false;
2590 GValue gvalue
= { 0, };
2591 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2592 g_value_set_boolean( &gvalue
, FALSE
);
2593 g_object_set_property( G_OBJECT(renderer
), "foreground-set", &gvalue
);
2594 g_value_unset( &gvalue
);
2597 if (attr
.GetItalic())
2599 GValue gvalue
= { 0, };
2600 g_value_init( &gvalue
, PANGO_TYPE_STYLE
);
2601 g_value_set_enum( &gvalue
, PANGO_STYLE_ITALIC
);
2602 g_object_set_property( G_OBJECT(renderer
), "style", &gvalue
);
2603 g_value_unset( &gvalue
);
2605 usingDefaultAttrs
= false;
2609 GValue gvalue
= { 0, };
2610 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2611 g_value_set_boolean( &gvalue
, FALSE
);
2612 g_object_set_property( G_OBJECT(renderer
), "style-set", &gvalue
);
2613 g_value_unset( &gvalue
);
2619 GValue gvalue
= { 0, };
2620 g_value_init( &gvalue
, PANGO_TYPE_WEIGHT
);
2621 g_value_set_enum( &gvalue
, PANGO_WEIGHT_BOLD
);
2622 g_object_set_property( G_OBJECT(renderer
), "weight", &gvalue
);
2623 g_value_unset( &gvalue
);
2625 usingDefaultAttrs
= false;
2629 GValue gvalue
= { 0, };
2630 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2631 g_value_set_boolean( &gvalue
, FALSE
);
2632 g_object_set_property( G_OBJECT(renderer
), "weight-set", &gvalue
);
2633 g_value_unset( &gvalue
);
2637 if (attr
.HasBackgroundColour())
2639 wxColour colour
= attr
.GetBackgroundColour();
2640 const GdkColor
* const gcol
= colour
.GetColor();
2642 GValue gvalue
= { 0, };
2643 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2644 g_value_set_boxed( &gvalue
, gcol
);
2645 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
2646 g_value_unset( &gvalue
);
2650 GValue gvalue
= { 0, };
2651 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2652 g_value_set_boolean( &gvalue
, FALSE
);
2653 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
2654 g_value_unset( &gvalue
);
2658 cell
->GtkSetUsingDefaultAttrs(usingDefaultAttrs
);
2663 #include <wx/listimpl.cpp>
2664 WX_DEFINE_LIST(wxDataViewColumnList
)
2666 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
2667 unsigned int model_column
, int width
,
2668 wxAlignment align
, int flags
)
2669 : wxDataViewColumnBase( cell
, model_column
)
2671 Init( align
, flags
, width
);
2676 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
2677 unsigned int model_column
, int width
,
2678 wxAlignment align
, int flags
)
2679 : wxDataViewColumnBase( bitmap
, cell
, model_column
)
2681 Init( align
, flags
, width
);
2683 SetBitmap( bitmap
);
2686 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
2688 m_isConnected
= false;
2690 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
2691 m_column
= (GtkWidget
*) column
;
2694 SetAlignment( align
);
2698 // Create container for icon and label
2699 GtkWidget
*box
= gtk_hbox_new( FALSE
, 1 );
2700 gtk_widget_show( box
);
2701 // gtk_container_set_border_width((GtkContainer*)box, 2);
2702 m_image
= gtk_image_new();
2703 gtk_box_pack_start(GTK_BOX(box
), m_image
, FALSE
, FALSE
, 1);
2704 m_label
= gtk_label_new("");
2705 gtk_box_pack_end( GTK_BOX(box
), GTK_WIDGET(m_label
), FALSE
, FALSE
, 1 );
2706 gtk_tree_view_column_set_widget( column
, box
);
2708 wxDataViewRenderer
* const colRenderer
= GetRenderer();
2709 GtkCellRenderer
* const cellRenderer
= colRenderer
->GetGtkHandle();
2711 colRenderer
->GtkPackIntoColumn(column
);
2713 gtk_tree_view_column_set_cell_data_func( column
, cellRenderer
,
2714 wxGtkTreeCellDataFunc
, (gpointer
) colRenderer
, NULL
);
2717 void wxDataViewColumn::OnInternalIdle()
2722 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
2724 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2727 g_signal_connect(column
->button
, "button_press_event",
2728 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
2730 m_isConnected
= true;
2735 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
2737 wxDataViewColumnBase::SetOwner( owner
);
2739 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2741 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
2744 void wxDataViewColumn::SetTitle( const wxString
&title
)
2746 wxDataViewCtrl
*ctrl
= GetOwner();
2747 gtk_label_set_text( GTK_LABEL(m_label
), ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
2748 : wxGTK_CONV_SYS(title
) );
2750 gtk_widget_hide( m_label
);
2752 gtk_widget_show( m_label
);
2755 wxString
wxDataViewColumn::GetTitle() const
2757 return wxGTK_CONV_BACK_FONT(
2758 gtk_label_get_text( GTK_LABEL(m_label
) ),
2759 GetOwner()->GetFont()
2763 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
2765 wxDataViewColumnBase::SetBitmap( bitmap
);
2769 GtkImage
*gtk_image
= GTK_IMAGE(m_image
);
2771 GdkBitmap
*mask
= NULL
;
2772 if (bitmap
.GetMask())
2773 mask
= bitmap
.GetMask()->GetBitmap();
2775 if (bitmap
.HasPixbuf())
2777 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
2778 bitmap
.GetPixbuf());
2782 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
2783 bitmap
.GetPixmap(), mask
);
2785 gtk_widget_show( m_image
);
2789 gtk_widget_hide( m_image
);
2793 void wxDataViewColumn::SetHidden( bool hidden
)
2795 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
2798 void wxDataViewColumn::SetResizeable( bool resizeable
)
2800 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizeable
);
2803 void wxDataViewColumn::SetAlignment( wxAlignment align
)
2805 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2807 gfloat xalign
= 0.0;
2808 if (align
== wxALIGN_RIGHT
)
2810 if (align
== wxALIGN_CENTER_HORIZONTAL
||
2811 align
== wxALIGN_CENTER
)
2814 gtk_tree_view_column_set_alignment( column
, xalign
);
2816 if (m_renderer
&& m_renderer
->GetAlignment() == -1)
2817 m_renderer
->GtkUpdateAlignment();
2820 wxAlignment
wxDataViewColumn::GetAlignment() const
2822 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
2825 return wxALIGN_RIGHT
;
2827 return wxALIGN_CENTER_HORIZONTAL
;
2829 return wxALIGN_LEFT
;
2832 void wxDataViewColumn::SetSortable( bool sortable
)
2834 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2838 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
2842 gtk_tree_view_column_set_sort_column_id( column
, -1 );
2843 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
2844 gtk_tree_view_column_set_clickable( column
, FALSE
);
2848 bool wxDataViewColumn::IsSortable() const
2850 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2851 return gtk_tree_view_column_get_clickable( column
);
2854 void wxDataViewColumn::SetAsSortKey( bool WXUNUSED(sort
) )
2856 // it might not make sense to have this function in wxHeaderColumn at
2857 // all in fact, changing of the sort order should only be done using the
2858 // associated control API
2859 wxFAIL_MSG( "not implemented" );
2862 bool wxDataViewColumn::IsSortKey() const
2864 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2865 return gtk_tree_view_column_get_sort_indicator( column
);
2868 bool wxDataViewColumn::IsResizeable() const
2870 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2871 return gtk_tree_view_column_get_resizable( column
);
2874 bool wxDataViewColumn::IsHidden() const
2876 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2877 return !gtk_tree_view_column_get_visible( column
);
2880 void wxDataViewColumn::SetSortOrder( bool ascending
)
2882 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2885 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
2887 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
2889 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
2892 bool wxDataViewColumn::IsSortOrderAscending() const
2894 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2896 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
2899 void wxDataViewColumn::SetMinWidth( int width
)
2901 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2904 int wxDataViewColumn::GetMinWidth() const
2906 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2909 int wxDataViewColumn::GetWidth() const
2911 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2914 void wxDataViewColumn::SetWidth( int width
)
2919 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
2921 // TODO find a better calculation
2922 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), wxDVC_DEFAULT_WIDTH
);
2924 // this is unpractical for large numbers of items and disables
2925 // user resizing, which is totally unexpected
2926 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
2931 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
2933 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2937 void wxDataViewColumn::SetReorderable( bool reorderable
)
2939 gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column
), reorderable
);
2942 bool wxDataViewColumn::IsReorderable() const
2944 return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column
) );
2947 //-----------------------------------------------------------------------------
2948 // wxGtkTreeModelNode
2949 //-----------------------------------------------------------------------------
2952 class wxGtkTreeModelChildWithPos
2960 int wxGtkTreeModelChildWithPosCmp( const void* data1
, const void* data2
, const void* user_data
)
2962 const wxGtkTreeModelChildWithPos
* child1
= (const wxGtkTreeModelChildWithPos
*) data1
;
2963 const wxGtkTreeModelChildWithPos
* child2
= (const wxGtkTreeModelChildWithPos
*) data2
;
2964 const wxDataViewCtrlInternal
*internal
= (const wxDataViewCtrlInternal
*) user_data
;
2965 int ret
= internal
->GetDataViewModel()->Compare( child1
->id
, child2
->id
,
2966 internal
->GetSortColumn(), (internal
->GetSortOrder() == GTK_SORT_DESCENDING
) );
2972 int LINKAGEMODE
wxGtkTreeModelChildPtrCmp( void*** data1
, void*** data2
)
2974 return gs_internal
->GetDataViewModel()->Compare( **data1
, **data2
,
2975 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
2978 WX_DEFINE_ARRAY_PTR( void**, wxGtkTreeModelChildrenPtr
);
2981 void wxGtkTreeModelNode::Resort()
2983 size_t child_count
= GetChildCount();
2984 if (child_count
== 0)
2987 size_t node_count
= GetNodesCount();
2989 if (child_count
== 1)
2991 if (node_count
== 1)
2993 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
2999 gint
*new_order
= new gint
[child_count
];
3002 // m_children has the original *void
3003 // ptrs points to these
3004 wxGtkTreeModelChildrenPtr ptrs
;
3006 for (i
= 0; i
< child_count
; i
++)
3007 ptrs
.Add( &(m_children
[i
]) );
3009 gs_internal
= m_internal
;
3010 ptrs
.Sort( &wxGtkTreeModelChildPtrCmp
);
3012 wxGtkTreeModelChildren temp
;
3013 void** base_ptr
= &(m_children
[0]);
3014 // Transfer positions to new_order array and
3016 for (i
= 0; i
< child_count
; i
++)
3018 new_order
[i
] = ptrs
[i
] - base_ptr
;
3019 temp
.Add( *ptrs
[i
] );
3022 // Transfer IDs back to m_children
3024 WX_APPEND_ARRAY( temp
, m_children
);
3029 // Build up array with IDs and original positions
3030 wxGtkTreeModelChildWithPos
* temp
= new wxGtkTreeModelChildWithPos
[child_count
];
3032 for (i
= 0; i
< child_count
; i
++)
3035 temp
[i
].id
= m_children
[i
];
3037 // Sort array keeping original positions
3038 wxQsort( temp
, child_count
, sizeof(wxGtkTreeModelChildWithPos
),
3039 &wxGtkTreeModelChildWithPosCmp
, m_internal
);
3040 // Transfer positions to new_order array and
3041 // IDs to m_children
3043 for (i
= 0; i
< child_count
; i
++)
3045 new_order
[i
] = temp
[i
].pos
;
3046 m_children
.Add( temp
[i
].id
);
3055 wxGtkTreeModelChildren temp
;
3056 WX_APPEND_ARRAY( temp
, m_children
);
3058 gs_internal
= m_internal
;
3059 m_children
.Sort( &wxGtkTreeModelChildCmp
);
3062 for (pos
= 0; pos
< child_count
; pos
++)
3064 void *id
= m_children
.Item( pos
);
3065 int old_pos
= temp
.Index( id
);
3066 new_order
[pos
] = old_pos
;
3070 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
3073 iter
.user_data
= GetItem().GetID();
3074 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
3076 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3078 gtk_tree_model_rows_reordered( gtk_tree_model
, path
, &iter
, new_order
);
3080 gtk_tree_path_free (path
);
3082 delete [] new_order
;
3085 for (pos
= 0; pos
< node_count
; pos
++)
3087 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
3092 //-----------------------------------------------------------------------------
3093 // wxDataViewCtrlInternal
3094 //-----------------------------------------------------------------------------
3096 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
,
3097 wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
)
3100 m_wx_model
= wx_model
;
3101 m_gtk_model
= gtk_model
;
3103 m_sort_order
= GTK_SORT_ASCENDING
;
3105 m_dataview_sort_column
= NULL
;
3107 m_dragDataObject
= NULL
;
3108 m_dropDataObject
= NULL
;
3110 if (!m_wx_model
->IsVirtualListModel())
3114 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
3116 g_object_unref( m_gtk_model
);
3118 delete m_dragDataObject
;
3119 delete m_dropDataObject
;
3122 void wxDataViewCtrlInternal::InitTree()
3124 wxDataViewItem item
;
3125 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
3127 BuildBranch( m_root
);
3130 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
3132 if (node
->GetChildCount() == 0)
3134 wxDataViewItemArray children
;
3135 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
3137 for (pos
= 0; pos
< count
; pos
++)
3139 wxDataViewItem child
= children
[pos
];
3141 if (m_wx_model
->IsContainer( child
))
3142 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
3144 node
->AddLeave( child
.GetID() );
3146 // Don't send any events here
3153 bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat
&format
)
3155 wxGtkString
atom_str( gdk_atom_name( format
) );
3156 m_dragSourceTargetEntryTarget
= wxCharBuffer( atom_str
);
3158 m_dragSourceTargetEntry
.target
= m_dragSourceTargetEntryTarget
.data();
3159 m_dragSourceTargetEntry
.flags
= 0;
3160 m_dragSourceTargetEntry
.info
= static_cast<guint
>(-1);
3162 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3163 GDK_BUTTON1_MASK
, &m_dragSourceTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3168 bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat
&format
)
3170 wxGtkString
atom_str( gdk_atom_name( format
) );
3171 m_dropTargetTargetEntryTarget
= wxCharBuffer( atom_str
);
3173 m_dropTargetTargetEntry
.target
= m_dropTargetTargetEntryTarget
.data();
3174 m_dropTargetTargetEntry
.flags
= 0;
3175 m_dropTargetTargetEntry
.info
= static_cast<guint
>(-1);
3177 gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3178 &m_dropTargetTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3183 gboolean
wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource
*WXUNUSED(drag_source
),
3186 delete m_dragDataObject
;
3189 if (!get_iter( &iter
, path
)) return FALSE
;
3190 wxDataViewItem
item( (void*) iter
.user_data
);
3192 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3193 event
.SetEventObject( m_owner
);
3194 event
.SetItem( item
);
3195 event
.SetModel( m_wx_model
);
3196 if (!m_owner
->HandleWindowEvent( event
))
3199 if (!event
.IsAllowed())
3202 wxDataObject
*obj
= event
.GetDataObject();
3206 m_dragDataObject
= obj
;
3212 wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource
*WXUNUSED(drag_source
),
3213 GtkTreePath
*WXUNUSED(path
))
3218 gboolean
wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource
*WXUNUSED(drag_source
),
3219 GtkTreePath
*path
, GtkSelectionData
*selection_data
)
3222 if (!get_iter( &iter
, path
)) return FALSE
;
3223 wxDataViewItem
item( (void*) iter
.user_data
);
3225 if (!m_dragDataObject
->IsSupported( selection_data
->target
))
3228 size_t size
= m_dragDataObject
->GetDataSize( selection_data
->target
);
3232 void *buf
= malloc( size
);
3234 gboolean res
= FALSE
;
3235 if (m_dragDataObject
->GetDataHere( selection_data
->target
, buf
))
3239 gtk_selection_data_set( selection_data
, selection_data
->target
,
3240 8, (const guchar
*) buf
, size
);
3249 wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3251 GtkSelectionData
*selection_data
)
3254 if (!get_iter( &iter
, path
)) return FALSE
;
3255 wxDataViewItem
item( (void*) iter
.user_data
);
3257 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
3258 event
.SetEventObject( m_owner
);
3259 event
.SetItem( item
);
3260 event
.SetModel( m_wx_model
);
3261 event
.SetDataFormat( selection_data
->target
);
3262 event
.SetDataSize( selection_data
->length
);
3263 event
.SetDataBuffer( selection_data
->data
);
3264 if (!m_owner
->HandleWindowEvent( event
))
3267 if (!event
.IsAllowed())
3274 wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3276 GtkSelectionData
*selection_data
)
3279 if (!get_iter( &iter
, path
)) return FALSE
;
3280 wxDataViewItem
item( (void*) iter
.user_data
);
3282 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
3283 event
.SetEventObject( m_owner
);
3284 event
.SetItem( item
);
3285 event
.SetModel( m_wx_model
);
3286 event
.SetDataFormat( selection_data
->target
);
3287 if (!m_owner
->HandleWindowEvent( event
))
3290 if (!event
.IsAllowed())
3296 // notifications from wxDataViewModel
3298 bool wxDataViewCtrlInternal::Cleared()
3300 GtkWidget
* tree_widget
= GetOwner()->GtkGetTreeView();
3301 gtk_tree_view_set_model( GTK_TREE_VIEW(tree_widget
), NULL
);
3302 gtk_tree_view_set_model( GTK_TREE_VIEW(tree_widget
), GTK_TREE_MODEL(m_gtk_model
) );
3313 void wxDataViewCtrlInternal::Resort()
3315 if (!m_wx_model
->IsVirtualListModel())
3319 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3321 if (!m_wx_model
->IsVirtualListModel())
3323 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3324 wxASSERT_MSG(parent_node
,
3325 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3327 if (m_wx_model
->IsContainer( item
))
3328 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
3330 parent_node
->AddLeave( item
.GetID() );
3336 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3338 if (!m_wx_model
->IsVirtualListModel())
3340 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3341 wxASSERT_MSG(parent_node
,
3342 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3344 parent_node
->DeleteChild( item
.GetID() );
3350 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
3352 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3353 event
.SetEventObject( m_owner
);
3354 event
.SetModel( m_owner
->GetModel() );
3355 event
.SetItem( item
);
3356 m_owner
->HandleWindowEvent( event
);
3361 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
3363 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3364 event
.SetEventObject( m_owner
);
3365 event
.SetModel( m_owner
->GetModel() );
3366 event
.SetColumn( col
);
3367 event
.SetDataViewColumn( GetOwner()->GetColumn(col
) );
3368 event
.SetItem( item
);
3369 m_owner
->HandleWindowEvent( event
);
3376 GtkTreeModelFlags
wxDataViewCtrlInternal::get_flags()
3378 if (m_wx_model
->IsVirtualListModel())
3379 return GTK_TREE_MODEL_LIST_ONLY
;
3381 return GTK_TREE_MODEL_ITERS_PERSIST
;
3384 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
3387 if (m_wx_model
->IsVirtualListModel())
3389 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3391 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
3393 if (i
>= wx_model
->GetCount())
3396 iter
->stamp
= m_gtk_model
->stamp
;
3397 // user_data is just the index +1
3398 iter
->user_data
= (gpointer
) (i
+1);
3404 int depth
= gtk_tree_path_get_depth( path
);
3406 wxGtkTreeModelNode
*node
= m_root
;
3409 for (i
= 0; i
< depth
; i
++)
3411 BuildBranch( node
);
3413 gint pos
= gtk_tree_path_get_indices (path
)[i
];
3414 if (pos
< 0) return FALSE
;
3415 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
3417 void* id
= node
->GetChildren().Item( (size_t) pos
);
3421 iter
->stamp
= m_gtk_model
->stamp
;
3422 iter
->user_data
= id
;
3426 size_t count
= node
->GetNodes().GetCount();
3428 for (pos2
= 0; pos2
< count
; pos2
++)
3430 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
3431 if (child_node
->GetItem().GetID() == id
)
3443 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
3445 GtkTreePath
*retval
= gtk_tree_path_new ();
3447 if (m_wx_model
->IsVirtualListModel())
3449 // user_data is just the index +1
3450 int i
= ( (wxUIntPtr
) iter
->user_data
) -1;
3451 gtk_tree_path_append_index (retval
, i
);
3455 void *id
= iter
->user_data
;
3457 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
3460 int pos
= node
->GetChildren().Index( id
);
3462 gtk_tree_path_prepend_index( retval
, pos
);
3464 id
= node
->GetItem().GetID();
3465 node
= node
->GetParent();
3472 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
3474 if (m_wx_model
->IsVirtualListModel())
3476 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3478 // user_data is just the index +1
3479 int n
= ( (wxUIntPtr
) iter
->user_data
) -1;
3483 iter
->user_data
= NULL
;
3487 if (n
>= (int) wx_model
->GetCount()-1)
3489 iter
->user_data
= NULL
;
3493 // user_data is just the index +1 (+2 because we need the next)
3494 iter
->user_data
= (gpointer
) (n
+2);
3498 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
3499 if( parent
== NULL
)
3501 iter
->user_data
= NULL
;
3505 int pos
= parent
->GetChildren().Index( iter
->user_data
);
3507 if (pos
== (int) parent
->GetChildCount()-1)
3509 iter
->user_data
= NULL
;
3513 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
3519 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
3521 if (m_wx_model
->IsVirtualListModel())
3523 // this is a list, nodes have no children
3527 iter
->stamp
= m_gtk_model
->stamp
;
3528 iter
->user_data
= (gpointer
) 1;
3536 if (m_root
->GetChildCount() == 0) return FALSE
;
3537 iter
->stamp
= m_gtk_model
->stamp
;
3538 iter
->user_data
= (gpointer
) m_root
->GetChildren().Item( 0 );
3542 wxDataViewItem
item( (void*) parent
->user_data
);
3544 if (!m_wx_model
->IsContainer( item
))
3547 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3548 wxASSERT_MSG(parent_node
,
3549 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3551 BuildBranch( parent_node
);
3553 if (parent_node
->GetChildCount() == 0)
3556 iter
->stamp
= m_gtk_model
->stamp
;
3557 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
3563 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
3565 if (m_wx_model
->IsVirtualListModel())
3567 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3570 return (wx_model
->GetCount() > 0);
3572 // this is a list, nodes have no children
3578 return (m_root
->GetChildCount() > 0);
3580 wxDataViewItem
item( (void*) iter
->user_data
);
3582 bool is_container
= m_wx_model
->IsContainer( item
);
3587 wxGtkTreeModelNode
*node
= FindNode( iter
);
3589 "Did you forget a call to ItemAdded()? The iterator is unknown to the wxGtkTreeModel");
3591 BuildBranch( node
);
3593 return (node
->GetChildCount() > 0);
3597 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
3599 if (m_wx_model
->IsVirtualListModel())
3601 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3604 return (gint
) wx_model
->GetCount();
3611 return m_root
->GetChildCount();
3613 wxDataViewItem
item( (void*) iter
->user_data
);
3615 if (!m_wx_model
->IsContainer( item
))
3618 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
3619 wxASSERT_MSG(parent_node
,
3620 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3622 BuildBranch( parent_node
);
3624 return parent_node
->GetChildCount();
3628 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
3630 if (m_wx_model
->IsVirtualListModel())
3632 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3640 if (n
>= (gint
) wx_model
->GetCount())
3643 iter
->stamp
= m_gtk_model
->stamp
;
3644 // user_data is just the index +1
3645 iter
->user_data
= (gpointer
) (n
+1);
3652 if (parent
) id
= (void*) parent
->user_data
;
3653 wxDataViewItem
item( id
);
3655 if (!m_wx_model
->IsContainer( item
))
3658 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3659 wxASSERT_MSG(parent_node
,
3660 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3662 BuildBranch( parent_node
);
3664 iter
->stamp
= m_gtk_model
->stamp
;
3665 iter
->user_data
= parent_node
->GetChildren().Item( n
);
3671 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
3673 if (m_wx_model
->IsVirtualListModel())
3679 wxGtkTreeModelNode
*node
= FindParentNode( child
);
3683 iter
->stamp
= m_gtk_model
->stamp
;
3684 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
3690 static wxGtkTreeModelNode
*
3691 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3697 list
.DeleteContents( true );
3698 wxDataViewItem
it( item
);
3702 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3703 list
.Insert( pItem
);
3704 it
= model
->GetParent( it
);
3707 wxGtkTreeModelNode
* node
= treeNode
;
3708 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3710 if( node
&& node
->GetNodes().GetCount() != 0 )
3712 int len
= node
->GetNodes().GetCount();
3713 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3715 for( ; j
< len
; j
++)
3717 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3736 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
3741 wxDataViewItem
item( (void*) iter
->user_data
);
3745 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3750 wxLogDebug( "Not found %p", iter->user_data );
3754 // TODO: remove this code
3760 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
3765 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3770 wxLogDebug( "Not found %p", item.GetID() );
3774 // TODO: remove this code
3780 static wxGtkTreeModelNode
*
3781 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3787 list
.DeleteContents( true );
3791 wxDataViewItem
it( model
->GetParent( item
) );
3794 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3795 list
.Insert( pItem
);
3796 it
= model
->GetParent( it
);
3799 wxGtkTreeModelNode
* node
= treeNode
;
3800 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3802 if( node
&& node
->GetNodes().GetCount() != 0 )
3804 int len
= node
->GetNodes().GetCount();
3805 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3807 for( ; j
< len
; j
++)
3809 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3824 //Examine whether the node is item's parent node
3825 int len
= node
->GetChildCount();
3826 for( int i
= 0; i
< len
; i
++ )
3828 if( node
->GetChildren().Item( i
) == item
.GetID() )
3834 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
3839 wxDataViewItem
item( (void*) iter
->user_data
);
3843 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3846 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
3851 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3854 //-----------------------------------------------------------------------------
3855 // wxDataViewCtrl signal callbacks
3856 //-----------------------------------------------------------------------------
3859 wxdataview_selection_changed_callback( GtkTreeSelection
* WXUNUSED(selection
), wxDataViewCtrl
*dv
)
3861 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
3864 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
3865 event
.SetItem( dv
->GetSelection() );
3866 event
.SetModel( dv
->GetModel() );
3867 dv
->HandleWindowEvent( event
);
3871 wxdataview_row_activated_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreePath
*path
,
3872 GtkTreeViewColumn
*WXUNUSED(column
), wxDataViewCtrl
*dv
)
3874 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
3877 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3878 wxDataViewItem
item( (void*) iter
.user_data
);;
3879 event
.SetItem( item
);
3880 event
.SetModel( dv
->GetModel() );
3881 dv
->HandleWindowEvent( event
);
3885 wxdataview_test_expand_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3886 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3888 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
3890 wxDataViewItem
item( (void*) iter
->user_data
);;
3891 event
.SetItem( item
);
3892 event
.SetModel( dv
->GetModel() );
3893 dv
->HandleWindowEvent( event
);
3895 return !event
.IsAllowed();
3899 wxdataview_row_expanded_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3900 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3902 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
3904 wxDataViewItem
item( (void*) iter
->user_data
);;
3905 event
.SetItem( item
);
3906 event
.SetModel( dv
->GetModel() );
3907 dv
->HandleWindowEvent( event
);
3911 wxdataview_test_collapse_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3912 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3914 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
3916 wxDataViewItem
item( (void*) iter
->user_data
);;
3917 event
.SetItem( item
);
3918 event
.SetModel( dv
->GetModel() );
3919 dv
->HandleWindowEvent( event
);
3921 return !event
.IsAllowed();
3925 wxdataview_row_collapsed_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3926 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3928 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
3930 wxDataViewItem
item( (void*) iter
->user_data
);;
3931 event
.SetItem( item
);
3932 event
.SetModel( dv
->GetModel() );
3933 dv
->HandleWindowEvent( event
);
3936 //-----------------------------------------------------------------------------
3938 //-----------------------------------------------------------------------------
3940 void wxDataViewCtrl::AddChildGTK(wxWindowGTK
* child
)
3942 GtkWidget
* treeview
= GtkGetTreeView();
3944 // Insert widget in GtkTreeView
3945 if (GTK_WIDGET_REALIZED(treeview
))
3946 gtk_widget_set_parent_window( child
->m_widget
,
3947 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
3948 gtk_widget_set_parent( child
->m_widget
, treeview
);
3952 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
3953 GtkAllocation
*WXUNUSED(gtk_alloc
),
3954 wxDataViewCtrl
*win
)
3956 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
3959 wxWindow
*child
= node
->GetData();
3962 gtk_widget_size_request( child
->m_widget
, &req
);
3964 GtkAllocation alloc
;
3965 alloc
.x
= child
->m_x
;
3966 alloc
.y
= child
->m_y
;
3967 alloc
.width
= child
->m_width
;
3968 alloc
.height
= child
->m_height
;
3969 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
3971 node
= node
->GetNext();
3976 //-----------------------------------------------------------------------------
3977 // "motion_notify_event"
3978 //-----------------------------------------------------------------------------
3981 gtk_dataview_motion_notify_callback( GtkWidget
*WXUNUSED(widget
),
3982 GdkEventMotion
*gdk_event
,
3983 wxDataViewCtrl
*dv
)
3985 if (gdk_event
->is_hint
)
3989 GdkModifierType state
;
3990 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
3995 GtkTreePath
*path
= NULL
;
3996 GtkTreeViewColumn
*column
= NULL
;
3999 if (gtk_tree_view_get_path_at_pos(
4000 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4001 (int) gdk_event
->x
, (int) gdk_event
->y
,
4010 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4012 gtk_tree_path_free( path
);
4020 //-----------------------------------------------------------------------------
4021 // "button_press_event"
4022 //-----------------------------------------------------------------------------
4025 gtk_dataview_button_press_callback( GtkWidget
*WXUNUSED(widget
),
4026 GdkEventButton
*gdk_event
,
4027 wxDataViewCtrl
*dv
)
4029 if ((gdk_event
->button
== 3) && (gdk_event
->type
== GDK_BUTTON_PRESS
))
4031 GtkTreePath
*path
= NULL
;
4032 GtkTreeViewColumn
*column
= NULL
;
4035 if (gtk_tree_view_get_path_at_pos(
4036 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4037 (int) gdk_event
->x
, (int) gdk_event
->y
,
4046 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4048 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, dv
->GetId() );
4049 wxDataViewItem
item( (void*) iter
.user_data
);;
4050 event
.SetItem( item
);
4051 event
.SetModel( dv
->GetModel() );
4052 bool ret
= dv
->HandleWindowEvent( event
);
4053 gtk_tree_path_free( path
);
4062 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
4064 wxDataViewCtrl::~wxDataViewCtrl()
4067 GetModel()->RemoveNotifier( m_notifier
);
4071 // remove the model from the GtkTreeView before it gets destroyed by the
4072 // wxDataViewCtrlBase's dtor
4073 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), NULL
);
4078 void wxDataViewCtrl::Init()
4083 m_cols
.DeleteContents( true );
4086 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
4087 const wxPoint
& pos
, const wxSize
& size
,
4088 long style
, const wxValidator
& validator
)
4092 if (!PreCreation( parent
, pos
, size
) ||
4093 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
4095 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
4099 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
4100 g_object_ref(m_widget
);
4102 GTKScrolledWindowSetBorder(m_widget
, style
);
4104 m_treeview
= gtk_tree_view_new();
4105 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
4107 g_signal_connect (m_treeview
, "size_allocate",
4108 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
4111 if (!gtk_check_version(2,6,0))
4113 bool fixed
= (style
& wxDV_VARIABLE_LINE_HEIGHT
) == 0;
4114 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4118 if (style
& wxDV_MULTIPLE
)
4120 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4121 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
4124 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
4127 if (!gtk_check_version(2,10,0))
4129 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
4131 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
4132 (style
& wxDV_VERT_RULES
) != 0)
4133 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
4134 else if (style
& wxDV_VERT_RULES
)
4135 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
4136 else if (style
& wxDV_HORIZ_RULES
)
4137 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
4139 if (grid
!= GTK_TREE_VIEW_GRID_LINES_NONE
)
4140 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
4144 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_ROW_LINES
) != 0 );
4146 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
4147 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
4148 gtk_widget_show (m_treeview
);
4150 m_parent
->DoAddChild( this );
4154 GtkEnableSelectionEvents();
4156 g_signal_connect_after (m_treeview
, "row-activated",
4157 G_CALLBACK (wxdataview_row_activated_callback
), this);
4159 g_signal_connect (m_treeview
, "test-collapse-row",
4160 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
4162 g_signal_connect_after (m_treeview
, "row-collapsed",
4163 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
4165 g_signal_connect (m_treeview
, "test-expand-row",
4166 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
4168 g_signal_connect_after (m_treeview
, "row-expanded",
4169 G_CALLBACK (wxdataview_row_expanded_callback
), this);
4171 g_signal_connect (m_treeview
, "motion_notify_event",
4172 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
4174 g_signal_connect (m_treeview
, "button_press_event",
4175 G_CALLBACK (gtk_dataview_button_press_callback
), this);
4180 void wxDataViewCtrl::OnInternalIdle()
4182 wxWindow::OnInternalIdle();
4184 unsigned int cols
= GetColumnCount();
4186 for (i
= 0; i
< cols
; i
++)
4188 wxDataViewColumn
*col
= GetColumn( i
);
4189 col
->OnInternalIdle();
4193 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4204 if (!wxDataViewCtrlBase::AssociateModel( model
))
4208 if (!gtk_check_version(2,6,0))
4210 bool fixed
= (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
) == 0) || (model
->IsVirtualListModel()));
4211 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4215 GtkWxTreeModel
*gtk_model
= wxgtk_tree_model_new();
4216 m_internal
= new wxDataViewCtrlInternal( this, model
, gtk_model
);
4217 gtk_model
->internal
= m_internal
;
4219 m_notifier
= new wxGtkDataViewModelNotifier( gtk_model
, model
, this );
4221 model
->AddNotifier( m_notifier
);
4223 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_model
) );
4225 // unref in wxDataViewCtrlInternal
4226 // g_object_unref( gtk_model );
4231 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4233 return m_internal
->EnableDragSource( format
);
4236 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4238 return m_internal
->EnableDropTarget( format
);
4241 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4243 if (!wxDataViewCtrlBase::AppendColumn(col
))
4246 m_cols
.Append( col
);
4249 if (!gtk_check_version(2,6,0))
4251 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4252 GTK_TREE_VIEW_COLUMN_FIXED
)
4253 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4257 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
4258 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4263 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4265 if (!wxDataViewCtrlBase::PrependColumn(col
))
4268 m_cols
.Insert( col
);
4271 if (!gtk_check_version(2,6,0))
4273 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4274 GTK_TREE_VIEW_COLUMN_FIXED
)
4275 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4279 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4280 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
4285 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4287 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4290 m_cols
.Insert( pos
, col
);
4293 if (!gtk_check_version(2,6,0))
4295 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4296 GTK_TREE_VIEW_COLUMN_FIXED
)
4297 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4301 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4302 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), pos
);
4307 unsigned int wxDataViewCtrl::GetColumnCount() const
4309 return m_cols
.GetCount();
4312 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
4314 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
4318 wxDataViewColumnList::const_iterator iter
;
4319 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4321 wxDataViewColumn
*col
= *iter
;
4322 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
4331 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4333 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4334 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
4336 m_cols
.DeleteObject( column
);
4341 bool wxDataViewCtrl::ClearColumns()
4343 wxDataViewColumnList::iterator iter
;
4344 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4346 wxDataViewColumn
*col
= *iter
;
4347 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4348 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4356 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4358 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetConstGtkHandle());
4360 GList
*list
= gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview
) );
4362 gint pos
= g_list_index( list
, (gconstpointer
) gtk_column
);
4364 g_list_free( list
);
4369 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4371 return m_internal
->GetDataViewSortColumn();
4374 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4377 iter
.user_data
= item
.GetID();
4378 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4379 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
4380 gtk_tree_path_free( path
);
4383 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4386 iter
.user_data
= item
.GetID();
4387 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4388 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
4389 gtk_tree_path_free( path
);
4392 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4395 iter
.user_data
= item
.GetID();
4396 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4397 bool res
= gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview
), path
);
4398 gtk_tree_path_free( path
);
4403 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4405 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4407 if (m_windowStyle
& wxDV_MULTIPLE
)
4409 // Report the first one
4410 GtkTreeModel
*model
;
4411 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4415 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4417 m_internal
->get_iter( &iter
, path
);
4420 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4421 g_list_free( list
);
4423 return wxDataViewItem( (void*) iter
.user_data
);
4429 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
4431 wxDataViewItem
item( (void*) iter
.user_data
);
4436 return wxDataViewItem(0);
4439 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4443 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4444 if (HasFlag(wxDV_MULTIPLE
))
4446 GtkTreeModel
*model
;
4447 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4452 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4455 m_internal
->get_iter( &iter
, path
);
4457 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4459 list
= g_list_next( list
);
4464 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4465 g_list_free( list
);
4471 GtkTreeModel
*model
;
4473 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
4476 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4484 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4486 GtkDisableSelectionEvents();
4488 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4490 gtk_tree_selection_unselect_all( selection
);
4492 wxDataViewItem last_parent
;
4495 for (i
= 0; i
< sel
.GetCount(); i
++)
4497 wxDataViewItem item
= sel
[i
];
4498 wxDataViewItem parent
= GetModel()->GetParent( item
);
4501 if (parent
!= last_parent
)
4502 ExpandAncestors(item
);
4504 last_parent
= parent
;
4507 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4508 iter
.user_data
= (gpointer
) item
.GetID();
4509 gtk_tree_selection_select_iter( selection
, &iter
);
4512 GtkEnableSelectionEvents();
4515 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4517 ExpandAncestors(item
);
4519 GtkDisableSelectionEvents();
4521 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4524 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4525 iter
.user_data
= (gpointer
) item
.GetID();
4526 gtk_tree_selection_select_iter( selection
, &iter
);
4528 GtkEnableSelectionEvents();
4531 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4533 GtkDisableSelectionEvents();
4535 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4538 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4539 iter
.user_data
= (gpointer
) item
.GetID();
4540 gtk_tree_selection_unselect_iter( selection
, &iter
);
4542 GtkEnableSelectionEvents();
4545 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4547 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4550 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4551 iter
.user_data
= (gpointer
) item
.GetID();
4553 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
4556 void wxDataViewCtrl::SelectAll()
4558 GtkDisableSelectionEvents();
4560 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4562 gtk_tree_selection_select_all( selection
);
4564 GtkEnableSelectionEvents();
4567 void wxDataViewCtrl::UnselectAll()
4569 GtkDisableSelectionEvents();
4571 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4573 gtk_tree_selection_unselect_all( selection
);
4575 GtkEnableSelectionEvents();
4578 void wxDataViewCtrl::EnsureVisible(const wxDataViewItem
& item
,
4579 const wxDataViewColumn
*WXUNUSED(column
))
4581 ExpandAncestors(item
);
4584 iter
.user_data
= (gpointer
) item
.GetID();
4585 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4586 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
4587 gtk_tree_path_free( path
);
4590 void wxDataViewCtrl::HitTest(const wxPoint
& WXUNUSED(point
),
4591 wxDataViewItem
& item
,
4592 wxDataViewColumn
*& column
) const
4594 item
= wxDataViewItem(0);
4599 wxDataViewCtrl::GetItemRect(const wxDataViewItem
& WXUNUSED(item
),
4600 const wxDataViewColumn
*WXUNUSED(column
)) const
4605 void wxDataViewCtrl::DoSetExpanderColumn()
4607 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
4608 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
4611 void wxDataViewCtrl::DoSetIndent()
4615 void wxDataViewCtrl::GtkDisableSelectionEvents()
4617 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4618 g_signal_handlers_disconnect_by_func( selection
,
4619 (gpointer
) (wxdataview_selection_changed_callback
), this);
4622 void wxDataViewCtrl::GtkEnableSelectionEvents()
4624 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4625 g_signal_connect_after (selection
, "changed",
4626 G_CALLBACK (wxdataview_selection_changed_callback
), this);
4629 // ----------------------------------------------------------------------------
4630 // visual attributes stuff
4631 // ----------------------------------------------------------------------------
4635 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
4637 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
4640 void wxDataViewCtrl::DoApplyWidgetStyle(GtkRcStyle
*style
)
4642 wxDataViewCtrlBase::DoApplyWidgetStyle(style
);
4643 gtk_widget_modify_style(m_treeview
, style
);
4646 #endif // !wxUSE_GENERICDATAVIEWCTRL
4648 #endif // wxUSE_DATAVIEWCTRL