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 wxScopedCharBuffer buf
;
2574 if ( m_label
.empty() )
2575 buf
= wxScopedCharBuffer::CreateNonOwned("");
2577 buf
= wxGTK_CONV_FONT(m_label
, GetOwner()->GetOwner()->GetFont());
2579 g_value_set_string( &gvalue
, buf
);
2580 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2581 g_value_unset( &gvalue
);
2584 m_needsToSetLabel
= false;
2585 #endif // !wxUSE_UNICODE
2588 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
2591 if (!gtk_check_version(2,6,0))
2594 if ( m_needsToSetLabel
)
2596 #endif // !wxUSE_UNICODE
2598 gint tmp
= (long) value
;
2599 GValue gvalue
= { 0, };
2600 g_value_init( &gvalue
, G_TYPE_INT
);
2601 g_value_set_int( &gvalue
, tmp
);
2602 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
2603 g_value_unset( &gvalue
);
2608 m_value
= (long) value
;
2610 if (m_value
< 0) m_value
= 0;
2611 if (m_value
> 100) m_value
= 100;
2617 bool wxDataViewProgressRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2622 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
2624 double pct
= (double)m_value
/ 100.0;
2626 bar
.width
= (int)(cell
.width
* pct
);
2627 dc
->SetPen( *wxTRANSPARENT_PEN
);
2628 dc
->SetBrush( *wxBLUE_BRUSH
);
2629 dc
->DrawRectangle( bar
);
2631 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
2632 dc
->SetPen( *wxBLACK_PEN
);
2633 dc
->DrawRectangle( cell
);
2638 wxSize
wxDataViewProgressRenderer::GetSize() const
2640 return wxSize(40,12);
2643 // -------------------------------------
2644 // wxDataViewChoiceRenderer
2645 // -------------------------------------
2647 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
&choices
,
2648 wxDataViewCellMode mode
, int alignment
) :
2649 wxDataViewCustomRenderer( "string", mode
, alignment
, true )
2651 m_choices
= choices
;
2654 if (!gtk_check_version(2,6,0))
2656 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_combo_new();
2658 GtkListStore
*store
= gtk_list_store_new( 1, G_TYPE_STRING
);
2659 for (size_t n
= 0; n
< m_choices
.GetCount(); n
++)
2661 gtk_list_store_insert_with_values(
2663 static_cast<const char *>(m_choices
[n
].utf8_str()), -1 );
2666 g_object_set (m_renderer
,
2672 bool editable
= (mode
& wxDATAVIEW_CELL_EDITABLE
);
2673 g_object_set (m_renderer
, "editable", editable
, NULL
);
2675 SetAlignment(alignment
);
2677 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2684 // Use custom cell code
2685 wxDataViewCustomRenderer::Init(mode
, alignment
);
2689 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
2691 RenderText( m_data
, 0, rect
, dc
, state
);
2695 wxSize
wxDataViewChoiceRenderer::GetSize() const
2697 return wxSize(70,20);
2700 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
2704 if (!gtk_check_version(2,6,0))
2706 GValue gvalue
= { 0, };
2707 g_value_init( &gvalue
, G_TYPE_STRING
);
2708 g_value_set_string(&gvalue
,
2709 wxGTK_CONV_FONT(value
.GetString(),
2710 GetOwner()->GetOwner()->GetFont()));
2711 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2712 g_value_unset( &gvalue
);
2716 m_data
= value
.GetString();
2721 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
2724 if (!gtk_check_version(2,6,0))
2726 GValue gvalue
= { 0, };
2727 g_value_init( &gvalue
, G_TYPE_STRING
);
2728 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2729 wxString temp
= wxGTK_CONV_BACK_FONT(g_value_get_string(&gvalue
),
2730 GetOwner()->GetOwner()->GetFont());
2731 g_value_unset( &gvalue
);
2734 //wxPrintf( "temp %s\n", temp );
2735 // TODO: remove this code
2744 void wxDataViewChoiceRenderer::SetAlignment( int align
)
2746 wxDataViewCustomRenderer::SetAlignment(align
);
2748 if (gtk_check_version(2,10,0))
2751 // horizontal alignment:
2752 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2753 if (align
& wxALIGN_RIGHT
)
2754 pangoAlign
= PANGO_ALIGN_RIGHT
;
2755 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2756 pangoAlign
= PANGO_ALIGN_CENTER
;
2758 GValue gvalue
= { 0, };
2759 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2760 g_value_set_enum( &gvalue
, pangoAlign
);
2761 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2762 g_value_unset( &gvalue
);
2765 // ----------------------------------------------------------------------------
2766 // wxDataViewChoiceByIndexRenderer
2767 // ----------------------------------------------------------------------------
2769 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
2770 wxDataViewCellMode mode
, int alignment
) :
2771 wxDataViewChoiceRenderer( choices
, mode
, alignment
)
2775 void wxDataViewChoiceByIndexRenderer::GtkOnTextEdited(const char *itempath
, const wxString
& str
)
2777 wxVariant
value( (long) GetChoices().Index( str
) );
2779 if (!Validate( value
))
2783 item(GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(itempath
)));
2785 GtkOnCellChanged(value
, item
, GetOwner()->GetModelColumn());
2788 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant
&value
)
2790 wxVariant string_value
= GetChoice( value
.GetLong() );
2791 return wxDataViewChoiceRenderer::SetValue( string_value
);
2794 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant
&value
) const
2796 wxVariant string_value
;
2797 if (!wxDataViewChoiceRenderer::GetValue( string_value
))
2800 value
= (long) GetChoices().Index( string_value
.GetString() );
2804 // ---------------------------------------------------------
2805 // wxDataViewIconTextRenderer
2806 // ---------------------------------------------------------
2808 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
2810 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer
2812 const wxString
&varianttype
,
2813 wxDataViewCellMode mode
,
2816 : wxDataViewTextRenderer(varianttype
, mode
, align
)
2818 m_rendererIcon
= gtk_cell_renderer_pixbuf_new();
2821 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2825 void wxDataViewIconTextRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
2827 // add the icon renderer first
2828 gtk_tree_view_column_pack_start(column
, m_rendererIcon
, FALSE
/* !expand */);
2830 // add the text renderer too
2831 wxDataViewRenderer::GtkPackIntoColumn(column
);
2834 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
2838 SetTextValue(m_value
.GetText());
2839 SetPixbufProp(m_rendererIcon
, m_value
.GetIcon().GetPixbuf());
2844 bool wxDataViewIconTextRenderer::GetValue(wxVariant
& value
) const
2847 if ( !GetTextValue(str
) )
2850 // user doesn't have any way to edit the icon so leave it unchanged
2851 value
<< wxDataViewIconText(str
, m_value
.GetIcon());
2857 wxDataViewIconTextRenderer::GtkOnCellChanged(const wxVariant
& value
,
2858 const wxDataViewItem
& item
,
2861 // we receive just the text part of our value as it's the only one which
2862 // can be edited, but we need the full wxDataViewIconText value for the
2864 wxVariant valueIconText
;
2865 valueIconText
<< wxDataViewIconText(value
.GetString(), m_value
.GetIcon());
2866 wxDataViewTextRenderer::GtkOnCellChanged(valueIconText
, item
, col
);
2869 // ---------------------------------------------------------
2871 // ---------------------------------------------------------
2875 gtk_dataview_header_button_press_callback( GtkWidget
*WXUNUSED(widget
),
2876 GdkEventButton
*gdk_event
,
2877 wxDataViewColumn
*column
)
2879 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
2882 if (gdk_event
->button
== 1)
2884 gs_lastLeftClickHeader
= column
;
2886 wxDataViewCtrl
*dv
= column
->GetOwner();
2887 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
2888 event
.SetDataViewColumn( column
);
2889 event
.SetModel( dv
->GetModel() );
2890 if (dv
->HandleWindowEvent( event
))
2894 if (gdk_event
->button
== 3)
2896 wxDataViewCtrl
*dv
= column
->GetOwner();
2897 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
2898 event
.SetDataViewColumn( column
);
2899 event
.SetModel( dv
->GetModel() );
2900 if (dv
->HandleWindowEvent( event
))
2910 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*WXUNUSED(column
),
2911 GtkCellRenderer
*renderer
,
2912 GtkTreeModel
*model
,
2916 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2917 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2919 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2921 wxDataViewItem
item( (void*) iter
->user_data
);
2923 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
2925 if (!wx_model
->IsVirtualListModel())
2928 if (wx_model
->IsContainer( item
))
2930 visible
= wx_model
->HasContainerColumns( item
) ||
2931 (cell
->GetOwner()->GetModelColumn() == 0);
2938 GValue gvalue
= { 0, };
2939 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2940 g_value_set_boolean( &gvalue
, visible
);
2941 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2942 g_value_unset( &gvalue
);
2949 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
2951 if (value
.GetType() != cell
->GetVariantType())
2953 wxLogError( wxT("Wrong type, required: %s but: %s"),
2954 value
.GetType().c_str(),
2955 cell
->GetVariantType().c_str() );
2958 cell
->SetValue( value
);
2960 // deal with disabled items
2961 bool enabled
= wx_model
->IsEnabled( item
, cell
->GetOwner()->GetModelColumn() );
2963 // a) this sets the appearance to disabled grey
2964 GValue gvalue
= { 0, };
2965 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2966 g_value_set_boolean( &gvalue
, enabled
);
2967 g_object_set_property( G_OBJECT(renderer
), "sensitive", &gvalue
);
2968 g_value_unset( &gvalue
);
2970 // b) this actually disables the control/renderer
2972 cell
->SetMode( cell
->GtkGetMode() );
2974 cell
->SetMode( wxDATAVIEW_CELL_INERT
);
2977 // deal with attributes: if the renderer doesn't support them at all, we
2978 // don't even need to query the model for them
2979 if ( !cell
->GtkSupportsAttrs() )
2982 // it can support attributes so check if this item has any
2983 wxDataViewItemAttr attr
;
2984 if ( wx_model
->GetAttr( item
, cell
->GetOwner()->GetModelColumn(), attr
)
2985 || !cell
->GtkIsUsingDefaultAttrs() )
2987 bool usingDefaultAttrs
= !cell
->GtkSetAttr(attr
);
2988 cell
->GtkSetUsingDefaultAttrs(usingDefaultAttrs
);
2990 // else: no custom attributes specified and we're already using the default
2991 // ones -- nothing to do
2997 #include <wx/listimpl.cpp>
2998 WX_DEFINE_LIST(wxDataViewColumnList
)
3000 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
3001 unsigned int model_column
, int width
,
3002 wxAlignment align
, int flags
)
3003 : wxDataViewColumnBase( cell
, model_column
)
3005 Init( align
, flags
, width
);
3010 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
3011 unsigned int model_column
, int width
,
3012 wxAlignment align
, int flags
)
3013 : wxDataViewColumnBase( bitmap
, cell
, model_column
)
3015 Init( align
, flags
, width
);
3017 SetBitmap( bitmap
);
3020 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
3022 m_isConnected
= false;
3024 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
3025 m_column
= (GtkWidget
*) column
;
3028 SetAlignment( align
);
3032 // Create container for icon and label
3033 GtkWidget
*box
= gtk_hbox_new( FALSE
, 1 );
3034 gtk_widget_show( box
);
3035 // gtk_container_set_border_width((GtkContainer*)box, 2);
3036 m_image
= gtk_image_new();
3037 gtk_box_pack_start(GTK_BOX(box
), m_image
, FALSE
, FALSE
, 1);
3038 m_label
= gtk_label_new("");
3039 gtk_box_pack_end( GTK_BOX(box
), GTK_WIDGET(m_label
), FALSE
, FALSE
, 1 );
3040 gtk_tree_view_column_set_widget( column
, box
);
3042 wxDataViewRenderer
* const colRenderer
= GetRenderer();
3043 GtkCellRenderer
* const cellRenderer
= colRenderer
->GetGtkHandle();
3045 colRenderer
->GtkPackIntoColumn(column
);
3047 gtk_tree_view_column_set_cell_data_func( column
, cellRenderer
,
3048 wxGtkTreeCellDataFunc
, (gpointer
) colRenderer
, NULL
);
3051 void wxDataViewColumn::OnInternalIdle()
3056 if (gtk_widget_get_realized(GetOwner()->m_treeview
))
3058 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3061 g_signal_connect(column
->button
, "button_press_event",
3062 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
3064 // otherwise the event will be blocked by GTK+
3065 gtk_tree_view_column_set_clickable( column
, TRUE
);
3067 m_isConnected
= true;
3072 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
3074 wxDataViewColumnBase::SetOwner( owner
);
3076 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3078 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
3081 void wxDataViewColumn::SetTitle( const wxString
&title
)
3083 wxDataViewCtrl
*ctrl
= GetOwner();
3084 gtk_label_set_text( GTK_LABEL(m_label
), ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
3085 : wxGTK_CONV_SYS(title
) );
3087 gtk_widget_hide( m_label
);
3089 gtk_widget_show( m_label
);
3092 wxString
wxDataViewColumn::GetTitle() const
3094 return wxGTK_CONV_BACK_FONT(
3095 gtk_label_get_text( GTK_LABEL(m_label
) ),
3096 GetOwner()->GetFont()
3100 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
3102 wxDataViewColumnBase::SetBitmap( bitmap
);
3106 GtkImage
*gtk_image
= GTK_IMAGE(m_image
);
3108 GdkBitmap
*mask
= NULL
;
3109 if (bitmap
.GetMask())
3110 mask
= bitmap
.GetMask()->GetBitmap();
3112 if (bitmap
.HasPixbuf())
3114 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
3115 bitmap
.GetPixbuf());
3119 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
3120 bitmap
.GetPixmap(), mask
);
3122 gtk_widget_show( m_image
);
3126 gtk_widget_hide( m_image
);
3130 void wxDataViewColumn::SetHidden( bool hidden
)
3132 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
3135 void wxDataViewColumn::SetResizeable( bool resizable
)
3137 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizable
);
3140 void wxDataViewColumn::SetAlignment( wxAlignment align
)
3142 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3144 gfloat xalign
= 0.0;
3145 if (align
== wxALIGN_RIGHT
)
3147 if (align
== wxALIGN_CENTER_HORIZONTAL
||
3148 align
== wxALIGN_CENTER
)
3151 gtk_tree_view_column_set_alignment( column
, xalign
);
3153 if (m_renderer
&& m_renderer
->GetAlignment() == -1)
3154 m_renderer
->GtkUpdateAlignment();
3157 wxAlignment
wxDataViewColumn::GetAlignment() const
3159 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
3162 return wxALIGN_RIGHT
;
3164 return wxALIGN_CENTER_HORIZONTAL
;
3166 return wxALIGN_LEFT
;
3169 void wxDataViewColumn::SetSortable( bool sortable
)
3171 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3175 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
3179 gtk_tree_view_column_set_sort_column_id( column
, -1 );
3180 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
3181 gtk_tree_view_column_set_clickable( column
, FALSE
);
3185 bool wxDataViewColumn::IsSortable() const
3187 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3188 return gtk_tree_view_column_get_clickable( column
);
3191 bool wxDataViewColumn::IsSortKey() const
3193 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3194 return gtk_tree_view_column_get_sort_indicator( column
);
3197 bool wxDataViewColumn::IsResizeable() const
3199 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3200 return gtk_tree_view_column_get_resizable( column
);
3203 bool wxDataViewColumn::IsHidden() const
3205 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3206 return !gtk_tree_view_column_get_visible( column
);
3209 void wxDataViewColumn::SetSortOrder( bool ascending
)
3211 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3214 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
3216 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
3218 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
3221 bool wxDataViewColumn::IsSortOrderAscending() const
3223 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3225 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
3228 void wxDataViewColumn::SetMinWidth( int width
)
3230 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
3233 int wxDataViewColumn::GetMinWidth() const
3235 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
3238 int wxDataViewColumn::GetWidth() const
3240 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
3243 void wxDataViewColumn::SetWidth( int width
)
3245 if ( width
== wxCOL_WIDTH_AUTOSIZE
)
3247 // NB: this disables user resizing
3248 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
3252 if ( width
== wxCOL_WIDTH_DEFAULT
)
3254 // TODO find a better calculation
3255 width
= wxDVC_DEFAULT_WIDTH
;
3258 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
3259 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
3263 void wxDataViewColumn::SetReorderable( bool reorderable
)
3265 gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column
), reorderable
);
3268 bool wxDataViewColumn::IsReorderable() const
3270 return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column
) );
3273 //-----------------------------------------------------------------------------
3274 // wxGtkTreeModelNode
3275 //-----------------------------------------------------------------------------
3278 class wxGtkTreeModelChildWithPos
3286 int wxGtkTreeModelChildWithPosCmp( const void* data1
, const void* data2
, const void* user_data
)
3288 const wxGtkTreeModelChildWithPos
* child1
= (const wxGtkTreeModelChildWithPos
*) data1
;
3289 const wxGtkTreeModelChildWithPos
* child2
= (const wxGtkTreeModelChildWithPos
*) data2
;
3290 const wxDataViewCtrlInternal
*internal
= (const wxDataViewCtrlInternal
*) user_data
;
3291 int ret
= internal
->GetDataViewModel()->Compare( child1
->id
, child2
->id
,
3292 internal
->GetSortColumn(), (internal
->GetSortOrder() == GTK_SORT_DESCENDING
) );
3298 int LINKAGEMODE
wxGtkTreeModelChildPtrCmp( void*** data1
, void*** data2
)
3300 return gs_internal
->GetDataViewModel()->Compare( wxDataViewItem(**data1
), wxDataViewItem(**data2
),
3301 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
3304 WX_DEFINE_ARRAY_PTR( void**, wxGtkTreeModelChildrenPtr
);
3307 void wxGtkTreeModelNode::Resort()
3309 size_t child_count
= GetChildCount();
3310 if (child_count
== 0)
3313 size_t node_count
= GetNodesCount();
3315 if (child_count
== 1)
3317 if (node_count
== 1)
3319 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
3325 gint
*new_order
= new gint
[child_count
];
3328 // m_children has the original *void
3329 // ptrs points to these
3330 wxGtkTreeModelChildrenPtr ptrs
;
3332 for (i
= 0; i
< child_count
; i
++)
3333 ptrs
.Add( &(m_children
[i
]) );
3335 gs_internal
= m_internal
;
3336 ptrs
.Sort( &wxGtkTreeModelChildPtrCmp
);
3338 wxGtkTreeModelChildren temp
;
3339 void** base_ptr
= &(m_children
[0]);
3340 // Transfer positions to new_order array and
3342 for (i
= 0; i
< child_count
; i
++)
3344 new_order
[i
] = ptrs
[i
] - base_ptr
;
3345 temp
.Add( *ptrs
[i
] );
3348 // Transfer IDs back to m_children
3350 WX_APPEND_ARRAY( temp
, m_children
);
3355 // Build up array with IDs and original positions
3356 wxGtkTreeModelChildWithPos
* temp
= new wxGtkTreeModelChildWithPos
[child_count
];
3358 for (i
= 0; i
< child_count
; i
++)
3361 temp
[i
].id
= m_children
[i
];
3363 // Sort array keeping original positions
3364 wxQsort( temp
, child_count
, sizeof(wxGtkTreeModelChildWithPos
),
3365 &wxGtkTreeModelChildWithPosCmp
, m_internal
);
3366 // Transfer positions to new_order array and
3367 // IDs to m_children
3369 for (i
= 0; i
< child_count
; i
++)
3371 new_order
[i
] = temp
[i
].pos
;
3372 m_children
.Add( temp
[i
].id
);
3381 wxGtkTreeModelChildren temp
;
3382 WX_APPEND_ARRAY( temp
, m_children
);
3384 gs_internal
= m_internal
;
3385 m_children
.Sort( &wxGtkTreeModelChildCmp
);
3388 for (pos
= 0; pos
< child_count
; pos
++)
3390 void *id
= m_children
.Item( pos
);
3391 int old_pos
= temp
.Index( id
);
3392 new_order
[pos
] = old_pos
;
3396 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
3399 iter
.user_data
= GetItem().GetID();
3400 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
3402 gtk_tree_model_rows_reordered( gtk_tree_model
,
3403 wxGtkTreePath(m_internal
->get_path(&iter
)), &iter
, new_order
);
3405 delete [] new_order
;
3408 for (pos
= 0; pos
< node_count
; pos
++)
3410 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
3415 //-----------------------------------------------------------------------------
3416 // wxDataViewCtrlInternal
3417 //-----------------------------------------------------------------------------
3419 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
)
3422 m_wx_model
= wx_model
;
3426 m_sort_order
= GTK_SORT_ASCENDING
;
3428 m_dataview_sort_column
= NULL
;
3430 m_dragDataObject
= NULL
;
3431 m_dropDataObject
= NULL
;
3435 m_gtk_model
= wxgtk_tree_model_new();
3436 m_gtk_model
->internal
= this;
3438 m_notifier
= new wxGtkDataViewModelNotifier( wx_model
, this );
3440 wx_model
->AddNotifier( m_notifier
);
3442 // g_object_unref( gtk_model ); ???
3444 if (!m_wx_model
->IsVirtualListModel())
3447 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->GtkGetTreeView()), GTK_TREE_MODEL(m_gtk_model
) );
3450 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
3452 m_wx_model
->RemoveNotifier( m_notifier
);
3454 // remove the model from the GtkTreeView before it gets destroyed
3455 gtk_tree_view_set_model( GTK_TREE_VIEW( m_owner
->GtkGetTreeView() ), NULL
);
3457 g_object_unref( m_gtk_model
);
3459 delete m_dragDataObject
;
3460 delete m_dropDataObject
;
3463 void wxDataViewCtrlInternal::ScheduleRefresh()
3468 void wxDataViewCtrlInternal::OnInternalIdle()
3472 GtkWidget
*widget
= m_owner
->GtkGetTreeView();
3473 gtk_widget_queue_draw( widget
);
3478 void wxDataViewCtrlInternal::InitTree()
3480 wxDataViewItem item
;
3481 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
3483 BuildBranch( m_root
);
3486 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
3488 if (node
->GetChildCount() == 0)
3490 wxDataViewItemArray children
;
3491 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
3494 for (pos
= 0; pos
< count
; pos
++)
3496 wxDataViewItem child
= children
[pos
];
3498 if (m_wx_model
->IsContainer( child
))
3499 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
3501 node
->AddLeaf( child
.GetID() );
3503 // Don't send any events here
3510 bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat
&format
)
3512 wxGtkString
atom_str( gdk_atom_name( format
) );
3513 m_dragSourceTargetEntryTarget
= wxCharBuffer( atom_str
);
3515 m_dragSourceTargetEntry
.target
= m_dragSourceTargetEntryTarget
.data();
3516 m_dragSourceTargetEntry
.flags
= 0;
3517 m_dragSourceTargetEntry
.info
= static_cast<guint
>(-1);
3519 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3520 GDK_BUTTON1_MASK
, &m_dragSourceTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3525 bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat
&format
)
3527 wxGtkString
atom_str( gdk_atom_name( format
) );
3528 m_dropTargetTargetEntryTarget
= wxCharBuffer( atom_str
);
3530 m_dropTargetTargetEntry
.target
= m_dropTargetTargetEntryTarget
.data();
3531 m_dropTargetTargetEntry
.flags
= 0;
3532 m_dropTargetTargetEntry
.info
= static_cast<guint
>(-1);
3534 gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3535 &m_dropTargetTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3540 gboolean
wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource
*WXUNUSED(drag_source
),
3543 delete m_dragDataObject
;
3544 m_dragDataObject
= NULL
;
3546 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3550 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3551 event
.SetEventObject( m_owner
);
3552 event
.SetItem( item
);
3553 event
.SetModel( m_wx_model
);
3555 gtk_widget_get_pointer(m_owner
->GtkGetTreeView(), &x
, &y
);
3556 event
.SetPosition(x
, y
);
3557 if (!m_owner
->HandleWindowEvent( event
))
3560 if (!event
.IsAllowed())
3563 wxDataObject
*obj
= event
.GetDataObject();
3567 m_dragDataObject
= obj
;
3573 wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource
*WXUNUSED(drag_source
),
3574 GtkTreePath
*WXUNUSED(path
))
3579 gboolean
wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource
*WXUNUSED(drag_source
),
3580 GtkTreePath
*path
, GtkSelectionData
*selection_data
)
3582 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3586 GdkAtom target
= gtk_selection_data_get_target(selection_data
);
3587 if (!m_dragDataObject
->IsSupported(target
))
3590 size_t size
= m_dragDataObject
->GetDataSize(target
);
3594 void *buf
= malloc( size
);
3596 gboolean res
= FALSE
;
3597 if (m_dragDataObject
->GetDataHere(target
, buf
))
3601 gtk_selection_data_set(selection_data
, target
,
3602 8, (const guchar
*) buf
, size
);
3611 wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3613 GtkSelectionData
*selection_data
)
3615 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3619 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
3620 event
.SetEventObject( m_owner
);
3621 event
.SetItem( item
);
3622 event
.SetModel( m_wx_model
);
3623 event
.SetDataFormat(gtk_selection_data_get_target(selection_data
));
3624 event
.SetDataSize(gtk_selection_data_get_length(selection_data
));
3625 event
.SetDataBuffer(const_cast<guchar
*>(gtk_selection_data_get_data(selection_data
)));
3626 if (!m_owner
->HandleWindowEvent( event
))
3629 if (!event
.IsAllowed())
3636 wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3638 GtkSelectionData
*selection_data
)
3640 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3644 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
3645 event
.SetEventObject( m_owner
);
3646 event
.SetItem( item
);
3647 event
.SetModel( m_wx_model
);
3648 event
.SetDataFormat(gtk_selection_data_get_target(selection_data
));
3649 if (!m_owner
->HandleWindowEvent( event
))
3652 if (!event
.IsAllowed())
3658 // notifications from wxDataViewModel
3660 bool wxDataViewCtrlInternal::Cleared()
3675 void wxDataViewCtrlInternal::Resort()
3677 if (!m_wx_model
->IsVirtualListModel())
3683 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3685 if (!m_wx_model
->IsVirtualListModel())
3687 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3688 wxCHECK_MSG(parent_node
, false,
3689 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3691 wxDataViewItemArray modelSiblings
;
3692 m_wx_model
->GetChildren(parent
, modelSiblings
);
3693 const int modelSiblingsSize
= modelSiblings
.size();
3695 int posInModel
= modelSiblings
.Index(item
, /*fromEnd=*/true);
3696 wxCHECK_MSG( posInModel
!= wxNOT_FOUND
, false, "adding non-existent item?" );
3698 const wxGtkTreeModelChildren
& nodeSiblings
= parent_node
->GetChildren();
3699 const int nodeSiblingsSize
= nodeSiblings
.size();
3703 if ( posInModel
== modelSiblingsSize
- 1 )
3705 nodePos
= nodeSiblingsSize
;
3707 else if ( modelSiblingsSize
== nodeSiblingsSize
+ 1 )
3709 // This is the simple case when our node tree already matches the
3710 // model and only this one item is missing.
3711 nodePos
= posInModel
;
3715 // It's possible that a larger discrepancy between the model and
3716 // our realization exists. This can happen e.g. when adding a bunch
3717 // of items to the model and then calling ItemsAdded() just once
3718 // afterwards. In this case, we must find the right position by
3719 // looking at sibling items.
3721 // append to the end if we won't find a better position:
3722 nodePos
= nodeSiblingsSize
;
3724 for ( int nextItemPos
= posInModel
+ 1;
3725 nextItemPos
< modelSiblingsSize
;
3728 int nextNodePos
= parent_node
->FindChildByItem(modelSiblings
[nextItemPos
]);
3729 if ( nextNodePos
!= wxNOT_FOUND
)
3731 nodePos
= nextNodePos
;
3737 if (m_wx_model
->IsContainer( item
))
3738 parent_node
->InsertNode( new wxGtkTreeModelNode( parent_node
, item
, this ), nodePos
);
3740 parent_node
->InsertLeaf( item
.GetID(), nodePos
);
3748 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3750 if (!m_wx_model
->IsVirtualListModel())
3752 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3753 wxASSERT_MSG(parent_node
,
3754 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3756 parent_node
->DeleteChild( item
.GetID() );
3764 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
3766 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3767 event
.SetEventObject( m_owner
);
3768 event
.SetModel( m_owner
->GetModel() );
3769 event
.SetItem( item
);
3770 m_owner
->HandleWindowEvent( event
);
3775 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int view_column
)
3777 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3778 event
.SetEventObject( m_owner
);
3779 event
.SetModel( m_owner
->GetModel() );
3780 event
.SetColumn( view_column
);
3781 event
.SetDataViewColumn( GetOwner()->GetColumn(view_column
) );
3782 event
.SetItem( item
);
3783 m_owner
->HandleWindowEvent( event
);
3790 GtkTreeModelFlags
wxDataViewCtrlInternal::get_flags()
3794 if ( m_wx_model
->IsListModel() )
3795 flags
|= GTK_TREE_MODEL_LIST_ONLY
;
3797 if ( !m_wx_model
->IsVirtualListModel() )
3798 flags
|= GTK_TREE_MODEL_ITERS_PERSIST
;
3800 return GtkTreeModelFlags(flags
);
3803 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
3806 if (m_wx_model
->IsVirtualListModel())
3808 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3810 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
3812 if (i
>= wx_model
->GetCount())
3815 iter
->stamp
= m_gtk_model
->stamp
;
3816 // user_data is just the index +1
3817 iter
->user_data
= (gpointer
) (i
+1);
3823 int depth
= gtk_tree_path_get_depth( path
);
3825 wxGtkTreeModelNode
*node
= m_root
;
3828 for (i
= 0; i
< depth
; i
++)
3830 BuildBranch( node
);
3832 gint pos
= gtk_tree_path_get_indices (path
)[i
];
3833 if (pos
< 0) return FALSE
;
3834 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
3836 void* id
= node
->GetChildren().Item( (size_t) pos
);
3840 iter
->stamp
= m_gtk_model
->stamp
;
3841 iter
->user_data
= id
;
3845 size_t count
= node
->GetNodes().GetCount();
3847 for (pos2
= 0; pos2
< count
; pos2
++)
3849 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
3850 if (child_node
->GetItem().GetID() == id
)
3862 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
3864 // When this is called from ItemDeleted(), the item is already
3865 // deleted in the model.
3867 GtkTreePath
*retval
= gtk_tree_path_new ();
3869 if (m_wx_model
->IsVirtualListModel())
3871 // iter is root, add nothing
3872 if (!iter
->user_data
)
3875 // user_data is just the index +1
3876 int i
= ( (wxUIntPtr
) iter
->user_data
) -1;
3877 gtk_tree_path_append_index (retval
, i
);
3881 void *id
= iter
->user_data
;
3883 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
3886 int pos
= node
->GetChildren().Index( id
);
3888 gtk_tree_path_prepend_index( retval
, pos
);
3890 id
= node
->GetItem().GetID();
3891 node
= node
->GetParent();
3898 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
3900 if (m_wx_model
->IsVirtualListModel())
3902 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3904 // user_data is just the index +1
3905 int n
= ( (wxUIntPtr
) iter
->user_data
) -1;
3909 iter
->user_data
= NULL
;
3913 if (n
>= (int) wx_model
->GetCount()-1)
3915 iter
->user_data
= NULL
;
3919 // user_data is just the index +1 (+2 because we need the next)
3920 iter
->user_data
= (gpointer
) (n
+2);
3924 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
3925 if( parent
== NULL
)
3927 iter
->user_data
= NULL
;
3931 int pos
= parent
->GetChildren().Index( iter
->user_data
);
3933 if (pos
== (int) parent
->GetChildCount()-1)
3935 iter
->user_data
= NULL
;
3939 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
3945 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
3947 if (m_wx_model
->IsVirtualListModel())
3949 // this is a list, nodes have no children
3953 iter
->stamp
= m_gtk_model
->stamp
;
3954 iter
->user_data
= (gpointer
) 1;
3962 if (m_root
->GetChildCount() == 0) return FALSE
;
3963 iter
->stamp
= m_gtk_model
->stamp
;
3964 iter
->user_data
= (gpointer
) m_root
->GetChildren().Item( 0 );
3969 wxDataViewItem item
;
3971 item
= wxDataViewItem( (void*) parent
->user_data
);
3973 if (!m_wx_model
->IsContainer( item
))
3976 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3977 wxASSERT_MSG(parent_node
,
3978 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3980 BuildBranch( parent_node
);
3982 if (parent_node
->GetChildCount() == 0)
3985 iter
->stamp
= m_gtk_model
->stamp
;
3986 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
3992 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
3994 if (m_wx_model
->IsVirtualListModel())
3996 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3999 return (wx_model
->GetCount() > 0);
4001 // this is a list, nodes have no children
4007 return (m_root
->GetChildCount() > 0);
4009 wxDataViewItem
item( (void*) iter
->user_data
);
4011 bool is_container
= m_wx_model
->IsContainer( item
);
4016 wxGtkTreeModelNode
*node
= FindNode( iter
);
4018 "Did you forget a call to ItemAdded()? The iterator is unknown to the wxGtkTreeModel");
4020 BuildBranch( node
);
4022 return (node
->GetChildCount() > 0);
4026 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
4028 if (m_wx_model
->IsVirtualListModel())
4030 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
4033 return (gint
) wx_model
->GetCount();
4040 return m_root
->GetChildCount();
4042 wxDataViewItem
item( (void*) iter
->user_data
);
4044 if (!m_wx_model
->IsContainer( item
))
4047 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
4048 wxASSERT_MSG(parent_node
,
4049 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
4051 BuildBranch( parent_node
);
4053 return parent_node
->GetChildCount();
4057 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
4059 if (m_wx_model
->IsVirtualListModel())
4061 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
4069 if (n
>= (gint
) wx_model
->GetCount())
4072 iter
->stamp
= m_gtk_model
->stamp
;
4073 // user_data is just the index +1
4074 iter
->user_data
= (gpointer
) (n
+1);
4081 if (parent
) id
= (void*) parent
->user_data
;
4082 wxDataViewItem
item( id
);
4084 if (!m_wx_model
->IsContainer( item
))
4087 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
4088 wxASSERT_MSG(parent_node
,
4089 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
4091 BuildBranch( parent_node
);
4093 iter
->stamp
= m_gtk_model
->stamp
;
4094 iter
->user_data
= parent_node
->GetChildren().Item( n
);
4100 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
4102 if (m_wx_model
->IsVirtualListModel())
4108 wxGtkTreeModelNode
*node
= FindParentNode( child
);
4112 iter
->stamp
= m_gtk_model
->stamp
;
4113 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
4119 // item can be deleted already in the model
4120 int wxDataViewCtrlInternal::GetIndexOf( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
4122 if (m_wx_model
->IsVirtualListModel())
4124 return wxPtrToUInt(item
.GetID()) - 1;
4128 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
4129 wxGtkTreeModelChildren
&children
= parent_node
->GetChildren();
4131 for (j
= 0; j
< children
.GetCount(); j
++)
4133 if (children
[j
] == item
.GetID())
4141 static wxGtkTreeModelNode
*
4142 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
4148 list
.DeleteContents( true );
4149 wxDataViewItem
it( item
);
4153 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
4154 list
.Insert( pItem
);
4155 it
= model
->GetParent( it
);
4158 wxGtkTreeModelNode
* node
= treeNode
;
4159 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
4161 if( node
&& node
->GetNodes().GetCount() != 0 )
4163 int len
= node
->GetNodes().GetCount();
4164 wxGtkTreeModelNodes
&nodes
= node
->GetNodes();
4166 for( ; j
< len
; j
++)
4168 if( nodes
[j
]->GetItem() == *(n
->GetData()))
4187 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
4192 wxDataViewItem
item( (void*) iter
->user_data
);
4196 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
4201 wxLogDebug( "Not found %p", iter->user_data );
4205 // TODO: remove this code
4211 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
4216 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
4221 wxLogDebug( "Not found %p", item.GetID() );
4225 // TODO: remove this code
4231 static wxGtkTreeModelNode
*
4232 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
4238 list
.DeleteContents( true );
4242 wxDataViewItem
it( model
->GetParent( item
) );
4245 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
4246 list
.Insert( pItem
);
4247 it
= model
->GetParent( it
);
4250 wxGtkTreeModelNode
* node
= treeNode
;
4251 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
4253 if( node
&& node
->GetNodes().GetCount() != 0 )
4255 int len
= node
->GetNodes().GetCount();
4256 wxGtkTreeModelNodes nodes
= node
->GetNodes();
4258 for( ; j
< len
; j
++)
4260 if( nodes
[j
]->GetItem() == *(n
->GetData()))
4275 //Examine whether the node is item's parent node
4276 int len
= node
->GetChildCount();
4277 for( int i
= 0; i
< len
; i
++ )
4279 if( node
->GetChildren().Item( i
) == item
.GetID() )
4285 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
4290 wxDataViewItem
item( (void*) iter
->user_data
);
4294 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
4297 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
4302 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
4305 //-----------------------------------------------------------------------------
4306 // wxDataViewCtrl signal callbacks
4307 //-----------------------------------------------------------------------------
4310 wxdataview_selection_changed_callback( GtkTreeSelection
* WXUNUSED(selection
), wxDataViewCtrl
*dv
)
4312 if (!gtk_widget_get_realized(dv
->m_widget
))
4315 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
4316 event
.SetItem( dv
->GetSelection() );
4317 event
.SetModel( dv
->GetModel() );
4318 dv
->HandleWindowEvent( event
);
4322 wxdataview_row_activated_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreePath
*path
,
4323 GtkTreeViewColumn
*WXUNUSED(column
), wxDataViewCtrl
*dv
)
4325 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
4327 wxDataViewItem
item(dv
->GTKPathToItem(path
));
4328 event
.SetItem( item
);
4329 event
.SetModel( dv
->GetModel() );
4330 dv
->HandleWindowEvent( event
);
4334 wxdataview_test_expand_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4335 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4337 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
4339 wxDataViewItem
item( (void*) iter
->user_data
);;
4340 event
.SetItem( item
);
4341 event
.SetModel( dv
->GetModel() );
4342 dv
->HandleWindowEvent( event
);
4344 return !event
.IsAllowed();
4348 wxdataview_row_expanded_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4349 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4351 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
4353 wxDataViewItem
item( (void*) iter
->user_data
);;
4354 event
.SetItem( item
);
4355 event
.SetModel( dv
->GetModel() );
4356 dv
->HandleWindowEvent( event
);
4360 wxdataview_test_collapse_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4361 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4363 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
4365 wxDataViewItem
item( (void*) iter
->user_data
);;
4366 event
.SetItem( item
);
4367 event
.SetModel( dv
->GetModel() );
4368 dv
->HandleWindowEvent( event
);
4370 return !event
.IsAllowed();
4374 wxdataview_row_collapsed_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4375 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4377 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
4379 wxDataViewItem
item( (void*) iter
->user_data
);;
4380 event
.SetItem( item
);
4381 event
.SetModel( dv
->GetModel() );
4382 dv
->HandleWindowEvent( event
);
4385 //-----------------------------------------------------------------------------
4387 //-----------------------------------------------------------------------------
4389 void wxDataViewCtrl::AddChildGTK(wxWindowGTK
* child
)
4391 GtkWidget
* treeview
= GtkGetTreeView();
4393 // Insert widget in GtkTreeView
4394 if (gtk_widget_get_realized(treeview
))
4395 gtk_widget_set_parent_window( child
->m_widget
,
4396 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
4397 gtk_widget_set_parent( child
->m_widget
, treeview
);
4401 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
4402 GtkAllocation
*WXUNUSED(gtk_alloc
),
4403 wxDataViewCtrl
*win
)
4405 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
4408 wxWindow
*child
= node
->GetData();
4411 gtk_widget_size_request( child
->m_widget
, &req
);
4413 GtkAllocation alloc
;
4414 alloc
.x
= child
->m_x
;
4415 alloc
.y
= child
->m_y
;
4416 alloc
.width
= child
->m_width
;
4417 alloc
.height
= child
->m_height
;
4418 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
4420 node
= node
->GetNext();
4425 //-----------------------------------------------------------------------------
4426 // "motion_notify_event"
4427 //-----------------------------------------------------------------------------
4430 gtk_dataview_motion_notify_callback( GtkWidget
*WXUNUSED(widget
),
4431 GdkEventMotion
*gdk_event
,
4432 wxDataViewCtrl
*dv
)
4434 if (gdk_event
->is_hint
)
4438 GdkModifierType state
;
4439 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
4445 GtkTreeViewColumn
*column
= NULL
;
4448 if (gtk_tree_view_get_path_at_pos(
4449 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4450 (int) gdk_event
->x
, (int) gdk_event
->y
,
4459 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4467 //-----------------------------------------------------------------------------
4468 // "button_press_event"
4469 //-----------------------------------------------------------------------------
4472 gtk_dataview_button_press_callback( GtkWidget
*WXUNUSED(widget
),
4473 GdkEventButton
*gdk_event
,
4474 wxDataViewCtrl
*dv
)
4476 if ((gdk_event
->button
== 3) && (gdk_event
->type
== GDK_BUTTON_PRESS
))
4479 GtkTreeViewColumn
*column
= NULL
;
4482 gtk_tree_view_get_path_at_pos
4484 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4485 (int) gdk_event
->x
, (int) gdk_event
->y
,
4492 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, dv
->GetId() );
4494 event
.SetItem(dv
->GTKPathToItem(path
));
4495 event
.SetModel( dv
->GetModel() );
4496 return dv
->HandleWindowEvent( event
);
4502 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
4504 wxDataViewCtrl::~wxDataViewCtrl()
4506 // Stop editing before destroying the control to remove any event handlers
4507 // which are added when editing started: if we didn't do this, the base
4508 // class dtor would assert as it checks for any leftover handlers.
4511 GtkTreeViewColumn
*col
;
4512 gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview
), NULL
, &col
);
4514 wxDataViewColumn
* const wxcol
= FromGTKColumn(col
);
4517 // This won't do anything if we're not editing it
4518 wxcol
->GetRenderer()->CancelEditing();
4527 void wxDataViewCtrl::Init()
4531 m_cols
.DeleteContents( true );
4533 m_uniformRowHeight
= -1;
4536 bool wxDataViewCtrl::Create(wxWindow
*parent
,
4541 const wxValidator
& validator
,
4542 const wxString
& name
)
4544 if (!PreCreation( parent
, pos
, size
) ||
4545 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
4547 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
4551 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
4552 g_object_ref(m_widget
);
4554 GTKScrolledWindowSetBorder(m_widget
, style
);
4556 m_treeview
= gtk_tree_view_new();
4557 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
4559 m_focusWidget
= GTK_WIDGET(m_treeview
);
4561 g_signal_connect (m_treeview
, "size_allocate",
4562 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
4565 if (!gtk_check_version(2,6,0))
4567 bool fixed
= (style
& wxDV_VARIABLE_LINE_HEIGHT
) == 0;
4568 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4572 if (style
& wxDV_MULTIPLE
)
4574 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4575 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
4578 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
4581 if (!gtk_check_version(2,10,0))
4583 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
4585 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
4586 (style
& wxDV_VERT_RULES
) != 0)
4587 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
4588 else if (style
& wxDV_VERT_RULES
)
4589 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
4590 else if (style
& wxDV_HORIZ_RULES
)
4591 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
4593 if (grid
!= GTK_TREE_VIEW_GRID_LINES_NONE
)
4594 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
4598 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_ROW_LINES
) != 0 );
4600 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
4601 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
4602 gtk_widget_show (m_treeview
);
4604 m_parent
->DoAddChild( this );
4608 GtkEnableSelectionEvents();
4610 g_signal_connect_after (m_treeview
, "row-activated",
4611 G_CALLBACK (wxdataview_row_activated_callback
), this);
4613 g_signal_connect (m_treeview
, "test-collapse-row",
4614 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
4616 g_signal_connect_after (m_treeview
, "row-collapsed",
4617 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
4619 g_signal_connect (m_treeview
, "test-expand-row",
4620 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
4622 g_signal_connect_after (m_treeview
, "row-expanded",
4623 G_CALLBACK (wxdataview_row_expanded_callback
), this);
4625 g_signal_connect (m_treeview
, "motion_notify_event",
4626 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
4628 g_signal_connect (m_treeview
, "button_press_event",
4629 G_CALLBACK (gtk_dataview_button_press_callback
), this);
4634 wxDataViewItem
wxDataViewCtrl::GTKPathToItem(GtkTreePath
*path
) const
4637 return wxDataViewItem(path
&& m_internal
->get_iter(&iter
, path
)
4642 void wxDataViewCtrl::OnInternalIdle()
4644 wxWindow::OnInternalIdle();
4646 m_internal
->OnInternalIdle();
4648 unsigned int cols
= GetColumnCount();
4650 for (i
= 0; i
< cols
; i
++)
4652 wxDataViewColumn
*col
= GetColumn( i
);
4653 col
->OnInternalIdle();
4656 if (m_ensureVisibleDefered
.IsOk())
4658 ExpandAncestors(m_ensureVisibleDefered
);
4660 iter
.user_data
= (gpointer
) m_ensureVisibleDefered
.GetID();
4661 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4662 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
4663 m_ensureVisibleDefered
= wxDataViewItem(0);
4667 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4669 wxDELETE(m_internal
);
4671 if (!wxDataViewCtrlBase::AssociateModel( model
))
4675 if (!gtk_check_version(2,6,0))
4677 bool fixed
= (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
) == 0) || (model
->IsVirtualListModel()));
4678 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4682 m_internal
= new wxDataViewCtrlInternal( this, model
);
4687 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4689 return m_internal
->EnableDragSource( format
);
4692 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4694 return m_internal
->EnableDropTarget( format
);
4697 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4699 if (!wxDataViewCtrlBase::AppendColumn(col
))
4702 m_cols
.Append( col
);
4705 if (!gtk_check_version(2,6,0))
4707 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4708 GTK_TREE_VIEW_COLUMN_FIXED
)
4709 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4713 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
4714 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4719 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4721 if (!wxDataViewCtrlBase::PrependColumn(col
))
4724 m_cols
.Insert( col
);
4727 if (!gtk_check_version(2,6,0))
4729 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4730 GTK_TREE_VIEW_COLUMN_FIXED
)
4731 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4735 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4736 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
4741 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4743 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4746 m_cols
.Insert( pos
, col
);
4749 if (!gtk_check_version(2,6,0))
4751 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4752 GTK_TREE_VIEW_COLUMN_FIXED
)
4753 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4757 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4758 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), pos
);
4763 unsigned int wxDataViewCtrl::GetColumnCount() const
4765 return m_cols
.GetCount();
4768 wxDataViewColumn
* wxDataViewCtrl::FromGTKColumn(GtkTreeViewColumn
*gtk_col
) const
4773 wxDataViewColumnList::const_iterator iter
;
4774 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4776 wxDataViewColumn
*col
= *iter
;
4777 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
4783 wxFAIL_MSG( "No matching column?" );
4788 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
4790 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
4792 return FromGTKColumn(gtk_col
);
4795 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4797 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4798 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
4800 m_cols
.DeleteObject( column
);
4805 bool wxDataViewCtrl::ClearColumns()
4807 wxDataViewColumnList::iterator iter
;
4808 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4810 wxDataViewColumn
*col
= *iter
;
4811 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4812 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4820 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4822 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
4824 wxGtkList
list(gtk_tree_view_get_columns(GTK_TREE_VIEW(m_treeview
)));
4826 return g_list_index( list
, (gconstpointer
) gtk_column
);
4829 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4831 return m_internal
->GetDataViewSortColumn();
4834 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4837 iter
.user_data
= item
.GetID();
4838 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4839 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
4842 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4845 iter
.user_data
= item
.GetID();
4846 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4847 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
4850 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4853 iter
.user_data
= item
.GetID();
4854 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4855 return gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview
), path
);
4858 wxDataViewItem
wxDataViewCtrl::DoGetCurrentItem() const
4860 // The tree doesn't have any current item if it hadn't been created yet but
4861 // it's arguably not an error to call this function in this case so just
4862 // return an invalid item without asserting.
4864 return wxDataViewItem();
4867 gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview
), path
.ByRef(), NULL
);
4869 return GTKPathToItem(path
);
4872 void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem
& item
)
4874 wxCHECK_RET( m_treeview
,
4875 "Current item can't be set before creating the control." );
4877 // We need to make sure the model knows about this item or the path would
4878 // be invalid and gtk_tree_view_set_cursor() would silently do nothing.
4879 ExpandAncestors(item
);
4881 // We also need to preserve the existing selection from changing.
4882 // Unfortunately the only way to do it seems to use our own selection
4883 // function and forbid any selection changes during set cursor call.
4884 wxGtkTreeSelectionLock
4885 lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview
)));
4887 // Do move the cursor now.
4889 iter
.user_data
= item
.GetID();
4890 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4892 gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview
), path
, NULL
, FALSE
);
4895 void wxDataViewCtrl::StartEditor(const wxDataViewItem
& item
, unsigned int column
)
4897 wxCHECK_RET( m_treeview
,
4898 "Current item can't be set before creating the control." );
4900 // We need to make sure the model knows about this item or the path would
4901 // be invalid and gtk_tree_view_set_cursor() would silently do nothing.
4902 ExpandAncestors(item
);
4904 wxDataViewColumn
*dvcolumn
= GetColumn(column
);
4905 wxASSERT_MSG(dvcolumn
, "Could not retrieve column");
4906 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(dvcolumn
->GetGtkHandle());
4908 // We also need to preserve the existing selection from changing.
4909 // Unfortunately the only way to do it seems to use our own selection
4910 // function and forbid any selection changes during set cursor call.
4911 wxGtkTreeSelectionLock
4912 lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview
)));
4914 // Do move the cursor now.
4916 iter
.user_data
= item
.GetID();
4917 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4919 gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview
), path
, gcolumn
, TRUE
);
4922 int wxDataViewCtrl::GetSelectedItemsCount() const
4924 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4926 return gtk_tree_selection_count_selected_rows(selection
);
4929 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4933 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4934 if (HasFlag(wxDV_MULTIPLE
))
4936 GtkTreeModel
*model
;
4937 wxGtkTreePathList
list(gtk_tree_selection_get_selected_rows(selection
, &model
));
4939 for ( GList
* current
= list
; current
; current
= g_list_next(current
) )
4941 GtkTreePath
*path
= (GtkTreePath
*) current
->data
;
4943 sel
.Add(GTKPathToItem(path
));
4949 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
4951 sel
.Add( wxDataViewItem(iter
.user_data
) );
4958 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4960 GtkDisableSelectionEvents();
4962 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4964 gtk_tree_selection_unselect_all( selection
);
4966 wxDataViewItem last_parent
;
4969 for (i
= 0; i
< sel
.GetCount(); i
++)
4971 wxDataViewItem item
= sel
[i
];
4972 wxDataViewItem parent
= GetModel()->GetParent( item
);
4975 if (parent
!= last_parent
)
4976 ExpandAncestors(item
);
4978 last_parent
= parent
;
4981 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4982 iter
.user_data
= (gpointer
) item
.GetID();
4983 gtk_tree_selection_select_iter( selection
, &iter
);
4986 GtkEnableSelectionEvents();
4989 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4991 ExpandAncestors(item
);
4993 GtkDisableSelectionEvents();
4995 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4998 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4999 iter
.user_data
= (gpointer
) item
.GetID();
5000 gtk_tree_selection_select_iter( selection
, &iter
);
5002 GtkEnableSelectionEvents();
5005 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
5007 GtkDisableSelectionEvents();
5009 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5012 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
5013 iter
.user_data
= (gpointer
) item
.GetID();
5014 gtk_tree_selection_unselect_iter( selection
, &iter
);
5016 GtkEnableSelectionEvents();
5019 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
5021 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5024 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
5025 iter
.user_data
= (gpointer
) item
.GetID();
5027 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
5030 void wxDataViewCtrl::SelectAll()
5032 GtkDisableSelectionEvents();
5034 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5036 gtk_tree_selection_select_all( selection
);
5038 GtkEnableSelectionEvents();
5041 void wxDataViewCtrl::UnselectAll()
5043 GtkDisableSelectionEvents();
5045 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5047 gtk_tree_selection_unselect_all( selection
);
5049 GtkEnableSelectionEvents();
5052 void wxDataViewCtrl::EnsureVisible(const wxDataViewItem
& item
,
5053 const wxDataViewColumn
*WXUNUSED(column
))
5055 m_ensureVisibleDefered
= item
;
5056 ExpandAncestors(item
);
5059 iter
.user_data
= (gpointer
) item
.GetID();
5060 wxGtkTreePath
path(m_internal
->get_path( &iter
));
5061 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
5064 void wxDataViewCtrl::HitTest(const wxPoint
& point
,
5065 wxDataViewItem
& item
,
5066 wxDataViewColumn
*& column
) const
5068 // gtk_tree_view_get_dest_row_at_pos() is the right one. But it does not tell the column.
5069 // gtk_tree_view_get_path_at_pos() is the wrong function. It doesn't mind the header but returns column.
5070 // See http://mail.gnome.org/archives/gtkmm-list/2005-January/msg00080.html
5071 // So we have to use both of them.
5072 // Friedrich Haase 2010-9-20
5073 wxGtkTreePath path
, pathScratch
;
5074 GtkTreeViewColumn
* GtkColumn
= NULL
;
5075 GtkTreeViewDropPosition pos
= GTK_TREE_VIEW_DROP_INTO_OR_AFTER
;
5079 // cannot directly call GtkGetTreeView(), HitTest is const and so is this pointer
5080 wxDataViewCtrl
* ctrl
= (wxDataViewCtrl
*)this; // ugly workaround, ctrl is NOT const
5081 GtkTreeView
* treeView
= GTK_TREE_VIEW(ctrl
->GtkGetTreeView());
5083 // is there possibly a better suited function to get the column?
5084 gtk_tree_view_get_path_at_pos( // and this is the wrong call but it delivers the column
5086 (int) point
.x
, (int) point
.y
,
5087 pathScratch
.ByRef(),
5088 &GtkColumn
, // here we get the GtkColumn
5092 if ( GtkColumn
!= NULL
)
5094 // we got GTK column
5095 // the right call now which takes the header into account
5096 gtk_tree_view_get_dest_row_at_pos( treeView
, (int) point
.x
, (int) point
.y
, path
.ByRef(), &pos
);
5099 item
= wxDataViewItem(GTKPathToItem(path
));
5100 // else we got a GTK column but the position is not over an item, e.g. below last item
5101 for ( unsigned int i
=0, cols
=GetColumnCount(); i
<cols
; ++i
) // search the wx column
5103 wxDataViewColumn
* col
= GetColumn(i
);
5104 if ( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == GtkColumn
)
5106 column
= col
; // here we get the wx column
5111 // else no column and thus no item, both null
5115 wxDataViewCtrl::GetItemRect(const wxDataViewItem
& WXUNUSED(item
),
5116 const wxDataViewColumn
*WXUNUSED(column
)) const
5121 bool wxDataViewCtrl::SetRowHeight(int rowHeight
)
5123 m_uniformRowHeight
= rowHeight
;
5127 void wxDataViewCtrl::DoSetExpanderColumn()
5129 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
5130 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
5133 void wxDataViewCtrl::DoSetIndent()
5137 void wxDataViewCtrl::GtkDisableSelectionEvents()
5139 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5140 g_signal_handlers_disconnect_by_func( selection
,
5141 (gpointer
) (wxdataview_selection_changed_callback
), this);
5144 void wxDataViewCtrl::GtkEnableSelectionEvents()
5146 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
5147 g_signal_connect_after (selection
, "changed",
5148 G_CALLBACK (wxdataview_selection_changed_callback
), this);
5151 // ----------------------------------------------------------------------------
5152 // visual attributes stuff
5153 // ----------------------------------------------------------------------------
5157 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
5159 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
5162 void wxDataViewCtrl::DoApplyWidgetStyle(GtkRcStyle
*style
)
5164 wxDataViewCtrlBase::DoApplyWidgetStyle(style
);
5165 gtk_widget_modify_style(m_treeview
, style
);
5168 #endif // !wxUSE_GENERICDATAVIEWCTRL
5170 #endif // wxUSE_DATAVIEWCTRL