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"
36 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 class wxDataViewCtrlInternal
;
41 wxDataViewCtrlInternal
*g_internal
= NULL
;
43 class wxGtkTreeModelNode
;
46 typedef struct _GtkWxTreeModel GtkWxTreeModel
;
49 //-----------------------------------------------------------------------------
50 // wxDataViewCtrlInternal
51 //-----------------------------------------------------------------------------
53 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
54 WX_DEFINE_LIST(ItemList
)
56 class wxDataViewCtrlInternal
59 wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
, GtkWxTreeModel
*owner
);
60 ~wxDataViewCtrlInternal();
62 gboolean
get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
);
63 GtkTreePath
*get_path( GtkTreeIter
*iter
);
64 gboolean
iter_next( GtkTreeIter
*iter
);
65 gboolean
iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
);
66 gboolean
iter_has_child( GtkTreeIter
*iter
);
67 gint
iter_n_children( GtkTreeIter
*iter
);
68 gboolean
iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
);
69 gboolean
iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
);
71 wxDataViewModel
* GetDataViewModel() { return m_wx_model
; }
72 wxDataViewCtrl
* GetOwner() { return m_owner
; }
73 GtkWxTreeModel
* GetGtkModel() { return m_gtk_model
; }
75 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
76 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
77 bool ItemChanged( const wxDataViewItem
&item
);
78 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
82 void SetSortOrder( GtkSortType sort_order
) { m_sort_order
= sort_order
; }
83 GtkSortType
GetSortOrder() { return m_sort_order
; }
85 void SetSortColumn( int column
) { m_sort_column
= column
; }
86 int GetSortColumn() { return m_sort_column
; }
88 void SetDataViewSortColumn( wxDataViewColumn
*column
) { m_dataview_sort_column
= column
; }
89 wxDataViewColumn
*GetDataViewSortColumn() { return m_dataview_sort_column
; }
91 bool IsSorted() { return (m_sort_column
>= 0); }
96 wxGtkTreeModelNode
*FindNode( const wxDataViewItem
&item
);
97 wxGtkTreeModelNode
*FindNode( GtkTreeIter
*iter
);
98 wxGtkTreeModelNode
*FindParentNode( const wxDataViewItem
&item
);
99 wxGtkTreeModelNode
*FindParentNode( GtkTreeIter
*iter
);
100 void BuildBranch( wxGtkTreeModelNode
*branch
);
103 wxGtkTreeModelNode
*m_root
;
104 wxDataViewModel
*m_wx_model
;
105 GtkWxTreeModel
*m_gtk_model
;
106 wxDataViewCtrl
*m_owner
;
107 GtkSortType m_sort_order
;
108 wxDataViewColumn
*m_dataview_sort_column
;
113 //-----------------------------------------------------------------------------
114 // wxGtkTreeModelNode
115 //-----------------------------------------------------------------------------
117 int LINKAGEMODE
wxGtkTreeModelChildCmp( void** id1
, void** id2
)
119 int ret
= g_internal
->GetDataViewModel()->Compare( *id1
, *id2
,
120 g_internal
->GetSortColumn(), (g_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
125 WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode
*, wxGtkTreeModelNodes
);
126 WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren
);
128 class wxGtkTreeModelNode
131 wxGtkTreeModelNode( wxGtkTreeModelNode
* parent
, const wxDataViewItem
&item
,
132 wxDataViewCtrlInternal
*internal
)
136 m_internal
= internal
;
139 ~wxGtkTreeModelNode()
141 size_t count
= m_children
.GetCount();
143 for (i
= 0; i
< count
; i
++)
145 wxGtkTreeModelNode
*child
= m_nodes
.Item( i
);
150 unsigned int AddNode( wxGtkTreeModelNode
* child
)
152 m_nodes
.Add( child
);
154 void *id
= child
->GetItem().GetID();
156 m_children
.Add( id
);
158 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
160 g_internal
= m_internal
;
161 m_children
.Sort( &wxGtkTreeModelChildCmp
);
162 return m_children
.Index( id
);
165 return m_children
.GetCount()-1;
168 unsigned int AddLeave( void* id
)
170 m_children
.Add( id
);
172 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
174 g_internal
= m_internal
;
175 m_children
.Sort( &wxGtkTreeModelChildCmp
);
176 return m_children
.Index( id
);
179 return m_children
.GetCount()-1;
182 void DeleteChild( void* id
)
184 m_children
.Remove( id
);
186 unsigned int count
= m_nodes
.GetCount();
188 for (pos
= 0; pos
< count
; pos
++)
190 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
191 if (node
->GetItem().GetID() == id
)
193 m_nodes
.RemoveAt( pos
);
201 wxGtkTreeModelNode
* GetParent()
203 wxGtkTreeModelNodes
&GetNodes()
205 wxGtkTreeModelChildren
&GetChildren()
206 { return m_children
; }
208 unsigned int GetChildCount() { return m_children
.GetCount(); }
209 unsigned int GetNodesCount() { return m_nodes
.GetCount(); }
211 wxDataViewItem
&GetItem() { return m_item
; }
212 wxDataViewCtrlInternal
*GetInternal() { return m_internal
; }
217 wxGtkTreeModelNode
*m_parent
;
218 wxGtkTreeModelNodes m_nodes
;
219 wxGtkTreeModelChildren m_children
;
220 wxDataViewItem m_item
;
221 wxDataViewCtrlInternal
*m_internal
;
225 //-----------------------------------------------------------------------------
227 //-----------------------------------------------------------------------------
229 extern bool g_blockEventsOnDrag
;
231 //-----------------------------------------------------------------------------
232 // define new GTK+ class wxGtkTreeModel
233 //-----------------------------------------------------------------------------
237 #define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ())
238 #define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel))
239 #define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
240 #define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL))
241 #define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL))
242 #define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
244 GType
gtk_wx_tree_model_get_type (void);
246 typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass
;
248 struct _GtkWxTreeModel
254 wxDataViewCtrlInternal
*internal
;
257 struct _GtkWxTreeModelClass
259 GObjectClass list_parent_class
;
262 static GtkWxTreeModel
*wxgtk_tree_model_new (void);
263 static void wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
);
264 static void wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
);
265 static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
);
266 static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
);
267 static void wxgtk_tree_model_finalize (GObject
*object
);
268 static GtkTreeModelFlags
wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
);
269 static gint
wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
);
270 static GType
wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
272 static gboolean
wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
275 static GtkTreePath
*wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
277 static void wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
281 static gboolean
wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
283 static gboolean
wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
285 GtkTreeIter
*parent
);
286 static gboolean
wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
288 static gint
wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
290 static gboolean
wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
294 static gboolean
wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
299 static gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
300 gint
*sort_column_id
,
302 static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
305 static void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
307 GtkTreeIterCompareFunc func
,
309 GtkDestroyNotify destroy
);
310 static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
311 GtkTreeIterCompareFunc func
,
313 GtkDestroyNotify destroy
);
314 static gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
);
318 static GObjectClass
*list_parent_class
= NULL
;
321 gtk_wx_tree_model_get_type (void)
323 static GType tree_model_type
= 0;
325 if (!tree_model_type
)
327 const GTypeInfo tree_model_info
=
329 sizeof (GtkWxTreeModelClass
),
330 NULL
, /* base_init */
331 NULL
, /* base_finalize */
332 (GClassInitFunc
) wxgtk_tree_model_class_init
,
333 NULL
, /* class_finalize */
334 NULL
, /* class_data */
335 sizeof (GtkWxTreeModel
),
337 (GInstanceInitFunc
) wxgtk_tree_model_init
,
340 static const GInterfaceInfo tree_model_iface_info
=
342 (GInterfaceInitFunc
) wxgtk_tree_model_tree_model_init
,
347 static const GInterfaceInfo sortable_iface_info
=
349 (GInterfaceInitFunc
) wxgtk_tree_model_sortable_init
,
354 tree_model_type
= g_type_register_static (G_TYPE_OBJECT
, "GtkWxTreeModel",
355 &tree_model_info
, (GTypeFlags
)0 );
357 g_type_add_interface_static (tree_model_type
,
359 &tree_model_iface_info
);
360 g_type_add_interface_static (tree_model_type
,
361 GTK_TYPE_TREE_SORTABLE
,
362 &sortable_iface_info
);
365 return tree_model_type
;
368 static GtkWxTreeModel
*
369 wxgtk_tree_model_new(void)
371 GtkWxTreeModel
*retval
= (GtkWxTreeModel
*) g_object_new (GTK_TYPE_WX_TREE_MODEL
, NULL
);
376 wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
)
378 list_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
379 GObjectClass
*object_class
= (GObjectClass
*) klass
;
380 object_class
->finalize
= wxgtk_tree_model_finalize
;
384 wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
)
386 iface
->get_flags
= wxgtk_tree_model_get_flags
;
387 iface
->get_n_columns
= wxgtk_tree_model_get_n_columns
;
388 iface
->get_column_type
= wxgtk_tree_model_get_column_type
;
389 iface
->get_iter
= wxgtk_tree_model_get_iter
;
390 iface
->get_path
= wxgtk_tree_model_get_path
;
391 iface
->get_value
= wxgtk_tree_model_get_value
;
392 iface
->iter_next
= wxgtk_tree_model_iter_next
;
393 iface
->iter_children
= wxgtk_tree_model_iter_children
;
394 iface
->iter_has_child
= wxgtk_tree_model_iter_has_child
;
395 iface
->iter_n_children
= wxgtk_tree_model_iter_n_children
;
396 iface
->iter_nth_child
= wxgtk_tree_model_iter_nth_child
;
397 iface
->iter_parent
= wxgtk_tree_model_iter_parent
;
401 wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
)
403 iface
->get_sort_column_id
= wxgtk_tree_model_get_sort_column_id
;
404 iface
->set_sort_column_id
= wxgtk_tree_model_set_sort_column_id
;
405 iface
->set_sort_func
= wxgtk_tree_model_set_sort_func
;
406 iface
->set_default_sort_func
= wxgtk_tree_model_set_default_sort_func
;
407 iface
->has_default_sort_func
= wxgtk_tree_model_has_default_sort_func
;
411 wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
)
413 tree_model
->internal
= NULL
;
414 tree_model
->stamp
= g_random_int();
418 wxgtk_tree_model_finalize (GObject
*object
)
421 (* list_parent_class
->finalize
) (object
);
426 //-----------------------------------------------------------------------------
427 // implement callbacks from wxGtkTreeModel class by letting
428 // them call the methods of wxWidgets' wxDataViewModel
429 //-----------------------------------------------------------------------------
431 static GtkTreeModelFlags
432 wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
)
434 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (tree_model
), (GtkTreeModelFlags
)0 );
436 return GTK_TREE_MODEL_ITERS_PERSIST
;
440 wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
)
442 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
443 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
445 return wxtree_model
->internal
->GetDataViewModel()->GetColumnCount();
449 wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
452 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
453 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), G_TYPE_INVALID
);
455 GType gtype
= G_TYPE_INVALID
;
457 wxString wxtype
= wxtree_model
->internal
->GetDataViewModel()->GetColumnType( (unsigned int) index
);
459 if (wxtype
== wxT("string"))
460 gtype
= G_TYPE_STRING
;
463 gtype
= G_TYPE_STRING
;
464 // wxFAIL_MSG( _T("non-string columns not supported yet") );
471 wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
475 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
476 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
477 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
479 return wxtree_model
->internal
->get_iter( iter
, path
);
483 wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
486 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
487 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), NULL
);
488 g_return_val_if_fail (iter
->stamp
== GTK_WX_TREE_MODEL (wxtree_model
)->stamp
, NULL
);
490 return wxtree_model
->internal
->get_path( iter
);
494 wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
499 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
500 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
) );
502 wxDataViewModel
*model
= wxtree_model
->internal
->GetDataViewModel();
503 wxString mtype
= model
->GetColumnType( (unsigned int) column
);
504 if (mtype
== wxT("string"))
507 g_value_init( value
, G_TYPE_STRING
);
508 wxDataViewItem
item( (void*) iter
->user_data
);
509 model
->GetValue( variant
, item
, (unsigned int) column
);
511 g_value_set_string( value
, variant
.GetString().utf8_str() );
515 wxFAIL_MSG( _T("non-string columns not supported yet") );
520 wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
523 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
524 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
525 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
527 return wxtree_model
->internal
->iter_next( iter
);
531 wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
535 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
536 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
537 g_return_val_if_fail (wxtree_model
->stamp
== parent
->stamp
, FALSE
);
539 return wxtree_model
->internal
->iter_children( iter
, parent
);
543 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
546 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
547 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
548 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
550 return wxtree_model
->internal
->iter_has_child( iter
);
554 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
557 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
558 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
559 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, 0);
561 return wxtree_model
->internal
->iter_n_children( iter
);
565 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
570 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
571 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
573 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
577 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
581 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
582 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
583 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
585 return wxtree_model
->internal
->iter_parent( iter
, child
);
589 gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
590 gint
*sort_column_id
,
593 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
595 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
597 if (!tree_model
->internal
->IsSorted())
600 *sort_column_id
= -1;
607 *sort_column_id
= tree_model
->internal
->GetSortColumn();
610 *order
= tree_model
->internal
->GetSortOrder();
615 wxDataViewColumn
*gs_lastLeftClickHeader
= NULL
;
617 void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
621 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
622 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
624 tree_model
->internal
->SetDataViewSortColumn( gs_lastLeftClickHeader
);
626 if ((sort_column_id
!= (gint
) tree_model
->internal
->GetSortColumn()) ||
627 (order
!= tree_model
->internal
->GetSortOrder()))
629 tree_model
->internal
->SetSortColumn( sort_column_id
);
630 tree_model
->internal
->SetSortOrder( order
);
632 gtk_tree_sortable_sort_column_changed (sortable
);
634 tree_model
->internal
->GetDataViewModel()->Resort();
637 if (gs_lastLeftClickHeader
)
639 wxDataViewCtrl
*dv
= tree_model
->internal
->GetOwner();
640 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, dv
->GetId() );
641 event
.SetDataViewColumn( gs_lastLeftClickHeader
);
642 event
.SetModel( dv
->GetModel() );
643 dv
->GetEventHandler()->ProcessEvent( event
);
646 gs_lastLeftClickHeader
= NULL
;
649 void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
651 GtkTreeIterCompareFunc func
,
653 GtkDestroyNotify destroy
)
655 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
656 g_return_if_fail (func
!= NULL
);
659 void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
660 GtkTreeIterCompareFunc func
,
662 GtkDestroyNotify destroy
)
664 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
665 g_return_if_fail (func
!= NULL
);
667 wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
670 gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
)
675 //-----------------------------------------------------------------------------
676 // define new GTK+ class wxGtkRendererRenderer
677 //-----------------------------------------------------------------------------
681 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
682 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
683 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
684 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
685 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
686 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
688 GType
gtk_wx_cell_renderer_get_type (void);
690 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
691 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
693 struct _GtkWxCellRenderer
695 GtkCellRenderer parent
;
698 wxDataViewCustomRenderer
*cell
;
702 struct _GtkWxCellRendererClass
704 GtkCellRendererClass cell_parent_class
;
708 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
709 static void gtk_wx_cell_renderer_init (
710 GtkWxCellRenderer
*cell
);
711 static void gtk_wx_cell_renderer_class_init(
712 GtkWxCellRendererClass
*klass
);
713 static void gtk_wx_cell_renderer_finalize (
715 static void gtk_wx_cell_renderer_get_size (
716 GtkCellRenderer
*cell
,
718 GdkRectangle
*rectangle
,
723 static void gtk_wx_cell_renderer_render (
724 GtkCellRenderer
*cell
,
727 GdkRectangle
*background_area
,
728 GdkRectangle
*cell_area
,
729 GdkRectangle
*expose_area
,
730 GtkCellRendererState flags
);
731 static gboolean
gtk_wx_cell_renderer_activate(
732 GtkCellRenderer
*cell
,
736 GdkRectangle
*background_area
,
737 GdkRectangle
*cell_area
,
738 GtkCellRendererState flags
);
739 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
740 GtkCellRenderer
*cell
,
744 GdkRectangle
*background_area
,
745 GdkRectangle
*cell_area
,
746 GtkCellRendererState flags
);
749 static GObjectClass
*cell_parent_class
= NULL
;
754 gtk_wx_cell_renderer_get_type (void)
756 static GType cell_wx_type
= 0;
760 const GTypeInfo cell_wx_info
=
762 sizeof (GtkWxCellRendererClass
),
763 NULL
, /* base_init */
764 NULL
, /* base_finalize */
765 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
766 NULL
, /* class_finalize */
767 NULL
, /* class_data */
768 sizeof (GtkWxCellRenderer
),
770 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
773 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
774 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
781 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
784 cell
->last_click
= 0;
788 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
790 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
791 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
793 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
795 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
797 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
798 cell_class
->render
= gtk_wx_cell_renderer_render
;
799 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
800 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
804 gtk_wx_cell_renderer_finalize (GObject
*object
)
807 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
811 gtk_wx_cell_renderer_new (void)
813 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
818 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
819 GtkCellRenderer
*renderer
,
823 GdkRectangle
*background_area
,
824 GdkRectangle
*cell_area
,
825 GtkCellRendererState flags
)
827 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
828 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
829 if (!cell
->HasEditorCtrl())
833 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
839 rect
.x
+= cell_area
->x
;
840 rect
.y
+= cell_area
->y
;
841 // rect.width -= renderer->xpad * 2;
842 // rect.height -= renderer->ypad * 2;
844 // wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
845 wxRect
renderrect( cell_area
->x
, cell_area
->y
, cell_area
->width
, cell_area
->height
);
847 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
849 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
850 wxDataViewItem
item( (void*) iter
.user_data
);
851 gtk_tree_path_free( treepath
);
853 cell
->StartEditing( item
, renderrect
);
859 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
861 GdkRectangle
*cell_area
,
867 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
868 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
870 wxSize size
= cell
->GetSize();
872 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
873 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
880 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
884 *x_offset
= (gint
)((renderer
->xalign
*
885 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
886 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
890 *y_offset
= (gint
)((renderer
->yalign
*
891 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
892 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
900 *height
= calc_height
;
904 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
907 GdkRectangle
*background_area
,
908 GdkRectangle
*cell_area
,
909 GdkRectangle
*expose_area
,
910 GtkCellRendererState flags
)
913 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
914 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
916 cell
->window
= window
;
917 cell
->widget
= widget
;
918 cell
->background_area
= (void*) background_area
;
919 cell
->cell_area
= (void*) cell_area
;
920 cell
->expose_area
= (void*) expose_area
;
921 cell
->flags
= (int) flags
;
924 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
930 rect
.x
+= cell_area
->x
;
931 rect
.y
+= cell_area
->y
;
932 rect
.width
-= renderer
->xpad
* 2;
933 rect
.height
-= renderer
->ypad
* 2;
936 if (gdk_rectangle_intersect (expose_area
, &rect
, &dummy
))
938 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
939 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
940 if (dc
->m_window
== NULL
)
942 dc
->m_window
= window
;
947 if (flags
& GTK_CELL_RENDERER_SELECTED
)
948 state
|= wxDATAVIEW_CELL_SELECTED
;
949 if (flags
& GTK_CELL_RENDERER_PRELIT
)
950 state
|= wxDATAVIEW_CELL_PRELIT
;
951 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
952 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
953 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
954 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
955 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
956 state
|= wxDATAVIEW_CELL_FOCUSED
;
957 cell
->Render( renderrect
, dc
, state
);
962 gtk_wx_cell_renderer_activate(
963 GtkCellRenderer
*renderer
,
967 GdkRectangle
*background_area
,
968 GdkRectangle
*cell_area
,
969 GtkCellRendererState flags
)
971 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
972 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
975 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
981 rect
.x
+= cell_area
->x
;
982 rect
.y
+= cell_area
->y
;
983 rect
.width
-= renderer
->xpad
* 2;
984 rect
.height
-= renderer
->ypad
* 2;
986 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
988 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
990 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
993 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
994 wxDataViewItem
item( iter
.user_data
);
995 gtk_tree_path_free( treepath
);
997 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1003 // activated by <ENTER>
1004 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1009 else if (event
->type
== GDK_BUTTON_PRESS
)
1011 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
1012 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
1013 ((int) button_event
->y
) - renderrect
.y
);
1016 if (button_event
->button
== 1)
1018 if (cell
->LeftClick( pt
, renderrect
, model
, item
, model_col
))
1020 // TODO: query system double-click time
1021 if (button_event
->time
- wxrenderer
->last_click
< 400)
1022 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1025 if (button_event
->button
== 3)
1027 if (cell
->RightClick( pt
, renderrect
, model
, item
, model_col
))
1031 wxrenderer
->last_click
= button_event
->time
;
1039 // ---------------------------------------------------------
1040 // wxGtkDataViewModelNotifier
1041 // ---------------------------------------------------------
1043 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1046 wxGtkDataViewModelNotifier( GtkWxTreeModel
*wxgtk_model
,
1047 wxDataViewModel
*wx_model
,
1048 wxDataViewCtrl
*ctrl
);
1049 ~wxGtkDataViewModelNotifier();
1051 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1052 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1053 virtual bool ItemChanged( const wxDataViewItem
&item
);
1054 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
1055 virtual bool Cleared();
1056 virtual void Resort();
1058 GtkWxTreeModel
*m_wxgtk_model
;
1059 wxDataViewModel
*m_wx_model
;
1060 wxDataViewCtrl
*m_owner
;
1063 // ---------------------------------------------------------
1064 // wxGtkDataViewListModelNotifier
1065 // ---------------------------------------------------------
1067 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1068 GtkWxTreeModel
* wxgtk_model
, wxDataViewModel
*wx_model
,
1069 wxDataViewCtrl
*ctrl
)
1071 m_wxgtk_model
= wxgtk_model
;
1072 m_wx_model
= wx_model
;
1076 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1079 m_wxgtk_model
= NULL
;
1082 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1084 m_owner
->GtkGetInternal()->ItemAdded( parent
, item
);
1087 iter
.stamp
= m_wxgtk_model
->stamp
;
1088 iter
.user_data
= (gpointer
) item
.GetID();
1090 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1091 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1092 gtk_tree_model_row_inserted(
1093 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1094 gtk_tree_path_free (path
);
1099 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1102 iter
.stamp
= m_wxgtk_model
->stamp
;
1103 iter
.user_data
= (gpointer
) item
.GetID();
1105 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1106 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1107 gtk_tree_model_row_deleted(
1108 GTK_TREE_MODEL(m_wxgtk_model
), path
);
1109 gtk_tree_path_free (path
);
1111 m_owner
->GtkGetInternal()->ItemDeleted( parent
, item
);
1116 void wxGtkDataViewModelNotifier::Resort()
1118 m_owner
->GtkGetInternal()->Resort();
1121 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1124 iter
.stamp
= m_wxgtk_model
->stamp
;
1125 iter
.user_data
= (gpointer
) item
.GetID();
1127 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1128 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1129 gtk_tree_model_row_changed(
1130 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1131 gtk_tree_path_free (path
);
1133 m_owner
->GtkGetInternal()->ItemChanged( item
);
1138 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_col
)
1140 // This adds GTK+'s missing MVC logic for ValueChanged
1142 for (index
= 0; index
< m_owner
->GetColumnCount(); index
++)
1144 wxDataViewColumn
*column
= m_owner
->GetColumn( index
);
1145 if (column
->GetModelColumn() == model_col
)
1147 GtkTreeView
*widget
= GTK_TREE_VIEW(m_owner
->m_treeview
);
1148 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1152 iter
.stamp
= m_wxgtk_model
->stamp
;
1153 iter
.user_data
= (gpointer
) item
.GetID();
1154 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1155 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1156 GdkRectangle cell_area
;
1157 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1158 gtk_tree_path_free( path
);
1160 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1161 double d
= gtk_adjustment_get_value( hadjust
);
1162 int xdiff
= (int) d
;
1164 int ydiff
= gcolumn
->button
->allocation
.height
;
1166 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1167 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1169 m_owner
->GtkGetInternal()->ValueChanged( item
, model_col
);
1178 bool wxGtkDataViewModelNotifier::Cleared()
1180 // TODO: delete everything
1182 m_owner
->GtkGetInternal()->Cleared();
1187 // ---------------------------------------------------------
1188 // wxDataViewRenderer
1189 // ---------------------------------------------------------
1191 static gpointer s_user_data
= NULL
;
1194 wxgtk_cell_editable_editing_done( GtkCellEditable
*editable
,
1195 wxDataViewRenderer
*wxrenderer
)
1197 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1198 wxDataViewCtrl
*dv
= column
->GetOwner();
1199 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1200 event
.SetDataViewColumn( column
);
1201 event
.SetModel( dv
->GetModel() );
1202 wxDataViewItem
item( s_user_data
);
1203 event
.SetItem( item
);
1204 dv
->GetEventHandler()->ProcessEvent( event
);
1208 wxgtk_renderer_editing_started( GtkCellRenderer
*cell
, GtkCellEditable
*editable
,
1209 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1211 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1212 wxDataViewCtrl
*dv
= column
->GetOwner();
1213 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1214 event
.SetDataViewColumn( column
);
1215 event
.SetModel( dv
->GetModel() );
1216 GtkTreePath
*tree_path
= gtk_tree_path_new_from_string( path
);
1218 dv
->GtkGetInternal()->get_iter( &iter
, tree_path
);
1219 gtk_tree_path_free( tree_path
);
1220 wxDataViewItem
item( iter
.user_data
);
1221 event
.SetItem( item
);
1222 dv
->GetEventHandler()->ProcessEvent( event
);
1224 if (GTK_IS_CELL_EDITABLE(editable
))
1226 s_user_data
= iter
.user_data
;
1228 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1229 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1230 (gpointer
) wxrenderer
);
1236 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1238 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1240 wxDataViewRendererBase( varianttype
, mode
, align
)
1244 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1245 // after the m_renderer pointer has been initialized
1248 void wxDataViewRenderer::GtkInitHandlers()
1250 if (!gtk_check_version(2,6,0))
1252 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1253 G_CALLBACK (wxgtk_renderer_editing_started
),
1258 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1260 GtkCellRendererMode gtkMode
;
1263 case wxDATAVIEW_CELL_INERT
:
1264 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1266 case wxDATAVIEW_CELL_ACTIVATABLE
:
1267 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1269 case wxDATAVIEW_CELL_EDITABLE
:
1270 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1274 // This value is most often ignored in GtkTreeView
1275 GValue gvalue
= { 0, };
1276 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1277 g_value_set_enum( &gvalue
, gtkMode
);
1278 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1279 g_value_unset( &gvalue
);
1282 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1284 wxDataViewCellMode ret
;
1287 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1289 switch (g_value_get_enum(&gvalue
))
1291 case GTK_CELL_RENDERER_MODE_INERT
:
1292 ret
= wxDATAVIEW_CELL_INERT
;
1294 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1295 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1297 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1298 ret
= wxDATAVIEW_CELL_EDITABLE
;
1302 g_value_unset( &gvalue
);
1307 void wxDataViewRenderer::SetAlignment( int align
)
1309 // horizontal alignment:
1311 gfloat xalign
= 0.0;
1312 if (align
& wxALIGN_RIGHT
)
1314 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1317 GValue gvalue
= { 0, };
1318 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1319 g_value_set_float( &gvalue
, xalign
);
1320 g_object_set_property( G_OBJECT(m_renderer
), "xalign", &gvalue
);
1321 g_value_unset( &gvalue
);
1323 // vertical alignment:
1325 gfloat yalign
= 0.0;
1326 if (align
& wxALIGN_BOTTOM
)
1328 else if (align
& wxALIGN_CENTER_VERTICAL
)
1331 GValue gvalue2
= { 0, };
1332 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1333 g_value_set_float( &gvalue2
, yalign
);
1334 g_object_set_property( G_OBJECT(m_renderer
), "yalign", &gvalue2
);
1335 g_value_unset( &gvalue2
);
1338 int wxDataViewRenderer::GetAlignment() const
1343 // horizontal alignment:
1345 g_object_get( G_OBJECT(m_renderer
), "xalign", &gvalue
, NULL
);
1346 float xalign
= g_value_get_float( &gvalue
);
1348 ret
|= wxALIGN_LEFT
;
1349 else if (xalign
== 0.5)
1350 ret
|= wxALIGN_CENTER_HORIZONTAL
;
1352 ret
|= wxALIGN_RIGHT
;
1353 g_value_unset( &gvalue
);
1356 // vertical alignment:
1358 g_object_get( G_OBJECT(m_renderer
), "yalign", &gvalue
, NULL
);
1359 float yalign
= g_value_get_float( &gvalue
);
1362 else if (yalign
== 0.5)
1363 ret
|= wxALIGN_CENTER_VERTICAL
;
1365 ret
|= wxALIGN_BOTTOM
;
1366 g_value_unset( &gvalue
);
1373 // ---------------------------------------------------------
1374 // wxDataViewTextRenderer
1375 // ---------------------------------------------------------
1378 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1379 gchar
*arg1
, gchar
*arg2
, gpointer user_data
);
1382 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1383 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1385 wxDataViewTextRenderer
*cell
= (wxDataViewTextRenderer
*) user_data
;
1387 wxString tmp
= wxGTK_CONV_BACK_FONT(arg2
, cell
->GetOwner()->GetOwner()->GetFont());
1388 wxVariant value
= tmp
;
1389 if (!cell
->Validate( value
))
1392 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1394 GtkTreePath
*path
= gtk_tree_path_new_from_string( arg1
);
1396 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, path
);
1397 wxDataViewItem
item( (void*) iter
.user_data
);;
1398 gtk_tree_path_free( path
);
1400 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1402 model
->SetValue( value
, item
, model_col
);
1403 model
->ValueChanged( item
, model_col
);
1406 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
1408 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1410 wxDataViewRenderer( varianttype
, mode
, align
)
1412 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_text_new();
1414 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
1416 GValue gvalue
= { 0, };
1417 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1418 g_value_set_boolean( &gvalue
, true );
1419 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
1420 g_value_unset( &gvalue
);
1422 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
1428 SetAlignment(align
);
1431 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
1433 wxString tmp
= value
;
1435 GValue gvalue
= { 0, };
1436 g_value_init( &gvalue
, G_TYPE_STRING
);
1437 g_value_set_string( &gvalue
, wxGTK_CONV( tmp
) );
1438 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1439 g_value_unset( &gvalue
);
1444 bool wxDataViewTextRenderer::GetValue( wxVariant
&value
) const
1446 GValue gvalue
= { 0, };
1447 g_value_init( &gvalue
, G_TYPE_STRING
);
1448 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1449 wxString tmp
= wxGTK_CONV_BACK( g_value_get_string( &gvalue
) );
1450 g_value_unset( &gvalue
);
1457 void wxDataViewTextRenderer::SetAlignment( int align
)
1459 wxDataViewRenderer::SetAlignment(align
);
1461 if (gtk_check_version(2,10,0))
1464 // horizontal alignment:
1465 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
1466 if (align
& wxALIGN_RIGHT
)
1467 pangoAlign
= PANGO_ALIGN_RIGHT
;
1468 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1469 pangoAlign
= PANGO_ALIGN_CENTER
;
1471 GValue gvalue
= { 0, };
1472 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1473 g_value_set_enum( &gvalue
, pangoAlign
);
1474 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
1475 g_value_unset( &gvalue
);
1478 // ---------------------------------------------------------
1479 // wxDataViewTextRendererAttr
1480 // ---------------------------------------------------------
1482 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
,wxDataViewTextRenderer
)
1484 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString
&varianttype
,
1485 wxDataViewCellMode mode
, int align
) :
1486 wxDataViewTextRenderer( varianttype
, mode
, align
)
1490 // ---------------------------------------------------------
1491 // wxDataViewBitmapRenderer
1492 // ---------------------------------------------------------
1494 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
1496 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1498 wxDataViewRenderer( varianttype
, mode
, align
)
1500 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_pixbuf_new();
1503 SetAlignment(align
);
1506 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
1508 if (value
.GetType() == wxT("wxBitmap"))
1513 // This may create a Pixbuf representation in the
1514 // wxBitmap object (and it will stay there)
1515 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1517 GValue gvalue
= { 0, };
1518 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1519 g_value_set_object( &gvalue
, pixbuf
);
1520 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1521 g_value_unset( &gvalue
);
1526 if (value
.GetType() == wxT("wxIcon"))
1531 // This may create a Pixbuf representation in the
1532 // wxBitmap object (and it will stay there)
1533 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1535 GValue gvalue
= { 0, };
1536 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1537 g_value_set_object( &gvalue
, pixbuf
);
1538 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1539 g_value_unset( &gvalue
);
1547 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&value
) const
1552 // ---------------------------------------------------------
1553 // wxDataViewToggleRenderer
1554 // ---------------------------------------------------------
1557 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1558 gchar
*path
, gpointer user_data
);
1561 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1562 gchar
*path
, gpointer user_data
)
1564 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
1567 GValue gvalue
= { 0, };
1568 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1569 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
1570 bool tmp
= g_value_get_boolean( &gvalue
);
1571 g_value_unset( &gvalue
);
1575 wxVariant value
= tmp
;
1576 if (!cell
->Validate( value
))
1579 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1581 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
1583 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, gtk_path
);
1584 wxDataViewItem
item( (void*) iter
.user_data
);;
1585 gtk_tree_path_free( gtk_path
);
1587 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1589 model
->SetValue( value
, item
, model_col
);
1590 model
->ValueChanged( item
, model_col
);
1593 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1595 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1596 wxDataViewCellMode mode
, int align
) :
1597 wxDataViewRenderer( varianttype
, mode
, align
)
1599 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
1601 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1603 g_signal_connect_after( m_renderer
, "toggled",
1604 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
1608 GValue gvalue
= { 0, };
1609 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1610 g_value_set_boolean( &gvalue
, false );
1611 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
1612 g_value_unset( &gvalue
);
1616 SetAlignment(align
);
1619 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1623 GValue gvalue
= { 0, };
1624 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1625 g_value_set_boolean( &gvalue
, tmp
);
1626 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1627 g_value_unset( &gvalue
);
1632 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
1634 GValue gvalue
= { 0, };
1635 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1636 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1637 bool tmp
= g_value_get_boolean( &gvalue
);
1638 g_value_unset( &gvalue
);
1645 // ---------------------------------------------------------
1646 // wxDataViewCustomRenderer
1647 // ---------------------------------------------------------
1649 class wxDataViewCtrlDC
: public wxWindowDC
1652 wxDataViewCtrlDC( wxDataViewCtrl
*window
)
1654 GtkWidget
*widget
= window
->m_treeview
;
1658 m_context
= window
->GtkGetPangoDefaultContext();
1659 m_layout
= pango_layout_new( m_context
);
1660 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
1662 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
1664 // Set m_window later
1666 // m_owner = window;
1670 // ---------------------------------------------------------
1671 // wxDataViewCustomRenderer
1672 // ---------------------------------------------------------
1674 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
1676 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
1677 wxDataViewCellMode mode
, int align
,
1679 wxDataViewRenderer( varianttype
, mode
, align
)
1682 m_text_renderer
= NULL
;
1690 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
)
1693 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
1694 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
1695 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
1696 view
->GetForegroundColour();
1697 dc
->SetTextForeground(col
);
1698 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
1700 if (!m_text_renderer
)
1701 m_text_renderer
= gtk_cell_renderer_text_new();
1703 GValue gvalue
= { 0, };
1704 g_value_init( &gvalue
, G_TYPE_STRING
);
1705 g_value_set_string( &gvalue
, wxGTK_CONV( text
) );
1706 g_object_set_property( G_OBJECT(m_text_renderer
), "text", &gvalue
);
1707 g_value_unset( &gvalue
);
1709 ((GdkRectangle
*) cell_area
)->x
+= xoffset
;
1710 ((GdkRectangle
*) cell_area
)->width
-= xoffset
;
1712 gtk_cell_renderer_render( m_text_renderer
,
1715 (GdkRectangle
*) background_area
,
1716 (GdkRectangle
*) cell_area
,
1717 (GdkRectangle
*) expose_area
,
1718 (GtkCellRendererState
) flags
);
1720 ((GdkRectangle
*) cell_area
)->x
-= xoffset
;
1721 ((GdkRectangle
*) cell_area
)->width
+= xoffset
;
1725 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
1727 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
1728 renderer
->cell
= this;
1730 m_renderer
= (GtkCellRenderer
*) renderer
;
1733 SetAlignment(align
);
1740 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
1745 if (m_text_renderer
)
1746 gtk_object_sink( GTK_OBJECT(m_text_renderer
) );
1749 wxDC
*wxDataViewCustomRenderer::GetDC()
1753 if (GetOwner() == NULL
)
1755 if (GetOwner()->GetOwner() == NULL
)
1757 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
1763 // ---------------------------------------------------------
1764 // wxDataViewProgressRenderer
1765 // ---------------------------------------------------------
1767 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
1769 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
1770 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1771 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
1777 if (!gtk_check_version(2,6,0))
1779 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
1781 GValue gvalue
= { 0, };
1782 g_value_init( &gvalue
, G_TYPE_STRING
);
1784 g_value_set_string( &gvalue
, wxGTK_CONV(m_label
) );
1785 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1786 g_value_unset( &gvalue
);
1789 SetAlignment(align
);
1794 // Use custom cell code
1795 wxDataViewCustomRenderer::Init(mode
, align
);
1799 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
1803 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
1806 if (!gtk_check_version(2,6,0))
1808 gint tmp
= (long) value
;
1809 GValue gvalue
= { 0, };
1810 g_value_init( &gvalue
, G_TYPE_INT
);
1811 g_value_set_int( &gvalue
, tmp
);
1812 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
1813 g_value_unset( &gvalue
);
1818 m_value
= (long) value
;
1820 if (m_value
< 0) m_value
= 0;
1821 if (m_value
> 100) m_value
= 100;
1827 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
1832 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1834 double pct
= (double)m_value
/ 100.0;
1836 bar
.width
= (int)(cell
.width
* pct
);
1837 dc
->SetPen( *wxTRANSPARENT_PEN
);
1838 dc
->SetBrush( *wxBLUE_BRUSH
);
1839 dc
->DrawRectangle( bar
);
1841 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1842 dc
->SetPen( *wxBLACK_PEN
);
1843 dc
->DrawRectangle( cell
);
1848 wxSize
wxDataViewProgressRenderer::GetSize() const
1850 return wxSize(40,12);
1853 // ---------------------------------------------------------
1854 // wxDataViewDateRenderer
1855 // ---------------------------------------------------------
1857 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
1860 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
1861 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
1862 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
1867 m_cal
= new wxCalendarCtrl( this, -1, *value
);
1868 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
1869 sizer
->Add( m_cal
, 1, wxGROW
);
1874 virtual void OnDismiss()
1878 void OnCalendar( wxCalendarEvent
&event
);
1880 wxCalendarCtrl
*m_cal
;
1881 wxDataViewModel
*m_model
;
1882 wxDataViewItem m_item
;
1886 DECLARE_EVENT_TABLE()
1889 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
1890 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
1893 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
1895 wxDateTime date
= event
.GetDate();
1896 wxVariant value
= date
;
1897 m_model
->SetValue( value
, m_item
, m_col
);
1898 m_model
->ValueChanged( m_item
, m_col
);
1902 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
1904 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1905 wxDataViewCellMode mode
, int align
) :
1906 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1909 SetAlignment(align
);
1912 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1914 m_date
= value
.GetDateTime();
1919 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
1924 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1926 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
1927 wxString tmp
= m_date
.FormatDate();
1928 RenderText( tmp
, 0, cell
, dc
, state
);
1932 wxSize
wxDataViewDateRenderer::GetSize() const
1934 wxString tmp
= m_date
.FormatDate();
1936 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
1937 return wxSize(x
,y
+d
);
1940 bool wxDataViewDateRenderer::Activate( wxRect cell
, wxDataViewModel
*model
,
1941 const wxDataViewItem
&item
, unsigned int col
)
1944 model
->GetValue( variant
, item
, col
);
1945 wxDateTime value
= variant
.GetDateTime();
1947 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1948 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
1949 wxPoint pos
= wxGetMousePosition();
1952 popup
->Popup( popup
->m_cal
);
1958 // ---------------------------------------------------------
1959 // wxDataViewIconTextRenderer
1960 // ---------------------------------------------------------
1962 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
1964 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
1965 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1966 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1969 SetAlignment(align
);
1972 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
1976 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
1982 bool wxDataViewIconTextRenderer::GetValue( wxVariant
&value
) const
1987 bool wxDataViewIconTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1989 const wxIcon
&icon
= m_value
.GetIcon();
1993 int yoffset
= wxMax( 0, (cell
.height
- icon
.GetHeight()) / 2 );
1994 dc
->DrawIcon( icon
, cell
.x
, cell
.y
+ yoffset
);
1995 offset
= icon
.GetWidth() + 4;
1998 RenderText( m_value
.GetText(), offset
, cell
, dc
, state
);
2003 wxSize
wxDataViewIconTextRenderer::GetSize() const
2006 if (m_value
.GetIcon().IsOk())
2007 size
.x
= 4 + m_value
.GetIcon().GetWidth();
2009 GetView()->GetTextExtent( m_value
.GetText(), &x
, &y
, &d
);
2015 wxControl
* wxDataViewIconTextRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
2020 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
2025 // ---------------------------------------------------------
2027 // ---------------------------------------------------------
2031 gtk_dataview_header_button_press_callback( GtkWidget
*widget
,
2032 GdkEventButton
*gdk_event
,
2033 wxDataViewColumn
*column
)
2035 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
2038 if (gdk_event
->button
== 1)
2040 gs_lastLeftClickHeader
= column
;
2042 wxDataViewCtrl
*dv
= column
->GetOwner();
2043 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
2044 event
.SetDataViewColumn( column
);
2045 event
.SetModel( dv
->GetModel() );
2046 if (dv
->GetEventHandler()->ProcessEvent( event
))
2050 if (gdk_event
->button
== 3)
2052 wxDataViewCtrl
*dv
= column
->GetOwner();
2053 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
2054 event
.SetDataViewColumn( column
);
2055 event
.SetModel( dv
->GetModel() );
2056 if (dv
->GetEventHandler()->ProcessEvent( event
))
2064 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
2065 GtkCellRenderer
*cell
,
2066 GtkTreeModel
*model
,
2072 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
2073 GtkCellRenderer
*renderer
,
2074 GtkTreeModel
*model
,
2078 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2079 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2081 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2083 wxDataViewItem
item( (void*) iter
->user_data
);
2085 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
2087 if (wx_model
->IsContainer( item
))
2089 if (wx_model
->HasContainerColumns( item
) || (cell
->GetOwner()->GetModelColumn() == 0))
2091 GValue gvalue
= { 0, };
2092 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2093 g_value_set_boolean( &gvalue
, TRUE
);
2094 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2095 g_value_unset( &gvalue
);
2099 GValue gvalue
= { 0, };
2100 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2101 g_value_set_boolean( &gvalue
, FALSE
);
2102 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2103 g_value_unset( &gvalue
);
2110 GValue gvalue
= { 0, };
2111 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2112 g_value_set_boolean( &gvalue
, TRUE
);
2113 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2114 g_value_unset( &gvalue
);
2118 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
2120 if (value
.GetType() != cell
->GetVariantType())
2121 wxLogError( wxT("Wrong type, required: %s but: %s"),
2122 value
.GetType().c_str(),
2123 cell
->GetVariantType().c_str() );
2125 cell
->SetValue( value
);
2127 if (cell
->GtkHasAttributes())
2129 wxDataViewItemAttr attr
;
2130 bool colour_set
= false;
2131 bool style_set
= false;
2132 bool weight_set
= false;
2134 if (wx_model
->GetAttr( item
, cell
->GetOwner()->GetModelColumn(), attr
))
2136 // this must be a GtkCellRendererText
2137 wxColour colour
= attr
.GetColour();
2140 const GdkColor
* const gcol
= colour
.GetColor();
2142 GValue gvalue
= { 0, };
2143 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2144 g_value_set_boxed( &gvalue
, gcol
);
2145 g_object_set_property( G_OBJECT(renderer
), "foreground_gdk", &gvalue
);
2146 g_value_unset( &gvalue
);
2151 if (attr
.GetItalic())
2153 GValue gvalue
= { 0, };
2154 g_value_init( &gvalue
, PANGO_TYPE_STYLE
);
2155 g_value_set_enum( &gvalue
, PANGO_STYLE_ITALIC
);
2156 g_object_set_property( G_OBJECT(renderer
), "style", &gvalue
);
2157 g_value_unset( &gvalue
);
2164 GValue gvalue
= { 0, };
2165 g_value_init( &gvalue
, PANGO_TYPE_WEIGHT
);
2166 g_value_set_enum( &gvalue
, PANGO_WEIGHT_BOLD
);
2167 g_object_set_property( G_OBJECT(renderer
), "weight", &gvalue
);
2168 g_value_unset( &gvalue
);
2176 GValue gvalue
= { 0, };
2177 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2178 g_value_set_boolean( &gvalue
, FALSE
);
2179 g_object_set_property( G_OBJECT(renderer
), "style-set", &gvalue
);
2180 g_value_unset( &gvalue
);
2185 GValue gvalue
= { 0, };
2186 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2187 g_value_set_boolean( &gvalue
, FALSE
);
2188 g_object_set_property( G_OBJECT(renderer
), "weight-set", &gvalue
);
2189 g_value_unset( &gvalue
);
2194 GValue gvalue
= { 0, };
2195 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2196 g_value_set_boolean( &gvalue
, FALSE
);
2197 g_object_set_property( G_OBJECT(renderer
), "foreground-set", &gvalue
);
2198 g_value_unset( &gvalue
);
2203 if (attr
.HasBackgroundColour())
2205 wxColour colour
= attr
.GetBackgroundColour();
2206 const GdkColor
* const gcol
= colour
.GetColor();
2208 GValue gvalue
= { 0, };
2209 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2210 g_value_set_boxed( &gvalue
, gcol
);
2211 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
2212 g_value_unset( &gvalue
);
2216 GValue gvalue
= { 0, };
2217 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2218 g_value_set_boolean( &gvalue
, FALSE
);
2219 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
2220 g_value_unset( &gvalue
);
2226 IMPLEMENT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
2228 #include <wx/listimpl.cpp>
2229 WX_DEFINE_LIST(wxDataViewColumnList
)
2231 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
2232 unsigned int model_column
, int width
,
2233 wxAlignment align
, int flags
) :
2234 wxDataViewColumnBase( title
, cell
, model_column
, width
, align
, flags
)
2236 Init( align
, flags
, width
);
2238 gtk_tree_view_column_set_clickable( GTK_TREE_VIEW_COLUMN(m_column
), TRUE
);
2242 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
2243 unsigned int model_column
, int width
,
2244 wxAlignment align
, int flags
) :
2245 wxDataViewColumnBase( bitmap
, cell
, model_column
, width
, align
, flags
)
2247 Init( align
, flags
, width
);
2249 SetBitmap( bitmap
);
2252 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
2254 m_isConnected
= false;
2256 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) GetRenderer()->GetGtkHandle();
2257 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
2258 m_column
= (GtkWidget
*) column
;
2261 SetAlignment( align
);
2263 // NOTE: we prefer not to call SetMinWidth(wxDVC_DEFAULT_MINWIDTH);
2264 // as GTK+ is smart and unless explicitely told, will set the minimal
2265 // width to the title's lenght, which is a better default
2267 // the GTK_TREE_VIEW_COLUMN_FIXED is required by the "fixed height" mode
2268 // that we use for the wxDataViewCtrl
2269 gtk_tree_view_column_set_fixed_width( column
, width
< 0 ? wxDVC_DEFAULT_WIDTH
: width
);
2270 gtk_tree_view_column_set_sizing( column
, GTK_TREE_VIEW_COLUMN_FIXED
);
2272 gtk_tree_view_column_pack_end( column
, renderer
, TRUE
);
2274 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
2275 wxGtkTreeCellDataFunc
, (gpointer
) GetRenderer(), NULL
);
2278 wxDataViewColumn::~wxDataViewColumn()
2282 void wxDataViewColumn::OnInternalIdle()
2287 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
2289 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2292 g_signal_connect(column
->button
, "button_press_event",
2293 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
2295 m_isConnected
= true;
2300 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
2302 wxDataViewColumnBase::SetOwner( owner
);
2304 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2306 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
2309 void wxDataViewColumn::SetTitle( const wxString
&title
)
2311 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2315 // disconnect before column->button gets recreated
2316 g_signal_handlers_disconnect_by_func( column
->button
,
2317 (GtkWidget
*) gtk_dataview_header_button_press_callback
, this);
2319 m_isConnected
= false;
2322 // FIXME: can it really happen that we don't have the owner here??
2323 wxDataViewCtrl
*ctrl
= GetOwner();
2324 gtk_tree_view_column_set_title( column
, ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
2325 : wxGTK_CONV_SYS(title
) );
2327 gtk_tree_view_column_set_widget( column
, NULL
);
2330 wxString
wxDataViewColumn::GetTitle() const
2332 const gchar
*str
= gtk_tree_view_column_get_title( GTK_TREE_VIEW_COLUMN(m_column
) );
2333 return wxConvFileName
->cMB2WX(str
);
2336 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
2338 wxDataViewColumnBase::SetBitmap( bitmap
);
2340 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2343 GtkImage
*gtk_image
= GTK_IMAGE( gtk_image_new() );
2345 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
2346 if (bitmap
.GetMask())
2347 mask
= bitmap
.GetMask()->GetBitmap();
2349 if (bitmap
.HasPixbuf())
2351 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
2352 bitmap
.GetPixbuf());
2356 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
2357 bitmap
.GetPixmap(), mask
);
2359 gtk_widget_show( GTK_WIDGET(gtk_image
) );
2361 gtk_tree_view_column_set_widget( column
, GTK_WIDGET(gtk_image
) );
2365 gtk_tree_view_column_set_widget( column
, NULL
);
2369 void wxDataViewColumn::SetHidden( bool hidden
)
2371 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
2374 void wxDataViewColumn::SetResizeable( bool resizeable
)
2376 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizeable
);
2379 void wxDataViewColumn::SetAlignment( wxAlignment align
)
2381 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2383 gfloat xalign
= 0.0;
2384 if (align
== wxALIGN_RIGHT
)
2386 if (align
== wxALIGN_CENTER_HORIZONTAL
||
2387 align
== wxALIGN_CENTER
)
2390 gtk_tree_view_column_set_alignment( column
, xalign
);
2393 wxAlignment
wxDataViewColumn::GetAlignment() const
2395 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
2398 return wxALIGN_RIGHT
;
2400 return wxALIGN_CENTER_HORIZONTAL
;
2402 return wxALIGN_LEFT
;
2405 void wxDataViewColumn::SetSortable( bool sortable
)
2407 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2411 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
2415 gtk_tree_view_column_set_sort_column_id( column
, -1 );
2416 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
2420 bool wxDataViewColumn::IsSortable() const
2422 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2423 return (gtk_tree_view_column_get_sort_column_id( column
) != -1);
2426 bool wxDataViewColumn::IsResizeable() const
2428 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2429 return gtk_tree_view_column_get_resizable( column
);
2432 bool wxDataViewColumn::IsHidden() const
2434 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2435 return !gtk_tree_view_column_get_visible( column
);
2438 void wxDataViewColumn::SetSortOrder( bool ascending
)
2440 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2443 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
2445 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
2447 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
2450 bool wxDataViewColumn::IsSortOrderAscending() const
2452 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2454 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
2457 void wxDataViewColumn::SetMinWidth( int width
)
2459 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2462 int wxDataViewColumn::GetMinWidth() const
2464 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2467 int wxDataViewColumn::GetWidth() const
2469 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2472 void wxDataViewColumn::SetWidth( int width
)
2474 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2478 //-----------------------------------------------------------------------------
2479 // wxGtkTreeModelNode
2480 //-----------------------------------------------------------------------------
2482 void wxGtkTreeModelNode::Resort()
2484 size_t child_count
= GetChildCount();
2485 if (child_count
== 0)
2488 size_t node_count
= GetNodesCount();
2490 if (child_count
== 1)
2492 if (node_count
== 1)
2494 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
2500 wxGtkTreeModelChildren temp
;
2501 WX_APPEND_ARRAY( temp
, m_children
);
2503 g_internal
= m_internal
;
2504 m_children
.Sort( &wxGtkTreeModelChildCmp
);
2506 gint
*new_order
= new gint
[child_count
];
2509 for (pos
= 0; pos
< child_count
; pos
++)
2511 void *id
= m_children
.Item( pos
);
2512 int old_pos
= temp
.Index( id
);
2513 new_order
[pos
] = old_pos
;
2516 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
2519 iter
.user_data
= GetItem().GetID();
2520 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
2522 GtkTreePath
*path
= m_internal
->get_path( &iter
);
2524 gtk_tree_model_rows_reordered( gtk_tree_model
, path
, &iter
, new_order
);
2526 gtk_tree_path_free (path
);
2528 delete [] new_order
;
2530 for (pos
= 0; pos
< node_count
; pos
++)
2532 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
2537 //-----------------------------------------------------------------------------
2538 // wxDataViewCtrlInternal
2539 //-----------------------------------------------------------------------------
2541 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
,
2542 wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
)
2545 m_wx_model
= wx_model
;
2546 m_gtk_model
= gtk_model
;
2548 m_sort_order
= GTK_SORT_ASCENDING
;
2550 m_dataview_sort_column
= NULL
;
2554 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
2556 g_object_unref( m_gtk_model
);
2559 void wxDataViewCtrlInternal::InitTree()
2561 wxDataViewItem item
;
2562 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
2564 BuildBranch( m_root
);
2567 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
2569 if (node
->GetChildCount() == 0)
2571 wxDataViewItemArray children
;
2572 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
2574 for (pos
= 0; pos
< count
; pos
++)
2576 wxDataViewItem child
= children
[pos
];
2578 if (m_wx_model
->IsContainer( child
))
2579 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
2581 node
->AddLeave( child
.GetID() );
2583 // Don't send any events here
2588 void wxDataViewCtrlInternal::Resort()
2593 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
2595 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2596 if (m_wx_model
->IsContainer( item
))
2597 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
2599 parent_node
->AddLeave( item
.GetID() );
2604 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
2606 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2607 parent_node
->DeleteChild( item
.GetID() );
2612 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
2614 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
2615 event
.SetEventObject( m_owner
);
2616 event
.SetModel( m_owner
->GetModel() );
2617 event
.SetItem( item
);
2618 m_owner
->GetEventHandler()->ProcessEvent( event
);
2623 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
2625 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
2626 event
.SetEventObject( m_owner
);
2627 event
.SetModel( m_owner
->GetModel() );
2628 event
.SetColumn( col
);
2629 event
.SetDataViewColumn( GetOwner()->GetColumn(col
) );
2630 event
.SetItem( item
);
2631 m_owner
->GetEventHandler()->ProcessEvent( event
);
2636 bool wxDataViewCtrlInternal::Cleared()
2641 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
2643 int depth
= gtk_tree_path_get_depth( path
);
2645 wxGtkTreeModelNode
*node
= m_root
;
2648 for (i
= 0; i
< depth
; i
++)
2650 BuildBranch( node
);
2652 gint pos
= gtk_tree_path_get_indices (path
)[i
];
2653 if (pos
< 0) return FALSE
;
2654 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
2656 void* id
= node
->GetChildren().Item( (size_t) pos
);
2660 iter
->stamp
= m_gtk_model
->stamp
;
2661 iter
->user_data
= id
;
2665 size_t count
= node
->GetNodes().GetCount();
2667 for (pos2
= 0; pos2
< count
; pos2
++)
2669 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
2670 if (child_node
->GetItem().GetID() == id
)
2681 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
2683 GtkTreePath
*retval
= gtk_tree_path_new ();
2684 void *id
= iter
->user_data
;
2686 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
2689 int pos
= node
->GetChildren().Index( id
);
2691 gtk_tree_path_prepend_index( retval
, pos
);
2693 id
= node
->GetItem().GetID();
2694 node
= node
->GetParent();
2700 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
2702 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
2703 if( parent
== NULL
)
2706 int pos
= parent
->GetChildren().Index( iter
->user_data
);
2708 if (pos
== (int) parent
->GetChildCount()-1)
2711 iter
->stamp
= m_gtk_model
->stamp
;
2712 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
2717 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
2719 wxDataViewItem
item( (void*) parent
->user_data
);
2721 if (!m_wx_model
->IsContainer( item
))
2724 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2725 BuildBranch( parent_node
);
2727 if (parent_node
->GetChildCount() == 0)
2730 iter
->stamp
= m_gtk_model
->stamp
;
2731 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
2736 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
2738 wxDataViewItem
item( (void*) iter
->user_data
);
2740 bool is_container
= m_wx_model
->IsContainer( item
);
2745 wxGtkTreeModelNode
*node
= FindNode( iter
);
2746 BuildBranch( node
);
2748 return (node
->GetChildCount() > 0);
2751 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
2753 wxDataViewItem
item( (void*) iter
->user_data
);
2755 if (!m_wx_model
->IsContainer( item
))
2758 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
2759 BuildBranch( parent_node
);
2761 // wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() );
2763 return parent_node
->GetChildCount();
2766 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
2769 if (parent
) id
= (void*) parent
->user_data
;
2770 wxDataViewItem
item( id
);
2772 if (!m_wx_model
->IsContainer( item
))
2775 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2776 BuildBranch( parent_node
);
2778 // wxPrintf( "iter_nth_child %d\n", n );
2780 iter
->stamp
= m_gtk_model
->stamp
;
2781 iter
->user_data
= parent_node
->GetChildren().Item( n
);
2786 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
2788 wxGtkTreeModelNode
*node
= FindParentNode( child
);
2792 iter
->stamp
= m_gtk_model
->stamp
;
2793 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
2798 static wxGtkTreeModelNode
*
2799 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
2805 list
.DeleteContents( true );
2806 wxDataViewItem
it( item
);
2810 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
2811 list
.Insert( pItem
);
2812 it
= model
->GetParent( it
);
2815 wxGtkTreeModelNode
* node
= treeNode
;
2816 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
2818 if( node
&& node
->GetNodes().GetCount() != 0 )
2820 int len
= node
->GetNodes().GetCount();
2821 wxGtkTreeModelNodes nodes
= node
->GetNodes();
2823 for( ; j
< len
; j
++)
2825 if( nodes
[j
]->GetItem() == *(n
->GetData()))
2844 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
2849 wxDataViewItem
item( (void*) iter
->user_data
);
2853 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
2857 wxLogDebug( "Not found %p", iter
->user_data
);
2865 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
2870 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
2874 wxLogDebug( "Not found %p", item
.GetID() );
2882 static wxGtkTreeModelNode
*
2883 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
2889 list
.DeleteContents( true );
2893 wxDataViewItem
it( model
->GetParent( item
) );
2896 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
2897 list
.Insert( pItem
);
2898 it
= model
->GetParent( it
);
2901 wxGtkTreeModelNode
* node
= treeNode
;
2902 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
2904 if( node
&& node
->GetNodes().GetCount() != 0 )
2906 int len
= node
->GetNodes().GetCount();
2907 wxGtkTreeModelNodes nodes
= node
->GetNodes();
2909 for( ; j
< len
; j
++)
2911 if( nodes
[j
]->GetItem() == *(n
->GetData()))
2926 //Examine whether the node is item's parent node
2927 int len
= node
->GetChildCount();
2928 for( int i
= 0; i
< len
; i
++ )
2930 if( node
->GetChildren().Item( i
) == item
.GetID() )
2936 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
2941 wxDataViewItem
item( (void*) iter
->user_data
);
2945 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
2948 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
2953 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
2956 //-----------------------------------------------------------------------------
2957 // wxDataViewCtrl signal callbacks
2958 //-----------------------------------------------------------------------------
2961 wxdataview_selection_changed_callback( GtkTreeSelection
* selection
, wxDataViewCtrl
*dv
)
2963 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
2966 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
2967 event
.SetItem( dv
->GetSelection() );
2968 event
.SetModel( dv
->GetModel() );
2969 dv
->GetEventHandler()->ProcessEvent( event
);
2973 wxdataview_row_activated_callback( GtkTreeView
* treeview
, GtkTreePath
*path
,
2974 GtkTreeViewColumn
*column
, wxDataViewCtrl
*dv
)
2976 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
2979 dv
->GtkGetInternal()->get_iter( &iter
, path
);
2980 wxDataViewItem
item( (void*) iter
.user_data
);;
2981 event
.SetItem( item
);
2982 event
.SetModel( dv
->GetModel() );
2983 dv
->GetEventHandler()->ProcessEvent( event
);
2987 wxdataview_test_expand_row_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
2988 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
2990 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
2992 wxDataViewItem
item( (void*) iter
->user_data
);;
2993 event
.SetItem( item
);
2994 event
.SetModel( dv
->GetModel() );
2995 dv
->GetEventHandler()->ProcessEvent( event
);
2997 return !event
.IsAllowed();
3001 wxdataview_row_expanded_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
3002 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
3004 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
3006 wxDataViewItem
item( (void*) iter
->user_data
);;
3007 event
.SetItem( item
);
3008 event
.SetModel( dv
->GetModel() );
3009 dv
->GetEventHandler()->ProcessEvent( event
);
3013 wxdataview_test_collapse_row_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
3014 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
3016 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
3018 wxDataViewItem
item( (void*) iter
->user_data
);;
3019 event
.SetItem( item
);
3020 event
.SetModel( dv
->GetModel() );
3021 dv
->GetEventHandler()->ProcessEvent( event
);
3023 return !event
.IsAllowed();
3027 wxdataview_row_collapsed_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
3028 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
3030 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
3032 wxDataViewItem
item( (void*) iter
->user_data
);;
3033 event
.SetItem( item
);
3034 event
.SetModel( dv
->GetModel() );
3035 dv
->GetEventHandler()->ProcessEvent( event
);
3038 //-----------------------------------------------------------------------------
3040 //-----------------------------------------------------------------------------
3042 //-----------------------------------------------------------------------------
3043 // InsertChild for wxDataViewCtrl
3044 //-----------------------------------------------------------------------------
3046 static void wxInsertChildInDataViewCtrl( wxWindowGTK
* parent
, wxWindowGTK
* child
)
3048 wxDataViewCtrl
* dvc
= (wxDataViewCtrl
*) parent
;
3049 GtkWidget
*treeview
= dvc
->GtkGetTreeView();
3051 // Insert widget in GtkTreeView
3052 if (GTK_WIDGET_REALIZED(treeview
))
3053 gtk_widget_set_parent_window( child
->m_widget
,
3054 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
3055 gtk_widget_set_parent( child
->m_widget
, treeview
);
3059 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
3060 GtkAllocation
*alloc
,
3061 wxDataViewCtrl
*win
)
3063 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
3066 wxWindow
*child
= node
->GetData();
3069 gtk_widget_size_request( child
->m_widget
, &req
);
3071 GtkAllocation alloc
;
3072 alloc
.x
= child
->m_x
;
3073 alloc
.y
= child
->m_y
;
3074 alloc
.width
= child
->m_width
;
3075 alloc
.height
= child
->m_height
;
3076 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
3078 node
= node
->GetNext();
3083 //-----------------------------------------------------------------------------
3084 // "motion_notify_event"
3085 //-----------------------------------------------------------------------------
3088 gtk_dataview_motion_notify_callback( GtkWidget
*widget
,
3089 GdkEventMotion
*gdk_event
,
3090 wxDataViewCtrl
*dv
)
3092 if (gdk_event
->is_hint
)
3096 GdkModifierType state
;
3097 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
3102 GtkTreePath
*path
= NULL
;
3103 GtkTreeViewColumn
*column
= NULL
;
3106 if (gtk_tree_view_get_path_at_pos(
3107 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
3108 (int) gdk_event
->x
, (int) gdk_event
->y
,
3117 dv
->GtkGetInternal()->get_iter( &iter
, path
);
3119 // wxPrintf( "mouse %d %d\n", (int) gdk_event->x, (int) gdk_event->y );
3121 gtk_tree_path_free( path
);
3130 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
3132 wxDataViewCtrl::~wxDataViewCtrl()
3135 GetModel()->RemoveNotifier( m_notifier
);
3137 // remove the model from the GtkTreeView before it gets destroyed by the
3138 // wxDataViewCtrlBase's dtor
3139 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), NULL
);
3144 void wxDataViewCtrl::Init()
3149 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
3150 const wxPoint
& pos
, const wxSize
& size
,
3151 long style
, const wxValidator
& validator
)
3155 if (!PreCreation( parent
, pos
, size
) ||
3156 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
3158 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
3162 m_insertCallback
= wxInsertChildInDataViewCtrl
;
3164 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
3166 GtkScrolledWindowSetBorder(m_widget
, style
);
3168 m_treeview
= gtk_tree_view_new();
3169 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
3171 g_signal_connect (m_treeview
, "size_allocate",
3172 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
3175 if (!gtk_check_version(2,6,0))
3176 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), TRUE
);
3179 if (style
& wxDV_MULTIPLE
)
3181 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3182 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
3185 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
3188 if (!gtk_check_version(2,10,0))
3190 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
3192 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
3193 (style
& wxDV_VERT_RULES
) != 0)
3194 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
3195 else if (style
& wxDV_VERT_RULES
)
3196 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
3197 else if (style
& wxDV_HORIZ_RULES
)
3198 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
3200 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
3205 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_HORIZ_RULES
) != 0 );
3208 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
3209 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
3210 gtk_widget_show (m_treeview
);
3212 m_parent
->DoAddChild( this );
3216 GtkEnableSelectionEvents();
3218 g_signal_connect_after (m_treeview
, "row-activated",
3219 G_CALLBACK (wxdataview_row_activated_callback
), this);
3221 g_signal_connect (m_treeview
, "test-collapse-row",
3222 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
3224 g_signal_connect_after (m_treeview
, "row-collapsed",
3225 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
3227 g_signal_connect (m_treeview
, "test-expand-row",
3228 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
3230 g_signal_connect_after (m_treeview
, "row-expanded",
3231 G_CALLBACK (wxdataview_row_expanded_callback
), this);
3233 g_signal_connect (m_treeview
, "motion_notify_event",
3234 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
3239 void wxDataViewCtrl::OnInternalIdle()
3241 wxWindow::OnInternalIdle();
3243 unsigned int cols
= GetColumnCount();
3245 for (i
= 0; i
< cols
; i
++)
3247 wxDataViewColumn
*col
= GetColumn( i
);
3248 col
->OnInternalIdle();
3252 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
3254 if (!wxDataViewCtrlBase::AssociateModel( model
))
3257 GtkWxTreeModel
*gtk_model
= wxgtk_tree_model_new();
3258 m_internal
= new wxDataViewCtrlInternal( this, model
, gtk_model
);
3259 gtk_model
->internal
= m_internal
;
3261 m_notifier
= new wxGtkDataViewModelNotifier( gtk_model
, model
, this );
3263 model
->AddNotifier( m_notifier
);
3265 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_model
) );
3267 // unref in wxDataViewCtrlInternal
3268 // g_object_unref( gtk_model );
3273 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
3275 if (!wxDataViewCtrlBase::AppendColumn(col
))
3278 m_cols
.Append( col
);
3280 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
3281 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
3286 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
3288 if (!wxDataViewCtrlBase::PrependColumn(col
))
3291 m_cols
.Insert( col
);
3293 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview
),
3294 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()), 0 );
3299 unsigned int wxDataViewCtrl::GetColumnCount() const
3301 return m_cols
.GetCount();
3304 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
3306 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
3310 wxDataViewColumnList::const_iterator iter
;
3311 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); iter
++)
3313 wxDataViewColumn
*col
= *iter
;
3314 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
3323 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
3325 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
3326 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
3328 m_cols
.remove( column
);
3335 bool wxDataViewCtrl::ClearColumns()
3337 wxDataViewColumnList::iterator iter
;
3338 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); iter
++)
3340 wxDataViewColumn
*col
= *iter
;
3341 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
3342 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
3350 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
3352 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetConstGtkHandle());
3354 GList
*list
= gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview
) );
3356 gint pos
= g_list_index( list
, (gconstpointer
) gtk_column
);
3358 g_list_free( list
);
3363 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
3365 return m_internal
->GetDataViewSortColumn();
3368 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
3371 iter
.user_data
= item
.GetID();
3372 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3373 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
3374 gtk_tree_path_free( path
);
3377 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
3380 iter
.user_data
= item
.GetID();
3381 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3382 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
3383 gtk_tree_path_free( path
);
3386 wxDataViewItem
wxDataViewCtrl::GetSelection() const
3388 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3390 if (m_windowStyle
& wxDV_MULTIPLE
)
3392 // Report the first one
3393 GtkTreeModel
*model
;
3394 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
3398 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
3400 m_internal
->get_iter( &iter
, path
);
3403 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
3404 g_list_free( list
);
3406 return wxDataViewItem( (void*) iter
.user_data
);
3412 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
3414 wxDataViewItem
item( (void*) iter
.user_data
);
3419 return wxDataViewItem(0);
3422 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
3426 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3427 if (HasFlag(wxDV_MULTIPLE
))
3429 GtkTreeModel
*model
;
3430 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
3435 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
3438 m_internal
->get_iter( &iter
, path
);
3440 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
3442 list
= g_list_next( list
);
3447 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
3448 g_list_free( list
);
3454 GtkTreeModel
*model
;
3456 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
3459 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
3467 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
3469 GtkDisableSelectionEvents();
3471 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3473 gtk_tree_selection_unselect_all( selection
);
3476 for (i
= 0; i
< sel
.GetCount(); i
++)
3479 iter
.user_data
= (gpointer
) sel
[i
].GetID();
3480 gtk_tree_selection_select_iter( selection
, &iter
);
3483 GtkEnableSelectionEvents();
3486 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
3488 GtkDisableSelectionEvents();
3490 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3493 iter
.user_data
= (gpointer
) item
.GetID();
3494 gtk_tree_selection_select_iter( selection
, &iter
);
3496 GtkEnableSelectionEvents();
3499 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
3501 GtkDisableSelectionEvents();
3503 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3506 iter
.user_data
= (gpointer
) item
.GetID();
3507 gtk_tree_selection_unselect_iter( selection
, &iter
);
3509 GtkEnableSelectionEvents();
3512 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
3514 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3517 iter
.user_data
= (gpointer
) item
.GetID();
3519 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
3522 void wxDataViewCtrl::SelectAll()
3524 GtkDisableSelectionEvents();
3526 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3528 gtk_tree_selection_select_all( selection
);
3530 GtkEnableSelectionEvents();
3533 void wxDataViewCtrl::UnselectAll()
3535 GtkDisableSelectionEvents();
3537 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3539 gtk_tree_selection_unselect_all( selection
);
3541 GtkEnableSelectionEvents();
3544 void wxDataViewCtrl::EnsureVisible( const wxDataViewItem
& item
, const wxDataViewColumn
*column
)
3547 iter
.user_data
= (gpointer
) item
.GetID();
3548 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3549 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
3550 gtk_tree_path_free( path
);
3553 void wxDataViewCtrl::HitTest( const wxPoint
&point
,
3554 wxDataViewItem
&item
, wxDataViewColumn
*&column
) const
3556 item
= wxDataViewItem(0);
3560 wxRect
wxDataViewCtrl::GetItemRect( const wxDataViewItem
&item
,
3561 const wxDataViewColumn
*column
) const
3566 void wxDataViewCtrl::DoSetExpanderColumn()
3568 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
3569 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
3572 void wxDataViewCtrl::DoSetIndent()
3576 void wxDataViewCtrl::GtkDisableSelectionEvents()
3578 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3579 g_signal_handlers_disconnect_by_func( selection
,
3580 (gpointer
) (wxdataview_selection_changed_callback
), this);
3583 void wxDataViewCtrl::GtkEnableSelectionEvents()
3585 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3586 g_signal_connect_after (selection
, "changed",
3587 G_CALLBACK (wxdataview_selection_changed_callback
), this);
3592 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
3594 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
3599 // !wxUSE_GENERICDATAVIEWCTRL
3602 // wxUSE_DATAVIEWCTRL