1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/dataview.cpp
3 // Purpose: wxDataViewCtrl GTK+2 implementation
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if wxUSE_DATAVIEWCTRL
15 #include "wx/dataview.h"
17 #ifndef wxUSE_GENERICDATAVIEWCTRL
21 #include "wx/dcclient.h"
23 #include "wx/settings.h"
27 #include "wx/stockitem.h"
28 #include "wx/calctrl.h"
29 #include "wx/popupwin.h"
30 #include "wx/listimpl.cpp"
32 #include "wx/gtk/private.h"
33 #include "wx/gtk/dc.h"
34 #include "wx/gtk/dcclient.h"
36 #include "wx/gtk/private/gdkconv.h"
37 using namespace wxGTKImpl
;
39 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 static wxDataViewCtrlInternal
*gs_internal
= NULL
;
44 class wxGtkTreeModelNode
;
47 typedef struct _GtkWxTreeModel GtkWxTreeModel
;
50 //-----------------------------------------------------------------------------
51 // wxDataViewCtrlInternal
52 //-----------------------------------------------------------------------------
54 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
55 WX_DEFINE_LIST(ItemList
)
57 class WXDLLIMPEXP_ADV wxDataViewCtrlInternal
60 wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
);
61 ~wxDataViewCtrlInternal();
64 GtkTreeModelFlags
get_flags();
65 gboolean
get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
);
66 GtkTreePath
*get_path( GtkTreeIter
*iter
);
67 gboolean
iter_next( GtkTreeIter
*iter
);
68 gboolean
iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
);
69 gboolean
iter_has_child( GtkTreeIter
*iter
);
70 gint
iter_n_children( GtkTreeIter
*iter
);
71 gboolean
iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
);
72 gboolean
iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
);
76 bool EnableDragSource( const wxDataFormat
&format
);
77 bool EnableDropTarget( const wxDataFormat
&format
);
79 gboolean
row_draggable( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
);
80 gboolean
drag_data_delete( GtkTreeDragSource
*drag_source
, GtkTreePath
* path
);
81 gboolean
drag_data_get( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
,
82 GtkSelectionData
*selection_data
);
83 gboolean
drag_data_received( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest
,
84 GtkSelectionData
*selection_data
);
85 gboolean
row_drop_possible( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest_path
,
86 GtkSelectionData
*selection_data
);
88 // notifactions from wxDataViewModel
89 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
90 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
91 bool ItemChanged( const wxDataViewItem
&item
);
92 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
97 void SetSortOrder( GtkSortType sort_order
) { m_sort_order
= sort_order
; }
98 GtkSortType
GetSortOrder() const { return m_sort_order
; }
100 void SetSortColumn( int column
) { m_sort_column
= column
; }
101 int GetSortColumn() const { return m_sort_column
; }
103 void SetDataViewSortColumn( wxDataViewColumn
*column
) { m_dataview_sort_column
= column
; }
104 wxDataViewColumn
*GetDataViewSortColumn() { return m_dataview_sort_column
; }
106 bool IsSorted() { return (m_sort_column
>= 0); }
109 wxDataViewModel
* GetDataViewModel() { return m_wx_model
; }
110 const wxDataViewModel
* GetDataViewModel() const { return m_wx_model
; }
111 wxDataViewCtrl
* GetOwner() { return m_owner
; }
112 GtkWxTreeModel
* GetGtkModel() { return m_gtk_model
; }
114 // item can be deleted already in the model
115 int GetIndexOf( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
119 wxGtkTreeModelNode
*FindNode( const wxDataViewItem
&item
);
120 wxGtkTreeModelNode
*FindNode( GtkTreeIter
*iter
);
121 wxGtkTreeModelNode
*FindParentNode( const wxDataViewItem
&item
);
122 wxGtkTreeModelNode
*FindParentNode( GtkTreeIter
*iter
);
123 void BuildBranch( wxGtkTreeModelNode
*branch
);
126 wxGtkTreeModelNode
*m_root
;
127 wxDataViewModel
*m_wx_model
;
128 GtkWxTreeModel
*m_gtk_model
;
129 wxDataViewCtrl
*m_owner
;
130 GtkSortType m_sort_order
;
131 wxDataViewColumn
*m_dataview_sort_column
;
134 GtkTargetEntry m_dragSourceTargetEntry
;
135 wxCharBuffer m_dragSourceTargetEntryTarget
;
136 wxDataObject
*m_dragDataObject
;
138 GtkTargetEntry m_dropTargetTargetEntry
;
139 wxCharBuffer m_dropTargetTargetEntryTarget
;
140 wxDataObject
*m_dropDataObject
;
144 //-----------------------------------------------------------------------------
145 // wxGtkTreeModelNode
146 //-----------------------------------------------------------------------------
149 int LINKAGEMODE
wxGtkTreeModelChildCmp( void** id1
, void** id2
)
151 int ret
= gs_internal
->GetDataViewModel()->Compare( *id1
, *id2
,
152 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
157 WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode
*, wxGtkTreeModelNodes
);
158 WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren
);
160 class wxGtkTreeModelNode
163 wxGtkTreeModelNode( wxGtkTreeModelNode
* parent
, const wxDataViewItem
&item
,
164 wxDataViewCtrlInternal
*internal
)
168 m_internal
= internal
;
171 ~wxGtkTreeModelNode()
173 size_t count
= m_nodes
.GetCount();
175 for (i
= 0; i
< count
; i
++)
177 wxGtkTreeModelNode
*child
= m_nodes
.Item( i
);
182 unsigned int AddNode( wxGtkTreeModelNode
* child
)
184 m_nodes
.Add( child
);
186 void *id
= child
->GetItem().GetID();
188 m_children
.Add( id
);
190 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
192 gs_internal
= m_internal
;
193 m_children
.Sort( &wxGtkTreeModelChildCmp
);
194 return m_children
.Index( id
);
197 return m_children
.GetCount()-1;
200 unsigned int AddLeave( void* id
)
202 m_children
.Add( id
);
204 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
206 gs_internal
= m_internal
;
207 m_children
.Sort( &wxGtkTreeModelChildCmp
);
208 return m_children
.Index( id
);
211 return m_children
.GetCount()-1;
214 void DeleteChild( void* id
)
216 m_children
.Remove( id
);
218 unsigned int count
= m_nodes
.GetCount();
220 for (pos
= 0; pos
< count
; pos
++)
222 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
223 if (node
->GetItem().GetID() == id
)
225 m_nodes
.RemoveAt( pos
);
232 wxGtkTreeModelNode
* GetParent()
234 wxGtkTreeModelNodes
&GetNodes()
236 wxGtkTreeModelChildren
&GetChildren()
237 { return m_children
; }
239 unsigned int GetChildCount() const { return m_children
.GetCount(); }
240 unsigned int GetNodesCount() const { return m_nodes
.GetCount(); }
242 wxDataViewItem
&GetItem() { return m_item
; }
243 wxDataViewCtrlInternal
*GetInternal() { return m_internal
; }
248 wxGtkTreeModelNode
*m_parent
;
249 wxGtkTreeModelNodes m_nodes
;
250 wxGtkTreeModelChildren m_children
;
251 wxDataViewItem m_item
;
252 wxDataViewCtrlInternal
*m_internal
;
256 //-----------------------------------------------------------------------------
258 //-----------------------------------------------------------------------------
260 extern bool g_blockEventsOnDrag
;
262 //-----------------------------------------------------------------------------
263 // define new GTK+ class wxGtkTreeModel
264 //-----------------------------------------------------------------------------
268 #define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ())
269 #define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel))
270 #define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
271 #define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL))
272 #define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL))
273 #define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
275 GType
gtk_wx_tree_model_get_type (void);
277 typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass
;
279 struct _GtkWxTreeModel
285 wxDataViewCtrlInternal
*internal
;
288 struct _GtkWxTreeModelClass
290 GObjectClass list_parent_class
;
293 static GtkWxTreeModel
*wxgtk_tree_model_new (void);
294 static void wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
);
295 static void wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
);
297 static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
);
298 static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
);
299 static void wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
);
300 static void wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
);
302 static void wxgtk_tree_model_finalize (GObject
*object
);
303 static GtkTreeModelFlags
wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
);
304 static gint
wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
);
305 static GType
wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
307 static gboolean
wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
310 static GtkTreePath
*wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
312 static void wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
316 static gboolean
wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
318 static gboolean
wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
320 GtkTreeIter
*parent
);
321 static gboolean
wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
323 static gint
wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
325 static gboolean
wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
329 static gboolean
wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
334 static gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
335 gint
*sort_column_id
,
337 static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
340 static void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
342 GtkTreeIterCompareFunc func
,
344 GtkDestroyNotify destroy
);
345 static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
346 GtkTreeIterCompareFunc func
,
348 GtkDestroyNotify destroy
);
349 static gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
);
352 static gboolean
wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
354 static gboolean
wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
356 static gboolean
wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
358 GtkSelectionData
*selection_data
);
359 static gboolean
wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
361 GtkSelectionData
*selection_data
);
362 static gboolean
wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
363 GtkTreePath
*dest_path
,
364 GtkSelectionData
*selection_data
);
367 static GObjectClass
*list_parent_class
= NULL
;
370 gtk_wx_tree_model_get_type (void)
372 static GType tree_model_type
= 0;
374 if (!tree_model_type
)
376 const GTypeInfo tree_model_info
=
378 sizeof (GtkWxTreeModelClass
),
379 NULL
, /* base_init */
380 NULL
, /* base_finalize */
381 (GClassInitFunc
) wxgtk_tree_model_class_init
,
382 NULL
, /* class_finalize */
383 NULL
, /* class_data */
384 sizeof (GtkWxTreeModel
),
386 (GInstanceInitFunc
) wxgtk_tree_model_init
,
389 static const GInterfaceInfo tree_model_iface_info
=
391 (GInterfaceInitFunc
) wxgtk_tree_model_tree_model_init
,
396 static const GInterfaceInfo sortable_iface_info
=
398 (GInterfaceInitFunc
) wxgtk_tree_model_sortable_init
,
403 static const GInterfaceInfo drag_source_iface_info
=
405 (GInterfaceInitFunc
) wxgtk_tree_model_drag_source_init
,
410 static const GInterfaceInfo drag_dest_iface_info
=
412 (GInterfaceInitFunc
) wxgtk_tree_model_drag_dest_init
,
417 tree_model_type
= g_type_register_static (G_TYPE_OBJECT
, "GtkWxTreeModel",
418 &tree_model_info
, (GTypeFlags
)0 );
420 g_type_add_interface_static (tree_model_type
,
422 &tree_model_iface_info
);
423 g_type_add_interface_static (tree_model_type
,
424 GTK_TYPE_TREE_SORTABLE
,
425 &sortable_iface_info
);
426 g_type_add_interface_static (tree_model_type
,
427 GTK_TYPE_TREE_DRAG_DEST
,
428 &drag_dest_iface_info
);
429 g_type_add_interface_static (tree_model_type
,
430 GTK_TYPE_TREE_DRAG_SOURCE
,
431 &drag_source_iface_info
);
434 return tree_model_type
;
437 static GtkWxTreeModel
*
438 wxgtk_tree_model_new(void)
440 GtkWxTreeModel
*retval
= (GtkWxTreeModel
*) g_object_new (GTK_TYPE_WX_TREE_MODEL
, NULL
);
445 wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
)
447 list_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
448 GObjectClass
*object_class
= (GObjectClass
*) klass
;
449 object_class
->finalize
= wxgtk_tree_model_finalize
;
453 wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
)
455 iface
->get_flags
= wxgtk_tree_model_get_flags
;
456 iface
->get_n_columns
= wxgtk_tree_model_get_n_columns
;
457 iface
->get_column_type
= wxgtk_tree_model_get_column_type
;
458 iface
->get_iter
= wxgtk_tree_model_get_iter
;
459 iface
->get_path
= wxgtk_tree_model_get_path
;
460 iface
->get_value
= wxgtk_tree_model_get_value
;
461 iface
->iter_next
= wxgtk_tree_model_iter_next
;
462 iface
->iter_children
= wxgtk_tree_model_iter_children
;
463 iface
->iter_has_child
= wxgtk_tree_model_iter_has_child
;
464 iface
->iter_n_children
= wxgtk_tree_model_iter_n_children
;
465 iface
->iter_nth_child
= wxgtk_tree_model_iter_nth_child
;
466 iface
->iter_parent
= wxgtk_tree_model_iter_parent
;
470 wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
)
472 iface
->get_sort_column_id
= wxgtk_tree_model_get_sort_column_id
;
473 iface
->set_sort_column_id
= wxgtk_tree_model_set_sort_column_id
;
474 iface
->set_sort_func
= wxgtk_tree_model_set_sort_func
;
475 iface
->set_default_sort_func
= wxgtk_tree_model_set_default_sort_func
;
476 iface
->has_default_sort_func
= wxgtk_tree_model_has_default_sort_func
;
480 wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
)
482 iface
->row_draggable
= wxgtk_tree_model_row_draggable
;
483 iface
->drag_data_delete
= wxgtk_tree_model_drag_data_delete
;
484 iface
->drag_data_get
= wxgtk_tree_model_drag_data_get
;
488 wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
)
490 iface
->drag_data_received
= wxgtk_tree_model_drag_data_received
;
491 iface
->row_drop_possible
= wxgtk_tree_model_row_drop_possible
;
495 wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
)
497 tree_model
->internal
= NULL
;
498 tree_model
->stamp
= g_random_int();
502 wxgtk_tree_model_finalize (GObject
*object
)
505 (* list_parent_class
->finalize
) (object
);
510 //-----------------------------------------------------------------------------
511 // implement callbacks from wxGtkTreeModel class by letting
512 // them call the methods of wxWidgets' wxDataViewModel
513 //-----------------------------------------------------------------------------
515 static GtkTreeModelFlags
516 wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
)
518 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
519 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), (GtkTreeModelFlags
)0 );
521 return wxtree_model
->internal
->get_flags();
525 wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
)
527 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
528 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
530 return wxtree_model
->internal
->GetDataViewModel()->GetColumnCount();
534 wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
537 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
538 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), G_TYPE_INVALID
);
540 GType gtype
= G_TYPE_INVALID
;
542 wxString wxtype
= wxtree_model
->internal
->GetDataViewModel()->GetColumnType( (unsigned int) index
);
544 if (wxtype
== wxT("string"))
545 gtype
= G_TYPE_STRING
;
548 gtype
= G_TYPE_POINTER
;
549 // wxFAIL_MSG( wxT("non-string columns not supported for searching yet") );
556 wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
560 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
561 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
562 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
564 return wxtree_model
->internal
->get_iter( iter
, path
);
568 wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
571 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
572 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), NULL
);
573 g_return_val_if_fail (iter
->stamp
== GTK_WX_TREE_MODEL (wxtree_model
)->stamp
, NULL
);
575 return wxtree_model
->internal
->get_path( iter
);
579 wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
584 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
585 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
) );
587 wxDataViewModel
*model
= wxtree_model
->internal
->GetDataViewModel();
588 wxString mtype
= model
->GetColumnType( (unsigned int) column
);
589 if (mtype
== wxT("string"))
592 g_value_init( value
, G_TYPE_STRING
);
593 wxDataViewItem
item( (void*) iter
->user_data
);
594 model
->GetValue( variant
, item
, (unsigned int) column
);
596 g_value_set_string( value
, variant
.GetString().utf8_str() );
600 wxFAIL_MSG( wxT("non-string columns not supported yet") );
605 wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
608 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
610 // This happens when clearing the view by calling .._set_model( NULL );
611 if (iter
->stamp
== 0) return FALSE
;
613 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
614 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
616 return wxtree_model
->internal
->iter_next( iter
);
620 wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
624 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
625 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
626 g_return_val_if_fail (wxtree_model
->stamp
== parent
->stamp
, FALSE
);
628 return wxtree_model
->internal
->iter_children( iter
, parent
);
632 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
635 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
636 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
637 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
639 return wxtree_model
->internal
->iter_has_child( iter
);
643 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
646 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
647 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
648 g_return_val_if_fail ( !iter
|| wxtree_model
->stamp
== iter
->stamp
, 0);
650 return wxtree_model
->internal
->iter_n_children( iter
);
654 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
659 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
660 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
662 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
666 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
670 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
671 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
672 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
674 return wxtree_model
->internal
->iter_parent( iter
, child
);
677 /* drag'n'drop iface */
679 wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
682 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
683 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
685 return wxtree_model
->internal
->row_draggable( drag_source
, path
);
689 wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
692 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
693 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
695 return wxtree_model
->internal
->drag_data_delete( drag_source
, path
);
699 wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
701 GtkSelectionData
*selection_data
)
703 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
704 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
707 wxPrintf( "drag_get_data\n");
709 wxGtkString
atom_selection(gdk_atom_name(selection_data
->selection
));
710 wxPrintf( "selection %s\n", wxString::FromAscii(atom_selection
) );
712 wxGtkString
atom_target(gdk_atom_name(selection_data
->target
));
713 wxPrintf( "target %s\n", wxString::FromAscii(atom_target
) );
715 wxGtkString
atom_type(gdk_atom_name(selection_data
->type
));
716 wxPrintf( "type %s\n", wxString::FromAscii(atom_type
) );
718 wxPrintf( "format %d\n", selection_data
->format
);
721 return wxtree_model
->internal
->drag_data_get( drag_source
, path
, selection_data
);
725 wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
727 GtkSelectionData
*selection_data
)
729 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
730 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
732 return wxtree_model
->internal
->drag_data_received( drag_dest
, dest
, selection_data
);
736 wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
737 GtkTreePath
*dest_path
,
738 GtkSelectionData
*selection_data
)
740 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
741 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
743 return wxtree_model
->internal
->row_drop_possible( drag_dest
, dest_path
, selection_data
);
748 wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
749 gint
*sort_column_id
,
752 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) sortable
;
754 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
756 if (!wxtree_model
->internal
->IsSorted())
759 *sort_column_id
= -1;
766 *sort_column_id
= wxtree_model
->internal
->GetSortColumn();
769 *order
= wxtree_model
->internal
->GetSortOrder();
774 wxDataViewColumn
*gs_lastLeftClickHeader
= NULL
;
777 wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
781 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
782 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
784 tree_model
->internal
->SetDataViewSortColumn( gs_lastLeftClickHeader
);
786 if ((sort_column_id
!= (gint
) tree_model
->internal
->GetSortColumn()) ||
787 (order
!= tree_model
->internal
->GetSortOrder()))
789 tree_model
->internal
->SetSortColumn( sort_column_id
);
790 tree_model
->internal
->SetSortOrder( order
);
792 gtk_tree_sortable_sort_column_changed (sortable
);
794 tree_model
->internal
->GetDataViewModel()->Resort();
797 if (gs_lastLeftClickHeader
)
799 wxDataViewCtrl
*dv
= tree_model
->internal
->GetOwner();
800 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, dv
->GetId() );
801 event
.SetDataViewColumn( gs_lastLeftClickHeader
);
802 event
.SetModel( dv
->GetModel() );
803 dv
->HandleWindowEvent( event
);
806 gs_lastLeftClickHeader
= NULL
;
810 wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
811 gint
WXUNUSED(sort_column_id
),
812 GtkTreeIterCompareFunc func
,
813 gpointer
WXUNUSED(data
),
814 GtkDestroyNotify
WXUNUSED(destroy
))
816 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
817 g_return_if_fail (func
!= NULL
);
821 wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
822 GtkTreeIterCompareFunc func
,
823 gpointer
WXUNUSED(data
),
824 GtkDestroyNotify
WXUNUSED(destroy
))
826 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
827 g_return_if_fail (func
!= NULL
);
829 //wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
830 // TODO: remove this code
834 wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
)
836 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
841 //-----------------------------------------------------------------------------
842 // define new GTK+ class GtkWxRendererText
843 //-----------------------------------------------------------------------------
847 #define GTK_TYPE_WX_CELL_RENDERER_TEXT (gtk_wx_cell_renderer_text_get_type ())
848 #define GTK_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererText))
849 #define GTK_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
850 #define GTK_IS_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT))
851 #define GTK_IS_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT))
852 #define GTK_WX_CELL_RENDERER_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
854 GType
gtk_wx_cell_renderer_text_get_type (void);
856 typedef struct _GtkWxCellRendererText GtkWxCellRendererText
;
857 typedef struct _GtkWxCellRendererTextClass GtkWxCellRendererTextClass
;
859 struct _GtkWxCellRendererText
861 GtkCellRendererText parent
;
863 wxDataViewRenderer
*wx_renderer
;
866 struct _GtkWxCellRendererTextClass
868 GtkCellRendererTextClass cell_parent_class
;
872 static GtkWxCellRendererText
*gtk_wx_cell_renderer_text_new (void);
873 static void gtk_wx_cell_renderer_text_init (
874 GtkWxCellRendererText
*cell
);
875 static void gtk_wx_cell_renderer_text_class_init(
876 GtkWxCellRendererTextClass
*klass
);
877 static void gtk_wx_cell_renderer_text_finalize (
879 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
880 GtkCellRenderer
*cell
,
884 GdkRectangle
*background_area
,
885 GdkRectangle
*cell_area
,
886 GtkCellRendererState flags
);
889 static GObjectClass
*text_cell_parent_class
= NULL
;
894 gtk_wx_cell_renderer_text_get_type (void)
896 static GType cell_wx_type
= 0;
900 const GTypeInfo cell_wx_info
=
902 sizeof (GtkWxCellRendererTextClass
),
903 NULL
, /* base_init */
904 NULL
, /* base_finalize */
905 (GClassInitFunc
) gtk_wx_cell_renderer_text_class_init
,
906 NULL
, /* class_finalize */
907 NULL
, /* class_data */
908 sizeof (GtkWxCellRendererText
),
910 (GInstanceInitFunc
) gtk_wx_cell_renderer_text_init
,
913 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER_TEXT
,
914 "GtkWxCellRendererText", &cell_wx_info
, (GTypeFlags
)0 );
921 gtk_wx_cell_renderer_text_init (GtkWxCellRendererText
*cell
)
923 cell
->wx_renderer
= NULL
;
927 gtk_wx_cell_renderer_text_class_init (GtkWxCellRendererTextClass
*klass
)
929 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
930 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
932 text_cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
934 object_class
->finalize
= gtk_wx_cell_renderer_text_finalize
;
936 cell_class
->start_editing
= gtk_wx_cell_renderer_text_start_editing
;
940 gtk_wx_cell_renderer_text_finalize (GObject
*object
)
943 (* G_OBJECT_CLASS (text_cell_parent_class
)->finalize
) (object
);
946 GtkWxCellRendererText
*
947 gtk_wx_cell_renderer_text_new (void)
949 return (GtkWxCellRendererText
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER_TEXT
, NULL
);
952 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
953 GtkCellRenderer
*gtk_renderer
,
957 GdkRectangle
*background_area
,
958 GdkRectangle
*cell_area
,
959 GtkCellRendererState flags
)
961 GtkWxCellRendererText
*wxgtk_renderer
= (GtkWxCellRendererText
*) gtk_renderer
;
962 wxDataViewRenderer
*wx_renderer
= wxgtk_renderer
->wx_renderer
;
964 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
966 wx_renderer
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
967 wxDataViewItem
item( (void*) iter
.user_data
);;
968 gtk_tree_path_free( treepath
);
970 wxDataViewColumn
*column
= wx_renderer
->GetOwner();
971 wxDataViewCtrl
*dv
= column
->GetOwner();
972 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, dv
->GetId() );
973 event
.SetDataViewColumn( column
);
974 event
.SetModel( dv
->GetModel() );
975 event
.SetColumn( wx_renderer
->GetOwner()->GetModelColumn() );
976 event
.SetItem( item
);
977 dv
->HandleWindowEvent( event
);
979 if (event
.IsAllowed())
980 return GTK_CELL_RENDERER_CLASS(text_cell_parent_class
)->
981 start_editing( gtk_renderer
, gdk_event
, widget
, path
, background_area
, cell_area
, flags
);
986 //-----------------------------------------------------------------------------
987 // define new GTK+ class GtkWxCellRenderer
988 //-----------------------------------------------------------------------------
992 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
993 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
994 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
995 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
996 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
997 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
999 GType
gtk_wx_cell_renderer_get_type (void);
1001 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
1002 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
1004 struct _GtkWxCellRenderer
1006 GtkCellRenderer parent
;
1009 wxDataViewCustomRenderer
*cell
;
1013 struct _GtkWxCellRendererClass
1015 GtkCellRendererClass cell_parent_class
;
1019 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
1020 static void gtk_wx_cell_renderer_init (
1021 GtkWxCellRenderer
*cell
);
1022 static void gtk_wx_cell_renderer_class_init(
1023 GtkWxCellRendererClass
*klass
);
1024 static void gtk_wx_cell_renderer_finalize (
1026 static void gtk_wx_cell_renderer_get_size (
1027 GtkCellRenderer
*cell
,
1029 GdkRectangle
*rectangle
,
1034 static void gtk_wx_cell_renderer_render (
1035 GtkCellRenderer
*cell
,
1038 GdkRectangle
*background_area
,
1039 GdkRectangle
*cell_area
,
1040 GdkRectangle
*expose_area
,
1041 GtkCellRendererState flags
);
1042 static gboolean
gtk_wx_cell_renderer_activate(
1043 GtkCellRenderer
*cell
,
1047 GdkRectangle
*background_area
,
1048 GdkRectangle
*cell_area
,
1049 GtkCellRendererState flags
);
1050 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1051 GtkCellRenderer
*cell
,
1055 GdkRectangle
*background_area
,
1056 GdkRectangle
*cell_area
,
1057 GtkCellRendererState flags
);
1060 static GObjectClass
*cell_parent_class
= NULL
;
1065 gtk_wx_cell_renderer_get_type (void)
1067 static GType cell_wx_type
= 0;
1071 const GTypeInfo cell_wx_info
=
1073 sizeof (GtkWxCellRendererClass
),
1074 NULL
, /* base_init */
1075 NULL
, /* base_finalize */
1076 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
1077 NULL
, /* class_finalize */
1078 NULL
, /* class_data */
1079 sizeof (GtkWxCellRenderer
),
1080 0, /* n_preallocs */
1081 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
1084 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
1085 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
1088 return cell_wx_type
;
1092 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
1095 cell
->last_click
= 0;
1099 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
1101 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1102 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
1104 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
1106 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
1108 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
1109 cell_class
->render
= gtk_wx_cell_renderer_render
;
1110 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
1111 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
1115 gtk_wx_cell_renderer_finalize (GObject
*object
)
1118 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
1122 gtk_wx_cell_renderer_new (void)
1124 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
1127 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1128 GtkCellRenderer
*renderer
,
1129 GdkEvent
*WXUNUSED(event
),
1132 GdkRectangle
*WXUNUSED(background_area
),
1133 GdkRectangle
*cell_area
,
1134 GtkCellRendererState
WXUNUSED(flags
) )
1136 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1137 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1139 // Renderer doesn't support in-place editing
1140 if (!cell
->HasEditorCtrl())
1143 // An in-place editing control is still around
1144 if (cell
->GetEditorCtrl())
1148 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1154 rect
.x
+= cell_area
->x
;
1155 rect
.y
+= cell_area
->y
;
1156 // rect.width -= renderer->xpad * 2;
1157 // rect.height -= renderer->ypad * 2;
1159 // wxRect renderrect(wxRectFromGDKRect(&rect));
1160 wxRect
renderrect(wxRectFromGDKRect(cell_area
));
1162 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
1164 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
1165 wxDataViewItem
item( (void*) iter
.user_data
);
1166 gtk_tree_path_free( treepath
);
1168 cell
->StartEditing( item
, renderrect
);
1174 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
1175 GtkWidget
*WXUNUSED(widget
),
1176 GdkRectangle
*cell_area
,
1182 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1183 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1185 wxSize size
= cell
->GetSize();
1187 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
1188 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
1195 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
1199 *x_offset
= (gint
)((renderer
->xalign
*
1200 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
1201 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
1205 *y_offset
= (gint
)((renderer
->yalign
*
1206 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
1207 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
1212 *width
= calc_width
;
1215 *height
= calc_height
;
1219 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
1222 GdkRectangle
*background_area
,
1223 GdkRectangle
*cell_area
,
1224 GdkRectangle
*expose_area
,
1225 GtkCellRendererState flags
)
1228 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1229 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1231 cell
->GTKStashRenderParams(window
, widget
,
1232 background_area
, expose_area
, flags
);
1234 wxRect
rect(wxRectFromGDKRect(cell_area
));
1235 rect
= rect
.Deflate(renderer
->xpad
, renderer
->ypad
);
1237 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
1238 wxWindowDCImpl
*impl
= (wxWindowDCImpl
*) dc
->GetImpl();
1240 // Reinitialize wxWindowDC's GDK window if drawing occurs into a different
1241 // window such as a DnD drop window.
1242 if (window
!= impl
->m_gdkwindow
)
1245 impl
->m_gdkwindow
= window
;
1250 if (flags
& GTK_CELL_RENDERER_SELECTED
)
1251 state
|= wxDATAVIEW_CELL_SELECTED
;
1252 if (flags
& GTK_CELL_RENDERER_PRELIT
)
1253 state
|= wxDATAVIEW_CELL_PRELIT
;
1254 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1255 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1256 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1257 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1258 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
1259 state
|= wxDATAVIEW_CELL_FOCUSED
;
1260 cell
->WXCallRender( rect
, dc
, state
);
1264 gtk_wx_cell_renderer_activate(
1265 GtkCellRenderer
*renderer
,
1269 GdkRectangle
*WXUNUSED(background_area
),
1270 GdkRectangle
*cell_area
,
1271 GtkCellRendererState
WXUNUSED(flags
) )
1273 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1274 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1277 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1283 rect
.x
+= cell_area
->x
;
1284 rect
.y
+= cell_area
->y
;
1285 rect
.width
-= renderer
->xpad
* 2;
1286 rect
.height
-= renderer
->ypad
* 2;
1288 wxRect
renderrect(wxRectFromGDKRect(&rect
));
1290 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1292 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
1295 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
1296 wxDataViewItem
item( iter
.user_data
);
1297 gtk_tree_path_free( treepath
);
1299 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1305 // activated by <ENTER>
1306 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1311 else if (event
->type
== GDK_BUTTON_PRESS
)
1313 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
1314 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
1315 ((int) button_event
->y
) - renderrect
.y
);
1318 if (button_event
->button
== 1)
1320 if (cell
->LeftClick( pt
, renderrect
, model
, item
, model_col
))
1322 // TODO: query system double-click time
1323 if (button_event
->time
- wxrenderer
->last_click
< 400)
1324 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1327 wxrenderer
->last_click
= button_event
->time
;
1335 // ---------------------------------------------------------
1336 // wxGtkDataViewModelNotifier
1337 // ---------------------------------------------------------
1339 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1342 wxGtkDataViewModelNotifier( GtkWxTreeModel
*wxgtk_model
,
1343 wxDataViewModel
*wx_model
,
1344 wxDataViewCtrl
*ctrl
);
1345 ~wxGtkDataViewModelNotifier();
1347 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1348 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1349 virtual bool ItemChanged( const wxDataViewItem
&item
);
1350 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
1351 virtual bool Cleared();
1352 virtual void Resort();
1354 void SetGtkModel( GtkWxTreeModel
*model
) { m_wxgtk_model
= model
; }
1357 GtkWxTreeModel
*m_wxgtk_model
;
1358 wxDataViewModel
*m_wx_model
;
1359 wxDataViewCtrl
*m_owner
;
1362 // ---------------------------------------------------------
1363 // wxGtkDataViewListModelNotifier
1364 // ---------------------------------------------------------
1366 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1367 GtkWxTreeModel
* wxgtk_model
, wxDataViewModel
*wx_model
,
1368 wxDataViewCtrl
*ctrl
)
1370 m_wxgtk_model
= wxgtk_model
;
1371 m_wx_model
= wx_model
;
1375 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1378 m_wxgtk_model
= NULL
;
1381 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1383 m_owner
->GtkGetInternal()->ItemAdded( parent
, item
);
1386 iter
.stamp
= m_wxgtk_model
->stamp
;
1387 iter
.user_data
= (gpointer
) item
.GetID();
1389 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1390 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1391 gtk_tree_model_row_inserted(
1392 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1393 gtk_tree_path_free (path
);
1398 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1401 // using _get_path for a deleted item cannot be
1404 iter
.stamp
= m_wxgtk_model
->stamp
;
1405 iter
.user_data
= (gpointer
) item
.GetID();
1406 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1407 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1409 // so get the path from the parent
1411 iter
.stamp
= m_wxgtk_model
->stamp
;
1412 iter
.user_data
= (gpointer
) parent
.GetID();
1413 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1414 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1415 // and add the final index ourselves
1416 int index
= m_owner
->GtkGetInternal()->GetIndexOf( parent
, item
);
1417 gtk_tree_path_append_index( path
, index
);
1420 gtk_tree_model_row_deleted(
1421 GTK_TREE_MODEL(m_wxgtk_model
), path
);
1422 gtk_tree_path_free (path
);
1424 m_owner
->GtkGetInternal()->ItemDeleted( parent
, item
);
1429 void wxGtkDataViewModelNotifier::Resort()
1431 m_owner
->GtkGetInternal()->Resort();
1434 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1437 iter
.stamp
= m_wxgtk_model
->stamp
;
1438 iter
.user_data
= (gpointer
) item
.GetID();
1440 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1441 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1442 gtk_tree_model_row_changed(
1443 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1444 gtk_tree_path_free (path
);
1446 m_owner
->GtkGetInternal()->ItemChanged( item
);
1451 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_col
)
1453 // This adds GTK+'s missing MVC logic for ValueChanged
1455 for (index
= 0; index
< m_owner
->GetColumnCount(); index
++)
1457 wxDataViewColumn
*column
= m_owner
->GetColumn( index
);
1458 if (column
->GetModelColumn() == model_col
)
1460 GtkTreeView
*widget
= GTK_TREE_VIEW(m_owner
->m_treeview
);
1461 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1465 iter
.stamp
= m_wxgtk_model
->stamp
;
1466 iter
.user_data
= (gpointer
) item
.GetID();
1467 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1468 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1469 GdkRectangle cell_area
;
1470 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1471 gtk_tree_path_free( path
);
1473 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1474 double d
= gtk_adjustment_get_value( hadjust
);
1475 int xdiff
= (int) d
;
1477 int ydiff
= gcolumn
->button
->allocation
.height
;
1479 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1480 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1482 m_owner
->GtkGetInternal()->ValueChanged( item
, model_col
);
1491 bool wxGtkDataViewModelNotifier::Cleared()
1493 m_owner
->GtkGetInternal()->Cleared();
1498 // ---------------------------------------------------------
1499 // wxDataViewRenderer
1500 // ---------------------------------------------------------
1502 static gpointer s_user_data
= NULL
;
1505 wxgtk_cell_editable_editing_done( GtkCellEditable
*WXUNUSED(editable
),
1506 wxDataViewRenderer
*wxrenderer
)
1508 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1509 wxDataViewCtrl
*dv
= column
->GetOwner();
1510 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1511 event
.SetDataViewColumn( column
);
1512 event
.SetModel( dv
->GetModel() );
1513 wxDataViewItem
item( s_user_data
);
1514 event
.SetItem( item
);
1515 dv
->HandleWindowEvent( event
);
1519 wxgtk_renderer_editing_started( GtkCellRenderer
*WXUNUSED(cell
), GtkCellEditable
*editable
,
1520 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1525 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1526 wxDataViewCtrl
*dv
= column
->GetOwner();
1527 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1528 event
.SetDataViewColumn( column
);
1529 event
.SetModel( dv
->GetModel() );
1530 GtkTreePath
*tree_path
= gtk_tree_path_new_from_string( path
);
1532 dv
->GtkGetInternal()->get_iter( &iter
, tree_path
);
1533 gtk_tree_path_free( tree_path
);
1534 wxDataViewItem
item( iter
.user_data
);
1535 event
.SetItem( item
);
1536 dv
->HandleWindowEvent( event
);
1538 if (GTK_IS_CELL_EDITABLE(editable
))
1540 s_user_data
= iter
.user_data
;
1542 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1543 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1544 (gpointer
) wxrenderer
);
1550 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1552 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1554 wxDataViewRendererBase( varianttype
, mode
, align
)
1558 // we haven't changed them yet
1559 m_usingDefaultAttrs
= true;
1561 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1562 // after the m_renderer pointer has been initialized
1565 void wxDataViewRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
1567 gtk_tree_view_column_pack_end( column
, m_renderer
, TRUE
/* expand */);
1570 void wxDataViewRenderer::GtkInitHandlers()
1572 if (!gtk_check_version(2,6,0))
1574 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1575 G_CALLBACK (wxgtk_renderer_editing_started
),
1580 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1582 GtkCellRendererMode gtkMode
;
1585 case wxDATAVIEW_CELL_INERT
:
1586 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1589 case wxDATAVIEW_CELL_ACTIVATABLE
:
1590 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1593 case wxDATAVIEW_CELL_EDITABLE
:
1594 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1598 wxFAIL_MSG( "unknown wxDataViewCellMode value" );
1602 // This value is most often ignored in GtkTreeView
1603 GValue gvalue
= { 0, };
1604 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1605 g_value_set_enum( &gvalue
, gtkMode
);
1606 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1607 g_value_unset( &gvalue
);
1610 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1612 wxDataViewCellMode ret
;
1615 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1617 switch (g_value_get_enum(&gvalue
))
1620 wxFAIL_MSG( "unknown GtkCellRendererMode value" );
1621 // fall through (we have to return something)
1623 case GTK_CELL_RENDERER_MODE_INERT
:
1624 ret
= wxDATAVIEW_CELL_INERT
;
1627 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1628 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1631 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1632 ret
= wxDATAVIEW_CELL_EDITABLE
;
1636 g_value_unset( &gvalue
);
1641 void wxDataViewRenderer::GtkUpdateAlignment()
1643 int align
= m_alignment
;
1645 // query alignment from column ?
1649 if (GetOwner() == NULL
)
1652 align
= GetOwner()->GetAlignment();
1653 align
|= wxALIGN_CENTRE_VERTICAL
;
1656 // horizontal alignment:
1658 gfloat xalign
= 0.0;
1659 if (align
& wxALIGN_RIGHT
)
1661 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1664 GValue gvalue
= { 0, };
1665 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1666 g_value_set_float( &gvalue
, xalign
);
1667 g_object_set_property( G_OBJECT(m_renderer
), "xalign", &gvalue
);
1668 g_value_unset( &gvalue
);
1670 // vertical alignment:
1672 gfloat yalign
= 0.0;
1673 if (align
& wxALIGN_BOTTOM
)
1675 else if (align
& wxALIGN_CENTER_VERTICAL
)
1678 GValue gvalue2
= { 0, };
1679 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1680 g_value_set_float( &gvalue2
, yalign
);
1681 g_object_set_property( G_OBJECT(m_renderer
), "yalign", &gvalue2
);
1682 g_value_unset( &gvalue2
);
1685 void wxDataViewRenderer::SetAlignment( int align
)
1687 m_alignment
= align
;
1688 GtkUpdateAlignment();
1691 int wxDataViewRenderer::GetAlignment() const
1696 void wxDataViewRenderer::EnableEllipsize(wxEllipsizeMode mode
)
1698 if ( gtk_check_version(2, 6, 0) != NULL
)
1701 GtkCellRendererText
* const rend
= GtkGetTextRenderer();
1705 // we use the same values in wxEllipsizeMode as PangoEllipsizeMode so we
1706 // can just cast between them
1707 GValue gvalue
= { 0, };
1708 g_value_init( &gvalue
, PANGO_TYPE_ELLIPSIZE_MODE
);
1709 g_value_set_enum( &gvalue
, static_cast<PangoEllipsizeMode
>(mode
) );
1710 g_object_set_property( G_OBJECT(rend
), "ellipsize", &gvalue
);
1711 g_value_unset( &gvalue
);
1714 wxEllipsizeMode
wxDataViewRenderer::GetEllipsizeMode() const
1716 if ( gtk_check_version(2, 6, 0) != NULL
)
1717 return wxELLIPSIZE_NONE
;
1719 GtkCellRendererText
* const rend
= GtkGetTextRenderer();
1721 return wxELLIPSIZE_NONE
;
1723 GValue gvalue
= { 0, };
1724 g_value_init( &gvalue
, PANGO_TYPE_ELLIPSIZE_MODE
);
1725 g_object_get_property( G_OBJECT(rend
), "ellipsize", &gvalue
);
1727 mode
= static_cast<wxEllipsizeMode
>(g_value_get_enum( &gvalue
));
1728 g_value_unset( &gvalue
);
1734 wxDataViewRenderer::GtkOnTextEdited(const gchar
*itempath
, const wxString
& str
)
1736 wxVariant
value(str
);
1737 if (!Validate( value
))
1740 GtkTreePath
*path
= gtk_tree_path_new_from_string( itempath
);
1742 GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, path
);
1743 wxDataViewItem
item( (void*) iter
.user_data
);;
1744 gtk_tree_path_free( path
);
1746 GtkOnCellChanged(value
, item
, GetOwner()->GetModelColumn());
1750 wxDataViewRenderer::GtkOnCellChanged(const wxVariant
& value
,
1751 const wxDataViewItem
& item
,
1754 wxDataViewModel
*model
= GetOwner()->GetOwner()->GetModel();
1755 model
->ChangeValue( value
, item
, col
);
1758 // ---------------------------------------------------------
1759 // wxDataViewTextRenderer
1760 // ---------------------------------------------------------
1765 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*WXUNUSED(renderer
),
1766 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1768 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) user_data
;
1770 cell
->GtkOnTextEdited(arg1
, wxGTK_CONV_BACK_FONT(
1771 arg2
, cell
->GetOwner()->GetOwner()->GetFont()));
1779 // helper function used by wxDataViewTextRenderer and
1780 // wxDataViewCustomRenderer::RenderText(): it applies the attributes to the
1781 // given text renderer and returns true if anything was done
1782 bool GtkApplyAttr(GtkCellRendererText
*renderer
, const wxDataViewItemAttr
& attr
)
1784 bool usingDefaultAttrs
= true;
1785 if (attr
.HasColour())
1787 const GdkColor
* const gcol
= attr
.GetColour().GetColor();
1789 GValue gvalue
= { 0, };
1790 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
1791 g_value_set_boxed( &gvalue
, gcol
);
1792 g_object_set_property( G_OBJECT(renderer
), "foreground_gdk", &gvalue
);
1793 g_value_unset( &gvalue
);
1795 usingDefaultAttrs
= false;
1799 GValue gvalue
= { 0, };
1800 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1801 g_value_set_boolean( &gvalue
, FALSE
);
1802 g_object_set_property( G_OBJECT(renderer
), "foreground-set", &gvalue
);
1803 g_value_unset( &gvalue
);
1806 if (attr
.GetItalic())
1808 GValue gvalue
= { 0, };
1809 g_value_init( &gvalue
, PANGO_TYPE_STYLE
);
1810 g_value_set_enum( &gvalue
, PANGO_STYLE_ITALIC
);
1811 g_object_set_property( G_OBJECT(renderer
), "style", &gvalue
);
1812 g_value_unset( &gvalue
);
1814 usingDefaultAttrs
= false;
1818 GValue gvalue
= { 0, };
1819 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1820 g_value_set_boolean( &gvalue
, FALSE
);
1821 g_object_set_property( G_OBJECT(renderer
), "style-set", &gvalue
);
1822 g_value_unset( &gvalue
);
1828 GValue gvalue
= { 0, };
1829 g_value_init( &gvalue
, PANGO_TYPE_WEIGHT
);
1830 g_value_set_enum( &gvalue
, PANGO_WEIGHT_BOLD
);
1831 g_object_set_property( G_OBJECT(renderer
), "weight", &gvalue
);
1832 g_value_unset( &gvalue
);
1834 usingDefaultAttrs
= false;
1838 GValue gvalue
= { 0, };
1839 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1840 g_value_set_boolean( &gvalue
, FALSE
);
1841 g_object_set_property( G_OBJECT(renderer
), "weight-set", &gvalue
);
1842 g_value_unset( &gvalue
);
1846 if (attr
.HasBackgroundColour())
1848 wxColour colour
= attr
.GetBackgroundColour();
1849 const GdkColor
* const gcol
= colour
.GetColor();
1851 GValue gvalue
= { 0, };
1852 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
1853 g_value_set_boxed( &gvalue
, gcol
);
1854 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
1855 g_value_unset( &gvalue
);
1859 GValue gvalue
= { 0, };
1860 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1861 g_value_set_boolean( &gvalue
, FALSE
);
1862 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
1863 g_value_unset( &gvalue
);
1867 return !usingDefaultAttrs
;
1870 } // anonymous namespace
1872 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
1874 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1876 wxDataViewRenderer( varianttype
, mode
, align
)
1878 GtkWxCellRendererText
*text_renderer
= gtk_wx_cell_renderer_text_new();
1879 text_renderer
->wx_renderer
= this;
1880 m_renderer
= (GtkCellRenderer
*) text_renderer
;
1882 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
1884 GValue gvalue
= { 0, };
1885 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1886 g_value_set_boolean( &gvalue
, true );
1887 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
1888 g_value_unset( &gvalue
);
1890 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
1896 SetAlignment(align
);
1899 bool wxDataViewTextRenderer::SetTextValue(const wxString
& str
)
1901 GValue gvalue
= { 0, };
1902 g_value_init( &gvalue
, G_TYPE_STRING
);
1903 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( str
, GetOwner()->GetOwner()->GetFont() ) );
1904 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1905 g_value_unset( &gvalue
);
1910 bool wxDataViewTextRenderer::GetTextValue(wxString
& str
) const
1912 GValue gvalue
= { 0, };
1913 g_value_init( &gvalue
, G_TYPE_STRING
);
1914 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1915 str
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
), const_cast<wxDataViewTextRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
1916 g_value_unset( &gvalue
);
1921 void wxDataViewTextRenderer::SetAlignment( int align
)
1923 wxDataViewRenderer::SetAlignment(align
);
1925 if (gtk_check_version(2,10,0))
1928 // horizontal alignment:
1929 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
1930 if (align
& wxALIGN_RIGHT
)
1931 pangoAlign
= PANGO_ALIGN_RIGHT
;
1932 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1933 pangoAlign
= PANGO_ALIGN_CENTER
;
1935 GValue gvalue
= { 0, };
1936 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1937 g_value_set_enum( &gvalue
, pangoAlign
);
1938 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
1939 g_value_unset( &gvalue
);
1942 bool wxDataViewTextRenderer::GtkSetAttr(const wxDataViewItemAttr
& attr
)
1944 return GtkApplyAttr(GtkGetTextRenderer(), attr
);
1947 GtkCellRendererText
*wxDataViewTextRenderer::GtkGetTextRenderer() const
1949 return GTK_CELL_RENDERER_TEXT(m_renderer
);
1952 // ---------------------------------------------------------
1953 // wxDataViewBitmapRenderer
1954 // ---------------------------------------------------------
1959 // set "pixbuf" property on the given renderer
1960 void SetPixbufProp(GtkCellRenderer
*renderer
, GdkPixbuf
*pixbuf
)
1962 GValue gvalue
= { 0, };
1963 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1964 g_value_set_object( &gvalue
, pixbuf
);
1965 g_object_set_property( G_OBJECT(renderer
), "pixbuf", &gvalue
);
1966 g_value_unset( &gvalue
);
1969 } // anonymous namespace
1971 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
1973 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1975 wxDataViewRenderer( varianttype
, mode
, align
)
1977 m_renderer
= gtk_cell_renderer_pixbuf_new();
1980 SetAlignment(align
);
1983 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
1985 if (value
.GetType() == wxT("wxBitmap"))
1990 // GetPixbuf() may create a Pixbuf representation in the wxBitmap
1991 // object (and it will stay there and remain owned by wxBitmap)
1992 SetPixbufProp(m_renderer
, bitmap
.GetPixbuf());
1994 else if (value
.GetType() == wxT("wxIcon"))
1999 SetPixbufProp(m_renderer
, icon
.GetPixbuf());
2009 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2014 // ---------------------------------------------------------
2015 // wxDataViewToggleRenderer
2016 // ---------------------------------------------------------
2019 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
2020 gchar
*path
, gpointer user_data
);
2023 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
2024 gchar
*path
, gpointer user_data
)
2026 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
2029 GValue gvalue
= { 0, };
2030 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2031 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
2032 bool tmp
= g_value_get_boolean( &gvalue
);
2033 g_value_unset( &gvalue
);
2037 wxVariant value
= tmp
;
2038 if (!cell
->Validate( value
))
2041 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
2043 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
2045 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, gtk_path
);
2046 wxDataViewItem
item( (void*) iter
.user_data
);;
2047 gtk_tree_path_free( gtk_path
);
2049 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
2051 model
->ChangeValue( value
, item
, model_col
);
2054 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
2056 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
2057 wxDataViewCellMode mode
, int align
) :
2058 wxDataViewRenderer( varianttype
, mode
, align
)
2060 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
2062 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
2064 g_signal_connect_after( m_renderer
, "toggled",
2065 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
2069 GValue gvalue
= { 0, };
2070 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2071 g_value_set_boolean( &gvalue
, false );
2072 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
2073 g_value_unset( &gvalue
);
2077 SetAlignment(align
);
2080 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
2084 GValue gvalue
= { 0, };
2085 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2086 g_value_set_boolean( &gvalue
, tmp
);
2087 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
2088 g_value_unset( &gvalue
);
2093 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
2095 GValue gvalue
= { 0, };
2096 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2097 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
2098 bool tmp
= g_value_get_boolean( &gvalue
);
2099 g_value_unset( &gvalue
);
2106 // ---------------------------------------------------------
2107 // wxDataViewCustomRenderer
2108 // ---------------------------------------------------------
2110 class wxDataViewCtrlDCImpl
: public wxWindowDCImpl
2113 wxDataViewCtrlDCImpl( wxDC
*owner
, wxDataViewCtrl
*window
) :
2114 wxWindowDCImpl( owner
)
2116 GtkWidget
*widget
= window
->m_treeview
;
2122 m_context
= window
->GTKGetPangoDefaultContext();
2123 m_layout
= pango_layout_new( m_context
);
2124 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
2126 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
2128 // Set m_gdkwindow later
2133 class wxDataViewCtrlDC
: public wxWindowDC
2136 wxDataViewCtrlDC( wxDataViewCtrl
*window
) :
2137 wxWindowDC( new wxDataViewCtrlDCImpl( this, window
) )
2142 // ---------------------------------------------------------
2143 // wxDataViewCustomRenderer
2144 // ---------------------------------------------------------
2146 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
2148 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
2149 wxDataViewCellMode mode
,
2152 : wxDataViewCustomRendererBase( varianttype
, mode
, align
)
2155 m_text_renderer
= NULL
;
2163 GtkCellRendererText
*wxDataViewCustomRenderer::GtkGetTextRenderer() const
2165 if ( !m_text_renderer
)
2167 // we create it on demand so need to do it even from a const function
2168 const_cast<wxDataViewCustomRenderer
*>(this)->
2169 m_text_renderer
= GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new());
2172 return m_text_renderer
;
2175 void wxDataViewCustomRenderer::RenderText( const wxString
&text
,
2179 int WXUNUSED(state
) )
2182 GtkCellRendererText
* const textRenderer
= GtkGetTextRenderer();
2184 GValue gvalue
= { 0, };
2185 g_value_init( &gvalue
, G_TYPE_STRING
);
2186 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( text
, GetOwner()->GetOwner()->GetFont() ) );
2187 g_object_set_property( G_OBJECT(textRenderer
), "text", &gvalue
);
2188 g_value_unset( &gvalue
);
2190 GtkApplyAttr(textRenderer
, GetAttr());
2192 GdkRectangle cell_area
;
2193 wxRectToGDKRect(cell
, cell_area
);
2194 cell_area
.x
+= xoffset
;
2195 cell_area
.width
-= xoffset
;
2197 gtk_cell_renderer_render( GTK_CELL_RENDERER(textRenderer
),
2198 m_renderParams
.window
,
2199 m_renderParams
.widget
,
2200 m_renderParams
.background_area
,
2202 m_renderParams
.expose_area
,
2203 (GtkCellRendererState
) m_renderParams
.flags
);
2206 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
2208 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
2209 renderer
->cell
= this;
2211 m_renderer
= (GtkCellRenderer
*) renderer
;
2214 SetAlignment(align
);
2221 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
2226 if (m_text_renderer
)
2227 gtk_object_sink( GTK_OBJECT(m_text_renderer
) );
2230 wxDC
*wxDataViewCustomRenderer::GetDC()
2234 if (GetOwner() == NULL
)
2236 if (GetOwner()->GetOwner() == NULL
)
2238 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
2244 // ---------------------------------------------------------
2245 // wxDataViewProgressRenderer
2246 // ---------------------------------------------------------
2248 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
2250 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
2251 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
2252 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
2258 if (!gtk_check_version(2,6,0))
2260 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
2262 GValue gvalue
= { 0, };
2263 g_value_init( &gvalue
, G_TYPE_STRING
);
2265 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( m_label
, GetOwner()->GetOwner()->GetFont() ) );
2266 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2267 g_value_unset( &gvalue
);
2270 SetAlignment(align
);
2275 // Use custom cell code
2276 wxDataViewCustomRenderer::Init(mode
, align
);
2280 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
2284 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
2287 if (!gtk_check_version(2,6,0))
2289 gint tmp
= (long) value
;
2290 GValue gvalue
= { 0, };
2291 g_value_init( &gvalue
, G_TYPE_INT
);
2292 g_value_set_int( &gvalue
, tmp
);
2293 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
2294 g_value_unset( &gvalue
);
2299 m_value
= (long) value
;
2301 if (m_value
< 0) m_value
= 0;
2302 if (m_value
> 100) m_value
= 100;
2308 bool wxDataViewProgressRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2313 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
2315 double pct
= (double)m_value
/ 100.0;
2317 bar
.width
= (int)(cell
.width
* pct
);
2318 dc
->SetPen( *wxTRANSPARENT_PEN
);
2319 dc
->SetBrush( *wxBLUE_BRUSH
);
2320 dc
->DrawRectangle( bar
);
2322 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
2323 dc
->SetPen( *wxBLACK_PEN
);
2324 dc
->DrawRectangle( cell
);
2329 wxSize
wxDataViewProgressRenderer::GetSize() const
2331 return wxSize(40,12);
2334 // -------------------------------------
2335 // wxDataViewChoiceRenderer
2336 // -------------------------------------
2338 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
&choices
,
2339 wxDataViewCellMode mode
, int alignment
) :
2340 wxDataViewCustomRenderer( "string", mode
, alignment
, true )
2342 m_choices
= choices
;
2345 if (!gtk_check_version(2,6,0))
2347 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_combo_new();
2349 GtkListStore
*store
= gtk_list_store_new( 1, G_TYPE_STRING
);
2350 for (size_t n
= 0; n
< m_choices
.GetCount(); n
++)
2352 gtk_list_store_insert_with_values(
2354 static_cast<const char *>(m_choices
[n
].utf8_str()), -1 );
2357 g_object_set (m_renderer
,
2363 bool editable
= (mode
& wxDATAVIEW_CELL_EDITABLE
);
2364 g_object_set (m_renderer
, "editable", editable
, NULL
);
2366 SetAlignment(alignment
);
2368 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2375 // Use custom cell code
2376 wxDataViewCustomRenderer::Init(mode
, alignment
);
2380 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
2382 RenderText( m_data
, 0, rect
, dc
, state
);
2386 wxSize
wxDataViewChoiceRenderer::GetSize() const
2388 return wxSize(70,20);
2391 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
2395 if (!gtk_check_version(2,6,0))
2397 GValue gvalue
= { 0, };
2398 g_value_init( &gvalue
, G_TYPE_STRING
);
2399 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( value
.GetString(), GetOwner()->GetOwner()->GetFont() ) );
2400 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2401 g_value_unset( &gvalue
);
2405 m_data
= value
.GetString();
2410 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
2413 if (!gtk_check_version(2,6,0))
2415 GValue gvalue
= { 0, };
2416 g_value_init( &gvalue
, G_TYPE_STRING
);
2417 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2418 wxString temp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
),
2419 const_cast<wxDataViewChoiceRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
2420 g_value_unset( &gvalue
);
2423 //wxPrintf( "temp %s\n", temp );
2424 // TODO: remove this code
2433 void wxDataViewChoiceRenderer::SetAlignment( int align
)
2435 wxDataViewCustomRenderer::SetAlignment(align
);
2437 if (gtk_check_version(2,10,0))
2440 // horizontal alignment:
2441 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2442 if (align
& wxALIGN_RIGHT
)
2443 pangoAlign
= PANGO_ALIGN_RIGHT
;
2444 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2445 pangoAlign
= PANGO_ALIGN_CENTER
;
2447 GValue gvalue
= { 0, };
2448 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2449 g_value_set_enum( &gvalue
, pangoAlign
);
2450 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2451 g_value_unset( &gvalue
);
2454 // ---------------------------------------------------------
2455 // wxDataViewDateRenderer
2456 // ---------------------------------------------------------
2458 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
2461 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
2462 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
2463 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
2468 m_cal
= new wxCalendarCtrl( this, -1, *value
);
2469 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
2470 sizer
->Add( m_cal
, 1, wxGROW
);
2475 virtual void OnDismiss()
2479 void OnCalendar( wxCalendarEvent
&event
);
2481 wxCalendarCtrl
*m_cal
;
2482 wxDataViewModel
*m_model
;
2483 wxDataViewItem m_item
;
2487 DECLARE_EVENT_TABLE()
2490 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
2491 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
2494 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
2496 m_model
->ChangeValue( event
.GetDate(), m_item
, m_col
);
2500 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
2502 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
2503 wxDataViewCellMode mode
, int align
) :
2504 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2507 SetAlignment(align
);
2510 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
2512 m_date
= value
.GetDateTime();
2517 bool wxDataViewDateRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2522 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2524 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
2525 wxString tmp
= m_date
.FormatDate();
2526 RenderText( tmp
, 0, cell
, dc
, state
);
2530 wxSize
wxDataViewDateRenderer::GetSize() const
2532 wxString tmp
= m_date
.FormatDate();
2534 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
2535 return wxSize(x
,y
+d
);
2538 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
2539 const wxDataViewItem
&item
, unsigned int col
)
2542 model
->GetValue( variant
, item
, col
);
2543 wxDateTime value
= variant
.GetDateTime();
2545 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
2546 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
2547 wxPoint pos
= wxGetMousePosition();
2550 popup
->Popup( popup
->m_cal
);
2556 // ---------------------------------------------------------
2557 // wxDataViewIconTextRenderer
2558 // ---------------------------------------------------------
2560 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
2562 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer
2564 const wxString
&varianttype
,
2565 wxDataViewCellMode mode
,
2568 : wxDataViewTextRenderer(varianttype
, mode
, align
)
2570 m_rendererIcon
= gtk_cell_renderer_pixbuf_new();
2573 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2577 void wxDataViewIconTextRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
2579 // add the icon renderer first
2580 gtk_tree_view_column_pack_start(column
, m_rendererIcon
, FALSE
/* !expand */);
2582 // add the text renderer too
2583 wxDataViewRenderer::GtkPackIntoColumn(column
);
2586 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
2590 SetTextValue(m_value
.GetText());
2591 SetPixbufProp(m_rendererIcon
, m_value
.GetIcon().GetPixbuf());
2596 bool wxDataViewIconTextRenderer::GetValue(wxVariant
& value
) const
2599 if ( !GetTextValue(str
) )
2602 // user doesn't have any way to edit the icon so leave it unchanged
2603 value
<< wxDataViewIconText(str
, m_value
.GetIcon());
2609 wxDataViewIconTextRenderer::GtkOnCellChanged(const wxVariant
& value
,
2610 const wxDataViewItem
& item
,
2613 // we receive just the text part of our value as it's the only one which
2614 // can be edited, but we need the full wxDataViewIconText value for the
2616 wxVariant valueIconText
;
2617 valueIconText
<< wxDataViewIconText(value
.GetString(), m_value
.GetIcon());
2618 wxDataViewTextRenderer::GtkOnCellChanged(valueIconText
, item
, col
);
2621 // ---------------------------------------------------------
2623 // ---------------------------------------------------------
2627 gtk_dataview_header_button_press_callback( GtkWidget
*WXUNUSED(widget
),
2628 GdkEventButton
*gdk_event
,
2629 wxDataViewColumn
*column
)
2631 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
2634 if (gdk_event
->button
== 1)
2636 gs_lastLeftClickHeader
= column
;
2638 wxDataViewCtrl
*dv
= column
->GetOwner();
2639 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
2640 event
.SetDataViewColumn( column
);
2641 event
.SetModel( dv
->GetModel() );
2642 if (dv
->HandleWindowEvent( event
))
2646 if (gdk_event
->button
== 3)
2648 wxDataViewCtrl
*dv
= column
->GetOwner();
2649 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
2650 event
.SetDataViewColumn( column
);
2651 event
.SetModel( dv
->GetModel() );
2652 if (dv
->HandleWindowEvent( event
))
2662 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*WXUNUSED(column
),
2663 GtkCellRenderer
*renderer
,
2664 GtkTreeModel
*model
,
2668 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2669 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2671 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2673 wxDataViewItem
item( (void*) iter
->user_data
);
2675 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
2677 if (!wx_model
->IsVirtualListModel())
2680 if (wx_model
->IsContainer( item
))
2682 visible
= wx_model
->HasContainerColumns( item
) ||
2683 (cell
->GetOwner()->GetModelColumn() == 0);
2690 GValue gvalue
= { 0, };
2691 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2692 g_value_set_boolean( &gvalue
, visible
);
2693 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2694 g_value_unset( &gvalue
);
2701 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
2703 if (value
.GetType() != cell
->GetVariantType())
2705 wxLogError( wxT("Wrong type, required: %s but: %s"),
2706 value
.GetType().c_str(),
2707 cell
->GetVariantType().c_str() );
2710 cell
->SetValue( value
);
2713 // deal with attributes: if the renderer doesn't support them at all, we
2714 // don't even need to query the model for them
2715 if ( !cell
->GtkSupportsAttrs() )
2718 // it can support attributes so check if this item has any
2719 wxDataViewItemAttr attr
;
2720 if ( wx_model
->GetAttr( item
, cell
->GetOwner()->GetModelColumn(), attr
)
2721 || !cell
->GtkIsUsingDefaultAttrs() )
2723 bool usingDefaultAttrs
= !cell
->GtkSetAttr(attr
);
2724 cell
->GtkSetUsingDefaultAttrs(usingDefaultAttrs
);
2726 // else: no custom attributes specified and we're already using the default
2727 // ones -- nothing to do
2732 #include <wx/listimpl.cpp>
2733 WX_DEFINE_LIST(wxDataViewColumnList
)
2735 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
2736 unsigned int model_column
, int width
,
2737 wxAlignment align
, int flags
)
2738 : wxDataViewColumnBase( cell
, model_column
)
2740 Init( align
, flags
, width
);
2745 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
2746 unsigned int model_column
, int width
,
2747 wxAlignment align
, int flags
)
2748 : wxDataViewColumnBase( bitmap
, cell
, model_column
)
2750 Init( align
, flags
, width
);
2752 SetBitmap( bitmap
);
2755 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
2757 m_isConnected
= false;
2759 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
2760 m_column
= (GtkWidget
*) column
;
2763 SetAlignment( align
);
2767 // Create container for icon and label
2768 GtkWidget
*box
= gtk_hbox_new( FALSE
, 1 );
2769 gtk_widget_show( box
);
2770 // gtk_container_set_border_width((GtkContainer*)box, 2);
2771 m_image
= gtk_image_new();
2772 gtk_box_pack_start(GTK_BOX(box
), m_image
, FALSE
, FALSE
, 1);
2773 m_label
= gtk_label_new("");
2774 gtk_box_pack_end( GTK_BOX(box
), GTK_WIDGET(m_label
), FALSE
, FALSE
, 1 );
2775 gtk_tree_view_column_set_widget( column
, box
);
2777 wxDataViewRenderer
* const colRenderer
= GetRenderer();
2778 GtkCellRenderer
* const cellRenderer
= colRenderer
->GetGtkHandle();
2780 colRenderer
->GtkPackIntoColumn(column
);
2782 gtk_tree_view_column_set_cell_data_func( column
, cellRenderer
,
2783 wxGtkTreeCellDataFunc
, (gpointer
) colRenderer
, NULL
);
2786 void wxDataViewColumn::OnInternalIdle()
2791 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
2793 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2796 g_signal_connect(column
->button
, "button_press_event",
2797 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
2799 m_isConnected
= true;
2804 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
2806 wxDataViewColumnBase::SetOwner( owner
);
2808 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2810 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
2813 void wxDataViewColumn::SetTitle( const wxString
&title
)
2815 wxDataViewCtrl
*ctrl
= GetOwner();
2816 gtk_label_set_text( GTK_LABEL(m_label
), ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
2817 : wxGTK_CONV_SYS(title
) );
2819 gtk_widget_hide( m_label
);
2821 gtk_widget_show( m_label
);
2824 wxString
wxDataViewColumn::GetTitle() const
2826 return wxGTK_CONV_BACK_FONT(
2827 gtk_label_get_text( GTK_LABEL(m_label
) ),
2828 GetOwner()->GetFont()
2832 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
2834 wxDataViewColumnBase::SetBitmap( bitmap
);
2838 GtkImage
*gtk_image
= GTK_IMAGE(m_image
);
2840 GdkBitmap
*mask
= NULL
;
2841 if (bitmap
.GetMask())
2842 mask
= bitmap
.GetMask()->GetBitmap();
2844 if (bitmap
.HasPixbuf())
2846 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
2847 bitmap
.GetPixbuf());
2851 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
2852 bitmap
.GetPixmap(), mask
);
2854 gtk_widget_show( m_image
);
2858 gtk_widget_hide( m_image
);
2862 void wxDataViewColumn::SetHidden( bool hidden
)
2864 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
2867 void wxDataViewColumn::SetResizeable( bool resizeable
)
2869 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizeable
);
2872 void wxDataViewColumn::SetAlignment( wxAlignment align
)
2874 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2876 gfloat xalign
= 0.0;
2877 if (align
== wxALIGN_RIGHT
)
2879 if (align
== wxALIGN_CENTER_HORIZONTAL
||
2880 align
== wxALIGN_CENTER
)
2883 gtk_tree_view_column_set_alignment( column
, xalign
);
2885 if (m_renderer
&& m_renderer
->GetAlignment() == -1)
2886 m_renderer
->GtkUpdateAlignment();
2889 wxAlignment
wxDataViewColumn::GetAlignment() const
2891 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
2894 return wxALIGN_RIGHT
;
2896 return wxALIGN_CENTER_HORIZONTAL
;
2898 return wxALIGN_LEFT
;
2901 void wxDataViewColumn::SetSortable( bool sortable
)
2903 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2907 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
2911 gtk_tree_view_column_set_sort_column_id( column
, -1 );
2912 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
2913 gtk_tree_view_column_set_clickable( column
, FALSE
);
2917 bool wxDataViewColumn::IsSortable() const
2919 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2920 return gtk_tree_view_column_get_clickable( column
);
2923 void wxDataViewColumn::SetAsSortKey( bool WXUNUSED(sort
) )
2925 // it might not make sense to have this function in wxHeaderColumn at
2926 // all in fact, changing of the sort order should only be done using the
2927 // associated control API
2928 wxFAIL_MSG( "not implemented" );
2931 bool wxDataViewColumn::IsSortKey() const
2933 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2934 return gtk_tree_view_column_get_sort_indicator( column
);
2937 bool wxDataViewColumn::IsResizeable() const
2939 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2940 return gtk_tree_view_column_get_resizable( column
);
2943 bool wxDataViewColumn::IsHidden() const
2945 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2946 return !gtk_tree_view_column_get_visible( column
);
2949 void wxDataViewColumn::SetSortOrder( bool ascending
)
2951 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2954 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
2956 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
2958 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
2961 bool wxDataViewColumn::IsSortOrderAscending() const
2963 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2965 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
2968 void wxDataViewColumn::SetMinWidth( int width
)
2970 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2973 int wxDataViewColumn::GetMinWidth() const
2975 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2978 int wxDataViewColumn::GetWidth() const
2980 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2983 void wxDataViewColumn::SetWidth( int width
)
2988 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
2990 // TODO find a better calculation
2991 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), wxDVC_DEFAULT_WIDTH
);
2993 // this is unpractical for large numbers of items and disables
2994 // user resizing, which is totally unexpected
2995 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
3000 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
3002 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
3006 void wxDataViewColumn::SetReorderable( bool reorderable
)
3008 gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column
), reorderable
);
3011 bool wxDataViewColumn::IsReorderable() const
3013 return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column
) );
3016 //-----------------------------------------------------------------------------
3017 // wxGtkTreeModelNode
3018 //-----------------------------------------------------------------------------
3021 class wxGtkTreeModelChildWithPos
3029 int wxGtkTreeModelChildWithPosCmp( const void* data1
, const void* data2
, const void* user_data
)
3031 const wxGtkTreeModelChildWithPos
* child1
= (const wxGtkTreeModelChildWithPos
*) data1
;
3032 const wxGtkTreeModelChildWithPos
* child2
= (const wxGtkTreeModelChildWithPos
*) data2
;
3033 const wxDataViewCtrlInternal
*internal
= (const wxDataViewCtrlInternal
*) user_data
;
3034 int ret
= internal
->GetDataViewModel()->Compare( child1
->id
, child2
->id
,
3035 internal
->GetSortColumn(), (internal
->GetSortOrder() == GTK_SORT_DESCENDING
) );
3041 int LINKAGEMODE
wxGtkTreeModelChildPtrCmp( void*** data1
, void*** data2
)
3043 return gs_internal
->GetDataViewModel()->Compare( **data1
, **data2
,
3044 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
3047 WX_DEFINE_ARRAY_PTR( void**, wxGtkTreeModelChildrenPtr
);
3050 void wxGtkTreeModelNode::Resort()
3052 size_t child_count
= GetChildCount();
3053 if (child_count
== 0)
3056 size_t node_count
= GetNodesCount();
3058 if (child_count
== 1)
3060 if (node_count
== 1)
3062 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
3068 gint
*new_order
= new gint
[child_count
];
3071 // m_children has the original *void
3072 // ptrs points to these
3073 wxGtkTreeModelChildrenPtr ptrs
;
3075 for (i
= 0; i
< child_count
; i
++)
3076 ptrs
.Add( &(m_children
[i
]) );
3078 gs_internal
= m_internal
;
3079 ptrs
.Sort( &wxGtkTreeModelChildPtrCmp
);
3081 wxGtkTreeModelChildren temp
;
3082 void** base_ptr
= &(m_children
[0]);
3083 // Transfer positions to new_order array and
3085 for (i
= 0; i
< child_count
; i
++)
3087 new_order
[i
] = ptrs
[i
] - base_ptr
;
3088 temp
.Add( *ptrs
[i
] );
3091 // Transfer IDs back to m_children
3093 WX_APPEND_ARRAY( temp
, m_children
);
3098 // Build up array with IDs and original positions
3099 wxGtkTreeModelChildWithPos
* temp
= new wxGtkTreeModelChildWithPos
[child_count
];
3101 for (i
= 0; i
< child_count
; i
++)
3104 temp
[i
].id
= m_children
[i
];
3106 // Sort array keeping original positions
3107 wxQsort( temp
, child_count
, sizeof(wxGtkTreeModelChildWithPos
),
3108 &wxGtkTreeModelChildWithPosCmp
, m_internal
);
3109 // Transfer positions to new_order array and
3110 // IDs to m_children
3112 for (i
= 0; i
< child_count
; i
++)
3114 new_order
[i
] = temp
[i
].pos
;
3115 m_children
.Add( temp
[i
].id
);
3124 wxGtkTreeModelChildren temp
;
3125 WX_APPEND_ARRAY( temp
, m_children
);
3127 gs_internal
= m_internal
;
3128 m_children
.Sort( &wxGtkTreeModelChildCmp
);
3131 for (pos
= 0; pos
< child_count
; pos
++)
3133 void *id
= m_children
.Item( pos
);
3134 int old_pos
= temp
.Index( id
);
3135 new_order
[pos
] = old_pos
;
3139 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
3142 iter
.user_data
= GetItem().GetID();
3143 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
3145 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3147 gtk_tree_model_rows_reordered( gtk_tree_model
, path
, &iter
, new_order
);
3149 gtk_tree_path_free (path
);
3151 delete [] new_order
;
3154 for (pos
= 0; pos
< node_count
; pos
++)
3156 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
3161 //-----------------------------------------------------------------------------
3162 // wxDataViewCtrlInternal
3163 //-----------------------------------------------------------------------------
3165 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
,
3166 wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
)
3169 m_wx_model
= wx_model
;
3170 m_gtk_model
= gtk_model
;
3172 m_sort_order
= GTK_SORT_ASCENDING
;
3174 m_dataview_sort_column
= NULL
;
3176 m_dragDataObject
= NULL
;
3177 m_dropDataObject
= NULL
;
3179 if (!m_wx_model
->IsVirtualListModel())
3183 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
3185 g_object_unref( m_gtk_model
);
3187 delete m_dragDataObject
;
3188 delete m_dropDataObject
;
3191 void wxDataViewCtrlInternal::InitTree()
3193 wxDataViewItem item
;
3194 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
3196 BuildBranch( m_root
);
3199 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
3201 if (node
->GetChildCount() == 0)
3203 wxDataViewItemArray children
;
3204 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
3206 for (pos
= 0; pos
< count
; pos
++)
3208 wxDataViewItem child
= children
[pos
];
3210 if (m_wx_model
->IsContainer( child
))
3211 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
3213 node
->AddLeave( child
.GetID() );
3215 // Don't send any events here
3222 bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat
&format
)
3224 wxGtkString
atom_str( gdk_atom_name( format
) );
3225 m_dragSourceTargetEntryTarget
= wxCharBuffer( atom_str
);
3227 m_dragSourceTargetEntry
.target
= m_dragSourceTargetEntryTarget
.data();
3228 m_dragSourceTargetEntry
.flags
= 0;
3229 m_dragSourceTargetEntry
.info
= static_cast<guint
>(-1);
3231 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3232 GDK_BUTTON1_MASK
, &m_dragSourceTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3237 bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat
&format
)
3239 wxGtkString
atom_str( gdk_atom_name( format
) );
3240 m_dropTargetTargetEntryTarget
= wxCharBuffer( atom_str
);
3242 m_dropTargetTargetEntry
.target
= m_dropTargetTargetEntryTarget
.data();
3243 m_dropTargetTargetEntry
.flags
= 0;
3244 m_dropTargetTargetEntry
.info
= static_cast<guint
>(-1);
3246 gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3247 &m_dropTargetTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3252 gboolean
wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource
*WXUNUSED(drag_source
),
3255 delete m_dragDataObject
;
3258 if (!get_iter( &iter
, path
)) return FALSE
;
3259 wxDataViewItem
item( (void*) iter
.user_data
);
3261 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3262 event
.SetEventObject( m_owner
);
3263 event
.SetItem( item
);
3264 event
.SetModel( m_wx_model
);
3265 if (!m_owner
->HandleWindowEvent( event
))
3268 if (!event
.IsAllowed())
3271 wxDataObject
*obj
= event
.GetDataObject();
3275 m_dragDataObject
= obj
;
3281 wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource
*WXUNUSED(drag_source
),
3282 GtkTreePath
*WXUNUSED(path
))
3287 gboolean
wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource
*WXUNUSED(drag_source
),
3288 GtkTreePath
*path
, GtkSelectionData
*selection_data
)
3291 if (!get_iter( &iter
, path
)) return FALSE
;
3292 wxDataViewItem
item( (void*) iter
.user_data
);
3294 if (!m_dragDataObject
->IsSupported( selection_data
->target
))
3297 size_t size
= m_dragDataObject
->GetDataSize( selection_data
->target
);
3301 void *buf
= malloc( size
);
3303 gboolean res
= FALSE
;
3304 if (m_dragDataObject
->GetDataHere( selection_data
->target
, buf
))
3308 gtk_selection_data_set( selection_data
, selection_data
->target
,
3309 8, (const guchar
*) buf
, size
);
3318 wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3320 GtkSelectionData
*selection_data
)
3323 if (!get_iter( &iter
, path
)) return FALSE
;
3324 wxDataViewItem
item( (void*) iter
.user_data
);
3326 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
3327 event
.SetEventObject( m_owner
);
3328 event
.SetItem( item
);
3329 event
.SetModel( m_wx_model
);
3330 event
.SetDataFormat( selection_data
->target
);
3331 event
.SetDataSize( selection_data
->length
);
3332 event
.SetDataBuffer( selection_data
->data
);
3333 if (!m_owner
->HandleWindowEvent( event
))
3336 if (!event
.IsAllowed())
3343 wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3345 GtkSelectionData
*selection_data
)
3348 if (!get_iter( &iter
, path
)) return FALSE
;
3349 wxDataViewItem
item( (void*) iter
.user_data
);
3351 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
3352 event
.SetEventObject( m_owner
);
3353 event
.SetItem( item
);
3354 event
.SetModel( m_wx_model
);
3355 event
.SetDataFormat( selection_data
->target
);
3356 if (!m_owner
->HandleWindowEvent( event
))
3359 if (!event
.IsAllowed())
3365 // notifications from wxDataViewModel
3367 bool wxDataViewCtrlInternal::Cleared()
3369 GtkWidget
* tree_widget
= GetOwner()->GtkGetTreeView();
3370 gtk_tree_view_set_model( GTK_TREE_VIEW(tree_widget
), NULL
);
3371 gtk_tree_view_set_model( GTK_TREE_VIEW(tree_widget
), GTK_TREE_MODEL(m_gtk_model
) );
3382 void wxDataViewCtrlInternal::Resort()
3384 if (!m_wx_model
->IsVirtualListModel())
3388 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3390 if (!m_wx_model
->IsVirtualListModel())
3392 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3393 wxASSERT_MSG(parent_node
,
3394 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3396 if (m_wx_model
->IsContainer( item
))
3397 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
3399 parent_node
->AddLeave( item
.GetID() );
3405 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3407 if (!m_wx_model
->IsVirtualListModel())
3409 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3410 wxASSERT_MSG(parent_node
,
3411 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3413 parent_node
->DeleteChild( item
.GetID() );
3419 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
3421 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3422 event
.SetEventObject( m_owner
);
3423 event
.SetModel( m_owner
->GetModel() );
3424 event
.SetItem( item
);
3425 m_owner
->HandleWindowEvent( event
);
3430 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
3432 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3433 event
.SetEventObject( m_owner
);
3434 event
.SetModel( m_owner
->GetModel() );
3435 event
.SetColumn( col
);
3436 event
.SetDataViewColumn( GetOwner()->GetColumn(col
) );
3437 event
.SetItem( item
);
3438 m_owner
->HandleWindowEvent( event
);
3445 GtkTreeModelFlags
wxDataViewCtrlInternal::get_flags()
3447 if (m_wx_model
->IsVirtualListModel())
3448 return GTK_TREE_MODEL_LIST_ONLY
;
3450 return GTK_TREE_MODEL_ITERS_PERSIST
;
3453 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
3456 if (m_wx_model
->IsVirtualListModel())
3458 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3460 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
3462 if (i
>= wx_model
->GetCount())
3465 iter
->stamp
= m_gtk_model
->stamp
;
3466 // user_data is just the index +1
3467 iter
->user_data
= (gpointer
) (i
+1);
3473 int depth
= gtk_tree_path_get_depth( path
);
3475 wxGtkTreeModelNode
*node
= m_root
;
3478 for (i
= 0; i
< depth
; i
++)
3480 BuildBranch( node
);
3482 gint pos
= gtk_tree_path_get_indices (path
)[i
];
3483 if (pos
< 0) return FALSE
;
3484 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
3486 void* id
= node
->GetChildren().Item( (size_t) pos
);
3490 iter
->stamp
= m_gtk_model
->stamp
;
3491 iter
->user_data
= id
;
3495 size_t count
= node
->GetNodes().GetCount();
3497 for (pos2
= 0; pos2
< count
; pos2
++)
3499 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
3500 if (child_node
->GetItem().GetID() == id
)
3512 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
3514 // When this is called from ItemDeleted(), the item is already
3515 // deleted in the model.
3517 GtkTreePath
*retval
= gtk_tree_path_new ();
3519 if (m_wx_model
->IsVirtualListModel())
3521 // user_data is just the index +1
3522 int i
= ( (wxUIntPtr
) iter
->user_data
) -1;
3523 gtk_tree_path_append_index (retval
, i
);
3527 void *id
= iter
->user_data
;
3529 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
3532 int pos
= node
->GetChildren().Index( id
);
3534 gtk_tree_path_prepend_index( retval
, pos
);
3536 id
= node
->GetItem().GetID();
3537 node
= node
->GetParent();
3544 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
3546 if (m_wx_model
->IsVirtualListModel())
3548 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3550 // user_data is just the index +1
3551 int n
= ( (wxUIntPtr
) iter
->user_data
) -1;
3555 iter
->user_data
= NULL
;
3559 if (n
>= (int) wx_model
->GetCount()-1)
3561 iter
->user_data
= NULL
;
3565 // user_data is just the index +1 (+2 because we need the next)
3566 iter
->user_data
= (gpointer
) (n
+2);
3570 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
3571 if( parent
== NULL
)
3573 iter
->user_data
= NULL
;
3577 int pos
= parent
->GetChildren().Index( iter
->user_data
);
3579 if (pos
== (int) parent
->GetChildCount()-1)
3581 iter
->user_data
= NULL
;
3585 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
3591 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
3593 if (m_wx_model
->IsVirtualListModel())
3595 // this is a list, nodes have no children
3599 iter
->stamp
= m_gtk_model
->stamp
;
3600 iter
->user_data
= (gpointer
) 1;
3608 if (m_root
->GetChildCount() == 0) return FALSE
;
3609 iter
->stamp
= m_gtk_model
->stamp
;
3610 iter
->user_data
= (gpointer
) m_root
->GetChildren().Item( 0 );
3614 wxDataViewItem
item( (void*) parent
->user_data
);
3616 if (!m_wx_model
->IsContainer( item
))
3619 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3620 wxASSERT_MSG(parent_node
,
3621 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3623 BuildBranch( parent_node
);
3625 if (parent_node
->GetChildCount() == 0)
3628 iter
->stamp
= m_gtk_model
->stamp
;
3629 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
3635 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
3637 if (m_wx_model
->IsVirtualListModel())
3639 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3642 return (wx_model
->GetCount() > 0);
3644 // this is a list, nodes have no children
3650 return (m_root
->GetChildCount() > 0);
3652 wxDataViewItem
item( (void*) iter
->user_data
);
3654 bool is_container
= m_wx_model
->IsContainer( item
);
3659 wxGtkTreeModelNode
*node
= FindNode( iter
);
3661 "Did you forget a call to ItemAdded()? The iterator is unknown to the wxGtkTreeModel");
3663 BuildBranch( node
);
3665 return (node
->GetChildCount() > 0);
3669 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
3671 if (m_wx_model
->IsVirtualListModel())
3673 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3676 return (gint
) wx_model
->GetCount();
3683 return m_root
->GetChildCount();
3685 wxDataViewItem
item( (void*) iter
->user_data
);
3687 if (!m_wx_model
->IsContainer( item
))
3690 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
3691 wxASSERT_MSG(parent_node
,
3692 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3694 BuildBranch( parent_node
);
3696 return parent_node
->GetChildCount();
3700 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
3702 if (m_wx_model
->IsVirtualListModel())
3704 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3712 if (n
>= (gint
) wx_model
->GetCount())
3715 iter
->stamp
= m_gtk_model
->stamp
;
3716 // user_data is just the index +1
3717 iter
->user_data
= (gpointer
) (n
+1);
3724 if (parent
) id
= (void*) parent
->user_data
;
3725 wxDataViewItem
item( id
);
3727 if (!m_wx_model
->IsContainer( item
))
3730 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3731 wxASSERT_MSG(parent_node
,
3732 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3734 BuildBranch( parent_node
);
3736 iter
->stamp
= m_gtk_model
->stamp
;
3737 iter
->user_data
= parent_node
->GetChildren().Item( n
);
3743 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
3745 if (m_wx_model
->IsVirtualListModel())
3751 wxGtkTreeModelNode
*node
= FindParentNode( child
);
3755 iter
->stamp
= m_gtk_model
->stamp
;
3756 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
3762 // item can be deleted already in the model
3763 int wxDataViewCtrlInternal::GetIndexOf( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3765 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3766 wxGtkTreeModelChildren
&children
= parent_node
->GetChildren();
3768 for (j
= 0; j
< children
.GetCount(); j
++)
3770 if (children
[j
] == item
.GetID())
3777 static wxGtkTreeModelNode
*
3778 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3784 list
.DeleteContents( true );
3785 wxDataViewItem
it( item
);
3789 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3790 list
.Insert( pItem
);
3791 it
= model
->GetParent( it
);
3794 wxGtkTreeModelNode
* node
= treeNode
;
3795 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3797 if( node
&& node
->GetNodes().GetCount() != 0 )
3799 int len
= node
->GetNodes().GetCount();
3800 wxGtkTreeModelNodes
&nodes
= node
->GetNodes();
3802 for( ; j
< len
; j
++)
3804 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3823 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
3828 wxDataViewItem
item( (void*) iter
->user_data
);
3832 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3837 wxLogDebug( "Not found %p", iter->user_data );
3841 // TODO: remove this code
3847 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
3852 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3857 wxLogDebug( "Not found %p", item.GetID() );
3861 // TODO: remove this code
3867 static wxGtkTreeModelNode
*
3868 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3874 list
.DeleteContents( true );
3878 wxDataViewItem
it( model
->GetParent( item
) );
3881 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3882 list
.Insert( pItem
);
3883 it
= model
->GetParent( it
);
3886 wxGtkTreeModelNode
* node
= treeNode
;
3887 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3889 if( node
&& node
->GetNodes().GetCount() != 0 )
3891 int len
= node
->GetNodes().GetCount();
3892 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3894 for( ; j
< len
; j
++)
3896 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3911 //Examine whether the node is item's parent node
3912 int len
= node
->GetChildCount();
3913 for( int i
= 0; i
< len
; i
++ )
3915 if( node
->GetChildren().Item( i
) == item
.GetID() )
3921 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
3926 wxDataViewItem
item( (void*) iter
->user_data
);
3930 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3933 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
3938 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3941 //-----------------------------------------------------------------------------
3942 // wxDataViewCtrl signal callbacks
3943 //-----------------------------------------------------------------------------
3946 wxdataview_selection_changed_callback( GtkTreeSelection
* WXUNUSED(selection
), wxDataViewCtrl
*dv
)
3948 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
3951 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
3952 event
.SetItem( dv
->GetSelection() );
3953 event
.SetModel( dv
->GetModel() );
3954 dv
->HandleWindowEvent( event
);
3958 wxdataview_row_activated_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreePath
*path
,
3959 GtkTreeViewColumn
*WXUNUSED(column
), wxDataViewCtrl
*dv
)
3961 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
3964 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3965 wxDataViewItem
item( (void*) iter
.user_data
);;
3966 event
.SetItem( item
);
3967 event
.SetModel( dv
->GetModel() );
3968 dv
->HandleWindowEvent( event
);
3972 wxdataview_test_expand_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3973 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3975 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
3977 wxDataViewItem
item( (void*) iter
->user_data
);;
3978 event
.SetItem( item
);
3979 event
.SetModel( dv
->GetModel() );
3980 dv
->HandleWindowEvent( event
);
3982 return !event
.IsAllowed();
3986 wxdataview_row_expanded_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3987 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3989 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
3991 wxDataViewItem
item( (void*) iter
->user_data
);;
3992 event
.SetItem( item
);
3993 event
.SetModel( dv
->GetModel() );
3994 dv
->HandleWindowEvent( event
);
3998 wxdataview_test_collapse_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3999 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4001 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
4003 wxDataViewItem
item( (void*) iter
->user_data
);;
4004 event
.SetItem( item
);
4005 event
.SetModel( dv
->GetModel() );
4006 dv
->HandleWindowEvent( event
);
4008 return !event
.IsAllowed();
4012 wxdataview_row_collapsed_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4013 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4015 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
4017 wxDataViewItem
item( (void*) iter
->user_data
);;
4018 event
.SetItem( item
);
4019 event
.SetModel( dv
->GetModel() );
4020 dv
->HandleWindowEvent( event
);
4023 //-----------------------------------------------------------------------------
4025 //-----------------------------------------------------------------------------
4027 void wxDataViewCtrl::AddChildGTK(wxWindowGTK
* child
)
4029 GtkWidget
* treeview
= GtkGetTreeView();
4031 // Insert widget in GtkTreeView
4032 if (GTK_WIDGET_REALIZED(treeview
))
4033 gtk_widget_set_parent_window( child
->m_widget
,
4034 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
4035 gtk_widget_set_parent( child
->m_widget
, treeview
);
4039 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
4040 GtkAllocation
*WXUNUSED(gtk_alloc
),
4041 wxDataViewCtrl
*win
)
4043 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
4046 wxWindow
*child
= node
->GetData();
4049 gtk_widget_size_request( child
->m_widget
, &req
);
4051 GtkAllocation alloc
;
4052 alloc
.x
= child
->m_x
;
4053 alloc
.y
= child
->m_y
;
4054 alloc
.width
= child
->m_width
;
4055 alloc
.height
= child
->m_height
;
4056 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
4058 node
= node
->GetNext();
4063 //-----------------------------------------------------------------------------
4064 // "motion_notify_event"
4065 //-----------------------------------------------------------------------------
4068 gtk_dataview_motion_notify_callback( GtkWidget
*WXUNUSED(widget
),
4069 GdkEventMotion
*gdk_event
,
4070 wxDataViewCtrl
*dv
)
4072 if (gdk_event
->is_hint
)
4076 GdkModifierType state
;
4077 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
4082 GtkTreePath
*path
= NULL
;
4083 GtkTreeViewColumn
*column
= NULL
;
4086 if (gtk_tree_view_get_path_at_pos(
4087 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4088 (int) gdk_event
->x
, (int) gdk_event
->y
,
4097 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4099 gtk_tree_path_free( path
);
4107 //-----------------------------------------------------------------------------
4108 // "button_press_event"
4109 //-----------------------------------------------------------------------------
4112 gtk_dataview_button_press_callback( GtkWidget
*WXUNUSED(widget
),
4113 GdkEventButton
*gdk_event
,
4114 wxDataViewCtrl
*dv
)
4116 if ((gdk_event
->button
== 3) && (gdk_event
->type
== GDK_BUTTON_PRESS
))
4118 GtkTreePath
*path
= NULL
;
4119 GtkTreeViewColumn
*column
= NULL
;
4122 if (gtk_tree_view_get_path_at_pos(
4123 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4124 (int) gdk_event
->x
, (int) gdk_event
->y
,
4133 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4135 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, dv
->GetId() );
4136 wxDataViewItem
item( (void*) iter
.user_data
);;
4137 event
.SetItem( item
);
4138 event
.SetModel( dv
->GetModel() );
4139 bool ret
= dv
->HandleWindowEvent( event
);
4140 gtk_tree_path_free( path
);
4149 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
4151 wxDataViewCtrl::~wxDataViewCtrl()
4154 GetModel()->RemoveNotifier( m_notifier
);
4158 // remove the model from the GtkTreeView before it gets destroyed by the
4159 // wxDataViewCtrlBase's dtor
4160 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), NULL
);
4165 void wxDataViewCtrl::Init()
4170 m_cols
.DeleteContents( true );
4173 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
4174 const wxPoint
& pos
, const wxSize
& size
,
4175 long style
, const wxValidator
& validator
)
4177 if (!PreCreation( parent
, pos
, size
) ||
4178 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
4180 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
4184 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
4185 g_object_ref(m_widget
);
4187 GTKScrolledWindowSetBorder(m_widget
, style
);
4189 m_treeview
= gtk_tree_view_new();
4190 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
4192 g_signal_connect (m_treeview
, "size_allocate",
4193 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
4196 if (!gtk_check_version(2,6,0))
4198 bool fixed
= (style
& wxDV_VARIABLE_LINE_HEIGHT
) == 0;
4199 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4203 if (style
& wxDV_MULTIPLE
)
4205 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4206 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
4209 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
4212 if (!gtk_check_version(2,10,0))
4214 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
4216 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
4217 (style
& wxDV_VERT_RULES
) != 0)
4218 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
4219 else if (style
& wxDV_VERT_RULES
)
4220 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
4221 else if (style
& wxDV_HORIZ_RULES
)
4222 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
4224 if (grid
!= GTK_TREE_VIEW_GRID_LINES_NONE
)
4225 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
4229 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_ROW_LINES
) != 0 );
4231 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
4232 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
4233 gtk_widget_show (m_treeview
);
4235 m_parent
->DoAddChild( this );
4239 GtkEnableSelectionEvents();
4241 g_signal_connect_after (m_treeview
, "row-activated",
4242 G_CALLBACK (wxdataview_row_activated_callback
), this);
4244 g_signal_connect (m_treeview
, "test-collapse-row",
4245 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
4247 g_signal_connect_after (m_treeview
, "row-collapsed",
4248 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
4250 g_signal_connect (m_treeview
, "test-expand-row",
4251 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
4253 g_signal_connect_after (m_treeview
, "row-expanded",
4254 G_CALLBACK (wxdataview_row_expanded_callback
), this);
4256 g_signal_connect (m_treeview
, "motion_notify_event",
4257 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
4259 g_signal_connect (m_treeview
, "button_press_event",
4260 G_CALLBACK (gtk_dataview_button_press_callback
), this);
4265 void wxDataViewCtrl::OnInternalIdle()
4267 wxWindow::OnInternalIdle();
4269 unsigned int cols
= GetColumnCount();
4271 for (i
= 0; i
< cols
; i
++)
4273 wxDataViewColumn
*col
= GetColumn( i
);
4274 col
->OnInternalIdle();
4278 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4286 if (!wxDataViewCtrlBase::AssociateModel( model
))
4290 if (!gtk_check_version(2,6,0))
4292 bool fixed
= (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
) == 0) || (model
->IsVirtualListModel()));
4293 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4297 GtkWxTreeModel
*gtk_model
= wxgtk_tree_model_new();
4298 m_internal
= new wxDataViewCtrlInternal( this, model
, gtk_model
);
4299 gtk_model
->internal
= m_internal
;
4301 m_notifier
= new wxGtkDataViewModelNotifier( gtk_model
, model
, this );
4303 model
->AddNotifier( m_notifier
);
4305 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_model
) );
4307 // unref in wxDataViewCtrlInternal
4308 // g_object_unref( gtk_model );
4313 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4315 return m_internal
->EnableDragSource( format
);
4318 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4320 return m_internal
->EnableDropTarget( format
);
4323 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4325 if (!wxDataViewCtrlBase::AppendColumn(col
))
4328 m_cols
.Append( col
);
4331 if (!gtk_check_version(2,6,0))
4333 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4334 GTK_TREE_VIEW_COLUMN_FIXED
)
4335 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4339 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
4340 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4345 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4347 if (!wxDataViewCtrlBase::PrependColumn(col
))
4350 m_cols
.Insert( col
);
4353 if (!gtk_check_version(2,6,0))
4355 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4356 GTK_TREE_VIEW_COLUMN_FIXED
)
4357 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4361 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4362 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
4367 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4369 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4372 m_cols
.Insert( pos
, col
);
4375 if (!gtk_check_version(2,6,0))
4377 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4378 GTK_TREE_VIEW_COLUMN_FIXED
)
4379 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4383 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4384 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), pos
);
4389 unsigned int wxDataViewCtrl::GetColumnCount() const
4391 return m_cols
.GetCount();
4394 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
4396 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
4400 wxDataViewColumnList::const_iterator iter
;
4401 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4403 wxDataViewColumn
*col
= *iter
;
4404 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
4413 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4415 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4416 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
4418 m_cols
.DeleteObject( column
);
4423 bool wxDataViewCtrl::ClearColumns()
4425 wxDataViewColumnList::iterator iter
;
4426 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4428 wxDataViewColumn
*col
= *iter
;
4429 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4430 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4438 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4440 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetConstGtkHandle());
4442 GList
*list
= gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview
) );
4444 gint pos
= g_list_index( list
, (gconstpointer
) gtk_column
);
4446 g_list_free( list
);
4451 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4453 return m_internal
->GetDataViewSortColumn();
4456 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4459 iter
.user_data
= item
.GetID();
4460 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4461 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
4462 gtk_tree_path_free( path
);
4465 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4468 iter
.user_data
= item
.GetID();
4469 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4470 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
4471 gtk_tree_path_free( path
);
4474 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4477 iter
.user_data
= item
.GetID();
4478 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4479 bool res
= gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview
), path
);
4480 gtk_tree_path_free( path
);
4485 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4487 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4489 if (m_windowStyle
& wxDV_MULTIPLE
)
4491 // Report the first one
4492 GtkTreeModel
*model
;
4493 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4497 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4499 m_internal
->get_iter( &iter
, path
);
4502 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4503 g_list_free( list
);
4505 return wxDataViewItem( (void*) iter
.user_data
);
4511 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
4513 wxDataViewItem
item( (void*) iter
.user_data
);
4518 return wxDataViewItem(0);
4521 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4525 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4526 if (HasFlag(wxDV_MULTIPLE
))
4528 GtkTreeModel
*model
;
4529 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4534 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4537 m_internal
->get_iter( &iter
, path
);
4539 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4541 list
= g_list_next( list
);
4546 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4547 g_list_free( list
);
4553 GtkTreeModel
*model
;
4555 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
4558 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4566 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4568 GtkDisableSelectionEvents();
4570 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4572 gtk_tree_selection_unselect_all( selection
);
4574 wxDataViewItem last_parent
;
4577 for (i
= 0; i
< sel
.GetCount(); i
++)
4579 wxDataViewItem item
= sel
[i
];
4580 wxDataViewItem parent
= GetModel()->GetParent( item
);
4583 if (parent
!= last_parent
)
4584 ExpandAncestors(item
);
4586 last_parent
= parent
;
4589 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4590 iter
.user_data
= (gpointer
) item
.GetID();
4591 gtk_tree_selection_select_iter( selection
, &iter
);
4594 GtkEnableSelectionEvents();
4597 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4599 ExpandAncestors(item
);
4601 GtkDisableSelectionEvents();
4603 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4606 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4607 iter
.user_data
= (gpointer
) item
.GetID();
4608 gtk_tree_selection_select_iter( selection
, &iter
);
4610 GtkEnableSelectionEvents();
4613 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4615 GtkDisableSelectionEvents();
4617 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4620 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4621 iter
.user_data
= (gpointer
) item
.GetID();
4622 gtk_tree_selection_unselect_iter( selection
, &iter
);
4624 GtkEnableSelectionEvents();
4627 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4629 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4632 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4633 iter
.user_data
= (gpointer
) item
.GetID();
4635 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
4638 void wxDataViewCtrl::SelectAll()
4640 GtkDisableSelectionEvents();
4642 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4644 gtk_tree_selection_select_all( selection
);
4646 GtkEnableSelectionEvents();
4649 void wxDataViewCtrl::UnselectAll()
4651 GtkDisableSelectionEvents();
4653 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4655 gtk_tree_selection_unselect_all( selection
);
4657 GtkEnableSelectionEvents();
4660 void wxDataViewCtrl::EnsureVisible(const wxDataViewItem
& item
,
4661 const wxDataViewColumn
*WXUNUSED(column
))
4663 ExpandAncestors(item
);
4666 iter
.user_data
= (gpointer
) item
.GetID();
4667 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4668 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
4669 gtk_tree_path_free( path
);
4672 void wxDataViewCtrl::HitTest(const wxPoint
& WXUNUSED(point
),
4673 wxDataViewItem
& item
,
4674 wxDataViewColumn
*& column
) const
4676 item
= wxDataViewItem(0);
4681 wxDataViewCtrl::GetItemRect(const wxDataViewItem
& WXUNUSED(item
),
4682 const wxDataViewColumn
*WXUNUSED(column
)) const
4687 void wxDataViewCtrl::DoSetExpanderColumn()
4689 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
4690 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
4693 void wxDataViewCtrl::DoSetIndent()
4697 void wxDataViewCtrl::GtkDisableSelectionEvents()
4699 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4700 g_signal_handlers_disconnect_by_func( selection
,
4701 (gpointer
) (wxdataview_selection_changed_callback
), this);
4704 void wxDataViewCtrl::GtkEnableSelectionEvents()
4706 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4707 g_signal_connect_after (selection
, "changed",
4708 G_CALLBACK (wxdataview_selection_changed_callback
), this);
4711 // ----------------------------------------------------------------------------
4712 // visual attributes stuff
4713 // ----------------------------------------------------------------------------
4717 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
4719 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
4722 void wxDataViewCtrl::DoApplyWidgetStyle(GtkRcStyle
*style
)
4724 wxDataViewCtrlBase::DoApplyWidgetStyle(style
);
4725 gtk_widget_modify_style(m_treeview
, style
);
4728 #endif // !wxUSE_GENERICDATAVIEWCTRL
4730 #endif // wxUSE_DATAVIEWCTRL