1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/dataview.cpp
3 // Purpose: wxDataViewCtrl GTK+2 implementation
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if wxUSE_DATAVIEWCTRL
15 #include "wx/dataview.h"
17 #ifndef wxUSE_GENERICDATAVIEWCTRL
21 #include "wx/dcclient.h"
23 #include "wx/settings.h"
27 #include "wx/stockitem.h"
28 #include "wx/calctrl.h"
29 #include "wx/popupwin.h"
30 #include "wx/listimpl.cpp"
32 #include "wx/gtk/private.h"
33 #include "wx/gtk/dc.h"
34 #include "wx/gtk/dcclient.h"
36 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 static wxDataViewCtrlInternal
*gs_internal
= NULL
;
41 class wxGtkTreeModelNode
;
44 typedef struct _GtkWxTreeModel GtkWxTreeModel
;
47 //-----------------------------------------------------------------------------
48 // wxDataViewCtrlInternal
49 //-----------------------------------------------------------------------------
51 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
52 WX_DEFINE_LIST(ItemList
)
54 class WXDLLIMPEXP_ADV wxDataViewCtrlInternal
57 wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
);
58 ~wxDataViewCtrlInternal();
61 GtkTreeModelFlags
get_flags();
62 gboolean
get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
);
63 GtkTreePath
*get_path( GtkTreeIter
*iter
);
64 gboolean
iter_next( GtkTreeIter
*iter
);
65 gboolean
iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
);
66 gboolean
iter_has_child( GtkTreeIter
*iter
);
67 gint
iter_n_children( GtkTreeIter
*iter
);
68 gboolean
iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
);
69 gboolean
iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
);
73 bool EnableDragSource( const wxDataFormat
&format
);
74 bool EnableDropTarget( const wxDataFormat
&format
);
76 gboolean
row_draggable( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
);
77 gboolean
drag_data_delete( GtkTreeDragSource
*drag_source
, GtkTreePath
* path
);
78 gboolean
drag_data_get( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
,
79 GtkSelectionData
*selection_data
);
80 gboolean
drag_data_received( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest
,
81 GtkSelectionData
*selection_data
);
82 gboolean
row_drop_possible( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest_path
,
83 GtkSelectionData
*selection_data
);
85 // notifactions from wxDataViewModel
86 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
87 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
88 bool ItemChanged( const wxDataViewItem
&item
);
89 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
94 void SetSortOrder( GtkSortType sort_order
) { m_sort_order
= sort_order
; }
95 GtkSortType
GetSortOrder() { return m_sort_order
; }
97 void SetSortColumn( int column
) { m_sort_column
= column
; }
98 int GetSortColumn() { return m_sort_column
; }
100 void SetDataViewSortColumn( wxDataViewColumn
*column
) { m_dataview_sort_column
= column
; }
101 wxDataViewColumn
*GetDataViewSortColumn() { return m_dataview_sort_column
; }
103 bool IsSorted() { return (m_sort_column
>= 0); }
106 wxDataViewModel
* GetDataViewModel() { return m_wx_model
; }
107 wxDataViewCtrl
* GetOwner() { return m_owner
; }
108 GtkWxTreeModel
* GetGtkModel() { return m_gtk_model
; }
112 wxGtkTreeModelNode
*FindNode( const wxDataViewItem
&item
);
113 wxGtkTreeModelNode
*FindNode( GtkTreeIter
*iter
);
114 wxGtkTreeModelNode
*FindParentNode( const wxDataViewItem
&item
);
115 wxGtkTreeModelNode
*FindParentNode( GtkTreeIter
*iter
);
116 void BuildBranch( wxGtkTreeModelNode
*branch
);
119 wxGtkTreeModelNode
*m_root
;
120 wxDataViewModel
*m_wx_model
;
121 GtkWxTreeModel
*m_gtk_model
;
122 wxDataViewCtrl
*m_owner
;
123 GtkSortType m_sort_order
;
124 wxDataViewColumn
*m_dataview_sort_column
;
127 GtkTargetEntry m_dragSourceTargetEntry
;
128 wxCharBuffer m_dragSourceTargetEntryTarget
;
129 wxDataObject
*m_dragDataObject
;
131 GtkTargetEntry m_dropTargetTargetEntry
;
132 wxCharBuffer m_dropTargetTargetEntryTarget
;
133 wxDataObject
*m_dropDataObject
;
137 //-----------------------------------------------------------------------------
138 // wxGtkTreeModelNode
139 //-----------------------------------------------------------------------------
142 int LINKAGEMODE
wxGtkTreeModelChildCmp( void** id1
, void** id2
)
144 int ret
= gs_internal
->GetDataViewModel()->Compare( *id1
, *id2
,
145 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
150 WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode
*, wxGtkTreeModelNodes
);
151 WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren
);
153 class wxGtkTreeModelNode
156 wxGtkTreeModelNode( wxGtkTreeModelNode
* parent
, const wxDataViewItem
&item
,
157 wxDataViewCtrlInternal
*internal
)
161 m_internal
= internal
;
164 ~wxGtkTreeModelNode()
166 size_t count
= m_nodes
.GetCount();
168 for (i
= 0; i
< count
; i
++)
170 wxGtkTreeModelNode
*child
= m_nodes
.Item( i
);
175 unsigned int AddNode( wxGtkTreeModelNode
* child
)
177 m_nodes
.Add( child
);
179 void *id
= child
->GetItem().GetID();
181 m_children
.Add( id
);
183 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
185 gs_internal
= m_internal
;
186 m_children
.Sort( &wxGtkTreeModelChildCmp
);
187 return m_children
.Index( id
);
190 return m_children
.GetCount()-1;
193 unsigned int AddLeave( void* id
)
195 m_children
.Add( id
);
197 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
199 gs_internal
= m_internal
;
200 m_children
.Sort( &wxGtkTreeModelChildCmp
);
201 return m_children
.Index( id
);
204 return m_children
.GetCount()-1;
207 void DeleteChild( void* id
)
209 m_children
.Remove( id
);
211 unsigned int count
= m_nodes
.GetCount();
213 for (pos
= 0; pos
< count
; pos
++)
215 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
216 if (node
->GetItem().GetID() == id
)
218 m_nodes
.RemoveAt( pos
);
226 wxGtkTreeModelNode
* GetParent()
228 wxGtkTreeModelNodes
&GetNodes()
230 wxGtkTreeModelChildren
&GetChildren()
231 { return m_children
; }
233 unsigned int GetChildCount() { return m_children
.GetCount(); }
234 unsigned int GetNodesCount() { return m_nodes
.GetCount(); }
236 wxDataViewItem
&GetItem() { return m_item
; }
237 wxDataViewCtrlInternal
*GetInternal() { return m_internal
; }
242 wxGtkTreeModelNode
*m_parent
;
243 wxGtkTreeModelNodes m_nodes
;
244 wxGtkTreeModelChildren m_children
;
245 wxDataViewItem m_item
;
246 wxDataViewCtrlInternal
*m_internal
;
250 //-----------------------------------------------------------------------------
252 //-----------------------------------------------------------------------------
254 extern bool g_blockEventsOnDrag
;
256 //-----------------------------------------------------------------------------
257 // define new GTK+ class wxGtkTreeModel
258 //-----------------------------------------------------------------------------
262 #define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ())
263 #define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel))
264 #define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
265 #define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL))
266 #define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL))
267 #define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
269 GType
gtk_wx_tree_model_get_type (void);
271 typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass
;
273 struct _GtkWxTreeModel
279 wxDataViewCtrlInternal
*internal
;
282 struct _GtkWxTreeModelClass
284 GObjectClass list_parent_class
;
287 static GtkWxTreeModel
*wxgtk_tree_model_new (void);
288 static void wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
);
289 static void wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
);
291 static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
);
292 static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
);
293 static void wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
);
294 static void wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
);
296 static void wxgtk_tree_model_finalize (GObject
*object
);
297 static GtkTreeModelFlags
wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
);
298 static gint
wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
);
299 static GType
wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
301 static gboolean
wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
304 static GtkTreePath
*wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
306 static void wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
310 static gboolean
wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
312 static gboolean
wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
314 GtkTreeIter
*parent
);
315 static gboolean
wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
317 static gint
wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
319 static gboolean
wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
323 static gboolean
wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
328 static gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
329 gint
*sort_column_id
,
331 static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
334 static void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
336 GtkTreeIterCompareFunc func
,
338 GtkDestroyNotify destroy
);
339 static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
340 GtkTreeIterCompareFunc func
,
342 GtkDestroyNotify destroy
);
343 static gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
);
346 static gboolean
wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
348 static gboolean
wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
350 static gboolean
wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
352 GtkSelectionData
*selection_data
);
353 static gboolean
wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
355 GtkSelectionData
*selection_data
);
356 static gboolean
wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
357 GtkTreePath
*dest_path
,
358 GtkSelectionData
*selection_data
);
361 static GObjectClass
*list_parent_class
= NULL
;
364 gtk_wx_tree_model_get_type (void)
366 static GType tree_model_type
= 0;
368 if (!tree_model_type
)
370 const GTypeInfo tree_model_info
=
372 sizeof (GtkWxTreeModelClass
),
373 NULL
, /* base_init */
374 NULL
, /* base_finalize */
375 (GClassInitFunc
) wxgtk_tree_model_class_init
,
376 NULL
, /* class_finalize */
377 NULL
, /* class_data */
378 sizeof (GtkWxTreeModel
),
380 (GInstanceInitFunc
) wxgtk_tree_model_init
,
383 static const GInterfaceInfo tree_model_iface_info
=
385 (GInterfaceInitFunc
) wxgtk_tree_model_tree_model_init
,
390 static const GInterfaceInfo sortable_iface_info
=
392 (GInterfaceInitFunc
) wxgtk_tree_model_sortable_init
,
397 static const GInterfaceInfo drag_source_iface_info
=
399 (GInterfaceInitFunc
) wxgtk_tree_model_drag_source_init
,
404 static const GInterfaceInfo drag_dest_iface_info
=
406 (GInterfaceInitFunc
) wxgtk_tree_model_drag_dest_init
,
411 tree_model_type
= g_type_register_static (G_TYPE_OBJECT
, "GtkWxTreeModel",
412 &tree_model_info
, (GTypeFlags
)0 );
414 g_type_add_interface_static (tree_model_type
,
416 &tree_model_iface_info
);
417 g_type_add_interface_static (tree_model_type
,
418 GTK_TYPE_TREE_SORTABLE
,
419 &sortable_iface_info
);
420 g_type_add_interface_static (tree_model_type
,
421 GTK_TYPE_TREE_DRAG_DEST
,
422 &drag_dest_iface_info
);
423 g_type_add_interface_static (tree_model_type
,
424 GTK_TYPE_TREE_DRAG_SOURCE
,
425 &drag_source_iface_info
);
428 return tree_model_type
;
431 static GtkWxTreeModel
*
432 wxgtk_tree_model_new(void)
434 GtkWxTreeModel
*retval
= (GtkWxTreeModel
*) g_object_new (GTK_TYPE_WX_TREE_MODEL
, NULL
);
439 wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
)
441 list_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
442 GObjectClass
*object_class
= (GObjectClass
*) klass
;
443 object_class
->finalize
= wxgtk_tree_model_finalize
;
447 wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
)
449 iface
->get_flags
= wxgtk_tree_model_get_flags
;
450 iface
->get_n_columns
= wxgtk_tree_model_get_n_columns
;
451 iface
->get_column_type
= wxgtk_tree_model_get_column_type
;
452 iface
->get_iter
= wxgtk_tree_model_get_iter
;
453 iface
->get_path
= wxgtk_tree_model_get_path
;
454 iface
->get_value
= wxgtk_tree_model_get_value
;
455 iface
->iter_next
= wxgtk_tree_model_iter_next
;
456 iface
->iter_children
= wxgtk_tree_model_iter_children
;
457 iface
->iter_has_child
= wxgtk_tree_model_iter_has_child
;
458 iface
->iter_n_children
= wxgtk_tree_model_iter_n_children
;
459 iface
->iter_nth_child
= wxgtk_tree_model_iter_nth_child
;
460 iface
->iter_parent
= wxgtk_tree_model_iter_parent
;
464 wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
)
466 iface
->get_sort_column_id
= wxgtk_tree_model_get_sort_column_id
;
467 iface
->set_sort_column_id
= wxgtk_tree_model_set_sort_column_id
;
468 iface
->set_sort_func
= wxgtk_tree_model_set_sort_func
;
469 iface
->set_default_sort_func
= wxgtk_tree_model_set_default_sort_func
;
470 iface
->has_default_sort_func
= wxgtk_tree_model_has_default_sort_func
;
474 wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
)
476 iface
->row_draggable
= wxgtk_tree_model_row_draggable
;
477 iface
->drag_data_delete
= wxgtk_tree_model_drag_data_delete
;
478 iface
->drag_data_get
= wxgtk_tree_model_drag_data_get
;
482 wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
)
484 iface
->drag_data_received
= wxgtk_tree_model_drag_data_received
;
485 iface
->row_drop_possible
= wxgtk_tree_model_row_drop_possible
;
489 wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
)
491 tree_model
->internal
= NULL
;
492 tree_model
->stamp
= g_random_int();
496 wxgtk_tree_model_finalize (GObject
*object
)
499 (* list_parent_class
->finalize
) (object
);
504 //-----------------------------------------------------------------------------
505 // implement callbacks from wxGtkTreeModel class by letting
506 // them call the methods of wxWidgets' wxDataViewModel
507 //-----------------------------------------------------------------------------
509 static GtkTreeModelFlags
510 wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
)
512 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
513 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), (GtkTreeModelFlags
)0 );
515 return wxtree_model
->internal
->get_flags();
519 wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
)
521 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
522 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
524 return wxtree_model
->internal
->GetDataViewModel()->GetColumnCount();
528 wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
531 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
532 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), G_TYPE_INVALID
);
534 GType gtype
= G_TYPE_INVALID
;
536 wxString wxtype
= wxtree_model
->internal
->GetDataViewModel()->GetColumnType( (unsigned int) index
);
538 wxPrintf( "get_column_type %s\n", wxtype
);
540 if (wxtype
== wxT("string"))
541 gtype
= G_TYPE_STRING
;
544 gtype
= G_TYPE_STRING
;
545 // wxFAIL_MSG( _T("non-string columns not supported yet") );
552 wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
556 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
557 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
558 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
560 return wxtree_model
->internal
->get_iter( iter
, path
);
564 wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
567 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
568 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), NULL
);
569 g_return_val_if_fail (iter
->stamp
== GTK_WX_TREE_MODEL (wxtree_model
)->stamp
, NULL
);
571 return wxtree_model
->internal
->get_path( iter
);
575 wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
580 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
581 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
) );
583 wxDataViewModel
*model
= wxtree_model
->internal
->GetDataViewModel();
584 wxString mtype
= model
->GetColumnType( (unsigned int) column
);
585 if (mtype
== wxT("string"))
588 g_value_init( value
, G_TYPE_STRING
);
589 wxDataViewItem
item( (void*) iter
->user_data
);
590 model
->GetValue( variant
, item
, (unsigned int) column
);
592 g_value_set_string( value
, variant
.GetString().utf8_str() );
596 wxFAIL_MSG( _T("non-string columns not supported yet") );
601 wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
604 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
606 if (wxtree_model
->stamp
!= iter
->stamp
)
607 wxPrintf( "crash\n" );
609 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
610 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
612 return wxtree_model
->internal
->iter_next( iter
);
616 wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
620 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
621 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
622 g_return_val_if_fail (wxtree_model
->stamp
== parent
->stamp
, FALSE
);
624 return wxtree_model
->internal
->iter_children( iter
, parent
);
628 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
631 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
632 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
633 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
635 return wxtree_model
->internal
->iter_has_child( iter
);
639 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
642 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
643 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
646 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, 0);
648 return wxtree_model
->internal
->iter_n_children( iter
);
652 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
657 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
658 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
660 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
664 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
668 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
669 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
670 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
672 return wxtree_model
->internal
->iter_parent( iter
, child
);
675 /* drag'n'drop iface */
677 wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
680 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
681 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
683 return wxtree_model
->internal
->row_draggable( drag_source
, path
);
687 wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
690 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
691 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
693 return wxtree_model
->internal
->drag_data_delete( drag_source
, path
);
697 wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
699 GtkSelectionData
*selection_data
)
701 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
702 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
705 wxPrintf( "drag_get_data\n");
707 wxGtkString
atom_selection(gdk_atom_name(selection_data
->selection
));
708 wxPrintf( "selection %s\n", wxString::FromAscii(atom_selection
) );
710 wxGtkString
atom_target(gdk_atom_name(selection_data
->target
));
711 wxPrintf( "target %s\n", wxString::FromAscii(atom_target
) );
713 wxGtkString
atom_type(gdk_atom_name(selection_data
->type
));
714 wxPrintf( "type %s\n", wxString::FromAscii(atom_type
) );
716 wxPrintf( "format %d\n", selection_data
->format
);
719 return wxtree_model
->internal
->drag_data_get( drag_source
, path
, selection_data
);
723 wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
725 GtkSelectionData
*selection_data
)
727 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
728 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
730 return wxtree_model
->internal
->drag_data_received( drag_dest
, dest
, selection_data
);
734 wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
735 GtkTreePath
*dest_path
,
736 GtkSelectionData
*selection_data
)
738 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
739 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
741 return wxtree_model
->internal
->row_drop_possible( drag_dest
, dest_path
, selection_data
);
746 wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
747 gint
*sort_column_id
,
750 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) sortable
;
752 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
754 if (!wxtree_model
->internal
->IsSorted())
757 *sort_column_id
= -1;
764 *sort_column_id
= wxtree_model
->internal
->GetSortColumn();
767 *order
= wxtree_model
->internal
->GetSortOrder();
772 wxDataViewColumn
*gs_lastLeftClickHeader
= NULL
;
775 wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
779 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
780 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
782 tree_model
->internal
->SetDataViewSortColumn( gs_lastLeftClickHeader
);
784 if ((sort_column_id
!= (gint
) tree_model
->internal
->GetSortColumn()) ||
785 (order
!= tree_model
->internal
->GetSortOrder()))
787 tree_model
->internal
->SetSortColumn( sort_column_id
);
788 tree_model
->internal
->SetSortOrder( order
);
790 gtk_tree_sortable_sort_column_changed (sortable
);
792 tree_model
->internal
->GetDataViewModel()->Resort();
795 if (gs_lastLeftClickHeader
)
797 wxDataViewCtrl
*dv
= tree_model
->internal
->GetOwner();
798 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, dv
->GetId() );
799 event
.SetDataViewColumn( gs_lastLeftClickHeader
);
800 event
.SetModel( dv
->GetModel() );
801 dv
->HandleWindowEvent( event
);
804 gs_lastLeftClickHeader
= NULL
;
808 wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
809 gint
WXUNUSED(sort_column_id
),
810 GtkTreeIterCompareFunc func
,
811 gpointer
WXUNUSED(data
),
812 GtkDestroyNotify
WXUNUSED(destroy
) )
814 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
815 g_return_if_fail (func
!= NULL
);
818 void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
819 GtkTreeIterCompareFunc func
,
820 gpointer
WXUNUSED(data
),
821 GtkDestroyNotify
WXUNUSED(destroy
) )
823 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
824 g_return_if_fail (func
!= NULL
);
826 wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
829 gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
)
831 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
836 //-----------------------------------------------------------------------------
837 // define new GTK+ class wxGtkRendererRenderer
838 //-----------------------------------------------------------------------------
842 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
843 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
844 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
845 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
846 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
847 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
849 GType
gtk_wx_cell_renderer_get_type (void);
851 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
852 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
854 struct _GtkWxCellRenderer
856 GtkCellRenderer parent
;
859 wxDataViewCustomRenderer
*cell
;
863 struct _GtkWxCellRendererClass
865 GtkCellRendererClass cell_parent_class
;
869 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
870 static void gtk_wx_cell_renderer_init (
871 GtkWxCellRenderer
*cell
);
872 static void gtk_wx_cell_renderer_class_init(
873 GtkWxCellRendererClass
*klass
);
874 static void gtk_wx_cell_renderer_finalize (
876 static void gtk_wx_cell_renderer_get_size (
877 GtkCellRenderer
*cell
,
879 GdkRectangle
*rectangle
,
884 static void gtk_wx_cell_renderer_render (
885 GtkCellRenderer
*cell
,
888 GdkRectangle
*background_area
,
889 GdkRectangle
*cell_area
,
890 GdkRectangle
*expose_area
,
891 GtkCellRendererState flags
);
892 static gboolean
gtk_wx_cell_renderer_activate(
893 GtkCellRenderer
*cell
,
897 GdkRectangle
*background_area
,
898 GdkRectangle
*cell_area
,
899 GtkCellRendererState flags
);
900 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
901 GtkCellRenderer
*cell
,
905 GdkRectangle
*background_area
,
906 GdkRectangle
*cell_area
,
907 GtkCellRendererState flags
);
910 static GObjectClass
*cell_parent_class
= NULL
;
915 gtk_wx_cell_renderer_get_type (void)
917 static GType cell_wx_type
= 0;
921 const GTypeInfo cell_wx_info
=
923 sizeof (GtkWxCellRendererClass
),
924 NULL
, /* base_init */
925 NULL
, /* base_finalize */
926 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
927 NULL
, /* class_finalize */
928 NULL
, /* class_data */
929 sizeof (GtkWxCellRenderer
),
931 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
934 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
935 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
942 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
945 cell
->last_click
= 0;
949 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
951 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
952 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
954 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
956 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
958 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
959 cell_class
->render
= gtk_wx_cell_renderer_render
;
960 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
961 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
965 gtk_wx_cell_renderer_finalize (GObject
*object
)
968 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
972 gtk_wx_cell_renderer_new (void)
974 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
979 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
980 GtkCellRenderer
*renderer
,
981 GdkEvent
*WXUNUSED(event
),
984 GdkRectangle
*WXUNUSED(background_area
),
985 GdkRectangle
*cell_area
,
986 GtkCellRendererState
WXUNUSED(flags
) )
988 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
989 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
991 // Renderer doesn't support in-place editing
992 if (!cell
->HasEditorCtrl())
995 // An in-place editing control is still around
996 if (cell
->GetEditorCtrl())
1000 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1006 rect
.x
+= cell_area
->x
;
1007 rect
.y
+= cell_area
->y
;
1008 // rect.width -= renderer->xpad * 2;
1009 // rect.height -= renderer->ypad * 2;
1011 // wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
1012 wxRect
renderrect( cell_area
->x
, cell_area
->y
, cell_area
->width
, cell_area
->height
);
1014 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
1016 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
1017 wxDataViewItem
item( (void*) iter
.user_data
);
1018 gtk_tree_path_free( treepath
);
1020 cell
->StartEditing( item
, renderrect
);
1026 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
1027 GtkWidget
*WXUNUSED(widget
),
1028 GdkRectangle
*cell_area
,
1034 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1035 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1037 wxSize size
= cell
->GetSize();
1039 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
1040 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
1047 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
1051 *x_offset
= (gint
)((renderer
->xalign
*
1052 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
1053 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
1057 *y_offset
= (gint
)((renderer
->yalign
*
1058 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
1059 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
1064 *width
= calc_width
;
1067 *height
= calc_height
;
1071 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
1074 GdkRectangle
*background_area
,
1075 GdkRectangle
*cell_area
,
1076 GdkRectangle
*expose_area
,
1077 GtkCellRendererState flags
)
1080 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1081 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1083 cell
->window
= window
;
1084 cell
->widget
= widget
;
1085 cell
->background_area
= (void*) background_area
;
1086 cell
->cell_area
= (void*) cell_area
;
1087 cell
->expose_area
= (void*) expose_area
;
1088 cell
->flags
= (int) flags
;
1091 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1097 rect
.x
+= cell_area
->x
;
1098 rect
.y
+= cell_area
->y
;
1099 rect
.width
-= renderer
->xpad
* 2;
1100 rect
.height
-= renderer
->ypad
* 2;
1103 if (gdk_rectangle_intersect (expose_area
, &rect
, &dummy
))
1105 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1106 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
1107 wxWindowDCImpl
*impl
= (wxWindowDCImpl
*) dc
->GetImpl();
1109 // Reinitilise DC if drawing occurs into a different
1110 // window such as a DnD drop window.
1111 if (window
!= impl
->m_gdkwindow
)
1114 impl
->m_gdkwindow
= window
;
1119 if (flags
& GTK_CELL_RENDERER_SELECTED
)
1120 state
|= wxDATAVIEW_CELL_SELECTED
;
1121 if (flags
& GTK_CELL_RENDERER_PRELIT
)
1122 state
|= wxDATAVIEW_CELL_PRELIT
;
1123 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1124 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1125 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1126 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1127 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
1128 state
|= wxDATAVIEW_CELL_FOCUSED
;
1129 cell
->Render( renderrect
, dc
, state
);
1134 gtk_wx_cell_renderer_activate(
1135 GtkCellRenderer
*renderer
,
1139 GdkRectangle
*WXUNUSED(background_area
),
1140 GdkRectangle
*cell_area
,
1141 GtkCellRendererState
WXUNUSED(flags
) )
1143 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1144 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1147 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1153 rect
.x
+= cell_area
->x
;
1154 rect
.y
+= cell_area
->y
;
1155 rect
.width
-= renderer
->xpad
* 2;
1156 rect
.height
-= renderer
->ypad
* 2;
1158 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1160 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1162 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
1165 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
1166 wxDataViewItem
item( iter
.user_data
);
1167 gtk_tree_path_free( treepath
);
1169 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1175 // activated by <ENTER>
1176 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1181 else if (event
->type
== GDK_BUTTON_PRESS
)
1183 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
1184 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
1185 ((int) button_event
->y
) - renderrect
.y
);
1188 if (button_event
->button
== 1)
1190 if (cell
->LeftClick( pt
, renderrect
, model
, item
, model_col
))
1192 // TODO: query system double-click time
1193 if (button_event
->time
- wxrenderer
->last_click
< 400)
1194 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1197 wxrenderer
->last_click
= button_event
->time
;
1205 // ---------------------------------------------------------
1206 // wxGtkDataViewModelNotifier
1207 // ---------------------------------------------------------
1209 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1212 wxGtkDataViewModelNotifier( GtkWxTreeModel
*wxgtk_model
,
1213 wxDataViewModel
*wx_model
,
1214 wxDataViewCtrl
*ctrl
);
1215 ~wxGtkDataViewModelNotifier();
1217 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1218 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1219 virtual bool ItemChanged( const wxDataViewItem
&item
);
1220 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
1221 virtual bool Cleared();
1222 virtual void Resort();
1224 void SetGtkModel( GtkWxTreeModel
*model
) { m_wxgtk_model
= model
; }
1227 GtkWxTreeModel
*m_wxgtk_model
;
1228 wxDataViewModel
*m_wx_model
;
1229 wxDataViewCtrl
*m_owner
;
1232 // ---------------------------------------------------------
1233 // wxGtkDataViewListModelNotifier
1234 // ---------------------------------------------------------
1236 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1237 GtkWxTreeModel
* wxgtk_model
, wxDataViewModel
*wx_model
,
1238 wxDataViewCtrl
*ctrl
)
1240 m_wxgtk_model
= wxgtk_model
;
1241 m_wx_model
= wx_model
;
1245 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1248 m_wxgtk_model
= NULL
;
1251 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1253 m_owner
->GtkGetInternal()->ItemAdded( parent
, item
);
1256 iter
.stamp
= m_wxgtk_model
->stamp
;
1257 iter
.user_data
= (gpointer
) item
.GetID();
1259 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1260 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1261 gtk_tree_model_row_inserted(
1262 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1263 gtk_tree_path_free (path
);
1268 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1271 iter
.stamp
= m_wxgtk_model
->stamp
;
1272 iter
.user_data
= (gpointer
) item
.GetID();
1274 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1275 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1276 gtk_tree_model_row_deleted(
1277 GTK_TREE_MODEL(m_wxgtk_model
), path
);
1278 gtk_tree_path_free (path
);
1280 m_owner
->GtkGetInternal()->ItemDeleted( parent
, item
);
1285 void wxGtkDataViewModelNotifier::Resort()
1287 m_owner
->GtkGetInternal()->Resort();
1290 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1293 iter
.stamp
= m_wxgtk_model
->stamp
;
1294 iter
.user_data
= (gpointer
) item
.GetID();
1296 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1297 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1298 gtk_tree_model_row_changed(
1299 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1300 gtk_tree_path_free (path
);
1302 m_owner
->GtkGetInternal()->ItemChanged( item
);
1307 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_col
)
1309 // This adds GTK+'s missing MVC logic for ValueChanged
1311 for (index
= 0; index
< m_owner
->GetColumnCount(); index
++)
1313 wxDataViewColumn
*column
= m_owner
->GetColumn( index
);
1314 if (column
->GetModelColumn() == model_col
)
1316 GtkTreeView
*widget
= GTK_TREE_VIEW(m_owner
->m_treeview
);
1317 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1321 iter
.stamp
= m_wxgtk_model
->stamp
;
1322 iter
.user_data
= (gpointer
) item
.GetID();
1323 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1324 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1325 GdkRectangle cell_area
;
1326 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1327 gtk_tree_path_free( path
);
1329 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1330 double d
= gtk_adjustment_get_value( hadjust
);
1331 int xdiff
= (int) d
;
1333 int ydiff
= gcolumn
->button
->allocation
.height
;
1335 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1336 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1338 m_owner
->GtkGetInternal()->ValueChanged( item
, model_col
);
1347 bool wxGtkDataViewModelNotifier::Cleared()
1349 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->m_treeview
), NULL
);
1351 // this will create a new GTK model
1352 m_owner
->GtkGetInternal()->Cleared();
1354 SetGtkModel( m_owner
->GtkGetInternal()->GetGtkModel() );
1356 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->m_treeview
), GTK_TREE_MODEL(m_wxgtk_model
) );
1361 // ---------------------------------------------------------
1362 // wxDataViewRenderer
1363 // ---------------------------------------------------------
1365 static gpointer s_user_data
= NULL
;
1368 wxgtk_cell_editable_editing_done( GtkCellEditable
*WXUNUSED(editable
),
1369 wxDataViewRenderer
*wxrenderer
)
1371 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1372 wxDataViewCtrl
*dv
= column
->GetOwner();
1373 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1374 event
.SetDataViewColumn( column
);
1375 event
.SetModel( dv
->GetModel() );
1376 wxDataViewItem
item( s_user_data
);
1377 event
.SetItem( item
);
1378 dv
->HandleWindowEvent( event
);
1382 wxgtk_renderer_editing_started( GtkCellRenderer
*WXUNUSED(cell
), GtkCellEditable
*editable
,
1383 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1385 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1386 wxDataViewCtrl
*dv
= column
->GetOwner();
1387 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1388 event
.SetDataViewColumn( column
);
1389 event
.SetModel( dv
->GetModel() );
1390 GtkTreePath
*tree_path
= gtk_tree_path_new_from_string( path
);
1392 dv
->GtkGetInternal()->get_iter( &iter
, tree_path
);
1393 gtk_tree_path_free( tree_path
);
1394 wxDataViewItem
item( iter
.user_data
);
1395 event
.SetItem( item
);
1396 dv
->HandleWindowEvent( event
);
1398 if (GTK_IS_CELL_EDITABLE(editable
))
1400 s_user_data
= iter
.user_data
;
1402 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1403 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1404 (gpointer
) wxrenderer
);
1410 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1412 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1414 wxDataViewRendererBase( varianttype
, mode
, align
)
1418 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1419 // after the m_renderer pointer has been initialized
1422 void wxDataViewRenderer::GtkInitHandlers()
1424 if (!gtk_check_version(2,6,0))
1426 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1427 G_CALLBACK (wxgtk_renderer_editing_started
),
1432 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1434 GtkCellRendererMode gtkMode
;
1437 case wxDATAVIEW_CELL_INERT
:
1438 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1441 case wxDATAVIEW_CELL_ACTIVATABLE
:
1442 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1445 case wxDATAVIEW_CELL_EDITABLE
:
1446 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1450 wxFAIL_MSG( "unknown wxDataViewCellMode value" );
1454 // This value is most often ignored in GtkTreeView
1455 GValue gvalue
= { 0, };
1456 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1457 g_value_set_enum( &gvalue
, gtkMode
);
1458 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1459 g_value_unset( &gvalue
);
1462 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1464 wxDataViewCellMode ret
;
1467 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1469 switch (g_value_get_enum(&gvalue
))
1472 wxFAIL_MSG( "unknown GtkCellRendererMode value" );
1473 // fall through (we have to return something)
1475 case GTK_CELL_RENDERER_MODE_INERT
:
1476 ret
= wxDATAVIEW_CELL_INERT
;
1479 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1480 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1483 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1484 ret
= wxDATAVIEW_CELL_EDITABLE
;
1488 g_value_unset( &gvalue
);
1493 void wxDataViewRenderer::GtkUpdateAlignment()
1495 int align
= m_alignment
;
1497 // query alignment from column ?
1501 if (GetOwner() == NULL
)
1504 align
= GetOwner()->GetAlignment();
1505 align
|= wxALIGN_CENTRE_VERTICAL
;
1508 // horizontal alignment:
1510 gfloat xalign
= 0.0;
1511 if (align
& wxALIGN_RIGHT
)
1513 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1516 GValue gvalue
= { 0, };
1517 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1518 g_value_set_float( &gvalue
, xalign
);
1519 g_object_set_property( G_OBJECT(m_renderer
), "xalign", &gvalue
);
1520 g_value_unset( &gvalue
);
1522 // vertical alignment:
1524 gfloat yalign
= 0.0;
1525 if (align
& wxALIGN_BOTTOM
)
1527 else if (align
& wxALIGN_CENTER_VERTICAL
)
1530 GValue gvalue2
= { 0, };
1531 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1532 g_value_set_float( &gvalue2
, yalign
);
1533 g_object_set_property( G_OBJECT(m_renderer
), "yalign", &gvalue2
);
1534 g_value_unset( &gvalue2
);
1537 void wxDataViewRenderer::SetAlignment( int align
)
1539 m_alignment
= align
;
1540 GtkUpdateAlignment();
1543 int wxDataViewRenderer::GetAlignment() const
1548 // ---------------------------------------------------------
1549 // wxDataViewTextRenderer
1550 // ---------------------------------------------------------
1553 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1554 gchar
*arg1
, gchar
*arg2
, gpointer user_data
);
1557 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*WXUNUSED(renderer
),
1558 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1560 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) user_data
;
1562 wxString tmp
= wxGTK_CONV_BACK_FONT(arg2
, cell
->GetOwner()->GetOwner()->GetFont());
1563 wxVariant value
= tmp
;
1564 if (!cell
->Validate( value
))
1567 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1569 GtkTreePath
*path
= gtk_tree_path_new_from_string( arg1
);
1571 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, path
);
1572 wxDataViewItem
item( (void*) iter
.user_data
);;
1573 gtk_tree_path_free( path
);
1575 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1577 model
->SetValue( value
, item
, model_col
);
1578 model
->ValueChanged( item
, model_col
);
1581 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
1583 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1585 wxDataViewRenderer( varianttype
, mode
, align
)
1587 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_text_new();
1589 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
1591 GValue gvalue
= { 0, };
1592 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1593 g_value_set_boolean( &gvalue
, true );
1594 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
1595 g_value_unset( &gvalue
);
1597 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
1603 SetAlignment(align
);
1606 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
1608 wxString tmp
= value
;
1610 GValue gvalue
= { 0, };
1611 g_value_init( &gvalue
, G_TYPE_STRING
);
1612 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( tmp
, GetOwner()->GetOwner()->GetFont() ) );
1613 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1614 g_value_unset( &gvalue
);
1619 bool wxDataViewTextRenderer::GetValue( wxVariant
&value
) const
1621 GValue gvalue
= { 0, };
1622 g_value_init( &gvalue
, G_TYPE_STRING
);
1623 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1624 wxString tmp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
), const_cast<wxDataViewTextRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
1625 g_value_unset( &gvalue
);
1632 void wxDataViewTextRenderer::SetAlignment( int align
)
1634 wxDataViewRenderer::SetAlignment(align
);
1636 if (gtk_check_version(2,10,0))
1639 // horizontal alignment:
1640 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
1641 if (align
& wxALIGN_RIGHT
)
1642 pangoAlign
= PANGO_ALIGN_RIGHT
;
1643 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1644 pangoAlign
= PANGO_ALIGN_CENTER
;
1646 GValue gvalue
= { 0, };
1647 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1648 g_value_set_enum( &gvalue
, pangoAlign
);
1649 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
1650 g_value_unset( &gvalue
);
1653 // ---------------------------------------------------------
1654 // wxDataViewTextRendererAttr
1655 // ---------------------------------------------------------
1657 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
,wxDataViewTextRenderer
)
1659 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString
&varianttype
,
1660 wxDataViewCellMode mode
, int align
) :
1661 wxDataViewTextRenderer( varianttype
, mode
, align
)
1665 // ---------------------------------------------------------
1666 // wxDataViewBitmapRenderer
1667 // ---------------------------------------------------------
1669 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
1671 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1673 wxDataViewRenderer( varianttype
, mode
, align
)
1675 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_pixbuf_new();
1678 SetAlignment(align
);
1681 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
1683 if (value
.GetType() == wxT("wxBitmap"))
1688 // This may create a Pixbuf representation in the
1689 // wxBitmap object (and it will stay there)
1690 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1692 GValue gvalue
= { 0, };
1693 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1694 g_value_set_object( &gvalue
, pixbuf
);
1695 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1696 g_value_unset( &gvalue
);
1701 if (value
.GetType() == wxT("wxIcon"))
1706 // This may create a Pixbuf representation in the
1707 // wxBitmap object (and it will stay there)
1708 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1710 GValue gvalue
= { 0, };
1711 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1712 g_value_set_object( &gvalue
, pixbuf
);
1713 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1714 g_value_unset( &gvalue
);
1722 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
1727 // ---------------------------------------------------------
1728 // wxDataViewToggleRenderer
1729 // ---------------------------------------------------------
1732 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1733 gchar
*path
, gpointer user_data
);
1736 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1737 gchar
*path
, gpointer user_data
)
1739 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
1742 GValue gvalue
= { 0, };
1743 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1744 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
1745 bool tmp
= g_value_get_boolean( &gvalue
);
1746 g_value_unset( &gvalue
);
1750 wxVariant value
= tmp
;
1751 if (!cell
->Validate( value
))
1754 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1756 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
1758 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, gtk_path
);
1759 wxDataViewItem
item( (void*) iter
.user_data
);;
1760 gtk_tree_path_free( gtk_path
);
1762 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1764 model
->SetValue( value
, item
, model_col
);
1765 model
->ValueChanged( item
, model_col
);
1768 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1770 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1771 wxDataViewCellMode mode
, int align
) :
1772 wxDataViewRenderer( varianttype
, mode
, align
)
1774 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
1776 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1778 g_signal_connect_after( m_renderer
, "toggled",
1779 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
1783 GValue gvalue
= { 0, };
1784 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1785 g_value_set_boolean( &gvalue
, false );
1786 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
1787 g_value_unset( &gvalue
);
1791 SetAlignment(align
);
1794 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1798 GValue gvalue
= { 0, };
1799 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1800 g_value_set_boolean( &gvalue
, tmp
);
1801 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1802 g_value_unset( &gvalue
);
1807 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
1809 GValue gvalue
= { 0, };
1810 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1811 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1812 bool tmp
= g_value_get_boolean( &gvalue
);
1813 g_value_unset( &gvalue
);
1820 // ---------------------------------------------------------
1821 // wxDataViewCustomRenderer
1822 // ---------------------------------------------------------
1824 class wxDataViewCtrlDCImpl
: public wxWindowDCImpl
1827 wxDataViewCtrlDCImpl( wxDC
*owner
, wxDataViewCtrl
*window
) :
1828 wxWindowDCImpl( owner
)
1830 GtkWidget
*widget
= window
->m_treeview
;
1836 m_context
= window
->GTKGetPangoDefaultContext();
1837 m_layout
= pango_layout_new( m_context
);
1838 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
1840 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
1842 // Set m_gdkwindow later
1847 class wxDataViewCtrlDC
: public wxWindowDC
1850 wxDataViewCtrlDC( wxDataViewCtrl
*window
) :
1851 wxWindowDC( new wxDataViewCtrlDCImpl( this, window
) )
1856 // ---------------------------------------------------------
1857 // wxDataViewCustomRenderer
1858 // ---------------------------------------------------------
1860 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
1862 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
1863 wxDataViewCellMode mode
, int align
,
1865 wxDataViewRenderer( varianttype
, mode
, align
)
1868 m_text_renderer
= NULL
;
1876 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
,
1877 wxRect
WXUNUSED(cell
), wxDC
*WXUNUSED(dc
), int WXUNUSED(state
) )
1880 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
1881 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
1882 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
1883 view
->GetForegroundColour();
1884 dc
->SetTextForeground(col
);
1885 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
1887 if (!m_text_renderer
)
1888 m_text_renderer
= gtk_cell_renderer_text_new();
1890 GValue gvalue
= { 0, };
1891 g_value_init( &gvalue
, G_TYPE_STRING
);
1892 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( text
, GetOwner()->GetOwner()->GetFont() ) );
1893 g_object_set_property( G_OBJECT(m_text_renderer
), "text", &gvalue
);
1894 g_value_unset( &gvalue
);
1896 ((GdkRectangle
*) cell_area
)->x
+= xoffset
;
1897 ((GdkRectangle
*) cell_area
)->width
-= xoffset
;
1899 gtk_cell_renderer_render( m_text_renderer
,
1902 (GdkRectangle
*) background_area
,
1903 (GdkRectangle
*) cell_area
,
1904 (GdkRectangle
*) expose_area
,
1905 (GtkCellRendererState
) flags
);
1907 ((GdkRectangle
*) cell_area
)->x
-= xoffset
;
1908 ((GdkRectangle
*) cell_area
)->width
+= xoffset
;
1912 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
1914 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
1915 renderer
->cell
= this;
1917 m_renderer
= (GtkCellRenderer
*) renderer
;
1920 SetAlignment(align
);
1927 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
1932 if (m_text_renderer
)
1933 gtk_object_sink( GTK_OBJECT(m_text_renderer
) );
1936 wxDC
*wxDataViewCustomRenderer::GetDC()
1940 if (GetOwner() == NULL
)
1942 if (GetOwner()->GetOwner() == NULL
)
1944 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
1950 // ---------------------------------------------------------
1951 // wxDataViewProgressRenderer
1952 // ---------------------------------------------------------
1954 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
1956 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
1957 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1958 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
1964 if (!gtk_check_version(2,6,0))
1966 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
1968 GValue gvalue
= { 0, };
1969 g_value_init( &gvalue
, G_TYPE_STRING
);
1971 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( m_label
, GetOwner()->GetOwner()->GetFont() ) );
1972 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1973 g_value_unset( &gvalue
);
1976 SetAlignment(align
);
1981 // Use custom cell code
1982 wxDataViewCustomRenderer::Init(mode
, align
);
1986 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
1990 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
1993 if (!gtk_check_version(2,6,0))
1995 gint tmp
= (long) value
;
1996 GValue gvalue
= { 0, };
1997 g_value_init( &gvalue
, G_TYPE_INT
);
1998 g_value_set_int( &gvalue
, tmp
);
1999 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
2000 g_value_unset( &gvalue
);
2005 m_value
= (long) value
;
2007 if (m_value
< 0) m_value
= 0;
2008 if (m_value
> 100) m_value
= 100;
2014 bool wxDataViewProgressRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2019 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
2021 double pct
= (double)m_value
/ 100.0;
2023 bar
.width
= (int)(cell
.width
* pct
);
2024 dc
->SetPen( *wxTRANSPARENT_PEN
);
2025 dc
->SetBrush( *wxBLUE_BRUSH
);
2026 dc
->DrawRectangle( bar
);
2028 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
2029 dc
->SetPen( *wxBLACK_PEN
);
2030 dc
->DrawRectangle( cell
);
2035 wxSize
wxDataViewProgressRenderer::GetSize() const
2037 return wxSize(40,12);
2040 // -------------------------------------
2041 // wxDataViewChoiceRenderer
2042 // -------------------------------------
2044 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
&choices
,
2045 wxDataViewCellMode mode
, int alignment
) :
2046 wxDataViewCustomRenderer( "string", mode
, alignment
, true )
2048 m_choices
= choices
;
2051 if (!gtk_check_version(2,6,0))
2053 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_combo_new();
2055 GtkListStore
*store
= gtk_list_store_new( 1, G_TYPE_STRING
);
2056 for (size_t n
= 0; n
< m_choices
.GetCount(); n
++)
2058 gtk_list_store_insert_with_values(
2060 static_cast<const char *>(m_choices
[n
].utf8_str()), -1 );
2063 g_object_set (m_renderer
,
2069 bool editable
= (mode
& wxDATAVIEW_CELL_EDITABLE
);
2070 g_object_set (m_renderer
, "editable", editable
, NULL
);
2072 SetAlignment(alignment
);
2074 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2081 // Use custom cell code
2082 wxDataViewCustomRenderer::Init(mode
, alignment
);
2086 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
2088 RenderText( m_data
, 0, rect
, dc
, state
);
2092 wxSize
wxDataViewChoiceRenderer::GetSize() const
2094 return wxSize(70,20);
2097 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
2101 if (!gtk_check_version(2,6,0))
2103 GValue gvalue
= { 0, };
2104 g_value_init( &gvalue
, G_TYPE_STRING
);
2105 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( value
.GetString(), GetOwner()->GetOwner()->GetFont() ) );
2106 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2107 g_value_unset( &gvalue
);
2111 m_data
= value
.GetString();
2116 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
2119 if (!gtk_check_version(2,6,0))
2121 GValue gvalue
= { 0, };
2122 g_value_init( &gvalue
, G_TYPE_STRING
);
2123 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2124 wxString temp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
),
2125 const_cast<wxDataViewChoiceRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
2126 g_value_unset( &gvalue
);
2128 wxPrintf( "temp %s\n", temp
);
2137 void wxDataViewChoiceRenderer::SetAlignment( int align
)
2139 wxDataViewCustomRenderer::SetAlignment(align
);
2141 if (gtk_check_version(2,10,0))
2144 // horizontal alignment:
2145 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2146 if (align
& wxALIGN_RIGHT
)
2147 pangoAlign
= PANGO_ALIGN_RIGHT
;
2148 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2149 pangoAlign
= PANGO_ALIGN_CENTER
;
2151 GValue gvalue
= { 0, };
2152 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2153 g_value_set_enum( &gvalue
, pangoAlign
);
2154 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2155 g_value_unset( &gvalue
);
2158 // ---------------------------------------------------------
2159 // wxDataViewDateRenderer
2160 // ---------------------------------------------------------
2162 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
2165 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
2166 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
2167 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
2172 m_cal
= new wxCalendarCtrl( this, -1, *value
);
2173 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
2174 sizer
->Add( m_cal
, 1, wxGROW
);
2179 virtual void OnDismiss()
2183 void OnCalendar( wxCalendarEvent
&event
);
2185 wxCalendarCtrl
*m_cal
;
2186 wxDataViewModel
*m_model
;
2187 wxDataViewItem m_item
;
2191 DECLARE_EVENT_TABLE()
2194 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
2195 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
2198 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
2200 wxDateTime date
= event
.GetDate();
2201 wxVariant value
= date
;
2202 m_model
->SetValue( value
, m_item
, m_col
);
2203 m_model
->ValueChanged( m_item
, m_col
);
2207 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
2209 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
2210 wxDataViewCellMode mode
, int align
) :
2211 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2214 SetAlignment(align
);
2217 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
2219 m_date
= value
.GetDateTime();
2224 bool wxDataViewDateRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2229 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2231 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
2232 wxString tmp
= m_date
.FormatDate();
2233 RenderText( tmp
, 0, cell
, dc
, state
);
2237 wxSize
wxDataViewDateRenderer::GetSize() const
2239 wxString tmp
= m_date
.FormatDate();
2241 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
2242 return wxSize(x
,y
+d
);
2245 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
2246 const wxDataViewItem
&item
, unsigned int col
)
2249 model
->GetValue( variant
, item
, col
);
2250 wxDateTime value
= variant
.GetDateTime();
2252 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
2253 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
2254 wxPoint pos
= wxGetMousePosition();
2257 popup
->Popup( popup
->m_cal
);
2263 // ---------------------------------------------------------
2264 // wxDataViewIconTextRenderer
2265 // ---------------------------------------------------------
2267 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
2269 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
2270 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
2271 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2274 SetAlignment(align
);
2277 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2281 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
2287 bool wxDataViewIconTextRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2292 bool wxDataViewIconTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2294 const wxIcon
&icon
= m_value
.GetIcon();
2298 int yoffset
= wxMax( 0, (cell
.height
- icon
.GetHeight()) / 2 );
2299 dc
->DrawIcon( icon
, cell
.x
, cell
.y
+ yoffset
);
2300 offset
= icon
.GetWidth() + 4;
2303 RenderText( m_value
.GetText(), offset
, cell
, dc
, state
);
2308 wxSize
wxDataViewIconTextRenderer::GetSize() const
2311 if (m_value
.GetIcon().IsOk())
2312 size
.x
= 4 + m_value
.GetIcon().GetWidth();
2314 GetView()->GetTextExtent( m_value
.GetText(), &x
, &y
, &d
);
2320 wxControl
* wxDataViewIconTextRenderer::CreateEditorCtrl(
2321 wxWindow
*WXUNUSED(parent
), wxRect
WXUNUSED(labelRect
), const wxVariant
&WXUNUSED(value
) )
2326 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl(
2327 wxControl
* WXUNUSED(editor
), wxVariant
&WXUNUSED(value
) )
2332 // ---------------------------------------------------------
2334 // ---------------------------------------------------------
2338 gtk_dataview_header_button_press_callback( GtkWidget
*WXUNUSED(widget
),
2339 GdkEventButton
*gdk_event
,
2340 wxDataViewColumn
*column
)
2342 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
2345 if (gdk_event
->button
== 1)
2347 gs_lastLeftClickHeader
= column
;
2349 wxDataViewCtrl
*dv
= column
->GetOwner();
2350 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
2351 event
.SetDataViewColumn( column
);
2352 event
.SetModel( dv
->GetModel() );
2353 if (dv
->HandleWindowEvent( event
))
2357 if (gdk_event
->button
== 3)
2359 wxDataViewCtrl
*dv
= column
->GetOwner();
2360 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
2361 event
.SetDataViewColumn( column
);
2362 event
.SetModel( dv
->GetModel() );
2363 if (dv
->HandleWindowEvent( event
))
2371 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
2372 GtkCellRenderer
*cell
,
2373 GtkTreeModel
*model
,
2379 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*WXUNUSED(column
),
2380 GtkCellRenderer
*renderer
,
2381 GtkTreeModel
*model
,
2385 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2386 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2388 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2390 wxDataViewItem
item( (void*) iter
->user_data
);
2392 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
2394 if (!wx_model
->IsVirtualListModel())
2397 if (wx_model
->IsContainer( item
))
2399 if (wx_model
->HasContainerColumns( item
) || (cell
->GetOwner()->GetModelColumn() == 0))
2401 GValue gvalue
= { 0, };
2402 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2403 g_value_set_boolean( &gvalue
, TRUE
);
2404 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2405 g_value_unset( &gvalue
);
2409 GValue gvalue
= { 0, };
2410 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2411 g_value_set_boolean( &gvalue
, FALSE
);
2412 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2413 g_value_unset( &gvalue
);
2420 GValue gvalue
= { 0, };
2421 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2422 g_value_set_boolean( &gvalue
, TRUE
);
2423 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2424 g_value_unset( &gvalue
);
2430 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
2432 if (value
.GetType() != cell
->GetVariantType())
2433 wxLogError( wxT("Wrong type, required: %s but: %s"),
2434 value
.GetType().c_str(),
2435 cell
->GetVariantType().c_str() );
2437 cell
->SetValue( value
);
2439 if (cell
->GtkHasAttributes())
2441 wxDataViewItemAttr attr
;
2442 bool colour_set
= false;
2443 bool style_set
= false;
2444 bool weight_set
= false;
2446 if (wx_model
->GetAttr( item
, cell
->GetOwner()->GetModelColumn(), attr
))
2448 // this must be a GtkCellRendererText
2449 wxColour colour
= attr
.GetColour();
2452 const GdkColor
* const gcol
= colour
.GetColor();
2454 GValue gvalue
= { 0, };
2455 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2456 g_value_set_boxed( &gvalue
, gcol
);
2457 g_object_set_property( G_OBJECT(renderer
), "foreground_gdk", &gvalue
);
2458 g_value_unset( &gvalue
);
2463 if (attr
.GetItalic())
2465 GValue gvalue
= { 0, };
2466 g_value_init( &gvalue
, PANGO_TYPE_STYLE
);
2467 g_value_set_enum( &gvalue
, PANGO_STYLE_ITALIC
);
2468 g_object_set_property( G_OBJECT(renderer
), "style", &gvalue
);
2469 g_value_unset( &gvalue
);
2476 GValue gvalue
= { 0, };
2477 g_value_init( &gvalue
, PANGO_TYPE_WEIGHT
);
2478 g_value_set_enum( &gvalue
, PANGO_WEIGHT_BOLD
);
2479 g_object_set_property( G_OBJECT(renderer
), "weight", &gvalue
);
2480 g_value_unset( &gvalue
);
2488 GValue gvalue
= { 0, };
2489 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2490 g_value_set_boolean( &gvalue
, FALSE
);
2491 g_object_set_property( G_OBJECT(renderer
), "style-set", &gvalue
);
2492 g_value_unset( &gvalue
);
2497 GValue gvalue
= { 0, };
2498 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2499 g_value_set_boolean( &gvalue
, FALSE
);
2500 g_object_set_property( G_OBJECT(renderer
), "weight-set", &gvalue
);
2501 g_value_unset( &gvalue
);
2506 GValue gvalue
= { 0, };
2507 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2508 g_value_set_boolean( &gvalue
, FALSE
);
2509 g_object_set_property( G_OBJECT(renderer
), "foreground-set", &gvalue
);
2510 g_value_unset( &gvalue
);
2515 if (attr
.HasBackgroundColour())
2517 wxColour colour
= attr
.GetBackgroundColour();
2518 const GdkColor
* const gcol
= colour
.GetColor();
2520 GValue gvalue
= { 0, };
2521 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2522 g_value_set_boxed( &gvalue
, gcol
);
2523 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
2524 g_value_unset( &gvalue
);
2528 GValue gvalue
= { 0, };
2529 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2530 g_value_set_boolean( &gvalue
, FALSE
);
2531 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
2532 g_value_unset( &gvalue
);
2538 #include <wx/listimpl.cpp>
2539 WX_DEFINE_LIST(wxDataViewColumnList
)
2541 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
2542 unsigned int model_column
, int width
,
2543 wxAlignment align
, int flags
)
2544 : wxDataViewColumnBase( cell
, model_column
)
2546 Init( align
, flags
, width
);
2551 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
2552 unsigned int model_column
, int width
,
2553 wxAlignment align
, int flags
)
2554 : wxDataViewColumnBase( bitmap
, cell
, model_column
)
2556 Init( align
, flags
, width
);
2558 SetBitmap( bitmap
);
2561 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
2563 m_isConnected
= false;
2565 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) GetRenderer()->GetGtkHandle();
2566 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
2567 m_column
= (GtkWidget
*) column
;
2570 SetAlignment( align
);
2574 // Create container for icon and label
2575 GtkWidget
*box
= gtk_hbox_new( FALSE
, 1 );
2576 gtk_widget_show( box
);
2577 // gtk_container_set_border_width((GtkContainer*)box, 2);
2578 m_image
= gtk_image_new();
2579 gtk_box_pack_start(GTK_BOX(box
), m_image
, FALSE
, FALSE
, 1);
2580 m_label
= gtk_label_new("");
2581 gtk_box_pack_end( GTK_BOX(box
), GTK_WIDGET(m_label
), FALSE
, FALSE
, 1 );
2582 gtk_tree_view_column_set_widget( column
, box
);
2584 gtk_tree_view_column_pack_end( column
, renderer
, TRUE
);
2586 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
2587 wxGtkTreeCellDataFunc
, (gpointer
) GetRenderer(), NULL
);
2590 void wxDataViewColumn::OnInternalIdle()
2595 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
2597 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2600 g_signal_connect(column
->button
, "button_press_event",
2601 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
2603 m_isConnected
= true;
2608 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
2610 wxDataViewColumnBase::SetOwner( owner
);
2612 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2614 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
2617 void wxDataViewColumn::SetTitle( const wxString
&title
)
2619 wxDataViewCtrl
*ctrl
= GetOwner();
2620 gtk_label_set_text( GTK_LABEL(m_label
), ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
2621 : wxGTK_CONV_SYS(title
) );
2623 gtk_widget_hide( m_label
);
2625 gtk_widget_show( m_label
);
2628 wxString
wxDataViewColumn::GetTitle() const
2630 return wxGTK_CONV_BACK_FONT(
2631 gtk_label_get_text( GTK_LABEL(m_label
) ),
2632 GetOwner()->GetFont()
2636 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
2638 wxDataViewColumnBase::SetBitmap( bitmap
);
2642 GtkImage
*gtk_image
= GTK_IMAGE(m_image
);
2644 GdkBitmap
*mask
= NULL
;
2645 if (bitmap
.GetMask())
2646 mask
= bitmap
.GetMask()->GetBitmap();
2648 if (bitmap
.HasPixbuf())
2650 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
2651 bitmap
.GetPixbuf());
2655 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
2656 bitmap
.GetPixmap(), mask
);
2658 gtk_widget_show( m_image
);
2662 gtk_widget_hide( m_image
);
2666 void wxDataViewColumn::SetHidden( bool hidden
)
2668 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
2671 void wxDataViewColumn::SetResizeable( bool resizeable
)
2673 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizeable
);
2676 void wxDataViewColumn::SetAlignment( wxAlignment align
)
2678 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2680 gfloat xalign
= 0.0;
2681 if (align
== wxALIGN_RIGHT
)
2683 if (align
== wxALIGN_CENTER_HORIZONTAL
||
2684 align
== wxALIGN_CENTER
)
2687 gtk_tree_view_column_set_alignment( column
, xalign
);
2689 if (m_renderer
&& m_renderer
->GetAlignment() == -1)
2690 m_renderer
->GtkUpdateAlignment();
2693 wxAlignment
wxDataViewColumn::GetAlignment() const
2695 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
2698 return wxALIGN_RIGHT
;
2700 return wxALIGN_CENTER_HORIZONTAL
;
2702 return wxALIGN_LEFT
;
2705 void wxDataViewColumn::SetSortable( bool sortable
)
2707 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2711 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
2715 gtk_tree_view_column_set_sort_column_id( column
, -1 );
2716 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
2717 gtk_tree_view_column_set_clickable( column
, FALSE
);
2721 bool wxDataViewColumn::IsSortable() const
2723 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2724 return gtk_tree_view_column_get_clickable( column
);
2727 void wxDataViewColumn::SetAsSortKey( bool WXUNUSED(sort
) )
2729 // it might not make sense to have this function in wxHeaderColumn at
2730 // all in fact, changing of the sort order should only be done using the
2731 // associated control API
2732 wxFAIL_MSG( "not implemented" );
2735 bool wxDataViewColumn::IsSortKey() const
2737 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2738 return gtk_tree_view_column_get_sort_indicator( column
);
2741 bool wxDataViewColumn::IsResizeable() const
2743 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2744 return gtk_tree_view_column_get_resizable( column
);
2747 bool wxDataViewColumn::IsHidden() const
2749 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2750 return !gtk_tree_view_column_get_visible( column
);
2753 void wxDataViewColumn::SetSortOrder( bool ascending
)
2755 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2758 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
2760 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
2762 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
2765 bool wxDataViewColumn::IsSortOrderAscending() const
2767 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2769 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
2772 void wxDataViewColumn::SetMinWidth( int width
)
2774 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2777 int wxDataViewColumn::GetMinWidth() const
2779 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2782 int wxDataViewColumn::GetWidth() const
2784 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2787 void wxDataViewColumn::SetWidth( int width
)
2792 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
2794 // TODO find a better calculation
2795 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), wxDVC_DEFAULT_WIDTH
);
2797 // this is unpractical for large numbers of items and disables
2798 // user resizing, which is totally unexpected
2799 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
2804 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
2806 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2810 void wxDataViewColumn::SetReorderable( bool reorderable
)
2812 gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column
), reorderable
);
2815 bool wxDataViewColumn::IsReorderable() const
2817 return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column
) );
2820 //-----------------------------------------------------------------------------
2821 // wxGtkTreeModelNode
2822 //-----------------------------------------------------------------------------
2824 void wxGtkTreeModelNode::Resort()
2826 size_t child_count
= GetChildCount();
2827 if (child_count
== 0)
2830 size_t node_count
= GetNodesCount();
2832 if (child_count
== 1)
2834 if (node_count
== 1)
2836 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
2842 wxGtkTreeModelChildren temp
;
2843 WX_APPEND_ARRAY( temp
, m_children
);
2845 gs_internal
= m_internal
;
2846 m_children
.Sort( &wxGtkTreeModelChildCmp
);
2848 gint
*new_order
= new gint
[child_count
];
2851 for (pos
= 0; pos
< child_count
; pos
++)
2853 void *id
= m_children
.Item( pos
);
2854 int old_pos
= temp
.Index( id
);
2855 new_order
[pos
] = old_pos
;
2858 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
2861 iter
.user_data
= GetItem().GetID();
2862 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
2864 GtkTreePath
*path
= m_internal
->get_path( &iter
);
2866 gtk_tree_model_rows_reordered( gtk_tree_model
, path
, &iter
, new_order
);
2868 gtk_tree_path_free (path
);
2870 delete [] new_order
;
2872 for (pos
= 0; pos
< node_count
; pos
++)
2874 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
2879 //-----------------------------------------------------------------------------
2880 // wxDataViewCtrlInternal
2881 //-----------------------------------------------------------------------------
2883 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
,
2884 wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
)
2887 m_wx_model
= wx_model
;
2888 m_gtk_model
= gtk_model
;
2890 m_sort_order
= GTK_SORT_ASCENDING
;
2892 m_dataview_sort_column
= NULL
;
2894 m_dragDataObject
= NULL
;
2895 m_dropDataObject
= NULL
;
2897 if (!m_wx_model
->IsVirtualListModel())
2901 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
2903 g_object_unref( m_gtk_model
);
2905 delete m_dragDataObject
;
2906 delete m_dropDataObject
;
2909 void wxDataViewCtrlInternal::InitTree()
2911 wxDataViewItem item
;
2912 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
2914 BuildBranch( m_root
);
2917 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
2919 if (node
->GetChildCount() == 0)
2921 wxDataViewItemArray children
;
2922 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
2924 for (pos
= 0; pos
< count
; pos
++)
2926 wxDataViewItem child
= children
[pos
];
2928 if (m_wx_model
->IsContainer( child
))
2929 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
2931 node
->AddLeave( child
.GetID() );
2933 // Don't send any events here
2940 bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat
&format
)
2942 wxGtkString
atom_str( gdk_atom_name( format
) );
2943 m_dragSourceTargetEntryTarget
= wxCharBuffer( atom_str
);
2945 m_dragSourceTargetEntry
.target
= m_dragSourceTargetEntryTarget
.data();
2946 m_dragSourceTargetEntry
.flags
= 0;
2947 m_dragSourceTargetEntry
.info
= static_cast<guint
>(-1);
2949 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
2950 GDK_BUTTON1_MASK
, &m_dragSourceTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
2955 bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat
&format
)
2957 wxGtkString
atom_str( gdk_atom_name( format
) );
2958 m_dropTargetTargetEntryTarget
= wxCharBuffer( atom_str
);
2960 m_dropTargetTargetEntry
.target
= m_dropTargetTargetEntryTarget
.data();
2961 m_dropTargetTargetEntry
.flags
= 0;
2962 m_dropTargetTargetEntry
.info
= static_cast<guint
>(-1);
2964 gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
2965 &m_dropTargetTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
2970 gboolean
wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource
*WXUNUSED(drag_source
),
2973 delete m_dragDataObject
;
2976 if (!get_iter( &iter
, path
)) return FALSE
;
2977 wxDataViewItem
item( (void*) iter
.user_data
);
2979 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
2980 event
.SetEventObject( m_owner
);
2981 event
.SetItem( item
);
2982 event
.SetModel( m_wx_model
);
2983 if (!m_owner
->HandleWindowEvent( event
))
2986 if (!event
.IsAllowed())
2989 wxDataObject
*obj
= event
.GetDataObject();
2993 m_dragDataObject
= obj
;
2999 wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource
*WXUNUSED(drag_source
),
3000 GtkTreePath
*WXUNUSED(path
))
3005 gboolean
wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource
*WXUNUSED(drag_source
),
3006 GtkTreePath
*path
, GtkSelectionData
*selection_data
)
3009 if (!get_iter( &iter
, path
)) return FALSE
;
3010 wxDataViewItem
item( (void*) iter
.user_data
);
3012 if (!m_dragDataObject
->IsSupported( selection_data
->target
))
3015 size_t size
= m_dragDataObject
->GetDataSize( selection_data
->target
);
3019 void *buf
= malloc( size
);
3021 gboolean res
= FALSE
;
3022 if (m_dragDataObject
->GetDataHere( selection_data
->target
, buf
))
3026 gtk_selection_data_set( selection_data
, selection_data
->target
,
3027 8, (const guchar
*) buf
, size
);
3036 wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3038 GtkSelectionData
*selection_data
)
3041 if (!get_iter( &iter
, path
)) return FALSE
;
3042 wxDataViewItem
item( (void*) iter
.user_data
);
3044 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
3045 event
.SetEventObject( m_owner
);
3046 event
.SetItem( item
);
3047 event
.SetModel( m_wx_model
);
3048 event
.SetDataFormat( selection_data
->target
);
3049 event
.SetDataSize( selection_data
->length
);
3050 event
.SetDataBuffer( selection_data
->data
);
3051 if (!m_owner
->HandleWindowEvent( event
))
3054 if (!event
.IsAllowed())
3061 wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3063 GtkSelectionData
*selection_data
)
3066 if (!get_iter( &iter
, path
)) return FALSE
;
3067 wxDataViewItem
item( (void*) iter
.user_data
);
3069 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
3070 event
.SetEventObject( m_owner
);
3071 event
.SetItem( item
);
3072 event
.SetModel( m_wx_model
);
3073 event
.SetDataFormat( selection_data
->target
);
3074 if (!m_owner
->HandleWindowEvent( event
))
3077 if (!event
.IsAllowed())
3083 // notifications from wxDataViewModel
3085 bool wxDataViewCtrlInternal::Cleared()
3093 // Create new GTK model
3094 g_object_unref( m_gtk_model
);
3095 m_gtk_model
= wxgtk_tree_model_new();
3096 m_gtk_model
->internal
= this;
3101 void wxDataViewCtrlInternal::Resort()
3103 if (!m_wx_model
->IsVirtualListModel())
3107 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3109 if (!m_wx_model
->IsVirtualListModel())
3111 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3112 if (m_wx_model
->IsContainer( item
))
3113 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
3115 parent_node
->AddLeave( item
.GetID() );
3121 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3123 if (!m_wx_model
->IsVirtualListModel())
3125 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3126 parent_node
->DeleteChild( item
.GetID() );
3132 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
3134 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3135 event
.SetEventObject( m_owner
);
3136 event
.SetModel( m_owner
->GetModel() );
3137 event
.SetItem( item
);
3138 m_owner
->HandleWindowEvent( event
);
3143 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
3145 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3146 event
.SetEventObject( m_owner
);
3147 event
.SetModel( m_owner
->GetModel() );
3148 event
.SetColumn( col
);
3149 event
.SetDataViewColumn( GetOwner()->GetColumn(col
) );
3150 event
.SetItem( item
);
3151 m_owner
->HandleWindowEvent( event
);
3158 GtkTreeModelFlags
wxDataViewCtrlInternal::get_flags()
3160 if (m_wx_model
->IsVirtualListModel())
3161 return GTK_TREE_MODEL_LIST_ONLY
;
3163 return GTK_TREE_MODEL_ITERS_PERSIST
;
3166 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
3168 if (m_wx_model
->IsVirtualListModel())
3170 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3172 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
3174 if (i
>= wx_model
->GetLastIndex() + 1)
3177 iter
->stamp
= m_gtk_model
->stamp
;
3178 // user_data is just the index
3179 iter
->user_data
= (gpointer
) i
;
3185 int depth
= gtk_tree_path_get_depth( path
);
3187 wxGtkTreeModelNode
*node
= m_root
;
3190 for (i
= 0; i
< depth
; i
++)
3192 BuildBranch( node
);
3194 gint pos
= gtk_tree_path_get_indices (path
)[i
];
3195 if (pos
< 0) return FALSE
;
3196 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
3198 void* id
= node
->GetChildren().Item( (size_t) pos
);
3202 iter
->stamp
= m_gtk_model
->stamp
;
3203 iter
->user_data
= id
;
3207 size_t count
= node
->GetNodes().GetCount();
3209 for (pos2
= 0; pos2
< count
; pos2
++)
3211 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
3212 if (child_node
->GetItem().GetID() == id
)
3224 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
3226 GtkTreePath
*retval
= gtk_tree_path_new ();
3228 if (m_wx_model
->IsVirtualListModel())
3230 // user_data is just the index
3231 int i
= (wxUIntPtr
) iter
->user_data
;
3232 gtk_tree_path_append_index (retval
, i
);
3236 void *id
= iter
->user_data
;
3238 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
3241 int pos
= node
->GetChildren().Index( id
);
3243 gtk_tree_path_prepend_index( retval
, pos
);
3245 id
= node
->GetItem().GetID();
3246 node
= node
->GetParent();
3253 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
3255 if (m_wx_model
->IsVirtualListModel())
3257 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3259 int n
= (wxUIntPtr
) iter
->user_data
;
3264 if (n
>= (int) wx_model
->GetLastIndex())
3267 iter
->user_data
= (gpointer
) ++n
;
3271 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
3272 if( parent
== NULL
)
3275 int pos
= parent
->GetChildren().Index( iter
->user_data
);
3277 if (pos
== (int) parent
->GetChildCount()-1)
3280 iter
->stamp
= m_gtk_model
->stamp
;
3281 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
3287 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
3289 if (m_wx_model
->IsVirtualListModel())
3291 // this is a list, nodes have no children
3295 iter
->stamp
= m_gtk_model
->stamp
;
3296 iter
->user_data
= (gpointer
) -1;
3302 wxDataViewItem
item( (void*) parent
->user_data
);
3304 if (!m_wx_model
->IsContainer( item
))
3307 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3308 BuildBranch( parent_node
);
3310 if (parent_node
->GetChildCount() == 0)
3313 iter
->stamp
= m_gtk_model
->stamp
;
3314 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
3320 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
3322 if (m_wx_model
->IsVirtualListModel())
3324 // this is a list, nodes have no children
3329 wxDataViewItem
item( (void*) iter
->user_data
);
3331 bool is_container
= m_wx_model
->IsContainer( item
);
3336 wxGtkTreeModelNode
*node
= FindNode( iter
);
3337 BuildBranch( node
);
3339 return (node
->GetChildCount() > 0);
3343 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
3345 if (m_wx_model
->IsVirtualListModel())
3347 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3350 return (gint
) wx_model
->GetLastIndex() + 1;
3357 return m_root
->GetChildCount();
3359 wxDataViewItem
item( (void*) iter
->user_data
);
3361 if (!m_wx_model
->IsContainer( item
))
3364 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
3365 BuildBranch( parent_node
);
3367 // wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() );
3369 return parent_node
->GetChildCount();
3373 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
3375 if (m_wx_model
->IsVirtualListModel())
3377 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
3385 if (n
>= (gint
) wx_model
->GetLastIndex() + 1)
3388 iter
->stamp
= m_gtk_model
->stamp
;
3389 iter
->user_data
= (gpointer
) n
;
3396 if (parent
) id
= (void*) parent
->user_data
;
3397 wxDataViewItem
item( id
);
3399 if (!m_wx_model
->IsContainer( item
))
3402 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3403 BuildBranch( parent_node
);
3405 // wxPrintf( "iter_nth_child %d\n", n );
3407 iter
->stamp
= m_gtk_model
->stamp
;
3408 iter
->user_data
= parent_node
->GetChildren().Item( n
);
3414 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
3416 if (m_wx_model
->IsVirtualListModel())
3422 wxGtkTreeModelNode
*node
= FindParentNode( child
);
3426 iter
->stamp
= m_gtk_model
->stamp
;
3427 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
3433 static wxGtkTreeModelNode
*
3434 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3440 list
.DeleteContents( true );
3441 wxDataViewItem
it( item
);
3445 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3446 list
.Insert( pItem
);
3447 it
= model
->GetParent( it
);
3450 wxGtkTreeModelNode
* node
= treeNode
;
3451 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3453 if( node
&& node
->GetNodes().GetCount() != 0 )
3455 int len
= node
->GetNodes().GetCount();
3456 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3458 for( ; j
< len
; j
++)
3460 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3479 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
3484 wxDataViewItem
item( (void*) iter
->user_data
);
3488 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3492 wxLogDebug( "Not found %p", iter
->user_data
);
3500 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
3505 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3509 wxLogDebug( "Not found %p", item
.GetID() );
3517 static wxGtkTreeModelNode
*
3518 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3524 list
.DeleteContents( true );
3528 wxDataViewItem
it( model
->GetParent( item
) );
3531 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3532 list
.Insert( pItem
);
3533 it
= model
->GetParent( it
);
3536 wxGtkTreeModelNode
* node
= treeNode
;
3537 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3539 if( node
&& node
->GetNodes().GetCount() != 0 )
3541 int len
= node
->GetNodes().GetCount();
3542 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3544 for( ; j
< len
; j
++)
3546 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3561 //Examine whether the node is item's parent node
3562 int len
= node
->GetChildCount();
3563 for( int i
= 0; i
< len
; i
++ )
3565 if( node
->GetChildren().Item( i
) == item
.GetID() )
3571 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
3576 wxDataViewItem
item( (void*) iter
->user_data
);
3580 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3583 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
3588 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3591 //-----------------------------------------------------------------------------
3592 // wxDataViewCtrl signal callbacks
3593 //-----------------------------------------------------------------------------
3596 wxdataview_selection_changed_callback( GtkTreeSelection
* WXUNUSED(selection
), wxDataViewCtrl
*dv
)
3598 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
3601 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
3602 event
.SetItem( dv
->GetSelection() );
3603 event
.SetModel( dv
->GetModel() );
3604 dv
->HandleWindowEvent( event
);
3608 wxdataview_row_activated_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreePath
*path
,
3609 GtkTreeViewColumn
*WXUNUSED(column
), wxDataViewCtrl
*dv
)
3611 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
3614 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3615 wxDataViewItem
item( (void*) iter
.user_data
);;
3616 event
.SetItem( item
);
3617 event
.SetModel( dv
->GetModel() );
3618 dv
->HandleWindowEvent( event
);
3622 wxdataview_test_expand_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3623 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3625 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
3627 wxDataViewItem
item( (void*) iter
->user_data
);;
3628 event
.SetItem( item
);
3629 event
.SetModel( dv
->GetModel() );
3630 dv
->HandleWindowEvent( event
);
3632 return !event
.IsAllowed();
3636 wxdataview_row_expanded_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3637 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3639 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
3641 wxDataViewItem
item( (void*) iter
->user_data
);;
3642 event
.SetItem( item
);
3643 event
.SetModel( dv
->GetModel() );
3644 dv
->HandleWindowEvent( event
);
3648 wxdataview_test_collapse_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3649 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3651 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
3653 wxDataViewItem
item( (void*) iter
->user_data
);;
3654 event
.SetItem( item
);
3655 event
.SetModel( dv
->GetModel() );
3656 dv
->HandleWindowEvent( event
);
3658 return !event
.IsAllowed();
3662 wxdataview_row_collapsed_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
3663 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
3665 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
3667 wxDataViewItem
item( (void*) iter
->user_data
);;
3668 event
.SetItem( item
);
3669 event
.SetModel( dv
->GetModel() );
3670 dv
->HandleWindowEvent( event
);
3673 //-----------------------------------------------------------------------------
3675 //-----------------------------------------------------------------------------
3677 void wxDataViewCtrl::AddChildGTK(wxWindowGTK
* child
)
3679 GtkWidget
* treeview
= GtkGetTreeView();
3681 // Insert widget in GtkTreeView
3682 if (GTK_WIDGET_REALIZED(treeview
))
3683 gtk_widget_set_parent_window( child
->m_widget
,
3684 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
3685 gtk_widget_set_parent( child
->m_widget
, treeview
);
3689 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
3690 GtkAllocation
*WXUNUSED(gtk_alloc
),
3691 wxDataViewCtrl
*win
)
3693 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
3696 wxWindow
*child
= node
->GetData();
3699 gtk_widget_size_request( child
->m_widget
, &req
);
3701 GtkAllocation alloc
;
3702 alloc
.x
= child
->m_x
;
3703 alloc
.y
= child
->m_y
;
3704 alloc
.width
= child
->m_width
;
3705 alloc
.height
= child
->m_height
;
3706 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
3708 node
= node
->GetNext();
3713 //-----------------------------------------------------------------------------
3714 // "motion_notify_event"
3715 //-----------------------------------------------------------------------------
3718 gtk_dataview_motion_notify_callback( GtkWidget
*WXUNUSED(widget
),
3719 GdkEventMotion
*gdk_event
,
3720 wxDataViewCtrl
*dv
)
3722 if (gdk_event
->is_hint
)
3726 GdkModifierType state
;
3727 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
3732 GtkTreePath
*path
= NULL
;
3733 GtkTreeViewColumn
*column
= NULL
;
3736 if (gtk_tree_view_get_path_at_pos(
3737 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
3738 (int) gdk_event
->x
, (int) gdk_event
->y
,
3747 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3749 // wxPrintf( "mouse %d %d\n", (int) gdk_event->x, (int) gdk_event->y );
3751 gtk_tree_path_free( path
);
3759 //-----------------------------------------------------------------------------
3760 // "button_press_event"
3761 //-----------------------------------------------------------------------------
3764 gtk_dataview_button_press_callback( GtkWidget
*WXUNUSED(widget
),
3765 GdkEventButton
*gdk_event
,
3766 wxDataViewCtrl
*dv
)
3768 if ((gdk_event
->button
== 3) && (gdk_event
->type
== GDK_BUTTON_PRESS
))
3770 GtkTreePath
*path
= NULL
;
3771 GtkTreeViewColumn
*column
= NULL
;
3774 if (gtk_tree_view_get_path_at_pos(
3775 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
3776 (int) gdk_event
->x
, (int) gdk_event
->y
,
3785 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3787 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, dv
->GetId() );
3788 wxDataViewItem
item( (void*) iter
.user_data
);;
3789 event
.SetItem( item
);
3790 event
.SetModel( dv
->GetModel() );
3791 bool ret
= dv
->HandleWindowEvent( event
);
3792 gtk_tree_path_free( path
);
3801 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
3803 wxDataViewCtrl::~wxDataViewCtrl()
3806 GetModel()->RemoveNotifier( m_notifier
);
3810 // remove the model from the GtkTreeView before it gets destroyed by the
3811 // wxDataViewCtrlBase's dtor
3812 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), NULL
);
3817 void wxDataViewCtrl::Init()
3822 m_cols
.DeleteContents( true );
3825 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
3826 const wxPoint
& pos
, const wxSize
& size
,
3827 long style
, const wxValidator
& validator
)
3831 if (!PreCreation( parent
, pos
, size
) ||
3832 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
3834 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
3838 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
3839 g_object_ref(m_widget
);
3841 GTKScrolledWindowSetBorder(m_widget
, style
);
3843 m_treeview
= gtk_tree_view_new();
3844 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
3846 g_signal_connect (m_treeview
, "size_allocate",
3847 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
3850 if (!gtk_check_version(2,6,0))
3852 bool fixed
= (style
& wxDV_VARIABLE_LINE_HEIGHT
) == 0;
3853 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
3857 if (style
& wxDV_MULTIPLE
)
3859 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3860 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
3863 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
3866 if (!gtk_check_version(2,10,0))
3868 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
3870 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
3871 (style
& wxDV_VERT_RULES
) != 0)
3872 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
3873 else if (style
& wxDV_VERT_RULES
)
3874 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
3875 else if (style
& wxDV_HORIZ_RULES
)
3876 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
3878 if (grid
!= GTK_TREE_VIEW_GRID_LINES_NONE
)
3879 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
3883 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_ROW_LINES
) != 0 );
3885 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
3886 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
3887 gtk_widget_show (m_treeview
);
3889 m_parent
->DoAddChild( this );
3893 GtkEnableSelectionEvents();
3895 g_signal_connect_after (m_treeview
, "row-activated",
3896 G_CALLBACK (wxdataview_row_activated_callback
), this);
3898 g_signal_connect (m_treeview
, "test-collapse-row",
3899 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
3901 g_signal_connect_after (m_treeview
, "row-collapsed",
3902 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
3904 g_signal_connect (m_treeview
, "test-expand-row",
3905 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
3907 g_signal_connect_after (m_treeview
, "row-expanded",
3908 G_CALLBACK (wxdataview_row_expanded_callback
), this);
3910 g_signal_connect (m_treeview
, "motion_notify_event",
3911 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
3913 g_signal_connect (m_treeview
, "button_press_event",
3914 G_CALLBACK (gtk_dataview_button_press_callback
), this);
3919 void wxDataViewCtrl::OnInternalIdle()
3921 wxWindow::OnInternalIdle();
3923 unsigned int cols
= GetColumnCount();
3925 for (i
= 0; i
< cols
; i
++)
3927 wxDataViewColumn
*col
= GetColumn( i
);
3928 col
->OnInternalIdle();
3932 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
3943 if (!wxDataViewCtrlBase::AssociateModel( model
))
3947 if (!gtk_check_version(2,6,0))
3949 bool fixed
= (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
) == 0) || (model
->IsVirtualListModel()));
3950 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
3954 GtkWxTreeModel
*gtk_model
= wxgtk_tree_model_new();
3955 m_internal
= new wxDataViewCtrlInternal( this, model
, gtk_model
);
3956 gtk_model
->internal
= m_internal
;
3958 m_notifier
= new wxGtkDataViewModelNotifier( gtk_model
, model
, this );
3960 model
->AddNotifier( m_notifier
);
3962 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_model
) );
3964 // unref in wxDataViewCtrlInternal
3965 // g_object_unref( gtk_model );
3970 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
3972 return m_internal
->EnableDragSource( format
);
3975 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
3977 return m_internal
->EnableDropTarget( format
);
3980 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
3982 if (!wxDataViewCtrlBase::AppendColumn(col
))
3985 m_cols
.Append( col
);
3988 if (!gtk_check_version(2,6,0))
3990 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
3991 GTK_TREE_VIEW_COLUMN_FIXED
)
3992 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
3996 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
3997 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4002 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4004 if (!wxDataViewCtrlBase::PrependColumn(col
))
4007 m_cols
.Insert( col
);
4010 if (!gtk_check_version(2,6,0))
4012 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4013 GTK_TREE_VIEW_COLUMN_FIXED
)
4014 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4018 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4019 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
4024 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4026 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4029 m_cols
.Insert( pos
, col
);
4032 if (!gtk_check_version(2,6,0))
4034 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4035 GTK_TREE_VIEW_COLUMN_FIXED
)
4036 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4040 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4041 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), pos
);
4046 unsigned int wxDataViewCtrl::GetColumnCount() const
4048 return m_cols
.GetCount();
4051 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
4053 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
4057 wxDataViewColumnList::const_iterator iter
;
4058 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4060 wxDataViewColumn
*col
= *iter
;
4061 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
4070 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4072 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4073 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
4075 m_cols
.DeleteObject( column
);
4080 bool wxDataViewCtrl::ClearColumns()
4082 wxDataViewColumnList::iterator iter
;
4083 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4085 wxDataViewColumn
*col
= *iter
;
4086 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4087 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4095 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4097 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetConstGtkHandle());
4099 GList
*list
= gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview
) );
4101 gint pos
= g_list_index( list
, (gconstpointer
) gtk_column
);
4103 g_list_free( list
);
4108 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4110 return m_internal
->GetDataViewSortColumn();
4113 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4116 iter
.user_data
= item
.GetID();
4117 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4118 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
4119 gtk_tree_path_free( path
);
4122 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4125 iter
.user_data
= item
.GetID();
4126 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4127 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
4128 gtk_tree_path_free( path
);
4131 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4134 iter
.user_data
= item
.GetID();
4135 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4136 bool res
= gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview
), path
);
4137 gtk_tree_path_free( path
);
4142 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4144 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4146 if (m_windowStyle
& wxDV_MULTIPLE
)
4148 // Report the first one
4149 GtkTreeModel
*model
;
4150 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4154 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4156 m_internal
->get_iter( &iter
, path
);
4159 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4160 g_list_free( list
);
4162 return wxDataViewItem( (void*) iter
.user_data
);
4168 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
4170 wxDataViewItem
item( (void*) iter
.user_data
);
4175 return wxDataViewItem(0);
4178 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4182 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4183 if (HasFlag(wxDV_MULTIPLE
))
4185 GtkTreeModel
*model
;
4186 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4191 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4194 m_internal
->get_iter( &iter
, path
);
4196 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4198 list
= g_list_next( list
);
4203 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4204 g_list_free( list
);
4210 GtkTreeModel
*model
;
4212 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
4215 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4223 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4225 GtkDisableSelectionEvents();
4227 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4229 gtk_tree_selection_unselect_all( selection
);
4231 wxDataViewItem last_parent
;
4234 for (i
= 0; i
< sel
.GetCount(); i
++)
4236 wxDataViewItem item
= sel
[i
];
4237 wxDataViewItem parent
= GetModel()->GetParent( item
);
4240 if (parent
!= last_parent
)
4241 ExpandAncestors(item
);
4243 last_parent
= parent
;
4246 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4247 iter
.user_data
= (gpointer
) item
.GetID();
4248 gtk_tree_selection_select_iter( selection
, &iter
);
4251 GtkEnableSelectionEvents();
4254 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4256 ExpandAncestors(item
);
4258 GtkDisableSelectionEvents();
4260 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4263 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4264 iter
.user_data
= (gpointer
) item
.GetID();
4265 gtk_tree_selection_select_iter( selection
, &iter
);
4267 GtkEnableSelectionEvents();
4270 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4272 GtkDisableSelectionEvents();
4274 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4277 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4278 iter
.user_data
= (gpointer
) item
.GetID();
4279 gtk_tree_selection_unselect_iter( selection
, &iter
);
4281 GtkEnableSelectionEvents();
4284 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4286 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4289 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4290 iter
.user_data
= (gpointer
) item
.GetID();
4292 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
4295 void wxDataViewCtrl::SelectAll()
4297 GtkDisableSelectionEvents();
4299 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4301 gtk_tree_selection_select_all( selection
);
4303 GtkEnableSelectionEvents();
4306 void wxDataViewCtrl::UnselectAll()
4308 GtkDisableSelectionEvents();
4310 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4312 gtk_tree_selection_unselect_all( selection
);
4314 GtkEnableSelectionEvents();
4317 void wxDataViewCtrl::EnsureVisible(const wxDataViewItem
& item
,
4318 const wxDataViewColumn
*WXUNUSED(column
))
4320 ExpandAncestors(item
);
4323 iter
.user_data
= (gpointer
) item
.GetID();
4324 GtkTreePath
*path
= m_internal
->get_path( &iter
);
4325 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
4326 gtk_tree_path_free( path
);
4329 void wxDataViewCtrl::HitTest(const wxPoint
& WXUNUSED(point
),
4330 wxDataViewItem
& item
,
4331 wxDataViewColumn
*& column
) const
4333 item
= wxDataViewItem(0);
4338 wxDataViewCtrl::GetItemRect(const wxDataViewItem
& WXUNUSED(item
),
4339 const wxDataViewColumn
*WXUNUSED(column
)) const
4344 void wxDataViewCtrl::DoSetExpanderColumn()
4346 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
4347 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
4350 void wxDataViewCtrl::DoSetIndent()
4354 void wxDataViewCtrl::GtkDisableSelectionEvents()
4356 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4357 g_signal_handlers_disconnect_by_func( selection
,
4358 (gpointer
) (wxdataview_selection_changed_callback
), this);
4361 void wxDataViewCtrl::GtkEnableSelectionEvents()
4363 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4364 g_signal_connect_after (selection
, "changed",
4365 G_CALLBACK (wxdataview_selection_changed_callback
), this);
4370 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
4372 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
4377 // !wxUSE_GENERICDATAVIEWCTRL
4380 // wxUSE_DATAVIEWCTRL