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 //-----------------------------------------------------------------------------
2977 class wxGtkTreeModelChildWithPos
2985 int wxGtkTreeModelChildWithPosCmp( const void* data1
, const void* data2
, const void* user_data
)
2987 const wxGtkTreeModelChildWithPos
* child1
= (const wxGtkTreeModelChildWithPos
*) data1
;
2988 const wxGtkTreeModelChildWithPos
* child2
= (const wxGtkTreeModelChildWithPos
*) data2
;
2989 const wxDataViewCtrlInternal
*internal
= (const wxDataViewCtrlInternal
*) user_data
;
2990 int ret
= internal
->GetDataViewModel()->Compare( child1
->id
, child2
->id
,
2991 internal
->GetSortColumn(), (internal
->GetSortOrder() == GTK_SORT_DESCENDING
) );
2997 int LINKAGEMODE
wxGtkTreeModelChildPtrCmp( void*** data1
, void*** data2
)
2999 return gs_internal
->GetDataViewModel()->Compare( **data1
, **data2
,
3000 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
3003 WX_DEFINE_ARRAY_PTR( void**, wxGtkTreeModelChildrenPtr
);
3006 void wxGtkTreeModelNode::Resort()
3008 size_t child_count
= GetChildCount();
3009 if (child_count
== 0)
3012 size_t node_count
= GetNodesCount();
3014 if (child_count
== 1)
3016 if (node_count
== 1)
3018 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
3024 gint
*new_order
= new gint
[child_count
];
3027 // m_children has the original *void
3028 // ptrs points to these
3029 wxGtkTreeModelChildrenPtr ptrs
;
3031 for (i
= 0; i
< child_count
; i
++)
3032 ptrs
.Add( &(m_children
[i
]) );
3034 gs_internal
= m_internal
;
3035 ptrs
.Sort( &wxGtkTreeModelChildPtrCmp
);
3037 wxGtkTreeModelChildren temp
;
3038 void** base_ptr
= &(m_children
[0]);
3039 // Transfer positions to new_order array and
3041 for (i
= 0; i
< child_count
; i
++)
3043 new_order
[i
] = ptrs
[i
] - base_ptr
;
3044 temp
.Add( *ptrs
[i
] );
3047 // Transfer IDs back to m_children
3049 WX_APPEND_ARRAY( temp
, m_children
);
3054 // Build up array with IDs and original positions
3055 wxGtkTreeModelChildWithPos
* temp
= new wxGtkTreeModelChildWithPos
[child_count
];
3057 for (i
= 0; i
< child_count
; i
++)
3060 temp
[i
].id
= m_children
[i
];
3062 // Sort array keeping original positions
3063 wxQsort( temp
, child_count
, sizeof(wxGtkTreeModelChildWithPos
),
3064 &wxGtkTreeModelChildWithPosCmp
, m_internal
);
3065 // Transfer positions to new_order array and
3066 // IDs to m_children
3068 for (i
= 0; i
< child_count
; i
++)
3070 new_order
[i
] = temp
[i
].pos
;
3071 m_children
.Add( temp
[i
].id
);
3080 wxGtkTreeModelChildren temp
;
3081 WX_APPEND_ARRAY( temp
, m_children
);
3083 gs_internal
= m_internal
;
3084 m_children
.Sort( &wxGtkTreeModelChildCmp
);
3087 for (pos
= 0; pos
< child_count
; pos
++)
3089 void *id
= m_children
.Item( pos
);
3090 int old_pos
= temp
.Index( id
);
3091 new_order
[pos
] = old_pos
;
3095 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
3098 iter
.user_data
= GetItem().GetID();
3099 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
3101 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3103 gtk_tree_model_rows_reordered( gtk_tree_model
, path
, &iter
, new_order
);
3105 gtk_tree_path_free (path
);
3107 delete [] new_order
;
3110 for (pos
= 0; pos
< node_count
; pos
++)
3112 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
3117 //-----------------------------------------------------------------------------
3118 // wxDataViewCtrlInternal
3119 //-----------------------------------------------------------------------------
3121 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
,
3122 wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
)
3125 m_wx_model
= wx_model
;
3126 m_gtk_model
= gtk_model
;
3128 m_sort_order
= GTK_SORT_ASCENDING
;
3130 m_dataview_sort_column
= NULL
;
3132 m_dragDataObject
= NULL
;
3133 m_dropDataObject
= NULL
;
3135 if (!m_wx_model
->IsVirtualListModel())
3139 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
3141 g_object_unref( m_gtk_model
);
3143 delete m_dragDataObject
;
3144 delete m_dropDataObject
;
3147 void wxDataViewCtrlInternal::InitTree()
3149 wxDataViewItem item
;
3150 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
3152 BuildBranch( m_root
);
3155 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
3157 if (node
->GetChildCount() == 0)
3159 wxDataViewItemArray children
;
3160 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
3162 for (pos
= 0; pos
< count
; pos
++)
3164 wxDataViewItem child
= children
[pos
];
3166 if (m_wx_model
->IsContainer( child
))
3167 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
3169 node
->AddLeave( child
.GetID() );
3171 // Don't send any events here
3178 bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat
&format
)
3180 wxGtkString
atom_str( gdk_atom_name( format
) );
3181 m_dragSourceTargetEntryTarget
= wxCharBuffer( atom_str
);
3183 m_dragSourceTargetEntry
.target
= m_dragSourceTargetEntryTarget
.data();
3184 m_dragSourceTargetEntry
.flags
= 0;
3185 m_dragSourceTargetEntry
.info
= static_cast<guint
>(-1);
3187 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3188 GDK_BUTTON1_MASK
, &m_dragSourceTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3193 bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat
&format
)
3195 wxGtkString
atom_str( gdk_atom_name( format
) );
3196 m_dropTargetTargetEntryTarget
= wxCharBuffer( atom_str
);
3198 m_dropTargetTargetEntry
.target
= m_dropTargetTargetEntryTarget
.data();
3199 m_dropTargetTargetEntry
.flags
= 0;
3200 m_dropTargetTargetEntry
.info
= static_cast<guint
>(-1);
3202 gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3203 &m_dropTargetTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3208 gboolean
wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource
*WXUNUSED(drag_source
),
3211 delete m_dragDataObject
;
3214 if (!get_iter( &iter
, path
)) return FALSE
;
3215 wxDataViewItem
item( (void*) iter
.user_data
);
3217 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3218 event
.SetEventObject( m_owner
);
3219 event
.SetItem( item
);
3220 event
.SetModel( m_wx_model
);
3221 if (!m_owner
->HandleWindowEvent( event
))
3224 if (!event
.IsAllowed())
3227 wxDataObject
*obj
= event
.GetDataObject();
3231 m_dragDataObject
= obj
;
3237 wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource
*WXUNUSED(drag_source
),
3238 GtkTreePath
*WXUNUSED(path
))
3243 gboolean
wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource
*WXUNUSED(drag_source
),
3244 GtkTreePath
*path
, GtkSelectionData
*selection_data
)
3247 if (!get_iter( &iter
, path
)) return FALSE
;
3248 wxDataViewItem
item( (void*) iter
.user_data
);
3250 if (!m_dragDataObject
->IsSupported( selection_data
->target
))
3253 size_t size
= m_dragDataObject
->GetDataSize( selection_data
->target
);
3257 void *buf
= malloc( size
);
3259 gboolean res
= FALSE
;
3260 if (m_dragDataObject
->GetDataHere( selection_data
->target
, buf
))
3264 gtk_selection_data_set( selection_data
, selection_data
->target
,
3265 8, (const guchar
*) buf
, size
);
3274 wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3276 GtkSelectionData
*selection_data
)
3279 if (!get_iter( &iter
, path
)) return FALSE
;
3280 wxDataViewItem
item( (void*) iter
.user_data
);
3282 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
3283 event
.SetEventObject( m_owner
);
3284 event
.SetItem( item
);
3285 event
.SetModel( m_wx_model
);
3286 event
.SetDataFormat( selection_data
->target
);
3287 event
.SetDataSize( selection_data
->length
);
3288 event
.SetDataBuffer( selection_data
->data
);
3289 if (!m_owner
->HandleWindowEvent( event
))
3292 if (!event
.IsAllowed())
3299 wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3301 GtkSelectionData
*selection_data
)
3304 if (!get_iter( &iter
, path
)) return FALSE
;
3305 wxDataViewItem
item( (void*) iter
.user_data
);
3307 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
3308 event
.SetEventObject( m_owner
);
3309 event
.SetItem( item
);
3310 event
.SetModel( m_wx_model
);
3311 event
.SetDataFormat( selection_data
->target
);
3312 if (!m_owner
->HandleWindowEvent( event
))
3315 if (!event
.IsAllowed())
3321 // notifications from wxDataViewModel
3323 bool wxDataViewCtrlInternal::Cleared()
3331 // Create new GTK model
3332 g_object_unref( m_gtk_model
);
3333 m_gtk_model
= wxgtk_tree_model_new();
3334 m_gtk_model
->internal
= this;
3339 void wxDataViewCtrlInternal::Resort()
3341 if (!m_wx_model
->IsVirtualListModel())
3345 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3347 if (!m_wx_model
->IsVirtualListModel())
3349 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3350 wxASSERT_MSG(parent_node
,
3351 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3353 if (m_wx_model
->IsContainer( item
))
3354 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
3356 parent_node
->AddLeave( item
.GetID() );
3362 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3364 if (!m_wx_model
->IsVirtualListModel())
3366 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3367 wxASSERT_MSG(parent_node
,
3368 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3370 parent_node
->DeleteChild( item
.GetID() );
3376 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
3378 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3379 event
.SetEventObject( m_owner
);
3380 event
.SetModel( m_owner
->GetModel() );
3381 event
.SetItem( item
);
3382 m_owner
->HandleWindowEvent( event
);
3387 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
3389 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3390 event
.SetEventObject( m_owner
);
3391 event
.SetModel( m_owner
->GetModel() );
3392 event
.SetColumn( col
);
3393 event
.SetDataViewColumn( GetOwner()->GetColumn(col
) );
3394 event
.SetItem( item
);
3395 m_owner
->HandleWindowEvent( event
);
3402 GtkTreeModelFlags
wxDataViewCtrlInternal::get_flags()
3404 if (m_wx_model
->IsVirtualListModel())
3405 return GTK_TREE_MODEL_LIST_ONLY
;
3407 return GTK_TREE_MODEL_ITERS_PERSIST
;
3410 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
3412 if (m_wx_model
->IsVirtualListModel())
3414 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3416 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
3418 if (i
>= wx_model
->GetLastIndex() + 1)
3421 iter
->stamp
= m_gtk_model
->stamp
;
3422 // user_data is just the index
3423 iter
->user_data
= (gpointer
) i
;
3429 int depth
= gtk_tree_path_get_depth( path
);
3431 wxGtkTreeModelNode
*node
= m_root
;
3434 for (i
= 0; i
< depth
; i
++)
3436 BuildBranch( node
);
3438 gint pos
= gtk_tree_path_get_indices (path
)[i
];
3439 if (pos
< 0) return FALSE
;
3440 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
3442 void* id
= node
->GetChildren().Item( (size_t) pos
);
3446 iter
->stamp
= m_gtk_model
->stamp
;
3447 iter
->user_data
= id
;
3451 size_t count
= node
->GetNodes().GetCount();
3453 for (pos2
= 0; pos2
< count
; pos2
++)
3455 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
3456 if (child_node
->GetItem().GetID() == id
)
3468 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
3470 GtkTreePath
*retval
= gtk_tree_path_new ();
3472 if (m_wx_model
->IsVirtualListModel())
3474 // user_data is just the index
3475 int i
= (wxUIntPtr
) iter
->user_data
;
3476 gtk_tree_path_append_index (retval
, i
);
3480 void *id
= iter
->user_data
;
3482 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
3485 int pos
= node
->GetChildren().Index( id
);
3487 gtk_tree_path_prepend_index( retval
, pos
);
3489 id
= node
->GetItem().GetID();
3490 node
= node
->GetParent();
3497 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
3499 if (m_wx_model
->IsVirtualListModel())
3501 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3503 int n
= (wxUIntPtr
) iter
->user_data
;
3508 if (n
>= (int) wx_model
->GetLastIndex())
3511 iter
->user_data
= (gpointer
) ++n
;
3515 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
3516 if( parent
== NULL
)
3519 int pos
= parent
->GetChildren().Index( iter
->user_data
);
3521 if (pos
== (int) parent
->GetChildCount()-1)
3524 iter
->stamp
= m_gtk_model
->stamp
;
3525 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
3531 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
3533 if (m_wx_model
->IsVirtualListModel())
3535 // this is a list, nodes have no children
3539 iter
->stamp
= m_gtk_model
->stamp
;
3540 iter
->user_data
= (gpointer
) -1;
3546 wxDataViewItem
item( (void*) parent
->user_data
);
3548 if (!m_wx_model
->IsContainer( item
))
3551 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3552 wxASSERT_MSG(parent_node
,
3553 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3555 BuildBranch( parent_node
);
3557 if (parent_node
->GetChildCount() == 0)
3560 iter
->stamp
= m_gtk_model
->stamp
;
3561 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
3567 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
3569 if (m_wx_model
->IsVirtualListModel())
3571 // this is a list, nodes have no children
3576 wxDataViewItem
item( (void*) iter
->user_data
);
3578 bool is_container
= m_wx_model
->IsContainer( item
);
3583 wxGtkTreeModelNode
*node
= FindNode( iter
);
3585 "Did you forget a call to ItemAdded()? The iterator is unknown to the wxGtkTreeModel");
3587 BuildBranch( node
);
3589 return (node
->GetChildCount() > 0);
3593 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
3595 if (m_wx_model
->IsVirtualListModel())
3597 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3600 return (gint
) wx_model
->GetLastIndex() + 1;
3607 return m_root
->GetChildCount();
3609 wxDataViewItem
item( (void*) iter
->user_data
);
3611 if (!m_wx_model
->IsContainer( item
))
3614 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
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_n_children %d\n", parent_node->GetChildCount() );
3622 return parent_node
->GetChildCount();
3626 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
3628 if (m_wx_model
->IsVirtualListModel())
3630 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3638 if (n
>= (gint
) wx_model
->GetLastIndex() + 1)
3641 iter
->stamp
= m_gtk_model
->stamp
;
3642 iter
->user_data
= (gpointer
) n
;
3649 if (parent
) id
= (void*) parent
->user_data
;
3650 wxDataViewItem
item( id
);
3652 if (!m_wx_model
->IsContainer( item
))
3655 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3656 wxASSERT_MSG(parent_node
,
3657 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3659 BuildBranch( parent_node
);
3661 // wxPrintf( "iter_nth_child %d\n", n );
3663 iter
->stamp
= m_gtk_model
->stamp
;
3664 iter
->user_data
= parent_node
->GetChildren().Item( n
);
3670 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
3672 if (m_wx_model
->IsVirtualListModel())
3678 wxGtkTreeModelNode
*node
= FindParentNode( child
);
3682 iter
->stamp
= m_gtk_model
->stamp
;
3683 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
3689 static wxGtkTreeModelNode
*
3690 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3696 list
.DeleteContents( true );
3697 wxDataViewItem
it( item
);
3701 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3702 list
.Insert( pItem
);
3703 it
= model
->GetParent( it
);
3706 wxGtkTreeModelNode
* node
= treeNode
;
3707 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3709 if( node
&& node
->GetNodes().GetCount() != 0 )
3711 int len
= node
->GetNodes().GetCount();
3712 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3714 for( ; j
< len
; j
++)
3716 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3735 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
3740 wxDataViewItem
item( (void*) iter
->user_data
);
3744 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3749 wxLogDebug( "Not found %p", iter->user_data );
3753 // TODO: remove this code
3759 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
3764 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3769 wxLogDebug( "Not found %p", item.GetID() );
3773 // TODO: remove this code
3779 static wxGtkTreeModelNode
*
3780 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3786 list
.DeleteContents( true );
3790 wxDataViewItem
it( model
->GetParent( item
) );
3793 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3794 list
.Insert( pItem
);
3795 it
= model
->GetParent( it
);
3798 wxGtkTreeModelNode
* node
= treeNode
;
3799 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3801 if( node
&& node
->GetNodes().GetCount() != 0 )
3803 int len
= node
->GetNodes().GetCount();
3804 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3806 for( ; j
< len
; j
++)
3808 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3823 //Examine whether the node is item's parent node
3824 int len
= node
->GetChildCount();
3825 for( int i
= 0; i
< len
; i
++ )
3827 if( node
->GetChildren().Item( i
) == item
.GetID() )
3833 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
3838 wxDataViewItem
item( (void*) iter
->user_data
);
3842 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3845 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
3850 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3853 //-----------------------------------------------------------------------------
3854 // wxDataViewCtrl signal callbacks
3855 //-----------------------------------------------------------------------------
3858 wxdataview_selection_changed_callback( GtkTreeSelection
* WXUNUSED(selection
), wxDataViewCtrl
*dv
)
3860 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
3863 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
3864 event
.SetItem( dv
->GetSelection() );
3865 event
.SetModel( dv
->GetModel() );
3866 dv
->HandleWindowEvent( event
);
3870 wxdataview_row_activated_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreePath
*path
,
3871 GtkTreeViewColumn
*WXUNUSED(column
), wxDataViewCtrl
*dv
)
3873 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
3876 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3877 wxDataViewItem
item( (void*) iter
.user_data
);;
3878 event
.SetItem( item
);
3879 event
.SetModel( dv
->GetModel() );
3880 dv
->HandleWindowEvent( event
);
3884 wxdataview_test_expand_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3885 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3887 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
3889 wxDataViewItem
item( (void*) iter
->user_data
);;
3890 event
.SetItem( item
);
3891 event
.SetModel( dv
->GetModel() );
3892 dv
->HandleWindowEvent( event
);
3894 return !event
.IsAllowed();
3898 wxdataview_row_expanded_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3899 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3901 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
3903 wxDataViewItem
item( (void*) iter
->user_data
);;
3904 event
.SetItem( item
);
3905 event
.SetModel( dv
->GetModel() );
3906 dv
->HandleWindowEvent( event
);
3910 wxdataview_test_collapse_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3911 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3913 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
3915 wxDataViewItem
item( (void*) iter
->user_data
);;
3916 event
.SetItem( item
);
3917 event
.SetModel( dv
->GetModel() );
3918 dv
->HandleWindowEvent( event
);
3920 return !event
.IsAllowed();
3924 wxdataview_row_collapsed_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3925 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3927 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
3929 wxDataViewItem
item( (void*) iter
->user_data
);;
3930 event
.SetItem( item
);
3931 event
.SetModel( dv
->GetModel() );
3932 dv
->HandleWindowEvent( event
);
3935 //-----------------------------------------------------------------------------
3937 //-----------------------------------------------------------------------------
3939 void wxDataViewCtrl::AddChildGTK(wxWindowGTK
* child
)
3941 GtkWidget
* treeview
= GtkGetTreeView();
3943 // Insert widget in GtkTreeView
3944 if (GTK_WIDGET_REALIZED(treeview
))
3945 gtk_widget_set_parent_window( child
->m_widget
,
3946 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
3947 gtk_widget_set_parent( child
->m_widget
, treeview
);
3951 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
3952 GtkAllocation
*WXUNUSED(gtk_alloc
),
3953 wxDataViewCtrl
*win
)
3955 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
3958 wxWindow
*child
= node
->GetData();
3961 gtk_widget_size_request( child
->m_widget
, &req
);
3963 GtkAllocation alloc
;
3964 alloc
.x
= child
->m_x
;
3965 alloc
.y
= child
->m_y
;
3966 alloc
.width
= child
->m_width
;
3967 alloc
.height
= child
->m_height
;
3968 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
3970 node
= node
->GetNext();
3975 //-----------------------------------------------------------------------------
3976 // "motion_notify_event"
3977 //-----------------------------------------------------------------------------
3980 gtk_dataview_motion_notify_callback( GtkWidget
*WXUNUSED(widget
),
3981 GdkEventMotion
*gdk_event
,
3982 wxDataViewCtrl
*dv
)
3984 if (gdk_event
->is_hint
)
3988 GdkModifierType state
;
3989 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
3994 GtkTreePath
*path
= NULL
;
3995 GtkTreeViewColumn
*column
= NULL
;
3998 if (gtk_tree_view_get_path_at_pos(
3999 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4000 (int) gdk_event
->x
, (int) gdk_event
->y
,
4009 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4011 // wxPrintf( "mouse %d %d\n", (int) gdk_event->x, (int) gdk_event->y );
4013 gtk_tree_path_free( path
);
4021 //-----------------------------------------------------------------------------
4022 // "button_press_event"
4023 //-----------------------------------------------------------------------------
4026 gtk_dataview_button_press_callback( GtkWidget
*WXUNUSED(widget
),
4027 GdkEventButton
*gdk_event
,
4028 wxDataViewCtrl
*dv
)
4030 if ((gdk_event
->button
== 3) && (gdk_event
->type
== GDK_BUTTON_PRESS
))
4032 GtkTreePath
*path
= NULL
;
4033 GtkTreeViewColumn
*column
= NULL
;
4036 if (gtk_tree_view_get_path_at_pos(
4037 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4038 (int) gdk_event
->x
, (int) gdk_event
->y
,
4047 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4049 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, dv
->GetId() );
4050 wxDataViewItem
item( (void*) iter
.user_data
);;
4051 event
.SetItem( item
);
4052 event
.SetModel( dv
->GetModel() );
4053 bool ret
= dv
->HandleWindowEvent( event
);
4054 gtk_tree_path_free( path
);
4063 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
4065 wxDataViewCtrl::~wxDataViewCtrl()
4068 GetModel()->RemoveNotifier( m_notifier
);
4072 // remove the model from the GtkTreeView before it gets destroyed by the
4073 // wxDataViewCtrlBase's dtor
4074 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), NULL
);
4079 void wxDataViewCtrl::Init()
4084 m_cols
.DeleteContents( true );
4087 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
4088 const wxPoint
& pos
, const wxSize
& size
,
4089 long style
, const wxValidator
& validator
)
4093 if (!PreCreation( parent
, pos
, size
) ||
4094 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
4096 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
4100 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
4101 g_object_ref(m_widget
);
4103 GTKScrolledWindowSetBorder(m_widget
, style
);
4105 m_treeview
= gtk_tree_view_new();
4106 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
4108 g_signal_connect (m_treeview
, "size_allocate",
4109 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
4112 if (!gtk_check_version(2,6,0))
4114 bool fixed
= (style
& wxDV_VARIABLE_LINE_HEIGHT
) == 0;
4115 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4119 if (style
& wxDV_MULTIPLE
)
4121 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4122 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
4125 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
4128 if (!gtk_check_version(2,10,0))
4130 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
4132 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
4133 (style
& wxDV_VERT_RULES
) != 0)
4134 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
4135 else if (style
& wxDV_VERT_RULES
)
4136 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
4137 else if (style
& wxDV_HORIZ_RULES
)
4138 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
4140 if (grid
!= GTK_TREE_VIEW_GRID_LINES_NONE
)
4141 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
4145 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_ROW_LINES
) != 0 );
4147 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
4148 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
4149 gtk_widget_show (m_treeview
);
4151 m_parent
->DoAddChild( this );
4155 GtkEnableSelectionEvents();
4157 g_signal_connect_after (m_treeview
, "row-activated",
4158 G_CALLBACK (wxdataview_row_activated_callback
), this);
4160 g_signal_connect (m_treeview
, "test-collapse-row",
4161 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
4163 g_signal_connect_after (m_treeview
, "row-collapsed",
4164 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
4166 g_signal_connect (m_treeview
, "test-expand-row",
4167 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
4169 g_signal_connect_after (m_treeview
, "row-expanded",
4170 G_CALLBACK (wxdataview_row_expanded_callback
), this);
4172 g_signal_connect (m_treeview
, "motion_notify_event",
4173 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
4175 g_signal_connect (m_treeview
, "button_press_event",
4176 G_CALLBACK (gtk_dataview_button_press_callback
), this);
4181 void wxDataViewCtrl::OnInternalIdle()
4183 wxWindow::OnInternalIdle();
4185 unsigned int cols
= GetColumnCount();
4187 for (i
= 0; i
< cols
; i
++)
4189 wxDataViewColumn
*col
= GetColumn( i
);
4190 col
->OnInternalIdle();
4194 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4205 if (!wxDataViewCtrlBase::AssociateModel( model
))
4209 if (!gtk_check_version(2,6,0))
4211 bool fixed
= (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
) == 0) || (model
->IsVirtualListModel()));
4212 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4216 GtkWxTreeModel
*gtk_model
= wxgtk_tree_model_new();
4217 m_internal
= new wxDataViewCtrlInternal( this, model
, gtk_model
);
4218 gtk_model
->internal
= m_internal
;
4220 m_notifier
= new wxGtkDataViewModelNotifier( gtk_model
, model
, this );
4222 model
->AddNotifier( m_notifier
);
4224 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_model
) );
4226 // unref in wxDataViewCtrlInternal
4227 // g_object_unref( gtk_model );
4232 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4234 return m_internal
->EnableDragSource( format
);
4237 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4239 return m_internal
->EnableDropTarget( format
);
4242 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4244 if (!wxDataViewCtrlBase::AppendColumn(col
))
4247 m_cols
.Append( col
);
4250 if (!gtk_check_version(2,6,0))
4252 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4253 GTK_TREE_VIEW_COLUMN_FIXED
)
4254 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4258 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
4259 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4264 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4266 if (!wxDataViewCtrlBase::PrependColumn(col
))
4269 m_cols
.Insert( col
);
4272 if (!gtk_check_version(2,6,0))
4274 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4275 GTK_TREE_VIEW_COLUMN_FIXED
)
4276 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4280 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4281 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
4286 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4288 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4291 m_cols
.Insert( pos
, col
);
4294 if (!gtk_check_version(2,6,0))
4296 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4297 GTK_TREE_VIEW_COLUMN_FIXED
)
4298 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4302 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4303 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), pos
);
4308 unsigned int wxDataViewCtrl::GetColumnCount() const
4310 return m_cols
.GetCount();
4313 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
4315 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
4319 wxDataViewColumnList::const_iterator iter
;
4320 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4322 wxDataViewColumn
*col
= *iter
;
4323 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
4332 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4334 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4335 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
4337 m_cols
.DeleteObject( column
);
4342 bool wxDataViewCtrl::ClearColumns()
4344 wxDataViewColumnList::iterator iter
;
4345 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4347 wxDataViewColumn
*col
= *iter
;
4348 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4349 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4357 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4359 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetConstGtkHandle());
4361 GList
*list
= gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview
) );
4363 gint pos
= g_list_index( list
, (gconstpointer
) gtk_column
);
4365 g_list_free( list
);
4370 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4372 return m_internal
->GetDataViewSortColumn();
4375 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4378 iter
.user_data
= item
.GetID();
4379 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4380 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
4381 gtk_tree_path_free( path
);
4384 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4387 iter
.user_data
= item
.GetID();
4388 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4389 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
4390 gtk_tree_path_free( path
);
4393 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4396 iter
.user_data
= item
.GetID();
4397 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4398 bool res
= gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview
), path
);
4399 gtk_tree_path_free( path
);
4404 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4406 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4408 if (m_windowStyle
& wxDV_MULTIPLE
)
4410 // Report the first one
4411 GtkTreeModel
*model
;
4412 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4416 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4418 m_internal
->get_iter( &iter
, path
);
4421 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4422 g_list_free( list
);
4424 return wxDataViewItem( (void*) iter
.user_data
);
4430 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
4432 wxDataViewItem
item( (void*) iter
.user_data
);
4437 return wxDataViewItem(0);
4440 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4444 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4445 if (HasFlag(wxDV_MULTIPLE
))
4447 GtkTreeModel
*model
;
4448 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4453 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4456 m_internal
->get_iter( &iter
, path
);
4458 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4460 list
= g_list_next( list
);
4465 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4466 g_list_free( list
);
4472 GtkTreeModel
*model
;
4474 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
4477 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4485 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4487 GtkDisableSelectionEvents();
4489 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4491 gtk_tree_selection_unselect_all( selection
);
4493 wxDataViewItem last_parent
;
4496 for (i
= 0; i
< sel
.GetCount(); i
++)
4498 wxDataViewItem item
= sel
[i
];
4499 wxDataViewItem parent
= GetModel()->GetParent( item
);
4502 if (parent
!= last_parent
)
4503 ExpandAncestors(item
);
4505 last_parent
= parent
;
4508 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4509 iter
.user_data
= (gpointer
) item
.GetID();
4510 gtk_tree_selection_select_iter( selection
, &iter
);
4513 GtkEnableSelectionEvents();
4516 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4518 ExpandAncestors(item
);
4520 GtkDisableSelectionEvents();
4522 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4525 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4526 iter
.user_data
= (gpointer
) item
.GetID();
4527 gtk_tree_selection_select_iter( selection
, &iter
);
4529 GtkEnableSelectionEvents();
4532 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4534 GtkDisableSelectionEvents();
4536 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4539 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4540 iter
.user_data
= (gpointer
) item
.GetID();
4541 gtk_tree_selection_unselect_iter( selection
, &iter
);
4543 GtkEnableSelectionEvents();
4546 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4548 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4551 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4552 iter
.user_data
= (gpointer
) item
.GetID();
4554 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
4557 void wxDataViewCtrl::SelectAll()
4559 GtkDisableSelectionEvents();
4561 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4563 gtk_tree_selection_select_all( selection
);
4565 GtkEnableSelectionEvents();
4568 void wxDataViewCtrl::UnselectAll()
4570 GtkDisableSelectionEvents();
4572 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4574 gtk_tree_selection_unselect_all( selection
);
4576 GtkEnableSelectionEvents();
4579 void wxDataViewCtrl::EnsureVisible(const wxDataViewItem
& item
,
4580 const wxDataViewColumn
*WXUNUSED(column
))
4582 ExpandAncestors(item
);
4585 iter
.user_data
= (gpointer
) item
.GetID();
4586 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4587 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
4588 gtk_tree_path_free( path
);
4591 void wxDataViewCtrl::HitTest(const wxPoint
& WXUNUSED(point
),
4592 wxDataViewItem
& item
,
4593 wxDataViewColumn
*& column
) const
4595 item
= wxDataViewItem(0);
4600 wxDataViewCtrl::GetItemRect(const wxDataViewItem
& WXUNUSED(item
),
4601 const wxDataViewColumn
*WXUNUSED(column
)) const
4606 void wxDataViewCtrl::DoSetExpanderColumn()
4608 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
4609 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
4612 void wxDataViewCtrl::DoSetIndent()
4616 void wxDataViewCtrl::GtkDisableSelectionEvents()
4618 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4619 g_signal_handlers_disconnect_by_func( selection
,
4620 (gpointer
) (wxdataview_selection_changed_callback
), this);
4623 void wxDataViewCtrl::GtkEnableSelectionEvents()
4625 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4626 g_signal_connect_after (selection
, "changed",
4627 G_CALLBACK (wxdataview_selection_changed_callback
), this);
4632 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
4634 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
4639 // !wxUSE_GENERICDATAVIEWCTRL
4642 // wxUSE_DATAVIEWCTRL