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 wxDataViewModel
*g_model
= NULL
;
48 class wxGtkTreeModelNode
;
51 typedef struct _GtkWxTreeModel GtkWxTreeModel
;
54 //-----------------------------------------------------------------------------
55 // wxDataViewCtrlInternal
56 //-----------------------------------------------------------------------------
58 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
59 WX_DEFINE_LIST(ItemList
);
61 class wxDataViewCtrlInternal
64 wxDataViewCtrlInternal( wxDataViewCtrl
*owner
, wxDataViewModel
*wx_model
, GtkWxTreeModel
*owner
);
65 ~wxDataViewCtrlInternal();
67 gboolean
get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
);
68 GtkTreePath
*get_path( GtkTreeIter
*iter
);
69 GtkTreePath
*get_path_safe( GtkTreeIter
*iter
);
70 gboolean
iter_next( GtkTreeIter
*iter
);
71 gboolean
iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
);
72 gboolean
iter_has_child( GtkTreeIter
*iter
);
73 gint
iter_n_children( GtkTreeIter
*iter
);
74 gboolean
iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
);
75 gboolean
iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
);
77 wxDataViewModel
* GetDataViewModel() { return m_wx_model
; }
78 wxDataViewCtrl
* GetOwner() { return m_owner
; }
79 GtkWxTreeModel
* GetGtkModel() { return m_gtk_model
; }
81 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
82 bool ItemDeleted( const wxDataViewItem
&item
);
83 bool ItemChanged( const wxDataViewItem
&item
);
84 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
90 wxGtkTreeModelNode
*FindNode( const wxDataViewItem
&item
);
91 wxGtkTreeModelNode
*FindNode( GtkTreeIter
*iter
);
92 wxGtkTreeModelNode
*FindParentNode( const wxDataViewItem
&item
);
93 wxGtkTreeModelNode
*FindParentNode( GtkTreeIter
*iter
);
94 void BuildBranch( wxGtkTreeModelNode
*branch
);
97 wxGtkTreeModelNode
*m_root
;
98 wxDataViewModel
*m_wx_model
;
99 GtkWxTreeModel
*m_gtk_model
;
100 wxDataViewCtrl
*m_owner
;
104 //-----------------------------------------------------------------------------
105 // wxGtkTreeModelNode
106 //-----------------------------------------------------------------------------
108 int LINKAGEMODE
wxGtkTreeModelNodeCmp( void *id1
, void *id2
);
110 WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode
*, wxGtkTreeModelNodes
);
111 WX_DEFINE_SORTED_ARRAY( void* , wxGtkTreeModelChildren
);
113 class wxGtkTreeModelNode
116 wxGtkTreeModelNode( wxGtkTreeModelNode
* parent
, const wxDataViewItem
&item
,
117 wxDataViewCtrlInternal
*internal
)
121 m_internal
= internal
;
122 g_model
= internal
->GetDataViewModel();
123 m_children
= new wxGtkTreeModelChildren( wxGtkTreeModelNodeCmp
);
126 ~wxGtkTreeModelNode()
128 g_model
= m_internal
->GetDataViewModel();
129 size_t count
= m_children
->GetCount();
131 for (i
= 0; i
< count
; i
++)
133 wxGtkTreeModelNode
*child
= m_nodes
.Item( i
);
139 unsigned int AddNode( wxGtkTreeModelNode
* child
)
141 g_model
= m_internal
->GetDataViewModel();
142 m_nodes
.Add( child
);
143 return m_children
->Add( child
->GetItem().GetID() );
146 unsigned int AddLeave( void* id
)
148 g_model
= m_internal
->GetDataViewModel();
149 return m_children
->Add( id
);
152 void DeleteChild( void* id
)
154 g_model
= m_internal
->GetDataViewModel();
156 size_t count
= m_children
->GetCount();
157 for (pos
= 0; pos
< count
; pos
++)
159 if (m_children
->Item( pos
) == id
)
161 m_children
->RemoveAt( pos
);
165 count
= m_nodes
.GetCount();
166 for (pos
= 0; pos
< count
; pos
++)
168 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
169 if (node
->GetItem().GetID() == id
)
171 m_nodes
.RemoveAt( pos
);
179 wxGtkTreeModelNode
* GetParent()
181 wxGtkTreeModelNodes
&GetNodes()
183 wxGtkTreeModelChildren
&GetChildren()
184 { return *m_children
; }
186 unsigned int GetChildCount() { return m_children
->GetCount(); }
187 unsigned int GetNodesCount() { return m_nodes
.GetCount(); }
189 wxDataViewItem
&GetItem() { return m_item
; }
190 wxDataViewCtrlInternal
*GetInternal() { return m_internal
; }
195 wxGtkTreeModelNode
*m_parent
;
196 wxGtkTreeModelNodes m_nodes
;
197 wxGtkTreeModelChildren
*m_children
;
198 wxDataViewItem m_item
;
199 wxDataViewCtrlInternal
*m_internal
;
203 int LINKAGEMODE
wxGtkTreeModelNodeCmp( void* id1
, void* id2
)
205 return g_model
->Compare( id1
, id2
);
208 //-----------------------------------------------------------------------------
210 //-----------------------------------------------------------------------------
212 extern bool g_blockEventsOnDrag
;
214 //-----------------------------------------------------------------------------
215 // define new GTK+ class wxGtkTreeModel
216 //-----------------------------------------------------------------------------
220 #define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ())
221 #define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel))
222 #define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
223 #define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL))
224 #define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL))
225 #define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
227 GType
gtk_wx_tree_model_get_type (void);
229 typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass
;
231 struct _GtkWxTreeModel
237 wxDataViewCtrlInternal
*internal
;
240 struct _GtkWxTreeModelClass
242 GObjectClass list_parent_class
;
245 static GtkWxTreeModel
*wxgtk_tree_model_new (void);
246 static void wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
);
247 static void wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
);
248 static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
);
249 static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
);
250 static void wxgtk_tree_model_finalize (GObject
*object
);
251 static GtkTreeModelFlags
wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
);
252 static gint
wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
);
253 static GType
wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
255 static gboolean
wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
258 static GtkTreePath
*wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
260 static GtkTreePath
*wxgtk_tree_model_get_path_safe (GtkTreeModel
*tree_model
,
262 static void wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
266 static gboolean
wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
268 static gboolean
wxgtk_tree_model_iter_children (GtkTreeModel
*tree_model
,
270 GtkTreeIter
*parent
);
271 static gboolean
wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
273 static gint
wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
275 static gboolean
wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
279 static gboolean
wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
284 static gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
285 gint
*sort_column_id
,
287 static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
290 static void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
292 GtkTreeIterCompareFunc func
,
294 GtkDestroyNotify destroy
);
295 static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
296 GtkTreeIterCompareFunc func
,
298 GtkDestroyNotify destroy
);
299 static gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
);
303 static GObjectClass
*list_parent_class
= NULL
;
306 gtk_wx_tree_model_get_type (void)
308 static GType tree_model_type
= 0;
310 if (!tree_model_type
)
312 const GTypeInfo tree_model_info
=
314 sizeof (GtkWxTreeModelClass
),
315 NULL
, /* base_init */
316 NULL
, /* base_finalize */
317 (GClassInitFunc
) wxgtk_tree_model_class_init
,
318 NULL
, /* class_finalize */
319 NULL
, /* class_data */
320 sizeof (GtkWxTreeModel
),
322 (GInstanceInitFunc
) wxgtk_tree_model_init
,
325 static const GInterfaceInfo tree_model_iface_info
=
327 (GInterfaceInitFunc
) wxgtk_tree_model_tree_model_init
,
332 static const GInterfaceInfo sortable_iface_info
=
334 (GInterfaceInitFunc
) wxgtk_tree_model_sortable_init
,
339 tree_model_type
= g_type_register_static (G_TYPE_OBJECT
, "GtkWxTreeModel",
340 &tree_model_info
, (GTypeFlags
)0 );
342 g_type_add_interface_static (tree_model_type
,
344 &tree_model_iface_info
);
345 g_type_add_interface_static (tree_model_type
,
346 GTK_TYPE_TREE_SORTABLE
,
347 &sortable_iface_info
);
350 return tree_model_type
;
353 static GtkWxTreeModel
*
354 wxgtk_tree_model_new(void)
356 GtkWxTreeModel
*retval
= (GtkWxTreeModel
*) g_object_new (GTK_TYPE_WX_TREE_MODEL
, NULL
);
361 wxgtk_tree_model_class_init (GtkWxTreeModelClass
*klass
)
363 list_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
364 GObjectClass
*object_class
= (GObjectClass
*) klass
;
365 object_class
->finalize
= wxgtk_tree_model_finalize
;
369 wxgtk_tree_model_tree_model_init (GtkTreeModelIface
*iface
)
371 iface
->get_flags
= wxgtk_tree_model_get_flags
;
372 iface
->get_n_columns
= wxgtk_tree_model_get_n_columns
;
373 iface
->get_column_type
= wxgtk_tree_model_get_column_type
;
374 iface
->get_iter
= wxgtk_tree_model_get_iter
;
375 iface
->get_path
= wxgtk_tree_model_get_path
;
376 iface
->get_value
= wxgtk_tree_model_get_value
;
377 iface
->iter_next
= wxgtk_tree_model_iter_next
;
378 iface
->iter_children
= wxgtk_tree_model_iter_children
;
379 iface
->iter_has_child
= wxgtk_tree_model_iter_has_child
;
380 iface
->iter_n_children
= wxgtk_tree_model_iter_n_children
;
381 iface
->iter_nth_child
= wxgtk_tree_model_iter_nth_child
;
382 iface
->iter_parent
= wxgtk_tree_model_iter_parent
;
386 wxgtk_tree_model_sortable_init (GtkTreeSortableIface
*iface
)
388 iface
->get_sort_column_id
= wxgtk_tree_model_get_sort_column_id
;
389 iface
->set_sort_column_id
= wxgtk_tree_model_set_sort_column_id
;
390 iface
->set_sort_func
= wxgtk_tree_model_set_sort_func
;
391 iface
->set_default_sort_func
= wxgtk_tree_model_set_default_sort_func
;
392 iface
->has_default_sort_func
= wxgtk_tree_model_has_default_sort_func
;
396 wxgtk_tree_model_init (GtkWxTreeModel
*tree_model
)
398 tree_model
->internal
= NULL
;
399 tree_model
->stamp
= g_random_int();
403 wxgtk_tree_model_finalize (GObject
*object
)
406 (* list_parent_class
->finalize
) (object
);
411 //-----------------------------------------------------------------------------
412 // implement callbacks from wxGtkTreeModel class by letting
413 // them call the methods of wxWidgets' wxDataViewModel
414 //-----------------------------------------------------------------------------
416 static GtkTreeModelFlags
417 wxgtk_tree_model_get_flags (GtkTreeModel
*tree_model
)
419 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (tree_model
), (GtkTreeModelFlags
)0 );
421 return GTK_TREE_MODEL_ITERS_PERSIST
;
425 wxgtk_tree_model_get_n_columns (GtkTreeModel
*tree_model
)
427 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
428 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), 0);
430 return wxtree_model
->internal
->GetDataViewModel()->GetColumnCount();
434 wxgtk_tree_model_get_column_type (GtkTreeModel
*tree_model
,
437 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
438 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), G_TYPE_INVALID
);
440 GType gtype
= G_TYPE_INVALID
;
442 wxString wxtype
= wxtree_model
->internal
->GetDataViewModel()->GetColumnType( (unsigned int) index
);
444 if (wxtype
== wxT("string"))
445 gtype
= G_TYPE_STRING
;
448 wxFAIL_MSG( _T("non-string columns not supported yet") );
455 wxgtk_tree_model_get_iter (GtkTreeModel
*tree_model
,
459 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
460 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
461 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
463 return wxtree_model
->internal
->get_iter( iter
, path
);
467 wxgtk_tree_model_get_path (GtkTreeModel
*tree_model
,
470 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
471 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), NULL
);
472 g_return_val_if_fail (iter
->stamp
== GTK_WX_TREE_MODEL (wxtree_model
)->stamp
, NULL
);
474 return wxtree_model
->internal
->get_path( iter
);
478 wxgtk_tree_model_get_path_safe (GtkTreeModel
*tree_model
,
481 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
482 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), NULL
);
483 g_return_val_if_fail (iter
->stamp
== GTK_WX_TREE_MODEL (wxtree_model
)->stamp
, NULL
);
485 return wxtree_model
->internal
->get_path_safe( iter
);
489 wxgtk_tree_model_get_value (GtkTreeModel
*tree_model
,
494 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
495 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
) );
497 wxDataViewModel
*model
= wxtree_model
->internal
->GetDataViewModel();
498 wxString mtype
= model
->GetColumnType( (unsigned int) column
);
499 if (mtype
== wxT("string"))
502 g_value_init( value
, G_TYPE_STRING
);
503 wxDataViewItem
item( (void*) iter
->user_data
);
504 model
->GetValue( variant
, item
, (unsigned int) column
);
506 g_value_set_string( value
, variant
.GetString().utf8_str() );
510 wxFAIL_MSG( _T("non-string columns not supported yet") );
515 wxgtk_tree_model_iter_next (GtkTreeModel
*tree_model
,
518 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
519 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
520 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
522 return wxtree_model
->internal
->iter_next( iter
);
526 wxgtk_tree_model_iter_children (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
== parent
->stamp
, FALSE
);
534 return wxtree_model
->internal
->iter_children( iter
, parent
);
538 wxgtk_tree_model_iter_has_child (GtkTreeModel
*tree_model
,
541 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
542 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
543 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, FALSE
);
545 return wxtree_model
->internal
->iter_has_child( iter
);
549 wxgtk_tree_model_iter_n_children (GtkTreeModel
*tree_model
,
552 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
553 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
554 g_return_val_if_fail (wxtree_model
->stamp
== iter
->stamp
, 0);
556 return wxtree_model
->internal
->iter_n_children( iter
);
560 wxgtk_tree_model_iter_nth_child (GtkTreeModel
*tree_model
,
565 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
566 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
568 return wxtree_model
->internal
->iter_nth_child( iter
, parent
, n
);
572 wxgtk_tree_model_iter_parent (GtkTreeModel
*tree_model
,
576 GtkWxTreeModel
*wxtree_model
= (GtkWxTreeModel
*) tree_model
;
577 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model
), FALSE
);
578 g_return_val_if_fail (wxtree_model
->stamp
== child
->stamp
, FALSE
);
580 return wxtree_model
->internal
->iter_parent( iter
, child
);
584 gboolean
wxgtk_tree_model_get_sort_column_id (GtkTreeSortable
*sortable
,
585 gint
*sort_column_id
,
588 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
590 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable
), FALSE
);
593 *sort_column_id
= tree_model
->internal
->GetDataViewModel()->GetSortingColumn();
597 bool ascending
= tree_model
->internal
->GetDataViewModel()->GetSortOrderAscending();
599 *order
= GTK_SORT_ASCENDING
;
601 *order
= GTK_SORT_DESCENDING
;
607 void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable
*sortable
,
611 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) sortable
;
612 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
614 bool ascending
= TRUE
;
615 if (order
!= GTK_SORT_ASCENDING
)
618 if ((sort_column_id
== (gint
) tree_model
->internal
->GetDataViewModel()->GetSortingColumn()) &&
619 (ascending
== tree_model
->internal
->GetDataViewModel()->GetSortOrderAscending()))
622 tree_model
->internal
->GetDataViewModel()->SetSortingColumn( sort_column_id
);
624 tree_model
->internal
->GetDataViewModel()->SetSortOrderAscending( ascending
);
626 gtk_tree_sortable_sort_column_changed (sortable
);
628 tree_model
->internal
->GetDataViewModel()->Resort();
631 void wxgtk_tree_model_set_sort_func (GtkTreeSortable
*sortable
,
633 GtkTreeIterCompareFunc func
,
635 GtkDestroyNotify destroy
)
637 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
638 g_return_if_fail (func
!= NULL
);
641 void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable
*sortable
,
642 GtkTreeIterCompareFunc func
,
644 GtkDestroyNotify destroy
)
646 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable
) );
647 g_return_if_fail (func
!= NULL
);
649 wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
652 gboolean
wxgtk_tree_model_has_default_sort_func (GtkTreeSortable
*sortable
)
657 //-----------------------------------------------------------------------------
658 // define new GTK+ class wxGtkRendererRenderer
659 //-----------------------------------------------------------------------------
663 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
664 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
665 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
666 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
667 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
668 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
670 GType
gtk_wx_cell_renderer_get_type (void);
672 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
673 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
675 struct _GtkWxCellRenderer
677 GtkCellRenderer parent
;
680 wxDataViewCustomRenderer
*cell
;
684 struct _GtkWxCellRendererClass
686 GtkCellRendererClass cell_parent_class
;
690 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
691 static void gtk_wx_cell_renderer_init (
692 GtkWxCellRenderer
*cell
);
693 static void gtk_wx_cell_renderer_class_init(
694 GtkWxCellRendererClass
*klass
);
695 static void gtk_wx_cell_renderer_finalize (
697 static void gtk_wx_cell_renderer_get_size (
698 GtkCellRenderer
*cell
,
700 GdkRectangle
*rectangle
,
705 static void gtk_wx_cell_renderer_render (
706 GtkCellRenderer
*cell
,
709 GdkRectangle
*background_area
,
710 GdkRectangle
*cell_area
,
711 GdkRectangle
*expose_area
,
712 GtkCellRendererState flags
);
713 static gboolean
gtk_wx_cell_renderer_activate(
714 GtkCellRenderer
*cell
,
718 GdkRectangle
*background_area
,
719 GdkRectangle
*cell_area
,
720 GtkCellRendererState flags
);
721 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
722 GtkCellRenderer
*cell
,
726 GdkRectangle
*background_area
,
727 GdkRectangle
*cell_area
,
728 GtkCellRendererState flags
);
731 static GObjectClass
*cell_parent_class
= NULL
;
736 gtk_wx_cell_renderer_get_type (void)
738 static GType cell_wx_type
= 0;
742 const GTypeInfo cell_wx_info
=
744 sizeof (GtkWxCellRendererClass
),
745 NULL
, /* base_init */
746 NULL
, /* base_finalize */
747 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
748 NULL
, /* class_finalize */
749 NULL
, /* class_data */
750 sizeof (GtkWxCellRenderer
),
752 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
755 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
756 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
763 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
766 cell
->last_click
= 0;
770 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
772 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
773 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
775 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
777 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
779 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
780 cell_class
->render
= gtk_wx_cell_renderer_render
;
781 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
782 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
786 gtk_wx_cell_renderer_finalize (GObject
*object
)
789 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
793 gtk_wx_cell_renderer_new (void)
795 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
800 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
801 GtkCellRenderer
*renderer
,
805 GdkRectangle
*background_area
,
806 GdkRectangle
*cell_area
,
807 GtkCellRendererState flags
)
809 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
810 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
811 if (!cell
->HasEditorCtrl())
815 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
821 rect
.x
+= cell_area
->x
;
822 rect
.y
+= cell_area
->y
;
823 // rect.width -= renderer->xpad * 2;
824 // rect.height -= renderer->ypad * 2;
826 // wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
827 wxRect
renderrect( cell_area
->x
, cell_area
->y
, cell_area
->width
, cell_area
->height
);
829 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
831 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, treepath
);
832 wxDataViewItem
item( (void*) iter
.user_data
);
833 gtk_tree_path_free( treepath
);
835 cell
->StartEditing( item
, renderrect
);
841 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
843 GdkRectangle
*cell_area
,
849 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
850 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
852 wxSize size
= cell
->GetSize();
854 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
855 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
862 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
866 *x_offset
= (gint
)((renderer
->xalign
*
867 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
868 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
872 *y_offset
= (gint
)((renderer
->yalign
*
873 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
874 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
882 *height
= calc_height
;
886 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
889 GdkRectangle
*background_area
,
890 GdkRectangle
*cell_area
,
891 GdkRectangle
*expose_area
,
892 GtkCellRendererState flags
)
895 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
896 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
899 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
905 rect
.x
+= cell_area
->x
;
906 rect
.y
+= cell_area
->y
;
907 rect
.width
-= renderer
->xpad
* 2;
908 rect
.height
-= renderer
->ypad
* 2;
911 if (gdk_rectangle_intersect (expose_area
, &rect
, &dummy
))
913 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
914 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
915 if (dc
->m_window
== NULL
)
917 dc
->m_window
= window
;
922 if (flags
& GTK_CELL_RENDERER_SELECTED
)
923 state
|= wxDATAVIEW_CELL_SELECTED
;
924 if (flags
& GTK_CELL_RENDERER_PRELIT
)
925 state
|= wxDATAVIEW_CELL_PRELIT
;
926 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
927 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
928 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
929 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
930 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
931 state
|= wxDATAVIEW_CELL_FOCUSED
;
932 cell
->Render( renderrect
, dc
, state
);
937 gtk_wx_cell_renderer_activate(
938 GtkCellRenderer
*renderer
,
942 GdkRectangle
*background_area
,
943 GdkRectangle
*cell_area
,
944 GtkCellRendererState flags
)
946 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
947 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
950 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
956 rect
.x
+= cell_area
->x
;
957 rect
.y
+= cell_area
->y
;
958 rect
.width
-= renderer
->xpad
* 2;
959 rect
.height
-= renderer
->ypad
* 2;
961 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
963 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
965 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
968 gtk_tree_path_free( treepath
);
970 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
976 // activated by <ENTER>
977 if (cell
->Activate( renderrect
, model
, item
, model_col
))
982 else if (event
->type
== GDK_BUTTON_PRESS
)
984 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
985 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
986 ((int) button_event
->y
) - renderrect
.y
);
989 if (button_event
->button
== 1)
991 if (cell
->LeftClick( pt
, renderrect
, model
, item
, model_col
))
993 // TODO: query system double-click time
994 if (button_event
->time
- wxrenderer
->last_click
< 400)
995 if (cell
->Activate( renderrect
, model
, item
, model_col
))
998 if (button_event
->button
== 3)
1000 if (cell
->RightClick( pt
, renderrect
, model
, item
, model_col
))
1004 wxrenderer
->last_click
= button_event
->time
;
1012 // ---------------------------------------------------------
1013 // wxGtkDataViewModelNotifier
1014 // ---------------------------------------------------------
1016 class wxGtkDataViewModelNotifier
: public wxDataViewModelNotifier
1019 wxGtkDataViewModelNotifier( GtkWxTreeModel
*wxgtk_model
,
1020 wxDataViewModel
*wx_model
,
1021 wxDataViewCtrl
*ctrl
);
1022 ~wxGtkDataViewModelNotifier();
1024 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
1025 virtual bool ItemDeleted( const wxDataViewItem
&item
);
1026 virtual bool ItemChanged( const wxDataViewItem
&item
);
1027 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
1028 virtual bool Cleared();
1029 virtual void Resort();
1031 GtkWxTreeModel
*m_wxgtk_model
;
1032 wxDataViewModel
*m_wx_model
;
1033 wxDataViewCtrl
*m_owner
;
1036 // ---------------------------------------------------------
1037 // wxGtkDataViewListModelNotifier
1038 // ---------------------------------------------------------
1040 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1041 GtkWxTreeModel
* wxgtk_model
, wxDataViewModel
*wx_model
,
1042 wxDataViewCtrl
*ctrl
)
1044 m_wxgtk_model
= wxgtk_model
;
1045 m_wx_model
= wx_model
;
1049 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1052 m_wxgtk_model
= NULL
;
1055 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
1057 m_owner
->GtkGetInternal()->ItemAdded( parent
, item
);
1060 iter
.stamp
= m_wxgtk_model
->stamp
;
1061 iter
.user_data
= (gpointer
) item
.GetID();
1063 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1064 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1065 gtk_tree_model_row_inserted(
1066 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1067 gtk_tree_path_free (path
);
1072 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem
&item
)
1075 iter
.stamp
= m_wxgtk_model
->stamp
;
1076 iter
.user_data
= (gpointer
) item
.GetID();
1078 GtkTreePath
*path
= wxgtk_tree_model_get_path_safe(
1079 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1080 gtk_tree_model_row_deleted(
1081 GTK_TREE_MODEL(m_wxgtk_model
), path
);
1082 gtk_tree_path_free (path
);
1084 m_owner
->GtkGetInternal()->ItemDeleted( item
);
1089 void wxGtkDataViewModelNotifier::Resort()
1091 m_owner
->GtkGetInternal()->Resort();
1094 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem
&item
)
1097 iter
.stamp
= m_wxgtk_model
->stamp
;
1098 iter
.user_data
= (gpointer
) item
.GetID();
1100 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1101 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1102 gtk_tree_model_row_changed(
1103 GTK_TREE_MODEL(m_wxgtk_model
), path
, &iter
);
1104 gtk_tree_path_free (path
);
1106 m_owner
->GtkGetInternal()->ItemChanged( item
);
1111 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem
&item
, unsigned int model_col
)
1113 // This adds GTK+'s missing MVC logic for ValueChanged
1115 for (index
= 0; index
< m_owner
->GetColumnCount(); index
++)
1117 wxDataViewColumn
*column
= m_owner
->GetColumn( index
);
1118 if (column
->GetModelColumn() == model_col
)
1120 GtkTreeView
*widget
= GTK_TREE_VIEW(m_owner
->m_treeview
);
1121 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
1125 iter
.stamp
= m_wxgtk_model
->stamp
;
1126 iter
.user_data
= (gpointer
) item
.GetID();
1127 GtkTreePath
*path
= wxgtk_tree_model_get_path(
1128 GTK_TREE_MODEL(m_wxgtk_model
), &iter
);
1129 GdkRectangle cell_area
;
1130 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
1131 gtk_tree_path_free( path
);
1133 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
1134 double d
= gtk_adjustment_get_value( hadjust
);
1135 int xdiff
= (int) d
;
1137 int ydiff
= gcolumn
->button
->allocation
.height
;
1139 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
1140 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
1142 m_owner
->GtkGetInternal()->ValueChanged( item
, model_col
);
1151 bool wxGtkDataViewModelNotifier::Cleared()
1153 // TODO: delete everything
1155 m_owner
->GtkGetInternal()->Cleared();
1160 // ---------------------------------------------------------
1161 // wxDataViewRenderer
1162 // ---------------------------------------------------------
1164 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
1166 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1168 wxDataViewRendererBase( varianttype
, mode
, align
)
1172 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1173 // after the m_renderer pointer has been initialized
1176 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
1178 GtkCellRendererMode gtkMode
;
1181 case wxDATAVIEW_CELL_INERT
:
1182 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
1184 case wxDATAVIEW_CELL_ACTIVATABLE
:
1185 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
1187 case wxDATAVIEW_CELL_EDITABLE
:
1188 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
1192 GValue gvalue
= { 0, };
1193 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1194 g_value_set_enum( &gvalue
, gtkMode
);
1195 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1196 g_value_unset( &gvalue
);
1199 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
1201 wxDataViewCellMode ret
;
1204 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
1206 switch (g_value_get_enum(&gvalue
))
1208 case GTK_CELL_RENDERER_MODE_INERT
:
1209 ret
= wxDATAVIEW_CELL_INERT
;
1211 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
1212 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
1214 case GTK_CELL_RENDERER_MODE_EDITABLE
:
1215 ret
= wxDATAVIEW_CELL_EDITABLE
;
1219 g_value_unset( &gvalue
);
1224 void wxDataViewRenderer::SetAlignment( int align
)
1226 // horizontal alignment:
1228 gfloat xalign
= 0.0;
1229 if (align
& wxALIGN_RIGHT
)
1231 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1234 GValue gvalue
= { 0, };
1235 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1236 g_value_set_float( &gvalue
, xalign
);
1237 g_object_set_property( G_OBJECT(m_renderer
), "xalign", &gvalue
);
1238 g_value_unset( &gvalue
);
1240 // vertical alignment:
1242 gfloat yalign
= 0.0;
1243 if (align
& wxALIGN_BOTTOM
)
1245 else if (align
& wxALIGN_CENTER_VERTICAL
)
1248 GValue gvalue2
= { 0, };
1249 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1250 g_value_set_float( &gvalue2
, yalign
);
1251 g_object_set_property( G_OBJECT(m_renderer
), "yalign", &gvalue2
);
1252 g_value_unset( &gvalue2
);
1255 int wxDataViewRenderer::GetAlignment() const
1260 // horizontal alignment:
1262 g_object_get( G_OBJECT(m_renderer
), "xalign", &gvalue
, NULL
);
1263 float xalign
= g_value_get_float( &gvalue
);
1265 ret
|= wxALIGN_LEFT
;
1266 else if (xalign
== 0.5)
1267 ret
|= wxALIGN_CENTER_HORIZONTAL
;
1269 ret
|= wxALIGN_RIGHT
;
1270 g_value_unset( &gvalue
);
1273 // vertical alignment:
1275 g_object_get( G_OBJECT(m_renderer
), "yalign", &gvalue
, NULL
);
1276 float yalign
= g_value_get_float( &gvalue
);
1279 else if (yalign
== 0.5)
1280 ret
|= wxALIGN_CENTER_VERTICAL
;
1282 ret
|= wxALIGN_BOTTOM
;
1283 g_value_unset( &gvalue
);
1290 // ---------------------------------------------------------
1291 // wxDataViewTextRenderer
1292 // ---------------------------------------------------------
1295 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1296 gchar
*arg1
, gchar
*arg2
, gpointer user_data
);
1299 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1300 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1302 wxDataViewTextRenderer
*cell
= (wxDataViewTextRenderer
*) user_data
;
1304 wxString tmp
= wxGTK_CONV_BACK_FONT(arg2
, cell
->GetOwner()->GetOwner()->GetFont());
1305 wxVariant value
= tmp
;
1306 if (!cell
->Validate( value
))
1309 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1311 GtkTreePath
*path
= gtk_tree_path_new_from_string( arg1
);
1313 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, path
);
1314 wxDataViewItem
item( (void*) iter
.user_data
);;
1315 gtk_tree_path_free( path
);
1317 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1319 model
->SetValue( value
, item
, model_col
);
1320 model
->ValueChanged( item
, model_col
);
1323 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
1325 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1327 wxDataViewRenderer( varianttype
, mode
, align
)
1329 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_text_new();
1331 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
1333 GValue gvalue
= { 0, };
1334 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1335 g_value_set_boolean( &gvalue
, true );
1336 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
1337 g_value_unset( &gvalue
);
1339 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
1343 SetAlignment(align
);
1346 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
1348 wxString tmp
= value
;
1350 GValue gvalue
= { 0, };
1351 g_value_init( &gvalue
, G_TYPE_STRING
);
1352 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( tmp
, GetOwner()->GetOwner()->GetFont() ) );
1353 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1354 g_value_unset( &gvalue
);
1359 bool wxDataViewTextRenderer::GetValue( wxVariant
&value
) const
1361 GValue gvalue
= { 0, };
1362 g_value_init( &gvalue
, G_TYPE_STRING
);
1363 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1364 wxString tmp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
),
1365 wx_const_cast(wxDataViewTextRenderer
*, this)->GetOwner()->GetOwner()->GetFont() );
1366 g_value_unset( &gvalue
);
1373 void wxDataViewTextRenderer::SetAlignment( int align
)
1375 wxDataViewRenderer::SetAlignment(align
);
1377 if (gtk_check_version(2,10,0))
1380 // horizontal alignment:
1381 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
1382 if (align
& wxALIGN_RIGHT
)
1383 pangoAlign
= PANGO_ALIGN_RIGHT
;
1384 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1385 pangoAlign
= PANGO_ALIGN_CENTER
;
1387 GValue gvalue
= { 0, };
1388 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1389 g_value_set_enum( &gvalue
, pangoAlign
);
1390 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
1391 g_value_unset( &gvalue
);
1394 // ---------------------------------------------------------
1395 // wxDataViewBitmapRenderer
1396 // ---------------------------------------------------------
1398 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
1400 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1402 wxDataViewRenderer( varianttype
, mode
, align
)
1404 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_pixbuf_new();
1407 SetAlignment(align
);
1410 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
1412 if (value
.GetType() == wxT("wxBitmap"))
1417 // This may create a Pixbuf representation in the
1418 // wxBitmap object (and it will stay there)
1419 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1421 GValue gvalue
= { 0, };
1422 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1423 g_value_set_object( &gvalue
, pixbuf
);
1424 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1425 g_value_unset( &gvalue
);
1430 if (value
.GetType() == wxT("wxIcon"))
1435 // This may create a Pixbuf representation in the
1436 // wxBitmap object (and it will stay there)
1437 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1439 GValue gvalue
= { 0, };
1440 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1441 g_value_set_object( &gvalue
, pixbuf
);
1442 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1443 g_value_unset( &gvalue
);
1451 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&value
) const
1456 // ---------------------------------------------------------
1457 // wxDataViewToggleRenderer
1458 // ---------------------------------------------------------
1461 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1462 gchar
*path
, gpointer user_data
);
1465 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1466 gchar
*path
, gpointer user_data
)
1468 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
1471 GValue gvalue
= { 0, };
1472 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1473 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
1474 bool tmp
= g_value_get_boolean( &gvalue
);
1475 g_value_unset( &gvalue
);
1479 wxVariant value
= tmp
;
1480 if (!cell
->Validate( value
))
1483 wxDataViewModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1485 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
1487 cell
->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter
, gtk_path
);
1488 wxDataViewItem
item( (void*) iter
.user_data
);;
1489 gtk_tree_path_free( gtk_path
);
1491 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1493 model
->SetValue( value
, item
, model_col
);
1494 model
->ValueChanged( item
, model_col
);
1497 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1499 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1500 wxDataViewCellMode mode
, int align
) :
1501 wxDataViewRenderer( varianttype
, mode
, align
)
1503 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
1505 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1507 g_signal_connect_after( m_renderer
, "toggled",
1508 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
1512 GValue gvalue
= { 0, };
1513 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1514 g_value_set_boolean( &gvalue
, false );
1515 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
1516 g_value_unset( &gvalue
);
1520 SetAlignment(align
);
1523 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1527 GValue gvalue
= { 0, };
1528 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1529 g_value_set_boolean( &gvalue
, tmp
);
1530 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1531 g_value_unset( &gvalue
);
1536 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
1538 GValue gvalue
= { 0, };
1539 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1540 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1541 bool tmp
= g_value_get_boolean( &gvalue
);
1542 g_value_unset( &gvalue
);
1549 // ---------------------------------------------------------
1550 // wxDataViewCustomRenderer
1551 // ---------------------------------------------------------
1553 class wxDataViewCtrlDC
: public wxWindowDC
1556 wxDataViewCtrlDC( wxDataViewCtrl
*window
)
1558 GtkWidget
*widget
= window
->m_treeview
;
1562 m_context
= window
->GtkGetPangoDefaultContext();
1563 m_layout
= pango_layout_new( m_context
);
1564 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
1566 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
1568 // Set m_window later
1570 // m_owner = window;
1574 // ---------------------------------------------------------
1575 // wxDataViewCustomRenderer
1576 // ---------------------------------------------------------
1578 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
1580 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
1581 wxDataViewCellMode mode
, int align
,
1583 wxDataViewRenderer( varianttype
, mode
, align
)
1593 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
1595 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
1596 renderer
->cell
= this;
1598 m_renderer
= (GtkCellRenderer
*) renderer
;
1601 SetAlignment(align
);
1606 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
1612 wxDC
*wxDataViewCustomRenderer::GetDC()
1616 if (GetOwner() == NULL
)
1618 if (GetOwner()->GetOwner() == NULL
)
1620 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
1626 // ---------------------------------------------------------
1627 // wxDataViewProgressRenderer
1628 // ---------------------------------------------------------
1630 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
1632 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
1633 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1634 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
1640 if (!gtk_check_version(2,6,0))
1642 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
1644 GValue gvalue
= { 0, };
1645 g_value_init( &gvalue
, G_TYPE_STRING
);
1647 // FIXME: font encoding support
1648 g_value_set_string( &gvalue
, wxGTK_CONV_SYS(m_label
) );
1649 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1650 g_value_unset( &gvalue
);
1653 SetAlignment(align
);
1658 // Use custom cell code
1659 wxDataViewCustomRenderer::Init(mode
, align
);
1663 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
1667 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
1670 if (!gtk_check_version(2,6,0))
1672 gint tmp
= (long) value
;
1673 GValue gvalue
= { 0, };
1674 g_value_init( &gvalue
, G_TYPE_INT
);
1675 g_value_set_int( &gvalue
, tmp
);
1676 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
1677 g_value_unset( &gvalue
);
1682 m_value
= (long) value
;
1684 if (m_value
< 0) m_value
= 0;
1685 if (m_value
> 100) m_value
= 100;
1691 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
1696 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1698 double pct
= (double)m_value
/ 100.0;
1700 bar
.width
= (int)(cell
.width
* pct
);
1701 dc
->SetPen( *wxTRANSPARENT_PEN
);
1702 dc
->SetBrush( *wxBLUE_BRUSH
);
1703 dc
->DrawRectangle( bar
);
1705 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1706 dc
->SetPen( *wxBLACK_PEN
);
1707 dc
->DrawRectangle( cell
);
1712 wxSize
wxDataViewProgressRenderer::GetSize() const
1714 return wxSize(40,12);
1717 // ---------------------------------------------------------
1718 // wxDataViewDateRenderer
1719 // ---------------------------------------------------------
1721 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
1724 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
1725 wxDataViewModel
*model
, const wxDataViewItem
&item
, unsigned int col
) :
1726 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
1731 m_cal
= new wxCalendarCtrl( this, -1, *value
);
1732 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
1733 sizer
->Add( m_cal
, 1, wxGROW
);
1738 virtual void OnDismiss()
1742 void OnCalendar( wxCalendarEvent
&event
);
1744 wxCalendarCtrl
*m_cal
;
1745 wxDataViewModel
*m_model
;
1746 wxDataViewItem m_item
;
1750 DECLARE_EVENT_TABLE()
1753 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
1754 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
1757 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
1759 wxDateTime date
= event
.GetDate();
1760 wxVariant value
= date
;
1761 m_model
->SetValue( value
, m_item
, m_col
);
1762 m_model
->ValueChanged( m_item
, m_col
);
1766 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
1768 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1769 wxDataViewCellMode mode
, int align
) :
1770 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1773 SetAlignment(align
);
1776 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1778 m_date
= value
.GetDateTime();
1783 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
1788 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1790 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
1791 wxString tmp
= m_date
.FormatDate();
1792 dc
->DrawText( tmp
, cell
.x
, cell
.y
);
1797 wxSize
wxDataViewDateRenderer::GetSize() const
1799 wxString tmp
= m_date
.FormatDate();
1801 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
1802 return wxSize(x
,y
+d
);
1805 bool wxDataViewDateRenderer::Activate( wxRect cell
, wxDataViewModel
*model
,
1806 const wxDataViewItem
&item
, unsigned int col
)
1809 model
->GetValue( variant
, item
, col
);
1810 wxDateTime value
= variant
.GetDateTime();
1812 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1813 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
1814 wxPoint pos
= wxGetMousePosition();
1817 popup
->Popup( popup
->m_cal
);
1822 // ---------------------------------------------------------
1824 // ---------------------------------------------------------
1828 gtk_dataview_header_button_press_callback( GtkWidget
*widget
,
1829 GdkEventButton
*gdk_event
,
1830 wxDataViewColumn
*column
)
1832 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
1835 if (gdk_event
->button
== 1)
1837 wxDataViewCtrl
*dv
= column
->GetOwner();
1838 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
1839 event
.SetDataViewColumn( column
);
1840 event
.SetModel( dv
->GetModel() );
1841 if (dv
->GetEventHandler()->ProcessEvent( event
))
1849 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
1850 GtkCellRenderer
*cell
,
1851 GtkTreeModel
*model
,
1857 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
1858 GtkCellRenderer
*renderer
,
1859 GtkTreeModel
*model
,
1863 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model
));
1864 GtkWxTreeModel
*tree_model
= (GtkWxTreeModel
*) model
;
1866 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
1868 wxDataViewItem
item( (void*) iter
->user_data
);
1871 tree_model
->internal
->GetDataViewModel()->GetValue( value
, item
, cell
->GetOwner()->GetModelColumn() );
1873 if (value
.GetType() != cell
->GetVariantType())
1874 wxLogError( wxT("Wrong type, required: %s but: %s"),
1875 value
.GetType().c_str(),
1876 cell
->GetVariantType().c_str() );
1878 cell
->SetValue( value
);
1881 wxListItemAttr attr
;
1882 tree_model
->model
->GetAttr( attr
, cell
->GetOwner()->GetModelColumn(), model_row
);
1884 if (attr
.HasBackgroundColour())
1886 wxColour colour
= attr
.GetBackgroundColour();
1887 const GdkColor
* const gcol
= colour
.GetColor();
1889 GValue gvalue
= { 0, };
1890 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
1891 g_value_set_boxed( &gvalue
, gcol
);
1892 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
1893 g_value_unset( &gvalue
);
1897 GValue gvalue
= { 0, };
1898 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1899 g_value_set_boolean( &gvalue
, FALSE
);
1900 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
1901 g_value_unset( &gvalue
);
1907 IMPLEMENT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
1909 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
1910 unsigned int model_column
, int width
,
1911 wxAlignment align
, int flags
) :
1912 wxDataViewColumnBase( title
, cell
, model_column
, width
, align
, flags
)
1914 Init( align
, flags
, width
);
1916 gtk_tree_view_column_set_clickable( GTK_TREE_VIEW_COLUMN(m_column
), TRUE
);
1920 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
1921 unsigned int model_column
, int width
,
1922 wxAlignment align
, int flags
) :
1923 wxDataViewColumnBase( bitmap
, cell
, model_column
, width
, align
, flags
)
1925 Init( align
, flags
, width
);
1927 SetBitmap( bitmap
);
1930 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
1932 m_isConnected
= false;
1934 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) GetRenderer()->GetGtkHandle();
1935 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
1936 m_column
= (GtkWidget
*) column
;
1939 SetAlignment( align
);
1941 // NOTE: we prefer not to call SetMinWidth(wxDVC_DEFAULT_MINWIDTH);
1942 // as GTK+ is smart and unless explicitely told, will set the minimal
1943 // width to the title's lenght, which is a better default
1945 // the GTK_TREE_VIEW_COLUMN_FIXED is required by the "fixed height" mode
1946 // that we use for the wxDataViewCtrl
1947 gtk_tree_view_column_set_fixed_width( column
, width
< 0 ? wxDVC_DEFAULT_WIDTH
: width
);
1948 gtk_tree_view_column_set_sizing( column
, GTK_TREE_VIEW_COLUMN_FIXED
);
1950 gtk_tree_view_column_pack_end( column
, renderer
, TRUE
);
1952 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
1953 wxGtkTreeCellDataFunc
, (gpointer
) GetRenderer(), NULL
);
1956 wxDataViewColumn::~wxDataViewColumn()
1960 void wxDataViewColumn::OnInternalIdle()
1965 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
1967 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
1970 g_signal_connect(column
->button
, "button_press_event",
1971 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
1973 m_isConnected
= true;
1978 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
1980 wxDataViewColumnBase::SetOwner( owner
);
1982 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
1984 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
1987 void wxDataViewColumn::SetTitle( const wxString
&title
)
1989 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
1993 // disconnect before column->button gets recreated
1994 g_signal_handlers_disconnect_by_func( column
->button
,
1995 (GtkWidget
*) gtk_dataview_header_button_press_callback
, this);
1997 m_isConnected
= false;
2000 // FIXME: can it really happen that we don't have the owner here??
2001 wxDataViewCtrl
*ctrl
= GetOwner();
2002 gtk_tree_view_column_set_title( column
, ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
2003 : wxGTK_CONV_SYS(title
) );
2005 gtk_tree_view_column_set_widget( column
, NULL
);
2008 wxString
wxDataViewColumn::GetTitle() const
2010 const gchar
*str
= gtk_tree_view_column_get_title( GTK_TREE_VIEW_COLUMN(m_column
) );
2011 return wxConvFileName
->cMB2WX(str
);
2014 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
2016 wxDataViewColumnBase::SetBitmap( bitmap
);
2018 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2021 GtkImage
*gtk_image
= GTK_IMAGE( gtk_image_new() );
2023 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
2024 if (bitmap
.GetMask())
2025 mask
= bitmap
.GetMask()->GetBitmap();
2027 if (bitmap
.HasPixbuf())
2029 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
2030 bitmap
.GetPixbuf());
2034 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
2035 bitmap
.GetPixmap(), mask
);
2037 gtk_widget_show( GTK_WIDGET(gtk_image
) );
2039 gtk_tree_view_column_set_widget( column
, GTK_WIDGET(gtk_image
) );
2043 gtk_tree_view_column_set_widget( column
, NULL
);
2047 void wxDataViewColumn::SetHidden( bool hidden
)
2049 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
2052 void wxDataViewColumn::SetResizeable( bool resizeable
)
2054 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizeable
);
2057 void wxDataViewColumn::SetAlignment( wxAlignment align
)
2059 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2061 gfloat xalign
= 0.0;
2062 if (align
== wxALIGN_RIGHT
)
2064 if (align
== wxALIGN_CENTER_HORIZONTAL
||
2065 align
== wxALIGN_CENTER
)
2068 gtk_tree_view_column_set_alignment( column
, xalign
);
2071 wxAlignment
wxDataViewColumn::GetAlignment() const
2073 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
2076 return wxALIGN_RIGHT
;
2078 return wxALIGN_CENTER_HORIZONTAL
;
2080 return wxALIGN_LEFT
;
2083 void wxDataViewColumn::SetSortable( bool sortable
)
2085 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2088 gtk_tree_view_column_set_sort_column_id( column
, GetModelColumn() );
2090 gtk_tree_view_column_set_sort_column_id( column
, -1 );
2093 bool wxDataViewColumn::IsSortable() const
2095 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2096 return (gtk_tree_view_column_get_sort_column_id( column
) != -1);
2099 bool wxDataViewColumn::IsResizeable() const
2101 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2102 return gtk_tree_view_column_get_resizable( column
);
2105 bool wxDataViewColumn::IsHidden() const
2107 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2108 return !gtk_tree_view_column_get_visible( column
);
2111 void wxDataViewColumn::SetSortOrder( bool ascending
)
2113 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2116 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
2118 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
2121 bool wxDataViewColumn::IsSortOrderAscending() const
2123 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
2125 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
2128 void wxDataViewColumn::SetMinWidth( int width
)
2130 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2133 int wxDataViewColumn::GetMinWidth() const
2135 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2138 int wxDataViewColumn::GetWidth() const
2140 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
2143 void wxDataViewColumn::SetWidth( int width
)
2145 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
2149 //-----------------------------------------------------------------------------
2150 // wxGtkTreeModelNode
2151 //-----------------------------------------------------------------------------
2153 void wxGtkTreeModelNode::Resort()
2155 g_model
= m_internal
->GetDataViewModel();
2157 size_t child_count
= GetChildCount();
2158 if (child_count
== 0)
2161 size_t node_count
= GetNodesCount();
2163 if (child_count
== 1)
2165 if (node_count
== 1)
2167 wxGtkTreeModelNode
*node
= m_nodes
.Item( 0 );
2173 wxGtkTreeModelChildren
*new_array
= new wxGtkTreeModelChildren( wxGtkTreeModelNodeCmp
);
2176 for (pos
= 0; pos
< child_count
; pos
++)
2177 new_array
->Add( m_children
->Item( pos
) );
2179 gint
*new_order
= new gint
[child_count
];
2181 for (pos
= 0; pos
< child_count
; pos
++)
2183 void *id
= new_array
->Item( pos
);
2185 for (old_pos
= 0; old_pos
< child_count
; old_pos
++)
2187 if (id
== m_children
->Item(old_pos
))
2189 new_order
[pos
] = old_pos
;
2195 // for (pos = 0; pos < count; pos++)
2196 // m_children->Clear();
2199 m_children
= new_array
;
2201 GtkTreeModel
*gtk_tree_model
= GTK_TREE_MODEL( m_internal
->GetGtkModel() );
2203 GtkTreePath
*path
= gtk_tree_path_new ();
2204 wxGtkTreeModelNode
*parent
= GetParent();
2205 void *id
= GetItem().GetID();
2209 int pos
= parent
->GetChildren().Index( id
);
2210 gtk_tree_path_prepend_index( path
, pos
);
2211 id
= parent
->GetItem().GetID();
2212 parent
= parent
->GetParent();
2216 iter
.user_data
= id
;
2217 iter
.stamp
= m_internal
->GetGtkModel()->stamp
;
2218 gtk_tree_model_rows_reordered( gtk_tree_model
, path
, &iter
, new_order
);
2220 gtk_tree_path_free (path
);
2222 delete [] new_order
;
2224 for (pos
= 0; pos
< node_count
; pos
++)
2226 wxGtkTreeModelNode
*node
= m_nodes
.Item( pos
);
2231 //-----------------------------------------------------------------------------
2232 // wxDataViewCtrlInternal
2233 //-----------------------------------------------------------------------------
2235 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl
*owner
,
2236 wxDataViewModel
*wx_model
, GtkWxTreeModel
*gtk_model
)
2239 m_wx_model
= wx_model
;
2240 m_gtk_model
= gtk_model
;
2245 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
2247 g_object_unref( m_gtk_model
);
2250 void wxDataViewCtrlInternal::InitTree()
2252 wxDataViewItem item
;
2253 m_root
= new wxGtkTreeModelNode( NULL
, item
, this );
2255 BuildBranch( m_root
);
2258 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode
*node
)
2260 if (node
->GetChildCount() == 0)
2262 wxDataViewItem child
= m_wx_model
->GetFirstChild( node
->GetItem() );
2263 while (child
.IsOk())
2265 if (m_wx_model
->IsContainer( child
))
2266 node
->AddNode( new wxGtkTreeModelNode( node
, child
, this ) );
2268 node
->AddLeave( child
.GetID() );
2270 // Don't send any events here
2272 child
= m_wx_model
->GetNextSibling( child
);
2277 void wxDataViewCtrlInternal::Resort()
2282 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
2284 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2285 if (m_wx_model
->IsContainer( item
))
2286 parent_node
->AddNode( new wxGtkTreeModelNode( parent_node
, item
, this ) );
2288 parent_node
->AddLeave( item
.GetID() );
2290 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_ADDED
, m_owner
->GetId() );
2291 event
.SetEventObject( m_owner
);
2292 event
.SetModel( m_owner
->GetModel() );
2293 event
.SetItem( item
);
2294 m_owner
->GetEventHandler()->ProcessEvent( event
);
2299 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem
&item
)
2301 wxGtkTreeModelNode
*parent
= FindParentNode( item
);
2302 parent
->DeleteChild( item
.GetID() );
2304 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED
, m_owner
->GetId() );
2305 event
.SetEventObject( m_owner
);
2306 event
.SetModel( m_owner
->GetModel() );
2307 event
.SetItem( item
);
2308 m_owner
->GetEventHandler()->ProcessEvent( event
);
2313 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem
&item
)
2315 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_CHANGED
, m_owner
->GetId() );
2316 event
.SetEventObject( m_owner
);
2317 event
.SetModel( m_owner
->GetModel() );
2318 event
.SetItem( item
);
2319 m_owner
->GetEventHandler()->ProcessEvent( event
);
2324 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
2326 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED
, m_owner
->GetId() );
2327 event
.SetEventObject( m_owner
);
2328 event
.SetModel( m_owner
->GetModel() );
2329 event
.SetColumn( col
);
2330 event
.SetItem( item
);
2331 m_owner
->GetEventHandler()->ProcessEvent( event
);
2336 bool wxDataViewCtrlInternal::Cleared()
2338 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED
, m_owner
->GetId() );
2339 event
.SetEventObject( m_owner
);
2340 event
.SetModel( m_owner
->GetModel() );
2341 m_owner
->GetEventHandler()->ProcessEvent( event
);
2346 gboolean
wxDataViewCtrlInternal::get_iter( GtkTreeIter
*iter
, GtkTreePath
*path
)
2348 g_model
= m_wx_model
;
2350 int depth
= gtk_tree_path_get_depth( path
);
2352 wxGtkTreeModelNode
*node
= m_root
;
2355 for (i
= 0; i
< depth
; i
++)
2357 BuildBranch( node
);
2359 gint pos
= gtk_tree_path_get_indices (path
)[i
];
2360 if (pos
< 0) return FALSE
;
2361 if ((size_t)pos
>= node
->GetChildCount()) return FALSE
;
2363 void* id
= node
->GetChildren().Item( (size_t) pos
);
2367 iter
->stamp
= m_gtk_model
->stamp
;
2368 iter
->user_data
= id
;
2372 size_t count
= node
->GetNodes().GetCount();
2374 for (pos2
= 0; pos2
< count
; pos2
++)
2376 wxGtkTreeModelNode
*child_node
= node
->GetNodes().Item( pos2
);
2377 if (child_node
->GetItem().GetID() == id
)
2388 GtkTreePath
*wxDataViewCtrlInternal::get_path( GtkTreeIter
*iter
)
2390 g_model
= m_wx_model
;
2392 GtkTreePath
*retval
= gtk_tree_path_new ();
2393 void *id
= iter
->user_data
;
2395 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
2398 int pos
= node
->GetChildren().Index( id
);
2399 gtk_tree_path_prepend_index( retval
, pos
);
2401 id
= node
->GetItem().GetID();
2402 node
= node
->GetParent();
2408 GtkTreePath
*wxDataViewCtrlInternal::get_path_safe( GtkTreeIter
*iter
)
2410 g_model
= m_wx_model
;
2412 GtkTreePath
*retval
= gtk_tree_path_new ();
2413 void *id
= iter
->user_data
;
2415 wxGtkTreeModelNode
*node
= FindParentNode( iter
);
2419 for (pos
= 0; pos
< node
->GetChildren().GetCount(); pos
++)
2421 if (id
== node
->GetChildren().Item( pos
))
2423 gtk_tree_path_prepend_index( retval
, (int) pos
);
2428 id
= node
->GetItem().GetID();
2429 node
= node
->GetParent();
2435 gboolean
wxDataViewCtrlInternal::iter_next( GtkTreeIter
*iter
)
2437 g_model
= m_wx_model
;
2439 wxGtkTreeModelNode
*parent
= FindParentNode( iter
);
2440 if( parent
== NULL
)
2443 unsigned int pos
= parent
->GetChildren().Index( iter
->user_data
);
2445 if (pos
== parent
->GetChildCount()-1)
2448 iter
->stamp
= m_gtk_model
->stamp
;
2449 iter
->user_data
= parent
->GetChildren().Item( pos
+1 );
2454 gboolean
wxDataViewCtrlInternal::iter_children( GtkTreeIter
*iter
, GtkTreeIter
*parent
)
2456 g_model
= m_wx_model
;
2458 wxDataViewItem
item( (void*) parent
->user_data
);
2460 if (!m_wx_model
->IsContainer( item
))
2463 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2464 BuildBranch( parent_node
);
2466 if (parent_node
->GetChildCount() == 0)
2469 iter
->stamp
= m_gtk_model
->stamp
;
2470 iter
->user_data
= (gpointer
) parent_node
->GetChildren().Item( 0 );
2475 gboolean
wxDataViewCtrlInternal::iter_has_child( GtkTreeIter
*iter
)
2477 g_model
= m_wx_model
;
2479 wxDataViewItem
item( (void*) iter
->user_data
);
2480 bool is_container
= m_wx_model
->IsContainer( item
);
2485 wxGtkTreeModelNode
*node
= FindNode( iter
);
2486 BuildBranch( node
);
2488 return (node
->GetChildCount() > 0);
2491 gint
wxDataViewCtrlInternal::iter_n_children( GtkTreeIter
*iter
)
2493 g_model
= m_wx_model
;
2495 wxDataViewItem
item( (void*) iter
->user_data
);
2497 if (!m_wx_model
->IsContainer( item
))
2500 wxGtkTreeModelNode
*parent_node
= FindNode( iter
);
2501 BuildBranch( parent_node
);
2503 // wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() );
2505 return parent_node
->GetChildCount();
2508 gboolean
wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter
*iter
, GtkTreeIter
*parent
, gint n
)
2510 g_model
= m_wx_model
;
2513 if (parent
) id
= (void*) parent
->user_data
;
2514 wxDataViewItem
item( id
);
2516 if (!m_wx_model
->IsContainer( item
))
2519 wxGtkTreeModelNode
*parent_node
= FindNode( parent
);
2520 BuildBranch( parent_node
);
2522 // wxPrintf( "iter_nth_child %d\n", n );
2524 iter
->stamp
= m_gtk_model
->stamp
;
2525 iter
->user_data
= parent_node
->GetChildren().Item( n
);
2530 gboolean
wxDataViewCtrlInternal::iter_parent( GtkTreeIter
*iter
, GtkTreeIter
*child
)
2532 g_model
= m_wx_model
;
2534 wxGtkTreeModelNode
*node
= FindParentNode( child
);
2538 iter
->stamp
= m_gtk_model
->stamp
;
2539 iter
->user_data
= (gpointer
) node
->GetItem().GetID();
2544 static wxGtkTreeModelNode
*
2545 wxDataViewCtrlInternal_FindNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
2551 list
.DeleteContents( true );
2552 wxDataViewItem
it( item
);
2555 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
2556 list
.Insert( pItem
);
2557 it
= model
->GetParent( it
);
2560 wxGtkTreeModelNode
* node
= treeNode
;
2561 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
2563 if( node
&& node
->GetNodes().GetCount() != 0 )
2565 int len
= node
->GetNodes().GetCount();
2566 wxGtkTreeModelNodes nodes
= node
->GetNodes();
2568 for( ; j
< len
; j
++)
2570 if( nodes
[j
]->GetItem() == *(n
->GetData()))
2589 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( GtkTreeIter
*iter
)
2594 wxDataViewItem
item( (void*) iter
->user_data
);
2598 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
2602 wxPrintf( "Not found %d\n", (int) iter
->user_data
);
2610 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindNode( const wxDataViewItem
&item
)
2615 wxGtkTreeModelNode
*result
= wxDataViewCtrlInternal_FindNode( m_wx_model
, m_root
, item
);
2619 wxPrintf( "Not found %d\n", (int) item
.GetID() );
2627 static wxGtkTreeModelNode
*
2628 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel
* model
, wxGtkTreeModelNode
*treeNode
, const wxDataViewItem
&item
)
2634 list
.DeleteContents( true );
2638 wxDataViewItem
it( model
->GetParent( item
) );
2641 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
2642 list
.Insert( pItem
);
2643 it
= model
->GetParent( it
);
2646 wxGtkTreeModelNode
* node
= treeNode
;
2647 for( ItemList::compatibility_iterator n
= list
.GetFirst(); n
; n
= n
->GetNext() )
2649 if( node
&& node
->GetNodes().GetCount() != 0 )
2651 int len
= node
->GetNodes().GetCount();
2652 wxGtkTreeModelNodes nodes
= node
->GetNodes();
2654 for( ; j
< len
; j
++)
2656 if( nodes
[j
]->GetItem() == *(n
->GetData()))
2671 //Examine whether the node is item's parent node
2672 int len
= node
->GetChildCount();
2673 for( int i
= 0; i
< len
; i
++ )
2675 if( node
->GetChildren().Item( i
) == item
.GetID() )
2681 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( GtkTreeIter
*iter
)
2686 wxDataViewItem
item( (void*) iter
->user_data
);
2690 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
2693 wxGtkTreeModelNode
*wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
&item
)
2698 return wxDataViewCtrlInternal_FindParentNode( m_wx_model
, m_root
, item
);
2701 //-----------------------------------------------------------------------------
2702 // wxDataViewCtrl signal callbacks
2703 //-----------------------------------------------------------------------------
2706 wxdataview_selection_changed_callback( GtkTreeSelection
* selection
, wxDataViewCtrl
*dv
)
2708 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
2711 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_SELECTED
, dv
->GetId() );
2713 event
.SetModel( dv
->GetModel() );
2714 dv
->GetEventHandler()->ProcessEvent( event
);
2718 wxdataview_row_activated_callback( GtkTreeView
* treeview
, GtkTreePath
*path
,
2719 GtkTreeViewColumn
*column
, wxDataViewCtrl
*dv
)
2721 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, dv
->GetId() );
2724 dv
->GtkGetInternal()->get_iter( &iter
, path
);
2725 wxDataViewItem
item( (void*) iter
.user_data
);;
2726 event
.SetItem( item
);
2727 event
.SetModel( dv
->GetModel() );
2728 dv
->GetEventHandler()->ProcessEvent( event
);
2731 //-----------------------------------------------------------------------------
2733 //-----------------------------------------------------------------------------
2735 //-----------------------------------------------------------------------------
2736 // InsertChild for wxDataViewCtrl
2737 //-----------------------------------------------------------------------------
2739 static void wxInsertChildInDataViewCtrl( wxWindowGTK
* parent
, wxWindowGTK
* child
)
2741 wxDataViewCtrl
* dvc
= (wxDataViewCtrl
*) parent
;
2742 GtkWidget
*treeview
= dvc
->GtkGetTreeView();
2744 // Insert widget in GtkTreeView
2745 if (GTK_WIDGET_REALIZED(treeview
))
2746 gtk_widget_set_parent_window( child
->m_widget
,
2747 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
2748 gtk_widget_set_parent( child
->m_widget
, treeview
);
2752 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
2753 GtkAllocation
*alloc
,
2754 wxDataViewCtrl
*win
)
2757 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
2760 wxWindow
*child
= node
->GetData();
2763 gtk_widget_size_request( child
->m_widget
, &req
);
2765 GtkAllocation alloc
;
2766 alloc
.x
= child
->m_x
;
2767 alloc
.y
= child
->m_y
;
2768 alloc
.width
= child
->m_width
;
2769 alloc
.height
= child
->m_height
;
2770 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
2772 node
= node
->GetNext();
2778 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
2780 wxDataViewCtrl::~wxDataViewCtrl()
2783 GetModel()->RemoveNotifier( m_notifier
);
2785 // remove the model from the GtkTreeView before it gets destroyed by the
2786 // wxDataViewCtrlBase's dtor
2787 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), NULL
);
2792 void wxDataViewCtrl::Init()
2797 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
2798 const wxPoint
& pos
, const wxSize
& size
,
2799 long style
, const wxValidator
& validator
)
2803 if (!PreCreation( parent
, pos
, size
) ||
2804 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
2806 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
2810 m_insertCallback
= wxInsertChildInDataViewCtrl
;
2812 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
2814 GtkScrolledWindowSetBorder(m_widget
, style
);
2816 m_treeview
= gtk_tree_view_new();
2817 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
2819 g_signal_connect (m_treeview
, "size_allocate",
2820 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
2823 if (!gtk_check_version(2,6,0))
2824 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), TRUE
);
2827 if (style
& wxDV_MULTIPLE
)
2829 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
2830 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
2833 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
2836 if (!gtk_check_version(2,10,0))
2838 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
2840 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
2841 (style
& wxDV_VERT_RULES
) != 0)
2842 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
2843 else if (style
& wxDV_VERT_RULES
)
2844 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
2845 else if (style
& wxDV_HORIZ_RULES
)
2846 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
2848 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
2853 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_HORIZ_RULES
) != 0 );
2856 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
2857 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
2858 gtk_widget_show (m_treeview
);
2860 m_parent
->DoAddChild( this );
2864 GtkEnableSelectionEvents();
2866 g_signal_connect_after (m_treeview
, "row_activated",
2867 G_CALLBACK (wxdataview_row_activated_callback
), this);
2872 void wxDataViewCtrl::OnInternalIdle()
2874 wxWindow::OnInternalIdle();
2876 unsigned int cols
= GetColumnCount();
2878 for (i
= 0; i
< cols
; i
++)
2880 wxDataViewColumn
*col
= GetColumn( i
);
2881 col
->OnInternalIdle();
2885 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
2887 if (!wxDataViewCtrlBase::AssociateModel( model
))
2890 GtkWxTreeModel
*gtk_model
= wxgtk_tree_model_new();
2891 m_internal
= new wxDataViewCtrlInternal( this, model
, gtk_model
);
2892 gtk_model
->internal
= m_internal
;
2894 m_notifier
= new wxGtkDataViewModelNotifier( gtk_model
, model
, this );
2896 model
->AddNotifier( m_notifier
);
2898 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_model
) );
2900 // unref in wxDataViewCtrlInternal
2901 // g_object_unref( gtk_model );
2906 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
2908 if (!wxDataViewCtrlBase::AppendColumn(col
))
2911 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)col
->GetGtkHandle();
2913 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
), column
);
2918 wxDataViewItem
wxDataViewCtrl::GetSelection()
2920 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
2922 if (m_windowStyle
& wxDV_MULTIPLE
)
2928 if (gtk_tree_selection_get_selected( selection
, NULL
, &iter
))
2930 wxDataViewItem
item( (void*) iter
.user_data
);
2935 return wxDataViewItem(0);
2938 void wxDataViewCtrl::DoSetExpanderColumn()
2942 void wxDataViewCtrl::DoSetIndent()
2946 void wxDataViewCtrl::GtkDisableSelectionEvents()
2948 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
2949 g_signal_connect_after (selection
, "changed",
2950 G_CALLBACK (wxdataview_selection_changed_callback
), this);
2953 void wxDataViewCtrl::GtkEnableSelectionEvents()
2955 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
2956 g_signal_handlers_disconnect_by_func( selection
,
2957 (gpointer
) (wxdataview_selection_changed_callback
), this);
2962 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
2964 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
2969 // !wxUSE_GENERICDATAVIEWCTRL
2972 // wxUSE_DATAVIEWCTRL