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
);
628 g_return_val_if_fail (wxtree_model
->stamp
== parent
->stamp
, FALSE
);
631 return wxtree_model
->internal
->iter_children( iter
, parent
);
635 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
638 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
639 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
640 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
642 return wxtree_model
->internal
->iter_has_child( iter
);
646 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
649 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
650 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
651 g_return_val_if_fail ( !iter
|| wxtree_model
->stamp
== iter
->stamp
, 0);
653 return wxtree_model
->internal
->iter_n_children( iter
);
657 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
662 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
663 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
665 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
669 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
673 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
674 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
675 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
677 return wxtree_model
->internal
->iter_parent( iter
, child
);
680 /* drag'n'drop iface */
682 wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
685 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
686 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
688 return wxtree_model
->internal
->row_draggable( drag_source
, path
);
692 wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
695 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
696 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
698 return wxtree_model
->internal
->drag_data_delete( drag_source
, path
);
702 wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
704 GtkSelectionData
*selection_data
)
706 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
707 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
710 wxPrintf( "drag_get_data\n");
712 wxGtkString
atom_selection(gdk_atom_name(selection_data
->selection
));
713 wxPrintf( "selection %s\n", wxString::FromAscii(atom_selection
) );
715 wxGtkString
atom_target(gdk_atom_name(selection_data
->target
));
716 wxPrintf( "target %s\n", wxString::FromAscii(atom_target
) );
718 wxGtkString
atom_type(gdk_atom_name(selection_data
->type
));
719 wxPrintf( "type %s\n", wxString::FromAscii(atom_type
) );
721 wxPrintf( "format %d\n", selection_data
->format
);
724 return wxtree_model
->internal
->drag_data_get( drag_source
, path
, selection_data
);
728 wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
730 GtkSelectionData
*selection_data
)
732 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
733 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
735 return wxtree_model
->internal
->drag_data_received( drag_dest
, dest
, selection_data
);
739 wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
740 GtkTreePath
*dest_path
,
741 GtkSelectionData
*selection_data
)
743 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
744 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
746 return wxtree_model
->internal
->row_drop_possible( drag_dest
, dest_path
, selection_data
);
751 wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
752 gint
*sort_column_id
,
755 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) sortable
;
757 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
759 if (!wxtree_model
->internal
->IsSorted())
762 *sort_column_id
= -1;
769 *sort_column_id
= wxtree_model
->internal
->GetSortColumn();
772 *order
= wxtree_model
->internal
->GetSortOrder();
777 wxDataViewColumn
*gs_lastLeftClickHeader
= NULL
;
780 wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
784 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
785 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
787 tree_model
->internal
->SetDataViewSortColumn( gs_lastLeftClickHeader
);
789 if ((sort_column_id
!= (gint
) tree_model
->internal
->GetSortColumn()) ||
790 (order
!= tree_model
->internal
->GetSortOrder()))
792 tree_model
->internal
->SetSortColumn( sort_column_id
);
793 tree_model
->internal
->SetSortOrder( order
);
795 gtk_tree_sortable_sort_column_changed (sortable
);
797 tree_model
->internal
->GetDataViewModel()->Resort();
800 if (gs_lastLeftClickHeader
)
802 wxDataViewCtrl
*dv
= tree_model
->internal
->GetOwner();
803 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, dv
->GetId() );
804 event
.SetDataViewColumn( gs_lastLeftClickHeader
);
805 event
.SetModel( dv
->GetModel() );
806 dv
->HandleWindowEvent( event
);
809 gs_lastLeftClickHeader
= NULL
;
813 wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
814 gint
WXUNUSED(sort_column_id
),
815 GtkTreeIterCompareFunc func
,
816 gpointer
WXUNUSED(data
),
817 GtkDestroyNotify
WXUNUSED(destroy
))
819 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
820 g_return_if_fail (func
!= NULL
);
824 wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
825 GtkTreeIterCompareFunc func
,
826 gpointer
WXUNUSED(data
),
827 GtkDestroyNotify
WXUNUSED(destroy
))
829 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
830 g_return_if_fail (func
!= NULL
);
832 //wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
833 // TODO: remove this code
837 wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
)
839 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
844 //-----------------------------------------------------------------------------
845 // define new GTK+ class GtkWxRendererText
846 //-----------------------------------------------------------------------------
850 #define GTK_TYPE_WX_CELL_RENDERER_TEXT (gtk_wx_cell_renderer_text_get_type ())
851 #define GTK_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererText))
852 #define GTK_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
853 #define GTK_IS_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT))
854 #define GTK_IS_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT))
855 #define GTK_WX_CELL_RENDERER_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
857 GType
gtk_wx_cell_renderer_text_get_type (void);
859 typedef struct _GtkWxCellRendererText GtkWxCellRendererText
;
860 typedef struct _GtkWxCellRendererTextClass GtkWxCellRendererTextClass
;
862 struct _GtkWxCellRendererText
864 GtkCellRendererText parent
;
866 wxDataViewRenderer
*wx_renderer
;
869 struct _GtkWxCellRendererTextClass
871 GtkCellRendererTextClass cell_parent_class
;
875 static GtkWxCellRendererText
*gtk_wx_cell_renderer_text_new (void);
876 static void gtk_wx_cell_renderer_text_init (
877 GtkWxCellRendererText
*cell
);
878 static void gtk_wx_cell_renderer_text_class_init(
879 GtkWxCellRendererTextClass
*klass
);
880 static void gtk_wx_cell_renderer_text_finalize (
882 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
883 GtkCellRenderer
*cell
,
887 GdkRectangle
*background_area
,
888 GdkRectangle
*cell_area
,
889 GtkCellRendererState flags
);
892 static GObjectClass
*text_cell_parent_class
= NULL
;
897 gtk_wx_cell_renderer_text_get_type (void)
899 static GType cell_wx_type
= 0;
903 const GTypeInfo cell_wx_info
=
905 sizeof (GtkWxCellRendererTextClass
),
906 NULL
, /* base_init */
907 NULL
, /* base_finalize */
908 (GClassInitFunc
) gtk_wx_cell_renderer_text_class_init
,
909 NULL
, /* class_finalize */
910 NULL
, /* class_data */
911 sizeof (GtkWxCellRendererText
),
913 (GInstanceInitFunc
) gtk_wx_cell_renderer_text_init
,
916 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER_TEXT
,
917 "GtkWxCellRendererText", &cell_wx_info
, (GTypeFlags
)0 );
924 gtk_wx_cell_renderer_text_init (GtkWxCellRendererText
*cell
)
926 cell
->wx_renderer
= NULL
;
930 gtk_wx_cell_renderer_text_class_init (GtkWxCellRendererTextClass
*klass
)
932 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
933 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
935 text_cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
937 object_class
->finalize
= gtk_wx_cell_renderer_text_finalize
;
939 cell_class
->start_editing
= gtk_wx_cell_renderer_text_start_editing
;
943 gtk_wx_cell_renderer_text_finalize (GObject
*object
)
946 (* G_OBJECT_CLASS (text_cell_parent_class
)->finalize
) (object
);
949 GtkWxCellRendererText
*
950 gtk_wx_cell_renderer_text_new (void)
952 return (GtkWxCellRendererText
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER_TEXT
, NULL
);
955 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
956 GtkCellRenderer
*gtk_renderer
,
960 GdkRectangle
*background_area
,
961 GdkRectangle
*cell_area
,
962 GtkCellRendererState flags
)
964 GtkWxCellRendererText
*wxgtk_renderer
= (GtkWxCellRendererText
*) gtk_renderer
;
965 wxDataViewRenderer
*wx_renderer
= wxgtk_renderer
->wx_renderer
;
967 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
969 wx_renderer
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
970 wxDataViewItem
item( (void*) iter
.user_data
);;
971 gtk_tree_path_free( treepath
);
973 wxDataViewColumn
*column
= wx_renderer
->GetOwner();
974 wxDataViewCtrl
*dv
= column
->GetOwner();
975 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, dv
->GetId() );
976 event
.SetDataViewColumn( column
);
977 event
.SetModel( dv
->GetModel() );
978 event
.SetColumn( wx_renderer
->GetOwner()->GetModelColumn() );
979 event
.SetItem( item
);
980 dv
->HandleWindowEvent( event
);
982 if (event
.IsAllowed())
983 return GTK_CELL_RENDERER_CLASS(text_cell_parent_class
)->
984 start_editing( gtk_renderer
, gdk_event
, widget
, path
, background_area
, cell_area
, flags
);
989 //-----------------------------------------------------------------------------
990 // define new GTK+ class GtkWxCellRenderer
991 //-----------------------------------------------------------------------------
995 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
996 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
997 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
998 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
999 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
1000 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
1002 GType
gtk_wx_cell_renderer_get_type (void);
1004 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
1005 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
1007 struct _GtkWxCellRenderer
1009 GtkCellRenderer parent
;
1012 wxDataViewCustomRenderer
*cell
;
1016 struct _GtkWxCellRendererClass
1018 GtkCellRendererClass cell_parent_class
;
1022 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
1023 static void gtk_wx_cell_renderer_init (
1024 GtkWxCellRenderer
*cell
);
1025 static void gtk_wx_cell_renderer_class_init(
1026 GtkWxCellRendererClass
*klass
);
1027 static void gtk_wx_cell_renderer_finalize (
1029 static void gtk_wx_cell_renderer_get_size (
1030 GtkCellRenderer
*cell
,
1032 GdkRectangle
*rectangle
,
1037 static void gtk_wx_cell_renderer_render (
1038 GtkCellRenderer
*cell
,
1041 GdkRectangle
*background_area
,
1042 GdkRectangle
*cell_area
,
1043 GdkRectangle
*expose_area
,
1044 GtkCellRendererState flags
);
1045 static gboolean
gtk_wx_cell_renderer_activate(
1046 GtkCellRenderer
*cell
,
1050 GdkRectangle
*background_area
,
1051 GdkRectangle
*cell_area
,
1052 GtkCellRendererState flags
);
1053 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1054 GtkCellRenderer
*cell
,
1058 GdkRectangle
*background_area
,
1059 GdkRectangle
*cell_area
,
1060 GtkCellRendererState flags
);
1063 static GObjectClass
*cell_parent_class
= NULL
;
1068 gtk_wx_cell_renderer_get_type (void)
1070 static GType cell_wx_type
= 0;
1074 const GTypeInfo cell_wx_info
=
1076 sizeof (GtkWxCellRendererClass
),
1077 NULL
, /* base_init */
1078 NULL
, /* base_finalize */
1079 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
1080 NULL
, /* class_finalize */
1081 NULL
, /* class_data */
1082 sizeof (GtkWxCellRenderer
),
1083 0, /* n_preallocs */
1084 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
1087 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
1088 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
1091 return cell_wx_type
;
1095 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
1098 cell
->last_click
= 0;
1102 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
1104 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1105 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
1107 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
1109 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
1111 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
1112 cell_class
->render
= gtk_wx_cell_renderer_render
;
1113 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
1114 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
1118 gtk_wx_cell_renderer_finalize (GObject
*object
)
1121 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
1125 gtk_wx_cell_renderer_new (void)
1127 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
1130 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1131 GtkCellRenderer
*renderer
,
1132 GdkEvent
*WXUNUSED(event
),
1135 GdkRectangle
*WXUNUSED(background_area
),
1136 GdkRectangle
*cell_area
,
1137 GtkCellRendererState
WXUNUSED(flags
) )
1139 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1140 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1142 // Renderer doesn't support in-place editing
1143 if (!cell
->HasEditorCtrl())
1146 // An in-place editing control is still around
1147 if (cell
->GetEditorCtrl())
1151 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1157 rect
.x
+= cell_area
->x
;
1158 rect
.y
+= cell_area
->y
;
1159 // rect.width -= renderer->xpad * 2;
1160 // rect.height -= renderer->ypad * 2;
1162 // wxRect renderrect(wxRectFromGDKRect(&rect));
1163 wxRect
renderrect(wxRectFromGDKRect(cell_area
));
1165 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
1167 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
1168 wxDataViewItem
item( (void*) iter
.user_data
);
1169 gtk_tree_path_free( treepath
);
1171 cell
->StartEditing( item
, renderrect
);
1177 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
1178 GtkWidget
*WXUNUSED(widget
),
1179 GdkRectangle
*cell_area
,
1185 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1186 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1188 wxSize size
= cell
->GetSize();
1190 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
1191 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
1198 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
1202 *x_offset
= (gint
)((renderer
->xalign
*
1203 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
1204 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
1208 *y_offset
= (gint
)((renderer
->yalign
*
1209 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
1210 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
1215 *width
= calc_width
;
1218 *height
= calc_height
;
1222 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
1225 GdkRectangle
*background_area
,
1226 GdkRectangle
*cell_area
,
1227 GdkRectangle
*expose_area
,
1228 GtkCellRendererState flags
)
1231 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1232 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1234 cell
->GTKStashRenderParams(window
, widget
,
1235 background_area
, expose_area
, flags
);
1237 wxRect
rect(wxRectFromGDKRect(cell_area
));
1238 rect
= rect
.Deflate(renderer
->xpad
, renderer
->ypad
);
1240 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
1241 wxWindowDCImpl
*impl
= (wxWindowDCImpl
*) dc
->GetImpl();
1243 // Reinitialize wxWindowDC's GDK window if drawing occurs into a different
1244 // window such as a DnD drop window.
1245 if (window
!= impl
->m_gdkwindow
)
1248 impl
->m_gdkwindow
= window
;
1253 if (flags
& GTK_CELL_RENDERER_SELECTED
)
1254 state
|= wxDATAVIEW_CELL_SELECTED
;
1255 if (flags
& GTK_CELL_RENDERER_PRELIT
)
1256 state
|= wxDATAVIEW_CELL_PRELIT
;
1257 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1258 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1259 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1260 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1261 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
1262 state
|= wxDATAVIEW_CELL_FOCUSED
;
1263 cell
->WXCallRender( rect
, dc
, state
);
1267 gtk_wx_cell_renderer_activate(
1268 GtkCellRenderer
*renderer
,
1272 GdkRectangle
*WXUNUSED(background_area
),
1273 GdkRectangle
*cell_area
,
1274 GtkCellRendererState
WXUNUSED(flags
) )
1276 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1277 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1280 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1286 rect
.x
+= cell_area
->x
;
1287 rect
.y
+= cell_area
->y
;
1288 rect
.width
-= renderer
->xpad
* 2;
1289 rect
.height
-= renderer
->ypad
* 2;
1291 wxRect
renderrect(wxRectFromGDKRect(&rect
));
1293 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1295 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
1298 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
1299 wxDataViewItem
item( iter
.user_data
);
1300 gtk_tree_path_free( treepath
);
1302 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1308 // activated by <ENTER>
1309 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1314 else if (event
->type
== GDK_BUTTON_PRESS
)
1316 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
1317 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
1318 ((int) button_event
->y
) - renderrect
.y
);
1321 if (button_event
->button
== 1)
1323 if (cell
->LeftClick( pt
, renderrect
, model
, item
, model_col
))
1325 // TODO: query system double-click time
1326 if (button_event
->time
- wxrenderer
->last_click
< 400)
1327 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1330 wxrenderer
->last_click
= button_event
->time
;
1338 // ---------------------------------------------------------
1339 // wxGtkDataViewModelNotifier
1340 // ---------------------------------------------------------
1342 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1345 wxGtkDataViewModelNotifier( GtkWxTreeModel
*wxgtk_model
,
1346 wxDataViewModel
*wx_model
,
1347 wxDataViewCtrl
*ctrl
);
1348 ~wxGtkDataViewModelNotifier();
1350 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1351 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1352 virtual bool ItemChanged( const wxDataViewItem
&item
);
1353 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
1354 virtual bool Cleared();
1355 virtual void Resort();
1357 void SetGtkModel( GtkWxTreeModel
*model
) { m_wxgtk_model
= model
; }
1360 GtkWxTreeModel
*m_wxgtk_model
;
1361 wxDataViewModel
*m_wx_model
;
1362 wxDataViewCtrl
*m_owner
;
1365 // ---------------------------------------------------------
1366 // wxGtkDataViewListModelNotifier
1367 // ---------------------------------------------------------
1369 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1370 GtkWxTreeModel
* wxgtk_model
, wxDataViewModel
*wx_model
,
1371 wxDataViewCtrl
*ctrl
)
1373 m_wxgtk_model
= wxgtk_model
;
1374 m_wx_model
= wx_model
;
1378 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1381 m_wxgtk_model
= NULL
;
1384 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1386 m_owner
->GtkGetInternal()->ItemAdded( parent
, item
);
1389 iter
.stamp
= m_wxgtk_model
->stamp
;
1390 iter
.user_data
= (gpointer
) item
.GetID();
1392 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1393 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1394 gtk_tree_model_row_inserted(
1395 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1396 gtk_tree_path_free (path
);
1401 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1404 // using _get_path for a deleted item cannot be
1407 iter
.stamp
= m_wxgtk_model
->stamp
;
1408 iter
.user_data
= (gpointer
) item
.GetID();
1409 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1410 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1412 // so get the path from the parent
1414 iter
.stamp
= m_wxgtk_model
->stamp
;
1415 iter
.user_data
= (gpointer
) parent
.GetID();
1416 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1417 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1418 // and add the final index ourselves
1419 int index
= m_owner
->GtkGetInternal()->GetIndexOf( parent
, item
);
1420 gtk_tree_path_append_index( path
, index
);
1423 gtk_tree_model_row_deleted(
1424 GTK_TREE_MODEL(m_wxgtk_model
), path
);
1425 gtk_tree_path_free (path
);
1427 m_owner
->GtkGetInternal()->ItemDeleted( parent
, item
);
1432 void wxGtkDataViewModelNotifier::Resort()
1434 m_owner
->GtkGetInternal()->Resort();
1437 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1440 iter
.stamp
= m_wxgtk_model
->stamp
;
1441 iter
.user_data
= (gpointer
) item
.GetID();
1443 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1444 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1445 gtk_tree_model_row_changed(
1446 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1447 gtk_tree_path_free (path
);
1449 m_owner
->GtkGetInternal()->ItemChanged( item
);
1454 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_col
)
1456 // This adds GTK+'s missing MVC logic for ValueChanged
1458 for (index
= 0; index
< m_owner
->GetColumnCount(); index
++)
1460 wxDataViewColumn
*column
= m_owner
->GetColumn( index
);
1461 if (column
->GetModelColumn() == model_col
)
1463 GtkTreeView
*widget
= GTK_TREE_VIEW(m_owner
->m_treeview
);
1464 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1468 iter
.stamp
= m_wxgtk_model
->stamp
;
1469 iter
.user_data
= (gpointer
) item
.GetID();
1470 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1471 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1472 GdkRectangle cell_area
;
1473 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1474 gtk_tree_path_free( path
);
1476 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1477 double d
= gtk_adjustment_get_value( hadjust
);
1478 int xdiff
= (int) d
;
1480 int ydiff
= gcolumn
->button
->allocation
.height
;
1482 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1483 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1485 m_owner
->GtkGetInternal()->ValueChanged( item
, model_col
);
1494 bool wxGtkDataViewModelNotifier::Cleared()
1496 m_owner
->GtkGetInternal()->Cleared();
1501 // ---------------------------------------------------------
1502 // wxDataViewRenderer
1503 // ---------------------------------------------------------
1505 static gpointer s_user_data
= NULL
;
1508 wxgtk_cell_editable_editing_done( GtkCellEditable
*WXUNUSED(editable
),
1509 wxDataViewRenderer
*wxrenderer
)
1511 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1512 wxDataViewCtrl
*dv
= column
->GetOwner();
1513 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1514 event
.SetDataViewColumn( column
);
1515 event
.SetModel( dv
->GetModel() );
1516 wxDataViewItem
item( s_user_data
);
1517 event
.SetItem( item
);
1518 dv
->HandleWindowEvent( event
);
1522 wxgtk_renderer_editing_started( GtkCellRenderer
*WXUNUSED(cell
), GtkCellEditable
*editable
,
1523 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1528 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1529 wxDataViewCtrl
*dv
= column
->GetOwner();
1530 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1531 event
.SetDataViewColumn( column
);
1532 event
.SetModel( dv
->GetModel() );
1533 GtkTreePath
*tree_path
= gtk_tree_path_new_from_string( path
);
1535 dv
->GtkGetInternal()->get_iter( &iter
, tree_path
);
1536 gtk_tree_path_free( tree_path
);
1537 wxDataViewItem
item( iter
.user_data
);
1538 event
.SetItem( item
);
1539 dv
->HandleWindowEvent( event
);
1541 if (GTK_IS_CELL_EDITABLE(editable
))
1543 s_user_data
= iter
.user_data
;
1545 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1546 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1547 (gpointer
) wxrenderer
);
1553 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1555 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1557 wxDataViewRendererBase( varianttype
, mode
, align
)
1561 // we haven't changed them yet
1562 m_usingDefaultAttrs
= true;
1564 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1565 // after the m_renderer pointer has been initialized
1568 void wxDataViewRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
1570 gtk_tree_view_column_pack_end( column
, m_renderer
, TRUE
/* expand */);
1573 void wxDataViewRenderer::GtkInitHandlers()
1575 if (!gtk_check_version(2,6,0))
1577 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1578 G_CALLBACK (wxgtk_renderer_editing_started
),
1583 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1585 GtkCellRendererMode gtkMode
;
1588 case wxDATAVIEW_CELL_INERT
:
1589 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1592 case wxDATAVIEW_CELL_ACTIVATABLE
:
1593 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1596 case wxDATAVIEW_CELL_EDITABLE
:
1597 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1601 wxFAIL_MSG( "unknown wxDataViewCellMode value" );
1605 // This value is most often ignored in GtkTreeView
1606 GValue gvalue
= { 0, };
1607 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1608 g_value_set_enum( &gvalue
, gtkMode
);
1609 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1610 g_value_unset( &gvalue
);
1613 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1615 wxDataViewCellMode ret
;
1618 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1620 switch (g_value_get_enum(&gvalue
))
1623 wxFAIL_MSG( "unknown GtkCellRendererMode value" );
1624 // fall through (we have to return something)
1626 case GTK_CELL_RENDERER_MODE_INERT
:
1627 ret
= wxDATAVIEW_CELL_INERT
;
1630 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1631 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1634 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1635 ret
= wxDATAVIEW_CELL_EDITABLE
;
1639 g_value_unset( &gvalue
);
1644 void wxDataViewRenderer::GtkUpdateAlignment()
1646 int align
= m_alignment
;
1648 // query alignment from column ?
1652 if (GetOwner() == NULL
)
1655 align
= GetOwner()->GetAlignment();
1656 align
|= wxALIGN_CENTRE_VERTICAL
;
1659 // horizontal alignment:
1661 gfloat xalign
= 0.0;
1662 if (align
& wxALIGN_RIGHT
)
1664 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1667 GValue gvalue
= { 0, };
1668 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1669 g_value_set_float( &gvalue
, xalign
);
1670 g_object_set_property( G_OBJECT(m_renderer
), "xalign", &gvalue
);
1671 g_value_unset( &gvalue
);
1673 // vertical alignment:
1675 gfloat yalign
= 0.0;
1676 if (align
& wxALIGN_BOTTOM
)
1678 else if (align
& wxALIGN_CENTER_VERTICAL
)
1681 GValue gvalue2
= { 0, };
1682 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1683 g_value_set_float( &gvalue2
, yalign
);
1684 g_object_set_property( G_OBJECT(m_renderer
), "yalign", &gvalue2
);
1685 g_value_unset( &gvalue2
);
1688 void wxDataViewRenderer::SetAlignment( int align
)
1690 m_alignment
= align
;
1691 GtkUpdateAlignment();
1694 int wxDataViewRenderer::GetAlignment() const
1699 void wxDataViewRenderer::EnableEllipsize(wxEllipsizeMode mode
)
1702 if ( gtk_check_version(2, 6, 0) != NULL
)
1705 GtkCellRendererText
* const rend
= GtkGetTextRenderer();
1709 // we use the same values in wxEllipsizeMode as PangoEllipsizeMode so we
1710 // can just cast between them
1711 GValue gvalue
= { 0, };
1712 g_value_init( &gvalue
, PANGO_TYPE_ELLIPSIZE_MODE
);
1713 g_value_set_enum( &gvalue
, static_cast<PangoEllipsizeMode
>(mode
) );
1714 g_object_set_property( G_OBJECT(rend
), "ellipsize", &gvalue
);
1715 g_value_unset( &gvalue
);
1718 #endif // GTK 2.6/before
1721 wxEllipsizeMode
wxDataViewRenderer::GetEllipsizeMode() const
1724 if ( gtk_check_version(2, 6, 0) != NULL
)
1725 return wxELLIPSIZE_NONE
;
1727 GtkCellRendererText
* const rend
= GtkGetTextRenderer();
1729 return wxELLIPSIZE_NONE
;
1731 GValue gvalue
= { 0, };
1732 g_value_init( &gvalue
, PANGO_TYPE_ELLIPSIZE_MODE
);
1733 g_object_get_property( G_OBJECT(rend
), "ellipsize", &gvalue
);
1735 mode
= static_cast<wxEllipsizeMode
>(g_value_get_enum( &gvalue
));
1736 g_value_unset( &gvalue
);
1740 return wxELLIPSIZE_NONE
;
1741 #endif // GTK 2.6/before
1745 wxDataViewRenderer::GtkOnTextEdited(const gchar
*itempath
, const wxString
& str
)
1747 wxVariant
value(str
);
1748 if (!Validate( value
))
1751 GtkTreePath
*path
= gtk_tree_path_new_from_string( itempath
);
1753 GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, path
);
1754 wxDataViewItem
item( (void*) iter
.user_data
);;
1755 gtk_tree_path_free( path
);
1757 GtkOnCellChanged(value
, item
, GetOwner()->GetModelColumn());
1761 wxDataViewRenderer::GtkOnCellChanged(const wxVariant
& value
,
1762 const wxDataViewItem
& item
,
1765 wxDataViewModel
*model
= GetOwner()->GetOwner()->GetModel();
1766 model
->ChangeValue( value
, item
, col
);
1769 // ---------------------------------------------------------
1770 // wxDataViewTextRenderer
1771 // ---------------------------------------------------------
1776 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*WXUNUSED(renderer
),
1777 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1779 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) user_data
;
1781 cell
->GtkOnTextEdited(arg1
, wxGTK_CONV_BACK_FONT(
1782 arg2
, cell
->GetOwner()->GetOwner()->GetFont()));
1790 // helper function used by wxDataViewTextRenderer and
1791 // wxDataViewCustomRenderer::RenderText(): it applies the attributes to the
1792 // given text renderer and returns true if anything was done
1793 bool GtkApplyAttr(GtkCellRendererText
*renderer
, const wxDataViewItemAttr
& attr
)
1795 bool usingDefaultAttrs
= true;
1796 if (attr
.HasColour())
1798 const GdkColor
* const gcol
= attr
.GetColour().GetColor();
1800 GValue gvalue
= { 0, };
1801 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
1802 g_value_set_boxed( &gvalue
, gcol
);
1803 g_object_set_property( G_OBJECT(renderer
), "foreground_gdk", &gvalue
);
1804 g_value_unset( &gvalue
);
1806 usingDefaultAttrs
= false;
1810 GValue gvalue
= { 0, };
1811 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1812 g_value_set_boolean( &gvalue
, FALSE
);
1813 g_object_set_property( G_OBJECT(renderer
), "foreground-set", &gvalue
);
1814 g_value_unset( &gvalue
);
1817 if (attr
.GetItalic())
1819 GValue gvalue
= { 0, };
1820 g_value_init( &gvalue
, PANGO_TYPE_STYLE
);
1821 g_value_set_enum( &gvalue
, PANGO_STYLE_ITALIC
);
1822 g_object_set_property( G_OBJECT(renderer
), "style", &gvalue
);
1823 g_value_unset( &gvalue
);
1825 usingDefaultAttrs
= false;
1829 GValue gvalue
= { 0, };
1830 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1831 g_value_set_boolean( &gvalue
, FALSE
);
1832 g_object_set_property( G_OBJECT(renderer
), "style-set", &gvalue
);
1833 g_value_unset( &gvalue
);
1839 GValue gvalue
= { 0, };
1840 g_value_init( &gvalue
, PANGO_TYPE_WEIGHT
);
1841 g_value_set_enum( &gvalue
, PANGO_WEIGHT_BOLD
);
1842 g_object_set_property( G_OBJECT(renderer
), "weight", &gvalue
);
1843 g_value_unset( &gvalue
);
1845 usingDefaultAttrs
= false;
1849 GValue gvalue
= { 0, };
1850 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1851 g_value_set_boolean( &gvalue
, FALSE
);
1852 g_object_set_property( G_OBJECT(renderer
), "weight-set", &gvalue
);
1853 g_value_unset( &gvalue
);
1857 if (attr
.HasBackgroundColour())
1859 wxColour colour
= attr
.GetBackgroundColour();
1860 const GdkColor
* const gcol
= colour
.GetColor();
1862 GValue gvalue
= { 0, };
1863 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
1864 g_value_set_boxed( &gvalue
, gcol
);
1865 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
1866 g_value_unset( &gvalue
);
1870 GValue gvalue
= { 0, };
1871 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1872 g_value_set_boolean( &gvalue
, FALSE
);
1873 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
1874 g_value_unset( &gvalue
);
1878 return !usingDefaultAttrs
;
1881 } // anonymous namespace
1883 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
1885 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1887 wxDataViewRenderer( varianttype
, mode
, align
)
1889 GtkWxCellRendererText
*text_renderer
= gtk_wx_cell_renderer_text_new();
1890 text_renderer
->wx_renderer
= this;
1891 m_renderer
= (GtkCellRenderer
*) text_renderer
;
1893 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
1895 GValue gvalue
= { 0, };
1896 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1897 g_value_set_boolean( &gvalue
, true );
1898 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
1899 g_value_unset( &gvalue
);
1901 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
1907 SetAlignment(align
);
1910 bool wxDataViewTextRenderer::SetTextValue(const wxString
& str
)
1912 GValue gvalue
= { 0, };
1913 g_value_init( &gvalue
, G_TYPE_STRING
);
1914 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( str
, GetOwner()->GetOwner()->GetFont() ) );
1915 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1916 g_value_unset( &gvalue
);
1921 bool wxDataViewTextRenderer::GetTextValue(wxString
& str
) const
1923 GValue gvalue
= { 0, };
1924 g_value_init( &gvalue
, G_TYPE_STRING
);
1925 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1926 str
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
), const_cast<wxDataViewTextRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
1927 g_value_unset( &gvalue
);
1932 void wxDataViewTextRenderer::SetAlignment( int align
)
1934 wxDataViewRenderer::SetAlignment(align
);
1936 if (gtk_check_version(2,10,0))
1939 // horizontal alignment:
1940 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
1941 if (align
& wxALIGN_RIGHT
)
1942 pangoAlign
= PANGO_ALIGN_RIGHT
;
1943 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1944 pangoAlign
= PANGO_ALIGN_CENTER
;
1946 GValue gvalue
= { 0, };
1947 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1948 g_value_set_enum( &gvalue
, pangoAlign
);
1949 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
1950 g_value_unset( &gvalue
);
1953 bool wxDataViewTextRenderer::GtkSetAttr(const wxDataViewItemAttr
& attr
)
1955 return GtkApplyAttr(GtkGetTextRenderer(), attr
);
1958 GtkCellRendererText
*wxDataViewTextRenderer::GtkGetTextRenderer() const
1960 return GTK_CELL_RENDERER_TEXT(m_renderer
);
1963 // ---------------------------------------------------------
1964 // wxDataViewBitmapRenderer
1965 // ---------------------------------------------------------
1970 // set "pixbuf" property on the given renderer
1971 void SetPixbufProp(GtkCellRenderer
*renderer
, GdkPixbuf
*pixbuf
)
1973 GValue gvalue
= { 0, };
1974 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1975 g_value_set_object( &gvalue
, pixbuf
);
1976 g_object_set_property( G_OBJECT(renderer
), "pixbuf", &gvalue
);
1977 g_value_unset( &gvalue
);
1980 } // anonymous namespace
1982 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
1984 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1986 wxDataViewRenderer( varianttype
, mode
, align
)
1988 m_renderer
= gtk_cell_renderer_pixbuf_new();
1991 SetAlignment(align
);
1994 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
1996 if (value
.GetType() == wxT("wxBitmap"))
2001 // GetPixbuf() may create a Pixbuf representation in the wxBitmap
2002 // object (and it will stay there and remain owned by wxBitmap)
2003 SetPixbufProp(m_renderer
, bitmap
.GetPixbuf());
2005 else if (value
.GetType() == wxT("wxIcon"))
2010 SetPixbufProp(m_renderer
, icon
.GetPixbuf());
2020 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2025 // ---------------------------------------------------------
2026 // wxDataViewToggleRenderer
2027 // ---------------------------------------------------------
2030 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
2031 gchar
*path
, gpointer user_data
);
2034 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
2035 gchar
*path
, gpointer user_data
)
2037 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
2040 GValue gvalue
= { 0, };
2041 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2042 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
2043 bool tmp
= g_value_get_boolean( &gvalue
);
2044 g_value_unset( &gvalue
);
2048 wxVariant value
= tmp
;
2049 if (!cell
->Validate( value
))
2052 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
2054 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
2056 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, gtk_path
);
2057 wxDataViewItem
item( (void*) iter
.user_data
);;
2058 gtk_tree_path_free( gtk_path
);
2060 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
2062 model
->ChangeValue( value
, item
, model_col
);
2065 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
2067 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
2068 wxDataViewCellMode mode
, int align
) :
2069 wxDataViewRenderer( varianttype
, mode
, align
)
2071 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
2073 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
2075 g_signal_connect_after( m_renderer
, "toggled",
2076 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
2080 GValue gvalue
= { 0, };
2081 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2082 g_value_set_boolean( &gvalue
, false );
2083 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
2084 g_value_unset( &gvalue
);
2088 SetAlignment(align
);
2091 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
2095 GValue gvalue
= { 0, };
2096 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2097 g_value_set_boolean( &gvalue
, tmp
);
2098 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
2099 g_value_unset( &gvalue
);
2104 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
2106 GValue gvalue
= { 0, };
2107 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2108 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
2109 bool tmp
= g_value_get_boolean( &gvalue
);
2110 g_value_unset( &gvalue
);
2117 // ---------------------------------------------------------
2118 // wxDataViewCustomRenderer
2119 // ---------------------------------------------------------
2121 class wxDataViewCtrlDCImpl
: public wxWindowDCImpl
2124 wxDataViewCtrlDCImpl( wxDC
*owner
, wxDataViewCtrl
*window
) :
2125 wxWindowDCImpl( owner
)
2127 GtkWidget
*widget
= window
->m_treeview
;
2133 m_context
= window
->GTKGetPangoDefaultContext();
2134 m_layout
= pango_layout_new( m_context
);
2135 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
2137 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
2139 // Set m_gdkwindow later
2144 class wxDataViewCtrlDC
: public wxWindowDC
2147 wxDataViewCtrlDC( wxDataViewCtrl
*window
) :
2148 wxWindowDC( new wxDataViewCtrlDCImpl( this, window
) )
2153 // ---------------------------------------------------------
2154 // wxDataViewCustomRenderer
2155 // ---------------------------------------------------------
2157 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
2159 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
2160 wxDataViewCellMode mode
,
2163 : wxDataViewCustomRendererBase( varianttype
, mode
, align
)
2166 m_text_renderer
= NULL
;
2174 GtkCellRendererText
*wxDataViewCustomRenderer::GtkGetTextRenderer() const
2176 if ( !m_text_renderer
)
2178 // we create it on demand so need to do it even from a const function
2179 const_cast<wxDataViewCustomRenderer
*>(this)->
2180 m_text_renderer
= GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new());
2183 return m_text_renderer
;
2186 void wxDataViewCustomRenderer::RenderText( const wxString
&text
,
2190 int WXUNUSED(state
) )
2193 GtkCellRendererText
* const textRenderer
= GtkGetTextRenderer();
2195 GValue gvalue
= { 0, };
2196 g_value_init( &gvalue
, G_TYPE_STRING
);
2197 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( text
, GetOwner()->GetOwner()->GetFont() ) );
2198 g_object_set_property( G_OBJECT(textRenderer
), "text", &gvalue
);
2199 g_value_unset( &gvalue
);
2201 GtkApplyAttr(textRenderer
, GetAttr());
2203 GdkRectangle cell_area
;
2204 wxRectToGDKRect(cell
, cell_area
);
2205 cell_area
.x
+= xoffset
;
2206 cell_area
.width
-= xoffset
;
2208 gtk_cell_renderer_render( GTK_CELL_RENDERER(textRenderer
),
2209 m_renderParams
.window
,
2210 m_renderParams
.widget
,
2211 m_renderParams
.background_area
,
2213 m_renderParams
.expose_area
,
2214 (GtkCellRendererState
) m_renderParams
.flags
);
2217 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
2219 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
2220 renderer
->cell
= this;
2222 m_renderer
= (GtkCellRenderer
*) renderer
;
2225 SetAlignment(align
);
2232 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
2237 if (m_text_renderer
)
2238 gtk_object_sink( GTK_OBJECT(m_text_renderer
) );
2241 wxDC
*wxDataViewCustomRenderer::GetDC()
2245 if (GetOwner() == NULL
)
2247 if (GetOwner()->GetOwner() == NULL
)
2249 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
2255 // ---------------------------------------------------------
2256 // wxDataViewProgressRenderer
2257 // ---------------------------------------------------------
2259 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
2261 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
2262 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
2263 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
2269 if (!gtk_check_version(2,6,0))
2271 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
2273 GValue gvalue
= { 0, };
2274 g_value_init( &gvalue
, G_TYPE_STRING
);
2276 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( m_label
, GetOwner()->GetOwner()->GetFont() ) );
2277 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2278 g_value_unset( &gvalue
);
2281 SetAlignment(align
);
2286 // Use custom cell code
2287 wxDataViewCustomRenderer::Init(mode
, align
);
2291 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
2295 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
2298 if (!gtk_check_version(2,6,0))
2300 gint tmp
= (long) value
;
2301 GValue gvalue
= { 0, };
2302 g_value_init( &gvalue
, G_TYPE_INT
);
2303 g_value_set_int( &gvalue
, tmp
);
2304 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
2305 g_value_unset( &gvalue
);
2310 m_value
= (long) value
;
2312 if (m_value
< 0) m_value
= 0;
2313 if (m_value
> 100) m_value
= 100;
2319 bool wxDataViewProgressRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2324 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
2326 double pct
= (double)m_value
/ 100.0;
2328 bar
.width
= (int)(cell
.width
* pct
);
2329 dc
->SetPen( *wxTRANSPARENT_PEN
);
2330 dc
->SetBrush( *wxBLUE_BRUSH
);
2331 dc
->DrawRectangle( bar
);
2333 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
2334 dc
->SetPen( *wxBLACK_PEN
);
2335 dc
->DrawRectangle( cell
);
2340 wxSize
wxDataViewProgressRenderer::GetSize() const
2342 return wxSize(40,12);
2345 // -------------------------------------
2346 // wxDataViewChoiceRenderer
2347 // -------------------------------------
2349 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
&choices
,
2350 wxDataViewCellMode mode
, int alignment
) :
2351 wxDataViewCustomRenderer( "string", mode
, alignment
, true )
2353 m_choices
= choices
;
2356 if (!gtk_check_version(2,6,0))
2358 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_combo_new();
2360 GtkListStore
*store
= gtk_list_store_new( 1, G_TYPE_STRING
);
2361 for (size_t n
= 0; n
< m_choices
.GetCount(); n
++)
2363 gtk_list_store_insert_with_values(
2365 static_cast<const char *>(m_choices
[n
].utf8_str()), -1 );
2368 g_object_set (m_renderer
,
2374 bool editable
= (mode
& wxDATAVIEW_CELL_EDITABLE
);
2375 g_object_set (m_renderer
, "editable", editable
, NULL
);
2377 SetAlignment(alignment
);
2379 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2386 // Use custom cell code
2387 wxDataViewCustomRenderer::Init(mode
, alignment
);
2391 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
2393 RenderText( m_data
, 0, rect
, dc
, state
);
2397 wxSize
wxDataViewChoiceRenderer::GetSize() const
2399 return wxSize(70,20);
2402 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
2406 if (!gtk_check_version(2,6,0))
2408 GValue gvalue
= { 0, };
2409 g_value_init( &gvalue
, G_TYPE_STRING
);
2410 g_value_set_string(&gvalue
,
2411 wxGTK_CONV_FONT(value
.GetString(),
2412 GetOwner()->GetOwner()->GetFont()));
2413 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2414 g_value_unset( &gvalue
);
2418 m_data
= value
.GetString();
2423 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
2426 if (!gtk_check_version(2,6,0))
2428 GValue gvalue
= { 0, };
2429 g_value_init( &gvalue
, G_TYPE_STRING
);
2430 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2431 wxString temp
= wxGTK_CONV_BACK_FONT(g_value_get_string(&gvalue
),
2432 GetOwner()->GetOwner()->GetFont());
2433 g_value_unset( &gvalue
);
2436 //wxPrintf( "temp %s\n", temp );
2437 // TODO: remove this code
2446 void wxDataViewChoiceRenderer::SetAlignment( int align
)
2448 wxDataViewCustomRenderer::SetAlignment(align
);
2450 if (gtk_check_version(2,10,0))
2453 // horizontal alignment:
2454 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2455 if (align
& wxALIGN_RIGHT
)
2456 pangoAlign
= PANGO_ALIGN_RIGHT
;
2457 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2458 pangoAlign
= PANGO_ALIGN_CENTER
;
2460 GValue gvalue
= { 0, };
2461 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2462 g_value_set_enum( &gvalue
, pangoAlign
);
2463 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2464 g_value_unset( &gvalue
);
2467 // ----------------------------------------------------------------------------
2468 // wxDataViewChoiceByIndexRenderer
2469 // ----------------------------------------------------------------------------
2471 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
2472 wxDataViewCellMode mode
, int alignment
) :
2473 wxDataViewChoiceRenderer( choices
, mode
, alignment
)
2477 void wxDataViewChoiceByIndexRenderer::GtkOnTextEdited(const gchar
*itempath
, const wxString
& str
)
2479 wxVariant
value( (long) GetChoices().Index( str
) );
2481 if (!Validate( value
))
2484 GtkTreePath
*path
= gtk_tree_path_new_from_string( itempath
);
2486 GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, path
);
2487 wxDataViewItem
item( (void*) iter
.user_data
);;
2488 gtk_tree_path_free( path
);
2490 GtkOnCellChanged(value
, item
, GetOwner()->GetModelColumn());
2493 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant
&value
)
2495 wxVariant string_value
= GetChoice( value
.GetLong() );
2496 return wxDataViewChoiceRenderer::SetValue( string_value
);
2499 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant
&value
) const
2501 wxVariant string_value
;
2502 if (!wxDataViewChoiceRenderer::GetValue( string_value
))
2505 value
= (long) GetChoices().Index( string_value
.GetString() );
2509 // ---------------------------------------------------------
2510 // wxDataViewDateRenderer
2511 // ---------------------------------------------------------
2513 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
2516 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
2517 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
2518 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
2523 m_cal
= new wxCalendarCtrl( this, -1, *value
);
2524 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
2525 sizer
->Add( m_cal
, 1, wxGROW
);
2530 virtual void OnDismiss()
2534 void OnCalendar( wxCalendarEvent
&event
);
2536 wxCalendarCtrl
*m_cal
;
2537 wxDataViewModel
*m_model
;
2538 wxDataViewItem m_item
;
2542 DECLARE_EVENT_TABLE()
2545 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
2546 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
2549 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
2551 m_model
->ChangeValue( event
.GetDate(), m_item
, m_col
);
2555 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
2557 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
2558 wxDataViewCellMode mode
, int align
) :
2559 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2562 SetAlignment(align
);
2565 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
2567 m_date
= value
.GetDateTime();
2572 bool wxDataViewDateRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2577 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2579 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
2580 wxString tmp
= m_date
.FormatDate();
2581 RenderText( tmp
, 0, cell
, dc
, state
);
2585 wxSize
wxDataViewDateRenderer::GetSize() const
2587 wxString tmp
= m_date
.FormatDate();
2589 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
2590 return wxSize(x
,y
+d
);
2593 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
2594 const wxDataViewItem
&item
, unsigned int col
)
2597 model
->GetValue( variant
, item
, col
);
2598 wxDateTime value
= variant
.GetDateTime();
2600 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
2601 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
2602 wxPoint pos
= wxGetMousePosition();
2605 popup
->Popup( popup
->m_cal
);
2611 // ---------------------------------------------------------
2612 // wxDataViewIconTextRenderer
2613 // ---------------------------------------------------------
2615 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
2617 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer
2619 const wxString
&varianttype
,
2620 wxDataViewCellMode mode
,
2623 : wxDataViewTextRenderer(varianttype
, mode
, align
)
2625 m_rendererIcon
= gtk_cell_renderer_pixbuf_new();
2628 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2632 void wxDataViewIconTextRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
2634 // add the icon renderer first
2635 gtk_tree_view_column_pack_start(column
, m_rendererIcon
, FALSE
/* !expand */);
2637 // add the text renderer too
2638 wxDataViewRenderer::GtkPackIntoColumn(column
);
2641 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
2645 SetTextValue(m_value
.GetText());
2646 SetPixbufProp(m_rendererIcon
, m_value
.GetIcon().GetPixbuf());
2651 bool wxDataViewIconTextRenderer::GetValue(wxVariant
& value
) const
2654 if ( !GetTextValue(str
) )
2657 // user doesn't have any way to edit the icon so leave it unchanged
2658 value
<< wxDataViewIconText(str
, m_value
.GetIcon());
2664 wxDataViewIconTextRenderer::GtkOnCellChanged(const wxVariant
& value
,
2665 const wxDataViewItem
& item
,
2668 // we receive just the text part of our value as it's the only one which
2669 // can be edited, but we need the full wxDataViewIconText value for the
2671 wxVariant valueIconText
;
2672 valueIconText
<< wxDataViewIconText(value
.GetString(), m_value
.GetIcon());
2673 wxDataViewTextRenderer::GtkOnCellChanged(valueIconText
, item
, col
);
2676 // ---------------------------------------------------------
2678 // ---------------------------------------------------------
2682 gtk_dataview_header_button_press_callback( GtkWidget
*WXUNUSED(widget
),
2683 GdkEventButton
*gdk_event
,
2684 wxDataViewColumn
*column
)
2686 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
2689 if (gdk_event
->button
== 1)
2691 gs_lastLeftClickHeader
= column
;
2693 wxDataViewCtrl
*dv
= column
->GetOwner();
2694 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
2695 event
.SetDataViewColumn( column
);
2696 event
.SetModel( dv
->GetModel() );
2697 if (dv
->HandleWindowEvent( event
))
2701 if (gdk_event
->button
== 3)
2703 wxDataViewCtrl
*dv
= column
->GetOwner();
2704 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
2705 event
.SetDataViewColumn( column
);
2706 event
.SetModel( dv
->GetModel() );
2707 if (dv
->HandleWindowEvent( event
))
2717 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*WXUNUSED(column
),
2718 GtkCellRenderer
*renderer
,
2719 GtkTreeModel
*model
,
2723 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2724 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2726 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2728 wxDataViewItem
item( (void*) iter
->user_data
);
2730 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
2732 if (!wx_model
->IsVirtualListModel())
2735 if (wx_model
->IsContainer( item
))
2737 visible
= wx_model
->HasContainerColumns( item
) ||
2738 (cell
->GetOwner()->GetModelColumn() == 0);
2745 GValue gvalue
= { 0, };
2746 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2747 g_value_set_boolean( &gvalue
, visible
);
2748 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2749 g_value_unset( &gvalue
);
2756 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
2758 if (value
.GetType() != cell
->GetVariantType())
2760 wxLogError( wxT("Wrong type, required: %s but: %s"),
2761 value
.GetType().c_str(),
2762 cell
->GetVariantType().c_str() );
2765 cell
->SetValue( value
);
2768 // deal with attributes: if the renderer doesn't support them at all, we
2769 // don't even need to query the model for them
2770 if ( !cell
->GtkSupportsAttrs() )
2773 // it can support attributes so check if this item has any
2774 wxDataViewItemAttr attr
;
2775 if ( wx_model
->GetAttr( item
, cell
->GetOwner()->GetModelColumn(), attr
)
2776 || !cell
->GtkIsUsingDefaultAttrs() )
2778 bool usingDefaultAttrs
= !cell
->GtkSetAttr(attr
);
2779 cell
->GtkSetUsingDefaultAttrs(usingDefaultAttrs
);
2781 // else: no custom attributes specified and we're already using the default
2782 // ones -- nothing to do
2787 #include <wx/listimpl.cpp>
2788 WX_DEFINE_LIST(wxDataViewColumnList
)
2790 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
2791 unsigned int model_column
, int width
,
2792 wxAlignment align
, int flags
)
2793 : wxDataViewColumnBase( cell
, model_column
)
2795 Init( align
, flags
, width
);
2800 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
2801 unsigned int model_column
, int width
,
2802 wxAlignment align
, int flags
)
2803 : wxDataViewColumnBase( bitmap
, cell
, model_column
)
2805 Init( align
, flags
, width
);
2807 SetBitmap( bitmap
);
2810 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
2812 m_isConnected
= false;
2814 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
2815 m_column
= (GtkWidget
*) column
;
2818 SetAlignment( align
);
2822 // Create container for icon and label
2823 GtkWidget
*box
= gtk_hbox_new( FALSE
, 1 );
2824 gtk_widget_show( box
);
2825 // gtk_container_set_border_width((GtkContainer*)box, 2);
2826 m_image
= gtk_image_new();
2827 gtk_box_pack_start(GTK_BOX(box
), m_image
, FALSE
, FALSE
, 1);
2828 m_label
= gtk_label_new("");
2829 gtk_box_pack_end( GTK_BOX(box
), GTK_WIDGET(m_label
), FALSE
, FALSE
, 1 );
2830 gtk_tree_view_column_set_widget( column
, box
);
2832 wxDataViewRenderer
* const colRenderer
= GetRenderer();
2833 GtkCellRenderer
* const cellRenderer
= colRenderer
->GetGtkHandle();
2835 colRenderer
->GtkPackIntoColumn(column
);
2837 gtk_tree_view_column_set_cell_data_func( column
, cellRenderer
,
2838 wxGtkTreeCellDataFunc
, (gpointer
) colRenderer
, NULL
);
2841 void wxDataViewColumn::OnInternalIdle()
2846 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
2848 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2851 g_signal_connect(column
->button
, "button_press_event",
2852 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
2854 // otherwise the event will be blocked by GTK+
2855 gtk_tree_view_column_set_clickable( column
, TRUE
);
2857 m_isConnected
= true;
2862 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
2864 wxDataViewColumnBase::SetOwner( owner
);
2866 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2868 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
2871 void wxDataViewColumn::SetTitle( const wxString
&title
)
2873 wxDataViewCtrl
*ctrl
= GetOwner();
2874 gtk_label_set_text( GTK_LABEL(m_label
), ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
2875 : wxGTK_CONV_SYS(title
) );
2877 gtk_widget_hide( m_label
);
2879 gtk_widget_show( m_label
);
2882 wxString
wxDataViewColumn::GetTitle() const
2884 return wxGTK_CONV_BACK_FONT(
2885 gtk_label_get_text( GTK_LABEL(m_label
) ),
2886 GetOwner()->GetFont()
2890 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
2892 wxDataViewColumnBase::SetBitmap( bitmap
);
2896 GtkImage
*gtk_image
= GTK_IMAGE(m_image
);
2898 GdkBitmap
*mask
= NULL
;
2899 if (bitmap
.GetMask())
2900 mask
= bitmap
.GetMask()->GetBitmap();
2902 if (bitmap
.HasPixbuf())
2904 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
2905 bitmap
.GetPixbuf());
2909 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
2910 bitmap
.GetPixmap(), mask
);
2912 gtk_widget_show( m_image
);
2916 gtk_widget_hide( m_image
);
2920 void wxDataViewColumn::SetHidden( bool hidden
)
2922 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
2925 void wxDataViewColumn::SetResizeable( bool resizeable
)
2927 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizeable
);
2930 void wxDataViewColumn::SetAlignment( wxAlignment align
)
2932 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2934 gfloat xalign
= 0.0;
2935 if (align
== wxALIGN_RIGHT
)
2937 if (align
== wxALIGN_CENTER_HORIZONTAL
||
2938 align
== wxALIGN_CENTER
)
2941 gtk_tree_view_column_set_alignment( column
, xalign
);
2943 if (m_renderer
&& m_renderer
->GetAlignment() == -1)
2944 m_renderer
->GtkUpdateAlignment();
2947 wxAlignment
wxDataViewColumn::GetAlignment() const
2949 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
2952 return wxALIGN_RIGHT
;
2954 return wxALIGN_CENTER_HORIZONTAL
;
2956 return wxALIGN_LEFT
;
2959 void wxDataViewColumn::SetSortable( bool sortable
)
2961 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2965 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
2969 gtk_tree_view_column_set_sort_column_id( column
, -1 );
2970 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
2971 gtk_tree_view_column_set_clickable( column
, FALSE
);
2975 bool wxDataViewColumn::IsSortable() const
2977 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2978 return gtk_tree_view_column_get_clickable( column
);
2981 void wxDataViewColumn::SetAsSortKey( bool WXUNUSED(sort
) )
2983 // it might not make sense to have this function in wxHeaderColumn at
2984 // all in fact, changing of the sort order should only be done using the
2985 // associated control API
2986 wxFAIL_MSG( "not implemented" );
2989 bool wxDataViewColumn::IsSortKey() const
2991 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2992 return gtk_tree_view_column_get_sort_indicator( column
);
2995 bool wxDataViewColumn::IsResizeable() const
2997 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2998 return gtk_tree_view_column_get_resizable( column
);
3001 bool wxDataViewColumn::IsHidden() const
3003 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3004 return !gtk_tree_view_column_get_visible( column
);
3007 void wxDataViewColumn::SetSortOrder( bool ascending
)
3009 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3012 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
3014 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
3016 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
3019 bool wxDataViewColumn::IsSortOrderAscending() const
3021 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3023 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
3026 void wxDataViewColumn::SetMinWidth( int width
)
3028 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
3031 int wxDataViewColumn::GetMinWidth() const
3033 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
3036 int wxDataViewColumn::GetWidth() const
3038 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
3041 void wxDataViewColumn::SetWidth( int width
)
3046 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
3048 // TODO find a better calculation
3049 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), wxDVC_DEFAULT_WIDTH
);
3051 // this is unpractical for large numbers of items and disables
3052 // user resizing, which is totally unexpected
3053 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
3058 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
3060 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
3064 void wxDataViewColumn::SetReorderable( bool reorderable
)
3066 gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column
), reorderable
);
3069 bool wxDataViewColumn::IsReorderable() const
3071 return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column
) );
3074 //-----------------------------------------------------------------------------
3075 // wxGtkTreeModelNode
3076 //-----------------------------------------------------------------------------
3079 class wxGtkTreeModelChildWithPos
3087 int wxGtkTreeModelChildWithPosCmp( const void* data1
, const void* data2
, const void* user_data
)
3089 const wxGtkTreeModelChildWithPos
* child1
= (const wxGtkTreeModelChildWithPos
*) data1
;
3090 const wxGtkTreeModelChildWithPos
* child2
= (const wxGtkTreeModelChildWithPos
*) data2
;
3091 const wxDataViewCtrlInternal
*internal
= (const wxDataViewCtrlInternal
*) user_data
;
3092 int ret
= internal
->GetDataViewModel()->Compare( child1
->id
, child2
->id
,
3093 internal
->GetSortColumn(), (internal
->GetSortOrder() == GTK_SORT_DESCENDING
) );
3099 int LINKAGEMODE
wxGtkTreeModelChildPtrCmp( void*** data1
, void*** data2
)
3101 return gs_internal
->GetDataViewModel()->Compare( **data1
, **data2
,
3102 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
3105 WX_DEFINE_ARRAY_PTR( void**, wxGtkTreeModelChildrenPtr
);
3108 void wxGtkTreeModelNode::Resort()
3110 size_t child_count
= GetChildCount();
3111 if (child_count
== 0)
3114 size_t node_count
= GetNodesCount();
3116 if (child_count
== 1)
3118 if (node_count
== 1)
3120 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
3126 gint
*new_order
= new gint
[child_count
];
3129 // m_children has the original *void
3130 // ptrs points to these
3131 wxGtkTreeModelChildrenPtr ptrs
;
3133 for (i
= 0; i
< child_count
; i
++)
3134 ptrs
.Add( &(m_children
[i
]) );
3136 gs_internal
= m_internal
;
3137 ptrs
.Sort( &wxGtkTreeModelChildPtrCmp
);
3139 wxGtkTreeModelChildren temp
;
3140 void** base_ptr
= &(m_children
[0]);
3141 // Transfer positions to new_order array and
3143 for (i
= 0; i
< child_count
; i
++)
3145 new_order
[i
] = ptrs
[i
] - base_ptr
;
3146 temp
.Add( *ptrs
[i
] );
3149 // Transfer IDs back to m_children
3151 WX_APPEND_ARRAY( temp
, m_children
);
3156 // Build up array with IDs and original positions
3157 wxGtkTreeModelChildWithPos
* temp
= new wxGtkTreeModelChildWithPos
[child_count
];
3159 for (i
= 0; i
< child_count
; i
++)
3162 temp
[i
].id
= m_children
[i
];
3164 // Sort array keeping original positions
3165 wxQsort( temp
, child_count
, sizeof(wxGtkTreeModelChildWithPos
),
3166 &wxGtkTreeModelChildWithPosCmp
, m_internal
);
3167 // Transfer positions to new_order array and
3168 // IDs to m_children
3170 for (i
= 0; i
< child_count
; i
++)
3172 new_order
[i
] = temp
[i
].pos
;
3173 m_children
.Add( temp
[i
].id
);
3182 wxGtkTreeModelChildren temp
;
3183 WX_APPEND_ARRAY( temp
, m_children
);
3185 gs_internal
= m_internal
;
3186 m_children
.Sort( &wxGtkTreeModelChildCmp
);
3189 for (pos
= 0; pos
< child_count
; pos
++)
3191 void *id
= m_children
.Item( pos
);
3192 int old_pos
= temp
.Index( id
);
3193 new_order
[pos
] = old_pos
;
3197 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
3200 iter
.user_data
= GetItem().GetID();
3201 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
3203 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3205 gtk_tree_model_rows_reordered( gtk_tree_model
, path
, &iter
, new_order
);
3207 gtk_tree_path_free (path
);
3209 delete [] new_order
;
3212 for (pos
= 0; pos
< node_count
; pos
++)
3214 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
3219 //-----------------------------------------------------------------------------
3220 // wxDataViewCtrlInternal
3221 //-----------------------------------------------------------------------------
3223 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
,
3224 wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
)
3227 m_wx_model
= wx_model
;
3228 m_gtk_model
= gtk_model
;
3230 m_sort_order
= GTK_SORT_ASCENDING
;
3232 m_dataview_sort_column
= NULL
;
3234 m_dragDataObject
= NULL
;
3235 m_dropDataObject
= NULL
;
3237 if (!m_wx_model
->IsVirtualListModel())
3241 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
3243 g_object_unref( m_gtk_model
);
3245 delete m_dragDataObject
;
3246 delete m_dropDataObject
;
3249 void wxDataViewCtrlInternal::InitTree()
3251 wxDataViewItem item
;
3252 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
3254 BuildBranch( m_root
);
3257 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
3259 if (node
->GetChildCount() == 0)
3261 wxDataViewItemArray children
;
3262 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
3264 for (pos
= 0; pos
< count
; pos
++)
3266 wxDataViewItem child
= children
[pos
];
3268 if (m_wx_model
->IsContainer( child
))
3269 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
3271 node
->AddLeave( child
.GetID() );
3273 // Don't send any events here
3280 bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat
&format
)
3282 wxGtkString
atom_str( gdk_atom_name( format
) );
3283 m_dragSourceTargetEntryTarget
= wxCharBuffer( atom_str
);
3285 m_dragSourceTargetEntry
.target
= m_dragSourceTargetEntryTarget
.data();
3286 m_dragSourceTargetEntry
.flags
= 0;
3287 m_dragSourceTargetEntry
.info
= static_cast<guint
>(-1);
3289 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3290 GDK_BUTTON1_MASK
, &m_dragSourceTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3295 bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat
&format
)
3297 wxGtkString
atom_str( gdk_atom_name( format
) );
3298 m_dropTargetTargetEntryTarget
= wxCharBuffer( atom_str
);
3300 m_dropTargetTargetEntry
.target
= m_dropTargetTargetEntryTarget
.data();
3301 m_dropTargetTargetEntry
.flags
= 0;
3302 m_dropTargetTargetEntry
.info
= static_cast<guint
>(-1);
3304 gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3305 &m_dropTargetTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3310 gboolean
wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource
*WXUNUSED(drag_source
),
3313 delete m_dragDataObject
;
3316 if (!get_iter( &iter
, path
)) return FALSE
;
3317 wxDataViewItem
item( (void*) iter
.user_data
);
3319 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3320 event
.SetEventObject( m_owner
);
3321 event
.SetItem( item
);
3322 event
.SetModel( m_wx_model
);
3323 if (!m_owner
->HandleWindowEvent( event
))
3326 if (!event
.IsAllowed())
3329 wxDataObject
*obj
= event
.GetDataObject();
3333 m_dragDataObject
= obj
;
3339 wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource
*WXUNUSED(drag_source
),
3340 GtkTreePath
*WXUNUSED(path
))
3345 gboolean
wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource
*WXUNUSED(drag_source
),
3346 GtkTreePath
*path
, GtkSelectionData
*selection_data
)
3349 if (!get_iter( &iter
, path
)) return FALSE
;
3350 wxDataViewItem
item( (void*) iter
.user_data
);
3352 if (!m_dragDataObject
->IsSupported( selection_data
->target
))
3355 size_t size
= m_dragDataObject
->GetDataSize( selection_data
->target
);
3359 void *buf
= malloc( size
);
3361 gboolean res
= FALSE
;
3362 if (m_dragDataObject
->GetDataHere( selection_data
->target
, buf
))
3366 gtk_selection_data_set( selection_data
, selection_data
->target
,
3367 8, (const guchar
*) buf
, size
);
3376 wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3378 GtkSelectionData
*selection_data
)
3381 if (!get_iter( &iter
, path
)) return FALSE
;
3382 wxDataViewItem
item( (void*) iter
.user_data
);
3384 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
3385 event
.SetEventObject( m_owner
);
3386 event
.SetItem( item
);
3387 event
.SetModel( m_wx_model
);
3388 event
.SetDataFormat( selection_data
->target
);
3389 event
.SetDataSize( selection_data
->length
);
3390 event
.SetDataBuffer( selection_data
->data
);
3391 if (!m_owner
->HandleWindowEvent( event
))
3394 if (!event
.IsAllowed())
3401 wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3403 GtkSelectionData
*selection_data
)
3406 if (!get_iter( &iter
, path
)) return FALSE
;
3407 wxDataViewItem
item( (void*) iter
.user_data
);
3409 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
3410 event
.SetEventObject( m_owner
);
3411 event
.SetItem( item
);
3412 event
.SetModel( m_wx_model
);
3413 event
.SetDataFormat( selection_data
->target
);
3414 if (!m_owner
->HandleWindowEvent( event
))
3417 if (!event
.IsAllowed())
3423 // notifications from wxDataViewModel
3425 bool wxDataViewCtrlInternal::Cleared()
3427 GtkWidget
* tree_widget
= GetOwner()->GtkGetTreeView();
3428 gtk_tree_view_set_model( GTK_TREE_VIEW(tree_widget
), NULL
);
3429 gtk_tree_view_set_model( GTK_TREE_VIEW(tree_widget
), GTK_TREE_MODEL(m_gtk_model
) );
3440 void wxDataViewCtrlInternal::Resort()
3442 if (!m_wx_model
->IsVirtualListModel())
3446 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3448 if (!m_wx_model
->IsVirtualListModel())
3450 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3451 wxASSERT_MSG(parent_node
,
3452 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3454 if (m_wx_model
->IsContainer( item
))
3455 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
3457 parent_node
->AddLeave( item
.GetID() );
3463 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3465 if (!m_wx_model
->IsVirtualListModel())
3467 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3468 wxASSERT_MSG(parent_node
,
3469 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3471 parent_node
->DeleteChild( item
.GetID() );
3477 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
3479 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3480 event
.SetEventObject( m_owner
);
3481 event
.SetModel( m_owner
->GetModel() );
3482 event
.SetItem( item
);
3483 m_owner
->HandleWindowEvent( event
);
3488 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
3490 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3491 event
.SetEventObject( m_owner
);
3492 event
.SetModel( m_owner
->GetModel() );
3493 event
.SetColumn( col
);
3494 event
.SetDataViewColumn( GetOwner()->GetColumn(col
) );
3495 event
.SetItem( item
);
3496 m_owner
->HandleWindowEvent( event
);
3503 GtkTreeModelFlags
wxDataViewCtrlInternal::get_flags()
3507 if ( m_wx_model
->IsListModel() )
3508 flags
|= GTK_TREE_MODEL_LIST_ONLY
;
3510 if ( !m_wx_model
->IsVirtualListModel() )
3511 flags
|= GTK_TREE_MODEL_ITERS_PERSIST
;
3513 return GtkTreeModelFlags(flags
);
3516 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
3519 if (m_wx_model
->IsVirtualListModel())
3521 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3523 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
3525 if (i
>= wx_model
->GetCount())
3528 iter
->stamp
= m_gtk_model
->stamp
;
3529 // user_data is just the index +1
3530 iter
->user_data
= (gpointer
) (i
+1);
3536 int depth
= gtk_tree_path_get_depth( path
);
3538 wxGtkTreeModelNode
*node
= m_root
;
3541 for (i
= 0; i
< depth
; i
++)
3543 BuildBranch( node
);
3545 gint pos
= gtk_tree_path_get_indices (path
)[i
];
3546 if (pos
< 0) return FALSE
;
3547 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
3549 void* id
= node
->GetChildren().Item( (size_t) pos
);
3553 iter
->stamp
= m_gtk_model
->stamp
;
3554 iter
->user_data
= id
;
3558 size_t count
= node
->GetNodes().GetCount();
3560 for (pos2
= 0; pos2
< count
; pos2
++)
3562 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
3563 if (child_node
->GetItem().GetID() == id
)
3575 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
3577 // When this is called from ItemDeleted(), the item is already
3578 // deleted in the model.
3580 GtkTreePath
*retval
= gtk_tree_path_new ();
3582 if (m_wx_model
->IsVirtualListModel())
3584 // iter is root, add nothing
3585 if (!iter
->user_data
)
3588 // user_data is just the index +1
3589 int i
= ( (wxUIntPtr
) iter
->user_data
) -1;
3590 gtk_tree_path_append_index (retval
, i
);
3594 void *id
= iter
->user_data
;
3596 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
3599 int pos
= node
->GetChildren().Index( id
);
3601 gtk_tree_path_prepend_index( retval
, pos
);
3603 id
= node
->GetItem().GetID();
3604 node
= node
->GetParent();
3611 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
3613 if (m_wx_model
->IsVirtualListModel())
3615 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3617 // user_data is just the index +1
3618 int n
= ( (wxUIntPtr
) iter
->user_data
) -1;
3622 iter
->user_data
= NULL
;
3626 if (n
>= (int) wx_model
->GetCount()-1)
3628 iter
->user_data
= NULL
;
3632 // user_data is just the index +1 (+2 because we need the next)
3633 iter
->user_data
= (gpointer
) (n
+2);
3637 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
3638 if( parent
== NULL
)
3640 iter
->user_data
= NULL
;
3644 int pos
= parent
->GetChildren().Index( iter
->user_data
);
3646 if (pos
== (int) parent
->GetChildCount()-1)
3648 iter
->user_data
= NULL
;
3652 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
3658 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
3660 if (m_wx_model
->IsVirtualListModel())
3662 // this is a list, nodes have no children
3666 iter
->stamp
= m_gtk_model
->stamp
;
3667 iter
->user_data
= (gpointer
) 1;
3675 if (m_root
->GetChildCount() == 0) return FALSE
;
3676 iter
->stamp
= m_gtk_model
->stamp
;
3677 iter
->user_data
= (gpointer
) m_root
->GetChildren().Item( 0 );
3682 wxDataViewItem item
;
3684 item
= wxDataViewItem( (void*) parent
->user_data
);
3686 if (!m_wx_model
->IsContainer( item
))
3689 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3690 wxASSERT_MSG(parent_node
,
3691 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3693 BuildBranch( parent_node
);
3695 if (parent_node
->GetChildCount() == 0)
3698 iter
->stamp
= m_gtk_model
->stamp
;
3699 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
3705 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
3707 if (m_wx_model
->IsVirtualListModel())
3709 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3712 return (wx_model
->GetCount() > 0);
3714 // this is a list, nodes have no children
3720 return (m_root
->GetChildCount() > 0);
3722 wxDataViewItem
item( (void*) iter
->user_data
);
3724 bool is_container
= m_wx_model
->IsContainer( item
);
3729 wxGtkTreeModelNode
*node
= FindNode( iter
);
3731 "Did you forget a call to ItemAdded()? The iterator is unknown to the wxGtkTreeModel");
3733 BuildBranch( node
);
3735 return (node
->GetChildCount() > 0);
3739 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
3741 if (m_wx_model
->IsVirtualListModel())
3743 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3746 return (gint
) wx_model
->GetCount();
3753 return m_root
->GetChildCount();
3755 wxDataViewItem
item( (void*) iter
->user_data
);
3757 if (!m_wx_model
->IsContainer( item
))
3760 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
3761 wxASSERT_MSG(parent_node
,
3762 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3764 BuildBranch( parent_node
);
3766 return parent_node
->GetChildCount();
3770 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
3772 if (m_wx_model
->IsVirtualListModel())
3774 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3782 if (n
>= (gint
) wx_model
->GetCount())
3785 iter
->stamp
= m_gtk_model
->stamp
;
3786 // user_data is just the index +1
3787 iter
->user_data
= (gpointer
) (n
+1);
3794 if (parent
) id
= (void*) parent
->user_data
;
3795 wxDataViewItem
item( id
);
3797 if (!m_wx_model
->IsContainer( item
))
3800 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3801 wxASSERT_MSG(parent_node
,
3802 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3804 BuildBranch( parent_node
);
3806 iter
->stamp
= m_gtk_model
->stamp
;
3807 iter
->user_data
= parent_node
->GetChildren().Item( n
);
3813 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
3815 if (m_wx_model
->IsVirtualListModel())
3821 wxGtkTreeModelNode
*node
= FindParentNode( child
);
3825 iter
->stamp
= m_gtk_model
->stamp
;
3826 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
3832 // item can be deleted already in the model
3833 int wxDataViewCtrlInternal::GetIndexOf( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3835 if (m_wx_model
->IsVirtualListModel())
3837 return wxPtrToUInt(item
.GetID()) - 1;
3841 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3842 wxGtkTreeModelChildren
&children
= parent_node
->GetChildren();
3844 for (j
= 0; j
< children
.GetCount(); j
++)
3846 if (children
[j
] == item
.GetID())
3854 static wxGtkTreeModelNode
*
3855 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3861 list
.DeleteContents( true );
3862 wxDataViewItem
it( item
);
3866 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3867 list
.Insert( pItem
);
3868 it
= model
->GetParent( it
);
3871 wxGtkTreeModelNode
* node
= treeNode
;
3872 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3874 if( node
&& node
->GetNodes().GetCount() != 0 )
3876 int len
= node
->GetNodes().GetCount();
3877 wxGtkTreeModelNodes
&nodes
= node
->GetNodes();
3879 for( ; j
< len
; j
++)
3881 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3900 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
3905 wxDataViewItem
item( (void*) iter
->user_data
);
3909 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3914 wxLogDebug( "Not found %p", iter->user_data );
3918 // TODO: remove this code
3924 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
3929 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3934 wxLogDebug( "Not found %p", item.GetID() );
3938 // TODO: remove this code
3944 static wxGtkTreeModelNode
*
3945 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3951 list
.DeleteContents( true );
3955 wxDataViewItem
it( model
->GetParent( item
) );
3958 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3959 list
.Insert( pItem
);
3960 it
= model
->GetParent( it
);
3963 wxGtkTreeModelNode
* node
= treeNode
;
3964 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3966 if( node
&& node
->GetNodes().GetCount() != 0 )
3968 int len
= node
->GetNodes().GetCount();
3969 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3971 for( ; j
< len
; j
++)
3973 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3988 //Examine whether the node is item's parent node
3989 int len
= node
->GetChildCount();
3990 for( int i
= 0; i
< len
; i
++ )
3992 if( node
->GetChildren().Item( i
) == item
.GetID() )
3998 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
4003 wxDataViewItem
item( (void*) iter
->user_data
);
4007 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
4010 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
4015 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
4018 //-----------------------------------------------------------------------------
4019 // wxDataViewCtrl signal callbacks
4020 //-----------------------------------------------------------------------------
4023 wxdataview_selection_changed_callback( GtkTreeSelection
* WXUNUSED(selection
), wxDataViewCtrl
*dv
)
4025 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
4028 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
4029 event
.SetItem( dv
->GetSelection() );
4030 event
.SetModel( dv
->GetModel() );
4031 dv
->HandleWindowEvent( event
);
4035 wxdataview_row_activated_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreePath
*path
,
4036 GtkTreeViewColumn
*WXUNUSED(column
), wxDataViewCtrl
*dv
)
4038 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
4041 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4042 wxDataViewItem
item( (void*) iter
.user_data
);;
4043 event
.SetItem( item
);
4044 event
.SetModel( dv
->GetModel() );
4045 dv
->HandleWindowEvent( event
);
4049 wxdataview_test_expand_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4050 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4052 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
4054 wxDataViewItem
item( (void*) iter
->user_data
);;
4055 event
.SetItem( item
);
4056 event
.SetModel( dv
->GetModel() );
4057 dv
->HandleWindowEvent( event
);
4059 return !event
.IsAllowed();
4063 wxdataview_row_expanded_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4064 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4066 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
4068 wxDataViewItem
item( (void*) iter
->user_data
);;
4069 event
.SetItem( item
);
4070 event
.SetModel( dv
->GetModel() );
4071 dv
->HandleWindowEvent( event
);
4075 wxdataview_test_collapse_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4076 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4078 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
4080 wxDataViewItem
item( (void*) iter
->user_data
);;
4081 event
.SetItem( item
);
4082 event
.SetModel( dv
->GetModel() );
4083 dv
->HandleWindowEvent( event
);
4085 return !event
.IsAllowed();
4089 wxdataview_row_collapsed_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4090 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4092 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
4094 wxDataViewItem
item( (void*) iter
->user_data
);;
4095 event
.SetItem( item
);
4096 event
.SetModel( dv
->GetModel() );
4097 dv
->HandleWindowEvent( event
);
4100 //-----------------------------------------------------------------------------
4102 //-----------------------------------------------------------------------------
4104 void wxDataViewCtrl::AddChildGTK(wxWindowGTK
* child
)
4106 GtkWidget
* treeview
= GtkGetTreeView();
4108 // Insert widget in GtkTreeView
4109 if (GTK_WIDGET_REALIZED(treeview
))
4110 gtk_widget_set_parent_window( child
->m_widget
,
4111 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
4112 gtk_widget_set_parent( child
->m_widget
, treeview
);
4116 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
4117 GtkAllocation
*WXUNUSED(gtk_alloc
),
4118 wxDataViewCtrl
*win
)
4120 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
4123 wxWindow
*child
= node
->GetData();
4126 gtk_widget_size_request( child
->m_widget
, &req
);
4128 GtkAllocation alloc
;
4129 alloc
.x
= child
->m_x
;
4130 alloc
.y
= child
->m_y
;
4131 alloc
.width
= child
->m_width
;
4132 alloc
.height
= child
->m_height
;
4133 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
4135 node
= node
->GetNext();
4140 //-----------------------------------------------------------------------------
4141 // "motion_notify_event"
4142 //-----------------------------------------------------------------------------
4145 gtk_dataview_motion_notify_callback( GtkWidget
*WXUNUSED(widget
),
4146 GdkEventMotion
*gdk_event
,
4147 wxDataViewCtrl
*dv
)
4149 if (gdk_event
->is_hint
)
4153 GdkModifierType state
;
4154 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
4159 GtkTreePath
*path
= NULL
;
4160 GtkTreeViewColumn
*column
= NULL
;
4163 if (gtk_tree_view_get_path_at_pos(
4164 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4165 (int) gdk_event
->x
, (int) gdk_event
->y
,
4174 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4176 gtk_tree_path_free( path
);
4184 //-----------------------------------------------------------------------------
4185 // "button_press_event"
4186 //-----------------------------------------------------------------------------
4189 gtk_dataview_button_press_callback( GtkWidget
*WXUNUSED(widget
),
4190 GdkEventButton
*gdk_event
,
4191 wxDataViewCtrl
*dv
)
4193 if ((gdk_event
->button
== 3) && (gdk_event
->type
== GDK_BUTTON_PRESS
))
4195 GtkTreePath
*path
= NULL
;
4196 GtkTreeViewColumn
*column
= NULL
;
4199 if (gtk_tree_view_get_path_at_pos(
4200 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4201 (int) gdk_event
->x
, (int) gdk_event
->y
,
4210 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4212 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, dv
->GetId() );
4213 wxDataViewItem
item( (void*) iter
.user_data
);;
4214 event
.SetItem( item
);
4215 event
.SetModel( dv
->GetModel() );
4216 bool ret
= dv
->HandleWindowEvent( event
);
4217 gtk_tree_path_free( path
);
4226 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
4228 wxDataViewCtrl::~wxDataViewCtrl()
4231 GetModel()->RemoveNotifier( m_notifier
);
4235 // remove the model from the GtkTreeView before it gets destroyed by the
4236 // wxDataViewCtrlBase's dtor
4237 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), NULL
);
4242 void wxDataViewCtrl::Init()
4247 m_cols
.DeleteContents( true );
4250 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
4251 const wxPoint
& pos
, const wxSize
& size
,
4252 long style
, const wxValidator
& validator
)
4254 if (!PreCreation( parent
, pos
, size
) ||
4255 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
4257 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
4261 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
4262 g_object_ref(m_widget
);
4264 GTKScrolledWindowSetBorder(m_widget
, style
);
4266 m_treeview
= gtk_tree_view_new();
4267 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
4269 g_signal_connect (m_treeview
, "size_allocate",
4270 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
4273 if (!gtk_check_version(2,6,0))
4275 bool fixed
= (style
& wxDV_VARIABLE_LINE_HEIGHT
) == 0;
4276 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4280 if (style
& wxDV_MULTIPLE
)
4282 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4283 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
4286 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
4289 if (!gtk_check_version(2,10,0))
4291 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
4293 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
4294 (style
& wxDV_VERT_RULES
) != 0)
4295 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
4296 else if (style
& wxDV_VERT_RULES
)
4297 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
4298 else if (style
& wxDV_HORIZ_RULES
)
4299 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
4301 if (grid
!= GTK_TREE_VIEW_GRID_LINES_NONE
)
4302 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
4306 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_ROW_LINES
) != 0 );
4308 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
4309 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
4310 gtk_widget_show (m_treeview
);
4312 m_parent
->DoAddChild( this );
4316 GtkEnableSelectionEvents();
4318 g_signal_connect_after (m_treeview
, "row-activated",
4319 G_CALLBACK (wxdataview_row_activated_callback
), this);
4321 g_signal_connect (m_treeview
, "test-collapse-row",
4322 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
4324 g_signal_connect_after (m_treeview
, "row-collapsed",
4325 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
4327 g_signal_connect (m_treeview
, "test-expand-row",
4328 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
4330 g_signal_connect_after (m_treeview
, "row-expanded",
4331 G_CALLBACK (wxdataview_row_expanded_callback
), this);
4333 g_signal_connect (m_treeview
, "motion_notify_event",
4334 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
4336 g_signal_connect (m_treeview
, "button_press_event",
4337 G_CALLBACK (gtk_dataview_button_press_callback
), this);
4342 void wxDataViewCtrl::OnInternalIdle()
4344 wxWindow::OnInternalIdle();
4346 unsigned int cols
= GetColumnCount();
4348 for (i
= 0; i
< cols
; i
++)
4350 wxDataViewColumn
*col
= GetColumn( i
);
4351 col
->OnInternalIdle();
4355 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4357 wxDELETE(m_internal
);
4359 if (!wxDataViewCtrlBase::AssociateModel( model
))
4363 if (!gtk_check_version(2,6,0))
4365 bool fixed
= (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
) == 0) || (model
->IsVirtualListModel()));
4366 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4370 GtkWxTreeModel
*gtk_model
= wxgtk_tree_model_new();
4371 m_internal
= new wxDataViewCtrlInternal( this, model
, gtk_model
);
4372 gtk_model
->internal
= m_internal
;
4374 m_notifier
= new wxGtkDataViewModelNotifier( gtk_model
, model
, this );
4376 model
->AddNotifier( m_notifier
);
4378 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_model
) );
4380 // unref in wxDataViewCtrlInternal
4381 // g_object_unref( gtk_model );
4386 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4388 return m_internal
->EnableDragSource( format
);
4391 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4393 return m_internal
->EnableDropTarget( format
);
4396 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4398 if (!wxDataViewCtrlBase::AppendColumn(col
))
4401 m_cols
.Append( col
);
4404 if (!gtk_check_version(2,6,0))
4406 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4407 GTK_TREE_VIEW_COLUMN_FIXED
)
4408 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4412 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
4413 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4418 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4420 if (!wxDataViewCtrlBase::PrependColumn(col
))
4423 m_cols
.Insert( col
);
4426 if (!gtk_check_version(2,6,0))
4428 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4429 GTK_TREE_VIEW_COLUMN_FIXED
)
4430 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4434 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4435 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
4440 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4442 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4445 m_cols
.Insert( pos
, col
);
4448 if (!gtk_check_version(2,6,0))
4450 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4451 GTK_TREE_VIEW_COLUMN_FIXED
)
4452 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4456 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4457 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), pos
);
4462 unsigned int wxDataViewCtrl::GetColumnCount() const
4464 return m_cols
.GetCount();
4467 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
4469 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
4473 wxDataViewColumnList::const_iterator iter
;
4474 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4476 wxDataViewColumn
*col
= *iter
;
4477 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
4486 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4488 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4489 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
4491 m_cols
.DeleteObject( column
);
4496 bool wxDataViewCtrl::ClearColumns()
4498 wxDataViewColumnList::iterator iter
;
4499 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4501 wxDataViewColumn
*col
= *iter
;
4502 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4503 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4511 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4513 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetConstGtkHandle());
4515 GList
*list
= gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview
) );
4517 gint pos
= g_list_index( list
, (gconstpointer
) gtk_column
);
4519 g_list_free( list
);
4524 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4526 return m_internal
->GetDataViewSortColumn();
4529 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4532 iter
.user_data
= item
.GetID();
4533 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4534 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
4535 gtk_tree_path_free( path
);
4538 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4541 iter
.user_data
= item
.GetID();
4542 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4543 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
4544 gtk_tree_path_free( path
);
4547 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4550 iter
.user_data
= item
.GetID();
4551 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4552 bool res
= gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview
), path
);
4553 gtk_tree_path_free( path
);
4558 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4560 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4562 if (m_windowStyle
& wxDV_MULTIPLE
)
4564 // Report the first one
4565 GtkTreeModel
*model
;
4566 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4570 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4572 m_internal
->get_iter( &iter
, path
);
4575 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4576 g_list_free( list
);
4578 return wxDataViewItem( (void*) iter
.user_data
);
4584 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
4586 wxDataViewItem
item( (void*) iter
.user_data
);
4591 return wxDataViewItem(0);
4594 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4598 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4599 if (HasFlag(wxDV_MULTIPLE
))
4601 GtkTreeModel
*model
;
4602 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4607 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4610 m_internal
->get_iter( &iter
, path
);
4612 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4614 list
= g_list_next( list
);
4619 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4620 g_list_free( list
);
4626 GtkTreeModel
*model
;
4628 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
4631 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4639 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4641 GtkDisableSelectionEvents();
4643 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4645 gtk_tree_selection_unselect_all( selection
);
4647 wxDataViewItem last_parent
;
4650 for (i
= 0; i
< sel
.GetCount(); i
++)
4652 wxDataViewItem item
= sel
[i
];
4653 wxDataViewItem parent
= GetModel()->GetParent( item
);
4656 if (parent
!= last_parent
)
4657 ExpandAncestors(item
);
4659 last_parent
= parent
;
4662 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4663 iter
.user_data
= (gpointer
) item
.GetID();
4664 gtk_tree_selection_select_iter( selection
, &iter
);
4667 GtkEnableSelectionEvents();
4670 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4672 ExpandAncestors(item
);
4674 GtkDisableSelectionEvents();
4676 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4679 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4680 iter
.user_data
= (gpointer
) item
.GetID();
4681 gtk_tree_selection_select_iter( selection
, &iter
);
4683 GtkEnableSelectionEvents();
4686 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4688 GtkDisableSelectionEvents();
4690 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4693 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4694 iter
.user_data
= (gpointer
) item
.GetID();
4695 gtk_tree_selection_unselect_iter( selection
, &iter
);
4697 GtkEnableSelectionEvents();
4700 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4702 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4705 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4706 iter
.user_data
= (gpointer
) item
.GetID();
4708 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
4711 void wxDataViewCtrl::SelectAll()
4713 GtkDisableSelectionEvents();
4715 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4717 gtk_tree_selection_select_all( selection
);
4719 GtkEnableSelectionEvents();
4722 void wxDataViewCtrl::UnselectAll()
4724 GtkDisableSelectionEvents();
4726 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4728 gtk_tree_selection_unselect_all( selection
);
4730 GtkEnableSelectionEvents();
4733 void wxDataViewCtrl::EnsureVisible(const wxDataViewItem
& item
,
4734 const wxDataViewColumn
*WXUNUSED(column
))
4736 ExpandAncestors(item
);
4739 iter
.user_data
= (gpointer
) item
.GetID();
4740 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4741 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
4742 gtk_tree_path_free( path
);
4745 void wxDataViewCtrl::HitTest(const wxPoint
& WXUNUSED(point
),
4746 wxDataViewItem
& item
,
4747 wxDataViewColumn
*& column
) const
4749 item
= wxDataViewItem(0);
4754 wxDataViewCtrl::GetItemRect(const wxDataViewItem
& WXUNUSED(item
),
4755 const wxDataViewColumn
*WXUNUSED(column
)) const
4760 void wxDataViewCtrl::DoSetExpanderColumn()
4762 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
4763 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
4766 void wxDataViewCtrl::DoSetIndent()
4770 void wxDataViewCtrl::GtkDisableSelectionEvents()
4772 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4773 g_signal_handlers_disconnect_by_func( selection
,
4774 (gpointer
) (wxdataview_selection_changed_callback
), this);
4777 void wxDataViewCtrl::GtkEnableSelectionEvents()
4779 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4780 g_signal_connect_after (selection
, "changed",
4781 G_CALLBACK (wxdataview_selection_changed_callback
), this);
4784 // ----------------------------------------------------------------------------
4785 // visual attributes stuff
4786 // ----------------------------------------------------------------------------
4790 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
4792 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
4795 void wxDataViewCtrl::DoApplyWidgetStyle(GtkRcStyle
*style
)
4797 wxDataViewCtrlBase::DoApplyWidgetStyle(style
);
4798 gtk_widget_modify_style(m_treeview
, style
);
4801 #endif // !wxUSE_GENERICDATAVIEWCTRL
4803 #endif // wxUSE_DATAVIEWCTRL