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() { return m_sort_order
; }
97 void SetSortColumn( int column
) { m_sort_column
= column
; }
98 int GetSortColumn() { 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 wxDataViewCtrl
* GetOwner() { return m_owner
; }
108 GtkWxTreeModel
* GetGtkModel() { return m_gtk_model
; }
112 wxGtkTreeModelNode
*FindNode( const wxDataViewItem
&item
);
113 wxGtkTreeModelNode
*FindNode( GtkTreeIter
*iter
);
114 wxGtkTreeModelNode
*FindParentNode( const wxDataViewItem
&item
);
115 wxGtkTreeModelNode
*FindParentNode( GtkTreeIter
*iter
);
116 void BuildBranch( wxGtkTreeModelNode
*branch
);
119 wxGtkTreeModelNode
*m_root
;
120 wxDataViewModel
*m_wx_model
;
121 GtkWxTreeModel
*m_gtk_model
;
122 wxDataViewCtrl
*m_owner
;
123 GtkSortType m_sort_order
;
124 wxDataViewColumn
*m_dataview_sort_column
;
127 GtkTargetEntry m_dragSourceTargetEntry
;
128 wxCharBuffer m_dragSourceTargetEntryTarget
;
129 wxDataObject
*m_dragDataObject
;
131 GtkTargetEntry m_dropTargetTargetEntry
;
132 wxCharBuffer m_dropTargetTargetEntryTarget
;
133 wxDataObject
*m_dropDataObject
;
137 //-----------------------------------------------------------------------------
138 // wxGtkTreeModelNode
139 //-----------------------------------------------------------------------------
142 int LINKAGEMODE
wxGtkTreeModelChildCmp( void** id1
, void** id2
)
144 int ret
= gs_internal
->GetDataViewModel()->Compare( *id1
, *id2
,
145 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
150 WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode
*, wxGtkTreeModelNodes
);
151 WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren
);
153 class wxGtkTreeModelNode
156 wxGtkTreeModelNode( wxGtkTreeModelNode
* parent
, const wxDataViewItem
&item
,
157 wxDataViewCtrlInternal
*internal
)
161 m_internal
= internal
;
164 ~wxGtkTreeModelNode()
166 size_t count
= m_nodes
.GetCount();
168 for (i
= 0; i
< count
; i
++)
170 wxGtkTreeModelNode
*child
= m_nodes
.Item( i
);
175 unsigned int AddNode( wxGtkTreeModelNode
* child
)
177 m_nodes
.Add( child
);
179 void *id
= child
->GetItem().GetID();
181 m_children
.Add( id
);
183 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
185 gs_internal
= m_internal
;
186 m_children
.Sort( &wxGtkTreeModelChildCmp
);
187 return m_children
.Index( id
);
190 return m_children
.GetCount()-1;
193 unsigned int AddLeave( void* id
)
195 m_children
.Add( id
);
197 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
199 gs_internal
= m_internal
;
200 m_children
.Sort( &wxGtkTreeModelChildCmp
);
201 return m_children
.Index( id
);
204 return m_children
.GetCount()-1;
207 void DeleteChild( void* id
)
209 m_children
.Remove( id
);
211 unsigned int count
= m_nodes
.GetCount();
213 for (pos
= 0; pos
< count
; pos
++)
215 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
216 if (node
->GetItem().GetID() == id
)
218 m_nodes
.RemoveAt( pos
);
226 wxGtkTreeModelNode
* GetParent()
228 wxGtkTreeModelNodes
&GetNodes()
230 wxGtkTreeModelChildren
&GetChildren()
231 { return m_children
; }
233 unsigned int GetChildCount() { return m_children
.GetCount(); }
234 unsigned int GetNodesCount() { 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 wxPrintf( "get_column_type %s\n", wxtype
);
540 if (wxtype
== wxT("string"))
541 gtype
= G_TYPE_STRING
;
544 gtype
= G_TYPE_STRING
;
545 // wxFAIL_MSG( _T("non-string columns not supported yet") );
552 wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
556 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
557 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
558 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
560 return wxtree_model
->internal
->get_iter( iter
, path
);
564 wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
567 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
568 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), NULL
);
569 g_return_val_if_fail (iter
->stamp
== GTK_WX_TREE_MODEL (wxtree_model
)->stamp
, NULL
);
571 return wxtree_model
->internal
->get_path( iter
);
575 wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
580 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
581 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
) );
583 wxDataViewModel
*model
= wxtree_model
->internal
->GetDataViewModel();
584 wxString mtype
= model
->GetColumnType( (unsigned int) column
);
585 if (mtype
== wxT("string"))
588 g_value_init( value
, G_TYPE_STRING
);
589 wxDataViewItem
item( (void*) iter
->user_data
);
590 model
->GetValue( variant
, item
, (unsigned int) column
);
592 g_value_set_string( value
, variant
.GetString().utf8_str() );
596 wxFAIL_MSG( _T("non-string columns not supported yet") );
601 wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
604 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
606 if (wxtree_model
->stamp
!= iter
->stamp
)
607 wxPrintf( "crash\n" );
609 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
610 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
612 return wxtree_model
->internal
->iter_next( iter
);
616 wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
620 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
621 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
622 g_return_val_if_fail (wxtree_model
->stamp
== parent
->stamp
, FALSE
);
624 return wxtree_model
->internal
->iter_children( iter
, parent
);
628 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
631 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
632 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
633 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
635 return wxtree_model
->internal
->iter_has_child( iter
);
639 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
642 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
643 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
646 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, 0);
648 return wxtree_model
->internal
->iter_n_children( iter
);
652 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
657 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
658 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
660 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
664 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
668 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
669 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
670 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
672 return wxtree_model
->internal
->iter_parent( iter
, child
);
675 /* drag'n'drop iface */
677 wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
680 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
681 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
683 return wxtree_model
->internal
->row_draggable( drag_source
, path
);
687 wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
690 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
691 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
693 return wxtree_model
->internal
->drag_data_delete( drag_source
, path
);
697 wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
699 GtkSelectionData
*selection_data
)
701 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
702 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
705 wxPrintf( "drag_get_data\n");
707 wxGtkString
atom_selection(gdk_atom_name(selection_data
->selection
));
708 wxPrintf( "selection %s\n", wxString::FromAscii(atom_selection
) );
710 wxGtkString
atom_target(gdk_atom_name(selection_data
->target
));
711 wxPrintf( "target %s\n", wxString::FromAscii(atom_target
) );
713 wxGtkString
atom_type(gdk_atom_name(selection_data
->type
));
714 wxPrintf( "type %s\n", wxString::FromAscii(atom_type
) );
716 wxPrintf( "format %d\n", selection_data
->format
);
719 return wxtree_model
->internal
->drag_data_get( drag_source
, path
, selection_data
);
723 wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
725 GtkSelectionData
*selection_data
)
727 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
728 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
730 return wxtree_model
->internal
->drag_data_received( drag_dest
, dest
, selection_data
);
734 wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
735 GtkTreePath
*dest_path
,
736 GtkSelectionData
*selection_data
)
738 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
739 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
741 return wxtree_model
->internal
->row_drop_possible( drag_dest
, dest_path
, selection_data
);
746 wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
747 gint
*sort_column_id
,
750 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) sortable
;
752 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
754 if (!wxtree_model
->internal
->IsSorted())
757 *sort_column_id
= -1;
764 *sort_column_id
= wxtree_model
->internal
->GetSortColumn();
767 *order
= wxtree_model
->internal
->GetSortOrder();
772 wxDataViewColumn
*gs_lastLeftClickHeader
= NULL
;
775 wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
779 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
780 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
782 tree_model
->internal
->SetDataViewSortColumn( gs_lastLeftClickHeader
);
784 if ((sort_column_id
!= (gint
) tree_model
->internal
->GetSortColumn()) ||
785 (order
!= tree_model
->internal
->GetSortOrder()))
787 tree_model
->internal
->SetSortColumn( sort_column_id
);
788 tree_model
->internal
->SetSortOrder( order
);
790 gtk_tree_sortable_sort_column_changed (sortable
);
792 tree_model
->internal
->GetDataViewModel()->Resort();
795 if (gs_lastLeftClickHeader
)
797 wxDataViewCtrl
*dv
= tree_model
->internal
->GetOwner();
798 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, dv
->GetId() );
799 event
.SetDataViewColumn( gs_lastLeftClickHeader
);
800 event
.SetModel( dv
->GetModel() );
801 dv
->HandleWindowEvent( event
);
804 gs_lastLeftClickHeader
= NULL
;
808 wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
809 gint
WXUNUSED(sort_column_id
),
810 GtkTreeIterCompareFunc func
,
811 gpointer
WXUNUSED(data
),
812 GtkDestroyNotify
WXUNUSED(destroy
) )
814 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
815 g_return_if_fail (func
!= NULL
);
818 void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
819 GtkTreeIterCompareFunc func
,
820 gpointer
WXUNUSED(data
),
821 GtkDestroyNotify
WXUNUSED(destroy
) )
823 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
824 g_return_if_fail (func
!= NULL
);
826 wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
829 gboolean
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 wxGtkRendererRenderer
838 //-----------------------------------------------------------------------------
842 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
843 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
844 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
845 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
846 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
847 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
849 GType
gtk_wx_cell_renderer_get_type (void);
851 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
852 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
854 struct _GtkWxCellRenderer
856 GtkCellRenderer parent
;
859 wxDataViewCustomRenderer
*cell
;
863 struct _GtkWxCellRendererClass
865 GtkCellRendererClass cell_parent_class
;
869 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
870 static void gtk_wx_cell_renderer_init (
871 GtkWxCellRenderer
*cell
);
872 static void gtk_wx_cell_renderer_class_init(
873 GtkWxCellRendererClass
*klass
);
874 static void gtk_wx_cell_renderer_finalize (
876 static void gtk_wx_cell_renderer_get_size (
877 GtkCellRenderer
*cell
,
879 GdkRectangle
*rectangle
,
884 static void gtk_wx_cell_renderer_render (
885 GtkCellRenderer
*cell
,
888 GdkRectangle
*background_area
,
889 GdkRectangle
*cell_area
,
890 GdkRectangle
*expose_area
,
891 GtkCellRendererState flags
);
892 static gboolean
gtk_wx_cell_renderer_activate(
893 GtkCellRenderer
*cell
,
897 GdkRectangle
*background_area
,
898 GdkRectangle
*cell_area
,
899 GtkCellRendererState flags
);
900 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
901 GtkCellRenderer
*cell
,
905 GdkRectangle
*background_area
,
906 GdkRectangle
*cell_area
,
907 GtkCellRendererState flags
);
910 static GObjectClass
*cell_parent_class
= NULL
;
915 gtk_wx_cell_renderer_get_type (void)
917 static GType cell_wx_type
= 0;
921 const GTypeInfo cell_wx_info
=
923 sizeof (GtkWxCellRendererClass
),
924 NULL
, /* base_init */
925 NULL
, /* base_finalize */
926 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
927 NULL
, /* class_finalize */
928 NULL
, /* class_data */
929 sizeof (GtkWxCellRenderer
),
931 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
934 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
935 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
942 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
945 cell
->last_click
= 0;
949 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
951 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
952 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
954 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
956 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
958 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
959 cell_class
->render
= gtk_wx_cell_renderer_render
;
960 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
961 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
965 gtk_wx_cell_renderer_finalize (GObject
*object
)
968 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
972 gtk_wx_cell_renderer_new (void)
974 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
979 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
980 GtkCellRenderer
*renderer
,
981 GdkEvent
*WXUNUSED(event
),
984 GdkRectangle
*WXUNUSED(background_area
),
985 GdkRectangle
*cell_area
,
986 GtkCellRendererState
WXUNUSED(flags
) )
988 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
989 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
991 // Renderer doesn't support in-place editing
992 if (!cell
->HasEditorCtrl())
995 // An in-place editing control is still around
996 if (cell
->GetEditorCtrl())
1000 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1006 rect
.x
+= cell_area
->x
;
1007 rect
.y
+= cell_area
->y
;
1008 // rect.width -= renderer->xpad * 2;
1009 // rect.height -= renderer->ypad * 2;
1011 // wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
1012 wxRect
renderrect( cell_area
->x
, cell_area
->y
, cell_area
->width
, cell_area
->height
);
1014 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
1016 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
1017 wxDataViewItem
item( (void*) iter
.user_data
);
1018 gtk_tree_path_free( treepath
);
1020 cell
->StartEditing( item
, renderrect
);
1026 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
1027 GtkWidget
*WXUNUSED(widget
),
1028 GdkRectangle
*cell_area
,
1034 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1035 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1037 wxSize size
= cell
->GetSize();
1039 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
1040 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
1047 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
1051 *x_offset
= (gint
)((renderer
->xalign
*
1052 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
1053 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
1057 *y_offset
= (gint
)((renderer
->yalign
*
1058 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
1059 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
1064 *width
= calc_width
;
1067 *height
= calc_height
;
1071 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
1074 GdkRectangle
*background_area
,
1075 GdkRectangle
*cell_area
,
1076 GdkRectangle
*expose_area
,
1077 GtkCellRendererState flags
)
1080 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1081 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1083 cell
->window
= window
;
1084 cell
->widget
= widget
;
1085 cell
->background_area
= (void*) background_area
;
1086 cell
->cell_area
= (void*) cell_area
;
1087 cell
->expose_area
= (void*) expose_area
;
1088 cell
->flags
= (int) flags
;
1091 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1097 rect
.x
+= cell_area
->x
;
1098 rect
.y
+= cell_area
->y
;
1099 rect
.width
-= renderer
->xpad
* 2;
1100 rect
.height
-= renderer
->ypad
* 2;
1103 if (gdk_rectangle_intersect (expose_area
, &rect
, &dummy
))
1105 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1106 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
1107 wxWindowDCImpl
*impl
= (wxWindowDCImpl
*) dc
->GetImpl();
1108 // Reinitilise GDK window everytime as drawing can also
1109 // be done into DnD drop window.
1110 impl
->m_gdkwindow
= window
;
1114 if (flags
& GTK_CELL_RENDERER_SELECTED
)
1115 state
|= wxDATAVIEW_CELL_SELECTED
;
1116 if (flags
& GTK_CELL_RENDERER_PRELIT
)
1117 state
|= wxDATAVIEW_CELL_PRELIT
;
1118 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1119 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1120 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1121 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1122 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
1123 state
|= wxDATAVIEW_CELL_FOCUSED
;
1124 cell
->Render( renderrect
, dc
, state
);
1129 gtk_wx_cell_renderer_activate(
1130 GtkCellRenderer
*renderer
,
1134 GdkRectangle
*WXUNUSED(background_area
),
1135 GdkRectangle
*cell_area
,
1136 GtkCellRendererState
WXUNUSED(flags
) )
1138 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1139 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1142 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1148 rect
.x
+= cell_area
->x
;
1149 rect
.y
+= cell_area
->y
;
1150 rect
.width
-= renderer
->xpad
* 2;
1151 rect
.height
-= renderer
->ypad
* 2;
1153 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1155 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1157 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
1160 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
1161 wxDataViewItem
item( iter
.user_data
);
1162 gtk_tree_path_free( treepath
);
1164 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1170 // activated by <ENTER>
1171 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1176 else if (event
->type
== GDK_BUTTON_PRESS
)
1178 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
1179 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
1180 ((int) button_event
->y
) - renderrect
.y
);
1183 if (button_event
->button
== 1)
1185 if (cell
->LeftClick( pt
, renderrect
, model
, item
, model_col
))
1187 // TODO: query system double-click time
1188 if (button_event
->time
- wxrenderer
->last_click
< 400)
1189 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1192 wxrenderer
->last_click
= button_event
->time
;
1200 // ---------------------------------------------------------
1201 // wxGtkDataViewModelNotifier
1202 // ---------------------------------------------------------
1204 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1207 wxGtkDataViewModelNotifier( GtkWxTreeModel
*wxgtk_model
,
1208 wxDataViewModel
*wx_model
,
1209 wxDataViewCtrl
*ctrl
);
1210 ~wxGtkDataViewModelNotifier();
1212 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1213 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1214 virtual bool ItemChanged( const wxDataViewItem
&item
);
1215 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
1216 virtual bool Cleared();
1217 virtual void Resort();
1219 void SetGtkModel( GtkWxTreeModel
*model
) { m_wxgtk_model
= model
; }
1222 GtkWxTreeModel
*m_wxgtk_model
;
1223 wxDataViewModel
*m_wx_model
;
1224 wxDataViewCtrl
*m_owner
;
1227 // ---------------------------------------------------------
1228 // wxGtkDataViewListModelNotifier
1229 // ---------------------------------------------------------
1231 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1232 GtkWxTreeModel
* wxgtk_model
, wxDataViewModel
*wx_model
,
1233 wxDataViewCtrl
*ctrl
)
1235 m_wxgtk_model
= wxgtk_model
;
1236 m_wx_model
= wx_model
;
1240 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1243 m_wxgtk_model
= NULL
;
1246 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1248 m_owner
->GtkGetInternal()->ItemAdded( parent
, item
);
1251 iter
.stamp
= m_wxgtk_model
->stamp
;
1252 iter
.user_data
= (gpointer
) item
.GetID();
1254 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1255 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1256 gtk_tree_model_row_inserted(
1257 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1258 gtk_tree_path_free (path
);
1263 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1266 iter
.stamp
= m_wxgtk_model
->stamp
;
1267 iter
.user_data
= (gpointer
) item
.GetID();
1269 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1270 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1271 gtk_tree_model_row_deleted(
1272 GTK_TREE_MODEL(m_wxgtk_model
), path
);
1273 gtk_tree_path_free (path
);
1275 m_owner
->GtkGetInternal()->ItemDeleted( parent
, item
);
1280 void wxGtkDataViewModelNotifier::Resort()
1282 m_owner
->GtkGetInternal()->Resort();
1285 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1288 iter
.stamp
= m_wxgtk_model
->stamp
;
1289 iter
.user_data
= (gpointer
) item
.GetID();
1291 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1292 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1293 gtk_tree_model_row_changed(
1294 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1295 gtk_tree_path_free (path
);
1297 m_owner
->GtkGetInternal()->ItemChanged( item
);
1302 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_col
)
1304 // This adds GTK+'s missing MVC logic for ValueChanged
1306 for (index
= 0; index
< m_owner
->GetColumnCount(); index
++)
1308 wxDataViewColumn
*column
= m_owner
->GetColumn( index
);
1309 if (column
->GetModelColumn() == model_col
)
1311 GtkTreeView
*widget
= GTK_TREE_VIEW(m_owner
->m_treeview
);
1312 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1316 iter
.stamp
= m_wxgtk_model
->stamp
;
1317 iter
.user_data
= (gpointer
) item
.GetID();
1318 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1319 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1320 GdkRectangle cell_area
;
1321 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1322 gtk_tree_path_free( path
);
1324 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1325 double d
= gtk_adjustment_get_value( hadjust
);
1326 int xdiff
= (int) d
;
1328 int ydiff
= gcolumn
->button
->allocation
.height
;
1330 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1331 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1333 m_owner
->GtkGetInternal()->ValueChanged( item
, model_col
);
1342 bool wxGtkDataViewModelNotifier::Cleared()
1344 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->m_treeview
), NULL
);
1346 // this will create a new GTK model
1347 m_owner
->GtkGetInternal()->Cleared();
1349 SetGtkModel( m_owner
->GtkGetInternal()->GetGtkModel() );
1351 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->m_treeview
), GTK_TREE_MODEL(m_wxgtk_model
) );
1356 // ---------------------------------------------------------
1357 // wxDataViewRenderer
1358 // ---------------------------------------------------------
1360 static gpointer s_user_data
= NULL
;
1363 wxgtk_cell_editable_editing_done( GtkCellEditable
*WXUNUSED(editable
),
1364 wxDataViewRenderer
*wxrenderer
)
1366 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1367 wxDataViewCtrl
*dv
= column
->GetOwner();
1368 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1369 event
.SetDataViewColumn( column
);
1370 event
.SetModel( dv
->GetModel() );
1371 wxDataViewItem
item( s_user_data
);
1372 event
.SetItem( item
);
1373 dv
->HandleWindowEvent( event
);
1377 wxgtk_renderer_editing_started( GtkCellRenderer
*WXUNUSED(cell
), GtkCellEditable
*editable
,
1378 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1380 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1381 wxDataViewCtrl
*dv
= column
->GetOwner();
1382 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1383 event
.SetDataViewColumn( column
);
1384 event
.SetModel( dv
->GetModel() );
1385 GtkTreePath
*tree_path
= gtk_tree_path_new_from_string( path
);
1387 dv
->GtkGetInternal()->get_iter( &iter
, tree_path
);
1388 gtk_tree_path_free( tree_path
);
1389 wxDataViewItem
item( iter
.user_data
);
1390 event
.SetItem( item
);
1391 dv
->HandleWindowEvent( event
);
1393 if (GTK_IS_CELL_EDITABLE(editable
))
1395 s_user_data
= iter
.user_data
;
1397 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1398 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1399 (gpointer
) wxrenderer
);
1405 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1407 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1409 wxDataViewRendererBase( varianttype
, mode
, align
)
1413 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1414 // after the m_renderer pointer has been initialized
1417 void wxDataViewRenderer::GtkInitHandlers()
1419 if (!gtk_check_version(2,6,0))
1421 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1422 G_CALLBACK (wxgtk_renderer_editing_started
),
1427 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1429 GtkCellRendererMode gtkMode
;
1432 case wxDATAVIEW_CELL_INERT
:
1433 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1436 case wxDATAVIEW_CELL_ACTIVATABLE
:
1437 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1440 case wxDATAVIEW_CELL_EDITABLE
:
1441 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1445 wxFAIL_MSG( "unknown wxDataViewCellMode value" );
1449 // This value is most often ignored in GtkTreeView
1450 GValue gvalue
= { 0, };
1451 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1452 g_value_set_enum( &gvalue
, gtkMode
);
1453 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1454 g_value_unset( &gvalue
);
1457 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1459 wxDataViewCellMode ret
;
1462 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1464 switch (g_value_get_enum(&gvalue
))
1467 wxFAIL_MSG( "unknown GtkCellRendererMode value" );
1468 // fall through (we have to return something)
1470 case GTK_CELL_RENDERER_MODE_INERT
:
1471 ret
= wxDATAVIEW_CELL_INERT
;
1474 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1475 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1478 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1479 ret
= wxDATAVIEW_CELL_EDITABLE
;
1483 g_value_unset( &gvalue
);
1488 void wxDataViewRenderer::GtkUpdateAlignment()
1490 int align
= m_alignment
;
1492 // query alignment from column ?
1496 if (GetOwner() == NULL
)
1499 align
= GetOwner()->GetAlignment();
1500 align
|= wxALIGN_CENTRE_VERTICAL
;
1503 // horizontal alignment:
1505 gfloat xalign
= 0.0;
1506 if (align
& wxALIGN_RIGHT
)
1508 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1511 GValue gvalue
= { 0, };
1512 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1513 g_value_set_float( &gvalue
, xalign
);
1514 g_object_set_property( G_OBJECT(m_renderer
), "xalign", &gvalue
);
1515 g_value_unset( &gvalue
);
1517 // vertical alignment:
1519 gfloat yalign
= 0.0;
1520 if (align
& wxALIGN_BOTTOM
)
1522 else if (align
& wxALIGN_CENTER_VERTICAL
)
1525 GValue gvalue2
= { 0, };
1526 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1527 g_value_set_float( &gvalue2
, yalign
);
1528 g_object_set_property( G_OBJECT(m_renderer
), "yalign", &gvalue2
);
1529 g_value_unset( &gvalue2
);
1532 void wxDataViewRenderer::SetAlignment( int align
)
1534 m_alignment
= align
;
1535 GtkUpdateAlignment();
1538 int wxDataViewRenderer::GetAlignment() const
1543 // ---------------------------------------------------------
1544 // wxDataViewTextRenderer
1545 // ---------------------------------------------------------
1548 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1549 gchar
*arg1
, gchar
*arg2
, gpointer user_data
);
1552 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*WXUNUSED(renderer
),
1553 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1555 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) user_data
;
1557 wxString tmp
= wxGTK_CONV_BACK_FONT(arg2
, cell
->GetOwner()->GetOwner()->GetFont());
1558 wxVariant value
= tmp
;
1559 if (!cell
->Validate( value
))
1562 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1564 GtkTreePath
*path
= gtk_tree_path_new_from_string( arg1
);
1566 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, path
);
1567 wxDataViewItem
item( (void*) iter
.user_data
);;
1568 gtk_tree_path_free( path
);
1570 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1572 model
->SetValue( value
, item
, model_col
);
1573 model
->ValueChanged( item
, model_col
);
1576 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
1578 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1580 wxDataViewRenderer( varianttype
, mode
, align
)
1582 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_text_new();
1584 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
1586 GValue gvalue
= { 0, };
1587 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1588 g_value_set_boolean( &gvalue
, true );
1589 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
1590 g_value_unset( &gvalue
);
1592 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
1598 SetAlignment(align
);
1601 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
1603 wxString tmp
= value
;
1605 GValue gvalue
= { 0, };
1606 g_value_init( &gvalue
, G_TYPE_STRING
);
1607 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( tmp
, GetOwner()->GetOwner()->GetFont() ) );
1608 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1609 g_value_unset( &gvalue
);
1614 bool wxDataViewTextRenderer::GetValue( wxVariant
&value
) const
1616 GValue gvalue
= { 0, };
1617 g_value_init( &gvalue
, G_TYPE_STRING
);
1618 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1619 wxString tmp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
), const_cast<wxDataViewTextRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
1620 g_value_unset( &gvalue
);
1627 void wxDataViewTextRenderer::SetAlignment( int align
)
1629 wxDataViewRenderer::SetAlignment(align
);
1631 if (gtk_check_version(2,10,0))
1634 // horizontal alignment:
1635 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
1636 if (align
& wxALIGN_RIGHT
)
1637 pangoAlign
= PANGO_ALIGN_RIGHT
;
1638 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1639 pangoAlign
= PANGO_ALIGN_CENTER
;
1641 GValue gvalue
= { 0, };
1642 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1643 g_value_set_enum( &gvalue
, pangoAlign
);
1644 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
1645 g_value_unset( &gvalue
);
1648 // ---------------------------------------------------------
1649 // wxDataViewTextRendererAttr
1650 // ---------------------------------------------------------
1652 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
,wxDataViewTextRenderer
)
1654 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString
&varianttype
,
1655 wxDataViewCellMode mode
, int align
) :
1656 wxDataViewTextRenderer( varianttype
, mode
, align
)
1660 // ---------------------------------------------------------
1661 // wxDataViewBitmapRenderer
1662 // ---------------------------------------------------------
1664 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
1666 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1668 wxDataViewRenderer( varianttype
, mode
, align
)
1670 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_pixbuf_new();
1673 SetAlignment(align
);
1676 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
1678 if (value
.GetType() == wxT("wxBitmap"))
1683 // This may create a Pixbuf representation in the
1684 // wxBitmap object (and it will stay there)
1685 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1687 GValue gvalue
= { 0, };
1688 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1689 g_value_set_object( &gvalue
, pixbuf
);
1690 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1691 g_value_unset( &gvalue
);
1696 if (value
.GetType() == wxT("wxIcon"))
1701 // This may create a Pixbuf representation in the
1702 // wxBitmap object (and it will stay there)
1703 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1705 GValue gvalue
= { 0, };
1706 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1707 g_value_set_object( &gvalue
, pixbuf
);
1708 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1709 g_value_unset( &gvalue
);
1717 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
1722 // ---------------------------------------------------------
1723 // wxDataViewToggleRenderer
1724 // ---------------------------------------------------------
1727 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1728 gchar
*path
, gpointer user_data
);
1731 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1732 gchar
*path
, gpointer user_data
)
1734 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
1737 GValue gvalue
= { 0, };
1738 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1739 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
1740 bool tmp
= g_value_get_boolean( &gvalue
);
1741 g_value_unset( &gvalue
);
1745 wxVariant value
= tmp
;
1746 if (!cell
->Validate( value
))
1749 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1751 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
1753 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, gtk_path
);
1754 wxDataViewItem
item( (void*) iter
.user_data
);;
1755 gtk_tree_path_free( gtk_path
);
1757 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1759 model
->SetValue( value
, item
, model_col
);
1760 model
->ValueChanged( item
, model_col
);
1763 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1765 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1766 wxDataViewCellMode mode
, int align
) :
1767 wxDataViewRenderer( varianttype
, mode
, align
)
1769 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
1771 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1773 g_signal_connect_after( m_renderer
, "toggled",
1774 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
1778 GValue gvalue
= { 0, };
1779 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1780 g_value_set_boolean( &gvalue
, false );
1781 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
1782 g_value_unset( &gvalue
);
1786 SetAlignment(align
);
1789 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1793 GValue gvalue
= { 0, };
1794 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1795 g_value_set_boolean( &gvalue
, tmp
);
1796 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1797 g_value_unset( &gvalue
);
1802 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
1804 GValue gvalue
= { 0, };
1805 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1806 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1807 bool tmp
= g_value_get_boolean( &gvalue
);
1808 g_value_unset( &gvalue
);
1815 // ---------------------------------------------------------
1816 // wxDataViewCustomRenderer
1817 // ---------------------------------------------------------
1819 class wxDataViewCtrlDCImpl
: public wxWindowDCImpl
1822 wxDataViewCtrlDCImpl( wxDC
*owner
, wxDataViewCtrl
*window
) :
1823 wxWindowDCImpl( owner
)
1825 GtkWidget
*widget
= window
->m_treeview
;
1831 m_context
= window
->GtkGetPangoDefaultContext();
1832 m_layout
= pango_layout_new( m_context
);
1833 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
1835 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
1837 // Set m_gdkwindow later
1842 class wxDataViewCtrlDC
: public wxWindowDC
1845 wxDataViewCtrlDC( wxDataViewCtrl
*window
) :
1846 wxWindowDC( new wxDataViewCtrlDCImpl( this, window
) )
1851 // ---------------------------------------------------------
1852 // wxDataViewCustomRenderer
1853 // ---------------------------------------------------------
1855 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
1857 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
1858 wxDataViewCellMode mode
, int align
,
1860 wxDataViewRenderer( varianttype
, mode
, align
)
1863 m_text_renderer
= NULL
;
1871 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
,
1872 wxRect
WXUNUSED(cell
), wxDC
*WXUNUSED(dc
), int WXUNUSED(state
) )
1875 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
1876 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
1877 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
1878 view
->GetForegroundColour();
1879 dc
->SetTextForeground(col
);
1880 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
1882 if (!m_text_renderer
)
1883 m_text_renderer
= gtk_cell_renderer_text_new();
1885 GValue gvalue
= { 0, };
1886 g_value_init( &gvalue
, G_TYPE_STRING
);
1887 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( text
, GetOwner()->GetOwner()->GetFont() ) );
1888 g_object_set_property( G_OBJECT(m_text_renderer
), "text", &gvalue
);
1889 g_value_unset( &gvalue
);
1891 ((GdkRectangle
*) cell_area
)->x
+= xoffset
;
1892 ((GdkRectangle
*) cell_area
)->width
-= xoffset
;
1894 gtk_cell_renderer_render( m_text_renderer
,
1897 (GdkRectangle
*) background_area
,
1898 (GdkRectangle
*) cell_area
,
1899 (GdkRectangle
*) expose_area
,
1900 (GtkCellRendererState
) flags
);
1902 ((GdkRectangle
*) cell_area
)->x
-= xoffset
;
1903 ((GdkRectangle
*) cell_area
)->width
+= xoffset
;
1907 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
1909 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
1910 renderer
->cell
= this;
1912 m_renderer
= (GtkCellRenderer
*) renderer
;
1915 SetAlignment(align
);
1922 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
1927 if (m_text_renderer
)
1928 gtk_object_sink( GTK_OBJECT(m_text_renderer
) );
1931 wxDC
*wxDataViewCustomRenderer::GetDC()
1935 if (GetOwner() == NULL
)
1937 if (GetOwner()->GetOwner() == NULL
)
1939 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
1945 // ---------------------------------------------------------
1946 // wxDataViewProgressRenderer
1947 // ---------------------------------------------------------
1949 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
1951 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
1952 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1953 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
1959 if (!gtk_check_version(2,6,0))
1961 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
1963 GValue gvalue
= { 0, };
1964 g_value_init( &gvalue
, G_TYPE_STRING
);
1966 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( m_label
, GetOwner()->GetOwner()->GetFont() ) );
1967 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1968 g_value_unset( &gvalue
);
1971 SetAlignment(align
);
1976 // Use custom cell code
1977 wxDataViewCustomRenderer::Init(mode
, align
);
1981 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
1985 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
1988 if (!gtk_check_version(2,6,0))
1990 gint tmp
= (long) value
;
1991 GValue gvalue
= { 0, };
1992 g_value_init( &gvalue
, G_TYPE_INT
);
1993 g_value_set_int( &gvalue
, tmp
);
1994 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
1995 g_value_unset( &gvalue
);
2000 m_value
= (long) value
;
2002 if (m_value
< 0) m_value
= 0;
2003 if (m_value
> 100) m_value
= 100;
2009 bool wxDataViewProgressRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2014 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
2016 double pct
= (double)m_value
/ 100.0;
2018 bar
.width
= (int)(cell
.width
* pct
);
2019 dc
->SetPen( *wxTRANSPARENT_PEN
);
2020 dc
->SetBrush( *wxBLUE_BRUSH
);
2021 dc
->DrawRectangle( bar
);
2023 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
2024 dc
->SetPen( *wxBLACK_PEN
);
2025 dc
->DrawRectangle( cell
);
2030 wxSize
wxDataViewProgressRenderer::GetSize() const
2032 return wxSize(40,12);
2035 // -------------------------------------
2036 // wxDataViewChoiceRenderer
2037 // -------------------------------------
2039 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
&choices
,
2040 wxDataViewCellMode mode
, int alignment
) :
2041 wxDataViewCustomRenderer( "string", mode
, alignment
, true )
2043 m_choices
= choices
;
2046 if (!gtk_check_version(2,6,0))
2048 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_combo_new();
2050 GtkListStore
*store
= gtk_list_store_new( 1, G_TYPE_STRING
);
2052 for (n
= 0; n
< m_choices
.GetCount(); n
++)
2053 gtk_list_store_insert_with_values( store
, NULL
, n
, 0, m_choices
[n
].utf8_str(), -1 );
2055 g_object_set (m_renderer
,
2061 bool editable
= (mode
& wxDATAVIEW_CELL_EDITABLE
);
2062 g_object_set (m_renderer
, "editable", editable
, NULL
);
2064 SetAlignment(alignment
);
2066 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2073 // Use custom cell code
2074 wxDataViewCustomRenderer::Init(mode
, alignment
);
2078 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
2080 RenderText( m_data
, 0, rect
, dc
, state
);
2084 wxSize
wxDataViewChoiceRenderer::GetSize() const
2086 return wxSize(70,20);
2089 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
2093 if (!gtk_check_version(2,6,0))
2095 GValue gvalue
= { 0, };
2096 g_value_init( &gvalue
, G_TYPE_STRING
);
2097 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( value
.GetString(), GetOwner()->GetOwner()->GetFont() ) );
2098 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2099 g_value_unset( &gvalue
);
2103 m_data
= value
.GetString();
2108 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
2111 if (!gtk_check_version(2,6,0))
2113 GValue gvalue
= { 0, };
2114 g_value_init( &gvalue
, G_TYPE_STRING
);
2115 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2116 wxString temp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
), const_cast<wxDataViewTextRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
2117 g_value_unset( &gvalue
);
2119 wxPrintf( "temp %s\n", temp
);
2128 void wxDataViewChoiceRenderer::SetAlignment( int align
)
2130 wxDataViewCustomRenderer::SetAlignment(align
);
2132 if (gtk_check_version(2,10,0))
2135 // horizontal alignment:
2136 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2137 if (align
& wxALIGN_RIGHT
)
2138 pangoAlign
= PANGO_ALIGN_RIGHT
;
2139 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2140 pangoAlign
= PANGO_ALIGN_CENTER
;
2142 GValue gvalue
= { 0, };
2143 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2144 g_value_set_enum( &gvalue
, pangoAlign
);
2145 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2146 g_value_unset( &gvalue
);
2149 // ---------------------------------------------------------
2150 // wxDataViewDateRenderer
2151 // ---------------------------------------------------------
2153 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
2156 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
2157 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
2158 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
2163 m_cal
= new wxCalendarCtrl( this, -1, *value
);
2164 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
2165 sizer
->Add( m_cal
, 1, wxGROW
);
2170 virtual void OnDismiss()
2174 void OnCalendar( wxCalendarEvent
&event
);
2176 wxCalendarCtrl
*m_cal
;
2177 wxDataViewModel
*m_model
;
2178 wxDataViewItem m_item
;
2182 DECLARE_EVENT_TABLE()
2185 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
2186 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
2189 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
2191 wxDateTime date
= event
.GetDate();
2192 wxVariant value
= date
;
2193 m_model
->SetValue( value
, m_item
, m_col
);
2194 m_model
->ValueChanged( m_item
, m_col
);
2198 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
2200 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
2201 wxDataViewCellMode mode
, int align
) :
2202 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2205 SetAlignment(align
);
2208 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
2210 m_date
= value
.GetDateTime();
2215 bool wxDataViewDateRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2220 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2222 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
2223 wxString tmp
= m_date
.FormatDate();
2224 RenderText( tmp
, 0, cell
, dc
, state
);
2228 wxSize
wxDataViewDateRenderer::GetSize() const
2230 wxString tmp
= m_date
.FormatDate();
2232 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
2233 return wxSize(x
,y
+d
);
2236 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
2237 const wxDataViewItem
&item
, unsigned int col
)
2240 model
->GetValue( variant
, item
, col
);
2241 wxDateTime value
= variant
.GetDateTime();
2243 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
2244 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
2245 wxPoint pos
= wxGetMousePosition();
2248 popup
->Popup( popup
->m_cal
);
2254 // ---------------------------------------------------------
2255 // wxDataViewIconTextRenderer
2256 // ---------------------------------------------------------
2258 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
2260 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
2261 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
2262 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2265 SetAlignment(align
);
2268 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2272 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
2278 bool wxDataViewIconTextRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2283 bool wxDataViewIconTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2285 const wxIcon
&icon
= m_value
.GetIcon();
2289 int yoffset
= wxMax( 0, (cell
.height
- icon
.GetHeight()) / 2 );
2290 dc
->DrawIcon( icon
, cell
.x
, cell
.y
+ yoffset
);
2291 offset
= icon
.GetWidth() + 4;
2294 RenderText( m_value
.GetText(), offset
, cell
, dc
, state
);
2299 wxSize
wxDataViewIconTextRenderer::GetSize() const
2302 if (m_value
.GetIcon().IsOk())
2303 size
.x
= 4 + m_value
.GetIcon().GetWidth();
2305 GetView()->GetTextExtent( m_value
.GetText(), &x
, &y
, &d
);
2311 wxControl
* wxDataViewIconTextRenderer::CreateEditorCtrl(
2312 wxWindow
*WXUNUSED(parent
), wxRect
WXUNUSED(labelRect
), const wxVariant
&WXUNUSED(value
) )
2317 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl(
2318 wxControl
* WXUNUSED(editor
), wxVariant
&WXUNUSED(value
) )
2323 // ---------------------------------------------------------
2325 // ---------------------------------------------------------
2329 gtk_dataview_header_button_press_callback( GtkWidget
*WXUNUSED(widget
),
2330 GdkEventButton
*gdk_event
,
2331 wxDataViewColumn
*column
)
2333 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
2336 if (gdk_event
->button
== 1)
2338 gs_lastLeftClickHeader
= column
;
2340 wxDataViewCtrl
*dv
= column
->GetOwner();
2341 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
2342 event
.SetDataViewColumn( column
);
2343 event
.SetModel( dv
->GetModel() );
2344 if (dv
->HandleWindowEvent( event
))
2348 if (gdk_event
->button
== 3)
2350 wxDataViewCtrl
*dv
= column
->GetOwner();
2351 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
2352 event
.SetDataViewColumn( column
);
2353 event
.SetModel( dv
->GetModel() );
2354 if (dv
->HandleWindowEvent( event
))
2362 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
2363 GtkCellRenderer
*cell
,
2364 GtkTreeModel
*model
,
2370 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*WXUNUSED(column
),
2371 GtkCellRenderer
*renderer
,
2372 GtkTreeModel
*model
,
2376 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2377 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2379 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2381 wxDataViewItem
item( (void*) iter
->user_data
);
2383 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
2385 if (!wx_model
->IsVirtualListModel())
2388 if (wx_model
->IsContainer( item
))
2390 if (wx_model
->HasContainerColumns( item
) || (cell
->GetOwner()->GetModelColumn() == 0))
2392 GValue gvalue
= { 0, };
2393 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2394 g_value_set_boolean( &gvalue
, TRUE
);
2395 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2396 g_value_unset( &gvalue
);
2400 GValue gvalue
= { 0, };
2401 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2402 g_value_set_boolean( &gvalue
, FALSE
);
2403 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2404 g_value_unset( &gvalue
);
2411 GValue gvalue
= { 0, };
2412 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2413 g_value_set_boolean( &gvalue
, TRUE
);
2414 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2415 g_value_unset( &gvalue
);
2421 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
2423 if (value
.GetType() != cell
->GetVariantType())
2424 wxLogError( wxT("Wrong type, required: %s but: %s"),
2425 value
.GetType().c_str(),
2426 cell
->GetVariantType().c_str() );
2428 cell
->SetValue( value
);
2430 if (cell
->GtkHasAttributes())
2432 wxDataViewItemAttr attr
;
2433 bool colour_set
= false;
2434 bool style_set
= false;
2435 bool weight_set
= false;
2437 if (wx_model
->GetAttr( item
, cell
->GetOwner()->GetModelColumn(), attr
))
2439 // this must be a GtkCellRendererText
2440 wxColour colour
= attr
.GetColour();
2443 const GdkColor
* const gcol
= colour
.GetColor();
2445 GValue gvalue
= { 0, };
2446 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2447 g_value_set_boxed( &gvalue
, gcol
);
2448 g_object_set_property( G_OBJECT(renderer
), "foreground_gdk", &gvalue
);
2449 g_value_unset( &gvalue
);
2454 if (attr
.GetItalic())
2456 GValue gvalue
= { 0, };
2457 g_value_init( &gvalue
, PANGO_TYPE_STYLE
);
2458 g_value_set_enum( &gvalue
, PANGO_STYLE_ITALIC
);
2459 g_object_set_property( G_OBJECT(renderer
), "style", &gvalue
);
2460 g_value_unset( &gvalue
);
2467 GValue gvalue
= { 0, };
2468 g_value_init( &gvalue
, PANGO_TYPE_WEIGHT
);
2469 g_value_set_enum( &gvalue
, PANGO_WEIGHT_BOLD
);
2470 g_object_set_property( G_OBJECT(renderer
), "weight", &gvalue
);
2471 g_value_unset( &gvalue
);
2479 GValue gvalue
= { 0, };
2480 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2481 g_value_set_boolean( &gvalue
, FALSE
);
2482 g_object_set_property( G_OBJECT(renderer
), "style-set", &gvalue
);
2483 g_value_unset( &gvalue
);
2488 GValue gvalue
= { 0, };
2489 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2490 g_value_set_boolean( &gvalue
, FALSE
);
2491 g_object_set_property( G_OBJECT(renderer
), "weight-set", &gvalue
);
2492 g_value_unset( &gvalue
);
2497 GValue gvalue
= { 0, };
2498 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2499 g_value_set_boolean( &gvalue
, FALSE
);
2500 g_object_set_property( G_OBJECT(renderer
), "foreground-set", &gvalue
);
2501 g_value_unset( &gvalue
);
2506 if (attr
.HasBackgroundColour())
2508 wxColour colour
= attr
.GetBackgroundColour();
2509 const GdkColor
* const gcol
= colour
.GetColor();
2511 GValue gvalue
= { 0, };
2512 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2513 g_value_set_boxed( &gvalue
, gcol
);
2514 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
2515 g_value_unset( &gvalue
);
2519 GValue gvalue
= { 0, };
2520 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2521 g_value_set_boolean( &gvalue
, FALSE
);
2522 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
2523 g_value_unset( &gvalue
);
2529 #include <wx/listimpl.cpp>
2530 WX_DEFINE_LIST(wxDataViewColumnList
)
2532 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
2533 unsigned int model_column
, int width
,
2534 wxAlignment align
, int flags
)
2535 : wxDataViewColumnBase( cell
, model_column
)
2537 Init( align
, flags
, width
);
2542 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
2543 unsigned int model_column
, int width
,
2544 wxAlignment align
, int flags
)
2545 : wxDataViewColumnBase( bitmap
, cell
, model_column
)
2547 Init( align
, flags
, width
);
2549 SetBitmap( bitmap
);
2552 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
2554 m_isConnected
= false;
2556 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) GetRenderer()->GetGtkHandle();
2557 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
2558 m_column
= (GtkWidget
*) column
;
2561 SetAlignment( align
);
2565 // Create container for icon and label
2566 GtkWidget
*box
= gtk_hbox_new( FALSE
, 1 );
2567 gtk_widget_show( box
);
2568 // gtk_container_set_border_width((GtkContainer*)box, 2);
2569 m_image
= gtk_image_new();
2570 gtk_box_pack_start(GTK_BOX(box
), m_image
, FALSE
, FALSE
, 1);
2571 m_label
= gtk_label_new("");
2572 gtk_box_pack_end( GTK_BOX(box
), GTK_WIDGET(m_label
), FALSE
, FALSE
, 1 );
2573 gtk_tree_view_column_set_widget( column
, box
);
2575 gtk_tree_view_column_pack_end( column
, renderer
, TRUE
);
2577 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
2578 wxGtkTreeCellDataFunc
, (gpointer
) GetRenderer(), NULL
);
2581 void wxDataViewColumn::OnInternalIdle()
2586 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
2588 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2591 g_signal_connect(column
->button
, "button_press_event",
2592 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
2594 m_isConnected
= true;
2599 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
2601 wxDataViewColumnBase::SetOwner( owner
);
2603 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2605 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
2608 void wxDataViewColumn::SetTitle( const wxString
&title
)
2610 wxDataViewCtrl
*ctrl
= GetOwner();
2611 gtk_label_set_text( GTK_LABEL(m_label
), ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
2612 : wxGTK_CONV_SYS(title
) );
2614 gtk_widget_hide( m_label
);
2616 gtk_widget_show( m_label
);
2619 wxString
wxDataViewColumn::GetTitle() const
2621 return wxGTK_CONV_BACK_FONT(
2622 gtk_label_get_text( GTK_LABEL(m_label
) ),
2623 GetOwner()->GetFont()
2627 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
2629 wxDataViewColumnBase::SetBitmap( bitmap
);
2633 GtkImage
*gtk_image
= GTK_IMAGE(m_image
);
2635 GdkBitmap
*mask
= NULL
;
2636 if (bitmap
.GetMask())
2637 mask
= bitmap
.GetMask()->GetBitmap();
2639 if (bitmap
.HasPixbuf())
2641 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
2642 bitmap
.GetPixbuf());
2646 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
2647 bitmap
.GetPixmap(), mask
);
2649 gtk_widget_show( m_image
);
2653 gtk_widget_hide( m_image
);
2657 void wxDataViewColumn::SetHidden( bool hidden
)
2659 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
2662 void wxDataViewColumn::SetResizeable( bool resizeable
)
2664 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizeable
);
2667 void wxDataViewColumn::SetAlignment( wxAlignment align
)
2669 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2671 gfloat xalign
= 0.0;
2672 if (align
== wxALIGN_RIGHT
)
2674 if (align
== wxALIGN_CENTER_HORIZONTAL
||
2675 align
== wxALIGN_CENTER
)
2678 gtk_tree_view_column_set_alignment( column
, xalign
);
2680 if (m_renderer
&& m_renderer
->GetAlignment() == -1)
2681 m_renderer
->GtkUpdateAlignment();
2684 wxAlignment
wxDataViewColumn::GetAlignment() const
2686 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
2689 return wxALIGN_RIGHT
;
2691 return wxALIGN_CENTER_HORIZONTAL
;
2693 return wxALIGN_LEFT
;
2696 void wxDataViewColumn::SetSortable( bool sortable
)
2698 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2702 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
2706 gtk_tree_view_column_set_sort_column_id( column
, -1 );
2707 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
2708 gtk_tree_view_column_set_clickable( column
, FALSE
);
2712 bool wxDataViewColumn::IsSortable() const
2714 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2715 return gtk_tree_view_column_get_clickable( column
);
2718 void wxDataViewColumn::SetAsSortKey( bool WXUNUSED(sort
) )
2720 // it might not make sense to have this function in wxHeaderColumn at
2721 // all in fact, changing of the sort order should only be done using the
2722 // associated control API
2723 wxFAIL_MSG( "not implemented" );
2726 bool wxDataViewColumn::IsSortKey() const
2728 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2729 return gtk_tree_view_column_get_sort_indicator( column
);
2732 bool wxDataViewColumn::IsResizeable() const
2734 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2735 return gtk_tree_view_column_get_resizable( column
);
2738 bool wxDataViewColumn::IsHidden() const
2740 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2741 return !gtk_tree_view_column_get_visible( column
);
2744 void wxDataViewColumn::SetSortOrder( bool ascending
)
2746 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2749 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
2751 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
2753 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
2756 bool wxDataViewColumn::IsSortOrderAscending() const
2758 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2760 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
2763 void wxDataViewColumn::SetMinWidth( int width
)
2765 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2768 int wxDataViewColumn::GetMinWidth() const
2770 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2773 int wxDataViewColumn::GetWidth() const
2775 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2778 void wxDataViewColumn::SetWidth( int width
)
2783 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
2785 // TODO find a better calculation
2786 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), wxDVC_DEFAULT_WIDTH
);
2788 // this is unpractical for large numbers of items and disables
2789 // user resizing, which is totally unexpected
2790 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
2795 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
2797 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2801 void wxDataViewColumn::SetReorderable( bool reorderable
)
2803 gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column
), reorderable
);
2806 bool wxDataViewColumn::IsReorderable() const
2808 return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column
) );
2811 //-----------------------------------------------------------------------------
2812 // wxGtkTreeModelNode
2813 //-----------------------------------------------------------------------------
2815 void wxGtkTreeModelNode::Resort()
2817 size_t child_count
= GetChildCount();
2818 if (child_count
== 0)
2821 size_t node_count
= GetNodesCount();
2823 if (child_count
== 1)
2825 if (node_count
== 1)
2827 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
2833 wxGtkTreeModelChildren temp
;
2834 WX_APPEND_ARRAY( temp
, m_children
);
2836 gs_internal
= m_internal
;
2837 m_children
.Sort( &wxGtkTreeModelChildCmp
);
2839 gint
*new_order
= new gint
[child_count
];
2842 for (pos
= 0; pos
< child_count
; pos
++)
2844 void *id
= m_children
.Item( pos
);
2845 int old_pos
= temp
.Index( id
);
2846 new_order
[pos
] = old_pos
;
2849 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
2852 iter
.user_data
= GetItem().GetID();
2853 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
2855 GtkTreePath
*path
= m_internal
->get_path( &iter
);
2857 gtk_tree_model_rows_reordered( gtk_tree_model
, path
, &iter
, new_order
);
2859 gtk_tree_path_free (path
);
2861 delete [] new_order
;
2863 for (pos
= 0; pos
< node_count
; pos
++)
2865 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
2870 //-----------------------------------------------------------------------------
2871 // wxDataViewCtrlInternal
2872 //-----------------------------------------------------------------------------
2874 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
,
2875 wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
)
2878 m_wx_model
= wx_model
;
2879 m_gtk_model
= gtk_model
;
2881 m_sort_order
= GTK_SORT_ASCENDING
;
2883 m_dataview_sort_column
= NULL
;
2885 m_dragDataObject
= NULL
;
2886 m_dropDataObject
= NULL
;
2888 if (!m_wx_model
->IsVirtualListModel())
2892 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
2894 g_object_unref( m_gtk_model
);
2896 delete m_dragDataObject
;
2897 delete m_dropDataObject
;
2900 void wxDataViewCtrlInternal::InitTree()
2902 wxDataViewItem item
;
2903 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
2905 BuildBranch( m_root
);
2908 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
2910 if (node
->GetChildCount() == 0)
2912 wxDataViewItemArray children
;
2913 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
2915 for (pos
= 0; pos
< count
; pos
++)
2917 wxDataViewItem child
= children
[pos
];
2919 if (m_wx_model
->IsContainer( child
))
2920 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
2922 node
->AddLeave( child
.GetID() );
2924 // Don't send any events here
2931 bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat
&format
)
2933 wxGtkString
atom_str( gdk_atom_name( format
) );
2934 m_dragSourceTargetEntryTarget
= wxCharBuffer( atom_str
);
2936 m_dragSourceTargetEntry
.target
= m_dragSourceTargetEntryTarget
.data();
2937 m_dragSourceTargetEntry
.flags
= 0;
2938 m_dragSourceTargetEntry
.info
= static_cast<guint
>(-1);
2940 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
2941 GDK_BUTTON1_MASK
, &m_dragSourceTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
2946 bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat
&format
)
2948 wxGtkString
atom_str( gdk_atom_name( format
) );
2949 m_dropTargetTargetEntryTarget
= wxCharBuffer( atom_str
);
2951 m_dropTargetTargetEntry
.target
= m_dropTargetTargetEntryTarget
.data();
2952 m_dropTargetTargetEntry
.flags
= 0;
2953 m_dropTargetTargetEntry
.info
= static_cast<guint
>(-1);
2955 gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
2956 &m_dropTargetTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
2961 gboolean
wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource
*WXUNUSED(drag_source
),
2964 delete m_dragDataObject
;
2967 if (!get_iter( &iter
, path
)) return FALSE
;
2968 wxDataViewItem
item( (void*) iter
.user_data
);
2970 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
2971 event
.SetEventObject( m_owner
);
2972 event
.SetItem( item
);
2973 event
.SetModel( m_wx_model
);
2974 if (!m_owner
->HandleWindowEvent( event
))
2977 if (!event
.IsAllowed())
2980 wxDataObject
*obj
= event
.GetDataObject();
2984 m_dragDataObject
= obj
;
2990 wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource
*WXUNUSED(drag_source
),
2991 GtkTreePath
*WXUNUSED(path
))
2996 gboolean
wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource
*WXUNUSED(drag_source
),
2997 GtkTreePath
*path
, GtkSelectionData
*selection_data
)
3000 if (!get_iter( &iter
, path
)) return FALSE
;
3001 wxDataViewItem
item( (void*) iter
.user_data
);
3003 if (!m_dragDataObject
->IsSupported( selection_data
->target
))
3006 size_t size
= m_dragDataObject
->GetDataSize( selection_data
->target
);
3010 void *buf
= malloc( size
);
3012 gboolean res
= FALSE
;
3013 if (m_dragDataObject
->GetDataHere( selection_data
->target
, buf
))
3017 gtk_selection_data_set( selection_data
, selection_data
->target
,
3018 8, (const guchar
*) buf
, size
);
3027 wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3029 GtkSelectionData
*selection_data
)
3032 if (!get_iter( &iter
, path
)) return FALSE
;
3033 wxDataViewItem
item( (void*) iter
.user_data
);
3035 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
3036 event
.SetEventObject( m_owner
);
3037 event
.SetItem( item
);
3038 event
.SetModel( m_wx_model
);
3039 event
.SetDataFormat( selection_data
->target
);
3040 event
.SetDataSize( selection_data
->length
);
3041 event
.SetDataBuffer( selection_data
->data
);
3042 if (!m_owner
->HandleWindowEvent( event
))
3045 if (!event
.IsAllowed())
3052 wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3054 GtkSelectionData
*selection_data
)
3057 if (!get_iter( &iter
, path
)) return FALSE
;
3058 wxDataViewItem
item( (void*) iter
.user_data
);
3060 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
3061 event
.SetEventObject( m_owner
);
3062 event
.SetItem( item
);
3063 event
.SetModel( m_wx_model
);
3064 event
.SetDataFormat( selection_data
->target
);
3065 if (!m_owner
->HandleWindowEvent( event
))
3068 if (!event
.IsAllowed())
3074 // notifications from wxDataViewModel
3076 bool wxDataViewCtrlInternal::Cleared()
3084 // Create new GTK model
3085 g_object_unref( m_gtk_model
);
3086 m_gtk_model
= wxgtk_tree_model_new();
3087 m_gtk_model
->internal
= this;
3092 void wxDataViewCtrlInternal::Resort()
3094 if (!m_wx_model
->IsVirtualListModel())
3098 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3100 if (!m_wx_model
->IsVirtualListModel())
3102 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3103 if (m_wx_model
->IsContainer( item
))
3104 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
3106 parent_node
->AddLeave( item
.GetID() );
3112 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3114 if (!m_wx_model
->IsVirtualListModel())
3116 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3117 parent_node
->DeleteChild( item
.GetID() );
3123 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
3125 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3126 event
.SetEventObject( m_owner
);
3127 event
.SetModel( m_owner
->GetModel() );
3128 event
.SetItem( item
);
3129 m_owner
->HandleWindowEvent( event
);
3134 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
3136 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3137 event
.SetEventObject( m_owner
);
3138 event
.SetModel( m_owner
->GetModel() );
3139 event
.SetColumn( col
);
3140 event
.SetDataViewColumn( GetOwner()->GetColumn(col
) );
3141 event
.SetItem( item
);
3142 m_owner
->HandleWindowEvent( event
);
3149 GtkTreeModelFlags
wxDataViewCtrlInternal::get_flags()
3151 if (m_wx_model
->IsVirtualListModel())
3152 return GTK_TREE_MODEL_LIST_ONLY
;
3154 return GTK_TREE_MODEL_ITERS_PERSIST
;
3157 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
3159 if (m_wx_model
->IsVirtualListModel())
3161 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3163 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
3165 if (i
>= wx_model
->GetLastIndex() + 1)
3168 iter
->stamp
= m_gtk_model
->stamp
;
3169 // user_data is just the index
3170 iter
->user_data
= (gpointer
) i
;
3176 int depth
= gtk_tree_path_get_depth( path
);
3178 wxGtkTreeModelNode
*node
= m_root
;
3181 for (i
= 0; i
< depth
; i
++)
3183 BuildBranch( node
);
3185 gint pos
= gtk_tree_path_get_indices (path
)[i
];
3186 if (pos
< 0) return FALSE
;
3187 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
3189 void* id
= node
->GetChildren().Item( (size_t) pos
);
3193 iter
->stamp
= m_gtk_model
->stamp
;
3194 iter
->user_data
= id
;
3198 size_t count
= node
->GetNodes().GetCount();
3200 for (pos2
= 0; pos2
< count
; pos2
++)
3202 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
3203 if (child_node
->GetItem().GetID() == id
)
3215 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
3217 GtkTreePath
*retval
= gtk_tree_path_new ();
3219 if (m_wx_model
->IsVirtualListModel())
3221 // user_data is just the index
3222 int i
= (wxUIntPtr
) iter
->user_data
;
3223 gtk_tree_path_append_index (retval
, i
);
3227 void *id
= iter
->user_data
;
3229 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
3232 int pos
= node
->GetChildren().Index( id
);
3234 gtk_tree_path_prepend_index( retval
, pos
);
3236 id
= node
->GetItem().GetID();
3237 node
= node
->GetParent();
3244 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
3246 if (m_wx_model
->IsVirtualListModel())
3248 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3250 int n
= (wxUIntPtr
) iter
->user_data
;
3255 if (n
>= (int) wx_model
->GetLastIndex())
3258 iter
->user_data
= (gpointer
) ++n
;
3262 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
3263 if( parent
== NULL
)
3266 int pos
= parent
->GetChildren().Index( iter
->user_data
);
3268 if (pos
== (int) parent
->GetChildCount()-1)
3271 iter
->stamp
= m_gtk_model
->stamp
;
3272 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
3278 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
3280 if (m_wx_model
->IsVirtualListModel())
3282 // this is a list, nodes have no children
3286 iter
->stamp
= m_gtk_model
->stamp
;
3287 iter
->user_data
= (gpointer
) -1;
3293 wxDataViewItem
item( (void*) parent
->user_data
);
3295 if (!m_wx_model
->IsContainer( item
))
3298 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3299 BuildBranch( parent_node
);
3301 if (parent_node
->GetChildCount() == 0)
3304 iter
->stamp
= m_gtk_model
->stamp
;
3305 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
3311 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
3313 if (m_wx_model
->IsVirtualListModel())
3315 // this is a list, nodes have no children
3320 wxDataViewItem
item( (void*) iter
->user_data
);
3322 bool is_container
= m_wx_model
->IsContainer( item
);
3327 wxGtkTreeModelNode
*node
= FindNode( iter
);
3328 BuildBranch( node
);
3330 return (node
->GetChildCount() > 0);
3334 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
3336 if (m_wx_model
->IsVirtualListModel())
3338 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3341 return (gint
) wx_model
->GetLastIndex() + 1;
3348 return m_root
->GetChildCount();
3350 wxDataViewItem
item( (void*) iter
->user_data
);
3352 if (!m_wx_model
->IsContainer( item
))
3355 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
3356 BuildBranch( parent_node
);
3358 // wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() );
3360 return parent_node
->GetChildCount();
3364 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
3366 if (m_wx_model
->IsVirtualListModel())
3368 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3376 if (n
>= (gint
) wx_model
->GetLastIndex() + 1)
3379 iter
->stamp
= m_gtk_model
->stamp
;
3380 iter
->user_data
= (gpointer
) n
;
3387 if (parent
) id
= (void*) parent
->user_data
;
3388 wxDataViewItem
item( id
);
3390 if (!m_wx_model
->IsContainer( item
))
3393 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3394 BuildBranch( parent_node
);
3396 // wxPrintf( "iter_nth_child %d\n", n );
3398 iter
->stamp
= m_gtk_model
->stamp
;
3399 iter
->user_data
= parent_node
->GetChildren().Item( n
);
3405 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
3407 if (m_wx_model
->IsVirtualListModel())
3413 wxGtkTreeModelNode
*node
= FindParentNode( child
);
3417 iter
->stamp
= m_gtk_model
->stamp
;
3418 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
3424 static wxGtkTreeModelNode
*
3425 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3431 list
.DeleteContents( true );
3432 wxDataViewItem
it( item
);
3436 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3437 list
.Insert( pItem
);
3438 it
= model
->GetParent( it
);
3441 wxGtkTreeModelNode
* node
= treeNode
;
3442 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3444 if( node
&& node
->GetNodes().GetCount() != 0 )
3446 int len
= node
->GetNodes().GetCount();
3447 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3449 for( ; j
< len
; j
++)
3451 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3470 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
3475 wxDataViewItem
item( (void*) iter
->user_data
);
3479 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3483 wxLogDebug( "Not found %p", iter
->user_data
);
3491 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
3496 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3500 wxLogDebug( "Not found %p", item
.GetID() );
3508 static wxGtkTreeModelNode
*
3509 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3515 list
.DeleteContents( true );
3519 wxDataViewItem
it( model
->GetParent( item
) );
3522 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3523 list
.Insert( pItem
);
3524 it
= model
->GetParent( it
);
3527 wxGtkTreeModelNode
* node
= treeNode
;
3528 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3530 if( node
&& node
->GetNodes().GetCount() != 0 )
3532 int len
= node
->GetNodes().GetCount();
3533 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3535 for( ; j
< len
; j
++)
3537 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3552 //Examine whether the node is item's parent node
3553 int len
= node
->GetChildCount();
3554 for( int i
= 0; i
< len
; i
++ )
3556 if( node
->GetChildren().Item( i
) == item
.GetID() )
3562 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
3567 wxDataViewItem
item( (void*) iter
->user_data
);
3571 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3574 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
3579 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3582 //-----------------------------------------------------------------------------
3583 // wxDataViewCtrl signal callbacks
3584 //-----------------------------------------------------------------------------
3587 wxdataview_selection_changed_callback( GtkTreeSelection
* WXUNUSED(selection
), wxDataViewCtrl
*dv
)
3589 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
3592 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
3593 event
.SetItem( dv
->GetSelection() );
3594 event
.SetModel( dv
->GetModel() );
3595 dv
->HandleWindowEvent( event
);
3599 wxdataview_row_activated_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreePath
*path
,
3600 GtkTreeViewColumn
*WXUNUSED(column
), wxDataViewCtrl
*dv
)
3602 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
3605 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3606 wxDataViewItem
item( (void*) iter
.user_data
);;
3607 event
.SetItem( item
);
3608 event
.SetModel( dv
->GetModel() );
3609 dv
->HandleWindowEvent( event
);
3613 wxdataview_test_expand_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3614 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3616 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
3618 wxDataViewItem
item( (void*) iter
->user_data
);;
3619 event
.SetItem( item
);
3620 event
.SetModel( dv
->GetModel() );
3621 dv
->HandleWindowEvent( event
);
3623 return !event
.IsAllowed();
3627 wxdataview_row_expanded_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3628 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3630 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
3632 wxDataViewItem
item( (void*) iter
->user_data
);;
3633 event
.SetItem( item
);
3634 event
.SetModel( dv
->GetModel() );
3635 dv
->HandleWindowEvent( event
);
3639 wxdataview_test_collapse_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3640 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3642 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
3644 wxDataViewItem
item( (void*) iter
->user_data
);;
3645 event
.SetItem( item
);
3646 event
.SetModel( dv
->GetModel() );
3647 dv
->HandleWindowEvent( event
);
3649 return !event
.IsAllowed();
3653 wxdataview_row_collapsed_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3654 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3656 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
3658 wxDataViewItem
item( (void*) iter
->user_data
);;
3659 event
.SetItem( item
);
3660 event
.SetModel( dv
->GetModel() );
3661 dv
->HandleWindowEvent( event
);
3664 //-----------------------------------------------------------------------------
3666 //-----------------------------------------------------------------------------
3668 void wxDataViewCtrl::AddChildGTK(wxWindowGTK
* child
)
3670 GtkWidget
* treeview
= GtkGetTreeView();
3672 // Insert widget in GtkTreeView
3673 if (GTK_WIDGET_REALIZED(treeview
))
3674 gtk_widget_set_parent_window( child
->m_widget
,
3675 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
3676 gtk_widget_set_parent( child
->m_widget
, treeview
);
3680 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
3681 GtkAllocation
*WXUNUSED(gtk_alloc
),
3682 wxDataViewCtrl
*win
)
3684 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
3687 wxWindow
*child
= node
->GetData();
3690 gtk_widget_size_request( child
->m_widget
, &req
);
3692 GtkAllocation alloc
;
3693 alloc
.x
= child
->m_x
;
3694 alloc
.y
= child
->m_y
;
3695 alloc
.width
= child
->m_width
;
3696 alloc
.height
= child
->m_height
;
3697 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
3699 node
= node
->GetNext();
3704 //-----------------------------------------------------------------------------
3705 // "motion_notify_event"
3706 //-----------------------------------------------------------------------------
3709 gtk_dataview_motion_notify_callback( GtkWidget
*WXUNUSED(widget
),
3710 GdkEventMotion
*gdk_event
,
3711 wxDataViewCtrl
*dv
)
3713 if (gdk_event
->is_hint
)
3717 GdkModifierType state
;
3718 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
3723 GtkTreePath
*path
= NULL
;
3724 GtkTreeViewColumn
*column
= NULL
;
3727 if (gtk_tree_view_get_path_at_pos(
3728 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
3729 (int) gdk_event
->x
, (int) gdk_event
->y
,
3738 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3740 // wxPrintf( "mouse %d %d\n", (int) gdk_event->x, (int) gdk_event->y );
3742 gtk_tree_path_free( path
);
3750 //-----------------------------------------------------------------------------
3751 // "button_press_event"
3752 //-----------------------------------------------------------------------------
3755 gtk_dataview_button_press_callback( GtkWidget
*WXUNUSED(widget
),
3756 GdkEventButton
*gdk_event
,
3757 wxDataViewCtrl
*dv
)
3759 if ((gdk_event
->button
== 3) && (gdk_event
->type
== GDK_BUTTON_PRESS
))
3761 GtkTreePath
*path
= NULL
;
3762 GtkTreeViewColumn
*column
= NULL
;
3765 if (gtk_tree_view_get_path_at_pos(
3766 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
3767 (int) gdk_event
->x
, (int) gdk_event
->y
,
3776 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3778 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, dv
->GetId() );
3779 wxDataViewItem
item( (void*) iter
.user_data
);;
3780 event
.SetItem( item
);
3781 event
.SetModel( dv
->GetModel() );
3782 bool ret
= dv
->HandleWindowEvent( event
);
3783 gtk_tree_path_free( path
);
3792 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
3794 wxDataViewCtrl::~wxDataViewCtrl()
3797 GetModel()->RemoveNotifier( m_notifier
);
3801 // remove the model from the GtkTreeView before it gets destroyed by the
3802 // wxDataViewCtrlBase's dtor
3803 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), NULL
);
3808 void wxDataViewCtrl::Init()
3813 m_cols
.DeleteContents( true );
3816 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
3817 const wxPoint
& pos
, const wxSize
& size
,
3818 long style
, const wxValidator
& validator
)
3822 if (!PreCreation( parent
, pos
, size
) ||
3823 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
3825 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
3829 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
3830 g_object_ref(m_widget
);
3832 GtkScrolledWindowSetBorder(m_widget
, style
);
3834 m_treeview
= gtk_tree_view_new();
3835 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
3837 g_signal_connect (m_treeview
, "size_allocate",
3838 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
3841 if (!gtk_check_version(2,6,0))
3843 bool fixed
= (style
& wxDV_VARIABLE_LINE_HEIGHT
) == 0;
3844 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
3848 if (style
& wxDV_MULTIPLE
)
3850 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3851 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
3854 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
3857 if (!gtk_check_version(2,10,0))
3859 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
3861 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
3862 (style
& wxDV_VERT_RULES
) != 0)
3863 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
3864 else if (style
& wxDV_VERT_RULES
)
3865 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
3866 else if (style
& wxDV_HORIZ_RULES
)
3867 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
3869 if (grid
!= GTK_TREE_VIEW_GRID_LINES_NONE
)
3870 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
3874 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_ROW_LINES
) != 0 );
3876 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
3877 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
3878 gtk_widget_show (m_treeview
);
3880 m_parent
->DoAddChild( this );
3884 GtkEnableSelectionEvents();
3886 g_signal_connect_after (m_treeview
, "row-activated",
3887 G_CALLBACK (wxdataview_row_activated_callback
), this);
3889 g_signal_connect (m_treeview
, "test-collapse-row",
3890 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
3892 g_signal_connect_after (m_treeview
, "row-collapsed",
3893 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
3895 g_signal_connect (m_treeview
, "test-expand-row",
3896 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
3898 g_signal_connect_after (m_treeview
, "row-expanded",
3899 G_CALLBACK (wxdataview_row_expanded_callback
), this);
3901 g_signal_connect (m_treeview
, "motion_notify_event",
3902 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
3904 g_signal_connect (m_treeview
, "button_press_event",
3905 G_CALLBACK (gtk_dataview_button_press_callback
), this);
3910 void wxDataViewCtrl::OnInternalIdle()
3912 wxWindow::OnInternalIdle();
3914 unsigned int cols
= GetColumnCount();
3916 for (i
= 0; i
< cols
; i
++)
3918 wxDataViewColumn
*col
= GetColumn( i
);
3919 col
->OnInternalIdle();
3923 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
3934 if (!wxDataViewCtrlBase::AssociateModel( model
))
3938 if (!gtk_check_version(2,6,0))
3940 bool fixed
= (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
) == 0) || (model
->IsVirtualListModel()));
3941 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
3945 GtkWxTreeModel
*gtk_model
= wxgtk_tree_model_new();
3946 m_internal
= new wxDataViewCtrlInternal( this, model
, gtk_model
);
3947 gtk_model
->internal
= m_internal
;
3949 m_notifier
= new wxGtkDataViewModelNotifier( gtk_model
, model
, this );
3951 model
->AddNotifier( m_notifier
);
3953 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_model
) );
3955 // unref in wxDataViewCtrlInternal
3956 // g_object_unref( gtk_model );
3961 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
3963 return m_internal
->EnableDragSource( format
);
3966 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
3968 return m_internal
->EnableDropTarget( format
);
3971 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
3973 if (!wxDataViewCtrlBase::AppendColumn(col
))
3976 m_cols
.Append( col
);
3979 if (!gtk_check_version(2,6,0))
3981 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
3982 GTK_TREE_VIEW_COLUMN_FIXED
)
3983 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
3987 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
3988 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
3993 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
3995 if (!wxDataViewCtrlBase::PrependColumn(col
))
3998 m_cols
.Insert( col
);
4001 if (!gtk_check_version(2,6,0))
4003 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4004 GTK_TREE_VIEW_COLUMN_FIXED
)
4005 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4009 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4010 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
4015 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4017 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4020 m_cols
.Insert( pos
, col
);
4023 if (!gtk_check_version(2,6,0))
4025 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4026 GTK_TREE_VIEW_COLUMN_FIXED
)
4027 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4031 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4032 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), pos
);
4037 unsigned int wxDataViewCtrl::GetColumnCount() const
4039 return m_cols
.GetCount();
4042 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
4044 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
4048 wxDataViewColumnList::const_iterator iter
;
4049 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4051 wxDataViewColumn
*col
= *iter
;
4052 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
4061 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4063 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4064 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
4066 m_cols
.DeleteObject( column
);
4071 bool wxDataViewCtrl::ClearColumns()
4073 wxDataViewColumnList::iterator iter
;
4074 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4076 wxDataViewColumn
*col
= *iter
;
4077 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4078 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4086 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4088 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetConstGtkHandle());
4090 GList
*list
= gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview
) );
4092 gint pos
= g_list_index( list
, (gconstpointer
) gtk_column
);
4094 g_list_free( list
);
4099 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4101 return m_internal
->GetDataViewSortColumn();
4104 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4107 iter
.user_data
= item
.GetID();
4108 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4109 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
4110 gtk_tree_path_free( path
);
4113 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4116 iter
.user_data
= item
.GetID();
4117 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4118 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
4119 gtk_tree_path_free( path
);
4122 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4125 iter
.user_data
= item
.GetID();
4126 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4127 bool res
= gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview
), path
);
4128 gtk_tree_path_free( path
);
4133 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4135 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4137 if (m_windowStyle
& wxDV_MULTIPLE
)
4139 // Report the first one
4140 GtkTreeModel
*model
;
4141 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4145 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4147 m_internal
->get_iter( &iter
, path
);
4150 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4151 g_list_free( list
);
4153 return wxDataViewItem( (void*) iter
.user_data
);
4159 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
4161 wxDataViewItem
item( (void*) iter
.user_data
);
4166 return wxDataViewItem(0);
4169 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4173 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4174 if (HasFlag(wxDV_MULTIPLE
))
4176 GtkTreeModel
*model
;
4177 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4182 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4185 m_internal
->get_iter( &iter
, path
);
4187 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4189 list
= g_list_next( list
);
4194 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4195 g_list_free( list
);
4201 GtkTreeModel
*model
;
4203 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
4206 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4214 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4216 GtkDisableSelectionEvents();
4218 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4220 gtk_tree_selection_unselect_all( selection
);
4222 wxDataViewItem last_parent
;
4225 for (i
= 0; i
< sel
.GetCount(); i
++)
4227 wxDataViewItem item
= sel
[i
];
4228 wxDataViewItem parent
= GetModel()->GetParent( item
);
4231 if (parent
!= last_parent
)
4232 ExpandAncestors(item
);
4234 last_parent
= parent
;
4237 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4238 iter
.user_data
= (gpointer
) item
.GetID();
4239 gtk_tree_selection_select_iter( selection
, &iter
);
4242 GtkEnableSelectionEvents();
4245 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4247 ExpandAncestors(item
);
4249 GtkDisableSelectionEvents();
4251 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4254 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4255 iter
.user_data
= (gpointer
) item
.GetID();
4256 gtk_tree_selection_select_iter( selection
, &iter
);
4258 GtkEnableSelectionEvents();
4261 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4263 GtkDisableSelectionEvents();
4265 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4268 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4269 iter
.user_data
= (gpointer
) item
.GetID();
4270 gtk_tree_selection_unselect_iter( selection
, &iter
);
4272 GtkEnableSelectionEvents();
4275 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4277 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4280 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4281 iter
.user_data
= (gpointer
) item
.GetID();
4283 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
4286 void wxDataViewCtrl::SelectAll()
4288 GtkDisableSelectionEvents();
4290 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4292 gtk_tree_selection_select_all( selection
);
4294 GtkEnableSelectionEvents();
4297 void wxDataViewCtrl::UnselectAll()
4299 GtkDisableSelectionEvents();
4301 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4303 gtk_tree_selection_unselect_all( selection
);
4305 GtkEnableSelectionEvents();
4308 void wxDataViewCtrl::EnsureVisible(const wxDataViewItem
& item
,
4309 const wxDataViewColumn
*WXUNUSED(column
))
4311 ExpandAncestors(item
);
4314 iter
.user_data
= (gpointer
) item
.GetID();
4315 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4316 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
4317 gtk_tree_path_free( path
);
4320 void wxDataViewCtrl::HitTest(const wxPoint
& WXUNUSED(point
),
4321 wxDataViewItem
& item
,
4322 wxDataViewColumn
*& column
) const
4324 item
= wxDataViewItem(0);
4329 wxDataViewCtrl::GetItemRect(const wxDataViewItem
& WXUNUSED(item
),
4330 const wxDataViewColumn
*WXUNUSED(column
)) const
4335 void wxDataViewCtrl::DoSetExpanderColumn()
4337 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
4338 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
4341 void wxDataViewCtrl::DoSetIndent()
4345 void wxDataViewCtrl::GtkDisableSelectionEvents()
4347 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4348 g_signal_handlers_disconnect_by_func( selection
,
4349 (gpointer
) (wxdataview_selection_changed_callback
), this);
4352 void wxDataViewCtrl::GtkEnableSelectionEvents()
4354 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4355 g_signal_connect_after (selection
, "changed",
4356 G_CALLBACK (wxdataview_selection_changed_callback
), this);
4361 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
4363 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
4368 // !wxUSE_GENERICDATAVIEWCTRL
4371 // wxUSE_DATAVIEWCTRL