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"
25 #include "wx/settings.h"
29 #include "wx/stockitem.h"
30 #include "wx/calctrl.h"
31 #include "wx/popupwin.h"
32 #include "wx/listimpl.cpp"
34 #include "wx/gtk/private.h"
35 #include "wx/gtk/dc.h"
36 #include "wx/gtk/dcclient.h"
38 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
41 class wxDataViewCtrlInternal
;
43 wxDataViewCtrlInternal
*g_internal
= NULL
;
45 class wxGtkTreeModelNode
;
48 typedef struct _GtkWxTreeModel GtkWxTreeModel
;
51 //-----------------------------------------------------------------------------
52 // wxDataViewCtrlInternal
53 //-----------------------------------------------------------------------------
55 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
56 WX_DEFINE_LIST(ItemList
)
58 class wxDataViewCtrlInternal
61 wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
, GtkWxTreeModel
*owner
);
62 ~wxDataViewCtrlInternal();
64 GtkTreeModelFlags
get_flags();
65 gboolean
get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
);
66 GtkTreePath
*get_path( GtkTreeIter
*iter
);
67 gboolean
iter_next( GtkTreeIter
*iter
);
68 gboolean
iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
);
69 gboolean
iter_has_child( GtkTreeIter
*iter
);
70 gint
iter_n_children( GtkTreeIter
*iter
);
71 gboolean
iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
);
72 gboolean
iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
);
74 wxDataViewModel
* GetDataViewModel() { return m_wx_model
; }
75 wxDataViewCtrl
* GetOwner() { return m_owner
; }
76 GtkWxTreeModel
* GetGtkModel() { return m_gtk_model
; }
78 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
79 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
80 bool ItemChanged( const wxDataViewItem
&item
);
81 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
85 void SetSortOrder( GtkSortType sort_order
) { m_sort_order
= sort_order
; }
86 GtkSortType
GetSortOrder() { return m_sort_order
; }
88 void SetSortColumn( int column
) { m_sort_column
= column
; }
89 int GetSortColumn() { return m_sort_column
; }
91 void SetDataViewSortColumn( wxDataViewColumn
*column
) { m_dataview_sort_column
= column
; }
92 wxDataViewColumn
*GetDataViewSortColumn() { return m_dataview_sort_column
; }
94 bool IsSorted() { return (m_sort_column
>= 0); }
99 wxGtkTreeModelNode
*FindNode( const wxDataViewItem
&item
);
100 wxGtkTreeModelNode
*FindNode( GtkTreeIter
*iter
);
101 wxGtkTreeModelNode
*FindParentNode( const wxDataViewItem
&item
);
102 wxGtkTreeModelNode
*FindParentNode( GtkTreeIter
*iter
);
103 void BuildBranch( wxGtkTreeModelNode
*branch
);
106 wxGtkTreeModelNode
*m_root
;
107 wxDataViewModel
*m_wx_model
;
108 GtkWxTreeModel
*m_gtk_model
;
109 wxDataViewCtrl
*m_owner
;
110 GtkSortType m_sort_order
;
111 wxDataViewColumn
*m_dataview_sort_column
;
116 //-----------------------------------------------------------------------------
117 // wxGtkTreeModelNode
118 //-----------------------------------------------------------------------------
120 int LINKAGEMODE
wxGtkTreeModelChildCmp( void** id1
, void** id2
)
122 int ret
= g_internal
->GetDataViewModel()->Compare( *id1
, *id2
,
123 g_internal
->GetSortColumn(), (g_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
128 WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode
*, wxGtkTreeModelNodes
);
129 WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren
);
131 class wxGtkTreeModelNode
134 wxGtkTreeModelNode( wxGtkTreeModelNode
* parent
, const wxDataViewItem
&item
,
135 wxDataViewCtrlInternal
*internal
)
139 m_internal
= internal
;
142 ~wxGtkTreeModelNode()
144 size_t count
= m_children
.GetCount();
146 for (i
= 0; i
< count
; i
++)
148 wxGtkTreeModelNode
*child
= m_nodes
.Item( i
);
153 unsigned int AddNode( wxGtkTreeModelNode
* child
)
155 m_nodes
.Add( child
);
157 void *id
= child
->GetItem().GetID();
159 m_children
.Add( id
);
161 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
163 g_internal
= m_internal
;
164 m_children
.Sort( &wxGtkTreeModelChildCmp
);
165 return m_children
.Index( id
);
168 return m_children
.GetCount()-1;
171 unsigned int AddLeave( void* id
)
173 m_children
.Add( id
);
175 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
177 g_internal
= m_internal
;
178 m_children
.Sort( &wxGtkTreeModelChildCmp
);
179 return m_children
.Index( id
);
182 return m_children
.GetCount()-1;
185 void DeleteChild( void* id
)
187 m_children
.Remove( id
);
189 unsigned int count
= m_nodes
.GetCount();
191 for (pos
= 0; pos
< count
; pos
++)
193 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
194 if (node
->GetItem().GetID() == id
)
196 m_nodes
.RemoveAt( pos
);
204 wxGtkTreeModelNode
* GetParent()
206 wxGtkTreeModelNodes
&GetNodes()
208 wxGtkTreeModelChildren
&GetChildren()
209 { return m_children
; }
211 unsigned int GetChildCount() { return m_children
.GetCount(); }
212 unsigned int GetNodesCount() { return m_nodes
.GetCount(); }
214 wxDataViewItem
&GetItem() { return m_item
; }
215 wxDataViewCtrlInternal
*GetInternal() { return m_internal
; }
220 wxGtkTreeModelNode
*m_parent
;
221 wxGtkTreeModelNodes m_nodes
;
222 wxGtkTreeModelChildren m_children
;
223 wxDataViewItem m_item
;
224 wxDataViewCtrlInternal
*m_internal
;
228 //-----------------------------------------------------------------------------
230 //-----------------------------------------------------------------------------
232 extern bool g_blockEventsOnDrag
;
234 //-----------------------------------------------------------------------------
235 // define new GTK+ class wxGtkTreeModel
236 //-----------------------------------------------------------------------------
240 #define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ())
241 #define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel))
242 #define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
243 #define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL))
244 #define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL))
245 #define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
247 GType
gtk_wx_tree_model_get_type (void);
249 typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass
;
251 struct _GtkWxTreeModel
257 wxDataViewCtrlInternal
*internal
;
260 struct _GtkWxTreeModelClass
262 GObjectClass list_parent_class
;
265 static GtkWxTreeModel
*wxgtk_tree_model_new (void);
266 static void wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
);
267 static void wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
);
268 static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
);
269 static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
);
270 static void wxgtk_tree_model_finalize (GObject
*object
);
271 static GtkTreeModelFlags
wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
);
272 static gint
wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
);
273 static GType
wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
275 static gboolean
wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
278 static GtkTreePath
*wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
280 static void wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
284 static gboolean
wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
286 static gboolean
wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
288 GtkTreeIter
*parent
);
289 static gboolean
wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
291 static gint
wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
293 static gboolean
wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
297 static gboolean
wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
302 static gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
303 gint
*sort_column_id
,
305 static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
308 static void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
310 GtkTreeIterCompareFunc func
,
312 GtkDestroyNotify destroy
);
313 static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
314 GtkTreeIterCompareFunc func
,
316 GtkDestroyNotify destroy
);
317 static gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
);
321 static GObjectClass
*list_parent_class
= NULL
;
324 gtk_wx_tree_model_get_type (void)
326 static GType tree_model_type
= 0;
328 if (!tree_model_type
)
330 const GTypeInfo tree_model_info
=
332 sizeof (GtkWxTreeModelClass
),
333 NULL
, /* base_init */
334 NULL
, /* base_finalize */
335 (GClassInitFunc
) wxgtk_tree_model_class_init
,
336 NULL
, /* class_finalize */
337 NULL
, /* class_data */
338 sizeof (GtkWxTreeModel
),
340 (GInstanceInitFunc
) wxgtk_tree_model_init
,
343 static const GInterfaceInfo tree_model_iface_info
=
345 (GInterfaceInitFunc
) wxgtk_tree_model_tree_model_init
,
350 static const GInterfaceInfo sortable_iface_info
=
352 (GInterfaceInitFunc
) wxgtk_tree_model_sortable_init
,
357 tree_model_type
= g_type_register_static (G_TYPE_OBJECT
, "GtkWxTreeModel",
358 &tree_model_info
, (GTypeFlags
)0 );
360 g_type_add_interface_static (tree_model_type
,
362 &tree_model_iface_info
);
363 g_type_add_interface_static (tree_model_type
,
364 GTK_TYPE_TREE_SORTABLE
,
365 &sortable_iface_info
);
368 return tree_model_type
;
371 static GtkWxTreeModel
*
372 wxgtk_tree_model_new(void)
374 GtkWxTreeModel
*retval
= (GtkWxTreeModel
*) g_object_new (GTK_TYPE_WX_TREE_MODEL
, NULL
);
379 wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
)
381 list_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
382 GObjectClass
*object_class
= (GObjectClass
*) klass
;
383 object_class
->finalize
= wxgtk_tree_model_finalize
;
387 wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
)
389 iface
->get_flags
= wxgtk_tree_model_get_flags
;
390 iface
->get_n_columns
= wxgtk_tree_model_get_n_columns
;
391 iface
->get_column_type
= wxgtk_tree_model_get_column_type
;
392 iface
->get_iter
= wxgtk_tree_model_get_iter
;
393 iface
->get_path
= wxgtk_tree_model_get_path
;
394 iface
->get_value
= wxgtk_tree_model_get_value
;
395 iface
->iter_next
= wxgtk_tree_model_iter_next
;
396 iface
->iter_children
= wxgtk_tree_model_iter_children
;
397 iface
->iter_has_child
= wxgtk_tree_model_iter_has_child
;
398 iface
->iter_n_children
= wxgtk_tree_model_iter_n_children
;
399 iface
->iter_nth_child
= wxgtk_tree_model_iter_nth_child
;
400 iface
->iter_parent
= wxgtk_tree_model_iter_parent
;
404 wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
)
406 iface
->get_sort_column_id
= wxgtk_tree_model_get_sort_column_id
;
407 iface
->set_sort_column_id
= wxgtk_tree_model_set_sort_column_id
;
408 iface
->set_sort_func
= wxgtk_tree_model_set_sort_func
;
409 iface
->set_default_sort_func
= wxgtk_tree_model_set_default_sort_func
;
410 iface
->has_default_sort_func
= wxgtk_tree_model_has_default_sort_func
;
414 wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
)
416 tree_model
->internal
= NULL
;
417 tree_model
->stamp
= g_random_int();
421 wxgtk_tree_model_finalize (GObject
*object
)
424 (* list_parent_class
->finalize
) (object
);
429 //-----------------------------------------------------------------------------
430 // implement callbacks from wxGtkTreeModel class by letting
431 // them call the methods of wxWidgets' wxDataViewModel
432 //-----------------------------------------------------------------------------
434 static GtkTreeModelFlags
435 wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
)
437 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
438 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), (GtkTreeModelFlags
)0 );
440 return wxtree_model
->internal
->get_flags();
444 wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
)
446 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
447 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
449 return wxtree_model
->internal
->GetDataViewModel()->GetColumnCount();
453 wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
456 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
457 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), G_TYPE_INVALID
);
459 GType gtype
= G_TYPE_INVALID
;
461 wxString wxtype
= wxtree_model
->internal
->GetDataViewModel()->GetColumnType( (unsigned int) index
);
463 if (wxtype
== wxT("string"))
464 gtype
= G_TYPE_STRING
;
467 gtype
= G_TYPE_STRING
;
468 // wxFAIL_MSG( _T("non-string columns not supported yet") );
475 wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
479 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
480 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
481 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
483 return wxtree_model
->internal
->get_iter( iter
, path
);
487 wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
490 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
491 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), NULL
);
492 g_return_val_if_fail (iter
->stamp
== GTK_WX_TREE_MODEL (wxtree_model
)->stamp
, NULL
);
494 return wxtree_model
->internal
->get_path( iter
);
498 wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
503 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
504 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
) );
506 wxDataViewModel
*model
= wxtree_model
->internal
->GetDataViewModel();
507 wxString mtype
= model
->GetColumnType( (unsigned int) column
);
508 if (mtype
== wxT("string"))
511 g_value_init( value
, G_TYPE_STRING
);
512 wxDataViewItem
item( (void*) iter
->user_data
);
513 model
->GetValue( variant
, item
, (unsigned int) column
);
515 g_value_set_string( value
, variant
.GetString().utf8_str() );
519 wxFAIL_MSG( _T("non-string columns not supported yet") );
524 wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
527 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
529 if (wxtree_model
->stamp
!= iter
->stamp
)
530 wxPrintf( "crash\n" );
532 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
533 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
535 return wxtree_model
->internal
->iter_next( iter
);
539 wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
543 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
544 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
545 g_return_val_if_fail (wxtree_model
->stamp
== parent
->stamp
, FALSE
);
547 return wxtree_model
->internal
->iter_children( iter
, parent
);
551 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
554 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
555 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
556 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
558 return wxtree_model
->internal
->iter_has_child( iter
);
562 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
565 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
566 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
567 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, 0);
569 return wxtree_model
->internal
->iter_n_children( iter
);
573 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
578 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
579 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
581 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
585 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
589 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
590 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
591 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
593 return wxtree_model
->internal
->iter_parent( iter
, child
);
597 gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
598 gint
*sort_column_id
,
601 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
603 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
605 if (!tree_model
->internal
->IsSorted())
608 *sort_column_id
= -1;
615 *sort_column_id
= tree_model
->internal
->GetSortColumn();
618 *order
= tree_model
->internal
->GetSortOrder();
623 wxDataViewColumn
*gs_lastLeftClickHeader
= NULL
;
625 void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
629 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
630 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
632 tree_model
->internal
->SetDataViewSortColumn( gs_lastLeftClickHeader
);
634 if ((sort_column_id
!= (gint
) tree_model
->internal
->GetSortColumn()) ||
635 (order
!= tree_model
->internal
->GetSortOrder()))
637 tree_model
->internal
->SetSortColumn( sort_column_id
);
638 tree_model
->internal
->SetSortOrder( order
);
640 gtk_tree_sortable_sort_column_changed (sortable
);
642 tree_model
->internal
->GetDataViewModel()->Resort();
645 if (gs_lastLeftClickHeader
)
647 wxDataViewCtrl
*dv
= tree_model
->internal
->GetOwner();
648 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, dv
->GetId() );
649 event
.SetDataViewColumn( gs_lastLeftClickHeader
);
650 event
.SetModel( dv
->GetModel() );
651 dv
->HandleWindowEvent( event
);
654 gs_lastLeftClickHeader
= NULL
;
657 void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
658 gint
WXUNUSED(sort_column_id
),
659 GtkTreeIterCompareFunc func
,
660 gpointer
WXUNUSED(data
),
661 GtkDestroyNotify
WXUNUSED(destroy
) )
663 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
664 g_return_if_fail (func
!= NULL
);
667 void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
668 GtkTreeIterCompareFunc func
,
669 gpointer
WXUNUSED(data
),
670 GtkDestroyNotify
WXUNUSED(destroy
) )
672 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
673 g_return_if_fail (func
!= NULL
);
675 wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
678 gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
)
680 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
685 //-----------------------------------------------------------------------------
686 // define new GTK+ class wxGtkRendererRenderer
687 //-----------------------------------------------------------------------------
691 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
692 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
693 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
694 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
695 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
696 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
698 GType
gtk_wx_cell_renderer_get_type (void);
700 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
701 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
703 struct _GtkWxCellRenderer
705 GtkCellRenderer parent
;
708 wxDataViewCustomRenderer
*cell
;
712 struct _GtkWxCellRendererClass
714 GtkCellRendererClass cell_parent_class
;
718 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
719 static void gtk_wx_cell_renderer_init (
720 GtkWxCellRenderer
*cell
);
721 static void gtk_wx_cell_renderer_class_init(
722 GtkWxCellRendererClass
*klass
);
723 static void gtk_wx_cell_renderer_finalize (
725 static void gtk_wx_cell_renderer_get_size (
726 GtkCellRenderer
*cell
,
728 GdkRectangle
*rectangle
,
733 static void gtk_wx_cell_renderer_render (
734 GtkCellRenderer
*cell
,
737 GdkRectangle
*background_area
,
738 GdkRectangle
*cell_area
,
739 GdkRectangle
*expose_area
,
740 GtkCellRendererState flags
);
741 static gboolean
gtk_wx_cell_renderer_activate(
742 GtkCellRenderer
*cell
,
746 GdkRectangle
*background_area
,
747 GdkRectangle
*cell_area
,
748 GtkCellRendererState flags
);
749 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
750 GtkCellRenderer
*cell
,
754 GdkRectangle
*background_area
,
755 GdkRectangle
*cell_area
,
756 GtkCellRendererState flags
);
759 static GObjectClass
*cell_parent_class
= NULL
;
764 gtk_wx_cell_renderer_get_type (void)
766 static GType cell_wx_type
= 0;
770 const GTypeInfo cell_wx_info
=
772 sizeof (GtkWxCellRendererClass
),
773 NULL
, /* base_init */
774 NULL
, /* base_finalize */
775 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
776 NULL
, /* class_finalize */
777 NULL
, /* class_data */
778 sizeof (GtkWxCellRenderer
),
780 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
783 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
784 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
791 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
794 cell
->last_click
= 0;
798 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
800 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
801 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
803 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
805 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
807 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
808 cell_class
->render
= gtk_wx_cell_renderer_render
;
809 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
810 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
814 gtk_wx_cell_renderer_finalize (GObject
*object
)
817 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
821 gtk_wx_cell_renderer_new (void)
823 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
828 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
829 GtkCellRenderer
*renderer
,
830 GdkEvent
*WXUNUSED(event
),
833 GdkRectangle
*WXUNUSED(background_area
),
834 GdkRectangle
*cell_area
,
835 GtkCellRendererState
WXUNUSED(flags
) )
837 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
838 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
839 if (!cell
->HasEditorCtrl())
843 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
849 rect
.x
+= cell_area
->x
;
850 rect
.y
+= cell_area
->y
;
851 // rect.width -= renderer->xpad * 2;
852 // rect.height -= renderer->ypad * 2;
854 // wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
855 wxRect
renderrect( cell_area
->x
, cell_area
->y
, cell_area
->width
, cell_area
->height
);
857 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
859 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
860 wxDataViewItem
item( (void*) iter
.user_data
);
861 gtk_tree_path_free( treepath
);
863 cell
->StartEditing( item
, renderrect
);
869 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
870 GtkWidget
*WXUNUSED(widget
),
871 GdkRectangle
*cell_area
,
877 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
878 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
880 wxSize size
= cell
->GetSize();
882 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
883 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
890 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
894 *x_offset
= (gint
)((renderer
->xalign
*
895 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
896 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
900 *y_offset
= (gint
)((renderer
->yalign
*
901 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
902 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
910 *height
= calc_height
;
914 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
917 GdkRectangle
*background_area
,
918 GdkRectangle
*cell_area
,
919 GdkRectangle
*expose_area
,
920 GtkCellRendererState flags
)
923 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
924 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
926 cell
->window
= window
;
927 cell
->widget
= widget
;
928 cell
->background_area
= (void*) background_area
;
929 cell
->cell_area
= (void*) cell_area
;
930 cell
->expose_area
= (void*) expose_area
;
931 cell
->flags
= (int) flags
;
934 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
940 rect
.x
+= cell_area
->x
;
941 rect
.y
+= cell_area
->y
;
942 rect
.width
-= renderer
->xpad
* 2;
943 rect
.height
-= renderer
->ypad
* 2;
946 if (gdk_rectangle_intersect (expose_area
, &rect
, &dummy
))
948 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
949 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
950 wxWindowDCImpl
*impl
= (wxWindowDCImpl
*) dc
->GetImpl();
951 if (impl
->m_gdkwindow
== NULL
)
953 impl
->m_gdkwindow
= window
;
958 if (flags
& GTK_CELL_RENDERER_SELECTED
)
959 state
|= wxDATAVIEW_CELL_SELECTED
;
960 if (flags
& GTK_CELL_RENDERER_PRELIT
)
961 state
|= wxDATAVIEW_CELL_PRELIT
;
962 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
963 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
964 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
965 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
966 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
967 state
|= wxDATAVIEW_CELL_FOCUSED
;
968 cell
->Render( renderrect
, dc
, state
);
973 gtk_wx_cell_renderer_activate(
974 GtkCellRenderer
*renderer
,
978 GdkRectangle
*WXUNUSED(background_area
),
979 GdkRectangle
*cell_area
,
980 GtkCellRendererState
WXUNUSED(flags
) )
982 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
983 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
986 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
992 rect
.x
+= cell_area
->x
;
993 rect
.y
+= cell_area
->y
;
994 rect
.width
-= renderer
->xpad
* 2;
995 rect
.height
-= renderer
->ypad
* 2;
997 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
999 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1001 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
1004 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
1005 wxDataViewItem
item( iter
.user_data
);
1006 gtk_tree_path_free( treepath
);
1008 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1014 // activated by <ENTER>
1015 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1020 else if (event
->type
== GDK_BUTTON_PRESS
)
1022 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
1023 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
1024 ((int) button_event
->y
) - renderrect
.y
);
1027 if (button_event
->button
== 1)
1029 if (cell
->LeftClick( pt
, renderrect
, model
, item
, model_col
))
1031 // TODO: query system double-click time
1032 if (button_event
->time
- wxrenderer
->last_click
< 400)
1033 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1036 if (button_event
->button
== 3)
1038 if (cell
->RightClick( pt
, renderrect
, model
, item
, model_col
))
1042 wxrenderer
->last_click
= button_event
->time
;
1050 // ---------------------------------------------------------
1051 // wxGtkDataViewModelNotifier
1052 // ---------------------------------------------------------
1054 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1057 wxGtkDataViewModelNotifier( GtkWxTreeModel
*wxgtk_model
,
1058 wxDataViewModel
*wx_model
,
1059 wxDataViewCtrl
*ctrl
);
1060 ~wxGtkDataViewModelNotifier();
1062 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1063 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1064 virtual bool ItemChanged( const wxDataViewItem
&item
);
1065 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
1066 virtual bool Cleared();
1067 virtual void Resort();
1069 void SetGtkModel( GtkWxTreeModel
*model
) { m_wxgtk_model
= model
; }
1072 GtkWxTreeModel
*m_wxgtk_model
;
1073 wxDataViewModel
*m_wx_model
;
1074 wxDataViewCtrl
*m_owner
;
1077 // ---------------------------------------------------------
1078 // wxGtkDataViewListModelNotifier
1079 // ---------------------------------------------------------
1081 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1082 GtkWxTreeModel
* wxgtk_model
, wxDataViewModel
*wx_model
,
1083 wxDataViewCtrl
*ctrl
)
1085 m_wxgtk_model
= wxgtk_model
;
1086 m_wx_model
= wx_model
;
1090 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1093 m_wxgtk_model
= NULL
;
1096 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1098 m_owner
->GtkGetInternal()->ItemAdded( parent
, item
);
1101 iter
.stamp
= m_wxgtk_model
->stamp
;
1102 iter
.user_data
= (gpointer
) item
.GetID();
1104 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1105 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1106 gtk_tree_model_row_inserted(
1107 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1108 gtk_tree_path_free (path
);
1113 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1116 iter
.stamp
= m_wxgtk_model
->stamp
;
1117 iter
.user_data
= (gpointer
) item
.GetID();
1119 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1120 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1121 gtk_tree_model_row_deleted(
1122 GTK_TREE_MODEL(m_wxgtk_model
), path
);
1123 gtk_tree_path_free (path
);
1125 m_owner
->GtkGetInternal()->ItemDeleted( parent
, item
);
1130 void wxGtkDataViewModelNotifier::Resort()
1132 m_owner
->GtkGetInternal()->Resort();
1135 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1138 iter
.stamp
= m_wxgtk_model
->stamp
;
1139 iter
.user_data
= (gpointer
) item
.GetID();
1141 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1142 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1143 gtk_tree_model_row_changed(
1144 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1145 gtk_tree_path_free (path
);
1147 m_owner
->GtkGetInternal()->ItemChanged( item
);
1152 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_col
)
1154 // This adds GTK+'s missing MVC logic for ValueChanged
1156 for (index
= 0; index
< m_owner
->GetColumnCount(); index
++)
1158 wxDataViewColumn
*column
= m_owner
->GetColumn( index
);
1159 if (column
->GetModelColumn() == model_col
)
1161 GtkTreeView
*widget
= GTK_TREE_VIEW(m_owner
->m_treeview
);
1162 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1166 iter
.stamp
= m_wxgtk_model
->stamp
;
1167 iter
.user_data
= (gpointer
) item
.GetID();
1168 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1169 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1170 GdkRectangle cell_area
;
1171 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1172 gtk_tree_path_free( path
);
1174 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1175 double d
= gtk_adjustment_get_value( hadjust
);
1176 int xdiff
= (int) d
;
1178 int ydiff
= gcolumn
->button
->allocation
.height
;
1180 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1181 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1183 m_owner
->GtkGetInternal()->ValueChanged( item
, model_col
);
1192 bool wxGtkDataViewModelNotifier::Cleared()
1194 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->m_treeview
), NULL
);
1196 // this will create a new GTK model
1197 m_owner
->GtkGetInternal()->Cleared();
1199 SetGtkModel( m_owner
->GtkGetInternal()->GetGtkModel() );
1201 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner
->m_treeview
), GTK_TREE_MODEL(m_wxgtk_model
) );
1206 // ---------------------------------------------------------
1207 // wxDataViewRenderer
1208 // ---------------------------------------------------------
1210 static gpointer s_user_data
= NULL
;
1213 wxgtk_cell_editable_editing_done( GtkCellEditable
*WXUNUSED(editable
),
1214 wxDataViewRenderer
*wxrenderer
)
1216 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1217 wxDataViewCtrl
*dv
= column
->GetOwner();
1218 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1219 event
.SetDataViewColumn( column
);
1220 event
.SetModel( dv
->GetModel() );
1221 wxDataViewItem
item( s_user_data
);
1222 event
.SetItem( item
);
1223 dv
->HandleWindowEvent( event
);
1227 wxgtk_renderer_editing_started( GtkCellRenderer
*WXUNUSED(cell
), GtkCellEditable
*editable
,
1228 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1230 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1231 wxDataViewCtrl
*dv
= column
->GetOwner();
1232 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1233 event
.SetDataViewColumn( column
);
1234 event
.SetModel( dv
->GetModel() );
1235 GtkTreePath
*tree_path
= gtk_tree_path_new_from_string( path
);
1237 dv
->GtkGetInternal()->get_iter( &iter
, tree_path
);
1238 gtk_tree_path_free( tree_path
);
1239 wxDataViewItem
item( iter
.user_data
);
1240 event
.SetItem( item
);
1241 dv
->HandleWindowEvent( event
);
1243 if (GTK_IS_CELL_EDITABLE(editable
))
1245 s_user_data
= iter
.user_data
;
1247 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1248 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1249 (gpointer
) wxrenderer
);
1255 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1257 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1259 wxDataViewRendererBase( varianttype
, mode
, align
)
1263 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1264 // after the m_renderer pointer has been initialized
1267 void wxDataViewRenderer::GtkInitHandlers()
1269 if (!gtk_check_version(2,6,0))
1271 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1272 G_CALLBACK (wxgtk_renderer_editing_started
),
1277 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1279 GtkCellRendererMode gtkMode
;
1282 case wxDATAVIEW_CELL_INERT
:
1283 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1285 case wxDATAVIEW_CELL_ACTIVATABLE
:
1286 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1288 case wxDATAVIEW_CELL_EDITABLE
:
1289 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1293 // This value is most often ignored in GtkTreeView
1294 GValue gvalue
= { 0, };
1295 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1296 g_value_set_enum( &gvalue
, gtkMode
);
1297 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1298 g_value_unset( &gvalue
);
1301 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1303 wxDataViewCellMode ret
;
1306 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1308 switch (g_value_get_enum(&gvalue
))
1310 case GTK_CELL_RENDERER_MODE_INERT
:
1311 ret
= wxDATAVIEW_CELL_INERT
;
1313 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1314 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1316 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1317 ret
= wxDATAVIEW_CELL_EDITABLE
;
1321 g_value_unset( &gvalue
);
1326 void wxDataViewRenderer::SetAlignment( int align
)
1328 // horizontal alignment:
1330 gfloat xalign
= 0.0;
1331 if (align
& wxALIGN_RIGHT
)
1333 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1336 GValue gvalue
= { 0, };
1337 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1338 g_value_set_float( &gvalue
, xalign
);
1339 g_object_set_property( G_OBJECT(m_renderer
), "xalign", &gvalue
);
1340 g_value_unset( &gvalue
);
1342 // vertical alignment:
1344 gfloat yalign
= 0.0;
1345 if (align
& wxALIGN_BOTTOM
)
1347 else if (align
& wxALIGN_CENTER_VERTICAL
)
1350 GValue gvalue2
= { 0, };
1351 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1352 g_value_set_float( &gvalue2
, yalign
);
1353 g_object_set_property( G_OBJECT(m_renderer
), "yalign", &gvalue2
);
1354 g_value_unset( &gvalue2
);
1357 int wxDataViewRenderer::GetAlignment() const
1362 // horizontal alignment:
1364 g_object_get( G_OBJECT(m_renderer
), "xalign", &gvalue
, NULL
);
1365 float xalign
= g_value_get_float( &gvalue
);
1367 ret
|= wxALIGN_LEFT
;
1368 else if (xalign
== 0.5)
1369 ret
|= wxALIGN_CENTER_HORIZONTAL
;
1371 ret
|= wxALIGN_RIGHT
;
1372 g_value_unset( &gvalue
);
1375 // vertical alignment:
1377 g_object_get( G_OBJECT(m_renderer
), "yalign", &gvalue
, NULL
);
1378 float yalign
= g_value_get_float( &gvalue
);
1381 else if (yalign
== 0.5)
1382 ret
|= wxALIGN_CENTER_VERTICAL
;
1384 ret
|= wxALIGN_BOTTOM
;
1385 g_value_unset( &gvalue
);
1392 // ---------------------------------------------------------
1393 // wxDataViewTextRenderer
1394 // ---------------------------------------------------------
1397 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1398 gchar
*arg1
, gchar
*arg2
, gpointer user_data
);
1401 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*WXUNUSED(renderer
),
1402 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1404 wxDataViewTextRenderer
*cell
= (wxDataViewTextRenderer
*) user_data
;
1406 wxString tmp
= wxGTK_CONV_BACK_FONT(arg2
, cell
->GetOwner()->GetOwner()->GetFont());
1407 wxVariant value
= tmp
;
1408 if (!cell
->Validate( value
))
1411 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1413 GtkTreePath
*path
= gtk_tree_path_new_from_string( arg1
);
1415 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, path
);
1416 wxDataViewItem
item( (void*) iter
.user_data
);;
1417 gtk_tree_path_free( path
);
1419 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1421 model
->SetValue( value
, item
, model_col
);
1422 model
->ValueChanged( item
, model_col
);
1425 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
1427 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1429 wxDataViewRenderer( varianttype
, mode
, align
)
1431 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_text_new();
1433 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
1435 GValue gvalue
= { 0, };
1436 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1437 g_value_set_boolean( &gvalue
, true );
1438 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
1439 g_value_unset( &gvalue
);
1441 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
1447 SetAlignment(align
);
1450 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
1452 wxString tmp
= value
;
1454 GValue gvalue
= { 0, };
1455 g_value_init( &gvalue
, G_TYPE_STRING
);
1456 g_value_set_string( &gvalue
, wxGTK_CONV( tmp
) );
1457 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1458 g_value_unset( &gvalue
);
1463 bool wxDataViewTextRenderer::GetValue( wxVariant
&value
) const
1465 GValue gvalue
= { 0, };
1466 g_value_init( &gvalue
, G_TYPE_STRING
);
1467 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1468 wxString tmp
= wxGTK_CONV_BACK( g_value_get_string( &gvalue
) );
1469 g_value_unset( &gvalue
);
1476 void wxDataViewTextRenderer::SetAlignment( int align
)
1478 wxDataViewRenderer::SetAlignment(align
);
1480 if (gtk_check_version(2,10,0))
1483 // horizontal alignment:
1484 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
1485 if (align
& wxALIGN_RIGHT
)
1486 pangoAlign
= PANGO_ALIGN_RIGHT
;
1487 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1488 pangoAlign
= PANGO_ALIGN_CENTER
;
1490 GValue gvalue
= { 0, };
1491 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1492 g_value_set_enum( &gvalue
, pangoAlign
);
1493 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
1494 g_value_unset( &gvalue
);
1497 // ---------------------------------------------------------
1498 // wxDataViewTextRendererAttr
1499 // ---------------------------------------------------------
1501 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
,wxDataViewTextRenderer
)
1503 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString
&varianttype
,
1504 wxDataViewCellMode mode
, int align
) :
1505 wxDataViewTextRenderer( varianttype
, mode
, align
)
1509 // ---------------------------------------------------------
1510 // wxDataViewBitmapRenderer
1511 // ---------------------------------------------------------
1513 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
1515 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1517 wxDataViewRenderer( varianttype
, mode
, align
)
1519 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_pixbuf_new();
1522 SetAlignment(align
);
1525 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
1527 if (value
.GetType() == wxT("wxBitmap"))
1532 // This may create a Pixbuf representation in the
1533 // wxBitmap object (and it will stay there)
1534 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1536 GValue gvalue
= { 0, };
1537 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1538 g_value_set_object( &gvalue
, pixbuf
);
1539 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1540 g_value_unset( &gvalue
);
1545 if (value
.GetType() == wxT("wxIcon"))
1550 // This may create a Pixbuf representation in the
1551 // wxBitmap object (and it will stay there)
1552 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1554 GValue gvalue
= { 0, };
1555 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1556 g_value_set_object( &gvalue
, pixbuf
);
1557 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1558 g_value_unset( &gvalue
);
1566 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
1571 // ---------------------------------------------------------
1572 // wxDataViewToggleRenderer
1573 // ---------------------------------------------------------
1576 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1577 gchar
*path
, gpointer user_data
);
1580 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1581 gchar
*path
, gpointer user_data
)
1583 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
1586 GValue gvalue
= { 0, };
1587 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1588 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
1589 bool tmp
= g_value_get_boolean( &gvalue
);
1590 g_value_unset( &gvalue
);
1594 wxVariant value
= tmp
;
1595 if (!cell
->Validate( value
))
1598 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1600 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
1602 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, gtk_path
);
1603 wxDataViewItem
item( (void*) iter
.user_data
);;
1604 gtk_tree_path_free( gtk_path
);
1606 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1608 model
->SetValue( value
, item
, model_col
);
1609 model
->ValueChanged( item
, model_col
);
1612 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1614 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1615 wxDataViewCellMode mode
, int align
) :
1616 wxDataViewRenderer( varianttype
, mode
, align
)
1618 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
1620 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1622 g_signal_connect_after( m_renderer
, "toggled",
1623 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
1627 GValue gvalue
= { 0, };
1628 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1629 g_value_set_boolean( &gvalue
, false );
1630 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
1631 g_value_unset( &gvalue
);
1635 SetAlignment(align
);
1638 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1642 GValue gvalue
= { 0, };
1643 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1644 g_value_set_boolean( &gvalue
, tmp
);
1645 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1646 g_value_unset( &gvalue
);
1651 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
1653 GValue gvalue
= { 0, };
1654 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1655 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1656 bool tmp
= g_value_get_boolean( &gvalue
);
1657 g_value_unset( &gvalue
);
1664 // ---------------------------------------------------------
1665 // wxDataViewCustomRenderer
1666 // ---------------------------------------------------------
1668 class wxDataViewCtrlDCImpl
: public wxWindowDCImpl
1671 wxDataViewCtrlDCImpl( wxDC
*owner
, wxDataViewCtrl
*window
) :
1672 wxWindowDCImpl( owner
)
1674 GtkWidget
*widget
= window
->m_treeview
;
1680 m_context
= window
->GtkGetPangoDefaultContext();
1681 m_layout
= pango_layout_new( m_context
);
1682 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
1684 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
1686 // Set m_gdkwindow later
1691 class wxDataViewCtrlDC
: public wxWindowDC
1694 wxDataViewCtrlDC( wxDataViewCtrl
*window
) :
1695 wxWindowDC( new wxDataViewCtrlDCImpl( this, window
) )
1700 // ---------------------------------------------------------
1701 // wxDataViewCustomRenderer
1702 // ---------------------------------------------------------
1704 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
1706 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
1707 wxDataViewCellMode mode
, int align
,
1709 wxDataViewRenderer( varianttype
, mode
, align
)
1712 m_text_renderer
= NULL
;
1720 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
)
1723 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
1724 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
1725 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
1726 view
->GetForegroundColour();
1727 dc
->SetTextForeground(col
);
1728 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
1730 if (!m_text_renderer
)
1731 m_text_renderer
= gtk_cell_renderer_text_new();
1733 GValue gvalue
= { 0, };
1734 g_value_init( &gvalue
, G_TYPE_STRING
);
1735 g_value_set_string( &gvalue
, wxGTK_CONV( text
) );
1736 g_object_set_property( G_OBJECT(m_text_renderer
), "text", &gvalue
);
1737 g_value_unset( &gvalue
);
1739 ((GdkRectangle
*) cell_area
)->x
+= xoffset
;
1740 ((GdkRectangle
*) cell_area
)->width
-= xoffset
;
1742 gtk_cell_renderer_render( m_text_renderer
,
1745 (GdkRectangle
*) background_area
,
1746 (GdkRectangle
*) cell_area
,
1747 (GdkRectangle
*) expose_area
,
1748 (GtkCellRendererState
) flags
);
1750 ((GdkRectangle
*) cell_area
)->x
-= xoffset
;
1751 ((GdkRectangle
*) cell_area
)->width
+= xoffset
;
1755 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
1757 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
1758 renderer
->cell
= this;
1760 m_renderer
= (GtkCellRenderer
*) renderer
;
1763 SetAlignment(align
);
1770 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
1775 if (m_text_renderer
)
1776 gtk_object_sink( GTK_OBJECT(m_text_renderer
) );
1779 wxDC
*wxDataViewCustomRenderer::GetDC()
1783 if (GetOwner() == NULL
)
1785 if (GetOwner()->GetOwner() == NULL
)
1787 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
1793 // ---------------------------------------------------------
1794 // wxDataViewProgressRenderer
1795 // ---------------------------------------------------------
1797 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
1799 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
1800 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1801 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
1807 if (!gtk_check_version(2,6,0))
1809 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
1811 GValue gvalue
= { 0, };
1812 g_value_init( &gvalue
, G_TYPE_STRING
);
1814 g_value_set_string( &gvalue
, wxGTK_CONV(m_label
) );
1815 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1816 g_value_unset( &gvalue
);
1819 SetAlignment(align
);
1824 // Use custom cell code
1825 wxDataViewCustomRenderer::Init(mode
, align
);
1829 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
1833 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
1836 if (!gtk_check_version(2,6,0))
1838 gint tmp
= (long) value
;
1839 GValue gvalue
= { 0, };
1840 g_value_init( &gvalue
, G_TYPE_INT
);
1841 g_value_set_int( &gvalue
, tmp
);
1842 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
1843 g_value_unset( &gvalue
);
1848 m_value
= (long) value
;
1850 if (m_value
< 0) m_value
= 0;
1851 if (m_value
> 100) m_value
= 100;
1857 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
1862 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1864 double pct
= (double)m_value
/ 100.0;
1866 bar
.width
= (int)(cell
.width
* pct
);
1867 dc
->SetPen( *wxTRANSPARENT_PEN
);
1868 dc
->SetBrush( *wxBLUE_BRUSH
);
1869 dc
->DrawRectangle( bar
);
1871 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1872 dc
->SetPen( *wxBLACK_PEN
);
1873 dc
->DrawRectangle( cell
);
1878 wxSize
wxDataViewProgressRenderer::GetSize() const
1880 return wxSize(40,12);
1883 // ---------------------------------------------------------
1884 // wxDataViewDateRenderer
1885 // ---------------------------------------------------------
1887 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
1890 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
1891 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
1892 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
1897 m_cal
= new wxCalendarCtrl( this, -1, *value
);
1898 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
1899 sizer
->Add( m_cal
, 1, wxGROW
);
1904 virtual void OnDismiss()
1908 void OnCalendar( wxCalendarEvent
&event
);
1910 wxCalendarCtrl
*m_cal
;
1911 wxDataViewModel
*m_model
;
1912 wxDataViewItem m_item
;
1916 DECLARE_EVENT_TABLE()
1919 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
1920 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
1923 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
1925 wxDateTime date
= event
.GetDate();
1926 wxVariant value
= date
;
1927 m_model
->SetValue( value
, m_item
, m_col
);
1928 m_model
->ValueChanged( m_item
, m_col
);
1932 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
1934 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1935 wxDataViewCellMode mode
, int align
) :
1936 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1939 SetAlignment(align
);
1942 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1944 m_date
= value
.GetDateTime();
1949 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
1954 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1956 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
1957 wxString tmp
= m_date
.FormatDate();
1958 RenderText( tmp
, 0, cell
, dc
, state
);
1962 wxSize
wxDataViewDateRenderer::GetSize() const
1964 wxString tmp
= m_date
.FormatDate();
1966 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
1967 return wxSize(x
,y
+d
);
1970 bool wxDataViewDateRenderer::Activate( wxRect cell
, wxDataViewModel
*model
,
1971 const wxDataViewItem
&item
, unsigned int col
)
1974 model
->GetValue( variant
, item
, col
);
1975 wxDateTime value
= variant
.GetDateTime();
1977 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1978 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
1979 wxPoint pos
= wxGetMousePosition();
1982 popup
->Popup( popup
->m_cal
);
1988 // ---------------------------------------------------------
1989 // wxDataViewIconTextRenderer
1990 // ---------------------------------------------------------
1992 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
1994 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
1995 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1996 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1999 SetAlignment(align
);
2002 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2006 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
2012 bool wxDataViewIconTextRenderer::GetValue( wxVariant
&value
) const
2017 bool wxDataViewIconTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
2019 const wxIcon
&icon
= m_value
.GetIcon();
2023 int yoffset
= wxMax( 0, (cell
.height
- icon
.GetHeight()) / 2 );
2024 dc
->DrawIcon( icon
, cell
.x
, cell
.y
+ yoffset
);
2025 offset
= icon
.GetWidth() + 4;
2028 RenderText( m_value
.GetText(), offset
, cell
, dc
, state
);
2033 wxSize
wxDataViewIconTextRenderer::GetSize() const
2036 if (m_value
.GetIcon().IsOk())
2037 size
.x
= 4 + m_value
.GetIcon().GetWidth();
2039 GetView()->GetTextExtent( m_value
.GetText(), &x
, &y
, &d
);
2045 wxControl
* wxDataViewIconTextRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
2050 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
2055 // ---------------------------------------------------------
2057 // ---------------------------------------------------------
2061 gtk_dataview_header_button_press_callback( GtkWidget
*widget
,
2062 GdkEventButton
*gdk_event
,
2063 wxDataViewColumn
*column
)
2065 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
2068 if (gdk_event
->button
== 1)
2070 gs_lastLeftClickHeader
= column
;
2072 wxDataViewCtrl
*dv
= column
->GetOwner();
2073 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
2074 event
.SetDataViewColumn( column
);
2075 event
.SetModel( dv
->GetModel() );
2076 if (dv
->HandleWindowEvent( event
))
2080 if (gdk_event
->button
== 3)
2082 wxDataViewCtrl
*dv
= column
->GetOwner();
2083 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
2084 event
.SetDataViewColumn( column
);
2085 event
.SetModel( dv
->GetModel() );
2086 if (dv
->HandleWindowEvent( event
))
2094 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
2095 GtkCellRenderer
*cell
,
2096 GtkTreeModel
*model
,
2102 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
2103 GtkCellRenderer
*renderer
,
2104 GtkTreeModel
*model
,
2108 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2109 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2111 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2113 wxDataViewItem
item( (void*) iter
->user_data
);
2115 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
2117 if (!wx_model
->IsIndexListModel())
2120 if (wx_model
->IsContainer( item
))
2122 if (wx_model
->HasContainerColumns( item
) || (cell
->GetOwner()->GetModelColumn() == 0))
2124 GValue gvalue
= { 0, };
2125 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2126 g_value_set_boolean( &gvalue
, TRUE
);
2127 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2128 g_value_unset( &gvalue
);
2132 GValue gvalue
= { 0, };
2133 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2134 g_value_set_boolean( &gvalue
, FALSE
);
2135 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2136 g_value_unset( &gvalue
);
2143 GValue gvalue
= { 0, };
2144 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2145 g_value_set_boolean( &gvalue
, TRUE
);
2146 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2147 g_value_unset( &gvalue
);
2153 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
2155 if (value
.GetType() != cell
->GetVariantType())
2156 wxLogError( wxT("Wrong type, required: %s but: %s"),
2157 value
.GetType().c_str(),
2158 cell
->GetVariantType().c_str() );
2160 cell
->SetValue( value
);
2162 if (cell
->GtkHasAttributes())
2164 wxDataViewItemAttr attr
;
2165 bool colour_set
= false;
2166 bool style_set
= false;
2167 bool weight_set
= false;
2169 if (wx_model
->GetAttr( item
, cell
->GetOwner()->GetModelColumn(), attr
))
2171 // this must be a GtkCellRendererText
2172 wxColour colour
= attr
.GetColour();
2175 const GdkColor
* const gcol
= colour
.GetColor();
2177 GValue gvalue
= { 0, };
2178 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2179 g_value_set_boxed( &gvalue
, gcol
);
2180 g_object_set_property( G_OBJECT(renderer
), "foreground_gdk", &gvalue
);
2181 g_value_unset( &gvalue
);
2186 if (attr
.GetItalic())
2188 GValue gvalue
= { 0, };
2189 g_value_init( &gvalue
, PANGO_TYPE_STYLE
);
2190 g_value_set_enum( &gvalue
, PANGO_STYLE_ITALIC
);
2191 g_object_set_property( G_OBJECT(renderer
), "style", &gvalue
);
2192 g_value_unset( &gvalue
);
2199 GValue gvalue
= { 0, };
2200 g_value_init( &gvalue
, PANGO_TYPE_WEIGHT
);
2201 g_value_set_enum( &gvalue
, PANGO_WEIGHT_BOLD
);
2202 g_object_set_property( G_OBJECT(renderer
), "weight", &gvalue
);
2203 g_value_unset( &gvalue
);
2211 GValue gvalue
= { 0, };
2212 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2213 g_value_set_boolean( &gvalue
, FALSE
);
2214 g_object_set_property( G_OBJECT(renderer
), "style-set", &gvalue
);
2215 g_value_unset( &gvalue
);
2220 GValue gvalue
= { 0, };
2221 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2222 g_value_set_boolean( &gvalue
, FALSE
);
2223 g_object_set_property( G_OBJECT(renderer
), "weight-set", &gvalue
);
2224 g_value_unset( &gvalue
);
2229 GValue gvalue
= { 0, };
2230 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2231 g_value_set_boolean( &gvalue
, FALSE
);
2232 g_object_set_property( G_OBJECT(renderer
), "foreground-set", &gvalue
);
2233 g_value_unset( &gvalue
);
2238 if (attr
.HasBackgroundColour())
2240 wxColour colour
= attr
.GetBackgroundColour();
2241 const GdkColor
* const gcol
= colour
.GetColor();
2243 GValue gvalue
= { 0, };
2244 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2245 g_value_set_boxed( &gvalue
, gcol
);
2246 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
2247 g_value_unset( &gvalue
);
2251 GValue gvalue
= { 0, };
2252 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2253 g_value_set_boolean( &gvalue
, FALSE
);
2254 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
2255 g_value_unset( &gvalue
);
2261 IMPLEMENT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
2263 #include <wx/listimpl.cpp>
2264 WX_DEFINE_LIST(wxDataViewColumnList
)
2266 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
2267 unsigned int model_column
, int width
,
2268 wxAlignment align
, int flags
) :
2269 wxDataViewColumnBase( title
, cell
, model_column
, width
, align
, flags
)
2271 Init( align
, flags
, width
);
2273 gtk_tree_view_column_set_clickable( GTK_TREE_VIEW_COLUMN(m_column
), TRUE
);
2277 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
2278 unsigned int model_column
, int width
,
2279 wxAlignment align
, int flags
) :
2280 wxDataViewColumnBase( bitmap
, cell
, model_column
, width
, align
, flags
)
2282 Init( align
, flags
, width
);
2284 SetBitmap( bitmap
);
2287 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
2289 m_isConnected
= false;
2291 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) GetRenderer()->GetGtkHandle();
2292 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
2293 m_column
= (GtkWidget
*) column
;
2296 SetAlignment( align
);
2298 // NOTE: we prefer not to call SetMinWidth(wxDVC_DEFAULT_MINWIDTH);
2299 // as GTK+ is smart and unless explicitely told, will set the minimal
2300 // width to the title's lenght, which is a better default
2302 // the GTK_TREE_VIEW_COLUMN_FIXED is required by the "fixed height" mode
2303 // that we use for the wxDataViewCtrl
2304 gtk_tree_view_column_set_fixed_width( column
, width
< 0 ? wxDVC_DEFAULT_WIDTH
: width
);
2305 gtk_tree_view_column_set_sizing( column
, GTK_TREE_VIEW_COLUMN_FIXED
);
2307 gtk_tree_view_column_pack_end( column
, renderer
, TRUE
);
2309 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
2310 wxGtkTreeCellDataFunc
, (gpointer
) GetRenderer(), NULL
);
2313 wxDataViewColumn::~wxDataViewColumn()
2317 void wxDataViewColumn::OnInternalIdle()
2322 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
2324 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2327 g_signal_connect(column
->button
, "button_press_event",
2328 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
2330 m_isConnected
= true;
2335 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
2337 wxDataViewColumnBase::SetOwner( owner
);
2339 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2341 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
2344 void wxDataViewColumn::SetTitle( const wxString
&title
)
2346 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2350 // disconnect before column->button gets recreated
2351 g_signal_handlers_disconnect_by_func( column
->button
,
2352 (GtkWidget
*) gtk_dataview_header_button_press_callback
, this);
2354 m_isConnected
= false;
2357 // FIXME: can it really happen that we don't have the owner here??
2358 wxDataViewCtrl
*ctrl
= GetOwner();
2359 gtk_tree_view_column_set_title( column
, ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
2360 : wxGTK_CONV_SYS(title
) );
2362 gtk_tree_view_column_set_widget( column
, NULL
);
2365 wxString
wxDataViewColumn::GetTitle() const
2367 const gchar
*str
= gtk_tree_view_column_get_title( GTK_TREE_VIEW_COLUMN(m_column
) );
2368 return wxConvFileName
->cMB2WX(str
);
2371 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
2373 wxDataViewColumnBase::SetBitmap( bitmap
);
2375 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2378 GtkImage
*gtk_image
= GTK_IMAGE( gtk_image_new() );
2380 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
2381 if (bitmap
.GetMask())
2382 mask
= bitmap
.GetMask()->GetBitmap();
2384 if (bitmap
.HasPixbuf())
2386 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
2387 bitmap
.GetPixbuf());
2391 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
2392 bitmap
.GetPixmap(), mask
);
2394 gtk_widget_show( GTK_WIDGET(gtk_image
) );
2396 gtk_tree_view_column_set_widget( column
, GTK_WIDGET(gtk_image
) );
2400 gtk_tree_view_column_set_widget( column
, NULL
);
2404 void wxDataViewColumn::SetHidden( bool hidden
)
2406 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
2409 void wxDataViewColumn::SetResizeable( bool resizeable
)
2411 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizeable
);
2414 void wxDataViewColumn::SetAlignment( wxAlignment align
)
2416 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2418 gfloat xalign
= 0.0;
2419 if (align
== wxALIGN_RIGHT
)
2421 if (align
== wxALIGN_CENTER_HORIZONTAL
||
2422 align
== wxALIGN_CENTER
)
2425 gtk_tree_view_column_set_alignment( column
, xalign
);
2428 wxAlignment
wxDataViewColumn::GetAlignment() const
2430 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
2433 return wxALIGN_RIGHT
;
2435 return wxALIGN_CENTER_HORIZONTAL
;
2437 return wxALIGN_LEFT
;
2440 void wxDataViewColumn::SetSortable( bool sortable
)
2442 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2446 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
2450 gtk_tree_view_column_set_sort_column_id( column
, -1 );
2451 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
2455 bool wxDataViewColumn::IsSortable() const
2457 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2458 return (gtk_tree_view_column_get_sort_column_id( column
) != -1);
2461 bool wxDataViewColumn::IsResizeable() const
2463 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2464 return gtk_tree_view_column_get_resizable( column
);
2467 bool wxDataViewColumn::IsHidden() const
2469 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2470 return !gtk_tree_view_column_get_visible( column
);
2473 void wxDataViewColumn::SetSortOrder( bool ascending
)
2475 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2478 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
2480 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
2482 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
2485 bool wxDataViewColumn::IsSortOrderAscending() const
2487 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2489 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
2492 void wxDataViewColumn::SetMinWidth( int width
)
2494 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2497 int wxDataViewColumn::GetMinWidth() const
2499 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2502 int wxDataViewColumn::GetWidth() const
2504 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2507 void wxDataViewColumn::SetWidth( int width
)
2509 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2513 //-----------------------------------------------------------------------------
2514 // wxGtkTreeModelNode
2515 //-----------------------------------------------------------------------------
2517 void wxGtkTreeModelNode::Resort()
2519 size_t child_count
= GetChildCount();
2520 if (child_count
== 0)
2523 size_t node_count
= GetNodesCount();
2525 if (child_count
== 1)
2527 if (node_count
== 1)
2529 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
2535 wxGtkTreeModelChildren temp
;
2536 WX_APPEND_ARRAY( temp
, m_children
);
2538 g_internal
= m_internal
;
2539 m_children
.Sort( &wxGtkTreeModelChildCmp
);
2541 gint
*new_order
= new gint
[child_count
];
2544 for (pos
= 0; pos
< child_count
; pos
++)
2546 void *id
= m_children
.Item( pos
);
2547 int old_pos
= temp
.Index( id
);
2548 new_order
[pos
] = old_pos
;
2551 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
2554 iter
.user_data
= GetItem().GetID();
2555 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
2557 GtkTreePath
*path
= m_internal
->get_path( &iter
);
2559 gtk_tree_model_rows_reordered( gtk_tree_model
, path
, &iter
, new_order
);
2561 gtk_tree_path_free (path
);
2563 delete [] new_order
;
2565 for (pos
= 0; pos
< node_count
; pos
++)
2567 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
2572 //-----------------------------------------------------------------------------
2573 // wxDataViewCtrlInternal
2574 //-----------------------------------------------------------------------------
2576 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
,
2577 wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
)
2580 m_wx_model
= wx_model
;
2581 m_gtk_model
= gtk_model
;
2583 m_sort_order
= GTK_SORT_ASCENDING
;
2585 m_dataview_sort_column
= NULL
;
2587 if (!m_wx_model
->IsIndexListModel())
2591 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
2593 g_object_unref( m_gtk_model
);
2596 void wxDataViewCtrlInternal::InitTree()
2598 wxDataViewItem item
;
2599 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
2601 BuildBranch( m_root
);
2604 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
2606 if (node
->GetChildCount() == 0)
2608 wxDataViewItemArray children
;
2609 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
2611 for (pos
= 0; pos
< count
; pos
++)
2613 wxDataViewItem child
= children
[pos
];
2615 if (m_wx_model
->IsContainer( child
))
2616 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
2618 node
->AddLeave( child
.GetID() );
2620 // Don't send any events here
2625 bool wxDataViewCtrlInternal::Cleared()
2633 // Create new GTK model
2634 g_object_unref( m_gtk_model
);
2635 m_gtk_model
= wxgtk_tree_model_new();
2636 m_gtk_model
->internal
= this;
2641 void wxDataViewCtrlInternal::Resort()
2643 if (!m_wx_model
->IsIndexListModel())
2647 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
2649 if (!m_wx_model
->IsIndexListModel())
2651 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2652 if (m_wx_model
->IsContainer( item
))
2653 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
2655 parent_node
->AddLeave( item
.GetID() );
2661 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
2663 if (!m_wx_model
->IsIndexListModel())
2665 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2666 parent_node
->DeleteChild( item
.GetID() );
2672 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
2674 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
2675 event
.SetEventObject( m_owner
);
2676 event
.SetModel( m_owner
->GetModel() );
2677 event
.SetItem( item
);
2678 m_owner
->HandleWindowEvent( event
);
2683 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
2685 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
2686 event
.SetEventObject( m_owner
);
2687 event
.SetModel( m_owner
->GetModel() );
2688 event
.SetColumn( col
);
2689 event
.SetDataViewColumn( GetOwner()->GetColumn(col
) );
2690 event
.SetItem( item
);
2691 m_owner
->HandleWindowEvent( event
);
2696 GtkTreeModelFlags
wxDataViewCtrlInternal::get_flags()
2698 if (m_wx_model
->IsIndexListModel())
2699 return GTK_TREE_MODEL_LIST_ONLY
;
2701 return GTK_TREE_MODEL_ITERS_PERSIST
;
2704 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
2706 if (m_wx_model
->IsIndexListModel())
2708 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
2710 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
2712 if (i
>= wx_model
->GetLastIndex() + 1)
2715 iter
->stamp
= m_gtk_model
->stamp
;
2716 // user_data is just the index
2717 iter
->user_data
= (gpointer
) i
;
2723 int depth
= gtk_tree_path_get_depth( path
);
2725 wxGtkTreeModelNode
*node
= m_root
;
2728 for (i
= 0; i
< depth
; i
++)
2730 BuildBranch( node
);
2732 gint pos
= gtk_tree_path_get_indices (path
)[i
];
2733 if (pos
< 0) return FALSE
;
2734 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
2736 void* id
= node
->GetChildren().Item( (size_t) pos
);
2740 iter
->stamp
= m_gtk_model
->stamp
;
2741 iter
->user_data
= id
;
2745 size_t count
= node
->GetNodes().GetCount();
2747 for (pos2
= 0; pos2
< count
; pos2
++)
2749 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
2750 if (child_node
->GetItem().GetID() == id
)
2762 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
2764 GtkTreePath
*retval
= gtk_tree_path_new ();
2766 if (m_wx_model
->IsIndexListModel())
2768 // user_data is just the index
2769 int i
= (wxUIntPtr
) iter
->user_data
;
2770 gtk_tree_path_append_index (retval
, i
);
2774 void *id
= iter
->user_data
;
2776 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
2779 int pos
= node
->GetChildren().Index( id
);
2781 gtk_tree_path_prepend_index( retval
, pos
);
2783 id
= node
->GetItem().GetID();
2784 node
= node
->GetParent();
2791 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
2793 if (m_wx_model
->IsIndexListModel())
2795 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
2797 int n
= (wxUIntPtr
) iter
->user_data
;
2802 if (n
>= (int) wx_model
->GetLastIndex())
2805 iter
->user_data
= (gpointer
) ++n
;
2809 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
2810 if( parent
== NULL
)
2813 int pos
= parent
->GetChildren().Index( iter
->user_data
);
2815 if (pos
== (int) parent
->GetChildCount()-1)
2818 iter
->stamp
= m_gtk_model
->stamp
;
2819 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
2825 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
2827 if (m_wx_model
->IsIndexListModel())
2829 // this is a list, nodes have no children
2833 iter
->stamp
= m_gtk_model
->stamp
;
2834 iter
->user_data
= (gpointer
) -1;
2840 wxDataViewItem
item( (void*) parent
->user_data
);
2842 if (!m_wx_model
->IsContainer( item
))
2845 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2846 BuildBranch( parent_node
);
2848 if (parent_node
->GetChildCount() == 0)
2851 iter
->stamp
= m_gtk_model
->stamp
;
2852 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
2858 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
2860 if (m_wx_model
->IsIndexListModel())
2862 // this is a list, nodes have no children
2867 wxDataViewItem
item( (void*) iter
->user_data
);
2869 bool is_container
= m_wx_model
->IsContainer( item
);
2874 wxGtkTreeModelNode
*node
= FindNode( iter
);
2875 BuildBranch( node
);
2877 return (node
->GetChildCount() > 0);
2881 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
2883 if (m_wx_model
->IsIndexListModel())
2885 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
2888 return (gint
) wx_model
->GetLastIndex() + 1;
2894 wxDataViewItem
item( (void*) iter
->user_data
);
2896 if (!m_wx_model
->IsContainer( item
))
2899 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
2900 BuildBranch( parent_node
);
2902 // wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() );
2904 return parent_node
->GetChildCount();
2908 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
2910 if (m_wx_model
->IsIndexListModel())
2912 wxDataViewIndexListModel
*wx_model
= (wxDataViewIndexListModel
*) m_wx_model
;
2920 if (n
>= (gint
) wx_model
->GetLastIndex() + 1)
2923 iter
->stamp
= m_gtk_model
->stamp
;
2924 iter
->user_data
= (gpointer
) n
;
2931 if (parent
) id
= (void*) parent
->user_data
;
2932 wxDataViewItem
item( id
);
2934 if (!m_wx_model
->IsContainer( item
))
2937 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2938 BuildBranch( parent_node
);
2940 // wxPrintf( "iter_nth_child %d\n", n );
2942 iter
->stamp
= m_gtk_model
->stamp
;
2943 iter
->user_data
= parent_node
->GetChildren().Item( n
);
2949 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
2951 if (m_wx_model
->IsIndexListModel())
2957 wxGtkTreeModelNode
*node
= FindParentNode( child
);
2961 iter
->stamp
= m_gtk_model
->stamp
;
2962 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
2968 static wxGtkTreeModelNode
*
2969 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
2975 list
.DeleteContents( true );
2976 wxDataViewItem
it( item
);
2980 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
2981 list
.Insert( pItem
);
2982 it
= model
->GetParent( it
);
2985 wxGtkTreeModelNode
* node
= treeNode
;
2986 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
2988 if( node
&& node
->GetNodes().GetCount() != 0 )
2990 int len
= node
->GetNodes().GetCount();
2991 wxGtkTreeModelNodes nodes
= node
->GetNodes();
2993 for( ; j
< len
; j
++)
2995 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3014 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
3019 wxDataViewItem
item( (void*) iter
->user_data
);
3023 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3027 wxLogDebug( "Not found %p", iter
->user_data
);
3035 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
3040 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
3044 wxLogDebug( "Not found %p", item
.GetID() );
3052 static wxGtkTreeModelNode
*
3053 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
3059 list
.DeleteContents( true );
3063 wxDataViewItem
it( model
->GetParent( item
) );
3066 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3067 list
.Insert( pItem
);
3068 it
= model
->GetParent( it
);
3071 wxGtkTreeModelNode
* node
= treeNode
;
3072 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
3074 if( node
&& node
->GetNodes().GetCount() != 0 )
3076 int len
= node
->GetNodes().GetCount();
3077 wxGtkTreeModelNodes nodes
= node
->GetNodes();
3079 for( ; j
< len
; j
++)
3081 if( nodes
[j
]->GetItem() == *(n
->GetData()))
3096 //Examine whether the node is item's parent node
3097 int len
= node
->GetChildCount();
3098 for( int i
= 0; i
< len
; i
++ )
3100 if( node
->GetChildren().Item( i
) == item
.GetID() )
3106 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
3111 wxDataViewItem
item( (void*) iter
->user_data
);
3115 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3118 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
3123 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
3126 //-----------------------------------------------------------------------------
3127 // wxDataViewCtrl signal callbacks
3128 //-----------------------------------------------------------------------------
3131 wxdataview_selection_changed_callback( GtkTreeSelection
* selection
, wxDataViewCtrl
*dv
)
3133 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
3136 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
3137 event
.SetItem( dv
->GetSelection() );
3138 event
.SetModel( dv
->GetModel() );
3139 dv
->HandleWindowEvent( event
);
3143 wxdataview_row_activated_callback( GtkTreeView
* treeview
, GtkTreePath
*path
,
3144 GtkTreeViewColumn
*column
, wxDataViewCtrl
*dv
)
3146 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
3149 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3150 wxDataViewItem
item( (void*) iter
.user_data
);;
3151 event
.SetItem( item
);
3152 event
.SetModel( dv
->GetModel() );
3153 dv
->HandleWindowEvent( event
);
3157 wxdataview_test_expand_row_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
3158 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
3160 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
3162 wxDataViewItem
item( (void*) iter
->user_data
);;
3163 event
.SetItem( item
);
3164 event
.SetModel( dv
->GetModel() );
3165 dv
->HandleWindowEvent( event
);
3167 return !event
.IsAllowed();
3171 wxdataview_row_expanded_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
3172 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
3174 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
3176 wxDataViewItem
item( (void*) iter
->user_data
);;
3177 event
.SetItem( item
);
3178 event
.SetModel( dv
->GetModel() );
3179 dv
->HandleWindowEvent( event
);
3183 wxdataview_test_collapse_row_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
3184 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
3186 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
3188 wxDataViewItem
item( (void*) iter
->user_data
);;
3189 event
.SetItem( item
);
3190 event
.SetModel( dv
->GetModel() );
3191 dv
->HandleWindowEvent( event
);
3193 return !event
.IsAllowed();
3197 wxdataview_row_collapsed_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
3198 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
3200 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
3202 wxDataViewItem
item( (void*) iter
->user_data
);;
3203 event
.SetItem( item
);
3204 event
.SetModel( dv
->GetModel() );
3205 dv
->HandleWindowEvent( event
);
3208 //-----------------------------------------------------------------------------
3210 //-----------------------------------------------------------------------------
3212 //-----------------------------------------------------------------------------
3213 // InsertChild for wxDataViewCtrl
3214 //-----------------------------------------------------------------------------
3216 static void wxInsertChildInDataViewCtrl( wxWindowGTK
* parent
, wxWindowGTK
* child
)
3218 wxDataViewCtrl
* dvc
= (wxDataViewCtrl
*) parent
;
3219 GtkWidget
*treeview
= dvc
->GtkGetTreeView();
3221 // Insert widget in GtkTreeView
3222 if (GTK_WIDGET_REALIZED(treeview
))
3223 gtk_widget_set_parent_window( child
->m_widget
,
3224 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
3225 gtk_widget_set_parent( child
->m_widget
, treeview
);
3229 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
3230 GtkAllocation
*alloc
,
3231 wxDataViewCtrl
*win
)
3233 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
3236 wxWindow
*child
= node
->GetData();
3239 gtk_widget_size_request( child
->m_widget
, &req
);
3241 GtkAllocation alloc
;
3242 alloc
.x
= child
->m_x
;
3243 alloc
.y
= child
->m_y
;
3244 alloc
.width
= child
->m_width
;
3245 alloc
.height
= child
->m_height
;
3246 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
3248 node
= node
->GetNext();
3253 //-----------------------------------------------------------------------------
3254 // "motion_notify_event"
3255 //-----------------------------------------------------------------------------
3258 gtk_dataview_motion_notify_callback( GtkWidget
*widget
,
3259 GdkEventMotion
*gdk_event
,
3260 wxDataViewCtrl
*dv
)
3262 if (gdk_event
->is_hint
)
3266 GdkModifierType state
;
3267 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
3272 GtkTreePath
*path
= NULL
;
3273 GtkTreeViewColumn
*column
= NULL
;
3276 if (gtk_tree_view_get_path_at_pos(
3277 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
3278 (int) gdk_event
->x
, (int) gdk_event
->y
,
3287 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3289 // wxPrintf( "mouse %d %d\n", (int) gdk_event->x, (int) gdk_event->y );
3291 gtk_tree_path_free( path
);
3299 //-----------------------------------------------------------------------------
3300 // "button_press_event"
3301 //-----------------------------------------------------------------------------
3304 gtk_dataview_button_press_callback( GtkWidget
*WXUNUSED(widget
),
3305 GdkEventButton
*gdk_event
,
3306 wxDataViewCtrl
*dv
)
3308 if ((gdk_event
->button
== 3) && (gdk_event
->type
== GDK_BUTTON_PRESS
))
3310 GtkTreePath
*path
= NULL
;
3311 GtkTreeViewColumn
*column
= NULL
;
3314 if (gtk_tree_view_get_path_at_pos(
3315 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
3316 (int) gdk_event
->x
, (int) gdk_event
->y
,
3325 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3327 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, dv
->GetId() );
3328 wxDataViewItem
item( (void*) iter
.user_data
);;
3329 event
.SetItem( item
);
3330 event
.SetModel( dv
->GetModel() );
3331 bool ret
= dv
->HandleWindowEvent( event
);
3332 gtk_tree_path_free( path
);
3341 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
3343 wxDataViewCtrl::~wxDataViewCtrl()
3346 GetModel()->RemoveNotifier( m_notifier
);
3348 // remove the model from the GtkTreeView before it gets destroyed by the
3349 // wxDataViewCtrlBase's dtor
3350 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), NULL
);
3355 void wxDataViewCtrl::Init()
3361 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
3362 const wxPoint
& pos
, const wxSize
& size
,
3363 long style
, const wxValidator
& validator
)
3367 if (!PreCreation( parent
, pos
, size
) ||
3368 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
3370 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
3374 m_insertCallback
= wxInsertChildInDataViewCtrl
;
3376 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
3378 GtkScrolledWindowSetBorder(m_widget
, style
);
3380 m_treeview
= gtk_tree_view_new();
3381 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
3383 g_signal_connect (m_treeview
, "size_allocate",
3384 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
3387 if (!gtk_check_version(2,6,0))
3388 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), TRUE
);
3391 if (style
& wxDV_MULTIPLE
)
3393 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3394 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
3397 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
3400 if (!gtk_check_version(2,10,0))
3402 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
3404 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
3405 (style
& wxDV_VERT_RULES
) != 0)
3406 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
3407 else if (style
& wxDV_VERT_RULES
)
3408 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
3409 else if (style
& wxDV_HORIZ_RULES
)
3410 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
3412 if (grid
!= GTK_TREE_VIEW_GRID_LINES_NONE
)
3413 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
3417 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_ROW_LINES
) != 0 );
3419 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
3420 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
3421 gtk_widget_show (m_treeview
);
3423 m_parent
->DoAddChild( this );
3427 GtkEnableSelectionEvents();
3429 g_signal_connect_after (m_treeview
, "row-activated",
3430 G_CALLBACK (wxdataview_row_activated_callback
), this);
3432 g_signal_connect (m_treeview
, "test-collapse-row",
3433 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
3435 g_signal_connect_after (m_treeview
, "row-collapsed",
3436 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
3438 g_signal_connect (m_treeview
, "test-expand-row",
3439 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
3441 g_signal_connect_after (m_treeview
, "row-expanded",
3442 G_CALLBACK (wxdataview_row_expanded_callback
), this);
3444 g_signal_connect (m_treeview
, "motion_notify_event",
3445 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
3447 g_signal_connect (m_treeview
, "button_press_event",
3448 G_CALLBACK (gtk_dataview_button_press_callback
), this);
3453 void wxDataViewCtrl::OnInternalIdle()
3455 wxWindow::OnInternalIdle();
3457 unsigned int cols
= GetColumnCount();
3459 for (i
= 0; i
< cols
; i
++)
3461 wxDataViewColumn
*col
= GetColumn( i
);
3462 col
->OnInternalIdle();
3466 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
3477 if (!wxDataViewCtrlBase::AssociateModel( model
))
3480 GtkWxTreeModel
*gtk_model
= wxgtk_tree_model_new();
3481 m_internal
= new wxDataViewCtrlInternal( this, model
, gtk_model
);
3482 gtk_model
->internal
= m_internal
;
3484 m_notifier
= new wxGtkDataViewModelNotifier( gtk_model
, model
, this );
3486 model
->AddNotifier( m_notifier
);
3488 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_model
) );
3490 // unref in wxDataViewCtrlInternal
3491 // g_object_unref( gtk_model );
3496 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
3498 if (!wxDataViewCtrlBase::AppendColumn(col
))
3501 m_cols
.Append( col
);
3503 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
3504 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
3509 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
3511 if (!wxDataViewCtrlBase::PrependColumn(col
))
3514 m_cols
.Insert( col
);
3516 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
3517 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
3522 unsigned int wxDataViewCtrl::GetColumnCount() const
3524 return m_cols
.GetCount();
3527 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
3529 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
3533 wxDataViewColumnList::const_iterator iter
;
3534 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); iter
++)
3536 wxDataViewColumn
*col
= *iter
;
3537 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
3546 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
3548 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
3549 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
3551 m_cols
.remove( column
);
3558 bool wxDataViewCtrl::ClearColumns()
3560 wxDataViewColumnList::iterator iter
;
3561 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); iter
++)
3563 wxDataViewColumn
*col
= *iter
;
3564 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
3565 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
3573 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
3575 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetConstGtkHandle());
3577 GList
*list
= gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview
) );
3579 gint pos
= g_list_index( list
, (gconstpointer
) gtk_column
);
3581 g_list_free( list
);
3586 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
3588 return m_internal
->GetDataViewSortColumn();
3591 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
3594 iter
.user_data
= item
.GetID();
3595 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3596 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
3597 gtk_tree_path_free( path
);
3600 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
3603 iter
.user_data
= item
.GetID();
3604 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3605 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
3606 gtk_tree_path_free( path
);
3609 wxDataViewItem
wxDataViewCtrl::GetSelection() const
3611 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3613 if (m_windowStyle
& wxDV_MULTIPLE
)
3615 // Report the first one
3616 GtkTreeModel
*model
;
3617 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
3621 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
3623 m_internal
->get_iter( &iter
, path
);
3626 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
3627 g_list_free( list
);
3629 return wxDataViewItem( (void*) iter
.user_data
);
3635 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
3637 wxDataViewItem
item( (void*) iter
.user_data
);
3642 return wxDataViewItem(0);
3645 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
3649 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3650 if (HasFlag(wxDV_MULTIPLE
))
3652 GtkTreeModel
*model
;
3653 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
3658 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
3661 m_internal
->get_iter( &iter
, path
);
3663 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
3665 list
= g_list_next( list
);
3670 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
3671 g_list_free( list
);
3677 GtkTreeModel
*model
;
3679 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
3682 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
3690 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
3692 GtkDisableSelectionEvents();
3694 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3696 gtk_tree_selection_unselect_all( selection
);
3699 for (i
= 0; i
< sel
.GetCount(); i
++)
3702 iter
.user_data
= (gpointer
) sel
[i
].GetID();
3703 gtk_tree_selection_select_iter( selection
, &iter
);
3706 GtkEnableSelectionEvents();
3709 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
3711 GtkDisableSelectionEvents();
3713 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3716 iter
.user_data
= (gpointer
) item
.GetID();
3717 gtk_tree_selection_select_iter( selection
, &iter
);
3719 GtkEnableSelectionEvents();
3722 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
3724 GtkDisableSelectionEvents();
3726 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3729 iter
.user_data
= (gpointer
) item
.GetID();
3730 gtk_tree_selection_unselect_iter( selection
, &iter
);
3732 GtkEnableSelectionEvents();
3735 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
3737 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3740 iter
.user_data
= (gpointer
) item
.GetID();
3742 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
3745 void wxDataViewCtrl::SelectAll()
3747 GtkDisableSelectionEvents();
3749 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3751 gtk_tree_selection_select_all( selection
);
3753 GtkEnableSelectionEvents();
3756 void wxDataViewCtrl::UnselectAll()
3758 GtkDisableSelectionEvents();
3760 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3762 gtk_tree_selection_unselect_all( selection
);
3764 GtkEnableSelectionEvents();
3767 void wxDataViewCtrl::EnsureVisible( const wxDataViewItem
& item
, const wxDataViewColumn
*column
)
3770 iter
.user_data
= (gpointer
) item
.GetID();
3771 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3772 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
3773 gtk_tree_path_free( path
);
3776 void wxDataViewCtrl::HitTest( const wxPoint
&point
,
3777 wxDataViewItem
&item
, wxDataViewColumn
*&column
) const
3779 item
= wxDataViewItem(0);
3783 wxRect
wxDataViewCtrl::GetItemRect( const wxDataViewItem
&item
,
3784 const wxDataViewColumn
*column
) const
3789 void wxDataViewCtrl::DoSetExpanderColumn()
3791 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
3792 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
3795 void wxDataViewCtrl::DoSetIndent()
3799 void wxDataViewCtrl::GtkDisableSelectionEvents()
3801 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3802 g_signal_handlers_disconnect_by_func( selection
,
3803 (gpointer
) (wxdataview_selection_changed_callback
), this);
3806 void wxDataViewCtrl::GtkEnableSelectionEvents()
3808 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3809 g_signal_connect_after (selection
, "changed",
3810 G_CALLBACK (wxdataview_selection_changed_callback
), this);
3815 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
3817 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
3822 // !wxUSE_GENERICDATAVIEWCTRL
3825 // wxUSE_DATAVIEWCTRL