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 static gpointer s_user_data
= NULL
;
1179 wxgtk_cell_editable_editing_done( GtkCellEditable
*editable
,
1180 wxDataViewRenderer
*wxrenderer
)
1182 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1183 wxDataViewCtrl
*dv
= column
->GetOwner();
1184 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv
->GetId() );
1185 event
.SetDataViewColumn( column
);
1186 event
.SetModel( dv
->GetModel() );
1187 wxDataViewItem
item( s_user_data
);
1188 event
.SetItem( item
);
1189 dv
->GetEventHandler()->ProcessEvent( event
);
1193 wxgtk_renderer_editing_started( GtkCellRenderer
*cell
, GtkCellEditable
*editable
,
1194 gchar
*path
, wxDataViewRenderer
*wxrenderer
)
1196 wxDataViewColumn
*column
= wxrenderer
->GetOwner();
1197 wxDataViewCtrl
*dv
= column
->GetOwner();
1198 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv
->GetId() );
1199 event
.SetDataViewColumn( column
);
1200 event
.SetModel( dv
->GetModel() );
1201 GtkTreePath
*tree_path
= gtk_tree_path_new_from_string( path
);
1203 dv
->GtkGetInternal()->get_iter( &iter
, tree_path
);
1204 gtk_tree_path_free( tree_path
);
1205 wxDataViewItem
item( iter
.user_data
);
1206 event
.SetItem( item
);
1207 dv
->GetEventHandler()->ProcessEvent( event
);
1209 if (GTK_IS_CELL_EDITABLE(editable
))
1211 s_user_data
= iter
.user_data
;
1213 g_signal_connect (GTK_CELL_EDITABLE (editable
), "editing_done",
1214 G_CALLBACK (wxgtk_cell_editable_editing_done
),
1215 (gpointer
) wxrenderer
);
1221 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1223 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1225 wxDataViewRendererBase( varianttype
, mode
, align
)
1229 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1230 // after the m_renderer pointer has been initialized
1233 void wxDataViewRenderer::GtkInitHandlers()
1235 if (!gtk_check_version(2,6,0))
1237 g_signal_connect (GTK_CELL_RENDERER(m_renderer
), "editing_started",
1238 G_CALLBACK (wxgtk_renderer_editing_started
),
1243 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1245 GtkCellRendererMode gtkMode
;
1248 case wxDATAVIEW_CELL_INERT
:
1249 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1251 case wxDATAVIEW_CELL_ACTIVATABLE
:
1252 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1254 case wxDATAVIEW_CELL_EDITABLE
:
1255 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1259 // This value is most often ignored in GtkTreeView
1260 GValue gvalue
= { 0, };
1261 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1262 g_value_set_enum( &gvalue
, gtkMode
);
1263 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1264 g_value_unset( &gvalue
);
1267 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1269 wxDataViewCellMode ret
;
1272 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1274 switch (g_value_get_enum(&gvalue
))
1276 case GTK_CELL_RENDERER_MODE_INERT
:
1277 ret
= wxDATAVIEW_CELL_INERT
;
1279 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1280 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1282 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1283 ret
= wxDATAVIEW_CELL_EDITABLE
;
1287 g_value_unset( &gvalue
);
1292 void wxDataViewRenderer::SetAlignment( int align
)
1294 // horizontal alignment:
1296 gfloat xalign
= 0.0;
1297 if (align
& wxALIGN_RIGHT
)
1299 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1302 GValue gvalue
= { 0, };
1303 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1304 g_value_set_float( &gvalue
, xalign
);
1305 g_object_set_property( G_OBJECT(m_renderer
), "xalign", &gvalue
);
1306 g_value_unset( &gvalue
);
1308 // vertical alignment:
1310 gfloat yalign
= 0.0;
1311 if (align
& wxALIGN_BOTTOM
)
1313 else if (align
& wxALIGN_CENTER_VERTICAL
)
1316 GValue gvalue2
= { 0, };
1317 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1318 g_value_set_float( &gvalue2
, yalign
);
1319 g_object_set_property( G_OBJECT(m_renderer
), "yalign", &gvalue2
);
1320 g_value_unset( &gvalue2
);
1323 int wxDataViewRenderer::GetAlignment() const
1328 // horizontal alignment:
1330 g_object_get( G_OBJECT(m_renderer
), "xalign", &gvalue
, NULL
);
1331 float xalign
= g_value_get_float( &gvalue
);
1333 ret
|= wxALIGN_LEFT
;
1334 else if (xalign
== 0.5)
1335 ret
|= wxALIGN_CENTER_HORIZONTAL
;
1337 ret
|= wxALIGN_RIGHT
;
1338 g_value_unset( &gvalue
);
1341 // vertical alignment:
1343 g_object_get( G_OBJECT(m_renderer
), "yalign", &gvalue
, NULL
);
1344 float yalign
= g_value_get_float( &gvalue
);
1347 else if (yalign
== 0.5)
1348 ret
|= wxALIGN_CENTER_VERTICAL
;
1350 ret
|= wxALIGN_BOTTOM
;
1351 g_value_unset( &gvalue
);
1358 // ---------------------------------------------------------
1359 // wxDataViewTextRenderer
1360 // ---------------------------------------------------------
1363 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1364 gchar
*arg1
, gchar
*arg2
, gpointer user_data
);
1367 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1368 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1370 wxDataViewTextRenderer
*cell
= (wxDataViewTextRenderer
*) user_data
;
1372 wxString tmp
= wxGTK_CONV_BACK_FONT(arg2
, cell
->GetOwner()->GetOwner()->GetFont());
1373 wxVariant value
= tmp
;
1374 if (!cell
->Validate( value
))
1377 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1379 GtkTreePath
*path
= gtk_tree_path_new_from_string( arg1
);
1381 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, path
);
1382 wxDataViewItem
item( (void*) iter
.user_data
);;
1383 gtk_tree_path_free( path
);
1385 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1387 model
->SetValue( value
, item
, model_col
);
1388 model
->ValueChanged( item
, model_col
);
1391 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
1393 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1395 wxDataViewRenderer( varianttype
, mode
, align
)
1397 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_text_new();
1399 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
1401 GValue gvalue
= { 0, };
1402 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1403 g_value_set_boolean( &gvalue
, true );
1404 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
1405 g_value_unset( &gvalue
);
1407 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
1413 SetAlignment(align
);
1416 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
1418 wxString tmp
= value
;
1420 GValue gvalue
= { 0, };
1421 g_value_init( &gvalue
, G_TYPE_STRING
);
1422 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( tmp
, GetOwner()->GetOwner()->GetFont() ) );
1423 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1424 g_value_unset( &gvalue
);
1429 bool wxDataViewTextRenderer::GetValue( wxVariant
&value
) const
1431 GValue gvalue
= { 0, };
1432 g_value_init( &gvalue
, G_TYPE_STRING
);
1433 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1434 wxString tmp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
),
1435 wx_const_cast(wxDataViewTextRenderer
*, this)->GetOwner()->GetOwner()->GetFont() );
1436 g_value_unset( &gvalue
);
1443 void wxDataViewTextRenderer::SetAlignment( int align
)
1445 wxDataViewRenderer::SetAlignment(align
);
1447 if (gtk_check_version(2,10,0))
1450 // horizontal alignment:
1451 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
1452 if (align
& wxALIGN_RIGHT
)
1453 pangoAlign
= PANGO_ALIGN_RIGHT
;
1454 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1455 pangoAlign
= PANGO_ALIGN_CENTER
;
1457 GValue gvalue
= { 0, };
1458 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1459 g_value_set_enum( &gvalue
, pangoAlign
);
1460 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
1461 g_value_unset( &gvalue
);
1464 // ---------------------------------------------------------
1465 // wxDataViewBitmapRenderer
1466 // ---------------------------------------------------------
1468 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
1470 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1472 wxDataViewRenderer( varianttype
, mode
, align
)
1474 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_pixbuf_new();
1477 SetAlignment(align
);
1480 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
1482 if (value
.GetType() == wxT("wxBitmap"))
1487 // This may create a Pixbuf representation in the
1488 // wxBitmap object (and it will stay there)
1489 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1491 GValue gvalue
= { 0, };
1492 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1493 g_value_set_object( &gvalue
, pixbuf
);
1494 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1495 g_value_unset( &gvalue
);
1500 if (value
.GetType() == wxT("wxIcon"))
1505 // This may create a Pixbuf representation in the
1506 // wxBitmap object (and it will stay there)
1507 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1509 GValue gvalue
= { 0, };
1510 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1511 g_value_set_object( &gvalue
, pixbuf
);
1512 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1513 g_value_unset( &gvalue
);
1521 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&value
) const
1526 // ---------------------------------------------------------
1527 // wxDataViewToggleRenderer
1528 // ---------------------------------------------------------
1531 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1532 gchar
*path
, gpointer user_data
);
1535 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1536 gchar
*path
, gpointer user_data
)
1538 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
1541 GValue gvalue
= { 0, };
1542 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1543 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
1544 bool tmp
= g_value_get_boolean( &gvalue
);
1545 g_value_unset( &gvalue
);
1549 wxVariant value
= tmp
;
1550 if (!cell
->Validate( value
))
1553 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1555 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
1557 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, gtk_path
);
1558 wxDataViewItem
item( (void*) iter
.user_data
);;
1559 gtk_tree_path_free( gtk_path
);
1561 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1563 model
->SetValue( value
, item
, model_col
);
1564 model
->ValueChanged( item
, model_col
);
1567 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1569 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1570 wxDataViewCellMode mode
, int align
) :
1571 wxDataViewRenderer( varianttype
, mode
, align
)
1573 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
1575 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1577 g_signal_connect_after( m_renderer
, "toggled",
1578 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
1582 GValue gvalue
= { 0, };
1583 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1584 g_value_set_boolean( &gvalue
, false );
1585 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
1586 g_value_unset( &gvalue
);
1590 SetAlignment(align
);
1593 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1597 GValue gvalue
= { 0, };
1598 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1599 g_value_set_boolean( &gvalue
, tmp
);
1600 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1601 g_value_unset( &gvalue
);
1606 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
1608 GValue gvalue
= { 0, };
1609 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1610 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1611 bool tmp
= g_value_get_boolean( &gvalue
);
1612 g_value_unset( &gvalue
);
1619 // ---------------------------------------------------------
1620 // wxDataViewCustomRenderer
1621 // ---------------------------------------------------------
1623 class wxDataViewCtrlDC
: public wxWindowDC
1626 wxDataViewCtrlDC( wxDataViewCtrl
*window
)
1628 GtkWidget
*widget
= window
->m_treeview
;
1632 m_context
= window
->GtkGetPangoDefaultContext();
1633 m_layout
= pango_layout_new( m_context
);
1634 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
1636 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
1638 // Set m_window later
1640 // m_owner = window;
1644 // ---------------------------------------------------------
1645 // wxDataViewCustomRenderer
1646 // ---------------------------------------------------------
1648 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
1650 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
1651 wxDataViewCellMode mode
, int align
,
1653 wxDataViewRenderer( varianttype
, mode
, align
)
1663 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
1665 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
1666 renderer
->cell
= this;
1668 m_renderer
= (GtkCellRenderer
*) renderer
;
1671 SetAlignment(align
);
1678 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
1684 wxDC
*wxDataViewCustomRenderer::GetDC()
1688 if (GetOwner() == NULL
)
1690 if (GetOwner()->GetOwner() == NULL
)
1692 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
1698 // ---------------------------------------------------------
1699 // wxDataViewProgressRenderer
1700 // ---------------------------------------------------------
1702 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
1704 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
1705 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1706 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
1712 if (!gtk_check_version(2,6,0))
1714 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
1716 GValue gvalue
= { 0, };
1717 g_value_init( &gvalue
, G_TYPE_STRING
);
1719 // FIXME: font encoding support
1720 g_value_set_string( &gvalue
, wxGTK_CONV_SYS(m_label
) );
1721 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1722 g_value_unset( &gvalue
);
1725 SetAlignment(align
);
1730 // Use custom cell code
1731 wxDataViewCustomRenderer::Init(mode
, align
);
1735 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
1739 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
1742 if (!gtk_check_version(2,6,0))
1744 gint tmp
= (long) value
;
1745 GValue gvalue
= { 0, };
1746 g_value_init( &gvalue
, G_TYPE_INT
);
1747 g_value_set_int( &gvalue
, tmp
);
1748 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
1749 g_value_unset( &gvalue
);
1754 m_value
= (long) value
;
1756 if (m_value
< 0) m_value
= 0;
1757 if (m_value
> 100) m_value
= 100;
1763 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
1768 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1770 double pct
= (double)m_value
/ 100.0;
1772 bar
.width
= (int)(cell
.width
* pct
);
1773 dc
->SetPen( *wxTRANSPARENT_PEN
);
1774 dc
->SetBrush( *wxBLUE_BRUSH
);
1775 dc
->DrawRectangle( bar
);
1777 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1778 dc
->SetPen( *wxBLACK_PEN
);
1779 dc
->DrawRectangle( cell
);
1784 wxSize
wxDataViewProgressRenderer::GetSize() const
1786 return wxSize(40,12);
1789 // ---------------------------------------------------------
1790 // wxDataViewDateRenderer
1791 // ---------------------------------------------------------
1793 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
1796 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
1797 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
1798 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
1803 m_cal
= new wxCalendarCtrl( this, -1, *value
);
1804 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
1805 sizer
->Add( m_cal
, 1, wxGROW
);
1810 virtual void OnDismiss()
1814 void OnCalendar( wxCalendarEvent
&event
);
1816 wxCalendarCtrl
*m_cal
;
1817 wxDataViewModel
*m_model
;
1818 wxDataViewItem m_item
;
1822 DECLARE_EVENT_TABLE()
1825 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
1826 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
1829 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
1831 wxDateTime date
= event
.GetDate();
1832 wxVariant value
= date
;
1833 m_model
->SetValue( value
, m_item
, m_col
);
1834 m_model
->ValueChanged( m_item
, m_col
);
1838 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
1840 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1841 wxDataViewCellMode mode
, int align
) :
1842 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1845 SetAlignment(align
);
1848 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1850 m_date
= value
.GetDateTime();
1855 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
1860 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1862 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
1863 wxString tmp
= m_date
.FormatDate();
1864 dc
->DrawText( tmp
, cell
.x
, cell
.y
);
1869 wxSize
wxDataViewDateRenderer::GetSize() const
1871 wxString tmp
= m_date
.FormatDate();
1873 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
1874 return wxSize(x
,y
+d
);
1877 bool wxDataViewDateRenderer::Activate( wxRect cell
, wxDataViewModel
*model
,
1878 const wxDataViewItem
&item
, unsigned int col
)
1881 model
->GetValue( variant
, item
, col
);
1882 wxDateTime value
= variant
.GetDateTime();
1884 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1885 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
1886 wxPoint pos
= wxGetMousePosition();
1889 popup
->Popup( popup
->m_cal
);
1895 // ---------------------------------------------------------
1896 // wxDataViewIconTextRenderer
1897 // ---------------------------------------------------------
1899 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
1901 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
1902 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1903 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1906 SetAlignment(align
);
1909 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
1913 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
1919 bool wxDataViewIconTextRenderer::GetValue( wxVariant
&value
) const
1924 bool wxDataViewIconTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1926 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
1928 const wxIcon
&icon
= m_value
.GetIcon();
1931 dc
->DrawIcon( icon
, cell
.x
, cell
.y
); // TODO centre
1932 cell
.x
+= icon
.GetWidth()+4;
1935 dc
->DrawText( m_value
.GetText(), cell
.x
, cell
.y
);
1940 wxSize
wxDataViewIconTextRenderer::GetSize() const
1942 return wxSize(80,16); // TODO
1945 wxControl
* wxDataViewIconTextRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1950 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1955 // ---------------------------------------------------------
1957 // ---------------------------------------------------------
1961 gtk_dataview_header_button_press_callback( GtkWidget
*widget
,
1962 GdkEventButton
*gdk_event
,
1963 wxDataViewColumn
*column
)
1965 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
1968 if (gdk_event
->button
== 1)
1970 wxDataViewCtrl
*dv
= column
->GetOwner();
1971 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
1972 event
.SetDataViewColumn( column
);
1973 event
.SetModel( dv
->GetModel() );
1974 if (dv
->GetEventHandler()->ProcessEvent( event
))
1982 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
1983 GtkCellRenderer
*cell
,
1984 GtkTreeModel
*model
,
1990 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
1991 GtkCellRenderer
*renderer
,
1992 GtkTreeModel
*model
,
1996 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
1997 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
1999 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
2001 wxDataViewItem
item( (void*) iter
->user_data
);
2004 tree_model
->internal
->GetDataViewModel()->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
2006 if (value
.GetType() != cell
->GetVariantType())
2007 wxLogError( wxT("Wrong type, required: %s but: %s"),
2008 value
.GetType().c_str(),
2009 cell
->GetVariantType().c_str() );
2011 cell
->SetValue( value
);
2014 wxListItemAttr attr
;
2015 tree_model
->model
->GetAttr( attr
, cell
->GetOwner()->GetModelColumn(), model_row
);
2017 if (attr
.HasBackgroundColour())
2019 wxColour colour
= attr
.GetBackgroundColour();
2020 const GdkColor
* const gcol
= colour
.GetColor();
2022 GValue gvalue
= { 0, };
2023 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
2024 g_value_set_boxed( &gvalue
, gcol
);
2025 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
2026 g_value_unset( &gvalue
);
2030 GValue gvalue
= { 0, };
2031 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
2032 g_value_set_boolean( &gvalue
, FALSE
);
2033 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
2034 g_value_unset( &gvalue
);
2040 IMPLEMENT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
2042 #include <wx/listimpl.cpp>
2043 WX_DEFINE_LIST(wxDataViewColumnList
);
2045 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
2046 unsigned int model_column
, int width
,
2047 wxAlignment align
, int flags
) :
2048 wxDataViewColumnBase( title
, cell
, model_column
, width
, align
, flags
)
2050 Init( align
, flags
, width
);
2052 gtk_tree_view_column_set_clickable( GTK_TREE_VIEW_COLUMN(m_column
), TRUE
);
2056 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
2057 unsigned int model_column
, int width
,
2058 wxAlignment align
, int flags
) :
2059 wxDataViewColumnBase( bitmap
, cell
, model_column
, width
, align
, flags
)
2061 Init( align
, flags
, width
);
2063 SetBitmap( bitmap
);
2066 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
2068 m_isConnected
= false;
2070 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) GetRenderer()->GetGtkHandle();
2071 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
2072 m_column
= (GtkWidget
*) column
;
2075 SetAlignment( align
);
2077 // NOTE: we prefer not to call SetMinWidth(wxDVC_DEFAULT_MINWIDTH);
2078 // as GTK+ is smart and unless explicitely told, will set the minimal
2079 // width to the title's lenght, which is a better default
2081 // the GTK_TREE_VIEW_COLUMN_FIXED is required by the "fixed height" mode
2082 // that we use for the wxDataViewCtrl
2083 gtk_tree_view_column_set_fixed_width( column
, width
< 0 ? wxDVC_DEFAULT_WIDTH
: width
);
2084 gtk_tree_view_column_set_sizing( column
, GTK_TREE_VIEW_COLUMN_FIXED
);
2086 gtk_tree_view_column_pack_end( column
, renderer
, TRUE
);
2088 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
2089 wxGtkTreeCellDataFunc
, (gpointer
) GetRenderer(), NULL
);
2092 wxDataViewColumn::~wxDataViewColumn()
2096 void wxDataViewColumn::OnInternalIdle()
2101 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
2103 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2106 g_signal_connect(column
->button
, "button_press_event",
2107 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
2109 m_isConnected
= true;
2114 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
2116 wxDataViewColumnBase::SetOwner( owner
);
2118 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2120 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
2123 void wxDataViewColumn::SetTitle( const wxString
&title
)
2125 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2129 // disconnect before column->button gets recreated
2130 g_signal_handlers_disconnect_by_func( column
->button
,
2131 (GtkWidget
*) gtk_dataview_header_button_press_callback
, this);
2133 m_isConnected
= false;
2136 // FIXME: can it really happen that we don't have the owner here??
2137 wxDataViewCtrl
*ctrl
= GetOwner();
2138 gtk_tree_view_column_set_title( column
, ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
2139 : wxGTK_CONV_SYS(title
) );
2141 gtk_tree_view_column_set_widget( column
, NULL
);
2144 wxString
wxDataViewColumn::GetTitle() const
2146 const gchar
*str
= gtk_tree_view_column_get_title( GTK_TREE_VIEW_COLUMN(m_column
) );
2147 return wxConvFileName
->cMB2WX(str
);
2150 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
2152 wxDataViewColumnBase::SetBitmap( bitmap
);
2154 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2157 GtkImage
*gtk_image
= GTK_IMAGE( gtk_image_new() );
2159 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
2160 if (bitmap
.GetMask())
2161 mask
= bitmap
.GetMask()->GetBitmap();
2163 if (bitmap
.HasPixbuf())
2165 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
2166 bitmap
.GetPixbuf());
2170 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
2171 bitmap
.GetPixmap(), mask
);
2173 gtk_widget_show( GTK_WIDGET(gtk_image
) );
2175 gtk_tree_view_column_set_widget( column
, GTK_WIDGET(gtk_image
) );
2179 gtk_tree_view_column_set_widget( column
, NULL
);
2183 void wxDataViewColumn::SetHidden( bool hidden
)
2185 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
2188 void wxDataViewColumn::SetResizeable( bool resizeable
)
2190 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizeable
);
2193 void wxDataViewColumn::SetAlignment( wxAlignment align
)
2195 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2197 gfloat xalign
= 0.0;
2198 if (align
== wxALIGN_RIGHT
)
2200 if (align
== wxALIGN_CENTER_HORIZONTAL
||
2201 align
== wxALIGN_CENTER
)
2204 gtk_tree_view_column_set_alignment( column
, xalign
);
2207 wxAlignment
wxDataViewColumn::GetAlignment() const
2209 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
2212 return wxALIGN_RIGHT
;
2214 return wxALIGN_CENTER_HORIZONTAL
;
2216 return wxALIGN_LEFT
;
2219 void wxDataViewColumn::SetSortable( bool sortable
)
2221 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2225 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
2229 gtk_tree_view_column_set_sort_column_id( column
, -1 );
2230 gtk_tree_view_column_set_sort_indicator( column
, FALSE
);
2234 bool wxDataViewColumn::IsSortable() const
2236 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2237 return (gtk_tree_view_column_get_sort_column_id( column
) != -1);
2240 bool wxDataViewColumn::IsResizeable() const
2242 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2243 return gtk_tree_view_column_get_resizable( column
);
2246 bool wxDataViewColumn::IsHidden() const
2248 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2249 return !gtk_tree_view_column_get_visible( column
);
2252 void wxDataViewColumn::SetSortOrder( bool ascending
)
2254 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2257 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
2259 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
2261 gtk_tree_view_column_set_sort_indicator( column
, TRUE
);
2264 bool wxDataViewColumn::IsSortOrderAscending() const
2266 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2268 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
2271 void wxDataViewColumn::SetMinWidth( int width
)
2273 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2276 int wxDataViewColumn::GetMinWidth() const
2278 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2281 int wxDataViewColumn::GetWidth() const
2283 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2286 void wxDataViewColumn::SetWidth( int width
)
2288 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2292 //-----------------------------------------------------------------------------
2293 // wxGtkTreeModelNode
2294 //-----------------------------------------------------------------------------
2296 void wxGtkTreeModelNode::Resort()
2298 size_t child_count
= GetChildCount();
2299 if (child_count
== 0)
2302 size_t node_count
= GetNodesCount();
2304 if (child_count
== 1)
2306 if (node_count
== 1)
2308 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
2314 wxGtkTreeModelChildren temp
;
2315 WX_APPEND_ARRAY( temp
, m_children
);
2317 g_internal
= m_internal
;
2318 m_children
.Sort( &wxGtkTreeModelChildCmp
);
2320 gint
*new_order
= new gint
[child_count
];
2323 for (pos
= 0; pos
< child_count
; pos
++)
2325 void *id
= m_children
.Item( pos
);
2326 int old_pos
= temp
.Index( id
);
2327 new_order
[pos
] = old_pos
;
2330 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
2333 iter
.user_data
= GetItem().GetID();
2334 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
2336 GtkTreePath
*path
= m_internal
->get_path( &iter
);
2338 gtk_tree_model_rows_reordered( gtk_tree_model
, path
, &iter
, new_order
);
2340 gtk_tree_path_free (path
);
2342 delete [] new_order
;
2344 for (pos
= 0; pos
< node_count
; pos
++)
2346 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
2351 //-----------------------------------------------------------------------------
2352 // wxDataViewCtrlInternal
2353 //-----------------------------------------------------------------------------
2355 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
,
2356 wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
)
2359 m_wx_model
= wx_model
;
2360 m_gtk_model
= gtk_model
;
2362 m_sort_order
= GTK_SORT_ASCENDING
;
2367 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
2369 g_object_unref( m_gtk_model
);
2372 void wxDataViewCtrlInternal::InitTree()
2374 wxDataViewItem item
;
2375 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
2377 BuildBranch( m_root
);
2380 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
2382 if (node
->GetChildCount() == 0)
2384 wxDataViewItemArray children
;
2385 unsigned int count
= m_wx_model
->GetChildren( node
->GetItem(), children
);
2387 for (pos
= 0; pos
< count
; pos
++)
2389 wxDataViewItem child
= children
[pos
];
2391 if (m_wx_model
->IsContainer( child
))
2392 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
2394 node
->AddLeave( child
.GetID() );
2396 // Don't send any events here
2401 void wxDataViewCtrlInternal::Resort()
2406 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
2408 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2409 if (m_wx_model
->IsContainer( item
))
2410 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
2412 parent_node
->AddLeave( item
.GetID() );
2414 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_ADDED
, m_owner
->GetId() );
2415 event
.SetEventObject( m_owner
);
2416 event
.SetModel( m_owner
->GetModel() );
2417 event
.SetItem( item
);
2418 m_owner
->GetEventHandler()->ProcessEvent( event
);
2423 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
2425 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2426 parent_node
->DeleteChild( item
.GetID() );
2428 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED
, m_owner
->GetId() );
2429 event
.SetEventObject( m_owner
);
2430 event
.SetModel( m_owner
->GetModel() );
2431 event
.SetItem( item
);
2432 m_owner
->GetEventHandler()->ProcessEvent( event
);
2437 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
2439 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_CHANGED
, m_owner
->GetId() );
2440 event
.SetEventObject( m_owner
);
2441 event
.SetModel( m_owner
->GetModel() );
2442 event
.SetItem( item
);
2443 m_owner
->GetEventHandler()->ProcessEvent( event
);
2448 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
2450 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED
, m_owner
->GetId() );
2451 event
.SetEventObject( m_owner
);
2452 event
.SetModel( m_owner
->GetModel() );
2453 event
.SetColumn( col
);
2454 event
.SetItem( item
);
2455 m_owner
->GetEventHandler()->ProcessEvent( event
);
2460 bool wxDataViewCtrlInternal::Cleared()
2462 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED
, m_owner
->GetId() );
2463 event
.SetEventObject( m_owner
);
2464 event
.SetModel( m_owner
->GetModel() );
2465 m_owner
->GetEventHandler()->ProcessEvent( event
);
2470 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
2472 int depth
= gtk_tree_path_get_depth( path
);
2474 wxGtkTreeModelNode
*node
= m_root
;
2477 for (i
= 0; i
< depth
; i
++)
2479 BuildBranch( node
);
2481 gint pos
= gtk_tree_path_get_indices (path
)[i
];
2482 if (pos
< 0) return FALSE
;
2483 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
2485 void* id
= node
->GetChildren().Item( (size_t) pos
);
2489 iter
->stamp
= m_gtk_model
->stamp
;
2490 iter
->user_data
= id
;
2494 size_t count
= node
->GetNodes().GetCount();
2496 for (pos2
= 0; pos2
< count
; pos2
++)
2498 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
2499 if (child_node
->GetItem().GetID() == id
)
2510 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
2512 GtkTreePath
*retval
= gtk_tree_path_new ();
2513 void *id
= iter
->user_data
;
2515 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
2518 int pos
= node
->GetChildren().Index( id
);
2520 gtk_tree_path_prepend_index( retval
, pos
);
2522 id
= node
->GetItem().GetID();
2523 node
= node
->GetParent();
2529 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
2531 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
2532 if( parent
== NULL
)
2535 int pos
= parent
->GetChildren().Index( iter
->user_data
);
2537 if (pos
== (int) parent
->GetChildCount()-1)
2540 iter
->stamp
= m_gtk_model
->stamp
;
2541 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
2546 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
2548 wxDataViewItem
item( (void*) parent
->user_data
);
2550 if (!m_wx_model
->IsContainer( item
))
2553 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2554 BuildBranch( parent_node
);
2556 if (parent_node
->GetChildCount() == 0)
2559 iter
->stamp
= m_gtk_model
->stamp
;
2560 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
2565 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
2567 wxDataViewItem
item( (void*) iter
->user_data
);
2568 bool is_container
= m_wx_model
->IsContainer( item
);
2573 wxGtkTreeModelNode
*node
= FindNode( iter
);
2574 BuildBranch( node
);
2576 return (node
->GetChildCount() > 0);
2579 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
2581 wxDataViewItem
item( (void*) iter
->user_data
);
2583 if (!m_wx_model
->IsContainer( item
))
2586 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
2587 BuildBranch( parent_node
);
2589 // wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() );
2591 return parent_node
->GetChildCount();
2594 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
2597 if (parent
) id
= (void*) parent
->user_data
;
2598 wxDataViewItem
item( id
);
2600 if (!m_wx_model
->IsContainer( item
))
2603 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2604 BuildBranch( parent_node
);
2606 // wxPrintf( "iter_nth_child %d\n", n );
2608 iter
->stamp
= m_gtk_model
->stamp
;
2609 iter
->user_data
= parent_node
->GetChildren().Item( n
);
2614 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
2616 wxGtkTreeModelNode
*node
= FindParentNode( child
);
2620 iter
->stamp
= m_gtk_model
->stamp
;
2621 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
2626 static wxGtkTreeModelNode
*
2627 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
2633 list
.DeleteContents( true );
2634 wxDataViewItem
it( item
);
2637 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
2638 list
.Insert( pItem
);
2639 it
= model
->GetParent( it
);
2642 wxGtkTreeModelNode
* node
= treeNode
;
2643 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
2645 if( node
&& node
->GetNodes().GetCount() != 0 )
2647 int len
= node
->GetNodes().GetCount();
2648 wxGtkTreeModelNodes nodes
= node
->GetNodes();
2650 for( ; j
< len
; j
++)
2652 if( nodes
[j
]->GetItem() == *(n
->GetData()))
2671 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
2676 wxDataViewItem
item( (void*) iter
->user_data
);
2680 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
2684 wxPrintf( "Not found %d\n", (int) iter
->user_data
);
2692 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
2697 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
2701 wxPrintf( "Not found %d\n", (int) item
.GetID() );
2709 static wxGtkTreeModelNode
*
2710 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
2716 list
.DeleteContents( true );
2720 wxDataViewItem
it( model
->GetParent( item
) );
2723 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
2724 list
.Insert( pItem
);
2725 it
= model
->GetParent( it
);
2728 wxGtkTreeModelNode
* node
= treeNode
;
2729 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
2731 if( node
&& node
->GetNodes().GetCount() != 0 )
2733 int len
= node
->GetNodes().GetCount();
2734 wxGtkTreeModelNodes nodes
= node
->GetNodes();
2736 for( ; j
< len
; j
++)
2738 if( nodes
[j
]->GetItem() == *(n
->GetData()))
2753 //Examine whether the node is item's parent node
2754 int len
= node
->GetChildCount();
2755 for( int i
= 0; i
< len
; i
++ )
2757 if( node
->GetChildren().Item( i
) == item
.GetID() )
2763 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
2768 wxDataViewItem
item( (void*) iter
->user_data
);
2772 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
2775 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
2780 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
2783 //-----------------------------------------------------------------------------
2784 // wxDataViewCtrl signal callbacks
2785 //-----------------------------------------------------------------------------
2788 wxdataview_selection_changed_callback( GtkTreeSelection
* selection
, wxDataViewCtrl
*dv
)
2790 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
2793 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_SELECTED
, dv
->GetId() );
2794 event
.SetItem( dv
->GetSelection() );
2795 event
.SetModel( dv
->GetModel() );
2796 dv
->GetEventHandler()->ProcessEvent( event
);
2800 wxdataview_row_activated_callback( GtkTreeView
* treeview
, GtkTreePath
*path
,
2801 GtkTreeViewColumn
*column
, wxDataViewCtrl
*dv
)
2803 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
2806 dv
->GtkGetInternal()->get_iter( &iter
, path
);
2807 wxDataViewItem
item( (void*) iter
.user_data
);;
2808 event
.SetItem( item
);
2809 event
.SetModel( dv
->GetModel() );
2810 dv
->GetEventHandler()->ProcessEvent( event
);
2814 wxdataview_test_expand_row_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
2815 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
2817 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, dv
->GetId() );
2819 wxDataViewItem
item( (void*) iter
->user_data
);;
2820 event
.SetItem( item
);
2821 event
.SetModel( dv
->GetModel() );
2822 dv
->GetEventHandler()->ProcessEvent( event
);
2824 return !event
.IsAllowed();
2828 wxdataview_row_expanded_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
2829 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
2831 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, dv
->GetId() );
2833 wxDataViewItem
item( (void*) iter
->user_data
);;
2834 event
.SetItem( item
);
2835 event
.SetModel( dv
->GetModel() );
2836 dv
->GetEventHandler()->ProcessEvent( event
);
2840 wxdataview_test_collapse_row_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
2841 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
2843 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, dv
->GetId() );
2845 wxDataViewItem
item( (void*) iter
->user_data
);;
2846 event
.SetItem( item
);
2847 event
.SetModel( dv
->GetModel() );
2848 dv
->GetEventHandler()->ProcessEvent( event
);
2850 return !event
.IsAllowed();
2854 wxdataview_row_collapsed_callback( GtkTreeView
* treeview
, GtkTreeIter
* iter
,
2855 GtkTreePath
*path
, wxDataViewCtrl
*dv
)
2857 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, dv
->GetId() );
2859 wxDataViewItem
item( (void*) iter
->user_data
);;
2860 event
.SetItem( item
);
2861 event
.SetModel( dv
->GetModel() );
2862 dv
->GetEventHandler()->ProcessEvent( event
);
2865 //-----------------------------------------------------------------------------
2867 //-----------------------------------------------------------------------------
2869 //-----------------------------------------------------------------------------
2870 // InsertChild for wxDataViewCtrl
2871 //-----------------------------------------------------------------------------
2873 static void wxInsertChildInDataViewCtrl( wxWindowGTK
* parent
, wxWindowGTK
* child
)
2875 wxDataViewCtrl
* dvc
= (wxDataViewCtrl
*) parent
;
2876 GtkWidget
*treeview
= dvc
->GtkGetTreeView();
2878 // Insert widget in GtkTreeView
2879 if (GTK_WIDGET_REALIZED(treeview
))
2880 gtk_widget_set_parent_window( child
->m_widget
,
2881 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
2882 gtk_widget_set_parent( child
->m_widget
, treeview
);
2886 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
2887 GtkAllocation
*alloc
,
2888 wxDataViewCtrl
*win
)
2890 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
2893 wxWindow
*child
= node
->GetData();
2896 gtk_widget_size_request( child
->m_widget
, &req
);
2898 GtkAllocation alloc
;
2899 alloc
.x
= child
->m_x
;
2900 alloc
.y
= child
->m_y
;
2901 alloc
.width
= child
->m_width
;
2902 alloc
.height
= child
->m_height
;
2903 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
2905 node
= node
->GetNext();
2911 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
2913 wxDataViewCtrl::~wxDataViewCtrl()
2916 GetModel()->RemoveNotifier( m_notifier
);
2918 // remove the model from the GtkTreeView before it gets destroyed by the
2919 // wxDataViewCtrlBase's dtor
2920 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), NULL
);
2925 void wxDataViewCtrl::Init()
2930 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
2931 const wxPoint
& pos
, const wxSize
& size
,
2932 long style
, const wxValidator
& validator
)
2936 if (!PreCreation( parent
, pos
, size
) ||
2937 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
2939 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
2943 m_insertCallback
= wxInsertChildInDataViewCtrl
;
2945 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
2947 GtkScrolledWindowSetBorder(m_widget
, style
);
2949 m_treeview
= gtk_tree_view_new();
2950 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
2952 g_signal_connect (m_treeview
, "size_allocate",
2953 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
2956 if (!gtk_check_version(2,6,0))
2957 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), TRUE
);
2960 if (style
& wxDV_MULTIPLE
)
2962 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
2963 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
2966 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
2969 if (!gtk_check_version(2,10,0))
2971 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
2973 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
2974 (style
& wxDV_VERT_RULES
) != 0)
2975 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
2976 else if (style
& wxDV_VERT_RULES
)
2977 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
2978 else if (style
& wxDV_HORIZ_RULES
)
2979 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
2981 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
2986 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_HORIZ_RULES
) != 0 );
2989 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
2990 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
2991 gtk_widget_show (m_treeview
);
2993 m_parent
->DoAddChild( this );
2997 GtkEnableSelectionEvents();
2999 g_signal_connect_after (m_treeview
, "row-activated",
3000 G_CALLBACK (wxdataview_row_activated_callback
), this);
3002 g_signal_connect (m_treeview
, "test-collapse-row",
3003 G_CALLBACK (wxdataview_test_collapse_row_callback
), this);
3005 g_signal_connect_after (m_treeview
, "row-collapsed",
3006 G_CALLBACK (wxdataview_row_collapsed_callback
), this);
3008 g_signal_connect (m_treeview
, "test-expand-row",
3009 G_CALLBACK (wxdataview_test_expand_row_callback
), this);
3011 g_signal_connect_after (m_treeview
, "row-expanded",
3012 G_CALLBACK (wxdataview_row_expanded_callback
), this);
3017 void wxDataViewCtrl::OnInternalIdle()
3019 wxWindow::OnInternalIdle();
3021 unsigned int cols
= GetColumnCount();
3023 for (i
= 0; i
< cols
; i
++)
3025 wxDataViewColumn
*col
= GetColumn( i
);
3026 col
->OnInternalIdle();
3030 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
3032 if (!wxDataViewCtrlBase::AssociateModel( model
))
3035 GtkWxTreeModel
*gtk_model
= wxgtk_tree_model_new();
3036 m_internal
= new wxDataViewCtrlInternal( this, model
, gtk_model
);
3037 gtk_model
->internal
= m_internal
;
3039 m_notifier
= new wxGtkDataViewModelNotifier( gtk_model
, model
, this );
3041 model
->AddNotifier( m_notifier
);
3043 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_model
) );
3045 // unref in wxDataViewCtrlInternal
3046 // g_object_unref( gtk_model );
3051 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
3053 if (!wxDataViewCtrlBase::AppendColumn(col
))
3056 m_cols
.Append( col
);
3058 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
),
3059 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
3064 unsigned int wxDataViewCtrl::GetColumnCount() const
3066 return m_cols
.GetCount();
3069 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
3071 GtkTreeViewColumn
*gtk_col
= gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview
), pos
);
3075 wxDataViewColumnList::const_iterator iter
;
3076 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); iter
++)
3078 wxDataViewColumn
*col
= *iter
;
3079 if (GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) == gtk_col
)
3088 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
3090 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
3091 GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle()) );
3093 m_cols
.remove( column
);
3100 bool wxDataViewCtrl::ClearColumns()
3102 wxDataViewColumnList::iterator iter
;
3103 for (iter
= m_cols
.begin(); iter
!= m_cols
.end(); iter
++)
3105 wxDataViewColumn
*col
= *iter
;
3106 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview
),
3107 GTK_TREE_VIEW_COLUMN(col
->GetGtkHandle()) );
3115 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
3120 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
3125 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
3128 iter
.user_data
= item
.GetID();
3129 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3130 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview
), path
, false );
3131 gtk_tree_path_free( path
);
3134 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
3137 iter
.user_data
= item
.GetID();
3138 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3139 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview
), path
);
3140 gtk_tree_path_free( path
);
3143 wxDataViewItem
wxDataViewCtrl::GetSelection() const
3145 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3147 if (m_windowStyle
& wxDV_MULTIPLE
)
3149 // Report the first one
3150 GtkTreeModel
*model
;
3151 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
3155 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
3157 m_internal
->get_iter( &iter
, path
);
3160 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
3161 g_list_free( list
);
3163 return wxDataViewItem( (void*) iter
.user_data
);
3169 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
3171 wxDataViewItem
item( (void*) iter
.user_data
);
3176 return wxDataViewItem(0);
3179 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
3183 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3184 if (HasFlag(wxDV_MULTIPLE
))
3186 GtkTreeModel
*model
;
3187 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
3192 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
3195 m_internal
->get_iter( &iter
, path
);
3197 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
3199 list
= g_list_next( list
);
3204 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
3205 g_list_free( list
);
3211 GtkTreeModel
*model
;
3213 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
3216 sel
.Add( wxDataViewItem( (void*) iter
.user_data
) );
3224 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
3226 GtkDisableSelectionEvents();
3228 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3230 gtk_tree_selection_unselect_all( selection
);
3233 for (i
= 0; i
< sel
.GetCount(); i
++)
3236 iter
.user_data
= (gpointer
) sel
[i
].GetID();
3237 gtk_tree_selection_select_iter( selection
, &iter
);
3240 GtkEnableSelectionEvents();
3243 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
3245 GtkDisableSelectionEvents();
3247 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3250 iter
.user_data
= (gpointer
) item
.GetID();
3251 gtk_tree_selection_select_iter( selection
, &iter
);
3253 GtkEnableSelectionEvents();
3256 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
3258 GtkDisableSelectionEvents();
3260 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3263 iter
.user_data
= (gpointer
) item
.GetID();
3264 gtk_tree_selection_unselect_iter( selection
, &iter
);
3266 GtkEnableSelectionEvents();
3269 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
3271 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3274 iter
.user_data
= (gpointer
) item
.GetID();
3276 return gtk_tree_selection_iter_is_selected( selection
, &iter
);
3279 void wxDataViewCtrl::SelectAll()
3281 GtkDisableSelectionEvents();
3283 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3285 gtk_tree_selection_select_all( selection
);
3287 GtkEnableSelectionEvents();
3290 void wxDataViewCtrl::UnselectAll()
3292 GtkDisableSelectionEvents();
3294 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3296 gtk_tree_selection_unselect_all( selection
);
3298 GtkEnableSelectionEvents();
3301 void wxDataViewCtrl::EnsureVisible( const wxDataViewItem
& item
, const wxDataViewColumn
*column
)
3304 iter
.user_data
= (gpointer
) item
.GetID();
3305 GtkTreePath
*path
= m_internal
->get_path( &iter
);
3306 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview
), path
, NULL
, false, 0.0, 0.0 );
3307 gtk_tree_path_free( path
);
3310 void wxDataViewCtrl::HitTest( const wxPoint
&point
,
3311 wxDataViewItem
&item
, wxDataViewColumn
*&column
) const
3313 item
= wxDataViewItem(0);
3317 wxRect
wxDataViewCtrl::GetItemRect( const wxDataViewItem
&item
,
3318 const wxDataViewColumn
*column
) const
3323 void wxDataViewCtrl::DoSetExpanderColumn()
3325 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview
),
3326 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
3329 void wxDataViewCtrl::DoSetIndent()
3333 void wxDataViewCtrl::GtkDisableSelectionEvents()
3335 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3336 g_signal_handlers_disconnect_by_func( selection
,
3337 (gpointer
) (wxdataview_selection_changed_callback
), this);
3340 void wxDataViewCtrl::GtkEnableSelectionEvents()
3342 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
3343 g_signal_connect_after (selection
, "changed",
3344 G_CALLBACK (wxdataview_selection_changed_callback
), this);
3349 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
3351 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
3356 // !wxUSE_GENERICDATAVIEWCTRL
3359 // wxUSE_DATAVIEWCTRL