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/popupwin.h"
29 #include "wx/listimpl.cpp"
31 #include "wx/gtk/private.h"
32 #include "wx/gtk/dc.h"
33 #include "wx/gtk/dcclient.h"
35 #include "wx/gtk/private/gdkconv.h"
36 #include "wx/gtk/private/list.h"
37 #include "wx/gtk/private/event.h"
38 using namespace wxGTKImpl
;
40 class wxGtkDataViewModelNotifier
;
42 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 static wxDataViewCtrlInternal
*gs_internal
= NULL
;
47 class wxGtkTreeModelNode
;
50 typedef struct _GtkWxTreeModel GtkWxTreeModel
;
53 // ----------------------------------------------------------------------------
54 // wxGtkTreePath: self-destroying GtkTreePath
55 // ----------------------------------------------------------------------------
57 // Usually this object is initialized with the associated GtkTreePath
58 // immediately when it's constructed but it can also be changed later either by
59 // using Assign() or by getting the pointer to the internally stored pointer
60 // value using ByRef(). The latter should be avoided but is very convenient
61 // when using GTK functions with GtkTreePath output parameters.
65 // Ctor takes ownership of the given path and will free it if non-NULL.
66 wxGtkTreePath(GtkTreePath
*path
= NULL
) : m_path(path
) { }
68 // Creates a tree path for the given string path.
69 wxGtkTreePath(const gchar
*strpath
)
70 : m_path(gtk_tree_path_new_from_string(strpath
))
74 // Set the stored pointer if not done by ctor.
75 void Assign(GtkTreePath
*path
)
77 wxASSERT_MSG( !m_path
, "shouldn't be already initialized" );
82 // Return the pointer to the internally stored pointer. This should only be
83 // used to initialize the object by passing it to some GTK function.
86 wxASSERT_MSG( !m_path
, "shouldn't be already initialized" );
92 operator GtkTreePath
*() const { return m_path
; }
94 ~wxGtkTreePath() { if ( m_path
) gtk_tree_path_free(m_path
); }
99 wxDECLARE_NO_COPY_CLASS(wxGtkTreePath
);
102 // ----------------------------------------------------------------------------
103 // wxGtkTreePathList: self-destroying list of GtkTreePath objects.
104 // ----------------------------------------------------------------------------
106 class wxGtkTreePathList
: public wxGtkList
109 // Ctor takes ownership of the list.
110 explicit wxGtkTreePathList(GList
* list
)
117 // Delete the list contents, wxGtkList will delete the list itself.
118 g_list_foreach(m_list
, (GFunc
)gtk_tree_path_free
, NULL
);
122 // ----------------------------------------------------------------------------
123 // wxGtkTreeSelectionLock: prevent selection from changing during the
124 // lifetime of this object
125 // ----------------------------------------------------------------------------
127 // Implementation note: it could be expected that setting the selection
128 // function in this class ctor and resetting it back to the old value in its
129 // dtor would work. However currently gtk_tree_selection_get_select_function()
130 // can't be passed NULL (see https://bugzilla.gnome.org/show_bug.cgi?id=626276)
131 // so we can't do this. Instead, we always use the selection function (which
132 // imposes extra overhead, albeit minimal one, on all selection operations) and
133 // just set/reset the flag telling it whether it should allow or forbid the
136 // Also notice that currently only a single object of this class may exist at
137 // any given moment. It's just simpler like this and we don't need anything
141 gboolean
wxdataview_selection_func(GtkTreeSelection
* WXUNUSED(selection
),
142 GtkTreeModel
* WXUNUSED(model
),
143 GtkTreePath
* WXUNUSED(path
),
144 gboolean
WXUNUSED(path_currently_selected
),
150 class wxGtkTreeSelectionLock
153 wxGtkTreeSelectionLock(GtkTreeSelection
*selection
)
154 : m_selection(selection
)
156 wxASSERT_MSG( !ms_instance
, "this class is not reentrant currently" );
160 CheckCurrentSelectionFunc(NULL
);
162 // Pass some non-NULL pointer as "data" for the callback, it doesn't
163 // matter what it is as long as it's non-NULL.
164 gtk_tree_selection_set_select_function(selection
,
165 wxdataview_selection_func
,
170 ~wxGtkTreeSelectionLock()
172 CheckCurrentSelectionFunc(wxdataview_selection_func
);
174 gtk_tree_selection_set_select_function(m_selection
,
175 wxdataview_selection_func
,
183 void CheckCurrentSelectionFunc(GtkTreeSelectionFunc func
)
185 // We can only use gtk_tree_selection_get_select_function() with 2.14+
186 // so check for its availability both during compile- and run-time.
187 #if GTK_CHECK_VERSION(2, 14, 0)
188 if ( gtk_check_version(2, 14, 0) != NULL
)
191 // If this assert is triggered, it means the code elsewhere has called
192 // gtk_tree_selection_set_select_function() but currently doing this
193 // breaks this class so the code here needs to be changed.
196 gtk_tree_selection_get_select_function(m_selection
) == func
,
197 "selection function has changed unexpectedly, review this code!"
204 static wxGtkTreeSelectionLock
*ms_instance
;
206 GtkTreeSelection
* const m_selection
;
208 wxDECLARE_NO_COPY_CLASS(wxGtkTreeSelectionLock
);
211 wxGtkTreeSelectionLock
*wxGtkTreeSelectionLock::ms_instance
= NULL
;
213 //-----------------------------------------------------------------------------
214 // wxDataViewCtrlInternal
215 //-----------------------------------------------------------------------------
217 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
218 WX_DEFINE_LIST(ItemList
)
220 class wxDataViewCtrlInternal
223 wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
);
224 ~wxDataViewCtrlInternal();
227 GtkTreeModelFlags
get_flags();
228 gboolean
get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
);
229 GtkTreePath
*get_path( GtkTreeIter
*iter
);
230 gboolean
iter_next( GtkTreeIter
*iter
);
231 gboolean
iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
);
232 gboolean
iter_has_child( GtkTreeIter
*iter
);
233 gint
iter_n_children( GtkTreeIter
*iter
);
234 gboolean
iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
);
235 gboolean
iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
);
239 bool EnableDragSource( const wxDataFormat
&format
);
240 bool EnableDropTarget( const wxDataFormat
&format
);
242 gboolean
row_draggable( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
);
243 gboolean
drag_data_delete( GtkTreeDragSource
*drag_source
, GtkTreePath
* path
);
244 gboolean
drag_data_get( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
,
245 GtkSelectionData
*selection_data
);
246 gboolean
drag_data_received( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest
,
247 GtkSelectionData
*selection_data
);
248 gboolean
row_drop_possible( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest_path
,
249 GtkSelectionData
*selection_data
);
251 // notifactions from wxDataViewModel
252 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
253 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
254 bool ItemChanged( const wxDataViewItem
&item
);
255 bool ValueChanged( const wxDataViewItem
&item
, unsigned int model_column
);
262 void SetSortOrder( GtkSortType sort_order
) { m_sort_order
= sort_order
; }
263 GtkSortType
GetSortOrder() const { return m_sort_order
; }
265 void SetSortColumn( int column
) { m_sort_column
= column
; }
266 int GetSortColumn() const { return m_sort_column
; }
268 void SetDataViewSortColumn( wxDataViewColumn
*column
) { m_dataview_sort_column
= column
; }
269 wxDataViewColumn
*GetDataViewSortColumn() { return m_dataview_sort_column
; }
271 bool IsSorted() { return (m_sort_column
>= 0); }
274 wxDataViewModel
* GetDataViewModel() { return m_wx_model
; }
275 const wxDataViewModel
* GetDataViewModel() const { return m_wx_model
; }
276 wxDataViewCtrl
* GetOwner() { return m_owner
; }
277 GtkWxTreeModel
* GetGtkModel() { return m_gtk_model
; }
279 // item can be deleted already in the model
280 int GetIndexOf( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
282 virtual void OnInternalIdle();
286 void ScheduleRefresh();
288 wxGtkTreeModelNode
*FindNode( const wxDataViewItem
&item
);
289 wxGtkTreeModelNode
*FindNode( GtkTreeIter
*iter
);
290 wxGtkTreeModelNode
*FindParentNode( const wxDataViewItem
&item
);
291 wxGtkTreeModelNode
*FindParentNode( GtkTreeIter
*iter
);
292 void BuildBranch( wxGtkTreeModelNode
*branch
);
295 wxGtkTreeModelNode
*m_root
;
296 wxDataViewModel
*m_wx_model
;
297 GtkWxTreeModel
*m_gtk_model
;
298 wxDataViewCtrl
*m_owner
;
299 GtkSortType m_sort_order
;
300 wxDataViewColumn
*m_dataview_sort_column
;
303 GtkTargetEntry m_dragSourceTargetEntry
;
304 wxCharBuffer m_dragSourceTargetEntryTarget
;
305 wxDataObject
*m_dragDataObject
;
307 GtkTargetEntry m_dropTargetTargetEntry
;
308 wxCharBuffer m_dropTargetTargetEntryTarget
;
309 wxDataObject
*m_dropDataObject
;
311 wxGtkDataViewModelNotifier
*m_notifier
;
317 //-----------------------------------------------------------------------------
318 // wxGtkTreeModelNode
319 //-----------------------------------------------------------------------------
322 int LINKAGEMODE
wxGtkTreeModelChildCmp( void** id1
, void** id2
)
324 int ret
= gs_internal
->GetDataViewModel()->Compare( wxDataViewItem(*id1
), wxDataViewItem(*id2
),
325 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
330 WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode
*, wxGtkTreeModelNodes
);
331 WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren
);
333 class wxGtkTreeModelNode
336 wxGtkTreeModelNode( wxGtkTreeModelNode
* parent
, const wxDataViewItem
&item
,
337 wxDataViewCtrlInternal
*internal
)
341 m_internal
= internal
;
344 ~wxGtkTreeModelNode()
346 size_t count
= m_nodes
.GetCount();
348 for (i
= 0; i
< count
; i
++)
350 wxGtkTreeModelNode
*child
= m_nodes
.Item( i
);
355 void AddNode( wxGtkTreeModelNode
* child
)
357 m_nodes
.Add( child
);
359 void *id
= child
->GetItem().GetID();
361 m_children
.Add( id
);
363 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
365 gs_internal
= m_internal
;
366 m_children
.Sort( &wxGtkTreeModelChildCmp
);
370 void InsertNode( wxGtkTreeModelNode
* child
, unsigned pos
)
372 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
378 void *id
= child
->GetItem().GetID();
380 // Insert into m_nodes so that the order of nodes in m_nodes is the
381 // same as the order of their corresponding IDs in m_children:
382 const unsigned int count
= m_nodes
.GetCount();
383 bool inserted
= false;
384 for (unsigned i
= 0; i
< count
; i
++)
386 wxGtkTreeModelNode
*node
= m_nodes
[i
];
387 int posInChildren
= m_children
.Index(node
->GetItem().GetID());
388 if ( (unsigned)posInChildren
>= pos
)
390 m_nodes
.Insert(child
, i
);
398 m_children
.Insert( id
, pos
);
401 void AddLeaf( void* id
)
403 InsertLeaf(id
, m_children
.size());
406 void InsertLeaf( void* id
, unsigned pos
)
408 m_children
.Insert( id
, pos
);
410 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
412 gs_internal
= m_internal
;
413 m_children
.Sort( &wxGtkTreeModelChildCmp
);
417 void DeleteChild( void* id
)
419 m_children
.Remove( id
);
421 unsigned int count
= m_nodes
.GetCount();
423 for (pos
= 0; pos
< count
; pos
++)
425 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
426 if (node
->GetItem().GetID() == id
)
428 m_nodes
.RemoveAt( pos
);
435 // returns position of child node for given item in children list or wxNOT_FOUND
436 int FindChildByItem(const wxDataViewItem
& item
) const
438 const void* itemId
= item
.GetID();
439 const wxGtkTreeModelChildren
& nodes
= m_children
;
440 const int len
= nodes
.size();
441 for ( int i
= 0; i
< len
; i
++ )
443 if ( nodes
[i
] == itemId
)
449 wxGtkTreeModelNode
* GetParent()
451 wxGtkTreeModelNodes
&GetNodes()
453 wxGtkTreeModelChildren
&GetChildren()
454 { return m_children
; }
456 unsigned int GetChildCount() const { return m_children
.GetCount(); }
457 unsigned int GetNodesCount() const { return m_nodes
.GetCount(); }
459 wxDataViewItem
&GetItem() { return m_item
; }
460 wxDataViewCtrlInternal
*GetInternal() { return m_internal
; }
465 wxGtkTreeModelNode
*m_parent
;
466 wxGtkTreeModelNodes m_nodes
;
467 wxGtkTreeModelChildren m_children
;
468 wxDataViewItem m_item
;
469 wxDataViewCtrlInternal
*m_internal
;
473 //-----------------------------------------------------------------------------
475 //-----------------------------------------------------------------------------
477 extern bool g_blockEventsOnDrag
;
479 //-----------------------------------------------------------------------------
480 // define new GTK+ class wxGtkTreeModel
481 //-----------------------------------------------------------------------------
485 #define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ())
486 #define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel))
487 #define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
488 #define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL))
489 #define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL))
490 #define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
492 GType
gtk_wx_tree_model_get_type (void);
494 typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass
;
496 struct _GtkWxTreeModel
502 wxDataViewCtrlInternal
*internal
;
505 struct _GtkWxTreeModelClass
507 GObjectClass list_parent_class
;
510 static GtkWxTreeModel
*wxgtk_tree_model_new (void);
511 static void wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
);
512 static void wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
);
514 static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
);
515 static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
);
516 static void wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
);
517 static void wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
);
519 static void wxgtk_tree_model_finalize (GObject
*object
);
520 static GtkTreeModelFlags
wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
);
521 static gint
wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
);
522 static GType
wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
524 static gboolean
wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
527 static GtkTreePath
*wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
529 static void wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
533 static gboolean
wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
535 static gboolean
wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
537 GtkTreeIter
*parent
);
538 static gboolean
wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
540 static gint
wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
542 static gboolean
wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
546 static gboolean
wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
551 static gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
552 gint
*sort_column_id
,
554 static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
557 static void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
559 GtkTreeIterCompareFunc func
,
561 GDestroyNotify destroy
);
562 static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
563 GtkTreeIterCompareFunc func
,
565 GDestroyNotify destroy
);
566 static gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
);
569 static gboolean
wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
571 static gboolean
wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
573 static gboolean
wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
575 GtkSelectionData
*selection_data
);
576 static gboolean
wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
578 GtkSelectionData
*selection_data
);
579 static gboolean
wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
580 GtkTreePath
*dest_path
,
581 GtkSelectionData
*selection_data
);
584 static GObjectClass
*list_parent_class
= NULL
;
587 gtk_wx_tree_model_get_type (void)
589 static GType tree_model_type
= 0;
591 if (!tree_model_type
)
593 const GTypeInfo tree_model_info
=
595 sizeof (GtkWxTreeModelClass
),
596 NULL
, /* base_init */
597 NULL
, /* base_finalize */
598 (GClassInitFunc
) wxgtk_tree_model_class_init
,
599 NULL
, /* class_finalize */
600 NULL
, /* class_data */
601 sizeof (GtkWxTreeModel
),
603 (GInstanceInitFunc
) wxgtk_tree_model_init
,
606 static const GInterfaceInfo tree_model_iface_info
=
608 (GInterfaceInitFunc
) wxgtk_tree_model_tree_model_init
,
613 static const GInterfaceInfo sortable_iface_info
=
615 (GInterfaceInitFunc
) wxgtk_tree_model_sortable_init
,
620 static const GInterfaceInfo drag_source_iface_info
=
622 (GInterfaceInitFunc
) wxgtk_tree_model_drag_source_init
,
627 static const GInterfaceInfo drag_dest_iface_info
=
629 (GInterfaceInitFunc
) wxgtk_tree_model_drag_dest_init
,
634 tree_model_type
= g_type_register_static (G_TYPE_OBJECT
, "GtkWxTreeModel",
635 &tree_model_info
, (GTypeFlags
)0 );
637 g_type_add_interface_static (tree_model_type
,
639 &tree_model_iface_info
);
640 g_type_add_interface_static (tree_model_type
,
641 GTK_TYPE_TREE_SORTABLE
,
642 &sortable_iface_info
);
643 g_type_add_interface_static (tree_model_type
,
644 GTK_TYPE_TREE_DRAG_DEST
,
645 &drag_dest_iface_info
);
646 g_type_add_interface_static (tree_model_type
,
647 GTK_TYPE_TREE_DRAG_SOURCE
,
648 &drag_source_iface_info
);
651 return tree_model_type
;
654 static GtkWxTreeModel
*
655 wxgtk_tree_model_new(void)
657 GtkWxTreeModel
*retval
= (GtkWxTreeModel
*) g_object_new (GTK_TYPE_WX_TREE_MODEL
, NULL
);
662 wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
)
664 list_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
665 GObjectClass
*object_class
= (GObjectClass
*) klass
;
666 object_class
->finalize
= wxgtk_tree_model_finalize
;
670 wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
)
672 iface
->get_flags
= wxgtk_tree_model_get_flags
;
673 iface
->get_n_columns
= wxgtk_tree_model_get_n_columns
;
674 iface
->get_column_type
= wxgtk_tree_model_get_column_type
;
675 iface
->get_iter
= wxgtk_tree_model_get_iter
;
676 iface
->get_path
= wxgtk_tree_model_get_path
;
677 iface
->get_value
= wxgtk_tree_model_get_value
;
678 iface
->iter_next
= wxgtk_tree_model_iter_next
;
679 iface
->iter_children
= wxgtk_tree_model_iter_children
;
680 iface
->iter_has_child
= wxgtk_tree_model_iter_has_child
;
681 iface
->iter_n_children
= wxgtk_tree_model_iter_n_children
;
682 iface
->iter_nth_child
= wxgtk_tree_model_iter_nth_child
;
683 iface
->iter_parent
= wxgtk_tree_model_iter_parent
;
687 wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
)
689 iface
->get_sort_column_id
= wxgtk_tree_model_get_sort_column_id
;
690 iface
->set_sort_column_id
= wxgtk_tree_model_set_sort_column_id
;
691 iface
->set_sort_func
= wxgtk_tree_model_set_sort_func
;
692 iface
->set_default_sort_func
= wxgtk_tree_model_set_default_sort_func
;
693 iface
->has_default_sort_func
= wxgtk_tree_model_has_default_sort_func
;
697 wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
)
699 iface
->row_draggable
= wxgtk_tree_model_row_draggable
;
700 iface
->drag_data_delete
= wxgtk_tree_model_drag_data_delete
;
701 iface
->drag_data_get
= wxgtk_tree_model_drag_data_get
;
705 wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
)
707 iface
->drag_data_received
= wxgtk_tree_model_drag_data_received
;
708 iface
->row_drop_possible
= wxgtk_tree_model_row_drop_possible
;
712 wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
)
714 tree_model
->internal
= NULL
;
715 tree_model
->stamp
= g_random_int();
719 wxgtk_tree_model_finalize (GObject
*object
)
722 (* list_parent_class
->finalize
) (object
);
727 //-----------------------------------------------------------------------------
728 // implement callbacks from wxGtkTreeModel class by letting
729 // them call the methods of wxWidgets' wxDataViewModel
730 //-----------------------------------------------------------------------------
732 static GtkTreeModelFlags
733 wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
)
735 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
736 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), (GtkTreeModelFlags
)0 );
738 return wxtree_model
->internal
->get_flags();
742 wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
)
744 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
745 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
747 return wxtree_model
->internal
->GetDataViewModel()->GetColumnCount();
751 wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
754 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
755 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), G_TYPE_INVALID
);
757 GType gtype
= G_TYPE_INVALID
;
759 wxString wxtype
= wxtree_model
->internal
->GetDataViewModel()->GetColumnType( (unsigned int) index
);
761 if (wxtype
== wxT("string"))
762 gtype
= G_TYPE_STRING
;
765 gtype
= G_TYPE_POINTER
;
766 // wxFAIL_MSG( wxT("non-string columns not supported for searching yet") );
773 wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
777 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
778 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
779 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
781 return wxtree_model
->internal
->get_iter( iter
, path
);
785 wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
788 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
789 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), NULL
);
790 g_return_val_if_fail (iter
->stamp
== GTK_WX_TREE_MODEL (wxtree_model
)->stamp
, NULL
);
792 return wxtree_model
->internal
->get_path( iter
);
796 wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
801 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
802 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
) );
804 wxDataViewModel
*model
= wxtree_model
->internal
->GetDataViewModel();
805 wxString mtype
= model
->GetColumnType( (unsigned int) column
);
806 if (mtype
== wxT("string"))
809 g_value_init( value
, G_TYPE_STRING
);
810 wxDataViewItem
item( (void*) iter
->user_data
);
811 model
->GetValue( variant
, item
, (unsigned int) column
);
813 g_value_set_string( value
, variant
.GetString().utf8_str() );
817 wxFAIL_MSG( wxT("non-string columns not supported yet") );
822 wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
825 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
827 // This happens when clearing the view by calling .._set_model( NULL );
828 if (iter
->stamp
== 0) return FALSE
;
830 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
831 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
833 return wxtree_model
->internal
->iter_next( iter
);
837 wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
841 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
842 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
845 g_return_val_if_fail (wxtree_model
->stamp
== parent
->stamp
, FALSE
);
848 return wxtree_model
->internal
->iter_children( iter
, parent
);
852 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
855 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
856 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
857 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
859 return wxtree_model
->internal
->iter_has_child( iter
);
863 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
866 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
867 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
868 g_return_val_if_fail ( !iter
|| wxtree_model
->stamp
== iter
->stamp
, 0);
870 return wxtree_model
->internal
->iter_n_children( iter
);
874 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
879 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
880 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
882 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
886 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
890 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
891 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
892 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
894 return wxtree_model
->internal
->iter_parent( iter
, child
);
897 /* drag'n'drop iface */
899 wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
902 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
903 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
905 return wxtree_model
->internal
->row_draggable( drag_source
, path
);
909 wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
912 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
913 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
915 return wxtree_model
->internal
->drag_data_delete( drag_source
, path
);
919 wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
921 GtkSelectionData
*selection_data
)
923 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
924 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
927 wxPrintf( "drag_get_data\n");
929 wxGtkString
atom_selection(gdk_atom_name(selection_data
->selection
));
930 wxPrintf( "selection %s\n", wxString::FromAscii(atom_selection
) );
932 wxGtkString
atom_target(gdk_atom_name(selection_data
->target
));
933 wxPrintf( "target %s\n", wxString::FromAscii(atom_target
) );
935 wxGtkString
atom_type(gdk_atom_name(selection_data
->type
));
936 wxPrintf( "type %s\n", wxString::FromAscii(atom_type
) );
938 wxPrintf( "format %d\n", selection_data
->format
);
941 return wxtree_model
->internal
->drag_data_get( drag_source
, path
, selection_data
);
945 wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
947 GtkSelectionData
*selection_data
)
949 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
950 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
952 return wxtree_model
->internal
->drag_data_received( drag_dest
, dest
, selection_data
);
956 wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
957 GtkTreePath
*dest_path
,
958 GtkSelectionData
*selection_data
)
960 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
961 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
963 return wxtree_model
->internal
->row_drop_possible( drag_dest
, dest_path
, selection_data
);
968 wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
969 gint
*sort_column_id
,
972 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) sortable
;
974 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
976 if (!wxtree_model
->internal
->IsSorted())
979 *sort_column_id
= -1;
986 *sort_column_id
= wxtree_model
->internal
->GetSortColumn();
989 *order
= wxtree_model
->internal
->GetSortOrder();
994 wxDataViewColumn
*gs_lastLeftClickHeader
= NULL
;
997 wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
1001 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
1002 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
1004 tree_model
->internal
->SetDataViewSortColumn( gs_lastLeftClickHeader
);
1006 if ((sort_column_id
!= (gint
) tree_model
->internal
->GetSortColumn()) ||
1007 (order
!= tree_model
->internal
->GetSortOrder()))
1009 tree_model
->internal
->SetSortColumn( sort_column_id
);
1010 tree_model
->internal
->SetSortOrder( order
);
1012 gtk_tree_sortable_sort_column_changed (sortable
);
1014 tree_model
->internal
->GetDataViewModel()->Resort();
1017 if (gs_lastLeftClickHeader
)
1019 wxDataViewCtrl
*dv
= tree_model
->internal
->GetOwner();
1020 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, dv
->GetId() );
1021 event
.SetDataViewColumn( gs_lastLeftClickHeader
);
1022 event
.SetModel( dv
->GetModel() );
1023 dv
->HandleWindowEvent( event
);
1026 gs_lastLeftClickHeader
= NULL
;
1030 wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
1031 gint
WXUNUSED(sort_column_id
),
1032 GtkTreeIterCompareFunc func
,
1033 gpointer
WXUNUSED(data
),
1034 GDestroyNotify
WXUNUSED(destroy
))
1036 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
1037 g_return_if_fail (func
!= NULL
);
1041 wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
1042 GtkTreeIterCompareFunc func
,
1043 gpointer
WXUNUSED(data
),
1044 GDestroyNotify
WXUNUSED(destroy
))
1046 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
1047 g_return_if_fail (func
!= NULL
);
1049 //wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
1050 // TODO: remove this code
1054 wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
)
1056 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
1061 //-----------------------------------------------------------------------------
1062 // define new GTK+ class GtkWxRendererText
1063 //-----------------------------------------------------------------------------
1067 #define GTK_TYPE_WX_CELL_RENDERER_TEXT (gtk_wx_cell_renderer_text_get_type ())
1068 #define GTK_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererText))
1069 #define GTK_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
1070 #define GTK_IS_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT))
1071 #define GTK_IS_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT))
1072 #define GTK_WX_CELL_RENDERER_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
1074 GType
gtk_wx_cell_renderer_text_get_type (void);
1076 typedef struct _GtkWxCellRendererText GtkWxCellRendererText
;
1077 typedef struct _GtkWxCellRendererTextClass GtkWxCellRendererTextClass
;
1079 struct _GtkWxCellRendererText
1081 GtkCellRendererText parent
;
1083 wxDataViewRenderer
*wx_renderer
;
1086 struct _GtkWxCellRendererTextClass
1088 GtkCellRendererTextClass cell_parent_class
;
1092 static GtkWxCellRendererText
*gtk_wx_cell_renderer_text_new (void);
1093 static void gtk_wx_cell_renderer_text_init (
1094 GtkWxCellRendererText
*cell
);
1095 static void gtk_wx_cell_renderer_text_class_init(
1096 GtkWxCellRendererTextClass
*klass
);
1097 static void gtk_wx_cell_renderer_text_finalize (
1099 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
1100 GtkCellRenderer
*cell
,
1104 GdkRectangle
*background_area
,
1105 GdkRectangle
*cell_area
,
1106 GtkCellRendererState flags
);
1109 static GObjectClass
*text_cell_parent_class
= NULL
;
1114 gtk_wx_cell_renderer_text_get_type (void)
1116 static GType cell_wx_type
= 0;
1120 const GTypeInfo cell_wx_info
=
1122 sizeof (GtkWxCellRendererTextClass
),
1123 NULL
, /* base_init */
1124 NULL
, /* base_finalize */
1125 (GClassInitFunc
) gtk_wx_cell_renderer_text_class_init
,
1126 NULL
, /* class_finalize */
1127 NULL
, /* class_data */
1128 sizeof (GtkWxCellRendererText
),
1129 0, /* n_preallocs */
1130 (GInstanceInitFunc
) gtk_wx_cell_renderer_text_init
,
1133 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER_TEXT
,
1134 "GtkWxCellRendererText", &cell_wx_info
, (GTypeFlags
)0 );
1137 return cell_wx_type
;
1141 gtk_wx_cell_renderer_text_init (GtkWxCellRendererText
*cell
)
1143 cell
->wx_renderer
= NULL
;
1147 gtk_wx_cell_renderer_text_class_init (GtkWxCellRendererTextClass
*klass
)
1149 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1150 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
1152 text_cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
1154 object_class
->finalize
= gtk_wx_cell_renderer_text_finalize
;
1156 cell_class
->start_editing
= gtk_wx_cell_renderer_text_start_editing
;
1160 gtk_wx_cell_renderer_text_finalize (GObject
*object
)
1163 (* G_OBJECT_CLASS (text_cell_parent_class
)->finalize
) (object
);
1166 GtkWxCellRendererText
*
1167 gtk_wx_cell_renderer_text_new (void)
1169 return (GtkWxCellRendererText
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER_TEXT
, NULL
);
1172 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
1173 GtkCellRenderer
*gtk_renderer
,
1174 GdkEvent
*gdk_event
,
1177 GdkRectangle
*background_area
,
1178 GdkRectangle
*cell_area
,
1179 GtkCellRendererState flags
)
1181 GtkWxCellRendererText
*wxgtk_renderer
= (GtkWxCellRendererText
*) gtk_renderer
;
1182 wxDataViewRenderer
*wx_renderer
= wxgtk_renderer
->wx_renderer
;
1183 wxDataViewColumn
*column
= wx_renderer
->GetOwner();
1186 item(column
->GetOwner()->GTKPathToItem(wxGtkTreePath(path
)));
1188 wxDataViewCtrl
*dv
= column
->GetOwner();
1189 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, dv
->GetId() );
1190 event
.SetDataViewColumn( column
);
1191 event
.SetModel( dv
->GetModel() );
1192 event
.SetColumn( column
->GetModelColumn() );
1193 event
.SetItem( item
);
1194 dv
->HandleWindowEvent( event
);
1196 if (event
.IsAllowed())
1197 return GTK_CELL_RENDERER_CLASS(text_cell_parent_class
)->
1198 start_editing( gtk_renderer
, gdk_event
, widget
, path
, background_area
, cell_area
, flags
);
1203 //-----------------------------------------------------------------------------
1204 // define new GTK+ class GtkWxCellRenderer
1205 //-----------------------------------------------------------------------------
1209 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
1210 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
1211 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
1212 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
1213 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
1214 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
1216 GType
gtk_wx_cell_renderer_get_type (void);
1218 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
1219 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
1221 struct _GtkWxCellRenderer
1223 GtkCellRenderer parent
;
1226 wxDataViewCustomRenderer
*cell
;
1229 struct _GtkWxCellRendererClass
1231 GtkCellRendererClass cell_parent_class
;
1235 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
1236 static void gtk_wx_cell_renderer_init (
1237 GtkWxCellRenderer
*cell
);
1238 static void gtk_wx_cell_renderer_class_init(
1239 GtkWxCellRendererClass
*klass
);
1240 static void gtk_wx_cell_renderer_finalize (
1242 static void gtk_wx_cell_renderer_get_size (
1243 GtkCellRenderer
*cell
,
1245 GdkRectangle
*rectangle
,
1250 static void gtk_wx_cell_renderer_render (
1251 GtkCellRenderer
*cell
,
1254 GdkRectangle
*background_area
,
1255 GdkRectangle
*cell_area
,
1256 GdkRectangle
*expose_area
,
1257 GtkCellRendererState flags
);
1258 static gboolean
gtk_wx_cell_renderer_activate(
1259 GtkCellRenderer
*cell
,
1263 GdkRectangle
*background_area
,
1264 GdkRectangle
*cell_area
,
1265 GtkCellRendererState flags
);
1266 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1267 GtkCellRenderer
*cell
,
1271 GdkRectangle
*background_area
,
1272 GdkRectangle
*cell_area
,
1273 GtkCellRendererState flags
);
1276 static GObjectClass
*cell_parent_class
= NULL
;
1281 gtk_wx_cell_renderer_get_type (void)
1283 static GType cell_wx_type
= 0;
1287 const GTypeInfo cell_wx_info
=
1289 sizeof (GtkWxCellRendererClass
),
1290 NULL
, /* base_init */
1291 NULL
, /* base_finalize */
1292 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
1293 NULL
, /* class_finalize */
1294 NULL
, /* class_data */
1295 sizeof (GtkWxCellRenderer
),
1296 0, /* n_preallocs */
1297 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
1300 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
1301 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
1304 return cell_wx_type
;
1308 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
1314 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
1316 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1317 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
1319 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
1321 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
1323 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
1324 cell_class
->render
= gtk_wx_cell_renderer_render
;
1325 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
1326 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
1330 gtk_wx_cell_renderer_finalize (GObject
*object
)
1333 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
1337 gtk_wx_cell_renderer_new (void)
1339 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
1342 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1343 GtkCellRenderer
*renderer
,
1344 GdkEvent
*WXUNUSED(event
),
1347 GdkRectangle
*WXUNUSED(background_area
),
1348 GdkRectangle
*cell_area
,
1349 GtkCellRendererState
WXUNUSED(flags
) )
1351 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1352 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1354 // Renderer doesn't support in-place editing
1355 if (!cell
->HasEditorCtrl())
1358 // An in-place editing control is still around
1359 if (cell
->GetEditorCtrl())
1363 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1369 rect
.x
+= cell_area
->x
;
1370 rect
.y
+= cell_area
->y
;
1371 // rect.width -= renderer->xpad * 2;
1372 // rect.height -= renderer->ypad * 2;
1374 // wxRect renderrect(wxRectFromGDKRect(&rect));
1375 wxRect
renderrect(wxRectFromGDKRect(cell_area
));
1378 item(cell
->GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(path
)));
1380 cell
->StartEditing( item
, renderrect
);
1386 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
1387 GtkWidget
*WXUNUSED(widget
),
1388 GdkRectangle
*cell_area
,
1394 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1395 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1397 wxSize size
= cell
->GetSize();
1399 wxDataViewCtrl
* const ctrl
= cell
->GetOwner()->GetOwner();
1401 // Uniform row height, if specified, overrides the value returned by the
1403 if ( !ctrl
->HasFlag(wxDV_VARIABLE_LINE_HEIGHT
) )
1405 const int uniformHeight
= ctrl
->GTKGetUniformRowHeight();
1406 if ( uniformHeight
> 0 )
1407 size
.y
= uniformHeight
;
1411 gtk_cell_renderer_get_padding(renderer
, &xpad
, &ypad
);
1412 int calc_width
= xpad
* 2 + size
.x
;
1413 int calc_height
= ypad
* 2 + size
.y
;
1420 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
1422 float xalign
, yalign
;
1423 gtk_cell_renderer_get_alignment(renderer
, &xalign
, &yalign
);
1426 *x_offset
= int(xalign
* (cell_area
->width
- calc_width
- 2 * xpad
));
1427 *x_offset
= MAX(*x_offset
, 0) + xpad
;
1431 *y_offset
= int(yalign
* (cell_area
->height
- calc_height
- 2 * ypad
));
1432 *y_offset
= MAX(*y_offset
, 0) + ypad
;
1437 *width
= calc_width
;
1440 *height
= calc_height
;
1444 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
1447 GdkRectangle
*background_area
,
1448 GdkRectangle
*cell_area
,
1449 GdkRectangle
*expose_area
,
1450 GtkCellRendererState flags
)
1453 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1454 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1456 cell
->GTKStashRenderParams(window
, widget
,
1457 background_area
, expose_area
, flags
);
1459 wxRect
rect(wxRectFromGDKRect(cell_area
));
1461 gtk_cell_renderer_get_padding(renderer
, &xpad
, &ypad
);
1462 rect
= rect
.Deflate(xpad
, ypad
);
1464 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
1465 wxWindowDCImpl
*impl
= (wxWindowDCImpl
*) dc
->GetImpl();
1467 // Reinitialize wxWindowDC's GDK window if drawing occurs into a different
1468 // window such as a DnD drop window.
1469 if (window
!= impl
->m_gdkwindow
)
1472 impl
->m_gdkwindow
= window
;
1477 if (flags
& GTK_CELL_RENDERER_SELECTED
)
1478 state
|= wxDATAVIEW_CELL_SELECTED
;
1479 if (flags
& GTK_CELL_RENDERER_PRELIT
)
1480 state
|= wxDATAVIEW_CELL_PRELIT
;
1481 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1482 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1483 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1484 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1485 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
1486 state
|= wxDATAVIEW_CELL_FOCUSED
;
1487 cell
->WXCallRender( rect
, dc
, state
);
1491 gtk_wx_cell_renderer_activate(
1492 GtkCellRenderer
*renderer
,
1496 GdkRectangle
*WXUNUSED(background_area
),
1497 GdkRectangle
*cell_area
,
1498 GtkCellRendererState
WXUNUSED(flags
) )
1500 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1501 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1504 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1510 rect
.x
+= cell_area
->x
;
1511 rect
.y
+= cell_area
->y
;
1513 gtk_cell_renderer_get_padding(renderer
, &xpad
, &ypad
);
1514 rect
.width
-= xpad
* 2;
1515 rect
.height
-= ypad
* 2;
1517 wxRect
renderrect(wxRectFromGDKRect(&rect
));
1519 wxDataViewCtrl
* const ctrl
= cell
->GetOwner()->GetOwner();
1520 wxDataViewModel
*model
= ctrl
->GetModel();
1522 wxDataViewItem
item(ctrl
->GTKPathToItem(wxGtkTreePath(path
)));
1524 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1528 // activated by <ENTER>
1529 return cell
->ActivateCell(renderrect
, model
, item
, model_col
, NULL
);
1531 else if ( event
->type
== GDK_BUTTON_PRESS
)
1533 GdkEventButton
*button_event
= (GdkEventButton
*)event
;
1534 if ( button_event
->button
== 1 )
1536 wxMouseEvent
mouse_event(wxEVT_LEFT_DOWN
);
1537 InitMouseEvent(ctrl
, mouse_event
, button_event
);
1539 mouse_event
.m_x
-= renderrect
.x
;
1540 mouse_event
.m_y
-= renderrect
.y
;
1542 return cell
->ActivateCell(renderrect
, model
, item
, model_col
, &mouse_event
);
1546 wxLogDebug("unexpected event type in gtk_wx_cell_renderer_activate()");
1550 // ---------------------------------------------------------
1551 // wxGtkDataViewModelNotifier
1552 // ---------------------------------------------------------
1554 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1557 wxGtkDataViewModelNotifier( wxDataViewModel
*wx_model
, wxDataViewCtrlInternal
*internal
);
1558 ~wxGtkDataViewModelNotifier();
1560 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1561 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1562 virtual bool ItemChanged( const wxDataViewItem
&item
);
1563 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int model_column
);
1564 virtual bool Cleared();
1565 virtual void Resort();
1566 virtual bool BeforeReset();
1567 virtual bool AfterReset();
1569 void UpdateLastCount();
1572 wxDataViewModel
*m_wx_model
;
1573 wxDataViewCtrlInternal
*m_internal
;
1576 // ---------------------------------------------------------
1577 // wxGtkDataViewListModelNotifier
1578 // ---------------------------------------------------------
1580 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1581 wxDataViewModel
*wx_model
, wxDataViewCtrlInternal
*internal
)
1583 m_wx_model
= wx_model
;
1584 m_internal
= internal
;
1587 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1593 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1595 m_internal
->ItemAdded( parent
, item
);
1596 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1599 iter
.stamp
= wxgtk_model
->stamp
;
1600 iter
.user_data
= item
.GetID();
1602 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1603 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1604 gtk_tree_model_row_inserted(
1605 GTK_TREE_MODEL(wxgtk_model
), path
, &iter
);
1610 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1612 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1614 // using _get_path for a deleted item cannot be
1617 iter
.stamp
= wxgtk_model
->stamp
;
1618 iter
.user_data
= (gpointer
) item
.GetID();
1619 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1620 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1622 // so get the path from the parent
1623 GtkTreeIter parentIter
;
1624 parentIter
.stamp
= wxgtk_model
->stamp
;
1625 parentIter
.user_data
= (gpointer
) parent
.GetID();
1626 wxGtkTreePath
parentPath(wxgtk_tree_model_get_path(
1627 GTK_TREE_MODEL(wxgtk_model
), &parentIter
));
1629 // and add the final index ourselves
1630 wxGtkTreePath
path(gtk_tree_path_copy(parentPath
));
1631 int index
= m_internal
->GetIndexOf( parent
, item
);
1632 gtk_tree_path_append_index( path
, index
);
1635 gtk_tree_model_row_deleted(
1636 GTK_TREE_MODEL(wxgtk_model
), path
);
1638 m_internal
->ItemDeleted( parent
, item
);
1640 // Did we remove the last child, causing 'parent' to become a leaf?
1641 if ( !m_wx_model
->IsContainer(parent
) )
1643 gtk_tree_model_row_has_child_toggled
1645 GTK_TREE_MODEL(wxgtk_model
),
1654 void wxGtkDataViewModelNotifier::Resort()
1656 m_internal
->Resort();
1659 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1661 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1664 iter
.stamp
= wxgtk_model
->stamp
;
1665 iter
.user_data
= (gpointer
) item
.GetID();
1667 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1668 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1669 gtk_tree_model_row_changed(
1670 GTK_TREE_MODEL(wxgtk_model
), path
, &iter
);
1672 m_internal
->ItemChanged( item
);
1677 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_column
)
1679 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1680 wxDataViewCtrl
*ctrl
= m_internal
->GetOwner();
1682 // This adds GTK+'s missing MVC logic for ValueChanged
1684 for (index
= 0; index
< ctrl
->GetColumnCount(); index
++)
1686 wxDataViewColumn
*column
= ctrl
->GetColumn( index
);
1687 if (column
->GetModelColumn() == model_column
)
1689 GtkTreeView
*widget
= GTK_TREE_VIEW(ctrl
->GtkGetTreeView());
1690 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1692 // Don't attempt to refresh not yet realized tree, it is useless
1693 // and results in GTK errors.
1694 if ( gtk_widget_get_realized(ctrl
->GtkGetTreeView()) )
1698 iter
.stamp
= wxgtk_model
->stamp
;
1699 iter
.user_data
= (gpointer
) item
.GetID();
1700 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1701 GTK_TREE_MODEL(wxgtk_model
), &iter
));
1702 GdkRectangle cell_area
;
1703 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1705 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1706 double d
= gtk_adjustment_get_value( hadjust
);
1707 int xdiff
= (int) d
;
1709 int ydiff
= gcolumn
->button
->allocation
.height
;
1711 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1712 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1715 m_internal
->ValueChanged( item
, model_column
);
1724 bool wxGtkDataViewModelNotifier::BeforeReset()
1726 GtkWidget
*treeview
= m_internal
->GetOwner()->GtkGetTreeView();
1727 gtk_tree_view_set_model( GTK_TREE_VIEW(treeview
), NULL
);
1732 bool wxGtkDataViewModelNotifier::AfterReset()
1734 GtkWidget
*treeview
= m_internal
->GetOwner()->GtkGetTreeView();
1735 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1737 m_internal
->Cleared();
1739 gtk_tree_view_set_model( GTK_TREE_VIEW(treeview
), GTK_TREE_MODEL(wxgtk_model
) );
1744 bool wxGtkDataViewModelNotifier::Cleared()
1746 GtkWxTreeModel
*wxgtk_model
= m_internal
->GetGtkModel();
1748 // There is no call to tell the model that everything
1749 // has been deleted so call row_deleted() for every
1752 int count
= m_internal
->iter_n_children( NULL
); // number of children of root
1754 GtkTreePath
*path
= gtk_tree_path_new_first(); // points to root
1757 for (i
= 0; i
< count
; i
++)
1758 gtk_tree_model_row_deleted( GTK_TREE_MODEL(wxgtk_model
), path
);
1760 gtk_tree_path_free( path
);
1762 m_internal
->Cleared();
1767 // ---------------------------------------------------------
1768 // wxDataViewRenderer
1769 // ---------------------------------------------------------
1771 static gpointer s_user_data
= NULL
;
1774 wxgtk_cell_editable_editing_done( GtkCellEditable
*WXUNUSED(editable
),
1775 wxDataViewRenderer
*wxrenderer
)
1777 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1778 wxDataViewCtrl
*dv
= column
->GetOwner();
1779 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1780 event
.SetDataViewColumn( column
);
1781 event
.SetModel( dv
->GetModel() );
1782 wxDataViewItem
item( s_user_data
);
1783 event
.SetItem( item
);
1784 dv
->HandleWindowEvent( event
);
1788 wxgtk_renderer_editing_started( GtkCellRenderer
*WXUNUSED(cell
), GtkCellEditable
*editable
,
1789 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1794 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1795 wxDataViewCtrl
*dv
= column
->GetOwner();
1796 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1797 event
.SetDataViewColumn( column
);
1798 event
.SetModel( dv
->GetModel() );
1799 wxDataViewItem
item(dv
->GTKPathToItem(wxGtkTreePath(path
)));
1800 event
.SetItem( item
);
1801 dv
->HandleWindowEvent( event
);
1803 if (GTK_IS_CELL_EDITABLE(editable
))
1805 s_user_data
= item
.GetID();
1807 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1808 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1809 (gpointer
) wxrenderer
);
1815 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1817 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1819 wxDataViewRendererBase( varianttype
, mode
, align
)
1824 // we haven't changed them yet
1825 m_usingDefaultAttrs
= true;
1827 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1828 // after the m_renderer pointer has been initialized
1831 void wxDataViewRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
1833 gtk_tree_view_column_pack_end( column
, m_renderer
, TRUE
/* expand */);
1836 void wxDataViewRenderer::GtkInitHandlers()
1838 if (!gtk_check_version(2,6,0))
1840 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1841 G_CALLBACK (wxgtk_renderer_editing_started
),
1846 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1848 GtkCellRendererMode gtkMode
;
1851 case wxDATAVIEW_CELL_INERT
:
1852 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1855 case wxDATAVIEW_CELL_ACTIVATABLE
:
1856 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1859 case wxDATAVIEW_CELL_EDITABLE
:
1860 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1864 wxFAIL_MSG( "unknown wxDataViewCellMode value" );
1870 // This value is most often ignored in GtkTreeView
1871 GValue gvalue
= { 0, };
1872 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1873 g_value_set_enum( &gvalue
, gtkMode
);
1874 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1875 g_value_unset( &gvalue
);
1878 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1880 wxDataViewCellMode ret
;
1883 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1885 switch (g_value_get_enum(&gvalue
))
1888 wxFAIL_MSG( "unknown GtkCellRendererMode value" );
1889 // fall through (we have to return something)
1891 case GTK_CELL_RENDERER_MODE_INERT
:
1892 ret
= wxDATAVIEW_CELL_INERT
;
1895 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1896 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1899 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1900 ret
= wxDATAVIEW_CELL_EDITABLE
;
1904 g_value_unset( &gvalue
);
1909 void wxDataViewRenderer::GtkApplyAlignment(GtkCellRenderer
*renderer
)
1911 int align
= m_alignment
;
1913 // query alignment from column ?
1917 if (GetOwner() == NULL
)
1920 align
= GetOwner()->GetAlignment();
1921 align
|= wxALIGN_CENTRE_VERTICAL
;
1924 // horizontal alignment:
1926 gfloat xalign
= 0.0;
1927 if (align
& wxALIGN_RIGHT
)
1929 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1932 GValue gvalue
= { 0, };
1933 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1934 g_value_set_float( &gvalue
, xalign
);
1935 g_object_set_property( G_OBJECT(renderer
), "xalign", &gvalue
);
1936 g_value_unset( &gvalue
);
1938 // vertical alignment:
1940 gfloat yalign
= 0.0;
1941 if (align
& wxALIGN_BOTTOM
)
1943 else if (align
& wxALIGN_CENTER_VERTICAL
)
1946 GValue gvalue2
= { 0, };
1947 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1948 g_value_set_float( &gvalue2
, yalign
);
1949 g_object_set_property( G_OBJECT(renderer
), "yalign", &gvalue2
);
1950 g_value_unset( &gvalue2
);
1953 void wxDataViewRenderer::SetAlignment( int align
)
1955 m_alignment
= align
;
1956 GtkUpdateAlignment();
1959 int wxDataViewRenderer::GetAlignment() const
1964 void wxDataViewRenderer::EnableEllipsize(wxEllipsizeMode mode
)
1967 if ( gtk_check_version(2, 6, 0) != NULL
)
1970 GtkCellRendererText
* const rend
= GtkGetTextRenderer();
1974 // we use the same values in wxEllipsizeMode as PangoEllipsizeMode so we
1975 // can just cast between them
1976 GValue gvalue
= { 0, };
1977 g_value_init( &gvalue
, PANGO_TYPE_ELLIPSIZE_MODE
);
1978 g_value_set_enum( &gvalue
, static_cast<PangoEllipsizeMode
>(mode
) );
1979 g_object_set_property( G_OBJECT(rend
), "ellipsize", &gvalue
);
1980 g_value_unset( &gvalue
);
1983 #endif // GTK 2.6/before
1986 wxEllipsizeMode
wxDataViewRenderer::GetEllipsizeMode() const
1989 if ( gtk_check_version(2, 6, 0) != NULL
)
1990 return wxELLIPSIZE_NONE
;
1992 GtkCellRendererText
* const rend
= GtkGetTextRenderer();
1994 return wxELLIPSIZE_NONE
;
1996 GValue gvalue
= { 0, };
1997 g_value_init( &gvalue
, PANGO_TYPE_ELLIPSIZE_MODE
);
1998 g_object_get_property( G_OBJECT(rend
), "ellipsize", &gvalue
);
2000 mode
= static_cast<wxEllipsizeMode
>(g_value_get_enum( &gvalue
));
2001 g_value_unset( &gvalue
);
2005 return wxELLIPSIZE_NONE
;
2006 #endif // GTK 2.6/before
2010 wxDataViewRenderer::GtkOnTextEdited(const char *itempath
, const wxString
& str
)
2012 wxVariant
value(str
);
2013 if (!Validate( value
))
2017 item(GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(itempath
)));
2019 GtkOnCellChanged(value
, item
, GetOwner()->GetModelColumn());
2023 wxDataViewRenderer::GtkOnCellChanged(const wxVariant
& value
,
2024 const wxDataViewItem
& item
,
2027 wxDataViewModel
*model
= GetOwner()->GetOwner()->GetModel();
2028 model
->ChangeValue( value
, item
, col
);
2031 // ---------------------------------------------------------
2032 // wxDataViewTextRenderer
2033 // ---------------------------------------------------------
2038 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*WXUNUSED(renderer
),
2039 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
2041 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) user_data
;
2043 cell
->GtkOnTextEdited(arg1
, wxGTK_CONV_BACK_FONT(
2044 arg2
, cell
->GetOwner()->GetOwner()->GetFont()));
2052 // helper function used by wxDataViewTextRenderer and
2053 // wxDataViewCustomRenderer::RenderText(): it applies the attributes to the
2054 // given text renderer and returns true if anything was done
2055 bool GtkApplyAttr(GtkCellRendererText
*renderer
, const wxDataViewItemAttr
& attr
)
2057 bool usingDefaultAttrs
= true;
2058 if (attr
.HasColour())
2060 const GdkColor
* const gcol
= attr
.GetColour().GetColor();
2062 GValue gvalue
= { 0, };
2063 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2064 g_value_set_boxed( &gvalue
, gcol
);
2065 g_object_set_property( G_OBJECT(renderer
), "foreground_gdk", &gvalue
);
2066 g_value_unset( &gvalue
);
2068 usingDefaultAttrs
= false;
2072 GValue gvalue
= { 0, };
2073 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2074 g_value_set_boolean( &gvalue
, FALSE
);
2075 g_object_set_property( G_OBJECT(renderer
), "foreground-set", &gvalue
);
2076 g_value_unset( &gvalue
);
2079 if (attr
.GetItalic())
2081 GValue gvalue
= { 0, };
2082 g_value_init( &gvalue
, PANGO_TYPE_STYLE
);
2083 g_value_set_enum( &gvalue
, PANGO_STYLE_ITALIC
);
2084 g_object_set_property( G_OBJECT(renderer
), "style", &gvalue
);
2085 g_value_unset( &gvalue
);
2087 usingDefaultAttrs
= false;
2091 GValue gvalue
= { 0, };
2092 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2093 g_value_set_boolean( &gvalue
, FALSE
);
2094 g_object_set_property( G_OBJECT(renderer
), "style-set", &gvalue
);
2095 g_value_unset( &gvalue
);
2101 GValue gvalue
= { 0, };
2102 g_value_init( &gvalue
, PANGO_TYPE_WEIGHT
);
2103 g_value_set_enum( &gvalue
, PANGO_WEIGHT_BOLD
);
2104 g_object_set_property( G_OBJECT(renderer
), "weight", &gvalue
);
2105 g_value_unset( &gvalue
);
2107 usingDefaultAttrs
= false;
2111 GValue gvalue
= { 0, };
2112 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2113 g_value_set_boolean( &gvalue
, FALSE
);
2114 g_object_set_property( G_OBJECT(renderer
), "weight-set", &gvalue
);
2115 g_value_unset( &gvalue
);
2119 if (attr
.HasBackgroundColour())
2121 wxColour colour
= attr
.GetBackgroundColour();
2122 const GdkColor
* const gcol
= colour
.GetColor();
2124 GValue gvalue
= { 0, };
2125 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2126 g_value_set_boxed( &gvalue
, gcol
);
2127 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
2128 g_value_unset( &gvalue
);
2132 GValue gvalue
= { 0, };
2133 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2134 g_value_set_boolean( &gvalue
, FALSE
);
2135 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
2136 g_value_unset( &gvalue
);
2140 return !usingDefaultAttrs
;
2143 } // anonymous namespace
2145 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
2147 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
2149 wxDataViewRenderer( varianttype
, mode
, align
)
2151 GtkWxCellRendererText
*text_renderer
= gtk_wx_cell_renderer_text_new();
2152 text_renderer
->wx_renderer
= this;
2153 m_renderer
= (GtkCellRenderer
*) text_renderer
;
2155 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
2157 GValue gvalue
= { 0, };
2158 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2159 g_value_set_boolean( &gvalue
, true );
2160 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
2161 g_value_unset( &gvalue
);
2163 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2169 SetAlignment(align
);
2172 bool wxDataViewTextRenderer::SetTextValue(const wxString
& str
)
2174 GValue gvalue
= { 0, };
2175 g_value_init( &gvalue
, G_TYPE_STRING
);
2176 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( str
, GetOwner()->GetOwner()->GetFont() ) );
2177 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2178 g_value_unset( &gvalue
);
2183 bool wxDataViewTextRenderer::GetTextValue(wxString
& str
) const
2185 GValue gvalue
= { 0, };
2186 g_value_init( &gvalue
, G_TYPE_STRING
);
2187 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2188 str
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
), const_cast<wxDataViewTextRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
2189 g_value_unset( &gvalue
);
2194 void wxDataViewTextRenderer::SetAlignment( int align
)
2196 wxDataViewRenderer::SetAlignment(align
);
2198 if (gtk_check_version(2,10,0))
2201 // horizontal alignment:
2202 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2203 if (align
& wxALIGN_RIGHT
)
2204 pangoAlign
= PANGO_ALIGN_RIGHT
;
2205 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2206 pangoAlign
= PANGO_ALIGN_CENTER
;
2208 GValue gvalue
= { 0, };
2209 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2210 g_value_set_enum( &gvalue
, pangoAlign
);
2211 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2212 g_value_unset( &gvalue
);
2215 bool wxDataViewTextRenderer::GtkSetAttr(const wxDataViewItemAttr
& attr
)
2217 return GtkApplyAttr(GtkGetTextRenderer(), attr
);
2220 GtkCellRendererText
*wxDataViewTextRenderer::GtkGetTextRenderer() const
2222 return GTK_CELL_RENDERER_TEXT(m_renderer
);
2225 // ---------------------------------------------------------
2226 // wxDataViewBitmapRenderer
2227 // ---------------------------------------------------------
2232 // set "pixbuf" property on the given renderer
2233 void SetPixbufProp(GtkCellRenderer
*renderer
, GdkPixbuf
*pixbuf
)
2235 GValue gvalue
= { 0, };
2236 g_value_init( &gvalue
, G_TYPE_OBJECT
);
2237 g_value_set_object( &gvalue
, pixbuf
);
2238 g_object_set_property( G_OBJECT(renderer
), "pixbuf", &gvalue
);
2239 g_value_unset( &gvalue
);
2242 } // anonymous namespace
2244 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
2246 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
2248 wxDataViewRenderer( varianttype
, mode
, align
)
2250 m_renderer
= gtk_cell_renderer_pixbuf_new();
2253 SetAlignment(align
);
2256 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
2258 if (value
.GetType() == wxT("wxBitmap"))
2263 // GetPixbuf() may create a Pixbuf representation in the wxBitmap
2264 // object (and it will stay there and remain owned by wxBitmap)
2265 SetPixbufProp(m_renderer
, bitmap
.GetPixbuf());
2267 else if (value
.GetType() == wxT("wxIcon"))
2272 SetPixbufProp(m_renderer
, icon
.GetPixbuf());
2282 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2287 // ---------------------------------------------------------
2288 // wxDataViewToggleRenderer
2289 // ---------------------------------------------------------
2292 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
2293 gchar
*path
, gpointer user_data
);
2296 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
2297 gchar
*path
, gpointer user_data
)
2299 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
2302 GValue gvalue
= { 0, };
2303 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2304 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
2305 bool tmp
= g_value_get_boolean( &gvalue
);
2306 g_value_unset( &gvalue
);
2310 wxVariant value
= tmp
;
2311 if (!cell
->Validate( value
))
2314 wxDataViewCtrl
* const ctrl
= cell
->GetOwner()->GetOwner();
2315 wxDataViewModel
*model
= ctrl
->GetModel();
2317 wxDataViewItem
item(ctrl
->GTKPathToItem(wxGtkTreePath(path
)));
2319 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
2321 model
->ChangeValue( value
, item
, model_col
);
2324 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
2326 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
2327 wxDataViewCellMode mode
, int align
) :
2328 wxDataViewRenderer( varianttype
, mode
, align
)
2330 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
2332 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
2334 g_signal_connect_after( m_renderer
, "toggled",
2335 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
2339 GValue gvalue
= { 0, };
2340 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2341 g_value_set_boolean( &gvalue
, false );
2342 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
2343 g_value_unset( &gvalue
);
2347 SetAlignment(align
);
2350 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
2354 GValue gvalue
= { 0, };
2355 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2356 g_value_set_boolean( &gvalue
, tmp
);
2357 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
2358 g_value_unset( &gvalue
);
2363 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
2365 GValue gvalue
= { 0, };
2366 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2367 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
2368 bool tmp
= g_value_get_boolean( &gvalue
);
2369 g_value_unset( &gvalue
);
2376 // ---------------------------------------------------------
2377 // wxDataViewCustomRenderer
2378 // ---------------------------------------------------------
2380 class wxDataViewCtrlDCImpl
: public wxWindowDCImpl
2383 wxDataViewCtrlDCImpl( wxDC
*owner
, wxDataViewCtrl
*window
) :
2384 wxWindowDCImpl( owner
)
2386 GtkWidget
*widget
= window
->m_treeview
;
2392 m_context
= window
->GTKGetPangoDefaultContext();
2393 m_layout
= pango_layout_new( m_context
);
2394 m_fontdesc
= pango_font_description_copy(gtk_widget_get_style(widget
)->font_desc
);
2396 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
2398 // Set m_gdkwindow later
2403 class wxDataViewCtrlDC
: public wxWindowDC
2406 wxDataViewCtrlDC( wxDataViewCtrl
*window
) :
2407 wxWindowDC( new wxDataViewCtrlDCImpl( this, window
) )
2412 // ---------------------------------------------------------
2413 // wxDataViewCustomRenderer
2414 // ---------------------------------------------------------
2416 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
2418 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
2419 wxDataViewCellMode mode
,
2422 : wxDataViewCustomRendererBase( varianttype
, mode
, align
)
2425 m_text_renderer
= NULL
;
2433 void wxDataViewCustomRenderer::GtkInitTextRenderer()
2435 m_text_renderer
= GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new());
2436 g_object_ref_sink(m_text_renderer
);
2438 GtkApplyAlignment(GTK_CELL_RENDERER(m_text_renderer
));
2441 GtkCellRendererText
*wxDataViewCustomRenderer::GtkGetTextRenderer() const
2443 if ( !m_text_renderer
)
2445 // we create it on demand so need to do it even from a const function
2446 const_cast<wxDataViewCustomRenderer
*>(this)->GtkInitTextRenderer();
2449 return m_text_renderer
;
2452 void wxDataViewCustomRenderer::RenderText( const wxString
&text
,
2456 int WXUNUSED(state
) )
2459 GtkCellRendererText
* const textRenderer
= GtkGetTextRenderer();
2461 GValue gvalue
= { 0, };
2462 g_value_init( &gvalue
, G_TYPE_STRING
);
2463 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( text
, GetOwner()->GetOwner()->GetFont() ) );
2464 g_object_set_property( G_OBJECT(textRenderer
), "text", &gvalue
);
2465 g_value_unset( &gvalue
);
2467 GtkApplyAttr(textRenderer
, GetAttr());
2469 GdkRectangle cell_area
;
2470 wxRectToGDKRect(cell
, cell_area
);
2471 cell_area
.x
+= xoffset
;
2472 cell_area
.width
-= xoffset
;
2474 gtk_cell_renderer_render( GTK_CELL_RENDERER(textRenderer
),
2475 m_renderParams
.window
,
2476 m_renderParams
.widget
,
2477 m_renderParams
.background_area
,
2479 m_renderParams
.expose_area
,
2480 (GtkCellRendererState
) m_renderParams
.flags
);
2483 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
2485 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
2486 renderer
->cell
= this;
2488 m_renderer
= (GtkCellRenderer
*) renderer
;
2491 SetAlignment(align
);
2498 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
2503 if (m_text_renderer
)
2504 g_object_unref(m_text_renderer
);
2507 wxDC
*wxDataViewCustomRenderer::GetDC()
2511 if (GetOwner() == NULL
)
2513 if (GetOwner()->GetOwner() == NULL
)
2515 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
2521 // ---------------------------------------------------------
2522 // wxDataViewProgressRenderer
2523 // ---------------------------------------------------------
2525 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
2527 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
2528 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
2529 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
2535 if (!gtk_check_version(2,6,0))
2537 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
2540 SetAlignment(align
);
2543 // We can't initialize the renderer just yet because we don't have the
2544 // pointer to the column that uses this renderer yet and so attempt to
2545 // dereference GetOwner() to get the font that is used as a source of
2546 // encoding in multibyte-to-Unicode conversion in GTKSetLabel() in
2547 // non-Unicode builds would crash. So simply remember to do it later.
2548 if ( !m_label
.empty() )
2549 m_needsToSetLabel
= true;
2551 #endif // !wxUSE_UNICODE
2557 // Use custom cell code
2558 wxDataViewCustomRenderer::Init(mode
, align
);
2562 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
2566 void wxDataViewProgressRenderer::GTKSetLabel()
2568 GValue gvalue
= { 0, };
2569 g_value_init( &gvalue
, G_TYPE_STRING
);
2571 // Take care to not use GetOwner() here if the label is empty, we can be
2572 // called from ctor when GetOwner() is still NULL in this case.
2573 g_value_set_string( &gvalue
,
2574 m_label
.empty() ? ""
2575 : wxGTK_CONV_FONT(m_label
,
2576 GetOwner()->GetOwner()->GetFont())
2578 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2579 g_value_unset( &gvalue
);
2582 m_needsToSetLabel
= false;
2583 #endif // !wxUSE_UNICODE
2586 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
2589 if (!gtk_check_version(2,6,0))
2592 if ( m_needsToSetLabel
)
2594 #endif // !wxUSE_UNICODE
2596 gint tmp
= (long) value
;
2597 GValue gvalue
= { 0, };
2598 g_value_init( &gvalue
, G_TYPE_INT
);
2599 g_value_set_int( &gvalue
, tmp
);
2600 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
2601 g_value_unset( &gvalue
);
2606 m_value
= (long) value
;
2608 if (m_value
< 0) m_value
= 0;
2609 if (m_value
> 100) m_value
= 100;
2615 bool wxDataViewProgressRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2620 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
2622 double pct
= (double)m_value
/ 100.0;
2624 bar
.width
= (int)(cell
.width
* pct
);
2625 dc
->SetPen( *wxTRANSPARENT_PEN
);
2626 dc
->SetBrush( *wxBLUE_BRUSH
);
2627 dc
->DrawRectangle( bar
);
2629 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
2630 dc
->SetPen( *wxBLACK_PEN
);
2631 dc
->DrawRectangle( cell
);
2636 wxSize
wxDataViewProgressRenderer::GetSize() const
2638 return wxSize(40,12);
2641 // -------------------------------------
2642 // wxDataViewChoiceRenderer
2643 // -------------------------------------
2645 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
&choices
,
2646 wxDataViewCellMode mode
, int alignment
) :
2647 wxDataViewCustomRenderer( "string", mode
, alignment
, true )
2649 m_choices
= choices
;
2652 if (!gtk_check_version(2,6,0))
2654 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_combo_new();
2656 GtkListStore
*store
= gtk_list_store_new( 1, G_TYPE_STRING
);
2657 for (size_t n
= 0; n
< m_choices
.GetCount(); n
++)
2659 gtk_list_store_insert_with_values(
2661 static_cast<const char *>(m_choices
[n
].utf8_str()), -1 );
2664 g_object_set (m_renderer
,
2670 bool editable
= (mode
& wxDATAVIEW_CELL_EDITABLE
);
2671 g_object_set (m_renderer
, "editable", editable
, NULL
);
2673 SetAlignment(alignment
);
2675 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2682 // Use custom cell code
2683 wxDataViewCustomRenderer::Init(mode
, alignment
);
2687 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
2689 RenderText( m_data
, 0, rect
, dc
, state
);
2693 wxSize
wxDataViewChoiceRenderer::GetSize() const
2695 return wxSize(70,20);
2698 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
2702 if (!gtk_check_version(2,6,0))
2704 GValue gvalue
= { 0, };
2705 g_value_init( &gvalue
, G_TYPE_STRING
);
2706 g_value_set_string(&gvalue
,
2707 wxGTK_CONV_FONT(value
.GetString(),
2708 GetOwner()->GetOwner()->GetFont()));
2709 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2710 g_value_unset( &gvalue
);
2714 m_data
= value
.GetString();
2719 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
2722 if (!gtk_check_version(2,6,0))
2724 GValue gvalue
= { 0, };
2725 g_value_init( &gvalue
, G_TYPE_STRING
);
2726 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2727 wxString temp
= wxGTK_CONV_BACK_FONT(g_value_get_string(&gvalue
),
2728 GetOwner()->GetOwner()->GetFont());
2729 g_value_unset( &gvalue
);
2732 //wxPrintf( "temp %s\n", temp );
2733 // TODO: remove this code
2742 void wxDataViewChoiceRenderer::SetAlignment( int align
)
2744 wxDataViewCustomRenderer::SetAlignment(align
);
2746 if (gtk_check_version(2,10,0))
2749 // horizontal alignment:
2750 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2751 if (align
& wxALIGN_RIGHT
)
2752 pangoAlign
= PANGO_ALIGN_RIGHT
;
2753 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2754 pangoAlign
= PANGO_ALIGN_CENTER
;
2756 GValue gvalue
= { 0, };
2757 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2758 g_value_set_enum( &gvalue
, pangoAlign
);
2759 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2760 g_value_unset( &gvalue
);
2763 // ----------------------------------------------------------------------------
2764 // wxDataViewChoiceByIndexRenderer
2765 // ----------------------------------------------------------------------------
2767 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
2768 wxDataViewCellMode mode
, int alignment
) :
2769 wxDataViewChoiceRenderer( choices
, mode
, alignment
)
2773 void wxDataViewChoiceByIndexRenderer::GtkOnTextEdited(const char *itempath
, const wxString
& str
)
2775 wxVariant
value( (long) GetChoices().Index( str
) );
2777 if (!Validate( value
))
2781 item(GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(itempath
)));
2783 GtkOnCellChanged(value
, item
, GetOwner()->GetModelColumn());
2786 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant
&value
)
2788 wxVariant string_value
= GetChoice( value
.GetLong() );
2789 return wxDataViewChoiceRenderer::SetValue( string_value
);
2792 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant
&value
) const
2794 wxVariant string_value
;
2795 if (!wxDataViewChoiceRenderer::GetValue( string_value
))
2798 value
= (long) GetChoices().Index( string_value
.GetString() );
2802 // ---------------------------------------------------------
2803 // wxDataViewIconTextRenderer
2804 // ---------------------------------------------------------
2806 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
2808 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer
2810 const wxString
&varianttype
,
2811 wxDataViewCellMode mode
,
2814 : wxDataViewTextRenderer(varianttype
, mode
, align
)
2816 m_rendererIcon
= gtk_cell_renderer_pixbuf_new();
2819 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2823 void wxDataViewIconTextRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
2825 // add the icon renderer first
2826 gtk_tree_view_column_pack_start(column
, m_rendererIcon
, FALSE
/* !expand */);
2828 // add the text renderer too
2829 wxDataViewRenderer::GtkPackIntoColumn(column
);
2832 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
2836 SetTextValue(m_value
.GetText());
2837 SetPixbufProp(m_rendererIcon
, m_value
.GetIcon().GetPixbuf());
2842 bool wxDataViewIconTextRenderer::GetValue(wxVariant
& value
) const
2845 if ( !GetTextValue(str
) )
2848 // user doesn't have any way to edit the icon so leave it unchanged
2849 value
<< wxDataViewIconText(str
, m_value
.GetIcon());
2855 wxDataViewIconTextRenderer::GtkOnCellChanged(const wxVariant
& value
,
2856 const wxDataViewItem
& item
,
2859 // we receive just the text part of our value as it's the only one which
2860 // can be edited, but we need the full wxDataViewIconText value for the
2862 wxVariant valueIconText
;
2863 valueIconText
<< wxDataViewIconText(value
.GetString(), m_value
.GetIcon());
2864 wxDataViewTextRenderer::GtkOnCellChanged(valueIconText
, item
, col
);
2867 // ---------------------------------------------------------
2869 // ---------------------------------------------------------
2873 gtk_dataview_header_button_press_callback( GtkWidget
*WXUNUSED(widget
),
2874 GdkEventButton
*gdk_event
,
2875 wxDataViewColumn
*column
)
2877 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
2880 if (gdk_event
->button
== 1)
2882 gs_lastLeftClickHeader
= column
;
2884 wxDataViewCtrl
*dv
= column
->GetOwner();
2885 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
2886 event
.SetDataViewColumn( column
);
2887 event
.SetModel( dv
->GetModel() );
2888 if (dv
->HandleWindowEvent( event
))
2892 if (gdk_event
->button
== 3)
2894 wxDataViewCtrl
*dv
= column
->GetOwner();
2895 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
2896 event
.SetDataViewColumn( column
);
2897 event
.SetModel( dv
->GetModel() );
2898 if (dv
->HandleWindowEvent( event
))
2908 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*WXUNUSED(column
),
2909 GtkCellRenderer
*renderer
,
2910 GtkTreeModel
*model
,
2914 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2915 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2917 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2919 wxDataViewItem
item( (void*) iter
->user_data
);
2921 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
2923 if (!wx_model
->IsVirtualListModel())
2926 if (wx_model
->IsContainer( item
))
2928 visible
= wx_model
->HasContainerColumns( item
) ||
2929 (cell
->GetOwner()->GetModelColumn() == 0);
2936 GValue gvalue
= { 0, };
2937 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2938 g_value_set_boolean( &gvalue
, visible
);
2939 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2940 g_value_unset( &gvalue
);
2947 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
2949 if (value
.GetType() != cell
->GetVariantType())
2951 wxLogError( wxT("Wrong type, required: %s but: %s"),
2952 value
.GetType().c_str(),
2953 cell
->GetVariantType().c_str() );
2956 cell
->SetValue( value
);
2958 // deal with disabled items
2959 bool enabled
= wx_model
->IsEnabled( item
, cell
->GetOwner()->GetModelColumn() );
2961 // a) this sets the appearance to disabled grey
2962 GValue gvalue
= { 0, };
2963 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2964 g_value_set_boolean( &gvalue
, enabled
);
2965 g_object_set_property( G_OBJECT(renderer
), "sensitive", &gvalue
);
2966 g_value_unset( &gvalue
);
2968 // b) this actually disables the control/renderer
2970 cell
->SetMode( cell
->GtkGetMode() );
2972 cell
->SetMode( wxDATAVIEW_CELL_INERT
);
2975 // deal with attributes: if the renderer doesn't support them at all, we
2976 // don't even need to query the model for them
2977 if ( !cell
->GtkSupportsAttrs() )
2980 // it can support attributes so check if this item has any
2981 wxDataViewItemAttr attr
;
2982 if ( wx_model
->GetAttr( item
, cell
->GetOwner()->GetModelColumn(), attr
)
2983 || !cell
->GtkIsUsingDefaultAttrs() )
2985 bool usingDefaultAttrs
= !cell
->GtkSetAttr(attr
);
2986 cell
->GtkSetUsingDefaultAttrs(usingDefaultAttrs
);
2988 // else: no custom attributes specified and we're already using the default
2989 // ones -- nothing to do
2995 #include <wx/listimpl.cpp>
2996 WX_DEFINE_LIST(wxDataViewColumnList
)
2998 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
2999 unsigned int model_column
, int width
,
3000 wxAlignment align
, int flags
)
3001 : wxDataViewColumnBase( cell
, model_column
)
3003 Init( align
, flags
, width
);
3008 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
3009 unsigned int model_column
, int width
,
3010 wxAlignment align
, int flags
)
3011 : wxDataViewColumnBase( bitmap
, cell
, model_column
)
3013 Init( align
, flags
, width
);
3015 SetBitmap( bitmap
);
3018 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
3020 m_isConnected
= false;
3022 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
3023 m_column
= (GtkWidget
*) column
;
3026 SetAlignment( align
);
3030 // Create container for icon and label
3031 GtkWidget
*box
= gtk_hbox_new( FALSE
, 1 );
3032 gtk_widget_show( box
);
3033 // gtk_container_set_border_width((GtkContainer*)box, 2);
3034 m_image
= gtk_image_new();
3035 gtk_box_pack_start(GTK_BOX(box
), m_image
, FALSE
, FALSE
, 1);
3036 m_label
= gtk_label_new("");
3037 gtk_box_pack_end( GTK_BOX(box
), GTK_WIDGET(m_label
), FALSE
, FALSE
, 1 );
3038 gtk_tree_view_column_set_widget( column
, box
);
3040 wxDataViewRenderer
* const colRenderer
= GetRenderer();
3041 GtkCellRenderer
* const cellRenderer
= colRenderer
->GetGtkHandle();
3043 colRenderer
->GtkPackIntoColumn(column
);
3045 gtk_tree_view_column_set_cell_data_func( column
, cellRenderer
,
3046 wxGtkTreeCellDataFunc
, (gpointer
) colRenderer
, NULL
);
3049 void wxDataViewColumn::OnInternalIdle()
3054 if (gtk_widget_get_realized(GetOwner()->m_treeview
))
3056 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3059 g_signal_connect(column
->button
, "button_press_event",
3060 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
3062 // otherwise the event will be blocked by GTK+
3063 gtk_tree_view_column_set_clickable( column
, TRUE
);
3065 m_isConnected
= true;
3070 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
3072 wxDataViewColumnBase::SetOwner( owner
);
3074 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3076 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
3079 void wxDataViewColumn::SetTitle( const wxString
&title
)
3081 wxDataViewCtrl
*ctrl
= GetOwner();
3082 gtk_label_set_text( GTK_LABEL(m_label
), ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
3083 : wxGTK_CONV_SYS(title
) );
3085 gtk_widget_hide( m_label
);
3087 gtk_widget_show( m_label
);
3090 wxString
wxDataViewColumn::GetTitle() const
3092 return wxGTK_CONV_BACK_FONT(
3093 gtk_label_get_text( GTK_LABEL(m_label
) ),
3094 GetOwner()->GetFont()
3098 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
3100 wxDataViewColumnBase::SetBitmap( bitmap
);
3104 GtkImage
*gtk_image
= GTK_IMAGE(m_image
);
3106 GdkBitmap
*mask
= NULL
;
3107 if (bitmap
.GetMask())
3108 mask
= bitmap
.GetMask()->GetBitmap();
3110 if (bitmap
.HasPixbuf())
3112 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
3113 bitmap
.GetPixbuf());
3117 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
3118 bitmap
.GetPixmap(), mask
);
3120 gtk_widget_show( m_image
);
3124 gtk_widget_hide( m_image
);
3128 void wxDataViewColumn::SetHidden( bool hidden
)
3130 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
3133 void wxDataViewColumn::SetResizeable( bool resizable
)
3135 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizable
);
3138 void wxDataViewColumn::SetAlignment( wxAlignment align
)
3140 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3142 gfloat xalign
= 0.0;
3143 if (align
== wxALIGN_RIGHT
)
3145 if (align
== wxALIGN_CENTER_HORIZONTAL
||
3146 align
== wxALIGN_CENTER
)
3149 gtk_tree_view_column_set_alignment( column
, xalign
);
3151 if (m_renderer
&& m_renderer
->GetAlignment() == -1)
3152 m_renderer
->GtkUpdateAlignment();
3155 wxAlignment
wxDataViewColumn::GetAlignment() const
3157 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
3160 return wxALIGN_RIGHT
;
3162 return wxALIGN_CENTER_HORIZONTAL
;
3164 return wxALIGN_LEFT
;
3167 void wxDataViewColumn::SetSortable( bool sortable
)
3169 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3173 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
3177 gtk_tree_view_column_set_sort_column_id( column
, -1 );
3178 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
3179 gtk_tree_view_column_set_clickable( column
, FALSE
);
3183 bool wxDataViewColumn::IsSortable() const
3185 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3186 return gtk_tree_view_column_get_clickable( column
);
3189 bool wxDataViewColumn::IsSortKey() const
3191 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3192 return gtk_tree_view_column_get_sort_indicator( column
);
3195 bool wxDataViewColumn::IsResizeable() const
3197 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3198 return gtk_tree_view_column_get_resizable( column
);
3201 bool wxDataViewColumn::IsHidden() const
3203 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3204 return !gtk_tree_view_column_get_visible( column
);
3207 void wxDataViewColumn::SetSortOrder( bool ascending
)
3209 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3212 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
3214 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
3216 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
3219 bool wxDataViewColumn::IsSortOrderAscending() const
3221 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3223 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
3226 void wxDataViewColumn::SetMinWidth( int width
)
3228 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
3231 int wxDataViewColumn::GetMinWidth() const
3233 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
3236 int wxDataViewColumn::GetWidth() const
3238 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
3241 void wxDataViewColumn::SetWidth( int width
)
3243 if ( width
== wxCOL_WIDTH_AUTOSIZE
)
3245 // NB: this disables user resizing
3246 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
3250 if ( width
== wxCOL_WIDTH_DEFAULT
)
3252 // TODO find a better calculation
3253 width
= wxDVC_DEFAULT_WIDTH
;
3256 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
3257 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
3261 void wxDataViewColumn::SetReorderable( bool reorderable
)
3263 gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column
), reorderable
);
3266 bool wxDataViewColumn::IsReorderable() const
3268 return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column
) );
3271 //-----------------------------------------------------------------------------
3272 // wxGtkTreeModelNode
3273 //-----------------------------------------------------------------------------
3276 class wxGtkTreeModelChildWithPos
3284 int wxGtkTreeModelChildWithPosCmp( const void* data1
, const void* data2
, const void* user_data
)
3286 const wxGtkTreeModelChildWithPos
* child1
= (const wxGtkTreeModelChildWithPos
*) data1
;
3287 const wxGtkTreeModelChildWithPos
* child2
= (const wxGtkTreeModelChildWithPos
*) data2
;
3288 const wxDataViewCtrlInternal
*internal
= (const wxDataViewCtrlInternal
*) user_data
;
3289 int ret
= internal
->GetDataViewModel()->Compare( child1
->id
, child2
->id
,
3290 internal
->GetSortColumn(), (internal
->GetSortOrder() == GTK_SORT_DESCENDING
) );
3296 int LINKAGEMODE
wxGtkTreeModelChildPtrCmp( void*** data1
, void*** data2
)
3298 return gs_internal
->GetDataViewModel()->Compare( wxDataViewItem(**data1
), wxDataViewItem(**data2
),
3299 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
3302 WX_DEFINE_ARRAY_PTR( void**, wxGtkTreeModelChildrenPtr
);
3305 void wxGtkTreeModelNode::Resort()
3307 size_t child_count
= GetChildCount();
3308 if (child_count
== 0)
3311 size_t node_count
= GetNodesCount();
3313 if (child_count
== 1)
3315 if (node_count
== 1)
3317 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
3323 gint
*new_order
= new gint
[child_count
];
3326 // m_children has the original *void
3327 // ptrs points to these
3328 wxGtkTreeModelChildrenPtr ptrs
;
3330 for (i
= 0; i
< child_count
; i
++)
3331 ptrs
.Add( &(m_children
[i
]) );
3333 gs_internal
= m_internal
;
3334 ptrs
.Sort( &wxGtkTreeModelChildPtrCmp
);
3336 wxGtkTreeModelChildren temp
;
3337 void** base_ptr
= &(m_children
[0]);
3338 // Transfer positions to new_order array and
3340 for (i
= 0; i
< child_count
; i
++)
3342 new_order
[i
] = ptrs
[i
] - base_ptr
;
3343 temp
.Add( *ptrs
[i
] );
3346 // Transfer IDs back to m_children
3348 WX_APPEND_ARRAY( temp
, m_children
);
3353 // Build up array with IDs and original positions
3354 wxGtkTreeModelChildWithPos
* temp
= new wxGtkTreeModelChildWithPos
[child_count
];
3356 for (i
= 0; i
< child_count
; i
++)
3359 temp
[i
].id
= m_children
[i
];
3361 // Sort array keeping original positions
3362 wxQsort( temp
, child_count
, sizeof(wxGtkTreeModelChildWithPos
),
3363 &wxGtkTreeModelChildWithPosCmp
, m_internal
);
3364 // Transfer positions to new_order array and
3365 // IDs to m_children
3367 for (i
= 0; i
< child_count
; i
++)
3369 new_order
[i
] = temp
[i
].pos
;
3370 m_children
.Add( temp
[i
].id
);
3379 wxGtkTreeModelChildren temp
;
3380 WX_APPEND_ARRAY( temp
, m_children
);
3382 gs_internal
= m_internal
;
3383 m_children
.Sort( &wxGtkTreeModelChildCmp
);
3386 for (pos
= 0; pos
< child_count
; pos
++)
3388 void *id
= m_children
.Item( pos
);
3389 int old_pos
= temp
.Index( id
);
3390 new_order
[pos
] = old_pos
;
3394 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
3397 iter
.user_data
= GetItem().GetID();
3398 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
3400 gtk_tree_model_rows_reordered( gtk_tree_model
,
3401 wxGtkTreePath(m_internal
->get_path(&iter
)), &iter
, new_order
);
3403 delete [] new_order
;
3406 for (pos
= 0; pos
< node_count
; pos
++)
3408 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
3413 //-----------------------------------------------------------------------------
3414 // wxDataViewCtrlInternal
3415 //-----------------------------------------------------------------------------
3417 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
)
3420 m_wx_model
= wx_model
;
3424 m_sort_order
= GTK_SORT_ASCENDING
;
3426 m_dataview_sort_column
= NULL
;
3428 m_dragDataObject
= NULL
;
3429 m_dropDataObject
= NULL
;
3433 m_gtk_model
= wxgtk_tree_model_new();
3434 m_gtk_model
->internal
= this;
3436 m_notifier
= new wxGtkDataViewModelNotifier( wx_model
, this );
3438 wx_model
->AddNotifier( m_notifier
);
3440 // g_object_unref( gtk_model ); ???
3442 if (!m_wx_model
->IsVirtualListModel())
3445 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->GtkGetTreeView()), GTK_TREE_MODEL(m_gtk_model
) );
3448 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
3450 m_wx_model
->RemoveNotifier( m_notifier
);
3452 // remove the model from the GtkTreeView before it gets destroyed
3453 gtk_tree_view_set_model( GTK_TREE_VIEW( m_owner
->GtkGetTreeView() ), NULL
);
3455 g_object_unref( m_gtk_model
);
3457 delete m_dragDataObject
;
3458 delete m_dropDataObject
;
3461 void wxDataViewCtrlInternal::ScheduleRefresh()
3466 void wxDataViewCtrlInternal::OnInternalIdle()
3470 GtkWidget
*widget
= m_owner
->GtkGetTreeView();
3471 gtk_widget_queue_draw( widget
);
3476 void wxDataViewCtrlInternal::InitTree()
3478 wxDataViewItem item
;
3479 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
3481 BuildBranch( m_root
);
3484 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
3486 if (node
->GetChildCount() == 0)
3488 wxDataViewItemArray children
;
3489 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
3492 for (pos
= 0; pos
< count
; pos
++)
3494 wxDataViewItem child
= children
[pos
];
3496 if (m_wx_model
->IsContainer( child
))
3497 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
3499 node
->AddLeaf( child
.GetID() );
3501 // Don't send any events here
3508 bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat
&format
)
3510 wxGtkString
atom_str( gdk_atom_name( format
) );
3511 m_dragSourceTargetEntryTarget
= wxCharBuffer( atom_str
);
3513 m_dragSourceTargetEntry
.target
= m_dragSourceTargetEntryTarget
.data();
3514 m_dragSourceTargetEntry
.flags
= 0;
3515 m_dragSourceTargetEntry
.info
= static_cast<guint
>(-1);
3517 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3518 GDK_BUTTON1_MASK
, &m_dragSourceTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3523 bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat
&format
)
3525 wxGtkString
atom_str( gdk_atom_name( format
) );
3526 m_dropTargetTargetEntryTarget
= wxCharBuffer( atom_str
);
3528 m_dropTargetTargetEntry
.target
= m_dropTargetTargetEntryTarget
.data();
3529 m_dropTargetTargetEntry
.flags
= 0;
3530 m_dropTargetTargetEntry
.info
= static_cast<guint
>(-1);
3532 gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3533 &m_dropTargetTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3538 gboolean
wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource
*WXUNUSED(drag_source
),
3541 delete m_dragDataObject
;
3542 m_dragDataObject
= NULL
;
3544 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3548 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3549 event
.SetEventObject( m_owner
);
3550 event
.SetItem( item
);
3551 event
.SetModel( m_wx_model
);
3553 gtk_widget_get_pointer(m_owner
->GtkGetTreeView(), &x
, &y
);
3554 event
.SetPosition(x
, y
);
3555 if (!m_owner
->HandleWindowEvent( event
))
3558 if (!event
.IsAllowed())
3561 wxDataObject
*obj
= event
.GetDataObject();
3565 m_dragDataObject
= obj
;
3571 wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource
*WXUNUSED(drag_source
),
3572 GtkTreePath
*WXUNUSED(path
))
3577 gboolean
wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource
*WXUNUSED(drag_source
),
3578 GtkTreePath
*path
, GtkSelectionData
*selection_data
)
3580 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3584 GdkAtom target
= gtk_selection_data_get_target(selection_data
);
3585 if (!m_dragDataObject
->IsSupported(target
))
3588 size_t size
= m_dragDataObject
->GetDataSize(target
);
3592 void *buf
= malloc( size
);
3594 gboolean res
= FALSE
;
3595 if (m_dragDataObject
->GetDataHere(target
, buf
))
3599 gtk_selection_data_set(selection_data
, target
,
3600 8, (const guchar
*) buf
, size
);
3609 wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3611 GtkSelectionData
*selection_data
)
3613 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3617 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
3618 event
.SetEventObject( m_owner
);
3619 event
.SetItem( item
);
3620 event
.SetModel( m_wx_model
);
3621 event
.SetDataFormat(gtk_selection_data_get_target(selection_data
));
3622 event
.SetDataSize(gtk_selection_data_get_length(selection_data
));
3623 event
.SetDataBuffer(const_cast<guchar
*>(gtk_selection_data_get_data(selection_data
)));
3624 if (!m_owner
->HandleWindowEvent( event
))
3627 if (!event
.IsAllowed())
3634 wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3636 GtkSelectionData
*selection_data
)
3638 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3642 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
3643 event
.SetEventObject( m_owner
);
3644 event
.SetItem( item
);
3645 event
.SetModel( m_wx_model
);
3646 event
.SetDataFormat(gtk_selection_data_get_target(selection_data
));
3647 if (!m_owner
->HandleWindowEvent( event
))
3650 if (!event
.IsAllowed())
3656 // notifications from wxDataViewModel
3658 bool wxDataViewCtrlInternal::Cleared()
3673 void wxDataViewCtrlInternal::Resort()
3675 if (!m_wx_model
->IsVirtualListModel())
3681 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3683 if (!m_wx_model
->IsVirtualListModel())
3685 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3686 wxCHECK_MSG(parent_node
, false,
3687 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3689 wxDataViewItemArray modelSiblings
;
3690 m_wx_model
->GetChildren(parent
, modelSiblings
);
3691 const int modelSiblingsSize
= modelSiblings
.size();
3693 int posInModel
= modelSiblings
.Index(item
, /*fromEnd=*/true);
3694 wxCHECK_MSG( posInModel
!= wxNOT_FOUND
, false, "adding non-existent item?" );
3696 const wxGtkTreeModelChildren
& nodeSiblings
= parent_node
->GetChildren();
3697 const int nodeSiblingsSize
= nodeSiblings
.size();
3701 if ( posInModel
== modelSiblingsSize
- 1 )
3703 nodePos
= nodeSiblingsSize
;
3705 else if ( modelSiblingsSize
== nodeSiblingsSize
+ 1 )
3707 // This is the simple case when our node tree already matches the
3708 // model and only this one item is missing.
3709 nodePos
= posInModel
;
3713 // It's possible that a larger discrepancy between the model and
3714 // our realization exists. This can happen e.g. when adding a bunch
3715 // of items to the model and then calling ItemsAdded() just once
3716 // afterwards. In this case, we must find the right position by
3717 // looking at sibling items.
3719 // append to the end if we won't find a better position:
3720 nodePos
= nodeSiblingsSize
;
3722 for ( int nextItemPos
= posInModel
+ 1;
3723 nextItemPos
< modelSiblingsSize
;
3726 int nextNodePos
= parent_node
->FindChildByItem(modelSiblings
[nextItemPos
]);
3727 if ( nextNodePos
!= wxNOT_FOUND
)
3729 nodePos
= nextNodePos
;
3735 if (m_wx_model
->IsContainer( item
))
3736 parent_node
->InsertNode( new wxGtkTreeModelNode( parent_node
, item
, this ), nodePos
);
3738 parent_node
->InsertLeaf( item
.GetID(), nodePos
);
3746 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3748 if (!m_wx_model
->IsVirtualListModel())
3750 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3751 wxASSERT_MSG(parent_node
,
3752 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3754 parent_node
->DeleteChild( item
.GetID() );
3762 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
3764 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3765 event
.SetEventObject( m_owner
);
3766 event
.SetModel( m_owner
->GetModel() );
3767 event
.SetItem( item
);
3768 m_owner
->HandleWindowEvent( event
);
3773 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int view_column
)
3775 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3776 event
.SetEventObject( m_owner
);
3777 event
.SetModel( m_owner
->GetModel() );
3778 event
.SetColumn( view_column
);
3779 event
.SetDataViewColumn( GetOwner()->GetColumn(view_column
) );
3780 event
.SetItem( item
);
3781 m_owner
->HandleWindowEvent( event
);
3788 GtkTreeModelFlags
wxDataViewCtrlInternal::get_flags()
3792 if ( m_wx_model
->IsListModel() )
3793 flags
|= GTK_TREE_MODEL_LIST_ONLY
;
3795 if ( !m_wx_model
->IsVirtualListModel() )
3796 flags
|= GTK_TREE_MODEL_ITERS_PERSIST
;
3798 return GtkTreeModelFlags(flags
);
3801 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
3804 if (m_wx_model
->IsVirtualListModel())
3806 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3808 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
3810 if (i
>= wx_model
->GetCount())
3813 iter
->stamp
= m_gtk_model
->stamp
;
3814 // user_data is just the index +1
3815 iter
->user_data
= (gpointer
) (i
+1);
3821 int depth
= gtk_tree_path_get_depth( path
);
3823 wxGtkTreeModelNode
*node
= m_root
;
3826 for (i
= 0; i
< depth
; i
++)
3828 BuildBranch( node
);
3830 gint pos
= gtk_tree_path_get_indices (path
)[i
];
3831 if (pos
< 0) return FALSE
;
3832 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
3834 void* id
= node
->GetChildren().Item( (size_t) pos
);
3838 iter
->stamp
= m_gtk_model
->stamp
;
3839 iter
->user_data
= id
;
3843 size_t count
= node
->GetNodes().GetCount();
3845 for (pos2
= 0; pos2
< count
; pos2
++)
3847 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
3848 if (child_node
->GetItem().GetID() == id
)
3860 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
3862 // When this is called from ItemDeleted(), the item is already
3863 // deleted in the model.
3865 GtkTreePath
*retval
= gtk_tree_path_new ();
3867 if (m_wx_model
->IsVirtualListModel())
3869 // iter is root, add nothing
3870 if (!iter
->user_data
)
3873 // user_data is just the index +1
3874 int i
= ( (wxUIntPtr
) iter
->user_data
) -1;
3875 gtk_tree_path_append_index (retval
, i
);
3879 void *id
= iter
->user_data
;
3881 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
3884 int pos
= node
->GetChildren().Index( id
);
3886 gtk_tree_path_prepend_index( retval
, pos
);
3888 id
= node
->GetItem().GetID();
3889 node
= node
->GetParent();
3896 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
3898 if (m_wx_model
->IsVirtualListModel())
3900 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3902 // user_data is just the index +1
3903 int n
= ( (wxUIntPtr
) iter
->user_data
) -1;
3907 iter
->user_data
= NULL
;
3911 if (n
>= (int) wx_model
->GetCount()-1)
3913 iter
->user_data
= NULL
;
3917 // user_data is just the index +1 (+2 because we need the next)
3918 iter
->user_data
= (gpointer
) (n
+2);
3922 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
3923 if( parent
== NULL
)
3925 iter
->user_data
= NULL
;
3929 int pos
= parent
->GetChildren().Index( iter
->user_data
);
3931 if (pos
== (int) parent
->GetChildCount()-1)
3933 iter
->user_data
= NULL
;
3937 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
3943 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
3945 if (m_wx_model
->IsVirtualListModel())
3947 // this is a list, nodes have no children
3951 iter
->stamp
= m_gtk_model
->stamp
;
3952 iter
->user_data
= (gpointer
) 1;
3960 if (m_root
->GetChildCount() == 0) return FALSE
;
3961 iter
->stamp
= m_gtk_model
->stamp
;
3962 iter
->user_data
= (gpointer
) m_root
->GetChildren().Item( 0 );
3967 wxDataViewItem item
;
3969 item
= wxDataViewItem( (void*) parent
->user_data
);
3971 if (!m_wx_model
->IsContainer( item
))
3974 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3975 wxASSERT_MSG(parent_node
,
3976 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3978 BuildBranch( parent_node
);
3980 if (parent_node
->GetChildCount() == 0)
3983 iter
->stamp
= m_gtk_model
->stamp
;
3984 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
3990 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
3992 if (m_wx_model
->IsVirtualListModel())
3994 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3997 return (wx_model
->GetCount() > 0);
3999 // this is a list, nodes have no children
4005 return (m_root
->GetChildCount() > 0);
4007 wxDataViewItem
item( (void*) iter
->user_data
);
4009 bool is_container
= m_wx_model
->IsContainer( item
);
4014 wxGtkTreeModelNode
*node
= FindNode( iter
);
4016 "Did you forget a call to ItemAdded()? The iterator is unknown to the wxGtkTreeModel");
4018 BuildBranch( node
);
4020 return (node
->GetChildCount() > 0);
4024 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
4026 if (m_wx_model
->IsVirtualListModel())
4028 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
4031 return (gint
) wx_model
->GetCount();
4038 return m_root
->GetChildCount();
4040 wxDataViewItem
item( (void*) iter
->user_data
);
4042 if (!m_wx_model
->IsContainer( item
))
4045 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
4046 wxASSERT_MSG(parent_node
,
4047 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
4049 BuildBranch( parent_node
);
4051 return parent_node
->GetChildCount();
4055 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
4057 if (m_wx_model
->IsVirtualListModel())
4059 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
4067 if (n
>= (gint
) wx_model
->GetCount())
4070 iter
->stamp
= m_gtk_model
->stamp
;
4071 // user_data is just the index +1
4072 iter
->user_data
= (gpointer
) (n
+1);
4079 if (parent
) id
= (void*) parent
->user_data
;
4080 wxDataViewItem
item( id
);
4082 if (!m_wx_model
->IsContainer( item
))
4085 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
4086 wxASSERT_MSG(parent_node
,
4087 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
4089 BuildBranch( parent_node
);
4091 iter
->stamp
= m_gtk_model
->stamp
;
4092 iter
->user_data
= parent_node
->GetChildren().Item( n
);
4098 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
4100 if (m_wx_model
->IsVirtualListModel())
4106 wxGtkTreeModelNode
*node
= FindParentNode( child
);
4110 iter
->stamp
= m_gtk_model
->stamp
;
4111 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
4117 // item can be deleted already in the model
4118 int wxDataViewCtrlInternal::GetIndexOf( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
4120 if (m_wx_model
->IsVirtualListModel())
4122 return wxPtrToUInt(item
.GetID()) - 1;
4126 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
4127 wxGtkTreeModelChildren
&children
= parent_node
->GetChildren();
4129 for (j
= 0; j
< children
.GetCount(); j
++)
4131 if (children
[j
] == item
.GetID())
4139 static wxGtkTreeModelNode
*
4140 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
4146 list
.DeleteContents( true );
4147 wxDataViewItem
it( item
);
4151 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
4152 list
.Insert( pItem
);
4153 it
= model
->GetParent( it
);
4156 wxGtkTreeModelNode
* node
= treeNode
;
4157 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
4159 if( node
&& node
->GetNodes().GetCount() != 0 )
4161 int len
= node
->GetNodes().GetCount();
4162 wxGtkTreeModelNodes
&nodes
= node
->GetNodes();
4164 for( ; j
< len
; j
++)
4166 if( nodes
[j
]->GetItem() == *(n
->GetData()))
4185 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
4190 wxDataViewItem
item( (void*) iter
->user_data
);
4194 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
4199 wxLogDebug( "Not found %p", iter->user_data );
4203 // TODO: remove this code
4209 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
4214 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
4219 wxLogDebug( "Not found %p", item.GetID() );
4223 // TODO: remove this code
4229 static wxGtkTreeModelNode
*
4230 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
4236 list
.DeleteContents( true );
4240 wxDataViewItem
it( model
->GetParent( item
) );
4243 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
4244 list
.Insert( pItem
);
4245 it
= model
->GetParent( it
);
4248 wxGtkTreeModelNode
* node
= treeNode
;
4249 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
4251 if( node
&& node
->GetNodes().GetCount() != 0 )
4253 int len
= node
->GetNodes().GetCount();
4254 wxGtkTreeModelNodes nodes
= node
->GetNodes();
4256 for( ; j
< len
; j
++)
4258 if( nodes
[j
]->GetItem() == *(n
->GetData()))
4273 //Examine whether the node is item's parent node
4274 int len
= node
->GetChildCount();
4275 for( int i
= 0; i
< len
; i
++ )
4277 if( node
->GetChildren().Item( i
) == item
.GetID() )
4283 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
4288 wxDataViewItem
item( (void*) iter
->user_data
);
4292 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
4295 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
4300 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
4303 //-----------------------------------------------------------------------------
4304 // wxDataViewCtrl signal callbacks
4305 //-----------------------------------------------------------------------------
4308 wxdataview_selection_changed_callback( GtkTreeSelection
* WXUNUSED(selection
), wxDataViewCtrl
*dv
)
4310 if (!gtk_widget_get_realized(dv
->m_widget
))
4313 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
4314 event
.SetItem( dv
->GetSelection() );
4315 event
.SetModel( dv
->GetModel() );
4316 dv
->HandleWindowEvent( event
);
4320 wxdataview_row_activated_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreePath
*path
,
4321 GtkTreeViewColumn
*WXUNUSED(column
), wxDataViewCtrl
*dv
)
4323 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
4325 wxDataViewItem
item(dv
->GTKPathToItem(path
));
4326 event
.SetItem( item
);
4327 event
.SetModel( dv
->GetModel() );
4328 dv
->HandleWindowEvent( event
);
4332 wxdataview_test_expand_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4333 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4335 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
4337 wxDataViewItem
item( (void*) iter
->user_data
);;
4338 event
.SetItem( item
);
4339 event
.SetModel( dv
->GetModel() );
4340 dv
->HandleWindowEvent( event
);
4342 return !event
.IsAllowed();
4346 wxdataview_row_expanded_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4347 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4349 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
4351 wxDataViewItem
item( (void*) iter
->user_data
);;
4352 event
.SetItem( item
);
4353 event
.SetModel( dv
->GetModel() );
4354 dv
->HandleWindowEvent( event
);
4358 wxdataview_test_collapse_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4359 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4361 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
4363 wxDataViewItem
item( (void*) iter
->user_data
);;
4364 event
.SetItem( item
);
4365 event
.SetModel( dv
->GetModel() );
4366 dv
->HandleWindowEvent( event
);
4368 return !event
.IsAllowed();
4372 wxdataview_row_collapsed_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4373 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4375 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
4377 wxDataViewItem
item( (void*) iter
->user_data
);;
4378 event
.SetItem( item
);
4379 event
.SetModel( dv
->GetModel() );
4380 dv
->HandleWindowEvent( event
);
4383 //-----------------------------------------------------------------------------
4385 //-----------------------------------------------------------------------------
4387 void wxDataViewCtrl::AddChildGTK(wxWindowGTK
* child
)
4389 GtkWidget
* treeview
= GtkGetTreeView();
4391 // Insert widget in GtkTreeView
4392 if (gtk_widget_get_realized(treeview
))
4393 gtk_widget_set_parent_window( child
->m_widget
,
4394 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
4395 gtk_widget_set_parent( child
->m_widget
, treeview
);
4399 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
4400 GtkAllocation
*WXUNUSED(gtk_alloc
),
4401 wxDataViewCtrl
*win
)
4403 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
4406 wxWindow
*child
= node
->GetData();
4409 gtk_widget_size_request( child
->m_widget
, &req
);
4411 GtkAllocation alloc
;
4412 alloc
.x
= child
->m_x
;
4413 alloc
.y
= child
->m_y
;
4414 alloc
.width
= child
->m_width
;
4415 alloc
.height
= child
->m_height
;
4416 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
4418 node
= node
->GetNext();
4423 //-----------------------------------------------------------------------------
4424 // "motion_notify_event"
4425 //-----------------------------------------------------------------------------
4428 gtk_dataview_motion_notify_callback( GtkWidget
*WXUNUSED(widget
),
4429 GdkEventMotion
*gdk_event
,
4430 wxDataViewCtrl
*dv
)
4432 if (gdk_event
->is_hint
)
4436 GdkModifierType state
;
4437 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
4443 GtkTreeViewColumn
*column
= NULL
;
4446 if (gtk_tree_view_get_path_at_pos(
4447 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4448 (int) gdk_event
->x
, (int) gdk_event
->y
,
4457 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4465 //-----------------------------------------------------------------------------
4466 // "button_press_event"
4467 //-----------------------------------------------------------------------------
4470 gtk_dataview_button_press_callback( GtkWidget
*WXUNUSED(widget
),
4471 GdkEventButton
*gdk_event
,
4472 wxDataViewCtrl
*dv
)
4474 if ((gdk_event
->button
== 3) && (gdk_event
->type
== GDK_BUTTON_PRESS
))
4477 GtkTreeViewColumn
*column
= NULL
;
4480 gtk_tree_view_get_path_at_pos
4482 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4483 (int) gdk_event
->x
, (int) gdk_event
->y
,
4490 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, dv
->GetId() );
4492 event
.SetItem(dv
->GTKPathToItem(path
));
4493 event
.SetModel( dv
->GetModel() );
4494 return dv
->HandleWindowEvent( event
);
4500 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
4502 wxDataViewCtrl::~wxDataViewCtrl()
4504 // Stop editing before destroying the control to remove any event handlers
4505 // which are added when editing started: if we didn't do this, the base
4506 // class dtor would assert as it checks for any leftover handlers.
4509 GtkTreeViewColumn
*col
;
4510 gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview
), NULL
, &col
);
4512 wxDataViewColumn
* const wxcol
= FromGTKColumn(col
);
4515 // This won't do anything if we're not editing it
4516 wxcol
->GetRenderer()->CancelEditing();
4525 void wxDataViewCtrl::Init()
4529 m_cols
.DeleteContents( true );
4531 m_uniformRowHeight
= -1;
4534 bool wxDataViewCtrl::Create(wxWindow
*parent
,
4539 const wxValidator
& validator
,
4540 const wxString
& name
)
4542 if (!PreCreation( parent
, pos
, size
) ||
4543 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
4545 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
4549 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
4550 g_object_ref(m_widget
);
4552 GTKScrolledWindowSetBorder(m_widget
, style
);
4554 m_treeview
= gtk_tree_view_new();
4555 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
4557 m_focusWidget
= GTK_WIDGET(m_treeview
);
4559 g_signal_connect (m_treeview
, "size_allocate",
4560 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
4563 if (!gtk_check_version(2,6,0))
4565 bool fixed
= (style
& wxDV_VARIABLE_LINE_HEIGHT
) == 0;
4566 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4570 if (style
& wxDV_MULTIPLE
)
4572 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4573 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
4576 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
4579 if (!gtk_check_version(2,10,0))
4581 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
4583 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
4584 (style
& wxDV_VERT_RULES
) != 0)
4585 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
4586 else if (style
& wxDV_VERT_RULES
)
4587 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
4588 else if (style
& wxDV_HORIZ_RULES
)
4589 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
4591 if (grid
!= GTK_TREE_VIEW_GRID_LINES_NONE
)
4592 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
4596 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_ROW_LINES
) != 0 );
4598 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
4599 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
4600 gtk_widget_show (m_treeview
);
4602 m_parent
->DoAddChild( this );
4606 GtkEnableSelectionEvents();
4608 g_signal_connect_after (m_treeview
, "row-activated",
4609 G_CALLBACK (wxdataview_row_activated_callback
), this);
4611 g_signal_connect (m_treeview
, "test-collapse-row",
4612 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
4614 g_signal_connect_after (m_treeview
, "row-collapsed",
4615 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
4617 g_signal_connect (m_treeview
, "test-expand-row",
4618 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
4620 g_signal_connect_after (m_treeview
, "row-expanded",
4621 G_CALLBACK (wxdataview_row_expanded_callback
), this);
4623 g_signal_connect (m_treeview
, "motion_notify_event",
4624 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
4626 g_signal_connect (m_treeview
, "button_press_event",
4627 G_CALLBACK (gtk_dataview_button_press_callback
), this);
4632 wxDataViewItem
wxDataViewCtrl::GTKPathToItem(GtkTreePath
*path
) const
4635 return wxDataViewItem(path
&& m_internal
->get_iter(&iter
, path
)
4640 void wxDataViewCtrl::OnInternalIdle()
4642 wxWindow::OnInternalIdle();
4644 m_internal
->OnInternalIdle();
4646 unsigned int cols
= GetColumnCount();
4648 for (i
= 0; i
< cols
; i
++)
4650 wxDataViewColumn
*col
= GetColumn( i
);
4651 col
->OnInternalIdle();
4654 if (m_ensureVisibleDefered
.IsOk())
4656 ExpandAncestors(m_ensureVisibleDefered
);
4658 iter
.user_data
= (gpointer
) m_ensureVisibleDefered
.GetID();
4659 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4660 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
4661 m_ensureVisibleDefered
= wxDataViewItem(0);
4665 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4667 wxDELETE(m_internal
);
4669 if (!wxDataViewCtrlBase::AssociateModel( model
))
4673 if (!gtk_check_version(2,6,0))
4675 bool fixed
= (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
) == 0) || (model
->IsVirtualListModel()));
4676 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4680 m_internal
= new wxDataViewCtrlInternal( this, model
);
4685 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4687 return m_internal
->EnableDragSource( format
);
4690 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4692 return m_internal
->EnableDropTarget( format
);
4695 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4697 if (!wxDataViewCtrlBase::AppendColumn(col
))
4700 m_cols
.Append( col
);
4703 if (!gtk_check_version(2,6,0))
4705 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4706 GTK_TREE_VIEW_COLUMN_FIXED
)
4707 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4711 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
4712 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4717 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4719 if (!wxDataViewCtrlBase::PrependColumn(col
))
4722 m_cols
.Insert( col
);
4725 if (!gtk_check_version(2,6,0))
4727 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4728 GTK_TREE_VIEW_COLUMN_FIXED
)
4729 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4733 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4734 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
4739 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4741 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4744 m_cols
.Insert( pos
, col
);
4747 if (!gtk_check_version(2,6,0))
4749 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4750 GTK_TREE_VIEW_COLUMN_FIXED
)
4751 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4755 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4756 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), pos
);
4761 unsigned int wxDataViewCtrl::GetColumnCount() const
4763 return m_cols
.GetCount();
4766 wxDataViewColumn
* wxDataViewCtrl::FromGTKColumn(GtkTreeViewColumn
*gtk_col
) const
4771 wxDataViewColumnList::const_iterator iter
;
4772 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4774 wxDataViewColumn
*col
= *iter
;
4775 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
4781 wxFAIL_MSG( "No matching column?" );
4786 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
4788 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
4790 return FromGTKColumn(gtk_col
);
4793 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4795 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4796 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
4798 m_cols
.DeleteObject( column
);
4803 bool wxDataViewCtrl::ClearColumns()
4805 wxDataViewColumnList::iterator iter
;
4806 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4808 wxDataViewColumn
*col
= *iter
;
4809 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4810 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4818 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4820 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
4822 wxGtkList
list(gtk_tree_view_get_columns(GTK_TREE_VIEW(m_treeview
)));
4824 return g_list_index( list
, (gconstpointer
) gtk_column
);
4827 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4829 return m_internal
->GetDataViewSortColumn();
4832 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4835 iter
.user_data
= item
.GetID();
4836 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4837 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
4840 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4843 iter
.user_data
= item
.GetID();
4844 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4845 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
4848 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4851 iter
.user_data
= item
.GetID();
4852 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4853 return gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview
), path
);
4856 wxDataViewItem
wxDataViewCtrl::DoGetCurrentItem() const
4858 // The tree doesn't have any current item if it hadn't been created yet but
4859 // it's arguably not an error to call this function in this case so just
4860 // return an invalid item without asserting.
4862 return wxDataViewItem();
4865 gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview
), path
.ByRef(), NULL
);
4867 return GTKPathToItem(path
);
4870 void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem
& item
)
4872 wxCHECK_RET( m_treeview
,
4873 "Current item can't be set before creating the control." );
4875 // We need to make sure the model knows about this item or the path would
4876 // be invalid and gtk_tree_view_set_cursor() would silently do nothing.
4877 ExpandAncestors(item
);
4879 // We also need to preserve the existing selection from changing.
4880 // Unfortunately the only way to do it seems to use our own selection
4881 // function and forbid any selection changes during set cursor call.
4882 wxGtkTreeSelectionLock
4883 lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview
)));
4885 // Do move the cursor now.
4887 iter
.user_data
= item
.GetID();
4888 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4890 gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview
), path
, NULL
, FALSE
);
4893 void wxDataViewCtrl::StartEditor(const wxDataViewItem
& item
, unsigned int column
)
4895 wxCHECK_RET( m_treeview
,
4896 "Current item can't be set before creating the control." );
4898 // We need to make sure the model knows about this item or the path would
4899 // be invalid and gtk_tree_view_set_cursor() would silently do nothing.
4900 ExpandAncestors(item
);
4902 wxDataViewColumn
*dvcolumn
= GetColumn(column
);
4903 wxASSERT_MSG(dvcolumn
, "Could not retrieve column");
4904 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(dvcolumn
->GetGtkHandle());
4906 // We also need to preserve the existing selection from changing.
4907 // Unfortunately the only way to do it seems to use our own selection
4908 // function and forbid any selection changes during set cursor call.
4909 wxGtkTreeSelectionLock
4910 lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview
)));
4912 // Do move the cursor now.
4914 iter
.user_data
= item
.GetID();
4915 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4917 gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview
), path
, gcolumn
, TRUE
);
4920 int wxDataViewCtrl::GetSelectedItemsCount() const
4922 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4924 return gtk_tree_selection_count_selected_rows(selection
);
4927 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4931 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4932 if (HasFlag(wxDV_MULTIPLE
))
4934 GtkTreeModel
*model
;
4935 wxGtkTreePathList
list(gtk_tree_selection_get_selected_rows(selection
, &model
));
4937 for ( GList
* current
= list
; current
; current
= g_list_next(current
) )
4939 GtkTreePath
*path
= (GtkTreePath
*) current
->data
;
4941 sel
.Add(GTKPathToItem(path
));
4947 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
4949 sel
.Add( wxDataViewItem(iter
.user_data
) );
4956 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4958 GtkDisableSelectionEvents();
4960 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4962 gtk_tree_selection_unselect_all( selection
);
4964 wxDataViewItem last_parent
;
4967 for (i
= 0; i
< sel
.GetCount(); i
++)
4969 wxDataViewItem item
= sel
[i
];
4970 wxDataViewItem parent
= GetModel()->GetParent( item
);
4973 if (parent
!= last_parent
)
4974 ExpandAncestors(item
);
4976 last_parent
= parent
;
4979 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4980 iter
.user_data
= (gpointer
) item
.GetID();
4981 gtk_tree_selection_select_iter( selection
, &iter
);
4984 GtkEnableSelectionEvents();
4987 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4989 ExpandAncestors(item
);
4991 GtkDisableSelectionEvents();
4993 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4996 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4997 iter
.user_data
= (gpointer
) item
.GetID();
4998 gtk_tree_selection_select_iter( selection
, &iter
);
5000 GtkEnableSelectionEvents();
5003 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
5005 GtkDisableSelectionEvents();
5007 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5010 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
5011 iter
.user_data
= (gpointer
) item
.GetID();
5012 gtk_tree_selection_unselect_iter( selection
, &iter
);
5014 GtkEnableSelectionEvents();
5017 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
5019 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5022 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
5023 iter
.user_data
= (gpointer
) item
.GetID();
5025 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
5028 void wxDataViewCtrl::SelectAll()
5030 GtkDisableSelectionEvents();
5032 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5034 gtk_tree_selection_select_all( selection
);
5036 GtkEnableSelectionEvents();
5039 void wxDataViewCtrl::UnselectAll()
5041 GtkDisableSelectionEvents();
5043 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5045 gtk_tree_selection_unselect_all( selection
);
5047 GtkEnableSelectionEvents();
5050 void wxDataViewCtrl::EnsureVisible(const wxDataViewItem
& item
,
5051 const wxDataViewColumn
*WXUNUSED(column
))
5053 m_ensureVisibleDefered
= item
;
5054 ExpandAncestors(item
);
5057 iter
.user_data
= (gpointer
) item
.GetID();
5058 wxGtkTreePath
path(m_internal
->get_path( &iter
));
5059 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
5062 void wxDataViewCtrl::HitTest(const wxPoint
& point
,
5063 wxDataViewItem
& item
,
5064 wxDataViewColumn
*& column
) const
5066 // gtk_tree_view_get_dest_row_at_pos() is the right one. But it does not tell the column.
5067 // gtk_tree_view_get_path_at_pos() is the wrong function. It doesn't mind the header but returns column.
5068 // See http://mail.gnome.org/archives/gtkmm-list/2005-January/msg00080.html
5069 // So we have to use both of them.
5070 // Friedrich Haase 2010-9-20
5071 wxGtkTreePath path
, pathScratch
;
5072 GtkTreeViewColumn
* GtkColumn
= NULL
;
5073 GtkTreeViewDropPosition pos
= GTK_TREE_VIEW_DROP_INTO_OR_AFTER
;
5077 // cannot directly call GtkGetTreeView(), HitTest is const and so is this pointer
5078 wxDataViewCtrl
* ctrl
= (wxDataViewCtrl
*)this; // ugly workaround, ctrl is NOT const
5079 GtkTreeView
* treeView
= GTK_TREE_VIEW(ctrl
->GtkGetTreeView());
5081 // is there possibly a better suited function to get the column?
5082 gtk_tree_view_get_path_at_pos( // and this is the wrong call but it delivers the column
5084 (int) point
.x
, (int) point
.y
,
5085 pathScratch
.ByRef(),
5086 &GtkColumn
, // here we get the GtkColumn
5090 if ( GtkColumn
!= NULL
)
5092 // we got GTK column
5093 // the right call now which takes the header into account
5094 gtk_tree_view_get_dest_row_at_pos( treeView
, (int) point
.x
, (int) point
.y
, path
.ByRef(), &pos
);
5097 item
= wxDataViewItem(GTKPathToItem(path
));
5098 // else we got a GTK column but the position is not over an item, e.g. below last item
5099 for ( unsigned int i
=0, cols
=GetColumnCount(); i
<cols
; ++i
) // search the wx column
5101 wxDataViewColumn
* col
= GetColumn(i
);
5102 if ( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == GtkColumn
)
5104 column
= col
; // here we get the wx column
5109 // else no column and thus no item, both null
5113 wxDataViewCtrl::GetItemRect(const wxDataViewItem
& WXUNUSED(item
),
5114 const wxDataViewColumn
*WXUNUSED(column
)) const
5119 bool wxDataViewCtrl::SetRowHeight(int rowHeight
)
5121 m_uniformRowHeight
= rowHeight
;
5125 void wxDataViewCtrl::DoSetExpanderColumn()
5127 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
5128 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
5131 void wxDataViewCtrl::DoSetIndent()
5135 void wxDataViewCtrl::GtkDisableSelectionEvents()
5137 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5138 g_signal_handlers_disconnect_by_func( selection
,
5139 (gpointer
) (wxdataview_selection_changed_callback
), this);
5142 void wxDataViewCtrl::GtkEnableSelectionEvents()
5144 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5145 g_signal_connect_after (selection
, "changed",
5146 G_CALLBACK (wxdataview_selection_changed_callback
), this);
5149 // ----------------------------------------------------------------------------
5150 // visual attributes stuff
5151 // ----------------------------------------------------------------------------
5155 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
5157 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
5160 void wxDataViewCtrl::DoApplyWidgetStyle(GtkRcStyle
*style
)
5162 wxDataViewCtrlBase::DoApplyWidgetStyle(style
);
5163 gtk_widget_modify_style(m_treeview
, style
);
5166 #endif // !wxUSE_GENERICDATAVIEWCTRL
5168 #endif // wxUSE_DATAVIEWCTRL