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( _T("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( _T("non-string columns not supported yet") );
599 wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
602 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
604 //if (wxtree_model->stamp != iter->stamp)
605 // wxPrintf( "crash\n" );
606 // TODO: remove this code
608 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
609 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
611 return wxtree_model
->internal
->iter_next( iter
);
615 wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
619 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
620 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
621 g_return_val_if_fail (wxtree_model
->stamp
== parent
->stamp
, FALSE
);
623 return wxtree_model
->internal
->iter_children( iter
, parent
);
627 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
630 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
631 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
632 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
634 return wxtree_model
->internal
->iter_has_child( iter
);
638 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
641 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
642 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
645 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, 0);
647 return wxtree_model
->internal
->iter_n_children( iter
);
651 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
656 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
657 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
659 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
663 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
667 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
668 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
669 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
671 return wxtree_model
->internal
->iter_parent( iter
, child
);
674 /* drag'n'drop iface */
676 wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
679 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
680 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
682 return wxtree_model
->internal
->row_draggable( drag_source
, path
);
686 wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
689 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
690 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
692 return wxtree_model
->internal
->drag_data_delete( drag_source
, path
);
696 wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
698 GtkSelectionData
*selection_data
)
700 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
701 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
704 wxPrintf( "drag_get_data\n");
706 wxGtkString
atom_selection(gdk_atom_name(selection_data
->selection
));
707 wxPrintf( "selection %s\n", wxString::FromAscii(atom_selection
) );
709 wxGtkString
atom_target(gdk_atom_name(selection_data
->target
));
710 wxPrintf( "target %s\n", wxString::FromAscii(atom_target
) );
712 wxGtkString
atom_type(gdk_atom_name(selection_data
->type
));
713 wxPrintf( "type %s\n", wxString::FromAscii(atom_type
) );
715 wxPrintf( "format %d\n", selection_data
->format
);
718 return wxtree_model
->internal
->drag_data_get( drag_source
, path
, selection_data
);
722 wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
724 GtkSelectionData
*selection_data
)
726 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
727 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
729 return wxtree_model
->internal
->drag_data_received( drag_dest
, dest
, selection_data
);
733 wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
734 GtkTreePath
*dest_path
,
735 GtkSelectionData
*selection_data
)
737 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
738 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
740 return wxtree_model
->internal
->row_drop_possible( drag_dest
, dest_path
, selection_data
);
745 wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
746 gint
*sort_column_id
,
749 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) sortable
;
751 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
753 if (!wxtree_model
->internal
->IsSorted())
756 *sort_column_id
= -1;
763 *sort_column_id
= wxtree_model
->internal
->GetSortColumn();
766 *order
= wxtree_model
->internal
->GetSortOrder();
771 wxDataViewColumn
*gs_lastLeftClickHeader
= NULL
;
774 wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
778 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
779 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
781 tree_model
->internal
->SetDataViewSortColumn( gs_lastLeftClickHeader
);
783 if ((sort_column_id
!= (gint
) tree_model
->internal
->GetSortColumn()) ||
784 (order
!= tree_model
->internal
->GetSortOrder()))
786 tree_model
->internal
->SetSortColumn( sort_column_id
);
787 tree_model
->internal
->SetSortOrder( order
);
789 gtk_tree_sortable_sort_column_changed (sortable
);
791 tree_model
->internal
->GetDataViewModel()->Resort();
794 if (gs_lastLeftClickHeader
)
796 wxDataViewCtrl
*dv
= tree_model
->internal
->GetOwner();
797 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, dv
->GetId() );
798 event
.SetDataViewColumn( gs_lastLeftClickHeader
);
799 event
.SetModel( dv
->GetModel() );
800 dv
->HandleWindowEvent( event
);
803 gs_lastLeftClickHeader
= NULL
;
807 wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
808 gint
WXUNUSED(sort_column_id
),
809 GtkTreeIterCompareFunc func
,
810 gpointer
WXUNUSED(data
),
811 GtkDestroyNotify
WXUNUSED(destroy
))
813 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
814 g_return_if_fail (func
!= NULL
);
818 wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
819 GtkTreeIterCompareFunc func
,
820 gpointer
WXUNUSED(data
),
821 GtkDestroyNotify
WXUNUSED(destroy
))
823 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
824 g_return_if_fail (func
!= NULL
);
826 //wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
827 // TODO: remove this code
831 wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
)
833 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
838 //-----------------------------------------------------------------------------
839 // define new GTK+ class GtkWxRendererText
840 //-----------------------------------------------------------------------------
844 #define GTK_TYPE_WX_CELL_RENDERER_TEXT (gtk_wx_cell_renderer_text_get_type ())
845 #define GTK_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererText))
846 #define GTK_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
847 #define GTK_IS_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT))
848 #define GTK_IS_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT))
849 #define GTK_WX_CELL_RENDERER_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
851 GType
gtk_wx_cell_renderer_text_get_type (void);
853 typedef struct _GtkWxCellRendererText GtkWxCellRendererText
;
854 typedef struct _GtkWxCellRendererTextClass GtkWxCellRendererTextClass
;
856 struct _GtkWxCellRendererText
858 GtkCellRendererText parent
;
860 wxDataViewRenderer
*wx_renderer
;
863 struct _GtkWxCellRendererTextClass
865 GtkCellRendererTextClass cell_parent_class
;
869 static GtkWxCellRendererText
*gtk_wx_cell_renderer_text_new (void);
870 static void gtk_wx_cell_renderer_text_init (
871 GtkWxCellRendererText
*cell
);
872 static void gtk_wx_cell_renderer_text_class_init(
873 GtkWxCellRendererTextClass
*klass
);
874 static void gtk_wx_cell_renderer_text_finalize (
876 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
877 GtkCellRenderer
*cell
,
881 GdkRectangle
*background_area
,
882 GdkRectangle
*cell_area
,
883 GtkCellRendererState flags
);
886 static GObjectClass
*text_cell_parent_class
= NULL
;
891 gtk_wx_cell_renderer_text_get_type (void)
893 static GType cell_wx_type
= 0;
897 const GTypeInfo cell_wx_info
=
899 sizeof (GtkWxCellRendererTextClass
),
900 NULL
, /* base_init */
901 NULL
, /* base_finalize */
902 (GClassInitFunc
) gtk_wx_cell_renderer_text_class_init
,
903 NULL
, /* class_finalize */
904 NULL
, /* class_data */
905 sizeof (GtkWxCellRendererText
),
907 (GInstanceInitFunc
) gtk_wx_cell_renderer_text_init
,
910 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER_TEXT
,
911 "GtkWxCellRendererText", &cell_wx_info
, (GTypeFlags
)0 );
918 gtk_wx_cell_renderer_text_init (GtkWxCellRendererText
*cell
)
920 cell
->wx_renderer
= NULL
;
924 gtk_wx_cell_renderer_text_class_init (GtkWxCellRendererTextClass
*klass
)
926 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
927 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
929 text_cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
931 object_class
->finalize
= gtk_wx_cell_renderer_text_finalize
;
933 cell_class
->start_editing
= gtk_wx_cell_renderer_text_start_editing
;
937 gtk_wx_cell_renderer_text_finalize (GObject
*object
)
940 (* G_OBJECT_CLASS (text_cell_parent_class
)->finalize
) (object
);
943 GtkWxCellRendererText
*
944 gtk_wx_cell_renderer_text_new (void)
946 return (GtkWxCellRendererText
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER_TEXT
, NULL
);
949 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
950 GtkCellRenderer
*gtk_renderer
,
954 GdkRectangle
*background_area
,
955 GdkRectangle
*cell_area
,
956 GtkCellRendererState flags
)
958 GtkWxCellRendererText
*wxgtk_renderer
= (GtkWxCellRendererText
*) gtk_renderer
;
959 wxDataViewRenderer
*wx_renderer
= wxgtk_renderer
->wx_renderer
;
961 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
963 wx_renderer
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
964 wxDataViewItem
item( (void*) iter
.user_data
);;
965 gtk_tree_path_free( treepath
);
967 wxDataViewColumn
*column
= wx_renderer
->GetOwner();
968 wxDataViewCtrl
*dv
= column
->GetOwner();
969 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, dv
->GetId() );
970 event
.SetDataViewColumn( column
);
971 event
.SetModel( dv
->GetModel() );
972 event
.SetColumn( wx_renderer
->GetOwner()->GetModelColumn() );
973 event
.SetItem( item
);
974 dv
->HandleWindowEvent( event
);
976 if (event
.IsAllowed())
977 return GTK_CELL_RENDERER_CLASS(text_cell_parent_class
)->
978 start_editing( gtk_renderer
, gdk_event
, widget
, path
, background_area
, cell_area
, flags
);
983 //-----------------------------------------------------------------------------
984 // define new GTK+ class GtkWxCellRenderer
985 //-----------------------------------------------------------------------------
989 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
990 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
991 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
992 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
993 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
994 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
996 GType
gtk_wx_cell_renderer_get_type (void);
998 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
999 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
1001 struct _GtkWxCellRenderer
1003 GtkCellRenderer parent
;
1006 wxDataViewCustomRenderer
*cell
;
1010 struct _GtkWxCellRendererClass
1012 GtkCellRendererClass cell_parent_class
;
1016 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
1017 static void gtk_wx_cell_renderer_init (
1018 GtkWxCellRenderer
*cell
);
1019 static void gtk_wx_cell_renderer_class_init(
1020 GtkWxCellRendererClass
*klass
);
1021 static void gtk_wx_cell_renderer_finalize (
1023 static void gtk_wx_cell_renderer_get_size (
1024 GtkCellRenderer
*cell
,
1026 GdkRectangle
*rectangle
,
1031 static void gtk_wx_cell_renderer_render (
1032 GtkCellRenderer
*cell
,
1035 GdkRectangle
*background_area
,
1036 GdkRectangle
*cell_area
,
1037 GdkRectangle
*expose_area
,
1038 GtkCellRendererState flags
);
1039 static gboolean
gtk_wx_cell_renderer_activate(
1040 GtkCellRenderer
*cell
,
1044 GdkRectangle
*background_area
,
1045 GdkRectangle
*cell_area
,
1046 GtkCellRendererState flags
);
1047 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1048 GtkCellRenderer
*cell
,
1052 GdkRectangle
*background_area
,
1053 GdkRectangle
*cell_area
,
1054 GtkCellRendererState flags
);
1057 static GObjectClass
*cell_parent_class
= NULL
;
1062 gtk_wx_cell_renderer_get_type (void)
1064 static GType cell_wx_type
= 0;
1068 const GTypeInfo cell_wx_info
=
1070 sizeof (GtkWxCellRendererClass
),
1071 NULL
, /* base_init */
1072 NULL
, /* base_finalize */
1073 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
1074 NULL
, /* class_finalize */
1075 NULL
, /* class_data */
1076 sizeof (GtkWxCellRenderer
),
1077 0, /* n_preallocs */
1078 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
1081 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
1082 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
1085 return cell_wx_type
;
1089 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
1092 cell
->last_click
= 0;
1096 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
1098 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1099 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
1101 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
1103 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
1105 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
1106 cell_class
->render
= gtk_wx_cell_renderer_render
;
1107 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
1108 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
1112 gtk_wx_cell_renderer_finalize (GObject
*object
)
1115 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
1119 gtk_wx_cell_renderer_new (void)
1121 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
1124 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1125 GtkCellRenderer
*renderer
,
1126 GdkEvent
*WXUNUSED(event
),
1129 GdkRectangle
*WXUNUSED(background_area
),
1130 GdkRectangle
*cell_area
,
1131 GtkCellRendererState
WXUNUSED(flags
) )
1133 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1134 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1136 // Renderer doesn't support in-place editing
1137 if (!cell
->HasEditorCtrl())
1140 // An in-place editing control is still around
1141 if (cell
->GetEditorCtrl())
1145 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1151 rect
.x
+= cell_area
->x
;
1152 rect
.y
+= cell_area
->y
;
1153 // rect.width -= renderer->xpad * 2;
1154 // rect.height -= renderer->ypad * 2;
1156 // wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
1157 wxRect
renderrect( cell_area
->x
, cell_area
->y
, cell_area
->width
, cell_area
->height
);
1159 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
1161 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
1162 wxDataViewItem
item( (void*) iter
.user_data
);
1163 gtk_tree_path_free( treepath
);
1165 cell
->StartEditing( item
, renderrect
);
1171 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
1172 GtkWidget
*WXUNUSED(widget
),
1173 GdkRectangle
*cell_area
,
1179 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1180 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1182 wxSize size
= cell
->GetSize();
1184 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
1185 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
1192 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
1196 *x_offset
= (gint
)((renderer
->xalign
*
1197 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
1198 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
1202 *y_offset
= (gint
)((renderer
->yalign
*
1203 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
1204 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
1209 *width
= calc_width
;
1212 *height
= calc_height
;
1216 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
1219 GdkRectangle
*background_area
,
1220 GdkRectangle
*cell_area
,
1221 GdkRectangle
*expose_area
,
1222 GtkCellRendererState flags
)
1225 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1226 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1228 cell
->window
= window
;
1229 cell
->widget
= widget
;
1230 cell
->background_area
= (void*) background_area
;
1231 cell
->cell_area
= (void*) cell_area
;
1232 cell
->expose_area
= (void*) expose_area
;
1233 cell
->flags
= (int) flags
;
1236 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1242 rect
.x
+= cell_area
->x
;
1243 rect
.y
+= cell_area
->y
;
1244 rect
.width
-= renderer
->xpad
* 2;
1245 rect
.height
-= renderer
->ypad
* 2;
1248 if (gdk_rectangle_intersect (expose_area
, &rect
, &dummy
))
1250 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1251 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
1252 wxWindowDCImpl
*impl
= (wxWindowDCImpl
*) dc
->GetImpl();
1254 // Reinitialize wxWindowDC's GDK window if drawing occurs into a different
1255 // window such as a DnD drop window.
1256 if (window
!= impl
->m_gdkwindow
)
1259 impl
->m_gdkwindow
= window
;
1264 if (flags
& GTK_CELL_RENDERER_SELECTED
)
1265 state
|= wxDATAVIEW_CELL_SELECTED
;
1266 if (flags
& GTK_CELL_RENDERER_PRELIT
)
1267 state
|= wxDATAVIEW_CELL_PRELIT
;
1268 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1269 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1270 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1271 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1272 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
1273 state
|= wxDATAVIEW_CELL_FOCUSED
;
1274 cell
->Render( renderrect
, dc
, state
);
1279 gtk_wx_cell_renderer_activate(
1280 GtkCellRenderer
*renderer
,
1284 GdkRectangle
*WXUNUSED(background_area
),
1285 GdkRectangle
*cell_area
,
1286 GtkCellRendererState
WXUNUSED(flags
) )
1288 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1289 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1292 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1298 rect
.x
+= cell_area
->x
;
1299 rect
.y
+= cell_area
->y
;
1300 rect
.width
-= renderer
->xpad
* 2;
1301 rect
.height
-= renderer
->ypad
* 2;
1303 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1305 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1307 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
1310 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
1311 wxDataViewItem
item( iter
.user_data
);
1312 gtk_tree_path_free( treepath
);
1314 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1320 // activated by <ENTER>
1321 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1326 else if (event
->type
== GDK_BUTTON_PRESS
)
1328 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
1329 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
1330 ((int) button_event
->y
) - renderrect
.y
);
1333 if (button_event
->button
== 1)
1335 if (cell
->LeftClick( pt
, renderrect
, model
, item
, model_col
))
1337 // TODO: query system double-click time
1338 if (button_event
->time
- wxrenderer
->last_click
< 400)
1339 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1342 wxrenderer
->last_click
= button_event
->time
;
1350 // ---------------------------------------------------------
1351 // wxGtkDataViewModelNotifier
1352 // ---------------------------------------------------------
1354 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1357 wxGtkDataViewModelNotifier( GtkWxTreeModel
*wxgtk_model
,
1358 wxDataViewModel
*wx_model
,
1359 wxDataViewCtrl
*ctrl
);
1360 ~wxGtkDataViewModelNotifier();
1362 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1363 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1364 virtual bool ItemChanged( const wxDataViewItem
&item
);
1365 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
1366 virtual bool Cleared();
1367 virtual void Resort();
1369 void SetGtkModel( GtkWxTreeModel
*model
) { m_wxgtk_model
= model
; }
1372 GtkWxTreeModel
*m_wxgtk_model
;
1373 wxDataViewModel
*m_wx_model
;
1374 wxDataViewCtrl
*m_owner
;
1377 // ---------------------------------------------------------
1378 // wxGtkDataViewListModelNotifier
1379 // ---------------------------------------------------------
1381 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1382 GtkWxTreeModel
* wxgtk_model
, wxDataViewModel
*wx_model
,
1383 wxDataViewCtrl
*ctrl
)
1385 m_wxgtk_model
= wxgtk_model
;
1386 m_wx_model
= wx_model
;
1390 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1393 m_wxgtk_model
= NULL
;
1396 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1398 m_owner
->GtkGetInternal()->ItemAdded( parent
, item
);
1401 iter
.stamp
= m_wxgtk_model
->stamp
;
1402 iter
.user_data
= (gpointer
) item
.GetID();
1404 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1405 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1406 gtk_tree_model_row_inserted(
1407 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1408 gtk_tree_path_free (path
);
1413 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1416 iter
.stamp
= m_wxgtk_model
->stamp
;
1417 iter
.user_data
= (gpointer
) item
.GetID();
1419 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1420 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1421 gtk_tree_model_row_deleted(
1422 GTK_TREE_MODEL(m_wxgtk_model
), path
);
1423 gtk_tree_path_free (path
);
1425 m_owner
->GtkGetInternal()->ItemDeleted( parent
, item
);
1430 void wxGtkDataViewModelNotifier::Resort()
1432 m_owner
->GtkGetInternal()->Resort();
1435 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1438 iter
.stamp
= m_wxgtk_model
->stamp
;
1439 iter
.user_data
= (gpointer
) item
.GetID();
1441 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1442 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1443 gtk_tree_model_row_changed(
1444 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1445 gtk_tree_path_free (path
);
1447 m_owner
->GtkGetInternal()->ItemChanged( item
);
1452 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_col
)
1454 // This adds GTK+'s missing MVC logic for ValueChanged
1456 for (index
= 0; index
< m_owner
->GetColumnCount(); index
++)
1458 wxDataViewColumn
*column
= m_owner
->GetColumn( index
);
1459 if (column
->GetModelColumn() == model_col
)
1461 GtkTreeView
*widget
= GTK_TREE_VIEW(m_owner
->m_treeview
);
1462 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1466 iter
.stamp
= m_wxgtk_model
->stamp
;
1467 iter
.user_data
= (gpointer
) item
.GetID();
1468 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1469 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1470 GdkRectangle cell_area
;
1471 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1472 gtk_tree_path_free( path
);
1474 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1475 double d
= gtk_adjustment_get_value( hadjust
);
1476 int xdiff
= (int) d
;
1478 int ydiff
= gcolumn
->button
->allocation
.height
;
1480 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1481 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1483 m_owner
->GtkGetInternal()->ValueChanged( item
, model_col
);
1492 bool wxGtkDataViewModelNotifier::Cleared()
1494 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->m_treeview
), NULL
);
1496 // this will create a new GTK model
1497 m_owner
->GtkGetInternal()->Cleared();
1499 SetGtkModel( m_owner
->GtkGetInternal()->GetGtkModel() );
1501 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->m_treeview
), GTK_TREE_MODEL(m_wxgtk_model
) );
1506 // ---------------------------------------------------------
1507 // wxDataViewRenderer
1508 // ---------------------------------------------------------
1510 static gpointer s_user_data
= NULL
;
1513 wxgtk_cell_editable_editing_done( GtkCellEditable
*WXUNUSED(editable
),
1514 wxDataViewRenderer
*wxrenderer
)
1516 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1517 wxDataViewCtrl
*dv
= column
->GetOwner();
1518 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1519 event
.SetDataViewColumn( column
);
1520 event
.SetModel( dv
->GetModel() );
1521 wxDataViewItem
item( s_user_data
);
1522 event
.SetItem( item
);
1523 dv
->HandleWindowEvent( event
);
1527 wxgtk_renderer_editing_started( GtkCellRenderer
*WXUNUSED(cell
), GtkCellEditable
*editable
,
1528 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1533 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1534 wxDataViewCtrl
*dv
= column
->GetOwner();
1535 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1536 event
.SetDataViewColumn( column
);
1537 event
.SetModel( dv
->GetModel() );
1538 GtkTreePath
*tree_path
= gtk_tree_path_new_from_string( path
);
1540 dv
->GtkGetInternal()->get_iter( &iter
, tree_path
);
1541 gtk_tree_path_free( tree_path
);
1542 wxDataViewItem
item( iter
.user_data
);
1543 event
.SetItem( item
);
1544 dv
->HandleWindowEvent( event
);
1546 if (GTK_IS_CELL_EDITABLE(editable
))
1548 s_user_data
= iter
.user_data
;
1550 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1551 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1552 (gpointer
) wxrenderer
);
1558 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1560 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1562 wxDataViewRendererBase( varianttype
, mode
, align
)
1566 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1567 // after the m_renderer pointer has been initialized
1570 void wxDataViewRenderer::GtkInitHandlers()
1572 if (!gtk_check_version(2,6,0))
1574 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1575 G_CALLBACK (wxgtk_renderer_editing_started
),
1580 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1582 GtkCellRendererMode gtkMode
;
1585 case wxDATAVIEW_CELL_INERT
:
1586 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1589 case wxDATAVIEW_CELL_ACTIVATABLE
:
1590 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1593 case wxDATAVIEW_CELL_EDITABLE
:
1594 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1598 wxFAIL_MSG( "unknown wxDataViewCellMode value" );
1602 // This value is most often ignored in GtkTreeView
1603 GValue gvalue
= { 0, };
1604 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1605 g_value_set_enum( &gvalue
, gtkMode
);
1606 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1607 g_value_unset( &gvalue
);
1610 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1612 wxDataViewCellMode ret
;
1615 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1617 switch (g_value_get_enum(&gvalue
))
1620 wxFAIL_MSG( "unknown GtkCellRendererMode value" );
1621 // fall through (we have to return something)
1623 case GTK_CELL_RENDERER_MODE_INERT
:
1624 ret
= wxDATAVIEW_CELL_INERT
;
1627 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1628 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1631 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1632 ret
= wxDATAVIEW_CELL_EDITABLE
;
1636 g_value_unset( &gvalue
);
1641 void wxDataViewRenderer::GtkUpdateAlignment()
1643 int align
= m_alignment
;
1645 // query alignment from column ?
1649 if (GetOwner() == NULL
)
1652 align
= GetOwner()->GetAlignment();
1653 align
|= wxALIGN_CENTRE_VERTICAL
;
1656 // horizontal alignment:
1658 gfloat xalign
= 0.0;
1659 if (align
& wxALIGN_RIGHT
)
1661 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1664 GValue gvalue
= { 0, };
1665 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1666 g_value_set_float( &gvalue
, xalign
);
1667 g_object_set_property( G_OBJECT(m_renderer
), "xalign", &gvalue
);
1668 g_value_unset( &gvalue
);
1670 // vertical alignment:
1672 gfloat yalign
= 0.0;
1673 if (align
& wxALIGN_BOTTOM
)
1675 else if (align
& wxALIGN_CENTER_VERTICAL
)
1678 GValue gvalue2
= { 0, };
1679 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1680 g_value_set_float( &gvalue2
, yalign
);
1681 g_object_set_property( G_OBJECT(m_renderer
), "yalign", &gvalue2
);
1682 g_value_unset( &gvalue2
);
1685 void wxDataViewRenderer::SetAlignment( int align
)
1687 m_alignment
= align
;
1688 GtkUpdateAlignment();
1691 int wxDataViewRenderer::GetAlignment() const
1696 // ---------------------------------------------------------
1697 // wxDataViewTextRenderer
1698 // ---------------------------------------------------------
1701 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1702 gchar
*arg1
, gchar
*arg2
, gpointer user_data
);
1705 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*WXUNUSED(renderer
),
1706 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1708 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) user_data
;
1710 wxString tmp
= wxGTK_CONV_BACK_FONT(arg2
, cell
->GetOwner()->GetOwner()->GetFont());
1711 wxVariant value
= tmp
;
1712 if (!cell
->Validate( value
))
1715 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1717 GtkTreePath
*path
= gtk_tree_path_new_from_string( arg1
);
1719 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, path
);
1720 wxDataViewItem
item( (void*) iter
.user_data
);;
1721 gtk_tree_path_free( path
);
1723 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1725 model
->SetValue( value
, item
, model_col
);
1726 model
->ValueChanged( item
, model_col
);
1729 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
1731 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1733 wxDataViewRenderer( varianttype
, mode
, align
)
1735 GtkWxCellRendererText
*text_renderer
= gtk_wx_cell_renderer_text_new();
1736 text_renderer
->wx_renderer
= this;
1737 m_renderer
= (GtkCellRenderer
*) text_renderer
;
1739 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
1741 GValue gvalue
= { 0, };
1742 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1743 g_value_set_boolean( &gvalue
, true );
1744 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
1745 g_value_unset( &gvalue
);
1747 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
1753 SetAlignment(align
);
1756 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
1758 wxString tmp
= value
;
1760 GValue gvalue
= { 0, };
1761 g_value_init( &gvalue
, G_TYPE_STRING
);
1762 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( tmp
, GetOwner()->GetOwner()->GetFont() ) );
1763 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1764 g_value_unset( &gvalue
);
1769 bool wxDataViewTextRenderer::GetValue( wxVariant
&value
) const
1771 GValue gvalue
= { 0, };
1772 g_value_init( &gvalue
, G_TYPE_STRING
);
1773 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1774 wxString tmp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
), const_cast<wxDataViewTextRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
1775 g_value_unset( &gvalue
);
1782 void wxDataViewTextRenderer::SetAlignment( int align
)
1784 wxDataViewRenderer::SetAlignment(align
);
1786 if (gtk_check_version(2,10,0))
1789 // horizontal alignment:
1790 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
1791 if (align
& wxALIGN_RIGHT
)
1792 pangoAlign
= PANGO_ALIGN_RIGHT
;
1793 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1794 pangoAlign
= PANGO_ALIGN_CENTER
;
1796 GValue gvalue
= { 0, };
1797 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1798 g_value_set_enum( &gvalue
, pangoAlign
);
1799 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
1800 g_value_unset( &gvalue
);
1803 // ---------------------------------------------------------
1804 // wxDataViewTextRendererAttr
1805 // ---------------------------------------------------------
1807 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
,wxDataViewTextRenderer
)
1809 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString
&varianttype
,
1810 wxDataViewCellMode mode
, int align
) :
1811 wxDataViewTextRenderer( varianttype
, mode
, align
)
1815 // ---------------------------------------------------------
1816 // wxDataViewBitmapRenderer
1817 // ---------------------------------------------------------
1819 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
1821 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1823 wxDataViewRenderer( varianttype
, mode
, align
)
1825 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_pixbuf_new();
1828 SetAlignment(align
);
1831 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
1833 if (value
.GetType() == wxT("wxBitmap"))
1838 // This may create a Pixbuf representation in the
1839 // wxBitmap object (and it will stay there)
1840 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1842 GValue gvalue
= { 0, };
1843 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1844 g_value_set_object( &gvalue
, pixbuf
);
1845 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1846 g_value_unset( &gvalue
);
1851 if (value
.GetType() == wxT("wxIcon"))
1856 // This may create a Pixbuf representation in the
1857 // wxBitmap object (and it will stay there)
1858 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1860 GValue gvalue
= { 0, };
1861 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1862 g_value_set_object( &gvalue
, pixbuf
);
1863 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1864 g_value_unset( &gvalue
);
1872 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
1877 // ---------------------------------------------------------
1878 // wxDataViewToggleRenderer
1879 // ---------------------------------------------------------
1882 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1883 gchar
*path
, gpointer user_data
);
1886 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1887 gchar
*path
, gpointer user_data
)
1889 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
1892 GValue gvalue
= { 0, };
1893 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1894 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
1895 bool tmp
= g_value_get_boolean( &gvalue
);
1896 g_value_unset( &gvalue
);
1900 wxVariant value
= tmp
;
1901 if (!cell
->Validate( value
))
1904 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1906 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
1908 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, gtk_path
);
1909 wxDataViewItem
item( (void*) iter
.user_data
);;
1910 gtk_tree_path_free( gtk_path
);
1912 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1914 model
->SetValue( value
, item
, model_col
);
1915 model
->ValueChanged( item
, model_col
);
1918 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1920 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1921 wxDataViewCellMode mode
, int align
) :
1922 wxDataViewRenderer( varianttype
, mode
, align
)
1924 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
1926 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1928 g_signal_connect_after( m_renderer
, "toggled",
1929 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
1933 GValue gvalue
= { 0, };
1934 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1935 g_value_set_boolean( &gvalue
, false );
1936 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
1937 g_value_unset( &gvalue
);
1941 SetAlignment(align
);
1944 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1948 GValue gvalue
= { 0, };
1949 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1950 g_value_set_boolean( &gvalue
, tmp
);
1951 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1952 g_value_unset( &gvalue
);
1957 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
1959 GValue gvalue
= { 0, };
1960 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1961 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1962 bool tmp
= g_value_get_boolean( &gvalue
);
1963 g_value_unset( &gvalue
);
1970 // ---------------------------------------------------------
1971 // wxDataViewCustomRenderer
1972 // ---------------------------------------------------------
1974 class wxDataViewCtrlDCImpl
: public wxWindowDCImpl
1977 wxDataViewCtrlDCImpl( wxDC
*owner
, wxDataViewCtrl
*window
) :
1978 wxWindowDCImpl( owner
)
1980 GtkWidget
*widget
= window
->m_treeview
;
1986 m_context
= window
->GTKGetPangoDefaultContext();
1987 m_layout
= pango_layout_new( m_context
);
1988 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
1990 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
1992 // Set m_gdkwindow later
1997 class wxDataViewCtrlDC
: public wxWindowDC
2000 wxDataViewCtrlDC( wxDataViewCtrl
*window
) :
2001 wxWindowDC( new wxDataViewCtrlDCImpl( this, window
) )
2006 // ---------------------------------------------------------
2007 // wxDataViewCustomRenderer
2008 // ---------------------------------------------------------
2010 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
2012 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
2013 wxDataViewCellMode mode
, int align
,
2015 wxDataViewRenderer( varianttype
, mode
, align
)
2018 m_text_renderer
= NULL
;
2026 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
,
2027 wxRect
WXUNUSED(cell
), wxDC
*WXUNUSED(dc
), int WXUNUSED(state
) )
2030 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
2031 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
2032 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
2033 view
->GetForegroundColour();
2034 dc
->SetTextForeground(col
);
2035 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
2037 if (!m_text_renderer
)
2038 m_text_renderer
= gtk_cell_renderer_text_new();
2040 GValue gvalue
= { 0, };
2041 g_value_init( &gvalue
, G_TYPE_STRING
);
2042 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( text
, GetOwner()->GetOwner()->GetFont() ) );
2043 g_object_set_property( G_OBJECT(m_text_renderer
), "text", &gvalue
);
2044 g_value_unset( &gvalue
);
2046 ((GdkRectangle
*) cell_area
)->x
+= xoffset
;
2047 ((GdkRectangle
*) cell_area
)->width
-= xoffset
;
2049 gtk_cell_renderer_render( m_text_renderer
,
2052 (GdkRectangle
*) background_area
,
2053 (GdkRectangle
*) cell_area
,
2054 (GdkRectangle
*) expose_area
,
2055 (GtkCellRendererState
) flags
);
2057 ((GdkRectangle
*) cell_area
)->x
-= xoffset
;
2058 ((GdkRectangle
*) cell_area
)->width
+= xoffset
;
2062 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
2064 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
2065 renderer
->cell
= this;
2067 m_renderer
= (GtkCellRenderer
*) renderer
;
2070 SetAlignment(align
);
2077 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
2082 if (m_text_renderer
)
2083 gtk_object_sink( GTK_OBJECT(m_text_renderer
) );
2086 wxDC
*wxDataViewCustomRenderer::GetDC()
2090 if (GetOwner() == NULL
)
2092 if (GetOwner()->GetOwner() == NULL
)
2094 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
2100 // ---------------------------------------------------------
2101 // wxDataViewProgressRenderer
2102 // ---------------------------------------------------------
2104 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
2106 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
2107 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
2108 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
2114 if (!gtk_check_version(2,6,0))
2116 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
2118 GValue gvalue
= { 0, };
2119 g_value_init( &gvalue
, G_TYPE_STRING
);
2121 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( m_label
, GetOwner()->GetOwner()->GetFont() ) );
2122 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2123 g_value_unset( &gvalue
);
2126 SetAlignment(align
);
2131 // Use custom cell code
2132 wxDataViewCustomRenderer::Init(mode
, align
);
2136 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
2140 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
2143 if (!gtk_check_version(2,6,0))
2145 gint tmp
= (long) value
;
2146 GValue gvalue
= { 0, };
2147 g_value_init( &gvalue
, G_TYPE_INT
);
2148 g_value_set_int( &gvalue
, tmp
);
2149 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
2150 g_value_unset( &gvalue
);
2155 m_value
= (long) value
;
2157 if (m_value
< 0) m_value
= 0;
2158 if (m_value
> 100) m_value
= 100;
2164 bool wxDataViewProgressRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2169 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
2171 double pct
= (double)m_value
/ 100.0;
2173 bar
.width
= (int)(cell
.width
* pct
);
2174 dc
->SetPen( *wxTRANSPARENT_PEN
);
2175 dc
->SetBrush( *wxBLUE_BRUSH
);
2176 dc
->DrawRectangle( bar
);
2178 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
2179 dc
->SetPen( *wxBLACK_PEN
);
2180 dc
->DrawRectangle( cell
);
2185 wxSize
wxDataViewProgressRenderer::GetSize() const
2187 return wxSize(40,12);
2190 // -------------------------------------
2191 // wxDataViewChoiceRenderer
2192 // -------------------------------------
2194 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
&choices
,
2195 wxDataViewCellMode mode
, int alignment
) :
2196 wxDataViewCustomRenderer( "string", mode
, alignment
, true )
2198 m_choices
= choices
;
2201 if (!gtk_check_version(2,6,0))
2203 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_combo_new();
2205 GtkListStore
*store
= gtk_list_store_new( 1, G_TYPE_STRING
);
2206 for (size_t n
= 0; n
< m_choices
.GetCount(); n
++)
2208 gtk_list_store_insert_with_values(
2210 static_cast<const char *>(m_choices
[n
].utf8_str()), -1 );
2213 g_object_set (m_renderer
,
2219 bool editable
= (mode
& wxDATAVIEW_CELL_EDITABLE
);
2220 g_object_set (m_renderer
, "editable", editable
, NULL
);
2222 SetAlignment(alignment
);
2224 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2231 // Use custom cell code
2232 wxDataViewCustomRenderer::Init(mode
, alignment
);
2236 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
2238 RenderText( m_data
, 0, rect
, dc
, state
);
2242 wxSize
wxDataViewChoiceRenderer::GetSize() const
2244 return wxSize(70,20);
2247 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
2251 if (!gtk_check_version(2,6,0))
2253 GValue gvalue
= { 0, };
2254 g_value_init( &gvalue
, G_TYPE_STRING
);
2255 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( value
.GetString(), GetOwner()->GetOwner()->GetFont() ) );
2256 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2257 g_value_unset( &gvalue
);
2261 m_data
= value
.GetString();
2266 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
2269 if (!gtk_check_version(2,6,0))
2271 GValue gvalue
= { 0, };
2272 g_value_init( &gvalue
, G_TYPE_STRING
);
2273 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2274 wxString temp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
),
2275 const_cast<wxDataViewChoiceRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
2276 g_value_unset( &gvalue
);
2279 //wxPrintf( "temp %s\n", temp );
2280 // TODO: remove this code
2289 void wxDataViewChoiceRenderer::SetAlignment( int align
)
2291 wxDataViewCustomRenderer::SetAlignment(align
);
2293 if (gtk_check_version(2,10,0))
2296 // horizontal alignment:
2297 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2298 if (align
& wxALIGN_RIGHT
)
2299 pangoAlign
= PANGO_ALIGN_RIGHT
;
2300 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2301 pangoAlign
= PANGO_ALIGN_CENTER
;
2303 GValue gvalue
= { 0, };
2304 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2305 g_value_set_enum( &gvalue
, pangoAlign
);
2306 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2307 g_value_unset( &gvalue
);
2310 // ---------------------------------------------------------
2311 // wxDataViewDateRenderer
2312 // ---------------------------------------------------------
2314 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
2317 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
2318 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
2319 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
2324 m_cal
= new wxCalendarCtrl( this, -1, *value
);
2325 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
2326 sizer
->Add( m_cal
, 1, wxGROW
);
2331 virtual void OnDismiss()
2335 void OnCalendar( wxCalendarEvent
&event
);
2337 wxCalendarCtrl
*m_cal
;
2338 wxDataViewModel
*m_model
;
2339 wxDataViewItem m_item
;
2343 DECLARE_EVENT_TABLE()
2346 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
2347 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
2350 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
2352 wxDateTime date
= event
.GetDate();
2353 wxVariant value
= date
;
2354 m_model
->SetValue( value
, m_item
, m_col
);
2355 m_model
->ValueChanged( m_item
, m_col
);
2359 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
2361 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
2362 wxDataViewCellMode mode
, int align
) :
2363 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2366 SetAlignment(align
);
2369 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
2371 m_date
= value
.GetDateTime();
2376 bool wxDataViewDateRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2381 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2383 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
2384 wxString tmp
= m_date
.FormatDate();
2385 RenderText( tmp
, 0, cell
, dc
, state
);
2389 wxSize
wxDataViewDateRenderer::GetSize() const
2391 wxString tmp
= m_date
.FormatDate();
2393 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
2394 return wxSize(x
,y
+d
);
2397 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
2398 const wxDataViewItem
&item
, unsigned int col
)
2401 model
->GetValue( variant
, item
, col
);
2402 wxDateTime value
= variant
.GetDateTime();
2404 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
2405 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
2406 wxPoint pos
= wxGetMousePosition();
2409 popup
->Popup( popup
->m_cal
);
2415 // ---------------------------------------------------------
2416 // wxDataViewIconTextRenderer
2417 // ---------------------------------------------------------
2419 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
2421 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
2422 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
2423 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2426 SetAlignment(align
);
2429 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2433 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
2439 bool wxDataViewIconTextRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2444 bool wxDataViewIconTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2446 const wxIcon
&icon
= m_value
.GetIcon();
2450 int yoffset
= wxMax( 0, (cell
.height
- icon
.GetHeight()) / 2 );
2451 dc
->DrawIcon( icon
, cell
.x
, cell
.y
+ yoffset
);
2452 offset
= icon
.GetWidth() + 4;
2455 RenderText( m_value
.GetText(), offset
, cell
, dc
, state
);
2460 wxSize
wxDataViewIconTextRenderer::GetSize() const
2463 if (m_value
.GetIcon().IsOk())
2464 size
.x
= 4 + m_value
.GetIcon().GetWidth();
2466 GetView()->GetTextExtent( m_value
.GetText(), &x
, &y
, &d
);
2472 wxControl
* wxDataViewIconTextRenderer::CreateEditorCtrl(
2473 wxWindow
*WXUNUSED(parent
), wxRect
WXUNUSED(labelRect
), const wxVariant
&WXUNUSED(value
) )
2478 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl(
2479 wxControl
* WXUNUSED(editor
), wxVariant
&WXUNUSED(value
) )
2484 // ---------------------------------------------------------
2486 // ---------------------------------------------------------
2490 gtk_dataview_header_button_press_callback( GtkWidget
*WXUNUSED(widget
),
2491 GdkEventButton
*gdk_event
,
2492 wxDataViewColumn
*column
)
2494 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
2497 if (gdk_event
->button
== 1)
2499 gs_lastLeftClickHeader
= column
;
2501 wxDataViewCtrl
*dv
= column
->GetOwner();
2502 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
2503 event
.SetDataViewColumn( column
);
2504 event
.SetModel( dv
->GetModel() );
2505 if (dv
->HandleWindowEvent( event
))
2509 if (gdk_event
->button
== 3)
2511 wxDataViewCtrl
*dv
= column
->GetOwner();
2512 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
2513 event
.SetDataViewColumn( column
);
2514 event
.SetModel( dv
->GetModel() );
2515 if (dv
->HandleWindowEvent( event
))
2523 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
2524 GtkCellRenderer
*cell
,
2525 GtkTreeModel
*model
,
2531 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*WXUNUSED(column
),
2532 GtkCellRenderer
*renderer
,
2533 GtkTreeModel
*model
,
2537 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2538 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2540 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2542 wxDataViewItem
item( (void*) iter
->user_data
);
2544 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
2546 if (!wx_model
->IsVirtualListModel())
2549 if (wx_model
->IsContainer( item
))
2551 if (wx_model
->HasContainerColumns( item
) || (cell
->GetOwner()->GetModelColumn() == 0))
2553 GValue gvalue
= { 0, };
2554 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2555 g_value_set_boolean( &gvalue
, TRUE
);
2556 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2557 g_value_unset( &gvalue
);
2561 GValue gvalue
= { 0, };
2562 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2563 g_value_set_boolean( &gvalue
, FALSE
);
2564 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2565 g_value_unset( &gvalue
);
2572 GValue gvalue
= { 0, };
2573 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2574 g_value_set_boolean( &gvalue
, TRUE
);
2575 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2576 g_value_unset( &gvalue
);
2582 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
2584 if (value
.GetType() != cell
->GetVariantType())
2585 wxLogError( wxT("Wrong type, required: %s but: %s"),
2586 value
.GetType().c_str(),
2587 cell
->GetVariantType().c_str() );
2589 cell
->SetValue( value
);
2591 if (cell
->GtkHasAttributes())
2593 wxDataViewItemAttr attr
;
2594 bool colour_set
= false;
2595 bool style_set
= false;
2596 bool weight_set
= false;
2598 if (wx_model
->GetAttr( item
, cell
->GetOwner()->GetModelColumn(), attr
))
2600 // this must be a GtkCellRendererText
2601 wxColour colour
= attr
.GetColour();
2604 const GdkColor
* const gcol
= colour
.GetColor();
2606 GValue gvalue
= { 0, };
2607 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2608 g_value_set_boxed( &gvalue
, gcol
);
2609 g_object_set_property( G_OBJECT(renderer
), "foreground_gdk", &gvalue
);
2610 g_value_unset( &gvalue
);
2615 if (attr
.GetItalic())
2617 GValue gvalue
= { 0, };
2618 g_value_init( &gvalue
, PANGO_TYPE_STYLE
);
2619 g_value_set_enum( &gvalue
, PANGO_STYLE_ITALIC
);
2620 g_object_set_property( G_OBJECT(renderer
), "style", &gvalue
);
2621 g_value_unset( &gvalue
);
2628 GValue gvalue
= { 0, };
2629 g_value_init( &gvalue
, PANGO_TYPE_WEIGHT
);
2630 g_value_set_enum( &gvalue
, PANGO_WEIGHT_BOLD
);
2631 g_object_set_property( G_OBJECT(renderer
), "weight", &gvalue
);
2632 g_value_unset( &gvalue
);
2640 GValue gvalue
= { 0, };
2641 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2642 g_value_set_boolean( &gvalue
, FALSE
);
2643 g_object_set_property( G_OBJECT(renderer
), "style-set", &gvalue
);
2644 g_value_unset( &gvalue
);
2649 GValue gvalue
= { 0, };
2650 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2651 g_value_set_boolean( &gvalue
, FALSE
);
2652 g_object_set_property( G_OBJECT(renderer
), "weight-set", &gvalue
);
2653 g_value_unset( &gvalue
);
2658 GValue gvalue
= { 0, };
2659 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2660 g_value_set_boolean( &gvalue
, FALSE
);
2661 g_object_set_property( G_OBJECT(renderer
), "foreground-set", &gvalue
);
2662 g_value_unset( &gvalue
);
2667 if (attr
.HasBackgroundColour())
2669 wxColour colour
= attr
.GetBackgroundColour();
2670 const GdkColor
* const gcol
= colour
.GetColor();
2672 GValue gvalue
= { 0, };
2673 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2674 g_value_set_boxed( &gvalue
, gcol
);
2675 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
2676 g_value_unset( &gvalue
);
2680 GValue gvalue
= { 0, };
2681 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2682 g_value_set_boolean( &gvalue
, FALSE
);
2683 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
2684 g_value_unset( &gvalue
);
2690 #include <wx/listimpl.cpp>
2691 WX_DEFINE_LIST(wxDataViewColumnList
)
2693 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
2694 unsigned int model_column
, int width
,
2695 wxAlignment align
, int flags
)
2696 : wxDataViewColumnBase( cell
, model_column
)
2698 Init( align
, flags
, width
);
2703 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
2704 unsigned int model_column
, int width
,
2705 wxAlignment align
, int flags
)
2706 : wxDataViewColumnBase( bitmap
, cell
, model_column
)
2708 Init( align
, flags
, width
);
2710 SetBitmap( bitmap
);
2713 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
2715 m_isConnected
= false;
2717 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) GetRenderer()->GetGtkHandle();
2718 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
2719 m_column
= (GtkWidget
*) column
;
2722 SetAlignment( align
);
2726 // Create container for icon and label
2727 GtkWidget
*box
= gtk_hbox_new( FALSE
, 1 );
2728 gtk_widget_show( box
);
2729 // gtk_container_set_border_width((GtkContainer*)box, 2);
2730 m_image
= gtk_image_new();
2731 gtk_box_pack_start(GTK_BOX(box
), m_image
, FALSE
, FALSE
, 1);
2732 m_label
= gtk_label_new("");
2733 gtk_box_pack_end( GTK_BOX(box
), GTK_WIDGET(m_label
), FALSE
, FALSE
, 1 );
2734 gtk_tree_view_column_set_widget( column
, box
);
2736 gtk_tree_view_column_pack_end( column
, renderer
, TRUE
);
2738 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
2739 wxGtkTreeCellDataFunc
, (gpointer
) GetRenderer(), NULL
);
2742 void wxDataViewColumn::OnInternalIdle()
2747 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
2749 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2752 g_signal_connect(column
->button
, "button_press_event",
2753 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
2755 m_isConnected
= true;
2760 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
2762 wxDataViewColumnBase::SetOwner( owner
);
2764 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2766 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
2769 void wxDataViewColumn::SetTitle( const wxString
&title
)
2771 wxDataViewCtrl
*ctrl
= GetOwner();
2772 gtk_label_set_text( GTK_LABEL(m_label
), ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
2773 : wxGTK_CONV_SYS(title
) );
2775 gtk_widget_hide( m_label
);
2777 gtk_widget_show( m_label
);
2780 wxString
wxDataViewColumn::GetTitle() const
2782 return wxGTK_CONV_BACK_FONT(
2783 gtk_label_get_text( GTK_LABEL(m_label
) ),
2784 GetOwner()->GetFont()
2788 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
2790 wxDataViewColumnBase::SetBitmap( bitmap
);
2794 GtkImage
*gtk_image
= GTK_IMAGE(m_image
);
2796 GdkBitmap
*mask
= NULL
;
2797 if (bitmap
.GetMask())
2798 mask
= bitmap
.GetMask()->GetBitmap();
2800 if (bitmap
.HasPixbuf())
2802 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
2803 bitmap
.GetPixbuf());
2807 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
2808 bitmap
.GetPixmap(), mask
);
2810 gtk_widget_show( m_image
);
2814 gtk_widget_hide( m_image
);
2818 void wxDataViewColumn::SetHidden( bool hidden
)
2820 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
2823 void wxDataViewColumn::SetResizeable( bool resizeable
)
2825 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizeable
);
2828 void wxDataViewColumn::SetAlignment( wxAlignment align
)
2830 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2832 gfloat xalign
= 0.0;
2833 if (align
== wxALIGN_RIGHT
)
2835 if (align
== wxALIGN_CENTER_HORIZONTAL
||
2836 align
== wxALIGN_CENTER
)
2839 gtk_tree_view_column_set_alignment( column
, xalign
);
2841 if (m_renderer
&& m_renderer
->GetAlignment() == -1)
2842 m_renderer
->GtkUpdateAlignment();
2845 wxAlignment
wxDataViewColumn::GetAlignment() const
2847 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
2850 return wxALIGN_RIGHT
;
2852 return wxALIGN_CENTER_HORIZONTAL
;
2854 return wxALIGN_LEFT
;
2857 void wxDataViewColumn::SetSortable( bool sortable
)
2859 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2863 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
2867 gtk_tree_view_column_set_sort_column_id( column
, -1 );
2868 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
2869 gtk_tree_view_column_set_clickable( column
, FALSE
);
2873 bool wxDataViewColumn::IsSortable() const
2875 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2876 return gtk_tree_view_column_get_clickable( column
);
2879 void wxDataViewColumn::SetAsSortKey( bool WXUNUSED(sort
) )
2881 // it might not make sense to have this function in wxHeaderColumn at
2882 // all in fact, changing of the sort order should only be done using the
2883 // associated control API
2884 wxFAIL_MSG( "not implemented" );
2887 bool wxDataViewColumn::IsSortKey() const
2889 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2890 return gtk_tree_view_column_get_sort_indicator( column
);
2893 bool wxDataViewColumn::IsResizeable() const
2895 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2896 return gtk_tree_view_column_get_resizable( column
);
2899 bool wxDataViewColumn::IsHidden() const
2901 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2902 return !gtk_tree_view_column_get_visible( column
);
2905 void wxDataViewColumn::SetSortOrder( bool ascending
)
2907 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2910 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
2912 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
2914 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
2917 bool wxDataViewColumn::IsSortOrderAscending() const
2919 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2921 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
2924 void wxDataViewColumn::SetMinWidth( int width
)
2926 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2929 int wxDataViewColumn::GetMinWidth() const
2931 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2934 int wxDataViewColumn::GetWidth() const
2936 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2939 void wxDataViewColumn::SetWidth( int width
)
2944 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
2946 // TODO find a better calculation
2947 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), wxDVC_DEFAULT_WIDTH
);
2949 // this is unpractical for large numbers of items and disables
2950 // user resizing, which is totally unexpected
2951 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
2956 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
2958 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2962 void wxDataViewColumn::SetReorderable( bool reorderable
)
2964 gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column
), reorderable
);
2967 bool wxDataViewColumn::IsReorderable() const
2969 return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column
) );
2972 //-----------------------------------------------------------------------------
2973 // wxGtkTreeModelNode
2974 //-----------------------------------------------------------------------------
2976 class wxGtkTreeModelChildWithPos
2984 int wxGtkTreeModelChildWithPosCmp( const void* data1
, const void* data2
, const void* user_data
)
2986 const wxGtkTreeModelChildWithPos
* child1
= (const wxGtkTreeModelChildWithPos
*) data1
;
2987 const wxGtkTreeModelChildWithPos
* child2
= (const wxGtkTreeModelChildWithPos
*) data2
;
2988 const wxDataViewCtrlInternal
*internal
= (const wxDataViewCtrlInternal
*) user_data
;
2989 int ret
= internal
->GetDataViewModel()->Compare( child1
->id
, child2
->id
,
2990 internal
->GetSortColumn(), (internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
2995 void wxGtkTreeModelNode::Resort()
2997 size_t child_count
= GetChildCount();
2998 if (child_count
== 0)
3001 size_t node_count
= GetNodesCount();
3003 if (child_count
== 1)
3005 if (node_count
== 1)
3007 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
3014 // Build up array with IDs and original positions
3015 wxGtkTreeModelChildWithPos
* temp
= new wxGtkTreeModelChildWithPos
[child_count
];
3017 for (i
= 0; i
< child_count
; i
++)
3020 temp
[i
].id
= m_children
[i
];
3022 // Sort array keeping original positions
3023 wxQsort( temp
, child_count
, sizeof(wxGtkTreeModelChildWithPos
),
3024 &wxGtkTreeModelChildWithPosCmp
, m_internal
);
3025 // Transfer positions to new_order array and
3026 // IDs to m_children
3028 gint
*new_order
= new gint
[child_count
];
3029 for (i
= 0; i
< child_count
; i
++)
3031 new_order
[i
] = temp
[i
].pos
;
3032 m_children
.Add( temp
[i
].id
);
3037 wxGtkTreeModelChildren temp
;
3038 WX_APPEND_ARRAY( temp
, m_children
);
3040 gs_internal
= m_internal
;
3041 m_children
.Sort( &wxGtkTreeModelChildCmp
);
3043 gint
*new_order
= new gint
[child_count
];
3046 for (pos
= 0; pos
< child_count
; pos
++)
3048 void *id
= m_children
.Item( pos
);
3049 int old_pos
= temp
.Index( id
);
3050 new_order
[pos
] = old_pos
;
3054 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
3057 iter
.user_data
= GetItem().GetID();
3058 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
3060 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3062 gtk_tree_model_rows_reordered( gtk_tree_model
, path
, &iter
, new_order
);
3064 gtk_tree_path_free (path
);
3066 delete [] new_order
;
3069 for (pos
= 0; pos
< node_count
; pos
++)
3071 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
3076 //-----------------------------------------------------------------------------
3077 // wxDataViewCtrlInternal
3078 //-----------------------------------------------------------------------------
3080 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
,
3081 wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
)
3084 m_wx_model
= wx_model
;
3085 m_gtk_model
= gtk_model
;
3087 m_sort_order
= GTK_SORT_ASCENDING
;
3089 m_dataview_sort_column
= NULL
;
3091 m_dragDataObject
= NULL
;
3092 m_dropDataObject
= NULL
;
3094 if (!m_wx_model
->IsVirtualListModel())
3098 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
3100 g_object_unref( m_gtk_model
);
3102 delete m_dragDataObject
;
3103 delete m_dropDataObject
;
3106 void wxDataViewCtrlInternal::InitTree()
3108 wxDataViewItem item
;
3109 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
3111 BuildBranch( m_root
);
3114 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
3116 if (node
->GetChildCount() == 0)
3118 wxDataViewItemArray children
;
3119 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
3121 for (pos
= 0; pos
< count
; pos
++)
3123 wxDataViewItem child
= children
[pos
];
3125 if (m_wx_model
->IsContainer( child
))
3126 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
3128 node
->AddLeave( child
.GetID() );
3130 // Don't send any events here
3137 bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat
&format
)
3139 wxGtkString
atom_str( gdk_atom_name( format
) );
3140 m_dragSourceTargetEntryTarget
= wxCharBuffer( atom_str
);
3142 m_dragSourceTargetEntry
.target
= m_dragSourceTargetEntryTarget
.data();
3143 m_dragSourceTargetEntry
.flags
= 0;
3144 m_dragSourceTargetEntry
.info
= static_cast<guint
>(-1);
3146 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3147 GDK_BUTTON1_MASK
, &m_dragSourceTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3152 bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat
&format
)
3154 wxGtkString
atom_str( gdk_atom_name( format
) );
3155 m_dropTargetTargetEntryTarget
= wxCharBuffer( atom_str
);
3157 m_dropTargetTargetEntry
.target
= m_dropTargetTargetEntryTarget
.data();
3158 m_dropTargetTargetEntry
.flags
= 0;
3159 m_dropTargetTargetEntry
.info
= static_cast<guint
>(-1);
3161 gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3162 &m_dropTargetTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3167 gboolean
wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource
*WXUNUSED(drag_source
),
3170 delete m_dragDataObject
;
3173 if (!get_iter( &iter
, path
)) return FALSE
;
3174 wxDataViewItem
item( (void*) iter
.user_data
);
3176 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3177 event
.SetEventObject( m_owner
);
3178 event
.SetItem( item
);
3179 event
.SetModel( m_wx_model
);
3180 if (!m_owner
->HandleWindowEvent( event
))
3183 if (!event
.IsAllowed())
3186 wxDataObject
*obj
= event
.GetDataObject();
3190 m_dragDataObject
= obj
;
3196 wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource
*WXUNUSED(drag_source
),
3197 GtkTreePath
*WXUNUSED(path
))
3202 gboolean
wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource
*WXUNUSED(drag_source
),
3203 GtkTreePath
*path
, GtkSelectionData
*selection_data
)
3206 if (!get_iter( &iter
, path
)) return FALSE
;
3207 wxDataViewItem
item( (void*) iter
.user_data
);
3209 if (!m_dragDataObject
->IsSupported( selection_data
->target
))
3212 size_t size
= m_dragDataObject
->GetDataSize( selection_data
->target
);
3216 void *buf
= malloc( size
);
3218 gboolean res
= FALSE
;
3219 if (m_dragDataObject
->GetDataHere( selection_data
->target
, buf
))
3223 gtk_selection_data_set( selection_data
, selection_data
->target
,
3224 8, (const guchar
*) buf
, size
);
3233 wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3235 GtkSelectionData
*selection_data
)
3238 if (!get_iter( &iter
, path
)) return FALSE
;
3239 wxDataViewItem
item( (void*) iter
.user_data
);
3241 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
3242 event
.SetEventObject( m_owner
);
3243 event
.SetItem( item
);
3244 event
.SetModel( m_wx_model
);
3245 event
.SetDataFormat( selection_data
->target
);
3246 event
.SetDataSize( selection_data
->length
);
3247 event
.SetDataBuffer( selection_data
->data
);
3248 if (!m_owner
->HandleWindowEvent( event
))
3251 if (!event
.IsAllowed())
3258 wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3260 GtkSelectionData
*selection_data
)
3263 if (!get_iter( &iter
, path
)) return FALSE
;
3264 wxDataViewItem
item( (void*) iter
.user_data
);
3266 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
3267 event
.SetEventObject( m_owner
);
3268 event
.SetItem( item
);
3269 event
.SetModel( m_wx_model
);
3270 event
.SetDataFormat( selection_data
->target
);
3271 if (!m_owner
->HandleWindowEvent( event
))
3274 if (!event
.IsAllowed())
3280 // notifications from wxDataViewModel
3282 bool wxDataViewCtrlInternal::Cleared()
3290 // Create new GTK model
3291 g_object_unref( m_gtk_model
);
3292 m_gtk_model
= wxgtk_tree_model_new();
3293 m_gtk_model
->internal
= this;
3298 void wxDataViewCtrlInternal::Resort()
3300 if (!m_wx_model
->IsVirtualListModel())
3304 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3306 if (!m_wx_model
->IsVirtualListModel())
3308 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3309 wxASSERT_MSG(parent_node
,
3310 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3312 if (m_wx_model
->IsContainer( item
))
3313 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
3315 parent_node
->AddLeave( item
.GetID() );
3321 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3323 if (!m_wx_model
->IsVirtualListModel())
3325 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3326 wxASSERT_MSG(parent_node
,
3327 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3329 parent_node
->DeleteChild( item
.GetID() );
3335 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
3337 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3338 event
.SetEventObject( m_owner
);
3339 event
.SetModel( m_owner
->GetModel() );
3340 event
.SetItem( item
);
3341 m_owner
->HandleWindowEvent( event
);
3346 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
3348 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3349 event
.SetEventObject( m_owner
);
3350 event
.SetModel( m_owner
->GetModel() );
3351 event
.SetColumn( col
);
3352 event
.SetDataViewColumn( GetOwner()->GetColumn(col
) );
3353 event
.SetItem( item
);
3354 m_owner
->HandleWindowEvent( event
);
3361 GtkTreeModelFlags
wxDataViewCtrlInternal::get_flags()
3363 if (m_wx_model
->IsVirtualListModel())
3364 return GTK_TREE_MODEL_LIST_ONLY
;
3366 return GTK_TREE_MODEL_ITERS_PERSIST
;
3369 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
3371 if (m_wx_model
->IsVirtualListModel())
3373 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3375 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
3377 if (i
>= wx_model
->GetLastIndex() + 1)
3380 iter
->stamp
= m_gtk_model
->stamp
;
3381 // user_data is just the index
3382 iter
->user_data
= (gpointer
) i
;
3388 int depth
= gtk_tree_path_get_depth( path
);
3390 wxGtkTreeModelNode
*node
= m_root
;
3393 for (i
= 0; i
< depth
; i
++)
3395 BuildBranch( node
);
3397 gint pos
= gtk_tree_path_get_indices (path
)[i
];
3398 if (pos
< 0) return FALSE
;
3399 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
3401 void* id
= node
->GetChildren().Item( (size_t) pos
);
3405 iter
->stamp
= m_gtk_model
->stamp
;
3406 iter
->user_data
= id
;
3410 size_t count
= node
->GetNodes().GetCount();
3412 for (pos2
= 0; pos2
< count
; pos2
++)
3414 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
3415 if (child_node
->GetItem().GetID() == id
)
3427 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
3429 GtkTreePath
*retval
= gtk_tree_path_new ();
3431 if (m_wx_model
->IsVirtualListModel())
3433 // user_data is just the index
3434 int i
= (wxUIntPtr
) iter
->user_data
;
3435 gtk_tree_path_append_index (retval
, i
);
3439 void *id
= iter
->user_data
;
3441 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
3444 int pos
= node
->GetChildren().Index( id
);
3446 gtk_tree_path_prepend_index( retval
, pos
);
3448 id
= node
->GetItem().GetID();
3449 node
= node
->GetParent();
3456 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
3458 if (m_wx_model
->IsVirtualListModel())
3460 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3462 int n
= (wxUIntPtr
) iter
->user_data
;
3467 if (n
>= (int) wx_model
->GetLastIndex())
3470 iter
->user_data
= (gpointer
) ++n
;
3474 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
3475 if( parent
== NULL
)
3478 int pos
= parent
->GetChildren().Index( iter
->user_data
);
3480 if (pos
== (int) parent
->GetChildCount()-1)
3483 iter
->stamp
= m_gtk_model
->stamp
;
3484 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
3490 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
3492 if (m_wx_model
->IsVirtualListModel())
3494 // this is a list, nodes have no children
3498 iter
->stamp
= m_gtk_model
->stamp
;
3499 iter
->user_data
= (gpointer
) -1;
3505 wxDataViewItem
item( (void*) parent
->user_data
);
3507 if (!m_wx_model
->IsContainer( item
))
3510 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3511 wxASSERT_MSG(parent_node
,
3512 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3514 BuildBranch( parent_node
);
3516 if (parent_node
->GetChildCount() == 0)
3519 iter
->stamp
= m_gtk_model
->stamp
;
3520 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
3526 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
3528 if (m_wx_model
->IsVirtualListModel())
3530 // this is a list, nodes have no children
3535 wxDataViewItem
item( (void*) iter
->user_data
);
3537 bool is_container
= m_wx_model
->IsContainer( item
);
3542 wxGtkTreeModelNode
*node
= FindNode( iter
);
3544 "Did you forget a call to ItemAdded()? The iterator is unknown to the wxGtkTreeModel");
3546 BuildBranch( node
);
3548 return (node
->GetChildCount() > 0);
3552 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
3554 if (m_wx_model
->IsVirtualListModel())
3556 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3559 return (gint
) wx_model
->GetLastIndex() + 1;
3566 return m_root
->GetChildCount();
3568 wxDataViewItem
item( (void*) iter
->user_data
);
3570 if (!m_wx_model
->IsContainer( item
))
3573 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
3574 wxASSERT_MSG(parent_node
,
3575 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3577 BuildBranch( parent_node
);
3579 // wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() );
3581 return parent_node
->GetChildCount();
3585 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
3587 if (m_wx_model
->IsVirtualListModel())
3589 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3597 if (n
>= (gint
) wx_model
->GetLastIndex() + 1)
3600 iter
->stamp
= m_gtk_model
->stamp
;
3601 iter
->user_data
= (gpointer
) n
;
3608 if (parent
) id
= (void*) parent
->user_data
;
3609 wxDataViewItem
item( id
);
3611 if (!m_wx_model
->IsContainer( item
))
3614 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3615 wxASSERT_MSG(parent_node
,
3616 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3618 BuildBranch( parent_node
);
3620 // wxPrintf( "iter_nth_child %d\n", n );
3622 iter
->stamp
= m_gtk_model
->stamp
;
3623 iter
->user_data
= parent_node
->GetChildren().Item( n
);
3629 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
3631 if (m_wx_model
->IsVirtualListModel())
3637 wxGtkTreeModelNode
*node
= FindParentNode( child
);
3641 iter
->stamp
= m_gtk_model
->stamp
;
3642 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
3648 static wxGtkTreeModelNode
*
3649 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3655 list
.DeleteContents( true );
3656 wxDataViewItem
it( item
);
3660 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3661 list
.Insert( pItem
);
3662 it
= model
->GetParent( it
);
3665 wxGtkTreeModelNode
* node
= treeNode
;
3666 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3668 if( node
&& node
->GetNodes().GetCount() != 0 )
3670 int len
= node
->GetNodes().GetCount();
3671 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3673 for( ; j
< len
; j
++)
3675 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3694 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
3699 wxDataViewItem
item( (void*) iter
->user_data
);
3703 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3708 wxLogDebug( "Not found %p", iter->user_data );
3712 // TODO: remove this code
3718 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
3723 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3728 wxLogDebug( "Not found %p", item.GetID() );
3732 // TODO: remove this code
3738 static wxGtkTreeModelNode
*
3739 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3745 list
.DeleteContents( true );
3749 wxDataViewItem
it( model
->GetParent( item
) );
3752 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3753 list
.Insert( pItem
);
3754 it
= model
->GetParent( it
);
3757 wxGtkTreeModelNode
* node
= treeNode
;
3758 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3760 if( node
&& node
->GetNodes().GetCount() != 0 )
3762 int len
= node
->GetNodes().GetCount();
3763 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3765 for( ; j
< len
; j
++)
3767 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3782 //Examine whether the node is item's parent node
3783 int len
= node
->GetChildCount();
3784 for( int i
= 0; i
< len
; i
++ )
3786 if( node
->GetChildren().Item( i
) == item
.GetID() )
3792 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
3797 wxDataViewItem
item( (void*) iter
->user_data
);
3801 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3804 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
3809 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3812 //-----------------------------------------------------------------------------
3813 // wxDataViewCtrl signal callbacks
3814 //-----------------------------------------------------------------------------
3817 wxdataview_selection_changed_callback( GtkTreeSelection
* WXUNUSED(selection
), wxDataViewCtrl
*dv
)
3819 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
3822 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
3823 event
.SetItem( dv
->GetSelection() );
3824 event
.SetModel( dv
->GetModel() );
3825 dv
->HandleWindowEvent( event
);
3829 wxdataview_row_activated_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreePath
*path
,
3830 GtkTreeViewColumn
*WXUNUSED(column
), wxDataViewCtrl
*dv
)
3832 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
3835 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3836 wxDataViewItem
item( (void*) iter
.user_data
);;
3837 event
.SetItem( item
);
3838 event
.SetModel( dv
->GetModel() );
3839 dv
->HandleWindowEvent( event
);
3843 wxdataview_test_expand_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3844 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3846 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
3848 wxDataViewItem
item( (void*) iter
->user_data
);;
3849 event
.SetItem( item
);
3850 event
.SetModel( dv
->GetModel() );
3851 dv
->HandleWindowEvent( event
);
3853 return !event
.IsAllowed();
3857 wxdataview_row_expanded_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3858 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3860 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
3862 wxDataViewItem
item( (void*) iter
->user_data
);;
3863 event
.SetItem( item
);
3864 event
.SetModel( dv
->GetModel() );
3865 dv
->HandleWindowEvent( event
);
3869 wxdataview_test_collapse_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3870 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3872 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
3874 wxDataViewItem
item( (void*) iter
->user_data
);;
3875 event
.SetItem( item
);
3876 event
.SetModel( dv
->GetModel() );
3877 dv
->HandleWindowEvent( event
);
3879 return !event
.IsAllowed();
3883 wxdataview_row_collapsed_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3884 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3886 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
3888 wxDataViewItem
item( (void*) iter
->user_data
);;
3889 event
.SetItem( item
);
3890 event
.SetModel( dv
->GetModel() );
3891 dv
->HandleWindowEvent( event
);
3894 //-----------------------------------------------------------------------------
3896 //-----------------------------------------------------------------------------
3898 void wxDataViewCtrl::AddChildGTK(wxWindowGTK
* child
)
3900 GtkWidget
* treeview
= GtkGetTreeView();
3902 // Insert widget in GtkTreeView
3903 if (GTK_WIDGET_REALIZED(treeview
))
3904 gtk_widget_set_parent_window( child
->m_widget
,
3905 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
3906 gtk_widget_set_parent( child
->m_widget
, treeview
);
3910 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
3911 GtkAllocation
*WXUNUSED(gtk_alloc
),
3912 wxDataViewCtrl
*win
)
3914 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
3917 wxWindow
*child
= node
->GetData();
3920 gtk_widget_size_request( child
->m_widget
, &req
);
3922 GtkAllocation alloc
;
3923 alloc
.x
= child
->m_x
;
3924 alloc
.y
= child
->m_y
;
3925 alloc
.width
= child
->m_width
;
3926 alloc
.height
= child
->m_height
;
3927 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
3929 node
= node
->GetNext();
3934 //-----------------------------------------------------------------------------
3935 // "motion_notify_event"
3936 //-----------------------------------------------------------------------------
3939 gtk_dataview_motion_notify_callback( GtkWidget
*WXUNUSED(widget
),
3940 GdkEventMotion
*gdk_event
,
3941 wxDataViewCtrl
*dv
)
3943 if (gdk_event
->is_hint
)
3947 GdkModifierType state
;
3948 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
3953 GtkTreePath
*path
= NULL
;
3954 GtkTreeViewColumn
*column
= NULL
;
3957 if (gtk_tree_view_get_path_at_pos(
3958 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
3959 (int) gdk_event
->x
, (int) gdk_event
->y
,
3968 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3970 // wxPrintf( "mouse %d %d\n", (int) gdk_event->x, (int) gdk_event->y );
3972 gtk_tree_path_free( path
);
3980 //-----------------------------------------------------------------------------
3981 // "button_press_event"
3982 //-----------------------------------------------------------------------------
3985 gtk_dataview_button_press_callback( GtkWidget
*WXUNUSED(widget
),
3986 GdkEventButton
*gdk_event
,
3987 wxDataViewCtrl
*dv
)
3989 if ((gdk_event
->button
== 3) && (gdk_event
->type
== GDK_BUTTON_PRESS
))
3991 GtkTreePath
*path
= NULL
;
3992 GtkTreeViewColumn
*column
= NULL
;
3995 if (gtk_tree_view_get_path_at_pos(
3996 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
3997 (int) gdk_event
->x
, (int) gdk_event
->y
,
4006 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4008 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, dv
->GetId() );
4009 wxDataViewItem
item( (void*) iter
.user_data
);;
4010 event
.SetItem( item
);
4011 event
.SetModel( dv
->GetModel() );
4012 bool ret
= dv
->HandleWindowEvent( event
);
4013 gtk_tree_path_free( path
);
4022 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
4024 wxDataViewCtrl::~wxDataViewCtrl()
4027 GetModel()->RemoveNotifier( m_notifier
);
4031 // remove the model from the GtkTreeView before it gets destroyed by the
4032 // wxDataViewCtrlBase's dtor
4033 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), NULL
);
4038 void wxDataViewCtrl::Init()
4043 m_cols
.DeleteContents( true );
4046 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
4047 const wxPoint
& pos
, const wxSize
& size
,
4048 long style
, const wxValidator
& validator
)
4052 if (!PreCreation( parent
, pos
, size
) ||
4053 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
4055 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
4059 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
4060 g_object_ref(m_widget
);
4062 GTKScrolledWindowSetBorder(m_widget
, style
);
4064 m_treeview
= gtk_tree_view_new();
4065 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
4067 g_signal_connect (m_treeview
, "size_allocate",
4068 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
4071 if (!gtk_check_version(2,6,0))
4073 bool fixed
= (style
& wxDV_VARIABLE_LINE_HEIGHT
) == 0;
4074 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4078 if (style
& wxDV_MULTIPLE
)
4080 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4081 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
4084 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
4087 if (!gtk_check_version(2,10,0))
4089 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
4091 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
4092 (style
& wxDV_VERT_RULES
) != 0)
4093 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
4094 else if (style
& wxDV_VERT_RULES
)
4095 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
4096 else if (style
& wxDV_HORIZ_RULES
)
4097 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
4099 if (grid
!= GTK_TREE_VIEW_GRID_LINES_NONE
)
4100 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
4104 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_ROW_LINES
) != 0 );
4106 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
4107 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
4108 gtk_widget_show (m_treeview
);
4110 m_parent
->DoAddChild( this );
4114 GtkEnableSelectionEvents();
4116 g_signal_connect_after (m_treeview
, "row-activated",
4117 G_CALLBACK (wxdataview_row_activated_callback
), this);
4119 g_signal_connect (m_treeview
, "test-collapse-row",
4120 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
4122 g_signal_connect_after (m_treeview
, "row-collapsed",
4123 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
4125 g_signal_connect (m_treeview
, "test-expand-row",
4126 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
4128 g_signal_connect_after (m_treeview
, "row-expanded",
4129 G_CALLBACK (wxdataview_row_expanded_callback
), this);
4131 g_signal_connect (m_treeview
, "motion_notify_event",
4132 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
4134 g_signal_connect (m_treeview
, "button_press_event",
4135 G_CALLBACK (gtk_dataview_button_press_callback
), this);
4140 void wxDataViewCtrl::OnInternalIdle()
4142 wxWindow::OnInternalIdle();
4144 unsigned int cols
= GetColumnCount();
4146 for (i
= 0; i
< cols
; i
++)
4148 wxDataViewColumn
*col
= GetColumn( i
);
4149 col
->OnInternalIdle();
4153 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4164 if (!wxDataViewCtrlBase::AssociateModel( model
))
4168 if (!gtk_check_version(2,6,0))
4170 bool fixed
= (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
) == 0) || (model
->IsVirtualListModel()));
4171 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4175 GtkWxTreeModel
*gtk_model
= wxgtk_tree_model_new();
4176 m_internal
= new wxDataViewCtrlInternal( this, model
, gtk_model
);
4177 gtk_model
->internal
= m_internal
;
4179 m_notifier
= new wxGtkDataViewModelNotifier( gtk_model
, model
, this );
4181 model
->AddNotifier( m_notifier
);
4183 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_model
) );
4185 // unref in wxDataViewCtrlInternal
4186 // g_object_unref( gtk_model );
4191 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4193 return m_internal
->EnableDragSource( format
);
4196 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4198 return m_internal
->EnableDropTarget( format
);
4201 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4203 if (!wxDataViewCtrlBase::AppendColumn(col
))
4206 m_cols
.Append( col
);
4209 if (!gtk_check_version(2,6,0))
4211 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4212 GTK_TREE_VIEW_COLUMN_FIXED
)
4213 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4217 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
4218 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4223 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4225 if (!wxDataViewCtrlBase::PrependColumn(col
))
4228 m_cols
.Insert( col
);
4231 if (!gtk_check_version(2,6,0))
4233 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4234 GTK_TREE_VIEW_COLUMN_FIXED
)
4235 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4239 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4240 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
4245 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4247 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4250 m_cols
.Insert( pos
, col
);
4253 if (!gtk_check_version(2,6,0))
4255 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4256 GTK_TREE_VIEW_COLUMN_FIXED
)
4257 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4261 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4262 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), pos
);
4267 unsigned int wxDataViewCtrl::GetColumnCount() const
4269 return m_cols
.GetCount();
4272 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
4274 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
4278 wxDataViewColumnList::const_iterator iter
;
4279 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4281 wxDataViewColumn
*col
= *iter
;
4282 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
4291 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4293 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4294 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
4296 m_cols
.DeleteObject( column
);
4301 bool wxDataViewCtrl::ClearColumns()
4303 wxDataViewColumnList::iterator iter
;
4304 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4306 wxDataViewColumn
*col
= *iter
;
4307 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4308 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4316 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4318 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetConstGtkHandle());
4320 GList
*list
= gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview
) );
4322 gint pos
= g_list_index( list
, (gconstpointer
) gtk_column
);
4324 g_list_free( list
);
4329 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4331 return m_internal
->GetDataViewSortColumn();
4334 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4337 iter
.user_data
= item
.GetID();
4338 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4339 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
4340 gtk_tree_path_free( path
);
4343 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4346 iter
.user_data
= item
.GetID();
4347 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4348 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
4349 gtk_tree_path_free( path
);
4352 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4355 iter
.user_data
= item
.GetID();
4356 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4357 bool res
= gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview
), path
);
4358 gtk_tree_path_free( path
);
4363 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4365 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4367 if (m_windowStyle
& wxDV_MULTIPLE
)
4369 // Report the first one
4370 GtkTreeModel
*model
;
4371 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4375 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4377 m_internal
->get_iter( &iter
, path
);
4380 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4381 g_list_free( list
);
4383 return wxDataViewItem( (void*) iter
.user_data
);
4389 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
4391 wxDataViewItem
item( (void*) iter
.user_data
);
4396 return wxDataViewItem(0);
4399 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4403 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4404 if (HasFlag(wxDV_MULTIPLE
))
4406 GtkTreeModel
*model
;
4407 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4412 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4415 m_internal
->get_iter( &iter
, path
);
4417 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4419 list
= g_list_next( list
);
4424 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4425 g_list_free( list
);
4431 GtkTreeModel
*model
;
4433 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
4436 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4444 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4446 GtkDisableSelectionEvents();
4448 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4450 gtk_tree_selection_unselect_all( selection
);
4452 wxDataViewItem last_parent
;
4455 for (i
= 0; i
< sel
.GetCount(); i
++)
4457 wxDataViewItem item
= sel
[i
];
4458 wxDataViewItem parent
= GetModel()->GetParent( item
);
4461 if (parent
!= last_parent
)
4462 ExpandAncestors(item
);
4464 last_parent
= parent
;
4467 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4468 iter
.user_data
= (gpointer
) item
.GetID();
4469 gtk_tree_selection_select_iter( selection
, &iter
);
4472 GtkEnableSelectionEvents();
4475 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4477 ExpandAncestors(item
);
4479 GtkDisableSelectionEvents();
4481 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4484 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4485 iter
.user_data
= (gpointer
) item
.GetID();
4486 gtk_tree_selection_select_iter( selection
, &iter
);
4488 GtkEnableSelectionEvents();
4491 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4493 GtkDisableSelectionEvents();
4495 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4498 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4499 iter
.user_data
= (gpointer
) item
.GetID();
4500 gtk_tree_selection_unselect_iter( selection
, &iter
);
4502 GtkEnableSelectionEvents();
4505 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4507 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4510 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4511 iter
.user_data
= (gpointer
) item
.GetID();
4513 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
4516 void wxDataViewCtrl::SelectAll()
4518 GtkDisableSelectionEvents();
4520 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4522 gtk_tree_selection_select_all( selection
);
4524 GtkEnableSelectionEvents();
4527 void wxDataViewCtrl::UnselectAll()
4529 GtkDisableSelectionEvents();
4531 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4533 gtk_tree_selection_unselect_all( selection
);
4535 GtkEnableSelectionEvents();
4538 void wxDataViewCtrl::EnsureVisible(const wxDataViewItem
& item
,
4539 const wxDataViewColumn
*WXUNUSED(column
))
4541 ExpandAncestors(item
);
4544 iter
.user_data
= (gpointer
) item
.GetID();
4545 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4546 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
4547 gtk_tree_path_free( path
);
4550 void wxDataViewCtrl::HitTest(const wxPoint
& WXUNUSED(point
),
4551 wxDataViewItem
& item
,
4552 wxDataViewColumn
*& column
) const
4554 item
= wxDataViewItem(0);
4559 wxDataViewCtrl::GetItemRect(const wxDataViewItem
& WXUNUSED(item
),
4560 const wxDataViewColumn
*WXUNUSED(column
)) const
4565 void wxDataViewCtrl::DoSetExpanderColumn()
4567 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
4568 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
4571 void wxDataViewCtrl::DoSetIndent()
4575 void wxDataViewCtrl::GtkDisableSelectionEvents()
4577 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4578 g_signal_handlers_disconnect_by_func( selection
,
4579 (gpointer
) (wxdataview_selection_changed_callback
), this);
4582 void wxDataViewCtrl::GtkEnableSelectionEvents()
4584 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4585 g_signal_connect_after (selection
, "changed",
4586 G_CALLBACK (wxdataview_selection_changed_callback
), this);
4591 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
4593 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
4598 // !wxUSE_GENERICDATAVIEWCTRL
4601 // wxUSE_DATAVIEWCTRL