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 gtype
= G_TYPE_STRING
;
471 // wxFAIL_MSG( _T("non-string columns not supported yet") );
478 wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
482 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
483 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
484 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
486 return wxtree_model
->internal
->get_iter( iter
, path
);
490 wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
493 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
494 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), NULL
);
495 g_return_val_if_fail (iter
->stamp
== GTK_WX_TREE_MODEL (wxtree_model
)->stamp
, NULL
);
497 return wxtree_model
->internal
->get_path( iter
);
501 wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
506 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
507 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
) );
509 wxDataViewModel
*model
= wxtree_model
->internal
->GetDataViewModel();
510 wxString mtype
= model
->GetColumnType( (unsigned int) column
);
511 if (mtype
== wxT("string"))
514 g_value_init( value
, G_TYPE_STRING
);
515 wxDataViewItem
item( (void*) iter
->user_data
);
516 model
->GetValue( variant
, item
, (unsigned int) column
);
518 g_value_set_string( value
, variant
.GetString().utf8_str() );
522 wxFAIL_MSG( _T("non-string columns not supported yet") );
527 wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
530 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
531 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
532 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
534 return wxtree_model
->internal
->iter_next( iter
);
538 wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
542 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
543 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
544 g_return_val_if_fail (wxtree_model
->stamp
== parent
->stamp
, FALSE
);
546 return wxtree_model
->internal
->iter_children( iter
, parent
);
550 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
553 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
554 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
555 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
557 return wxtree_model
->internal
->iter_has_child( iter
);
561 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
564 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
565 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
566 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, 0);
568 return wxtree_model
->internal
->iter_n_children( iter
);
572 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
577 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
578 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
580 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
584 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
588 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
589 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
590 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
592 return wxtree_model
->internal
->iter_parent( iter
, child
);
596 gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
597 gint
*sort_column_id
,
600 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
602 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
604 if (!tree_model
->internal
->IsSorted())
607 *sort_column_id
= -1;
614 *sort_column_id
= tree_model
->internal
->GetSortColumn();
617 *order
= tree_model
->internal
->GetSortOrder();
622 wxDataViewColumn
*gs_lastLeftClickHeader
= NULL
;
624 void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
628 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
629 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
631 tree_model
->internal
->SetDataViewSortColumn( gs_lastLeftClickHeader
);
633 if ((sort_column_id
!= (gint
) tree_model
->internal
->GetSortColumn()) ||
634 (order
!= tree_model
->internal
->GetSortOrder()))
636 tree_model
->internal
->SetSortColumn( sort_column_id
);
637 tree_model
->internal
->SetSortOrder( order
);
639 gtk_tree_sortable_sort_column_changed (sortable
);
641 tree_model
->internal
->GetDataViewModel()->Resort();
644 if (gs_lastLeftClickHeader
)
646 wxDataViewCtrl
*dv
= tree_model
->internal
->GetOwner();
647 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, dv
->GetId() );
648 event
.SetDataViewColumn( gs_lastLeftClickHeader
);
649 event
.SetModel( dv
->GetModel() );
650 dv
->GetEventHandler()->ProcessEvent( event
);
653 gs_lastLeftClickHeader
= NULL
;
656 void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
658 GtkTreeIterCompareFunc func
,
660 GtkDestroyNotify destroy
)
662 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
663 g_return_if_fail (func
!= NULL
);
666 void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
667 GtkTreeIterCompareFunc func
,
669 GtkDestroyNotify destroy
)
671 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
672 g_return_if_fail (func
!= NULL
);
674 wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
677 gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
)
682 //-----------------------------------------------------------------------------
683 // define new GTK+ class wxGtkRendererRenderer
684 //-----------------------------------------------------------------------------
688 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
689 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
690 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
691 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
692 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
693 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
695 GType
gtk_wx_cell_renderer_get_type (void);
697 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
698 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
700 struct _GtkWxCellRenderer
702 GtkCellRenderer parent
;
705 wxDataViewCustomRenderer
*cell
;
709 struct _GtkWxCellRendererClass
711 GtkCellRendererClass cell_parent_class
;
715 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
716 static void gtk_wx_cell_renderer_init (
717 GtkWxCellRenderer
*cell
);
718 static void gtk_wx_cell_renderer_class_init(
719 GtkWxCellRendererClass
*klass
);
720 static void gtk_wx_cell_renderer_finalize (
722 static void gtk_wx_cell_renderer_get_size (
723 GtkCellRenderer
*cell
,
725 GdkRectangle
*rectangle
,
730 static void gtk_wx_cell_renderer_render (
731 GtkCellRenderer
*cell
,
734 GdkRectangle
*background_area
,
735 GdkRectangle
*cell_area
,
736 GdkRectangle
*expose_area
,
737 GtkCellRendererState flags
);
738 static gboolean
gtk_wx_cell_renderer_activate(
739 GtkCellRenderer
*cell
,
743 GdkRectangle
*background_area
,
744 GdkRectangle
*cell_area
,
745 GtkCellRendererState flags
);
746 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
747 GtkCellRenderer
*cell
,
751 GdkRectangle
*background_area
,
752 GdkRectangle
*cell_area
,
753 GtkCellRendererState flags
);
756 static GObjectClass
*cell_parent_class
= NULL
;
761 gtk_wx_cell_renderer_get_type (void)
763 static GType cell_wx_type
= 0;
767 const GTypeInfo cell_wx_info
=
769 sizeof (GtkWxCellRendererClass
),
770 NULL
, /* base_init */
771 NULL
, /* base_finalize */
772 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
773 NULL
, /* class_finalize */
774 NULL
, /* class_data */
775 sizeof (GtkWxCellRenderer
),
777 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
780 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
781 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
788 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
791 cell
->last_click
= 0;
795 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
797 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
798 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
800 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
802 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
804 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
805 cell_class
->render
= gtk_wx_cell_renderer_render
;
806 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
807 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
811 gtk_wx_cell_renderer_finalize (GObject
*object
)
814 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
818 gtk_wx_cell_renderer_new (void)
820 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
825 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
826 GtkCellRenderer
*renderer
,
830 GdkRectangle
*background_area
,
831 GdkRectangle
*cell_area
,
832 GtkCellRendererState flags
)
834 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
835 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
836 if (!cell
->HasEditorCtrl())
840 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
846 rect
.x
+= cell_area
->x
;
847 rect
.y
+= cell_area
->y
;
848 // rect.width -= renderer->xpad * 2;
849 // rect.height -= renderer->ypad * 2;
851 // wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
852 wxRect
renderrect( cell_area
->x
, cell_area
->y
, cell_area
->width
, cell_area
->height
);
854 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
856 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
857 wxDataViewItem
item( (void*) iter
.user_data
);
858 gtk_tree_path_free( treepath
);
860 cell
->StartEditing( item
, renderrect
);
866 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
868 GdkRectangle
*cell_area
,
874 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
875 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
877 wxSize size
= cell
->GetSize();
879 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
880 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
887 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
891 *x_offset
= (gint
)((renderer
->xalign
*
892 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
893 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
897 *y_offset
= (gint
)((renderer
->yalign
*
898 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
899 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
907 *height
= calc_height
;
911 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
914 GdkRectangle
*background_area
,
915 GdkRectangle
*cell_area
,
916 GdkRectangle
*expose_area
,
917 GtkCellRendererState flags
)
920 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
921 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
924 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
930 rect
.x
+= cell_area
->x
;
931 rect
.y
+= cell_area
->y
;
932 rect
.width
-= renderer
->xpad
* 2;
933 rect
.height
-= renderer
->ypad
* 2;
936 if (gdk_rectangle_intersect (expose_area
, &rect
, &dummy
))
938 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
939 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
940 if (dc
->m_window
== NULL
)
942 dc
->m_window
= window
;
947 if (flags
& GTK_CELL_RENDERER_SELECTED
)
948 state
|= wxDATAVIEW_CELL_SELECTED
;
949 if (flags
& GTK_CELL_RENDERER_PRELIT
)
950 state
|= wxDATAVIEW_CELL_PRELIT
;
951 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
952 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
953 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
954 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
955 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
956 state
|= wxDATAVIEW_CELL_FOCUSED
;
957 cell
->Render( renderrect
, dc
, state
);
962 gtk_wx_cell_renderer_activate(
963 GtkCellRenderer
*renderer
,
967 GdkRectangle
*background_area
,
968 GdkRectangle
*cell_area
,
969 GtkCellRendererState flags
)
971 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
972 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
975 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
981 rect
.x
+= cell_area
->x
;
982 rect
.y
+= cell_area
->y
;
983 rect
.width
-= renderer
->xpad
* 2;
984 rect
.height
-= renderer
->ypad
* 2;
986 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
988 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
990 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
993 gtk_tree_path_free( treepath
);
995 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1001 // activated by <ENTER>
1002 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1007 else if (event
->type
== GDK_BUTTON_PRESS
)
1009 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
1010 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
1011 ((int) button_event
->y
) - renderrect
.y
);
1014 if (button_event
->button
== 1)
1016 if (cell
->LeftClick( pt
, renderrect
, model
, item
, model_col
))
1018 // TODO: query system double-click time
1019 if (button_event
->time
- wxrenderer
->last_click
< 400)
1020 if (cell
->Activate( renderrect
, model
, item
, model_col
))
1023 if (button_event
->button
== 3)
1025 if (cell
->RightClick( pt
, renderrect
, model
, item
, model_col
))
1029 wxrenderer
->last_click
= button_event
->time
;
1037 // ---------------------------------------------------------
1038 // wxGtkDataViewModelNotifier
1039 // ---------------------------------------------------------
1041 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1044 wxGtkDataViewModelNotifier( GtkWxTreeModel
*wxgtk_model
,
1045 wxDataViewModel
*wx_model
,
1046 wxDataViewCtrl
*ctrl
);
1047 ~wxGtkDataViewModelNotifier();
1049 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1050 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1051 virtual bool ItemChanged( const wxDataViewItem
&item
);
1052 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
1053 virtual bool Cleared();
1054 virtual void Resort();
1056 GtkWxTreeModel
*m_wxgtk_model
;
1057 wxDataViewModel
*m_wx_model
;
1058 wxDataViewCtrl
*m_owner
;
1061 // ---------------------------------------------------------
1062 // wxGtkDataViewListModelNotifier
1063 // ---------------------------------------------------------
1065 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1066 GtkWxTreeModel
* wxgtk_model
, wxDataViewModel
*wx_model
,
1067 wxDataViewCtrl
*ctrl
)
1069 m_wxgtk_model
= wxgtk_model
;
1070 m_wx_model
= wx_model
;
1074 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1077 m_wxgtk_model
= NULL
;
1080 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1082 m_owner
->GtkGetInternal()->ItemAdded( parent
, item
);
1085 iter
.stamp
= m_wxgtk_model
->stamp
;
1086 iter
.user_data
= (gpointer
) item
.GetID();
1088 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1089 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1090 gtk_tree_model_row_inserted(
1091 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1092 gtk_tree_path_free (path
);
1097 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1100 iter
.stamp
= m_wxgtk_model
->stamp
;
1101 iter
.user_data
= (gpointer
) item
.GetID();
1103 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1104 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1105 gtk_tree_model_row_deleted(
1106 GTK_TREE_MODEL(m_wxgtk_model
), path
);
1107 gtk_tree_path_free (path
);
1109 m_owner
->GtkGetInternal()->ItemDeleted( parent
, item
);
1114 void wxGtkDataViewModelNotifier::Resort()
1116 m_owner
->GtkGetInternal()->Resort();
1119 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1122 iter
.stamp
= m_wxgtk_model
->stamp
;
1123 iter
.user_data
= (gpointer
) item
.GetID();
1125 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1126 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1127 gtk_tree_model_row_changed(
1128 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1129 gtk_tree_path_free (path
);
1131 m_owner
->GtkGetInternal()->ItemChanged( item
);
1136 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_col
)
1138 // This adds GTK+'s missing MVC logic for ValueChanged
1140 for (index
= 0; index
< m_owner
->GetColumnCount(); index
++)
1142 wxDataViewColumn
*column
= m_owner
->GetColumn( index
);
1143 if (column
->GetModelColumn() == model_col
)
1145 GtkTreeView
*widget
= GTK_TREE_VIEW(m_owner
->m_treeview
);
1146 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1150 iter
.stamp
= m_wxgtk_model
->stamp
;
1151 iter
.user_data
= (gpointer
) item
.GetID();
1152 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1153 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1154 GdkRectangle cell_area
;
1155 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1156 gtk_tree_path_free( path
);
1158 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1159 double d
= gtk_adjustment_get_value( hadjust
);
1160 int xdiff
= (int) d
;
1162 int ydiff
= gcolumn
->button
->allocation
.height
;
1164 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1165 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1167 m_owner
->GtkGetInternal()->ValueChanged( item
, model_col
);
1176 bool wxGtkDataViewModelNotifier::Cleared()
1178 // TODO: delete everything
1180 m_owner
->GtkGetInternal()->Cleared();
1185 // ---------------------------------------------------------
1186 // wxDataViewRenderer
1187 // ---------------------------------------------------------
1189 static gpointer s_user_data
= NULL
;
1192 wxgtk_cell_editable_editing_done( GtkCellEditable
*editable
,
1193 wxDataViewRenderer
*wxrenderer
)
1195 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1196 wxDataViewCtrl
*dv
= column
->GetOwner();
1197 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1198 event
.SetDataViewColumn( column
);
1199 event
.SetModel( dv
->GetModel() );
1200 wxDataViewItem
item( s_user_data
);
1201 event
.SetItem( item
);
1202 dv
->GetEventHandler()->ProcessEvent( event
);
1206 wxgtk_renderer_editing_started( GtkCellRenderer
*cell
, GtkCellEditable
*editable
,
1207 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1209 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1210 wxDataViewCtrl
*dv
= column
->GetOwner();
1211 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1212 event
.SetDataViewColumn( column
);
1213 event
.SetModel( dv
->GetModel() );
1214 GtkTreePath
*tree_path
= gtk_tree_path_new_from_string( path
);
1216 dv
->GtkGetInternal()->get_iter( &iter
, tree_path
);
1217 gtk_tree_path_free( tree_path
);
1218 wxDataViewItem
item( iter
.user_data
);
1219 event
.SetItem( item
);
1220 dv
->GetEventHandler()->ProcessEvent( event
);
1222 if (GTK_IS_CELL_EDITABLE(editable
))
1224 s_user_data
= iter
.user_data
;
1226 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1227 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1228 (gpointer
) wxrenderer
);
1234 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1236 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1238 wxDataViewRendererBase( varianttype
, mode
, align
)
1242 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1243 // after the m_renderer pointer has been initialized
1246 void wxDataViewRenderer::GtkInitHandlers()
1248 if (!gtk_check_version(2,6,0))
1250 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1251 G_CALLBACK (wxgtk_renderer_editing_started
),
1256 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1258 GtkCellRendererMode gtkMode
;
1261 case wxDATAVIEW_CELL_INERT
:
1262 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1264 case wxDATAVIEW_CELL_ACTIVATABLE
:
1265 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1267 case wxDATAVIEW_CELL_EDITABLE
:
1268 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1272 // This value is most often ignored in GtkTreeView
1273 GValue gvalue
= { 0, };
1274 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1275 g_value_set_enum( &gvalue
, gtkMode
);
1276 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1277 g_value_unset( &gvalue
);
1280 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1282 wxDataViewCellMode ret
;
1285 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1287 switch (g_value_get_enum(&gvalue
))
1289 case GTK_CELL_RENDERER_MODE_INERT
:
1290 ret
= wxDATAVIEW_CELL_INERT
;
1292 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1293 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1295 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1296 ret
= wxDATAVIEW_CELL_EDITABLE
;
1300 g_value_unset( &gvalue
);
1305 void wxDataViewRenderer::SetAlignment( int align
)
1307 // horizontal alignment:
1309 gfloat xalign
= 0.0;
1310 if (align
& wxALIGN_RIGHT
)
1312 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1315 GValue gvalue
= { 0, };
1316 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1317 g_value_set_float( &gvalue
, xalign
);
1318 g_object_set_property( G_OBJECT(m_renderer
), "xalign", &gvalue
);
1319 g_value_unset( &gvalue
);
1321 // vertical alignment:
1323 gfloat yalign
= 0.0;
1324 if (align
& wxALIGN_BOTTOM
)
1326 else if (align
& wxALIGN_CENTER_VERTICAL
)
1329 GValue gvalue2
= { 0, };
1330 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1331 g_value_set_float( &gvalue2
, yalign
);
1332 g_object_set_property( G_OBJECT(m_renderer
), "yalign", &gvalue2
);
1333 g_value_unset( &gvalue2
);
1336 int wxDataViewRenderer::GetAlignment() const
1341 // horizontal alignment:
1343 g_object_get( G_OBJECT(m_renderer
), "xalign", &gvalue
, NULL
);
1344 float xalign
= g_value_get_float( &gvalue
);
1346 ret
|= wxALIGN_LEFT
;
1347 else if (xalign
== 0.5)
1348 ret
|= wxALIGN_CENTER_HORIZONTAL
;
1350 ret
|= wxALIGN_RIGHT
;
1351 g_value_unset( &gvalue
);
1354 // vertical alignment:
1356 g_object_get( G_OBJECT(m_renderer
), "yalign", &gvalue
, NULL
);
1357 float yalign
= g_value_get_float( &gvalue
);
1360 else if (yalign
== 0.5)
1361 ret
|= wxALIGN_CENTER_VERTICAL
;
1363 ret
|= wxALIGN_BOTTOM
;
1364 g_value_unset( &gvalue
);
1371 // ---------------------------------------------------------
1372 // wxDataViewTextRenderer
1373 // ---------------------------------------------------------
1376 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1377 gchar
*arg1
, gchar
*arg2
, gpointer user_data
);
1380 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1381 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1383 wxDataViewTextRenderer
*cell
= (wxDataViewTextRenderer
*) user_data
;
1385 wxString tmp
= wxGTK_CONV_BACK_FONT(arg2
, cell
->GetOwner()->GetOwner()->GetFont());
1386 wxVariant value
= tmp
;
1387 if (!cell
->Validate( value
))
1390 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1392 GtkTreePath
*path
= gtk_tree_path_new_from_string( arg1
);
1394 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, path
);
1395 wxDataViewItem
item( (void*) iter
.user_data
);;
1396 gtk_tree_path_free( path
);
1398 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1400 model
->SetValue( value
, item
, model_col
);
1401 model
->ValueChanged( item
, model_col
);
1404 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
1406 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1408 wxDataViewRenderer( varianttype
, mode
, align
)
1410 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_text_new();
1412 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
1414 GValue gvalue
= { 0, };
1415 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1416 g_value_set_boolean( &gvalue
, true );
1417 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
1418 g_value_unset( &gvalue
);
1420 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
1426 SetAlignment(align
);
1429 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
1431 wxString tmp
= value
;
1433 GValue gvalue
= { 0, };
1434 g_value_init( &gvalue
, G_TYPE_STRING
);
1435 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( tmp
, GetOwner()->GetOwner()->GetFont() ) );
1436 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1437 g_value_unset( &gvalue
);
1442 bool wxDataViewTextRenderer::GetValue( wxVariant
&value
) const
1444 GValue gvalue
= { 0, };
1445 g_value_init( &gvalue
, G_TYPE_STRING
);
1446 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1447 wxString tmp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
),
1448 wx_const_cast(wxDataViewTextRenderer
*, this)->GetOwner()->GetOwner()->GetFont() );
1449 g_value_unset( &gvalue
);
1456 void wxDataViewTextRenderer::SetAlignment( int align
)
1458 wxDataViewRenderer::SetAlignment(align
);
1460 if (gtk_check_version(2,10,0))
1463 // horizontal alignment:
1464 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
1465 if (align
& wxALIGN_RIGHT
)
1466 pangoAlign
= PANGO_ALIGN_RIGHT
;
1467 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1468 pangoAlign
= PANGO_ALIGN_CENTER
;
1470 GValue gvalue
= { 0, };
1471 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1472 g_value_set_enum( &gvalue
, pangoAlign
);
1473 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
1474 g_value_unset( &gvalue
);
1477 // ---------------------------------------------------------
1478 // wxDataViewBitmapRenderer
1479 // ---------------------------------------------------------
1481 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
1483 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1485 wxDataViewRenderer( varianttype
, mode
, align
)
1487 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_pixbuf_new();
1490 SetAlignment(align
);
1493 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
1495 if (value
.GetType() == wxT("wxBitmap"))
1500 // This may create a Pixbuf representation in the
1501 // wxBitmap object (and it will stay there)
1502 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1504 GValue gvalue
= { 0, };
1505 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1506 g_value_set_object( &gvalue
, pixbuf
);
1507 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1508 g_value_unset( &gvalue
);
1513 if (value
.GetType() == wxT("wxIcon"))
1518 // This may create a Pixbuf representation in the
1519 // wxBitmap object (and it will stay there)
1520 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1522 GValue gvalue
= { 0, };
1523 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1524 g_value_set_object( &gvalue
, pixbuf
);
1525 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1526 g_value_unset( &gvalue
);
1534 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&value
) const
1539 // ---------------------------------------------------------
1540 // wxDataViewToggleRenderer
1541 // ---------------------------------------------------------
1544 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1545 gchar
*path
, gpointer user_data
);
1548 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1549 gchar
*path
, gpointer user_data
)
1551 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
1554 GValue gvalue
= { 0, };
1555 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1556 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
1557 bool tmp
= g_value_get_boolean( &gvalue
);
1558 g_value_unset( &gvalue
);
1562 wxVariant value
= tmp
;
1563 if (!cell
->Validate( value
))
1566 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1568 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
1570 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, gtk_path
);
1571 wxDataViewItem
item( (void*) iter
.user_data
);;
1572 gtk_tree_path_free( gtk_path
);
1574 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1576 model
->SetValue( value
, item
, model_col
);
1577 model
->ValueChanged( item
, model_col
);
1580 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1582 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1583 wxDataViewCellMode mode
, int align
) :
1584 wxDataViewRenderer( varianttype
, mode
, align
)
1586 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
1588 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1590 g_signal_connect_after( m_renderer
, "toggled",
1591 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
1595 GValue gvalue
= { 0, };
1596 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1597 g_value_set_boolean( &gvalue
, false );
1598 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
1599 g_value_unset( &gvalue
);
1603 SetAlignment(align
);
1606 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1610 GValue gvalue
= { 0, };
1611 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1612 g_value_set_boolean( &gvalue
, tmp
);
1613 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1614 g_value_unset( &gvalue
);
1619 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
1621 GValue gvalue
= { 0, };
1622 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1623 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1624 bool tmp
= g_value_get_boolean( &gvalue
);
1625 g_value_unset( &gvalue
);
1632 // ---------------------------------------------------------
1633 // wxDataViewCustomRenderer
1634 // ---------------------------------------------------------
1636 class wxDataViewCtrlDC
: public wxWindowDC
1639 wxDataViewCtrlDC( wxDataViewCtrl
*window
)
1641 GtkWidget
*widget
= window
->m_treeview
;
1645 m_context
= window
->GtkGetPangoDefaultContext();
1646 m_layout
= pango_layout_new( m_context
);
1647 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
1649 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
1651 // Set m_window later
1653 // m_owner = window;
1657 // ---------------------------------------------------------
1658 // wxDataViewCustomRenderer
1659 // ---------------------------------------------------------
1661 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
1663 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
1664 wxDataViewCellMode mode
, int align
,
1666 wxDataViewRenderer( varianttype
, mode
, align
)
1676 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
1678 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
1679 renderer
->cell
= this;
1681 m_renderer
= (GtkCellRenderer
*) renderer
;
1684 SetAlignment(align
);
1691 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
1697 wxDC
*wxDataViewCustomRenderer::GetDC()
1701 if (GetOwner() == NULL
)
1703 if (GetOwner()->GetOwner() == NULL
)
1705 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
1711 // ---------------------------------------------------------
1712 // wxDataViewProgressRenderer
1713 // ---------------------------------------------------------
1715 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
1717 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
1718 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1719 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
1725 if (!gtk_check_version(2,6,0))
1727 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
1729 GValue gvalue
= { 0, };
1730 g_value_init( &gvalue
, G_TYPE_STRING
);
1732 // FIXME: font encoding support
1733 g_value_set_string( &gvalue
, wxGTK_CONV_SYS(m_label
) );
1734 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1735 g_value_unset( &gvalue
);
1738 SetAlignment(align
);
1743 // Use custom cell code
1744 wxDataViewCustomRenderer::Init(mode
, align
);
1748 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
1752 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
1755 if (!gtk_check_version(2,6,0))
1757 gint tmp
= (long) value
;
1758 GValue gvalue
= { 0, };
1759 g_value_init( &gvalue
, G_TYPE_INT
);
1760 g_value_set_int( &gvalue
, tmp
);
1761 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
1762 g_value_unset( &gvalue
);
1767 m_value
= (long) value
;
1769 if (m_value
< 0) m_value
= 0;
1770 if (m_value
> 100) m_value
= 100;
1776 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
1781 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1783 double pct
= (double)m_value
/ 100.0;
1785 bar
.width
= (int)(cell
.width
* pct
);
1786 dc
->SetPen( *wxTRANSPARENT_PEN
);
1787 dc
->SetBrush( *wxBLUE_BRUSH
);
1788 dc
->DrawRectangle( bar
);
1790 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1791 dc
->SetPen( *wxBLACK_PEN
);
1792 dc
->DrawRectangle( cell
);
1797 wxSize
wxDataViewProgressRenderer::GetSize() const
1799 return wxSize(40,12);
1802 // ---------------------------------------------------------
1803 // wxDataViewDateRenderer
1804 // ---------------------------------------------------------
1806 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
1809 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
1810 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
1811 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
1816 m_cal
= new wxCalendarCtrl( this, -1, *value
);
1817 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
1818 sizer
->Add( m_cal
, 1, wxGROW
);
1823 virtual void OnDismiss()
1827 void OnCalendar( wxCalendarEvent
&event
);
1829 wxCalendarCtrl
*m_cal
;
1830 wxDataViewModel
*m_model
;
1831 wxDataViewItem m_item
;
1835 DECLARE_EVENT_TABLE()
1838 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
1839 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
1842 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
1844 wxDateTime date
= event
.GetDate();
1845 wxVariant value
= date
;
1846 m_model
->SetValue( value
, m_item
, m_col
);
1847 m_model
->ValueChanged( m_item
, m_col
);
1851 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
1853 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1854 wxDataViewCellMode mode
, int align
) :
1855 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1858 SetAlignment(align
);
1861 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1863 m_date
= value
.GetDateTime();
1868 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
1873 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1875 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
1876 wxString tmp
= m_date
.FormatDate();
1877 dc
->DrawText( tmp
, cell
.x
, cell
.y
);
1882 wxSize
wxDataViewDateRenderer::GetSize() const
1884 wxString tmp
= m_date
.FormatDate();
1886 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
1887 return wxSize(x
,y
+d
);
1890 bool wxDataViewDateRenderer::Activate( wxRect cell
, wxDataViewModel
*model
,
1891 const wxDataViewItem
&item
, unsigned int col
)
1894 model
->GetValue( variant
, item
, col
);
1895 wxDateTime value
= variant
.GetDateTime();
1897 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1898 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
1899 wxPoint pos
= wxGetMousePosition();
1902 popup
->Popup( popup
->m_cal
);
1908 // ---------------------------------------------------------
1909 // wxDataViewIconTextRenderer
1910 // ---------------------------------------------------------
1912 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
1914 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
1915 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1916 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1919 SetAlignment(align
);
1922 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
1926 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
1932 bool wxDataViewIconTextRenderer::GetValue( wxVariant
&value
) const
1937 bool wxDataViewIconTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1939 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
1941 const wxIcon
&icon
= m_value
.GetIcon();
1944 dc
->DrawIcon( icon
, cell
.x
, cell
.y
); // TODO centre
1945 cell
.x
+= icon
.GetWidth()+4;
1948 dc
->DrawText( m_value
.GetText(), cell
.x
, cell
.y
);
1953 wxSize
wxDataViewIconTextRenderer::GetSize() const
1955 return wxSize(80,16); // TODO
1958 wxControl
* wxDataViewIconTextRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1963 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1968 // ---------------------------------------------------------
1970 // ---------------------------------------------------------
1974 gtk_dataview_header_button_press_callback( GtkWidget
*widget
,
1975 GdkEventButton
*gdk_event
,
1976 wxDataViewColumn
*column
)
1978 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
1981 if (gdk_event
->button
== 1)
1983 gs_lastLeftClickHeader
= column
;
1985 wxDataViewCtrl
*dv
= column
->GetOwner();
1986 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
1987 event
.SetDataViewColumn( column
);
1988 event
.SetModel( dv
->GetModel() );
1989 if (dv
->GetEventHandler()->ProcessEvent( event
))
1993 if (gdk_event
->button
== 3)
1995 wxDataViewCtrl
*dv
= column
->GetOwner();
1996 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, dv
->GetId() );
1997 event
.SetDataViewColumn( column
);
1998 event
.SetModel( dv
->GetModel() );
1999 if (dv
->GetEventHandler()->ProcessEvent( event
))
2007 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
2008 GtkCellRenderer
*cell
,
2009 GtkTreeModel
*model
,
2015 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
2016 GtkCellRenderer
*renderer
,
2017 GtkTreeModel
*model
,
2021 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
2022 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
2024 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2026 wxDataViewItem
item( (void*) iter
->user_data
);
2028 wxDataViewModel
*wx_model
= tree_model
->internal
->GetDataViewModel();
2030 if (wx_model
->IsContainer( item
))
2032 if (wx_model
->HasContainerColumns( item
) || (cell
->GetOwner()->GetModelColumn() == 0))
2034 GValue gvalue
= { 0, };
2035 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2036 g_value_set_boolean( &gvalue
, TRUE
);
2037 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2038 g_value_unset( &gvalue
);
2042 GValue gvalue
= { 0, };
2043 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2044 g_value_set_boolean( &gvalue
, FALSE
);
2045 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2046 g_value_unset( &gvalue
);
2053 GValue gvalue
= { 0, };
2054 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2055 g_value_set_boolean( &gvalue
, TRUE
);
2056 g_object_set_property( G_OBJECT(renderer
), "visible", &gvalue
);
2057 g_value_unset( &gvalue
);
2061 wx_model
->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
2063 if (value
.GetType() != cell
->GetVariantType())
2064 wxLogError( wxT("Wrong type, required: %s but: %s"),
2065 value
.GetType().c_str(),
2066 cell
->GetVariantType().c_str() );
2068 cell
->SetValue( value
);
2071 wxListItemAttr attr
;
2072 wx_model
->GetAttr( item
, attr
, cell
->GetOwner()->GetModelColumn() );
2074 if (attr
.HasBackgroundColour())
2076 wxColour colour
= attr
.GetBackgroundColour();
2077 const GdkColor
* const gcol
= colour
.GetColor();
2079 GValue gvalue
= { 0, };
2080 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2081 g_value_set_boxed( &gvalue
, gcol
);
2082 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
2083 g_value_unset( &gvalue
);
2087 GValue gvalue
= { 0, };
2088 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2089 g_value_set_boolean( &gvalue
, FALSE
);
2090 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
2091 g_value_unset( &gvalue
);
2097 IMPLEMENT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
2099 #include <wx/listimpl.cpp>
2100 WX_DEFINE_LIST(wxDataViewColumnList
);
2102 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
2103 unsigned int model_column
, int width
,
2104 wxAlignment align
, int flags
) :
2105 wxDataViewColumnBase( title
, cell
, model_column
, width
, align
, flags
)
2107 Init( align
, flags
, width
);
2109 gtk_tree_view_column_set_clickable( GTK_TREE_VIEW_COLUMN(m_column
), TRUE
);
2113 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
2114 unsigned int model_column
, int width
,
2115 wxAlignment align
, int flags
) :
2116 wxDataViewColumnBase( bitmap
, cell
, model_column
, width
, align
, flags
)
2118 Init( align
, flags
, width
);
2120 SetBitmap( bitmap
);
2123 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
2125 m_isConnected
= false;
2127 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) GetRenderer()->GetGtkHandle();
2128 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
2129 m_column
= (GtkWidget
*) column
;
2132 SetAlignment( align
);
2134 // NOTE: we prefer not to call SetMinWidth(wxDVC_DEFAULT_MINWIDTH);
2135 // as GTK+ is smart and unless explicitely told, will set the minimal
2136 // width to the title's lenght, which is a better default
2138 // the GTK_TREE_VIEW_COLUMN_FIXED is required by the "fixed height" mode
2139 // that we use for the wxDataViewCtrl
2140 gtk_tree_view_column_set_fixed_width( column
, width
< 0 ? wxDVC_DEFAULT_WIDTH
: width
);
2141 gtk_tree_view_column_set_sizing( column
, GTK_TREE_VIEW_COLUMN_FIXED
);
2143 gtk_tree_view_column_pack_end( column
, renderer
, TRUE
);
2145 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
2146 wxGtkTreeCellDataFunc
, (gpointer
) GetRenderer(), NULL
);
2149 wxDataViewColumn::~wxDataViewColumn()
2153 void wxDataViewColumn::OnInternalIdle()
2158 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
2160 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2163 g_signal_connect(column
->button
, "button_press_event",
2164 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
2166 m_isConnected
= true;
2171 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
2173 wxDataViewColumnBase::SetOwner( owner
);
2175 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2177 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
2180 void wxDataViewColumn::SetTitle( const wxString
&title
)
2182 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2186 // disconnect before column->button gets recreated
2187 g_signal_handlers_disconnect_by_func( column
->button
,
2188 (GtkWidget
*) gtk_dataview_header_button_press_callback
, this);
2190 m_isConnected
= false;
2193 // FIXME: can it really happen that we don't have the owner here??
2194 wxDataViewCtrl
*ctrl
= GetOwner();
2195 gtk_tree_view_column_set_title( column
, ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
2196 : wxGTK_CONV_SYS(title
) );
2198 gtk_tree_view_column_set_widget( column
, NULL
);
2201 wxString
wxDataViewColumn::GetTitle() const
2203 const gchar
*str
= gtk_tree_view_column_get_title( GTK_TREE_VIEW_COLUMN(m_column
) );
2204 return wxConvFileName
->cMB2WX(str
);
2207 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
2209 wxDataViewColumnBase::SetBitmap( bitmap
);
2211 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2214 GtkImage
*gtk_image
= GTK_IMAGE( gtk_image_new() );
2216 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
2217 if (bitmap
.GetMask())
2218 mask
= bitmap
.GetMask()->GetBitmap();
2220 if (bitmap
.HasPixbuf())
2222 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
2223 bitmap
.GetPixbuf());
2227 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
2228 bitmap
.GetPixmap(), mask
);
2230 gtk_widget_show( GTK_WIDGET(gtk_image
) );
2232 gtk_tree_view_column_set_widget( column
, GTK_WIDGET(gtk_image
) );
2236 gtk_tree_view_column_set_widget( column
, NULL
);
2240 void wxDataViewColumn::SetHidden( bool hidden
)
2242 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
2245 void wxDataViewColumn::SetResizeable( bool resizeable
)
2247 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizeable
);
2250 void wxDataViewColumn::SetAlignment( wxAlignment align
)
2252 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2254 gfloat xalign
= 0.0;
2255 if (align
== wxALIGN_RIGHT
)
2257 if (align
== wxALIGN_CENTER_HORIZONTAL
||
2258 align
== wxALIGN_CENTER
)
2261 gtk_tree_view_column_set_alignment( column
, xalign
);
2264 wxAlignment
wxDataViewColumn::GetAlignment() const
2266 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
2269 return wxALIGN_RIGHT
;
2271 return wxALIGN_CENTER_HORIZONTAL
;
2273 return wxALIGN_LEFT
;
2276 void wxDataViewColumn::SetSortable( bool sortable
)
2278 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2282 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
2286 gtk_tree_view_column_set_sort_column_id( column
, -1 );
2287 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
2291 bool wxDataViewColumn::IsSortable() const
2293 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2294 return (gtk_tree_view_column_get_sort_column_id( column
) != -1);
2297 bool wxDataViewColumn::IsResizeable() const
2299 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2300 return gtk_tree_view_column_get_resizable( column
);
2303 bool wxDataViewColumn::IsHidden() const
2305 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2306 return !gtk_tree_view_column_get_visible( column
);
2309 void wxDataViewColumn::SetSortOrder( bool ascending
)
2311 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2314 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
2316 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
2318 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
2321 bool wxDataViewColumn::IsSortOrderAscending() const
2323 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2325 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
2328 void wxDataViewColumn::SetMinWidth( int width
)
2330 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2333 int wxDataViewColumn::GetMinWidth() const
2335 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2338 int wxDataViewColumn::GetWidth() const
2340 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2343 void wxDataViewColumn::SetWidth( int width
)
2345 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2349 //-----------------------------------------------------------------------------
2350 // wxGtkTreeModelNode
2351 //-----------------------------------------------------------------------------
2353 void wxGtkTreeModelNode::Resort()
2355 size_t child_count
= GetChildCount();
2356 if (child_count
== 0)
2359 size_t node_count
= GetNodesCount();
2361 if (child_count
== 1)
2363 if (node_count
== 1)
2365 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
2371 wxGtkTreeModelChildren temp
;
2372 WX_APPEND_ARRAY( temp
, m_children
);
2374 g_internal
= m_internal
;
2375 m_children
.Sort( &wxGtkTreeModelChildCmp
);
2377 gint
*new_order
= new gint
[child_count
];
2380 for (pos
= 0; pos
< child_count
; pos
++)
2382 void *id
= m_children
.Item( pos
);
2383 int old_pos
= temp
.Index( id
);
2384 new_order
[pos
] = old_pos
;
2387 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
2390 iter
.user_data
= GetItem().GetID();
2391 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
2393 GtkTreePath
*path
= m_internal
->get_path( &iter
);
2395 gtk_tree_model_rows_reordered( gtk_tree_model
, path
, &iter
, new_order
);
2397 gtk_tree_path_free (path
);
2399 delete [] new_order
;
2401 for (pos
= 0; pos
< node_count
; pos
++)
2403 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
2408 //-----------------------------------------------------------------------------
2409 // wxDataViewCtrlInternal
2410 //-----------------------------------------------------------------------------
2412 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
,
2413 wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
)
2416 m_wx_model
= wx_model
;
2417 m_gtk_model
= gtk_model
;
2419 m_sort_order
= GTK_SORT_ASCENDING
;
2421 m_dataview_sort_column
= NULL
;
2425 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
2427 g_object_unref( m_gtk_model
);
2430 void wxDataViewCtrlInternal::InitTree()
2432 wxDataViewItem item
;
2433 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
2435 BuildBranch( m_root
);
2438 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
2440 if (node
->GetChildCount() == 0)
2442 wxDataViewItemArray children
;
2443 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
2445 for (pos
= 0; pos
< count
; pos
++)
2447 wxDataViewItem child
= children
[pos
];
2449 if (m_wx_model
->IsContainer( child
))
2450 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
2452 node
->AddLeave( child
.GetID() );
2454 // Don't send any events here
2459 void wxDataViewCtrlInternal::Resort()
2464 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
2466 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2467 if (m_wx_model
->IsContainer( item
))
2468 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
2470 parent_node
->AddLeave( item
.GetID() );
2475 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
2477 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2478 parent_node
->DeleteChild( item
.GetID() );
2483 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
2485 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
2486 event
.SetEventObject( m_owner
);
2487 event
.SetModel( m_owner
->GetModel() );
2488 event
.SetItem( item
);
2489 m_owner
->GetEventHandler()->ProcessEvent( event
);
2494 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
2496 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, m_owner
->GetId() );
2497 event
.SetEventObject( m_owner
);
2498 event
.SetModel( m_owner
->GetModel() );
2499 event
.SetColumn( col
);
2500 event
.SetDataViewColumn( GetOwner()->GetColumn(col
) );
2501 event
.SetItem( item
);
2502 m_owner
->GetEventHandler()->ProcessEvent( event
);
2507 bool wxDataViewCtrlInternal::Cleared()
2512 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
2514 int depth
= gtk_tree_path_get_depth( path
);
2516 wxGtkTreeModelNode
*node
= m_root
;
2519 for (i
= 0; i
< depth
; i
++)
2521 BuildBranch( node
);
2523 gint pos
= gtk_tree_path_get_indices (path
)[i
];
2524 if (pos
< 0) return FALSE
;
2525 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
2527 void* id
= node
->GetChildren().Item( (size_t) pos
);
2531 iter
->stamp
= m_gtk_model
->stamp
;
2532 iter
->user_data
= id
;
2536 size_t count
= node
->GetNodes().GetCount();
2538 for (pos2
= 0; pos2
< count
; pos2
++)
2540 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
2541 if (child_node
->GetItem().GetID() == id
)
2552 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
2554 GtkTreePath
*retval
= gtk_tree_path_new ();
2555 void *id
= iter
->user_data
;
2557 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
2560 int pos
= node
->GetChildren().Index( id
);
2562 gtk_tree_path_prepend_index( retval
, pos
);
2564 id
= node
->GetItem().GetID();
2565 node
= node
->GetParent();
2571 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
2573 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
2574 if( parent
== NULL
)
2577 int pos
= parent
->GetChildren().Index( iter
->user_data
);
2579 if (pos
== (int) parent
->GetChildCount()-1)
2582 iter
->stamp
= m_gtk_model
->stamp
;
2583 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
2588 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
2590 wxDataViewItem
item( (void*) parent
->user_data
);
2592 if (!m_wx_model
->IsContainer( item
))
2595 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2596 BuildBranch( parent_node
);
2598 if (parent_node
->GetChildCount() == 0)
2601 iter
->stamp
= m_gtk_model
->stamp
;
2602 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
2607 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
2609 wxDataViewItem
item( (void*) iter
->user_data
);
2611 bool is_container
= m_wx_model
->IsContainer( item
);
2616 wxGtkTreeModelNode
*node
= FindNode( iter
);
2617 BuildBranch( node
);
2619 return (node
->GetChildCount() > 0);
2622 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
2624 wxDataViewItem
item( (void*) iter
->user_data
);
2626 if (!m_wx_model
->IsContainer( item
))
2629 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
2630 BuildBranch( parent_node
);
2632 // wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() );
2634 return parent_node
->GetChildCount();
2637 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
2640 if (parent
) id
= (void*) parent
->user_data
;
2641 wxDataViewItem
item( id
);
2643 if (!m_wx_model
->IsContainer( item
))
2646 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2647 BuildBranch( parent_node
);
2649 // wxPrintf( "iter_nth_child %d\n", n );
2651 iter
->stamp
= m_gtk_model
->stamp
;
2652 iter
->user_data
= parent_node
->GetChildren().Item( n
);
2657 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
2659 wxGtkTreeModelNode
*node
= FindParentNode( child
);
2663 iter
->stamp
= m_gtk_model
->stamp
;
2664 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
2669 static wxGtkTreeModelNode
*
2670 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
2676 list
.DeleteContents( true );
2677 wxDataViewItem
it( item
);
2681 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
2682 list
.Insert( pItem
);
2683 it
= model
->GetParent( it
);
2686 wxGtkTreeModelNode
* node
= treeNode
;
2687 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
2689 if( node
&& node
->GetNodes().GetCount() != 0 )
2691 int len
= node
->GetNodes().GetCount();
2692 wxGtkTreeModelNodes nodes
= node
->GetNodes();
2694 for( ; j
< len
; j
++)
2696 if( nodes
[j
]->GetItem() == *(n
->GetData()))
2715 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
2720 wxDataViewItem
item( (void*) iter
->user_data
);
2724 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
2728 wxLogDebug( "Not found %p", iter
->user_data
);
2736 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
2741 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
2745 wxLogDebug( "Not found %p", item
.GetID() );
2753 static wxGtkTreeModelNode
*
2754 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
2760 list
.DeleteContents( true );
2764 wxDataViewItem
it( model
->GetParent( item
) );
2767 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
2768 list
.Insert( pItem
);
2769 it
= model
->GetParent( it
);
2772 wxGtkTreeModelNode
* node
= treeNode
;
2773 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
2775 if( node
&& node
->GetNodes().GetCount() != 0 )
2777 int len
= node
->GetNodes().GetCount();
2778 wxGtkTreeModelNodes nodes
= node
->GetNodes();
2780 for( ; j
< len
; j
++)
2782 if( nodes
[j
]->GetItem() == *(n
->GetData()))
2797 //Examine whether the node is item's parent node
2798 int len
= node
->GetChildCount();
2799 for( int i
= 0; i
< len
; i
++ )
2801 if( node
->GetChildren().Item( i
) == item
.GetID() )
2807 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
2812 wxDataViewItem
item( (void*) iter
->user_data
);
2816 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
2819 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
2824 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
2827 //-----------------------------------------------------------------------------
2828 // wxDataViewCtrl signal callbacks
2829 //-----------------------------------------------------------------------------
2832 wxdataview_selection_changed_callback( GtkTreeSelection
* selection
, wxDataViewCtrl
*dv
)
2834 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
2837 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, dv
->GetId() );
2838 event
.SetItem( dv
->GetSelection() );
2839 event
.SetModel( dv
->GetModel() );
2840 dv
->GetEventHandler()->ProcessEvent( event
);
2844 wxdataview_row_activated_callback( GtkTreeView
* treeview
, GtkTreePath
*path
,
2845 GtkTreeViewColumn
*column
, wxDataViewCtrl
*dv
)
2847 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
2850 dv
->GtkGetInternal()->get_iter( &iter
, path
);
2851 wxDataViewItem
item( (void*) iter
.user_data
);;
2852 event
.SetItem( item
);
2853 event
.SetModel( dv
->GetModel() );
2854 dv
->GetEventHandler()->ProcessEvent( event
);
2858 wxdataview_test_expand_row_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
2859 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
2861 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
2863 wxDataViewItem
item( (void*) iter
->user_data
);;
2864 event
.SetItem( item
);
2865 event
.SetModel( dv
->GetModel() );
2866 dv
->GetEventHandler()->ProcessEvent( event
);
2868 return !event
.IsAllowed();
2872 wxdataview_row_expanded_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
2873 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
2875 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
2877 wxDataViewItem
item( (void*) iter
->user_data
);;
2878 event
.SetItem( item
);
2879 event
.SetModel( dv
->GetModel() );
2880 dv
->GetEventHandler()->ProcessEvent( event
);
2884 wxdataview_test_collapse_row_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
2885 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
2887 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
2889 wxDataViewItem
item( (void*) iter
->user_data
);;
2890 event
.SetItem( item
);
2891 event
.SetModel( dv
->GetModel() );
2892 dv
->GetEventHandler()->ProcessEvent( event
);
2894 return !event
.IsAllowed();
2898 wxdataview_row_collapsed_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
2899 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
2901 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
2903 wxDataViewItem
item( (void*) iter
->user_data
);;
2904 event
.SetItem( item
);
2905 event
.SetModel( dv
->GetModel() );
2906 dv
->GetEventHandler()->ProcessEvent( event
);
2909 //-----------------------------------------------------------------------------
2911 //-----------------------------------------------------------------------------
2913 //-----------------------------------------------------------------------------
2914 // InsertChild for wxDataViewCtrl
2915 //-----------------------------------------------------------------------------
2917 static void wxInsertChildInDataViewCtrl( wxWindowGTK
* parent
, wxWindowGTK
* child
)
2919 wxDataViewCtrl
* dvc
= (wxDataViewCtrl
*) parent
;
2920 GtkWidget
*treeview
= dvc
->GtkGetTreeView();
2922 // Insert widget in GtkTreeView
2923 if (GTK_WIDGET_REALIZED(treeview
))
2924 gtk_widget_set_parent_window( child
->m_widget
,
2925 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
2926 gtk_widget_set_parent( child
->m_widget
, treeview
);
2930 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
2931 GtkAllocation
*alloc
,
2932 wxDataViewCtrl
*win
)
2934 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
2937 wxWindow
*child
= node
->GetData();
2940 gtk_widget_size_request( child
->m_widget
, &req
);
2942 GtkAllocation alloc
;
2943 alloc
.x
= child
->m_x
;
2944 alloc
.y
= child
->m_y
;
2945 alloc
.width
= child
->m_width
;
2946 alloc
.height
= child
->m_height
;
2947 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
2949 node
= node
->GetNext();
2954 //-----------------------------------------------------------------------------
2955 // "motion_notify_event"
2956 //-----------------------------------------------------------------------------
2959 gtk_dataview_motion_notify_callback( GtkWidget
*widget
,
2960 GdkEventMotion
*gdk_event
,
2961 wxDataViewCtrl
*dv
)
2963 if (gdk_event
->is_hint
)
2967 GdkModifierType state
;
2968 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
2973 GtkTreePath
*path
= NULL
;
2974 GtkTreeViewColumn
*column
= NULL
;
2977 if (gtk_tree_view_get_path_at_pos(
2978 GTK_TREE_VIEW(dv
->GtkGetTreeView()),
2979 (int) gdk_event
->x
, (int) gdk_event
->y
,
2988 dv
->GtkGetInternal()->get_iter( &iter
, path
);
2990 // wxPrintf( "mouse %d %d\n", (int) gdk_event->x, (int) gdk_event->y );
2992 gtk_tree_path_free( path
);
3001 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
3003 wxDataViewCtrl::~wxDataViewCtrl()
3006 GetModel()->RemoveNotifier( m_notifier
);
3008 // remove the model from the GtkTreeView before it gets destroyed by the
3009 // wxDataViewCtrlBase's dtor
3010 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), NULL
);
3015 void wxDataViewCtrl::Init()
3020 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
3021 const wxPoint
& pos
, const wxSize
& size
,
3022 long style
, const wxValidator
& validator
)
3026 if (!PreCreation( parent
, pos
, size
) ||
3027 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
3029 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
3033 m_insertCallback
= wxInsertChildInDataViewCtrl
;
3035 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
3037 GtkScrolledWindowSetBorder(m_widget
, style
);
3039 m_treeview
= gtk_tree_view_new();
3040 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
3042 g_signal_connect (m_treeview
, "size_allocate",
3043 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
3046 if (!gtk_check_version(2,6,0))
3047 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), TRUE
);
3050 if (style
& wxDV_MULTIPLE
)
3052 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3053 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
3056 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
3059 if (!gtk_check_version(2,10,0))
3061 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
3063 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
3064 (style
& wxDV_VERT_RULES
) != 0)
3065 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
3066 else if (style
& wxDV_VERT_RULES
)
3067 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
3068 else if (style
& wxDV_HORIZ_RULES
)
3069 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
3071 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
3076 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_HORIZ_RULES
) != 0 );
3079 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
3080 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
3081 gtk_widget_show (m_treeview
);
3083 m_parent
->DoAddChild( this );
3087 GtkEnableSelectionEvents();
3089 g_signal_connect_after (m_treeview
, "row-activated",
3090 G_CALLBACK (wxdataview_row_activated_callback
), this);
3092 g_signal_connect (m_treeview
, "test-collapse-row",
3093 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
3095 g_signal_connect_after (m_treeview
, "row-collapsed",
3096 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
3098 g_signal_connect (m_treeview
, "test-expand-row",
3099 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
3101 g_signal_connect_after (m_treeview
, "row-expanded",
3102 G_CALLBACK (wxdataview_row_expanded_callback
), this);
3104 g_signal_connect (m_treeview
, "motion_notify_event",
3105 G_CALLBACK (gtk_dataview_motion_notify_callback
), this);
3110 void wxDataViewCtrl::OnInternalIdle()
3112 wxWindow::OnInternalIdle();
3114 unsigned int cols
= GetColumnCount();
3116 for (i
= 0; i
< cols
; i
++)
3118 wxDataViewColumn
*col
= GetColumn( i
);
3119 col
->OnInternalIdle();
3123 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
3125 if (!wxDataViewCtrlBase::AssociateModel( model
))
3128 GtkWxTreeModel
*gtk_model
= wxgtk_tree_model_new();
3129 m_internal
= new wxDataViewCtrlInternal( this, model
, gtk_model
);
3130 gtk_model
->internal
= m_internal
;
3132 m_notifier
= new wxGtkDataViewModelNotifier( gtk_model
, model
, this );
3134 model
->AddNotifier( m_notifier
);
3136 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_model
) );
3138 // unref in wxDataViewCtrlInternal
3139 // g_object_unref( gtk_model );
3144 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
3146 if (!wxDataViewCtrlBase::AppendColumn(col
))
3149 m_cols
.Append( col
);
3151 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
3152 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
3157 unsigned int wxDataViewCtrl::GetColumnCount() const
3159 return m_cols
.GetCount();
3162 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
3164 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
3168 wxDataViewColumnList::const_iterator iter
;
3169 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); iter
++)
3171 wxDataViewColumn
*col
= *iter
;
3172 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
3181 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
3183 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
3184 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
3186 m_cols
.remove( column
);
3193 bool wxDataViewCtrl::ClearColumns()
3195 wxDataViewColumnList::iterator iter
;
3196 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); iter
++)
3198 wxDataViewColumn
*col
= *iter
;
3199 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
3200 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
3208 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
3210 GtkTreeViewColumn
*gtk_column
= GTK_TREE_VIEW_COLUMN(column
->GetConstGtkHandle());
3212 GList
*list
= gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview
) );
3214 gint pos
= g_list_index( list
, (gconstpointer
) gtk_column
);
3216 g_list_free( list
);
3221 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
3223 return m_internal
->GetDataViewSortColumn();
3226 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
3229 iter
.user_data
= item
.GetID();
3230 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3231 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
3232 gtk_tree_path_free( path
);
3235 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
3238 iter
.user_data
= item
.GetID();
3239 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3240 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
3241 gtk_tree_path_free( path
);
3244 wxDataViewItem
wxDataViewCtrl::GetSelection() const
3246 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3248 if (m_windowStyle
& wxDV_MULTIPLE
)
3250 // Report the first one
3251 GtkTreeModel
*model
;
3252 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
3256 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
3258 m_internal
->get_iter( &iter
, path
);
3261 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
3262 g_list_free( list
);
3264 return wxDataViewItem( (void*) iter
.user_data
);
3270 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
3272 wxDataViewItem
item( (void*) iter
.user_data
);
3277 return wxDataViewItem(0);
3280 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
3284 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3285 if (HasFlag(wxDV_MULTIPLE
))
3287 GtkTreeModel
*model
;
3288 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
3293 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
3296 m_internal
->get_iter( &iter
, path
);
3298 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
3300 list
= g_list_next( list
);
3305 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
3306 g_list_free( list
);
3312 GtkTreeModel
*model
;
3314 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
3317 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
3325 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
3327 GtkDisableSelectionEvents();
3329 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3331 gtk_tree_selection_unselect_all( selection
);
3334 for (i
= 0; i
< sel
.GetCount(); i
++)
3337 iter
.user_data
= (gpointer
) sel
[i
].GetID();
3338 gtk_tree_selection_select_iter( selection
, &iter
);
3341 GtkEnableSelectionEvents();
3344 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
3346 GtkDisableSelectionEvents();
3348 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3351 iter
.user_data
= (gpointer
) item
.GetID();
3352 gtk_tree_selection_select_iter( selection
, &iter
);
3354 GtkEnableSelectionEvents();
3357 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
3359 GtkDisableSelectionEvents();
3361 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3364 iter
.user_data
= (gpointer
) item
.GetID();
3365 gtk_tree_selection_unselect_iter( selection
, &iter
);
3367 GtkEnableSelectionEvents();
3370 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
3372 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3375 iter
.user_data
= (gpointer
) item
.GetID();
3377 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
3380 void wxDataViewCtrl::SelectAll()
3382 GtkDisableSelectionEvents();
3384 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3386 gtk_tree_selection_select_all( selection
);
3388 GtkEnableSelectionEvents();
3391 void wxDataViewCtrl::UnselectAll()
3393 GtkDisableSelectionEvents();
3395 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3397 gtk_tree_selection_unselect_all( selection
);
3399 GtkEnableSelectionEvents();
3402 void wxDataViewCtrl::EnsureVisible( const wxDataViewItem
& item
, const wxDataViewColumn
*column
)
3405 iter
.user_data
= (gpointer
) item
.GetID();
3406 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3407 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
3408 gtk_tree_path_free( path
);
3411 void wxDataViewCtrl::HitTest( const wxPoint
&point
,
3412 wxDataViewItem
&item
, wxDataViewColumn
*&column
) const
3414 item
= wxDataViewItem(0);
3418 wxRect
wxDataViewCtrl::GetItemRect( const wxDataViewItem
&item
,
3419 const wxDataViewColumn
*column
) const
3424 void wxDataViewCtrl::DoSetExpanderColumn()
3426 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
3427 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
3430 void wxDataViewCtrl::DoSetIndent()
3434 void wxDataViewCtrl::GtkDisableSelectionEvents()
3436 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3437 g_signal_handlers_disconnect_by_func( selection
,
3438 (gpointer
) (wxdataview_selection_changed_callback
), this);
3441 void wxDataViewCtrl::GtkEnableSelectionEvents()
3443 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3444 g_signal_connect_after (selection
, "changed",
3445 G_CALLBACK (wxdataview_selection_changed_callback
), this);
3450 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
3452 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
3457 // !wxUSE_GENERICDATAVIEWCTRL
3460 // wxUSE_DATAVIEWCTRL