1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/dataview.cpp
3 // Purpose: wxDataViewCtrl GTK+2 implementation
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if wxUSE_DATAVIEWCTRL
15 #include "wx/dataview.h"
17 #ifndef wxUSE_GENERICDATAVIEWCTRL
21 #include "wx/dcclient.h"
23 #include "wx/settings.h"
27 #include "wx/stockitem.h"
28 #include "wx/calctrl.h"
29 #include "wx/popupwin.h"
30 #include "wx/listimpl.cpp"
32 #include "wx/gtk/private.h"
33 #include "wx/gtk/dc.h"
34 #include "wx/gtk/dcclient.h"
36 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 static wxDataViewCtrlInternal
*gs_internal
= NULL
;
41 class wxGtkTreeModelNode
;
44 typedef struct _GtkWxTreeModel GtkWxTreeModel
;
47 //-----------------------------------------------------------------------------
48 // wxDataViewCtrlInternal
49 //-----------------------------------------------------------------------------
51 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
52 WX_DEFINE_LIST(ItemList
)
54 class WXDLLIMPEXP_ADV wxDataViewCtrlInternal
57 wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
);
58 ~wxDataViewCtrlInternal();
61 GtkTreeModelFlags
get_flags();
62 gboolean
get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
);
63 GtkTreePath
*get_path( GtkTreeIter
*iter
);
64 gboolean
iter_next( GtkTreeIter
*iter
);
65 gboolean
iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
);
66 gboolean
iter_has_child( GtkTreeIter
*iter
);
67 gint
iter_n_children( GtkTreeIter
*iter
);
68 gboolean
iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
);
69 gboolean
iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
);
73 bool EnableDragSource( const wxDataFormat
&format
);
74 bool EnableDropTarget( const wxDataFormat
&format
);
76 gboolean
row_draggable( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
);
77 gboolean
drag_data_delete( GtkTreeDragSource
*drag_source
, GtkTreePath
* path
);
78 gboolean
drag_data_get( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
,
79 GtkSelectionData
*selection_data
);
80 gboolean
drag_data_received( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest
,
81 GtkSelectionData
*selection_data
);
82 gboolean
row_drop_possible( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest_path
,
83 GtkSelectionData
*selection_data
);
85 // notifactions from wxDataViewModel
86 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
87 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
88 bool ItemChanged( const wxDataViewItem
&item
);
89 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
94 void SetSortOrder( GtkSortType sort_order
) { m_sort_order
= sort_order
; }
95 GtkSortType
GetSortOrder() const { return m_sort_order
; }
97 void SetSortColumn( int column
) { m_sort_column
= column
; }
98 int GetSortColumn() const { return m_sort_column
; }
100 void SetDataViewSortColumn( wxDataViewColumn
*column
) { m_dataview_sort_column
= column
; }
101 wxDataViewColumn
*GetDataViewSortColumn() { return m_dataview_sort_column
; }
103 bool IsSorted() { return (m_sort_column
>= 0); }
106 wxDataViewModel
* GetDataViewModel() { return m_wx_model
; }
107 const wxDataViewModel
* GetDataViewModel() const { return m_wx_model
; }
108 wxDataViewCtrl
* GetOwner() { return m_owner
; }
109 GtkWxTreeModel
* GetGtkModel() { return m_gtk_model
; }
113 wxGtkTreeModelNode
*FindNode( const wxDataViewItem
&item
);
114 wxGtkTreeModelNode
*FindNode( GtkTreeIter
*iter
);
115 wxGtkTreeModelNode
*FindParentNode( const wxDataViewItem
&item
);
116 wxGtkTreeModelNode
*FindParentNode( GtkTreeIter
*iter
);
117 void BuildBranch( wxGtkTreeModelNode
*branch
);
120 wxGtkTreeModelNode
*m_root
;
121 wxDataViewModel
*m_wx_model
;
122 GtkWxTreeModel
*m_gtk_model
;
123 wxDataViewCtrl
*m_owner
;
124 GtkSortType m_sort_order
;
125 wxDataViewColumn
*m_dataview_sort_column
;
128 GtkTargetEntry m_dragSourceTargetEntry
;
129 wxCharBuffer m_dragSourceTargetEntryTarget
;
130 wxDataObject
*m_dragDataObject
;
132 GtkTargetEntry m_dropTargetTargetEntry
;
133 wxCharBuffer m_dropTargetTargetEntryTarget
;
134 wxDataObject
*m_dropDataObject
;
138 //-----------------------------------------------------------------------------
139 // wxGtkTreeModelNode
140 //-----------------------------------------------------------------------------
143 int LINKAGEMODE
wxGtkTreeModelChildCmp( void** id1
, void** id2
)
145 int ret
= gs_internal
->GetDataViewModel()->Compare( *id1
, *id2
,
146 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
151 WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode
*, wxGtkTreeModelNodes
);
152 WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren
);
154 class wxGtkTreeModelNode
157 wxGtkTreeModelNode( wxGtkTreeModelNode
* parent
, const wxDataViewItem
&item
,
158 wxDataViewCtrlInternal
*internal
)
162 m_internal
= internal
;
165 ~wxGtkTreeModelNode()
167 size_t count
= m_nodes
.GetCount();
169 for (i
= 0; i
< count
; i
++)
171 wxGtkTreeModelNode
*child
= m_nodes
.Item( i
);
176 unsigned int AddNode( wxGtkTreeModelNode
* child
)
178 m_nodes
.Add( child
);
180 void *id
= child
->GetItem().GetID();
182 m_children
.Add( id
);
184 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
186 gs_internal
= m_internal
;
187 m_children
.Sort( &wxGtkTreeModelChildCmp
);
188 return m_children
.Index( id
);
191 return m_children
.GetCount()-1;
194 unsigned int AddLeave( void* id
)
196 m_children
.Add( id
);
198 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
200 gs_internal
= m_internal
;
201 m_children
.Sort( &wxGtkTreeModelChildCmp
);
202 return m_children
.Index( id
);
205 return m_children
.GetCount()-1;
208 void DeleteChild( void* id
)
210 m_children
.Remove( id
);
212 unsigned int count
= m_nodes
.GetCount();
214 for (pos
= 0; pos
< count
; pos
++)
216 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
217 if (node
->GetItem().GetID() == id
)
219 m_nodes
.RemoveAt( pos
);
226 wxGtkTreeModelNode
* GetParent()
228 wxGtkTreeModelNodes
&GetNodes()
230 wxGtkTreeModelChildren
&GetChildren()
231 { return m_children
; }
233 unsigned int GetChildCount() const { return m_children
.GetCount(); }
234 unsigned int GetNodesCount() const { return m_nodes
.GetCount(); }
236 wxDataViewItem
&GetItem() { return m_item
; }
237 wxDataViewCtrlInternal
*GetInternal() { return m_internal
; }
242 wxGtkTreeModelNode
*m_parent
;
243 wxGtkTreeModelNodes m_nodes
;
244 wxGtkTreeModelChildren m_children
;
245 wxDataViewItem m_item
;
246 wxDataViewCtrlInternal
*m_internal
;
250 //-----------------------------------------------------------------------------
252 //-----------------------------------------------------------------------------
254 extern bool g_blockEventsOnDrag
;
256 //-----------------------------------------------------------------------------
257 // define new GTK+ class wxGtkTreeModel
258 //-----------------------------------------------------------------------------
262 #define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ())
263 #define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel))
264 #define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
265 #define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL))
266 #define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL))
267 #define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
269 GType
gtk_wx_tree_model_get_type (void);
271 typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass
;
273 struct _GtkWxTreeModel
279 wxDataViewCtrlInternal
*internal
;
282 struct _GtkWxTreeModelClass
284 GObjectClass list_parent_class
;
287 static GtkWxTreeModel
*wxgtk_tree_model_new (void);
288 static void wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
);
289 static void wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
);
291 static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
);
292 static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
);
293 static void wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
);
294 static void wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
);
296 static void wxgtk_tree_model_finalize (GObject
*object
);
297 static GtkTreeModelFlags
wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
);
298 static gint
wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
);
299 static GType
wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
301 static gboolean
wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
304 static GtkTreePath
*wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
306 static void wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
310 static gboolean
wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
312 static gboolean
wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
314 GtkTreeIter
*parent
);
315 static gboolean
wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
317 static gint
wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
319 static gboolean
wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
323 static gboolean
wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
328 static gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
329 gint
*sort_column_id
,
331 static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
334 static void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
336 GtkTreeIterCompareFunc func
,
338 GtkDestroyNotify destroy
);
339 static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
340 GtkTreeIterCompareFunc func
,
342 GtkDestroyNotify destroy
);
343 static gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
);
346 static gboolean
wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
348 static gboolean
wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
350 static gboolean
wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
352 GtkSelectionData
*selection_data
);
353 static gboolean
wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
355 GtkSelectionData
*selection_data
);
356 static gboolean
wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
357 GtkTreePath
*dest_path
,
358 GtkSelectionData
*selection_data
);
361 static GObjectClass
*list_parent_class
= NULL
;
364 gtk_wx_tree_model_get_type (void)
366 static GType tree_model_type
= 0;
368 if (!tree_model_type
)
370 const GTypeInfo tree_model_info
=
372 sizeof (GtkWxTreeModelClass
),
373 NULL
, /* base_init */
374 NULL
, /* base_finalize */
375 (GClassInitFunc
) wxgtk_tree_model_class_init
,
376 NULL
, /* class_finalize */
377 NULL
, /* class_data */
378 sizeof (GtkWxTreeModel
),
380 (GInstanceInitFunc
) wxgtk_tree_model_init
,
383 static const GInterfaceInfo tree_model_iface_info
=
385 (GInterfaceInitFunc
) wxgtk_tree_model_tree_model_init
,
390 static const GInterfaceInfo sortable_iface_info
=
392 (GInterfaceInitFunc
) wxgtk_tree_model_sortable_init
,
397 static const GInterfaceInfo drag_source_iface_info
=
399 (GInterfaceInitFunc
) wxgtk_tree_model_drag_source_init
,
404 static const GInterfaceInfo drag_dest_iface_info
=
406 (GInterfaceInitFunc
) wxgtk_tree_model_drag_dest_init
,
411 tree_model_type
= g_type_register_static (G_TYPE_OBJECT
, "GtkWxTreeModel",
412 &tree_model_info
, (GTypeFlags
)0 );
414 g_type_add_interface_static (tree_model_type
,
416 &tree_model_iface_info
);
417 g_type_add_interface_static (tree_model_type
,
418 GTK_TYPE_TREE_SORTABLE
,
419 &sortable_iface_info
);
420 g_type_add_interface_static (tree_model_type
,
421 GTK_TYPE_TREE_DRAG_DEST
,
422 &drag_dest_iface_info
);
423 g_type_add_interface_static (tree_model_type
,
424 GTK_TYPE_TREE_DRAG_SOURCE
,
425 &drag_source_iface_info
);
428 return tree_model_type
;
431 static GtkWxTreeModel
*
432 wxgtk_tree_model_new(void)
434 GtkWxTreeModel
*retval
= (GtkWxTreeModel
*) g_object_new (GTK_TYPE_WX_TREE_MODEL
, NULL
);
439 wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
)
441 list_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
442 GObjectClass
*object_class
= (GObjectClass
*) klass
;
443 object_class
->finalize
= wxgtk_tree_model_finalize
;
447 wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
)
449 iface
->get_flags
= wxgtk_tree_model_get_flags
;
450 iface
->get_n_columns
= wxgtk_tree_model_get_n_columns
;
451 iface
->get_column_type
= wxgtk_tree_model_get_column_type
;
452 iface
->get_iter
= wxgtk_tree_model_get_iter
;
453 iface
->get_path
= wxgtk_tree_model_get_path
;
454 iface
->get_value
= wxgtk_tree_model_get_value
;
455 iface
->iter_next
= wxgtk_tree_model_iter_next
;
456 iface
->iter_children
= wxgtk_tree_model_iter_children
;
457 iface
->iter_has_child
= wxgtk_tree_model_iter_has_child
;
458 iface
->iter_n_children
= wxgtk_tree_model_iter_n_children
;
459 iface
->iter_nth_child
= wxgtk_tree_model_iter_nth_child
;
460 iface
->iter_parent
= wxgtk_tree_model_iter_parent
;
464 wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
)
466 iface
->get_sort_column_id
= wxgtk_tree_model_get_sort_column_id
;
467 iface
->set_sort_column_id
= wxgtk_tree_model_set_sort_column_id
;
468 iface
->set_sort_func
= wxgtk_tree_model_set_sort_func
;
469 iface
->set_default_sort_func
= wxgtk_tree_model_set_default_sort_func
;
470 iface
->has_default_sort_func
= wxgtk_tree_model_has_default_sort_func
;
474 wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
)
476 iface
->row_draggable
= wxgtk_tree_model_row_draggable
;
477 iface
->drag_data_delete
= wxgtk_tree_model_drag_data_delete
;
478 iface
->drag_data_get
= wxgtk_tree_model_drag_data_get
;
482 wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
)
484 iface
->drag_data_received
= wxgtk_tree_model_drag_data_received
;
485 iface
->row_drop_possible
= wxgtk_tree_model_row_drop_possible
;
489 wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
)
491 tree_model
->internal
= NULL
;
492 tree_model
->stamp
= g_random_int();
496 wxgtk_tree_model_finalize (GObject
*object
)
499 (* list_parent_class
->finalize
) (object
);
504 //-----------------------------------------------------------------------------
505 // implement callbacks from wxGtkTreeModel class by letting
506 // them call the methods of wxWidgets' wxDataViewModel
507 //-----------------------------------------------------------------------------
509 static GtkTreeModelFlags
510 wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
)
512 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
513 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), (GtkTreeModelFlags
)0 );
515 return wxtree_model
->internal
->get_flags();
519 wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
)
521 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
522 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
524 return wxtree_model
->internal
->GetDataViewModel()->GetColumnCount();
528 wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
531 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
532 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), G_TYPE_INVALID
);
534 GType gtype
= G_TYPE_INVALID
;
536 wxString wxtype
= wxtree_model
->internal
->GetDataViewModel()->GetColumnType( (unsigned int) index
);
538 if (wxtype
== wxT("string"))
539 gtype
= G_TYPE_STRING
;
542 gtype
= G_TYPE_STRING
;
543 // wxFAIL_MSG( _T("non-string columns not supported yet") );
550 wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
554 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
555 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
556 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
558 return wxtree_model
->internal
->get_iter( iter
, path
);
562 wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
565 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
566 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), NULL
);
567 g_return_val_if_fail (iter
->stamp
== GTK_WX_TREE_MODEL (wxtree_model
)->stamp
, NULL
);
569 return wxtree_model
->internal
->get_path( iter
);
573 wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
578 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
579 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
) );
581 wxDataViewModel
*model
= wxtree_model
->internal
->GetDataViewModel();
582 wxString mtype
= model
->GetColumnType( (unsigned int) column
);
583 if (mtype
== wxT("string"))
586 g_value_init( value
, G_TYPE_STRING
);
587 wxDataViewItem
item( (void*) iter
->user_data
);
588 model
->GetValue( variant
, item
, (unsigned int) column
);
590 g_value_set_string( value
, variant
.GetString().utf8_str() );
594 wxFAIL_MSG( _T("non-string columns not supported yet") );
599 wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
602 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
604 //if (wxtree_model->stamp != iter->stamp)
605 // wxPrintf( "crash\n" );
606 // TODO: remove this code
608 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
609 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
611 return wxtree_model
->internal
->iter_next( iter
);
615 wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
619 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
620 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
621 g_return_val_if_fail (wxtree_model
->stamp
== parent
->stamp
, FALSE
);
623 return wxtree_model
->internal
->iter_children( iter
, parent
);
627 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
630 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
631 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
632 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
634 return wxtree_model
->internal
->iter_has_child( iter
);
638 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
641 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
642 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
643 g_return_val_if_fail ( !iter
|| wxtree_model
->stamp
== iter
->stamp
, 0);
645 return wxtree_model
->internal
->iter_n_children( iter
);
649 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
654 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
655 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
657 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
661 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
665 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
666 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
667 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
669 return wxtree_model
->internal
->iter_parent( iter
, child
);
672 /* drag'n'drop iface */
674 wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
677 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
678 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
680 return wxtree_model
->internal
->row_draggable( drag_source
, path
);
684 wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
687 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
688 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
690 return wxtree_model
->internal
->drag_data_delete( drag_source
, path
);
694 wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
696 GtkSelectionData
*selection_data
)
698 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
699 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
702 wxPrintf( "drag_get_data\n");
704 wxGtkString
atom_selection(gdk_atom_name(selection_data
->selection
));
705 wxPrintf( "selection %s\n", wxString::FromAscii(atom_selection
) );
707 wxGtkString
atom_target(gdk_atom_name(selection_data
->target
));
708 wxPrintf( "target %s\n", wxString::FromAscii(atom_target
) );
710 wxGtkString
atom_type(gdk_atom_name(selection_data
->type
));
711 wxPrintf( "type %s\n", wxString::FromAscii(atom_type
) );
713 wxPrintf( "format %d\n", selection_data
->format
);
716 return wxtree_model
->internal
->drag_data_get( drag_source
, path
, selection_data
);
720 wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
722 GtkSelectionData
*selection_data
)
724 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
725 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
727 return wxtree_model
->internal
->drag_data_received( drag_dest
, dest
, selection_data
);
731 wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
732 GtkTreePath
*dest_path
,
733 GtkSelectionData
*selection_data
)
735 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
736 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
738 return wxtree_model
->internal
->row_drop_possible( drag_dest
, dest_path
, selection_data
);
743 wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
744 gint
*sort_column_id
,
747 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) sortable
;
749 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
751 if (!wxtree_model
->internal
->IsSorted())
754 *sort_column_id
= -1;
761 *sort_column_id
= wxtree_model
->internal
->GetSortColumn();
764 *order
= wxtree_model
->internal
->GetSortOrder();
769 wxDataViewColumn
*gs_lastLeftClickHeader
= NULL
;
772 wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
776 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
777 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
779 tree_model
->internal
->SetDataViewSortColumn( gs_lastLeftClickHeader
);
781 if ((sort_column_id
!= (gint
) tree_model
->internal
->GetSortColumn()) ||
782 (order
!= tree_model
->internal
->GetSortOrder()))
784 tree_model
->internal
->SetSortColumn( sort_column_id
);
785 tree_model
->internal
->SetSortOrder( order
);
787 gtk_tree_sortable_sort_column_changed (sortable
);
789 tree_model
->internal
->GetDataViewModel()->Resort();
792 if (gs_lastLeftClickHeader
)
794 wxDataViewCtrl
*dv
= tree_model
->internal
->GetOwner();
795 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, dv
->GetId() );
796 event
.SetDataViewColumn( gs_lastLeftClickHeader
);
797 event
.SetModel( dv
->GetModel() );
798 dv
->HandleWindowEvent( event
);
801 gs_lastLeftClickHeader
= NULL
;
805 wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
806 gint
WXUNUSED(sort_column_id
),
807 GtkTreeIterCompareFunc func
,
808 gpointer
WXUNUSED(data
),
809 GtkDestroyNotify
WXUNUSED(destroy
))
811 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
812 g_return_if_fail (func
!= NULL
);
816 wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
817 GtkTreeIterCompareFunc func
,
818 gpointer
WXUNUSED(data
),
819 GtkDestroyNotify
WXUNUSED(destroy
))
821 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
822 g_return_if_fail (func
!= NULL
);
824 //wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
825 // TODO: remove this code
829 wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
)
831 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
836 //-----------------------------------------------------------------------------
837 // define new GTK+ class GtkWxRendererText
838 //-----------------------------------------------------------------------------
842 #define GTK_TYPE_WX_CELL_RENDERER_TEXT (gtk_wx_cell_renderer_text_get_type ())
843 #define GTK_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererText))
844 #define GTK_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
845 #define GTK_IS_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT))
846 #define GTK_IS_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT))
847 #define GTK_WX_CELL_RENDERER_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
849 GType
gtk_wx_cell_renderer_text_get_type (void);
851 typedef struct _GtkWxCellRendererText GtkWxCellRendererText
;
852 typedef struct _GtkWxCellRendererTextClass GtkWxCellRendererTextClass
;
854 struct _GtkWxCellRendererText
856 GtkCellRendererText parent
;
858 wxDataViewRenderer
*wx_renderer
;
861 struct _GtkWxCellRendererTextClass
863 GtkCellRendererTextClass cell_parent_class
;
867 static GtkWxCellRendererText
*gtk_wx_cell_renderer_text_new (void);
868 static void gtk_wx_cell_renderer_text_init (
869 GtkWxCellRendererText
*cell
);
870 static void gtk_wx_cell_renderer_text_class_init(
871 GtkWxCellRendererTextClass
*klass
);
872 static void gtk_wx_cell_renderer_text_finalize (
874 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
875 GtkCellRenderer
*cell
,
879 GdkRectangle
*background_area
,
880 GdkRectangle
*cell_area
,
881 GtkCellRendererState flags
);
884 static GObjectClass
*text_cell_parent_class
= NULL
;
889 gtk_wx_cell_renderer_text_get_type (void)
891 static GType cell_wx_type
= 0;
895 const GTypeInfo cell_wx_info
=
897 sizeof (GtkWxCellRendererTextClass
),
898 NULL
, /* base_init */
899 NULL
, /* base_finalize */
900 (GClassInitFunc
) gtk_wx_cell_renderer_text_class_init
,
901 NULL
, /* class_finalize */
902 NULL
, /* class_data */
903 sizeof (GtkWxCellRendererText
),
905 (GInstanceInitFunc
) gtk_wx_cell_renderer_text_init
,
908 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER_TEXT
,
909 "GtkWxCellRendererText", &cell_wx_info
, (GTypeFlags
)0 );
916 gtk_wx_cell_renderer_text_init (GtkWxCellRendererText
*cell
)
918 cell
->wx_renderer
= NULL
;
922 gtk_wx_cell_renderer_text_class_init (GtkWxCellRendererTextClass
*klass
)
924 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
925 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
927 text_cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
929 object_class
->finalize
= gtk_wx_cell_renderer_text_finalize
;
931 cell_class
->start_editing
= gtk_wx_cell_renderer_text_start_editing
;
935 gtk_wx_cell_renderer_text_finalize (GObject
*object
)
938 (* G_OBJECT_CLASS (text_cell_parent_class
)->finalize
) (object
);
941 GtkWxCellRendererText
*
942 gtk_wx_cell_renderer_text_new (void)
944 return (GtkWxCellRendererText
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER_TEXT
, NULL
);
947 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
948 GtkCellRenderer
*gtk_renderer
,
952 GdkRectangle
*background_area
,
953 GdkRectangle
*cell_area
,
954 GtkCellRendererState flags
)
956 GtkWxCellRendererText
*wxgtk_renderer
= (GtkWxCellRendererText
*) gtk_renderer
;
957 wxDataViewRenderer
*wx_renderer
= wxgtk_renderer
->wx_renderer
;
959 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
961 wx_renderer
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
962 wxDataViewItem
item( (void*) iter
.user_data
);;
963 gtk_tree_path_free( treepath
);
965 wxDataViewColumn
*column
= wx_renderer
->GetOwner();
966 wxDataViewCtrl
*dv
= column
->GetOwner();
967 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, dv
->GetId() );
968 event
.SetDataViewColumn( column
);
969 event
.SetModel( dv
->GetModel() );
970 event
.SetColumn( wx_renderer
->GetOwner()->GetModelColumn() );
971 event
.SetItem( item
);
972 dv
->HandleWindowEvent( event
);
974 if (event
.IsAllowed())
975 return GTK_CELL_RENDERER_CLASS(text_cell_parent_class
)->
976 start_editing( gtk_renderer
, gdk_event
, widget
, path
, background_area
, cell_area
, flags
);
981 //-----------------------------------------------------------------------------
982 // define new GTK+ class GtkWxCellRenderer
983 //-----------------------------------------------------------------------------
987 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
988 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
989 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
990 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
991 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
992 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
994 GType
gtk_wx_cell_renderer_get_type (void);
996 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
997 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
999 struct _GtkWxCellRenderer
1001 GtkCellRenderer parent
;
1004 wxDataViewCustomRenderer
*cell
;
1008 struct _GtkWxCellRendererClass
1010 GtkCellRendererClass cell_parent_class
;
1014 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
1015 static void gtk_wx_cell_renderer_init (
1016 GtkWxCellRenderer
*cell
);
1017 static void gtk_wx_cell_renderer_class_init(
1018 GtkWxCellRendererClass
*klass
);
1019 static void gtk_wx_cell_renderer_finalize (
1021 static void gtk_wx_cell_renderer_get_size (
1022 GtkCellRenderer
*cell
,
1024 GdkRectangle
*rectangle
,
1029 static void gtk_wx_cell_renderer_render (
1030 GtkCellRenderer
*cell
,
1033 GdkRectangle
*background_area
,
1034 GdkRectangle
*cell_area
,
1035 GdkRectangle
*expose_area
,
1036 GtkCellRendererState flags
);
1037 static gboolean
gtk_wx_cell_renderer_activate(
1038 GtkCellRenderer
*cell
,
1042 GdkRectangle
*background_area
,
1043 GdkRectangle
*cell_area
,
1044 GtkCellRendererState flags
);
1045 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1046 GtkCellRenderer
*cell
,
1050 GdkRectangle
*background_area
,
1051 GdkRectangle
*cell_area
,
1052 GtkCellRendererState flags
);
1055 static GObjectClass
*cell_parent_class
= NULL
;
1060 gtk_wx_cell_renderer_get_type (void)
1062 static GType cell_wx_type
= 0;
1066 const GTypeInfo cell_wx_info
=
1068 sizeof (GtkWxCellRendererClass
),
1069 NULL
, /* base_init */
1070 NULL
, /* base_finalize */
1071 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
1072 NULL
, /* class_finalize */
1073 NULL
, /* class_data */
1074 sizeof (GtkWxCellRenderer
),
1075 0, /* n_preallocs */
1076 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
1079 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
1080 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
1083 return cell_wx_type
;
1087 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
1090 cell
->last_click
= 0;
1094 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
1096 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1097 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
1099 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
1101 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
1103 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
1104 cell_class
->render
= gtk_wx_cell_renderer_render
;
1105 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
1106 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
1110 gtk_wx_cell_renderer_finalize (GObject
*object
)
1113 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
1117 gtk_wx_cell_renderer_new (void)
1119 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
1122 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1123 GtkCellRenderer
*renderer
,
1124 GdkEvent
*WXUNUSED(event
),
1127 GdkRectangle
*WXUNUSED(background_area
),
1128 GdkRectangle
*cell_area
,
1129 GtkCellRendererState
WXUNUSED(flags
) )
1131 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1132 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1134 // Renderer doesn't support in-place editing
1135 if (!cell
->HasEditorCtrl())
1138 // An in-place editing control is still around
1139 if (cell
->GetEditorCtrl())
1143 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1149 rect
.x
+= cell_area
->x
;
1150 rect
.y
+= cell_area
->y
;
1151 // rect.width -= renderer->xpad * 2;
1152 // rect.height -= renderer->ypad * 2;
1154 // wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
1155 wxRect
renderrect( cell_area
->x
, cell_area
->y
, cell_area
->width
, cell_area
->height
);
1157 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
1159 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
1160 wxDataViewItem
item( (void*) iter
.user_data
);
1161 gtk_tree_path_free( treepath
);
1163 cell
->StartEditing( item
, renderrect
);
1169 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
1170 GtkWidget
*WXUNUSED(widget
),
1171 GdkRectangle
*cell_area
,
1177 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1178 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1180 wxSize size
= cell
->GetSize();
1182 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
1183 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
1190 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
1194 *x_offset
= (gint
)((renderer
->xalign
*
1195 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
1196 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
1200 *y_offset
= (gint
)((renderer
->yalign
*
1201 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
1202 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
1207 *width
= calc_width
;
1210 *height
= calc_height
;
1214 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
1217 GdkRectangle
*background_area
,
1218 GdkRectangle
*cell_area
,
1219 GdkRectangle
*expose_area
,
1220 GtkCellRendererState flags
)
1223 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1224 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1226 cell
->window
= window
;
1227 cell
->widget
= widget
;
1228 cell
->background_area
= (void*) background_area
;
1229 cell
->cell_area
= (void*) cell_area
;
1230 cell
->expose_area
= (void*) expose_area
;
1231 cell
->flags
= (int) flags
;
1234 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1240 rect
.x
+= cell_area
->x
;
1241 rect
.y
+= cell_area
->y
;
1242 rect
.width
-= renderer
->xpad
* 2;
1243 rect
.height
-= renderer
->ypad
* 2;
1246 if (gdk_rectangle_intersect (expose_area
, &rect
, &dummy
))
1248 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1249 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
1250 wxWindowDCImpl
*impl
= (wxWindowDCImpl
*) dc
->GetImpl();
1252 // Reinitialize wxWindowDC's GDK window if drawing occurs into a different
1253 // window such as a DnD drop window.
1254 if (window
!= impl
->m_gdkwindow
)
1257 impl
->m_gdkwindow
= window
;
1262 if (flags
& GTK_CELL_RENDERER_SELECTED
)
1263 state
|= wxDATAVIEW_CELL_SELECTED
;
1264 if (flags
& GTK_CELL_RENDERER_PRELIT
)
1265 state
|= wxDATAVIEW_CELL_PRELIT
;
1266 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1267 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1268 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1269 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1270 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
1271 state
|= wxDATAVIEW_CELL_FOCUSED
;
1272 cell
->Render( renderrect
, dc
, state
);
1277 gtk_wx_cell_renderer_activate(
1278 GtkCellRenderer
*renderer
,
1282 GdkRectangle
*WXUNUSED(background_area
),
1283 GdkRectangle
*cell_area
,
1284 GtkCellRendererState
WXUNUSED(flags
) )
1286 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1287 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1290 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1296 rect
.x
+= cell_area
->x
;
1297 rect
.y
+= cell_area
->y
;
1298 rect
.width
-= renderer
->xpad
* 2;
1299 rect
.height
-= renderer
->ypad
* 2;
1301 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1303 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1305 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
1308 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
1309 wxDataViewItem
item( iter
.user_data
);
1310 gtk_tree_path_free( treepath
);
1312 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1318 // activated by <ENTER>
1319 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1324 else if (event
->type
== GDK_BUTTON_PRESS
)
1326 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
1327 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
1328 ((int) button_event
->y
) - renderrect
.y
);
1331 if (button_event
->button
== 1)
1333 if (cell
->LeftClick( pt
, renderrect
, model
, item
, model_col
))
1335 // TODO: query system double-click time
1336 if (button_event
->time
- wxrenderer
->last_click
< 400)
1337 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1340 wxrenderer
->last_click
= button_event
->time
;
1348 // ---------------------------------------------------------
1349 // wxGtkDataViewModelNotifier
1350 // ---------------------------------------------------------
1352 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1355 wxGtkDataViewModelNotifier( GtkWxTreeModel
*wxgtk_model
,
1356 wxDataViewModel
*wx_model
,
1357 wxDataViewCtrl
*ctrl
);
1358 ~wxGtkDataViewModelNotifier();
1360 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1361 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1362 virtual bool ItemChanged( const wxDataViewItem
&item
);
1363 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
1364 virtual bool Cleared();
1365 virtual void Resort();
1367 void SetGtkModel( GtkWxTreeModel
*model
) { m_wxgtk_model
= model
; }
1370 GtkWxTreeModel
*m_wxgtk_model
;
1371 wxDataViewModel
*m_wx_model
;
1372 wxDataViewCtrl
*m_owner
;
1375 // ---------------------------------------------------------
1376 // wxGtkDataViewListModelNotifier
1377 // ---------------------------------------------------------
1379 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1380 GtkWxTreeModel
* wxgtk_model
, wxDataViewModel
*wx_model
,
1381 wxDataViewCtrl
*ctrl
)
1383 m_wxgtk_model
= wxgtk_model
;
1384 m_wx_model
= wx_model
;
1388 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1391 m_wxgtk_model
= NULL
;
1394 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1396 m_owner
->GtkGetInternal()->ItemAdded( parent
, item
);
1399 iter
.stamp
= m_wxgtk_model
->stamp
;
1400 iter
.user_data
= (gpointer
) item
.GetID();
1402 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1403 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1404 gtk_tree_model_row_inserted(
1405 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1406 gtk_tree_path_free (path
);
1411 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1414 iter
.stamp
= m_wxgtk_model
->stamp
;
1415 iter
.user_data
= (gpointer
) item
.GetID();
1417 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1418 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1419 gtk_tree_model_row_deleted(
1420 GTK_TREE_MODEL(m_wxgtk_model
), path
);
1421 gtk_tree_path_free (path
);
1423 m_owner
->GtkGetInternal()->ItemDeleted( parent
, item
);
1428 void wxGtkDataViewModelNotifier::Resort()
1430 m_owner
->GtkGetInternal()->Resort();
1433 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1436 iter
.stamp
= m_wxgtk_model
->stamp
;
1437 iter
.user_data
= (gpointer
) item
.GetID();
1439 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1440 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1441 gtk_tree_model_row_changed(
1442 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1443 gtk_tree_path_free (path
);
1445 m_owner
->GtkGetInternal()->ItemChanged( item
);
1450 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_col
)
1452 // This adds GTK+'s missing MVC logic for ValueChanged
1454 for (index
= 0; index
< m_owner
->GetColumnCount(); index
++)
1456 wxDataViewColumn
*column
= m_owner
->GetColumn( index
);
1457 if (column
->GetModelColumn() == model_col
)
1459 GtkTreeView
*widget
= GTK_TREE_VIEW(m_owner
->m_treeview
);
1460 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1464 iter
.stamp
= m_wxgtk_model
->stamp
;
1465 iter
.user_data
= (gpointer
) item
.GetID();
1466 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1467 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1468 GdkRectangle cell_area
;
1469 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1470 gtk_tree_path_free( path
);
1472 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1473 double d
= gtk_adjustment_get_value( hadjust
);
1474 int xdiff
= (int) d
;
1476 int ydiff
= gcolumn
->button
->allocation
.height
;
1478 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1479 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1481 m_owner
->GtkGetInternal()->ValueChanged( item
, model_col
);
1490 bool wxGtkDataViewModelNotifier::Cleared()
1492 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->m_treeview
), NULL
);
1494 // this will create a new GTK model
1495 m_owner
->GtkGetInternal()->Cleared();
1497 SetGtkModel( m_owner
->GtkGetInternal()->GetGtkModel() );
1499 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->m_treeview
), GTK_TREE_MODEL(m_wxgtk_model
) );
1504 // ---------------------------------------------------------
1505 // wxDataViewRenderer
1506 // ---------------------------------------------------------
1508 static gpointer s_user_data
= NULL
;
1511 wxgtk_cell_editable_editing_done( GtkCellEditable
*WXUNUSED(editable
),
1512 wxDataViewRenderer
*wxrenderer
)
1514 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1515 wxDataViewCtrl
*dv
= column
->GetOwner();
1516 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1517 event
.SetDataViewColumn( column
);
1518 event
.SetModel( dv
->GetModel() );
1519 wxDataViewItem
item( s_user_data
);
1520 event
.SetItem( item
);
1521 dv
->HandleWindowEvent( event
);
1525 wxgtk_renderer_editing_started( GtkCellRenderer
*WXUNUSED(cell
), GtkCellEditable
*editable
,
1526 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1531 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1532 wxDataViewCtrl
*dv
= column
->GetOwner();
1533 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1534 event
.SetDataViewColumn( column
);
1535 event
.SetModel( dv
->GetModel() );
1536 GtkTreePath
*tree_path
= gtk_tree_path_new_from_string( path
);
1538 dv
->GtkGetInternal()->get_iter( &iter
, tree_path
);
1539 gtk_tree_path_free( tree_path
);
1540 wxDataViewItem
item( iter
.user_data
);
1541 event
.SetItem( item
);
1542 dv
->HandleWindowEvent( event
);
1544 if (GTK_IS_CELL_EDITABLE(editable
))
1546 s_user_data
= iter
.user_data
;
1548 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1549 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1550 (gpointer
) wxrenderer
);
1556 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1558 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1560 wxDataViewRendererBase( varianttype
, mode
, align
)
1564 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1565 // after the m_renderer pointer has been initialized
1568 void wxDataViewRenderer::GtkInitHandlers()
1570 if (!gtk_check_version(2,6,0))
1572 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1573 G_CALLBACK (wxgtk_renderer_editing_started
),
1578 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1580 GtkCellRendererMode gtkMode
;
1583 case wxDATAVIEW_CELL_INERT
:
1584 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1587 case wxDATAVIEW_CELL_ACTIVATABLE
:
1588 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1591 case wxDATAVIEW_CELL_EDITABLE
:
1592 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1596 wxFAIL_MSG( "unknown wxDataViewCellMode value" );
1600 // This value is most often ignored in GtkTreeView
1601 GValue gvalue
= { 0, };
1602 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1603 g_value_set_enum( &gvalue
, gtkMode
);
1604 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1605 g_value_unset( &gvalue
);
1608 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1610 wxDataViewCellMode ret
;
1613 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1615 switch (g_value_get_enum(&gvalue
))
1618 wxFAIL_MSG( "unknown GtkCellRendererMode value" );
1619 // fall through (we have to return something)
1621 case GTK_CELL_RENDERER_MODE_INERT
:
1622 ret
= wxDATAVIEW_CELL_INERT
;
1625 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1626 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1629 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1630 ret
= wxDATAVIEW_CELL_EDITABLE
;
1634 g_value_unset( &gvalue
);
1639 void wxDataViewRenderer::GtkUpdateAlignment()
1641 int align
= m_alignment
;
1643 // query alignment from column ?
1647 if (GetOwner() == NULL
)
1650 align
= GetOwner()->GetAlignment();
1651 align
|= wxALIGN_CENTRE_VERTICAL
;
1654 // horizontal alignment:
1656 gfloat xalign
= 0.0;
1657 if (align
& wxALIGN_RIGHT
)
1659 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1662 GValue gvalue
= { 0, };
1663 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1664 g_value_set_float( &gvalue
, xalign
);
1665 g_object_set_property( G_OBJECT(m_renderer
), "xalign", &gvalue
);
1666 g_value_unset( &gvalue
);
1668 // vertical alignment:
1670 gfloat yalign
= 0.0;
1671 if (align
& wxALIGN_BOTTOM
)
1673 else if (align
& wxALIGN_CENTER_VERTICAL
)
1676 GValue gvalue2
= { 0, };
1677 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1678 g_value_set_float( &gvalue2
, yalign
);
1679 g_object_set_property( G_OBJECT(m_renderer
), "yalign", &gvalue2
);
1680 g_value_unset( &gvalue2
);
1683 void wxDataViewRenderer::SetAlignment( int align
)
1685 m_alignment
= align
;
1686 GtkUpdateAlignment();
1689 int wxDataViewRenderer::GetAlignment() const
1694 // ---------------------------------------------------------
1695 // wxDataViewTextRenderer
1696 // ---------------------------------------------------------
1699 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1700 gchar
*arg1
, gchar
*arg2
, gpointer user_data
);
1703 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*WXUNUSED(renderer
),
1704 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1706 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) user_data
;
1708 wxString tmp
= wxGTK_CONV_BACK_FONT(arg2
, cell
->GetOwner()->GetOwner()->GetFont());
1709 wxVariant value
= tmp
;
1710 if (!cell
->Validate( value
))
1713 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1715 GtkTreePath
*path
= gtk_tree_path_new_from_string( arg1
);
1717 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, path
);
1718 wxDataViewItem
item( (void*) iter
.user_data
);;
1719 gtk_tree_path_free( path
);
1721 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1723 model
->SetValue( value
, item
, model_col
);
1724 model
->ValueChanged( item
, model_col
);
1727 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
1729 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1731 wxDataViewRenderer( varianttype
, mode
, align
)
1733 GtkWxCellRendererText
*text_renderer
= gtk_wx_cell_renderer_text_new();
1734 text_renderer
->wx_renderer
= this;
1735 m_renderer
= (GtkCellRenderer
*) text_renderer
;
1737 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
1739 GValue gvalue
= { 0, };
1740 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1741 g_value_set_boolean( &gvalue
, true );
1742 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
1743 g_value_unset( &gvalue
);
1745 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
1751 SetAlignment(align
);
1754 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
1756 wxString tmp
= value
;
1758 GValue gvalue
= { 0, };
1759 g_value_init( &gvalue
, G_TYPE_STRING
);
1760 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( tmp
, GetOwner()->GetOwner()->GetFont() ) );
1761 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1762 g_value_unset( &gvalue
);
1767 bool wxDataViewTextRenderer::GetValue( wxVariant
&value
) const
1769 GValue gvalue
= { 0, };
1770 g_value_init( &gvalue
, G_TYPE_STRING
);
1771 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1772 wxString tmp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
), const_cast<wxDataViewTextRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
1773 g_value_unset( &gvalue
);
1780 void wxDataViewTextRenderer::SetAlignment( int align
)
1782 wxDataViewRenderer::SetAlignment(align
);
1784 if (gtk_check_version(2,10,0))
1787 // horizontal alignment:
1788 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
1789 if (align
& wxALIGN_RIGHT
)
1790 pangoAlign
= PANGO_ALIGN_RIGHT
;
1791 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1792 pangoAlign
= PANGO_ALIGN_CENTER
;
1794 GValue gvalue
= { 0, };
1795 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1796 g_value_set_enum( &gvalue
, pangoAlign
);
1797 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
1798 g_value_unset( &gvalue
);
1801 // ---------------------------------------------------------
1802 // wxDataViewTextRendererAttr
1803 // ---------------------------------------------------------
1805 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
,wxDataViewTextRenderer
)
1807 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString
&varianttype
,
1808 wxDataViewCellMode mode
, int align
) :
1809 wxDataViewTextRenderer( varianttype
, mode
, align
)
1813 // ---------------------------------------------------------
1814 // wxDataViewBitmapRenderer
1815 // ---------------------------------------------------------
1817 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
1819 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1821 wxDataViewRenderer( varianttype
, mode
, align
)
1823 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_pixbuf_new();
1826 SetAlignment(align
);
1829 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
1831 if (value
.GetType() == wxT("wxBitmap"))
1836 // This may create a Pixbuf representation in the
1837 // wxBitmap object (and it will stay there)
1838 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1840 GValue gvalue
= { 0, };
1841 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1842 g_value_set_object( &gvalue
, pixbuf
);
1843 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1844 g_value_unset( &gvalue
);
1849 if (value
.GetType() == wxT("wxIcon"))
1854 // This may create a Pixbuf representation in the
1855 // wxBitmap object (and it will stay there)
1856 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1858 GValue gvalue
= { 0, };
1859 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1860 g_value_set_object( &gvalue
, pixbuf
);
1861 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1862 g_value_unset( &gvalue
);
1870 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
1875 // ---------------------------------------------------------
1876 // wxDataViewToggleRenderer
1877 // ---------------------------------------------------------
1880 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1881 gchar
*path
, gpointer user_data
);
1884 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1885 gchar
*path
, gpointer user_data
)
1887 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
1890 GValue gvalue
= { 0, };
1891 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1892 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
1893 bool tmp
= g_value_get_boolean( &gvalue
);
1894 g_value_unset( &gvalue
);
1898 wxVariant value
= tmp
;
1899 if (!cell
->Validate( value
))
1902 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1904 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
1906 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, gtk_path
);
1907 wxDataViewItem
item( (void*) iter
.user_data
);;
1908 gtk_tree_path_free( gtk_path
);
1910 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1912 model
->SetValue( value
, item
, model_col
);
1913 model
->ValueChanged( item
, model_col
);
1916 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1918 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1919 wxDataViewCellMode mode
, int align
) :
1920 wxDataViewRenderer( varianttype
, mode
, align
)
1922 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
1924 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1926 g_signal_connect_after( m_renderer
, "toggled",
1927 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
1931 GValue gvalue
= { 0, };
1932 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1933 g_value_set_boolean( &gvalue
, false );
1934 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
1935 g_value_unset( &gvalue
);
1939 SetAlignment(align
);
1942 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1946 GValue gvalue
= { 0, };
1947 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1948 g_value_set_boolean( &gvalue
, tmp
);
1949 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1950 g_value_unset( &gvalue
);
1955 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
1957 GValue gvalue
= { 0, };
1958 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1959 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1960 bool tmp
= g_value_get_boolean( &gvalue
);
1961 g_value_unset( &gvalue
);
1968 // ---------------------------------------------------------
1969 // wxDataViewCustomRenderer
1970 // ---------------------------------------------------------
1972 class wxDataViewCtrlDCImpl
: public wxWindowDCImpl
1975 wxDataViewCtrlDCImpl( wxDC
*owner
, wxDataViewCtrl
*window
) :
1976 wxWindowDCImpl( owner
)
1978 GtkWidget
*widget
= window
->m_treeview
;
1984 m_context
= window
->GTKGetPangoDefaultContext();
1985 m_layout
= pango_layout_new( m_context
);
1986 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
1988 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
1990 // Set m_gdkwindow later
1995 class wxDataViewCtrlDC
: public wxWindowDC
1998 wxDataViewCtrlDC( wxDataViewCtrl
*window
) :
1999 wxWindowDC( new wxDataViewCtrlDCImpl( this, window
) )
2004 // ---------------------------------------------------------
2005 // wxDataViewCustomRenderer
2006 // ---------------------------------------------------------
2008 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
2010 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
2011 wxDataViewCellMode mode
, int align
,
2013 wxDataViewRenderer( varianttype
, mode
, align
)
2016 m_text_renderer
= NULL
;
2024 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
,
2025 wxRect
WXUNUSED(cell
), wxDC
*WXUNUSED(dc
), int WXUNUSED(state
) )
2028 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
2029 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
2030 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
2031 view
->GetForegroundColour();
2032 dc
->SetTextForeground(col
);
2033 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
2035 if (!m_text_renderer
)
2036 m_text_renderer
= gtk_cell_renderer_text_new();
2038 GValue gvalue
= { 0, };
2039 g_value_init( &gvalue
, G_TYPE_STRING
);
2040 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( text
, GetOwner()->GetOwner()->GetFont() ) );
2041 g_object_set_property( G_OBJECT(m_text_renderer
), "text", &gvalue
);
2042 g_value_unset( &gvalue
);
2044 ((GdkRectangle
*) cell_area
)->x
+= xoffset
;
2045 ((GdkRectangle
*) cell_area
)->width
-= xoffset
;
2047 gtk_cell_renderer_render( m_text_renderer
,
2050 (GdkRectangle
*) background_area
,
2051 (GdkRectangle
*) cell_area
,
2052 (GdkRectangle
*) expose_area
,
2053 (GtkCellRendererState
) flags
);
2055 ((GdkRectangle
*) cell_area
)->x
-= xoffset
;
2056 ((GdkRectangle
*) cell_area
)->width
+= xoffset
;
2060 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
2062 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
2063 renderer
->cell
= this;
2065 m_renderer
= (GtkCellRenderer
*) renderer
;
2068 SetAlignment(align
);
2075 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
2080 if (m_text_renderer
)
2081 gtk_object_sink( GTK_OBJECT(m_text_renderer
) );
2084 wxDC
*wxDataViewCustomRenderer::GetDC()
2088 if (GetOwner() == NULL
)
2090 if (GetOwner()->GetOwner() == NULL
)
2092 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
2098 // ---------------------------------------------------------
2099 // wxDataViewProgressRenderer
2100 // ---------------------------------------------------------
2102 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
2104 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
2105 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
2106 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
2112 if (!gtk_check_version(2,6,0))
2114 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
2116 GValue gvalue
= { 0, };
2117 g_value_init( &gvalue
, G_TYPE_STRING
);
2119 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( m_label
, GetOwner()->GetOwner()->GetFont() ) );
2120 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2121 g_value_unset( &gvalue
);
2124 SetAlignment(align
);
2129 // Use custom cell code
2130 wxDataViewCustomRenderer::Init(mode
, align
);
2134 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
2138 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
2141 if (!gtk_check_version(2,6,0))
2143 gint tmp
= (long) value
;
2144 GValue gvalue
= { 0, };
2145 g_value_init( &gvalue
, G_TYPE_INT
);
2146 g_value_set_int( &gvalue
, tmp
);
2147 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
2148 g_value_unset( &gvalue
);
2153 m_value
= (long) value
;
2155 if (m_value
< 0) m_value
= 0;
2156 if (m_value
> 100) m_value
= 100;
2162 bool wxDataViewProgressRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2167 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
2169 double pct
= (double)m_value
/ 100.0;
2171 bar
.width
= (int)(cell
.width
* pct
);
2172 dc
->SetPen( *wxTRANSPARENT_PEN
);
2173 dc
->SetBrush( *wxBLUE_BRUSH
);
2174 dc
->DrawRectangle( bar
);
2176 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
2177 dc
->SetPen( *wxBLACK_PEN
);
2178 dc
->DrawRectangle( cell
);
2183 wxSize
wxDataViewProgressRenderer::GetSize() const
2185 return wxSize(40,12);
2188 // -------------------------------------
2189 // wxDataViewChoiceRenderer
2190 // -------------------------------------
2192 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
&choices
,
2193 wxDataViewCellMode mode
, int alignment
) :
2194 wxDataViewCustomRenderer( "string", mode
, alignment
, true )
2196 m_choices
= choices
;
2199 if (!gtk_check_version(2,6,0))
2201 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_combo_new();
2203 GtkListStore
*store
= gtk_list_store_new( 1, G_TYPE_STRING
);
2204 for (size_t n
= 0; n
< m_choices
.GetCount(); n
++)
2206 gtk_list_store_insert_with_values(
2208 static_cast<const char *>(m_choices
[n
].utf8_str()), -1 );
2211 g_object_set (m_renderer
,
2217 bool editable
= (mode
& wxDATAVIEW_CELL_EDITABLE
);
2218 g_object_set (m_renderer
, "editable", editable
, NULL
);
2220 SetAlignment(alignment
);
2222 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2229 // Use custom cell code
2230 wxDataViewCustomRenderer::Init(mode
, alignment
);
2234 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
2236 RenderText( m_data
, 0, rect
, dc
, state
);
2240 wxSize
wxDataViewChoiceRenderer::GetSize() const
2242 return wxSize(70,20);
2245 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
2249 if (!gtk_check_version(2,6,0))
2251 GValue gvalue
= { 0, };
2252 g_value_init( &gvalue
, G_TYPE_STRING
);
2253 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( value
.GetString(), GetOwner()->GetOwner()->GetFont() ) );
2254 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2255 g_value_unset( &gvalue
);
2259 m_data
= value
.GetString();
2264 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
2267 if (!gtk_check_version(2,6,0))
2269 GValue gvalue
= { 0, };
2270 g_value_init( &gvalue
, G_TYPE_STRING
);
2271 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2272 wxString temp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
),
2273 const_cast<wxDataViewChoiceRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
2274 g_value_unset( &gvalue
);
2277 //wxPrintf( "temp %s\n", temp );
2278 // TODO: remove this code
2287 void wxDataViewChoiceRenderer::SetAlignment( int align
)
2289 wxDataViewCustomRenderer::SetAlignment(align
);
2291 if (gtk_check_version(2,10,0))
2294 // horizontal alignment:
2295 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2296 if (align
& wxALIGN_RIGHT
)
2297 pangoAlign
= PANGO_ALIGN_RIGHT
;
2298 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2299 pangoAlign
= PANGO_ALIGN_CENTER
;
2301 GValue gvalue
= { 0, };
2302 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2303 g_value_set_enum( &gvalue
, pangoAlign
);
2304 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2305 g_value_unset( &gvalue
);
2308 // ---------------------------------------------------------
2309 // wxDataViewDateRenderer
2310 // ---------------------------------------------------------
2312 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
2315 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
2316 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
2317 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
2322 m_cal
= new wxCalendarCtrl( this, -1, *value
);
2323 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
2324 sizer
->Add( m_cal
, 1, wxGROW
);
2329 virtual void OnDismiss()
2333 void OnCalendar( wxCalendarEvent
&event
);
2335 wxCalendarCtrl
*m_cal
;
2336 wxDataViewModel
*m_model
;
2337 wxDataViewItem m_item
;
2341 DECLARE_EVENT_TABLE()
2344 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
2345 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
2348 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
2350 wxDateTime date
= event
.GetDate();
2351 wxVariant value
= date
;
2352 m_model
->SetValue( value
, m_item
, m_col
);
2353 m_model
->ValueChanged( m_item
, m_col
);
2357 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
2359 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
2360 wxDataViewCellMode mode
, int align
) :
2361 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2364 SetAlignment(align
);
2367 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
2369 m_date
= value
.GetDateTime();
2374 bool wxDataViewDateRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2379 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2381 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
2382 wxString tmp
= m_date
.FormatDate();
2383 RenderText( tmp
, 0, cell
, dc
, state
);
2387 wxSize
wxDataViewDateRenderer::GetSize() const
2389 wxString tmp
= m_date
.FormatDate();
2391 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
2392 return wxSize(x
,y
+d
);
2395 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
2396 const wxDataViewItem
&item
, unsigned int col
)
2399 model
->GetValue( variant
, item
, col
);
2400 wxDateTime value
= variant
.GetDateTime();
2402 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
2403 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
2404 wxPoint pos
= wxGetMousePosition();
2407 popup
->Popup( popup
->m_cal
);
2413 // ---------------------------------------------------------
2414 // wxDataViewIconTextRenderer
2415 // ---------------------------------------------------------
2417 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
2419 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
2420 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
2421 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2424 SetAlignment(align
);
2427 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2431 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
2437 bool wxDataViewIconTextRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2442 bool wxDataViewIconTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2444 const wxIcon
&icon
= m_value
.GetIcon();
2448 int yoffset
= wxMax( 0, (cell
.height
- icon
.GetHeight()) / 2 );
2449 dc
->DrawIcon( icon
, cell
.x
, cell
.y
+ yoffset
);
2450 offset
= icon
.GetWidth() + 4;
2453 RenderText( m_value
.GetText(), offset
, cell
, dc
, state
);
2458 wxSize
wxDataViewIconTextRenderer::GetSize() const
2461 if (m_value
.GetIcon().IsOk())
2462 size
.x
= 4 + m_value
.GetIcon().GetWidth();
2464 GetView()->GetTextExtent( m_value
.GetText(), &x
, &y
, &d
);
2470 wxControl
* wxDataViewIconTextRenderer::CreateEditorCtrl(
2471 wxWindow
*WXUNUSED(parent
), wxRect
WXUNUSED(labelRect
), const wxVariant
&WXUNUSED(value
) )
2476 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl(
2477 wxControl
* WXUNUSED(editor
), wxVariant
&WXUNUSED(value
) )
2482 // ---------------------------------------------------------
2484 // ---------------------------------------------------------
2488 gtk_dataview_header_button_press_callback( GtkWidget
*WXUNUSED(widget
),
2489 GdkEventButton
*gdk_event
,
2490 wxDataViewColumn
*column
)
2492 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
2495 if (gdk_event
->button
== 1)
2497 gs_lastLeftClickHeader
= column
;
2499 wxDataViewCtrl
*dv
= column
->GetOwner();
2500 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
2501 event
.SetDataViewColumn( column
);
2502 event
.SetModel( dv
->GetModel() );
2503 if (dv
->HandleWindowEvent( event
))
2507 if (gdk_event
->button
== 3)
2509 wxDataViewCtrl
*dv
= column
->GetOwner();
2510 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
2511 event
.SetDataViewColumn( column
);
2512 event
.SetModel( dv
->GetModel() );
2513 if (dv
->HandleWindowEvent( event
))
2521 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
2522 GtkCellRenderer
*cell
,
2523 GtkTreeModel
*model
,
2529 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*WXUNUSED(column
),
2530 GtkCellRenderer
*renderer
,
2531 GtkTreeModel
*model
,
2535 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2536 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2538 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2540 wxDataViewItem
item( (void*) iter
->user_data
);
2542 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
2544 if (!wx_model
->IsVirtualListModel())
2547 if (wx_model
->IsContainer( item
))
2549 if (wx_model
->HasContainerColumns( item
) || (cell
->GetOwner()->GetModelColumn() == 0))
2551 GValue gvalue
= { 0, };
2552 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2553 g_value_set_boolean( &gvalue
, TRUE
);
2554 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2555 g_value_unset( &gvalue
);
2559 GValue gvalue
= { 0, };
2560 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2561 g_value_set_boolean( &gvalue
, FALSE
);
2562 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2563 g_value_unset( &gvalue
);
2570 GValue gvalue
= { 0, };
2571 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2572 g_value_set_boolean( &gvalue
, TRUE
);
2573 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2574 g_value_unset( &gvalue
);
2580 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
2582 if (value
.GetType() != cell
->GetVariantType())
2583 wxLogError( wxT("Wrong type, required: %s but: %s"),
2584 value
.GetType().c_str(),
2585 cell
->GetVariantType().c_str() );
2587 cell
->SetValue( value
);
2589 if (cell
->GtkHasAttributes())
2591 wxDataViewItemAttr attr
;
2592 bool colour_set
= false;
2593 bool style_set
= false;
2594 bool weight_set
= false;
2596 if (wx_model
->GetAttr( item
, cell
->GetOwner()->GetModelColumn(), attr
))
2598 // this must be a GtkCellRendererText
2599 wxColour colour
= attr
.GetColour();
2602 const GdkColor
* const gcol
= colour
.GetColor();
2604 GValue gvalue
= { 0, };
2605 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2606 g_value_set_boxed( &gvalue
, gcol
);
2607 g_object_set_property( G_OBJECT(renderer
), "foreground_gdk", &gvalue
);
2608 g_value_unset( &gvalue
);
2613 if (attr
.GetItalic())
2615 GValue gvalue
= { 0, };
2616 g_value_init( &gvalue
, PANGO_TYPE_STYLE
);
2617 g_value_set_enum( &gvalue
, PANGO_STYLE_ITALIC
);
2618 g_object_set_property( G_OBJECT(renderer
), "style", &gvalue
);
2619 g_value_unset( &gvalue
);
2626 GValue gvalue
= { 0, };
2627 g_value_init( &gvalue
, PANGO_TYPE_WEIGHT
);
2628 g_value_set_enum( &gvalue
, PANGO_WEIGHT_BOLD
);
2629 g_object_set_property( G_OBJECT(renderer
), "weight", &gvalue
);
2630 g_value_unset( &gvalue
);
2638 GValue gvalue
= { 0, };
2639 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2640 g_value_set_boolean( &gvalue
, FALSE
);
2641 g_object_set_property( G_OBJECT(renderer
), "style-set", &gvalue
);
2642 g_value_unset( &gvalue
);
2647 GValue gvalue
= { 0, };
2648 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2649 g_value_set_boolean( &gvalue
, FALSE
);
2650 g_object_set_property( G_OBJECT(renderer
), "weight-set", &gvalue
);
2651 g_value_unset( &gvalue
);
2656 GValue gvalue
= { 0, };
2657 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2658 g_value_set_boolean( &gvalue
, FALSE
);
2659 g_object_set_property( G_OBJECT(renderer
), "foreground-set", &gvalue
);
2660 g_value_unset( &gvalue
);
2665 if (attr
.HasBackgroundColour())
2667 wxColour colour
= attr
.GetBackgroundColour();
2668 const GdkColor
* const gcol
= colour
.GetColor();
2670 GValue gvalue
= { 0, };
2671 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2672 g_value_set_boxed( &gvalue
, gcol
);
2673 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
2674 g_value_unset( &gvalue
);
2678 GValue gvalue
= { 0, };
2679 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2680 g_value_set_boolean( &gvalue
, FALSE
);
2681 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
2682 g_value_unset( &gvalue
);
2688 #include <wx/listimpl.cpp>
2689 WX_DEFINE_LIST(wxDataViewColumnList
)
2691 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
2692 unsigned int model_column
, int width
,
2693 wxAlignment align
, int flags
)
2694 : wxDataViewColumnBase( cell
, model_column
)
2696 Init( align
, flags
, width
);
2701 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
2702 unsigned int model_column
, int width
,
2703 wxAlignment align
, int flags
)
2704 : wxDataViewColumnBase( bitmap
, cell
, model_column
)
2706 Init( align
, flags
, width
);
2708 SetBitmap( bitmap
);
2711 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
2713 m_isConnected
= false;
2715 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) GetRenderer()->GetGtkHandle();
2716 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
2717 m_column
= (GtkWidget
*) column
;
2720 SetAlignment( align
);
2724 // Create container for icon and label
2725 GtkWidget
*box
= gtk_hbox_new( FALSE
, 1 );
2726 gtk_widget_show( box
);
2727 // gtk_container_set_border_width((GtkContainer*)box, 2);
2728 m_image
= gtk_image_new();
2729 gtk_box_pack_start(GTK_BOX(box
), m_image
, FALSE
, FALSE
, 1);
2730 m_label
= gtk_label_new("");
2731 gtk_box_pack_end( GTK_BOX(box
), GTK_WIDGET(m_label
), FALSE
, FALSE
, 1 );
2732 gtk_tree_view_column_set_widget( column
, box
);
2734 gtk_tree_view_column_pack_end( column
, renderer
, TRUE
);
2736 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
2737 wxGtkTreeCellDataFunc
, (gpointer
) GetRenderer(), NULL
);
2740 void wxDataViewColumn::OnInternalIdle()
2745 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
2747 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2750 g_signal_connect(column
->button
, "button_press_event",
2751 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
2753 m_isConnected
= true;
2758 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
2760 wxDataViewColumnBase::SetOwner( owner
);
2762 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2764 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
2767 void wxDataViewColumn::SetTitle( const wxString
&title
)
2769 wxDataViewCtrl
*ctrl
= GetOwner();
2770 gtk_label_set_text( GTK_LABEL(m_label
), ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
2771 : wxGTK_CONV_SYS(title
) );
2773 gtk_widget_hide( m_label
);
2775 gtk_widget_show( m_label
);
2778 wxString
wxDataViewColumn::GetTitle() const
2780 return wxGTK_CONV_BACK_FONT(
2781 gtk_label_get_text( GTK_LABEL(m_label
) ),
2782 GetOwner()->GetFont()
2786 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
2788 wxDataViewColumnBase::SetBitmap( bitmap
);
2792 GtkImage
*gtk_image
= GTK_IMAGE(m_image
);
2794 GdkBitmap
*mask
= NULL
;
2795 if (bitmap
.GetMask())
2796 mask
= bitmap
.GetMask()->GetBitmap();
2798 if (bitmap
.HasPixbuf())
2800 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
2801 bitmap
.GetPixbuf());
2805 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
2806 bitmap
.GetPixmap(), mask
);
2808 gtk_widget_show( m_image
);
2812 gtk_widget_hide( m_image
);
2816 void wxDataViewColumn::SetHidden( bool hidden
)
2818 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
2821 void wxDataViewColumn::SetResizeable( bool resizeable
)
2823 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizeable
);
2826 void wxDataViewColumn::SetAlignment( wxAlignment align
)
2828 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2830 gfloat xalign
= 0.0;
2831 if (align
== wxALIGN_RIGHT
)
2833 if (align
== wxALIGN_CENTER_HORIZONTAL
||
2834 align
== wxALIGN_CENTER
)
2837 gtk_tree_view_column_set_alignment( column
, xalign
);
2839 if (m_renderer
&& m_renderer
->GetAlignment() == -1)
2840 m_renderer
->GtkUpdateAlignment();
2843 wxAlignment
wxDataViewColumn::GetAlignment() const
2845 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
2848 return wxALIGN_RIGHT
;
2850 return wxALIGN_CENTER_HORIZONTAL
;
2852 return wxALIGN_LEFT
;
2855 void wxDataViewColumn::SetSortable( bool sortable
)
2857 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2861 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
2865 gtk_tree_view_column_set_sort_column_id( column
, -1 );
2866 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
2867 gtk_tree_view_column_set_clickable( column
, FALSE
);
2871 bool wxDataViewColumn::IsSortable() const
2873 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2874 return gtk_tree_view_column_get_clickable( column
);
2877 void wxDataViewColumn::SetAsSortKey( bool WXUNUSED(sort
) )
2879 // it might not make sense to have this function in wxHeaderColumn at
2880 // all in fact, changing of the sort order should only be done using the
2881 // associated control API
2882 wxFAIL_MSG( "not implemented" );
2885 bool wxDataViewColumn::IsSortKey() const
2887 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2888 return gtk_tree_view_column_get_sort_indicator( column
);
2891 bool wxDataViewColumn::IsResizeable() const
2893 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2894 return gtk_tree_view_column_get_resizable( column
);
2897 bool wxDataViewColumn::IsHidden() const
2899 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2900 return !gtk_tree_view_column_get_visible( column
);
2903 void wxDataViewColumn::SetSortOrder( bool ascending
)
2905 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2908 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
2910 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
2912 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
2915 bool wxDataViewColumn::IsSortOrderAscending() const
2917 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2919 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
2922 void wxDataViewColumn::SetMinWidth( int width
)
2924 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2927 int wxDataViewColumn::GetMinWidth() const
2929 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2932 int wxDataViewColumn::GetWidth() const
2934 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2937 void wxDataViewColumn::SetWidth( int width
)
2942 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
2944 // TODO find a better calculation
2945 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), wxDVC_DEFAULT_WIDTH
);
2947 // this is unpractical for large numbers of items and disables
2948 // user resizing, which is totally unexpected
2949 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
2954 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
2956 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2960 void wxDataViewColumn::SetReorderable( bool reorderable
)
2962 gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column
), reorderable
);
2965 bool wxDataViewColumn::IsReorderable() const
2967 return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column
) );
2970 //-----------------------------------------------------------------------------
2971 // wxGtkTreeModelNode
2972 //-----------------------------------------------------------------------------
2975 class wxGtkTreeModelChildWithPos
2983 int wxGtkTreeModelChildWithPosCmp( const void* data1
, const void* data2
, const void* user_data
)
2985 const wxGtkTreeModelChildWithPos
* child1
= (const wxGtkTreeModelChildWithPos
*) data1
;
2986 const wxGtkTreeModelChildWithPos
* child2
= (const wxGtkTreeModelChildWithPos
*) data2
;
2987 const wxDataViewCtrlInternal
*internal
= (const wxDataViewCtrlInternal
*) user_data
;
2988 int ret
= internal
->GetDataViewModel()->Compare( child1
->id
, child2
->id
,
2989 internal
->GetSortColumn(), (internal
->GetSortOrder() == GTK_SORT_DESCENDING
) );
2995 int LINKAGEMODE
wxGtkTreeModelChildPtrCmp( void*** data1
, void*** data2
)
2997 return gs_internal
->GetDataViewModel()->Compare( **data1
, **data2
,
2998 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
3001 WX_DEFINE_ARRAY_PTR( void**, wxGtkTreeModelChildrenPtr
);
3004 void wxGtkTreeModelNode::Resort()
3006 size_t child_count
= GetChildCount();
3007 if (child_count
== 0)
3010 size_t node_count
= GetNodesCount();
3012 if (child_count
== 1)
3014 if (node_count
== 1)
3016 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
3022 gint
*new_order
= new gint
[child_count
];
3025 // m_children has the original *void
3026 // ptrs points to these
3027 wxGtkTreeModelChildrenPtr ptrs
;
3029 for (i
= 0; i
< child_count
; i
++)
3030 ptrs
.Add( &(m_children
[i
]) );
3032 gs_internal
= m_internal
;
3033 ptrs
.Sort( &wxGtkTreeModelChildPtrCmp
);
3035 wxGtkTreeModelChildren temp
;
3036 void** base_ptr
= &(m_children
[0]);
3037 // Transfer positions to new_order array and
3039 for (i
= 0; i
< child_count
; i
++)
3041 new_order
[i
] = ptrs
[i
] - base_ptr
;
3042 temp
.Add( *ptrs
[i
] );
3045 // Transfer IDs back to m_children
3047 WX_APPEND_ARRAY( temp
, m_children
);
3052 // Build up array with IDs and original positions
3053 wxGtkTreeModelChildWithPos
* temp
= new wxGtkTreeModelChildWithPos
[child_count
];
3055 for (i
= 0; i
< child_count
; i
++)
3058 temp
[i
].id
= m_children
[i
];
3060 // Sort array keeping original positions
3061 wxQsort( temp
, child_count
, sizeof(wxGtkTreeModelChildWithPos
),
3062 &wxGtkTreeModelChildWithPosCmp
, m_internal
);
3063 // Transfer positions to new_order array and
3064 // IDs to m_children
3066 for (i
= 0; i
< child_count
; i
++)
3068 new_order
[i
] = temp
[i
].pos
;
3069 m_children
.Add( temp
[i
].id
);
3078 wxGtkTreeModelChildren temp
;
3079 WX_APPEND_ARRAY( temp
, m_children
);
3081 gs_internal
= m_internal
;
3082 m_children
.Sort( &wxGtkTreeModelChildCmp
);
3085 for (pos
= 0; pos
< child_count
; pos
++)
3087 void *id
= m_children
.Item( pos
);
3088 int old_pos
= temp
.Index( id
);
3089 new_order
[pos
] = old_pos
;
3093 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
3096 iter
.user_data
= GetItem().GetID();
3097 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
3099 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3101 gtk_tree_model_rows_reordered( gtk_tree_model
, path
, &iter
, new_order
);
3103 gtk_tree_path_free (path
);
3105 delete [] new_order
;
3108 for (pos
= 0; pos
< node_count
; pos
++)
3110 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
3115 //-----------------------------------------------------------------------------
3116 // wxDataViewCtrlInternal
3117 //-----------------------------------------------------------------------------
3119 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
,
3120 wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
)
3123 m_wx_model
= wx_model
;
3124 m_gtk_model
= gtk_model
;
3126 m_sort_order
= GTK_SORT_ASCENDING
;
3128 m_dataview_sort_column
= NULL
;
3130 m_dragDataObject
= NULL
;
3131 m_dropDataObject
= NULL
;
3133 if (!m_wx_model
->IsVirtualListModel())
3137 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
3139 g_object_unref( m_gtk_model
);
3141 delete m_dragDataObject
;
3142 delete m_dropDataObject
;
3145 void wxDataViewCtrlInternal::InitTree()
3147 wxDataViewItem item
;
3148 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
3150 BuildBranch( m_root
);
3153 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
3155 if (node
->GetChildCount() == 0)
3157 wxDataViewItemArray children
;
3158 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
3160 for (pos
= 0; pos
< count
; pos
++)
3162 wxDataViewItem child
= children
[pos
];
3164 if (m_wx_model
->IsContainer( child
))
3165 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
3167 node
->AddLeave( child
.GetID() );
3169 // Don't send any events here
3176 bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat
&format
)
3178 wxGtkString
atom_str( gdk_atom_name( format
) );
3179 m_dragSourceTargetEntryTarget
= wxCharBuffer( atom_str
);
3181 m_dragSourceTargetEntry
.target
= m_dragSourceTargetEntryTarget
.data();
3182 m_dragSourceTargetEntry
.flags
= 0;
3183 m_dragSourceTargetEntry
.info
= static_cast<guint
>(-1);
3185 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3186 GDK_BUTTON1_MASK
, &m_dragSourceTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3191 bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat
&format
)
3193 wxGtkString
atom_str( gdk_atom_name( format
) );
3194 m_dropTargetTargetEntryTarget
= wxCharBuffer( atom_str
);
3196 m_dropTargetTargetEntry
.target
= m_dropTargetTargetEntryTarget
.data();
3197 m_dropTargetTargetEntry
.flags
= 0;
3198 m_dropTargetTargetEntry
.info
= static_cast<guint
>(-1);
3200 gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3201 &m_dropTargetTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3206 gboolean
wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource
*WXUNUSED(drag_source
),
3209 delete m_dragDataObject
;
3212 if (!get_iter( &iter
, path
)) return FALSE
;
3213 wxDataViewItem
item( (void*) iter
.user_data
);
3215 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3216 event
.SetEventObject( m_owner
);
3217 event
.SetItem( item
);
3218 event
.SetModel( m_wx_model
);
3219 if (!m_owner
->HandleWindowEvent( event
))
3222 if (!event
.IsAllowed())
3225 wxDataObject
*obj
= event
.GetDataObject();
3229 m_dragDataObject
= obj
;
3235 wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource
*WXUNUSED(drag_source
),
3236 GtkTreePath
*WXUNUSED(path
))
3241 gboolean
wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource
*WXUNUSED(drag_source
),
3242 GtkTreePath
*path
, GtkSelectionData
*selection_data
)
3245 if (!get_iter( &iter
, path
)) return FALSE
;
3246 wxDataViewItem
item( (void*) iter
.user_data
);
3248 if (!m_dragDataObject
->IsSupported( selection_data
->target
))
3251 size_t size
= m_dragDataObject
->GetDataSize( selection_data
->target
);
3255 void *buf
= malloc( size
);
3257 gboolean res
= FALSE
;
3258 if (m_dragDataObject
->GetDataHere( selection_data
->target
, buf
))
3262 gtk_selection_data_set( selection_data
, selection_data
->target
,
3263 8, (const guchar
*) buf
, size
);
3272 wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3274 GtkSelectionData
*selection_data
)
3277 if (!get_iter( &iter
, path
)) return FALSE
;
3278 wxDataViewItem
item( (void*) iter
.user_data
);
3280 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
3281 event
.SetEventObject( m_owner
);
3282 event
.SetItem( item
);
3283 event
.SetModel( m_wx_model
);
3284 event
.SetDataFormat( selection_data
->target
);
3285 event
.SetDataSize( selection_data
->length
);
3286 event
.SetDataBuffer( selection_data
->data
);
3287 if (!m_owner
->HandleWindowEvent( event
))
3290 if (!event
.IsAllowed())
3297 wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3299 GtkSelectionData
*selection_data
)
3302 if (!get_iter( &iter
, path
)) return FALSE
;
3303 wxDataViewItem
item( (void*) iter
.user_data
);
3305 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
3306 event
.SetEventObject( m_owner
);
3307 event
.SetItem( item
);
3308 event
.SetModel( m_wx_model
);
3309 event
.SetDataFormat( selection_data
->target
);
3310 if (!m_owner
->HandleWindowEvent( event
))
3313 if (!event
.IsAllowed())
3319 // notifications from wxDataViewModel
3321 bool wxDataViewCtrlInternal::Cleared()
3329 // Create new GTK model
3330 g_object_unref( m_gtk_model
);
3331 m_gtk_model
= wxgtk_tree_model_new();
3332 m_gtk_model
->internal
= this;
3337 void wxDataViewCtrlInternal::Resort()
3339 if (!m_wx_model
->IsVirtualListModel())
3343 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3345 if (!m_wx_model
->IsVirtualListModel())
3347 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3348 wxASSERT_MSG(parent_node
,
3349 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3351 if (m_wx_model
->IsContainer( item
))
3352 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
3354 parent_node
->AddLeave( item
.GetID() );
3360 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3362 if (!m_wx_model
->IsVirtualListModel())
3364 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3365 wxASSERT_MSG(parent_node
,
3366 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3368 parent_node
->DeleteChild( item
.GetID() );
3374 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
3376 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3377 event
.SetEventObject( m_owner
);
3378 event
.SetModel( m_owner
->GetModel() );
3379 event
.SetItem( item
);
3380 m_owner
->HandleWindowEvent( event
);
3385 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
3387 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3388 event
.SetEventObject( m_owner
);
3389 event
.SetModel( m_owner
->GetModel() );
3390 event
.SetColumn( col
);
3391 event
.SetDataViewColumn( GetOwner()->GetColumn(col
) );
3392 event
.SetItem( item
);
3393 m_owner
->HandleWindowEvent( event
);
3400 GtkTreeModelFlags
wxDataViewCtrlInternal::get_flags()
3402 if (m_wx_model
->IsVirtualListModel())
3403 return GTK_TREE_MODEL_LIST_ONLY
;
3405 return GTK_TREE_MODEL_ITERS_PERSIST
;
3408 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
3411 if (m_wx_model
->IsVirtualListModel())
3413 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3415 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
3417 if (i
>= wx_model
->GetCount())
3420 iter
->stamp
= m_gtk_model
->stamp
;
3421 // user_data is just the index +1
3422 iter
->user_data
= (gpointer
) (i
+1);
3428 int depth
= gtk_tree_path_get_depth( path
);
3430 wxGtkTreeModelNode
*node
= m_root
;
3433 for (i
= 0; i
< depth
; i
++)
3435 BuildBranch( node
);
3437 gint pos
= gtk_tree_path_get_indices (path
)[i
];
3438 if (pos
< 0) return FALSE
;
3439 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
3441 void* id
= node
->GetChildren().Item( (size_t) pos
);
3445 iter
->stamp
= m_gtk_model
->stamp
;
3446 iter
->user_data
= id
;
3450 size_t count
= node
->GetNodes().GetCount();
3452 for (pos2
= 0; pos2
< count
; pos2
++)
3454 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
3455 if (child_node
->GetItem().GetID() == id
)
3467 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
3469 GtkTreePath
*retval
= gtk_tree_path_new ();
3471 if (m_wx_model
->IsVirtualListModel())
3473 // user_data is just the index +1
3474 int i
= ( (wxUIntPtr
) iter
->user_data
) -1;
3475 gtk_tree_path_append_index (retval
, i
);
3479 void *id
= iter
->user_data
;
3481 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
3484 int pos
= node
->GetChildren().Index( id
);
3486 gtk_tree_path_prepend_index( retval
, pos
);
3488 id
= node
->GetItem().GetID();
3489 node
= node
->GetParent();
3496 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
3498 if (m_wx_model
->IsVirtualListModel())
3500 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3502 // user_data is just the index +1
3503 int n
= ( (wxUIntPtr
) iter
->user_data
) -1;
3508 if (n
>= (int) wx_model
->GetCount())
3511 // user_data is just the index +1 (+2 because we need the next)
3512 iter
->user_data
= (gpointer
) (n
+2);
3516 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
3517 if( parent
== NULL
)
3520 int pos
= parent
->GetChildren().Index( iter
->user_data
);
3522 if (pos
== (int) parent
->GetChildCount()-1)
3525 iter
->stamp
= m_gtk_model
->stamp
;
3526 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
3532 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
3534 if (m_wx_model
->IsVirtualListModel())
3536 // this is a list, nodes have no children
3540 iter
->stamp
= m_gtk_model
->stamp
;
3541 iter
->user_data
= (gpointer
) 1;
3547 wxDataViewItem
item( (void*) parent
->user_data
);
3549 if (!m_wx_model
->IsContainer( item
))
3552 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3553 wxASSERT_MSG(parent_node
,
3554 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3556 BuildBranch( parent_node
);
3558 if (parent_node
->GetChildCount() == 0)
3561 iter
->stamp
= m_gtk_model
->stamp
;
3562 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
3568 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
3570 if (m_wx_model
->IsVirtualListModel())
3572 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3575 return (gint
) wx_model
->GetCount();
3577 // this is a list, nodes have no children
3582 wxDataViewItem
item( (void*) iter
->user_data
);
3584 bool is_container
= m_wx_model
->IsContainer( item
);
3589 wxGtkTreeModelNode
*node
= FindNode( iter
);
3591 "Did you forget a call to ItemAdded()? The iterator is unknown to the wxGtkTreeModel");
3593 BuildBranch( node
);
3595 return (node
->GetChildCount() > 0);
3599 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
3601 if (m_wx_model
->IsVirtualListModel())
3603 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3606 return (gint
) wx_model
->GetCount();
3613 return m_root
->GetChildCount();
3615 wxDataViewItem
item( (void*) iter
->user_data
);
3617 if (!m_wx_model
->IsContainer( item
))
3620 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
3621 wxASSERT_MSG(parent_node
,
3622 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3624 BuildBranch( parent_node
);
3626 // wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() );
3628 return parent_node
->GetChildCount();
3632 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
3634 if (m_wx_model
->IsVirtualListModel())
3636 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3644 if (n
>= (gint
) wx_model
->GetCount())
3647 iter
->stamp
= m_gtk_model
->stamp
;
3648 // user_data is just the index +1
3649 iter
->user_data
= (gpointer
) (n
+1);
3656 if (parent
) id
= (void*) parent
->user_data
;
3657 wxDataViewItem
item( id
);
3659 if (!m_wx_model
->IsContainer( item
))
3662 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3663 wxASSERT_MSG(parent_node
,
3664 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3666 BuildBranch( parent_node
);
3668 // wxPrintf( "iter_nth_child %d\n", n );
3670 iter
->stamp
= m_gtk_model
->stamp
;
3671 iter
->user_data
= parent_node
->GetChildren().Item( n
);
3677 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
3679 if (m_wx_model
->IsVirtualListModel())
3685 wxGtkTreeModelNode
*node
= FindParentNode( child
);
3689 iter
->stamp
= m_gtk_model
->stamp
;
3690 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
3696 static wxGtkTreeModelNode
*
3697 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3703 list
.DeleteContents( true );
3704 wxDataViewItem
it( item
);
3708 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3709 list
.Insert( pItem
);
3710 it
= model
->GetParent( it
);
3713 wxGtkTreeModelNode
* node
= treeNode
;
3714 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3716 if( node
&& node
->GetNodes().GetCount() != 0 )
3718 int len
= node
->GetNodes().GetCount();
3719 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3721 for( ; j
< len
; j
++)
3723 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3742 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
3747 wxDataViewItem
item( (void*) iter
->user_data
);
3751 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3756 wxLogDebug( "Not found %p", iter->user_data );
3760 // TODO: remove this code
3766 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
3771 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3776 wxLogDebug( "Not found %p", item.GetID() );
3780 // TODO: remove this code
3786 static wxGtkTreeModelNode
*
3787 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3793 list
.DeleteContents( true );
3797 wxDataViewItem
it( model
->GetParent( item
) );
3800 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3801 list
.Insert( pItem
);
3802 it
= model
->GetParent( it
);
3805 wxGtkTreeModelNode
* node
= treeNode
;
3806 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3808 if( node
&& node
->GetNodes().GetCount() != 0 )
3810 int len
= node
->GetNodes().GetCount();
3811 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3813 for( ; j
< len
; j
++)
3815 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3830 //Examine whether the node is item's parent node
3831 int len
= node
->GetChildCount();
3832 for( int i
= 0; i
< len
; i
++ )
3834 if( node
->GetChildren().Item( i
) == item
.GetID() )
3840 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
3845 wxDataViewItem
item( (void*) iter
->user_data
);
3849 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3852 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
3857 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3860 //-----------------------------------------------------------------------------
3861 // wxDataViewCtrl signal callbacks
3862 //-----------------------------------------------------------------------------
3865 wxdataview_selection_changed_callback( GtkTreeSelection
* WXUNUSED(selection
), wxDataViewCtrl
*dv
)
3867 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
3870 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
3871 event
.SetItem( dv
->GetSelection() );
3872 event
.SetModel( dv
->GetModel() );
3873 dv
->HandleWindowEvent( event
);
3877 wxdataview_row_activated_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreePath
*path
,
3878 GtkTreeViewColumn
*WXUNUSED(column
), wxDataViewCtrl
*dv
)
3880 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
3883 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3884 wxDataViewItem
item( (void*) iter
.user_data
);;
3885 event
.SetItem( item
);
3886 event
.SetModel( dv
->GetModel() );
3887 dv
->HandleWindowEvent( event
);
3891 wxdataview_test_expand_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3892 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3894 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
3896 wxDataViewItem
item( (void*) iter
->user_data
);;
3897 event
.SetItem( item
);
3898 event
.SetModel( dv
->GetModel() );
3899 dv
->HandleWindowEvent( event
);
3901 return !event
.IsAllowed();
3905 wxdataview_row_expanded_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3906 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3908 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
3910 wxDataViewItem
item( (void*) iter
->user_data
);;
3911 event
.SetItem( item
);
3912 event
.SetModel( dv
->GetModel() );
3913 dv
->HandleWindowEvent( event
);
3917 wxdataview_test_collapse_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3918 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3920 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
3922 wxDataViewItem
item( (void*) iter
->user_data
);;
3923 event
.SetItem( item
);
3924 event
.SetModel( dv
->GetModel() );
3925 dv
->HandleWindowEvent( event
);
3927 return !event
.IsAllowed();
3931 wxdataview_row_collapsed_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3932 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3934 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
3936 wxDataViewItem
item( (void*) iter
->user_data
);;
3937 event
.SetItem( item
);
3938 event
.SetModel( dv
->GetModel() );
3939 dv
->HandleWindowEvent( event
);
3942 //-----------------------------------------------------------------------------
3944 //-----------------------------------------------------------------------------
3946 void wxDataViewCtrl::AddChildGTK(wxWindowGTK
* child
)
3948 GtkWidget
* treeview
= GtkGetTreeView();
3950 // Insert widget in GtkTreeView
3951 if (GTK_WIDGET_REALIZED(treeview
))
3952 gtk_widget_set_parent_window( child
->m_widget
,
3953 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
3954 gtk_widget_set_parent( child
->m_widget
, treeview
);
3958 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
3959 GtkAllocation
*WXUNUSED(gtk_alloc
),
3960 wxDataViewCtrl
*win
)
3962 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
3965 wxWindow
*child
= node
->GetData();
3968 gtk_widget_size_request( child
->m_widget
, &req
);
3970 GtkAllocation alloc
;
3971 alloc
.x
= child
->m_x
;
3972 alloc
.y
= child
->m_y
;
3973 alloc
.width
= child
->m_width
;
3974 alloc
.height
= child
->m_height
;
3975 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
3977 node
= node
->GetNext();
3982 //-----------------------------------------------------------------------------
3983 // "motion_notify_event"
3984 //-----------------------------------------------------------------------------
3987 gtk_dataview_motion_notify_callback( GtkWidget
*WXUNUSED(widget
),
3988 GdkEventMotion
*gdk_event
,
3989 wxDataViewCtrl
*dv
)
3991 if (gdk_event
->is_hint
)
3995 GdkModifierType state
;
3996 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
4001 GtkTreePath
*path
= NULL
;
4002 GtkTreeViewColumn
*column
= NULL
;
4005 if (gtk_tree_view_get_path_at_pos(
4006 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4007 (int) gdk_event
->x
, (int) gdk_event
->y
,
4016 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4018 // wxPrintf( "mouse %d %d\n", (int) gdk_event->x, (int) gdk_event->y );
4020 gtk_tree_path_free( path
);
4028 //-----------------------------------------------------------------------------
4029 // "button_press_event"
4030 //-----------------------------------------------------------------------------
4033 gtk_dataview_button_press_callback( GtkWidget
*WXUNUSED(widget
),
4034 GdkEventButton
*gdk_event
,
4035 wxDataViewCtrl
*dv
)
4037 if ((gdk_event
->button
== 3) && (gdk_event
->type
== GDK_BUTTON_PRESS
))
4039 GtkTreePath
*path
= NULL
;
4040 GtkTreeViewColumn
*column
= NULL
;
4043 if (gtk_tree_view_get_path_at_pos(
4044 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4045 (int) gdk_event
->x
, (int) gdk_event
->y
,
4054 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4056 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, dv
->GetId() );
4057 wxDataViewItem
item( (void*) iter
.user_data
);;
4058 event
.SetItem( item
);
4059 event
.SetModel( dv
->GetModel() );
4060 bool ret
= dv
->HandleWindowEvent( event
);
4061 gtk_tree_path_free( path
);
4070 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
4072 wxDataViewCtrl::~wxDataViewCtrl()
4075 GetModel()->RemoveNotifier( m_notifier
);
4079 // remove the model from the GtkTreeView before it gets destroyed by the
4080 // wxDataViewCtrlBase's dtor
4081 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), NULL
);
4086 void wxDataViewCtrl::Init()
4091 m_cols
.DeleteContents( true );
4094 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
4095 const wxPoint
& pos
, const wxSize
& size
,
4096 long style
, const wxValidator
& validator
)
4100 if (!PreCreation( parent
, pos
, size
) ||
4101 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
4103 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
4107 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
4108 g_object_ref(m_widget
);
4110 GTKScrolledWindowSetBorder(m_widget
, style
);
4112 m_treeview
= gtk_tree_view_new();
4113 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
4115 g_signal_connect (m_treeview
, "size_allocate",
4116 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
4119 if (!gtk_check_version(2,6,0))
4121 bool fixed
= (style
& wxDV_VARIABLE_LINE_HEIGHT
) == 0;
4122 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4126 if (style
& wxDV_MULTIPLE
)
4128 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4129 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
4132 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
4135 if (!gtk_check_version(2,10,0))
4137 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
4139 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
4140 (style
& wxDV_VERT_RULES
) != 0)
4141 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
4142 else if (style
& wxDV_VERT_RULES
)
4143 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
4144 else if (style
& wxDV_HORIZ_RULES
)
4145 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
4147 if (grid
!= GTK_TREE_VIEW_GRID_LINES_NONE
)
4148 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
4152 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_ROW_LINES
) != 0 );
4154 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
4155 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
4156 gtk_widget_show (m_treeview
);
4158 m_parent
->DoAddChild( this );
4162 GtkEnableSelectionEvents();
4164 g_signal_connect_after (m_treeview
, "row-activated",
4165 G_CALLBACK (wxdataview_row_activated_callback
), this);
4167 g_signal_connect (m_treeview
, "test-collapse-row",
4168 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
4170 g_signal_connect_after (m_treeview
, "row-collapsed",
4171 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
4173 g_signal_connect (m_treeview
, "test-expand-row",
4174 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
4176 g_signal_connect_after (m_treeview
, "row-expanded",
4177 G_CALLBACK (wxdataview_row_expanded_callback
), this);
4179 g_signal_connect (m_treeview
, "motion_notify_event",
4180 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
4182 g_signal_connect (m_treeview
, "button_press_event",
4183 G_CALLBACK (gtk_dataview_button_press_callback
), this);
4188 void wxDataViewCtrl::OnInternalIdle()
4190 wxWindow::OnInternalIdle();
4192 unsigned int cols
= GetColumnCount();
4194 for (i
= 0; i
< cols
; i
++)
4196 wxDataViewColumn
*col
= GetColumn( i
);
4197 col
->OnInternalIdle();
4201 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4212 if (!wxDataViewCtrlBase::AssociateModel( model
))
4216 if (!gtk_check_version(2,6,0))
4218 bool fixed
= (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
) == 0) || (model
->IsVirtualListModel()));
4219 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4223 GtkWxTreeModel
*gtk_model
= wxgtk_tree_model_new();
4224 m_internal
= new wxDataViewCtrlInternal( this, model
, gtk_model
);
4225 gtk_model
->internal
= m_internal
;
4227 m_notifier
= new wxGtkDataViewModelNotifier( gtk_model
, model
, this );
4229 model
->AddNotifier( m_notifier
);
4231 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_model
) );
4233 // unref in wxDataViewCtrlInternal
4234 // g_object_unref( gtk_model );
4239 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4241 return m_internal
->EnableDragSource( format
);
4244 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4246 return m_internal
->EnableDropTarget( format
);
4249 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4251 if (!wxDataViewCtrlBase::AppendColumn(col
))
4254 m_cols
.Append( col
);
4257 if (!gtk_check_version(2,6,0))
4259 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4260 GTK_TREE_VIEW_COLUMN_FIXED
)
4261 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4265 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
4266 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4271 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4273 if (!wxDataViewCtrlBase::PrependColumn(col
))
4276 m_cols
.Insert( col
);
4279 if (!gtk_check_version(2,6,0))
4281 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4282 GTK_TREE_VIEW_COLUMN_FIXED
)
4283 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4287 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4288 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
4293 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4295 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4298 m_cols
.Insert( pos
, col
);
4301 if (!gtk_check_version(2,6,0))
4303 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4304 GTK_TREE_VIEW_COLUMN_FIXED
)
4305 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4309 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4310 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), pos
);
4315 unsigned int wxDataViewCtrl::GetColumnCount() const
4317 return m_cols
.GetCount();
4320 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
4322 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
4326 wxDataViewColumnList::const_iterator iter
;
4327 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4329 wxDataViewColumn
*col
= *iter
;
4330 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
4339 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4341 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4342 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
4344 m_cols
.DeleteObject( column
);
4349 bool wxDataViewCtrl::ClearColumns()
4351 wxDataViewColumnList::iterator iter
;
4352 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4354 wxDataViewColumn
*col
= *iter
;
4355 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4356 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4364 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4366 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetConstGtkHandle());
4368 GList
*list
= gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview
) );
4370 gint pos
= g_list_index( list
, (gconstpointer
) gtk_column
);
4372 g_list_free( list
);
4377 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4379 return m_internal
->GetDataViewSortColumn();
4382 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4385 iter
.user_data
= item
.GetID();
4386 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4387 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
4388 gtk_tree_path_free( path
);
4391 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4394 iter
.user_data
= item
.GetID();
4395 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4396 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
4397 gtk_tree_path_free( path
);
4400 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4403 iter
.user_data
= item
.GetID();
4404 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4405 bool res
= gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview
), path
);
4406 gtk_tree_path_free( path
);
4411 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4413 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4415 if (m_windowStyle
& wxDV_MULTIPLE
)
4417 // Report the first one
4418 GtkTreeModel
*model
;
4419 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4423 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4425 m_internal
->get_iter( &iter
, path
);
4428 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4429 g_list_free( list
);
4431 return wxDataViewItem( (void*) iter
.user_data
);
4437 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
4439 wxDataViewItem
item( (void*) iter
.user_data
);
4444 return wxDataViewItem(0);
4447 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4451 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4452 if (HasFlag(wxDV_MULTIPLE
))
4454 GtkTreeModel
*model
;
4455 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4460 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4463 m_internal
->get_iter( &iter
, path
);
4465 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4467 list
= g_list_next( list
);
4472 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4473 g_list_free( list
);
4479 GtkTreeModel
*model
;
4481 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
4484 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4492 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4494 GtkDisableSelectionEvents();
4496 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4498 gtk_tree_selection_unselect_all( selection
);
4500 wxDataViewItem last_parent
;
4503 for (i
= 0; i
< sel
.GetCount(); i
++)
4505 wxDataViewItem item
= sel
[i
];
4506 wxDataViewItem parent
= GetModel()->GetParent( item
);
4509 if (parent
!= last_parent
)
4510 ExpandAncestors(item
);
4512 last_parent
= parent
;
4515 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4516 iter
.user_data
= (gpointer
) item
.GetID();
4517 gtk_tree_selection_select_iter( selection
, &iter
);
4520 GtkEnableSelectionEvents();
4523 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4525 ExpandAncestors(item
);
4527 GtkDisableSelectionEvents();
4529 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4532 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4533 iter
.user_data
= (gpointer
) item
.GetID();
4534 gtk_tree_selection_select_iter( selection
, &iter
);
4536 GtkEnableSelectionEvents();
4539 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4541 GtkDisableSelectionEvents();
4543 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4546 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4547 iter
.user_data
= (gpointer
) item
.GetID();
4548 gtk_tree_selection_unselect_iter( selection
, &iter
);
4550 GtkEnableSelectionEvents();
4553 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4555 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4558 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4559 iter
.user_data
= (gpointer
) item
.GetID();
4561 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
4564 void wxDataViewCtrl::SelectAll()
4566 GtkDisableSelectionEvents();
4568 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4570 gtk_tree_selection_select_all( selection
);
4572 GtkEnableSelectionEvents();
4575 void wxDataViewCtrl::UnselectAll()
4577 GtkDisableSelectionEvents();
4579 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4581 gtk_tree_selection_unselect_all( selection
);
4583 GtkEnableSelectionEvents();
4586 void wxDataViewCtrl::EnsureVisible(const wxDataViewItem
& item
,
4587 const wxDataViewColumn
*WXUNUSED(column
))
4589 ExpandAncestors(item
);
4592 iter
.user_data
= (gpointer
) item
.GetID();
4593 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4594 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
4595 gtk_tree_path_free( path
);
4598 void wxDataViewCtrl::HitTest(const wxPoint
& WXUNUSED(point
),
4599 wxDataViewItem
& item
,
4600 wxDataViewColumn
*& column
) const
4602 item
= wxDataViewItem(0);
4607 wxDataViewCtrl::GetItemRect(const wxDataViewItem
& WXUNUSED(item
),
4608 const wxDataViewColumn
*WXUNUSED(column
)) const
4613 void wxDataViewCtrl::DoSetExpanderColumn()
4615 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
4616 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
4619 void wxDataViewCtrl::DoSetIndent()
4623 void wxDataViewCtrl::GtkDisableSelectionEvents()
4625 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4626 g_signal_handlers_disconnect_by_func( selection
,
4627 (gpointer
) (wxdataview_selection_changed_callback
), this);
4630 void wxDataViewCtrl::GtkEnableSelectionEvents()
4632 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4633 g_signal_connect_after (selection
, "changed",
4634 G_CALLBACK (wxdataview_selection_changed_callback
), this);
4639 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
4641 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
4646 // !wxUSE_GENERICDATAVIEWCTRL
4649 // wxUSE_DATAVIEWCTRL