1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/dataview.cpp
3 // Purpose: wxDataViewCtrl GTK+2 implementation
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if wxUSE_DATAVIEWCTRL
15 #include "wx/dataview.h"
17 #ifndef wxUSE_GENERICDATAVIEWCTRL
21 #include "wx/dcclient.h"
23 #include "wx/settings.h"
27 #include "wx/stockitem.h"
28 #include "wx/calctrl.h"
29 #include "wx/popupwin.h"
30 #include "wx/listimpl.cpp"
32 #include "wx/gtk/private.h"
33 #include "wx/gtk/dc.h"
34 #include "wx/gtk/dcclient.h"
36 #include "wx/gtk/private/gdkconv.h"
37 using namespace wxGTKImpl
;
39 class wxGtkDataViewModelNotifier
;
41 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
44 static wxDataViewCtrlInternal
*gs_internal
= NULL
;
46 class wxGtkTreeModelNode
;
49 typedef struct _GtkWxTreeModel GtkWxTreeModel
;
52 // ----------------------------------------------------------------------------
53 // wxGtkTreePath: self-destroying GtkTreePath
54 // ----------------------------------------------------------------------------
56 // Usually this object is initialized with the associated GtkTreePath
57 // immediately when it's constructed but it can also be changed later either by
58 // using Assign() or by getting the pointer to the internally stored pointer
59 // value using ByRef(). The latter should be avoided but is very convenient
60 // when using GTK functions with GtkTreePath output parameters.
64 // Ctor takes ownership of the given path and will free it if non-NULL.
65 wxGtkTreePath(GtkTreePath
*path
= NULL
) : m_path(path
) { }
67 // Creates a tree path for the given string path.
68 wxGtkTreePath(const gchar
*strpath
)
69 : m_path(gtk_tree_path_new_from_string(strpath
))
73 // Set the stored pointer if not done by ctor.
74 void Assign(GtkTreePath
*path
)
76 wxASSERT_MSG( !m_path
, "shouldn't be already initialized" );
81 // Return the pointer to the internally stored pointer. This should only be
82 // used to initialize the object by passing it to some GTK function.
85 wxASSERT_MSG( !m_path
, "shouldn't be already initialized" );
91 operator GtkTreePath
*() const { return m_path
; }
93 ~wxGtkTreePath() { if ( m_path
) gtk_tree_path_free(m_path
); }
98 wxDECLARE_NO_COPY_CLASS(wxGtkTreePath
);
101 // ----------------------------------------------------------------------------
102 // wxGtkTreeSelectionLock: prevent selection from changing during the
103 // lifetime of this object
104 // ----------------------------------------------------------------------------
106 // Implementation note: it could be expected that setting the selection
107 // function in this class ctor and resetting it back to the old value in its
108 // dtor would work. However currently gtk_tree_selection_get_select_function()
109 // can't be passed NULL (see https://bugzilla.gnome.org/show_bug.cgi?id=626276)
110 // so we can't do this. Instead, we always use the selection function (which
111 // imposes extra overhead, albeit minimal one, on all selection operations) and
112 // just set/reset the flag telling it whether it should allow or forbid the
115 // Also notice that currently only a single object of this class may exist at
116 // any given moment. It's just simpler like this and we don't need anything
120 gboolean
wxdataview_selection_func(GtkTreeSelection
* WXUNUSED(selection
),
121 GtkTreeModel
* WXUNUSED(model
),
122 GtkTreePath
* WXUNUSED(path
),
123 gboolean
WXUNUSED(path_currently_selected
),
129 class wxGtkTreeSelectionLock
132 wxGtkTreeSelectionLock(GtkTreeSelection
*selection
)
133 : m_selection(selection
)
135 wxASSERT_MSG( !ms_instance
, "this class is not reentrant currently" );
139 CheckCurrentSelectionFunc(NULL
);
141 // Pass some non-NULL pointer as "data" for the callback, it doesn't
142 // matter what it is as long as it's non-NULL.
143 gtk_tree_selection_set_select_function(selection
,
144 wxdataview_selection_func
,
149 ~wxGtkTreeSelectionLock()
151 CheckCurrentSelectionFunc(wxdataview_selection_func
);
153 gtk_tree_selection_set_select_function(m_selection
,
154 wxdataview_selection_func
,
162 void CheckCurrentSelectionFunc(GtkTreeSelectionFunc func
)
164 // We can only use gtk_tree_selection_get_select_function() with 2.14+
165 // so check for its availability both during compile- and run-time.
166 #if GTK_CHECK_VERSION(2, 14, 0)
167 if ( gtk_check_version(2, 14, 0) != NULL
)
170 // If this assert is triggered, it means the code elsewhere has called
171 // gtk_tree_selection_set_select_function() but currently doing this
172 // breaks this class so the code here needs to be changed.
175 gtk_tree_selection_get_select_function(m_selection
) == func
,
176 "selection function has changed unexpectedly, review this code!"
183 static wxGtkTreeSelectionLock
*ms_instance
;
185 GtkTreeSelection
* const m_selection
;
187 wxDECLARE_NO_COPY_CLASS(wxGtkTreeSelectionLock
);
190 wxGtkTreeSelectionLock
*wxGtkTreeSelectionLock::ms_instance
= NULL
;
192 //-----------------------------------------------------------------------------
193 // wxDataViewCtrlInternal
194 //-----------------------------------------------------------------------------
196 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
197 WX_DEFINE_LIST(ItemList
)
199 class wxDataViewCtrlInternal
202 wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
);
203 ~wxDataViewCtrlInternal();
206 GtkTreeModelFlags
get_flags();
207 gboolean
get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
);
208 GtkTreePath
*get_path( GtkTreeIter
*iter
);
209 gboolean
iter_next( GtkTreeIter
*iter
);
210 gboolean
iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
);
211 gboolean
iter_has_child( GtkTreeIter
*iter
);
212 gint
iter_n_children( GtkTreeIter
*iter
);
213 gboolean
iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
);
214 gboolean
iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
);
218 bool EnableDragSource( const wxDataFormat
&format
);
219 bool EnableDropTarget( const wxDataFormat
&format
);
221 gboolean
row_draggable( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
);
222 gboolean
drag_data_delete( GtkTreeDragSource
*drag_source
, GtkTreePath
* path
);
223 gboolean
drag_data_get( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
,
224 GtkSelectionData
*selection_data
);
225 gboolean
drag_data_received( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest
,
226 GtkSelectionData
*selection_data
);
227 gboolean
row_drop_possible( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest_path
,
228 GtkSelectionData
*selection_data
);
230 // notifactions from wxDataViewModel
231 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
232 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
233 bool ItemChanged( const wxDataViewItem
&item
);
234 bool ValueChanged( const wxDataViewItem
&item
, unsigned int model_column
);
241 void SetSortOrder( GtkSortType sort_order
) { m_sort_order
= sort_order
; }
242 GtkSortType
GetSortOrder() const { return m_sort_order
; }
244 void SetSortColumn( int column
) { m_sort_column
= column
; }
245 int GetSortColumn() const { return m_sort_column
; }
247 void SetDataViewSortColumn( wxDataViewColumn
*column
) { m_dataview_sort_column
= column
; }
248 wxDataViewColumn
*GetDataViewSortColumn() { return m_dataview_sort_column
; }
250 bool IsSorted() { return (m_sort_column
>= 0); }
253 wxDataViewModel
* GetDataViewModel() { return m_wx_model
; }
254 const wxDataViewModel
* GetDataViewModel() const { return m_wx_model
; }
255 wxDataViewCtrl
* GetOwner() { return m_owner
; }
256 GtkWxTreeModel
* GetGtkModel() { return m_gtk_model
; }
258 // item can be deleted already in the model
259 int GetIndexOf( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
261 virtual void OnInternalIdle();
265 void ScheduleRefresh();
267 wxGtkTreeModelNode
*FindNode( const wxDataViewItem
&item
);
268 wxGtkTreeModelNode
*FindNode( GtkTreeIter
*iter
);
269 wxGtkTreeModelNode
*FindParentNode( const wxDataViewItem
&item
);
270 wxGtkTreeModelNode
*FindParentNode( GtkTreeIter
*iter
);
271 void BuildBranch( wxGtkTreeModelNode
*branch
);
274 wxGtkTreeModelNode
*m_root
;
275 wxDataViewModel
*m_wx_model
;
276 GtkWxTreeModel
*m_gtk_model
;
277 wxDataViewCtrl
*m_owner
;
278 GtkSortType m_sort_order
;
279 wxDataViewColumn
*m_dataview_sort_column
;
282 GtkTargetEntry m_dragSourceTargetEntry
;
283 wxCharBuffer m_dragSourceTargetEntryTarget
;
284 wxDataObject
*m_dragDataObject
;
286 GtkTargetEntry m_dropTargetTargetEntry
;
287 wxCharBuffer m_dropTargetTargetEntryTarget
;
288 wxDataObject
*m_dropDataObject
;
290 wxGtkDataViewModelNotifier
*m_notifier
;
296 //-----------------------------------------------------------------------------
297 // wxGtkTreeModelNode
298 //-----------------------------------------------------------------------------
301 int LINKAGEMODE
wxGtkTreeModelChildCmp( void** id1
, void** id2
)
303 int ret
= gs_internal
->GetDataViewModel()->Compare( *id1
, *id2
,
304 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
309 WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode
*, wxGtkTreeModelNodes
);
310 WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren
);
312 class wxGtkTreeModelNode
315 wxGtkTreeModelNode( wxGtkTreeModelNode
* parent
, const wxDataViewItem
&item
,
316 wxDataViewCtrlInternal
*internal
)
320 m_internal
= internal
;
323 ~wxGtkTreeModelNode()
325 size_t count
= m_nodes
.GetCount();
327 for (i
= 0; i
< count
; i
++)
329 wxGtkTreeModelNode
*child
= m_nodes
.Item( i
);
334 unsigned int AddNode( wxGtkTreeModelNode
* child
)
336 m_nodes
.Add( child
);
338 void *id
= child
->GetItem().GetID();
340 m_children
.Add( id
);
342 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
344 gs_internal
= m_internal
;
345 m_children
.Sort( &wxGtkTreeModelChildCmp
);
346 return m_children
.Index( id
);
349 return m_children
.GetCount()-1;
352 unsigned int AddLeave( void* id
)
354 m_children
.Add( id
);
356 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
358 gs_internal
= m_internal
;
359 m_children
.Sort( &wxGtkTreeModelChildCmp
);
360 return m_children
.Index( id
);
363 return m_children
.GetCount()-1;
366 void DeleteChild( void* id
)
368 m_children
.Remove( id
);
370 unsigned int count
= m_nodes
.GetCount();
372 for (pos
= 0; pos
< count
; pos
++)
374 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
375 if (node
->GetItem().GetID() == id
)
377 m_nodes
.RemoveAt( pos
);
384 wxGtkTreeModelNode
* GetParent()
386 wxGtkTreeModelNodes
&GetNodes()
388 wxGtkTreeModelChildren
&GetChildren()
389 { return m_children
; }
391 unsigned int GetChildCount() const { return m_children
.GetCount(); }
392 unsigned int GetNodesCount() const { return m_nodes
.GetCount(); }
394 wxDataViewItem
&GetItem() { return m_item
; }
395 wxDataViewCtrlInternal
*GetInternal() { return m_internal
; }
400 wxGtkTreeModelNode
*m_parent
;
401 wxGtkTreeModelNodes m_nodes
;
402 wxGtkTreeModelChildren m_children
;
403 wxDataViewItem m_item
;
404 wxDataViewCtrlInternal
*m_internal
;
408 //-----------------------------------------------------------------------------
410 //-----------------------------------------------------------------------------
412 extern bool g_blockEventsOnDrag
;
414 //-----------------------------------------------------------------------------
415 // define new GTK+ class wxGtkTreeModel
416 //-----------------------------------------------------------------------------
420 #define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ())
421 #define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel))
422 #define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
423 #define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL))
424 #define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL))
425 #define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
427 GType
gtk_wx_tree_model_get_type (void);
429 typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass
;
431 struct _GtkWxTreeModel
437 wxDataViewCtrlInternal
*internal
;
440 struct _GtkWxTreeModelClass
442 GObjectClass list_parent_class
;
445 static GtkWxTreeModel
*wxgtk_tree_model_new (void);
446 static void wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
);
447 static void wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
);
449 static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
);
450 static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
);
451 static void wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
);
452 static void wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
);
454 static void wxgtk_tree_model_finalize (GObject
*object
);
455 static GtkTreeModelFlags
wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
);
456 static gint
wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
);
457 static GType
wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
459 static gboolean
wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
462 static GtkTreePath
*wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
464 static void wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
468 static gboolean
wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
470 static gboolean
wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
472 GtkTreeIter
*parent
);
473 static gboolean
wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
475 static gint
wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
477 static gboolean
wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
481 static gboolean
wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
486 static gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
487 gint
*sort_column_id
,
489 static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
492 static void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
494 GtkTreeIterCompareFunc func
,
496 GtkDestroyNotify destroy
);
497 static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
498 GtkTreeIterCompareFunc func
,
500 GtkDestroyNotify destroy
);
501 static gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
);
504 static gboolean
wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
506 static gboolean
wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
508 static gboolean
wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
510 GtkSelectionData
*selection_data
);
511 static gboolean
wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
513 GtkSelectionData
*selection_data
);
514 static gboolean
wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
515 GtkTreePath
*dest_path
,
516 GtkSelectionData
*selection_data
);
519 static GObjectClass
*list_parent_class
= NULL
;
522 gtk_wx_tree_model_get_type (void)
524 static GType tree_model_type
= 0;
526 if (!tree_model_type
)
528 const GTypeInfo tree_model_info
=
530 sizeof (GtkWxTreeModelClass
),
531 NULL
, /* base_init */
532 NULL
, /* base_finalize */
533 (GClassInitFunc
) wxgtk_tree_model_class_init
,
534 NULL
, /* class_finalize */
535 NULL
, /* class_data */
536 sizeof (GtkWxTreeModel
),
538 (GInstanceInitFunc
) wxgtk_tree_model_init
,
541 static const GInterfaceInfo tree_model_iface_info
=
543 (GInterfaceInitFunc
) wxgtk_tree_model_tree_model_init
,
548 static const GInterfaceInfo sortable_iface_info
=
550 (GInterfaceInitFunc
) wxgtk_tree_model_sortable_init
,
555 static const GInterfaceInfo drag_source_iface_info
=
557 (GInterfaceInitFunc
) wxgtk_tree_model_drag_source_init
,
562 static const GInterfaceInfo drag_dest_iface_info
=
564 (GInterfaceInitFunc
) wxgtk_tree_model_drag_dest_init
,
569 tree_model_type
= g_type_register_static (G_TYPE_OBJECT
, "GtkWxTreeModel",
570 &tree_model_info
, (GTypeFlags
)0 );
572 g_type_add_interface_static (tree_model_type
,
574 &tree_model_iface_info
);
575 g_type_add_interface_static (tree_model_type
,
576 GTK_TYPE_TREE_SORTABLE
,
577 &sortable_iface_info
);
578 g_type_add_interface_static (tree_model_type
,
579 GTK_TYPE_TREE_DRAG_DEST
,
580 &drag_dest_iface_info
);
581 g_type_add_interface_static (tree_model_type
,
582 GTK_TYPE_TREE_DRAG_SOURCE
,
583 &drag_source_iface_info
);
586 return tree_model_type
;
589 static GtkWxTreeModel
*
590 wxgtk_tree_model_new(void)
592 GtkWxTreeModel
*retval
= (GtkWxTreeModel
*) g_object_new (GTK_TYPE_WX_TREE_MODEL
, NULL
);
597 wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
)
599 list_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
600 GObjectClass
*object_class
= (GObjectClass
*) klass
;
601 object_class
->finalize
= wxgtk_tree_model_finalize
;
605 wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
)
607 iface
->get_flags
= wxgtk_tree_model_get_flags
;
608 iface
->get_n_columns
= wxgtk_tree_model_get_n_columns
;
609 iface
->get_column_type
= wxgtk_tree_model_get_column_type
;
610 iface
->get_iter
= wxgtk_tree_model_get_iter
;
611 iface
->get_path
= wxgtk_tree_model_get_path
;
612 iface
->get_value
= wxgtk_tree_model_get_value
;
613 iface
->iter_next
= wxgtk_tree_model_iter_next
;
614 iface
->iter_children
= wxgtk_tree_model_iter_children
;
615 iface
->iter_has_child
= wxgtk_tree_model_iter_has_child
;
616 iface
->iter_n_children
= wxgtk_tree_model_iter_n_children
;
617 iface
->iter_nth_child
= wxgtk_tree_model_iter_nth_child
;
618 iface
->iter_parent
= wxgtk_tree_model_iter_parent
;
622 wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
)
624 iface
->get_sort_column_id
= wxgtk_tree_model_get_sort_column_id
;
625 iface
->set_sort_column_id
= wxgtk_tree_model_set_sort_column_id
;
626 iface
->set_sort_func
= wxgtk_tree_model_set_sort_func
;
627 iface
->set_default_sort_func
= wxgtk_tree_model_set_default_sort_func
;
628 iface
->has_default_sort_func
= wxgtk_tree_model_has_default_sort_func
;
632 wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
)
634 iface
->row_draggable
= wxgtk_tree_model_row_draggable
;
635 iface
->drag_data_delete
= wxgtk_tree_model_drag_data_delete
;
636 iface
->drag_data_get
= wxgtk_tree_model_drag_data_get
;
640 wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
)
642 iface
->drag_data_received
= wxgtk_tree_model_drag_data_received
;
643 iface
->row_drop_possible
= wxgtk_tree_model_row_drop_possible
;
647 wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
)
649 tree_model
->internal
= NULL
;
650 tree_model
->stamp
= g_random_int();
654 wxgtk_tree_model_finalize (GObject
*object
)
657 (* list_parent_class
->finalize
) (object
);
662 //-----------------------------------------------------------------------------
663 // implement callbacks from wxGtkTreeModel class by letting
664 // them call the methods of wxWidgets' wxDataViewModel
665 //-----------------------------------------------------------------------------
667 static GtkTreeModelFlags
668 wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
)
670 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
671 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), (GtkTreeModelFlags
)0 );
673 return wxtree_model
->internal
->get_flags();
677 wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
)
679 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
680 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
682 return wxtree_model
->internal
->GetDataViewModel()->GetColumnCount();
686 wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
689 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
690 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), G_TYPE_INVALID
);
692 GType gtype
= G_TYPE_INVALID
;
694 wxString wxtype
= wxtree_model
->internal
->GetDataViewModel()->GetColumnType( (unsigned int) index
);
696 if (wxtype
== wxT("string"))
697 gtype
= G_TYPE_STRING
;
700 gtype
= G_TYPE_POINTER
;
701 // wxFAIL_MSG( wxT("non-string columns not supported for searching yet") );
708 wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
712 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
713 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
714 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
716 return wxtree_model
->internal
->get_iter( iter
, path
);
720 wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
723 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
724 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), NULL
);
725 g_return_val_if_fail (iter
->stamp
== GTK_WX_TREE_MODEL (wxtree_model
)->stamp
, NULL
);
727 return wxtree_model
->internal
->get_path( iter
);
731 wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
736 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
737 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
) );
739 wxDataViewModel
*model
= wxtree_model
->internal
->GetDataViewModel();
740 wxString mtype
= model
->GetColumnType( (unsigned int) column
);
741 if (mtype
== wxT("string"))
744 g_value_init( value
, G_TYPE_STRING
);
745 wxDataViewItem
item( (void*) iter
->user_data
);
746 model
->GetValue( variant
, item
, (unsigned int) column
);
748 g_value_set_string( value
, variant
.GetString().utf8_str() );
752 wxFAIL_MSG( wxT("non-string columns not supported yet") );
757 wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
760 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
762 // This happens when clearing the view by calling .._set_model( NULL );
763 if (iter
->stamp
== 0) return FALSE
;
765 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
766 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
768 return wxtree_model
->internal
->iter_next( iter
);
772 wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
776 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
777 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
780 g_return_val_if_fail (wxtree_model
->stamp
== parent
->stamp
, FALSE
);
783 return wxtree_model
->internal
->iter_children( iter
, parent
);
787 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
790 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
791 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
792 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
794 return wxtree_model
->internal
->iter_has_child( iter
);
798 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
801 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
802 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
803 g_return_val_if_fail ( !iter
|| wxtree_model
->stamp
== iter
->stamp
, 0);
805 return wxtree_model
->internal
->iter_n_children( iter
);
809 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
814 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
815 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
817 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
821 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
825 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
826 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
827 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
829 return wxtree_model
->internal
->iter_parent( iter
, child
);
832 /* drag'n'drop iface */
834 wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
837 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
838 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
840 return wxtree_model
->internal
->row_draggable( drag_source
, path
);
844 wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
847 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
848 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
850 return wxtree_model
->internal
->drag_data_delete( drag_source
, path
);
854 wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
856 GtkSelectionData
*selection_data
)
858 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
859 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
862 wxPrintf( "drag_get_data\n");
864 wxGtkString
atom_selection(gdk_atom_name(selection_data
->selection
));
865 wxPrintf( "selection %s\n", wxString::FromAscii(atom_selection
) );
867 wxGtkString
atom_target(gdk_atom_name(selection_data
->target
));
868 wxPrintf( "target %s\n", wxString::FromAscii(atom_target
) );
870 wxGtkString
atom_type(gdk_atom_name(selection_data
->type
));
871 wxPrintf( "type %s\n", wxString::FromAscii(atom_type
) );
873 wxPrintf( "format %d\n", selection_data
->format
);
876 return wxtree_model
->internal
->drag_data_get( drag_source
, path
, selection_data
);
880 wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
882 GtkSelectionData
*selection_data
)
884 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
885 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
887 return wxtree_model
->internal
->drag_data_received( drag_dest
, dest
, selection_data
);
891 wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
892 GtkTreePath
*dest_path
,
893 GtkSelectionData
*selection_data
)
895 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
896 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
898 return wxtree_model
->internal
->row_drop_possible( drag_dest
, dest_path
, selection_data
);
903 wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
904 gint
*sort_column_id
,
907 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) sortable
;
909 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
911 if (!wxtree_model
->internal
->IsSorted())
914 *sort_column_id
= -1;
921 *sort_column_id
= wxtree_model
->internal
->GetSortColumn();
924 *order
= wxtree_model
->internal
->GetSortOrder();
929 wxDataViewColumn
*gs_lastLeftClickHeader
= NULL
;
932 wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
936 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
937 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
939 tree_model
->internal
->SetDataViewSortColumn( gs_lastLeftClickHeader
);
941 if ((sort_column_id
!= (gint
) tree_model
->internal
->GetSortColumn()) ||
942 (order
!= tree_model
->internal
->GetSortOrder()))
944 tree_model
->internal
->SetSortColumn( sort_column_id
);
945 tree_model
->internal
->SetSortOrder( order
);
947 gtk_tree_sortable_sort_column_changed (sortable
);
949 tree_model
->internal
->GetDataViewModel()->Resort();
952 if (gs_lastLeftClickHeader
)
954 wxDataViewCtrl
*dv
= tree_model
->internal
->GetOwner();
955 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, dv
->GetId() );
956 event
.SetDataViewColumn( gs_lastLeftClickHeader
);
957 event
.SetModel( dv
->GetModel() );
958 dv
->HandleWindowEvent( event
);
961 gs_lastLeftClickHeader
= NULL
;
965 wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
966 gint
WXUNUSED(sort_column_id
),
967 GtkTreeIterCompareFunc func
,
968 gpointer
WXUNUSED(data
),
969 GtkDestroyNotify
WXUNUSED(destroy
))
971 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
972 g_return_if_fail (func
!= NULL
);
976 wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
977 GtkTreeIterCompareFunc func
,
978 gpointer
WXUNUSED(data
),
979 GtkDestroyNotify
WXUNUSED(destroy
))
981 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
982 g_return_if_fail (func
!= NULL
);
984 //wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
985 // TODO: remove this code
989 wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
)
991 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
996 //-----------------------------------------------------------------------------
997 // define new GTK+ class GtkWxRendererText
998 //-----------------------------------------------------------------------------
1002 #define GTK_TYPE_WX_CELL_RENDERER_TEXT (gtk_wx_cell_renderer_text_get_type ())
1003 #define GTK_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererText))
1004 #define GTK_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
1005 #define GTK_IS_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT))
1006 #define GTK_IS_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT))
1007 #define GTK_WX_CELL_RENDERER_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
1009 GType
gtk_wx_cell_renderer_text_get_type (void);
1011 typedef struct _GtkWxCellRendererText GtkWxCellRendererText
;
1012 typedef struct _GtkWxCellRendererTextClass GtkWxCellRendererTextClass
;
1014 struct _GtkWxCellRendererText
1016 GtkCellRendererText parent
;
1018 wxDataViewRenderer
*wx_renderer
;
1021 struct _GtkWxCellRendererTextClass
1023 GtkCellRendererTextClass cell_parent_class
;
1027 static GtkWxCellRendererText
*gtk_wx_cell_renderer_text_new (void);
1028 static void gtk_wx_cell_renderer_text_init (
1029 GtkWxCellRendererText
*cell
);
1030 static void gtk_wx_cell_renderer_text_class_init(
1031 GtkWxCellRendererTextClass
*klass
);
1032 static void gtk_wx_cell_renderer_text_finalize (
1034 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
1035 GtkCellRenderer
*cell
,
1039 GdkRectangle
*background_area
,
1040 GdkRectangle
*cell_area
,
1041 GtkCellRendererState flags
);
1044 static GObjectClass
*text_cell_parent_class
= NULL
;
1049 gtk_wx_cell_renderer_text_get_type (void)
1051 static GType cell_wx_type
= 0;
1055 const GTypeInfo cell_wx_info
=
1057 sizeof (GtkWxCellRendererTextClass
),
1058 NULL
, /* base_init */
1059 NULL
, /* base_finalize */
1060 (GClassInitFunc
) gtk_wx_cell_renderer_text_class_init
,
1061 NULL
, /* class_finalize */
1062 NULL
, /* class_data */
1063 sizeof (GtkWxCellRendererText
),
1064 0, /* n_preallocs */
1065 (GInstanceInitFunc
) gtk_wx_cell_renderer_text_init
,
1068 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER_TEXT
,
1069 "GtkWxCellRendererText", &cell_wx_info
, (GTypeFlags
)0 );
1072 return cell_wx_type
;
1076 gtk_wx_cell_renderer_text_init (GtkWxCellRendererText
*cell
)
1078 cell
->wx_renderer
= NULL
;
1082 gtk_wx_cell_renderer_text_class_init (GtkWxCellRendererTextClass
*klass
)
1084 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1085 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
1087 text_cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
1089 object_class
->finalize
= gtk_wx_cell_renderer_text_finalize
;
1091 cell_class
->start_editing
= gtk_wx_cell_renderer_text_start_editing
;
1095 gtk_wx_cell_renderer_text_finalize (GObject
*object
)
1098 (* G_OBJECT_CLASS (text_cell_parent_class
)->finalize
) (object
);
1101 GtkWxCellRendererText
*
1102 gtk_wx_cell_renderer_text_new (void)
1104 return (GtkWxCellRendererText
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER_TEXT
, NULL
);
1107 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
1108 GtkCellRenderer
*gtk_renderer
,
1109 GdkEvent
*gdk_event
,
1112 GdkRectangle
*background_area
,
1113 GdkRectangle
*cell_area
,
1114 GtkCellRendererState flags
)
1116 GtkWxCellRendererText
*wxgtk_renderer
= (GtkWxCellRendererText
*) gtk_renderer
;
1117 wxDataViewRenderer
*wx_renderer
= wxgtk_renderer
->wx_renderer
;
1118 wxDataViewColumn
*column
= wx_renderer
->GetOwner();
1121 item(column
->GetOwner()->GTKPathToItem(wxGtkTreePath(path
)));
1123 wxDataViewCtrl
*dv
= column
->GetOwner();
1124 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, dv
->GetId() );
1125 event
.SetDataViewColumn( column
);
1126 event
.SetModel( dv
->GetModel() );
1127 event
.SetColumn( column
->GetModelColumn() );
1128 event
.SetItem( item
);
1129 dv
->HandleWindowEvent( event
);
1131 if (event
.IsAllowed())
1132 return GTK_CELL_RENDERER_CLASS(text_cell_parent_class
)->
1133 start_editing( gtk_renderer
, gdk_event
, widget
, path
, background_area
, cell_area
, flags
);
1138 //-----------------------------------------------------------------------------
1139 // define new GTK+ class GtkWxCellRenderer
1140 //-----------------------------------------------------------------------------
1144 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
1145 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
1146 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
1147 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
1148 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
1149 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
1151 GType
gtk_wx_cell_renderer_get_type (void);
1153 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
1154 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
1156 struct _GtkWxCellRenderer
1158 GtkCellRenderer parent
;
1161 wxDataViewCustomRenderer
*cell
;
1165 struct _GtkWxCellRendererClass
1167 GtkCellRendererClass cell_parent_class
;
1171 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
1172 static void gtk_wx_cell_renderer_init (
1173 GtkWxCellRenderer
*cell
);
1174 static void gtk_wx_cell_renderer_class_init(
1175 GtkWxCellRendererClass
*klass
);
1176 static void gtk_wx_cell_renderer_finalize (
1178 static void gtk_wx_cell_renderer_get_size (
1179 GtkCellRenderer
*cell
,
1181 GdkRectangle
*rectangle
,
1186 static void gtk_wx_cell_renderer_render (
1187 GtkCellRenderer
*cell
,
1190 GdkRectangle
*background_area
,
1191 GdkRectangle
*cell_area
,
1192 GdkRectangle
*expose_area
,
1193 GtkCellRendererState flags
);
1194 static gboolean
gtk_wx_cell_renderer_activate(
1195 GtkCellRenderer
*cell
,
1199 GdkRectangle
*background_area
,
1200 GdkRectangle
*cell_area
,
1201 GtkCellRendererState flags
);
1202 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1203 GtkCellRenderer
*cell
,
1207 GdkRectangle
*background_area
,
1208 GdkRectangle
*cell_area
,
1209 GtkCellRendererState flags
);
1212 static GObjectClass
*cell_parent_class
= NULL
;
1217 gtk_wx_cell_renderer_get_type (void)
1219 static GType cell_wx_type
= 0;
1223 const GTypeInfo cell_wx_info
=
1225 sizeof (GtkWxCellRendererClass
),
1226 NULL
, /* base_init */
1227 NULL
, /* base_finalize */
1228 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
1229 NULL
, /* class_finalize */
1230 NULL
, /* class_data */
1231 sizeof (GtkWxCellRenderer
),
1232 0, /* n_preallocs */
1233 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
1236 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
1237 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
1240 return cell_wx_type
;
1244 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
1247 cell
->last_click
= 0;
1251 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
1253 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1254 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
1256 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
1258 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
1260 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
1261 cell_class
->render
= gtk_wx_cell_renderer_render
;
1262 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
1263 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
1267 gtk_wx_cell_renderer_finalize (GObject
*object
)
1270 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
1274 gtk_wx_cell_renderer_new (void)
1276 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
1279 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1280 GtkCellRenderer
*renderer
,
1281 GdkEvent
*WXUNUSED(event
),
1284 GdkRectangle
*WXUNUSED(background_area
),
1285 GdkRectangle
*cell_area
,
1286 GtkCellRendererState
WXUNUSED(flags
) )
1288 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1289 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1291 // Renderer doesn't support in-place editing
1292 if (!cell
->HasEditorCtrl())
1295 // An in-place editing control is still around
1296 if (cell
->GetEditorCtrl())
1300 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1306 rect
.x
+= cell_area
->x
;
1307 rect
.y
+= cell_area
->y
;
1308 // rect.width -= renderer->xpad * 2;
1309 // rect.height -= renderer->ypad * 2;
1311 // wxRect renderrect(wxRectFromGDKRect(&rect));
1312 wxRect
renderrect(wxRectFromGDKRect(cell_area
));
1315 item(cell
->GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(path
)));
1317 cell
->StartEditing( item
, renderrect
);
1323 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
1324 GtkWidget
*WXUNUSED(widget
),
1325 GdkRectangle
*cell_area
,
1331 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1332 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1334 wxSize size
= cell
->GetSize();
1336 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
1337 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
1344 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
1348 *x_offset
= (gint
)((renderer
->xalign
*
1349 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
1350 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
1354 *y_offset
= (gint
)((renderer
->yalign
*
1355 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
1356 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
1361 *width
= calc_width
;
1364 *height
= calc_height
;
1368 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
1371 GdkRectangle
*background_area
,
1372 GdkRectangle
*cell_area
,
1373 GdkRectangle
*expose_area
,
1374 GtkCellRendererState flags
)
1377 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1378 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1380 cell
->GTKStashRenderParams(window
, widget
,
1381 background_area
, expose_area
, flags
);
1383 wxRect
rect(wxRectFromGDKRect(cell_area
));
1384 rect
= rect
.Deflate(renderer
->xpad
, renderer
->ypad
);
1386 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
1387 wxWindowDCImpl
*impl
= (wxWindowDCImpl
*) dc
->GetImpl();
1389 // Reinitialize wxWindowDC's GDK window if drawing occurs into a different
1390 // window such as a DnD drop window.
1391 if (window
!= impl
->m_gdkwindow
)
1394 impl
->m_gdkwindow
= window
;
1399 if (flags
& GTK_CELL_RENDERER_SELECTED
)
1400 state
|= wxDATAVIEW_CELL_SELECTED
;
1401 if (flags
& GTK_CELL_RENDERER_PRELIT
)
1402 state
|= wxDATAVIEW_CELL_PRELIT
;
1403 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1404 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1405 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1406 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1407 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
1408 state
|= wxDATAVIEW_CELL_FOCUSED
;
1409 cell
->WXCallRender( rect
, dc
, state
);
1413 gtk_wx_cell_renderer_activate(
1414 GtkCellRenderer
*renderer
,
1418 GdkRectangle
*WXUNUSED(background_area
),
1419 GdkRectangle
*cell_area
,
1420 GtkCellRendererState
WXUNUSED(flags
) )
1422 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1423 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1426 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1432 rect
.x
+= cell_area
->x
;
1433 rect
.y
+= cell_area
->y
;
1434 rect
.width
-= renderer
->xpad
* 2;
1435 rect
.height
-= renderer
->ypad
* 2;
1437 wxRect
renderrect(wxRectFromGDKRect(&rect
));
1439 wxDataViewCtrl
* const ctrl
= cell
->GetOwner()->GetOwner();
1440 wxDataViewModel
*model
= ctrl
->GetModel();
1442 wxDataViewItem
item(ctrl
->GTKPathToItem(wxGtkTreePath(path
)));
1444 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1450 // activated by <ENTER>
1451 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1456 else if (event
->type
== GDK_BUTTON_PRESS
)
1458 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
1459 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
1460 ((int) button_event
->y
) - renderrect
.y
);
1463 if (button_event
->button
== 1)
1465 if (cell
->LeftClick( pt
, renderrect
, model
, item
, model_col
))
1467 // TODO: query system double-click time
1468 if (button_event
->time
- wxrenderer
->last_click
< 400)
1469 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1472 wxrenderer
->last_click
= button_event
->time
;
1480 // ---------------------------------------------------------
1481 // wxGtkDataViewModelNotifier
1482 // ---------------------------------------------------------
1484 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1487 wxGtkDataViewModelNotifier( wxDataViewModel
*wx_model
, wxDataViewCtrlInternal
*internal
);
1488 ~wxGtkDataViewModelNotifier();
1490 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1491 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1492 virtual bool ItemChanged( const wxDataViewItem
&item
);
1493 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int model_column
);
1494 virtual bool Cleared();
1495 virtual void Resort();
1496 virtual bool BeforeReset();
1497 virtual bool AfterReset();
1499 void UpdateLastCount();
1502 wxDataViewModel
*m_wx_model
;
1503 wxDataViewCtrlInternal
*m_internal
;
1506 // ---------------------------------------------------------
1507 // wxGtkDataViewListModelNotifier
1508 // ---------------------------------------------------------
1510 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1511 wxDataViewModel
*wx_model
, wxDataViewCtrlInternal
*internal
)
1513 m_wx_model
= wx_model
;
1514 m_internal
= internal
;
1517 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1523 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1525 m_internal
->ItemAdded( parent
, item
);
1526 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1529 iter
.stamp
= wxgtk_model
->stamp
;
1530 iter
.user_data
= item
.GetID();
1532 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1533 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1534 gtk_tree_model_row_inserted(
1535 GTK_TREE_MODEL(wxgtk_model
), path
, &iter
);
1540 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1542 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1544 // using _get_path for a deleted item cannot be
1547 iter
.stamp
= wxgtk_model
->stamp
;
1548 iter
.user_data
= (gpointer
) item
.GetID();
1549 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1550 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1552 // so get the path from the parent
1554 iter
.stamp
= wxgtk_model
->stamp
;
1555 iter
.user_data
= (gpointer
) parent
.GetID();
1556 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1557 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1558 // and add the final index ourselves
1559 int index
= m_internal
->GetIndexOf( parent
, item
);
1560 gtk_tree_path_append_index( path
, index
);
1563 gtk_tree_model_row_deleted(
1564 GTK_TREE_MODEL(wxgtk_model
), path
);
1566 m_internal
->ItemDeleted( parent
, item
);
1571 void wxGtkDataViewModelNotifier::Resort()
1573 m_internal
->Resort();
1576 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1578 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1581 iter
.stamp
= wxgtk_model
->stamp
;
1582 iter
.user_data
= (gpointer
) item
.GetID();
1584 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1585 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1586 gtk_tree_model_row_changed(
1587 GTK_TREE_MODEL(wxgtk_model
), path
, &iter
);
1589 m_internal
->ItemChanged( item
);
1594 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_column
)
1596 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1597 wxDataViewCtrl
*ctrl
= m_internal
->GetOwner();
1599 // This adds GTK+'s missing MVC logic for ValueChanged
1601 for (index
= 0; index
< ctrl
->GetColumnCount(); index
++)
1603 wxDataViewColumn
*column
= ctrl
->GetColumn( index
);
1604 if (column
->GetModelColumn() == model_column
)
1606 GtkTreeView
*widget
= GTK_TREE_VIEW(ctrl
->GtkGetTreeView());
1607 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1611 iter
.stamp
= wxgtk_model
->stamp
;
1612 iter
.user_data
= (gpointer
) item
.GetID();
1613 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1614 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1615 GdkRectangle cell_area
;
1616 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1618 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1619 double d
= gtk_adjustment_get_value( hadjust
);
1620 int xdiff
= (int) d
;
1622 int ydiff
= gcolumn
->button
->allocation
.height
;
1624 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1625 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1627 m_internal
->ValueChanged( item
, model_column
);
1636 bool wxGtkDataViewModelNotifier::BeforeReset()
1638 GtkWidget
*treeview
= m_internal
->GetOwner()->GtkGetTreeView();
1639 gtk_tree_view_set_model( GTK_TREE_VIEW(treeview
), NULL
);
1644 bool wxGtkDataViewModelNotifier::AfterReset()
1646 GtkWidget
*treeview
= m_internal
->GetOwner()->GtkGetTreeView();
1647 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1649 m_internal
->Cleared();
1651 gtk_tree_view_set_model( GTK_TREE_VIEW(treeview
), GTK_TREE_MODEL(wxgtk_model
) );
1656 bool wxGtkDataViewModelNotifier::Cleared()
1658 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1660 // There is no call to tell the model that everything
1661 // has been deleted so call row_deleted() for every
1664 int count
= m_internal
->iter_n_children( NULL
); // number of children of root
1666 GtkTreePath
*path
= gtk_tree_path_new_first(); // points to root
1669 for (i
= 0; i
< count
; i
++)
1670 gtk_tree_model_row_deleted( GTK_TREE_MODEL(wxgtk_model
), path
);
1672 gtk_tree_path_free( path
);
1674 m_internal
->Cleared();
1679 // ---------------------------------------------------------
1680 // wxDataViewRenderer
1681 // ---------------------------------------------------------
1683 static gpointer s_user_data
= NULL
;
1686 wxgtk_cell_editable_editing_done( GtkCellEditable
*WXUNUSED(editable
),
1687 wxDataViewRenderer
*wxrenderer
)
1689 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1690 wxDataViewCtrl
*dv
= column
->GetOwner();
1691 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1692 event
.SetDataViewColumn( column
);
1693 event
.SetModel( dv
->GetModel() );
1694 wxDataViewItem
item( s_user_data
);
1695 event
.SetItem( item
);
1696 dv
->HandleWindowEvent( event
);
1700 wxgtk_renderer_editing_started( GtkCellRenderer
*WXUNUSED(cell
), GtkCellEditable
*editable
,
1701 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1706 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1707 wxDataViewCtrl
*dv
= column
->GetOwner();
1708 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1709 event
.SetDataViewColumn( column
);
1710 event
.SetModel( dv
->GetModel() );
1711 wxDataViewItem
item(dv
->GTKPathToItem(wxGtkTreePath(path
)));
1712 event
.SetItem( item
);
1713 dv
->HandleWindowEvent( event
);
1715 if (GTK_IS_CELL_EDITABLE(editable
))
1717 s_user_data
= item
.GetID();
1719 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1720 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1721 (gpointer
) wxrenderer
);
1727 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1729 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1731 wxDataViewRendererBase( varianttype
, mode
, align
)
1736 // we haven't changed them yet
1737 m_usingDefaultAttrs
= true;
1739 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1740 // after the m_renderer pointer has been initialized
1743 void wxDataViewRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
1745 gtk_tree_view_column_pack_end( column
, m_renderer
, TRUE
/* expand */);
1748 void wxDataViewRenderer::GtkInitHandlers()
1750 if (!gtk_check_version(2,6,0))
1752 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1753 G_CALLBACK (wxgtk_renderer_editing_started
),
1758 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1760 GtkCellRendererMode gtkMode
;
1763 case wxDATAVIEW_CELL_INERT
:
1764 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1767 case wxDATAVIEW_CELL_ACTIVATABLE
:
1768 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1771 case wxDATAVIEW_CELL_EDITABLE
:
1772 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1776 wxFAIL_MSG( "unknown wxDataViewCellMode value" );
1782 // This value is most often ignored in GtkTreeView
1783 GValue gvalue
= { 0, };
1784 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1785 g_value_set_enum( &gvalue
, gtkMode
);
1786 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1787 g_value_unset( &gvalue
);
1790 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1792 wxDataViewCellMode ret
;
1795 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1797 switch (g_value_get_enum(&gvalue
))
1800 wxFAIL_MSG( "unknown GtkCellRendererMode value" );
1801 // fall through (we have to return something)
1803 case GTK_CELL_RENDERER_MODE_INERT
:
1804 ret
= wxDATAVIEW_CELL_INERT
;
1807 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1808 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1811 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1812 ret
= wxDATAVIEW_CELL_EDITABLE
;
1816 g_value_unset( &gvalue
);
1821 void wxDataViewRenderer::GtkUpdateAlignment()
1823 int align
= m_alignment
;
1825 // query alignment from column ?
1829 if (GetOwner() == NULL
)
1832 align
= GetOwner()->GetAlignment();
1833 align
|= wxALIGN_CENTRE_VERTICAL
;
1836 // horizontal alignment:
1838 gfloat xalign
= 0.0;
1839 if (align
& wxALIGN_RIGHT
)
1841 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1844 GValue gvalue
= { 0, };
1845 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1846 g_value_set_float( &gvalue
, xalign
);
1847 g_object_set_property( G_OBJECT(m_renderer
), "xalign", &gvalue
);
1848 g_value_unset( &gvalue
);
1850 // vertical alignment:
1852 gfloat yalign
= 0.0;
1853 if (align
& wxALIGN_BOTTOM
)
1855 else if (align
& wxALIGN_CENTER_VERTICAL
)
1858 GValue gvalue2
= { 0, };
1859 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1860 g_value_set_float( &gvalue2
, yalign
);
1861 g_object_set_property( G_OBJECT(m_renderer
), "yalign", &gvalue2
);
1862 g_value_unset( &gvalue2
);
1865 void wxDataViewRenderer::SetAlignment( int align
)
1867 m_alignment
= align
;
1868 GtkUpdateAlignment();
1871 int wxDataViewRenderer::GetAlignment() const
1876 void wxDataViewRenderer::EnableEllipsize(wxEllipsizeMode mode
)
1879 if ( gtk_check_version(2, 6, 0) != NULL
)
1882 GtkCellRendererText
* const rend
= GtkGetTextRenderer();
1886 // we use the same values in wxEllipsizeMode as PangoEllipsizeMode so we
1887 // can just cast between them
1888 GValue gvalue
= { 0, };
1889 g_value_init( &gvalue
, PANGO_TYPE_ELLIPSIZE_MODE
);
1890 g_value_set_enum( &gvalue
, static_cast<PangoEllipsizeMode
>(mode
) );
1891 g_object_set_property( G_OBJECT(rend
), "ellipsize", &gvalue
);
1892 g_value_unset( &gvalue
);
1895 #endif // GTK 2.6/before
1898 wxEllipsizeMode
wxDataViewRenderer::GetEllipsizeMode() const
1901 if ( gtk_check_version(2, 6, 0) != NULL
)
1902 return wxELLIPSIZE_NONE
;
1904 GtkCellRendererText
* const rend
= GtkGetTextRenderer();
1906 return wxELLIPSIZE_NONE
;
1908 GValue gvalue
= { 0, };
1909 g_value_init( &gvalue
, PANGO_TYPE_ELLIPSIZE_MODE
);
1910 g_object_get_property( G_OBJECT(rend
), "ellipsize", &gvalue
);
1912 mode
= static_cast<wxEllipsizeMode
>(g_value_get_enum( &gvalue
));
1913 g_value_unset( &gvalue
);
1917 return wxELLIPSIZE_NONE
;
1918 #endif // GTK 2.6/before
1922 wxDataViewRenderer::GtkOnTextEdited(const gchar
*itempath
, const wxString
& str
)
1924 wxVariant
value(str
);
1925 if (!Validate( value
))
1929 item(GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(itempath
)));
1931 GtkOnCellChanged(value
, item
, GetOwner()->GetModelColumn());
1935 wxDataViewRenderer::GtkOnCellChanged(const wxVariant
& value
,
1936 const wxDataViewItem
& item
,
1939 wxDataViewModel
*model
= GetOwner()->GetOwner()->GetModel();
1940 model
->ChangeValue( value
, item
, col
);
1943 // ---------------------------------------------------------
1944 // wxDataViewTextRenderer
1945 // ---------------------------------------------------------
1950 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*WXUNUSED(renderer
),
1951 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1953 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) user_data
;
1955 cell
->GtkOnTextEdited(arg1
, wxGTK_CONV_BACK_FONT(
1956 arg2
, cell
->GetOwner()->GetOwner()->GetFont()));
1964 // helper function used by wxDataViewTextRenderer and
1965 // wxDataViewCustomRenderer::RenderText(): it applies the attributes to the
1966 // given text renderer and returns true if anything was done
1967 bool GtkApplyAttr(GtkCellRendererText
*renderer
, const wxDataViewItemAttr
& attr
)
1969 bool usingDefaultAttrs
= true;
1970 if (attr
.HasColour())
1972 const GdkColor
* const gcol
= attr
.GetColour().GetColor();
1974 GValue gvalue
= { 0, };
1975 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
1976 g_value_set_boxed( &gvalue
, gcol
);
1977 g_object_set_property( G_OBJECT(renderer
), "foreground_gdk", &gvalue
);
1978 g_value_unset( &gvalue
);
1980 usingDefaultAttrs
= false;
1984 GValue gvalue
= { 0, };
1985 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1986 g_value_set_boolean( &gvalue
, FALSE
);
1987 g_object_set_property( G_OBJECT(renderer
), "foreground-set", &gvalue
);
1988 g_value_unset( &gvalue
);
1991 if (attr
.GetItalic())
1993 GValue gvalue
= { 0, };
1994 g_value_init( &gvalue
, PANGO_TYPE_STYLE
);
1995 g_value_set_enum( &gvalue
, PANGO_STYLE_ITALIC
);
1996 g_object_set_property( G_OBJECT(renderer
), "style", &gvalue
);
1997 g_value_unset( &gvalue
);
1999 usingDefaultAttrs
= false;
2003 GValue gvalue
= { 0, };
2004 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2005 g_value_set_boolean( &gvalue
, FALSE
);
2006 g_object_set_property( G_OBJECT(renderer
), "style-set", &gvalue
);
2007 g_value_unset( &gvalue
);
2013 GValue gvalue
= { 0, };
2014 g_value_init( &gvalue
, PANGO_TYPE_WEIGHT
);
2015 g_value_set_enum( &gvalue
, PANGO_WEIGHT_BOLD
);
2016 g_object_set_property( G_OBJECT(renderer
), "weight", &gvalue
);
2017 g_value_unset( &gvalue
);
2019 usingDefaultAttrs
= false;
2023 GValue gvalue
= { 0, };
2024 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2025 g_value_set_boolean( &gvalue
, FALSE
);
2026 g_object_set_property( G_OBJECT(renderer
), "weight-set", &gvalue
);
2027 g_value_unset( &gvalue
);
2031 if (attr
.HasBackgroundColour())
2033 wxColour colour
= attr
.GetBackgroundColour();
2034 const GdkColor
* const gcol
= colour
.GetColor();
2036 GValue gvalue
= { 0, };
2037 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2038 g_value_set_boxed( &gvalue
, gcol
);
2039 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
2040 g_value_unset( &gvalue
);
2044 GValue gvalue
= { 0, };
2045 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2046 g_value_set_boolean( &gvalue
, FALSE
);
2047 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
2048 g_value_unset( &gvalue
);
2052 return !usingDefaultAttrs
;
2055 } // anonymous namespace
2057 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
2059 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
2061 wxDataViewRenderer( varianttype
, mode
, align
)
2063 GtkWxCellRendererText
*text_renderer
= gtk_wx_cell_renderer_text_new();
2064 text_renderer
->wx_renderer
= this;
2065 m_renderer
= (GtkCellRenderer
*) text_renderer
;
2067 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
2069 GValue gvalue
= { 0, };
2070 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2071 g_value_set_boolean( &gvalue
, true );
2072 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
2073 g_value_unset( &gvalue
);
2075 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2081 SetAlignment(align
);
2084 bool wxDataViewTextRenderer::SetTextValue(const wxString
& str
)
2086 GValue gvalue
= { 0, };
2087 g_value_init( &gvalue
, G_TYPE_STRING
);
2088 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( str
, GetOwner()->GetOwner()->GetFont() ) );
2089 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2090 g_value_unset( &gvalue
);
2095 bool wxDataViewTextRenderer::GetTextValue(wxString
& str
) const
2097 GValue gvalue
= { 0, };
2098 g_value_init( &gvalue
, G_TYPE_STRING
);
2099 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2100 str
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
), const_cast<wxDataViewTextRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
2101 g_value_unset( &gvalue
);
2106 void wxDataViewTextRenderer::SetAlignment( int align
)
2108 wxDataViewRenderer::SetAlignment(align
);
2110 if (gtk_check_version(2,10,0))
2113 // horizontal alignment:
2114 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2115 if (align
& wxALIGN_RIGHT
)
2116 pangoAlign
= PANGO_ALIGN_RIGHT
;
2117 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2118 pangoAlign
= PANGO_ALIGN_CENTER
;
2120 GValue gvalue
= { 0, };
2121 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2122 g_value_set_enum( &gvalue
, pangoAlign
);
2123 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2124 g_value_unset( &gvalue
);
2127 bool wxDataViewTextRenderer::GtkSetAttr(const wxDataViewItemAttr
& attr
)
2129 return GtkApplyAttr(GtkGetTextRenderer(), attr
);
2132 GtkCellRendererText
*wxDataViewTextRenderer::GtkGetTextRenderer() const
2134 return GTK_CELL_RENDERER_TEXT(m_renderer
);
2137 // ---------------------------------------------------------
2138 // wxDataViewBitmapRenderer
2139 // ---------------------------------------------------------
2144 // set "pixbuf" property on the given renderer
2145 void SetPixbufProp(GtkCellRenderer
*renderer
, GdkPixbuf
*pixbuf
)
2147 GValue gvalue
= { 0, };
2148 g_value_init( &gvalue
, G_TYPE_OBJECT
);
2149 g_value_set_object( &gvalue
, pixbuf
);
2150 g_object_set_property( G_OBJECT(renderer
), "pixbuf", &gvalue
);
2151 g_value_unset( &gvalue
);
2154 } // anonymous namespace
2156 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
2158 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
2160 wxDataViewRenderer( varianttype
, mode
, align
)
2162 m_renderer
= gtk_cell_renderer_pixbuf_new();
2165 SetAlignment(align
);
2168 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
2170 if (value
.GetType() == wxT("wxBitmap"))
2175 // GetPixbuf() may create a Pixbuf representation in the wxBitmap
2176 // object (and it will stay there and remain owned by wxBitmap)
2177 SetPixbufProp(m_renderer
, bitmap
.GetPixbuf());
2179 else if (value
.GetType() == wxT("wxIcon"))
2184 SetPixbufProp(m_renderer
, icon
.GetPixbuf());
2194 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2199 // ---------------------------------------------------------
2200 // wxDataViewToggleRenderer
2201 // ---------------------------------------------------------
2204 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
2205 gchar
*path
, gpointer user_data
);
2208 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
2209 gchar
*path
, gpointer user_data
)
2211 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
2214 GValue gvalue
= { 0, };
2215 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2216 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
2217 bool tmp
= g_value_get_boolean( &gvalue
);
2218 g_value_unset( &gvalue
);
2222 wxVariant value
= tmp
;
2223 if (!cell
->Validate( value
))
2226 wxDataViewCtrl
* const ctrl
= cell
->GetOwner()->GetOwner();
2227 wxDataViewModel
*model
= ctrl
->GetModel();
2229 wxDataViewItem
item(ctrl
->GTKPathToItem(wxGtkTreePath(path
)));
2231 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
2233 model
->ChangeValue( value
, item
, model_col
);
2236 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
2238 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
2239 wxDataViewCellMode mode
, int align
) :
2240 wxDataViewRenderer( varianttype
, mode
, align
)
2242 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
2244 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
2246 g_signal_connect_after( m_renderer
, "toggled",
2247 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
2251 GValue gvalue
= { 0, };
2252 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2253 g_value_set_boolean( &gvalue
, false );
2254 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
2255 g_value_unset( &gvalue
);
2259 SetAlignment(align
);
2262 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
2266 GValue gvalue
= { 0, };
2267 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2268 g_value_set_boolean( &gvalue
, tmp
);
2269 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
2270 g_value_unset( &gvalue
);
2275 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
2277 GValue gvalue
= { 0, };
2278 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2279 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
2280 bool tmp
= g_value_get_boolean( &gvalue
);
2281 g_value_unset( &gvalue
);
2288 // ---------------------------------------------------------
2289 // wxDataViewCustomRenderer
2290 // ---------------------------------------------------------
2292 class wxDataViewCtrlDCImpl
: public wxWindowDCImpl
2295 wxDataViewCtrlDCImpl( wxDC
*owner
, wxDataViewCtrl
*window
) :
2296 wxWindowDCImpl( owner
)
2298 GtkWidget
*widget
= window
->m_treeview
;
2304 m_context
= window
->GTKGetPangoDefaultContext();
2305 m_layout
= pango_layout_new( m_context
);
2306 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
2308 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
2310 // Set m_gdkwindow later
2315 class wxDataViewCtrlDC
: public wxWindowDC
2318 wxDataViewCtrlDC( wxDataViewCtrl
*window
) :
2319 wxWindowDC( new wxDataViewCtrlDCImpl( this, window
) )
2324 // ---------------------------------------------------------
2325 // wxDataViewCustomRenderer
2326 // ---------------------------------------------------------
2328 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
2330 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
2331 wxDataViewCellMode mode
,
2334 : wxDataViewCustomRendererBase( varianttype
, mode
, align
)
2337 m_text_renderer
= NULL
;
2345 GtkCellRendererText
*wxDataViewCustomRenderer::GtkGetTextRenderer() const
2347 if ( !m_text_renderer
)
2349 // we create it on demand so need to do it even from a const function
2350 const_cast<wxDataViewCustomRenderer
*>(this)->
2351 m_text_renderer
= GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new());
2354 return m_text_renderer
;
2357 void wxDataViewCustomRenderer::RenderText( const wxString
&text
,
2361 int WXUNUSED(state
) )
2364 GtkCellRendererText
* const textRenderer
= GtkGetTextRenderer();
2366 GValue gvalue
= { 0, };
2367 g_value_init( &gvalue
, G_TYPE_STRING
);
2368 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( text
, GetOwner()->GetOwner()->GetFont() ) );
2369 g_object_set_property( G_OBJECT(textRenderer
), "text", &gvalue
);
2370 g_value_unset( &gvalue
);
2372 GtkApplyAttr(textRenderer
, GetAttr());
2374 GdkRectangle cell_area
;
2375 wxRectToGDKRect(cell
, cell_area
);
2376 cell_area
.x
+= xoffset
;
2377 cell_area
.width
-= xoffset
;
2379 gtk_cell_renderer_render( GTK_CELL_RENDERER(textRenderer
),
2380 m_renderParams
.window
,
2381 m_renderParams
.widget
,
2382 m_renderParams
.background_area
,
2384 m_renderParams
.expose_area
,
2385 (GtkCellRendererState
) m_renderParams
.flags
);
2388 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
2390 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
2391 renderer
->cell
= this;
2393 m_renderer
= (GtkCellRenderer
*) renderer
;
2396 SetAlignment(align
);
2403 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
2408 if (m_text_renderer
)
2409 gtk_object_sink( GTK_OBJECT(m_text_renderer
) );
2412 wxDC
*wxDataViewCustomRenderer::GetDC()
2416 if (GetOwner() == NULL
)
2418 if (GetOwner()->GetOwner() == NULL
)
2420 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
2426 // ---------------------------------------------------------
2427 // wxDataViewProgressRenderer
2428 // ---------------------------------------------------------
2430 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
2432 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
2433 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
2434 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
2440 if (!gtk_check_version(2,6,0))
2442 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
2444 GValue gvalue
= { 0, };
2445 g_value_init( &gvalue
, G_TYPE_STRING
);
2447 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( m_label
, GetOwner()->GetOwner()->GetFont() ) );
2448 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2449 g_value_unset( &gvalue
);
2452 SetAlignment(align
);
2457 // Use custom cell code
2458 wxDataViewCustomRenderer::Init(mode
, align
);
2462 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
2466 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
2469 if (!gtk_check_version(2,6,0))
2471 gint tmp
= (long) value
;
2472 GValue gvalue
= { 0, };
2473 g_value_init( &gvalue
, G_TYPE_INT
);
2474 g_value_set_int( &gvalue
, tmp
);
2475 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
2476 g_value_unset( &gvalue
);
2481 m_value
= (long) value
;
2483 if (m_value
< 0) m_value
= 0;
2484 if (m_value
> 100) m_value
= 100;
2490 bool wxDataViewProgressRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2495 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
2497 double pct
= (double)m_value
/ 100.0;
2499 bar
.width
= (int)(cell
.width
* pct
);
2500 dc
->SetPen( *wxTRANSPARENT_PEN
);
2501 dc
->SetBrush( *wxBLUE_BRUSH
);
2502 dc
->DrawRectangle( bar
);
2504 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
2505 dc
->SetPen( *wxBLACK_PEN
);
2506 dc
->DrawRectangle( cell
);
2511 wxSize
wxDataViewProgressRenderer::GetSize() const
2513 return wxSize(40,12);
2516 // -------------------------------------
2517 // wxDataViewChoiceRenderer
2518 // -------------------------------------
2520 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
&choices
,
2521 wxDataViewCellMode mode
, int alignment
) :
2522 wxDataViewCustomRenderer( "string", mode
, alignment
, true )
2524 m_choices
= choices
;
2527 if (!gtk_check_version(2,6,0))
2529 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_combo_new();
2531 GtkListStore
*store
= gtk_list_store_new( 1, G_TYPE_STRING
);
2532 for (size_t n
= 0; n
< m_choices
.GetCount(); n
++)
2534 gtk_list_store_insert_with_values(
2536 static_cast<const char *>(m_choices
[n
].utf8_str()), -1 );
2539 g_object_set (m_renderer
,
2545 bool editable
= (mode
& wxDATAVIEW_CELL_EDITABLE
);
2546 g_object_set (m_renderer
, "editable", editable
, NULL
);
2548 SetAlignment(alignment
);
2550 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2557 // Use custom cell code
2558 wxDataViewCustomRenderer::Init(mode
, alignment
);
2562 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
2564 RenderText( m_data
, 0, rect
, dc
, state
);
2568 wxSize
wxDataViewChoiceRenderer::GetSize() const
2570 return wxSize(70,20);
2573 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
2577 if (!gtk_check_version(2,6,0))
2579 GValue gvalue
= { 0, };
2580 g_value_init( &gvalue
, G_TYPE_STRING
);
2581 g_value_set_string(&gvalue
,
2582 wxGTK_CONV_FONT(value
.GetString(),
2583 GetOwner()->GetOwner()->GetFont()));
2584 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2585 g_value_unset( &gvalue
);
2589 m_data
= value
.GetString();
2594 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
2597 if (!gtk_check_version(2,6,0))
2599 GValue gvalue
= { 0, };
2600 g_value_init( &gvalue
, G_TYPE_STRING
);
2601 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2602 wxString temp
= wxGTK_CONV_BACK_FONT(g_value_get_string(&gvalue
),
2603 GetOwner()->GetOwner()->GetFont());
2604 g_value_unset( &gvalue
);
2607 //wxPrintf( "temp %s\n", temp );
2608 // TODO: remove this code
2617 void wxDataViewChoiceRenderer::SetAlignment( int align
)
2619 wxDataViewCustomRenderer::SetAlignment(align
);
2621 if (gtk_check_version(2,10,0))
2624 // horizontal alignment:
2625 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2626 if (align
& wxALIGN_RIGHT
)
2627 pangoAlign
= PANGO_ALIGN_RIGHT
;
2628 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2629 pangoAlign
= PANGO_ALIGN_CENTER
;
2631 GValue gvalue
= { 0, };
2632 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2633 g_value_set_enum( &gvalue
, pangoAlign
);
2634 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2635 g_value_unset( &gvalue
);
2638 // ----------------------------------------------------------------------------
2639 // wxDataViewChoiceByIndexRenderer
2640 // ----------------------------------------------------------------------------
2642 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
2643 wxDataViewCellMode mode
, int alignment
) :
2644 wxDataViewChoiceRenderer( choices
, mode
, alignment
)
2648 void wxDataViewChoiceByIndexRenderer::GtkOnTextEdited(const gchar
*itempath
, const wxString
& str
)
2650 wxVariant
value( (long) GetChoices().Index( str
) );
2652 if (!Validate( value
))
2656 item(GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(itempath
)));
2658 GtkOnCellChanged(value
, item
, GetOwner()->GetModelColumn());
2661 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant
&value
)
2663 wxVariant string_value
= GetChoice( value
.GetLong() );
2664 return wxDataViewChoiceRenderer::SetValue( string_value
);
2667 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant
&value
) const
2669 wxVariant string_value
;
2670 if (!wxDataViewChoiceRenderer::GetValue( string_value
))
2673 value
= (long) GetChoices().Index( string_value
.GetString() );
2677 // ---------------------------------------------------------
2678 // wxDataViewDateRenderer
2679 // ---------------------------------------------------------
2681 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
2684 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
2685 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
2686 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
2691 m_cal
= new wxCalendarCtrl( this, -1, *value
);
2692 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
2693 sizer
->Add( m_cal
, 1, wxGROW
);
2698 virtual void OnDismiss()
2702 void OnCalendar( wxCalendarEvent
&event
);
2704 wxCalendarCtrl
*m_cal
;
2705 wxDataViewModel
*m_model
;
2706 wxDataViewItem m_item
;
2710 DECLARE_EVENT_TABLE()
2713 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
2714 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
2717 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
2719 m_model
->ChangeValue( event
.GetDate(), m_item
, m_col
);
2723 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
2725 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
2726 wxDataViewCellMode mode
, int align
) :
2727 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2730 SetAlignment(align
);
2733 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
2735 m_date
= value
.GetDateTime();
2740 bool wxDataViewDateRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2745 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2747 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
2748 wxString tmp
= m_date
.FormatDate();
2749 RenderText( tmp
, 0, cell
, dc
, state
);
2753 wxSize
wxDataViewDateRenderer::GetSize() const
2755 wxString tmp
= m_date
.FormatDate();
2757 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
2758 return wxSize(x
,y
+d
);
2761 bool wxDataViewDateRenderer::Activate( const wxRect
& WXUNUSED(cell
), wxDataViewModel
*model
,
2762 const wxDataViewItem
&item
, unsigned int col
)
2765 model
->GetValue( variant
, item
, col
);
2766 wxDateTime value
= variant
.GetDateTime();
2768 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
2769 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
2770 wxPoint pos
= wxGetMousePosition();
2773 popup
->Popup( popup
->m_cal
);
2779 // ---------------------------------------------------------
2780 // wxDataViewIconTextRenderer
2781 // ---------------------------------------------------------
2783 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
2785 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer
2787 const wxString
&varianttype
,
2788 wxDataViewCellMode mode
,
2791 : wxDataViewTextRenderer(varianttype
, mode
, align
)
2793 m_rendererIcon
= gtk_cell_renderer_pixbuf_new();
2796 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2800 void wxDataViewIconTextRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
2802 // add the icon renderer first
2803 gtk_tree_view_column_pack_start(column
, m_rendererIcon
, FALSE
/* !expand */);
2805 // add the text renderer too
2806 wxDataViewRenderer::GtkPackIntoColumn(column
);
2809 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
2813 SetTextValue(m_value
.GetText());
2814 SetPixbufProp(m_rendererIcon
, m_value
.GetIcon().GetPixbuf());
2819 bool wxDataViewIconTextRenderer::GetValue(wxVariant
& value
) const
2822 if ( !GetTextValue(str
) )
2825 // user doesn't have any way to edit the icon so leave it unchanged
2826 value
<< wxDataViewIconText(str
, m_value
.GetIcon());
2832 wxDataViewIconTextRenderer::GtkOnCellChanged(const wxVariant
& value
,
2833 const wxDataViewItem
& item
,
2836 // we receive just the text part of our value as it's the only one which
2837 // can be edited, but we need the full wxDataViewIconText value for the
2839 wxVariant valueIconText
;
2840 valueIconText
<< wxDataViewIconText(value
.GetString(), m_value
.GetIcon());
2841 wxDataViewTextRenderer::GtkOnCellChanged(valueIconText
, item
, col
);
2844 // ---------------------------------------------------------
2846 // ---------------------------------------------------------
2850 gtk_dataview_header_button_press_callback( GtkWidget
*WXUNUSED(widget
),
2851 GdkEventButton
*gdk_event
,
2852 wxDataViewColumn
*column
)
2854 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
2857 if (gdk_event
->button
== 1)
2859 gs_lastLeftClickHeader
= column
;
2861 wxDataViewCtrl
*dv
= column
->GetOwner();
2862 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
2863 event
.SetDataViewColumn( column
);
2864 event
.SetModel( dv
->GetModel() );
2865 if (dv
->HandleWindowEvent( event
))
2869 if (gdk_event
->button
== 3)
2871 wxDataViewCtrl
*dv
= column
->GetOwner();
2872 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
2873 event
.SetDataViewColumn( column
);
2874 event
.SetModel( dv
->GetModel() );
2875 if (dv
->HandleWindowEvent( event
))
2885 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*WXUNUSED(column
),
2886 GtkCellRenderer
*renderer
,
2887 GtkTreeModel
*model
,
2891 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2892 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2894 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2896 wxDataViewItem
item( (void*) iter
->user_data
);
2898 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
2900 if (!wx_model
->IsVirtualListModel())
2903 if (wx_model
->IsContainer( item
))
2905 visible
= wx_model
->HasContainerColumns( item
) ||
2906 (cell
->GetOwner()->GetModelColumn() == 0);
2913 GValue gvalue
= { 0, };
2914 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2915 g_value_set_boolean( &gvalue
, visible
);
2916 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2917 g_value_unset( &gvalue
);
2924 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
2926 if (value
.GetType() != cell
->GetVariantType())
2928 wxLogError( wxT("Wrong type, required: %s but: %s"),
2929 value
.GetType().c_str(),
2930 cell
->GetVariantType().c_str() );
2933 cell
->SetValue( value
);
2935 // deal with disabled items
2936 bool enabled
= wx_model
->IsEnabled( item
, cell
->GetOwner()->GetModelColumn() );
2938 // a) this sets the appearance to disabled grey
2939 GValue gvalue
= { 0, };
2940 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2941 g_value_set_boolean( &gvalue
, enabled
);
2942 g_object_set_property( G_OBJECT(renderer
), "sensitive", &gvalue
);
2943 g_value_unset( &gvalue
);
2945 // b) this actually disables the control/renderer
2947 cell
->SetMode( cell
->GtkGetMode() );
2949 cell
->SetMode( wxDATAVIEW_CELL_INERT
);
2952 // deal with attributes: if the renderer doesn't support them at all, we
2953 // don't even need to query the model for them
2954 if ( !cell
->GtkSupportsAttrs() )
2957 // it can support attributes so check if this item has any
2958 wxDataViewItemAttr attr
;
2959 if ( wx_model
->GetAttr( item
, cell
->GetOwner()->GetModelColumn(), attr
)
2960 || !cell
->GtkIsUsingDefaultAttrs() )
2962 bool usingDefaultAttrs
= !cell
->GtkSetAttr(attr
);
2963 cell
->GtkSetUsingDefaultAttrs(usingDefaultAttrs
);
2965 // else: no custom attributes specified and we're already using the default
2966 // ones -- nothing to do
2972 #include <wx/listimpl.cpp>
2973 WX_DEFINE_LIST(wxDataViewColumnList
)
2975 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
2976 unsigned int model_column
, int width
,
2977 wxAlignment align
, int flags
)
2978 : wxDataViewColumnBase( cell
, model_column
)
2980 Init( align
, flags
, width
);
2985 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
2986 unsigned int model_column
, int width
,
2987 wxAlignment align
, int flags
)
2988 : wxDataViewColumnBase( bitmap
, cell
, model_column
)
2990 Init( align
, flags
, width
);
2992 SetBitmap( bitmap
);
2995 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
2997 m_isConnected
= false;
2999 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
3000 m_column
= (GtkWidget
*) column
;
3003 SetAlignment( align
);
3007 // Create container for icon and label
3008 GtkWidget
*box
= gtk_hbox_new( FALSE
, 1 );
3009 gtk_widget_show( box
);
3010 // gtk_container_set_border_width((GtkContainer*)box, 2);
3011 m_image
= gtk_image_new();
3012 gtk_box_pack_start(GTK_BOX(box
), m_image
, FALSE
, FALSE
, 1);
3013 m_label
= gtk_label_new("");
3014 gtk_box_pack_end( GTK_BOX(box
), GTK_WIDGET(m_label
), FALSE
, FALSE
, 1 );
3015 gtk_tree_view_column_set_widget( column
, box
);
3017 wxDataViewRenderer
* const colRenderer
= GetRenderer();
3018 GtkCellRenderer
* const cellRenderer
= colRenderer
->GetGtkHandle();
3020 colRenderer
->GtkPackIntoColumn(column
);
3022 gtk_tree_view_column_set_cell_data_func( column
, cellRenderer
,
3023 wxGtkTreeCellDataFunc
, (gpointer
) colRenderer
, NULL
);
3026 void wxDataViewColumn::OnInternalIdle()
3031 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
3033 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3036 g_signal_connect(column
->button
, "button_press_event",
3037 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
3039 // otherwise the event will be blocked by GTK+
3040 gtk_tree_view_column_set_clickable( column
, TRUE
);
3042 m_isConnected
= true;
3047 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
3049 wxDataViewColumnBase::SetOwner( owner
);
3051 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3053 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
3056 void wxDataViewColumn::SetTitle( const wxString
&title
)
3058 wxDataViewCtrl
*ctrl
= GetOwner();
3059 gtk_label_set_text( GTK_LABEL(m_label
), ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
3060 : wxGTK_CONV_SYS(title
) );
3062 gtk_widget_hide( m_label
);
3064 gtk_widget_show( m_label
);
3067 wxString
wxDataViewColumn::GetTitle() const
3069 return wxGTK_CONV_BACK_FONT(
3070 gtk_label_get_text( GTK_LABEL(m_label
) ),
3071 GetOwner()->GetFont()
3075 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
3077 wxDataViewColumnBase::SetBitmap( bitmap
);
3081 GtkImage
*gtk_image
= GTK_IMAGE(m_image
);
3083 GdkBitmap
*mask
= NULL
;
3084 if (bitmap
.GetMask())
3085 mask
= bitmap
.GetMask()->GetBitmap();
3087 if (bitmap
.HasPixbuf())
3089 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
3090 bitmap
.GetPixbuf());
3094 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
3095 bitmap
.GetPixmap(), mask
);
3097 gtk_widget_show( m_image
);
3101 gtk_widget_hide( m_image
);
3105 void wxDataViewColumn::SetHidden( bool hidden
)
3107 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
3110 void wxDataViewColumn::SetResizeable( bool resizeable
)
3112 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizeable
);
3115 void wxDataViewColumn::SetAlignment( wxAlignment align
)
3117 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3119 gfloat xalign
= 0.0;
3120 if (align
== wxALIGN_RIGHT
)
3122 if (align
== wxALIGN_CENTER_HORIZONTAL
||
3123 align
== wxALIGN_CENTER
)
3126 gtk_tree_view_column_set_alignment( column
, xalign
);
3128 if (m_renderer
&& m_renderer
->GetAlignment() == -1)
3129 m_renderer
->GtkUpdateAlignment();
3132 wxAlignment
wxDataViewColumn::GetAlignment() const
3134 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
3137 return wxALIGN_RIGHT
;
3139 return wxALIGN_CENTER_HORIZONTAL
;
3141 return wxALIGN_LEFT
;
3144 void wxDataViewColumn::SetSortable( bool sortable
)
3146 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3150 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
3154 gtk_tree_view_column_set_sort_column_id( column
, -1 );
3155 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
3156 gtk_tree_view_column_set_clickable( column
, FALSE
);
3160 bool wxDataViewColumn::IsSortable() const
3162 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3163 return gtk_tree_view_column_get_clickable( column
);
3166 void wxDataViewColumn::SetAsSortKey( bool WXUNUSED(sort
) )
3168 // it might not make sense to have this function in wxHeaderColumn at
3169 // all in fact, changing of the sort order should only be done using the
3170 // associated control API
3171 wxFAIL_MSG( "not implemented" );
3174 bool wxDataViewColumn::IsSortKey() const
3176 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3177 return gtk_tree_view_column_get_sort_indicator( column
);
3180 bool wxDataViewColumn::IsResizeable() const
3182 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3183 return gtk_tree_view_column_get_resizable( column
);
3186 bool wxDataViewColumn::IsHidden() const
3188 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3189 return !gtk_tree_view_column_get_visible( column
);
3192 void wxDataViewColumn::SetSortOrder( bool ascending
)
3194 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3197 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
3199 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
3201 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
3204 bool wxDataViewColumn::IsSortOrderAscending() const
3206 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3208 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
3211 void wxDataViewColumn::SetMinWidth( int width
)
3213 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
3216 int wxDataViewColumn::GetMinWidth() const
3218 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
3221 int wxDataViewColumn::GetWidth() const
3223 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
3226 void wxDataViewColumn::SetWidth( int width
)
3228 if ( width
== wxCOL_WIDTH_AUTOSIZE
)
3230 // NB: this disables user resizing
3231 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
3235 if ( width
== wxCOL_WIDTH_DEFAULT
)
3237 // TODO find a better calculation
3238 width
= wxDVC_DEFAULT_WIDTH
;
3241 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
3242 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
3246 void wxDataViewColumn::SetReorderable( bool reorderable
)
3248 gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column
), reorderable
);
3251 bool wxDataViewColumn::IsReorderable() const
3253 return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column
) );
3256 //-----------------------------------------------------------------------------
3257 // wxGtkTreeModelNode
3258 //-----------------------------------------------------------------------------
3261 class wxGtkTreeModelChildWithPos
3269 int wxGtkTreeModelChildWithPosCmp( const void* data1
, const void* data2
, const void* user_data
)
3271 const wxGtkTreeModelChildWithPos
* child1
= (const wxGtkTreeModelChildWithPos
*) data1
;
3272 const wxGtkTreeModelChildWithPos
* child2
= (const wxGtkTreeModelChildWithPos
*) data2
;
3273 const wxDataViewCtrlInternal
*internal
= (const wxDataViewCtrlInternal
*) user_data
;
3274 int ret
= internal
->GetDataViewModel()->Compare( child1
->id
, child2
->id
,
3275 internal
->GetSortColumn(), (internal
->GetSortOrder() == GTK_SORT_DESCENDING
) );
3281 int LINKAGEMODE
wxGtkTreeModelChildPtrCmp( void*** data1
, void*** data2
)
3283 return gs_internal
->GetDataViewModel()->Compare( **data1
, **data2
,
3284 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
3287 WX_DEFINE_ARRAY_PTR( void**, wxGtkTreeModelChildrenPtr
);
3290 void wxGtkTreeModelNode::Resort()
3292 size_t child_count
= GetChildCount();
3293 if (child_count
== 0)
3296 size_t node_count
= GetNodesCount();
3298 if (child_count
== 1)
3300 if (node_count
== 1)
3302 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
3308 gint
*new_order
= new gint
[child_count
];
3311 // m_children has the original *void
3312 // ptrs points to these
3313 wxGtkTreeModelChildrenPtr ptrs
;
3315 for (i
= 0; i
< child_count
; i
++)
3316 ptrs
.Add( &(m_children
[i
]) );
3318 gs_internal
= m_internal
;
3319 ptrs
.Sort( &wxGtkTreeModelChildPtrCmp
);
3321 wxGtkTreeModelChildren temp
;
3322 void** base_ptr
= &(m_children
[0]);
3323 // Transfer positions to new_order array and
3325 for (i
= 0; i
< child_count
; i
++)
3327 new_order
[i
] = ptrs
[i
] - base_ptr
;
3328 temp
.Add( *ptrs
[i
] );
3331 // Transfer IDs back to m_children
3333 WX_APPEND_ARRAY( temp
, m_children
);
3338 // Build up array with IDs and original positions
3339 wxGtkTreeModelChildWithPos
* temp
= new wxGtkTreeModelChildWithPos
[child_count
];
3341 for (i
= 0; i
< child_count
; i
++)
3344 temp
[i
].id
= m_children
[i
];
3346 // Sort array keeping original positions
3347 wxQsort( temp
, child_count
, sizeof(wxGtkTreeModelChildWithPos
),
3348 &wxGtkTreeModelChildWithPosCmp
, m_internal
);
3349 // Transfer positions to new_order array and
3350 // IDs to m_children
3352 for (i
= 0; i
< child_count
; i
++)
3354 new_order
[i
] = temp
[i
].pos
;
3355 m_children
.Add( temp
[i
].id
);
3364 wxGtkTreeModelChildren temp
;
3365 WX_APPEND_ARRAY( temp
, m_children
);
3367 gs_internal
= m_internal
;
3368 m_children
.Sort( &wxGtkTreeModelChildCmp
);
3371 for (pos
= 0; pos
< child_count
; pos
++)
3373 void *id
= m_children
.Item( pos
);
3374 int old_pos
= temp
.Index( id
);
3375 new_order
[pos
] = old_pos
;
3379 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
3382 iter
.user_data
= GetItem().GetID();
3383 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
3385 gtk_tree_model_rows_reordered( gtk_tree_model
,
3386 wxGtkTreePath(m_internal
->get_path(&iter
)), &iter
, new_order
);
3388 delete [] new_order
;
3391 for (pos
= 0; pos
< node_count
; pos
++)
3393 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
3398 //-----------------------------------------------------------------------------
3399 // wxDataViewCtrlInternal
3400 //-----------------------------------------------------------------------------
3402 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
)
3405 m_wx_model
= wx_model
;
3409 m_sort_order
= GTK_SORT_ASCENDING
;
3411 m_dataview_sort_column
= NULL
;
3413 m_dragDataObject
= NULL
;
3414 m_dropDataObject
= NULL
;
3418 m_gtk_model
= wxgtk_tree_model_new();
3419 m_gtk_model
->internal
= this;
3421 m_notifier
= new wxGtkDataViewModelNotifier( wx_model
, this );
3423 wx_model
->AddNotifier( m_notifier
);
3425 // g_object_unref( gtk_model ); ???
3427 if (!m_wx_model
->IsVirtualListModel())
3430 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->GtkGetTreeView()), GTK_TREE_MODEL(m_gtk_model
) );
3433 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
3435 m_wx_model
->RemoveNotifier( m_notifier
);
3437 // remove the model from the GtkTreeView before it gets destroyed
3438 gtk_tree_view_set_model( GTK_TREE_VIEW( m_owner
->GtkGetTreeView() ), NULL
);
3440 g_object_unref( m_gtk_model
);
3442 delete m_dragDataObject
;
3443 delete m_dropDataObject
;
3446 void wxDataViewCtrlInternal::ScheduleRefresh()
3451 void wxDataViewCtrlInternal::OnInternalIdle()
3455 GtkWidget
*widget
= m_owner
->GtkGetTreeView();
3456 gtk_widget_queue_draw( widget
);
3461 void wxDataViewCtrlInternal::InitTree()
3463 wxDataViewItem item
;
3464 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
3466 BuildBranch( m_root
);
3469 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
3471 if (node
->GetChildCount() == 0)
3473 wxDataViewItemArray children
;
3474 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
3477 for (pos
= 0; pos
< count
; pos
++)
3479 wxDataViewItem child
= children
[pos
];
3481 if (m_wx_model
->IsContainer( child
))
3482 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
3484 node
->AddLeave( child
.GetID() );
3486 // Don't send any events here
3493 bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat
&format
)
3495 wxGtkString
atom_str( gdk_atom_name( format
) );
3496 m_dragSourceTargetEntryTarget
= wxCharBuffer( atom_str
);
3498 m_dragSourceTargetEntry
.target
= m_dragSourceTargetEntryTarget
.data();
3499 m_dragSourceTargetEntry
.flags
= 0;
3500 m_dragSourceTargetEntry
.info
= static_cast<guint
>(-1);
3502 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3503 GDK_BUTTON1_MASK
, &m_dragSourceTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3508 bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat
&format
)
3510 wxGtkString
atom_str( gdk_atom_name( format
) );
3511 m_dropTargetTargetEntryTarget
= wxCharBuffer( atom_str
);
3513 m_dropTargetTargetEntry
.target
= m_dropTargetTargetEntryTarget
.data();
3514 m_dropTargetTargetEntry
.flags
= 0;
3515 m_dropTargetTargetEntry
.info
= static_cast<guint
>(-1);
3517 gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3518 &m_dropTargetTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3523 gboolean
wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource
*WXUNUSED(drag_source
),
3526 delete m_dragDataObject
;
3528 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3532 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3533 event
.SetEventObject( m_owner
);
3534 event
.SetItem( item
);
3535 event
.SetModel( m_wx_model
);
3537 gtk_widget_get_pointer(m_owner
->GtkGetTreeView(), &x
, &y
);
3538 event
.SetPosition(x
, y
);
3539 if (!m_owner
->HandleWindowEvent( event
))
3542 if (!event
.IsAllowed())
3545 wxDataObject
*obj
= event
.GetDataObject();
3549 m_dragDataObject
= obj
;
3555 wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource
*WXUNUSED(drag_source
),
3556 GtkTreePath
*WXUNUSED(path
))
3561 gboolean
wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource
*WXUNUSED(drag_source
),
3562 GtkTreePath
*path
, GtkSelectionData
*selection_data
)
3564 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3568 if (!m_dragDataObject
->IsSupported( selection_data
->target
))
3571 size_t size
= m_dragDataObject
->GetDataSize( selection_data
->target
);
3575 void *buf
= malloc( size
);
3577 gboolean res
= FALSE
;
3578 if (m_dragDataObject
->GetDataHere( selection_data
->target
, buf
))
3582 gtk_selection_data_set( selection_data
, selection_data
->target
,
3583 8, (const guchar
*) buf
, size
);
3592 wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3594 GtkSelectionData
*selection_data
)
3596 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3600 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
3601 event
.SetEventObject( m_owner
);
3602 event
.SetItem( item
);
3603 event
.SetModel( m_wx_model
);
3604 event
.SetDataFormat( selection_data
->target
);
3605 event
.SetDataSize( selection_data
->length
);
3606 event
.SetDataBuffer( selection_data
->data
);
3607 if (!m_owner
->HandleWindowEvent( event
))
3610 if (!event
.IsAllowed())
3617 wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3619 GtkSelectionData
*selection_data
)
3621 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3625 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
3626 event
.SetEventObject( m_owner
);
3627 event
.SetItem( item
);
3628 event
.SetModel( m_wx_model
);
3629 event
.SetDataFormat( selection_data
->target
);
3630 if (!m_owner
->HandleWindowEvent( event
))
3633 if (!event
.IsAllowed())
3639 // notifications from wxDataViewModel
3641 bool wxDataViewCtrlInternal::Cleared()
3656 void wxDataViewCtrlInternal::Resort()
3658 if (!m_wx_model
->IsVirtualListModel())
3664 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3666 if (!m_wx_model
->IsVirtualListModel())
3668 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3669 wxASSERT_MSG(parent_node
,
3670 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3672 if (m_wx_model
->IsContainer( item
))
3673 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
3675 parent_node
->AddLeave( item
.GetID() );
3683 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3685 if (!m_wx_model
->IsVirtualListModel())
3687 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3688 wxASSERT_MSG(parent_node
,
3689 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3691 parent_node
->DeleteChild( item
.GetID() );
3699 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
3701 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3702 event
.SetEventObject( m_owner
);
3703 event
.SetModel( m_owner
->GetModel() );
3704 event
.SetItem( item
);
3705 m_owner
->HandleWindowEvent( event
);
3710 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int view_column
)
3712 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3713 event
.SetEventObject( m_owner
);
3714 event
.SetModel( m_owner
->GetModel() );
3715 event
.SetColumn( view_column
);
3716 event
.SetDataViewColumn( GetOwner()->GetColumn(view_column
) );
3717 event
.SetItem( item
);
3718 m_owner
->HandleWindowEvent( event
);
3725 GtkTreeModelFlags
wxDataViewCtrlInternal::get_flags()
3729 if ( m_wx_model
->IsListModel() )
3730 flags
|= GTK_TREE_MODEL_LIST_ONLY
;
3732 if ( !m_wx_model
->IsVirtualListModel() )
3733 flags
|= GTK_TREE_MODEL_ITERS_PERSIST
;
3735 return GtkTreeModelFlags(flags
);
3738 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
3741 if (m_wx_model
->IsVirtualListModel())
3743 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3745 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
3747 if (i
>= wx_model
->GetCount())
3750 iter
->stamp
= m_gtk_model
->stamp
;
3751 // user_data is just the index +1
3752 iter
->user_data
= (gpointer
) (i
+1);
3758 int depth
= gtk_tree_path_get_depth( path
);
3760 wxGtkTreeModelNode
*node
= m_root
;
3763 for (i
= 0; i
< depth
; i
++)
3765 BuildBranch( node
);
3767 gint pos
= gtk_tree_path_get_indices (path
)[i
];
3768 if (pos
< 0) return FALSE
;
3769 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
3771 void* id
= node
->GetChildren().Item( (size_t) pos
);
3775 iter
->stamp
= m_gtk_model
->stamp
;
3776 iter
->user_data
= id
;
3780 size_t count
= node
->GetNodes().GetCount();
3782 for (pos2
= 0; pos2
< count
; pos2
++)
3784 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
3785 if (child_node
->GetItem().GetID() == id
)
3797 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
3799 // When this is called from ItemDeleted(), the item is already
3800 // deleted in the model.
3802 GtkTreePath
*retval
= gtk_tree_path_new ();
3804 if (m_wx_model
->IsVirtualListModel())
3806 // iter is root, add nothing
3807 if (!iter
->user_data
)
3810 // user_data is just the index +1
3811 int i
= ( (wxUIntPtr
) iter
->user_data
) -1;
3812 gtk_tree_path_append_index (retval
, i
);
3816 void *id
= iter
->user_data
;
3818 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
3821 int pos
= node
->GetChildren().Index( id
);
3823 gtk_tree_path_prepend_index( retval
, pos
);
3825 id
= node
->GetItem().GetID();
3826 node
= node
->GetParent();
3833 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
3835 if (m_wx_model
->IsVirtualListModel())
3837 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3839 // user_data is just the index +1
3840 int n
= ( (wxUIntPtr
) iter
->user_data
) -1;
3844 iter
->user_data
= NULL
;
3848 if (n
>= (int) wx_model
->GetCount()-1)
3850 iter
->user_data
= NULL
;
3854 // user_data is just the index +1 (+2 because we need the next)
3855 iter
->user_data
= (gpointer
) (n
+2);
3859 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
3860 if( parent
== NULL
)
3862 iter
->user_data
= NULL
;
3866 int pos
= parent
->GetChildren().Index( iter
->user_data
);
3868 if (pos
== (int) parent
->GetChildCount()-1)
3870 iter
->user_data
= NULL
;
3874 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
3880 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
3882 if (m_wx_model
->IsVirtualListModel())
3884 // this is a list, nodes have no children
3888 iter
->stamp
= m_gtk_model
->stamp
;
3889 iter
->user_data
= (gpointer
) 1;
3897 if (m_root
->GetChildCount() == 0) return FALSE
;
3898 iter
->stamp
= m_gtk_model
->stamp
;
3899 iter
->user_data
= (gpointer
) m_root
->GetChildren().Item( 0 );
3904 wxDataViewItem item
;
3906 item
= wxDataViewItem( (void*) parent
->user_data
);
3908 if (!m_wx_model
->IsContainer( item
))
3911 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3912 wxASSERT_MSG(parent_node
,
3913 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3915 BuildBranch( parent_node
);
3917 if (parent_node
->GetChildCount() == 0)
3920 iter
->stamp
= m_gtk_model
->stamp
;
3921 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
3927 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
3929 if (m_wx_model
->IsVirtualListModel())
3931 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3934 return (wx_model
->GetCount() > 0);
3936 // this is a list, nodes have no children
3942 return (m_root
->GetChildCount() > 0);
3944 wxDataViewItem
item( (void*) iter
->user_data
);
3946 bool is_container
= m_wx_model
->IsContainer( item
);
3951 wxGtkTreeModelNode
*node
= FindNode( iter
);
3953 "Did you forget a call to ItemAdded()? The iterator is unknown to the wxGtkTreeModel");
3955 BuildBranch( node
);
3957 return (node
->GetChildCount() > 0);
3961 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
3963 if (m_wx_model
->IsVirtualListModel())
3965 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3968 return (gint
) wx_model
->GetCount();
3975 return m_root
->GetChildCount();
3977 wxDataViewItem
item( (void*) iter
->user_data
);
3979 if (!m_wx_model
->IsContainer( item
))
3982 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
3983 wxASSERT_MSG(parent_node
,
3984 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3986 BuildBranch( parent_node
);
3988 return parent_node
->GetChildCount();
3992 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
3994 if (m_wx_model
->IsVirtualListModel())
3996 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
4004 if (n
>= (gint
) wx_model
->GetCount())
4007 iter
->stamp
= m_gtk_model
->stamp
;
4008 // user_data is just the index +1
4009 iter
->user_data
= (gpointer
) (n
+1);
4016 if (parent
) id
= (void*) parent
->user_data
;
4017 wxDataViewItem
item( id
);
4019 if (!m_wx_model
->IsContainer( item
))
4022 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
4023 wxASSERT_MSG(parent_node
,
4024 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
4026 BuildBranch( parent_node
);
4028 iter
->stamp
= m_gtk_model
->stamp
;
4029 iter
->user_data
= parent_node
->GetChildren().Item( n
);
4035 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
4037 if (m_wx_model
->IsVirtualListModel())
4043 wxGtkTreeModelNode
*node
= FindParentNode( child
);
4047 iter
->stamp
= m_gtk_model
->stamp
;
4048 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
4054 // item can be deleted already in the model
4055 int wxDataViewCtrlInternal::GetIndexOf( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
4057 if (m_wx_model
->IsVirtualListModel())
4059 return wxPtrToUInt(item
.GetID()) - 1;
4063 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
4064 wxGtkTreeModelChildren
&children
= parent_node
->GetChildren();
4066 for (j
= 0; j
< children
.GetCount(); j
++)
4068 if (children
[j
] == item
.GetID())
4076 static wxGtkTreeModelNode
*
4077 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
4083 list
.DeleteContents( true );
4084 wxDataViewItem
it( item
);
4088 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
4089 list
.Insert( pItem
);
4090 it
= model
->GetParent( it
);
4093 wxGtkTreeModelNode
* node
= treeNode
;
4094 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
4096 if( node
&& node
->GetNodes().GetCount() != 0 )
4098 int len
= node
->GetNodes().GetCount();
4099 wxGtkTreeModelNodes
&nodes
= node
->GetNodes();
4101 for( ; j
< len
; j
++)
4103 if( nodes
[j
]->GetItem() == *(n
->GetData()))
4122 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
4127 wxDataViewItem
item( (void*) iter
->user_data
);
4131 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
4136 wxLogDebug( "Not found %p", iter->user_data );
4140 // TODO: remove this code
4146 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
4151 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
4156 wxLogDebug( "Not found %p", item.GetID() );
4160 // TODO: remove this code
4166 static wxGtkTreeModelNode
*
4167 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
4173 list
.DeleteContents( true );
4177 wxDataViewItem
it( model
->GetParent( item
) );
4180 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
4181 list
.Insert( pItem
);
4182 it
= model
->GetParent( it
);
4185 wxGtkTreeModelNode
* node
= treeNode
;
4186 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
4188 if( node
&& node
->GetNodes().GetCount() != 0 )
4190 int len
= node
->GetNodes().GetCount();
4191 wxGtkTreeModelNodes nodes
= node
->GetNodes();
4193 for( ; j
< len
; j
++)
4195 if( nodes
[j
]->GetItem() == *(n
->GetData()))
4210 //Examine whether the node is item's parent node
4211 int len
= node
->GetChildCount();
4212 for( int i
= 0; i
< len
; i
++ )
4214 if( node
->GetChildren().Item( i
) == item
.GetID() )
4220 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
4225 wxDataViewItem
item( (void*) iter
->user_data
);
4229 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
4232 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
4237 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
4240 //-----------------------------------------------------------------------------
4241 // wxDataViewCtrl signal callbacks
4242 //-----------------------------------------------------------------------------
4245 wxdataview_selection_changed_callback( GtkTreeSelection
* WXUNUSED(selection
), wxDataViewCtrl
*dv
)
4247 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
4250 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
4251 event
.SetItem( dv
->GetSelection() );
4252 event
.SetModel( dv
->GetModel() );
4253 dv
->HandleWindowEvent( event
);
4257 wxdataview_row_activated_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreePath
*path
,
4258 GtkTreeViewColumn
*WXUNUSED(column
), wxDataViewCtrl
*dv
)
4260 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
4262 wxDataViewItem
item(dv
->GTKPathToItem(path
));
4263 event
.SetItem( item
);
4264 event
.SetModel( dv
->GetModel() );
4265 dv
->HandleWindowEvent( event
);
4269 wxdataview_test_expand_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4270 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4272 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
4274 wxDataViewItem
item( (void*) iter
->user_data
);;
4275 event
.SetItem( item
);
4276 event
.SetModel( dv
->GetModel() );
4277 dv
->HandleWindowEvent( event
);
4279 return !event
.IsAllowed();
4283 wxdataview_row_expanded_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4284 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4286 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
4288 wxDataViewItem
item( (void*) iter
->user_data
);;
4289 event
.SetItem( item
);
4290 event
.SetModel( dv
->GetModel() );
4291 dv
->HandleWindowEvent( event
);
4295 wxdataview_test_collapse_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4296 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4298 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
4300 wxDataViewItem
item( (void*) iter
->user_data
);;
4301 event
.SetItem( item
);
4302 event
.SetModel( dv
->GetModel() );
4303 dv
->HandleWindowEvent( event
);
4305 return !event
.IsAllowed();
4309 wxdataview_row_collapsed_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4310 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4312 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
4314 wxDataViewItem
item( (void*) iter
->user_data
);;
4315 event
.SetItem( item
);
4316 event
.SetModel( dv
->GetModel() );
4317 dv
->HandleWindowEvent( event
);
4320 //-----------------------------------------------------------------------------
4322 //-----------------------------------------------------------------------------
4324 void wxDataViewCtrl::AddChildGTK(wxWindowGTK
* child
)
4326 GtkWidget
* treeview
= GtkGetTreeView();
4328 // Insert widget in GtkTreeView
4329 if (GTK_WIDGET_REALIZED(treeview
))
4330 gtk_widget_set_parent_window( child
->m_widget
,
4331 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
4332 gtk_widget_set_parent( child
->m_widget
, treeview
);
4336 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
4337 GtkAllocation
*WXUNUSED(gtk_alloc
),
4338 wxDataViewCtrl
*win
)
4340 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
4343 wxWindow
*child
= node
->GetData();
4346 gtk_widget_size_request( child
->m_widget
, &req
);
4348 GtkAllocation alloc
;
4349 alloc
.x
= child
->m_x
;
4350 alloc
.y
= child
->m_y
;
4351 alloc
.width
= child
->m_width
;
4352 alloc
.height
= child
->m_height
;
4353 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
4355 node
= node
->GetNext();
4360 //-----------------------------------------------------------------------------
4361 // "motion_notify_event"
4362 //-----------------------------------------------------------------------------
4365 gtk_dataview_motion_notify_callback( GtkWidget
*WXUNUSED(widget
),
4366 GdkEventMotion
*gdk_event
,
4367 wxDataViewCtrl
*dv
)
4369 if (gdk_event
->is_hint
)
4373 GdkModifierType state
;
4374 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
4380 GtkTreeViewColumn
*column
= NULL
;
4383 if (gtk_tree_view_get_path_at_pos(
4384 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4385 (int) gdk_event
->x
, (int) gdk_event
->y
,
4394 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4402 //-----------------------------------------------------------------------------
4403 // "button_press_event"
4404 //-----------------------------------------------------------------------------
4407 gtk_dataview_button_press_callback( GtkWidget
*WXUNUSED(widget
),
4408 GdkEventButton
*gdk_event
,
4409 wxDataViewCtrl
*dv
)
4411 if ((gdk_event
->button
== 3) && (gdk_event
->type
== GDK_BUTTON_PRESS
))
4414 GtkTreeViewColumn
*column
= NULL
;
4417 if (gtk_tree_view_get_path_at_pos(
4418 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4419 (int) gdk_event
->x
, (int) gdk_event
->y
,
4427 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, dv
->GetId() );
4428 event
.SetItem(dv
->GTKPathToItem(path
));
4429 event
.SetModel( dv
->GetModel() );
4430 return dv
->HandleWindowEvent( event
);
4438 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
4440 wxDataViewCtrl::~wxDataViewCtrl()
4447 void wxDataViewCtrl::Init()
4451 m_cols
.DeleteContents( true );
4454 bool wxDataViewCtrl::Create(wxWindow
*parent
,
4459 const wxValidator
& validator
,
4460 const wxString
& name
)
4462 if (!PreCreation( parent
, pos
, size
) ||
4463 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
4465 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
4469 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
4470 g_object_ref(m_widget
);
4472 GTKScrolledWindowSetBorder(m_widget
, style
);
4474 m_treeview
= gtk_tree_view_new();
4475 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
4477 g_signal_connect (m_treeview
, "size_allocate",
4478 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
4481 if (!gtk_check_version(2,6,0))
4483 bool fixed
= (style
& wxDV_VARIABLE_LINE_HEIGHT
) == 0;
4484 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4488 if (style
& wxDV_MULTIPLE
)
4490 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4491 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
4494 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
4497 if (!gtk_check_version(2,10,0))
4499 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
4501 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
4502 (style
& wxDV_VERT_RULES
) != 0)
4503 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
4504 else if (style
& wxDV_VERT_RULES
)
4505 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
4506 else if (style
& wxDV_HORIZ_RULES
)
4507 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
4509 if (grid
!= GTK_TREE_VIEW_GRID_LINES_NONE
)
4510 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
4514 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_ROW_LINES
) != 0 );
4516 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
4517 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
4518 gtk_widget_show (m_treeview
);
4520 m_parent
->DoAddChild( this );
4524 GtkEnableSelectionEvents();
4526 g_signal_connect_after (m_treeview
, "row-activated",
4527 G_CALLBACK (wxdataview_row_activated_callback
), this);
4529 g_signal_connect (m_treeview
, "test-collapse-row",
4530 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
4532 g_signal_connect_after (m_treeview
, "row-collapsed",
4533 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
4535 g_signal_connect (m_treeview
, "test-expand-row",
4536 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
4538 g_signal_connect_after (m_treeview
, "row-expanded",
4539 G_CALLBACK (wxdataview_row_expanded_callback
), this);
4541 g_signal_connect (m_treeview
, "motion_notify_event",
4542 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
4544 g_signal_connect (m_treeview
, "button_press_event",
4545 G_CALLBACK (gtk_dataview_button_press_callback
), this);
4550 wxDataViewItem
wxDataViewCtrl::GTKPathToItem(GtkTreePath
*path
) const
4553 return wxDataViewItem(path
&& m_internal
->get_iter(&iter
, path
)
4558 void wxDataViewCtrl::OnInternalIdle()
4560 wxWindow::OnInternalIdle();
4562 m_internal
->OnInternalIdle();
4564 unsigned int cols
= GetColumnCount();
4566 for (i
= 0; i
< cols
; i
++)
4568 wxDataViewColumn
*col
= GetColumn( i
);
4569 col
->OnInternalIdle();
4572 if (m_ensureVisibleDefered
.IsOk())
4574 ExpandAncestors(m_ensureVisibleDefered
);
4576 iter
.user_data
= (gpointer
) m_ensureVisibleDefered
.GetID();
4577 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4578 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
4579 m_ensureVisibleDefered
= wxDataViewItem(0);
4583 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4585 wxDELETE(m_internal
);
4587 if (!wxDataViewCtrlBase::AssociateModel( model
))
4591 if (!gtk_check_version(2,6,0))
4593 bool fixed
= (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
) == 0) || (model
->IsVirtualListModel()));
4594 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4598 m_internal
= new wxDataViewCtrlInternal( this, model
);
4603 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4605 return m_internal
->EnableDragSource( format
);
4608 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4610 return m_internal
->EnableDropTarget( format
);
4613 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4615 if (!wxDataViewCtrlBase::AppendColumn(col
))
4618 m_cols
.Append( col
);
4621 if (!gtk_check_version(2,6,0))
4623 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4624 GTK_TREE_VIEW_COLUMN_FIXED
)
4625 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4629 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
4630 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4635 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4637 if (!wxDataViewCtrlBase::PrependColumn(col
))
4640 m_cols
.Insert( col
);
4643 if (!gtk_check_version(2,6,0))
4645 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4646 GTK_TREE_VIEW_COLUMN_FIXED
)
4647 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4651 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4652 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
4657 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4659 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4662 m_cols
.Insert( pos
, col
);
4665 if (!gtk_check_version(2,6,0))
4667 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4668 GTK_TREE_VIEW_COLUMN_FIXED
)
4669 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4673 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4674 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), pos
);
4679 unsigned int wxDataViewCtrl::GetColumnCount() const
4681 return m_cols
.GetCount();
4684 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
4686 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
4690 wxDataViewColumnList::const_iterator iter
;
4691 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4693 wxDataViewColumn
*col
= *iter
;
4694 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
4703 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4705 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4706 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
4708 m_cols
.DeleteObject( column
);
4713 bool wxDataViewCtrl::ClearColumns()
4715 wxDataViewColumnList::iterator iter
;
4716 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4718 wxDataViewColumn
*col
= *iter
;
4719 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4720 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4728 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4730 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetConstGtkHandle());
4732 GList
*list
= gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview
) );
4734 gint pos
= g_list_index( list
, (gconstpointer
) gtk_column
);
4736 g_list_free( list
);
4741 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4743 return m_internal
->GetDataViewSortColumn();
4746 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4749 iter
.user_data
= item
.GetID();
4750 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4751 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
4754 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4757 iter
.user_data
= item
.GetID();
4758 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4759 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
4762 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4765 iter
.user_data
= item
.GetID();
4766 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4767 return gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview
), path
);
4770 wxDataViewItem
wxDataViewCtrl::DoGetCurrentItem() const
4772 // The tree doesn't have any current item if it hadn't been created yet but
4773 // it's arguably not an error to call this function in this case so just
4774 // return an invalid item without asserting.
4776 return wxDataViewItem();
4779 gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview
), path
.ByRef(), NULL
);
4781 return GTKPathToItem(path
);
4784 void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem
& item
)
4786 wxCHECK_RET( m_treeview
,
4787 "Current item can't be set before creating the control." );
4789 // We need to make sure the model knows about this item or the path would
4790 // be invalid and gtk_tree_view_set_cursor() would silently do nothing.
4791 ExpandAncestors(item
);
4793 // We also need to preserve the existing selection from changing.
4794 // Unfortunately the only way to do it seems to use our own selection
4795 // function and forbid any selection changes during set cursor call.
4796 wxGtkTreeSelectionLock
4797 lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview
)));
4799 // Do move the cursor now.
4801 iter
.user_data
= item
.GetID();
4802 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4804 gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview
), path
, NULL
, FALSE
);
4807 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4809 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4811 if (m_windowStyle
& wxDV_MULTIPLE
)
4813 // Report the first one
4814 GtkTreeModel
*model
;
4815 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4819 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4820 wxDataViewItem
item(GTKPathToItem(path
));
4823 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4824 g_list_free( list
);
4832 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
4834 wxDataViewItem
item( iter
.user_data
);
4839 return wxDataViewItem(0);
4842 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4846 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4847 if (HasFlag(wxDV_MULTIPLE
))
4849 GtkTreeModel
*model
;
4850 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4855 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4857 sel
.Add(GTKPathToItem(path
));
4859 list
= g_list_next( list
);
4864 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4865 g_list_free( list
);
4871 GtkTreeModel
*model
;
4873 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
4876 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4884 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4886 GtkDisableSelectionEvents();
4888 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4890 gtk_tree_selection_unselect_all( selection
);
4892 wxDataViewItem last_parent
;
4895 for (i
= 0; i
< sel
.GetCount(); i
++)
4897 wxDataViewItem item
= sel
[i
];
4898 wxDataViewItem parent
= GetModel()->GetParent( item
);
4901 if (parent
!= last_parent
)
4902 ExpandAncestors(item
);
4904 last_parent
= parent
;
4907 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4908 iter
.user_data
= (gpointer
) item
.GetID();
4909 gtk_tree_selection_select_iter( selection
, &iter
);
4912 GtkEnableSelectionEvents();
4915 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4917 ExpandAncestors(item
);
4919 GtkDisableSelectionEvents();
4921 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4924 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4925 iter
.user_data
= (gpointer
) item
.GetID();
4926 gtk_tree_selection_select_iter( selection
, &iter
);
4928 GtkEnableSelectionEvents();
4931 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4933 GtkDisableSelectionEvents();
4935 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4938 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4939 iter
.user_data
= (gpointer
) item
.GetID();
4940 gtk_tree_selection_unselect_iter( selection
, &iter
);
4942 GtkEnableSelectionEvents();
4945 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4947 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4950 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4951 iter
.user_data
= (gpointer
) item
.GetID();
4953 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
4956 void wxDataViewCtrl::SelectAll()
4958 GtkDisableSelectionEvents();
4960 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4962 gtk_tree_selection_select_all( selection
);
4964 GtkEnableSelectionEvents();
4967 void wxDataViewCtrl::UnselectAll()
4969 GtkDisableSelectionEvents();
4971 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4973 gtk_tree_selection_unselect_all( selection
);
4975 GtkEnableSelectionEvents();
4978 void wxDataViewCtrl::EnsureVisible(const wxDataViewItem
& item
,
4979 const wxDataViewColumn
*WXUNUSED(column
))
4981 m_ensureVisibleDefered
= item
;
4982 ExpandAncestors(item
);
4985 iter
.user_data
= (gpointer
) item
.GetID();
4986 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4987 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
4990 void wxDataViewCtrl::HitTest(const wxPoint
& point
,
4991 wxDataViewItem
& item
,
4992 wxDataViewColumn
*& column
) const
4994 // gtk_tree_view_get_dest_row_at_pos() is the right one. But it does not tell the column.
4995 // gtk_tree_view_get_path_at_pos() is the wrong function. It doesn't mind the header but returns column.
4996 // See http://mail.gnome.org/archives/gtkmm-list/2005-January/msg00080.html
4997 // So we have to use both of them.
4998 // Friedrich Haase 2010-9-20
4999 wxGtkTreePath path
, pathScratch
;
5000 GtkTreeViewColumn
* GtkColumn
= NULL
;
5001 GtkTreeViewDropPosition pos
= GTK_TREE_VIEW_DROP_INTO_OR_AFTER
;
5005 // cannot directly call GtkGetTreeView(), HitTest is const and so is this pointer
5006 wxDataViewCtrl
* ctrl
= (wxDataViewCtrl
*)this; // ugly workaround, ctrl is NOT const
5007 GtkTreeView
* treeView
= GTK_TREE_VIEW(ctrl
->GtkGetTreeView());
5009 // is there possibly a better suited function to get the column?
5010 gtk_tree_view_get_path_at_pos( // and this is the wrong call but it delivers the column
5012 (int) point
.x
, (int) point
.y
,
5013 pathScratch
.ByRef(),
5014 &GtkColumn
, // here we get the GtkColumn
5018 if ( GtkColumn
!= NULL
)
5020 // we got GTK column
5021 // the right call now which takes the header into account
5022 gtk_tree_view_get_dest_row_at_pos( treeView
, (int) point
.x
, (int) point
.y
, path
.ByRef(), &pos
);
5025 item
= wxDataViewItem(GTKPathToItem(path
));
5026 // else we got a GTK column but the position is not over an item, e.g. below last item
5027 for ( unsigned int i
=0, cols
=GetColumnCount(); i
<cols
; ++i
) // search the wx column
5029 wxDataViewColumn
* col
= GetColumn(i
);
5030 if ( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == GtkColumn
)
5032 column
= col
; // here we get the wx column
5037 // else no column and thus no item, both null
5041 wxDataViewCtrl::GetItemRect(const wxDataViewItem
& WXUNUSED(item
),
5042 const wxDataViewColumn
*WXUNUSED(column
)) const
5047 void wxDataViewCtrl::DoSetExpanderColumn()
5049 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
5050 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
5053 void wxDataViewCtrl::DoSetIndent()
5057 void wxDataViewCtrl::GtkDisableSelectionEvents()
5059 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5060 g_signal_handlers_disconnect_by_func( selection
,
5061 (gpointer
) (wxdataview_selection_changed_callback
), this);
5064 void wxDataViewCtrl::GtkEnableSelectionEvents()
5066 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5067 g_signal_connect_after (selection
, "changed",
5068 G_CALLBACK (wxdataview_selection_changed_callback
), this);
5071 // ----------------------------------------------------------------------------
5072 // visual attributes stuff
5073 // ----------------------------------------------------------------------------
5077 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
5079 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
5082 void wxDataViewCtrl::DoApplyWidgetStyle(GtkRcStyle
*style
)
5084 wxDataViewCtrlBase::DoApplyWidgetStyle(style
);
5085 gtk_widget_modify_style(m_treeview
, style
);
5088 #endif // !wxUSE_GENERICDATAVIEWCTRL
5090 #endif // wxUSE_DATAVIEWCTRL