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 bool IsSorted() { return (m_sort_column
>= 0); }
100 wxGtkTreeModelNode
*FindNode( const wxDataViewItem
&item
);
101 wxGtkTreeModelNode
*FindNode( GtkTreeIter
*iter
);
102 wxGtkTreeModelNode
*FindParentNode( const wxDataViewItem
&item
);
103 wxGtkTreeModelNode
*FindParentNode( GtkTreeIter
*iter
);
104 void BuildBranch( wxGtkTreeModelNode
*branch
);
107 wxGtkTreeModelNode
*m_root
;
108 wxDataViewModel
*m_wx_model
;
109 GtkWxTreeModel
*m_gtk_model
;
110 wxDataViewCtrl
*m_owner
;
111 GtkSortType m_sort_order
;
116 //-----------------------------------------------------------------------------
117 // wxGtkTreeModelNode
118 //-----------------------------------------------------------------------------
120 int LINKAGEMODE
wxGtkTreeModelChildCmp( void** id1
, void** id2
)
122 int ret
= g_internal
->GetDataViewModel()->Compare( *id1
, *id2
,
123 g_internal
->GetSortColumn(), (g_internal
->GetSortOrder() == GTK_SORT_ASCENDING
) );
128 WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode
*, wxGtkTreeModelNodes
);
129 WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren
);
131 class wxGtkTreeModelNode
134 wxGtkTreeModelNode( wxGtkTreeModelNode
* parent
, const wxDataViewItem
&item
,
135 wxDataViewCtrlInternal
*internal
)
139 m_internal
= internal
;
142 ~wxGtkTreeModelNode()
144 size_t count
= m_children
.GetCount();
146 for (i
= 0; i
< count
; i
++)
148 wxGtkTreeModelNode
*child
= m_nodes
.Item( i
);
153 unsigned int AddNode( wxGtkTreeModelNode
* child
)
155 m_nodes
.Add( child
);
157 void *id
= child
->GetItem().GetID();
159 m_children
.Add( id
);
161 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
163 g_internal
= m_internal
;
164 m_children
.Sort( &wxGtkTreeModelChildCmp
);
165 return m_children
.Index( id
);
168 return m_children
.GetCount()-1;
171 unsigned int AddLeave( void* id
)
173 m_children
.Add( id
);
175 if (m_internal
->IsSorted() || m_internal
->GetDataViewModel()->HasDefaultCompare())
177 g_internal
= m_internal
;
178 m_children
.Sort( &wxGtkTreeModelChildCmp
);
179 return m_children
.Index( id
);
182 return m_children
.GetCount()-1;
185 void DeleteChild( void* id
)
187 m_children
.Remove( id
);
189 unsigned int count
= m_nodes
.GetCount();
191 for (pos
= 0; pos
< count
; pos
++)
193 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
194 if (node
->GetItem().GetID() == id
)
196 m_nodes
.RemoveAt( pos
);
204 wxGtkTreeModelNode
* GetParent()
206 wxGtkTreeModelNodes
&GetNodes()
208 wxGtkTreeModelChildren
&GetChildren()
209 { return m_children
; }
211 unsigned int GetChildCount() { return m_children
.GetCount(); }
212 unsigned int GetNodesCount() { return m_nodes
.GetCount(); }
214 wxDataViewItem
&GetItem() { return m_item
; }
215 wxDataViewCtrlInternal
*GetInternal() { return m_internal
; }
220 wxGtkTreeModelNode
*m_parent
;
221 wxGtkTreeModelNodes m_nodes
;
222 wxGtkTreeModelChildren m_children
;
223 wxDataViewItem m_item
;
224 wxDataViewCtrlInternal
*m_internal
;
228 //-----------------------------------------------------------------------------
230 //-----------------------------------------------------------------------------
232 extern bool g_blockEventsOnDrag
;
234 //-----------------------------------------------------------------------------
235 // define new GTK+ class wxGtkTreeModel
236 //-----------------------------------------------------------------------------
240 #define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ())
241 #define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel))
242 #define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
243 #define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL))
244 #define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL))
245 #define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
247 GType
gtk_wx_tree_model_get_type (void);
249 typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass
;
251 struct _GtkWxTreeModel
257 wxDataViewCtrlInternal
*internal
;
260 struct _GtkWxTreeModelClass
262 GObjectClass list_parent_class
;
265 static GtkWxTreeModel
*wxgtk_tree_model_new (void);
266 static void wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
);
267 static void wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
);
268 static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
);
269 static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
);
270 static void wxgtk_tree_model_finalize (GObject
*object
);
271 static GtkTreeModelFlags
wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
);
272 static gint
wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
);
273 static GType
wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
275 static gboolean
wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
278 static GtkTreePath
*wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
280 static void wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
284 static gboolean
wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
286 static gboolean
wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
288 GtkTreeIter
*parent
);
289 static gboolean
wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
291 static gint
wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
293 static gboolean
wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
297 static gboolean
wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
302 static gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
303 gint
*sort_column_id
,
305 static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
308 static void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
310 GtkTreeIterCompareFunc func
,
312 GtkDestroyNotify destroy
);
313 static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
314 GtkTreeIterCompareFunc func
,
316 GtkDestroyNotify destroy
);
317 static gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
);
321 static GObjectClass
*list_parent_class
= NULL
;
324 gtk_wx_tree_model_get_type (void)
326 static GType tree_model_type
= 0;
328 if (!tree_model_type
)
330 const GTypeInfo tree_model_info
=
332 sizeof (GtkWxTreeModelClass
),
333 NULL
, /* base_init */
334 NULL
, /* base_finalize */
335 (GClassInitFunc
) wxgtk_tree_model_class_init
,
336 NULL
, /* class_finalize */
337 NULL
, /* class_data */
338 sizeof (GtkWxTreeModel
),
340 (GInstanceInitFunc
) wxgtk_tree_model_init
,
343 static const GInterfaceInfo tree_model_iface_info
=
345 (GInterfaceInitFunc
) wxgtk_tree_model_tree_model_init
,
350 static const GInterfaceInfo sortable_iface_info
=
352 (GInterfaceInitFunc
) wxgtk_tree_model_sortable_init
,
357 tree_model_type
= g_type_register_static (G_TYPE_OBJECT
, "GtkWxTreeModel",
358 &tree_model_info
, (GTypeFlags
)0 );
360 g_type_add_interface_static (tree_model_type
,
362 &tree_model_iface_info
);
363 g_type_add_interface_static (tree_model_type
,
364 GTK_TYPE_TREE_SORTABLE
,
365 &sortable_iface_info
);
368 return tree_model_type
;
371 static GtkWxTreeModel
*
372 wxgtk_tree_model_new(void)
374 GtkWxTreeModel
*retval
= (GtkWxTreeModel
*) g_object_new (GTK_TYPE_WX_TREE_MODEL
, NULL
);
379 wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
)
381 list_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
382 GObjectClass
*object_class
= (GObjectClass
*) klass
;
383 object_class
->finalize
= wxgtk_tree_model_finalize
;
387 wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
)
389 iface
->get_flags
= wxgtk_tree_model_get_flags
;
390 iface
->get_n_columns
= wxgtk_tree_model_get_n_columns
;
391 iface
->get_column_type
= wxgtk_tree_model_get_column_type
;
392 iface
->get_iter
= wxgtk_tree_model_get_iter
;
393 iface
->get_path
= wxgtk_tree_model_get_path
;
394 iface
->get_value
= wxgtk_tree_model_get_value
;
395 iface
->iter_next
= wxgtk_tree_model_iter_next
;
396 iface
->iter_children
= wxgtk_tree_model_iter_children
;
397 iface
->iter_has_child
= wxgtk_tree_model_iter_has_child
;
398 iface
->iter_n_children
= wxgtk_tree_model_iter_n_children
;
399 iface
->iter_nth_child
= wxgtk_tree_model_iter_nth_child
;
400 iface
->iter_parent
= wxgtk_tree_model_iter_parent
;
404 wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
)
406 iface
->get_sort_column_id
= wxgtk_tree_model_get_sort_column_id
;
407 iface
->set_sort_column_id
= wxgtk_tree_model_set_sort_column_id
;
408 iface
->set_sort_func
= wxgtk_tree_model_set_sort_func
;
409 iface
->set_default_sort_func
= wxgtk_tree_model_set_default_sort_func
;
410 iface
->has_default_sort_func
= wxgtk_tree_model_has_default_sort_func
;
414 wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
)
416 tree_model
->internal
= NULL
;
417 tree_model
->stamp
= g_random_int();
421 wxgtk_tree_model_finalize (GObject
*object
)
424 (* list_parent_class
->finalize
) (object
);
429 //-----------------------------------------------------------------------------
430 // implement callbacks from wxGtkTreeModel class by letting
431 // them call the methods of wxWidgets' wxDataViewModel
432 //-----------------------------------------------------------------------------
434 static GtkTreeModelFlags
435 wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
)
437 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (tree_model
), (GtkTreeModelFlags
)0 );
439 return GTK_TREE_MODEL_ITERS_PERSIST
;
443 wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
)
445 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
446 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
448 return wxtree_model
->internal
->GetDataViewModel()->GetColumnCount();
452 wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
455 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
456 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), G_TYPE_INVALID
);
458 GType gtype
= G_TYPE_INVALID
;
460 wxString wxtype
= wxtree_model
->internal
->GetDataViewModel()->GetColumnType( (unsigned int) index
);
462 if (wxtype
== wxT("string"))
463 gtype
= G_TYPE_STRING
;
466 wxFAIL_MSG( _T("non-string columns not supported yet") );
473 wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
477 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
478 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
479 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
481 return wxtree_model
->internal
->get_iter( iter
, path
);
485 wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
488 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
489 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), NULL
);
490 g_return_val_if_fail (iter
->stamp
== GTK_WX_TREE_MODEL (wxtree_model
)->stamp
, NULL
);
492 return wxtree_model
->internal
->get_path( iter
);
496 wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
501 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
502 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
) );
504 wxDataViewModel
*model
= wxtree_model
->internal
->GetDataViewModel();
505 wxString mtype
= model
->GetColumnType( (unsigned int) column
);
506 if (mtype
== wxT("string"))
509 g_value_init( value
, G_TYPE_STRING
);
510 wxDataViewItem
item( (void*) iter
->user_data
);
511 model
->GetValue( variant
, item
, (unsigned int) column
);
513 g_value_set_string( value
, variant
.GetString().utf8_str() );
517 wxFAIL_MSG( _T("non-string columns not supported yet") );
522 wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
525 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
526 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
527 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
529 return wxtree_model
->internal
->iter_next( iter
);
533 wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
537 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
538 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
539 g_return_val_if_fail (wxtree_model
->stamp
== parent
->stamp
, FALSE
);
541 return wxtree_model
->internal
->iter_children( iter
, parent
);
545 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
548 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
549 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
550 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
552 return wxtree_model
->internal
->iter_has_child( iter
);
556 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
559 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
560 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
561 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, 0);
563 return wxtree_model
->internal
->iter_n_children( iter
);
567 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
572 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
573 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
575 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
579 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
583 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
584 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
585 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
587 return wxtree_model
->internal
->iter_parent( iter
, child
);
591 gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
592 gint
*sort_column_id
,
595 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
597 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
599 if (!tree_model
->internal
->IsSorted())
602 *sort_column_id
= -1;
609 *sort_column_id
= tree_model
->internal
->GetSortColumn();
612 *order
= tree_model
->internal
->GetSortOrder();
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 if ((sort_column_id
== (gint
) tree_model
->internal
->GetSortColumn()) &&
625 (order
== tree_model
->internal
->GetSortOrder()))
628 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();
636 wxDataViewCtrl
*dv
= tree_model
->internal
->GetOwner();
637 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, dv
->GetId() );
638 // TODO event.SetDataViewColumn( column );
639 event
.SetModel( dv
->GetModel() );
640 dv
->GetEventHandler()->ProcessEvent( event
);
643 void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
645 GtkTreeIterCompareFunc func
,
647 GtkDestroyNotify destroy
)
649 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
650 g_return_if_fail (func
!= NULL
);
653 void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
654 GtkTreeIterCompareFunc func
,
656 GtkDestroyNotify destroy
)
658 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
659 g_return_if_fail (func
!= NULL
);
661 wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
664 gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
)
669 //-----------------------------------------------------------------------------
670 // define new GTK+ class wxGtkRendererRenderer
671 //-----------------------------------------------------------------------------
675 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
676 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
677 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
678 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
679 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
680 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
682 GType
gtk_wx_cell_renderer_get_type (void);
684 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
685 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
687 struct _GtkWxCellRenderer
689 GtkCellRenderer parent
;
692 wxDataViewCustomRenderer
*cell
;
696 struct _GtkWxCellRendererClass
698 GtkCellRendererClass cell_parent_class
;
702 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
703 static void gtk_wx_cell_renderer_init (
704 GtkWxCellRenderer
*cell
);
705 static void gtk_wx_cell_renderer_class_init(
706 GtkWxCellRendererClass
*klass
);
707 static void gtk_wx_cell_renderer_finalize (
709 static void gtk_wx_cell_renderer_get_size (
710 GtkCellRenderer
*cell
,
712 GdkRectangle
*rectangle
,
717 static void gtk_wx_cell_renderer_render (
718 GtkCellRenderer
*cell
,
721 GdkRectangle
*background_area
,
722 GdkRectangle
*cell_area
,
723 GdkRectangle
*expose_area
,
724 GtkCellRendererState flags
);
725 static gboolean
gtk_wx_cell_renderer_activate(
726 GtkCellRenderer
*cell
,
730 GdkRectangle
*background_area
,
731 GdkRectangle
*cell_area
,
732 GtkCellRendererState flags
);
733 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
734 GtkCellRenderer
*cell
,
738 GdkRectangle
*background_area
,
739 GdkRectangle
*cell_area
,
740 GtkCellRendererState flags
);
743 static GObjectClass
*cell_parent_class
= NULL
;
748 gtk_wx_cell_renderer_get_type (void)
750 static GType cell_wx_type
= 0;
754 const GTypeInfo cell_wx_info
=
756 sizeof (GtkWxCellRendererClass
),
757 NULL
, /* base_init */
758 NULL
, /* base_finalize */
759 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
760 NULL
, /* class_finalize */
761 NULL
, /* class_data */
762 sizeof (GtkWxCellRenderer
),
764 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
767 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
768 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
775 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
778 cell
->last_click
= 0;
782 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
784 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
785 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
787 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
789 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
791 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
792 cell_class
->render
= gtk_wx_cell_renderer_render
;
793 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
794 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
798 gtk_wx_cell_renderer_finalize (GObject
*object
)
801 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
805 gtk_wx_cell_renderer_new (void)
807 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
812 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
813 GtkCellRenderer
*renderer
,
817 GdkRectangle
*background_area
,
818 GdkRectangle
*cell_area
,
819 GtkCellRendererState flags
)
821 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
822 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
823 if (!cell
->HasEditorCtrl())
827 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
833 rect
.x
+= cell_area
->x
;
834 rect
.y
+= cell_area
->y
;
835 // rect.width -= renderer->xpad * 2;
836 // rect.height -= renderer->ypad * 2;
838 // wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
839 wxRect
renderrect( cell_area
->x
, cell_area
->y
, cell_area
->width
, cell_area
->height
);
841 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
843 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
844 wxDataViewItem
item( (void*) iter
.user_data
);
845 gtk_tree_path_free( treepath
);
847 cell
->StartEditing( item
, renderrect
);
853 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
855 GdkRectangle
*cell_area
,
861 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
862 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
864 wxSize size
= cell
->GetSize();
866 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
867 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
874 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
878 *x_offset
= (gint
)((renderer
->xalign
*
879 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
880 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
884 *y_offset
= (gint
)((renderer
->yalign
*
885 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
886 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
894 *height
= calc_height
;
898 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
901 GdkRectangle
*background_area
,
902 GdkRectangle
*cell_area
,
903 GdkRectangle
*expose_area
,
904 GtkCellRendererState flags
)
907 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
908 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
911 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
917 rect
.x
+= cell_area
->x
;
918 rect
.y
+= cell_area
->y
;
919 rect
.width
-= renderer
->xpad
* 2;
920 rect
.height
-= renderer
->ypad
* 2;
923 if (gdk_rectangle_intersect (expose_area
, &rect
, &dummy
))
925 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
926 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
927 if (dc
->m_window
== NULL
)
929 dc
->m_window
= window
;
934 if (flags
& GTK_CELL_RENDERER_SELECTED
)
935 state
|= wxDATAVIEW_CELL_SELECTED
;
936 if (flags
& GTK_CELL_RENDERER_PRELIT
)
937 state
|= wxDATAVIEW_CELL_PRELIT
;
938 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
939 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
940 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
941 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
942 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
943 state
|= wxDATAVIEW_CELL_FOCUSED
;
944 cell
->Render( renderrect
, dc
, state
);
949 gtk_wx_cell_renderer_activate(
950 GtkCellRenderer
*renderer
,
954 GdkRectangle
*background_area
,
955 GdkRectangle
*cell_area
,
956 GtkCellRendererState flags
)
958 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
959 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
962 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
968 rect
.x
+= cell_area
->x
;
969 rect
.y
+= cell_area
->y
;
970 rect
.width
-= renderer
->xpad
* 2;
971 rect
.height
-= renderer
->ypad
* 2;
973 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
975 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
977 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
980 gtk_tree_path_free( treepath
);
982 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
988 // activated by <ENTER>
989 if (cell
->Activate( renderrect
, model
, item
, model_col
))
994 else if (event
->type
== GDK_BUTTON_PRESS
)
996 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
997 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
998 ((int) button_event
->y
) - renderrect
.y
);
1001 if (button_event
->button
== 1)
1003 if (cell
->LeftClick( pt
, renderrect
, model
, item
, model_col
))
1005 // TODO: query system double-click time
1006 if (button_event
->time
- wxrenderer
->last_click
< 400)
1007 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1010 if (button_event
->button
== 3)
1012 if (cell
->RightClick( pt
, renderrect
, model
, item
, model_col
))
1016 wxrenderer
->last_click
= button_event
->time
;
1024 // ---------------------------------------------------------
1025 // wxGtkDataViewModelNotifier
1026 // ---------------------------------------------------------
1028 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1031 wxGtkDataViewModelNotifier( GtkWxTreeModel
*wxgtk_model
,
1032 wxDataViewModel
*wx_model
,
1033 wxDataViewCtrl
*ctrl
);
1034 ~wxGtkDataViewModelNotifier();
1036 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1037 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1038 virtual bool ItemChanged( const wxDataViewItem
&item
);
1039 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
1040 virtual bool Cleared();
1041 virtual void Resort();
1043 GtkWxTreeModel
*m_wxgtk_model
;
1044 wxDataViewModel
*m_wx_model
;
1045 wxDataViewCtrl
*m_owner
;
1048 // ---------------------------------------------------------
1049 // wxGtkDataViewListModelNotifier
1050 // ---------------------------------------------------------
1052 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1053 GtkWxTreeModel
* wxgtk_model
, wxDataViewModel
*wx_model
,
1054 wxDataViewCtrl
*ctrl
)
1056 m_wxgtk_model
= wxgtk_model
;
1057 m_wx_model
= wx_model
;
1061 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1064 m_wxgtk_model
= NULL
;
1067 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1069 m_owner
->GtkGetInternal()->ItemAdded( parent
, item
);
1072 iter
.stamp
= m_wxgtk_model
->stamp
;
1073 iter
.user_data
= (gpointer
) item
.GetID();
1075 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1076 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1077 gtk_tree_model_row_inserted(
1078 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1079 gtk_tree_path_free (path
);
1084 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&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_deleted(
1093 GTK_TREE_MODEL(m_wxgtk_model
), path
);
1094 gtk_tree_path_free (path
);
1096 m_owner
->GtkGetInternal()->ItemDeleted( parent
, item
);
1101 void wxGtkDataViewModelNotifier::Resort()
1103 m_owner
->GtkGetInternal()->Resort();
1106 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1109 iter
.stamp
= m_wxgtk_model
->stamp
;
1110 iter
.user_data
= (gpointer
) item
.GetID();
1112 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1113 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1114 gtk_tree_model_row_changed(
1115 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1116 gtk_tree_path_free (path
);
1118 m_owner
->GtkGetInternal()->ItemChanged( item
);
1123 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_col
)
1125 // This adds GTK+'s missing MVC logic for ValueChanged
1127 for (index
= 0; index
< m_owner
->GetColumnCount(); index
++)
1129 wxDataViewColumn
*column
= m_owner
->GetColumn( index
);
1130 if (column
->GetModelColumn() == model_col
)
1132 GtkTreeView
*widget
= GTK_TREE_VIEW(m_owner
->m_treeview
);
1133 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1137 iter
.stamp
= m_wxgtk_model
->stamp
;
1138 iter
.user_data
= (gpointer
) item
.GetID();
1139 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1140 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1141 GdkRectangle cell_area
;
1142 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1143 gtk_tree_path_free( path
);
1145 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1146 double d
= gtk_adjustment_get_value( hadjust
);
1147 int xdiff
= (int) d
;
1149 int ydiff
= gcolumn
->button
->allocation
.height
;
1151 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1152 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1154 m_owner
->GtkGetInternal()->ValueChanged( item
, model_col
);
1163 bool wxGtkDataViewModelNotifier::Cleared()
1165 // TODO: delete everything
1167 m_owner
->GtkGetInternal()->Cleared();
1172 // ---------------------------------------------------------
1173 // wxDataViewRenderer
1174 // ---------------------------------------------------------
1176 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1178 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1180 wxDataViewRendererBase( varianttype
, mode
, align
)
1184 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1185 // after the m_renderer pointer has been initialized
1188 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1190 GtkCellRendererMode gtkMode
;
1193 case wxDATAVIEW_CELL_INERT
:
1194 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1196 case wxDATAVIEW_CELL_ACTIVATABLE
:
1197 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1199 case wxDATAVIEW_CELL_EDITABLE
:
1200 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1204 GValue gvalue
= { 0, };
1205 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1206 g_value_set_enum( &gvalue
, gtkMode
);
1207 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1208 g_value_unset( &gvalue
);
1211 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1213 wxDataViewCellMode ret
;
1216 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1218 switch (g_value_get_enum(&gvalue
))
1220 case GTK_CELL_RENDERER_MODE_INERT
:
1221 ret
= wxDATAVIEW_CELL_INERT
;
1223 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1224 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1226 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1227 ret
= wxDATAVIEW_CELL_EDITABLE
;
1231 g_value_unset( &gvalue
);
1236 void wxDataViewRenderer::SetAlignment( int align
)
1238 // horizontal alignment:
1240 gfloat xalign
= 0.0;
1241 if (align
& wxALIGN_RIGHT
)
1243 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1246 GValue gvalue
= { 0, };
1247 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1248 g_value_set_float( &gvalue
, xalign
);
1249 g_object_set_property( G_OBJECT(m_renderer
), "xalign", &gvalue
);
1250 g_value_unset( &gvalue
);
1252 // vertical alignment:
1254 gfloat yalign
= 0.0;
1255 if (align
& wxALIGN_BOTTOM
)
1257 else if (align
& wxALIGN_CENTER_VERTICAL
)
1260 GValue gvalue2
= { 0, };
1261 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1262 g_value_set_float( &gvalue2
, yalign
);
1263 g_object_set_property( G_OBJECT(m_renderer
), "yalign", &gvalue2
);
1264 g_value_unset( &gvalue2
);
1267 int wxDataViewRenderer::GetAlignment() const
1272 // horizontal alignment:
1274 g_object_get( G_OBJECT(m_renderer
), "xalign", &gvalue
, NULL
);
1275 float xalign
= g_value_get_float( &gvalue
);
1277 ret
|= wxALIGN_LEFT
;
1278 else if (xalign
== 0.5)
1279 ret
|= wxALIGN_CENTER_HORIZONTAL
;
1281 ret
|= wxALIGN_RIGHT
;
1282 g_value_unset( &gvalue
);
1285 // vertical alignment:
1287 g_object_get( G_OBJECT(m_renderer
), "yalign", &gvalue
, NULL
);
1288 float yalign
= g_value_get_float( &gvalue
);
1291 else if (yalign
== 0.5)
1292 ret
|= wxALIGN_CENTER_VERTICAL
;
1294 ret
|= wxALIGN_BOTTOM
;
1295 g_value_unset( &gvalue
);
1302 // ---------------------------------------------------------
1303 // wxDataViewTextRenderer
1304 // ---------------------------------------------------------
1307 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1308 gchar
*arg1
, gchar
*arg2
, gpointer user_data
);
1311 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1312 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1314 wxDataViewTextRenderer
*cell
= (wxDataViewTextRenderer
*) user_data
;
1316 wxString tmp
= wxGTK_CONV_BACK_FONT(arg2
, cell
->GetOwner()->GetOwner()->GetFont());
1317 wxVariant value
= tmp
;
1318 if (!cell
->Validate( value
))
1321 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1323 GtkTreePath
*path
= gtk_tree_path_new_from_string( arg1
);
1325 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, path
);
1326 wxDataViewItem
item( (void*) iter
.user_data
);;
1327 gtk_tree_path_free( path
);
1329 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1331 model
->SetValue( value
, item
, model_col
);
1332 model
->ValueChanged( item
, model_col
);
1335 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
1337 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1339 wxDataViewRenderer( varianttype
, mode
, align
)
1341 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_text_new();
1343 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
1345 GValue gvalue
= { 0, };
1346 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1347 g_value_set_boolean( &gvalue
, true );
1348 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
1349 g_value_unset( &gvalue
);
1351 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
1355 SetAlignment(align
);
1358 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
1360 wxString tmp
= value
;
1362 GValue gvalue
= { 0, };
1363 g_value_init( &gvalue
, G_TYPE_STRING
);
1364 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( tmp
, GetOwner()->GetOwner()->GetFont() ) );
1365 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1366 g_value_unset( &gvalue
);
1371 bool wxDataViewTextRenderer::GetValue( wxVariant
&value
) const
1373 GValue gvalue
= { 0, };
1374 g_value_init( &gvalue
, G_TYPE_STRING
);
1375 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1376 wxString tmp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
),
1377 wx_const_cast(wxDataViewTextRenderer
*, this)->GetOwner()->GetOwner()->GetFont() );
1378 g_value_unset( &gvalue
);
1385 void wxDataViewTextRenderer::SetAlignment( int align
)
1387 wxDataViewRenderer::SetAlignment(align
);
1389 if (gtk_check_version(2,10,0))
1392 // horizontal alignment:
1393 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
1394 if (align
& wxALIGN_RIGHT
)
1395 pangoAlign
= PANGO_ALIGN_RIGHT
;
1396 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1397 pangoAlign
= PANGO_ALIGN_CENTER
;
1399 GValue gvalue
= { 0, };
1400 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1401 g_value_set_enum( &gvalue
, pangoAlign
);
1402 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
1403 g_value_unset( &gvalue
);
1406 // ---------------------------------------------------------
1407 // wxDataViewBitmapRenderer
1408 // ---------------------------------------------------------
1410 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
1412 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1414 wxDataViewRenderer( varianttype
, mode
, align
)
1416 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_pixbuf_new();
1419 SetAlignment(align
);
1422 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
1424 if (value
.GetType() == wxT("wxBitmap"))
1429 // This may create a Pixbuf representation in the
1430 // wxBitmap object (and it will stay there)
1431 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1433 GValue gvalue
= { 0, };
1434 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1435 g_value_set_object( &gvalue
, pixbuf
);
1436 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1437 g_value_unset( &gvalue
);
1442 if (value
.GetType() == wxT("wxIcon"))
1447 // This may create a Pixbuf representation in the
1448 // wxBitmap object (and it will stay there)
1449 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1451 GValue gvalue
= { 0, };
1452 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1453 g_value_set_object( &gvalue
, pixbuf
);
1454 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1455 g_value_unset( &gvalue
);
1463 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&value
) const
1468 // ---------------------------------------------------------
1469 // wxDataViewToggleRenderer
1470 // ---------------------------------------------------------
1473 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1474 gchar
*path
, gpointer user_data
);
1477 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1478 gchar
*path
, gpointer user_data
)
1480 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
1483 GValue gvalue
= { 0, };
1484 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1485 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
1486 bool tmp
= g_value_get_boolean( &gvalue
);
1487 g_value_unset( &gvalue
);
1491 wxVariant value
= tmp
;
1492 if (!cell
->Validate( value
))
1495 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1497 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
1499 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, gtk_path
);
1500 wxDataViewItem
item( (void*) iter
.user_data
);;
1501 gtk_tree_path_free( gtk_path
);
1503 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1505 model
->SetValue( value
, item
, model_col
);
1506 model
->ValueChanged( item
, model_col
);
1509 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1511 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1512 wxDataViewCellMode mode
, int align
) :
1513 wxDataViewRenderer( varianttype
, mode
, align
)
1515 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
1517 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1519 g_signal_connect_after( m_renderer
, "toggled",
1520 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
1524 GValue gvalue
= { 0, };
1525 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1526 g_value_set_boolean( &gvalue
, false );
1527 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
1528 g_value_unset( &gvalue
);
1532 SetAlignment(align
);
1535 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1539 GValue gvalue
= { 0, };
1540 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1541 g_value_set_boolean( &gvalue
, tmp
);
1542 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1543 g_value_unset( &gvalue
);
1548 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
1550 GValue gvalue
= { 0, };
1551 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1552 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1553 bool tmp
= g_value_get_boolean( &gvalue
);
1554 g_value_unset( &gvalue
);
1561 // ---------------------------------------------------------
1562 // wxDataViewCustomRenderer
1563 // ---------------------------------------------------------
1565 class wxDataViewCtrlDC
: public wxWindowDC
1568 wxDataViewCtrlDC( wxDataViewCtrl
*window
)
1570 GtkWidget
*widget
= window
->m_treeview
;
1574 m_context
= window
->GtkGetPangoDefaultContext();
1575 m_layout
= pango_layout_new( m_context
);
1576 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
1578 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
1580 // Set m_window later
1582 // m_owner = window;
1586 // ---------------------------------------------------------
1587 // wxDataViewCustomRenderer
1588 // ---------------------------------------------------------
1590 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
1592 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
1593 wxDataViewCellMode mode
, int align
,
1595 wxDataViewRenderer( varianttype
, mode
, align
)
1605 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
1607 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
1608 renderer
->cell
= this;
1610 m_renderer
= (GtkCellRenderer
*) renderer
;
1613 SetAlignment(align
);
1618 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
1624 wxDC
*wxDataViewCustomRenderer::GetDC()
1628 if (GetOwner() == NULL
)
1630 if (GetOwner()->GetOwner() == NULL
)
1632 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
1638 // ---------------------------------------------------------
1639 // wxDataViewProgressRenderer
1640 // ---------------------------------------------------------
1642 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
1644 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
1645 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1646 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
1652 if (!gtk_check_version(2,6,0))
1654 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
1656 GValue gvalue
= { 0, };
1657 g_value_init( &gvalue
, G_TYPE_STRING
);
1659 // FIXME: font encoding support
1660 g_value_set_string( &gvalue
, wxGTK_CONV_SYS(m_label
) );
1661 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1662 g_value_unset( &gvalue
);
1665 SetAlignment(align
);
1670 // Use custom cell code
1671 wxDataViewCustomRenderer::Init(mode
, align
);
1675 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
1679 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
1682 if (!gtk_check_version(2,6,0))
1684 gint tmp
= (long) value
;
1685 GValue gvalue
= { 0, };
1686 g_value_init( &gvalue
, G_TYPE_INT
);
1687 g_value_set_int( &gvalue
, tmp
);
1688 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
1689 g_value_unset( &gvalue
);
1694 m_value
= (long) value
;
1696 if (m_value
< 0) m_value
= 0;
1697 if (m_value
> 100) m_value
= 100;
1703 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
1708 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1710 double pct
= (double)m_value
/ 100.0;
1712 bar
.width
= (int)(cell
.width
* pct
);
1713 dc
->SetPen( *wxTRANSPARENT_PEN
);
1714 dc
->SetBrush( *wxBLUE_BRUSH
);
1715 dc
->DrawRectangle( bar
);
1717 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1718 dc
->SetPen( *wxBLACK_PEN
);
1719 dc
->DrawRectangle( cell
);
1724 wxSize
wxDataViewProgressRenderer::GetSize() const
1726 return wxSize(40,12);
1729 // ---------------------------------------------------------
1730 // wxDataViewDateRenderer
1731 // ---------------------------------------------------------
1733 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
1736 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
1737 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
1738 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
1743 m_cal
= new wxCalendarCtrl( this, -1, *value
);
1744 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
1745 sizer
->Add( m_cal
, 1, wxGROW
);
1750 virtual void OnDismiss()
1754 void OnCalendar( wxCalendarEvent
&event
);
1756 wxCalendarCtrl
*m_cal
;
1757 wxDataViewModel
*m_model
;
1758 wxDataViewItem m_item
;
1762 DECLARE_EVENT_TABLE()
1765 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
1766 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
1769 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
1771 wxDateTime date
= event
.GetDate();
1772 wxVariant value
= date
;
1773 m_model
->SetValue( value
, m_item
, m_col
);
1774 m_model
->ValueChanged( m_item
, m_col
);
1778 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
1780 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1781 wxDataViewCellMode mode
, int align
) :
1782 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1785 SetAlignment(align
);
1788 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1790 m_date
= value
.GetDateTime();
1795 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
1800 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1802 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
1803 wxString tmp
= m_date
.FormatDate();
1804 dc
->DrawText( tmp
, cell
.x
, cell
.y
);
1809 wxSize
wxDataViewDateRenderer::GetSize() const
1811 wxString tmp
= m_date
.FormatDate();
1813 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
1814 return wxSize(x
,y
+d
);
1817 bool wxDataViewDateRenderer::Activate( wxRect cell
, wxDataViewModel
*model
,
1818 const wxDataViewItem
&item
, unsigned int col
)
1821 model
->GetValue( variant
, item
, col
);
1822 wxDateTime value
= variant
.GetDateTime();
1824 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1825 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
1826 wxPoint pos
= wxGetMousePosition();
1829 popup
->Popup( popup
->m_cal
);
1834 // ---------------------------------------------------------
1836 // ---------------------------------------------------------
1840 gtk_dataview_header_button_press_callback( GtkWidget
*widget
,
1841 GdkEventButton
*gdk_event
,
1842 wxDataViewColumn
*column
)
1844 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
1847 if (gdk_event
->button
== 1)
1849 wxDataViewCtrl
*dv
= column
->GetOwner();
1850 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
1851 event
.SetDataViewColumn( column
);
1852 event
.SetModel( dv
->GetModel() );
1853 if (dv
->GetEventHandler()->ProcessEvent( event
))
1861 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
1862 GtkCellRenderer
*cell
,
1863 GtkTreeModel
*model
,
1869 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
1870 GtkCellRenderer
*renderer
,
1871 GtkTreeModel
*model
,
1875 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
1876 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
1878 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
1880 wxDataViewItem
item( (void*) iter
->user_data
);
1883 tree_model
->internal
->GetDataViewModel()->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
1885 if (value
.GetType() != cell
->GetVariantType())
1886 wxLogError( wxT("Wrong type, required: %s but: %s"),
1887 value
.GetType().c_str(),
1888 cell
->GetVariantType().c_str() );
1890 cell
->SetValue( value
);
1893 wxListItemAttr attr
;
1894 tree_model
->model
->GetAttr( attr
, cell
->GetOwner()->GetModelColumn(), model_row
);
1896 if (attr
.HasBackgroundColour())
1898 wxColour colour
= attr
.GetBackgroundColour();
1899 const GdkColor
* const gcol
= colour
.GetColor();
1901 GValue gvalue
= { 0, };
1902 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
1903 g_value_set_boxed( &gvalue
, gcol
);
1904 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
1905 g_value_unset( &gvalue
);
1909 GValue gvalue
= { 0, };
1910 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1911 g_value_set_boolean( &gvalue
, FALSE
);
1912 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
1913 g_value_unset( &gvalue
);
1919 IMPLEMENT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
1921 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
1922 unsigned int model_column
, int width
,
1923 wxAlignment align
, int flags
) :
1924 wxDataViewColumnBase( title
, cell
, model_column
, width
, align
, flags
)
1926 Init( align
, flags
, width
);
1928 gtk_tree_view_column_set_clickable( GTK_TREE_VIEW_COLUMN(m_column
), TRUE
);
1932 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
1933 unsigned int model_column
, int width
,
1934 wxAlignment align
, int flags
) :
1935 wxDataViewColumnBase( bitmap
, cell
, model_column
, width
, align
, flags
)
1937 Init( align
, flags
, width
);
1939 SetBitmap( bitmap
);
1942 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
1944 m_isConnected
= false;
1946 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) GetRenderer()->GetGtkHandle();
1947 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
1948 m_column
= (GtkWidget
*) column
;
1951 SetAlignment( align
);
1953 // NOTE: we prefer not to call SetMinWidth(wxDVC_DEFAULT_MINWIDTH);
1954 // as GTK+ is smart and unless explicitely told, will set the minimal
1955 // width to the title's lenght, which is a better default
1957 // the GTK_TREE_VIEW_COLUMN_FIXED is required by the "fixed height" mode
1958 // that we use for the wxDataViewCtrl
1959 gtk_tree_view_column_set_fixed_width( column
, width
< 0 ? wxDVC_DEFAULT_WIDTH
: width
);
1960 gtk_tree_view_column_set_sizing( column
, GTK_TREE_VIEW_COLUMN_FIXED
);
1962 gtk_tree_view_column_pack_end( column
, renderer
, TRUE
);
1964 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
1965 wxGtkTreeCellDataFunc
, (gpointer
) GetRenderer(), NULL
);
1968 wxDataViewColumn::~wxDataViewColumn()
1972 void wxDataViewColumn::OnInternalIdle()
1977 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
1979 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
1982 g_signal_connect(column
->button
, "button_press_event",
1983 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
1985 m_isConnected
= true;
1990 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
1992 wxDataViewColumnBase::SetOwner( owner
);
1994 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
1996 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
1999 void wxDataViewColumn::SetTitle( const wxString
&title
)
2001 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2005 // disconnect before column->button gets recreated
2006 g_signal_handlers_disconnect_by_func( column
->button
,
2007 (GtkWidget
*) gtk_dataview_header_button_press_callback
, this);
2009 m_isConnected
= false;
2012 // FIXME: can it really happen that we don't have the owner here??
2013 wxDataViewCtrl
*ctrl
= GetOwner();
2014 gtk_tree_view_column_set_title( column
, ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
2015 : wxGTK_CONV_SYS(title
) );
2017 gtk_tree_view_column_set_widget( column
, NULL
);
2020 wxString
wxDataViewColumn::GetTitle() const
2022 const gchar
*str
= gtk_tree_view_column_get_title( GTK_TREE_VIEW_COLUMN(m_column
) );
2023 return wxConvFileName
->cMB2WX(str
);
2026 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
2028 wxDataViewColumnBase::SetBitmap( bitmap
);
2030 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2033 GtkImage
*gtk_image
= GTK_IMAGE( gtk_image_new() );
2035 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
2036 if (bitmap
.GetMask())
2037 mask
= bitmap
.GetMask()->GetBitmap();
2039 if (bitmap
.HasPixbuf())
2041 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
2042 bitmap
.GetPixbuf());
2046 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
2047 bitmap
.GetPixmap(), mask
);
2049 gtk_widget_show( GTK_WIDGET(gtk_image
) );
2051 gtk_tree_view_column_set_widget( column
, GTK_WIDGET(gtk_image
) );
2055 gtk_tree_view_column_set_widget( column
, NULL
);
2059 void wxDataViewColumn::SetHidden( bool hidden
)
2061 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
2064 void wxDataViewColumn::SetResizeable( bool resizeable
)
2066 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizeable
);
2069 void wxDataViewColumn::SetAlignment( wxAlignment align
)
2071 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2073 gfloat xalign
= 0.0;
2074 if (align
== wxALIGN_RIGHT
)
2076 if (align
== wxALIGN_CENTER_HORIZONTAL
||
2077 align
== wxALIGN_CENTER
)
2080 gtk_tree_view_column_set_alignment( column
, xalign
);
2083 wxAlignment
wxDataViewColumn::GetAlignment() const
2085 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
2088 return wxALIGN_RIGHT
;
2090 return wxALIGN_CENTER_HORIZONTAL
;
2092 return wxALIGN_LEFT
;
2095 void wxDataViewColumn::SetSortable( bool sortable
)
2097 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2101 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
2105 gtk_tree_view_column_set_sort_column_id( column
, -1 );
2106 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
2110 bool wxDataViewColumn::IsSortable() const
2112 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2113 return (gtk_tree_view_column_get_sort_column_id( column
) != -1);
2116 bool wxDataViewColumn::IsResizeable() const
2118 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2119 return gtk_tree_view_column_get_resizable( column
);
2122 bool wxDataViewColumn::IsHidden() const
2124 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2125 return !gtk_tree_view_column_get_visible( column
);
2128 void wxDataViewColumn::SetSortOrder( bool ascending
)
2130 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2133 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
2135 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
2137 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
2140 bool wxDataViewColumn::IsSortOrderAscending() const
2142 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2144 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
2147 void wxDataViewColumn::SetMinWidth( int width
)
2149 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2152 int wxDataViewColumn::GetMinWidth() const
2154 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2157 int wxDataViewColumn::GetWidth() const
2159 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2162 void wxDataViewColumn::SetWidth( int width
)
2164 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2168 //-----------------------------------------------------------------------------
2169 // wxGtkTreeModelNode
2170 //-----------------------------------------------------------------------------
2172 void wxGtkTreeModelNode::Resort()
2174 size_t child_count
= GetChildCount();
2175 if (child_count
== 0)
2178 size_t node_count
= GetNodesCount();
2180 if (child_count
== 1)
2182 if (node_count
== 1)
2184 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
2190 wxGtkTreeModelChildren temp
;
2191 WX_APPEND_ARRAY( temp
, m_children
);
2193 g_internal
= m_internal
;
2194 m_children
.Sort( &wxGtkTreeModelChildCmp
);
2196 gint
*new_order
= new gint
[child_count
];
2199 for (pos
= 0; pos
< child_count
; pos
++)
2201 void *id
= m_children
.Item( pos
);
2202 int old_pos
= temp
.Index( id
);
2203 new_order
[pos
] = old_pos
;
2206 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
2209 iter
.user_data
= GetItem().GetID();
2210 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
2212 GtkTreePath
*path
= m_internal
->get_path( &iter
);
2214 gtk_tree_model_rows_reordered( gtk_tree_model
, path
, &iter
, new_order
);
2216 gtk_tree_path_free (path
);
2218 delete [] new_order
;
2220 for (pos
= 0; pos
< node_count
; pos
++)
2222 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
2227 //-----------------------------------------------------------------------------
2228 // wxDataViewCtrlInternal
2229 //-----------------------------------------------------------------------------
2231 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
,
2232 wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
)
2235 m_wx_model
= wx_model
;
2236 m_gtk_model
= gtk_model
;
2238 m_sort_order
= GTK_SORT_ASCENDING
;
2243 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
2245 g_object_unref( m_gtk_model
);
2248 void wxDataViewCtrlInternal::InitTree()
2250 wxDataViewItem item
;
2251 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
2253 BuildBranch( m_root
);
2256 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
2258 if (node
->GetChildCount() == 0)
2260 wxDataViewItem child
= m_wx_model
->GetFirstChild( node
->GetItem() );
2261 while (child
.IsOk())
2263 if (m_wx_model
->IsContainer( child
))
2264 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
2266 node
->AddLeave( child
.GetID() );
2268 // Don't send any events here
2270 child
= m_wx_model
->GetNextSibling( child
);
2275 void wxDataViewCtrlInternal::Resort()
2280 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
2282 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2283 if (m_wx_model
->IsContainer( item
))
2284 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
2286 parent_node
->AddLeave( item
.GetID() );
2288 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_ADDED
, m_owner
->GetId() );
2289 event
.SetEventObject( m_owner
);
2290 event
.SetModel( m_owner
->GetModel() );
2291 event
.SetItem( item
);
2292 m_owner
->GetEventHandler()->ProcessEvent( event
);
2297 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
2299 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2300 parent_node
->DeleteChild( item
.GetID() );
2302 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED
, m_owner
->GetId() );
2303 event
.SetEventObject( m_owner
);
2304 event
.SetModel( m_owner
->GetModel() );
2305 event
.SetItem( item
);
2306 m_owner
->GetEventHandler()->ProcessEvent( event
);
2311 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
2313 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_CHANGED
, m_owner
->GetId() );
2314 event
.SetEventObject( m_owner
);
2315 event
.SetModel( m_owner
->GetModel() );
2316 event
.SetItem( item
);
2317 m_owner
->GetEventHandler()->ProcessEvent( event
);
2322 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
2324 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED
, m_owner
->GetId() );
2325 event
.SetEventObject( m_owner
);
2326 event
.SetModel( m_owner
->GetModel() );
2327 event
.SetColumn( col
);
2328 event
.SetItem( item
);
2329 m_owner
->GetEventHandler()->ProcessEvent( event
);
2334 bool wxDataViewCtrlInternal::Cleared()
2336 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED
, m_owner
->GetId() );
2337 event
.SetEventObject( m_owner
);
2338 event
.SetModel( m_owner
->GetModel() );
2339 m_owner
->GetEventHandler()->ProcessEvent( event
);
2344 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
2346 int depth
= gtk_tree_path_get_depth( path
);
2348 wxGtkTreeModelNode
*node
= m_root
;
2351 for (i
= 0; i
< depth
; i
++)
2353 BuildBranch( node
);
2355 gint pos
= gtk_tree_path_get_indices (path
)[i
];
2356 if (pos
< 0) return FALSE
;
2357 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
2359 void* id
= node
->GetChildren().Item( (size_t) pos
);
2363 iter
->stamp
= m_gtk_model
->stamp
;
2364 iter
->user_data
= id
;
2368 size_t count
= node
->GetNodes().GetCount();
2370 for (pos2
= 0; pos2
< count
; pos2
++)
2372 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
2373 if (child_node
->GetItem().GetID() == id
)
2384 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
2386 GtkTreePath
*retval
= gtk_tree_path_new ();
2387 void *id
= iter
->user_data
;
2389 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
2392 int pos
= node
->GetChildren().Index( id
);
2394 gtk_tree_path_prepend_index( retval
, pos
);
2396 id
= node
->GetItem().GetID();
2397 node
= node
->GetParent();
2403 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
2405 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
2406 if( parent
== NULL
)
2409 int pos
= parent
->GetChildren().Index( iter
->user_data
);
2411 if (pos
== (int) parent
->GetChildCount()-1)
2414 iter
->stamp
= m_gtk_model
->stamp
;
2415 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
2420 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
2422 wxDataViewItem
item( (void*) parent
->user_data
);
2424 if (!m_wx_model
->IsContainer( item
))
2427 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2428 BuildBranch( parent_node
);
2430 if (parent_node
->GetChildCount() == 0)
2433 iter
->stamp
= m_gtk_model
->stamp
;
2434 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
2439 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
2441 wxDataViewItem
item( (void*) iter
->user_data
);
2442 bool is_container
= m_wx_model
->IsContainer( item
);
2447 wxGtkTreeModelNode
*node
= FindNode( iter
);
2448 BuildBranch( node
);
2450 return (node
->GetChildCount() > 0);
2453 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
2455 wxDataViewItem
item( (void*) iter
->user_data
);
2457 if (!m_wx_model
->IsContainer( item
))
2460 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
2461 BuildBranch( parent_node
);
2463 // wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() );
2465 return parent_node
->GetChildCount();
2468 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
2471 if (parent
) id
= (void*) parent
->user_data
;
2472 wxDataViewItem
item( id
);
2474 if (!m_wx_model
->IsContainer( item
))
2477 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2478 BuildBranch( parent_node
);
2480 // wxPrintf( "iter_nth_child %d\n", n );
2482 iter
->stamp
= m_gtk_model
->stamp
;
2483 iter
->user_data
= parent_node
->GetChildren().Item( n
);
2488 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
2490 wxGtkTreeModelNode
*node
= FindParentNode( child
);
2494 iter
->stamp
= m_gtk_model
->stamp
;
2495 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
2500 static wxGtkTreeModelNode
*
2501 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
2507 list
.DeleteContents( true );
2508 wxDataViewItem
it( item
);
2511 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
2512 list
.Insert( pItem
);
2513 it
= model
->GetParent( it
);
2516 wxGtkTreeModelNode
* node
= treeNode
;
2517 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
2519 if( node
&& node
->GetNodes().GetCount() != 0 )
2521 int len
= node
->GetNodes().GetCount();
2522 wxGtkTreeModelNodes nodes
= node
->GetNodes();
2524 for( ; j
< len
; j
++)
2526 if( nodes
[j
]->GetItem() == *(n
->GetData()))
2545 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
2550 wxDataViewItem
item( (void*) iter
->user_data
);
2554 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
2558 wxPrintf( "Not found %d\n", (int) iter
->user_data
);
2566 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
2571 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
2575 wxPrintf( "Not found %d\n", (int) item
.GetID() );
2583 static wxGtkTreeModelNode
*
2584 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
2590 list
.DeleteContents( true );
2594 wxDataViewItem
it( model
->GetParent( item
) );
2597 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
2598 list
.Insert( pItem
);
2599 it
= model
->GetParent( it
);
2602 wxGtkTreeModelNode
* node
= treeNode
;
2603 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
2605 if( node
&& node
->GetNodes().GetCount() != 0 )
2607 int len
= node
->GetNodes().GetCount();
2608 wxGtkTreeModelNodes nodes
= node
->GetNodes();
2610 for( ; j
< len
; j
++)
2612 if( nodes
[j
]->GetItem() == *(n
->GetData()))
2627 //Examine whether the node is item's parent node
2628 int len
= node
->GetChildCount();
2629 for( int i
= 0; i
< len
; i
++ )
2631 if( node
->GetChildren().Item( i
) == item
.GetID() )
2637 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
2642 wxDataViewItem
item( (void*) iter
->user_data
);
2646 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
2649 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
2654 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
2657 //-----------------------------------------------------------------------------
2658 // wxDataViewCtrl signal callbacks
2659 //-----------------------------------------------------------------------------
2662 wxdataview_selection_changed_callback( GtkTreeSelection
* selection
, wxDataViewCtrl
*dv
)
2664 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
2667 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_SELECTED
, dv
->GetId() );
2668 event
.SetItem( dv
->GetSelection() );
2669 event
.SetModel( dv
->GetModel() );
2670 dv
->GetEventHandler()->ProcessEvent( event
);
2674 wxdataview_row_activated_callback( GtkTreeView
* treeview
, GtkTreePath
*path
,
2675 GtkTreeViewColumn
*column
, wxDataViewCtrl
*dv
)
2677 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
2680 dv
->GtkGetInternal()->get_iter( &iter
, path
);
2681 wxDataViewItem
item( (void*) iter
.user_data
);;
2682 event
.SetItem( item
);
2683 event
.SetModel( dv
->GetModel() );
2684 dv
->GetEventHandler()->ProcessEvent( event
);
2688 wxdataview_test_expand_row_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
2689 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
2691 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
2693 wxDataViewItem
item( (void*) iter
->user_data
);;
2694 event
.SetItem( item
);
2695 event
.SetModel( dv
->GetModel() );
2696 dv
->GetEventHandler()->ProcessEvent( event
);
2698 return !event
.IsAllowed();
2702 wxdataview_row_expanded_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
2703 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
2705 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
2707 wxDataViewItem
item( (void*) iter
->user_data
);;
2708 event
.SetItem( item
);
2709 event
.SetModel( dv
->GetModel() );
2710 dv
->GetEventHandler()->ProcessEvent( event
);
2714 wxdataview_test_collapse_row_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
2715 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
2717 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
2719 wxDataViewItem
item( (void*) iter
->user_data
);;
2720 event
.SetItem( item
);
2721 event
.SetModel( dv
->GetModel() );
2722 dv
->GetEventHandler()->ProcessEvent( event
);
2724 return !event
.IsAllowed();
2728 wxdataview_row_collapsed_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
2729 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
2731 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
2733 wxDataViewItem
item( (void*) iter
->user_data
);;
2734 event
.SetItem( item
);
2735 event
.SetModel( dv
->GetModel() );
2736 dv
->GetEventHandler()->ProcessEvent( event
);
2739 //-----------------------------------------------------------------------------
2741 //-----------------------------------------------------------------------------
2743 //-----------------------------------------------------------------------------
2744 // InsertChild for wxDataViewCtrl
2745 //-----------------------------------------------------------------------------
2747 static void wxInsertChildInDataViewCtrl( wxWindowGTK
* parent
, wxWindowGTK
* child
)
2749 wxDataViewCtrl
* dvc
= (wxDataViewCtrl
*) parent
;
2750 GtkWidget
*treeview
= dvc
->GtkGetTreeView();
2752 // Insert widget in GtkTreeView
2753 if (GTK_WIDGET_REALIZED(treeview
))
2754 gtk_widget_set_parent_window( child
->m_widget
,
2755 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
2756 gtk_widget_set_parent( child
->m_widget
, treeview
);
2760 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
2761 GtkAllocation
*alloc
,
2762 wxDataViewCtrl
*win
)
2764 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
2767 wxWindow
*child
= node
->GetData();
2770 gtk_widget_size_request( child
->m_widget
, &req
);
2772 GtkAllocation alloc
;
2773 alloc
.x
= child
->m_x
;
2774 alloc
.y
= child
->m_y
;
2775 alloc
.width
= child
->m_width
;
2776 alloc
.height
= child
->m_height
;
2777 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
2779 node
= node
->GetNext();
2785 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
2787 wxDataViewCtrl::~wxDataViewCtrl()
2790 GetModel()->RemoveNotifier( m_notifier
);
2792 // remove the model from the GtkTreeView before it gets destroyed by the
2793 // wxDataViewCtrlBase's dtor
2794 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), NULL
);
2799 void wxDataViewCtrl::Init()
2804 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
2805 const wxPoint
& pos
, const wxSize
& size
,
2806 long style
, const wxValidator
& validator
)
2810 if (!PreCreation( parent
, pos
, size
) ||
2811 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
2813 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
2817 m_insertCallback
= wxInsertChildInDataViewCtrl
;
2819 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
2821 GtkScrolledWindowSetBorder(m_widget
, style
);
2823 m_treeview
= gtk_tree_view_new();
2824 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
2826 g_signal_connect (m_treeview
, "size_allocate",
2827 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
2830 if (!gtk_check_version(2,6,0))
2831 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), TRUE
);
2834 if (style
& wxDV_MULTIPLE
)
2836 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
2837 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
2840 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
2843 if (!gtk_check_version(2,10,0))
2845 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
2847 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
2848 (style
& wxDV_VERT_RULES
) != 0)
2849 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
2850 else if (style
& wxDV_VERT_RULES
)
2851 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
2852 else if (style
& wxDV_HORIZ_RULES
)
2853 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
2855 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
2860 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_HORIZ_RULES
) != 0 );
2863 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
2864 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
2865 gtk_widget_show (m_treeview
);
2867 m_parent
->DoAddChild( this );
2871 GtkEnableSelectionEvents();
2873 g_signal_connect_after (m_treeview
, "row-activated",
2874 G_CALLBACK (wxdataview_row_activated_callback
), this);
2876 g_signal_connect (m_treeview
, "test-collapse-row",
2877 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
2879 g_signal_connect_after (m_treeview
, "row-collapsed",
2880 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
2882 g_signal_connect (m_treeview
, "test-expand-row",
2883 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
2885 g_signal_connect_after (m_treeview
, "row-expanded",
2886 G_CALLBACK (wxdataview_row_expanded_callback
), this);
2891 void wxDataViewCtrl::OnInternalIdle()
2893 wxWindow::OnInternalIdle();
2895 unsigned int cols
= GetColumnCount();
2897 for (i
= 0; i
< cols
; i
++)
2899 wxDataViewColumn
*col
= GetColumn( i
);
2900 col
->OnInternalIdle();
2904 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
2906 if (!wxDataViewCtrlBase::AssociateModel( model
))
2909 GtkWxTreeModel
*gtk_model
= wxgtk_tree_model_new();
2910 m_internal
= new wxDataViewCtrlInternal( this, model
, gtk_model
);
2911 gtk_model
->internal
= m_internal
;
2913 m_notifier
= new wxGtkDataViewModelNotifier( gtk_model
, model
, this );
2915 model
->AddNotifier( m_notifier
);
2917 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_model
) );
2919 // unref in wxDataViewCtrlInternal
2920 // g_object_unref( gtk_model );
2925 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
2927 if (!wxDataViewCtrlBase::AppendColumn(col
))
2930 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)col
->GetGtkHandle();
2932 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
), column
);
2937 wxDataViewItem
wxDataViewCtrl::GetSelection()
2939 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
2941 if (m_windowStyle
& wxDV_MULTIPLE
)
2943 // Report the first one
2944 GtkTreeModel
*model
;
2945 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
2949 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
2951 m_internal
->get_iter( &iter
, path
);
2954 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
2955 g_list_free( list
);
2957 return wxDataViewItem( (void*) iter
.user_data
);
2963 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
2965 wxDataViewItem
item( (void*) iter
.user_data
);
2970 return wxDataViewItem(0);
2973 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
2977 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
2978 if (HasFlag(wxDV_MULTIPLE
))
2980 GtkTreeModel
*model
;
2981 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
2986 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
2989 m_internal
->get_iter( &iter
, path
);
2991 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
2993 list
= g_list_next( list
);
2998 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
2999 g_list_free( list
);
3005 GtkTreeModel
*model
;
3007 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
3010 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
3018 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
3020 GtkDisableSelectionEvents();
3022 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3024 gtk_tree_selection_unselect_all( selection
);
3027 for (i
= 0; i
< sel
.GetCount(); i
++)
3030 iter
.user_data
= (gpointer
) sel
[i
].GetID();
3031 gtk_tree_selection_select_iter( selection
, &iter
);
3034 GtkEnableSelectionEvents();
3037 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
3039 GtkDisableSelectionEvents();
3041 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3044 iter
.user_data
= (gpointer
) item
.GetID();
3045 gtk_tree_selection_select_iter( selection
, &iter
);
3047 GtkEnableSelectionEvents();
3050 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
3052 GtkDisableSelectionEvents();
3054 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3057 iter
.user_data
= (gpointer
) item
.GetID();
3058 gtk_tree_selection_unselect_iter( selection
, &iter
);
3060 GtkEnableSelectionEvents();
3063 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
3065 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3068 iter
.user_data
= (gpointer
) item
.GetID();
3070 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
3073 void wxDataViewCtrl::SelectAll()
3075 GtkDisableSelectionEvents();
3077 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3079 gtk_tree_selection_select_all( selection
);
3081 GtkEnableSelectionEvents();
3084 void wxDataViewCtrl::UnselectAll()
3086 GtkDisableSelectionEvents();
3088 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3090 gtk_tree_selection_unselect_all( selection
);
3092 GtkEnableSelectionEvents();
3095 void wxDataViewCtrl::EnsureVisible( const wxDataViewItem
& item
, wxDataViewColumn
*column
)
3098 iter
.user_data
= (gpointer
) item
.GetID();
3099 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3100 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
3101 gtk_tree_path_free( path
);
3104 void wxDataViewCtrl::HitTest( const wxPoint
&point
,
3105 wxDataViewItem
&item
, unsigned int &column
) const
3107 item
= wxDataViewItem(0);
3111 wxRect
wxDataViewCtrl::GetItemRect( const wxDataViewItem
&item
,
3112 unsigned int column
) const
3117 void wxDataViewCtrl::DoSetExpanderColumn()
3121 void wxDataViewCtrl::DoSetIndent()
3125 void wxDataViewCtrl::GtkDisableSelectionEvents()
3127 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3128 g_signal_handlers_disconnect_by_func( selection
,
3129 (gpointer
) (wxdataview_selection_changed_callback
), this);
3132 void wxDataViewCtrl::GtkEnableSelectionEvents()
3134 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3135 g_signal_connect_after (selection
, "changed",
3136 G_CALLBACK (wxdataview_selection_changed_callback
), this);
3141 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
3143 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
3148 // !wxUSE_GENERICDATAVIEWCTRL
3151 // wxUSE_DATAVIEWCTRL