1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/dataview.cpp
3 // Purpose: wxDataViewCtrl GTK+2 implementation
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if wxUSE_DATAVIEWCTRL
15 #include "wx/dataview.h"
17 #ifndef wxUSE_GENERICDATAVIEWCTRL
21 #include "wx/dcclient.h"
23 #include "wx/settings.h"
27 #include "wx/stockitem.h"
28 #include "wx/calctrl.h"
29 #include "wx/popupwin.h"
30 #include "wx/listimpl.cpp"
32 #include "wx/gtk/private.h"
33 #include "wx/gtk/dc.h"
34 #include "wx/gtk/dcclient.h"
36 #include "wx/gtk/private/gdkconv.h"
37 using namespace wxGTKImpl
;
39 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 static wxDataViewCtrlInternal
*gs_internal
= NULL
;
44 class wxGtkTreeModelNode
;
47 typedef struct _GtkWxTreeModel GtkWxTreeModel
;
50 // ----------------------------------------------------------------------------
51 // wxGtkTreePath: self-destroying GtkTreePath
52 // ----------------------------------------------------------------------------
54 // Usually this object is initialized with the associated GtkTreePath
55 // immediately when it's constructed but it can also be changed later either by
56 // using Assign() or by getting the pointer to the internally stored pointer
57 // value using ByRef(). The latter should be avoided but is very convenient
58 // when using GTK functions with GtkTreePath output parameters.
62 // Ctor takes ownership of the given path and will free it if non-NULL.
63 wxGtkTreePath(GtkTreePath
*path
= NULL
) : m_path(path
) { }
65 // Creates a tree path for the given string path.
66 wxGtkTreePath(const gchar
*strpath
)
67 : m_path(gtk_tree_path_new_from_string(strpath
))
71 // Set the stored pointer if not done by ctor.
72 void Assign(GtkTreePath
*path
)
74 wxASSERT_MSG( !m_path
, "shouldn't be already initialized" );
79 // Return the pointer to the internally stored pointer. This should only be
80 // used to initialize the object by passing it to some GTK function.
83 wxASSERT_MSG( !m_path
, "shouldn't be already initialized" );
89 operator GtkTreePath
*() const { return m_path
; }
91 ~wxGtkTreePath() { if ( m_path
) gtk_tree_path_free(m_path
); }
96 wxDECLARE_NO_COPY_CLASS(wxGtkTreePath
);
99 // ----------------------------------------------------------------------------
100 // wxGtkTreeSelectionLock: prevent selection from changing during the
101 // lifetime of this object
102 // ----------------------------------------------------------------------------
104 // Implementation note: it could be expected that setting the selection
105 // function in this class ctor and resetting it back to the old value in its
106 // dtor would work. However currently gtk_tree_selection_get_select_function()
107 // can't be passed NULL (see https://bugzilla.gnome.org/show_bug.cgi?id=626276)
108 // so we can't do this. Instead, we always use the selection function (which
109 // imposes extra overhead, albeit minimal one, on all selection operations) and
110 // just set/reset the flag telling it whether it should allow or forbid the
113 // Also notice that currently only a single object of this class may exist at
114 // any given moment. It's just simpler like this and we don't need anything
118 gboolean
wxdataview_selection_func(GtkTreeSelection
* WXUNUSED(selection
),
119 GtkTreeModel
* WXUNUSED(model
),
120 GtkTreePath
* WXUNUSED(path
),
121 gboolean
WXUNUSED(path_currently_selected
),
127 class wxGtkTreeSelectionLock
130 wxGtkTreeSelectionLock(GtkTreeSelection
*selection
)
131 : m_selection(selection
)
133 wxASSERT_MSG( !ms_instance
, "this class is not reentrant currently" );
137 CheckCurrentSelectionFunc(NULL
);
139 // Pass some non-NULL pointer as "data" for the callback, it doesn't
140 // matter what it is as long as it's non-NULL.
141 gtk_tree_selection_set_select_function(selection
,
142 wxdataview_selection_func
,
147 ~wxGtkTreeSelectionLock()
149 CheckCurrentSelectionFunc(wxdataview_selection_func
);
151 gtk_tree_selection_set_select_function(m_selection
,
152 wxdataview_selection_func
,
160 void CheckCurrentSelectionFunc(GtkTreeSelectionFunc func
)
162 // We can only use gtk_tree_selection_get_select_function() with 2.14+
163 // so check for its availability both during compile- and run-time.
164 #if GTK_CHECK_VERSION(2, 14, 0)
165 if ( gtk_check_version(2, 14, 0) != NULL
)
168 // If this assert is triggered, it means the code elsewhere has called
169 // gtk_tree_selection_set_select_function() but currently doing this
170 // breaks this class so the code here needs to be changed.
173 gtk_tree_selection_get_select_function(m_selection
) == func
,
174 "selection function has changed unexpectedly, review this code!"
181 static wxGtkTreeSelectionLock
*ms_instance
;
183 GtkTreeSelection
* const m_selection
;
185 wxDECLARE_NO_COPY_CLASS(wxGtkTreeSelectionLock
);
188 wxGtkTreeSelectionLock
*wxGtkTreeSelectionLock::ms_instance
= NULL
;
190 //-----------------------------------------------------------------------------
191 // wxDataViewCtrlInternal
192 //-----------------------------------------------------------------------------
194 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
195 WX_DEFINE_LIST(ItemList
)
197 class wxDataViewCtrlInternal
200 wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
);
201 ~wxDataViewCtrlInternal();
204 GtkTreeModelFlags
get_flags();
205 gboolean
get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
);
206 GtkTreePath
*get_path( GtkTreeIter
*iter
);
207 gboolean
iter_next( GtkTreeIter
*iter
);
208 gboolean
iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
);
209 gboolean
iter_has_child( GtkTreeIter
*iter
);
210 gint
iter_n_children( GtkTreeIter
*iter
);
211 gboolean
iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
);
212 gboolean
iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
);
216 bool EnableDragSource( const wxDataFormat
&format
);
217 bool EnableDropTarget( const wxDataFormat
&format
);
219 gboolean
row_draggable( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
);
220 gboolean
drag_data_delete( GtkTreeDragSource
*drag_source
, GtkTreePath
* path
);
221 gboolean
drag_data_get( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
,
222 GtkSelectionData
*selection_data
);
223 gboolean
drag_data_received( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest
,
224 GtkSelectionData
*selection_data
);
225 gboolean
row_drop_possible( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest_path
,
226 GtkSelectionData
*selection_data
);
228 // notifactions from wxDataViewModel
229 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
230 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
231 bool ItemChanged( const wxDataViewItem
&item
);
232 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
237 void SetSortOrder( GtkSortType sort_order
) { m_sort_order
= sort_order
; }
238 GtkSortType
GetSortOrder() const { return m_sort_order
; }
240 void SetSortColumn( int column
) { m_sort_column
= column
; }
241 int GetSortColumn() const { return m_sort_column
; }
243 void SetDataViewSortColumn( wxDataViewColumn
*column
) { m_dataview_sort_column
= column
; }
244 wxDataViewColumn
*GetDataViewSortColumn() { return m_dataview_sort_column
; }
246 bool IsSorted() { return (m_sort_column
>= 0); }
249 wxDataViewModel
* GetDataViewModel() { return m_wx_model
; }
250 const wxDataViewModel
* GetDataViewModel() const { return m_wx_model
; }
251 wxDataViewCtrl
* GetOwner() { return m_owner
; }
252 GtkWxTreeModel
* GetGtkModel() { return m_gtk_model
; }
254 // item can be deleted already in the model
255 int GetIndexOf( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
259 wxGtkTreeModelNode
*FindNode( const wxDataViewItem
&item
);
260 wxGtkTreeModelNode
*FindNode( GtkTreeIter
*iter
);
261 wxGtkTreeModelNode
*FindParentNode( const wxDataViewItem
&item
);
262 wxGtkTreeModelNode
*FindParentNode( GtkTreeIter
*iter
);
263 void BuildBranch( wxGtkTreeModelNode
*branch
);
266 wxGtkTreeModelNode
*m_root
;
267 wxDataViewModel
*m_wx_model
;
268 GtkWxTreeModel
*m_gtk_model
;
269 wxDataViewCtrl
*m_owner
;
270 GtkSortType m_sort_order
;
271 wxDataViewColumn
*m_dataview_sort_column
;
274 GtkTargetEntry m_dragSourceTargetEntry
;
275 wxCharBuffer m_dragSourceTargetEntryTarget
;
276 wxDataObject
*m_dragDataObject
;
278 GtkTargetEntry m_dropTargetTargetEntry
;
279 wxCharBuffer m_dropTargetTargetEntryTarget
;
280 wxDataObject
*m_dropDataObject
;
284 //-----------------------------------------------------------------------------
285 // wxGtkTreeModelNode
286 //-----------------------------------------------------------------------------
289 int LINKAGEMODE
wxGtkTreeModelChildCmp( void** id1
, void** id2
)
291 int ret
= gs_internal
->GetDataViewModel()->Compare( *id1
, *id2
,
292 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
297 WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode
*, wxGtkTreeModelNodes
);
298 WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren
);
300 class wxGtkTreeModelNode
303 wxGtkTreeModelNode( wxGtkTreeModelNode
* parent
, const wxDataViewItem
&item
,
304 wxDataViewCtrlInternal
*internal
)
308 m_internal
= internal
;
311 ~wxGtkTreeModelNode()
313 size_t count
= m_nodes
.GetCount();
315 for (i
= 0; i
< count
; i
++)
317 wxGtkTreeModelNode
*child
= m_nodes
.Item( i
);
322 unsigned int AddNode( wxGtkTreeModelNode
* child
)
324 m_nodes
.Add( child
);
326 void *id
= child
->GetItem().GetID();
328 m_children
.Add( id
);
330 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
332 gs_internal
= m_internal
;
333 m_children
.Sort( &wxGtkTreeModelChildCmp
);
334 return m_children
.Index( id
);
337 return m_children
.GetCount()-1;
340 unsigned int AddLeave( void* id
)
342 m_children
.Add( id
);
344 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
346 gs_internal
= m_internal
;
347 m_children
.Sort( &wxGtkTreeModelChildCmp
);
348 return m_children
.Index( id
);
351 return m_children
.GetCount()-1;
354 void DeleteChild( void* id
)
356 m_children
.Remove( id
);
358 unsigned int count
= m_nodes
.GetCount();
360 for (pos
= 0; pos
< count
; pos
++)
362 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
363 if (node
->GetItem().GetID() == id
)
365 m_nodes
.RemoveAt( pos
);
372 wxGtkTreeModelNode
* GetParent()
374 wxGtkTreeModelNodes
&GetNodes()
376 wxGtkTreeModelChildren
&GetChildren()
377 { return m_children
; }
379 unsigned int GetChildCount() const { return m_children
.GetCount(); }
380 unsigned int GetNodesCount() const { return m_nodes
.GetCount(); }
382 wxDataViewItem
&GetItem() { return m_item
; }
383 wxDataViewCtrlInternal
*GetInternal() { return m_internal
; }
388 wxGtkTreeModelNode
*m_parent
;
389 wxGtkTreeModelNodes m_nodes
;
390 wxGtkTreeModelChildren m_children
;
391 wxDataViewItem m_item
;
392 wxDataViewCtrlInternal
*m_internal
;
396 //-----------------------------------------------------------------------------
398 //-----------------------------------------------------------------------------
400 extern bool g_blockEventsOnDrag
;
402 //-----------------------------------------------------------------------------
403 // define new GTK+ class wxGtkTreeModel
404 //-----------------------------------------------------------------------------
408 #define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ())
409 #define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel))
410 #define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
411 #define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL))
412 #define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL))
413 #define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
415 GType
gtk_wx_tree_model_get_type (void);
417 typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass
;
419 struct _GtkWxTreeModel
425 wxDataViewCtrlInternal
*internal
;
428 struct _GtkWxTreeModelClass
430 GObjectClass list_parent_class
;
433 static GtkWxTreeModel
*wxgtk_tree_model_new (void);
434 static void wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
);
435 static void wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
);
437 static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
);
438 static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
);
439 static void wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
);
440 static void wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
);
442 static void wxgtk_tree_model_finalize (GObject
*object
);
443 static GtkTreeModelFlags
wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
);
444 static gint
wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
);
445 static GType
wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
447 static gboolean
wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
450 static GtkTreePath
*wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
452 static void wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
456 static gboolean
wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
458 static gboolean
wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
460 GtkTreeIter
*parent
);
461 static gboolean
wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
463 static gint
wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
465 static gboolean
wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
469 static gboolean
wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
474 static gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
475 gint
*sort_column_id
,
477 static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
480 static void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
482 GtkTreeIterCompareFunc func
,
484 GtkDestroyNotify destroy
);
485 static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
486 GtkTreeIterCompareFunc func
,
488 GtkDestroyNotify destroy
);
489 static gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
);
492 static gboolean
wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
494 static gboolean
wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
496 static gboolean
wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
498 GtkSelectionData
*selection_data
);
499 static gboolean
wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
501 GtkSelectionData
*selection_data
);
502 static gboolean
wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
503 GtkTreePath
*dest_path
,
504 GtkSelectionData
*selection_data
);
507 static GObjectClass
*list_parent_class
= NULL
;
510 gtk_wx_tree_model_get_type (void)
512 static GType tree_model_type
= 0;
514 if (!tree_model_type
)
516 const GTypeInfo tree_model_info
=
518 sizeof (GtkWxTreeModelClass
),
519 NULL
, /* base_init */
520 NULL
, /* base_finalize */
521 (GClassInitFunc
) wxgtk_tree_model_class_init
,
522 NULL
, /* class_finalize */
523 NULL
, /* class_data */
524 sizeof (GtkWxTreeModel
),
526 (GInstanceInitFunc
) wxgtk_tree_model_init
,
529 static const GInterfaceInfo tree_model_iface_info
=
531 (GInterfaceInitFunc
) wxgtk_tree_model_tree_model_init
,
536 static const GInterfaceInfo sortable_iface_info
=
538 (GInterfaceInitFunc
) wxgtk_tree_model_sortable_init
,
543 static const GInterfaceInfo drag_source_iface_info
=
545 (GInterfaceInitFunc
) wxgtk_tree_model_drag_source_init
,
550 static const GInterfaceInfo drag_dest_iface_info
=
552 (GInterfaceInitFunc
) wxgtk_tree_model_drag_dest_init
,
557 tree_model_type
= g_type_register_static (G_TYPE_OBJECT
, "GtkWxTreeModel",
558 &tree_model_info
, (GTypeFlags
)0 );
560 g_type_add_interface_static (tree_model_type
,
562 &tree_model_iface_info
);
563 g_type_add_interface_static (tree_model_type
,
564 GTK_TYPE_TREE_SORTABLE
,
565 &sortable_iface_info
);
566 g_type_add_interface_static (tree_model_type
,
567 GTK_TYPE_TREE_DRAG_DEST
,
568 &drag_dest_iface_info
);
569 g_type_add_interface_static (tree_model_type
,
570 GTK_TYPE_TREE_DRAG_SOURCE
,
571 &drag_source_iface_info
);
574 return tree_model_type
;
577 static GtkWxTreeModel
*
578 wxgtk_tree_model_new(void)
580 GtkWxTreeModel
*retval
= (GtkWxTreeModel
*) g_object_new (GTK_TYPE_WX_TREE_MODEL
, NULL
);
585 wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
)
587 list_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
588 GObjectClass
*object_class
= (GObjectClass
*) klass
;
589 object_class
->finalize
= wxgtk_tree_model_finalize
;
593 wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
)
595 iface
->get_flags
= wxgtk_tree_model_get_flags
;
596 iface
->get_n_columns
= wxgtk_tree_model_get_n_columns
;
597 iface
->get_column_type
= wxgtk_tree_model_get_column_type
;
598 iface
->get_iter
= wxgtk_tree_model_get_iter
;
599 iface
->get_path
= wxgtk_tree_model_get_path
;
600 iface
->get_value
= wxgtk_tree_model_get_value
;
601 iface
->iter_next
= wxgtk_tree_model_iter_next
;
602 iface
->iter_children
= wxgtk_tree_model_iter_children
;
603 iface
->iter_has_child
= wxgtk_tree_model_iter_has_child
;
604 iface
->iter_n_children
= wxgtk_tree_model_iter_n_children
;
605 iface
->iter_nth_child
= wxgtk_tree_model_iter_nth_child
;
606 iface
->iter_parent
= wxgtk_tree_model_iter_parent
;
610 wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
)
612 iface
->get_sort_column_id
= wxgtk_tree_model_get_sort_column_id
;
613 iface
->set_sort_column_id
= wxgtk_tree_model_set_sort_column_id
;
614 iface
->set_sort_func
= wxgtk_tree_model_set_sort_func
;
615 iface
->set_default_sort_func
= wxgtk_tree_model_set_default_sort_func
;
616 iface
->has_default_sort_func
= wxgtk_tree_model_has_default_sort_func
;
620 wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface
*iface
)
622 iface
->row_draggable
= wxgtk_tree_model_row_draggable
;
623 iface
->drag_data_delete
= wxgtk_tree_model_drag_data_delete
;
624 iface
->drag_data_get
= wxgtk_tree_model_drag_data_get
;
628 wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface
*iface
)
630 iface
->drag_data_received
= wxgtk_tree_model_drag_data_received
;
631 iface
->row_drop_possible
= wxgtk_tree_model_row_drop_possible
;
635 wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
)
637 tree_model
->internal
= NULL
;
638 tree_model
->stamp
= g_random_int();
642 wxgtk_tree_model_finalize (GObject
*object
)
645 (* list_parent_class
->finalize
) (object
);
650 //-----------------------------------------------------------------------------
651 // implement callbacks from wxGtkTreeModel class by letting
652 // them call the methods of wxWidgets' wxDataViewModel
653 //-----------------------------------------------------------------------------
655 static GtkTreeModelFlags
656 wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
)
658 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
659 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), (GtkTreeModelFlags
)0 );
661 return wxtree_model
->internal
->get_flags();
665 wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
)
667 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
668 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
670 return wxtree_model
->internal
->GetDataViewModel()->GetColumnCount();
674 wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
677 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
678 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), G_TYPE_INVALID
);
680 GType gtype
= G_TYPE_INVALID
;
682 wxString wxtype
= wxtree_model
->internal
->GetDataViewModel()->GetColumnType( (unsigned int) index
);
684 if (wxtype
== wxT("string"))
685 gtype
= G_TYPE_STRING
;
688 gtype
= G_TYPE_POINTER
;
689 // wxFAIL_MSG( wxT("non-string columns not supported for searching yet") );
696 wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
700 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
701 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
702 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
704 return wxtree_model
->internal
->get_iter( iter
, path
);
708 wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
711 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
712 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), NULL
);
713 g_return_val_if_fail (iter
->stamp
== GTK_WX_TREE_MODEL (wxtree_model
)->stamp
, NULL
);
715 return wxtree_model
->internal
->get_path( iter
);
719 wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
724 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
725 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
) );
727 wxDataViewModel
*model
= wxtree_model
->internal
->GetDataViewModel();
728 wxString mtype
= model
->GetColumnType( (unsigned int) column
);
729 if (mtype
== wxT("string"))
732 g_value_init( value
, G_TYPE_STRING
);
733 wxDataViewItem
item( (void*) iter
->user_data
);
734 model
->GetValue( variant
, item
, (unsigned int) column
);
736 g_value_set_string( value
, variant
.GetString().utf8_str() );
740 wxFAIL_MSG( wxT("non-string columns not supported yet") );
745 wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
748 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
750 // This happens when clearing the view by calling .._set_model( NULL );
751 if (iter
->stamp
== 0) return FALSE
;
753 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
754 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
756 return wxtree_model
->internal
->iter_next( iter
);
760 wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
764 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
765 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
768 g_return_val_if_fail (wxtree_model
->stamp
== parent
->stamp
, FALSE
);
771 return wxtree_model
->internal
->iter_children( iter
, parent
);
775 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
778 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
779 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
780 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
782 return wxtree_model
->internal
->iter_has_child( iter
);
786 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
789 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
790 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
791 g_return_val_if_fail ( !iter
|| wxtree_model
->stamp
== iter
->stamp
, 0);
793 return wxtree_model
->internal
->iter_n_children( iter
);
797 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
802 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
803 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
805 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
809 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
813 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
814 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
815 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
817 return wxtree_model
->internal
->iter_parent( iter
, child
);
820 /* drag'n'drop iface */
822 wxgtk_tree_model_row_draggable (GtkTreeDragSource
*drag_source
,
825 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
826 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
828 return wxtree_model
->internal
->row_draggable( drag_source
, path
);
832 wxgtk_tree_model_drag_data_delete (GtkTreeDragSource
*drag_source
,
835 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
836 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
838 return wxtree_model
->internal
->drag_data_delete( drag_source
, path
);
842 wxgtk_tree_model_drag_data_get (GtkTreeDragSource
*drag_source
,
844 GtkSelectionData
*selection_data
)
846 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_source
;
847 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
850 wxPrintf( "drag_get_data\n");
852 wxGtkString
atom_selection(gdk_atom_name(selection_data
->selection
));
853 wxPrintf( "selection %s\n", wxString::FromAscii(atom_selection
) );
855 wxGtkString
atom_target(gdk_atom_name(selection_data
->target
));
856 wxPrintf( "target %s\n", wxString::FromAscii(atom_target
) );
858 wxGtkString
atom_type(gdk_atom_name(selection_data
->type
));
859 wxPrintf( "type %s\n", wxString::FromAscii(atom_type
) );
861 wxPrintf( "format %d\n", selection_data
->format
);
864 return wxtree_model
->internal
->drag_data_get( drag_source
, path
, selection_data
);
868 wxgtk_tree_model_drag_data_received (GtkTreeDragDest
*drag_dest
,
870 GtkSelectionData
*selection_data
)
872 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
873 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
875 return wxtree_model
->internal
->drag_data_received( drag_dest
, dest
, selection_data
);
879 wxgtk_tree_model_row_drop_possible (GtkTreeDragDest
*drag_dest
,
880 GtkTreePath
*dest_path
,
881 GtkSelectionData
*selection_data
)
883 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) drag_dest
;
884 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
886 return wxtree_model
->internal
->row_drop_possible( drag_dest
, dest_path
, selection_data
);
891 wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
892 gint
*sort_column_id
,
895 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) sortable
;
897 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
899 if (!wxtree_model
->internal
->IsSorted())
902 *sort_column_id
= -1;
909 *sort_column_id
= wxtree_model
->internal
->GetSortColumn();
912 *order
= wxtree_model
->internal
->GetSortOrder();
917 wxDataViewColumn
*gs_lastLeftClickHeader
= NULL
;
920 wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
924 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
925 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
927 tree_model
->internal
->SetDataViewSortColumn( gs_lastLeftClickHeader
);
929 if ((sort_column_id
!= (gint
) tree_model
->internal
->GetSortColumn()) ||
930 (order
!= tree_model
->internal
->GetSortOrder()))
932 tree_model
->internal
->SetSortColumn( sort_column_id
);
933 tree_model
->internal
->SetSortOrder( order
);
935 gtk_tree_sortable_sort_column_changed (sortable
);
937 tree_model
->internal
->GetDataViewModel()->Resort();
940 if (gs_lastLeftClickHeader
)
942 wxDataViewCtrl
*dv
= tree_model
->internal
->GetOwner();
943 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, dv
->GetId() );
944 event
.SetDataViewColumn( gs_lastLeftClickHeader
);
945 event
.SetModel( dv
->GetModel() );
946 dv
->HandleWindowEvent( event
);
949 gs_lastLeftClickHeader
= NULL
;
953 wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
954 gint
WXUNUSED(sort_column_id
),
955 GtkTreeIterCompareFunc func
,
956 gpointer
WXUNUSED(data
),
957 GtkDestroyNotify
WXUNUSED(destroy
))
959 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
960 g_return_if_fail (func
!= NULL
);
964 wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
965 GtkTreeIterCompareFunc func
,
966 gpointer
WXUNUSED(data
),
967 GtkDestroyNotify
WXUNUSED(destroy
))
969 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
970 g_return_if_fail (func
!= NULL
);
972 //wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
973 // TODO: remove this code
977 wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
)
979 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
984 //-----------------------------------------------------------------------------
985 // define new GTK+ class GtkWxRendererText
986 //-----------------------------------------------------------------------------
990 #define GTK_TYPE_WX_CELL_RENDERER_TEXT (gtk_wx_cell_renderer_text_get_type ())
991 #define GTK_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererText))
992 #define GTK_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
993 #define GTK_IS_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT))
994 #define GTK_IS_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT))
995 #define GTK_WX_CELL_RENDERER_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
997 GType
gtk_wx_cell_renderer_text_get_type (void);
999 typedef struct _GtkWxCellRendererText GtkWxCellRendererText
;
1000 typedef struct _GtkWxCellRendererTextClass GtkWxCellRendererTextClass
;
1002 struct _GtkWxCellRendererText
1004 GtkCellRendererText parent
;
1006 wxDataViewRenderer
*wx_renderer
;
1009 struct _GtkWxCellRendererTextClass
1011 GtkCellRendererTextClass cell_parent_class
;
1015 static GtkWxCellRendererText
*gtk_wx_cell_renderer_text_new (void);
1016 static void gtk_wx_cell_renderer_text_init (
1017 GtkWxCellRendererText
*cell
);
1018 static void gtk_wx_cell_renderer_text_class_init(
1019 GtkWxCellRendererTextClass
*klass
);
1020 static void gtk_wx_cell_renderer_text_finalize (
1022 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
1023 GtkCellRenderer
*cell
,
1027 GdkRectangle
*background_area
,
1028 GdkRectangle
*cell_area
,
1029 GtkCellRendererState flags
);
1032 static GObjectClass
*text_cell_parent_class
= NULL
;
1037 gtk_wx_cell_renderer_text_get_type (void)
1039 static GType cell_wx_type
= 0;
1043 const GTypeInfo cell_wx_info
=
1045 sizeof (GtkWxCellRendererTextClass
),
1046 NULL
, /* base_init */
1047 NULL
, /* base_finalize */
1048 (GClassInitFunc
) gtk_wx_cell_renderer_text_class_init
,
1049 NULL
, /* class_finalize */
1050 NULL
, /* class_data */
1051 sizeof (GtkWxCellRendererText
),
1052 0, /* n_preallocs */
1053 (GInstanceInitFunc
) gtk_wx_cell_renderer_text_init
,
1056 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER_TEXT
,
1057 "GtkWxCellRendererText", &cell_wx_info
, (GTypeFlags
)0 );
1060 return cell_wx_type
;
1064 gtk_wx_cell_renderer_text_init (GtkWxCellRendererText
*cell
)
1066 cell
->wx_renderer
= NULL
;
1070 gtk_wx_cell_renderer_text_class_init (GtkWxCellRendererTextClass
*klass
)
1072 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1073 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
1075 text_cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
1077 object_class
->finalize
= gtk_wx_cell_renderer_text_finalize
;
1079 cell_class
->start_editing
= gtk_wx_cell_renderer_text_start_editing
;
1083 gtk_wx_cell_renderer_text_finalize (GObject
*object
)
1086 (* G_OBJECT_CLASS (text_cell_parent_class
)->finalize
) (object
);
1089 GtkWxCellRendererText
*
1090 gtk_wx_cell_renderer_text_new (void)
1092 return (GtkWxCellRendererText
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER_TEXT
, NULL
);
1095 static GtkCellEditable
*gtk_wx_cell_renderer_text_start_editing(
1096 GtkCellRenderer
*gtk_renderer
,
1097 GdkEvent
*gdk_event
,
1100 GdkRectangle
*background_area
,
1101 GdkRectangle
*cell_area
,
1102 GtkCellRendererState flags
)
1104 GtkWxCellRendererText
*wxgtk_renderer
= (GtkWxCellRendererText
*) gtk_renderer
;
1105 wxDataViewRenderer
*wx_renderer
= wxgtk_renderer
->wx_renderer
;
1106 wxDataViewColumn
*column
= wx_renderer
->GetOwner();
1109 item(column
->GetOwner()->GTKPathToItem(wxGtkTreePath(path
)));
1111 wxDataViewCtrl
*dv
= column
->GetOwner();
1112 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, dv
->GetId() );
1113 event
.SetDataViewColumn( column
);
1114 event
.SetModel( dv
->GetModel() );
1115 event
.SetColumn( column
->GetModelColumn() );
1116 event
.SetItem( item
);
1117 dv
->HandleWindowEvent( event
);
1119 if (event
.IsAllowed())
1120 return GTK_CELL_RENDERER_CLASS(text_cell_parent_class
)->
1121 start_editing( gtk_renderer
, gdk_event
, widget
, path
, background_area
, cell_area
, flags
);
1126 //-----------------------------------------------------------------------------
1127 // define new GTK+ class GtkWxCellRenderer
1128 //-----------------------------------------------------------------------------
1132 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
1133 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
1134 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
1135 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
1136 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
1137 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
1139 GType
gtk_wx_cell_renderer_get_type (void);
1141 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
1142 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
1144 struct _GtkWxCellRenderer
1146 GtkCellRenderer parent
;
1149 wxDataViewCustomRenderer
*cell
;
1153 struct _GtkWxCellRendererClass
1155 GtkCellRendererClass cell_parent_class
;
1159 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
1160 static void gtk_wx_cell_renderer_init (
1161 GtkWxCellRenderer
*cell
);
1162 static void gtk_wx_cell_renderer_class_init(
1163 GtkWxCellRendererClass
*klass
);
1164 static void gtk_wx_cell_renderer_finalize (
1166 static void gtk_wx_cell_renderer_get_size (
1167 GtkCellRenderer
*cell
,
1169 GdkRectangle
*rectangle
,
1174 static void gtk_wx_cell_renderer_render (
1175 GtkCellRenderer
*cell
,
1178 GdkRectangle
*background_area
,
1179 GdkRectangle
*cell_area
,
1180 GdkRectangle
*expose_area
,
1181 GtkCellRendererState flags
);
1182 static gboolean
gtk_wx_cell_renderer_activate(
1183 GtkCellRenderer
*cell
,
1187 GdkRectangle
*background_area
,
1188 GdkRectangle
*cell_area
,
1189 GtkCellRendererState flags
);
1190 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1191 GtkCellRenderer
*cell
,
1195 GdkRectangle
*background_area
,
1196 GdkRectangle
*cell_area
,
1197 GtkCellRendererState flags
);
1200 static GObjectClass
*cell_parent_class
= NULL
;
1205 gtk_wx_cell_renderer_get_type (void)
1207 static GType cell_wx_type
= 0;
1211 const GTypeInfo cell_wx_info
=
1213 sizeof (GtkWxCellRendererClass
),
1214 NULL
, /* base_init */
1215 NULL
, /* base_finalize */
1216 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
1217 NULL
, /* class_finalize */
1218 NULL
, /* class_data */
1219 sizeof (GtkWxCellRenderer
),
1220 0, /* n_preallocs */
1221 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
1224 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
1225 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
1228 return cell_wx_type
;
1232 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
1235 cell
->last_click
= 0;
1239 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
1241 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1242 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
1244 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
1246 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
1248 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
1249 cell_class
->render
= gtk_wx_cell_renderer_render
;
1250 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
1251 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
1255 gtk_wx_cell_renderer_finalize (GObject
*object
)
1258 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
1262 gtk_wx_cell_renderer_new (void)
1264 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
1267 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
1268 GtkCellRenderer
*renderer
,
1269 GdkEvent
*WXUNUSED(event
),
1272 GdkRectangle
*WXUNUSED(background_area
),
1273 GdkRectangle
*cell_area
,
1274 GtkCellRendererState
WXUNUSED(flags
) )
1276 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1277 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1279 // Renderer doesn't support in-place editing
1280 if (!cell
->HasEditorCtrl())
1283 // An in-place editing control is still around
1284 if (cell
->GetEditorCtrl())
1288 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1294 rect
.x
+= cell_area
->x
;
1295 rect
.y
+= cell_area
->y
;
1296 // rect.width -= renderer->xpad * 2;
1297 // rect.height -= renderer->ypad * 2;
1299 // wxRect renderrect(wxRectFromGDKRect(&rect));
1300 wxRect
renderrect(wxRectFromGDKRect(cell_area
));
1303 item(cell
->GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(path
)));
1305 cell
->StartEditing( item
, renderrect
);
1311 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
1312 GtkWidget
*WXUNUSED(widget
),
1313 GdkRectangle
*cell_area
,
1319 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1320 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1322 wxSize size
= cell
->GetSize();
1324 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
1325 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
1332 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
1336 *x_offset
= (gint
)((renderer
->xalign
*
1337 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
1338 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
1342 *y_offset
= (gint
)((renderer
->yalign
*
1343 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
1344 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
1349 *width
= calc_width
;
1352 *height
= calc_height
;
1356 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
1359 GdkRectangle
*background_area
,
1360 GdkRectangle
*cell_area
,
1361 GdkRectangle
*expose_area
,
1362 GtkCellRendererState flags
)
1365 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1366 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1368 cell
->GTKStashRenderParams(window
, widget
,
1369 background_area
, expose_area
, flags
);
1371 wxRect
rect(wxRectFromGDKRect(cell_area
));
1372 rect
= rect
.Deflate(renderer
->xpad
, renderer
->ypad
);
1374 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
1375 wxWindowDCImpl
*impl
= (wxWindowDCImpl
*) dc
->GetImpl();
1377 // Reinitialize wxWindowDC's GDK window if drawing occurs into a different
1378 // window such as a DnD drop window.
1379 if (window
!= impl
->m_gdkwindow
)
1382 impl
->m_gdkwindow
= window
;
1387 if (flags
& GTK_CELL_RENDERER_SELECTED
)
1388 state
|= wxDATAVIEW_CELL_SELECTED
;
1389 if (flags
& GTK_CELL_RENDERER_PRELIT
)
1390 state
|= wxDATAVIEW_CELL_PRELIT
;
1391 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1392 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1393 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
1394 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
1395 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
1396 state
|= wxDATAVIEW_CELL_FOCUSED
;
1397 cell
->WXCallRender( rect
, dc
, state
);
1401 gtk_wx_cell_renderer_activate(
1402 GtkCellRenderer
*renderer
,
1406 GdkRectangle
*WXUNUSED(background_area
),
1407 GdkRectangle
*cell_area
,
1408 GtkCellRendererState
WXUNUSED(flags
) )
1410 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
1411 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
1414 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
1420 rect
.x
+= cell_area
->x
;
1421 rect
.y
+= cell_area
->y
;
1422 rect
.width
-= renderer
->xpad
* 2;
1423 rect
.height
-= renderer
->ypad
* 2;
1425 wxRect
renderrect(wxRectFromGDKRect(&rect
));
1427 wxDataViewCtrl
* const ctrl
= cell
->GetOwner()->GetOwner();
1428 wxDataViewModel
*model
= ctrl
->GetModel();
1430 wxDataViewItem
item(ctrl
->GTKPathToItem(wxGtkTreePath(path
)));
1432 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1438 // activated by <ENTER>
1439 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1444 else if (event
->type
== GDK_BUTTON_PRESS
)
1446 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
1447 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
1448 ((int) button_event
->y
) - renderrect
.y
);
1451 if (button_event
->button
== 1)
1453 if (cell
->LeftClick( pt
, renderrect
, model
, item
, model_col
))
1455 // TODO: query system double-click time
1456 if (button_event
->time
- wxrenderer
->last_click
< 400)
1457 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1460 wxrenderer
->last_click
= button_event
->time
;
1468 // ---------------------------------------------------------
1469 // wxGtkDataViewModelNotifier
1470 // ---------------------------------------------------------
1472 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1475 wxGtkDataViewModelNotifier( GtkWxTreeModel
*wxgtk_model
,
1476 wxDataViewModel
*wx_model
,
1477 wxDataViewCtrl
*ctrl
);
1478 ~wxGtkDataViewModelNotifier();
1480 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1481 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1482 virtual bool ItemChanged( const wxDataViewItem
&item
);
1483 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
1484 virtual bool Cleared();
1485 virtual void Resort();
1487 void SetGtkModel( GtkWxTreeModel
*model
) { m_wxgtk_model
= model
; }
1490 GtkWxTreeModel
*m_wxgtk_model
;
1491 wxDataViewModel
*m_wx_model
;
1492 wxDataViewCtrl
*m_owner
;
1495 // ---------------------------------------------------------
1496 // wxGtkDataViewListModelNotifier
1497 // ---------------------------------------------------------
1499 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1500 GtkWxTreeModel
* wxgtk_model
, wxDataViewModel
*wx_model
,
1501 wxDataViewCtrl
*ctrl
)
1503 m_wxgtk_model
= wxgtk_model
;
1504 m_wx_model
= wx_model
;
1508 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1511 m_wxgtk_model
= NULL
;
1514 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1516 m_owner
->GtkGetInternal()->ItemAdded( parent
, item
);
1519 iter
.stamp
= m_wxgtk_model
->stamp
;
1520 iter
.user_data
= item
.GetID();
1522 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1523 GTK_TREE_MODEL(m_wxgtk_model
), &iter
));
1524 gtk_tree_model_row_inserted(
1525 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1530 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1533 // using _get_path for a deleted item cannot be
1536 iter
.stamp
= m_wxgtk_model
->stamp
;
1537 iter
.user_data
= (gpointer
) item
.GetID();
1538 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1539 GTK_TREE_MODEL(m_wxgtk_model
), &iter
));
1541 // so get the path from the parent
1543 iter
.stamp
= m_wxgtk_model
->stamp
;
1544 iter
.user_data
= (gpointer
) parent
.GetID();
1545 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1546 GTK_TREE_MODEL(m_wxgtk_model
), &iter
));
1547 // and add the final index ourselves
1548 int index
= m_owner
->GtkGetInternal()->GetIndexOf( parent
, item
);
1549 gtk_tree_path_append_index( path
, index
);
1552 gtk_tree_model_row_deleted(
1553 GTK_TREE_MODEL(m_wxgtk_model
), path
);
1555 m_owner
->GtkGetInternal()->ItemDeleted( parent
, item
);
1560 void wxGtkDataViewModelNotifier::Resort()
1562 m_owner
->GtkGetInternal()->Resort();
1565 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1568 iter
.stamp
= m_wxgtk_model
->stamp
;
1569 iter
.user_data
= (gpointer
) item
.GetID();
1571 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1572 GTK_TREE_MODEL(m_wxgtk_model
), &iter
));
1573 gtk_tree_model_row_changed(
1574 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1576 m_owner
->GtkGetInternal()->ItemChanged( item
);
1581 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_col
)
1583 // This adds GTK+'s missing MVC logic for ValueChanged
1585 for (index
= 0; index
< m_owner
->GetColumnCount(); index
++)
1587 wxDataViewColumn
*column
= m_owner
->GetColumn( index
);
1588 if (column
->GetModelColumn() == model_col
)
1590 GtkTreeView
*widget
= GTK_TREE_VIEW(m_owner
->m_treeview
);
1591 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1595 iter
.stamp
= m_wxgtk_model
->stamp
;
1596 iter
.user_data
= (gpointer
) item
.GetID();
1597 wxGtkTreePath
path(wxgtk_tree_model_get_path(
1598 GTK_TREE_MODEL(m_wxgtk_model
), &iter
));
1599 GdkRectangle cell_area
;
1600 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1602 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1603 double d
= gtk_adjustment_get_value( hadjust
);
1604 int xdiff
= (int) d
;
1606 int ydiff
= gcolumn
->button
->allocation
.height
;
1608 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1609 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1611 m_owner
->GtkGetInternal()->ValueChanged( item
, model_col
);
1620 bool wxGtkDataViewModelNotifier::Cleared()
1622 m_owner
->GtkGetInternal()->Cleared();
1627 // ---------------------------------------------------------
1628 // wxDataViewRenderer
1629 // ---------------------------------------------------------
1631 static gpointer s_user_data
= NULL
;
1634 wxgtk_cell_editable_editing_done( GtkCellEditable
*WXUNUSED(editable
),
1635 wxDataViewRenderer
*wxrenderer
)
1637 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1638 wxDataViewCtrl
*dv
= column
->GetOwner();
1639 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1640 event
.SetDataViewColumn( column
);
1641 event
.SetModel( dv
->GetModel() );
1642 wxDataViewItem
item( s_user_data
);
1643 event
.SetItem( item
);
1644 dv
->HandleWindowEvent( event
);
1648 wxgtk_renderer_editing_started( GtkCellRenderer
*WXUNUSED(cell
), GtkCellEditable
*editable
,
1649 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1654 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1655 wxDataViewCtrl
*dv
= column
->GetOwner();
1656 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1657 event
.SetDataViewColumn( column
);
1658 event
.SetModel( dv
->GetModel() );
1659 wxDataViewItem
item(dv
->GTKPathToItem(wxGtkTreePath(path
)));
1660 event
.SetItem( item
);
1661 dv
->HandleWindowEvent( event
);
1663 if (GTK_IS_CELL_EDITABLE(editable
))
1665 s_user_data
= item
.GetID();
1667 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1668 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1669 (gpointer
) wxrenderer
);
1675 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1677 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1679 wxDataViewRendererBase( varianttype
, mode
, align
)
1683 // we haven't changed them yet
1684 m_usingDefaultAttrs
= true;
1686 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1687 // after the m_renderer pointer has been initialized
1690 void wxDataViewRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
1692 gtk_tree_view_column_pack_end( column
, m_renderer
, TRUE
/* expand */);
1695 void wxDataViewRenderer::GtkInitHandlers()
1697 if (!gtk_check_version(2,6,0))
1699 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1700 G_CALLBACK (wxgtk_renderer_editing_started
),
1705 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1707 GtkCellRendererMode gtkMode
;
1710 case wxDATAVIEW_CELL_INERT
:
1711 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1714 case wxDATAVIEW_CELL_ACTIVATABLE
:
1715 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1718 case wxDATAVIEW_CELL_EDITABLE
:
1719 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1723 wxFAIL_MSG( "unknown wxDataViewCellMode value" );
1727 // This value is most often ignored in GtkTreeView
1728 GValue gvalue
= { 0, };
1729 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1730 g_value_set_enum( &gvalue
, gtkMode
);
1731 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1732 g_value_unset( &gvalue
);
1735 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1737 wxDataViewCellMode ret
;
1740 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1742 switch (g_value_get_enum(&gvalue
))
1745 wxFAIL_MSG( "unknown GtkCellRendererMode value" );
1746 // fall through (we have to return something)
1748 case GTK_CELL_RENDERER_MODE_INERT
:
1749 ret
= wxDATAVIEW_CELL_INERT
;
1752 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1753 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1756 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1757 ret
= wxDATAVIEW_CELL_EDITABLE
;
1761 g_value_unset( &gvalue
);
1766 void wxDataViewRenderer::GtkUpdateAlignment()
1768 int align
= m_alignment
;
1770 // query alignment from column ?
1774 if (GetOwner() == NULL
)
1777 align
= GetOwner()->GetAlignment();
1778 align
|= wxALIGN_CENTRE_VERTICAL
;
1781 // horizontal alignment:
1783 gfloat xalign
= 0.0;
1784 if (align
& wxALIGN_RIGHT
)
1786 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1789 GValue gvalue
= { 0, };
1790 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1791 g_value_set_float( &gvalue
, xalign
);
1792 g_object_set_property( G_OBJECT(m_renderer
), "xalign", &gvalue
);
1793 g_value_unset( &gvalue
);
1795 // vertical alignment:
1797 gfloat yalign
= 0.0;
1798 if (align
& wxALIGN_BOTTOM
)
1800 else if (align
& wxALIGN_CENTER_VERTICAL
)
1803 GValue gvalue2
= { 0, };
1804 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1805 g_value_set_float( &gvalue2
, yalign
);
1806 g_object_set_property( G_OBJECT(m_renderer
), "yalign", &gvalue2
);
1807 g_value_unset( &gvalue2
);
1810 void wxDataViewRenderer::SetAlignment( int align
)
1812 m_alignment
= align
;
1813 GtkUpdateAlignment();
1816 int wxDataViewRenderer::GetAlignment() const
1821 void wxDataViewRenderer::EnableEllipsize(wxEllipsizeMode mode
)
1824 if ( gtk_check_version(2, 6, 0) != NULL
)
1827 GtkCellRendererText
* const rend
= GtkGetTextRenderer();
1831 // we use the same values in wxEllipsizeMode as PangoEllipsizeMode so we
1832 // can just cast between them
1833 GValue gvalue
= { 0, };
1834 g_value_init( &gvalue
, PANGO_TYPE_ELLIPSIZE_MODE
);
1835 g_value_set_enum( &gvalue
, static_cast<PangoEllipsizeMode
>(mode
) );
1836 g_object_set_property( G_OBJECT(rend
), "ellipsize", &gvalue
);
1837 g_value_unset( &gvalue
);
1840 #endif // GTK 2.6/before
1843 wxEllipsizeMode
wxDataViewRenderer::GetEllipsizeMode() const
1846 if ( gtk_check_version(2, 6, 0) != NULL
)
1847 return wxELLIPSIZE_NONE
;
1849 GtkCellRendererText
* const rend
= GtkGetTextRenderer();
1851 return wxELLIPSIZE_NONE
;
1853 GValue gvalue
= { 0, };
1854 g_value_init( &gvalue
, PANGO_TYPE_ELLIPSIZE_MODE
);
1855 g_object_get_property( G_OBJECT(rend
), "ellipsize", &gvalue
);
1857 mode
= static_cast<wxEllipsizeMode
>(g_value_get_enum( &gvalue
));
1858 g_value_unset( &gvalue
);
1862 return wxELLIPSIZE_NONE
;
1863 #endif // GTK 2.6/before
1867 wxDataViewRenderer::GtkOnTextEdited(const gchar
*itempath
, const wxString
& str
)
1869 wxVariant
value(str
);
1870 if (!Validate( value
))
1874 item(GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(itempath
)));
1876 GtkOnCellChanged(value
, item
, GetOwner()->GetModelColumn());
1880 wxDataViewRenderer::GtkOnCellChanged(const wxVariant
& value
,
1881 const wxDataViewItem
& item
,
1884 wxDataViewModel
*model
= GetOwner()->GetOwner()->GetModel();
1885 model
->ChangeValue( value
, item
, col
);
1888 // ---------------------------------------------------------
1889 // wxDataViewTextRenderer
1890 // ---------------------------------------------------------
1895 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*WXUNUSED(renderer
),
1896 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1898 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) user_data
;
1900 cell
->GtkOnTextEdited(arg1
, wxGTK_CONV_BACK_FONT(
1901 arg2
, cell
->GetOwner()->GetOwner()->GetFont()));
1909 // helper function used by wxDataViewTextRenderer and
1910 // wxDataViewCustomRenderer::RenderText(): it applies the attributes to the
1911 // given text renderer and returns true if anything was done
1912 bool GtkApplyAttr(GtkCellRendererText
*renderer
, const wxDataViewItemAttr
& attr
)
1914 bool usingDefaultAttrs
= true;
1915 if (attr
.HasColour())
1917 const GdkColor
* const gcol
= attr
.GetColour().GetColor();
1919 GValue gvalue
= { 0, };
1920 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
1921 g_value_set_boxed( &gvalue
, gcol
);
1922 g_object_set_property( G_OBJECT(renderer
), "foreground_gdk", &gvalue
);
1923 g_value_unset( &gvalue
);
1925 usingDefaultAttrs
= false;
1929 GValue gvalue
= { 0, };
1930 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1931 g_value_set_boolean( &gvalue
, FALSE
);
1932 g_object_set_property( G_OBJECT(renderer
), "foreground-set", &gvalue
);
1933 g_value_unset( &gvalue
);
1936 if (attr
.GetItalic())
1938 GValue gvalue
= { 0, };
1939 g_value_init( &gvalue
, PANGO_TYPE_STYLE
);
1940 g_value_set_enum( &gvalue
, PANGO_STYLE_ITALIC
);
1941 g_object_set_property( G_OBJECT(renderer
), "style", &gvalue
);
1942 g_value_unset( &gvalue
);
1944 usingDefaultAttrs
= false;
1948 GValue gvalue
= { 0, };
1949 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1950 g_value_set_boolean( &gvalue
, FALSE
);
1951 g_object_set_property( G_OBJECT(renderer
), "style-set", &gvalue
);
1952 g_value_unset( &gvalue
);
1958 GValue gvalue
= { 0, };
1959 g_value_init( &gvalue
, PANGO_TYPE_WEIGHT
);
1960 g_value_set_enum( &gvalue
, PANGO_WEIGHT_BOLD
);
1961 g_object_set_property( G_OBJECT(renderer
), "weight", &gvalue
);
1962 g_value_unset( &gvalue
);
1964 usingDefaultAttrs
= false;
1968 GValue gvalue
= { 0, };
1969 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1970 g_value_set_boolean( &gvalue
, FALSE
);
1971 g_object_set_property( G_OBJECT(renderer
), "weight-set", &gvalue
);
1972 g_value_unset( &gvalue
);
1976 if (attr
.HasBackgroundColour())
1978 wxColour colour
= attr
.GetBackgroundColour();
1979 const GdkColor
* const gcol
= colour
.GetColor();
1981 GValue gvalue
= { 0, };
1982 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
1983 g_value_set_boxed( &gvalue
, gcol
);
1984 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
1985 g_value_unset( &gvalue
);
1989 GValue gvalue
= { 0, };
1990 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1991 g_value_set_boolean( &gvalue
, FALSE
);
1992 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
1993 g_value_unset( &gvalue
);
1997 return !usingDefaultAttrs
;
2000 } // anonymous namespace
2002 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
2004 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
2006 wxDataViewRenderer( varianttype
, mode
, align
)
2008 GtkWxCellRendererText
*text_renderer
= gtk_wx_cell_renderer_text_new();
2009 text_renderer
->wx_renderer
= this;
2010 m_renderer
= (GtkCellRenderer
*) text_renderer
;
2012 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
2014 GValue gvalue
= { 0, };
2015 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2016 g_value_set_boolean( &gvalue
, true );
2017 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
2018 g_value_unset( &gvalue
);
2020 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2026 SetAlignment(align
);
2029 bool wxDataViewTextRenderer::SetTextValue(const wxString
& str
)
2031 GValue gvalue
= { 0, };
2032 g_value_init( &gvalue
, G_TYPE_STRING
);
2033 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( str
, GetOwner()->GetOwner()->GetFont() ) );
2034 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2035 g_value_unset( &gvalue
);
2040 bool wxDataViewTextRenderer::GetTextValue(wxString
& str
) const
2042 GValue gvalue
= { 0, };
2043 g_value_init( &gvalue
, G_TYPE_STRING
);
2044 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2045 str
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
), const_cast<wxDataViewTextRenderer
*>(this)->GetOwner()->GetOwner()->GetFont() );
2046 g_value_unset( &gvalue
);
2051 void wxDataViewTextRenderer::SetAlignment( int align
)
2053 wxDataViewRenderer::SetAlignment(align
);
2055 if (gtk_check_version(2,10,0))
2058 // horizontal alignment:
2059 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2060 if (align
& wxALIGN_RIGHT
)
2061 pangoAlign
= PANGO_ALIGN_RIGHT
;
2062 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2063 pangoAlign
= PANGO_ALIGN_CENTER
;
2065 GValue gvalue
= { 0, };
2066 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2067 g_value_set_enum( &gvalue
, pangoAlign
);
2068 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2069 g_value_unset( &gvalue
);
2072 bool wxDataViewTextRenderer::GtkSetAttr(const wxDataViewItemAttr
& attr
)
2074 return GtkApplyAttr(GtkGetTextRenderer(), attr
);
2077 GtkCellRendererText
*wxDataViewTextRenderer::GtkGetTextRenderer() const
2079 return GTK_CELL_RENDERER_TEXT(m_renderer
);
2082 // ---------------------------------------------------------
2083 // wxDataViewBitmapRenderer
2084 // ---------------------------------------------------------
2089 // set "pixbuf" property on the given renderer
2090 void SetPixbufProp(GtkCellRenderer
*renderer
, GdkPixbuf
*pixbuf
)
2092 GValue gvalue
= { 0, };
2093 g_value_init( &gvalue
, G_TYPE_OBJECT
);
2094 g_value_set_object( &gvalue
, pixbuf
);
2095 g_object_set_property( G_OBJECT(renderer
), "pixbuf", &gvalue
);
2096 g_value_unset( &gvalue
);
2099 } // anonymous namespace
2101 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
2103 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
2105 wxDataViewRenderer( varianttype
, mode
, align
)
2107 m_renderer
= gtk_cell_renderer_pixbuf_new();
2110 SetAlignment(align
);
2113 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
2115 if (value
.GetType() == wxT("wxBitmap"))
2120 // GetPixbuf() may create a Pixbuf representation in the wxBitmap
2121 // object (and it will stay there and remain owned by wxBitmap)
2122 SetPixbufProp(m_renderer
, bitmap
.GetPixbuf());
2124 else if (value
.GetType() == wxT("wxIcon"))
2129 SetPixbufProp(m_renderer
, icon
.GetPixbuf());
2139 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2144 // ---------------------------------------------------------
2145 // wxDataViewToggleRenderer
2146 // ---------------------------------------------------------
2149 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
2150 gchar
*path
, gpointer user_data
);
2153 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
2154 gchar
*path
, gpointer user_data
)
2156 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
2159 GValue gvalue
= { 0, };
2160 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2161 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
2162 bool tmp
= g_value_get_boolean( &gvalue
);
2163 g_value_unset( &gvalue
);
2167 wxVariant value
= tmp
;
2168 if (!cell
->Validate( value
))
2171 wxDataViewCtrl
* const ctrl
= cell
->GetOwner()->GetOwner();
2172 wxDataViewModel
*model
= ctrl
->GetModel();
2174 wxDataViewItem
item(ctrl
->GTKPathToItem(wxGtkTreePath(path
)));
2176 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
2178 model
->ChangeValue( value
, item
, model_col
);
2181 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
2183 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
2184 wxDataViewCellMode mode
, int align
) :
2185 wxDataViewRenderer( varianttype
, mode
, align
)
2187 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
2189 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
2191 g_signal_connect_after( m_renderer
, "toggled",
2192 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
2196 GValue gvalue
= { 0, };
2197 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2198 g_value_set_boolean( &gvalue
, false );
2199 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
2200 g_value_unset( &gvalue
);
2204 SetAlignment(align
);
2207 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
2211 GValue gvalue
= { 0, };
2212 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2213 g_value_set_boolean( &gvalue
, tmp
);
2214 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
2215 g_value_unset( &gvalue
);
2220 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
2222 GValue gvalue
= { 0, };
2223 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2224 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
2225 bool tmp
= g_value_get_boolean( &gvalue
);
2226 g_value_unset( &gvalue
);
2233 // ---------------------------------------------------------
2234 // wxDataViewCustomRenderer
2235 // ---------------------------------------------------------
2237 class wxDataViewCtrlDCImpl
: public wxWindowDCImpl
2240 wxDataViewCtrlDCImpl( wxDC
*owner
, wxDataViewCtrl
*window
) :
2241 wxWindowDCImpl( owner
)
2243 GtkWidget
*widget
= window
->m_treeview
;
2249 m_context
= window
->GTKGetPangoDefaultContext();
2250 m_layout
= pango_layout_new( m_context
);
2251 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
2253 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
2255 // Set m_gdkwindow later
2260 class wxDataViewCtrlDC
: public wxWindowDC
2263 wxDataViewCtrlDC( wxDataViewCtrl
*window
) :
2264 wxWindowDC( new wxDataViewCtrlDCImpl( this, window
) )
2269 // ---------------------------------------------------------
2270 // wxDataViewCustomRenderer
2271 // ---------------------------------------------------------
2273 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
2275 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
2276 wxDataViewCellMode mode
,
2279 : wxDataViewCustomRendererBase( varianttype
, mode
, align
)
2282 m_text_renderer
= NULL
;
2290 GtkCellRendererText
*wxDataViewCustomRenderer::GtkGetTextRenderer() const
2292 if ( !m_text_renderer
)
2294 // we create it on demand so need to do it even from a const function
2295 const_cast<wxDataViewCustomRenderer
*>(this)->
2296 m_text_renderer
= GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new());
2299 return m_text_renderer
;
2302 void wxDataViewCustomRenderer::RenderText( const wxString
&text
,
2306 int WXUNUSED(state
) )
2309 GtkCellRendererText
* const textRenderer
= GtkGetTextRenderer();
2311 GValue gvalue
= { 0, };
2312 g_value_init( &gvalue
, G_TYPE_STRING
);
2313 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( text
, GetOwner()->GetOwner()->GetFont() ) );
2314 g_object_set_property( G_OBJECT(textRenderer
), "text", &gvalue
);
2315 g_value_unset( &gvalue
);
2317 GtkApplyAttr(textRenderer
, GetAttr());
2319 GdkRectangle cell_area
;
2320 wxRectToGDKRect(cell
, cell_area
);
2321 cell_area
.x
+= xoffset
;
2322 cell_area
.width
-= xoffset
;
2324 gtk_cell_renderer_render( GTK_CELL_RENDERER(textRenderer
),
2325 m_renderParams
.window
,
2326 m_renderParams
.widget
,
2327 m_renderParams
.background_area
,
2329 m_renderParams
.expose_area
,
2330 (GtkCellRendererState
) m_renderParams
.flags
);
2333 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
2335 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
2336 renderer
->cell
= this;
2338 m_renderer
= (GtkCellRenderer
*) renderer
;
2341 SetAlignment(align
);
2348 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
2353 if (m_text_renderer
)
2354 gtk_object_sink( GTK_OBJECT(m_text_renderer
) );
2357 wxDC
*wxDataViewCustomRenderer::GetDC()
2361 if (GetOwner() == NULL
)
2363 if (GetOwner()->GetOwner() == NULL
)
2365 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
2371 // ---------------------------------------------------------
2372 // wxDataViewProgressRenderer
2373 // ---------------------------------------------------------
2375 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
2377 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
2378 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
2379 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
2385 if (!gtk_check_version(2,6,0))
2387 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
2389 GValue gvalue
= { 0, };
2390 g_value_init( &gvalue
, G_TYPE_STRING
);
2392 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( m_label
, GetOwner()->GetOwner()->GetFont() ) );
2393 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2394 g_value_unset( &gvalue
);
2397 SetAlignment(align
);
2402 // Use custom cell code
2403 wxDataViewCustomRenderer::Init(mode
, align
);
2407 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
2411 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
2414 if (!gtk_check_version(2,6,0))
2416 gint tmp
= (long) value
;
2417 GValue gvalue
= { 0, };
2418 g_value_init( &gvalue
, G_TYPE_INT
);
2419 g_value_set_int( &gvalue
, tmp
);
2420 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
2421 g_value_unset( &gvalue
);
2426 m_value
= (long) value
;
2428 if (m_value
< 0) m_value
= 0;
2429 if (m_value
> 100) m_value
= 100;
2435 bool wxDataViewProgressRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2440 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
2442 double pct
= (double)m_value
/ 100.0;
2444 bar
.width
= (int)(cell
.width
* pct
);
2445 dc
->SetPen( *wxTRANSPARENT_PEN
);
2446 dc
->SetBrush( *wxBLUE_BRUSH
);
2447 dc
->DrawRectangle( bar
);
2449 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
2450 dc
->SetPen( *wxBLACK_PEN
);
2451 dc
->DrawRectangle( cell
);
2456 wxSize
wxDataViewProgressRenderer::GetSize() const
2458 return wxSize(40,12);
2461 // -------------------------------------
2462 // wxDataViewChoiceRenderer
2463 // -------------------------------------
2465 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
&choices
,
2466 wxDataViewCellMode mode
, int alignment
) :
2467 wxDataViewCustomRenderer( "string", mode
, alignment
, true )
2469 m_choices
= choices
;
2472 if (!gtk_check_version(2,6,0))
2474 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_combo_new();
2476 GtkListStore
*store
= gtk_list_store_new( 1, G_TYPE_STRING
);
2477 for (size_t n
= 0; n
< m_choices
.GetCount(); n
++)
2479 gtk_list_store_insert_with_values(
2481 static_cast<const char *>(m_choices
[n
].utf8_str()), -1 );
2484 g_object_set (m_renderer
,
2490 bool editable
= (mode
& wxDATAVIEW_CELL_EDITABLE
);
2491 g_object_set (m_renderer
, "editable", editable
, NULL
);
2493 SetAlignment(alignment
);
2495 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
2502 // Use custom cell code
2503 wxDataViewCustomRenderer::Init(mode
, alignment
);
2507 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
2509 RenderText( m_data
, 0, rect
, dc
, state
);
2513 wxSize
wxDataViewChoiceRenderer::GetSize() const
2515 return wxSize(70,20);
2518 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
2522 if (!gtk_check_version(2,6,0))
2524 GValue gvalue
= { 0, };
2525 g_value_init( &gvalue
, G_TYPE_STRING
);
2526 g_value_set_string(&gvalue
,
2527 wxGTK_CONV_FONT(value
.GetString(),
2528 GetOwner()->GetOwner()->GetFont()));
2529 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2530 g_value_unset( &gvalue
);
2534 m_data
= value
.GetString();
2539 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
2542 if (!gtk_check_version(2,6,0))
2544 GValue gvalue
= { 0, };
2545 g_value_init( &gvalue
, G_TYPE_STRING
);
2546 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
2547 wxString temp
= wxGTK_CONV_BACK_FONT(g_value_get_string(&gvalue
),
2548 GetOwner()->GetOwner()->GetFont());
2549 g_value_unset( &gvalue
);
2552 //wxPrintf( "temp %s\n", temp );
2553 // TODO: remove this code
2562 void wxDataViewChoiceRenderer::SetAlignment( int align
)
2564 wxDataViewCustomRenderer::SetAlignment(align
);
2566 if (gtk_check_version(2,10,0))
2569 // horizontal alignment:
2570 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
2571 if (align
& wxALIGN_RIGHT
)
2572 pangoAlign
= PANGO_ALIGN_RIGHT
;
2573 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
2574 pangoAlign
= PANGO_ALIGN_CENTER
;
2576 GValue gvalue
= { 0, };
2577 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
2578 g_value_set_enum( &gvalue
, pangoAlign
);
2579 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
2580 g_value_unset( &gvalue
);
2583 // ----------------------------------------------------------------------------
2584 // wxDataViewChoiceByIndexRenderer
2585 // ----------------------------------------------------------------------------
2587 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
2588 wxDataViewCellMode mode
, int alignment
) :
2589 wxDataViewChoiceRenderer( choices
, mode
, alignment
)
2593 void wxDataViewChoiceByIndexRenderer::GtkOnTextEdited(const gchar
*itempath
, const wxString
& str
)
2595 wxVariant
value( (long) GetChoices().Index( str
) );
2597 if (!Validate( value
))
2601 item(GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(itempath
)));
2603 GtkOnCellChanged(value
, item
, GetOwner()->GetModelColumn());
2606 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant
&value
)
2608 wxVariant string_value
= GetChoice( value
.GetLong() );
2609 return wxDataViewChoiceRenderer::SetValue( string_value
);
2612 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant
&value
) const
2614 wxVariant string_value
;
2615 if (!wxDataViewChoiceRenderer::GetValue( string_value
))
2618 value
= (long) GetChoices().Index( string_value
.GetString() );
2622 // ---------------------------------------------------------
2623 // wxDataViewDateRenderer
2624 // ---------------------------------------------------------
2626 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
2629 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
2630 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
2631 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
2636 m_cal
= new wxCalendarCtrl( this, -1, *value
);
2637 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
2638 sizer
->Add( m_cal
, 1, wxGROW
);
2643 virtual void OnDismiss()
2647 void OnCalendar( wxCalendarEvent
&event
);
2649 wxCalendarCtrl
*m_cal
;
2650 wxDataViewModel
*m_model
;
2651 wxDataViewItem m_item
;
2655 DECLARE_EVENT_TABLE()
2658 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
2659 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
2662 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
2664 m_model
->ChangeValue( event
.GetDate(), m_item
, m_col
);
2668 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
2670 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
2671 wxDataViewCellMode mode
, int align
) :
2672 wxDataViewCustomRenderer( varianttype
, mode
, align
)
2675 SetAlignment(align
);
2678 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
2680 m_date
= value
.GetDateTime();
2685 bool wxDataViewDateRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
2690 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2692 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
2693 wxString tmp
= m_date
.FormatDate();
2694 RenderText( tmp
, 0, cell
, dc
, state
);
2698 wxSize
wxDataViewDateRenderer::GetSize() const
2700 wxString tmp
= m_date
.FormatDate();
2702 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
2703 return wxSize(x
,y
+d
);
2706 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
2707 const wxDataViewItem
&item
, unsigned int col
)
2710 model
->GetValue( variant
, item
, col
);
2711 wxDateTime value
= variant
.GetDateTime();
2713 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
2714 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
2715 wxPoint pos
= wxGetMousePosition();
2718 popup
->Popup( popup
->m_cal
);
2724 // ---------------------------------------------------------
2725 // wxDataViewIconTextRenderer
2726 // ---------------------------------------------------------
2728 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
2730 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer
2732 const wxString
&varianttype
,
2733 wxDataViewCellMode mode
,
2736 : wxDataViewTextRenderer(varianttype
, mode
, align
)
2738 m_rendererIcon
= gtk_cell_renderer_pixbuf_new();
2741 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2745 void wxDataViewIconTextRenderer::GtkPackIntoColumn(GtkTreeViewColumn
*column
)
2747 // add the icon renderer first
2748 gtk_tree_view_column_pack_start(column
, m_rendererIcon
, FALSE
/* !expand */);
2750 // add the text renderer too
2751 wxDataViewRenderer::GtkPackIntoColumn(column
);
2754 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
2758 SetTextValue(m_value
.GetText());
2759 SetPixbufProp(m_rendererIcon
, m_value
.GetIcon().GetPixbuf());
2764 bool wxDataViewIconTextRenderer::GetValue(wxVariant
& value
) const
2767 if ( !GetTextValue(str
) )
2770 // user doesn't have any way to edit the icon so leave it unchanged
2771 value
<< wxDataViewIconText(str
, m_value
.GetIcon());
2777 wxDataViewIconTextRenderer::GtkOnCellChanged(const wxVariant
& value
,
2778 const wxDataViewItem
& item
,
2781 // we receive just the text part of our value as it's the only one which
2782 // can be edited, but we need the full wxDataViewIconText value for the
2784 wxVariant valueIconText
;
2785 valueIconText
<< wxDataViewIconText(value
.GetString(), m_value
.GetIcon());
2786 wxDataViewTextRenderer::GtkOnCellChanged(valueIconText
, item
, col
);
2789 // ---------------------------------------------------------
2791 // ---------------------------------------------------------
2795 gtk_dataview_header_button_press_callback( GtkWidget
*WXUNUSED(widget
),
2796 GdkEventButton
*gdk_event
,
2797 wxDataViewColumn
*column
)
2799 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
2802 if (gdk_event
->button
== 1)
2804 gs_lastLeftClickHeader
= column
;
2806 wxDataViewCtrl
*dv
= column
->GetOwner();
2807 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
2808 event
.SetDataViewColumn( column
);
2809 event
.SetModel( dv
->GetModel() );
2810 if (dv
->HandleWindowEvent( event
))
2814 if (gdk_event
->button
== 3)
2816 wxDataViewCtrl
*dv
= column
->GetOwner();
2817 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
2818 event
.SetDataViewColumn( column
);
2819 event
.SetModel( dv
->GetModel() );
2820 if (dv
->HandleWindowEvent( event
))
2830 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*WXUNUSED(column
),
2831 GtkCellRenderer
*renderer
,
2832 GtkTreeModel
*model
,
2836 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2837 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2839 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2841 wxDataViewItem
item( (void*) iter
->user_data
);
2843 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
2845 if (!wx_model
->IsVirtualListModel())
2848 if (wx_model
->IsContainer( item
))
2850 visible
= wx_model
->HasContainerColumns( item
) ||
2851 (cell
->GetOwner()->GetModelColumn() == 0);
2858 GValue gvalue
= { 0, };
2859 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2860 g_value_set_boolean( &gvalue
, visible
);
2861 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2862 g_value_unset( &gvalue
);
2869 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
2871 if (value
.GetType() != cell
->GetVariantType())
2873 wxLogError( wxT("Wrong type, required: %s but: %s"),
2874 value
.GetType().c_str(),
2875 cell
->GetVariantType().c_str() );
2878 cell
->SetValue( value
);
2881 // deal with attributes: if the renderer doesn't support them at all, we
2882 // don't even need to query the model for them
2883 if ( !cell
->GtkSupportsAttrs() )
2886 // it can support attributes so check if this item has any
2887 wxDataViewItemAttr attr
;
2888 if ( wx_model
->GetAttr( item
, cell
->GetOwner()->GetModelColumn(), attr
)
2889 || !cell
->GtkIsUsingDefaultAttrs() )
2891 bool usingDefaultAttrs
= !cell
->GtkSetAttr(attr
);
2892 cell
->GtkSetUsingDefaultAttrs(usingDefaultAttrs
);
2894 // else: no custom attributes specified and we're already using the default
2895 // ones -- nothing to do
2900 #include <wx/listimpl.cpp>
2901 WX_DEFINE_LIST(wxDataViewColumnList
)
2903 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
2904 unsigned int model_column
, int width
,
2905 wxAlignment align
, int flags
)
2906 : wxDataViewColumnBase( cell
, model_column
)
2908 Init( align
, flags
, width
);
2913 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
2914 unsigned int model_column
, int width
,
2915 wxAlignment align
, int flags
)
2916 : wxDataViewColumnBase( bitmap
, cell
, model_column
)
2918 Init( align
, flags
, width
);
2920 SetBitmap( bitmap
);
2923 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
2925 m_isConnected
= false;
2927 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
2928 m_column
= (GtkWidget
*) column
;
2931 SetAlignment( align
);
2935 // Create container for icon and label
2936 GtkWidget
*box
= gtk_hbox_new( FALSE
, 1 );
2937 gtk_widget_show( box
);
2938 // gtk_container_set_border_width((GtkContainer*)box, 2);
2939 m_image
= gtk_image_new();
2940 gtk_box_pack_start(GTK_BOX(box
), m_image
, FALSE
, FALSE
, 1);
2941 m_label
= gtk_label_new("");
2942 gtk_box_pack_end( GTK_BOX(box
), GTK_WIDGET(m_label
), FALSE
, FALSE
, 1 );
2943 gtk_tree_view_column_set_widget( column
, box
);
2945 wxDataViewRenderer
* const colRenderer
= GetRenderer();
2946 GtkCellRenderer
* const cellRenderer
= colRenderer
->GetGtkHandle();
2948 colRenderer
->GtkPackIntoColumn(column
);
2950 gtk_tree_view_column_set_cell_data_func( column
, cellRenderer
,
2951 wxGtkTreeCellDataFunc
, (gpointer
) colRenderer
, NULL
);
2954 void wxDataViewColumn::OnInternalIdle()
2959 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
2961 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2964 g_signal_connect(column
->button
, "button_press_event",
2965 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
2967 // otherwise the event will be blocked by GTK+
2968 gtk_tree_view_column_set_clickable( column
, TRUE
);
2970 m_isConnected
= true;
2975 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
2977 wxDataViewColumnBase::SetOwner( owner
);
2979 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2981 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
2984 void wxDataViewColumn::SetTitle( const wxString
&title
)
2986 wxDataViewCtrl
*ctrl
= GetOwner();
2987 gtk_label_set_text( GTK_LABEL(m_label
), ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
2988 : wxGTK_CONV_SYS(title
) );
2990 gtk_widget_hide( m_label
);
2992 gtk_widget_show( m_label
);
2995 wxString
wxDataViewColumn::GetTitle() const
2997 return wxGTK_CONV_BACK_FONT(
2998 gtk_label_get_text( GTK_LABEL(m_label
) ),
2999 GetOwner()->GetFont()
3003 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
3005 wxDataViewColumnBase::SetBitmap( bitmap
);
3009 GtkImage
*gtk_image
= GTK_IMAGE(m_image
);
3011 GdkBitmap
*mask
= NULL
;
3012 if (bitmap
.GetMask())
3013 mask
= bitmap
.GetMask()->GetBitmap();
3015 if (bitmap
.HasPixbuf())
3017 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
3018 bitmap
.GetPixbuf());
3022 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
3023 bitmap
.GetPixmap(), mask
);
3025 gtk_widget_show( m_image
);
3029 gtk_widget_hide( m_image
);
3033 void wxDataViewColumn::SetHidden( bool hidden
)
3035 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
3038 void wxDataViewColumn::SetResizeable( bool resizeable
)
3040 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizeable
);
3043 void wxDataViewColumn::SetAlignment( wxAlignment align
)
3045 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3047 gfloat xalign
= 0.0;
3048 if (align
== wxALIGN_RIGHT
)
3050 if (align
== wxALIGN_CENTER_HORIZONTAL
||
3051 align
== wxALIGN_CENTER
)
3054 gtk_tree_view_column_set_alignment( column
, xalign
);
3056 if (m_renderer
&& m_renderer
->GetAlignment() == -1)
3057 m_renderer
->GtkUpdateAlignment();
3060 wxAlignment
wxDataViewColumn::GetAlignment() const
3062 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
3065 return wxALIGN_RIGHT
;
3067 return wxALIGN_CENTER_HORIZONTAL
;
3069 return wxALIGN_LEFT
;
3072 void wxDataViewColumn::SetSortable( bool sortable
)
3074 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3078 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
3082 gtk_tree_view_column_set_sort_column_id( column
, -1 );
3083 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
3084 gtk_tree_view_column_set_clickable( column
, FALSE
);
3088 bool wxDataViewColumn::IsSortable() const
3090 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3091 return gtk_tree_view_column_get_clickable( column
);
3094 void wxDataViewColumn::SetAsSortKey( bool WXUNUSED(sort
) )
3096 // it might not make sense to have this function in wxHeaderColumn at
3097 // all in fact, changing of the sort order should only be done using the
3098 // associated control API
3099 wxFAIL_MSG( "not implemented" );
3102 bool wxDataViewColumn::IsSortKey() const
3104 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3105 return gtk_tree_view_column_get_sort_indicator( column
);
3108 bool wxDataViewColumn::IsResizeable() const
3110 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3111 return gtk_tree_view_column_get_resizable( column
);
3114 bool wxDataViewColumn::IsHidden() const
3116 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3117 return !gtk_tree_view_column_get_visible( column
);
3120 void wxDataViewColumn::SetSortOrder( bool ascending
)
3122 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3125 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
3127 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
3129 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
3132 bool wxDataViewColumn::IsSortOrderAscending() const
3134 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
3136 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
3139 void wxDataViewColumn::SetMinWidth( int width
)
3141 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
3144 int wxDataViewColumn::GetMinWidth() const
3146 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
3149 int wxDataViewColumn::GetWidth() const
3151 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
3154 void wxDataViewColumn::SetWidth( int width
)
3159 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
3161 // TODO find a better calculation
3162 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), wxDVC_DEFAULT_WIDTH
);
3164 // this is unpractical for large numbers of items and disables
3165 // user resizing, which is totally unexpected
3166 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
3171 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column
), GTK_TREE_VIEW_COLUMN_FIXED
);
3173 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
3177 void wxDataViewColumn::SetReorderable( bool reorderable
)
3179 gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column
), reorderable
);
3182 bool wxDataViewColumn::IsReorderable() const
3184 return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column
) );
3187 //-----------------------------------------------------------------------------
3188 // wxGtkTreeModelNode
3189 //-----------------------------------------------------------------------------
3192 class wxGtkTreeModelChildWithPos
3200 int wxGtkTreeModelChildWithPosCmp( const void* data1
, const void* data2
, const void* user_data
)
3202 const wxGtkTreeModelChildWithPos
* child1
= (const wxGtkTreeModelChildWithPos
*) data1
;
3203 const wxGtkTreeModelChildWithPos
* child2
= (const wxGtkTreeModelChildWithPos
*) data2
;
3204 const wxDataViewCtrlInternal
*internal
= (const wxDataViewCtrlInternal
*) user_data
;
3205 int ret
= internal
->GetDataViewModel()->Compare( child1
->id
, child2
->id
,
3206 internal
->GetSortColumn(), (internal
->GetSortOrder() == GTK_SORT_DESCENDING
) );
3212 int LINKAGEMODE
wxGtkTreeModelChildPtrCmp( void*** data1
, void*** data2
)
3214 return gs_internal
->GetDataViewModel()->Compare( **data1
, **data2
,
3215 gs_internal
->GetSortColumn(), (gs_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
3218 WX_DEFINE_ARRAY_PTR( void**, wxGtkTreeModelChildrenPtr
);
3221 void wxGtkTreeModelNode::Resort()
3223 size_t child_count
= GetChildCount();
3224 if (child_count
== 0)
3227 size_t node_count
= GetNodesCount();
3229 if (child_count
== 1)
3231 if (node_count
== 1)
3233 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
3239 gint
*new_order
= new gint
[child_count
];
3242 // m_children has the original *void
3243 // ptrs points to these
3244 wxGtkTreeModelChildrenPtr ptrs
;
3246 for (i
= 0; i
< child_count
; i
++)
3247 ptrs
.Add( &(m_children
[i
]) );
3249 gs_internal
= m_internal
;
3250 ptrs
.Sort( &wxGtkTreeModelChildPtrCmp
);
3252 wxGtkTreeModelChildren temp
;
3253 void** base_ptr
= &(m_children
[0]);
3254 // Transfer positions to new_order array and
3256 for (i
= 0; i
< child_count
; i
++)
3258 new_order
[i
] = ptrs
[i
] - base_ptr
;
3259 temp
.Add( *ptrs
[i
] );
3262 // Transfer IDs back to m_children
3264 WX_APPEND_ARRAY( temp
, m_children
);
3269 // Build up array with IDs and original positions
3270 wxGtkTreeModelChildWithPos
* temp
= new wxGtkTreeModelChildWithPos
[child_count
];
3272 for (i
= 0; i
< child_count
; i
++)
3275 temp
[i
].id
= m_children
[i
];
3277 // Sort array keeping original positions
3278 wxQsort( temp
, child_count
, sizeof(wxGtkTreeModelChildWithPos
),
3279 &wxGtkTreeModelChildWithPosCmp
, m_internal
);
3280 // Transfer positions to new_order array and
3281 // IDs to m_children
3283 for (i
= 0; i
< child_count
; i
++)
3285 new_order
[i
] = temp
[i
].pos
;
3286 m_children
.Add( temp
[i
].id
);
3295 wxGtkTreeModelChildren temp
;
3296 WX_APPEND_ARRAY( temp
, m_children
);
3298 gs_internal
= m_internal
;
3299 m_children
.Sort( &wxGtkTreeModelChildCmp
);
3302 for (pos
= 0; pos
< child_count
; pos
++)
3304 void *id
= m_children
.Item( pos
);
3305 int old_pos
= temp
.Index( id
);
3306 new_order
[pos
] = old_pos
;
3310 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
3313 iter
.user_data
= GetItem().GetID();
3314 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
3316 gtk_tree_model_rows_reordered( gtk_tree_model
,
3317 wxGtkTreePath(m_internal
->get_path(&iter
)), &iter
, new_order
);
3319 delete [] new_order
;
3322 for (pos
= 0; pos
< node_count
; pos
++)
3324 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
3329 //-----------------------------------------------------------------------------
3330 // wxDataViewCtrlInternal
3331 //-----------------------------------------------------------------------------
3333 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
,
3334 wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
)
3337 m_wx_model
= wx_model
;
3338 m_gtk_model
= gtk_model
;
3340 m_sort_order
= GTK_SORT_ASCENDING
;
3342 m_dataview_sort_column
= NULL
;
3344 m_dragDataObject
= NULL
;
3345 m_dropDataObject
= NULL
;
3347 if (!m_wx_model
->IsVirtualListModel())
3351 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
3353 g_object_unref( m_gtk_model
);
3355 delete m_dragDataObject
;
3356 delete m_dropDataObject
;
3359 void wxDataViewCtrlInternal::InitTree()
3361 wxDataViewItem item
;
3362 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
3364 BuildBranch( m_root
);
3367 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
3369 if (node
->GetChildCount() == 0)
3371 wxDataViewItemArray children
;
3372 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
3374 for (pos
= 0; pos
< count
; pos
++)
3376 wxDataViewItem child
= children
[pos
];
3378 if (m_wx_model
->IsContainer( child
))
3379 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
3381 node
->AddLeave( child
.GetID() );
3383 // Don't send any events here
3390 bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat
&format
)
3392 wxGtkString
atom_str( gdk_atom_name( format
) );
3393 m_dragSourceTargetEntryTarget
= wxCharBuffer( atom_str
);
3395 m_dragSourceTargetEntry
.target
= m_dragSourceTargetEntryTarget
.data();
3396 m_dragSourceTargetEntry
.flags
= 0;
3397 m_dragSourceTargetEntry
.info
= static_cast<guint
>(-1);
3399 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3400 GDK_BUTTON1_MASK
, &m_dragSourceTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3405 bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat
&format
)
3407 wxGtkString
atom_str( gdk_atom_name( format
) );
3408 m_dropTargetTargetEntryTarget
= wxCharBuffer( atom_str
);
3410 m_dropTargetTargetEntry
.target
= m_dropTargetTargetEntryTarget
.data();
3411 m_dropTargetTargetEntry
.flags
= 0;
3412 m_dropTargetTargetEntry
.info
= static_cast<guint
>(-1);
3414 gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner
->GtkGetTreeView() ),
3415 &m_dropTargetTargetEntry
, 1, (GdkDragAction
) GDK_ACTION_COPY
);
3420 gboolean
wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource
*WXUNUSED(drag_source
),
3423 delete m_dragDataObject
;
3425 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3429 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3430 event
.SetEventObject( m_owner
);
3431 event
.SetItem( item
);
3432 event
.SetModel( m_wx_model
);
3433 if (!m_owner
->HandleWindowEvent( event
))
3436 if (!event
.IsAllowed())
3439 wxDataObject
*obj
= event
.GetDataObject();
3443 m_dragDataObject
= obj
;
3449 wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource
*WXUNUSED(drag_source
),
3450 GtkTreePath
*WXUNUSED(path
))
3455 gboolean
wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource
*WXUNUSED(drag_source
),
3456 GtkTreePath
*path
, GtkSelectionData
*selection_data
)
3458 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3462 if (!m_dragDataObject
->IsSupported( selection_data
->target
))
3465 size_t size
= m_dragDataObject
->GetDataSize( selection_data
->target
);
3469 void *buf
= malloc( size
);
3471 gboolean res
= FALSE
;
3472 if (m_dragDataObject
->GetDataHere( selection_data
->target
, buf
))
3476 gtk_selection_data_set( selection_data
, selection_data
->target
,
3477 8, (const guchar
*) buf
, size
);
3486 wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3488 GtkSelectionData
*selection_data
)
3490 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3494 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
3495 event
.SetEventObject( m_owner
);
3496 event
.SetItem( item
);
3497 event
.SetModel( m_wx_model
);
3498 event
.SetDataFormat( selection_data
->target
);
3499 event
.SetDataSize( selection_data
->length
);
3500 event
.SetDataBuffer( selection_data
->data
);
3501 if (!m_owner
->HandleWindowEvent( event
))
3504 if (!event
.IsAllowed())
3511 wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest
*WXUNUSED(drag_dest
),
3513 GtkSelectionData
*selection_data
)
3515 wxDataViewItem
item(GetOwner()->GTKPathToItem(path
));
3519 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
3520 event
.SetEventObject( m_owner
);
3521 event
.SetItem( item
);
3522 event
.SetModel( m_wx_model
);
3523 event
.SetDataFormat( selection_data
->target
);
3524 if (!m_owner
->HandleWindowEvent( event
))
3527 if (!event
.IsAllowed())
3533 // notifications from wxDataViewModel
3535 bool wxDataViewCtrlInternal::Cleared()
3537 GtkWidget
* tree_widget
= GetOwner()->GtkGetTreeView();
3538 gtk_tree_view_set_model( GTK_TREE_VIEW(tree_widget
), NULL
);
3539 gtk_tree_view_set_model( GTK_TREE_VIEW(tree_widget
), GTK_TREE_MODEL(m_gtk_model
) );
3550 void wxDataViewCtrlInternal::Resort()
3552 if (!m_wx_model
->IsVirtualListModel())
3556 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3558 if (!m_wx_model
->IsVirtualListModel())
3560 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3561 wxASSERT_MSG(parent_node
,
3562 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3564 if (m_wx_model
->IsContainer( item
))
3565 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
3567 parent_node
->AddLeave( item
.GetID() );
3573 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3575 if (!m_wx_model
->IsVirtualListModel())
3577 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3578 wxASSERT_MSG(parent_node
,
3579 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3581 parent_node
->DeleteChild( item
.GetID() );
3587 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
3589 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3590 event
.SetEventObject( m_owner
);
3591 event
.SetModel( m_owner
->GetModel() );
3592 event
.SetItem( item
);
3593 m_owner
->HandleWindowEvent( event
);
3598 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
3600 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
3601 event
.SetEventObject( m_owner
);
3602 event
.SetModel( m_owner
->GetModel() );
3603 event
.SetColumn( col
);
3604 event
.SetDataViewColumn( GetOwner()->GetColumn(col
) );
3605 event
.SetItem( item
);
3606 m_owner
->HandleWindowEvent( event
);
3613 GtkTreeModelFlags
wxDataViewCtrlInternal::get_flags()
3617 if ( m_wx_model
->IsListModel() )
3618 flags
|= GTK_TREE_MODEL_LIST_ONLY
;
3620 if ( !m_wx_model
->IsVirtualListModel() )
3621 flags
|= GTK_TREE_MODEL_ITERS_PERSIST
;
3623 return GtkTreeModelFlags(flags
);
3626 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
3629 if (m_wx_model
->IsVirtualListModel())
3631 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3633 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
3635 if (i
>= wx_model
->GetCount())
3638 iter
->stamp
= m_gtk_model
->stamp
;
3639 // user_data is just the index +1
3640 iter
->user_data
= (gpointer
) (i
+1);
3646 int depth
= gtk_tree_path_get_depth( path
);
3648 wxGtkTreeModelNode
*node
= m_root
;
3651 for (i
= 0; i
< depth
; i
++)
3653 BuildBranch( node
);
3655 gint pos
= gtk_tree_path_get_indices (path
)[i
];
3656 if (pos
< 0) return FALSE
;
3657 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
3659 void* id
= node
->GetChildren().Item( (size_t) pos
);
3663 iter
->stamp
= m_gtk_model
->stamp
;
3664 iter
->user_data
= id
;
3668 size_t count
= node
->GetNodes().GetCount();
3670 for (pos2
= 0; pos2
< count
; pos2
++)
3672 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
3673 if (child_node
->GetItem().GetID() == id
)
3685 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
3687 // When this is called from ItemDeleted(), the item is already
3688 // deleted in the model.
3690 GtkTreePath
*retval
= gtk_tree_path_new ();
3692 if (m_wx_model
->IsVirtualListModel())
3694 // iter is root, add nothing
3695 if (!iter
->user_data
)
3698 // user_data is just the index +1
3699 int i
= ( (wxUIntPtr
) iter
->user_data
) -1;
3700 gtk_tree_path_append_index (retval
, i
);
3704 void *id
= iter
->user_data
;
3706 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
3709 int pos
= node
->GetChildren().Index( id
);
3711 gtk_tree_path_prepend_index( retval
, pos
);
3713 id
= node
->GetItem().GetID();
3714 node
= node
->GetParent();
3721 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
3723 if (m_wx_model
->IsVirtualListModel())
3725 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3727 // user_data is just the index +1
3728 int n
= ( (wxUIntPtr
) iter
->user_data
) -1;
3732 iter
->user_data
= NULL
;
3736 if (n
>= (int) wx_model
->GetCount()-1)
3738 iter
->user_data
= NULL
;
3742 // user_data is just the index +1 (+2 because we need the next)
3743 iter
->user_data
= (gpointer
) (n
+2);
3747 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
3748 if( parent
== NULL
)
3750 iter
->user_data
= NULL
;
3754 int pos
= parent
->GetChildren().Index( iter
->user_data
);
3756 if (pos
== (int) parent
->GetChildCount()-1)
3758 iter
->user_data
= NULL
;
3762 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
3768 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
3770 if (m_wx_model
->IsVirtualListModel())
3772 // this is a list, nodes have no children
3776 iter
->stamp
= m_gtk_model
->stamp
;
3777 iter
->user_data
= (gpointer
) 1;
3785 if (m_root
->GetChildCount() == 0) return FALSE
;
3786 iter
->stamp
= m_gtk_model
->stamp
;
3787 iter
->user_data
= (gpointer
) m_root
->GetChildren().Item( 0 );
3792 wxDataViewItem item
;
3794 item
= wxDataViewItem( (void*) parent
->user_data
);
3796 if (!m_wx_model
->IsContainer( item
))
3799 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3800 wxASSERT_MSG(parent_node
,
3801 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3803 BuildBranch( parent_node
);
3805 if (parent_node
->GetChildCount() == 0)
3808 iter
->stamp
= m_gtk_model
->stamp
;
3809 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
3815 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
3817 if (m_wx_model
->IsVirtualListModel())
3819 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3822 return (wx_model
->GetCount() > 0);
3824 // this is a list, nodes have no children
3830 return (m_root
->GetChildCount() > 0);
3832 wxDataViewItem
item( (void*) iter
->user_data
);
3834 bool is_container
= m_wx_model
->IsContainer( item
);
3839 wxGtkTreeModelNode
*node
= FindNode( iter
);
3841 "Did you forget a call to ItemAdded()? The iterator is unknown to the wxGtkTreeModel");
3843 BuildBranch( node
);
3845 return (node
->GetChildCount() > 0);
3849 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
3851 if (m_wx_model
->IsVirtualListModel())
3853 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3856 return (gint
) wx_model
->GetCount();
3863 return m_root
->GetChildCount();
3865 wxDataViewItem
item( (void*) iter
->user_data
);
3867 if (!m_wx_model
->IsContainer( item
))
3870 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
3871 wxASSERT_MSG(parent_node
,
3872 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3874 BuildBranch( parent_node
);
3876 return parent_node
->GetChildCount();
3880 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
3882 if (m_wx_model
->IsVirtualListModel())
3884 wxDataViewVirtualListModel
*wx_model
= (wxDataViewVirtualListModel
*) m_wx_model
;
3892 if (n
>= (gint
) wx_model
->GetCount())
3895 iter
->stamp
= m_gtk_model
->stamp
;
3896 // user_data is just the index +1
3897 iter
->user_data
= (gpointer
) (n
+1);
3904 if (parent
) id
= (void*) parent
->user_data
;
3905 wxDataViewItem
item( id
);
3907 if (!m_wx_model
->IsContainer( item
))
3910 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3911 wxASSERT_MSG(parent_node
,
3912 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3914 BuildBranch( parent_node
);
3916 iter
->stamp
= m_gtk_model
->stamp
;
3917 iter
->user_data
= parent_node
->GetChildren().Item( n
);
3923 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
3925 if (m_wx_model
->IsVirtualListModel())
3931 wxGtkTreeModelNode
*node
= FindParentNode( child
);
3935 iter
->stamp
= m_gtk_model
->stamp
;
3936 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
3942 // item can be deleted already in the model
3943 int wxDataViewCtrlInternal::GetIndexOf( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
3945 if (m_wx_model
->IsVirtualListModel())
3947 return wxPtrToUInt(item
.GetID()) - 1;
3951 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
3952 wxGtkTreeModelChildren
&children
= parent_node
->GetChildren();
3954 for (j
= 0; j
< children
.GetCount(); j
++)
3956 if (children
[j
] == item
.GetID())
3964 static wxGtkTreeModelNode
*
3965 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3971 list
.DeleteContents( true );
3972 wxDataViewItem
it( item
);
3976 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3977 list
.Insert( pItem
);
3978 it
= model
->GetParent( it
);
3981 wxGtkTreeModelNode
* node
= treeNode
;
3982 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3984 if( node
&& node
->GetNodes().GetCount() != 0 )
3986 int len
= node
->GetNodes().GetCount();
3987 wxGtkTreeModelNodes
&nodes
= node
->GetNodes();
3989 for( ; j
< len
; j
++)
3991 if( nodes
[j
]->GetItem() == *(n
->GetData()))
4010 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
4015 wxDataViewItem
item( (void*) iter
->user_data
);
4019 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
4024 wxLogDebug( "Not found %p", iter->user_data );
4028 // TODO: remove this code
4034 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
4039 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
4044 wxLogDebug( "Not found %p", item.GetID() );
4048 // TODO: remove this code
4054 static wxGtkTreeModelNode
*
4055 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
4061 list
.DeleteContents( true );
4065 wxDataViewItem
it( model
->GetParent( item
) );
4068 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
4069 list
.Insert( pItem
);
4070 it
= model
->GetParent( it
);
4073 wxGtkTreeModelNode
* node
= treeNode
;
4074 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
4076 if( node
&& node
->GetNodes().GetCount() != 0 )
4078 int len
= node
->GetNodes().GetCount();
4079 wxGtkTreeModelNodes nodes
= node
->GetNodes();
4081 for( ; j
< len
; j
++)
4083 if( nodes
[j
]->GetItem() == *(n
->GetData()))
4098 //Examine whether the node is item's parent node
4099 int len
= node
->GetChildCount();
4100 for( int i
= 0; i
< len
; i
++ )
4102 if( node
->GetChildren().Item( i
) == item
.GetID() )
4108 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
4113 wxDataViewItem
item( (void*) iter
->user_data
);
4117 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
4120 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
4125 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
4128 //-----------------------------------------------------------------------------
4129 // wxDataViewCtrl signal callbacks
4130 //-----------------------------------------------------------------------------
4133 wxdataview_selection_changed_callback( GtkTreeSelection
* WXUNUSED(selection
), wxDataViewCtrl
*dv
)
4135 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
4138 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
4139 event
.SetItem( dv
->GetSelection() );
4140 event
.SetModel( dv
->GetModel() );
4141 dv
->HandleWindowEvent( event
);
4145 wxdataview_row_activated_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreePath
*path
,
4146 GtkTreeViewColumn
*WXUNUSED(column
), wxDataViewCtrl
*dv
)
4148 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
4150 wxDataViewItem
item(dv
->GTKPathToItem(path
));
4151 event
.SetItem( item
);
4152 event
.SetModel( dv
->GetModel() );
4153 dv
->HandleWindowEvent( event
);
4157 wxdataview_test_expand_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4158 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4160 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
4162 wxDataViewItem
item( (void*) iter
->user_data
);;
4163 event
.SetItem( item
);
4164 event
.SetModel( dv
->GetModel() );
4165 dv
->HandleWindowEvent( event
);
4167 return !event
.IsAllowed();
4171 wxdataview_row_expanded_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4172 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4174 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
4176 wxDataViewItem
item( (void*) iter
->user_data
);;
4177 event
.SetItem( item
);
4178 event
.SetModel( dv
->GetModel() );
4179 dv
->HandleWindowEvent( event
);
4183 wxdataview_test_collapse_row_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4184 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4186 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
4188 wxDataViewItem
item( (void*) iter
->user_data
);;
4189 event
.SetItem( item
);
4190 event
.SetModel( dv
->GetModel() );
4191 dv
->HandleWindowEvent( event
);
4193 return !event
.IsAllowed();
4197 wxdataview_row_collapsed_callback( GtkTreeView
* WXUNUSED(treeview
), GtkTreeIter
* iter
,
4198 GtkTreePath
*WXUNUSED(path
), wxDataViewCtrl
*dv
)
4200 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
4202 wxDataViewItem
item( (void*) iter
->user_data
);;
4203 event
.SetItem( item
);
4204 event
.SetModel( dv
->GetModel() );
4205 dv
->HandleWindowEvent( event
);
4208 //-----------------------------------------------------------------------------
4210 //-----------------------------------------------------------------------------
4212 void wxDataViewCtrl::AddChildGTK(wxWindowGTK
* child
)
4214 GtkWidget
* treeview
= GtkGetTreeView();
4216 // Insert widget in GtkTreeView
4217 if (GTK_WIDGET_REALIZED(treeview
))
4218 gtk_widget_set_parent_window( child
->m_widget
,
4219 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
4220 gtk_widget_set_parent( child
->m_widget
, treeview
);
4224 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
4225 GtkAllocation
*WXUNUSED(gtk_alloc
),
4226 wxDataViewCtrl
*win
)
4228 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
4231 wxWindow
*child
= node
->GetData();
4234 gtk_widget_size_request( child
->m_widget
, &req
);
4236 GtkAllocation alloc
;
4237 alloc
.x
= child
->m_x
;
4238 alloc
.y
= child
->m_y
;
4239 alloc
.width
= child
->m_width
;
4240 alloc
.height
= child
->m_height
;
4241 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
4243 node
= node
->GetNext();
4248 //-----------------------------------------------------------------------------
4249 // "motion_notify_event"
4250 //-----------------------------------------------------------------------------
4253 gtk_dataview_motion_notify_callback( GtkWidget
*WXUNUSED(widget
),
4254 GdkEventMotion
*gdk_event
,
4255 wxDataViewCtrl
*dv
)
4257 if (gdk_event
->is_hint
)
4261 GdkModifierType state
;
4262 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
4268 GtkTreeViewColumn
*column
= NULL
;
4271 if (gtk_tree_view_get_path_at_pos(
4272 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4273 (int) gdk_event
->x
, (int) gdk_event
->y
,
4282 dv
->GtkGetInternal()->get_iter( &iter
, path
);
4290 //-----------------------------------------------------------------------------
4291 // "button_press_event"
4292 //-----------------------------------------------------------------------------
4295 gtk_dataview_button_press_callback( GtkWidget
*WXUNUSED(widget
),
4296 GdkEventButton
*gdk_event
,
4297 wxDataViewCtrl
*dv
)
4299 if ((gdk_event
->button
== 3) && (gdk_event
->type
== GDK_BUTTON_PRESS
))
4302 GtkTreeViewColumn
*column
= NULL
;
4305 if (gtk_tree_view_get_path_at_pos(
4306 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
4307 (int) gdk_event
->x
, (int) gdk_event
->y
,
4315 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, dv
->GetId() );
4316 event
.SetItem(dv
->GTKPathToItem(path
));
4317 event
.SetModel( dv
->GetModel() );
4318 return dv
->HandleWindowEvent( event
);
4326 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
4328 wxDataViewCtrl::~wxDataViewCtrl()
4331 GetModel()->RemoveNotifier( m_notifier
);
4335 // remove the model from the GtkTreeView before it gets destroyed by the
4336 // wxDataViewCtrlBase's dtor
4337 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), NULL
);
4342 void wxDataViewCtrl::Init()
4347 m_cols
.DeleteContents( true );
4350 bool wxDataViewCtrl::Create(wxWindow
*parent
,
4355 const wxValidator
& validator
,
4356 const wxString
& name
)
4358 if (!PreCreation( parent
, pos
, size
) ||
4359 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
4361 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
4365 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
4366 g_object_ref(m_widget
);
4368 GTKScrolledWindowSetBorder(m_widget
, style
);
4370 m_treeview
= gtk_tree_view_new();
4371 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
4373 g_signal_connect (m_treeview
, "size_allocate",
4374 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
4377 if (!gtk_check_version(2,6,0))
4379 bool fixed
= (style
& wxDV_VARIABLE_LINE_HEIGHT
) == 0;
4380 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4384 if (style
& wxDV_MULTIPLE
)
4386 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4387 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
4390 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
4393 if (!gtk_check_version(2,10,0))
4395 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
4397 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
4398 (style
& wxDV_VERT_RULES
) != 0)
4399 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
4400 else if (style
& wxDV_VERT_RULES
)
4401 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
4402 else if (style
& wxDV_HORIZ_RULES
)
4403 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
4405 if (grid
!= GTK_TREE_VIEW_GRID_LINES_NONE
)
4406 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
4410 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_ROW_LINES
) != 0 );
4412 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
4413 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
4414 gtk_widget_show (m_treeview
);
4416 m_parent
->DoAddChild( this );
4420 GtkEnableSelectionEvents();
4422 g_signal_connect_after (m_treeview
, "row-activated",
4423 G_CALLBACK (wxdataview_row_activated_callback
), this);
4425 g_signal_connect (m_treeview
, "test-collapse-row",
4426 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
4428 g_signal_connect_after (m_treeview
, "row-collapsed",
4429 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
4431 g_signal_connect (m_treeview
, "test-expand-row",
4432 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
4434 g_signal_connect_after (m_treeview
, "row-expanded",
4435 G_CALLBACK (wxdataview_row_expanded_callback
), this);
4437 g_signal_connect (m_treeview
, "motion_notify_event",
4438 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
4440 g_signal_connect (m_treeview
, "button_press_event",
4441 G_CALLBACK (gtk_dataview_button_press_callback
), this);
4446 wxDataViewItem
wxDataViewCtrl::GTKPathToItem(GtkTreePath
*path
) const
4449 return wxDataViewItem(path
&& m_internal
->get_iter(&iter
, path
)
4454 void wxDataViewCtrl::OnInternalIdle()
4456 wxWindow::OnInternalIdle();
4458 unsigned int cols
= GetColumnCount();
4460 for (i
= 0; i
< cols
; i
++)
4462 wxDataViewColumn
*col
= GetColumn( i
);
4463 col
->OnInternalIdle();
4467 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4469 wxDELETE(m_internal
);
4471 if (!wxDataViewCtrlBase::AssociateModel( model
))
4475 if (!gtk_check_version(2,6,0))
4477 bool fixed
= (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
) == 0) || (model
->IsVirtualListModel()));
4478 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), fixed
);
4482 GtkWxTreeModel
*gtk_model
= wxgtk_tree_model_new();
4483 m_internal
= new wxDataViewCtrlInternal( this, model
, gtk_model
);
4484 gtk_model
->internal
= m_internal
;
4486 m_notifier
= new wxGtkDataViewModelNotifier( gtk_model
, model
, this );
4488 model
->AddNotifier( m_notifier
);
4490 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_model
) );
4492 // unref in wxDataViewCtrlInternal
4493 // g_object_unref( gtk_model );
4498 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4500 return m_internal
->EnableDragSource( format
);
4503 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4505 return m_internal
->EnableDropTarget( format
);
4508 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4510 if (!wxDataViewCtrlBase::AppendColumn(col
))
4513 m_cols
.Append( col
);
4516 if (!gtk_check_version(2,6,0))
4518 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4519 GTK_TREE_VIEW_COLUMN_FIXED
)
4520 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4524 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
4525 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4530 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4532 if (!wxDataViewCtrlBase::PrependColumn(col
))
4535 m_cols
.Insert( col
);
4538 if (!gtk_check_version(2,6,0))
4540 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4541 GTK_TREE_VIEW_COLUMN_FIXED
)
4542 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4546 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4547 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
4552 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4554 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4557 m_cols
.Insert( pos
, col
);
4560 if (!gtk_check_version(2,6,0))
4562 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) ) !=
4563 GTK_TREE_VIEW_COLUMN_FIXED
)
4564 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), FALSE
);
4568 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
4569 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), pos
);
4574 unsigned int wxDataViewCtrl::GetColumnCount() const
4576 return m_cols
.GetCount();
4579 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
4581 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
4585 wxDataViewColumnList::const_iterator iter
;
4586 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4588 wxDataViewColumn
*col
= *iter
;
4589 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
4598 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4600 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4601 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
4603 m_cols
.DeleteObject( column
);
4608 bool wxDataViewCtrl::ClearColumns()
4610 wxDataViewColumnList::iterator iter
;
4611 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); ++iter
)
4613 wxDataViewColumn
*col
= *iter
;
4614 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
4615 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
4623 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4625 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetConstGtkHandle());
4627 GList
*list
= gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview
) );
4629 gint pos
= g_list_index( list
, (gconstpointer
) gtk_column
);
4631 g_list_free( list
);
4636 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4638 return m_internal
->GetDataViewSortColumn();
4641 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4644 iter
.user_data
= item
.GetID();
4645 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4646 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
4649 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4652 iter
.user_data
= item
.GetID();
4653 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4654 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
4657 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4660 iter
.user_data
= item
.GetID();
4661 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4662 return gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview
), path
);
4665 wxDataViewItem
wxDataViewCtrl::DoGetCurrentItem() const
4667 // The tree doesn't have any current item if it hadn't been created yet but
4668 // it's arguably not an error to call this function in this case so just
4669 // return an invalid item without asserting.
4671 return wxDataViewItem();
4674 gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview
), path
.ByRef(), NULL
);
4676 return GTKPathToItem(path
);
4679 void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem
& item
)
4681 wxCHECK_RET( m_treeview
,
4682 "Current item can't be set before creating the control." );
4684 // We need to make sure the model knows about this item or the path would
4685 // be invalid and gtk_tree_view_set_cursor() would silently do nothing.
4686 ExpandAncestors(item
);
4688 // We also need to preserve the existing selection from changing.
4689 // Unfortunately the only way to do it seems to use our own selection
4690 // function and forbid any selection changes during set cursor call.
4691 wxGtkTreeSelectionLock
4692 lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview
)));
4694 // Do move the cursor now.
4696 iter
.user_data
= item
.GetID();
4697 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4699 gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview
), path
, NULL
, FALSE
);
4702 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4704 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4706 if (m_windowStyle
& wxDV_MULTIPLE
)
4708 // Report the first one
4709 GtkTreeModel
*model
;
4710 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4714 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4715 wxDataViewItem
item(GTKPathToItem(path
));
4718 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4719 g_list_free( list
);
4727 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
4729 wxDataViewItem
item( iter
.user_data
);
4734 return wxDataViewItem(0);
4737 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4741 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4742 if (HasFlag(wxDV_MULTIPLE
))
4744 GtkTreeModel
*model
;
4745 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
4750 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
4752 sel
.Add(GTKPathToItem(path
));
4754 list
= g_list_next( list
);
4759 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
4760 g_list_free( list
);
4766 GtkTreeModel
*model
;
4768 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
4771 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
4779 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4781 GtkDisableSelectionEvents();
4783 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4785 gtk_tree_selection_unselect_all( selection
);
4787 wxDataViewItem last_parent
;
4790 for (i
= 0; i
< sel
.GetCount(); i
++)
4792 wxDataViewItem item
= sel
[i
];
4793 wxDataViewItem parent
= GetModel()->GetParent( item
);
4796 if (parent
!= last_parent
)
4797 ExpandAncestors(item
);
4799 last_parent
= parent
;
4802 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4803 iter
.user_data
= (gpointer
) item
.GetID();
4804 gtk_tree_selection_select_iter( selection
, &iter
);
4807 GtkEnableSelectionEvents();
4810 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4812 ExpandAncestors(item
);
4814 GtkDisableSelectionEvents();
4816 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4819 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4820 iter
.user_data
= (gpointer
) item
.GetID();
4821 gtk_tree_selection_select_iter( selection
, &iter
);
4823 GtkEnableSelectionEvents();
4826 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4828 GtkDisableSelectionEvents();
4830 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4833 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4834 iter
.user_data
= (gpointer
) item
.GetID();
4835 gtk_tree_selection_unselect_iter( selection
, &iter
);
4837 GtkEnableSelectionEvents();
4840 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4842 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4845 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
4846 iter
.user_data
= (gpointer
) item
.GetID();
4848 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
4851 void wxDataViewCtrl::SelectAll()
4853 GtkDisableSelectionEvents();
4855 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4857 gtk_tree_selection_select_all( selection
);
4859 GtkEnableSelectionEvents();
4862 void wxDataViewCtrl::UnselectAll()
4864 GtkDisableSelectionEvents();
4866 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4868 gtk_tree_selection_unselect_all( selection
);
4870 GtkEnableSelectionEvents();
4873 void wxDataViewCtrl::EnsureVisible(const wxDataViewItem
& item
,
4874 const wxDataViewColumn
*WXUNUSED(column
))
4876 ExpandAncestors(item
);
4879 iter
.user_data
= (gpointer
) item
.GetID();
4880 wxGtkTreePath
path(m_internal
->get_path( &iter
));
4881 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
4884 void wxDataViewCtrl::HitTest(const wxPoint
& WXUNUSED(point
),
4885 wxDataViewItem
& item
,
4886 wxDataViewColumn
*& column
) const
4888 item
= wxDataViewItem(0);
4893 wxDataViewCtrl::GetItemRect(const wxDataViewItem
& WXUNUSED(item
),
4894 const wxDataViewColumn
*WXUNUSED(column
)) const
4899 void wxDataViewCtrl::DoSetExpanderColumn()
4901 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
4902 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
4905 void wxDataViewCtrl::DoSetIndent()
4909 void wxDataViewCtrl::GtkDisableSelectionEvents()
4911 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4912 g_signal_handlers_disconnect_by_func( selection
,
4913 (gpointer
) (wxdataview_selection_changed_callback
), this);
4916 void wxDataViewCtrl::GtkEnableSelectionEvents()
4918 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
4919 g_signal_connect_after (selection
, "changed",
4920 G_CALLBACK (wxdataview_selection_changed_callback
), this);
4923 // ----------------------------------------------------------------------------
4924 // visual attributes stuff
4925 // ----------------------------------------------------------------------------
4929 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
4931 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
4934 void wxDataViewCtrl::DoApplyWidgetStyle(GtkRcStyle
*style
)
4936 wxDataViewCtrlBase::DoApplyWidgetStyle(style
);
4937 gtk_widget_modify_style(m_treeview
, style
);
4940 #endif // !wxUSE_GENERICDATAVIEWCTRL
4942 #endif // wxUSE_DATAVIEWCTRL