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/stockitem.h"
26 #include "wx/calctrl.h"
27 #include "wx/popupwin.h"
30 #include "wx/listimpl.cpp"
33 #include "wx/gtk/private.h"
34 #include "wx/gtk/win_gtk.h"
36 #include <gobject/gvaluecollector.h>
37 #include <gtk/gtktreemodel.h>
38 #include <gtk/gtktreesortable.h>
39 #include <gtk/gtktreednd.h>
41 #include <gdk/gdkkeysyms.h>
43 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
46 class wxDataViewCtrlInternal
;
48 wxDataViewCtrlInternal
*g_internal
= NULL
;
50 class wxGtkTreeModelNode
;
53 typedef struct _GtkWxTreeModel GtkWxTreeModel
;
56 //-----------------------------------------------------------------------------
57 // wxDataViewCtrlInternal
58 //-----------------------------------------------------------------------------
60 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
61 WX_DEFINE_LIST(ItemList
);
63 class wxDataViewCtrlInternal
66 wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
, GtkWxTreeModel
*owner
);
67 ~wxDataViewCtrlInternal();
69 gboolean
get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
);
70 GtkTreePath
*get_path( GtkTreeIter
*iter
);
71 gboolean
iter_next( GtkTreeIter
*iter
);
72 gboolean
iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
);
73 gboolean
iter_has_child( GtkTreeIter
*iter
);
74 gint
iter_n_children( GtkTreeIter
*iter
);
75 gboolean
iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
);
76 gboolean
iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
);
78 wxDataViewModel
* GetDataViewModel() { return m_wx_model
; }
79 wxDataViewCtrl
* GetOwner() { return m_owner
; }
80 GtkWxTreeModel
* GetGtkModel() { return m_gtk_model
; }
82 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
83 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
84 bool ItemChanged( const wxDataViewItem
&item
);
85 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
89 void SetSortOrder( GtkSortType sort_order
) { m_sort_order
= sort_order
; }
90 GtkSortType
GetSortOrder() { return m_sort_order
; }
92 void SetSortColumn( int column
) { m_sort_column
= column
; }
93 int GetSortColumn() { return m_sort_column
; }
95 void SetDataViewSortColumn( wxDataViewColumn
*column
) { m_dataview_sort_column
= column
; }
96 wxDataViewColumn
*GetDataViewSortColumn() { return m_dataview_sort_column
; }
98 bool IsSorted() { return (m_sort_column
>= 0); }
103 wxGtkTreeModelNode
*FindNode( const wxDataViewItem
&item
);
104 wxGtkTreeModelNode
*FindNode( GtkTreeIter
*iter
);
105 wxGtkTreeModelNode
*FindParentNode( const wxDataViewItem
&item
);
106 wxGtkTreeModelNode
*FindParentNode( GtkTreeIter
*iter
);
107 void BuildBranch( wxGtkTreeModelNode
*branch
);
110 wxGtkTreeModelNode
*m_root
;
111 wxDataViewModel
*m_wx_model
;
112 GtkWxTreeModel
*m_gtk_model
;
113 wxDataViewCtrl
*m_owner
;
114 GtkSortType m_sort_order
;
115 wxDataViewColumn
*m_dataview_sort_column
;
120 //-----------------------------------------------------------------------------
121 // wxGtkTreeModelNode
122 //-----------------------------------------------------------------------------
124 int LINKAGEMODE
wxGtkTreeModelChildCmp( void** id1
, void** id2
)
126 int ret
= g_internal
->GetDataViewModel()->Compare( *id1
, *id2
,
127 g_internal
->GetSortColumn(), (g_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
132 WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode
*, wxGtkTreeModelNodes
);
133 WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren
);
135 class wxGtkTreeModelNode
138 wxGtkTreeModelNode( wxGtkTreeModelNode
* parent
, const wxDataViewItem
&item
,
139 wxDataViewCtrlInternal
*internal
)
143 m_internal
= internal
;
146 ~wxGtkTreeModelNode()
148 size_t count
= m_children
.GetCount();
150 for (i
= 0; i
< count
; i
++)
152 wxGtkTreeModelNode
*child
= m_nodes
.Item( i
);
157 unsigned int AddNode( wxGtkTreeModelNode
* child
)
159 m_nodes
.Add( child
);
161 void *id
= child
->GetItem().GetID();
163 m_children
.Add( id
);
165 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
167 g_internal
= m_internal
;
168 m_children
.Sort( &wxGtkTreeModelChildCmp
);
169 return m_children
.Index( id
);
172 return m_children
.GetCount()-1;
175 unsigned int AddLeave( void* id
)
177 m_children
.Add( id
);
179 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
181 g_internal
= m_internal
;
182 m_children
.Sort( &wxGtkTreeModelChildCmp
);
183 return m_children
.Index( id
);
186 return m_children
.GetCount()-1;
189 void DeleteChild( void* id
)
191 m_children
.Remove( id
);
193 unsigned int count
= m_nodes
.GetCount();
195 for (pos
= 0; pos
< count
; pos
++)
197 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
198 if (node
->GetItem().GetID() == id
)
200 m_nodes
.RemoveAt( pos
);
208 wxGtkTreeModelNode
* GetParent()
210 wxGtkTreeModelNodes
&GetNodes()
212 wxGtkTreeModelChildren
&GetChildren()
213 { return m_children
; }
215 unsigned int GetChildCount() { return m_children
.GetCount(); }
216 unsigned int GetNodesCount() { return m_nodes
.GetCount(); }
218 wxDataViewItem
&GetItem() { return m_item
; }
219 wxDataViewCtrlInternal
*GetInternal() { return m_internal
; }
224 wxGtkTreeModelNode
*m_parent
;
225 wxGtkTreeModelNodes m_nodes
;
226 wxGtkTreeModelChildren m_children
;
227 wxDataViewItem m_item
;
228 wxDataViewCtrlInternal
*m_internal
;
232 //-----------------------------------------------------------------------------
234 //-----------------------------------------------------------------------------
236 extern bool g_blockEventsOnDrag
;
238 //-----------------------------------------------------------------------------
239 // define new GTK+ class wxGtkTreeModel
240 //-----------------------------------------------------------------------------
244 #define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ())
245 #define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel))
246 #define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
247 #define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL))
248 #define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL))
249 #define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
251 GType
gtk_wx_tree_model_get_type (void);
253 typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass
;
255 struct _GtkWxTreeModel
261 wxDataViewCtrlInternal
*internal
;
264 struct _GtkWxTreeModelClass
266 GObjectClass list_parent_class
;
269 static GtkWxTreeModel
*wxgtk_tree_model_new (void);
270 static void wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
);
271 static void wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
);
272 static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
);
273 static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
);
274 static void wxgtk_tree_model_finalize (GObject
*object
);
275 static GtkTreeModelFlags
wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
);
276 static gint
wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
);
277 static GType
wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
279 static gboolean
wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
282 static GtkTreePath
*wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
284 static void wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
288 static gboolean
wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
290 static gboolean
wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
292 GtkTreeIter
*parent
);
293 static gboolean
wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
295 static gint
wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
297 static gboolean
wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
301 static gboolean
wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
306 static gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
307 gint
*sort_column_id
,
309 static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
312 static void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
314 GtkTreeIterCompareFunc func
,
316 GtkDestroyNotify destroy
);
317 static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
318 GtkTreeIterCompareFunc func
,
320 GtkDestroyNotify destroy
);
321 static gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
);
325 static GObjectClass
*list_parent_class
= NULL
;
328 gtk_wx_tree_model_get_type (void)
330 static GType tree_model_type
= 0;
332 if (!tree_model_type
)
334 const GTypeInfo tree_model_info
=
336 sizeof (GtkWxTreeModelClass
),
337 NULL
, /* base_init */
338 NULL
, /* base_finalize */
339 (GClassInitFunc
) wxgtk_tree_model_class_init
,
340 NULL
, /* class_finalize */
341 NULL
, /* class_data */
342 sizeof (GtkWxTreeModel
),
344 (GInstanceInitFunc
) wxgtk_tree_model_init
,
347 static const GInterfaceInfo tree_model_iface_info
=
349 (GInterfaceInitFunc
) wxgtk_tree_model_tree_model_init
,
354 static const GInterfaceInfo sortable_iface_info
=
356 (GInterfaceInitFunc
) wxgtk_tree_model_sortable_init
,
361 tree_model_type
= g_type_register_static (G_TYPE_OBJECT
, "GtkWxTreeModel",
362 &tree_model_info
, (GTypeFlags
)0 );
364 g_type_add_interface_static (tree_model_type
,
366 &tree_model_iface_info
);
367 g_type_add_interface_static (tree_model_type
,
368 GTK_TYPE_TREE_SORTABLE
,
369 &sortable_iface_info
);
372 return tree_model_type
;
375 static GtkWxTreeModel
*
376 wxgtk_tree_model_new(void)
378 GtkWxTreeModel
*retval
= (GtkWxTreeModel
*) g_object_new (GTK_TYPE_WX_TREE_MODEL
, NULL
);
383 wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
)
385 list_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
386 GObjectClass
*object_class
= (GObjectClass
*) klass
;
387 object_class
->finalize
= wxgtk_tree_model_finalize
;
391 wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
)
393 iface
->get_flags
= wxgtk_tree_model_get_flags
;
394 iface
->get_n_columns
= wxgtk_tree_model_get_n_columns
;
395 iface
->get_column_type
= wxgtk_tree_model_get_column_type
;
396 iface
->get_iter
= wxgtk_tree_model_get_iter
;
397 iface
->get_path
= wxgtk_tree_model_get_path
;
398 iface
->get_value
= wxgtk_tree_model_get_value
;
399 iface
->iter_next
= wxgtk_tree_model_iter_next
;
400 iface
->iter_children
= wxgtk_tree_model_iter_children
;
401 iface
->iter_has_child
= wxgtk_tree_model_iter_has_child
;
402 iface
->iter_n_children
= wxgtk_tree_model_iter_n_children
;
403 iface
->iter_nth_child
= wxgtk_tree_model_iter_nth_child
;
404 iface
->iter_parent
= wxgtk_tree_model_iter_parent
;
408 wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
)
410 iface
->get_sort_column_id
= wxgtk_tree_model_get_sort_column_id
;
411 iface
->set_sort_column_id
= wxgtk_tree_model_set_sort_column_id
;
412 iface
->set_sort_func
= wxgtk_tree_model_set_sort_func
;
413 iface
->set_default_sort_func
= wxgtk_tree_model_set_default_sort_func
;
414 iface
->has_default_sort_func
= wxgtk_tree_model_has_default_sort_func
;
418 wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
)
420 tree_model
->internal
= NULL
;
421 tree_model
->stamp
= g_random_int();
425 wxgtk_tree_model_finalize (GObject
*object
)
428 (* list_parent_class
->finalize
) (object
);
433 //-----------------------------------------------------------------------------
434 // implement callbacks from wxGtkTreeModel class by letting
435 // them call the methods of wxWidgets' wxDataViewModel
436 //-----------------------------------------------------------------------------
438 static GtkTreeModelFlags
439 wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
)
441 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (tree_model
), (GtkTreeModelFlags
)0 );
443 return GTK_TREE_MODEL_ITERS_PERSIST
;
447 wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
)
449 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
450 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
452 return wxtree_model
->internal
->GetDataViewModel()->GetColumnCount();
456 wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
459 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
460 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), G_TYPE_INVALID
);
462 GType gtype
= G_TYPE_INVALID
;
464 wxString wxtype
= wxtree_model
->internal
->GetDataViewModel()->GetColumnType( (unsigned int) index
);
466 if (wxtype
== wxT("string"))
467 gtype
= G_TYPE_STRING
;
470 wxFAIL_MSG( _T("non-string columns not supported yet") );
477 wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
481 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
482 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
483 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
485 return wxtree_model
->internal
->get_iter( iter
, path
);
489 wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
492 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
493 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), NULL
);
494 g_return_val_if_fail (iter
->stamp
== GTK_WX_TREE_MODEL (wxtree_model
)->stamp
, NULL
);
496 return wxtree_model
->internal
->get_path( iter
);
500 wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
505 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
506 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
) );
508 wxDataViewModel
*model
= wxtree_model
->internal
->GetDataViewModel();
509 wxString mtype
= model
->GetColumnType( (unsigned int) column
);
510 if (mtype
== wxT("string"))
513 g_value_init( value
, G_TYPE_STRING
);
514 wxDataViewItem
item( (void*) iter
->user_data
);
515 model
->GetValue( variant
, item
, (unsigned int) column
);
517 g_value_set_string( value
, variant
.GetString().utf8_str() );
521 wxFAIL_MSG( _T("non-string columns not supported yet") );
526 wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
529 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
530 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
531 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
533 return wxtree_model
->internal
->iter_next( iter
);
537 wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
541 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
542 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
543 g_return_val_if_fail (wxtree_model
->stamp
== parent
->stamp
, FALSE
);
545 return wxtree_model
->internal
->iter_children( iter
, parent
);
549 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
552 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
553 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
554 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
556 return wxtree_model
->internal
->iter_has_child( iter
);
560 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
563 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
564 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
565 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, 0);
567 return wxtree_model
->internal
->iter_n_children( iter
);
571 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
576 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
577 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
579 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
583 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
587 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
588 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
589 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
591 return wxtree_model
->internal
->iter_parent( iter
, child
);
595 gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
596 gint
*sort_column_id
,
599 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
601 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
603 if (!tree_model
->internal
->IsSorted())
606 *sort_column_id
= -1;
613 *sort_column_id
= tree_model
->internal
->GetSortColumn();
616 *order
= tree_model
->internal
->GetSortOrder();
621 wxDataViewColumn
*gs_lastLeftClickHeader
= NULL
;
623 void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
627 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
628 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
630 tree_model
->internal
->SetDataViewSortColumn( gs_lastLeftClickHeader
);
632 if ((sort_column_id
!= (gint
) tree_model
->internal
->GetSortColumn()) ||
633 (order
!= tree_model
->internal
->GetSortOrder()))
635 tree_model
->internal
->SetSortColumn( sort_column_id
);
636 tree_model
->internal
->SetSortOrder( order
);
638 gtk_tree_sortable_sort_column_changed (sortable
);
640 tree_model
->internal
->GetDataViewModel()->Resort();
643 if (gs_lastLeftClickHeader
)
645 wxDataViewCtrl
*dv
= tree_model
->internal
->GetOwner();
646 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, dv
->GetId() );
647 event
.SetDataViewColumn( gs_lastLeftClickHeader
);
648 event
.SetModel( dv
->GetModel() );
649 dv
->GetEventHandler()->ProcessEvent( event
);
652 gs_lastLeftClickHeader
= NULL
;
655 void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
657 GtkTreeIterCompareFunc func
,
659 GtkDestroyNotify destroy
)
661 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
662 g_return_if_fail (func
!= NULL
);
665 void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
666 GtkTreeIterCompareFunc func
,
668 GtkDestroyNotify destroy
)
670 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
671 g_return_if_fail (func
!= NULL
);
673 wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
676 gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
)
681 //-----------------------------------------------------------------------------
682 // define new GTK+ class wxGtkRendererRenderer
683 //-----------------------------------------------------------------------------
687 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
688 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
689 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
690 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
691 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
692 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
694 GType
gtk_wx_cell_renderer_get_type (void);
696 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
697 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
699 struct _GtkWxCellRenderer
701 GtkCellRenderer parent
;
704 wxDataViewCustomRenderer
*cell
;
708 struct _GtkWxCellRendererClass
710 GtkCellRendererClass cell_parent_class
;
714 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
715 static void gtk_wx_cell_renderer_init (
716 GtkWxCellRenderer
*cell
);
717 static void gtk_wx_cell_renderer_class_init(
718 GtkWxCellRendererClass
*klass
);
719 static void gtk_wx_cell_renderer_finalize (
721 static void gtk_wx_cell_renderer_get_size (
722 GtkCellRenderer
*cell
,
724 GdkRectangle
*rectangle
,
729 static void gtk_wx_cell_renderer_render (
730 GtkCellRenderer
*cell
,
733 GdkRectangle
*background_area
,
734 GdkRectangle
*cell_area
,
735 GdkRectangle
*expose_area
,
736 GtkCellRendererState flags
);
737 static gboolean
gtk_wx_cell_renderer_activate(
738 GtkCellRenderer
*cell
,
742 GdkRectangle
*background_area
,
743 GdkRectangle
*cell_area
,
744 GtkCellRendererState flags
);
745 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
746 GtkCellRenderer
*cell
,
750 GdkRectangle
*background_area
,
751 GdkRectangle
*cell_area
,
752 GtkCellRendererState flags
);
755 static GObjectClass
*cell_parent_class
= NULL
;
760 gtk_wx_cell_renderer_get_type (void)
762 static GType cell_wx_type
= 0;
766 const GTypeInfo cell_wx_info
=
768 sizeof (GtkWxCellRendererClass
),
769 NULL
, /* base_init */
770 NULL
, /* base_finalize */
771 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
772 NULL
, /* class_finalize */
773 NULL
, /* class_data */
774 sizeof (GtkWxCellRenderer
),
776 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
779 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
780 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
787 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
790 cell
->last_click
= 0;
794 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
796 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
797 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
799 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
801 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
803 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
804 cell_class
->render
= gtk_wx_cell_renderer_render
;
805 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
806 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
810 gtk_wx_cell_renderer_finalize (GObject
*object
)
813 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
817 gtk_wx_cell_renderer_new (void)
819 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
824 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
825 GtkCellRenderer
*renderer
,
829 GdkRectangle
*background_area
,
830 GdkRectangle
*cell_area
,
831 GtkCellRendererState flags
)
833 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
834 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
835 if (!cell
->HasEditorCtrl())
839 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
845 rect
.x
+= cell_area
->x
;
846 rect
.y
+= cell_area
->y
;
847 // rect.width -= renderer->xpad * 2;
848 // rect.height -= renderer->ypad * 2;
850 // wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
851 wxRect
renderrect( cell_area
->x
, cell_area
->y
, cell_area
->width
, cell_area
->height
);
853 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
855 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
856 wxDataViewItem
item( (void*) iter
.user_data
);
857 gtk_tree_path_free( treepath
);
859 cell
->StartEditing( item
, renderrect
);
865 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
867 GdkRectangle
*cell_area
,
873 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
874 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
876 wxSize size
= cell
->GetSize();
878 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
879 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
886 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
890 *x_offset
= (gint
)((renderer
->xalign
*
891 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
892 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
896 *y_offset
= (gint
)((renderer
->yalign
*
897 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
898 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
906 *height
= calc_height
;
910 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
913 GdkRectangle
*background_area
,
914 GdkRectangle
*cell_area
,
915 GdkRectangle
*expose_area
,
916 GtkCellRendererState flags
)
919 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
920 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
923 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
929 rect
.x
+= cell_area
->x
;
930 rect
.y
+= cell_area
->y
;
931 rect
.width
-= renderer
->xpad
* 2;
932 rect
.height
-= renderer
->ypad
* 2;
935 if (gdk_rectangle_intersect (expose_area
, &rect
, &dummy
))
937 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
938 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
939 if (dc
->m_window
== NULL
)
941 dc
->m_window
= window
;
946 if (flags
& GTK_CELL_RENDERER_SELECTED
)
947 state
|= wxDATAVIEW_CELL_SELECTED
;
948 if (flags
& GTK_CELL_RENDERER_PRELIT
)
949 state
|= wxDATAVIEW_CELL_PRELIT
;
950 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
951 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
952 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
953 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
954 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
955 state
|= wxDATAVIEW_CELL_FOCUSED
;
956 cell
->Render( renderrect
, dc
, state
);
961 gtk_wx_cell_renderer_activate(
962 GtkCellRenderer
*renderer
,
966 GdkRectangle
*background_area
,
967 GdkRectangle
*cell_area
,
968 GtkCellRendererState flags
)
970 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
971 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
974 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
980 rect
.x
+= cell_area
->x
;
981 rect
.y
+= cell_area
->y
;
982 rect
.width
-= renderer
->xpad
* 2;
983 rect
.height
-= renderer
->ypad
* 2;
985 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
987 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
989 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
992 gtk_tree_path_free( treepath
);
994 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1000 // activated by <ENTER>
1001 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1006 else if (event
->type
== GDK_BUTTON_PRESS
)
1008 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
1009 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
1010 ((int) button_event
->y
) - renderrect
.y
);
1013 if (button_event
->button
== 1)
1015 if (cell
->LeftClick( pt
, renderrect
, model
, item
, model_col
))
1017 // TODO: query system double-click time
1018 if (button_event
->time
- wxrenderer
->last_click
< 400)
1019 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1022 if (button_event
->button
== 3)
1024 if (cell
->RightClick( pt
, renderrect
, model
, item
, model_col
))
1028 wxrenderer
->last_click
= button_event
->time
;
1036 // ---------------------------------------------------------
1037 // wxGtkDataViewModelNotifier
1038 // ---------------------------------------------------------
1040 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1043 wxGtkDataViewModelNotifier( GtkWxTreeModel
*wxgtk_model
,
1044 wxDataViewModel
*wx_model
,
1045 wxDataViewCtrl
*ctrl
);
1046 ~wxGtkDataViewModelNotifier();
1048 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1049 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1050 virtual bool ItemChanged( const wxDataViewItem
&item
);
1051 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
1052 virtual bool Cleared();
1053 virtual void Resort();
1055 GtkWxTreeModel
*m_wxgtk_model
;
1056 wxDataViewModel
*m_wx_model
;
1057 wxDataViewCtrl
*m_owner
;
1060 // ---------------------------------------------------------
1061 // wxGtkDataViewListModelNotifier
1062 // ---------------------------------------------------------
1064 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1065 GtkWxTreeModel
* wxgtk_model
, wxDataViewModel
*wx_model
,
1066 wxDataViewCtrl
*ctrl
)
1068 m_wxgtk_model
= wxgtk_model
;
1069 m_wx_model
= wx_model
;
1073 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1076 m_wxgtk_model
= NULL
;
1079 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1081 m_owner
->GtkGetInternal()->ItemAdded( parent
, item
);
1084 iter
.stamp
= m_wxgtk_model
->stamp
;
1085 iter
.user_data
= (gpointer
) item
.GetID();
1087 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1088 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1089 gtk_tree_model_row_inserted(
1090 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1091 gtk_tree_path_free (path
);
1096 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1099 iter
.stamp
= m_wxgtk_model
->stamp
;
1100 iter
.user_data
= (gpointer
) item
.GetID();
1102 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1103 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1104 gtk_tree_model_row_deleted(
1105 GTK_TREE_MODEL(m_wxgtk_model
), path
);
1106 gtk_tree_path_free (path
);
1108 m_owner
->GtkGetInternal()->ItemDeleted( parent
, item
);
1113 void wxGtkDataViewModelNotifier::Resort()
1115 m_owner
->GtkGetInternal()->Resort();
1118 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1121 iter
.stamp
= m_wxgtk_model
->stamp
;
1122 iter
.user_data
= (gpointer
) item
.GetID();
1124 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1125 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1126 gtk_tree_model_row_changed(
1127 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1128 gtk_tree_path_free (path
);
1130 m_owner
->GtkGetInternal()->ItemChanged( item
);
1135 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_col
)
1137 // This adds GTK+'s missing MVC logic for ValueChanged
1139 for (index
= 0; index
< m_owner
->GetColumnCount(); index
++)
1141 wxDataViewColumn
*column
= m_owner
->GetColumn( index
);
1142 if (column
->GetModelColumn() == model_col
)
1144 GtkTreeView
*widget
= GTK_TREE_VIEW(m_owner
->m_treeview
);
1145 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1149 iter
.stamp
= m_wxgtk_model
->stamp
;
1150 iter
.user_data
= (gpointer
) item
.GetID();
1151 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1152 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1153 GdkRectangle cell_area
;
1154 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1155 gtk_tree_path_free( path
);
1157 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1158 double d
= gtk_adjustment_get_value( hadjust
);
1159 int xdiff
= (int) d
;
1161 int ydiff
= gcolumn
->button
->allocation
.height
;
1163 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1164 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1166 m_owner
->GtkGetInternal()->ValueChanged( item
, model_col
);
1175 bool wxGtkDataViewModelNotifier::Cleared()
1177 // TODO: delete everything
1179 m_owner
->GtkGetInternal()->Cleared();
1184 // ---------------------------------------------------------
1185 // wxDataViewRenderer
1186 // ---------------------------------------------------------
1188 static gpointer s_user_data
= NULL
;
1191 wxgtk_cell_editable_editing_done( GtkCellEditable
*editable
,
1192 wxDataViewRenderer
*wxrenderer
)
1194 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1195 wxDataViewCtrl
*dv
= column
->GetOwner();
1196 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1197 event
.SetDataViewColumn( column
);
1198 event
.SetModel( dv
->GetModel() );
1199 wxDataViewItem
item( s_user_data
);
1200 event
.SetItem( item
);
1201 dv
->GetEventHandler()->ProcessEvent( event
);
1205 wxgtk_renderer_editing_started( GtkCellRenderer
*cell
, GtkCellEditable
*editable
,
1206 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1208 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1209 wxDataViewCtrl
*dv
= column
->GetOwner();
1210 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1211 event
.SetDataViewColumn( column
);
1212 event
.SetModel( dv
->GetModel() );
1213 GtkTreePath
*tree_path
= gtk_tree_path_new_from_string( path
);
1215 dv
->GtkGetInternal()->get_iter( &iter
, tree_path
);
1216 gtk_tree_path_free( tree_path
);
1217 wxDataViewItem
item( iter
.user_data
);
1218 event
.SetItem( item
);
1219 dv
->GetEventHandler()->ProcessEvent( event
);
1221 if (GTK_IS_CELL_EDITABLE(editable
))
1223 s_user_data
= iter
.user_data
;
1225 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1226 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1227 (gpointer
) wxrenderer
);
1233 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1235 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1237 wxDataViewRendererBase( varianttype
, mode
, align
)
1241 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1242 // after the m_renderer pointer has been initialized
1245 void wxDataViewRenderer::GtkInitHandlers()
1247 if (!gtk_check_version(2,6,0))
1249 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1250 G_CALLBACK (wxgtk_renderer_editing_started
),
1255 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1257 GtkCellRendererMode gtkMode
;
1260 case wxDATAVIEW_CELL_INERT
:
1261 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1263 case wxDATAVIEW_CELL_ACTIVATABLE
:
1264 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1266 case wxDATAVIEW_CELL_EDITABLE
:
1267 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1271 // This value is most often ignored in GtkTreeView
1272 GValue gvalue
= { 0, };
1273 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1274 g_value_set_enum( &gvalue
, gtkMode
);
1275 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1276 g_value_unset( &gvalue
);
1279 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1281 wxDataViewCellMode ret
;
1284 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1286 switch (g_value_get_enum(&gvalue
))
1288 case GTK_CELL_RENDERER_MODE_INERT
:
1289 ret
= wxDATAVIEW_CELL_INERT
;
1291 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1292 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1294 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1295 ret
= wxDATAVIEW_CELL_EDITABLE
;
1299 g_value_unset( &gvalue
);
1304 void wxDataViewRenderer::SetAlignment( int align
)
1306 // horizontal alignment:
1308 gfloat xalign
= 0.0;
1309 if (align
& wxALIGN_RIGHT
)
1311 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1314 GValue gvalue
= { 0, };
1315 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1316 g_value_set_float( &gvalue
, xalign
);
1317 g_object_set_property( G_OBJECT(m_renderer
), "xalign", &gvalue
);
1318 g_value_unset( &gvalue
);
1320 // vertical alignment:
1322 gfloat yalign
= 0.0;
1323 if (align
& wxALIGN_BOTTOM
)
1325 else if (align
& wxALIGN_CENTER_VERTICAL
)
1328 GValue gvalue2
= { 0, };
1329 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1330 g_value_set_float( &gvalue2
, yalign
);
1331 g_object_set_property( G_OBJECT(m_renderer
), "yalign", &gvalue2
);
1332 g_value_unset( &gvalue2
);
1335 int wxDataViewRenderer::GetAlignment() const
1340 // horizontal alignment:
1342 g_object_get( G_OBJECT(m_renderer
), "xalign", &gvalue
, NULL
);
1343 float xalign
= g_value_get_float( &gvalue
);
1345 ret
|= wxALIGN_LEFT
;
1346 else if (xalign
== 0.5)
1347 ret
|= wxALIGN_CENTER_HORIZONTAL
;
1349 ret
|= wxALIGN_RIGHT
;
1350 g_value_unset( &gvalue
);
1353 // vertical alignment:
1355 g_object_get( G_OBJECT(m_renderer
), "yalign", &gvalue
, NULL
);
1356 float yalign
= g_value_get_float( &gvalue
);
1359 else if (yalign
== 0.5)
1360 ret
|= wxALIGN_CENTER_VERTICAL
;
1362 ret
|= wxALIGN_BOTTOM
;
1363 g_value_unset( &gvalue
);
1370 // ---------------------------------------------------------
1371 // wxDataViewTextRenderer
1372 // ---------------------------------------------------------
1375 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1376 gchar
*arg1
, gchar
*arg2
, gpointer user_data
);
1379 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1380 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1382 wxDataViewTextRenderer
*cell
= (wxDataViewTextRenderer
*) user_data
;
1384 wxString tmp
= wxGTK_CONV_BACK_FONT(arg2
, cell
->GetOwner()->GetOwner()->GetFont());
1385 wxVariant value
= tmp
;
1386 if (!cell
->Validate( value
))
1389 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1391 GtkTreePath
*path
= gtk_tree_path_new_from_string( arg1
);
1393 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, path
);
1394 wxDataViewItem
item( (void*) iter
.user_data
);;
1395 gtk_tree_path_free( path
);
1397 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1399 model
->SetValue( value
, item
, model_col
);
1400 model
->ValueChanged( item
, model_col
);
1403 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
1405 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1407 wxDataViewRenderer( varianttype
, mode
, align
)
1409 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_text_new();
1411 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
1413 GValue gvalue
= { 0, };
1414 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1415 g_value_set_boolean( &gvalue
, true );
1416 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
1417 g_value_unset( &gvalue
);
1419 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
1425 SetAlignment(align
);
1428 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
1430 wxString tmp
= value
;
1432 GValue gvalue
= { 0, };
1433 g_value_init( &gvalue
, G_TYPE_STRING
);
1434 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( tmp
, GetOwner()->GetOwner()->GetFont() ) );
1435 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1436 g_value_unset( &gvalue
);
1441 bool wxDataViewTextRenderer::GetValue( wxVariant
&value
) const
1443 GValue gvalue
= { 0, };
1444 g_value_init( &gvalue
, G_TYPE_STRING
);
1445 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1446 wxString tmp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
),
1447 wx_const_cast(wxDataViewTextRenderer
*, this)->GetOwner()->GetOwner()->GetFont() );
1448 g_value_unset( &gvalue
);
1455 void wxDataViewTextRenderer::SetAlignment( int align
)
1457 wxDataViewRenderer::SetAlignment(align
);
1459 if (gtk_check_version(2,10,0))
1462 // horizontal alignment:
1463 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
1464 if (align
& wxALIGN_RIGHT
)
1465 pangoAlign
= PANGO_ALIGN_RIGHT
;
1466 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1467 pangoAlign
= PANGO_ALIGN_CENTER
;
1469 GValue gvalue
= { 0, };
1470 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1471 g_value_set_enum( &gvalue
, pangoAlign
);
1472 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
1473 g_value_unset( &gvalue
);
1476 // ---------------------------------------------------------
1477 // wxDataViewBitmapRenderer
1478 // ---------------------------------------------------------
1480 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
1482 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1484 wxDataViewRenderer( varianttype
, mode
, align
)
1486 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_pixbuf_new();
1489 SetAlignment(align
);
1492 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
1494 if (value
.GetType() == wxT("wxBitmap"))
1499 // This may create a Pixbuf representation in the
1500 // wxBitmap object (and it will stay there)
1501 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1503 GValue gvalue
= { 0, };
1504 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1505 g_value_set_object( &gvalue
, pixbuf
);
1506 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1507 g_value_unset( &gvalue
);
1512 if (value
.GetType() == wxT("wxIcon"))
1517 // This may create a Pixbuf representation in the
1518 // wxBitmap object (and it will stay there)
1519 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1521 GValue gvalue
= { 0, };
1522 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1523 g_value_set_object( &gvalue
, pixbuf
);
1524 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1525 g_value_unset( &gvalue
);
1533 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&value
) const
1538 // ---------------------------------------------------------
1539 // wxDataViewToggleRenderer
1540 // ---------------------------------------------------------
1543 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1544 gchar
*path
, gpointer user_data
);
1547 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1548 gchar
*path
, gpointer user_data
)
1550 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
1553 GValue gvalue
= { 0, };
1554 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1555 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
1556 bool tmp
= g_value_get_boolean( &gvalue
);
1557 g_value_unset( &gvalue
);
1561 wxVariant value
= tmp
;
1562 if (!cell
->Validate( value
))
1565 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1567 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
1569 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, gtk_path
);
1570 wxDataViewItem
item( (void*) iter
.user_data
);;
1571 gtk_tree_path_free( gtk_path
);
1573 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1575 model
->SetValue( value
, item
, model_col
);
1576 model
->ValueChanged( item
, model_col
);
1579 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1581 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1582 wxDataViewCellMode mode
, int align
) :
1583 wxDataViewRenderer( varianttype
, mode
, align
)
1585 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
1587 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1589 g_signal_connect_after( m_renderer
, "toggled",
1590 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
1594 GValue gvalue
= { 0, };
1595 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1596 g_value_set_boolean( &gvalue
, false );
1597 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
1598 g_value_unset( &gvalue
);
1602 SetAlignment(align
);
1605 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1609 GValue gvalue
= { 0, };
1610 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1611 g_value_set_boolean( &gvalue
, tmp
);
1612 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1613 g_value_unset( &gvalue
);
1618 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
1620 GValue gvalue
= { 0, };
1621 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1622 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1623 bool tmp
= g_value_get_boolean( &gvalue
);
1624 g_value_unset( &gvalue
);
1631 // ---------------------------------------------------------
1632 // wxDataViewCustomRenderer
1633 // ---------------------------------------------------------
1635 class wxDataViewCtrlDC
: public wxWindowDC
1638 wxDataViewCtrlDC( wxDataViewCtrl
*window
)
1640 GtkWidget
*widget
= window
->m_treeview
;
1644 m_context
= window
->GtkGetPangoDefaultContext();
1645 m_layout
= pango_layout_new( m_context
);
1646 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
1648 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
1650 // Set m_window later
1652 // m_owner = window;
1656 // ---------------------------------------------------------
1657 // wxDataViewCustomRenderer
1658 // ---------------------------------------------------------
1660 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
1662 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
1663 wxDataViewCellMode mode
, int align
,
1665 wxDataViewRenderer( varianttype
, mode
, align
)
1675 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
1677 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
1678 renderer
->cell
= this;
1680 m_renderer
= (GtkCellRenderer
*) renderer
;
1683 SetAlignment(align
);
1690 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
1696 wxDC
*wxDataViewCustomRenderer::GetDC()
1700 if (GetOwner() == NULL
)
1702 if (GetOwner()->GetOwner() == NULL
)
1704 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
1710 // ---------------------------------------------------------
1711 // wxDataViewProgressRenderer
1712 // ---------------------------------------------------------
1714 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
1716 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
1717 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1718 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
1724 if (!gtk_check_version(2,6,0))
1726 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
1728 GValue gvalue
= { 0, };
1729 g_value_init( &gvalue
, G_TYPE_STRING
);
1731 // FIXME: font encoding support
1732 g_value_set_string( &gvalue
, wxGTK_CONV_SYS(m_label
) );
1733 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1734 g_value_unset( &gvalue
);
1737 SetAlignment(align
);
1742 // Use custom cell code
1743 wxDataViewCustomRenderer::Init(mode
, align
);
1747 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
1751 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
1754 if (!gtk_check_version(2,6,0))
1756 gint tmp
= (long) value
;
1757 GValue gvalue
= { 0, };
1758 g_value_init( &gvalue
, G_TYPE_INT
);
1759 g_value_set_int( &gvalue
, tmp
);
1760 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
1761 g_value_unset( &gvalue
);
1766 m_value
= (long) value
;
1768 if (m_value
< 0) m_value
= 0;
1769 if (m_value
> 100) m_value
= 100;
1775 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
1780 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1782 double pct
= (double)m_value
/ 100.0;
1784 bar
.width
= (int)(cell
.width
* pct
);
1785 dc
->SetPen( *wxTRANSPARENT_PEN
);
1786 dc
->SetBrush( *wxBLUE_BRUSH
);
1787 dc
->DrawRectangle( bar
);
1789 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1790 dc
->SetPen( *wxBLACK_PEN
);
1791 dc
->DrawRectangle( cell
);
1796 wxSize
wxDataViewProgressRenderer::GetSize() const
1798 return wxSize(40,12);
1801 // ---------------------------------------------------------
1802 // wxDataViewDateRenderer
1803 // ---------------------------------------------------------
1805 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
1808 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
1809 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
1810 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
1815 m_cal
= new wxCalendarCtrl( this, -1, *value
);
1816 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
1817 sizer
->Add( m_cal
, 1, wxGROW
);
1822 virtual void OnDismiss()
1826 void OnCalendar( wxCalendarEvent
&event
);
1828 wxCalendarCtrl
*m_cal
;
1829 wxDataViewModel
*m_model
;
1830 wxDataViewItem m_item
;
1834 DECLARE_EVENT_TABLE()
1837 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
1838 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
1841 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
1843 wxDateTime date
= event
.GetDate();
1844 wxVariant value
= date
;
1845 m_model
->SetValue( value
, m_item
, m_col
);
1846 m_model
->ValueChanged( m_item
, m_col
);
1850 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
1852 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1853 wxDataViewCellMode mode
, int align
) :
1854 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1857 SetAlignment(align
);
1860 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1862 m_date
= value
.GetDateTime();
1867 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
1872 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1874 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
1875 wxString tmp
= m_date
.FormatDate();
1876 dc
->DrawText( tmp
, cell
.x
, cell
.y
);
1881 wxSize
wxDataViewDateRenderer::GetSize() const
1883 wxString tmp
= m_date
.FormatDate();
1885 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
1886 return wxSize(x
,y
+d
);
1889 bool wxDataViewDateRenderer::Activate( wxRect cell
, wxDataViewModel
*model
,
1890 const wxDataViewItem
&item
, unsigned int col
)
1893 model
->GetValue( variant
, item
, col
);
1894 wxDateTime value
= variant
.GetDateTime();
1896 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1897 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
1898 wxPoint pos
= wxGetMousePosition();
1901 popup
->Popup( popup
->m_cal
);
1907 // ---------------------------------------------------------
1908 // wxDataViewIconTextRenderer
1909 // ---------------------------------------------------------
1911 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
1913 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
1914 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1915 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1918 SetAlignment(align
);
1921 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
1925 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
1931 bool wxDataViewIconTextRenderer::GetValue( wxVariant
&value
) const
1936 bool wxDataViewIconTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1938 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
1940 const wxIcon
&icon
= m_value
.GetIcon();
1943 dc
->DrawIcon( icon
, cell
.x
, cell
.y
); // TODO centre
1944 cell
.x
+= icon
.GetWidth()+4;
1947 dc
->DrawText( m_value
.GetText(), cell
.x
, cell
.y
);
1952 wxSize
wxDataViewIconTextRenderer::GetSize() const
1954 return wxSize(80,16); // TODO
1957 wxControl
* wxDataViewIconTextRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1962 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1967 // ---------------------------------------------------------
1969 // ---------------------------------------------------------
1973 gtk_dataview_header_button_press_callback( GtkWidget
*widget
,
1974 GdkEventButton
*gdk_event
,
1975 wxDataViewColumn
*column
)
1977 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
1980 if (gdk_event
->button
== 1)
1982 gs_lastLeftClickHeader
= column
;
1984 wxDataViewCtrl
*dv
= column
->GetOwner();
1985 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
1986 event
.SetDataViewColumn( column
);
1987 event
.SetModel( dv
->GetModel() );
1988 if (dv
->GetEventHandler()->ProcessEvent( event
))
1992 if (gdk_event
->button
== 3)
1994 wxDataViewCtrl
*dv
= column
->GetOwner();
1995 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
1996 event
.SetDataViewColumn( column
);
1997 event
.SetModel( dv
->GetModel() );
1998 if (dv
->GetEventHandler()->ProcessEvent( event
))
2006 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
2007 GtkCellRenderer
*cell
,
2008 GtkTreeModel
*model
,
2014 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
2015 GtkCellRenderer
*renderer
,
2016 GtkTreeModel
*model
,
2020 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2021 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2023 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2025 wxDataViewItem
item( (void*) iter
->user_data
);
2028 tree_model
->internal
->GetDataViewModel()->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
2030 if (value
.GetType() != cell
->GetVariantType())
2031 wxLogError( wxT("Wrong type, required: %s but: %s"),
2032 value
.GetType().c_str(),
2033 cell
->GetVariantType().c_str() );
2035 cell
->SetValue( value
);
2038 wxListItemAttr attr
;
2039 tree_model
->model
->GetAttr( attr
, cell
->GetOwner()->GetModelColumn(), model_row
);
2041 if (attr
.HasBackgroundColour())
2043 wxColour colour
= attr
.GetBackgroundColour();
2044 const GdkColor
* const gcol
= colour
.GetColor();
2046 GValue gvalue
= { 0, };
2047 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2048 g_value_set_boxed( &gvalue
, gcol
);
2049 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
2050 g_value_unset( &gvalue
);
2054 GValue gvalue
= { 0, };
2055 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2056 g_value_set_boolean( &gvalue
, FALSE
);
2057 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
2058 g_value_unset( &gvalue
);
2064 IMPLEMENT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
2066 #include <wx/listimpl.cpp>
2067 WX_DEFINE_LIST(wxDataViewColumnList
);
2069 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
2070 unsigned int model_column
, int width
,
2071 wxAlignment align
, int flags
) :
2072 wxDataViewColumnBase( title
, cell
, model_column
, width
, align
, flags
)
2074 Init( align
, flags
, width
);
2076 gtk_tree_view_column_set_clickable( GTK_TREE_VIEW_COLUMN(m_column
), TRUE
);
2080 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
2081 unsigned int model_column
, int width
,
2082 wxAlignment align
, int flags
) :
2083 wxDataViewColumnBase( bitmap
, cell
, model_column
, width
, align
, flags
)
2085 Init( align
, flags
, width
);
2087 SetBitmap( bitmap
);
2090 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
2092 m_isConnected
= false;
2094 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) GetRenderer()->GetGtkHandle();
2095 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
2096 m_column
= (GtkWidget
*) column
;
2099 SetAlignment( align
);
2101 // NOTE: we prefer not to call SetMinWidth(wxDVC_DEFAULT_MINWIDTH);
2102 // as GTK+ is smart and unless explicitely told, will set the minimal
2103 // width to the title's lenght, which is a better default
2105 // the GTK_TREE_VIEW_COLUMN_FIXED is required by the "fixed height" mode
2106 // that we use for the wxDataViewCtrl
2107 gtk_tree_view_column_set_fixed_width( column
, width
< 0 ? wxDVC_DEFAULT_WIDTH
: width
);
2108 gtk_tree_view_column_set_sizing( column
, GTK_TREE_VIEW_COLUMN_FIXED
);
2110 gtk_tree_view_column_pack_end( column
, renderer
, TRUE
);
2112 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
2113 wxGtkTreeCellDataFunc
, (gpointer
) GetRenderer(), NULL
);
2116 wxDataViewColumn::~wxDataViewColumn()
2120 void wxDataViewColumn::OnInternalIdle()
2125 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
2127 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2130 g_signal_connect(column
->button
, "button_press_event",
2131 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
2133 m_isConnected
= true;
2138 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
2140 wxDataViewColumnBase::SetOwner( owner
);
2142 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2144 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
2147 void wxDataViewColumn::SetTitle( const wxString
&title
)
2149 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2153 // disconnect before column->button gets recreated
2154 g_signal_handlers_disconnect_by_func( column
->button
,
2155 (GtkWidget
*) gtk_dataview_header_button_press_callback
, this);
2157 m_isConnected
= false;
2160 // FIXME: can it really happen that we don't have the owner here??
2161 wxDataViewCtrl
*ctrl
= GetOwner();
2162 gtk_tree_view_column_set_title( column
, ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
2163 : wxGTK_CONV_SYS(title
) );
2165 gtk_tree_view_column_set_widget( column
, NULL
);
2168 wxString
wxDataViewColumn::GetTitle() const
2170 const gchar
*str
= gtk_tree_view_column_get_title( GTK_TREE_VIEW_COLUMN(m_column
) );
2171 return wxConvFileName
->cMB2WX(str
);
2174 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
2176 wxDataViewColumnBase::SetBitmap( bitmap
);
2178 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2181 GtkImage
*gtk_image
= GTK_IMAGE( gtk_image_new() );
2183 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
2184 if (bitmap
.GetMask())
2185 mask
= bitmap
.GetMask()->GetBitmap();
2187 if (bitmap
.HasPixbuf())
2189 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
2190 bitmap
.GetPixbuf());
2194 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
2195 bitmap
.GetPixmap(), mask
);
2197 gtk_widget_show( GTK_WIDGET(gtk_image
) );
2199 gtk_tree_view_column_set_widget( column
, GTK_WIDGET(gtk_image
) );
2203 gtk_tree_view_column_set_widget( column
, NULL
);
2207 void wxDataViewColumn::SetHidden( bool hidden
)
2209 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
2212 void wxDataViewColumn::SetResizeable( bool resizeable
)
2214 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizeable
);
2217 void wxDataViewColumn::SetAlignment( wxAlignment align
)
2219 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2221 gfloat xalign
= 0.0;
2222 if (align
== wxALIGN_RIGHT
)
2224 if (align
== wxALIGN_CENTER_HORIZONTAL
||
2225 align
== wxALIGN_CENTER
)
2228 gtk_tree_view_column_set_alignment( column
, xalign
);
2231 wxAlignment
wxDataViewColumn::GetAlignment() const
2233 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
2236 return wxALIGN_RIGHT
;
2238 return wxALIGN_CENTER_HORIZONTAL
;
2240 return wxALIGN_LEFT
;
2243 void wxDataViewColumn::SetSortable( bool sortable
)
2245 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2249 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
2253 gtk_tree_view_column_set_sort_column_id( column
, -1 );
2254 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
2258 bool wxDataViewColumn::IsSortable() const
2260 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2261 return (gtk_tree_view_column_get_sort_column_id( column
) != -1);
2264 bool wxDataViewColumn::IsResizeable() const
2266 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2267 return gtk_tree_view_column_get_resizable( column
);
2270 bool wxDataViewColumn::IsHidden() const
2272 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2273 return !gtk_tree_view_column_get_visible( column
);
2276 void wxDataViewColumn::SetSortOrder( bool ascending
)
2278 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2281 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
2283 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
2285 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
2288 bool wxDataViewColumn::IsSortOrderAscending() const
2290 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2292 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
2295 void wxDataViewColumn::SetMinWidth( int width
)
2297 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2300 int wxDataViewColumn::GetMinWidth() const
2302 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2305 int wxDataViewColumn::GetWidth() const
2307 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2310 void wxDataViewColumn::SetWidth( int width
)
2312 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2316 //-----------------------------------------------------------------------------
2317 // wxGtkTreeModelNode
2318 //-----------------------------------------------------------------------------
2320 void wxGtkTreeModelNode::Resort()
2322 size_t child_count
= GetChildCount();
2323 if (child_count
== 0)
2326 size_t node_count
= GetNodesCount();
2328 if (child_count
== 1)
2330 if (node_count
== 1)
2332 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
2338 wxGtkTreeModelChildren temp
;
2339 WX_APPEND_ARRAY( temp
, m_children
);
2341 g_internal
= m_internal
;
2342 m_children
.Sort( &wxGtkTreeModelChildCmp
);
2344 gint
*new_order
= new gint
[child_count
];
2347 for (pos
= 0; pos
< child_count
; pos
++)
2349 void *id
= m_children
.Item( pos
);
2350 int old_pos
= temp
.Index( id
);
2351 new_order
[pos
] = old_pos
;
2354 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
2357 iter
.user_data
= GetItem().GetID();
2358 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
2360 GtkTreePath
*path
= m_internal
->get_path( &iter
);
2362 gtk_tree_model_rows_reordered( gtk_tree_model
, path
, &iter
, new_order
);
2364 gtk_tree_path_free (path
);
2366 delete [] new_order
;
2368 for (pos
= 0; pos
< node_count
; pos
++)
2370 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
2375 //-----------------------------------------------------------------------------
2376 // wxDataViewCtrlInternal
2377 //-----------------------------------------------------------------------------
2379 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
,
2380 wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
)
2383 m_wx_model
= wx_model
;
2384 m_gtk_model
= gtk_model
;
2386 m_sort_order
= GTK_SORT_ASCENDING
;
2388 m_dataview_sort_column
= NULL
;
2392 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
2394 g_object_unref( m_gtk_model
);
2397 void wxDataViewCtrlInternal::InitTree()
2399 wxDataViewItem item
;
2400 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
2402 BuildBranch( m_root
);
2405 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
2407 if (node
->GetChildCount() == 0)
2409 wxDataViewItemArray children
;
2410 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
2412 for (pos
= 0; pos
< count
; pos
++)
2414 wxDataViewItem child
= children
[pos
];
2416 if (m_wx_model
->IsContainer( child
))
2417 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
2419 node
->AddLeave( child
.GetID() );
2421 // Don't send any events here
2426 void wxDataViewCtrlInternal::Resort()
2431 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
2433 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2434 if (m_wx_model
->IsContainer( item
))
2435 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
2437 parent_node
->AddLeave( item
.GetID() );
2439 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_ADDED
, m_owner
->GetId() );
2440 event
.SetEventObject( m_owner
);
2441 event
.SetModel( m_owner
->GetModel() );
2442 event
.SetItem( item
);
2443 m_owner
->GetEventHandler()->ProcessEvent( event
);
2448 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
2450 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2451 parent_node
->DeleteChild( item
.GetID() );
2453 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED
, m_owner
->GetId() );
2454 event
.SetEventObject( m_owner
);
2455 event
.SetModel( m_owner
->GetModel() );
2456 event
.SetItem( item
);
2457 m_owner
->GetEventHandler()->ProcessEvent( event
);
2462 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
2464 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_CHANGED
, m_owner
->GetId() );
2465 event
.SetEventObject( m_owner
);
2466 event
.SetModel( m_owner
->GetModel() );
2467 event
.SetItem( item
);
2468 m_owner
->GetEventHandler()->ProcessEvent( event
);
2473 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
2475 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED
, m_owner
->GetId() );
2476 event
.SetEventObject( m_owner
);
2477 event
.SetModel( m_owner
->GetModel() );
2478 event
.SetColumn( col
);
2479 event
.SetItem( item
);
2480 m_owner
->GetEventHandler()->ProcessEvent( event
);
2485 bool wxDataViewCtrlInternal::Cleared()
2487 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED
, m_owner
->GetId() );
2488 event
.SetEventObject( m_owner
);
2489 event
.SetModel( m_owner
->GetModel() );
2490 m_owner
->GetEventHandler()->ProcessEvent( event
);
2495 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
2497 int depth
= gtk_tree_path_get_depth( path
);
2499 wxGtkTreeModelNode
*node
= m_root
;
2502 for (i
= 0; i
< depth
; i
++)
2504 BuildBranch( node
);
2506 gint pos
= gtk_tree_path_get_indices (path
)[i
];
2507 if (pos
< 0) return FALSE
;
2508 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
2510 void* id
= node
->GetChildren().Item( (size_t) pos
);
2514 iter
->stamp
= m_gtk_model
->stamp
;
2515 iter
->user_data
= id
;
2519 size_t count
= node
->GetNodes().GetCount();
2521 for (pos2
= 0; pos2
< count
; pos2
++)
2523 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
2524 if (child_node
->GetItem().GetID() == id
)
2535 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
2537 GtkTreePath
*retval
= gtk_tree_path_new ();
2538 void *id
= iter
->user_data
;
2540 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
2543 int pos
= node
->GetChildren().Index( id
);
2545 gtk_tree_path_prepend_index( retval
, pos
);
2547 id
= node
->GetItem().GetID();
2548 node
= node
->GetParent();
2554 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
2556 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
2557 if( parent
== NULL
)
2560 int pos
= parent
->GetChildren().Index( iter
->user_data
);
2562 if (pos
== (int) parent
->GetChildCount()-1)
2565 iter
->stamp
= m_gtk_model
->stamp
;
2566 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
2571 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
2573 wxDataViewItem
item( (void*) parent
->user_data
);
2575 if (!m_wx_model
->IsContainer( item
))
2578 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2579 BuildBranch( parent_node
);
2581 if (parent_node
->GetChildCount() == 0)
2584 iter
->stamp
= m_gtk_model
->stamp
;
2585 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
2590 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
2592 wxDataViewItem
item( (void*) iter
->user_data
);
2593 bool is_container
= m_wx_model
->IsContainer( item
);
2598 wxGtkTreeModelNode
*node
= FindNode( iter
);
2599 BuildBranch( node
);
2601 return (node
->GetChildCount() > 0);
2604 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
2606 wxDataViewItem
item( (void*) iter
->user_data
);
2608 if (!m_wx_model
->IsContainer( item
))
2611 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
2612 BuildBranch( parent_node
);
2614 // wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() );
2616 return parent_node
->GetChildCount();
2619 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
2622 if (parent
) id
= (void*) parent
->user_data
;
2623 wxDataViewItem
item( id
);
2625 if (!m_wx_model
->IsContainer( item
))
2628 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2629 BuildBranch( parent_node
);
2631 // wxPrintf( "iter_nth_child %d\n", n );
2633 iter
->stamp
= m_gtk_model
->stamp
;
2634 iter
->user_data
= parent_node
->GetChildren().Item( n
);
2639 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
2641 wxGtkTreeModelNode
*node
= FindParentNode( child
);
2645 iter
->stamp
= m_gtk_model
->stamp
;
2646 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
2651 static wxGtkTreeModelNode
*
2652 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
2658 list
.DeleteContents( true );
2659 wxDataViewItem
it( item
);
2662 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
2663 list
.Insert( pItem
);
2664 it
= model
->GetParent( it
);
2667 wxGtkTreeModelNode
* node
= treeNode
;
2668 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
2670 if( node
&& node
->GetNodes().GetCount() != 0 )
2672 int len
= node
->GetNodes().GetCount();
2673 wxGtkTreeModelNodes nodes
= node
->GetNodes();
2675 for( ; j
< len
; j
++)
2677 if( nodes
[j
]->GetItem() == *(n
->GetData()))
2696 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
2701 wxDataViewItem
item( (void*) iter
->user_data
);
2705 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
2709 wxPrintf( "Not found %d\n", (int) iter
->user_data
);
2717 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
2722 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
2726 wxPrintf( "Not found %d\n", (int) item
.GetID() );
2734 static wxGtkTreeModelNode
*
2735 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
2741 list
.DeleteContents( true );
2745 wxDataViewItem
it( model
->GetParent( item
) );
2748 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
2749 list
.Insert( pItem
);
2750 it
= model
->GetParent( it
);
2753 wxGtkTreeModelNode
* node
= treeNode
;
2754 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
2756 if( node
&& node
->GetNodes().GetCount() != 0 )
2758 int len
= node
->GetNodes().GetCount();
2759 wxGtkTreeModelNodes nodes
= node
->GetNodes();
2761 for( ; j
< len
; j
++)
2763 if( nodes
[j
]->GetItem() == *(n
->GetData()))
2778 //Examine whether the node is item's parent node
2779 int len
= node
->GetChildCount();
2780 for( int i
= 0; i
< len
; i
++ )
2782 if( node
->GetChildren().Item( i
) == item
.GetID() )
2788 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
2793 wxDataViewItem
item( (void*) iter
->user_data
);
2797 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
2800 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
2805 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
2808 //-----------------------------------------------------------------------------
2809 // wxDataViewCtrl signal callbacks
2810 //-----------------------------------------------------------------------------
2813 wxdataview_selection_changed_callback( GtkTreeSelection
* selection
, wxDataViewCtrl
*dv
)
2815 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
2818 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
2819 event
.SetItem( dv
->GetSelection() );
2820 event
.SetModel( dv
->GetModel() );
2821 dv
->GetEventHandler()->ProcessEvent( event
);
2825 wxdataview_row_activated_callback( GtkTreeView
* treeview
, GtkTreePath
*path
,
2826 GtkTreeViewColumn
*column
, wxDataViewCtrl
*dv
)
2828 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
2831 dv
->GtkGetInternal()->get_iter( &iter
, path
);
2832 wxDataViewItem
item( (void*) iter
.user_data
);;
2833 event
.SetItem( item
);
2834 event
.SetModel( dv
->GetModel() );
2835 dv
->GetEventHandler()->ProcessEvent( event
);
2839 wxdataview_test_expand_row_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
2840 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
2842 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
2844 wxDataViewItem
item( (void*) iter
->user_data
);;
2845 event
.SetItem( item
);
2846 event
.SetModel( dv
->GetModel() );
2847 dv
->GetEventHandler()->ProcessEvent( event
);
2849 return !event
.IsAllowed();
2853 wxdataview_row_expanded_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
2854 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
2856 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
2858 wxDataViewItem
item( (void*) iter
->user_data
);;
2859 event
.SetItem( item
);
2860 event
.SetModel( dv
->GetModel() );
2861 dv
->GetEventHandler()->ProcessEvent( event
);
2865 wxdataview_test_collapse_row_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
2866 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
2868 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
2870 wxDataViewItem
item( (void*) iter
->user_data
);;
2871 event
.SetItem( item
);
2872 event
.SetModel( dv
->GetModel() );
2873 dv
->GetEventHandler()->ProcessEvent( event
);
2875 return !event
.IsAllowed();
2879 wxdataview_row_collapsed_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
2880 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
2882 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
2884 wxDataViewItem
item( (void*) iter
->user_data
);;
2885 event
.SetItem( item
);
2886 event
.SetModel( dv
->GetModel() );
2887 dv
->GetEventHandler()->ProcessEvent( event
);
2890 //-----------------------------------------------------------------------------
2892 //-----------------------------------------------------------------------------
2894 //-----------------------------------------------------------------------------
2895 // InsertChild for wxDataViewCtrl
2896 //-----------------------------------------------------------------------------
2898 static void wxInsertChildInDataViewCtrl( wxWindowGTK
* parent
, wxWindowGTK
* child
)
2900 wxDataViewCtrl
* dvc
= (wxDataViewCtrl
*) parent
;
2901 GtkWidget
*treeview
= dvc
->GtkGetTreeView();
2903 // Insert widget in GtkTreeView
2904 if (GTK_WIDGET_REALIZED(treeview
))
2905 gtk_widget_set_parent_window( child
->m_widget
,
2906 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
2907 gtk_widget_set_parent( child
->m_widget
, treeview
);
2911 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
2912 GtkAllocation
*alloc
,
2913 wxDataViewCtrl
*win
)
2915 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
2918 wxWindow
*child
= node
->GetData();
2921 gtk_widget_size_request( child
->m_widget
, &req
);
2923 GtkAllocation alloc
;
2924 alloc
.x
= child
->m_x
;
2925 alloc
.y
= child
->m_y
;
2926 alloc
.width
= child
->m_width
;
2927 alloc
.height
= child
->m_height
;
2928 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
2930 node
= node
->GetNext();
2936 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
2938 wxDataViewCtrl::~wxDataViewCtrl()
2941 GetModel()->RemoveNotifier( m_notifier
);
2943 // remove the model from the GtkTreeView before it gets destroyed by the
2944 // wxDataViewCtrlBase's dtor
2945 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), NULL
);
2950 void wxDataViewCtrl::Init()
2955 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
2956 const wxPoint
& pos
, const wxSize
& size
,
2957 long style
, const wxValidator
& validator
)
2961 if (!PreCreation( parent
, pos
, size
) ||
2962 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
2964 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
2968 m_insertCallback
= wxInsertChildInDataViewCtrl
;
2970 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
2972 GtkScrolledWindowSetBorder(m_widget
, style
);
2974 m_treeview
= gtk_tree_view_new();
2975 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
2977 g_signal_connect (m_treeview
, "size_allocate",
2978 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
2981 if (!gtk_check_version(2,6,0))
2982 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), TRUE
);
2985 if (style
& wxDV_MULTIPLE
)
2987 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
2988 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
2991 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
2994 if (!gtk_check_version(2,10,0))
2996 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
2998 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
2999 (style
& wxDV_VERT_RULES
) != 0)
3000 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
3001 else if (style
& wxDV_VERT_RULES
)
3002 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
3003 else if (style
& wxDV_HORIZ_RULES
)
3004 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
3006 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
3011 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_HORIZ_RULES
) != 0 );
3014 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
3015 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
3016 gtk_widget_show (m_treeview
);
3018 m_parent
->DoAddChild( this );
3022 GtkEnableSelectionEvents();
3024 g_signal_connect_after (m_treeview
, "row-activated",
3025 G_CALLBACK (wxdataview_row_activated_callback
), this);
3027 g_signal_connect (m_treeview
, "test-collapse-row",
3028 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
3030 g_signal_connect_after (m_treeview
, "row-collapsed",
3031 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
3033 g_signal_connect (m_treeview
, "test-expand-row",
3034 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
3036 g_signal_connect_after (m_treeview
, "row-expanded",
3037 G_CALLBACK (wxdataview_row_expanded_callback
), this);
3042 void wxDataViewCtrl::OnInternalIdle()
3044 wxWindow::OnInternalIdle();
3046 unsigned int cols
= GetColumnCount();
3048 for (i
= 0; i
< cols
; i
++)
3050 wxDataViewColumn
*col
= GetColumn( i
);
3051 col
->OnInternalIdle();
3055 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
3057 if (!wxDataViewCtrlBase::AssociateModel( model
))
3060 GtkWxTreeModel
*gtk_model
= wxgtk_tree_model_new();
3061 m_internal
= new wxDataViewCtrlInternal( this, model
, gtk_model
);
3062 gtk_model
->internal
= m_internal
;
3064 m_notifier
= new wxGtkDataViewModelNotifier( gtk_model
, model
, this );
3066 model
->AddNotifier( m_notifier
);
3068 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_model
) );
3070 // unref in wxDataViewCtrlInternal
3071 // g_object_unref( gtk_model );
3076 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
3078 if (!wxDataViewCtrlBase::AppendColumn(col
))
3081 m_cols
.Append( col
);
3083 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
3084 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
3089 unsigned int wxDataViewCtrl::GetColumnCount() const
3091 return m_cols
.GetCount();
3094 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
3096 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
3100 wxDataViewColumnList::const_iterator iter
;
3101 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); iter
++)
3103 wxDataViewColumn
*col
= *iter
;
3104 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
3113 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
3115 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
3116 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
3118 m_cols
.remove( column
);
3125 bool wxDataViewCtrl::ClearColumns()
3127 wxDataViewColumnList::iterator iter
;
3128 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); iter
++)
3130 wxDataViewColumn
*col
= *iter
;
3131 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
3132 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
3140 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
3142 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetConstGtkHandle());
3144 GList
*list
= gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview
) );
3146 gint pos
= g_list_index( list
, (gconstpointer
) gtk_column
);
3148 g_list_free( list
);
3153 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
3155 return m_internal
->GetDataViewSortColumn();
3158 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
3161 iter
.user_data
= item
.GetID();
3162 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3163 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
3164 gtk_tree_path_free( path
);
3167 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
3170 iter
.user_data
= item
.GetID();
3171 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3172 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
3173 gtk_tree_path_free( path
);
3176 wxDataViewItem
wxDataViewCtrl::GetSelection() const
3178 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3180 if (m_windowStyle
& wxDV_MULTIPLE
)
3182 // Report the first one
3183 GtkTreeModel
*model
;
3184 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
3188 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
3190 m_internal
->get_iter( &iter
, path
);
3193 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
3194 g_list_free( list
);
3196 return wxDataViewItem( (void*) iter
.user_data
);
3202 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
3204 wxDataViewItem
item( (void*) iter
.user_data
);
3209 return wxDataViewItem(0);
3212 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
3216 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3217 if (HasFlag(wxDV_MULTIPLE
))
3219 GtkTreeModel
*model
;
3220 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
3225 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
3228 m_internal
->get_iter( &iter
, path
);
3230 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
3232 list
= g_list_next( list
);
3237 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
3238 g_list_free( list
);
3244 GtkTreeModel
*model
;
3246 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
3249 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
3257 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
3259 GtkDisableSelectionEvents();
3261 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3263 gtk_tree_selection_unselect_all( selection
);
3266 for (i
= 0; i
< sel
.GetCount(); i
++)
3269 iter
.user_data
= (gpointer
) sel
[i
].GetID();
3270 gtk_tree_selection_select_iter( selection
, &iter
);
3273 GtkEnableSelectionEvents();
3276 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
3278 GtkDisableSelectionEvents();
3280 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3283 iter
.user_data
= (gpointer
) item
.GetID();
3284 gtk_tree_selection_select_iter( selection
, &iter
);
3286 GtkEnableSelectionEvents();
3289 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
3291 GtkDisableSelectionEvents();
3293 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3296 iter
.user_data
= (gpointer
) item
.GetID();
3297 gtk_tree_selection_unselect_iter( selection
, &iter
);
3299 GtkEnableSelectionEvents();
3302 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
3304 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3307 iter
.user_data
= (gpointer
) item
.GetID();
3309 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
3312 void wxDataViewCtrl::SelectAll()
3314 GtkDisableSelectionEvents();
3316 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3318 gtk_tree_selection_select_all( selection
);
3320 GtkEnableSelectionEvents();
3323 void wxDataViewCtrl::UnselectAll()
3325 GtkDisableSelectionEvents();
3327 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3329 gtk_tree_selection_unselect_all( selection
);
3331 GtkEnableSelectionEvents();
3334 void wxDataViewCtrl::EnsureVisible( const wxDataViewItem
& item
, const wxDataViewColumn
*column
)
3337 iter
.user_data
= (gpointer
) item
.GetID();
3338 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3339 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
3340 gtk_tree_path_free( path
);
3343 void wxDataViewCtrl::HitTest( const wxPoint
&point
,
3344 wxDataViewItem
&item
, wxDataViewColumn
*&column
) const
3346 item
= wxDataViewItem(0);
3350 wxRect
wxDataViewCtrl::GetItemRect( const wxDataViewItem
&item
,
3351 const wxDataViewColumn
*column
) const
3356 void wxDataViewCtrl::DoSetExpanderColumn()
3358 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
3359 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
3362 void wxDataViewCtrl::DoSetIndent()
3366 void wxDataViewCtrl::GtkDisableSelectionEvents()
3368 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3369 g_signal_handlers_disconnect_by_func( selection
,
3370 (gpointer
) (wxdataview_selection_changed_callback
), this);
3373 void wxDataViewCtrl::GtkEnableSelectionEvents()
3375 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3376 g_signal_connect_after (selection
, "changed",
3377 G_CALLBACK (wxdataview_selection_changed_callback
), this);
3382 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
3384 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
3389 // !wxUSE_GENERICDATAVIEWCTRL
3392 // wxUSE_DATAVIEWCTRL