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"
25 #include "wx/settings.h"
26 #include "wx/dataobj.h"
30 #include "wx/stockitem.h"
31 #include "wx/calctrl.h"
32 #include "wx/popupwin.h"
33 #include "wx/listimpl.cpp"
35 #include "wx/gtk/private.h"
36 #include "wx/gtk/dc.h"
37 #include "wx/gtk/dcclient.h"
39 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 class wxDataViewCtrlInternal
;
44 wxDataViewCtrlInternal
*g_internal
= NULL
;
46 class wxGtkTreeModelNode
;
49 typedef struct _GtkWxTreeModel GtkWxTreeModel
;
52 //-----------------------------------------------------------------------------
53 // wxDataViewCtrlInternal
54 //-----------------------------------------------------------------------------
56 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
57 WX_DEFINE_LIST(ItemList
)
59 class wxDataViewCtrlInternal
62 wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
);
63 ~wxDataViewCtrlInternal();
66 GtkTreeModelFlags
get_flags();
67 gboolean
get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
);
68 GtkTreePath
*get_path( GtkTreeIter
*iter
);
69 gboolean
iter_next( GtkTreeIter
*iter
);
70 gboolean
iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
);
71 gboolean
iter_has_child( GtkTreeIter
*iter
);
72 gint
iter_n_children( GtkTreeIter
*iter
);
73 gboolean
iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
);
74 gboolean
iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
);
77 gboolean
row_draggable( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
);
78 gboolean
drag_data_delete( GtkTreeDragSource
*drag_source
, GtkTreePath
* path
);
79 gboolean
drag_data_get( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
,
80 GtkSelectionData
*selection_data
);
81 gboolean
drag_data_received( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest
,
82 GtkSelectionData
*selection_data
);
83 gboolean
row_drop_possible( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest_path
,
84 GtkSelectionData
*selection_data
);
86 // notifactions from wxDataViewModel
87 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
88 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
89 bool ItemChanged( const wxDataViewItem
&item
);
90 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
95 void SetSortOrder( GtkSortType sort_order
) { m_sort_order
= sort_order
; }
96 GtkSortType
GetSortOrder() { return m_sort_order
; }
98 void SetSortColumn( int column
) { m_sort_column
= column
; }
99 int GetSortColumn() { return m_sort_column
; }
101 void SetDataViewSortColumn( wxDataViewColumn
*column
) { m_dataview_sort_column
= column
; }
102 wxDataViewColumn
*GetDataViewSortColumn() { return m_dataview_sort_column
; }
104 bool IsSorted() { return (m_sort_column
>= 0); }
107 wxDataViewModel
* GetDataViewModel() { return m_wx_model
; }
108 wxDataViewCtrl
* GetOwner() { return m_owner
; }
109 GtkWxTreeModel
* GetGtkModel() { return m_gtk_model
; }
113 wxGtkTreeModelNode
*FindNode( const wxDataViewItem
&item
);
114 wxGtkTreeModelNode
*FindNode( GtkTreeIter
*iter
);
115 wxGtkTreeModelNode
*FindParentNode( const wxDataViewItem
&item
);
116 wxGtkTreeModelNode
*FindParentNode( GtkTreeIter
*iter
);
117 void BuildBranch( wxGtkTreeModelNode
*branch
);
120 wxGtkTreeModelNode
*m_root
;
121 wxDataViewModel
*m_wx_model
;
122 GtkWxTreeModel
*m_gtk_model
;
123 wxDataViewCtrl
*m_owner
;
124 GtkSortType m_sort_order
;
125 wxDataViewColumn
*m_dataview_sort_column
;
130 //-----------------------------------------------------------------------------
131 // wxGtkTreeModelNode
132 //-----------------------------------------------------------------------------
134 int LINKAGEMODE
wxGtkTreeModelChildCmp( void** id1
, void** id2
)
136 int ret
= g_internal
->GetDataViewModel()->Compare( *id1
, *id2
,
137 g_internal
->GetSortColumn(), (g_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
142 WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode
*, wxGtkTreeModelNodes
);
143 WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren
);
145 class wxGtkTreeModelNode
148 wxGtkTreeModelNode( wxGtkTreeModelNode
* parent
, const wxDataViewItem
&item
,
149 wxDataViewCtrlInternal
*internal
)
153 m_internal
= internal
;
156 ~wxGtkTreeModelNode()
158 size_t count
= m_children
.GetCount();
160 for (i
= 0; i
< count
; i
++)
162 wxGtkTreeModelNode
*child
= m_nodes
.Item( i
);
167 unsigned int AddNode( wxGtkTreeModelNode
* child
)
169 m_nodes
.Add( child
);
171 void *id
= child
->GetItem().GetID();
173 m_children
.Add( id
);
175 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
177 g_internal
= m_internal
;
178 m_children
.Sort( &wxGtkTreeModelChildCmp
);
179 return m_children
.Index( id
);
182 return m_children
.GetCount()-1;
185 unsigned int AddLeave( void* id
)
187 m_children
.Add( id
);
189 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
191 g_internal
= m_internal
;
192 m_children
.Sort( &wxGtkTreeModelChildCmp
);
193 return m_children
.Index( id
);
196 return m_children
.GetCount()-1;
199 void DeleteChild( void* id
)
201 m_children
.Remove( id
);
203 unsigned int count
= m_nodes
.GetCount();
205 for (pos
= 0; pos
< count
; pos
++)
207 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
208 if (node
->GetItem().GetID() == id
)
210 m_nodes
.RemoveAt( pos
);
218 wxGtkTreeModelNode
* GetParent()
220 wxGtkTreeModelNodes
&GetNodes()
222 wxGtkTreeModelChildren
&GetChildren()
223 { return m_children
; }
225 unsigned int GetChildCount() { return m_children
.GetCount(); }
226 unsigned int GetNodesCount() { return m_nodes
.GetCount(); }
228 wxDataViewItem
&GetItem() { return m_item
; }
229 wxDataViewCtrlInternal
*GetInternal() { return m_internal
; }
234 wxGtkTreeModelNode
*m_parent
;
235 wxGtkTreeModelNodes m_nodes
;
236 wxGtkTreeModelChildren m_children
;
237 wxDataViewItem m_item
;
238 wxDataViewCtrlInternal
*m_internal
;
242 //-----------------------------------------------------------------------------
244 //-----------------------------------------------------------------------------
246 extern bool g_blockEventsOnDrag
;
248 //-----------------------------------------------------------------------------
249 // define new GTK+ class wxGtkTreeModel
250 //-----------------------------------------------------------------------------
254 #define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ())
255 #define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel))
256 #define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
257 #define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL))
258 #define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL))
259 #define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
261 GType
gtk_wx_tree_model_get_type (void);
263 typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass
;
265 struct _GtkWxTreeModel
271 wxDataViewCtrlInternal
*internal
;
274 struct _GtkWxTreeModelClass
276 GObjectClass list_parent_class
;
279 static GtkWxTreeModel
*wxgtk_tree_model_new (void);
280 static void wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
);
281 static void wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
);
283 static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
);
284 static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
);
285 static void wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
);
286 static void wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
);
288 static void wxgtk_tree_model_finalize (GObject
*object
);
289 static GtkTreeModelFlags
wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
);
290 static gint
wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
);
291 static GType
wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
293 static gboolean
wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
296 static GtkTreePath
*wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
298 static void wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
302 static gboolean
wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
304 static gboolean
wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
306 GtkTreeIter
*parent
);
307 static gboolean
wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
309 static gint
wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
311 static gboolean
wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
315 static gboolean
wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
320 static gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
321 gint
*sort_column_id
,
323 static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
326 static void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
328 GtkTreeIterCompareFunc func
,
330 GtkDestroyNotify destroy
);
331 static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
332 GtkTreeIterCompareFunc func
,
334 GtkDestroyNotify destroy
);
335 static gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
);
338 static gboolean
wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
340 static gboolean
wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
342 static gboolean
wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
344 GtkSelectionData
*selection_data
);
345 static gboolean
wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
347 GtkSelectionData
*selection_data
);
348 static gboolean
wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
349 GtkTreePath
*dest_path
,
350 GtkSelectionData
*selection_data
);
353 static GObjectClass
*list_parent_class
= NULL
;
356 gtk_wx_tree_model_get_type (void)
358 static GType tree_model_type
= 0;
360 if (!tree_model_type
)
362 const GTypeInfo tree_model_info
=
364 sizeof (GtkWxTreeModelClass
),
365 NULL
, /* base_init */
366 NULL
, /* base_finalize */
367 (GClassInitFunc
) wxgtk_tree_model_class_init
,
368 NULL
, /* class_finalize */
369 NULL
, /* class_data */
370 sizeof (GtkWxTreeModel
),
372 (GInstanceInitFunc
) wxgtk_tree_model_init
,
375 static const GInterfaceInfo tree_model_iface_info
=
377 (GInterfaceInitFunc
) wxgtk_tree_model_tree_model_init
,
382 static const GInterfaceInfo sortable_iface_info
=
384 (GInterfaceInitFunc
) wxgtk_tree_model_sortable_init
,
389 static const GInterfaceInfo drag_source_iface_info
=
391 (GInterfaceInitFunc
) wxgtk_tree_model_drag_source_init
,
396 static const GInterfaceInfo drag_dest_iface_info
=
398 (GInterfaceInitFunc
) wxgtk_tree_model_drag_dest_init
,
403 tree_model_type
= g_type_register_static (G_TYPE_OBJECT
, "GtkWxTreeModel",
404 &tree_model_info
, (GTypeFlags
)0 );
406 g_type_add_interface_static (tree_model_type
,
408 &tree_model_iface_info
);
409 g_type_add_interface_static (tree_model_type
,
410 GTK_TYPE_TREE_SORTABLE
,
411 &sortable_iface_info
);
412 g_type_add_interface_static (tree_model_type
,
413 GTK_TYPE_TREE_DRAG_DEST
,
414 &drag_dest_iface_info
);
415 g_type_add_interface_static (tree_model_type
,
416 GTK_TYPE_TREE_DRAG_SOURCE
,
417 &drag_source_iface_info
);
420 return tree_model_type
;
423 static GtkWxTreeModel
*
424 wxgtk_tree_model_new(void)
426 GtkWxTreeModel
*retval
= (GtkWxTreeModel
*) g_object_new (GTK_TYPE_WX_TREE_MODEL
, NULL
);
431 wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
)
433 list_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
434 GObjectClass
*object_class
= (GObjectClass
*) klass
;
435 object_class
->finalize
= wxgtk_tree_model_finalize
;
439 wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
)
441 iface
->get_flags
= wxgtk_tree_model_get_flags
;
442 iface
->get_n_columns
= wxgtk_tree_model_get_n_columns
;
443 iface
->get_column_type
= wxgtk_tree_model_get_column_type
;
444 iface
->get_iter
= wxgtk_tree_model_get_iter
;
445 iface
->get_path
= wxgtk_tree_model_get_path
;
446 iface
->get_value
= wxgtk_tree_model_get_value
;
447 iface
->iter_next
= wxgtk_tree_model_iter_next
;
448 iface
->iter_children
= wxgtk_tree_model_iter_children
;
449 iface
->iter_has_child
= wxgtk_tree_model_iter_has_child
;
450 iface
->iter_n_children
= wxgtk_tree_model_iter_n_children
;
451 iface
->iter_nth_child
= wxgtk_tree_model_iter_nth_child
;
452 iface
->iter_parent
= wxgtk_tree_model_iter_parent
;
456 wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
)
458 iface
->get_sort_column_id
= wxgtk_tree_model_get_sort_column_id
;
459 iface
->set_sort_column_id
= wxgtk_tree_model_set_sort_column_id
;
460 iface
->set_sort_func
= wxgtk_tree_model_set_sort_func
;
461 iface
->set_default_sort_func
= wxgtk_tree_model_set_default_sort_func
;
462 iface
->has_default_sort_func
= wxgtk_tree_model_has_default_sort_func
;
466 wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
)
468 iface
->row_draggable
= wxgtk_tree_model_row_draggable
;
469 iface
->drag_data_delete
= wxgtk_tree_model_drag_data_delete
;
470 iface
->drag_data_get
= wxgtk_tree_model_drag_data_get
;
474 wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
)
476 iface
->drag_data_received
= wxgtk_tree_model_drag_data_received
;
477 iface
->row_drop_possible
= wxgtk_tree_model_row_drop_possible
;
481 wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
)
483 tree_model
->internal
= NULL
;
484 tree_model
->stamp
= g_random_int();
488 wxgtk_tree_model_finalize (GObject
*object
)
491 (* list_parent_class
->finalize
) (object
);
496 //-----------------------------------------------------------------------------
497 // implement callbacks from wxGtkTreeModel class by letting
498 // them call the methods of wxWidgets' wxDataViewModel
499 //-----------------------------------------------------------------------------
501 static GtkTreeModelFlags
502 wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
)
504 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
505 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), (GtkTreeModelFlags
)0 );
507 return wxtree_model
->internal
->get_flags();
511 wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
)
513 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
514 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
516 return wxtree_model
->internal
->GetDataViewModel()->GetColumnCount();
520 wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
523 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
524 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), G_TYPE_INVALID
);
526 GType gtype
= G_TYPE_INVALID
;
528 wxString wxtype
= wxtree_model
->internal
->GetDataViewModel()->GetColumnType( (unsigned int) index
);
530 if (wxtype
== wxT("string"))
531 gtype
= G_TYPE_STRING
;
534 gtype
= G_TYPE_STRING
;
535 // wxFAIL_MSG( _T("non-string columns not supported yet") );
542 wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
546 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
547 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
548 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
550 return wxtree_model
->internal
->get_iter( iter
, path
);
554 wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
557 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
558 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), NULL
);
559 g_return_val_if_fail (iter
->stamp
== GTK_WX_TREE_MODEL (wxtree_model
)->stamp
, NULL
);
561 return wxtree_model
->internal
->get_path( iter
);
565 wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
570 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
571 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
) );
573 wxDataViewModel
*model
= wxtree_model
->internal
->GetDataViewModel();
574 wxString mtype
= model
->GetColumnType( (unsigned int) column
);
575 if (mtype
== wxT("string"))
578 g_value_init( value
, G_TYPE_STRING
);
579 wxDataViewItem
item( (void*) iter
->user_data
);
580 model
->GetValue( variant
, item
, (unsigned int) column
);
582 g_value_set_string( value
, variant
.GetString().utf8_str() );
586 wxFAIL_MSG( _T("non-string columns not supported yet") );
591 wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
594 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
596 if (wxtree_model
->stamp
!= iter
->stamp
)
597 wxPrintf( "crash\n" );
599 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
600 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
602 return wxtree_model
->internal
->iter_next( iter
);
606 wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
610 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
611 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
612 g_return_val_if_fail (wxtree_model
->stamp
== parent
->stamp
, FALSE
);
614 return wxtree_model
->internal
->iter_children( iter
, parent
);
618 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
621 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
622 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
623 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
625 return wxtree_model
->internal
->iter_has_child( iter
);
629 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
632 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
633 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
634 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, 0);
636 return wxtree_model
->internal
->iter_n_children( iter
);
640 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
645 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
646 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
648 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
652 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
656 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
657 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
658 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
660 return wxtree_model
->internal
->iter_parent( iter
, child
);
663 /* drag'n'drop iface */
665 wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
668 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
669 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
671 return wxtree_model
->internal
->row_draggable( drag_source
, path
);
675 wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
678 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
679 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
681 return wxtree_model
->internal
->drag_data_delete( drag_source
, path
);
685 wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
687 GtkSelectionData
*selection_data
)
689 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
690 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
693 wxPrintf( "drag_get_data\n");
695 wxGtkString
atom_selection(gdk_atom_name(selection_data
->selection
));
696 wxPrintf( "selection %s\n", wxString::FromAscii(atom_selection
) );
698 wxGtkString
atom_target(gdk_atom_name(selection_data
->target
));
699 wxPrintf( "target %s\n", wxString::FromAscii(atom_target
) );
701 wxGtkString
atom_type(gdk_atom_name(selection_data
->type
));
702 wxPrintf( "type %s\n", wxString::FromAscii(atom_type
) );
704 wxPrintf( "format %d\n", selection_data
->format
);
707 return wxtree_model
->internal
->drag_data_get( drag_source
, path
, selection_data
);
711 wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
713 GtkSelectionData
*selection_data
)
715 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
716 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
718 return wxtree_model
->internal
->drag_data_received( drag_dest
, dest
, selection_data
);
722 wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
723 GtkTreePath
*dest_path
,
724 GtkSelectionData
*selection_data
)
726 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
727 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
729 return wxtree_model
->internal
->row_drop_possible( drag_dest
, dest_path
, selection_data
);
734 wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
735 gint
*sort_column_id
,
738 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) sortable
;
740 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
742 if (!wxtree_model
->internal
->IsSorted())
745 *sort_column_id
= -1;
752 *sort_column_id
= wxtree_model
->internal
->GetSortColumn();
755 *order
= wxtree_model
->internal
->GetSortOrder();
760 wxDataViewColumn
*gs_lastLeftClickHeader
= NULL
;
763 wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
767 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
768 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
770 tree_model
->internal
->SetDataViewSortColumn( gs_lastLeftClickHeader
);
772 if ((sort_column_id
!= (gint
) tree_model
->internal
->GetSortColumn()) ||
773 (order
!= tree_model
->internal
->GetSortOrder()))
775 tree_model
->internal
->SetSortColumn( sort_column_id
);
776 tree_model
->internal
->SetSortOrder( order
);
778 gtk_tree_sortable_sort_column_changed (sortable
);
780 tree_model
->internal
->GetDataViewModel()->Resort();
783 if (gs_lastLeftClickHeader
)
785 wxDataViewCtrl
*dv
= tree_model
->internal
->GetOwner();
786 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, dv
->GetId() );
787 event
.SetDataViewColumn( gs_lastLeftClickHeader
);
788 event
.SetModel( dv
->GetModel() );
789 dv
->HandleWindowEvent( event
);
792 gs_lastLeftClickHeader
= NULL
;
796 wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
797 gint
WXUNUSED(sort_column_id
),
798 GtkTreeIterCompareFunc func
,
799 gpointer
WXUNUSED(data
),
800 GtkDestroyNotify
WXUNUSED(destroy
) )
802 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
803 g_return_if_fail (func
!= NULL
);
806 void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
807 GtkTreeIterCompareFunc func
,
808 gpointer
WXUNUSED(data
),
809 GtkDestroyNotify
WXUNUSED(destroy
) )
811 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
812 g_return_if_fail (func
!= NULL
);
814 wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
817 gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
)
819 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
824 //-----------------------------------------------------------------------------
825 // define new GTK+ class wxGtkRendererRenderer
826 //-----------------------------------------------------------------------------
830 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
831 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
832 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
833 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
834 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
835 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
837 GType
gtk_wx_cell_renderer_get_type (void);
839 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
840 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
842 struct _GtkWxCellRenderer
844 GtkCellRenderer parent
;
847 wxDataViewCustomRenderer
*cell
;
851 struct _GtkWxCellRendererClass
853 GtkCellRendererClass cell_parent_class
;
857 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
858 static void gtk_wx_cell_renderer_init (
859 GtkWxCellRenderer
*cell
);
860 static void gtk_wx_cell_renderer_class_init(
861 GtkWxCellRendererClass
*klass
);
862 static void gtk_wx_cell_renderer_finalize (
864 static void gtk_wx_cell_renderer_get_size (
865 GtkCellRenderer
*cell
,
867 GdkRectangle
*rectangle
,
872 static void gtk_wx_cell_renderer_render (
873 GtkCellRenderer
*cell
,
876 GdkRectangle
*background_area
,
877 GdkRectangle
*cell_area
,
878 GdkRectangle
*expose_area
,
879 GtkCellRendererState flags
);
880 static gboolean
gtk_wx_cell_renderer_activate(
881 GtkCellRenderer
*cell
,
885 GdkRectangle
*background_area
,
886 GdkRectangle
*cell_area
,
887 GtkCellRendererState flags
);
888 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
889 GtkCellRenderer
*cell
,
893 GdkRectangle
*background_area
,
894 GdkRectangle
*cell_area
,
895 GtkCellRendererState flags
);
898 static GObjectClass
*cell_parent_class
= NULL
;
903 gtk_wx_cell_renderer_get_type (void)
905 static GType cell_wx_type
= 0;
909 const GTypeInfo cell_wx_info
=
911 sizeof (GtkWxCellRendererClass
),
912 NULL
, /* base_init */
913 NULL
, /* base_finalize */
914 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
915 NULL
, /* class_finalize */
916 NULL
, /* class_data */
917 sizeof (GtkWxCellRenderer
),
919 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
922 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
923 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
930 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
933 cell
->last_click
= 0;
937 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
939 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
940 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
942 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
944 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
946 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
947 cell_class
->render
= gtk_wx_cell_renderer_render
;
948 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
949 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
953 gtk_wx_cell_renderer_finalize (GObject
*object
)
956 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
960 gtk_wx_cell_renderer_new (void)
962 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
967 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
968 GtkCellRenderer
*renderer
,
969 GdkEvent
*WXUNUSED(event
),
972 GdkRectangle
*WXUNUSED(background_area
),
973 GdkRectangle
*cell_area
,
974 GtkCellRendererState
WXUNUSED(flags
) )
976 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
977 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
978 if (!cell
->HasEditorCtrl())
982 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
988 rect
.x
+= cell_area
->x
;
989 rect
.y
+= cell_area
->y
;
990 // rect.width -= renderer->xpad * 2;
991 // rect.height -= renderer->ypad * 2;
993 // wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
994 wxRect
renderrect( cell_area
->x
, cell_area
->y
, cell_area
->width
, cell_area
->height
);
996 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
998 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
999 wxDataViewItem
item( (void*) iter
.user_data
);
1000 gtk_tree_path_free( treepath
);
1002 cell
->StartEditing( item
, renderrect
);
1008 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
1009 GtkWidget
*WXUNUSED(widget
),
1010 GdkRectangle
*cell_area
,
1016 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1017 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1019 wxSize size
= cell
->GetSize();
1021 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
1022 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
1029 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
1033 *x_offset
= (gint
)((renderer
->xalign
*
1034 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
1035 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
1039 *y_offset
= (gint
)((renderer
->yalign
*
1040 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
1041 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
1046 *width
= calc_width
;
1049 *height
= calc_height
;
1053 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
1056 GdkRectangle
*background_area
,
1057 GdkRectangle
*cell_area
,
1058 GdkRectangle
*expose_area
,
1059 GtkCellRendererState flags
)
1062 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1063 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1065 cell
->window
= window
;
1066 cell
->widget
= widget
;
1067 cell
->background_area
= (void*) background_area
;
1068 cell
->cell_area
= (void*) cell_area
;
1069 cell
->expose_area
= (void*) expose_area
;
1070 cell
->flags
= (int) flags
;
1073 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1079 rect
.x
+= cell_area
->x
;
1080 rect
.y
+= cell_area
->y
;
1081 rect
.width
-= renderer
->xpad
* 2;
1082 rect
.height
-= renderer
->ypad
* 2;
1085 if (gdk_rectangle_intersect (expose_area
, &rect
, &dummy
))
1087 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1088 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
1089 wxWindowDCImpl
*impl
= (wxWindowDCImpl
*) dc
->GetImpl();
1090 if (impl
->m_gdkwindow
== NULL
)
1092 impl
->m_gdkwindow
= window
;
1097 if (flags
& GTK_CELL_RENDERER_SELECTED
)
1098 state
|= wxDATAVIEW_CELL_SELECTED
;
1099 if (flags
& GTK_CELL_RENDERER_PRELIT
)
1100 state
|= wxDATAVIEW_CELL_PRELIT
;
1101 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1102 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1103 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1104 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1105 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
1106 state
|= wxDATAVIEW_CELL_FOCUSED
;
1107 cell
->Render( renderrect
, dc
, state
);
1112 gtk_wx_cell_renderer_activate(
1113 GtkCellRenderer
*renderer
,
1117 GdkRectangle
*WXUNUSED(background_area
),
1118 GdkRectangle
*cell_area
,
1119 GtkCellRendererState
WXUNUSED(flags
) )
1121 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1122 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1125 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1131 rect
.x
+= cell_area
->x
;
1132 rect
.y
+= cell_area
->y
;
1133 rect
.width
-= renderer
->xpad
* 2;
1134 rect
.height
-= renderer
->ypad
* 2;
1136 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1138 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1140 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
1143 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
1144 wxDataViewItem
item( iter
.user_data
);
1145 gtk_tree_path_free( treepath
);
1147 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1153 // activated by <ENTER>
1154 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1159 else if (event
->type
== GDK_BUTTON_PRESS
)
1161 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
1162 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
1163 ((int) button_event
->y
) - renderrect
.y
);
1166 if (button_event
->button
== 1)
1168 if (cell
->LeftClick( pt
, renderrect
, model
, item
, model_col
))
1170 // TODO: query system double-click time
1171 if (button_event
->time
- wxrenderer
->last_click
< 400)
1172 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1175 wxrenderer
->last_click
= button_event
->time
;
1183 // ---------------------------------------------------------
1184 // wxGtkDataViewModelNotifier
1185 // ---------------------------------------------------------
1187 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1190 wxGtkDataViewModelNotifier( GtkWxTreeModel
*wxgtk_model
,
1191 wxDataViewModel
*wx_model
,
1192 wxDataViewCtrl
*ctrl
);
1193 ~wxGtkDataViewModelNotifier();
1195 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1196 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1197 virtual bool ItemChanged( const wxDataViewItem
&item
);
1198 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
1199 virtual bool Cleared();
1200 virtual void Resort();
1202 void SetGtkModel( GtkWxTreeModel
*model
) { m_wxgtk_model
= model
; }
1205 GtkWxTreeModel
*m_wxgtk_model
;
1206 wxDataViewModel
*m_wx_model
;
1207 wxDataViewCtrl
*m_owner
;
1210 // ---------------------------------------------------------
1211 // wxGtkDataViewListModelNotifier
1212 // ---------------------------------------------------------
1214 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1215 GtkWxTreeModel
* wxgtk_model
, wxDataViewModel
*wx_model
,
1216 wxDataViewCtrl
*ctrl
)
1218 m_wxgtk_model
= wxgtk_model
;
1219 m_wx_model
= wx_model
;
1223 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1226 m_wxgtk_model
= NULL
;
1229 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1231 m_owner
->GtkGetInternal()->ItemAdded( parent
, item
);
1234 iter
.stamp
= m_wxgtk_model
->stamp
;
1235 iter
.user_data
= (gpointer
) item
.GetID();
1237 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1238 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1239 gtk_tree_model_row_inserted(
1240 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1241 gtk_tree_path_free (path
);
1246 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1249 iter
.stamp
= m_wxgtk_model
->stamp
;
1250 iter
.user_data
= (gpointer
) item
.GetID();
1252 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1253 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1254 gtk_tree_model_row_deleted(
1255 GTK_TREE_MODEL(m_wxgtk_model
), path
);
1256 gtk_tree_path_free (path
);
1258 m_owner
->GtkGetInternal()->ItemDeleted( parent
, item
);
1263 void wxGtkDataViewModelNotifier::Resort()
1265 m_owner
->GtkGetInternal()->Resort();
1268 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1271 iter
.stamp
= m_wxgtk_model
->stamp
;
1272 iter
.user_data
= (gpointer
) item
.GetID();
1274 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1275 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1276 gtk_tree_model_row_changed(
1277 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1278 gtk_tree_path_free (path
);
1280 m_owner
->GtkGetInternal()->ItemChanged( item
);
1285 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_col
)
1287 // This adds GTK+'s missing MVC logic for ValueChanged
1289 for (index
= 0; index
< m_owner
->GetColumnCount(); index
++)
1291 wxDataViewColumn
*column
= m_owner
->GetColumn( index
);
1292 if (column
->GetModelColumn() == model_col
)
1294 GtkTreeView
*widget
= GTK_TREE_VIEW(m_owner
->m_treeview
);
1295 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1299 iter
.stamp
= m_wxgtk_model
->stamp
;
1300 iter
.user_data
= (gpointer
) item
.GetID();
1301 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1302 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1303 GdkRectangle cell_area
;
1304 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1305 gtk_tree_path_free( path
);
1307 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1308 double d
= gtk_adjustment_get_value( hadjust
);
1309 int xdiff
= (int) d
;
1311 int ydiff
= gcolumn
->button
->allocation
.height
;
1313 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1314 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1316 m_owner
->GtkGetInternal()->ValueChanged( item
, model_col
);
1325 bool wxGtkDataViewModelNotifier::Cleared()
1327 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->m_treeview
), NULL
);
1329 // this will create a new GTK model
1330 m_owner
->GtkGetInternal()->Cleared();
1332 SetGtkModel( m_owner
->GtkGetInternal()->GetGtkModel() );
1334 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->m_treeview
), GTK_TREE_MODEL(m_wxgtk_model
) );
1339 // ---------------------------------------------------------
1340 // wxDataViewRenderer
1341 // ---------------------------------------------------------
1343 static gpointer s_user_data
= NULL
;
1346 wxgtk_cell_editable_editing_done( GtkCellEditable
*WXUNUSED(editable
),
1347 wxDataViewRenderer
*wxrenderer
)
1349 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1350 wxDataViewCtrl
*dv
= column
->GetOwner();
1351 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1352 event
.SetDataViewColumn( column
);
1353 event
.SetModel( dv
->GetModel() );
1354 wxDataViewItem
item( s_user_data
);
1355 event
.SetItem( item
);
1356 dv
->HandleWindowEvent( event
);
1360 wxgtk_renderer_editing_started( GtkCellRenderer
*WXUNUSED(cell
), GtkCellEditable
*editable
,
1361 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1363 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1364 wxDataViewCtrl
*dv
= column
->GetOwner();
1365 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1366 event
.SetDataViewColumn( column
);
1367 event
.SetModel( dv
->GetModel() );
1368 GtkTreePath
*tree_path
= gtk_tree_path_new_from_string( path
);
1370 dv
->GtkGetInternal()->get_iter( &iter
, tree_path
);
1371 gtk_tree_path_free( tree_path
);
1372 wxDataViewItem
item( iter
.user_data
);
1373 event
.SetItem( item
);
1374 dv
->HandleWindowEvent( event
);
1376 if (GTK_IS_CELL_EDITABLE(editable
))
1378 s_user_data
= iter
.user_data
;
1380 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1381 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1382 (gpointer
) wxrenderer
);
1388 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1390 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1392 wxDataViewRendererBase( varianttype
, mode
, align
)
1396 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1397 // after the m_renderer pointer has been initialized
1400 void wxDataViewRenderer::GtkInitHandlers()
1402 if (!gtk_check_version(2,6,0))
1404 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1405 G_CALLBACK (wxgtk_renderer_editing_started
),
1410 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1412 GtkCellRendererMode gtkMode
;
1415 case wxDATAVIEW_CELL_INERT
:
1416 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1419 case wxDATAVIEW_CELL_ACTIVATABLE
:
1420 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1423 case wxDATAVIEW_CELL_EDITABLE
:
1424 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1428 wxFAIL_MSG( "unknown wxDataViewCellMode value" );
1432 // This value is most often ignored in GtkTreeView
1433 GValue gvalue
= { 0, };
1434 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1435 g_value_set_enum( &gvalue
, gtkMode
);
1436 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1437 g_value_unset( &gvalue
);
1440 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1442 wxDataViewCellMode ret
;
1445 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1447 switch (g_value_get_enum(&gvalue
))
1450 wxFAIL_MSG( "unknown GtkCellRendererMode value" );
1451 // fall through (we have to return something)
1453 case GTK_CELL_RENDERER_MODE_INERT
:
1454 ret
= wxDATAVIEW_CELL_INERT
;
1457 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1458 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1461 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1462 ret
= wxDATAVIEW_CELL_EDITABLE
;
1466 g_value_unset( &gvalue
);
1471 void wxDataViewRenderer::SetAlignment( int align
)
1473 // horizontal alignment:
1475 gfloat xalign
= 0.0;
1476 if (align
& wxALIGN_RIGHT
)
1478 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1481 GValue gvalue
= { 0, };
1482 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1483 g_value_set_float( &gvalue
, xalign
);
1484 g_object_set_property( G_OBJECT(m_renderer
), "xalign", &gvalue
);
1485 g_value_unset( &gvalue
);
1487 // vertical alignment:
1489 gfloat yalign
= 0.0;
1490 if (align
& wxALIGN_BOTTOM
)
1492 else if (align
& wxALIGN_CENTER_VERTICAL
)
1495 GValue gvalue2
= { 0, };
1496 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1497 g_value_set_float( &gvalue2
, yalign
);
1498 g_object_set_property( G_OBJECT(m_renderer
), "yalign", &gvalue2
);
1499 g_value_unset( &gvalue2
);
1502 int wxDataViewRenderer::GetAlignment() const
1507 // horizontal alignment:
1509 g_object_get( G_OBJECT(m_renderer
), "xalign", &gvalue
, NULL
);
1510 float xalign
= g_value_get_float( &gvalue
);
1512 ret
|= wxALIGN_LEFT
;
1513 else if (xalign
== 0.5)
1514 ret
|= wxALIGN_CENTER_HORIZONTAL
;
1516 ret
|= wxALIGN_RIGHT
;
1517 g_value_unset( &gvalue
);
1520 // vertical alignment:
1522 g_object_get( G_OBJECT(m_renderer
), "yalign", &gvalue
, NULL
);
1523 float yalign
= g_value_get_float( &gvalue
);
1526 else if (yalign
== 0.5)
1527 ret
|= wxALIGN_CENTER_VERTICAL
;
1529 ret
|= wxALIGN_BOTTOM
;
1530 g_value_unset( &gvalue
);
1537 // ---------------------------------------------------------
1538 // wxDataViewTextRenderer
1539 // ---------------------------------------------------------
1542 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1543 gchar
*arg1
, gchar
*arg2
, gpointer user_data
);
1546 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*WXUNUSED(renderer
),
1547 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1549 wxDataViewTextRenderer
*cell
= (wxDataViewTextRenderer
*) user_data
;
1551 wxString tmp
= wxGTK_CONV_BACK_FONT(arg2
, cell
->GetOwner()->GetOwner()->GetFont());
1552 wxVariant value
= tmp
;
1553 if (!cell
->Validate( value
))
1556 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1558 GtkTreePath
*path
= gtk_tree_path_new_from_string( arg1
);
1560 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, path
);
1561 wxDataViewItem
item( (void*) iter
.user_data
);;
1562 gtk_tree_path_free( path
);
1564 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1566 model
->SetValue( value
, item
, model_col
);
1567 model
->ValueChanged( item
, model_col
);
1570 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
1572 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1574 wxDataViewRenderer( varianttype
, mode
, align
)
1576 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_text_new();
1578 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
1580 GValue gvalue
= { 0, };
1581 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1582 g_value_set_boolean( &gvalue
, true );
1583 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
1584 g_value_unset( &gvalue
);
1586 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
1592 SetAlignment(align
);
1595 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
1597 wxString tmp
= value
;
1599 GValue gvalue
= { 0, };
1600 g_value_init( &gvalue
, G_TYPE_STRING
);
1601 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( tmp
, GetOwner()->GetOwner()->GetFont() ) );
1602 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1603 g_value_unset( &gvalue
);
1608 bool wxDataViewTextRenderer::GetValue( wxVariant
&value
) const
1610 GValue gvalue
= { 0, };
1611 g_value_init( &gvalue
, G_TYPE_STRING
);
1612 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1613 wxString tmp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
), wx_const_cast(wxDataViewTextRenderer
*, this)->GetOwner()->GetOwner()->GetFont() );
1614 g_value_unset( &gvalue
);
1621 void wxDataViewTextRenderer::SetAlignment( int align
)
1623 wxDataViewRenderer::SetAlignment(align
);
1625 if (gtk_check_version(2,10,0))
1628 // horizontal alignment:
1629 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
1630 if (align
& wxALIGN_RIGHT
)
1631 pangoAlign
= PANGO_ALIGN_RIGHT
;
1632 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1633 pangoAlign
= PANGO_ALIGN_CENTER
;
1635 GValue gvalue
= { 0, };
1636 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1637 g_value_set_enum( &gvalue
, pangoAlign
);
1638 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
1639 g_value_unset( &gvalue
);
1642 // ---------------------------------------------------------
1643 // wxDataViewTextRendererAttr
1644 // ---------------------------------------------------------
1646 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
,wxDataViewTextRenderer
)
1648 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString
&varianttype
,
1649 wxDataViewCellMode mode
, int align
) :
1650 wxDataViewTextRenderer( varianttype
, mode
, align
)
1654 // ---------------------------------------------------------
1655 // wxDataViewBitmapRenderer
1656 // ---------------------------------------------------------
1658 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
1660 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1662 wxDataViewRenderer( varianttype
, mode
, align
)
1664 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_pixbuf_new();
1667 SetAlignment(align
);
1670 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
1672 if (value
.GetType() == wxT("wxBitmap"))
1677 // This may create a Pixbuf representation in the
1678 // wxBitmap object (and it will stay there)
1679 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1681 GValue gvalue
= { 0, };
1682 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1683 g_value_set_object( &gvalue
, pixbuf
);
1684 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1685 g_value_unset( &gvalue
);
1690 if (value
.GetType() == wxT("wxIcon"))
1695 // This may create a Pixbuf representation in the
1696 // wxBitmap object (and it will stay there)
1697 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1699 GValue gvalue
= { 0, };
1700 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1701 g_value_set_object( &gvalue
, pixbuf
);
1702 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1703 g_value_unset( &gvalue
);
1711 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
1716 // ---------------------------------------------------------
1717 // wxDataViewToggleRenderer
1718 // ---------------------------------------------------------
1721 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1722 gchar
*path
, gpointer user_data
);
1725 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1726 gchar
*path
, gpointer user_data
)
1728 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
1731 GValue gvalue
= { 0, };
1732 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1733 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
1734 bool tmp
= g_value_get_boolean( &gvalue
);
1735 g_value_unset( &gvalue
);
1739 wxVariant value
= tmp
;
1740 if (!cell
->Validate( value
))
1743 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1745 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
1747 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, gtk_path
);
1748 wxDataViewItem
item( (void*) iter
.user_data
);;
1749 gtk_tree_path_free( gtk_path
);
1751 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1753 model
->SetValue( value
, item
, model_col
);
1754 model
->ValueChanged( item
, model_col
);
1757 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1759 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1760 wxDataViewCellMode mode
, int align
) :
1761 wxDataViewRenderer( varianttype
, mode
, align
)
1763 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
1765 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1767 g_signal_connect_after( m_renderer
, "toggled",
1768 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
1772 GValue gvalue
= { 0, };
1773 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1774 g_value_set_boolean( &gvalue
, false );
1775 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
1776 g_value_unset( &gvalue
);
1780 SetAlignment(align
);
1783 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1787 GValue gvalue
= { 0, };
1788 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1789 g_value_set_boolean( &gvalue
, tmp
);
1790 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1791 g_value_unset( &gvalue
);
1796 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
1798 GValue gvalue
= { 0, };
1799 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1800 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1801 bool tmp
= g_value_get_boolean( &gvalue
);
1802 g_value_unset( &gvalue
);
1809 // ---------------------------------------------------------
1810 // wxDataViewCustomRenderer
1811 // ---------------------------------------------------------
1813 class wxDataViewCtrlDCImpl
: public wxWindowDCImpl
1816 wxDataViewCtrlDCImpl( wxDC
*owner
, wxDataViewCtrl
*window
) :
1817 wxWindowDCImpl( owner
)
1819 GtkWidget
*widget
= window
->m_treeview
;
1825 m_context
= window
->GtkGetPangoDefaultContext();
1826 m_layout
= pango_layout_new( m_context
);
1827 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
1829 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
1831 // Set m_gdkwindow later
1836 class wxDataViewCtrlDC
: public wxWindowDC
1839 wxDataViewCtrlDC( wxDataViewCtrl
*window
) :
1840 wxWindowDC( new wxDataViewCtrlDCImpl( this, window
) )
1845 // ---------------------------------------------------------
1846 // wxDataViewCustomRenderer
1847 // ---------------------------------------------------------
1849 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
1851 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
1852 wxDataViewCellMode mode
, int align
,
1854 wxDataViewRenderer( varianttype
, mode
, align
)
1857 m_text_renderer
= NULL
;
1865 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
,
1866 wxRect
WXUNUSED(cell
), wxDC
*WXUNUSED(dc
), int WXUNUSED(state
) )
1869 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
1870 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
1871 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
1872 view
->GetForegroundColour();
1873 dc
->SetTextForeground(col
);
1874 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
1876 if (!m_text_renderer
)
1877 m_text_renderer
= gtk_cell_renderer_text_new();
1879 GValue gvalue
= { 0, };
1880 g_value_init( &gvalue
, G_TYPE_STRING
);
1881 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( text
, GetOwner()->GetOwner()->GetFont() ) );
1882 g_object_set_property( G_OBJECT(m_text_renderer
), "text", &gvalue
);
1883 g_value_unset( &gvalue
);
1885 ((GdkRectangle
*) cell_area
)->x
+= xoffset
;
1886 ((GdkRectangle
*) cell_area
)->width
-= xoffset
;
1888 gtk_cell_renderer_render( m_text_renderer
,
1891 (GdkRectangle
*) background_area
,
1892 (GdkRectangle
*) cell_area
,
1893 (GdkRectangle
*) expose_area
,
1894 (GtkCellRendererState
) flags
);
1896 ((GdkRectangle
*) cell_area
)->x
-= xoffset
;
1897 ((GdkRectangle
*) cell_area
)->width
+= xoffset
;
1901 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
1903 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
1904 renderer
->cell
= this;
1906 m_renderer
= (GtkCellRenderer
*) renderer
;
1909 SetAlignment(align
);
1916 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
1921 if (m_text_renderer
)
1922 gtk_object_sink( GTK_OBJECT(m_text_renderer
) );
1925 wxDC
*wxDataViewCustomRenderer::GetDC()
1929 if (GetOwner() == NULL
)
1931 if (GetOwner()->GetOwner() == NULL
)
1933 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
1939 // ---------------------------------------------------------
1940 // wxDataViewProgressRenderer
1941 // ---------------------------------------------------------
1943 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
1945 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
1946 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1947 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
1953 if (!gtk_check_version(2,6,0))
1955 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
1957 GValue gvalue
= { 0, };
1958 g_value_init( &gvalue
, G_TYPE_STRING
);
1960 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( m_label
, GetOwner()->GetOwner()->GetFont() ) );
1961 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1962 g_value_unset( &gvalue
);
1965 SetAlignment(align
);
1970 // Use custom cell code
1971 wxDataViewCustomRenderer::Init(mode
, align
);
1975 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
1979 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
1982 if (!gtk_check_version(2,6,0))
1984 gint tmp
= (long) value
;
1985 GValue gvalue
= { 0, };
1986 g_value_init( &gvalue
, G_TYPE_INT
);
1987 g_value_set_int( &gvalue
, tmp
);
1988 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
1989 g_value_unset( &gvalue
);
1994 m_value
= (long) value
;
1996 if (m_value
< 0) m_value
= 0;
1997 if (m_value
> 100) m_value
= 100;
2003 bool wxDataViewProgressRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2008 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
2010 double pct
= (double)m_value
/ 100.0;
2012 bar
.width
= (int)(cell
.width
* pct
);
2013 dc
->SetPen( *wxTRANSPARENT_PEN
);
2014 dc
->SetBrush( *wxBLUE_BRUSH
);
2015 dc
->DrawRectangle( bar
);
2017 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
2018 dc
->SetPen( *wxBLACK_PEN
);
2019 dc
->DrawRectangle( cell
);
2024 wxSize
wxDataViewProgressRenderer::GetSize() const
2026 return wxSize(40,12);
2029 // ---------------------------------------------------------
2030 // wxDataViewDateRenderer
2031 // ---------------------------------------------------------
2033 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
2036 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
2037 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
2038 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
2043 m_cal
= new wxCalendarCtrl( this, -1, *value
);
2044 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
2045 sizer
->Add( m_cal
, 1, wxGROW
);
2050 virtual void OnDismiss()
2054 void OnCalendar( wxCalendarEvent
&event
);
2056 wxCalendarCtrl
*m_cal
;
2057 wxDataViewModel
*m_model
;
2058 wxDataViewItem m_item
;
2062 DECLARE_EVENT_TABLE()
2065 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
2066 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
2069 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
2071 wxDateTime date
= event
.GetDate();
2072 wxVariant value
= date
;
2073 m_model
->SetValue( value
, m_item
, m_col
);
2074 m_model
->ValueChanged( m_item
, m_col
);
2078 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
2080 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
2081 wxDataViewCellMode mode
, int align
) :
2082 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2085 SetAlignment(align
);
2088 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
2090 m_date
= value
.GetDateTime();
2095 bool wxDataViewDateRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2100 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2102 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
2103 wxString tmp
= m_date
.FormatDate();
2104 RenderText( tmp
, 0, cell
, dc
, state
);
2108 wxSize
wxDataViewDateRenderer::GetSize() const
2110 wxString tmp
= m_date
.FormatDate();
2112 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
2113 return wxSize(x
,y
+d
);
2116 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
2117 const wxDataViewItem
&item
, unsigned int col
)
2120 model
->GetValue( variant
, item
, col
);
2121 wxDateTime value
= variant
.GetDateTime();
2123 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
2124 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
2125 wxPoint pos
= wxGetMousePosition();
2128 popup
->Popup( popup
->m_cal
);
2134 // ---------------------------------------------------------
2135 // wxDataViewIconTextRenderer
2136 // ---------------------------------------------------------
2138 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
2140 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
2141 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
2142 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2145 SetAlignment(align
);
2148 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2152 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
2158 bool wxDataViewIconTextRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2163 bool wxDataViewIconTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2165 const wxIcon
&icon
= m_value
.GetIcon();
2169 int yoffset
= wxMax( 0, (cell
.height
- icon
.GetHeight()) / 2 );
2170 dc
->DrawIcon( icon
, cell
.x
, cell
.y
+ yoffset
);
2171 offset
= icon
.GetWidth() + 4;
2174 RenderText( m_value
.GetText(), offset
, cell
, dc
, state
);
2179 wxSize
wxDataViewIconTextRenderer::GetSize() const
2182 if (m_value
.GetIcon().IsOk())
2183 size
.x
= 4 + m_value
.GetIcon().GetWidth();
2185 GetView()->GetTextExtent( m_value
.GetText(), &x
, &y
, &d
);
2191 wxControl
* wxDataViewIconTextRenderer::CreateEditorCtrl(
2192 wxWindow
*WXUNUSED(parent
), wxRect
WXUNUSED(labelRect
), const wxVariant
&WXUNUSED(value
) )
2197 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl(
2198 wxControl
* WXUNUSED(editor
), wxVariant
&WXUNUSED(value
) )
2203 // ---------------------------------------------------------
2205 // ---------------------------------------------------------
2209 gtk_dataview_header_button_press_callback( GtkWidget
*WXUNUSED(widget
),
2210 GdkEventButton
*gdk_event
,
2211 wxDataViewColumn
*column
)
2213 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
2216 if (gdk_event
->button
== 1)
2218 gs_lastLeftClickHeader
= column
;
2220 wxDataViewCtrl
*dv
= column
->GetOwner();
2221 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
2222 event
.SetDataViewColumn( column
);
2223 event
.SetModel( dv
->GetModel() );
2224 if (dv
->HandleWindowEvent( event
))
2228 if (gdk_event
->button
== 3)
2230 wxDataViewCtrl
*dv
= column
->GetOwner();
2231 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
2232 event
.SetDataViewColumn( column
);
2233 event
.SetModel( dv
->GetModel() );
2234 if (dv
->HandleWindowEvent( event
))
2242 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
2243 GtkCellRenderer
*cell
,
2244 GtkTreeModel
*model
,
2250 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*WXUNUSED(column
),
2251 GtkCellRenderer
*renderer
,
2252 GtkTreeModel
*model
,
2256 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2257 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2259 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2261 wxDataViewItem
item( (void*) iter
->user_data
);
2263 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
2265 if (!wx_model
->IsIndexListModel())
2268 if (wx_model
->IsContainer( item
))
2270 if (wx_model
->HasContainerColumns( item
) || (cell
->GetOwner()->GetModelColumn() == 0))
2272 GValue gvalue
= { 0, };
2273 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2274 g_value_set_boolean( &gvalue
, TRUE
);
2275 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2276 g_value_unset( &gvalue
);
2280 GValue gvalue
= { 0, };
2281 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2282 g_value_set_boolean( &gvalue
, FALSE
);
2283 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2284 g_value_unset( &gvalue
);
2291 GValue gvalue
= { 0, };
2292 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2293 g_value_set_boolean( &gvalue
, TRUE
);
2294 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2295 g_value_unset( &gvalue
);
2301 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
2303 if (value
.GetType() != cell
->GetVariantType())
2304 wxLogError( wxT("Wrong type, required: %s but: %s"),
2305 value
.GetType().c_str(),
2306 cell
->GetVariantType().c_str() );
2308 cell
->SetValue( value
);
2310 if (cell
->GtkHasAttributes())
2312 wxDataViewItemAttr attr
;
2313 bool colour_set
= false;
2314 bool style_set
= false;
2315 bool weight_set
= false;
2317 if (wx_model
->GetAttr( item
, cell
->GetOwner()->GetModelColumn(), attr
))
2319 // this must be a GtkCellRendererText
2320 wxColour colour
= attr
.GetColour();
2323 const GdkColor
* const gcol
= colour
.GetColor();
2325 GValue gvalue
= { 0, };
2326 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2327 g_value_set_boxed( &gvalue
, gcol
);
2328 g_object_set_property( G_OBJECT(renderer
), "foreground_gdk", &gvalue
);
2329 g_value_unset( &gvalue
);
2334 if (attr
.GetItalic())
2336 GValue gvalue
= { 0, };
2337 g_value_init( &gvalue
, PANGO_TYPE_STYLE
);
2338 g_value_set_enum( &gvalue
, PANGO_STYLE_ITALIC
);
2339 g_object_set_property( G_OBJECT(renderer
), "style", &gvalue
);
2340 g_value_unset( &gvalue
);
2347 GValue gvalue
= { 0, };
2348 g_value_init( &gvalue
, PANGO_TYPE_WEIGHT
);
2349 g_value_set_enum( &gvalue
, PANGO_WEIGHT_BOLD
);
2350 g_object_set_property( G_OBJECT(renderer
), "weight", &gvalue
);
2351 g_value_unset( &gvalue
);
2359 GValue gvalue
= { 0, };
2360 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2361 g_value_set_boolean( &gvalue
, FALSE
);
2362 g_object_set_property( G_OBJECT(renderer
), "style-set", &gvalue
);
2363 g_value_unset( &gvalue
);
2368 GValue gvalue
= { 0, };
2369 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2370 g_value_set_boolean( &gvalue
, FALSE
);
2371 g_object_set_property( G_OBJECT(renderer
), "weight-set", &gvalue
);
2372 g_value_unset( &gvalue
);
2377 GValue gvalue
= { 0, };
2378 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2379 g_value_set_boolean( &gvalue
, FALSE
);
2380 g_object_set_property( G_OBJECT(renderer
), "foreground-set", &gvalue
);
2381 g_value_unset( &gvalue
);
2386 if (attr
.HasBackgroundColour())
2388 wxColour colour
= attr
.GetBackgroundColour();
2389 const GdkColor
* const gcol
= colour
.GetColor();
2391 GValue gvalue
= { 0, };
2392 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2393 g_value_set_boxed( &gvalue
, gcol
);
2394 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
2395 g_value_unset( &gvalue
);
2399 GValue gvalue
= { 0, };
2400 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2401 g_value_set_boolean( &gvalue
, FALSE
);
2402 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
2403 g_value_unset( &gvalue
);
2409 IMPLEMENT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
2411 #include <wx/listimpl.cpp>
2412 WX_DEFINE_LIST(wxDataViewColumnList
)
2414 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
2415 unsigned int model_column
, int width
,
2416 wxAlignment align
, int flags
) :
2417 wxDataViewColumnBase( title
, cell
, model_column
, width
, align
, flags
)
2419 Init( align
, flags
, width
);
2421 gtk_tree_view_column_set_clickable( GTK_TREE_VIEW_COLUMN(m_column
), TRUE
);
2425 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
2426 unsigned int model_column
, int width
,
2427 wxAlignment align
, int flags
) :
2428 wxDataViewColumnBase( bitmap
, cell
, model_column
, width
, align
, flags
)
2430 Init( align
, flags
, width
);
2432 SetBitmap( bitmap
);
2435 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
2437 m_isConnected
= false;
2439 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) GetRenderer()->GetGtkHandle();
2440 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
2441 m_column
= (GtkWidget
*) column
;
2444 SetAlignment( align
);
2448 gtk_tree_view_column_pack_end( column
, renderer
, TRUE
);
2450 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
2451 wxGtkTreeCellDataFunc
, (gpointer
) GetRenderer(), NULL
);
2454 wxDataViewColumn::~wxDataViewColumn()
2458 void wxDataViewColumn::OnInternalIdle()
2463 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
2465 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2468 g_signal_connect(column
->button
, "button_press_event",
2469 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
2471 m_isConnected
= true;
2476 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
2478 wxDataViewColumnBase::SetOwner( owner
);
2480 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2482 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
2485 void wxDataViewColumn::SetTitle( const wxString
&title
)
2487 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2491 // disconnect before column->button gets recreated
2492 g_signal_handlers_disconnect_by_func( column
->button
,
2493 (GtkWidget
*) gtk_dataview_header_button_press_callback
, this);
2495 m_isConnected
= false;
2498 // FIXME: can it really happen that we don't have the owner here??
2499 wxDataViewCtrl
*ctrl
= GetOwner();
2500 gtk_tree_view_column_set_title( column
, ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
2501 : wxGTK_CONV_SYS(title
) );
2503 gtk_tree_view_column_set_widget( column
, NULL
);
2506 wxString
wxDataViewColumn::GetTitle() const
2508 const gchar
*str
= gtk_tree_view_column_get_title( GTK_TREE_VIEW_COLUMN(m_column
) );
2509 return wxConvFileName
->cMB2WX(str
);
2512 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
2514 wxDataViewColumnBase::SetBitmap( bitmap
);
2516 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2519 GtkImage
*gtk_image
= GTK_IMAGE( gtk_image_new() );
2521 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
2522 if (bitmap
.GetMask())
2523 mask
= bitmap
.GetMask()->GetBitmap();
2525 if (bitmap
.HasPixbuf())
2527 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
2528 bitmap
.GetPixbuf());
2532 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
2533 bitmap
.GetPixmap(), mask
);
2535 gtk_widget_show( GTK_WIDGET(gtk_image
) );
2537 gtk_tree_view_column_set_widget( column
, GTK_WIDGET(gtk_image
) );
2541 gtk_tree_view_column_set_widget( column
, NULL
);
2545 void wxDataViewColumn::SetHidden( bool hidden
)
2547 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
2550 void wxDataViewColumn::SetResizeable( bool resizeable
)
2552 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizeable
);
2555 void wxDataViewColumn::SetAlignment( wxAlignment align
)
2557 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2559 gfloat xalign
= 0.0;
2560 if (align
== wxALIGN_RIGHT
)
2562 if (align
== wxALIGN_CENTER_HORIZONTAL
||
2563 align
== wxALIGN_CENTER
)
2566 gtk_tree_view_column_set_alignment( column
, xalign
);
2569 wxAlignment
wxDataViewColumn::GetAlignment() const
2571 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
2574 return wxALIGN_RIGHT
;
2576 return wxALIGN_CENTER_HORIZONTAL
;
2578 return wxALIGN_LEFT
;
2581 void wxDataViewColumn::SetSortable( bool sortable
)
2583 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2587 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
2591 gtk_tree_view_column_set_sort_column_id( column
, -1 );
2592 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
2596 bool wxDataViewColumn::IsSortable() const
2598 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2599 return (gtk_tree_view_column_get_sort_column_id( column
) != -1);
2602 bool wxDataViewColumn::IsResizeable() const
2604 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2605 return gtk_tree_view_column_get_resizable( column
);
2608 bool wxDataViewColumn::IsHidden() const
2610 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2611 return !gtk_tree_view_column_get_visible( column
);
2614 void wxDataViewColumn::SetSortOrder( bool ascending
)
2616 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2619 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
2621 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
2623 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
2626 bool wxDataViewColumn::IsSortOrderAscending() const
2628 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2630 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
2633 void wxDataViewColumn::SetMinWidth( int width
)
2635 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2638 int wxDataViewColumn::GetMinWidth() const
2640 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2643 int wxDataViewColumn::GetWidth() const
2645 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2648 void wxDataViewColumn::SetWidth( int width
)
2652 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
2656 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
2658 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2662 void wxDataViewColumn::SetReorderable( bool reorderable
)
2664 gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column
), reorderable
);
2667 bool wxDataViewColumn::IsReorderable() const
2669 return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column
) );
2672 //-----------------------------------------------------------------------------
2673 // wxGtkTreeModelNode
2674 //-----------------------------------------------------------------------------
2676 void wxGtkTreeModelNode::Resort()
2678 size_t child_count
= GetChildCount();
2679 if (child_count
== 0)
2682 size_t node_count
= GetNodesCount();
2684 if (child_count
== 1)
2686 if (node_count
== 1)
2688 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
2694 wxGtkTreeModelChildren temp
;
2695 WX_APPEND_ARRAY( temp
, m_children
);
2697 g_internal
= m_internal
;
2698 m_children
.Sort( &wxGtkTreeModelChildCmp
);
2700 gint
*new_order
= new gint
[child_count
];
2703 for (pos
= 0; pos
< child_count
; pos
++)
2705 void *id
= m_children
.Item( pos
);
2706 int old_pos
= temp
.Index( id
);
2707 new_order
[pos
] = old_pos
;
2710 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
2713 iter
.user_data
= GetItem().GetID();
2714 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
2716 GtkTreePath
*path
= m_internal
->get_path( &iter
);
2718 gtk_tree_model_rows_reordered( gtk_tree_model
, path
, &iter
, new_order
);
2720 gtk_tree_path_free (path
);
2722 delete [] new_order
;
2724 for (pos
= 0; pos
< node_count
; pos
++)
2726 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
2731 //-----------------------------------------------------------------------------
2732 // wxDataViewCtrlInternal
2733 //-----------------------------------------------------------------------------
2735 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
,
2736 wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
)
2739 m_wx_model
= wx_model
;
2740 m_gtk_model
= gtk_model
;
2742 m_sort_order
= GTK_SORT_ASCENDING
;
2744 m_dataview_sort_column
= NULL
;
2746 if (!m_wx_model
->IsIndexListModel())
2750 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
2752 g_object_unref( m_gtk_model
);
2755 void wxDataViewCtrlInternal::InitTree()
2757 wxDataViewItem item
;
2758 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
2760 BuildBranch( m_root
);
2763 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
2765 if (node
->GetChildCount() == 0)
2767 wxDataViewItemArray children
;
2768 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
2770 for (pos
= 0; pos
< count
; pos
++)
2772 wxDataViewItem child
= children
[pos
];
2774 if (m_wx_model
->IsContainer( child
))
2775 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
2777 node
->AddLeave( child
.GetID() );
2779 // Don't send any events here
2786 gboolean
wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource
*WXUNUSED(drag_source
),
2790 if (!get_iter( &iter
, path
)) return FALSE
;
2792 wxDataViewItem
item( (void*) iter
.user_data
);
2794 return m_wx_model
->IsDraggable( item
);
2798 wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource
*WXUNUSED(drag_source
),
2799 GtkTreePath
*WXUNUSED(path
))
2804 gboolean
wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource
*WXUNUSED(drag_source
),
2805 GtkTreePath
*path
, GtkSelectionData
*selection_data
)
2808 if (!get_iter( &iter
, path
)) return FALSE
;
2810 wxDataViewItem
item( (void*) iter
.user_data
);
2812 wxDataFormat
format( selection_data
->target
);
2814 size_t size
= m_wx_model
->GetDragDataSize( item
, format
);
2815 if (size
== 0) return FALSE
;
2817 void *data
= malloc( size
);
2819 m_wx_model
->GetDragData( item
, format
, data
, size
);
2821 gtk_selection_data_set( selection_data
, selection_data
->target
,
2822 8, (const guchar
*) data
, size
);
2830 wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest
*WXUNUSED(drag_dest
),
2831 GtkTreePath
*WXUNUSED(dest
),
2832 GtkSelectionData
*WXUNUSED(selection_data
))
2838 wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest
*WXUNUSED(drag_dest
),
2839 GtkTreePath
*WXUNUSED(dest_path
),
2840 GtkSelectionData
*WXUNUSED(selection_data
))
2845 // notifications from wxDataViewModel
2847 bool wxDataViewCtrlInternal::Cleared()
2855 // Create new GTK model
2856 g_object_unref( m_gtk_model
);
2857 m_gtk_model
= wxgtk_tree_model_new();
2858 m_gtk_model
->internal
= this;
2863 void wxDataViewCtrlInternal::Resort()
2865 if (!m_wx_model
->IsIndexListModel())
2869 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
2871 if (!m_wx_model
->IsIndexListModel())
2873 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2874 if (m_wx_model
->IsContainer( item
))
2875 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
2877 parent_node
->AddLeave( item
.GetID() );
2883 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
2885 if (!m_wx_model
->IsIndexListModel())
2887 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2888 parent_node
->DeleteChild( item
.GetID() );
2894 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
2896 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
2897 event
.SetEventObject( m_owner
);
2898 event
.SetModel( m_owner
->GetModel() );
2899 event
.SetItem( item
);
2900 m_owner
->HandleWindowEvent( event
);
2905 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
2907 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
2908 event
.SetEventObject( m_owner
);
2909 event
.SetModel( m_owner
->GetModel() );
2910 event
.SetColumn( col
);
2911 event
.SetDataViewColumn( GetOwner()->GetColumn(col
) );
2912 event
.SetItem( item
);
2913 m_owner
->HandleWindowEvent( event
);
2920 GtkTreeModelFlags
wxDataViewCtrlInternal::get_flags()
2922 if (m_wx_model
->IsIndexListModel())
2923 return GTK_TREE_MODEL_LIST_ONLY
;
2925 return GTK_TREE_MODEL_ITERS_PERSIST
;
2928 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
2930 if (m_wx_model
->IsIndexListModel())
2932 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
2934 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
2936 if (i
>= wx_model
->GetLastIndex() + 1)
2939 iter
->stamp
= m_gtk_model
->stamp
;
2940 // user_data is just the index
2941 iter
->user_data
= (gpointer
) i
;
2947 int depth
= gtk_tree_path_get_depth( path
);
2949 wxGtkTreeModelNode
*node
= m_root
;
2952 for (i
= 0; i
< depth
; i
++)
2954 BuildBranch( node
);
2956 gint pos
= gtk_tree_path_get_indices (path
)[i
];
2957 if (pos
< 0) return FALSE
;
2958 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
2960 void* id
= node
->GetChildren().Item( (size_t) pos
);
2964 iter
->stamp
= m_gtk_model
->stamp
;
2965 iter
->user_data
= id
;
2969 size_t count
= node
->GetNodes().GetCount();
2971 for (pos2
= 0; pos2
< count
; pos2
++)
2973 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
2974 if (child_node
->GetItem().GetID() == id
)
2986 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
2988 GtkTreePath
*retval
= gtk_tree_path_new ();
2990 if (m_wx_model
->IsIndexListModel())
2992 // user_data is just the index
2993 int i
= (wxUIntPtr
) iter
->user_data
;
2994 gtk_tree_path_append_index (retval
, i
);
2998 void *id
= iter
->user_data
;
3000 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
3003 int pos
= node
->GetChildren().Index( id
);
3005 gtk_tree_path_prepend_index( retval
, pos
);
3007 id
= node
->GetItem().GetID();
3008 node
= node
->GetParent();
3015 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
3017 if (m_wx_model
->IsIndexListModel())
3019 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3021 int n
= (wxUIntPtr
) iter
->user_data
;
3026 if (n
>= (int) wx_model
->GetLastIndex())
3029 iter
->user_data
= (gpointer
) ++n
;
3033 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
3034 if( parent
== NULL
)
3037 int pos
= parent
->GetChildren().Index( iter
->user_data
);
3039 if (pos
== (int) parent
->GetChildCount()-1)
3042 iter
->stamp
= m_gtk_model
->stamp
;
3043 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
3049 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
3051 if (m_wx_model
->IsIndexListModel())
3053 // this is a list, nodes have no children
3057 iter
->stamp
= m_gtk_model
->stamp
;
3058 iter
->user_data
= (gpointer
) -1;
3064 wxDataViewItem
item( (void*) parent
->user_data
);
3066 if (!m_wx_model
->IsContainer( item
))
3069 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3070 BuildBranch( parent_node
);
3072 if (parent_node
->GetChildCount() == 0)
3075 iter
->stamp
= m_gtk_model
->stamp
;
3076 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
3082 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
3084 if (m_wx_model
->IsIndexListModel())
3086 // this is a list, nodes have no children
3091 wxDataViewItem
item( (void*) iter
->user_data
);
3093 bool is_container
= m_wx_model
->IsContainer( item
);
3098 wxGtkTreeModelNode
*node
= FindNode( iter
);
3099 BuildBranch( node
);
3101 return (node
->GetChildCount() > 0);
3105 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
3107 if (m_wx_model
->IsIndexListModel())
3109 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3112 return (gint
) wx_model
->GetLastIndex() + 1;
3118 wxDataViewItem
item( (void*) iter
->user_data
);
3120 if (!m_wx_model
->IsContainer( item
))
3123 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
3124 BuildBranch( parent_node
);
3126 // wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() );
3128 return parent_node
->GetChildCount();
3132 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
3134 if (m_wx_model
->IsIndexListModel())
3136 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3144 if (n
>= (gint
) wx_model
->GetLastIndex() + 1)
3147 iter
->stamp
= m_gtk_model
->stamp
;
3148 iter
->user_data
= (gpointer
) n
;
3155 if (parent
) id
= (void*) parent
->user_data
;
3156 wxDataViewItem
item( id
);
3158 if (!m_wx_model
->IsContainer( item
))
3161 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3162 BuildBranch( parent_node
);
3164 // wxPrintf( "iter_nth_child %d\n", n );
3166 iter
->stamp
= m_gtk_model
->stamp
;
3167 iter
->user_data
= parent_node
->GetChildren().Item( n
);
3173 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
3175 if (m_wx_model
->IsIndexListModel())
3181 wxGtkTreeModelNode
*node
= FindParentNode( child
);
3185 iter
->stamp
= m_gtk_model
->stamp
;
3186 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
3192 static wxGtkTreeModelNode
*
3193 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3199 list
.DeleteContents( true );
3200 wxDataViewItem
it( item
);
3204 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3205 list
.Insert( pItem
);
3206 it
= model
->GetParent( it
);
3209 wxGtkTreeModelNode
* node
= treeNode
;
3210 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3212 if( node
&& node
->GetNodes().GetCount() != 0 )
3214 int len
= node
->GetNodes().GetCount();
3215 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3217 for( ; j
< len
; j
++)
3219 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3238 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
3243 wxDataViewItem
item( (void*) iter
->user_data
);
3247 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3251 wxLogDebug( "Not found %p", iter
->user_data
);
3259 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
3264 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3268 wxLogDebug( "Not found %p", item
.GetID() );
3276 static wxGtkTreeModelNode
*
3277 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3283 list
.DeleteContents( true );
3287 wxDataViewItem
it( model
->GetParent( item
) );
3290 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3291 list
.Insert( pItem
);
3292 it
= model
->GetParent( it
);
3295 wxGtkTreeModelNode
* node
= treeNode
;
3296 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3298 if( node
&& node
->GetNodes().GetCount() != 0 )
3300 int len
= node
->GetNodes().GetCount();
3301 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3303 for( ; j
< len
; j
++)
3305 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3320 //Examine whether the node is item's parent node
3321 int len
= node
->GetChildCount();
3322 for( int i
= 0; i
< len
; i
++ )
3324 if( node
->GetChildren().Item( i
) == item
.GetID() )
3330 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
3335 wxDataViewItem
item( (void*) iter
->user_data
);
3339 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3342 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
3347 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3350 //-----------------------------------------------------------------------------
3351 // wxDataViewCtrl signal callbacks
3352 //-----------------------------------------------------------------------------
3355 wxdataview_selection_changed_callback( GtkTreeSelection
* WXUNUSED(selection
), wxDataViewCtrl
*dv
)
3357 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
3360 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
3361 event
.SetItem( dv
->GetSelection() );
3362 event
.SetModel( dv
->GetModel() );
3363 dv
->HandleWindowEvent( event
);
3367 wxdataview_row_activated_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreePath
*path
,
3368 GtkTreeViewColumn
*WXUNUSED(column
), wxDataViewCtrl
*dv
)
3370 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
3373 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3374 wxDataViewItem
item( (void*) iter
.user_data
);;
3375 event
.SetItem( item
);
3376 event
.SetModel( dv
->GetModel() );
3377 dv
->HandleWindowEvent( event
);
3381 wxdataview_test_expand_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3382 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3384 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
3386 wxDataViewItem
item( (void*) iter
->user_data
);;
3387 event
.SetItem( item
);
3388 event
.SetModel( dv
->GetModel() );
3389 dv
->HandleWindowEvent( event
);
3391 return !event
.IsAllowed();
3395 wxdataview_row_expanded_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3396 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3398 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
3400 wxDataViewItem
item( (void*) iter
->user_data
);;
3401 event
.SetItem( item
);
3402 event
.SetModel( dv
->GetModel() );
3403 dv
->HandleWindowEvent( event
);
3407 wxdataview_test_collapse_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3408 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3410 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
3412 wxDataViewItem
item( (void*) iter
->user_data
);;
3413 event
.SetItem( item
);
3414 event
.SetModel( dv
->GetModel() );
3415 dv
->HandleWindowEvent( event
);
3417 return !event
.IsAllowed();
3421 wxdataview_row_collapsed_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3422 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3424 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
3426 wxDataViewItem
item( (void*) iter
->user_data
);;
3427 event
.SetItem( item
);
3428 event
.SetModel( dv
->GetModel() );
3429 dv
->HandleWindowEvent( event
);
3432 //-----------------------------------------------------------------------------
3434 //-----------------------------------------------------------------------------
3436 //-----------------------------------------------------------------------------
3437 // InsertChild for wxDataViewCtrl
3438 //-----------------------------------------------------------------------------
3440 static void wxInsertChildInDataViewCtrl( wxWindowGTK
* parent
, wxWindowGTK
* child
)
3442 wxDataViewCtrl
* dvc
= (wxDataViewCtrl
*) parent
;
3443 GtkWidget
*treeview
= dvc
->GtkGetTreeView();
3445 // Insert widget in GtkTreeView
3446 if (GTK_WIDGET_REALIZED(treeview
))
3447 gtk_widget_set_parent_window( child
->m_widget
,
3448 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
3449 gtk_widget_set_parent( child
->m_widget
, treeview
);
3453 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
3454 GtkAllocation
*WXUNUSED(gtk_alloc
),
3455 wxDataViewCtrl
*win
)
3457 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
3460 wxWindow
*child
= node
->GetData();
3463 gtk_widget_size_request( child
->m_widget
, &req
);
3465 GtkAllocation alloc
;
3466 alloc
.x
= child
->m_x
;
3467 alloc
.y
= child
->m_y
;
3468 alloc
.width
= child
->m_width
;
3469 alloc
.height
= child
->m_height
;
3470 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
3472 node
= node
->GetNext();
3477 //-----------------------------------------------------------------------------
3478 // "motion_notify_event"
3479 //-----------------------------------------------------------------------------
3482 gtk_dataview_motion_notify_callback( GtkWidget
*WXUNUSED(widget
),
3483 GdkEventMotion
*gdk_event
,
3484 wxDataViewCtrl
*dv
)
3486 if (gdk_event
->is_hint
)
3490 GdkModifierType state
;
3491 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
3496 GtkTreePath
*path
= NULL
;
3497 GtkTreeViewColumn
*column
= NULL
;
3500 if (gtk_tree_view_get_path_at_pos(
3501 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
3502 (int) gdk_event
->x
, (int) gdk_event
->y
,
3511 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3513 // wxPrintf( "mouse %d %d\n", (int) gdk_event->x, (int) gdk_event->y );
3515 gtk_tree_path_free( path
);
3523 //-----------------------------------------------------------------------------
3524 // "button_press_event"
3525 //-----------------------------------------------------------------------------
3528 gtk_dataview_button_press_callback( GtkWidget
*WXUNUSED(widget
),
3529 GdkEventButton
*gdk_event
,
3530 wxDataViewCtrl
*dv
)
3532 if ((gdk_event
->button
== 3) && (gdk_event
->type
== GDK_BUTTON_PRESS
))
3534 GtkTreePath
*path
= NULL
;
3535 GtkTreeViewColumn
*column
= NULL
;
3538 if (gtk_tree_view_get_path_at_pos(
3539 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
3540 (int) gdk_event
->x
, (int) gdk_event
->y
,
3549 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3551 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, dv
->GetId() );
3552 wxDataViewItem
item( (void*) iter
.user_data
);;
3553 event
.SetItem( item
);
3554 event
.SetModel( dv
->GetModel() );
3555 bool ret
= dv
->HandleWindowEvent( event
);
3556 gtk_tree_path_free( path
);
3565 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
3567 wxDataViewCtrl::~wxDataViewCtrl()
3570 GetModel()->RemoveNotifier( m_notifier
);
3572 // remove the model from the GtkTreeView before it gets destroyed by the
3573 // wxDataViewCtrlBase's dtor
3574 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), NULL
);
3579 void wxDataViewCtrl::Init()
3585 static GtkTargetEntry gs_target
;
3587 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
3588 const wxPoint
& pos
, const wxSize
& size
,
3589 long style
, const wxValidator
& validator
)
3593 if (!PreCreation( parent
, pos
, size
) ||
3594 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
3596 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
3600 m_insertCallback
= wxInsertChildInDataViewCtrl
;
3602 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
3604 GtkScrolledWindowSetBorder(m_widget
, style
);
3606 m_treeview
= gtk_tree_view_new();
3607 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
3609 g_signal_connect (m_treeview
, "size_allocate",
3610 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
3612 gs_target
.target
= const_cast<char *>("UTF8_STRING");
3613 gs_target
.flags
= 0;
3614 gs_target
.info
= static_cast<guint
>(-1);
3615 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_treeview
),
3616 GDK_BUTTON1_MASK
, &gs_target
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3619 if (!gtk_check_version(2,6,0))
3620 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), TRUE
);
3623 if (style
& wxDV_MULTIPLE
)
3625 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3626 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
3629 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
3632 if (!gtk_check_version(2,10,0))
3634 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
3636 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
3637 (style
& wxDV_VERT_RULES
) != 0)
3638 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
3639 else if (style
& wxDV_VERT_RULES
)
3640 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
3641 else if (style
& wxDV_HORIZ_RULES
)
3642 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
3644 if (grid
!= GTK_TREE_VIEW_GRID_LINES_NONE
)
3645 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
3649 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_ROW_LINES
) != 0 );
3651 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
3652 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
3653 gtk_widget_show (m_treeview
);
3655 m_parent
->DoAddChild( this );
3659 GtkEnableSelectionEvents();
3661 g_signal_connect_after (m_treeview
, "row-activated",
3662 G_CALLBACK (wxdataview_row_activated_callback
), this);
3664 g_signal_connect (m_treeview
, "test-collapse-row",
3665 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
3667 g_signal_connect_after (m_treeview
, "row-collapsed",
3668 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
3670 g_signal_connect (m_treeview
, "test-expand-row",
3671 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
3673 g_signal_connect_after (m_treeview
, "row-expanded",
3674 G_CALLBACK (wxdataview_row_expanded_callback
), this);
3676 g_signal_connect (m_treeview
, "motion_notify_event",
3677 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
3679 g_signal_connect (m_treeview
, "button_press_event",
3680 G_CALLBACK (gtk_dataview_button_press_callback
), this);
3685 void wxDataViewCtrl::OnInternalIdle()
3687 wxWindow::OnInternalIdle();
3689 unsigned int cols
= GetColumnCount();
3691 for (i
= 0; i
< cols
; i
++)
3693 wxDataViewColumn
*col
= GetColumn( i
);
3694 col
->OnInternalIdle();
3698 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
3709 if (!wxDataViewCtrlBase::AssociateModel( model
))
3712 GtkWxTreeModel
*gtk_model
= wxgtk_tree_model_new();
3713 m_internal
= new wxDataViewCtrlInternal( this, model
, gtk_model
);
3714 gtk_model
->internal
= m_internal
;
3716 m_notifier
= new wxGtkDataViewModelNotifier( gtk_model
, model
, this );
3718 model
->AddNotifier( m_notifier
);
3720 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_model
) );
3722 // unref in wxDataViewCtrlInternal
3723 // g_object_unref( gtk_model );
3728 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
3730 if (!wxDataViewCtrlBase::AppendColumn(col
))
3733 m_cols
.Append( col
);
3736 if (!gtk_check_version(2,6,0))
3738 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
3739 GTK_TREE_VIEW_COLUMN_FIXED
)
3740 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
3744 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
3745 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
3750 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
3752 if (!wxDataViewCtrlBase::PrependColumn(col
))
3755 m_cols
.Insert( col
);
3758 if (!gtk_check_version(2,6,0))
3760 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
3761 GTK_TREE_VIEW_COLUMN_FIXED
)
3762 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
3766 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
3767 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
3772 unsigned int wxDataViewCtrl::GetColumnCount() const
3774 return m_cols
.GetCount();
3777 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
3779 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
3783 wxDataViewColumnList::const_iterator iter
;
3784 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); iter
++)
3786 wxDataViewColumn
*col
= *iter
;
3787 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
3796 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
3798 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
3799 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
3801 m_cols
.remove( column
);
3808 bool wxDataViewCtrl::ClearColumns()
3810 wxDataViewColumnList::iterator iter
;
3811 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); iter
++)
3813 wxDataViewColumn
*col
= *iter
;
3814 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
3815 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
3823 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
3825 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetConstGtkHandle());
3827 GList
*list
= gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview
) );
3829 gint pos
= g_list_index( list
, (gconstpointer
) gtk_column
);
3831 g_list_free( list
);
3836 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
3838 return m_internal
->GetDataViewSortColumn();
3841 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
3844 iter
.user_data
= item
.GetID();
3845 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3846 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
3847 gtk_tree_path_free( path
);
3850 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
3853 iter
.user_data
= item
.GetID();
3854 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3855 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
3856 gtk_tree_path_free( path
);
3859 wxDataViewItem
wxDataViewCtrl::GetSelection() const
3861 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3863 if (m_windowStyle
& wxDV_MULTIPLE
)
3865 // Report the first one
3866 GtkTreeModel
*model
;
3867 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
3871 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
3873 m_internal
->get_iter( &iter
, path
);
3876 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
3877 g_list_free( list
);
3879 return wxDataViewItem( (void*) iter
.user_data
);
3885 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
3887 wxDataViewItem
item( (void*) iter
.user_data
);
3892 return wxDataViewItem(0);
3895 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
3899 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3900 if (HasFlag(wxDV_MULTIPLE
))
3902 GtkTreeModel
*model
;
3903 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
3908 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
3911 m_internal
->get_iter( &iter
, path
);
3913 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
3915 list
= g_list_next( list
);
3920 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
3921 g_list_free( list
);
3927 GtkTreeModel
*model
;
3929 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
3932 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
3940 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
3942 GtkDisableSelectionEvents();
3944 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3946 gtk_tree_selection_unselect_all( selection
);
3949 for (i
= 0; i
< sel
.GetCount(); i
++)
3952 iter
.user_data
= (gpointer
) sel
[i
].GetID();
3953 gtk_tree_selection_select_iter( selection
, &iter
);
3956 GtkEnableSelectionEvents();
3959 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
3961 GtkDisableSelectionEvents();
3963 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3966 iter
.user_data
= (gpointer
) item
.GetID();
3967 gtk_tree_selection_select_iter( selection
, &iter
);
3969 GtkEnableSelectionEvents();
3972 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
3974 GtkDisableSelectionEvents();
3976 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3979 iter
.user_data
= (gpointer
) item
.GetID();
3980 gtk_tree_selection_unselect_iter( selection
, &iter
);
3982 GtkEnableSelectionEvents();
3985 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
3987 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3990 iter
.user_data
= (gpointer
) item
.GetID();
3992 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
3995 void wxDataViewCtrl::SelectAll()
3997 GtkDisableSelectionEvents();
3999 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4001 gtk_tree_selection_select_all( selection
);
4003 GtkEnableSelectionEvents();
4006 void wxDataViewCtrl::UnselectAll()
4008 GtkDisableSelectionEvents();
4010 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4012 gtk_tree_selection_unselect_all( selection
);
4014 GtkEnableSelectionEvents();
4017 void wxDataViewCtrl::EnsureVisible(const wxDataViewItem
& item
,
4018 const wxDataViewColumn
*WXUNUSED(column
))
4021 iter
.user_data
= (gpointer
) item
.GetID();
4022 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4023 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
4024 gtk_tree_path_free( path
);
4027 void wxDataViewCtrl::HitTest(const wxPoint
& WXUNUSED(point
),
4028 wxDataViewItem
& item
,
4029 wxDataViewColumn
*& column
) const
4031 item
= wxDataViewItem(0);
4036 wxDataViewCtrl::GetItemRect(const wxDataViewItem
& WXUNUSED(item
),
4037 const wxDataViewColumn
*WXUNUSED(column
)) const
4042 void wxDataViewCtrl::DoSetExpanderColumn()
4044 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
4045 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
4048 void wxDataViewCtrl::DoSetIndent()
4052 void wxDataViewCtrl::GtkDisableSelectionEvents()
4054 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4055 g_signal_handlers_disconnect_by_func( selection
,
4056 (gpointer
) (wxdataview_selection_changed_callback
), this);
4059 void wxDataViewCtrl::GtkEnableSelectionEvents()
4061 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4062 g_signal_connect_after (selection
, "changed",
4063 G_CALLBACK (wxdataview_selection_changed_callback
), this);
4068 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
4070 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
4075 // !wxUSE_GENERICDATAVIEWCTRL
4078 // wxUSE_DATAVIEWCTRL