1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/dataview.cpp
3 // Purpose: wxDataViewCtrl GTK+2 implementation
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if wxUSE_DATAVIEWCTRL
15 #include "wx/dataview.h"
17 #ifndef wxUSE_GENERICDATAVIEWCTRL
21 #include "wx/dcclient.h"
23 #include "wx/settings.h"
27 #include "wx/stockitem.h"
28 #include "wx/calctrl.h"
29 #include "wx/popupwin.h"
30 #include "wx/listimpl.cpp"
32 #include "wx/gtk/private.h"
33 #include "wx/gtk/dc.h"
34 #include "wx/gtk/dcclient.h"
36 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 static wxDataViewCtrlInternal
*gs_internal
= NULL
;
41 class wxGtkTreeModelNode
;
44 typedef struct _GtkWxTreeModel GtkWxTreeModel
;
47 //-----------------------------------------------------------------------------
48 // wxDataViewCtrlInternal
49 //-----------------------------------------------------------------------------
51 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
52 WX_DEFINE_LIST(ItemList
)
54 class WXDLLIMPEXP_ADV wxDataViewCtrlInternal
57 wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
);
58 ~wxDataViewCtrlInternal();
61 GtkTreeModelFlags
get_flags();
62 gboolean
get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
);
63 GtkTreePath
*get_path( GtkTreeIter
*iter
);
64 gboolean
iter_next( GtkTreeIter
*iter
);
65 gboolean
iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
);
66 gboolean
iter_has_child( GtkTreeIter
*iter
);
67 gint
iter_n_children( GtkTreeIter
*iter
);
68 gboolean
iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
);
69 gboolean
iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
);
73 bool EnableDragSource( const wxDataFormat
&format
);
74 bool EnableDropTarget( const wxDataFormat
&format
);
76 gboolean
row_draggable( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
);
77 gboolean
drag_data_delete( GtkTreeDragSource
*drag_source
, GtkTreePath
* path
);
78 gboolean
drag_data_get( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
,
79 GtkSelectionData
*selection_data
);
80 gboolean
drag_data_received( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest
,
81 GtkSelectionData
*selection_data
);
82 gboolean
row_drop_possible( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest_path
,
83 GtkSelectionData
*selection_data
);
85 // notifactions from wxDataViewModel
86 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
87 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
88 bool ItemChanged( const wxDataViewItem
&item
);
89 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
94 void SetSortOrder( GtkSortType sort_order
) { m_sort_order
= sort_order
; }
95 GtkSortType
GetSortOrder() const { return m_sort_order
; }
97 void SetSortColumn( int column
) { m_sort_column
= column
; }
98 int GetSortColumn() const { return m_sort_column
; }
100 void SetDataViewSortColumn( wxDataViewColumn
*column
) { m_dataview_sort_column
= column
; }
101 wxDataViewColumn
*GetDataViewSortColumn() { return m_dataview_sort_column
; }
103 bool IsSorted() { return (m_sort_column
>= 0); }
106 wxDataViewModel
* GetDataViewModel() { return m_wx_model
; }
107 const wxDataViewModel
* GetDataViewModel() const { return m_wx_model
; }
108 wxDataViewCtrl
* GetOwner() { return m_owner
; }
109 GtkWxTreeModel
* GetGtkModel() { return m_gtk_model
; }
113 wxGtkTreeModelNode
*FindNode( const wxDataViewItem
&item
);
114 wxGtkTreeModelNode
*FindNode( GtkTreeIter
*iter
);
115 wxGtkTreeModelNode
*FindParentNode( const wxDataViewItem
&item
);
116 wxGtkTreeModelNode
*FindParentNode( GtkTreeIter
*iter
);
117 void BuildBranch( wxGtkTreeModelNode
*branch
);
120 wxGtkTreeModelNode
*m_root
;
121 wxDataViewModel
*m_wx_model
;
122 GtkWxTreeModel
*m_gtk_model
;
123 wxDataViewCtrl
*m_owner
;
124 GtkSortType m_sort_order
;
125 wxDataViewColumn
*m_dataview_sort_column
;
128 GtkTargetEntry m_dragSourceTargetEntry
;
129 wxCharBuffer m_dragSourceTargetEntryTarget
;
130 wxDataObject
*m_dragDataObject
;
132 GtkTargetEntry m_dropTargetTargetEntry
;
133 wxCharBuffer m_dropTargetTargetEntryTarget
;
134 wxDataObject
*m_dropDataObject
;
138 //-----------------------------------------------------------------------------
139 // wxGtkTreeModelNode
140 //-----------------------------------------------------------------------------
143 int LINKAGEMODE
wxGtkTreeModelChildCmp( void** id1
, void** id2
)
145 int ret
= gs_internal
->GetDataViewModel()->Compare( *id1
, *id2
,
146 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
151 WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode
*, wxGtkTreeModelNodes
);
152 WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren
);
154 class wxGtkTreeModelNode
157 wxGtkTreeModelNode( wxGtkTreeModelNode
* parent
, const wxDataViewItem
&item
,
158 wxDataViewCtrlInternal
*internal
)
162 m_internal
= internal
;
165 ~wxGtkTreeModelNode()
167 size_t count
= m_nodes
.GetCount();
169 for (i
= 0; i
< count
; i
++)
171 wxGtkTreeModelNode
*child
= m_nodes
.Item( i
);
176 unsigned int AddNode( wxGtkTreeModelNode
* child
)
178 m_nodes
.Add( child
);
180 void *id
= child
->GetItem().GetID();
182 m_children
.Add( id
);
184 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
186 gs_internal
= m_internal
;
187 m_children
.Sort( &wxGtkTreeModelChildCmp
);
188 return m_children
.Index( id
);
191 return m_children
.GetCount()-1;
194 unsigned int AddLeave( void* id
)
196 m_children
.Add( id
);
198 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
200 gs_internal
= m_internal
;
201 m_children
.Sort( &wxGtkTreeModelChildCmp
);
202 return m_children
.Index( id
);
205 return m_children
.GetCount()-1;
208 void DeleteChild( void* id
)
210 m_children
.Remove( id
);
212 unsigned int count
= m_nodes
.GetCount();
214 for (pos
= 0; pos
< count
; pos
++)
216 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
217 if (node
->GetItem().GetID() == id
)
219 m_nodes
.RemoveAt( pos
);
226 wxGtkTreeModelNode
* GetParent()
228 wxGtkTreeModelNodes
&GetNodes()
230 wxGtkTreeModelChildren
&GetChildren()
231 { return m_children
; }
233 unsigned int GetChildCount() const { return m_children
.GetCount(); }
234 unsigned int GetNodesCount() const { return m_nodes
.GetCount(); }
236 wxDataViewItem
&GetItem() { return m_item
; }
237 wxDataViewCtrlInternal
*GetInternal() { return m_internal
; }
242 wxGtkTreeModelNode
*m_parent
;
243 wxGtkTreeModelNodes m_nodes
;
244 wxGtkTreeModelChildren m_children
;
245 wxDataViewItem m_item
;
246 wxDataViewCtrlInternal
*m_internal
;
250 //-----------------------------------------------------------------------------
252 //-----------------------------------------------------------------------------
254 extern bool g_blockEventsOnDrag
;
256 //-----------------------------------------------------------------------------
257 // define new GTK+ class wxGtkTreeModel
258 //-----------------------------------------------------------------------------
262 #define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ())
263 #define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel))
264 #define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
265 #define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL))
266 #define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL))
267 #define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
269 GType
gtk_wx_tree_model_get_type (void);
271 typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass
;
273 struct _GtkWxTreeModel
279 wxDataViewCtrlInternal
*internal
;
282 struct _GtkWxTreeModelClass
284 GObjectClass list_parent_class
;
287 static GtkWxTreeModel
*wxgtk_tree_model_new (void);
288 static void wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
);
289 static void wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
);
291 static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
);
292 static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
);
293 static void wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
);
294 static void wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
);
296 static void wxgtk_tree_model_finalize (GObject
*object
);
297 static GtkTreeModelFlags
wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
);
298 static gint
wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
);
299 static GType
wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
301 static gboolean
wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
304 static GtkTreePath
*wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
306 static void wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
310 static gboolean
wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
312 static gboolean
wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
314 GtkTreeIter
*parent
);
315 static gboolean
wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
317 static gint
wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
319 static gboolean
wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
323 static gboolean
wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
328 static gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
329 gint
*sort_column_id
,
331 static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
334 static void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
336 GtkTreeIterCompareFunc func
,
338 GtkDestroyNotify destroy
);
339 static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
340 GtkTreeIterCompareFunc func
,
342 GtkDestroyNotify destroy
);
343 static gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
);
346 static gboolean
wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
348 static gboolean
wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
350 static gboolean
wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
352 GtkSelectionData
*selection_data
);
353 static gboolean
wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
355 GtkSelectionData
*selection_data
);
356 static gboolean
wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
357 GtkTreePath
*dest_path
,
358 GtkSelectionData
*selection_data
);
361 static GObjectClass
*list_parent_class
= NULL
;
364 gtk_wx_tree_model_get_type (void)
366 static GType tree_model_type
= 0;
368 if (!tree_model_type
)
370 const GTypeInfo tree_model_info
=
372 sizeof (GtkWxTreeModelClass
),
373 NULL
, /* base_init */
374 NULL
, /* base_finalize */
375 (GClassInitFunc
) wxgtk_tree_model_class_init
,
376 NULL
, /* class_finalize */
377 NULL
, /* class_data */
378 sizeof (GtkWxTreeModel
),
380 (GInstanceInitFunc
) wxgtk_tree_model_init
,
383 static const GInterfaceInfo tree_model_iface_info
=
385 (GInterfaceInitFunc
) wxgtk_tree_model_tree_model_init
,
390 static const GInterfaceInfo sortable_iface_info
=
392 (GInterfaceInitFunc
) wxgtk_tree_model_sortable_init
,
397 static const GInterfaceInfo drag_source_iface_info
=
399 (GInterfaceInitFunc
) wxgtk_tree_model_drag_source_init
,
404 static const GInterfaceInfo drag_dest_iface_info
=
406 (GInterfaceInitFunc
) wxgtk_tree_model_drag_dest_init
,
411 tree_model_type
= g_type_register_static (G_TYPE_OBJECT
, "GtkWxTreeModel",
412 &tree_model_info
, (GTypeFlags
)0 );
414 g_type_add_interface_static (tree_model_type
,
416 &tree_model_iface_info
);
417 g_type_add_interface_static (tree_model_type
,
418 GTK_TYPE_TREE_SORTABLE
,
419 &sortable_iface_info
);
420 g_type_add_interface_static (tree_model_type
,
421 GTK_TYPE_TREE_DRAG_DEST
,
422 &drag_dest_iface_info
);
423 g_type_add_interface_static (tree_model_type
,
424 GTK_TYPE_TREE_DRAG_SOURCE
,
425 &drag_source_iface_info
);
428 return tree_model_type
;
431 static GtkWxTreeModel
*
432 wxgtk_tree_model_new(void)
434 GtkWxTreeModel
*retval
= (GtkWxTreeModel
*) g_object_new (GTK_TYPE_WX_TREE_MODEL
, NULL
);
439 wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
)
441 list_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
442 GObjectClass
*object_class
= (GObjectClass
*) klass
;
443 object_class
->finalize
= wxgtk_tree_model_finalize
;
447 wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
)
449 iface
->get_flags
= wxgtk_tree_model_get_flags
;
450 iface
->get_n_columns
= wxgtk_tree_model_get_n_columns
;
451 iface
->get_column_type
= wxgtk_tree_model_get_column_type
;
452 iface
->get_iter
= wxgtk_tree_model_get_iter
;
453 iface
->get_path
= wxgtk_tree_model_get_path
;
454 iface
->get_value
= wxgtk_tree_model_get_value
;
455 iface
->iter_next
= wxgtk_tree_model_iter_next
;
456 iface
->iter_children
= wxgtk_tree_model_iter_children
;
457 iface
->iter_has_child
= wxgtk_tree_model_iter_has_child
;
458 iface
->iter_n_children
= wxgtk_tree_model_iter_n_children
;
459 iface
->iter_nth_child
= wxgtk_tree_model_iter_nth_child
;
460 iface
->iter_parent
= wxgtk_tree_model_iter_parent
;
464 wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
)
466 iface
->get_sort_column_id
= wxgtk_tree_model_get_sort_column_id
;
467 iface
->set_sort_column_id
= wxgtk_tree_model_set_sort_column_id
;
468 iface
->set_sort_func
= wxgtk_tree_model_set_sort_func
;
469 iface
->set_default_sort_func
= wxgtk_tree_model_set_default_sort_func
;
470 iface
->has_default_sort_func
= wxgtk_tree_model_has_default_sort_func
;
474 wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
)
476 iface
->row_draggable
= wxgtk_tree_model_row_draggable
;
477 iface
->drag_data_delete
= wxgtk_tree_model_drag_data_delete
;
478 iface
->drag_data_get
= wxgtk_tree_model_drag_data_get
;
482 wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
)
484 iface
->drag_data_received
= wxgtk_tree_model_drag_data_received
;
485 iface
->row_drop_possible
= wxgtk_tree_model_row_drop_possible
;
489 wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
)
491 tree_model
->internal
= NULL
;
492 tree_model
->stamp
= g_random_int();
496 wxgtk_tree_model_finalize (GObject
*object
)
499 (* list_parent_class
->finalize
) (object
);
504 //-----------------------------------------------------------------------------
505 // implement callbacks from wxGtkTreeModel class by letting
506 // them call the methods of wxWidgets' wxDataViewModel
507 //-----------------------------------------------------------------------------
509 static GtkTreeModelFlags
510 wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
)
512 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
513 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), (GtkTreeModelFlags
)0 );
515 return wxtree_model
->internal
->get_flags();
519 wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
)
521 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
522 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
524 return wxtree_model
->internal
->GetDataViewModel()->GetColumnCount();
528 wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
531 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
532 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), G_TYPE_INVALID
);
534 GType gtype
= G_TYPE_INVALID
;
536 wxString wxtype
= wxtree_model
->internal
->GetDataViewModel()->GetColumnType( (unsigned int) index
);
538 if (wxtype
== wxT("string"))
539 gtype
= G_TYPE_STRING
;
542 gtype
= G_TYPE_STRING
;
543 // wxFAIL_MSG( wxT("non-string columns not supported yet") );
550 wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
554 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
555 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
556 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
558 return wxtree_model
->internal
->get_iter( iter
, path
);
562 wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
565 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
566 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), NULL
);
567 g_return_val_if_fail (iter
->stamp
== GTK_WX_TREE_MODEL (wxtree_model
)->stamp
, NULL
);
569 return wxtree_model
->internal
->get_path( iter
);
573 wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
578 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
579 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
) );
581 wxDataViewModel
*model
= wxtree_model
->internal
->GetDataViewModel();
582 wxString mtype
= model
->GetColumnType( (unsigned int) column
);
583 if (mtype
== wxT("string"))
586 g_value_init( value
, G_TYPE_STRING
);
587 wxDataViewItem
item( (void*) iter
->user_data
);
588 model
->GetValue( variant
, item
, (unsigned int) column
);
590 g_value_set_string( value
, variant
.GetString().utf8_str() );
594 wxFAIL_MSG( wxT("non-string columns not supported yet") );
599 wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
602 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
604 // This happens when clearing the view by calling .._set_model( NULL );
605 if (iter
->stamp
== 0) return FALSE
;
607 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
608 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
610 return wxtree_model
->internal
->iter_next( iter
);
614 wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
618 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
619 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
620 g_return_val_if_fail (wxtree_model
->stamp
== parent
->stamp
, FALSE
);
622 return wxtree_model
->internal
->iter_children( iter
, parent
);
626 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
629 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
630 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
631 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
633 return wxtree_model
->internal
->iter_has_child( iter
);
637 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
640 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
641 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
642 g_return_val_if_fail ( !iter
|| wxtree_model
->stamp
== iter
->stamp
, 0);
644 return wxtree_model
->internal
->iter_n_children( iter
);
648 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
653 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
654 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
656 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
660 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
664 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
665 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
666 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
668 return wxtree_model
->internal
->iter_parent( iter
, child
);
671 /* drag'n'drop iface */
673 wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
676 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
677 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
679 return wxtree_model
->internal
->row_draggable( drag_source
, path
);
683 wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
686 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
687 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
689 return wxtree_model
->internal
->drag_data_delete( drag_source
, path
);
693 wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
695 GtkSelectionData
*selection_data
)
697 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
698 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
701 wxPrintf( "drag_get_data\n");
703 wxGtkString
atom_selection(gdk_atom_name(selection_data
->selection
));
704 wxPrintf( "selection %s\n", wxString::FromAscii(atom_selection
) );
706 wxGtkString
atom_target(gdk_atom_name(selection_data
->target
));
707 wxPrintf( "target %s\n", wxString::FromAscii(atom_target
) );
709 wxGtkString
atom_type(gdk_atom_name(selection_data
->type
));
710 wxPrintf( "type %s\n", wxString::FromAscii(atom_type
) );
712 wxPrintf( "format %d\n", selection_data
->format
);
715 return wxtree_model
->internal
->drag_data_get( drag_source
, path
, selection_data
);
719 wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
721 GtkSelectionData
*selection_data
)
723 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
724 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
726 return wxtree_model
->internal
->drag_data_received( drag_dest
, dest
, selection_data
);
730 wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
731 GtkTreePath
*dest_path
,
732 GtkSelectionData
*selection_data
)
734 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
735 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
737 return wxtree_model
->internal
->row_drop_possible( drag_dest
, dest_path
, selection_data
);
742 wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
743 gint
*sort_column_id
,
746 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) sortable
;
748 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
750 if (!wxtree_model
->internal
->IsSorted())
753 *sort_column_id
= -1;
760 *sort_column_id
= wxtree_model
->internal
->GetSortColumn();
763 *order
= wxtree_model
->internal
->GetSortOrder();
768 wxDataViewColumn
*gs_lastLeftClickHeader
= NULL
;
771 wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
775 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
776 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
778 tree_model
->internal
->SetDataViewSortColumn( gs_lastLeftClickHeader
);
780 if ((sort_column_id
!= (gint
) tree_model
->internal
->GetSortColumn()) ||
781 (order
!= tree_model
->internal
->GetSortOrder()))
783 tree_model
->internal
->SetSortColumn( sort_column_id
);
784 tree_model
->internal
->SetSortOrder( order
);
786 gtk_tree_sortable_sort_column_changed (sortable
);
788 tree_model
->internal
->GetDataViewModel()->Resort();
791 if (gs_lastLeftClickHeader
)
793 wxDataViewCtrl
*dv
= tree_model
->internal
->GetOwner();
794 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, dv
->GetId() );
795 event
.SetDataViewColumn( gs_lastLeftClickHeader
);
796 event
.SetModel( dv
->GetModel() );
797 dv
->HandleWindowEvent( event
);
800 gs_lastLeftClickHeader
= NULL
;
804 wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
805 gint
WXUNUSED(sort_column_id
),
806 GtkTreeIterCompareFunc func
,
807 gpointer
WXUNUSED(data
),
808 GtkDestroyNotify
WXUNUSED(destroy
))
810 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
811 g_return_if_fail (func
!= NULL
);
815 wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
816 GtkTreeIterCompareFunc func
,
817 gpointer
WXUNUSED(data
),
818 GtkDestroyNotify
WXUNUSED(destroy
))
820 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
821 g_return_if_fail (func
!= NULL
);
823 //wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
824 // TODO: remove this code
828 wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
)
830 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
835 //-----------------------------------------------------------------------------
836 // define new GTK+ class GtkWxRendererText
837 //-----------------------------------------------------------------------------
841 #define GTK_TYPE_WX_CELL_RENDERER_TEXT (gtk_wx_cell_renderer_text_get_type ())
842 #define GTK_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererText))
843 #define GTK_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
844 #define GTK_IS_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT))
845 #define GTK_IS_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT))
846 #define GTK_WX_CELL_RENDERER_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
848 GType
gtk_wx_cell_renderer_text_get_type (void);
850 typedef struct _GtkWxCellRendererText GtkWxCellRendererText
;
851 typedef struct _GtkWxCellRendererTextClass GtkWxCellRendererTextClass
;
853 struct _GtkWxCellRendererText
855 GtkCellRendererText parent
;
857 wxDataViewRenderer
*wx_renderer
;
860 struct _GtkWxCellRendererTextClass
862 GtkCellRendererTextClass cell_parent_class
;
866 static GtkWxCellRendererText
*gtk_wx_cell_renderer_text_new (void);
867 static void gtk_wx_cell_renderer_text_init (
868 GtkWxCellRendererText
*cell
);
869 static void gtk_wx_cell_renderer_text_class_init(
870 GtkWxCellRendererTextClass
*klass
);
871 static void gtk_wx_cell_renderer_text_finalize (
873 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
874 GtkCellRenderer
*cell
,
878 GdkRectangle
*background_area
,
879 GdkRectangle
*cell_area
,
880 GtkCellRendererState flags
);
883 static GObjectClass
*text_cell_parent_class
= NULL
;
888 gtk_wx_cell_renderer_text_get_type (void)
890 static GType cell_wx_type
= 0;
894 const GTypeInfo cell_wx_info
=
896 sizeof (GtkWxCellRendererTextClass
),
897 NULL
, /* base_init */
898 NULL
, /* base_finalize */
899 (GClassInitFunc
) gtk_wx_cell_renderer_text_class_init
,
900 NULL
, /* class_finalize */
901 NULL
, /* class_data */
902 sizeof (GtkWxCellRendererText
),
904 (GInstanceInitFunc
) gtk_wx_cell_renderer_text_init
,
907 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER_TEXT
,
908 "GtkWxCellRendererText", &cell_wx_info
, (GTypeFlags
)0 );
915 gtk_wx_cell_renderer_text_init (GtkWxCellRendererText
*cell
)
917 cell
->wx_renderer
= NULL
;
921 gtk_wx_cell_renderer_text_class_init (GtkWxCellRendererTextClass
*klass
)
923 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
924 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
926 text_cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
928 object_class
->finalize
= gtk_wx_cell_renderer_text_finalize
;
930 cell_class
->start_editing
= gtk_wx_cell_renderer_text_start_editing
;
934 gtk_wx_cell_renderer_text_finalize (GObject
*object
)
937 (* G_OBJECT_CLASS (text_cell_parent_class
)->finalize
) (object
);
940 GtkWxCellRendererText
*
941 gtk_wx_cell_renderer_text_new (void)
943 return (GtkWxCellRendererText
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER_TEXT
, NULL
);
946 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
947 GtkCellRenderer
*gtk_renderer
,
951 GdkRectangle
*background_area
,
952 GdkRectangle
*cell_area
,
953 GtkCellRendererState flags
)
955 GtkWxCellRendererText
*wxgtk_renderer
= (GtkWxCellRendererText
*) gtk_renderer
;
956 wxDataViewRenderer
*wx_renderer
= wxgtk_renderer
->wx_renderer
;
958 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
960 wx_renderer
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
961 wxDataViewItem
item( (void*) iter
.user_data
);;
962 gtk_tree_path_free( treepath
);
964 wxDataViewColumn
*column
= wx_renderer
->GetOwner();
965 wxDataViewCtrl
*dv
= column
->GetOwner();
966 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, dv
->GetId() );
967 event
.SetDataViewColumn( column
);
968 event
.SetModel( dv
->GetModel() );
969 event
.SetColumn( wx_renderer
->GetOwner()->GetModelColumn() );
970 event
.SetItem( item
);
971 dv
->HandleWindowEvent( event
);
973 if (event
.IsAllowed())
974 return GTK_CELL_RENDERER_CLASS(text_cell_parent_class
)->
975 start_editing( gtk_renderer
, gdk_event
, widget
, path
, background_area
, cell_area
, flags
);
980 //-----------------------------------------------------------------------------
981 // define new GTK+ class GtkWxCellRenderer
982 //-----------------------------------------------------------------------------
986 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
987 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
988 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
989 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
990 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
991 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
993 GType
gtk_wx_cell_renderer_get_type (void);
995 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
996 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
998 struct _GtkWxCellRenderer
1000 GtkCellRenderer parent
;
1003 wxDataViewCustomRenderer
*cell
;
1007 struct _GtkWxCellRendererClass
1009 GtkCellRendererClass cell_parent_class
;
1013 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
1014 static void gtk_wx_cell_renderer_init (
1015 GtkWxCellRenderer
*cell
);
1016 static void gtk_wx_cell_renderer_class_init(
1017 GtkWxCellRendererClass
*klass
);
1018 static void gtk_wx_cell_renderer_finalize (
1020 static void gtk_wx_cell_renderer_get_size (
1021 GtkCellRenderer
*cell
,
1023 GdkRectangle
*rectangle
,
1028 static void gtk_wx_cell_renderer_render (
1029 GtkCellRenderer
*cell
,
1032 GdkRectangle
*background_area
,
1033 GdkRectangle
*cell_area
,
1034 GdkRectangle
*expose_area
,
1035 GtkCellRendererState flags
);
1036 static gboolean
gtk_wx_cell_renderer_activate(
1037 GtkCellRenderer
*cell
,
1041 GdkRectangle
*background_area
,
1042 GdkRectangle
*cell_area
,
1043 GtkCellRendererState flags
);
1044 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1045 GtkCellRenderer
*cell
,
1049 GdkRectangle
*background_area
,
1050 GdkRectangle
*cell_area
,
1051 GtkCellRendererState flags
);
1054 static GObjectClass
*cell_parent_class
= NULL
;
1059 gtk_wx_cell_renderer_get_type (void)
1061 static GType cell_wx_type
= 0;
1065 const GTypeInfo cell_wx_info
=
1067 sizeof (GtkWxCellRendererClass
),
1068 NULL
, /* base_init */
1069 NULL
, /* base_finalize */
1070 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
1071 NULL
, /* class_finalize */
1072 NULL
, /* class_data */
1073 sizeof (GtkWxCellRenderer
),
1074 0, /* n_preallocs */
1075 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
1078 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
1079 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
1082 return cell_wx_type
;
1086 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
1089 cell
->last_click
= 0;
1093 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
1095 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1096 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
1098 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
1100 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
1102 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
1103 cell_class
->render
= gtk_wx_cell_renderer_render
;
1104 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
1105 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
1109 gtk_wx_cell_renderer_finalize (GObject
*object
)
1112 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
1116 gtk_wx_cell_renderer_new (void)
1118 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
1121 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1122 GtkCellRenderer
*renderer
,
1123 GdkEvent
*WXUNUSED(event
),
1126 GdkRectangle
*WXUNUSED(background_area
),
1127 GdkRectangle
*cell_area
,
1128 GtkCellRendererState
WXUNUSED(flags
) )
1130 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1131 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1133 // Renderer doesn't support in-place editing
1134 if (!cell
->HasEditorCtrl())
1137 // An in-place editing control is still around
1138 if (cell
->GetEditorCtrl())
1142 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1148 rect
.x
+= cell_area
->x
;
1149 rect
.y
+= cell_area
->y
;
1150 // rect.width -= renderer->xpad * 2;
1151 // rect.height -= renderer->ypad * 2;
1153 // wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
1154 wxRect
renderrect( cell_area
->x
, cell_area
->y
, cell_area
->width
, cell_area
->height
);
1156 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
1158 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
1159 wxDataViewItem
item( (void*) iter
.user_data
);
1160 gtk_tree_path_free( treepath
);
1162 cell
->StartEditing( item
, renderrect
);
1168 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
1169 GtkWidget
*WXUNUSED(widget
),
1170 GdkRectangle
*cell_area
,
1176 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1177 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1179 wxSize size
= cell
->GetSize();
1181 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
1182 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
1189 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
1193 *x_offset
= (gint
)((renderer
->xalign
*
1194 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
1195 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
1199 *y_offset
= (gint
)((renderer
->yalign
*
1200 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
1201 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
1206 *width
= calc_width
;
1209 *height
= calc_height
;
1213 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
1216 GdkRectangle
*background_area
,
1217 GdkRectangle
*cell_area
,
1218 GdkRectangle
*expose_area
,
1219 GtkCellRendererState flags
)
1222 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1223 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1225 cell
->window
= window
;
1226 cell
->widget
= widget
;
1227 cell
->background_area
= (void*) background_area
;
1228 cell
->cell_area
= (void*) cell_area
;
1229 cell
->expose_area
= (void*) expose_area
;
1230 cell
->flags
= (int) flags
;
1233 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1239 rect
.x
+= cell_area
->x
;
1240 rect
.y
+= cell_area
->y
;
1241 rect
.width
-= renderer
->xpad
* 2;
1242 rect
.height
-= renderer
->ypad
* 2;
1245 if (gdk_rectangle_intersect (expose_area
, &rect
, &dummy
))
1247 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1248 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
1249 wxWindowDCImpl
*impl
= (wxWindowDCImpl
*) dc
->GetImpl();
1251 // Reinitialize wxWindowDC's GDK window if drawing occurs into a different
1252 // window such as a DnD drop window.
1253 if (window
!= impl
->m_gdkwindow
)
1256 impl
->m_gdkwindow
= window
;
1261 if (flags
& GTK_CELL_RENDERER_SELECTED
)
1262 state
|= wxDATAVIEW_CELL_SELECTED
;
1263 if (flags
& GTK_CELL_RENDERER_PRELIT
)
1264 state
|= wxDATAVIEW_CELL_PRELIT
;
1265 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1266 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1267 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1268 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1269 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
1270 state
|= wxDATAVIEW_CELL_FOCUSED
;
1271 cell
->Render( renderrect
, dc
, state
);
1276 gtk_wx_cell_renderer_activate(
1277 GtkCellRenderer
*renderer
,
1281 GdkRectangle
*WXUNUSED(background_area
),
1282 GdkRectangle
*cell_area
,
1283 GtkCellRendererState
WXUNUSED(flags
) )
1285 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1286 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1289 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1295 rect
.x
+= cell_area
->x
;
1296 rect
.y
+= cell_area
->y
;
1297 rect
.width
-= renderer
->xpad
* 2;
1298 rect
.height
-= renderer
->ypad
* 2;
1300 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1302 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1304 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
1307 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
1308 wxDataViewItem
item( iter
.user_data
);
1309 gtk_tree_path_free( treepath
);
1311 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1317 // activated by <ENTER>
1318 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1323 else if (event
->type
== GDK_BUTTON_PRESS
)
1325 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
1326 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
1327 ((int) button_event
->y
) - renderrect
.y
);
1330 if (button_event
->button
== 1)
1332 if (cell
->LeftClick( pt
, renderrect
, model
, item
, model_col
))
1334 // TODO: query system double-click time
1335 if (button_event
->time
- wxrenderer
->last_click
< 400)
1336 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1339 wxrenderer
->last_click
= button_event
->time
;
1347 // ---------------------------------------------------------
1348 // wxGtkDataViewModelNotifier
1349 // ---------------------------------------------------------
1351 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1354 wxGtkDataViewModelNotifier( GtkWxTreeModel
*wxgtk_model
,
1355 wxDataViewModel
*wx_model
,
1356 wxDataViewCtrl
*ctrl
);
1357 ~wxGtkDataViewModelNotifier();
1359 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1360 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1361 virtual bool ItemChanged( const wxDataViewItem
&item
);
1362 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
1363 virtual bool Cleared();
1364 virtual void Resort();
1366 void SetGtkModel( GtkWxTreeModel
*model
) { m_wxgtk_model
= model
; }
1369 GtkWxTreeModel
*m_wxgtk_model
;
1370 wxDataViewModel
*m_wx_model
;
1371 wxDataViewCtrl
*m_owner
;
1374 // ---------------------------------------------------------
1375 // wxGtkDataViewListModelNotifier
1376 // ---------------------------------------------------------
1378 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1379 GtkWxTreeModel
* wxgtk_model
, wxDataViewModel
*wx_model
,
1380 wxDataViewCtrl
*ctrl
)
1382 m_wxgtk_model
= wxgtk_model
;
1383 m_wx_model
= wx_model
;
1387 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1390 m_wxgtk_model
= NULL
;
1393 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1395 m_owner
->GtkGetInternal()->ItemAdded( parent
, item
);
1398 iter
.stamp
= m_wxgtk_model
->stamp
;
1399 iter
.user_data
= (gpointer
) item
.GetID();
1401 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1402 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1403 gtk_tree_model_row_inserted(
1404 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1405 gtk_tree_path_free (path
);
1410 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1413 iter
.stamp
= m_wxgtk_model
->stamp
;
1414 iter
.user_data
= (gpointer
) item
.GetID();
1416 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1417 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1418 gtk_tree_model_row_deleted(
1419 GTK_TREE_MODEL(m_wxgtk_model
), path
);
1420 gtk_tree_path_free (path
);
1422 m_owner
->GtkGetInternal()->ItemDeleted( parent
, item
);
1427 void wxGtkDataViewModelNotifier::Resort()
1429 m_owner
->GtkGetInternal()->Resort();
1432 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1435 iter
.stamp
= m_wxgtk_model
->stamp
;
1436 iter
.user_data
= (gpointer
) item
.GetID();
1438 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1439 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1440 gtk_tree_model_row_changed(
1441 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1442 gtk_tree_path_free (path
);
1444 m_owner
->GtkGetInternal()->ItemChanged( item
);
1449 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_col
)
1451 // This adds GTK+'s missing MVC logic for ValueChanged
1453 for (index
= 0; index
< m_owner
->GetColumnCount(); index
++)
1455 wxDataViewColumn
*column
= m_owner
->GetColumn( index
);
1456 if (column
->GetModelColumn() == model_col
)
1458 GtkTreeView
*widget
= GTK_TREE_VIEW(m_owner
->m_treeview
);
1459 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1463 iter
.stamp
= m_wxgtk_model
->stamp
;
1464 iter
.user_data
= (gpointer
) item
.GetID();
1465 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1466 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1467 GdkRectangle cell_area
;
1468 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1469 gtk_tree_path_free( path
);
1471 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1472 double d
= gtk_adjustment_get_value( hadjust
);
1473 int xdiff
= (int) d
;
1475 int ydiff
= gcolumn
->button
->allocation
.height
;
1477 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1478 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1480 m_owner
->GtkGetInternal()->ValueChanged( item
, model_col
);
1489 bool wxGtkDataViewModelNotifier::Cleared()
1491 m_owner
->GtkGetInternal()->Cleared();
1496 // ---------------------------------------------------------
1497 // wxDataViewRenderer
1498 // ---------------------------------------------------------
1500 static gpointer s_user_data
= NULL
;
1503 wxgtk_cell_editable_editing_done( GtkCellEditable
*WXUNUSED(editable
),
1504 wxDataViewRenderer
*wxrenderer
)
1506 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1507 wxDataViewCtrl
*dv
= column
->GetOwner();
1508 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1509 event
.SetDataViewColumn( column
);
1510 event
.SetModel( dv
->GetModel() );
1511 wxDataViewItem
item( s_user_data
);
1512 event
.SetItem( item
);
1513 dv
->HandleWindowEvent( event
);
1517 wxgtk_renderer_editing_started( GtkCellRenderer
*WXUNUSED(cell
), GtkCellEditable
*editable
,
1518 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1523 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1524 wxDataViewCtrl
*dv
= column
->GetOwner();
1525 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1526 event
.SetDataViewColumn( column
);
1527 event
.SetModel( dv
->GetModel() );
1528 GtkTreePath
*tree_path
= gtk_tree_path_new_from_string( path
);
1530 dv
->GtkGetInternal()->get_iter( &iter
, tree_path
);
1531 gtk_tree_path_free( tree_path
);
1532 wxDataViewItem
item( iter
.user_data
);
1533 event
.SetItem( item
);
1534 dv
->HandleWindowEvent( event
);
1536 if (GTK_IS_CELL_EDITABLE(editable
))
1538 s_user_data
= iter
.user_data
;
1540 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1541 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1542 (gpointer
) wxrenderer
);
1548 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1550 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1552 wxDataViewRendererBase( varianttype
, mode
, align
)
1556 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1557 // after the m_renderer pointer has been initialized
1560 void wxDataViewRenderer::GtkInitHandlers()
1562 if (!gtk_check_version(2,6,0))
1564 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1565 G_CALLBACK (wxgtk_renderer_editing_started
),
1570 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1572 GtkCellRendererMode gtkMode
;
1575 case wxDATAVIEW_CELL_INERT
:
1576 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1579 case wxDATAVIEW_CELL_ACTIVATABLE
:
1580 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1583 case wxDATAVIEW_CELL_EDITABLE
:
1584 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1588 wxFAIL_MSG( "unknown wxDataViewCellMode value" );
1592 // This value is most often ignored in GtkTreeView
1593 GValue gvalue
= { 0, };
1594 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1595 g_value_set_enum( &gvalue
, gtkMode
);
1596 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1597 g_value_unset( &gvalue
);
1600 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1602 wxDataViewCellMode ret
;
1605 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1607 switch (g_value_get_enum(&gvalue
))
1610 wxFAIL_MSG( "unknown GtkCellRendererMode value" );
1611 // fall through (we have to return something)
1613 case GTK_CELL_RENDERER_MODE_INERT
:
1614 ret
= wxDATAVIEW_CELL_INERT
;
1617 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1618 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1621 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1622 ret
= wxDATAVIEW_CELL_EDITABLE
;
1626 g_value_unset( &gvalue
);
1631 void wxDataViewRenderer::GtkUpdateAlignment()
1633 int align
= m_alignment
;
1635 // query alignment from column ?
1639 if (GetOwner() == NULL
)
1642 align
= GetOwner()->GetAlignment();
1643 align
|= wxALIGN_CENTRE_VERTICAL
;
1646 // horizontal alignment:
1648 gfloat xalign
= 0.0;
1649 if (align
& wxALIGN_RIGHT
)
1651 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1654 GValue gvalue
= { 0, };
1655 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1656 g_value_set_float( &gvalue
, xalign
);
1657 g_object_set_property( G_OBJECT(m_renderer
), "xalign", &gvalue
);
1658 g_value_unset( &gvalue
);
1660 // vertical alignment:
1662 gfloat yalign
= 0.0;
1663 if (align
& wxALIGN_BOTTOM
)
1665 else if (align
& wxALIGN_CENTER_VERTICAL
)
1668 GValue gvalue2
= { 0, };
1669 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1670 g_value_set_float( &gvalue2
, yalign
);
1671 g_object_set_property( G_OBJECT(m_renderer
), "yalign", &gvalue2
);
1672 g_value_unset( &gvalue2
);
1675 void wxDataViewRenderer::SetAlignment( int align
)
1677 m_alignment
= align
;
1678 GtkUpdateAlignment();
1681 int wxDataViewRenderer::GetAlignment() const
1686 // ---------------------------------------------------------
1687 // wxDataViewTextRenderer
1688 // ---------------------------------------------------------
1691 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1692 gchar
*arg1
, gchar
*arg2
, gpointer user_data
);
1695 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*WXUNUSED(renderer
),
1696 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1698 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) user_data
;
1700 wxString tmp
= wxGTK_CONV_BACK_FONT(arg2
, cell
->GetOwner()->GetOwner()->GetFont());
1701 wxVariant value
= tmp
;
1702 if (!cell
->Validate( value
))
1705 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1707 GtkTreePath
*path
= gtk_tree_path_new_from_string( arg1
);
1709 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, path
);
1710 wxDataViewItem
item( (void*) iter
.user_data
);;
1711 gtk_tree_path_free( path
);
1713 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1715 model
->SetValue( value
, item
, model_col
);
1716 model
->ValueChanged( item
, model_col
);
1719 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
1721 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1723 wxDataViewRenderer( varianttype
, mode
, align
)
1725 GtkWxCellRendererText
*text_renderer
= gtk_wx_cell_renderer_text_new();
1726 text_renderer
->wx_renderer
= this;
1727 m_renderer
= (GtkCellRenderer
*) text_renderer
;
1729 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
1731 GValue gvalue
= { 0, };
1732 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1733 g_value_set_boolean( &gvalue
, true );
1734 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
1735 g_value_unset( &gvalue
);
1737 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
1743 SetAlignment(align
);
1746 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
1748 wxString tmp
= value
;
1750 GValue gvalue
= { 0, };
1751 g_value_init( &gvalue
, G_TYPE_STRING
);
1752 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( tmp
, GetOwner()->GetOwner()->GetFont() ) );
1753 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1754 g_value_unset( &gvalue
);
1759 bool wxDataViewTextRenderer::GetValue( wxVariant
&value
) const
1761 GValue gvalue
= { 0, };
1762 g_value_init( &gvalue
, G_TYPE_STRING
);
1763 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1764 wxString tmp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
), const_cast<wxDataViewTextRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
1765 g_value_unset( &gvalue
);
1772 void wxDataViewTextRenderer::SetAlignment( int align
)
1774 wxDataViewRenderer::SetAlignment(align
);
1776 if (gtk_check_version(2,10,0))
1779 // horizontal alignment:
1780 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
1781 if (align
& wxALIGN_RIGHT
)
1782 pangoAlign
= PANGO_ALIGN_RIGHT
;
1783 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1784 pangoAlign
= PANGO_ALIGN_CENTER
;
1786 GValue gvalue
= { 0, };
1787 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1788 g_value_set_enum( &gvalue
, pangoAlign
);
1789 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
1790 g_value_unset( &gvalue
);
1793 // ---------------------------------------------------------
1794 // wxDataViewTextRendererAttr
1795 // ---------------------------------------------------------
1797 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
,wxDataViewTextRenderer
)
1799 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString
&varianttype
,
1800 wxDataViewCellMode mode
, int align
) :
1801 wxDataViewTextRenderer( varianttype
, mode
, align
)
1805 // ---------------------------------------------------------
1806 // wxDataViewBitmapRenderer
1807 // ---------------------------------------------------------
1809 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
1811 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1813 wxDataViewRenderer( varianttype
, mode
, align
)
1815 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_pixbuf_new();
1818 SetAlignment(align
);
1821 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
1823 if (value
.GetType() == wxT("wxBitmap"))
1828 // This may create a Pixbuf representation in the
1829 // wxBitmap object (and it will stay there)
1830 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1832 GValue gvalue
= { 0, };
1833 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1834 g_value_set_object( &gvalue
, pixbuf
);
1835 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1836 g_value_unset( &gvalue
);
1841 if (value
.GetType() == wxT("wxIcon"))
1846 // This may create a Pixbuf representation in the
1847 // wxBitmap object (and it will stay there)
1848 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1850 GValue gvalue
= { 0, };
1851 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1852 g_value_set_object( &gvalue
, pixbuf
);
1853 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1854 g_value_unset( &gvalue
);
1862 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
1867 // ---------------------------------------------------------
1868 // wxDataViewToggleRenderer
1869 // ---------------------------------------------------------
1872 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1873 gchar
*path
, gpointer user_data
);
1876 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1877 gchar
*path
, gpointer user_data
)
1879 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
1882 GValue gvalue
= { 0, };
1883 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1884 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
1885 bool tmp
= g_value_get_boolean( &gvalue
);
1886 g_value_unset( &gvalue
);
1890 wxVariant value
= tmp
;
1891 if (!cell
->Validate( value
))
1894 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1896 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
1898 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, gtk_path
);
1899 wxDataViewItem
item( (void*) iter
.user_data
);;
1900 gtk_tree_path_free( gtk_path
);
1902 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1904 model
->SetValue( value
, item
, model_col
);
1905 model
->ValueChanged( item
, model_col
);
1908 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1910 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1911 wxDataViewCellMode mode
, int align
) :
1912 wxDataViewRenderer( varianttype
, mode
, align
)
1914 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
1916 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1918 g_signal_connect_after( m_renderer
, "toggled",
1919 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
1923 GValue gvalue
= { 0, };
1924 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1925 g_value_set_boolean( &gvalue
, false );
1926 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
1927 g_value_unset( &gvalue
);
1931 SetAlignment(align
);
1934 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1938 GValue gvalue
= { 0, };
1939 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1940 g_value_set_boolean( &gvalue
, tmp
);
1941 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1942 g_value_unset( &gvalue
);
1947 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
1949 GValue gvalue
= { 0, };
1950 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1951 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1952 bool tmp
= g_value_get_boolean( &gvalue
);
1953 g_value_unset( &gvalue
);
1960 // ---------------------------------------------------------
1961 // wxDataViewCustomRenderer
1962 // ---------------------------------------------------------
1964 class wxDataViewCtrlDCImpl
: public wxWindowDCImpl
1967 wxDataViewCtrlDCImpl( wxDC
*owner
, wxDataViewCtrl
*window
) :
1968 wxWindowDCImpl( owner
)
1970 GtkWidget
*widget
= window
->m_treeview
;
1976 m_context
= window
->GTKGetPangoDefaultContext();
1977 m_layout
= pango_layout_new( m_context
);
1978 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
1980 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
1982 // Set m_gdkwindow later
1987 class wxDataViewCtrlDC
: public wxWindowDC
1990 wxDataViewCtrlDC( wxDataViewCtrl
*window
) :
1991 wxWindowDC( new wxDataViewCtrlDCImpl( this, window
) )
1996 // ---------------------------------------------------------
1997 // wxDataViewCustomRenderer
1998 // ---------------------------------------------------------
2000 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
2002 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
2003 wxDataViewCellMode mode
, int align
,
2005 wxDataViewRenderer( varianttype
, mode
, align
)
2008 m_text_renderer
= NULL
;
2016 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
,
2017 wxRect
WXUNUSED(cell
), wxDC
*WXUNUSED(dc
), int WXUNUSED(state
) )
2020 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
2021 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
2022 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
2023 view
->GetForegroundColour();
2024 dc
->SetTextForeground(col
);
2025 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
2027 if (!m_text_renderer
)
2028 m_text_renderer
= gtk_cell_renderer_text_new();
2030 GValue gvalue
= { 0, };
2031 g_value_init( &gvalue
, G_TYPE_STRING
);
2032 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( text
, GetOwner()->GetOwner()->GetFont() ) );
2033 g_object_set_property( G_OBJECT(m_text_renderer
), "text", &gvalue
);
2034 g_value_unset( &gvalue
);
2036 ((GdkRectangle
*) cell_area
)->x
+= xoffset
;
2037 ((GdkRectangle
*) cell_area
)->width
-= xoffset
;
2039 gtk_cell_renderer_render( m_text_renderer
,
2042 (GdkRectangle
*) background_area
,
2043 (GdkRectangle
*) cell_area
,
2044 (GdkRectangle
*) expose_area
,
2045 (GtkCellRendererState
) flags
);
2047 ((GdkRectangle
*) cell_area
)->x
-= xoffset
;
2048 ((GdkRectangle
*) cell_area
)->width
+= xoffset
;
2052 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
2054 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
2055 renderer
->cell
= this;
2057 m_renderer
= (GtkCellRenderer
*) renderer
;
2060 SetAlignment(align
);
2067 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
2072 if (m_text_renderer
)
2073 gtk_object_sink( GTK_OBJECT(m_text_renderer
) );
2076 wxDC
*wxDataViewCustomRenderer::GetDC()
2080 if (GetOwner() == NULL
)
2082 if (GetOwner()->GetOwner() == NULL
)
2084 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
2090 // ---------------------------------------------------------
2091 // wxDataViewProgressRenderer
2092 // ---------------------------------------------------------
2094 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
2096 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
2097 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
2098 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
2104 if (!gtk_check_version(2,6,0))
2106 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
2108 GValue gvalue
= { 0, };
2109 g_value_init( &gvalue
, G_TYPE_STRING
);
2111 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( m_label
, GetOwner()->GetOwner()->GetFont() ) );
2112 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2113 g_value_unset( &gvalue
);
2116 SetAlignment(align
);
2121 // Use custom cell code
2122 wxDataViewCustomRenderer::Init(mode
, align
);
2126 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
2130 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
2133 if (!gtk_check_version(2,6,0))
2135 gint tmp
= (long) value
;
2136 GValue gvalue
= { 0, };
2137 g_value_init( &gvalue
, G_TYPE_INT
);
2138 g_value_set_int( &gvalue
, tmp
);
2139 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
2140 g_value_unset( &gvalue
);
2145 m_value
= (long) value
;
2147 if (m_value
< 0) m_value
= 0;
2148 if (m_value
> 100) m_value
= 100;
2154 bool wxDataViewProgressRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2159 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
2161 double pct
= (double)m_value
/ 100.0;
2163 bar
.width
= (int)(cell
.width
* pct
);
2164 dc
->SetPen( *wxTRANSPARENT_PEN
);
2165 dc
->SetBrush( *wxBLUE_BRUSH
);
2166 dc
->DrawRectangle( bar
);
2168 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
2169 dc
->SetPen( *wxBLACK_PEN
);
2170 dc
->DrawRectangle( cell
);
2175 wxSize
wxDataViewProgressRenderer::GetSize() const
2177 return wxSize(40,12);
2180 // -------------------------------------
2181 // wxDataViewChoiceRenderer
2182 // -------------------------------------
2184 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
&choices
,
2185 wxDataViewCellMode mode
, int alignment
) :
2186 wxDataViewCustomRenderer( "string", mode
, alignment
, true )
2188 m_choices
= choices
;
2191 if (!gtk_check_version(2,6,0))
2193 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_combo_new();
2195 GtkListStore
*store
= gtk_list_store_new( 1, G_TYPE_STRING
);
2196 for (size_t n
= 0; n
< m_choices
.GetCount(); n
++)
2198 gtk_list_store_insert_with_values(
2200 static_cast<const char *>(m_choices
[n
].utf8_str()), -1 );
2203 g_object_set (m_renderer
,
2209 bool editable
= (mode
& wxDATAVIEW_CELL_EDITABLE
);
2210 g_object_set (m_renderer
, "editable", editable
, NULL
);
2212 SetAlignment(alignment
);
2214 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2221 // Use custom cell code
2222 wxDataViewCustomRenderer::Init(mode
, alignment
);
2226 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
2228 RenderText( m_data
, 0, rect
, dc
, state
);
2232 wxSize
wxDataViewChoiceRenderer::GetSize() const
2234 return wxSize(70,20);
2237 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
2241 if (!gtk_check_version(2,6,0))
2243 GValue gvalue
= { 0, };
2244 g_value_init( &gvalue
, G_TYPE_STRING
);
2245 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( value
.GetString(), GetOwner()->GetOwner()->GetFont() ) );
2246 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2247 g_value_unset( &gvalue
);
2251 m_data
= value
.GetString();
2256 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
2259 if (!gtk_check_version(2,6,0))
2261 GValue gvalue
= { 0, };
2262 g_value_init( &gvalue
, G_TYPE_STRING
);
2263 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2264 wxString temp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
),
2265 const_cast<wxDataViewChoiceRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
2266 g_value_unset( &gvalue
);
2269 //wxPrintf( "temp %s\n", temp );
2270 // TODO: remove this code
2279 void wxDataViewChoiceRenderer::SetAlignment( int align
)
2281 wxDataViewCustomRenderer::SetAlignment(align
);
2283 if (gtk_check_version(2,10,0))
2286 // horizontal alignment:
2287 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2288 if (align
& wxALIGN_RIGHT
)
2289 pangoAlign
= PANGO_ALIGN_RIGHT
;
2290 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2291 pangoAlign
= PANGO_ALIGN_CENTER
;
2293 GValue gvalue
= { 0, };
2294 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2295 g_value_set_enum( &gvalue
, pangoAlign
);
2296 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2297 g_value_unset( &gvalue
);
2300 // ---------------------------------------------------------
2301 // wxDataViewDateRenderer
2302 // ---------------------------------------------------------
2304 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
2307 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
2308 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
2309 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
2314 m_cal
= new wxCalendarCtrl( this, -1, *value
);
2315 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
2316 sizer
->Add( m_cal
, 1, wxGROW
);
2321 virtual void OnDismiss()
2325 void OnCalendar( wxCalendarEvent
&event
);
2327 wxCalendarCtrl
*m_cal
;
2328 wxDataViewModel
*m_model
;
2329 wxDataViewItem m_item
;
2333 DECLARE_EVENT_TABLE()
2336 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
2337 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
2340 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
2342 wxDateTime date
= event
.GetDate();
2343 wxVariant value
= date
;
2344 m_model
->SetValue( value
, m_item
, m_col
);
2345 m_model
->ValueChanged( m_item
, m_col
);
2349 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
2351 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
2352 wxDataViewCellMode mode
, int align
) :
2353 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2356 SetAlignment(align
);
2359 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
2361 m_date
= value
.GetDateTime();
2366 bool wxDataViewDateRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2371 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2373 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
2374 wxString tmp
= m_date
.FormatDate();
2375 RenderText( tmp
, 0, cell
, dc
, state
);
2379 wxSize
wxDataViewDateRenderer::GetSize() const
2381 wxString tmp
= m_date
.FormatDate();
2383 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
2384 return wxSize(x
,y
+d
);
2387 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
2388 const wxDataViewItem
&item
, unsigned int col
)
2391 model
->GetValue( variant
, item
, col
);
2392 wxDateTime value
= variant
.GetDateTime();
2394 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
2395 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
2396 wxPoint pos
= wxGetMousePosition();
2399 popup
->Popup( popup
->m_cal
);
2405 // ---------------------------------------------------------
2406 // wxDataViewIconTextRenderer
2407 // ---------------------------------------------------------
2409 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
2411 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
2412 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
2413 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2416 SetAlignment(align
);
2419 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2423 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
2429 bool wxDataViewIconTextRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2434 bool wxDataViewIconTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2436 const wxIcon
&icon
= m_value
.GetIcon();
2440 int yoffset
= wxMax( 0, (cell
.height
- icon
.GetHeight()) / 2 );
2441 dc
->DrawIcon( icon
, cell
.x
, cell
.y
+ yoffset
);
2442 offset
= icon
.GetWidth() + 4;
2445 RenderText( m_value
.GetText(), offset
, cell
, dc
, state
);
2450 wxSize
wxDataViewIconTextRenderer::GetSize() const
2453 if (m_value
.GetIcon().IsOk())
2454 size
.x
= 4 + m_value
.GetIcon().GetWidth();
2456 GetView()->GetTextExtent( m_value
.GetText(), &x
, &y
, &d
);
2462 wxControl
* wxDataViewIconTextRenderer::CreateEditorCtrl(
2463 wxWindow
*WXUNUSED(parent
), wxRect
WXUNUSED(labelRect
), const wxVariant
&WXUNUSED(value
) )
2468 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl(
2469 wxControl
* WXUNUSED(editor
), wxVariant
&WXUNUSED(value
) )
2474 // ---------------------------------------------------------
2476 // ---------------------------------------------------------
2480 gtk_dataview_header_button_press_callback( GtkWidget
*WXUNUSED(widget
),
2481 GdkEventButton
*gdk_event
,
2482 wxDataViewColumn
*column
)
2484 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
2487 if (gdk_event
->button
== 1)
2489 gs_lastLeftClickHeader
= column
;
2491 wxDataViewCtrl
*dv
= column
->GetOwner();
2492 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
2493 event
.SetDataViewColumn( column
);
2494 event
.SetModel( dv
->GetModel() );
2495 if (dv
->HandleWindowEvent( event
))
2499 if (gdk_event
->button
== 3)
2501 wxDataViewCtrl
*dv
= column
->GetOwner();
2502 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
2503 event
.SetDataViewColumn( column
);
2504 event
.SetModel( dv
->GetModel() );
2505 if (dv
->HandleWindowEvent( event
))
2513 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
2514 GtkCellRenderer
*cell
,
2515 GtkTreeModel
*model
,
2521 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*WXUNUSED(column
),
2522 GtkCellRenderer
*renderer
,
2523 GtkTreeModel
*model
,
2527 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2528 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2530 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2532 wxDataViewItem
item( (void*) iter
->user_data
);
2534 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
2536 if (!wx_model
->IsVirtualListModel())
2539 if (wx_model
->IsContainer( item
))
2541 if (wx_model
->HasContainerColumns( item
) || (cell
->GetOwner()->GetModelColumn() == 0))
2543 GValue gvalue
= { 0, };
2544 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2545 g_value_set_boolean( &gvalue
, TRUE
);
2546 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2547 g_value_unset( &gvalue
);
2551 GValue gvalue
= { 0, };
2552 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2553 g_value_set_boolean( &gvalue
, FALSE
);
2554 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2555 g_value_unset( &gvalue
);
2562 GValue gvalue
= { 0, };
2563 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2564 g_value_set_boolean( &gvalue
, TRUE
);
2565 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2566 g_value_unset( &gvalue
);
2572 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
2574 if (value
.GetType() != cell
->GetVariantType())
2576 wxLogError( wxT("Wrong type, required: %s but: %s"),
2577 value
.GetType().c_str(),
2578 cell
->GetVariantType().c_str() );
2581 cell
->SetValue( value
);
2583 if (cell
->GtkHasAttributes())
2585 wxDataViewItemAttr attr
;
2586 bool colour_set
= false;
2587 bool style_set
= false;
2588 bool weight_set
= false;
2590 if (wx_model
->GetAttr( item
, cell
->GetOwner()->GetModelColumn(), attr
))
2592 // this must be a GtkCellRendererText
2593 wxColour colour
= attr
.GetColour();
2596 const GdkColor
* const gcol
= colour
.GetColor();
2598 GValue gvalue
= { 0, };
2599 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2600 g_value_set_boxed( &gvalue
, gcol
);
2601 g_object_set_property( G_OBJECT(renderer
), "foreground_gdk", &gvalue
);
2602 g_value_unset( &gvalue
);
2607 if (attr
.GetItalic())
2609 GValue gvalue
= { 0, };
2610 g_value_init( &gvalue
, PANGO_TYPE_STYLE
);
2611 g_value_set_enum( &gvalue
, PANGO_STYLE_ITALIC
);
2612 g_object_set_property( G_OBJECT(renderer
), "style", &gvalue
);
2613 g_value_unset( &gvalue
);
2620 GValue gvalue
= { 0, };
2621 g_value_init( &gvalue
, PANGO_TYPE_WEIGHT
);
2622 g_value_set_enum( &gvalue
, PANGO_WEIGHT_BOLD
);
2623 g_object_set_property( G_OBJECT(renderer
), "weight", &gvalue
);
2624 g_value_unset( &gvalue
);
2632 GValue gvalue
= { 0, };
2633 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2634 g_value_set_boolean( &gvalue
, FALSE
);
2635 g_object_set_property( G_OBJECT(renderer
), "style-set", &gvalue
);
2636 g_value_unset( &gvalue
);
2641 GValue gvalue
= { 0, };
2642 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2643 g_value_set_boolean( &gvalue
, FALSE
);
2644 g_object_set_property( G_OBJECT(renderer
), "weight-set", &gvalue
);
2645 g_value_unset( &gvalue
);
2650 GValue gvalue
= { 0, };
2651 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2652 g_value_set_boolean( &gvalue
, FALSE
);
2653 g_object_set_property( G_OBJECT(renderer
), "foreground-set", &gvalue
);
2654 g_value_unset( &gvalue
);
2659 if (attr
.HasBackgroundColour())
2661 wxColour colour
= attr
.GetBackgroundColour();
2662 const GdkColor
* const gcol
= colour
.GetColor();
2664 GValue gvalue
= { 0, };
2665 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2666 g_value_set_boxed( &gvalue
, gcol
);
2667 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
2668 g_value_unset( &gvalue
);
2672 GValue gvalue
= { 0, };
2673 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2674 g_value_set_boolean( &gvalue
, FALSE
);
2675 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
2676 g_value_unset( &gvalue
);
2682 #include <wx/listimpl.cpp>
2683 WX_DEFINE_LIST(wxDataViewColumnList
)
2685 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
2686 unsigned int model_column
, int width
,
2687 wxAlignment align
, int flags
)
2688 : wxDataViewColumnBase( cell
, model_column
)
2690 Init( align
, flags
, width
);
2695 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
2696 unsigned int model_column
, int width
,
2697 wxAlignment align
, int flags
)
2698 : wxDataViewColumnBase( bitmap
, cell
, model_column
)
2700 Init( align
, flags
, width
);
2702 SetBitmap( bitmap
);
2705 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
2707 m_isConnected
= false;
2709 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) GetRenderer()->GetGtkHandle();
2710 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
2711 m_column
= (GtkWidget
*) column
;
2714 SetAlignment( align
);
2718 // Create container for icon and label
2719 GtkWidget
*box
= gtk_hbox_new( FALSE
, 1 );
2720 gtk_widget_show( box
);
2721 // gtk_container_set_border_width((GtkContainer*)box, 2);
2722 m_image
= gtk_image_new();
2723 gtk_box_pack_start(GTK_BOX(box
), m_image
, FALSE
, FALSE
, 1);
2724 m_label
= gtk_label_new("");
2725 gtk_box_pack_end( GTK_BOX(box
), GTK_WIDGET(m_label
), FALSE
, FALSE
, 1 );
2726 gtk_tree_view_column_set_widget( column
, box
);
2728 gtk_tree_view_column_pack_end( column
, renderer
, TRUE
);
2730 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
2731 wxGtkTreeCellDataFunc
, (gpointer
) GetRenderer(), NULL
);
2734 void wxDataViewColumn::OnInternalIdle()
2739 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
2741 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2744 g_signal_connect(column
->button
, "button_press_event",
2745 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
2747 m_isConnected
= true;
2752 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
2754 wxDataViewColumnBase::SetOwner( owner
);
2756 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2758 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
2761 void wxDataViewColumn::SetTitle( const wxString
&title
)
2763 wxDataViewCtrl
*ctrl
= GetOwner();
2764 gtk_label_set_text( GTK_LABEL(m_label
), ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
2765 : wxGTK_CONV_SYS(title
) );
2767 gtk_widget_hide( m_label
);
2769 gtk_widget_show( m_label
);
2772 wxString
wxDataViewColumn::GetTitle() const
2774 return wxGTK_CONV_BACK_FONT(
2775 gtk_label_get_text( GTK_LABEL(m_label
) ),
2776 GetOwner()->GetFont()
2780 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
2782 wxDataViewColumnBase::SetBitmap( bitmap
);
2786 GtkImage
*gtk_image
= GTK_IMAGE(m_image
);
2788 GdkBitmap
*mask
= NULL
;
2789 if (bitmap
.GetMask())
2790 mask
= bitmap
.GetMask()->GetBitmap();
2792 if (bitmap
.HasPixbuf())
2794 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
2795 bitmap
.GetPixbuf());
2799 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
2800 bitmap
.GetPixmap(), mask
);
2802 gtk_widget_show( m_image
);
2806 gtk_widget_hide( m_image
);
2810 void wxDataViewColumn::SetHidden( bool hidden
)
2812 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
2815 void wxDataViewColumn::SetResizeable( bool resizeable
)
2817 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizeable
);
2820 void wxDataViewColumn::SetAlignment( wxAlignment align
)
2822 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2824 gfloat xalign
= 0.0;
2825 if (align
== wxALIGN_RIGHT
)
2827 if (align
== wxALIGN_CENTER_HORIZONTAL
||
2828 align
== wxALIGN_CENTER
)
2831 gtk_tree_view_column_set_alignment( column
, xalign
);
2833 if (m_renderer
&& m_renderer
->GetAlignment() == -1)
2834 m_renderer
->GtkUpdateAlignment();
2837 wxAlignment
wxDataViewColumn::GetAlignment() const
2839 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
2842 return wxALIGN_RIGHT
;
2844 return wxALIGN_CENTER_HORIZONTAL
;
2846 return wxALIGN_LEFT
;
2849 void wxDataViewColumn::SetSortable( bool sortable
)
2851 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2855 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
2859 gtk_tree_view_column_set_sort_column_id( column
, -1 );
2860 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
2861 gtk_tree_view_column_set_clickable( column
, FALSE
);
2865 bool wxDataViewColumn::IsSortable() const
2867 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2868 return gtk_tree_view_column_get_clickable( column
);
2871 void wxDataViewColumn::SetAsSortKey( bool WXUNUSED(sort
) )
2873 // it might not make sense to have this function in wxHeaderColumn at
2874 // all in fact, changing of the sort order should only be done using the
2875 // associated control API
2876 wxFAIL_MSG( "not implemented" );
2879 bool wxDataViewColumn::IsSortKey() const
2881 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2882 return gtk_tree_view_column_get_sort_indicator( column
);
2885 bool wxDataViewColumn::IsResizeable() const
2887 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2888 return gtk_tree_view_column_get_resizable( column
);
2891 bool wxDataViewColumn::IsHidden() const
2893 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2894 return !gtk_tree_view_column_get_visible( column
);
2897 void wxDataViewColumn::SetSortOrder( bool ascending
)
2899 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2902 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
2904 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
2906 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
2909 bool wxDataViewColumn::IsSortOrderAscending() const
2911 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2913 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
2916 void wxDataViewColumn::SetMinWidth( int width
)
2918 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2921 int wxDataViewColumn::GetMinWidth() const
2923 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2926 int wxDataViewColumn::GetWidth() const
2928 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2931 void wxDataViewColumn::SetWidth( int width
)
2936 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
2938 // TODO find a better calculation
2939 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), wxDVC_DEFAULT_WIDTH
);
2941 // this is unpractical for large numbers of items and disables
2942 // user resizing, which is totally unexpected
2943 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
2948 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
2950 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2954 void wxDataViewColumn::SetReorderable( bool reorderable
)
2956 gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column
), reorderable
);
2959 bool wxDataViewColumn::IsReorderable() const
2961 return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column
) );
2964 //-----------------------------------------------------------------------------
2965 // wxGtkTreeModelNode
2966 //-----------------------------------------------------------------------------
2969 class wxGtkTreeModelChildWithPos
2977 int wxGtkTreeModelChildWithPosCmp( const void* data1
, const void* data2
, const void* user_data
)
2979 const wxGtkTreeModelChildWithPos
* child1
= (const wxGtkTreeModelChildWithPos
*) data1
;
2980 const wxGtkTreeModelChildWithPos
* child2
= (const wxGtkTreeModelChildWithPos
*) data2
;
2981 const wxDataViewCtrlInternal
*internal
= (const wxDataViewCtrlInternal
*) user_data
;
2982 int ret
= internal
->GetDataViewModel()->Compare( child1
->id
, child2
->id
,
2983 internal
->GetSortColumn(), (internal
->GetSortOrder() == GTK_SORT_DESCENDING
) );
2989 int LINKAGEMODE
wxGtkTreeModelChildPtrCmp( void*** data1
, void*** data2
)
2991 return gs_internal
->GetDataViewModel()->Compare( **data1
, **data2
,
2992 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
2995 WX_DEFINE_ARRAY_PTR( void**, wxGtkTreeModelChildrenPtr
);
2998 void wxGtkTreeModelNode::Resort()
3000 size_t child_count
= GetChildCount();
3001 if (child_count
== 0)
3004 size_t node_count
= GetNodesCount();
3006 if (child_count
== 1)
3008 if (node_count
== 1)
3010 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
3016 gint
*new_order
= new gint
[child_count
];
3019 // m_children has the original *void
3020 // ptrs points to these
3021 wxGtkTreeModelChildrenPtr ptrs
;
3023 for (i
= 0; i
< child_count
; i
++)
3024 ptrs
.Add( &(m_children
[i
]) );
3026 gs_internal
= m_internal
;
3027 ptrs
.Sort( &wxGtkTreeModelChildPtrCmp
);
3029 wxGtkTreeModelChildren temp
;
3030 void** base_ptr
= &(m_children
[0]);
3031 // Transfer positions to new_order array and
3033 for (i
= 0; i
< child_count
; i
++)
3035 new_order
[i
] = ptrs
[i
] - base_ptr
;
3036 temp
.Add( *ptrs
[i
] );
3039 // Transfer IDs back to m_children
3041 WX_APPEND_ARRAY( temp
, m_children
);
3046 // Build up array with IDs and original positions
3047 wxGtkTreeModelChildWithPos
* temp
= new wxGtkTreeModelChildWithPos
[child_count
];
3049 for (i
= 0; i
< child_count
; i
++)
3052 temp
[i
].id
= m_children
[i
];
3054 // Sort array keeping original positions
3055 wxQsort( temp
, child_count
, sizeof(wxGtkTreeModelChildWithPos
),
3056 &wxGtkTreeModelChildWithPosCmp
, m_internal
);
3057 // Transfer positions to new_order array and
3058 // IDs to m_children
3060 for (i
= 0; i
< child_count
; i
++)
3062 new_order
[i
] = temp
[i
].pos
;
3063 m_children
.Add( temp
[i
].id
);
3072 wxGtkTreeModelChildren temp
;
3073 WX_APPEND_ARRAY( temp
, m_children
);
3075 gs_internal
= m_internal
;
3076 m_children
.Sort( &wxGtkTreeModelChildCmp
);
3079 for (pos
= 0; pos
< child_count
; pos
++)
3081 void *id
= m_children
.Item( pos
);
3082 int old_pos
= temp
.Index( id
);
3083 new_order
[pos
] = old_pos
;
3087 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
3090 iter
.user_data
= GetItem().GetID();
3091 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
3093 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3095 gtk_tree_model_rows_reordered( gtk_tree_model
, path
, &iter
, new_order
);
3097 gtk_tree_path_free (path
);
3099 delete [] new_order
;
3102 for (pos
= 0; pos
< node_count
; pos
++)
3104 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
3109 //-----------------------------------------------------------------------------
3110 // wxDataViewCtrlInternal
3111 //-----------------------------------------------------------------------------
3113 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
,
3114 wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
)
3117 m_wx_model
= wx_model
;
3118 m_gtk_model
= gtk_model
;
3120 m_sort_order
= GTK_SORT_ASCENDING
;
3122 m_dataview_sort_column
= NULL
;
3124 m_dragDataObject
= NULL
;
3125 m_dropDataObject
= NULL
;
3127 if (!m_wx_model
->IsVirtualListModel())
3131 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
3133 g_object_unref( m_gtk_model
);
3135 delete m_dragDataObject
;
3136 delete m_dropDataObject
;
3139 void wxDataViewCtrlInternal::InitTree()
3141 wxDataViewItem item
;
3142 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
3144 BuildBranch( m_root
);
3147 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
3149 if (node
->GetChildCount() == 0)
3151 wxDataViewItemArray children
;
3152 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
3154 for (pos
= 0; pos
< count
; pos
++)
3156 wxDataViewItem child
= children
[pos
];
3158 if (m_wx_model
->IsContainer( child
))
3159 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
3161 node
->AddLeave( child
.GetID() );
3163 // Don't send any events here
3170 bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat
&format
)
3172 wxGtkString
atom_str( gdk_atom_name( format
) );
3173 m_dragSourceTargetEntryTarget
= wxCharBuffer( atom_str
);
3175 m_dragSourceTargetEntry
.target
= m_dragSourceTargetEntryTarget
.data();
3176 m_dragSourceTargetEntry
.flags
= 0;
3177 m_dragSourceTargetEntry
.info
= static_cast<guint
>(-1);
3179 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3180 GDK_BUTTON1_MASK
, &m_dragSourceTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3185 bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat
&format
)
3187 wxGtkString
atom_str( gdk_atom_name( format
) );
3188 m_dropTargetTargetEntryTarget
= wxCharBuffer( atom_str
);
3190 m_dropTargetTargetEntry
.target
= m_dropTargetTargetEntryTarget
.data();
3191 m_dropTargetTargetEntry
.flags
= 0;
3192 m_dropTargetTargetEntry
.info
= static_cast<guint
>(-1);
3194 gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3195 &m_dropTargetTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3200 gboolean
wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource
*WXUNUSED(drag_source
),
3203 delete m_dragDataObject
;
3206 if (!get_iter( &iter
, path
)) return FALSE
;
3207 wxDataViewItem
item( (void*) iter
.user_data
);
3209 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3210 event
.SetEventObject( m_owner
);
3211 event
.SetItem( item
);
3212 event
.SetModel( m_wx_model
);
3213 if (!m_owner
->HandleWindowEvent( event
))
3216 if (!event
.IsAllowed())
3219 wxDataObject
*obj
= event
.GetDataObject();
3223 m_dragDataObject
= obj
;
3229 wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource
*WXUNUSED(drag_source
),
3230 GtkTreePath
*WXUNUSED(path
))
3235 gboolean
wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource
*WXUNUSED(drag_source
),
3236 GtkTreePath
*path
, GtkSelectionData
*selection_data
)
3239 if (!get_iter( &iter
, path
)) return FALSE
;
3240 wxDataViewItem
item( (void*) iter
.user_data
);
3242 if (!m_dragDataObject
->IsSupported( selection_data
->target
))
3245 size_t size
= m_dragDataObject
->GetDataSize( selection_data
->target
);
3249 void *buf
= malloc( size
);
3251 gboolean res
= FALSE
;
3252 if (m_dragDataObject
->GetDataHere( selection_data
->target
, buf
))
3256 gtk_selection_data_set( selection_data
, selection_data
->target
,
3257 8, (const guchar
*) buf
, size
);
3266 wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3268 GtkSelectionData
*selection_data
)
3271 if (!get_iter( &iter
, path
)) return FALSE
;
3272 wxDataViewItem
item( (void*) iter
.user_data
);
3274 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
3275 event
.SetEventObject( m_owner
);
3276 event
.SetItem( item
);
3277 event
.SetModel( m_wx_model
);
3278 event
.SetDataFormat( selection_data
->target
);
3279 event
.SetDataSize( selection_data
->length
);
3280 event
.SetDataBuffer( selection_data
->data
);
3281 if (!m_owner
->HandleWindowEvent( event
))
3284 if (!event
.IsAllowed())
3291 wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3293 GtkSelectionData
*selection_data
)
3296 if (!get_iter( &iter
, path
)) return FALSE
;
3297 wxDataViewItem
item( (void*) iter
.user_data
);
3299 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
3300 event
.SetEventObject( m_owner
);
3301 event
.SetItem( item
);
3302 event
.SetModel( m_wx_model
);
3303 event
.SetDataFormat( selection_data
->target
);
3304 if (!m_owner
->HandleWindowEvent( event
))
3307 if (!event
.IsAllowed())
3313 // notifications from wxDataViewModel
3315 bool wxDataViewCtrlInternal::Cleared()
3317 GtkWidget
* tree_widget
= GetOwner()->GtkGetTreeView();
3318 gtk_tree_view_set_model( GTK_TREE_VIEW(tree_widget
), NULL
);
3319 gtk_tree_view_set_model( GTK_TREE_VIEW(tree_widget
), GTK_TREE_MODEL(m_gtk_model
) );
3330 void wxDataViewCtrlInternal::Resort()
3332 if (!m_wx_model
->IsVirtualListModel())
3336 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3338 if (!m_wx_model
->IsVirtualListModel())
3340 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3341 wxASSERT_MSG(parent_node
,
3342 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3344 if (m_wx_model
->IsContainer( item
))
3345 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
3347 parent_node
->AddLeave( item
.GetID() );
3353 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3355 if (!m_wx_model
->IsVirtualListModel())
3357 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3358 wxASSERT_MSG(parent_node
,
3359 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3361 parent_node
->DeleteChild( item
.GetID() );
3367 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
3369 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3370 event
.SetEventObject( m_owner
);
3371 event
.SetModel( m_owner
->GetModel() );
3372 event
.SetItem( item
);
3373 m_owner
->HandleWindowEvent( event
);
3378 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
3380 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3381 event
.SetEventObject( m_owner
);
3382 event
.SetModel( m_owner
->GetModel() );
3383 event
.SetColumn( col
);
3384 event
.SetDataViewColumn( GetOwner()->GetColumn(col
) );
3385 event
.SetItem( item
);
3386 m_owner
->HandleWindowEvent( event
);
3393 GtkTreeModelFlags
wxDataViewCtrlInternal::get_flags()
3395 if (m_wx_model
->IsVirtualListModel())
3396 return GTK_TREE_MODEL_LIST_ONLY
;
3398 return GTK_TREE_MODEL_ITERS_PERSIST
;
3401 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
3404 if (m_wx_model
->IsVirtualListModel())
3406 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3408 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
3410 if (i
>= wx_model
->GetCount())
3413 iter
->stamp
= m_gtk_model
->stamp
;
3414 // user_data is just the index +1
3415 iter
->user_data
= (gpointer
) (i
+1);
3421 int depth
= gtk_tree_path_get_depth( path
);
3423 wxGtkTreeModelNode
*node
= m_root
;
3426 for (i
= 0; i
< depth
; i
++)
3428 BuildBranch( node
);
3430 gint pos
= gtk_tree_path_get_indices (path
)[i
];
3431 if (pos
< 0) return FALSE
;
3432 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
3434 void* id
= node
->GetChildren().Item( (size_t) pos
);
3438 iter
->stamp
= m_gtk_model
->stamp
;
3439 iter
->user_data
= id
;
3443 size_t count
= node
->GetNodes().GetCount();
3445 for (pos2
= 0; pos2
< count
; pos2
++)
3447 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
3448 if (child_node
->GetItem().GetID() == id
)
3460 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
3462 GtkTreePath
*retval
= gtk_tree_path_new ();
3464 if (m_wx_model
->IsVirtualListModel())
3466 // user_data is just the index +1
3467 int i
= ( (wxUIntPtr
) iter
->user_data
) -1;
3468 gtk_tree_path_append_index (retval
, i
);
3472 void *id
= iter
->user_data
;
3474 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
3477 int pos
= node
->GetChildren().Index( id
);
3479 gtk_tree_path_prepend_index( retval
, pos
);
3481 id
= node
->GetItem().GetID();
3482 node
= node
->GetParent();
3489 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
3491 if (m_wx_model
->IsVirtualListModel())
3493 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3495 // user_data is just the index +1
3496 int n
= ( (wxUIntPtr
) iter
->user_data
) -1;
3500 iter
->user_data
= NULL
;
3504 if (n
>= (int) wx_model
->GetCount()-1)
3506 iter
->user_data
= NULL
;
3510 // user_data is just the index +1 (+2 because we need the next)
3511 iter
->user_data
= (gpointer
) (n
+2);
3515 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
3516 if( parent
== NULL
)
3518 iter
->user_data
= NULL
;
3522 int pos
= parent
->GetChildren().Index( iter
->user_data
);
3524 if (pos
== (int) parent
->GetChildCount()-1)
3526 iter
->user_data
= NULL
;
3530 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
3536 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
3538 if (m_wx_model
->IsVirtualListModel())
3540 // this is a list, nodes have no children
3544 iter
->stamp
= m_gtk_model
->stamp
;
3545 iter
->user_data
= (gpointer
) 1;
3553 if (m_root
->GetChildCount() == 0) return FALSE
;
3554 iter
->stamp
= m_gtk_model
->stamp
;
3555 iter
->user_data
= (gpointer
) m_root
->GetChildren().Item( 0 );
3559 wxDataViewItem
item( (void*) parent
->user_data
);
3561 if (!m_wx_model
->IsContainer( item
))
3564 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3565 wxASSERT_MSG(parent_node
,
3566 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3568 BuildBranch( parent_node
);
3570 if (parent_node
->GetChildCount() == 0)
3573 iter
->stamp
= m_gtk_model
->stamp
;
3574 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
3580 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
3582 if (m_wx_model
->IsVirtualListModel())
3584 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3587 return (wx_model
->GetCount() > 0);
3589 // this is a list, nodes have no children
3595 return (m_root
->GetChildCount() > 0);
3597 wxDataViewItem
item( (void*) iter
->user_data
);
3599 bool is_container
= m_wx_model
->IsContainer( item
);
3604 wxGtkTreeModelNode
*node
= FindNode( iter
);
3606 "Did you forget a call to ItemAdded()? The iterator is unknown to the wxGtkTreeModel");
3608 BuildBranch( node
);
3610 return (node
->GetChildCount() > 0);
3614 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
3616 if (m_wx_model
->IsVirtualListModel())
3618 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3621 return (gint
) wx_model
->GetCount();
3628 return m_root
->GetChildCount();
3630 wxDataViewItem
item( (void*) iter
->user_data
);
3632 if (!m_wx_model
->IsContainer( item
))
3635 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
3636 wxASSERT_MSG(parent_node
,
3637 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3639 BuildBranch( parent_node
);
3641 return parent_node
->GetChildCount();
3645 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
3647 if (m_wx_model
->IsVirtualListModel())
3649 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3657 if (n
>= (gint
) wx_model
->GetCount())
3660 iter
->stamp
= m_gtk_model
->stamp
;
3661 // user_data is just the index +1
3662 iter
->user_data
= (gpointer
) (n
+1);
3669 if (parent
) id
= (void*) parent
->user_data
;
3670 wxDataViewItem
item( id
);
3672 if (!m_wx_model
->IsContainer( item
))
3675 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3676 wxASSERT_MSG(parent_node
,
3677 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3679 BuildBranch( parent_node
);
3681 iter
->stamp
= m_gtk_model
->stamp
;
3682 iter
->user_data
= parent_node
->GetChildren().Item( n
);
3688 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
3690 if (m_wx_model
->IsVirtualListModel())
3696 wxGtkTreeModelNode
*node
= FindParentNode( child
);
3700 iter
->stamp
= m_gtk_model
->stamp
;
3701 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
3707 static wxGtkTreeModelNode
*
3708 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3714 list
.DeleteContents( true );
3715 wxDataViewItem
it( item
);
3719 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3720 list
.Insert( pItem
);
3721 it
= model
->GetParent( it
);
3724 wxGtkTreeModelNode
* node
= treeNode
;
3725 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3727 if( node
&& node
->GetNodes().GetCount() != 0 )
3729 int len
= node
->GetNodes().GetCount();
3730 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3732 for( ; j
< len
; j
++)
3734 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3753 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
3758 wxDataViewItem
item( (void*) iter
->user_data
);
3762 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3767 wxLogDebug( "Not found %p", iter->user_data );
3771 // TODO: remove this code
3777 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
3782 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3787 wxLogDebug( "Not found %p", item.GetID() );
3791 // TODO: remove this code
3797 static wxGtkTreeModelNode
*
3798 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3804 list
.DeleteContents( true );
3808 wxDataViewItem
it( model
->GetParent( item
) );
3811 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3812 list
.Insert( pItem
);
3813 it
= model
->GetParent( it
);
3816 wxGtkTreeModelNode
* node
= treeNode
;
3817 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3819 if( node
&& node
->GetNodes().GetCount() != 0 )
3821 int len
= node
->GetNodes().GetCount();
3822 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3824 for( ; j
< len
; j
++)
3826 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3841 //Examine whether the node is item's parent node
3842 int len
= node
->GetChildCount();
3843 for( int i
= 0; i
< len
; i
++ )
3845 if( node
->GetChildren().Item( i
) == item
.GetID() )
3851 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
3856 wxDataViewItem
item( (void*) iter
->user_data
);
3860 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3863 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
3868 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3871 //-----------------------------------------------------------------------------
3872 // wxDataViewCtrl signal callbacks
3873 //-----------------------------------------------------------------------------
3876 wxdataview_selection_changed_callback( GtkTreeSelection
* WXUNUSED(selection
), wxDataViewCtrl
*dv
)
3878 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
3881 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
3882 event
.SetItem( dv
->GetSelection() );
3883 event
.SetModel( dv
->GetModel() );
3884 dv
->HandleWindowEvent( event
);
3888 wxdataview_row_activated_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreePath
*path
,
3889 GtkTreeViewColumn
*WXUNUSED(column
), wxDataViewCtrl
*dv
)
3891 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
3894 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3895 wxDataViewItem
item( (void*) iter
.user_data
);;
3896 event
.SetItem( item
);
3897 event
.SetModel( dv
->GetModel() );
3898 dv
->HandleWindowEvent( event
);
3902 wxdataview_test_expand_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3903 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3905 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
3907 wxDataViewItem
item( (void*) iter
->user_data
);;
3908 event
.SetItem( item
);
3909 event
.SetModel( dv
->GetModel() );
3910 dv
->HandleWindowEvent( event
);
3912 return !event
.IsAllowed();
3916 wxdataview_row_expanded_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3917 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3919 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
3921 wxDataViewItem
item( (void*) iter
->user_data
);;
3922 event
.SetItem( item
);
3923 event
.SetModel( dv
->GetModel() );
3924 dv
->HandleWindowEvent( event
);
3928 wxdataview_test_collapse_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3929 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3931 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
3933 wxDataViewItem
item( (void*) iter
->user_data
);;
3934 event
.SetItem( item
);
3935 event
.SetModel( dv
->GetModel() );
3936 dv
->HandleWindowEvent( event
);
3938 return !event
.IsAllowed();
3942 wxdataview_row_collapsed_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3943 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3945 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
3947 wxDataViewItem
item( (void*) iter
->user_data
);;
3948 event
.SetItem( item
);
3949 event
.SetModel( dv
->GetModel() );
3950 dv
->HandleWindowEvent( event
);
3953 //-----------------------------------------------------------------------------
3955 //-----------------------------------------------------------------------------
3957 void wxDataViewCtrl::AddChildGTK(wxWindowGTK
* child
)
3959 GtkWidget
* treeview
= GtkGetTreeView();
3961 // Insert widget in GtkTreeView
3962 if (GTK_WIDGET_REALIZED(treeview
))
3963 gtk_widget_set_parent_window( child
->m_widget
,
3964 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
3965 gtk_widget_set_parent( child
->m_widget
, treeview
);
3969 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
3970 GtkAllocation
*WXUNUSED(gtk_alloc
),
3971 wxDataViewCtrl
*win
)
3973 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
3976 wxWindow
*child
= node
->GetData();
3979 gtk_widget_size_request( child
->m_widget
, &req
);
3981 GtkAllocation alloc
;
3982 alloc
.x
= child
->m_x
;
3983 alloc
.y
= child
->m_y
;
3984 alloc
.width
= child
->m_width
;
3985 alloc
.height
= child
->m_height
;
3986 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
3988 node
= node
->GetNext();
3993 //-----------------------------------------------------------------------------
3994 // "motion_notify_event"
3995 //-----------------------------------------------------------------------------
3998 gtk_dataview_motion_notify_callback( GtkWidget
*WXUNUSED(widget
),
3999 GdkEventMotion
*gdk_event
,
4000 wxDataViewCtrl
*dv
)
4002 if (gdk_event
->is_hint
)
4006 GdkModifierType state
;
4007 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
4012 GtkTreePath
*path
= NULL
;
4013 GtkTreeViewColumn
*column
= NULL
;
4016 if (gtk_tree_view_get_path_at_pos(
4017 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4018 (int) gdk_event
->x
, (int) gdk_event
->y
,
4027 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4029 gtk_tree_path_free( path
);
4037 //-----------------------------------------------------------------------------
4038 // "button_press_event"
4039 //-----------------------------------------------------------------------------
4042 gtk_dataview_button_press_callback( GtkWidget
*WXUNUSED(widget
),
4043 GdkEventButton
*gdk_event
,
4044 wxDataViewCtrl
*dv
)
4046 if ((gdk_event
->button
== 3) && (gdk_event
->type
== GDK_BUTTON_PRESS
))
4048 GtkTreePath
*path
= NULL
;
4049 GtkTreeViewColumn
*column
= NULL
;
4052 if (gtk_tree_view_get_path_at_pos(
4053 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4054 (int) gdk_event
->x
, (int) gdk_event
->y
,
4063 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4065 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, dv
->GetId() );
4066 wxDataViewItem
item( (void*) iter
.user_data
);;
4067 event
.SetItem( item
);
4068 event
.SetModel( dv
->GetModel() );
4069 bool ret
= dv
->HandleWindowEvent( event
);
4070 gtk_tree_path_free( path
);
4079 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
4081 wxDataViewCtrl::~wxDataViewCtrl()
4084 GetModel()->RemoveNotifier( m_notifier
);
4088 // remove the model from the GtkTreeView before it gets destroyed by the
4089 // wxDataViewCtrlBase's dtor
4090 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), NULL
);
4095 void wxDataViewCtrl::Init()
4100 m_cols
.DeleteContents( true );
4103 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
4104 const wxPoint
& pos
, const wxSize
& size
,
4105 long style
, const wxValidator
& validator
)
4109 if (!PreCreation( parent
, pos
, size
) ||
4110 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
4112 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
4116 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
4117 g_object_ref(m_widget
);
4119 GTKScrolledWindowSetBorder(m_widget
, style
);
4121 m_treeview
= gtk_tree_view_new();
4122 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
4124 g_signal_connect (m_treeview
, "size_allocate",
4125 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
4128 if (!gtk_check_version(2,6,0))
4130 bool fixed
= (style
& wxDV_VARIABLE_LINE_HEIGHT
) == 0;
4131 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4135 if (style
& wxDV_MULTIPLE
)
4137 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4138 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
4141 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
4144 if (!gtk_check_version(2,10,0))
4146 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
4148 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
4149 (style
& wxDV_VERT_RULES
) != 0)
4150 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
4151 else if (style
& wxDV_VERT_RULES
)
4152 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
4153 else if (style
& wxDV_HORIZ_RULES
)
4154 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
4156 if (grid
!= GTK_TREE_VIEW_GRID_LINES_NONE
)
4157 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
4161 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_ROW_LINES
) != 0 );
4163 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
4164 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
4165 gtk_widget_show (m_treeview
);
4167 m_parent
->DoAddChild( this );
4171 GtkEnableSelectionEvents();
4173 g_signal_connect_after (m_treeview
, "row-activated",
4174 G_CALLBACK (wxdataview_row_activated_callback
), this);
4176 g_signal_connect (m_treeview
, "test-collapse-row",
4177 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
4179 g_signal_connect_after (m_treeview
, "row-collapsed",
4180 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
4182 g_signal_connect (m_treeview
, "test-expand-row",
4183 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
4185 g_signal_connect_after (m_treeview
, "row-expanded",
4186 G_CALLBACK (wxdataview_row_expanded_callback
), this);
4188 g_signal_connect (m_treeview
, "motion_notify_event",
4189 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
4191 g_signal_connect (m_treeview
, "button_press_event",
4192 G_CALLBACK (gtk_dataview_button_press_callback
), this);
4197 void wxDataViewCtrl::OnInternalIdle()
4199 wxWindow::OnInternalIdle();
4201 unsigned int cols
= GetColumnCount();
4203 for (i
= 0; i
< cols
; i
++)
4205 wxDataViewColumn
*col
= GetColumn( i
);
4206 col
->OnInternalIdle();
4210 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4221 if (!wxDataViewCtrlBase::AssociateModel( model
))
4225 if (!gtk_check_version(2,6,0))
4227 bool fixed
= (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
) == 0) || (model
->IsVirtualListModel()));
4228 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4232 GtkWxTreeModel
*gtk_model
= wxgtk_tree_model_new();
4233 m_internal
= new wxDataViewCtrlInternal( this, model
, gtk_model
);
4234 gtk_model
->internal
= m_internal
;
4236 m_notifier
= new wxGtkDataViewModelNotifier( gtk_model
, model
, this );
4238 model
->AddNotifier( m_notifier
);
4240 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_model
) );
4242 // unref in wxDataViewCtrlInternal
4243 // g_object_unref( gtk_model );
4248 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4250 return m_internal
->EnableDragSource( format
);
4253 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4255 return m_internal
->EnableDropTarget( format
);
4258 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4260 if (!wxDataViewCtrlBase::AppendColumn(col
))
4263 m_cols
.Append( col
);
4266 if (!gtk_check_version(2,6,0))
4268 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4269 GTK_TREE_VIEW_COLUMN_FIXED
)
4270 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4274 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
4275 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4280 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4282 if (!wxDataViewCtrlBase::PrependColumn(col
))
4285 m_cols
.Insert( col
);
4288 if (!gtk_check_version(2,6,0))
4290 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4291 GTK_TREE_VIEW_COLUMN_FIXED
)
4292 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4296 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4297 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
4302 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4304 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4307 m_cols
.Insert( pos
, col
);
4310 if (!gtk_check_version(2,6,0))
4312 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4313 GTK_TREE_VIEW_COLUMN_FIXED
)
4314 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4318 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4319 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), pos
);
4324 unsigned int wxDataViewCtrl::GetColumnCount() const
4326 return m_cols
.GetCount();
4329 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
4331 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
4335 wxDataViewColumnList::const_iterator iter
;
4336 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4338 wxDataViewColumn
*col
= *iter
;
4339 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
4348 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4350 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4351 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
4353 m_cols
.DeleteObject( column
);
4358 bool wxDataViewCtrl::ClearColumns()
4360 wxDataViewColumnList::iterator iter
;
4361 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4363 wxDataViewColumn
*col
= *iter
;
4364 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4365 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4373 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4375 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetConstGtkHandle());
4377 GList
*list
= gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview
) );
4379 gint pos
= g_list_index( list
, (gconstpointer
) gtk_column
);
4381 g_list_free( list
);
4386 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4388 return m_internal
->GetDataViewSortColumn();
4391 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4394 iter
.user_data
= item
.GetID();
4395 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4396 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
4397 gtk_tree_path_free( path
);
4400 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4403 iter
.user_data
= item
.GetID();
4404 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4405 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
4406 gtk_tree_path_free( path
);
4409 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4412 iter
.user_data
= item
.GetID();
4413 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4414 bool res
= gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview
), path
);
4415 gtk_tree_path_free( path
);
4420 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4422 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4424 if (m_windowStyle
& wxDV_MULTIPLE
)
4426 // Report the first one
4427 GtkTreeModel
*model
;
4428 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4432 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4434 m_internal
->get_iter( &iter
, path
);
4437 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4438 g_list_free( list
);
4440 return wxDataViewItem( (void*) iter
.user_data
);
4446 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
4448 wxDataViewItem
item( (void*) iter
.user_data
);
4453 return wxDataViewItem(0);
4456 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4460 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4461 if (HasFlag(wxDV_MULTIPLE
))
4463 GtkTreeModel
*model
;
4464 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4469 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4472 m_internal
->get_iter( &iter
, path
);
4474 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4476 list
= g_list_next( list
);
4481 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4482 g_list_free( list
);
4488 GtkTreeModel
*model
;
4490 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
4493 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4501 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4503 GtkDisableSelectionEvents();
4505 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4507 gtk_tree_selection_unselect_all( selection
);
4509 wxDataViewItem last_parent
;
4512 for (i
= 0; i
< sel
.GetCount(); i
++)
4514 wxDataViewItem item
= sel
[i
];
4515 wxDataViewItem parent
= GetModel()->GetParent( item
);
4518 if (parent
!= last_parent
)
4519 ExpandAncestors(item
);
4521 last_parent
= parent
;
4524 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4525 iter
.user_data
= (gpointer
) item
.GetID();
4526 gtk_tree_selection_select_iter( selection
, &iter
);
4529 GtkEnableSelectionEvents();
4532 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4534 ExpandAncestors(item
);
4536 GtkDisableSelectionEvents();
4538 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4541 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4542 iter
.user_data
= (gpointer
) item
.GetID();
4543 gtk_tree_selection_select_iter( selection
, &iter
);
4545 GtkEnableSelectionEvents();
4548 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4550 GtkDisableSelectionEvents();
4552 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4555 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4556 iter
.user_data
= (gpointer
) item
.GetID();
4557 gtk_tree_selection_unselect_iter( selection
, &iter
);
4559 GtkEnableSelectionEvents();
4562 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4564 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4567 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4568 iter
.user_data
= (gpointer
) item
.GetID();
4570 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
4573 void wxDataViewCtrl::SelectAll()
4575 GtkDisableSelectionEvents();
4577 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4579 gtk_tree_selection_select_all( selection
);
4581 GtkEnableSelectionEvents();
4584 void wxDataViewCtrl::UnselectAll()
4586 GtkDisableSelectionEvents();
4588 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4590 gtk_tree_selection_unselect_all( selection
);
4592 GtkEnableSelectionEvents();
4595 void wxDataViewCtrl::EnsureVisible(const wxDataViewItem
& item
,
4596 const wxDataViewColumn
*WXUNUSED(column
))
4598 ExpandAncestors(item
);
4601 iter
.user_data
= (gpointer
) item
.GetID();
4602 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4603 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
4604 gtk_tree_path_free( path
);
4607 void wxDataViewCtrl::HitTest(const wxPoint
& WXUNUSED(point
),
4608 wxDataViewItem
& item
,
4609 wxDataViewColumn
*& column
) const
4611 item
= wxDataViewItem(0);
4616 wxDataViewCtrl::GetItemRect(const wxDataViewItem
& WXUNUSED(item
),
4617 const wxDataViewColumn
*WXUNUSED(column
)) const
4622 void wxDataViewCtrl::DoSetExpanderColumn()
4624 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
4625 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
4628 void wxDataViewCtrl::DoSetIndent()
4632 void wxDataViewCtrl::GtkDisableSelectionEvents()
4634 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4635 g_signal_handlers_disconnect_by_func( selection
,
4636 (gpointer
) (wxdataview_selection_changed_callback
), this);
4639 void wxDataViewCtrl::GtkEnableSelectionEvents()
4641 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4642 g_signal_connect_after (selection
, "changed",
4643 G_CALLBACK (wxdataview_selection_changed_callback
), this);
4646 // ----------------------------------------------------------------------------
4647 // visual attributes stuff
4648 // ----------------------------------------------------------------------------
4652 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
4654 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
4657 void wxDataViewCtrl::DoApplyWidgetStyle(GtkRcStyle
*style
)
4659 wxDataViewCtrlBase::DoApplyWidgetStyle(style
);
4660 gtk_widget_modify_style(m_treeview
, style
);
4663 #endif // !wxUSE_GENERICDATAVIEWCTRL
4665 #endif // wxUSE_DATAVIEWCTRL