]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dataview.cpp
Fixed wxAtomicInc/Dec() to not use asm/atomic.h header on Linux - it's kernel interna...
[wxWidgets.git] / src / gtk / dataview.cpp
CommitLineData
790b137e 1/////////////////////////////////////////////////////////////////////////////
93763ad5 2// Name: src/gtk/dataview.cpp
790b137e
RR
3// Purpose: wxDataViewCtrl GTK+2 implementation
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
790b137e
RR
13#if wxUSE_DATAVIEWCTRL
14
15#include "wx/dataview.h"
4ed7af08
RR
16
17#ifndef wxUSE_GENERICDATAVIEWCTRL
18
e4db172a
WS
19#ifndef WX_PRECOMP
20 #include "wx/log.h"
ed4b0fdc 21 #include "wx/dcclient.h"
ed2fbeb8 22 #include "wx/sizer.h"
e4db172a
WS
23#endif
24
790b137e 25#include "wx/stockitem.h"
7ea3a0de
RR
26#include "wx/calctrl.h"
27#include "wx/popupwin.h"
2586d4a1 28#include "wx/icon.h"
69892729
RR
29#include "wx/list.h"
30#include "wx/listimpl.cpp"
2586d4a1 31
790b137e
RR
32
33#include "wx/gtk/private.h"
34#include "wx/gtk/win_gtk.h"
35
36#include <gobject/gvaluecollector.h>
1557c77b 37#include <gtk/gtktreemodel.h>
773cca48 38#include <gtk/gtktreesortable.h>
1557c77b 39#include <gtk/gtktreednd.h>
790b137e 40
4d496ecb
RR
41#include <gdk/gdkkeysyms.h>
42
790b137e 43//-----------------------------------------------------------------------------
790b137e
RR
44//-----------------------------------------------------------------------------
45
b8b7b087
RR
46class wxDataViewCtrlInternal;
47
48wxDataViewCtrlInternal *g_internal = NULL;
3b6280be
RR
49
50class wxGtkTreeModelNode;
ef427989 51
0be79c8a
RR
52extern "C" {
53typedef struct _GtkWxTreeModel GtkWxTreeModel;
54}
55
af110130
RR
56//-----------------------------------------------------------------------------
57// wxDataViewCtrlInternal
58//-----------------------------------------------------------------------------
59
69892729
RR
60WX_DECLARE_LIST(wxDataViewItem, ItemList);
61WX_DEFINE_LIST(ItemList);
62
af110130
RR
63class wxDataViewCtrlInternal
64{
65public:
66 wxDataViewCtrlInternal( wxDataViewCtrl *owner, wxDataViewModel *wx_model, GtkWxTreeModel *owner );
67 ~wxDataViewCtrlInternal();
68
69 gboolean get_iter( GtkTreeIter *iter, GtkTreePath *path );
70 GtkTreePath *get_path( GtkTreeIter *iter);
af110130
RR
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 );
77
78 wxDataViewModel* GetDataViewModel() { return m_wx_model; }
79 wxDataViewCtrl* GetOwner() { return m_owner; }
80 GtkWxTreeModel* GetGtkModel() { return m_gtk_model; }
81
82 bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
469d3e9b 83 bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item );
d8331a01
RR
84 bool ItemChanged( const wxDataViewItem &item );
85 bool ValueChanged( const wxDataViewItem &item, unsigned int col );
86 bool Cleared();
af110130
RR
87 void Resort();
88
b8b7b087
RR
89 void SetSortOrder( GtkSortType sort_order ) { m_sort_order = sort_order; }
90 GtkSortType GetSortOrder() { return m_sort_order; }
7ee7191c 91
40196b1e
RR
92 void SetSortColumn( int column ) { m_sort_column = column; }
93 int GetSortColumn() { return m_sort_column; }
94
95 bool IsSorted() { return (m_sort_column >= 0); }
96
b8b7b087 97
af110130
RR
98protected:
99 void InitTree();
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 );
105
106private:
107 wxGtkTreeModelNode *m_root;
108 wxDataViewModel *m_wx_model;
109 GtkWxTreeModel *m_gtk_model;
110 wxDataViewCtrl *m_owner;
b8b7b087 111 GtkSortType m_sort_order;
40196b1e 112 int m_sort_column;
af110130 113};
ef427989 114
af110130
RR
115
116//-----------------------------------------------------------------------------
117// wxGtkTreeModelNode
118//-----------------------------------------------------------------------------
119
40196b1e
RR
120int LINKAGEMODE wxGtkTreeModelChildCmp( void** id1, void** id2 )
121{
122 int ret = g_internal->GetDataViewModel()->Compare( *id1, *id2,
123 g_internal->GetSortColumn(), (g_internal->GetSortOrder() == GTK_SORT_ASCENDING) );
124
125 return ret;
126}
af110130
RR
127
128WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode*, wxGtkTreeModelNodes );
40196b1e 129WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren );
3b6280be
RR
130
131class wxGtkTreeModelNode
132{
133public:
ef427989 134 wxGtkTreeModelNode( wxGtkTreeModelNode* parent, const wxDataViewItem &item,
0be79c8a 135 wxDataViewCtrlInternal *internal )
3b6280be
RR
136 {
137 m_parent = parent;
d5025dc0 138 m_item = item;
0be79c8a 139 m_internal = internal;
3b6280be
RR
140 }
141
142 ~wxGtkTreeModelNode()
143 {
40196b1e 144 size_t count = m_children.GetCount();
3b6280be
RR
145 size_t i;
146 for (i = 0; i < count; i++)
147 {
af110130 148 wxGtkTreeModelNode *child = m_nodes.Item( i );
3b6280be
RR
149 delete child;
150 }
151 }
152
af110130
RR
153 unsigned int AddNode( wxGtkTreeModelNode* child )
154 {
155 m_nodes.Add( child );
40196b1e
RR
156
157 void *id = child->GetItem().GetID();
158
159 m_children.Add( id );
0bd26819
RR
160
161 if (m_internal->IsSorted() || m_internal->GetDataViewModel()->HasDefaultCompare())
40196b1e
RR
162 {
163 g_internal = m_internal;
164 m_children.Sort( &wxGtkTreeModelChildCmp );
165 return m_children.Index( id );
166 }
0bd26819 167
40196b1e 168 return m_children.GetCount()-1;
af110130
RR
169 }
170
171 unsigned int AddLeave( void* id )
172 {
40196b1e 173 m_children.Add( id );
0bd26819
RR
174
175 if (m_internal->IsSorted() || m_internal->GetDataViewModel()->HasDefaultCompare())
40196b1e
RR
176 {
177 g_internal = m_internal;
178 m_children.Sort( &wxGtkTreeModelChildCmp );
179 return m_children.Index( id );
180 }
0bd26819 181
40196b1e 182 return m_children.GetCount()-1;
af110130
RR
183 }
184
185 void DeleteChild( void* id )
186 {
40196b1e
RR
187 m_children.Remove( id );
188
189 unsigned int count = m_nodes.GetCount();
190 unsigned int pos;
af110130
RR
191 for (pos = 0; pos < count; pos++)
192 {
193 wxGtkTreeModelNode *node = m_nodes.Item( pos );
194 if (node->GetItem().GetID() == id)
195 {
196 m_nodes.RemoveAt( pos );
197 delete node;
198 break;
199 }
200 }
201
202 }
203
3b6280be
RR
204 wxGtkTreeModelNode* GetParent()
205 { return m_parent; }
af110130
RR
206 wxGtkTreeModelNodes &GetNodes()
207 { return m_nodes; }
208 wxGtkTreeModelChildren &GetChildren()
40196b1e 209 { return m_children; }
4508fcd2 210
40196b1e 211 unsigned int GetChildCount() { return m_children.GetCount(); }
af110130 212 unsigned int GetNodesCount() { return m_nodes.GetCount(); }
3b6280be
RR
213
214 wxDataViewItem &GetItem() { return m_item; }
0be79c8a 215 wxDataViewCtrlInternal *GetInternal() { return m_internal; }
3b6280be 216
4508fcd2
RR
217 void Resort();
218
3b6280be 219private:
0be79c8a 220 wxGtkTreeModelNode *m_parent;
af110130 221 wxGtkTreeModelNodes m_nodes;
40196b1e 222 wxGtkTreeModelChildren m_children;
0be79c8a 223 wxDataViewItem m_item;
0be79c8a 224 wxDataViewCtrlInternal *m_internal;
3b6280be
RR
225};
226
ef427989 227
790b137e
RR
228//-----------------------------------------------------------------------------
229// data
230//-----------------------------------------------------------------------------
231
232extern bool g_blockEventsOnDrag;
233
234//-----------------------------------------------------------------------------
e0062c04 235// define new GTK+ class wxGtkTreeModel
790b137e
RR
236//-----------------------------------------------------------------------------
237
238extern "C" {
239
e0062c04
RR
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))
790b137e 246
e0062c04 247GType gtk_wx_tree_model_get_type (void);
790b137e 248
e0062c04 249typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass;
790b137e 250
e0062c04 251struct _GtkWxTreeModel
790b137e
RR
252{
253 GObject parent;
254
255 /*< private >*/
256 gint stamp;
55fbde12 257 wxDataViewCtrlInternal *internal;
790b137e
RR
258};
259
e0062c04 260struct _GtkWxTreeModelClass
790b137e 261{
e152afc3 262 GObjectClass list_parent_class;
790b137e
RR
263};
264
e0062c04 265static GtkWxTreeModel *wxgtk_tree_model_new (void);
773cca48
RR
266static void wxgtk_tree_model_init (GtkWxTreeModel *tree_model);
267static void wxgtk_tree_model_class_init (GtkWxTreeModelClass *klass);
268static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface *iface);
269static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface *iface);
e0062c04
RR
270static void wxgtk_tree_model_finalize (GObject *object);
271static GtkTreeModelFlags wxgtk_tree_model_get_flags (GtkTreeModel *tree_model);
272static gint wxgtk_tree_model_get_n_columns (GtkTreeModel *tree_model);
273static GType wxgtk_tree_model_get_column_type (GtkTreeModel *tree_model,
93763ad5 274 gint index);
e0062c04 275static gboolean wxgtk_tree_model_get_iter (GtkTreeModel *tree_model,
93763ad5
WS
276 GtkTreeIter *iter,
277 GtkTreePath *path);
e0062c04 278static GtkTreePath *wxgtk_tree_model_get_path (GtkTreeModel *tree_model,
93763ad5 279 GtkTreeIter *iter);
e0062c04 280static void wxgtk_tree_model_get_value (GtkTreeModel *tree_model,
93763ad5
WS
281 GtkTreeIter *iter,
282 gint column,
283 GValue *value);
e0062c04 284static gboolean wxgtk_tree_model_iter_next (GtkTreeModel *tree_model,
93763ad5 285 GtkTreeIter *iter);
e0062c04 286static gboolean wxgtk_tree_model_iter_children (GtkTreeModel *tree_model,
93763ad5
WS
287 GtkTreeIter *iter,
288 GtkTreeIter *parent);
e0062c04 289static gboolean wxgtk_tree_model_iter_has_child (GtkTreeModel *tree_model,
93763ad5 290 GtkTreeIter *iter);
e0062c04 291static gint wxgtk_tree_model_iter_n_children (GtkTreeModel *tree_model,
93763ad5 292 GtkTreeIter *iter);
e0062c04 293static gboolean wxgtk_tree_model_iter_nth_child (GtkTreeModel *tree_model,
93763ad5
WS
294 GtkTreeIter *iter,
295 GtkTreeIter *parent,
296 gint n);
e0062c04 297static gboolean wxgtk_tree_model_iter_parent (GtkTreeModel *tree_model,
93763ad5
WS
298 GtkTreeIter *iter,
299 GtkTreeIter *child);
790b137e 300
773cca48
RR
301/* sortable */
302static gboolean wxgtk_tree_model_get_sort_column_id (GtkTreeSortable *sortable,
303 gint *sort_column_id,
304 GtkSortType *order);
305static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable *sortable,
306 gint sort_column_id,
307 GtkSortType order);
308static void wxgtk_tree_model_set_sort_func (GtkTreeSortable *sortable,
309 gint sort_column_id,
310 GtkTreeIterCompareFunc func,
311 gpointer data,
312 GtkDestroyNotify destroy);
313static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable *sortable,
314 GtkTreeIterCompareFunc func,
315 gpointer data,
316 GtkDestroyNotify destroy);
317static gboolean wxgtk_tree_model_has_default_sort_func (GtkTreeSortable *sortable);
318
319
320
e152afc3 321static GObjectClass *list_parent_class = NULL;
790b137e
RR
322
323GType
e0062c04 324gtk_wx_tree_model_get_type (void)
790b137e 325{
e0062c04 326 static GType tree_model_type = 0;
790b137e 327
e0062c04 328 if (!tree_model_type)
790b137e 329 {
e0062c04 330 const GTypeInfo tree_model_info =
93763ad5 331 {
e0062c04 332 sizeof (GtkWxTreeModelClass),
93763ad5
WS
333 NULL, /* base_init */
334 NULL, /* base_finalize */
e0062c04 335 (GClassInitFunc) wxgtk_tree_model_class_init,
93763ad5
WS
336 NULL, /* class_finalize */
337 NULL, /* class_data */
e0062c04 338 sizeof (GtkWxTreeModel),
93763ad5 339 0,
e0062c04 340 (GInstanceInitFunc) wxgtk_tree_model_init,
93763ad5 341 };
790b137e 342
773cca48
RR
343 static const GInterfaceInfo tree_model_iface_info =
344 {
345 (GInterfaceInitFunc) wxgtk_tree_model_tree_model_init,
346 NULL,
347 NULL
348 };
349
350 static const GInterfaceInfo sortable_iface_info =
351 {
352 (GInterfaceInitFunc) wxgtk_tree_model_sortable_init,
353 NULL,
354 NULL
355 };
790b137e 356
773cca48 357 tree_model_type = g_type_register_static (G_TYPE_OBJECT, "GtkWxTreeModel",
e0062c04 358 &tree_model_info, (GTypeFlags)0 );
790b137e 359
773cca48
RR
360 g_type_add_interface_static (tree_model_type,
361 GTK_TYPE_TREE_MODEL,
362 &tree_model_iface_info);
363 g_type_add_interface_static (tree_model_type,
364 GTK_TYPE_TREE_SORTABLE,
365 &sortable_iface_info);
790b137e
RR
366 }
367
773cca48 368 return tree_model_type;
790b137e
RR
369}
370
e0062c04
RR
371static GtkWxTreeModel *
372wxgtk_tree_model_new(void)
1557c77b 373{
e0062c04 374 GtkWxTreeModel *retval = (GtkWxTreeModel *) g_object_new (GTK_TYPE_WX_TREE_MODEL, NULL);
e152afc3 375 return retval;
1557c77b
RR
376}
377
790b137e 378static void
e0062c04 379wxgtk_tree_model_class_init (GtkWxTreeModelClass *klass)
790b137e 380{
e152afc3
RR
381 list_parent_class = (GObjectClass*) g_type_class_peek_parent (klass);
382 GObjectClass *object_class = (GObjectClass*) klass;
e0062c04 383 object_class->finalize = wxgtk_tree_model_finalize;
790b137e
RR
384}
385
386static void
e0062c04
RR
387wxgtk_tree_model_tree_model_init (GtkTreeModelIface *iface)
388{
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;
790b137e
RR
401}
402
773cca48
RR
403static void
404wxgtk_tree_model_sortable_init (GtkTreeSortableIface *iface)
405{
94b1f7bc
RR
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;
773cca48
RR
411}
412
790b137e 413static void
e0062c04 414wxgtk_tree_model_init (GtkWxTreeModel *tree_model)
790b137e 415{
55fbde12 416 tree_model->internal = NULL;
e0062c04 417 tree_model->stamp = g_random_int();
790b137e
RR
418}
419
420static void
e0062c04 421wxgtk_tree_model_finalize (GObject *object)
790b137e 422{
790b137e 423 /* must chain up */
e152afc3 424 (* list_parent_class->finalize) (object);
790b137e 425}
93763ad5 426
790b137e
RR
427} // extern "C"
428
429//-----------------------------------------------------------------------------
e0062c04
RR
430// implement callbacks from wxGtkTreeModel class by letting
431// them call the methods of wxWidgets' wxDataViewModel
790b137e
RR
432//-----------------------------------------------------------------------------
433
434static GtkTreeModelFlags
e0062c04 435wxgtk_tree_model_get_flags (GtkTreeModel *tree_model)
790b137e 436{
e0062c04 437 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (tree_model), (GtkTreeModelFlags)0 );
790b137e 438
e0062c04 439 return GTK_TREE_MODEL_ITERS_PERSIST;
790b137e
RR
440}
441
442static gint
e0062c04 443wxgtk_tree_model_get_n_columns (GtkTreeModel *tree_model)
790b137e 444{
e0062c04
RR
445 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
446 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), 0);
790b137e 447
55fbde12 448 return wxtree_model->internal->GetDataViewModel()->GetColumnCount();
790b137e
RR
449}
450
451static GType
e0062c04 452wxgtk_tree_model_get_column_type (GtkTreeModel *tree_model,
93763ad5 453 gint index)
790b137e 454{
e0062c04
RR
455 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
456 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), G_TYPE_INVALID);
790b137e 457
1557c77b 458 GType gtype = G_TYPE_INVALID;
93763ad5 459
55fbde12 460 wxString wxtype = wxtree_model->internal->GetDataViewModel()->GetColumnType( (unsigned int) index );
93763ad5 461
1557c77b
RR
462 if (wxtype == wxT("string"))
463 gtype = G_TYPE_STRING;
72a3ac9b
VZ
464 else
465 {
466 wxFAIL_MSG( _T("non-string columns not supported yet") );
467 }
790b137e
RR
468
469 return gtype;
470}
471
472static gboolean
e0062c04 473wxgtk_tree_model_get_iter (GtkTreeModel *tree_model,
93763ad5
WS
474 GtkTreeIter *iter,
475 GtkTreePath *path)
790b137e 476{
e0062c04
RR
477 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
478 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
790b137e
RR
479 g_return_val_if_fail (gtk_tree_path_get_depth (path) > 0, FALSE);
480
55fbde12 481 return wxtree_model->internal->get_iter( iter, path );
790b137e
RR
482}
483
484static GtkTreePath *
e0062c04 485wxgtk_tree_model_get_path (GtkTreeModel *tree_model,
93763ad5 486 GtkTreeIter *iter)
790b137e 487{
e0062c04
RR
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);
93763ad5 491
55fbde12 492 return wxtree_model->internal->get_path( iter );
790b137e
RR
493}
494
495static void
e0062c04 496wxgtk_tree_model_get_value (GtkTreeModel *tree_model,
93763ad5
WS
497 GtkTreeIter *iter,
498 gint column,
499 GValue *value)
790b137e 500{
e0062c04
RR
501 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
502 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model) );
239eaa41 503
55fbde12 504 wxDataViewModel *model = wxtree_model->internal->GetDataViewModel();
9861f022 505 wxString mtype = model->GetColumnType( (unsigned int) column );
1557c77b
RR
506 if (mtype == wxT("string"))
507 {
3f3af7e7 508 wxVariant variant;
1557c77b 509 g_value_init( value, G_TYPE_STRING );
9d52aad3 510 wxDataViewItem item( (void*) iter->user_data );
e0062c04 511 model->GetValue( variant, item, (unsigned int) column );
72a3ac9b 512
e0062c04 513 g_value_set_string( value, variant.GetString().utf8_str() );
1557c77b
RR
514 }
515 else
516 {
72a3ac9b 517 wxFAIL_MSG( _T("non-string columns not supported yet") );
1557c77b 518 }
790b137e
RR
519}
520
521static gboolean
e0062c04 522wxgtk_tree_model_iter_next (GtkTreeModel *tree_model,
93763ad5 523 GtkTreeIter *iter)
790b137e 524{
e0062c04
RR
525 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
526 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
e0062c04 527 g_return_val_if_fail (wxtree_model->stamp == iter->stamp, FALSE);
93763ad5 528
55fbde12 529 return wxtree_model->internal->iter_next( iter );
790b137e
RR
530}
531
532static gboolean
e0062c04 533wxgtk_tree_model_iter_children (GtkTreeModel *tree_model,
93763ad5
WS
534 GtkTreeIter *iter,
535 GtkTreeIter *parent)
790b137e 536{
e0062c04
RR
537 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
538 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
e0062c04 539 g_return_val_if_fail (wxtree_model->stamp == parent->stamp, FALSE);
790b137e 540
55fbde12 541 return wxtree_model->internal->iter_children( iter, parent );
790b137e
RR
542}
543
544static gboolean
e0062c04 545wxgtk_tree_model_iter_has_child (GtkTreeModel *tree_model,
93763ad5 546 GtkTreeIter *iter)
790b137e 547{
e0062c04
RR
548 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
549 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
e0062c04 550 g_return_val_if_fail (wxtree_model->stamp == iter->stamp, FALSE);
d5025dc0 551
55fbde12 552 return wxtree_model->internal->iter_has_child( iter );
790b137e
RR
553}
554
555static gint
e0062c04 556wxgtk_tree_model_iter_n_children (GtkTreeModel *tree_model,
93763ad5 557 GtkTreeIter *iter)
790b137e 558{
e0062c04
RR
559 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
560 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
e0062c04 561 g_return_val_if_fail (wxtree_model->stamp == iter->stamp, 0);
d5025dc0 562
55fbde12 563 return wxtree_model->internal->iter_n_children( iter );
790b137e
RR
564}
565
566static gboolean
e0062c04 567wxgtk_tree_model_iter_nth_child (GtkTreeModel *tree_model,
93763ad5
WS
568 GtkTreeIter *iter,
569 GtkTreeIter *parent,
570 gint n)
790b137e 571{
e0062c04
RR
572 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
573 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
574
55fbde12 575 return wxtree_model->internal->iter_nth_child( iter, parent, n );
790b137e
RR
576}
577
578static gboolean
e0062c04 579wxgtk_tree_model_iter_parent (GtkTreeModel *tree_model,
93763ad5
WS
580 GtkTreeIter *iter,
581 GtkTreeIter *child)
790b137e 582{
e0062c04
RR
583 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
584 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
e0062c04
RR
585 g_return_val_if_fail (wxtree_model->stamp == child->stamp, FALSE);
586
55fbde12 587 return wxtree_model->internal->iter_parent( iter, child );
790b137e
RR
588}
589
773cca48
RR
590/* sortable */
591gboolean wxgtk_tree_model_get_sort_column_id (GtkTreeSortable *sortable,
592 gint *sort_column_id,
593 GtkSortType *order)
594{
94b1f7bc
RR
595 GtkWxTreeModel *tree_model = (GtkWxTreeModel *) sortable;
596
597 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable), FALSE);
598
40196b1e
RR
599 if (!tree_model->internal->IsSorted())
600 {
601 if (sort_column_id)
602 *sort_column_id = -1;
603
604 return TRUE;
605 }
606
607
94b1f7bc 608 if (sort_column_id)
7ee7191c 609 *sort_column_id = tree_model->internal->GetSortColumn();
94b1f7bc
RR
610
611 if (order)
b8b7b087 612 *order = tree_model->internal->GetSortOrder();
94b1f7bc
RR
613
614 return TRUE;
773cca48
RR
615}
616
b8b7b087 617void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable *sortable,
773cca48
RR
618 gint sort_column_id,
619 GtkSortType order)
620{
94b1f7bc 621 GtkWxTreeModel *tree_model = (GtkWxTreeModel *) sortable;
94b1f7bc
RR
622 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) );
623
7ee7191c 624 if ((sort_column_id == (gint) tree_model->internal->GetSortColumn()) &&
b8b7b087 625 (order == tree_model->internal->GetSortOrder()))
0be79c8a
RR
626 return;
627
7ee7191c 628 tree_model->internal->SetSortColumn( sort_column_id );
0be79c8a 629
b8b7b087 630 tree_model->internal->SetSortOrder( order );
ef427989 631
0be79c8a
RR
632 gtk_tree_sortable_sort_column_changed (sortable);
633
ef427989 634 tree_model->internal->GetDataViewModel()->Resort();
a84c5b6f
RR
635
636 wxDataViewCtrl *dv = tree_model->internal->GetOwner();
637 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, dv->GetId() );
6848478c 638 // TODO event.SetDataViewColumn( column );
a84c5b6f
RR
639 event.SetModel( dv->GetModel() );
640 dv->GetEventHandler()->ProcessEvent( event );
773cca48
RR
641}
642
643void wxgtk_tree_model_set_sort_func (GtkTreeSortable *sortable,
644 gint sort_column_id,
645 GtkTreeIterCompareFunc func,
646 gpointer data,
647 GtkDestroyNotify destroy)
648{
94b1f7bc
RR
649 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) );
650 g_return_if_fail (func != NULL);
773cca48
RR
651}
652
653void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable *sortable,
654 GtkTreeIterCompareFunc func,
655 gpointer data,
656 GtkDestroyNotify destroy)
657{
94b1f7bc 658 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) );
94b1f7bc
RR
659 g_return_if_fail (func != NULL);
660
94b1f7bc 661 wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
773cca48
RR
662}
663
664gboolean wxgtk_tree_model_has_default_sort_func (GtkTreeSortable *sortable)
665{
666 return FALSE;
667}
668
e152afc3 669//-----------------------------------------------------------------------------
baa9ebc4 670// define new GTK+ class wxGtkRendererRenderer
e152afc3
RR
671//-----------------------------------------------------------------------------
672
673extern "C" {
674
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))
681
682GType gtk_wx_cell_renderer_get_type (void);
683
684typedef struct _GtkWxCellRenderer GtkWxCellRenderer;
685typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass;
686
687struct _GtkWxCellRenderer
688{
689 GtkCellRenderer parent;
690
691 /*< private >*/
baa9ebc4 692 wxDataViewCustomRenderer *cell;
4d496ecb 693 guint32 last_click;
e152afc3
RR
694};
695
696struct _GtkWxCellRendererClass
697{
698 GtkCellRendererClass cell_parent_class;
e152afc3
RR
699};
700
701
702static GtkCellRenderer *gtk_wx_cell_renderer_new (void);
553f7d8f
RR
703static void gtk_wx_cell_renderer_init (
704 GtkWxCellRenderer *cell );
705static void gtk_wx_cell_renderer_class_init(
706 GtkWxCellRendererClass *klass );
707static void gtk_wx_cell_renderer_finalize (
708 GObject *object );
709static void gtk_wx_cell_renderer_get_size (
710 GtkCellRenderer *cell,
93763ad5
WS
711 GtkWidget *widget,
712 GdkRectangle *rectangle,
713 gint *x_offset,
714 gint *y_offset,
715 gint *width,
716 gint *height );
553f7d8f
RR
717static void gtk_wx_cell_renderer_render (
718 GtkCellRenderer *cell,
93763ad5
WS
719 GdkWindow *window,
720 GtkWidget *widget,
721 GdkRectangle *background_area,
722 GdkRectangle *cell_area,
723 GdkRectangle *expose_area,
724 GtkCellRendererState flags );
553f7d8f
RR
725static gboolean gtk_wx_cell_renderer_activate(
726 GtkCellRenderer *cell,
727 GdkEvent *event,
728 GtkWidget *widget,
729 const gchar *path,
730 GdkRectangle *background_area,
731 GdkRectangle *cell_area,
732 GtkCellRendererState flags );
1e510b1e
RR
733static GtkCellEditable *gtk_wx_cell_renderer_start_editing(
734 GtkCellRenderer *cell,
735 GdkEvent *event,
736 GtkWidget *widget,
737 const gchar *path,
738 GdkRectangle *background_area,
739 GdkRectangle *cell_area,
740 GtkCellRendererState flags );
e8375af8 741
e152afc3
RR
742
743static GObjectClass *cell_parent_class = NULL;
744
745} // extern "C"
746
93763ad5 747GType
e152afc3
RR
748gtk_wx_cell_renderer_get_type (void)
749{
553f7d8f 750 static GType cell_wx_type = 0;
e152afc3 751
553f7d8f 752 if (!cell_wx_type)
e152afc3 753 {
de4a74e2 754 const GTypeInfo cell_wx_info =
553f7d8f
RR
755 {
756 sizeof (GtkWxCellRendererClass),
93763ad5
WS
757 NULL, /* base_init */
758 NULL, /* base_finalize */
553f7d8f 759 (GClassInitFunc) gtk_wx_cell_renderer_class_init,
93763ad5
WS
760 NULL, /* class_finalize */
761 NULL, /* class_data */
553f7d8f
RR
762 sizeof (GtkWxCellRenderer),
763 0, /* n_preallocs */
764 (GInstanceInitFunc) gtk_wx_cell_renderer_init,
765 };
766
93763ad5 767 cell_wx_type = g_type_register_static( GTK_TYPE_CELL_RENDERER,
553f7d8f 768 "GtkWxCellRenderer", &cell_wx_info, (GTypeFlags)0 );
e152afc3
RR
769 }
770
553f7d8f 771 return cell_wx_type;
e152afc3
RR
772}
773
774static void
775gtk_wx_cell_renderer_init (GtkWxCellRenderer *cell)
776{
777 cell->cell = NULL;
4d496ecb 778 cell->last_click = 0;
e152afc3
RR
779}
780
781static void
782gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass *klass)
783{
784 GObjectClass *object_class = G_OBJECT_CLASS (klass);
785 GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass);
786
787 cell_parent_class = (GObjectClass*) g_type_class_peek_parent (klass);
788
789 object_class->finalize = gtk_wx_cell_renderer_finalize;
790
791 cell_class->get_size = gtk_wx_cell_renderer_get_size;
792 cell_class->render = gtk_wx_cell_renderer_render;
553f7d8f 793 cell_class->activate = gtk_wx_cell_renderer_activate;
1e510b1e 794 cell_class->start_editing = gtk_wx_cell_renderer_start_editing;
e152afc3
RR
795}
796
797static void
798gtk_wx_cell_renderer_finalize (GObject *object)
799{
800 /* must chain up */
801 (* G_OBJECT_CLASS (cell_parent_class)->finalize) (object);
802}
803
804GtkCellRenderer*
805gtk_wx_cell_renderer_new (void)
806{
807 return (GtkCellRenderer*) g_object_new (GTK_TYPE_WX_CELL_RENDERER, NULL);
808}
809
1e510b1e
RR
810
811
812static GtkCellEditable *gtk_wx_cell_renderer_start_editing(
813 GtkCellRenderer *renderer,
814 GdkEvent *event,
815 GtkWidget *widget,
816 const gchar *path,
817 GdkRectangle *background_area,
818 GdkRectangle *cell_area,
819 GtkCellRendererState flags )
820{
821 GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer;
822 wxDataViewCustomRenderer *cell = wxrenderer->cell;
823 if (!cell->HasEditorCtrl())
824 return NULL;
e8375af8 825
1e510b1e
RR
826 GdkRectangle rect;
827 gtk_wx_cell_renderer_get_size (renderer, widget, cell_area,
828 &rect.x,
829 &rect.y,
830 &rect.width,
831 &rect.height);
832
833 rect.x += cell_area->x;
834 rect.y += cell_area->y;
835// rect.width -= renderer->xpad * 2;
836// rect.height -= renderer->ypad * 2;
837
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 );
840
1e510b1e 841 GtkTreePath *treepath = gtk_tree_path_new_from_string( path );
55fbde12
RR
842 GtkTreeIter iter;
843 cell->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter, treepath );
844 wxDataViewItem item( (void*) iter.user_data );
1e510b1e
RR
845 gtk_tree_path_free( treepath );
846
9d52aad3 847 cell->StartEditing( item, renderrect );
30715fa1 848
1e510b1e
RR
849 return NULL;
850}
851
e152afc3
RR
852static void
853gtk_wx_cell_renderer_get_size (GtkCellRenderer *renderer,
93763ad5
WS
854 GtkWidget *widget,
855 GdkRectangle *cell_area,
856 gint *x_offset,
857 gint *y_offset,
858 gint *width,
859 gint *height)
e152afc3
RR
860{
861 GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer;
baa9ebc4 862 wxDataViewCustomRenderer *cell = wxrenderer->cell;
93763ad5 863
e152afc3
RR
864 wxSize size = cell->GetSize();
865
866 gint calc_width = (gint) renderer->xpad * 2 + size.x;
867 gint calc_height = (gint) renderer->ypad * 2 + size.y;
93763ad5
WS
868
869 if (x_offset)
e152afc3 870 *x_offset = 0;
93763ad5 871 if (y_offset)
e152afc3
RR
872 *y_offset = 0;
873
874 if (cell_area && size.x > 0 && size.y > 0)
875 {
876 if (x_offset)
93763ad5 877 {
e152afc3
RR
878 *x_offset = (gint)((renderer->xalign *
879 (cell_area->width - calc_width - 2 * renderer->xpad)));
880 *x_offset = MAX (*x_offset, 0) + renderer->xpad;
93763ad5 881 }
e152afc3
RR
882 if (y_offset)
883 {
884 *y_offset = (gint)((renderer->yalign *
885 (cell_area->height - calc_height - 2 * renderer->ypad)));
886 *y_offset = MAX (*y_offset, 0) + renderer->ypad;
887 }
888 }
889
890 if (width)
891 *width = calc_width;
93763ad5 892
e152afc3
RR
893 if (height)
894 *height = calc_height;
895}
896
897static void
898gtk_wx_cell_renderer_render (GtkCellRenderer *renderer,
93763ad5
WS
899 GdkWindow *window,
900 GtkWidget *widget,
901 GdkRectangle *background_area,
902 GdkRectangle *cell_area,
903 GdkRectangle *expose_area,
904 GtkCellRendererState flags)
e152afc3
RR
905
906{
907 GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer;
baa9ebc4 908 wxDataViewCustomRenderer *cell = wxrenderer->cell;
93763ad5 909
e152afc3
RR
910 GdkRectangle rect;
911 gtk_wx_cell_renderer_get_size (renderer, widget, cell_area,
93763ad5
WS
912 &rect.x,
913 &rect.y,
914 &rect.width,
915 &rect.height);
e152afc3
RR
916
917 rect.x += cell_area->x;
918 rect.y += cell_area->y;
919 rect.width -= renderer->xpad * 2;
920 rect.height -= renderer->ypad * 2;
93763ad5 921
e152afc3
RR
922 GdkRectangle dummy;
923 if (gdk_rectangle_intersect (expose_area, &rect, &dummy))
924 {
925 wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
926 wxWindowDC* dc = (wxWindowDC*) cell->GetDC();
4d496ecb
RR
927 if (dc->m_window == NULL)
928 {
929 dc->m_window = window;
930 dc->SetUpDC();
931 }
93763ad5 932
e152afc3
RR
933 int state = 0;
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 );
93763ad5 945 }
e152afc3
RR
946}
947
93763ad5 948static gboolean
553f7d8f
RR
949gtk_wx_cell_renderer_activate(
950 GtkCellRenderer *renderer,
951 GdkEvent *event,
952 GtkWidget *widget,
953 const gchar *path,
954 GdkRectangle *background_area,
955 GdkRectangle *cell_area,
956 GtkCellRendererState flags )
957{
958 GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer;
baa9ebc4 959 wxDataViewCustomRenderer *cell = wxrenderer->cell;
93763ad5 960
553f7d8f
RR
961 GdkRectangle rect;
962 gtk_wx_cell_renderer_get_size (renderer, widget, cell_area,
93763ad5
WS
963 &rect.x,
964 &rect.y,
965 &rect.width,
966 &rect.height);
553f7d8f
RR
967
968 rect.x += cell_area->x;
969 rect.y += cell_area->y;
970 rect.width -= renderer->xpad * 2;
971 rect.height -= renderer->ypad * 2;
93763ad5 972
553f7d8f 973 wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
93763ad5 974
e0062c04 975 wxDataViewModel *model = cell->GetOwner()->GetOwner()->GetModel();
93763ad5 976
4d496ecb 977 GtkTreePath *treepath = gtk_tree_path_new_from_string( path );
9d52aad3
RR
978 // TODO
979 wxDataViewItem item;
4d496ecb 980 gtk_tree_path_free( treepath );
93763ad5 981
0a71f9e9 982 unsigned int model_col = cell->GetOwner()->GetModelColumn();
93763ad5 983
456e5c21
RR
984 if (!event)
985 {
986 bool ret = false;
e8375af8 987
456e5c21 988 // activated by <ENTER>
9d52aad3 989 if (cell->Activate( renderrect, model, item, model_col ))
456e5c21 990 ret = true;
e8375af8 991
456e5c21
RR
992 return ret;
993 }
994 else if (event->type == GDK_BUTTON_PRESS)
4d496ecb
RR
995 {
996 GdkEventButton *button_event = (GdkEventButton*) event;
93763ad5 997 wxPoint pt( ((int) button_event->x) - renderrect.x,
4d496ecb 998 ((int) button_event->y) - renderrect.y );
93763ad5 999
4d496ecb
RR
1000 bool ret = false;
1001 if (button_event->button == 1)
1002 {
9d52aad3 1003 if (cell->LeftClick( pt, renderrect, model, item, model_col ))
4d496ecb 1004 ret = true;
7ea3a0de 1005 // TODO: query system double-click time
4d496ecb 1006 if (button_event->time - wxrenderer->last_click < 400)
9d52aad3 1007 if (cell->Activate( renderrect, model, item, model_col ))
4d496ecb
RR
1008 ret = true;
1009 }
1010 if (button_event->button == 3)
1011 {
9d52aad3 1012 if (cell->RightClick( pt, renderrect, model, item, model_col ))
4d496ecb
RR
1013 ret = true;
1014 }
93763ad5 1015
4d496ecb 1016 wxrenderer->last_click = button_event->time;
93763ad5 1017
4d496ecb
RR
1018 return ret;
1019 }
93763ad5 1020
4d496ecb 1021 return false;
553f7d8f
RR
1022}
1023
93763ad5 1024// ---------------------------------------------------------
e0062c04 1025// wxGtkDataViewModelNotifier
93763ad5 1026// ---------------------------------------------------------
6e2e590f 1027
e0062c04 1028class wxGtkDataViewModelNotifier: public wxDataViewModelNotifier
6e2e590f
RR
1029{
1030public:
e0062c04
RR
1031 wxGtkDataViewModelNotifier( GtkWxTreeModel *wxgtk_model,
1032 wxDataViewModel *wx_model,
1033 wxDataViewCtrl *ctrl );
1034 ~wxGtkDataViewModelNotifier();
1035
1036 virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
469d3e9b 1037 virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item );
e0062c04
RR
1038 virtual bool ItemChanged( const wxDataViewItem &item );
1039 virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col );
6e2e590f 1040 virtual bool Cleared();
4508fcd2 1041 virtual void Resort();
93763ad5 1042
e0062c04
RR
1043 GtkWxTreeModel *m_wxgtk_model;
1044 wxDataViewModel *m_wx_model;
63415a42 1045 wxDataViewCtrl *m_owner;
6e2e590f
RR
1046};
1047
93763ad5 1048// ---------------------------------------------------------
6e2e590f 1049// wxGtkDataViewListModelNotifier
93763ad5 1050// ---------------------------------------------------------
6e2e590f 1051
e0062c04
RR
1052wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1053 GtkWxTreeModel* wxgtk_model, wxDataViewModel *wx_model,
63415a42 1054 wxDataViewCtrl *ctrl )
6e2e590f 1055{
e0062c04 1056 m_wxgtk_model = wxgtk_model;
6e2e590f 1057 m_wx_model = wx_model;
63415a42 1058 m_owner = ctrl;
6e2e590f 1059}
93763ad5 1060
e0062c04 1061wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
f7ed8c89
RR
1062{
1063 m_wx_model = NULL;
e0062c04 1064 m_wxgtk_model = NULL;
f7ed8c89
RR
1065}
1066
e0062c04 1067bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item )
6e2e590f 1068{
55fbde12 1069 m_owner->GtkGetInternal()->ItemAdded( parent, item );
1e08ad10 1070
6e2e590f 1071 GtkTreeIter iter;
e0062c04
RR
1072 iter.stamp = m_wxgtk_model->stamp;
1073 iter.user_data = (gpointer) item.GetID();
93763ad5 1074
e0062c04
RR
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);
6e2e590f 1079 gtk_tree_path_free (path);
93763ad5 1080
6e2e590f
RR
1081 return true;
1082}
1083
469d3e9b 1084bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item )
6e2e590f 1085{
605c2c4a 1086 GtkTreeIter iter;
e0062c04
RR
1087 iter.stamp = m_wxgtk_model->stamp;
1088 iter.user_data = (gpointer) item.GetID();
93763ad5 1089
40196b1e 1090 GtkTreePath *path = wxgtk_tree_model_get_path(
e0062c04
RR
1091 GTK_TREE_MODEL(m_wxgtk_model), &iter );
1092 gtk_tree_model_row_deleted(
1093 GTK_TREE_MODEL(m_wxgtk_model), path );
605c2c4a 1094 gtk_tree_path_free (path);
93763ad5 1095
469d3e9b 1096 m_owner->GtkGetInternal()->ItemDeleted( parent, item );
e63807a8 1097
605c2c4a 1098 return true;
6e2e590f
RR
1099}
1100
4508fcd2
RR
1101void wxGtkDataViewModelNotifier::Resort()
1102{
1103 m_owner->GtkGetInternal()->Resort();
1104}
1105
e0062c04 1106bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem &item )
6e2e590f 1107{
4627af27 1108 GtkTreeIter iter;
e0062c04
RR
1109 iter.stamp = m_wxgtk_model->stamp;
1110 iter.user_data = (gpointer) item.GetID();
6e2e590f 1111
e0062c04
RR
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 );
a7f61f76
RR
1116 gtk_tree_path_free (path);
1117
d8331a01
RR
1118 m_owner->GtkGetInternal()->ItemChanged( item );
1119
a7f61f76 1120 return true;
6e2e590f
RR
1121}
1122
e0062c04 1123bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem &item, unsigned int model_col )
6e2e590f 1124{
4eccd3a1 1125 // This adds GTK+'s missing MVC logic for ValueChanged
63415a42
RR
1126 unsigned int index;
1127 for (index = 0; index < m_owner->GetColumnCount(); index++)
8f850e28 1128 {
63415a42
RR
1129 wxDataViewColumn *column = m_owner->GetColumn( index );
1130 if (column->GetModelColumn() == model_col)
8f850e28 1131 {
63415a42
RR
1132 GtkTreeView *widget = GTK_TREE_VIEW(m_owner->m_treeview);
1133 GtkTreeViewColumn *gcolumn = GTK_TREE_VIEW_COLUMN(column->GetGtkHandle());
8f850e28
RR
1134
1135 // Get cell area
e0062c04
RR
1136 GtkTreeIter iter;
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 );
8f850e28 1141 GdkRectangle cell_area;
63415a42 1142 gtk_tree_view_get_cell_area( widget, path, gcolumn, &cell_area );
93763ad5 1143 gtk_tree_path_free( path );
8f850e28 1144
1a64259d
RR
1145 GtkAdjustment* hadjust = gtk_tree_view_get_hadjustment( widget );
1146 double d = gtk_adjustment_get_value( hadjust );
1147 int xdiff = (int) d;
1148
63415a42 1149 int ydiff = gcolumn->button->allocation.height;
8f850e28 1150 // Redraw
93763ad5 1151 gtk_widget_queue_draw_area( GTK_WIDGET(widget),
1a64259d 1152 cell_area.x - xdiff, ydiff + cell_area.y, cell_area.width, cell_area.height );
d8331a01
RR
1153
1154 m_owner->GtkGetInternal()->ValueChanged( item, model_col );
1155
1156 return true;
8f850e28 1157 }
8f850e28 1158 }
93763ad5 1159
d8331a01 1160 return false;
6e2e590f
RR
1161}
1162
e0062c04 1163bool wxGtkDataViewModelNotifier::Cleared()
6e2e590f 1164{
d8331a01
RR
1165 // TODO: delete everything
1166
1167 m_owner->GtkGetInternal()->Cleared();
1168
6e2e590f
RR
1169 return false;
1170}
1171
93763ad5 1172// ---------------------------------------------------------
baa9ebc4 1173// wxDataViewRenderer
93763ad5 1174// ---------------------------------------------------------
6842a71a 1175
a912e81f
RR
1176static gpointer s_user_data = NULL;
1177
1178static void
1179wxgtk_cell_editable_editing_done( GtkCellEditable *editable,
1180 wxDataViewRenderer *wxrenderer )
1181{
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 );
1190}
1191
1192static void
1193wxgtk_renderer_editing_started( GtkCellRenderer *cell, GtkCellEditable *editable,
1194 gchar *path, wxDataViewRenderer *wxrenderer )
1195{
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 );
1202 GtkTreeIter iter;
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 );
1208
1209 if (GTK_IS_CELL_EDITABLE(editable))
1210 {
1211 s_user_data = iter.user_data;
1212
1213 g_signal_connect (GTK_CELL_EDITABLE (editable), "editing_done",
1214 G_CALLBACK (wxgtk_cell_editable_editing_done),
1215 (gpointer) wxrenderer );
1216
1217 }
1218}
1219
1220
baa9ebc4 1221IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer, wxDataViewRendererBase)
6842a71a 1222
9861f022
RR
1223wxDataViewRenderer::wxDataViewRenderer( const wxString &varianttype, wxDataViewCellMode mode,
1224 int align ) :
1225 wxDataViewRendererBase( varianttype, mode, align )
6842a71a
RR
1226{
1227 m_renderer = NULL;
9861f022
RR
1228
1229 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1230 // after the m_renderer pointer has been initialized
1231}
1232
a912e81f
RR
1233void wxDataViewRenderer::GtkInitHandlers()
1234{
1235 if (!gtk_check_version(2,6,0))
1236 {
1237 g_signal_connect (GTK_CELL_RENDERER(m_renderer), "editing_started",
1238 G_CALLBACK (wxgtk_renderer_editing_started),
1239 this);
1240 }
1241}
1242
9861f022
RR
1243void wxDataViewRenderer::SetMode( wxDataViewCellMode mode )
1244{
1245 GtkCellRendererMode gtkMode;
1246 switch (mode)
1247 {
1248 case wxDATAVIEW_CELL_INERT:
1249 gtkMode = GTK_CELL_RENDERER_MODE_INERT;
1250 break;
1251 case wxDATAVIEW_CELL_ACTIVATABLE:
1252 gtkMode = GTK_CELL_RENDERER_MODE_ACTIVATABLE;
1253 break;
1254 case wxDATAVIEW_CELL_EDITABLE:
1255 gtkMode = GTK_CELL_RENDERER_MODE_EDITABLE;
1256 break;
1257 }
1258
1259 GValue gvalue = { 0, };
1260 g_value_init( &gvalue, gtk_cell_renderer_mode_get_type() );
1261 g_value_set_enum( &gvalue, gtkMode );
1262 g_object_set_property( G_OBJECT(m_renderer), "mode", &gvalue );
1263 g_value_unset( &gvalue );
1264}
1265
1266wxDataViewCellMode wxDataViewRenderer::GetMode() const
1267{
1268 wxDataViewCellMode ret;
1269
1270 GValue gvalue;
1271 g_object_get( G_OBJECT(m_renderer), "mode", &gvalue, NULL);
1272
1273 switch (g_value_get_enum(&gvalue))
1274 {
1275 case GTK_CELL_RENDERER_MODE_INERT:
1276 ret = wxDATAVIEW_CELL_INERT;
1277 break;
1278 case GTK_CELL_RENDERER_MODE_ACTIVATABLE:
1279 ret = wxDATAVIEW_CELL_ACTIVATABLE;
1280 break;
1281 case GTK_CELL_RENDERER_MODE_EDITABLE:
1282 ret = wxDATAVIEW_CELL_EDITABLE;
1283 break;
1284 }
1285
1286 g_value_unset( &gvalue );
1287
1288 return ret;
1289}
1290
1291void wxDataViewRenderer::SetAlignment( int align )
1292{
1293 // horizontal alignment:
1294
1295 gfloat xalign = 0.0;
1296 if (align & wxALIGN_RIGHT)
1297 xalign = 1.0;
1298 else if (align & wxALIGN_CENTER_HORIZONTAL)
1299 xalign = 0.5;
1300
1301 GValue gvalue = { 0, };
1302 g_value_init( &gvalue, G_TYPE_FLOAT );
1303 g_value_set_float( &gvalue, xalign );
1304 g_object_set_property( G_OBJECT(m_renderer), "xalign", &gvalue );
1305 g_value_unset( &gvalue );
1306
1307 // vertical alignment:
1308
1309 gfloat yalign = 0.0;
1310 if (align & wxALIGN_BOTTOM)
1311 yalign = 1.0;
1312 else if (align & wxALIGN_CENTER_VERTICAL)
1313 yalign = 0.5;
1314
1315 GValue gvalue2 = { 0, };
1316 g_value_init( &gvalue2, G_TYPE_FLOAT );
1317 g_value_set_float( &gvalue2, yalign );
1318 g_object_set_property( G_OBJECT(m_renderer), "yalign", &gvalue2 );
1319 g_value_unset( &gvalue2 );
6842a71a
RR
1320}
1321
9861f022
RR
1322int wxDataViewRenderer::GetAlignment() const
1323{
1324 int ret = 0;
1325 GValue gvalue;
1326
1327 // horizontal alignment:
1328
1329 g_object_get( G_OBJECT(m_renderer), "xalign", &gvalue, NULL );
1330 float xalign = g_value_get_float( &gvalue );
1331 if (xalign < 0.5)
1332 ret |= wxALIGN_LEFT;
1333 else if (xalign == 0.5)
1334 ret |= wxALIGN_CENTER_HORIZONTAL;
1335 else
1336 ret |= wxALIGN_RIGHT;
1337 g_value_unset( &gvalue );
1338
1339
1340 // vertical alignment:
1341
1342 g_object_get( G_OBJECT(m_renderer), "yalign", &gvalue, NULL );
1343 float yalign = g_value_get_float( &gvalue );
1344 if (yalign < 0.5)
1345 ret |= wxALIGN_TOP;
1346 else if (yalign == 0.5)
1347 ret |= wxALIGN_CENTER_VERTICAL;
1348 else
1349 ret |= wxALIGN_BOTTOM;
1350 g_value_unset( &gvalue );
1351
1352 return ret;
1353}
1354
1355
1356
93763ad5 1357// ---------------------------------------------------------
baa9ebc4 1358// wxDataViewTextRenderer
93763ad5 1359// ---------------------------------------------------------
6842a71a 1360
a7f61f76 1361extern "C" {
93763ad5 1362static void wxGtkTextRendererEditedCallback( GtkCellRendererText *renderer,
a7f61f76
RR
1363 gchar *arg1, gchar *arg2, gpointer user_data );
1364}
1365
93763ad5 1366static void wxGtkTextRendererEditedCallback( GtkCellRendererText *renderer,
a7f61f76
RR
1367 gchar *arg1, gchar *arg2, gpointer user_data )
1368{
baa9ebc4 1369 wxDataViewTextRenderer *cell = (wxDataViewTextRenderer*) user_data;
93763ad5 1370
1a74f561 1371 wxString tmp = wxGTK_CONV_BACK_FONT(arg2, cell->GetOwner()->GetOwner()->GetFont());
a7f61f76
RR
1372 wxVariant value = tmp;
1373 if (!cell->Validate( value ))
1374 return;
93763ad5 1375
e0062c04 1376 wxDataViewModel *model = cell->GetOwner()->GetOwner()->GetModel();
93763ad5 1377
a7f61f76 1378 GtkTreePath *path = gtk_tree_path_new_from_string( arg1 );
9d52aad3 1379 GtkTreeIter iter;
55fbde12
RR
1380 cell->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter, path );
1381 wxDataViewItem item( (void*) iter.user_data );;
a7f61f76 1382 gtk_tree_path_free( path );
93763ad5 1383
0a71f9e9 1384 unsigned int model_col = cell->GetOwner()->GetModelColumn();
93763ad5 1385
9d52aad3
RR
1386 model->SetValue( value, item, model_col );
1387 model->ValueChanged( item, model_col );
a7f61f76
RR
1388}
1389
baa9ebc4 1390IMPLEMENT_CLASS(wxDataViewTextRenderer, wxDataViewRenderer)
6842a71a 1391
9861f022
RR
1392wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString &varianttype, wxDataViewCellMode mode,
1393 int align ) :
1394 wxDataViewRenderer( varianttype, mode, align )
6842a71a 1395{
ed38aa55 1396 m_renderer = (GtkCellRenderer*) gtk_cell_renderer_text_new();
93763ad5 1397
9861f022 1398 if (mode & wxDATAVIEW_CELL_EDITABLE)
a7f61f76
RR
1399 {
1400 GValue gvalue = { 0, };
1401 g_value_init( &gvalue, G_TYPE_BOOLEAN );
1402 g_value_set_boolean( &gvalue, true );
1403 g_object_set_property( G_OBJECT(m_renderer), "editable", &gvalue );
1404 g_value_unset( &gvalue );
93763ad5 1405
a7f61f76 1406 g_signal_connect_after( m_renderer, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback), this );
a912e81f
RR
1407
1408 GtkInitHandlers();
a7f61f76 1409 }
9861f022
RR
1410
1411 SetMode(mode);
1412 SetAlignment(align);
6842a71a 1413}
790b137e 1414
baa9ebc4 1415bool wxDataViewTextRenderer::SetValue( const wxVariant &value )
7b4fde82
RR
1416{
1417 wxString tmp = value;
93763ad5 1418
7b4fde82
RR
1419 GValue gvalue = { 0, };
1420 g_value_init( &gvalue, G_TYPE_STRING );
b94db696 1421 g_value_set_string( &gvalue, wxGTK_CONV_FONT( tmp, GetOwner()->GetOwner()->GetFont() ) );
7b4fde82
RR
1422 g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue );
1423 g_value_unset( &gvalue );
93763ad5 1424
7b4fde82
RR
1425 return true;
1426}
1427
9861f022 1428bool wxDataViewTextRenderer::GetValue( wxVariant &value ) const
a7f61f76
RR
1429{
1430 GValue gvalue = { 0, };
1431 g_value_init( &gvalue, G_TYPE_STRING );
1432 g_object_get_property( G_OBJECT(m_renderer), "text", &gvalue );
1a74f561
VZ
1433 wxString tmp = wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue ),
1434 wx_const_cast(wxDataViewTextRenderer*, this)->GetOwner()->GetOwner()->GetFont() );
a7f61f76 1435 g_value_unset( &gvalue );
93763ad5 1436
a7f61f76
RR
1437 value = tmp;
1438
1439 return true;
1440}
1441
9861f022
RR
1442void wxDataViewTextRenderer::SetAlignment( int align )
1443{
1444 wxDataViewRenderer::SetAlignment(align);
1445
01705e98
RR
1446 if (gtk_check_version(2,10,0))
1447 return;
9861f022 1448
01705e98 1449 // horizontal alignment:
9861f022
RR
1450 PangoAlignment pangoAlign = PANGO_ALIGN_LEFT;
1451 if (align & wxALIGN_RIGHT)
1452 pangoAlign = PANGO_ALIGN_RIGHT;
1453 else if (align & wxALIGN_CENTER_HORIZONTAL)
1454 pangoAlign = PANGO_ALIGN_CENTER;
1455
1456 GValue gvalue = { 0, };
1457 g_value_init( &gvalue, gtk_cell_renderer_mode_get_type() );
1458 g_value_set_enum( &gvalue, pangoAlign );
1459 g_object_set_property( G_OBJECT(m_renderer), "alignment", &gvalue );
1460 g_value_unset( &gvalue );
1461}
1462
f4322df6 1463// ---------------------------------------------------------
baa9ebc4 1464// wxDataViewBitmapRenderer
f4322df6 1465// ---------------------------------------------------------
cbc9145c 1466
baa9ebc4 1467IMPLEMENT_CLASS(wxDataViewBitmapRenderer, wxDataViewRenderer)
cbc9145c 1468
9861f022
RR
1469wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString &varianttype, wxDataViewCellMode mode,
1470 int align ) :
1471 wxDataViewRenderer( varianttype, mode, align )
cbc9145c 1472{
ed38aa55 1473 m_renderer = (GtkCellRenderer*) gtk_cell_renderer_pixbuf_new();
9861f022
RR
1474
1475 SetMode(mode);
1476 SetAlignment(align);
cbc9145c
RR
1477}
1478
baa9ebc4 1479bool wxDataViewBitmapRenderer::SetValue( const wxVariant &value )
cbc9145c
RR
1480{
1481 if (value.GetType() == wxT("wxBitmap"))
1482 {
2586d4a1
RR
1483 wxBitmap bitmap;
1484 bitmap << value;
f4322df6 1485
2586d4a1
RR
1486 // This may create a Pixbuf representation in the
1487 // wxBitmap object (and it will stay there)
1488 GdkPixbuf *pixbuf = bitmap.GetPixbuf();
f4322df6 1489
2586d4a1
RR
1490 GValue gvalue = { 0, };
1491 g_value_init( &gvalue, G_TYPE_OBJECT );
1492 g_value_set_object( &gvalue, pixbuf );
1493 g_object_set_property( G_OBJECT(m_renderer), "pixbuf", &gvalue );
1494 g_value_unset( &gvalue );
f4322df6 1495
2586d4a1
RR
1496 return true;
1497 }
f4322df6 1498
2586d4a1
RR
1499 if (value.GetType() == wxT("wxIcon"))
1500 {
1501 wxIcon bitmap;
1502 bitmap << value;
f4322df6 1503
cbc9145c
RR
1504 // This may create a Pixbuf representation in the
1505 // wxBitmap object (and it will stay there)
2586d4a1 1506 GdkPixbuf *pixbuf = bitmap.GetPixbuf();
f4322df6 1507
cbc9145c
RR
1508 GValue gvalue = { 0, };
1509 g_value_init( &gvalue, G_TYPE_OBJECT );
1510 g_value_set_object( &gvalue, pixbuf );
1511 g_object_set_property( G_OBJECT(m_renderer), "pixbuf", &gvalue );
1512 g_value_unset( &gvalue );
f4322df6 1513
cbc9145c
RR
1514 return true;
1515 }
f4322df6 1516
cbc9145c
RR
1517 return false;
1518}
1519
9861f022 1520bool wxDataViewBitmapRenderer::GetValue( wxVariant &value ) const
cbc9145c
RR
1521{
1522 return false;
1523}
f4322df6 1524
93763ad5 1525// ---------------------------------------------------------
baa9ebc4 1526// wxDataViewToggleRenderer
93763ad5 1527// ---------------------------------------------------------
fa28826d 1528
605c2c4a 1529extern "C" {
93763ad5 1530static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle *renderer,
605c2c4a
RR
1531 gchar *path, gpointer user_data );
1532}
1533
93763ad5 1534static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle *renderer,
605c2c4a
RR
1535 gchar *path, gpointer user_data )
1536{
baa9ebc4 1537 wxDataViewToggleRenderer *cell = (wxDataViewToggleRenderer*) user_data;
605c2c4a 1538
93763ad5 1539 // get old value
605c2c4a
RR
1540 GValue gvalue = { 0, };
1541 g_value_init( &gvalue, G_TYPE_BOOLEAN );
1542 g_object_get_property( G_OBJECT(renderer), "active", &gvalue );
93763ad5 1543 bool tmp = g_value_get_boolean( &gvalue );
605c2c4a
RR
1544 g_value_unset( &gvalue );
1545 // invert it
1546 tmp = !tmp;
93763ad5 1547
605c2c4a
RR
1548 wxVariant value = tmp;
1549 if (!cell->Validate( value ))
1550 return;
93763ad5 1551
e0062c04 1552 wxDataViewModel *model = cell->GetOwner()->GetOwner()->GetModel();
93763ad5 1553
605c2c4a 1554 GtkTreePath *gtk_path = gtk_tree_path_new_from_string( path );
55fbde12
RR
1555 GtkTreeIter iter;
1556 cell->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter, gtk_path );
1557 wxDataViewItem item( (void*) iter.user_data );;
605c2c4a 1558 gtk_tree_path_free( gtk_path );
93763ad5 1559
0a71f9e9 1560 unsigned int model_col = cell->GetOwner()->GetModelColumn();
93763ad5 1561
9d52aad3
RR
1562 model->SetValue( value, item, model_col );
1563 model->ValueChanged( item, model_col );
605c2c4a
RR
1564}
1565
baa9ebc4 1566IMPLEMENT_CLASS(wxDataViewToggleRenderer, wxDataViewRenderer)
605c2c4a 1567
baa9ebc4 1568wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString &varianttype,
9861f022
RR
1569 wxDataViewCellMode mode, int align ) :
1570 wxDataViewRenderer( varianttype, mode, align )
605c2c4a 1571{
ed38aa55 1572 m_renderer = (GtkCellRenderer*) gtk_cell_renderer_toggle_new();
93763ad5 1573
9861f022 1574 if (mode & wxDATAVIEW_CELL_ACTIVATABLE)
605c2c4a 1575 {
9861f022
RR
1576 g_signal_connect_after( m_renderer, "toggled",
1577 G_CALLBACK(wxGtkToggleRendererToggledCallback), this );
553f7d8f
RR
1578 }
1579 else
1580 {
605c2c4a
RR
1581 GValue gvalue = { 0, };
1582 g_value_init( &gvalue, G_TYPE_BOOLEAN );
553f7d8f 1583 g_value_set_boolean( &gvalue, false );
605c2c4a
RR
1584 g_object_set_property( G_OBJECT(m_renderer), "activatable", &gvalue );
1585 g_value_unset( &gvalue );
605c2c4a 1586 }
9861f022
RR
1587
1588 SetMode(mode);
1589 SetAlignment(align);
605c2c4a
RR
1590}
1591
baa9ebc4 1592bool wxDataViewToggleRenderer::SetValue( const wxVariant &value )
605c2c4a
RR
1593{
1594 bool tmp = value;
93763ad5 1595
605c2c4a
RR
1596 GValue gvalue = { 0, };
1597 g_value_init( &gvalue, G_TYPE_BOOLEAN );
1598 g_value_set_boolean( &gvalue, tmp );
1599 g_object_set_property( G_OBJECT(m_renderer), "active", &gvalue );
1600 g_value_unset( &gvalue );
93763ad5 1601
605c2c4a
RR
1602 return true;
1603}
1604
9861f022 1605bool wxDataViewToggleRenderer::GetValue( wxVariant &value ) const
605c2c4a
RR
1606{
1607 GValue gvalue = { 0, };
1608 g_value_init( &gvalue, G_TYPE_BOOLEAN );
1609 g_object_get_property( G_OBJECT(m_renderer), "active", &gvalue );
93763ad5 1610 bool tmp = g_value_get_boolean( &gvalue );
605c2c4a 1611 g_value_unset( &gvalue );
93763ad5 1612
605c2c4a
RR
1613 value = tmp;
1614
1615 return true;
1616}
93763ad5
WS
1617
1618// ---------------------------------------------------------
baa9ebc4 1619// wxDataViewCustomRenderer
93763ad5 1620// ---------------------------------------------------------
e152afc3
RR
1621
1622class wxDataViewCtrlDC: public wxWindowDC
1623{
1624public:
1625 wxDataViewCtrlDC( wxDataViewCtrl *window )
1626 {
1a367564 1627 GtkWidget *widget = window->m_treeview;
e152afc3
RR
1628 // Set later
1629 m_window = NULL;
4d496ecb 1630
e152afc3
RR
1631 m_context = window->GtkGetPangoDefaultContext();
1632 m_layout = pango_layout_new( m_context );
1633 m_fontdesc = pango_font_description_copy( widget->style->font_desc );
1634
1635 m_cmap = gtk_widget_get_colormap( widget ? widget : window->m_widget );
1636
4d496ecb
RR
1637 // Set m_window later
1638 // SetUpDC();
1639 // m_owner = window;
e152afc3
RR
1640 }
1641};
1642
93763ad5 1643// ---------------------------------------------------------
baa9ebc4 1644// wxDataViewCustomRenderer
93763ad5 1645// ---------------------------------------------------------
e152afc3 1646
baa9ebc4 1647IMPLEMENT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer)
e152afc3 1648
baa9ebc4 1649wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype,
9861f022
RR
1650 wxDataViewCellMode mode, int align,
1651 bool no_init ) :
1652 wxDataViewRenderer( varianttype, mode, align )
e152afc3
RR
1653{
1654 m_dc = NULL;
93763ad5 1655
ad63bf41
RR
1656 if (no_init)
1657 m_renderer = NULL;
1658 else
9861f022 1659 Init(mode, align);
ad63bf41
RR
1660}
1661
9861f022 1662bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode, int align)
ad63bf41 1663{
e152afc3
RR
1664 GtkWxCellRenderer *renderer = (GtkWxCellRenderer *) gtk_wx_cell_renderer_new();
1665 renderer->cell = this;
93763ad5 1666
ed38aa55 1667 m_renderer = (GtkCellRenderer*) renderer;
93763ad5 1668
9861f022
RR
1669 SetMode(mode);
1670 SetAlignment(align);
93763ad5 1671
a912e81f
RR
1672 GtkInitHandlers();
1673
ad63bf41 1674 return true;
e152afc3
RR
1675}
1676
baa9ebc4 1677wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
e152afc3
RR
1678{
1679 if (m_dc)
1680 delete m_dc;
1681}
1682
baa9ebc4 1683wxDC *wxDataViewCustomRenderer::GetDC()
e152afc3
RR
1684{
1685 if (m_dc == NULL)
4d496ecb
RR
1686 {
1687 if (GetOwner() == NULL)
1688 return NULL;
1689 if (GetOwner()->GetOwner() == NULL)
1690 return NULL;
e152afc3 1691 m_dc = new wxDataViewCtrlDC( GetOwner()->GetOwner() );
4d496ecb 1692 }
93763ad5 1693
e152afc3
RR
1694 return m_dc;
1695}
93763ad5
WS
1696
1697// ---------------------------------------------------------
baa9ebc4 1698// wxDataViewProgressRenderer
93763ad5 1699// ---------------------------------------------------------
ad63bf41 1700
baa9ebc4 1701IMPLEMENT_CLASS(wxDataViewProgressRenderer, wxDataViewCustomRenderer)
ad63bf41 1702
baa9ebc4 1703wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString &label,
9861f022
RR
1704 const wxString &varianttype, wxDataViewCellMode mode, int align ) :
1705 wxDataViewCustomRenderer( varianttype, mode, align, true )
ad63bf41
RR
1706{
1707 m_label = label;
1708 m_value = 0;
93763ad5 1709
ad63bf41
RR
1710#ifdef __WXGTK26__
1711 if (!gtk_check_version(2,6,0))
1712 {
ed38aa55 1713 m_renderer = (GtkCellRenderer*) gtk_cell_renderer_progress_new();
93763ad5 1714
ad63bf41
RR
1715 GValue gvalue = { 0, };
1716 g_value_init( &gvalue, G_TYPE_STRING );
09dfa6a0
VZ
1717
1718 // FIXME: font encoding support
b94db696 1719 g_value_set_string( &gvalue, wxGTK_CONV_SYS(m_label) );
ad63bf41
RR
1720 g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue );
1721 g_value_unset( &gvalue );
9861f022
RR
1722
1723 SetMode(mode);
1724 SetAlignment(align);
ad63bf41
RR
1725 }
1726 else
1727#endif
1728 {
1729 // Use custom cell code
9861f022 1730 wxDataViewCustomRenderer::Init(mode, align);
ad63bf41
RR
1731 }
1732}
1733
baa9ebc4 1734wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
ad63bf41
RR
1735{
1736}
1737
baa9ebc4 1738bool wxDataViewProgressRenderer::SetValue( const wxVariant &value )
ad63bf41
RR
1739{
1740#ifdef __WXGTK26__
1741 if (!gtk_check_version(2,6,0))
1742 {
7226118b 1743 gint tmp = (long) value;
ad63bf41
RR
1744 GValue gvalue = { 0, };
1745 g_value_init( &gvalue, G_TYPE_INT );
7226118b 1746 g_value_set_int( &gvalue, tmp );
ad63bf41
RR
1747 g_object_set_property( G_OBJECT(m_renderer), "value", &gvalue );
1748 g_value_unset( &gvalue );
1749 }
1750 else
1751#endif
1752 {
1753 m_value = (long) value;
93763ad5 1754
ad63bf41
RR
1755 if (m_value < 0) m_value = 0;
1756 if (m_value > 100) m_value = 100;
1757 }
93763ad5 1758
ad63bf41
RR
1759 return true;
1760}
93763ad5 1761
9861f022
RR
1762bool wxDataViewProgressRenderer::GetValue( wxVariant &value ) const
1763{
1764 return false;
1765}
1766
baa9ebc4 1767bool wxDataViewProgressRenderer::Render( wxRect cell, wxDC *dc, int state )
ad63bf41
RR
1768{
1769 double pct = (double)m_value / 100.0;
1770 wxRect bar = cell;
1771 bar.width = (int)(cell.width * pct);
1772 dc->SetPen( *wxTRANSPARENT_PEN );
1773 dc->SetBrush( *wxBLUE_BRUSH );
1774 dc->DrawRectangle( bar );
1775
1776 dc->SetBrush( *wxTRANSPARENT_BRUSH );
1777 dc->SetPen( *wxBLACK_PEN );
1778 dc->DrawRectangle( cell );
93763ad5 1779
ad63bf41
RR
1780 return true;
1781}
1782
9861f022 1783wxSize wxDataViewProgressRenderer::GetSize() const
ad63bf41
RR
1784{
1785 return wxSize(40,12);
1786}
93763ad5
WS
1787
1788// ---------------------------------------------------------
baa9ebc4 1789// wxDataViewDateRenderer
93763ad5 1790// ---------------------------------------------------------
4d496ecb 1791
baa9ebc4 1792class wxDataViewDateRendererPopupTransient: public wxPopupTransientWindow
7ea3a0de 1793{
93763ad5 1794public:
baa9ebc4 1795 wxDataViewDateRendererPopupTransient( wxWindow* parent, wxDateTime *value,
e0062c04 1796 wxDataViewModel *model, const wxDataViewItem &item, unsigned int col ) :
7ea3a0de
RR
1797 wxPopupTransientWindow( parent, wxBORDER_SIMPLE )
1798 {
1799 m_model = model;
e0062c04 1800 m_item = item;
7ea3a0de 1801 m_col = col;
7ea3a0de
RR
1802 m_cal = new wxCalendarCtrl( this, -1, *value );
1803 wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
1804 sizer->Add( m_cal, 1, wxGROW );
1805 SetSizer( sizer );
1806 sizer->Fit( this );
1807 }
93763ad5 1808
7ea3a0de
RR
1809 virtual void OnDismiss()
1810 {
1811 }
93763ad5 1812
7ea3a0de 1813 void OnCalendar( wxCalendarEvent &event );
93763ad5 1814
e0062c04
RR
1815 wxCalendarCtrl *m_cal;
1816 wxDataViewModel *m_model;
1817 wxDataViewItem m_item;
1818 unsigned int m_col;
93763ad5 1819
7ea3a0de
RR
1820private:
1821 DECLARE_EVENT_TABLE()
1822};
1823
baa9ebc4
RR
1824BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient,wxPopupTransientWindow)
1825 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar )
7ea3a0de
RR
1826END_EVENT_TABLE()
1827
baa9ebc4 1828void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent &event )
7ea3a0de
RR
1829{
1830 wxDateTime date = event.GetDate();
1831 wxVariant value = date;
e0062c04
RR
1832 m_model->SetValue( value, m_item, m_col );
1833 m_model->ValueChanged( m_item, m_col );
7ea3a0de
RR
1834 DismissAndNotify();
1835}
1836
baa9ebc4 1837IMPLEMENT_CLASS(wxDataViewDateRenderer, wxDataViewCustomRenderer)
4d496ecb 1838
baa9ebc4 1839wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString &varianttype,
9861f022
RR
1840 wxDataViewCellMode mode, int align ) :
1841 wxDataViewCustomRenderer( varianttype, mode, align )
4d496ecb 1842{
9861f022
RR
1843 SetMode(mode);
1844 SetAlignment(align);
4d496ecb 1845}
93763ad5 1846
baa9ebc4 1847bool wxDataViewDateRenderer::SetValue( const wxVariant &value )
4d496ecb
RR
1848{
1849 m_date = value.GetDateTime();
93763ad5 1850
4d496ecb
RR
1851 return true;
1852}
1853
9861f022
RR
1854bool wxDataViewDateRenderer::GetValue( wxVariant &value ) const
1855{
1856 return false;
1857}
1858
baa9ebc4 1859bool wxDataViewDateRenderer::Render( wxRect cell, wxDC *dc, int state )
4d496ecb
RR
1860{
1861 dc->SetFont( GetOwner()->GetOwner()->GetFont() );
1862 wxString tmp = m_date.FormatDate();
1863 dc->DrawText( tmp, cell.x, cell.y );
1864
1865 return true;
1866}
1867
9861f022 1868wxSize wxDataViewDateRenderer::GetSize() const
4d496ecb 1869{
4d496ecb
RR
1870 wxString tmp = m_date.FormatDate();
1871 wxCoord x,y,d;
9861f022 1872 GetView()->GetTextExtent( tmp, &x, &y, &d );
4d496ecb
RR
1873 return wxSize(x,y+d);
1874}
1875
e0062c04
RR
1876bool wxDataViewDateRenderer::Activate( wxRect cell, wxDataViewModel *model,
1877 const wxDataViewItem &item, unsigned int col )
4d496ecb 1878{
3f3af7e7 1879 wxVariant variant;
e0062c04 1880 model->GetValue( variant, item, col );
7ea3a0de
RR
1881 wxDateTime value = variant.GetDateTime();
1882
baa9ebc4 1883 wxDataViewDateRendererPopupTransient *popup = new wxDataViewDateRendererPopupTransient(
e0062c04 1884 GetOwner()->GetOwner()->GetParent(), &value, model, item, col );
7ea3a0de
RR
1885 wxPoint pos = wxGetMousePosition();
1886 popup->Move( pos );
1887 popup->Layout();
1888 popup->Popup( popup->m_cal );
4d496ecb
RR
1889
1890 return true;
1891}
1892
c9c13e70
RR
1893
1894// ---------------------------------------------------------
1895// wxDataViewIconTextRenderer
1896// ---------------------------------------------------------
1897
1898IMPLEMENT_CLASS(wxDataViewIconTextRenderer, wxDataViewCustomRenderer)
1899
1900wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
1901 const wxString &varianttype, wxDataViewCellMode mode, int align ) :
1902 wxDataViewCustomRenderer( varianttype, mode, align )
1903{
1904 SetMode(mode);
1905 SetAlignment(align);
1906}
1907
1908wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
1909{
1910}
1911
1912bool wxDataViewIconTextRenderer::SetValue( const wxVariant &value )
1913{
1914 m_value << value;
1915 return true;
1916}
1917
1918bool wxDataViewIconTextRenderer::GetValue( wxVariant &value ) const
1919{
1920 return false;
1921}
1922
1923bool wxDataViewIconTextRenderer::Render( wxRect cell, wxDC *dc, int state )
1924{
1925 dc->SetFont( GetOwner()->GetOwner()->GetFont() );
1926
1927 const wxIcon &icon = m_value.GetIcon();
1928 if (icon.IsOk())
1929 {
1930 dc->DrawIcon( icon, cell.x, cell.y ); // TODO centre
1931 cell.x += icon.GetWidth()+4;
1932 }
1933
1934 dc->DrawText( m_value.GetText(), cell.x, cell.y );
1935
1936 return true;
1937}
1938
1939wxSize wxDataViewIconTextRenderer::GetSize() const
1940{
1941 return wxSize(80,16); // TODO
1942}
1943
1944wxControl* wxDataViewIconTextRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
1945{
1946 return NULL;
1947}
1948
1949bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVariant &value )
1950{
1951 return false;
1952}
1953
93763ad5 1954// ---------------------------------------------------------
605c2c4a 1955// wxDataViewColumn
93763ad5 1956// ---------------------------------------------------------
7b4fde82 1957
31fb32e1
RR
1958
1959static gboolean
1960gtk_dataview_header_button_press_callback( GtkWidget *widget,
1961 GdkEventButton *gdk_event,
1962 wxDataViewColumn *column )
1963{
1964 if (gdk_event->type != GDK_BUTTON_PRESS)
94b1f7bc 1965 return FALSE;
f4322df6 1966
31fb32e1
RR
1967 if (gdk_event->button == 1)
1968 {
1969 wxDataViewCtrl *dv = column->GetOwner();
1970 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, dv->GetId() );
1971 event.SetDataViewColumn( column );
1972 event.SetModel( dv->GetModel() );
94b1f7bc 1973 if (dv->GetEventHandler()->ProcessEvent( event ))
a84c5b6f 1974 return FALSE;
31fb32e1 1975 }
f4322df6 1976
94b1f7bc 1977 return FALSE;
31fb32e1
RR
1978}
1979
7b4fde82
RR
1980extern "C" {
1981static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column,
1982 GtkCellRenderer *cell,
1983 GtkTreeModel *model,
1984 GtkTreeIter *iter,
1985 gpointer data );
1986}
1987
1988
1989static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column,
1990 GtkCellRenderer *renderer,
1991 GtkTreeModel *model,
1992 GtkTreeIter *iter,
1993 gpointer data )
1994{
e0062c04
RR
1995 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model));
1996 GtkWxTreeModel *tree_model = (GtkWxTreeModel *) model;
93763ad5 1997
baa9ebc4 1998 wxDataViewRenderer *cell = (wxDataViewRenderer*) data;
a7f61f76 1999
9d52aad3 2000 wxDataViewItem item( (void*) iter->user_data );
93763ad5 2001
3f3af7e7 2002 wxVariant value;
55fbde12 2003 tree_model->internal->GetDataViewModel()->GetValue( value, item, cell->GetOwner()->GetModelColumn() );
7b4fde82
RR
2004
2005 if (value.GetType() != cell->GetVariantType())
f4322df6
VZ
2006 wxLogError( wxT("Wrong type, required: %s but: %s"),
2007 value.GetType().c_str(),
cbc9145c 2008 cell->GetVariantType().c_str() );
93763ad5 2009
7b4fde82 2010 cell->SetValue( value );
e0743e63 2011
e0062c04 2012#if 0
2a5e6d1b 2013 wxListItemAttr attr;
e0062c04 2014 tree_model->model->GetAttr( attr, cell->GetOwner()->GetModelColumn(), model_row );
2a5e6d1b
RR
2015
2016 if (attr.HasBackgroundColour())
2017 {
2018 wxColour colour = attr.GetBackgroundColour();
1cd5e95c 2019 const GdkColor * const gcol = colour.GetColor();
e0743e63 2020
2a5e6d1b
RR
2021 GValue gvalue = { 0, };
2022 g_value_init( &gvalue, GDK_TYPE_COLOR );
2023 g_value_set_boxed( &gvalue, gcol );
2024 g_object_set_property( G_OBJECT(renderer), "cell-background_gdk", &gvalue );
2025 g_value_unset( &gvalue );
2026 }
2027 else
2028 {
2029 GValue gvalue = { 0, };
2030 g_value_init( &gvalue, G_TYPE_BOOLEAN );
2031 g_value_set_boolean( &gvalue, FALSE );
2032 g_object_set_property( G_OBJECT(renderer), "cell-background-set", &gvalue );
2033 g_value_unset( &gvalue );
2034 }
e0062c04
RR
2035#endif
2036
7b4fde82
RR
2037}
2038
cbc9145c 2039IMPLEMENT_CLASS(wxDataViewColumn, wxDataViewColumnBase)
fa28826d 2040
91a6c655
RR
2041#include <wx/listimpl.cpp>
2042WX_DEFINE_LIST(wxDataViewColumnList);
2043
f4322df6
VZ
2044wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewRenderer *cell,
2045 unsigned int model_column, int width,
87f0efe2
RR
2046 wxAlignment align, int flags ) :
2047 wxDataViewColumnBase( title, cell, model_column, width, align, flags )
fa28826d 2048{
9861f022 2049 Init( align, flags, width );
31fb32e1 2050
9861f022 2051 gtk_tree_view_column_set_clickable( GTK_TREE_VIEW_COLUMN(m_column), TRUE );
31fb32e1 2052 SetTitle( title );
fa28826d
RR
2053}
2054
f4322df6
VZ
2055wxDataViewColumn::wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *cell,
2056 unsigned int model_column, int width,
87f0efe2
RR
2057 wxAlignment align, int flags ) :
2058 wxDataViewColumnBase( bitmap, cell, model_column, width, align, flags )
9861f022
RR
2059{
2060 Init( align, flags, width );
2061
2062 SetBitmap( bitmap );
2063}
2064
2065void wxDataViewColumn::Init(wxAlignment align, int flags, int width)
07a84e7b 2066{
31fb32e1 2067 m_isConnected = false;
07a84e7b 2068
9861f022 2069 GtkCellRenderer *renderer = (GtkCellRenderer *) GetRenderer()->GetGtkHandle();
07a84e7b 2070 GtkTreeViewColumn *column = gtk_tree_view_column_new();
9861f022 2071 m_column = (GtkWidget*) column;
07a84e7b 2072
9861f022
RR
2073 SetFlags( flags );
2074 SetAlignment( align );
07a84e7b 2075
9861f022
RR
2076 // NOTE: we prefer not to call SetMinWidth(wxDVC_DEFAULT_MINWIDTH);
2077 // as GTK+ is smart and unless explicitely told, will set the minimal
2078 // width to the title's lenght, which is a better default
07a84e7b 2079
9861f022
RR
2080 // the GTK_TREE_VIEW_COLUMN_FIXED is required by the "fixed height" mode
2081 // that we use for the wxDataViewCtrl
2082 gtk_tree_view_column_set_fixed_width( column, width < 0 ? wxDVC_DEFAULT_WIDTH : width );
b94db696 2083 gtk_tree_view_column_set_sizing( column, GTK_TREE_VIEW_COLUMN_FIXED );
07a84e7b 2084
9861f022 2085 gtk_tree_view_column_pack_end( column, renderer, TRUE );
07a84e7b
RR
2086
2087 gtk_tree_view_column_set_cell_data_func( column, renderer,
9861f022 2088 wxGtkTreeCellDataFunc, (gpointer) GetRenderer(), NULL );
07a84e7b
RR
2089}
2090
fa28826d
RR
2091wxDataViewColumn::~wxDataViewColumn()
2092{
2093}
2094
31fb32e1
RR
2095void wxDataViewColumn::OnInternalIdle()
2096{
2097 if (m_isConnected)
2098 return;
f4322df6 2099
31fb32e1
RR
2100 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview))
2101 {
9861f022 2102 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
31fb32e1
RR
2103 if (column->button)
2104 {
2105 g_signal_connect(column->button, "button_press_event",
2106 G_CALLBACK (gtk_dataview_header_button_press_callback), this);
f4322df6 2107
31fb32e1
RR
2108 m_isConnected = true;
2109 }
2110 }
2111}
2112
b94db696
RR
2113void wxDataViewColumn::SetOwner( wxDataViewCtrl *owner )
2114{
2115 wxDataViewColumnBase::SetOwner( owner );
f4322df6 2116
9861f022 2117 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
f4322df6 2118
b94db696 2119 gtk_tree_view_column_set_title( column, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
b94db696
RR
2120}
2121
fa28826d
RR
2122void wxDataViewColumn::SetTitle( const wxString &title )
2123{
9861f022 2124 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
f4322df6 2125
31fb32e1
RR
2126 if (m_isConnected)
2127 {
2128 // disconnect before column->button gets recreated
f4322df6 2129 g_signal_handlers_disconnect_by_func( column->button,
9861f022 2130 (GtkWidget*) gtk_dataview_header_button_press_callback, this);
f4322df6 2131
31fb32e1
RR
2132 m_isConnected = false;
2133 }
2134
09dfa6a0
VZ
2135 // FIXME: can it really happen that we don't have the owner here??
2136 wxDataViewCtrl *ctrl = GetOwner();
2137 gtk_tree_view_column_set_title( column, ctrl ? wxGTK_CONV_FONT(title, ctrl->GetFont())
2138 : wxGTK_CONV_SYS(title) );
31fb32e1 2139
07a84e7b
RR
2140 gtk_tree_view_column_set_widget( column, NULL );
2141}
2142
9861f022
RR
2143wxString wxDataViewColumn::GetTitle() const
2144{
2145 const gchar *str = gtk_tree_view_column_get_title( GTK_TREE_VIEW_COLUMN(m_column) );
2146 return wxConvFileName->cMB2WX(str);
2147}
2148
07a84e7b
RR
2149void wxDataViewColumn::SetBitmap( const wxBitmap &bitmap )
2150{
2151 wxDataViewColumnBase::SetBitmap( bitmap );
2152
9861f022 2153 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
07a84e7b
RR
2154 if (bitmap.Ok())
2155 {
2156 GtkImage *gtk_image = GTK_IMAGE( gtk_image_new() );
f4322df6 2157
07a84e7b
RR
2158 GdkBitmap *mask = (GdkBitmap *) NULL;
2159 if (bitmap.GetMask())
2160 mask = bitmap.GetMask()->GetBitmap();
2161
2162 if (bitmap.HasPixbuf())
2163 {
2164 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image),
2165 bitmap.GetPixbuf());
2166 }
2167 else
2168 {
2169 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image),
2170 bitmap.GetPixmap(), mask);
2171 }
2172 gtk_widget_show( GTK_WIDGET(gtk_image) );
f4322df6 2173
07a84e7b
RR
2174 gtk_tree_view_column_set_widget( column, GTK_WIDGET(gtk_image) );
2175 }
2176 else
2177 {
2178 gtk_tree_view_column_set_widget( column, NULL );
2179 }
fa28826d
RR
2180}
2181
9861f022
RR
2182void wxDataViewColumn::SetHidden( bool hidden )
2183{
2184 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column), !hidden );
2185}
2186
2187void wxDataViewColumn::SetResizeable( bool resizeable )
2188{
2189 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column), resizeable );
2190}
2191
47cef10f
RR
2192void wxDataViewColumn::SetAlignment( wxAlignment align )
2193{
9861f022 2194 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
f4322df6 2195
47cef10f
RR
2196 gfloat xalign = 0.0;
2197 if (align == wxALIGN_RIGHT)
2198 xalign = 1.0;
9861f022
RR
2199 if (align == wxALIGN_CENTER_HORIZONTAL ||
2200 align == wxALIGN_CENTER)
47cef10f 2201 xalign = 0.5;
f4322df6 2202
9861f022
RR
2203 gtk_tree_view_column_set_alignment( column, xalign );
2204}
2205
2206wxAlignment wxDataViewColumn::GetAlignment() const
2207{
2208 gfloat xalign = gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column) );
2209
2210 if (xalign == 1.0)
2211 return wxALIGN_RIGHT;
2212 if (xalign == 0.5)
2213 return wxALIGN_CENTER_HORIZONTAL;
f4322df6 2214
9861f022 2215 return wxALIGN_LEFT;
47cef10f
RR
2216}
2217
31fb32e1
RR
2218void wxDataViewColumn::SetSortable( bool sortable )
2219{
9861f022 2220 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
94b1f7bc
RR
2221
2222 if (sortable)
0bd26819 2223 {
94b1f7bc 2224 gtk_tree_view_column_set_sort_column_id( column, GetModelColumn() );
0bd26819 2225 }
94b1f7bc 2226 else
0bd26819 2227 {
94b1f7bc 2228 gtk_tree_view_column_set_sort_column_id( column, -1 );
0bd26819
RR
2229 gtk_tree_view_column_set_sort_indicator( column, FALSE );
2230 }
31fb32e1
RR
2231}
2232
87f0efe2 2233bool wxDataViewColumn::IsSortable() const
31fb32e1 2234{
9861f022 2235 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
94b1f7bc 2236 return (gtk_tree_view_column_get_sort_column_id( column ) != -1);
31fb32e1
RR
2237}
2238
9861f022
RR
2239bool wxDataViewColumn::IsResizeable() const
2240{
2241 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
2242 return gtk_tree_view_column_get_resizable( column );
2243}
2244
2245bool wxDataViewColumn::IsHidden() const
2246{
2247 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
2248 return !gtk_tree_view_column_get_visible( column );
2249}
2250
47cef10f
RR
2251void wxDataViewColumn::SetSortOrder( bool ascending )
2252{
9861f022 2253 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
f4322df6 2254
47cef10f
RR
2255 if (ascending)
2256 gtk_tree_view_column_set_sort_order( column, GTK_SORT_ASCENDING );
2257 else
2258 gtk_tree_view_column_set_sort_order( column, GTK_SORT_DESCENDING );
0bd26819
RR
2259
2260 gtk_tree_view_column_set_sort_indicator( column, TRUE );
47cef10f
RR
2261}
2262
87f0efe2 2263bool wxDataViewColumn::IsSortOrderAscending() const
31fb32e1 2264{
9861f022 2265 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
f4322df6 2266
31fb32e1
RR
2267 return (gtk_tree_view_column_get_sort_order( column ) != GTK_SORT_DESCENDING);
2268}
2269
9861f022 2270void wxDataViewColumn::SetMinWidth( int width )
533544f2 2271{
9861f022 2272 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column), width );
533544f2
RR
2273}
2274
9861f022
RR
2275int wxDataViewColumn::GetMinWidth() const
2276{
2277 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column) );
2278}
2279
2280int wxDataViewColumn::GetWidth() const
533544f2 2281{
9861f022 2282 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column) );
533544f2
RR
2283}
2284
9861f022 2285void wxDataViewColumn::SetWidth( int width )
533544f2 2286{
9861f022 2287 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column), width );
533544f2
RR
2288}
2289
9861f022 2290
4508fcd2
RR
2291//-----------------------------------------------------------------------------
2292// wxGtkTreeModelNode
2293//-----------------------------------------------------------------------------
2294
2295void wxGtkTreeModelNode::Resort()
2296{
af110130
RR
2297 size_t child_count = GetChildCount();
2298 if (child_count == 0)
0be79c8a
RR
2299 return;
2300
af110130
RR
2301 size_t node_count = GetNodesCount();
2302
2303 if (child_count == 1)
0be79c8a 2304 {
af110130
RR
2305 if (node_count == 1)
2306 {
2307 wxGtkTreeModelNode *node = m_nodes.Item( 0 );
2308 node->Resort();
2309 }
0be79c8a
RR
2310 return;
2311 }
2312
40196b1e
RR
2313 wxGtkTreeModelChildren temp;
2314 WX_APPEND_ARRAY( temp, m_children );
2315
2316 g_internal = m_internal;
2317 m_children.Sort( &wxGtkTreeModelChildCmp );
0be79c8a 2318
af110130 2319 gint *new_order = new gint[child_count];
4508fcd2 2320
40196b1e 2321 unsigned int pos;
af110130 2322 for (pos = 0; pos < child_count; pos++)
4508fcd2 2323 {
40196b1e
RR
2324 void *id = m_children.Item( pos );
2325 int old_pos = temp.Index( id );
2326 new_order[pos] = old_pos;
4508fcd2 2327 }
0be79c8a 2328
0be79c8a
RR
2329 GtkTreeModel *gtk_tree_model = GTK_TREE_MODEL( m_internal->GetGtkModel() );
2330
2331 GtkTreeIter iter;
40196b1e 2332 iter.user_data = GetItem().GetID();
0be79c8a 2333 iter.stamp = m_internal->GetGtkModel()->stamp;
40196b1e
RR
2334
2335 GtkTreePath *path = m_internal->get_path( &iter );
2336
0be79c8a
RR
2337 gtk_tree_model_rows_reordered( gtk_tree_model, path, &iter, new_order );
2338
2339 gtk_tree_path_free (path);
2340
2341 delete [] new_order;
2342
af110130 2343 for (pos = 0; pos < node_count; pos++)
4508fcd2 2344 {
af110130 2345 wxGtkTreeModelNode *node = m_nodes.Item( pos );
4508fcd2
RR
2346 node->Resort();
2347 }
2348}
2349
55fbde12
RR
2350//-----------------------------------------------------------------------------
2351// wxDataViewCtrlInternal
2352//-----------------------------------------------------------------------------
2353
2354wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl *owner,
2355 wxDataViewModel *wx_model, GtkWxTreeModel *gtk_model )
2356{
2357 m_owner = owner;
2358 m_wx_model = wx_model;
2359 m_gtk_model = gtk_model;
2360 m_root = NULL;
b8b7b087 2361 m_sort_order = GTK_SORT_ASCENDING;
40196b1e 2362 m_sort_column = -1;
55fbde12
RR
2363 InitTree();
2364}
2365
2366wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
2367{
2368 g_object_unref( m_gtk_model );
2369}
2370
ef427989
RR
2371void wxDataViewCtrlInternal::InitTree()
2372{
2373 wxDataViewItem item;
0be79c8a 2374 m_root = new wxGtkTreeModelNode( NULL, item, this );
ef427989
RR
2375
2376 BuildBranch( m_root );
2377}
2378
55fbde12
RR
2379void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode *node )
2380{
2381 if (node->GetChildCount() == 0)
2382 {
74fe973b
RR
2383 wxDataViewItemArray children;
2384 unsigned int count = m_wx_model->GetChildren( node->GetItem(), children );
2385 unsigned int pos;
2386 for (pos = 0; pos < count; pos++)
55fbde12 2387 {
74fe973b
RR
2388 wxDataViewItem child = children[pos];
2389
af110130
RR
2390 if (m_wx_model->IsContainer( child ))
2391 node->AddNode( new wxGtkTreeModelNode( node, child, this ) );
2392 else
2393 node->AddLeave( child.GetID() );
effd54b0
RR
2394
2395 // Don't send any events here
55fbde12
RR
2396 }
2397 }
2398}
2399
4508fcd2
RR
2400void wxDataViewCtrlInternal::Resort()
2401{
2402 m_root->Resort();
2403}
2404
55fbde12
RR
2405bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item )
2406{
2407 wxGtkTreeModelNode *parent_node = FindNode( parent );
af110130
RR
2408 if (m_wx_model->IsContainer( item ))
2409 parent_node->AddNode( new wxGtkTreeModelNode( parent_node, item, this ) );
2410 else
2411 parent_node->AddLeave( item.GetID() );
d8331a01
RR
2412
2413 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_ADDED, m_owner->GetId() );
2414 event.SetEventObject( m_owner );
2415 event.SetModel( m_owner->GetModel() );
2416 event.SetItem( item );
2417 m_owner->GetEventHandler()->ProcessEvent( event );
2418
55fbde12
RR
2419 return true;
2420}
2421
469d3e9b 2422bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item )
55fbde12 2423{
46abf077
RR
2424 wxGtkTreeModelNode *parent_node = FindNode( parent );
2425 parent_node->DeleteChild( item.GetID() );
d8331a01
RR
2426
2427 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED, m_owner->GetId() );
2428 event.SetEventObject( m_owner );
2429 event.SetModel( m_owner->GetModel() );
2430 event.SetItem( item );
2431 m_owner->GetEventHandler()->ProcessEvent( event );
2432
2433 return true;
2434}
2435
2436bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem &item )
2437{
2438 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_CHANGED, m_owner->GetId() );
2439 event.SetEventObject( m_owner );
2440 event.SetModel( m_owner->GetModel() );
2441 event.SetItem( item );
2442 m_owner->GetEventHandler()->ProcessEvent( event );
2443
2444 return true;
2445}
2446
2447bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem &item, unsigned int col )
2448{
2449 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED, m_owner->GetId() );
2450 event.SetEventObject( m_owner );
2451 event.SetModel( m_owner->GetModel() );
2452 event.SetColumn( col );
2453 event.SetItem( item );
2454 m_owner->GetEventHandler()->ProcessEvent( event );
2455
2456 return true;
2457}
2458
2459bool wxDataViewCtrlInternal::Cleared()
2460{
2461 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED, m_owner->GetId() );
2462 event.SetEventObject( m_owner );
2463 event.SetModel( m_owner->GetModel() );
2464 m_owner->GetEventHandler()->ProcessEvent( event );
2465
55fbde12
RR
2466 return true;
2467}
2468
2469gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path )
2470{
2471 int depth = gtk_tree_path_get_depth( path );
2472
2473 wxGtkTreeModelNode *node = m_root;
2474
2475 int i;
2476 for (i = 0; i < depth; i++)
2477 {
2478 BuildBranch( node );
2479
2480 gint pos = gtk_tree_path_get_indices (path)[i];
2481 if (pos < 0) return FALSE;
2482 if ((size_t)pos >= node->GetChildCount()) return FALSE;
2483
af110130
RR
2484 void* id = node->GetChildren().Item( (size_t) pos );
2485
2486 if (i == depth-1)
2487 {
2488 iter->stamp = m_gtk_model->stamp;
2489 iter->user_data = id;
2490 return TRUE;
2491 }
55fbde12 2492
af110130
RR
2493 size_t count = node->GetNodes().GetCount();
2494 size_t pos2;
2495 for (pos2 = 0; pos2 < count; pos2++)
2496 {
2497 wxGtkTreeModelNode *child_node = node->GetNodes().Item( pos2 );
2498 if (child_node->GetItem().GetID() == id)
2499 {
2500 node = child_node;
2501 break;
2502 }
2503 }
2504 }
55fbde12 2505
af110130 2506 return FALSE;
55fbde12
RR
2507}
2508
2509GtkTreePath *wxDataViewCtrlInternal::get_path( GtkTreeIter *iter )
2510{
2511 GtkTreePath *retval = gtk_tree_path_new ();
af110130 2512 void *id = iter->user_data;
55fbde12 2513
af110130
RR
2514 wxGtkTreeModelNode *node = FindParentNode( iter );
2515 while (node)
55fbde12 2516 {
af110130 2517 int pos = node->GetChildren().Index( id );
40196b1e 2518
55fbde12 2519 gtk_tree_path_prepend_index( retval, pos );
af110130
RR
2520
2521 id = node->GetItem().GetID();
2522 node = node->GetParent();
55fbde12
RR
2523 }
2524
2525 return retval;
2526}
2527
2528gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter )
2529{
af110130 2530 wxGtkTreeModelNode *parent = FindParentNode( iter );
69892729
RR
2531 if( parent == NULL )
2532 return FALSE;
2533
40196b1e
RR
2534 int pos = parent->GetChildren().Index( iter->user_data );
2535
2536 if (pos == (int) parent->GetChildCount()-1)
55fbde12 2537 return FALSE;
ef427989 2538
ef427989 2539 iter->stamp = m_gtk_model->stamp;
af110130 2540 iter->user_data = parent->GetChildren().Item( pos+1 );
55fbde12
RR
2541
2542 return TRUE;
2543}
2544
2545gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter *parent )
2546{
2547 wxDataViewItem item( (void*) parent->user_data );
2548
ed903e42 2549 if (!m_wx_model->IsContainer( item ))
55fbde12
RR
2550 return FALSE;
2551
2552 wxGtkTreeModelNode *parent_node = FindNode( parent );
2553 BuildBranch( parent_node );
ee5aa9d4 2554
af110130 2555 if (parent_node->GetChildCount() == 0)
ee5aa9d4 2556 return FALSE;
55fbde12 2557
55fbde12 2558 iter->stamp = m_gtk_model->stamp;
af110130 2559 iter->user_data = (gpointer) parent_node->GetChildren().Item( 0 );
55fbde12
RR
2560
2561 return TRUE;
2562}
2563
2564gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter )
2565{
2566 wxDataViewItem item( (void*) iter->user_data );
af110130 2567 bool is_container = m_wx_model->IsContainer( item );
ee5aa9d4 2568
af110130 2569 if (!is_container)
ee5aa9d4
RR
2570 return FALSE;
2571
2572 wxGtkTreeModelNode *node = FindNode( iter );
2573 BuildBranch( node );
55fbde12 2574
af110130 2575 return (node->GetChildCount() > 0);
55fbde12
RR
2576}
2577
2578gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter )
2579{
2580 wxDataViewItem item( (void*) iter->user_data );
2581
ed903e42 2582 if (!m_wx_model->IsContainer( item ))
55fbde12
RR
2583 return 0;
2584
2585 wxGtkTreeModelNode *parent_node = FindNode( iter );
2586 BuildBranch( parent_node );
ef427989
RR
2587
2588 // wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() );
55fbde12
RR
2589
2590 return parent_node->GetChildCount();
2591}
2592
2593gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter *parent, gint n )
2594{
2595 void* id = NULL;
2596 if (parent) id = (void*) parent->user_data;
2597 wxDataViewItem item( id );
2598
ed903e42 2599 if (!m_wx_model->IsContainer( item ))
55fbde12
RR
2600 return FALSE;
2601
2602 wxGtkTreeModelNode *parent_node = FindNode( parent );
2603 BuildBranch( parent_node );
2604
ef427989 2605 // wxPrintf( "iter_nth_child %d\n", n );
55fbde12
RR
2606
2607 iter->stamp = m_gtk_model->stamp;
af110130 2608 iter->user_data = parent_node->GetChildren().Item( n );
55fbde12
RR
2609
2610 return TRUE;
2611}
2612
2613gboolean wxDataViewCtrlInternal::iter_parent( GtkTreeIter *iter, GtkTreeIter *child )
2614{
af110130 2615 wxGtkTreeModelNode *node = FindParentNode( child );
55fbde12
RR
2616 if (!node)
2617 return FALSE;
2618
2619 iter->stamp = m_gtk_model->stamp;
2620 iter->user_data = (gpointer) node->GetItem().GetID();
2621
2622 return TRUE;
2623}
2624
55fbde12 2625static wxGtkTreeModelNode*
69892729 2626wxDataViewCtrlInternal_FindNode( wxDataViewModel * model, wxGtkTreeModelNode *treeNode, const wxDataViewItem &item )
55fbde12 2627{
69892729
RR
2628 if( model == NULL )
2629 return NULL;
55fbde12 2630
69892729
RR
2631 ItemList list;
2632 list.DeleteContents( true );
2633 wxDataViewItem it( item );
2634 while( it.IsOk() )
55fbde12 2635 {
69892729
RR
2636 wxDataViewItem * pItem = new wxDataViewItem( it );
2637 list.Insert( pItem );
2638 it = model->GetParent( it );
2639 }
2640
2641 wxGtkTreeModelNode * node = treeNode;
966cb94d 2642 for( ItemList::compatibility_iterator n = list.GetFirst(); n; n = n->GetNext() )
69892729
RR
2643 {
2644 if( node && node->GetNodes().GetCount() != 0 )
ef427989 2645 {
69892729
RR
2646 int len = node->GetNodes().GetCount();
2647 wxGtkTreeModelNodes nodes = node->GetNodes();
2648 int j = 0;
2649 for( ; j < len; j ++)
2650 {
2651 if( nodes[j]->GetItem() == *(n->GetData()))
2652 {
2653 node = nodes[j];
2654 break;
2655 }
2656 }
2657
2658 if( j == len )
2659 {
2660 return NULL;
2661 }
ef427989 2662 }
69892729
RR
2663 else
2664 return NULL;
55fbde12 2665 }
69892729
RR
2666 return node;
2667
55fbde12
RR
2668}
2669
2670wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( GtkTreeIter *iter )
2671{
2672 if (!iter)
2673 return m_root;
2674
2675 wxDataViewItem item( (void*) iter->user_data );
0be79c8a
RR
2676 if (!item.IsOk())
2677 return m_root;
55fbde12 2678
69892729 2679 wxGtkTreeModelNode *result = wxDataViewCtrlInternal_FindNode( m_wx_model, m_root, item );
55fbde12
RR
2680
2681 if (!result)
2682 {
2683 wxPrintf( "Not found %d\n", (int) iter->user_data );
2684 char *crash = NULL;
2685 *crash = 0;
2686 }
2687
2688 return result;
2689}
2690
2691wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( const wxDataViewItem &item )
2692{
0be79c8a
RR
2693 if (!item.IsOk())
2694 return m_root;
2695
69892729 2696 wxGtkTreeModelNode *result = wxDataViewCtrlInternal_FindNode( m_wx_model, m_root, item );
55fbde12
RR
2697
2698 if (!result)
2699 {
2700 wxPrintf( "Not found %d\n", (int) item.GetID() );
2701 char *crash = NULL;
2702 *crash = 0;
2703 }
2704
2705 return result;
2706}
2707
af110130 2708static wxGtkTreeModelNode*
69892729 2709wxDataViewCtrlInternal_FindParentNode( wxDataViewModel * model, wxGtkTreeModelNode *treeNode, const wxDataViewItem &item )
af110130 2710{
69892729
RR
2711 if( model == NULL )
2712 return NULL;
2713
2714 ItemList list;
2715 list.DeleteContents( true );
2716 if( !item.IsOk() )
2717 return NULL;
2718
2719 wxDataViewItem it( model->GetParent( item ) );
2720 while( it.IsOk() )
af110130 2721 {
69892729
RR
2722 wxDataViewItem * pItem = new wxDataViewItem( it );
2723 list.Insert( pItem );
2724 it = model->GetParent( it );
af110130
RR
2725 }
2726
69892729 2727 wxGtkTreeModelNode * node = treeNode;
966cb94d 2728 for( ItemList::compatibility_iterator n = list.GetFirst(); n; n = n->GetNext() )
af110130 2729 {
69892729 2730 if( node && node->GetNodes().GetCount() != 0 )
af110130 2731 {
69892729
RR
2732 int len = node->GetNodes().GetCount();
2733 wxGtkTreeModelNodes nodes = node->GetNodes();
2734 int j = 0;
2735 for( ; j < len; j ++)
2736 {
2737 if( nodes[j]->GetItem() == *(n->GetData()))
2738 {
2739 node = nodes[j];
2740 break;
2741 }
2742 }
2743
2744 if( j == len )
2745 {
2746 return NULL;
2747 }
af110130 2748 }
69892729
RR
2749 else
2750 return NULL;
2751 }
2752 //Examine whether the node is item's parent node
2753 int len = node->GetChildCount();
2754 for( int i = 0; i < len ; i ++ )
2755 {
2756 if( node->GetChildren().Item( i ) == item.GetID() )
2757 return node;
af110130 2758 }
af110130
RR
2759 return NULL;
2760}
2761
2762wxGtkTreeModelNode *wxDataViewCtrlInternal::FindParentNode( GtkTreeIter *iter )
2763{
2764 if (!iter)
2765 return NULL;
2766
2767 wxDataViewItem item( (void*) iter->user_data );
2768 if (!item.IsOk())
2769 return NULL;
2770
69892729 2771 return wxDataViewCtrlInternal_FindParentNode( m_wx_model, m_root, item );
af110130
RR
2772}
2773
2774wxGtkTreeModelNode *wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem &item )
2775{
2776 if (!item.IsOk())
2777 return NULL;
2778
69892729 2779 return wxDataViewCtrlInternal_FindParentNode( m_wx_model, m_root, item );
af110130
RR
2780}
2781
eb7f97f8
RR
2782//-----------------------------------------------------------------------------
2783// wxDataViewCtrl signal callbacks
2784//-----------------------------------------------------------------------------
2785
2786static void
2787wxdataview_selection_changed_callback( GtkTreeSelection* selection, wxDataViewCtrl *dv )
2788{
b94db696
RR
2789 if (!GTK_WIDGET_REALIZED(dv->m_widget))
2790 return;
f4322df6 2791
e0062c04 2792 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_SELECTED, dv->GetId() );
6848478c 2793 event.SetItem( dv->GetSelection() );
eb7f97f8
RR
2794 event.SetModel( dv->GetModel() );
2795 dv->GetEventHandler()->ProcessEvent( event );
2796}
2797
f828871d 2798static void
f4322df6 2799wxdataview_row_activated_callback( GtkTreeView* treeview, GtkTreePath *path,
f828871d
RR
2800 GtkTreeViewColumn *column, wxDataViewCtrl *dv )
2801{
e0062c04 2802 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, dv->GetId() );
55fbde12
RR
2803
2804 GtkTreeIter iter;
2805 dv->GtkGetInternal()->get_iter( &iter, path );
2806 wxDataViewItem item( (void*) iter.user_data );;
2807 event.SetItem( item );
f828871d
RR
2808 event.SetModel( dv->GetModel() );
2809 dv->GetEventHandler()->ProcessEvent( event );
2810}
2811
718fd180
RR
2812static gboolean
2813wxdataview_test_expand_row_callback( GtkTreeView* treeview, GtkTreeIter* iter,
2814 GtkTreePath *path, wxDataViewCtrl *dv )
2815{
2816 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, dv->GetId() );
2817
2818 wxDataViewItem item( (void*) iter->user_data );;
2819 event.SetItem( item );
2820 event.SetModel( dv->GetModel() );
2821 dv->GetEventHandler()->ProcessEvent( event );
2822
2823 return !event.IsAllowed();
2824}
2825
2826static void
2827wxdataview_row_expanded_callback( GtkTreeView* treeview, GtkTreeIter* iter,
2828 GtkTreePath *path, wxDataViewCtrl *dv )
2829{
2830 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, dv->GetId() );
2831
2832 wxDataViewItem item( (void*) iter->user_data );;
2833 event.SetItem( item );
2834 event.SetModel( dv->GetModel() );
2835 dv->GetEventHandler()->ProcessEvent( event );
2836}
2837
2838static gboolean
2839wxdataview_test_collapse_row_callback( GtkTreeView* treeview, GtkTreeIter* iter,
2840 GtkTreePath *path, wxDataViewCtrl *dv )
2841{
2842 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, dv->GetId() );
2843
2844 wxDataViewItem item( (void*) iter->user_data );;
2845 event.SetItem( item );
2846 event.SetModel( dv->GetModel() );
2847 dv->GetEventHandler()->ProcessEvent( event );
2848
2849 return !event.IsAllowed();
2850}
2851
2852static void
2853wxdataview_row_collapsed_callback( GtkTreeView* treeview, GtkTreeIter* iter,
2854 GtkTreePath *path, wxDataViewCtrl *dv )
2855{
2856 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, dv->GetId() );
2857
2858 wxDataViewItem item( (void*) iter->user_data );;
2859 event.SetItem( item );
2860 event.SetModel( dv->GetModel() );
2861 dv->GetEventHandler()->ProcessEvent( event );
2862}
2863
790b137e 2864//-----------------------------------------------------------------------------
718fd180 2865 // wxDataViewCtrl
790b137e
RR
2866//-----------------------------------------------------------------------------
2867
1e510b1e
RR
2868//-----------------------------------------------------------------------------
2869// InsertChild for wxDataViewCtrl
2870//-----------------------------------------------------------------------------
2871
2872static void wxInsertChildInDataViewCtrl( wxWindowGTK* parent, wxWindowGTK* child )
2873{
2874 wxDataViewCtrl * dvc = (wxDataViewCtrl*) parent;
2875 GtkWidget *treeview = dvc->GtkGetTreeView();
2876
2877 // Insert widget in GtkTreeView
2878 if (GTK_WIDGET_REALIZED(treeview))
e8375af8 2879 gtk_widget_set_parent_window( child->m_widget,
1e510b1e
RR
2880 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview) ) );
2881 gtk_widget_set_parent( child->m_widget, treeview );
2882}
2883
2884static
2885void gtk_dataviewctrl_size_callback( GtkWidget *WXUNUSED(widget),
2886 GtkAllocation *alloc,
2887 wxDataViewCtrl *win )
2888{
966cb94d 2889 wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst();
1e510b1e
RR
2890 while (node)
2891 {
2892 wxWindow *child = node->GetData();
e8375af8 2893
1e510b1e
RR
2894 GtkRequisition req;
2895 gtk_widget_size_request( child->m_widget, &req );
e8375af8 2896
1e510b1e
RR
2897 GtkAllocation alloc;
2898 alloc.x = child->m_x;
2899 alloc.y = child->m_y;
2900 alloc.width = child->m_width;
2901 alloc.height = child->m_height;
2902 gtk_widget_size_allocate( child->m_widget, &alloc );
e8375af8 2903
1e510b1e
RR
2904 node = node->GetNext();
2905 }
2906}
2907
2908
2909
239eaa41
RR
2910IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase)
2911
2912wxDataViewCtrl::~wxDataViewCtrl()
2913{
8f850e28
RR
2914 if (m_notifier)
2915 GetModel()->RemoveNotifier( m_notifier );
87f0efe2
RR
2916
2917 // remove the model from the GtkTreeView before it gets destroyed by the
2918 // wxDataViewCtrlBase's dtor
2919 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview), NULL );
55fbde12
RR
2920
2921 delete m_internal;
239eaa41
RR
2922}
2923
2924void wxDataViewCtrl::Init()
2925{
8f850e28 2926 m_notifier = NULL;
239eaa41
RR
2927}
2928
2929bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
93763ad5 2930 const wxPoint& pos, const wxSize& size,
239eaa41
RR
2931 long style, const wxValidator& validator )
2932{
2933 Init();
93763ad5 2934
239eaa41
RR
2935 if (!PreCreation( parent, pos, size ) ||
2936 !CreateBase( parent, id, pos, size, style, validator ))
2937 {
2938 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
93763ad5 2939 return false;
239eaa41 2940 }
1a367564 2941
1e510b1e
RR
2942 m_insertCallback = wxInsertChildInDataViewCtrl;
2943
1a367564 2944 m_widget = gtk_scrolled_window_new (NULL, NULL);
6493aaca
VZ
2945
2946 GtkScrolledWindowSetBorder(m_widget, style);
1a367564
RR
2947
2948 m_treeview = gtk_tree_view_new();
2949 gtk_container_add (GTK_CONTAINER (m_widget), m_treeview);
e8375af8 2950
1e510b1e
RR
2951 g_signal_connect (m_treeview, "size_allocate",
2952 G_CALLBACK (gtk_dataviewctrl_size_callback), this);
ed4b0fdc 2953
b94db696
RR
2954#ifdef __WXGTK26__
2955 if (!gtk_check_version(2,6,0))
2956 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), TRUE );
2957#endif
2958
daebb44c
RR
2959 if (style & wxDV_MULTIPLE)
2960 {
2961 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
2962 gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE );
2963 }
93763ad5 2964
9861f022
RR
2965 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview), (style & wxDV_NO_HEADER) == 0 );
2966
2967#ifdef __WXGTK210__
2968 if (!gtk_check_version(2,10,0))
2969 {
2970 GtkTreeViewGridLines grid = GTK_TREE_VIEW_GRID_LINES_NONE;
f4322df6
VZ
2971
2972 if ((style & wxDV_HORIZ_RULES) != 0 &&
9861f022
RR
2973 (style & wxDV_VERT_RULES) != 0)
2974 grid = GTK_TREE_VIEW_GRID_LINES_BOTH;
2975 else if (style & wxDV_VERT_RULES)
2976 grid = GTK_TREE_VIEW_GRID_LINES_VERTICAL;
2977 else if (style & wxDV_HORIZ_RULES)
2978 grid = GTK_TREE_VIEW_GRID_LINES_HORIZONTAL;
2979
2980 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview), grid );
2981 }
2982 else
2983#endif
2fa73716 2984 {
9861f022 2985 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview), (style & wxDV_HORIZ_RULES) != 0 );
2fa73716 2986 }
9861f022 2987
1a367564
RR
2988 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget),
2989 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
2990 gtk_widget_show (m_treeview);
93763ad5 2991
239eaa41
RR
2992 m_parent->DoAddChild( this );
2993
b94db696
RR
2994 PostCreation(size);
2995
b086d55f
RR
2996 GtkEnableSelectionEvents();
2997
718fd180 2998 g_signal_connect_after (m_treeview, "row-activated",
f828871d 2999 G_CALLBACK (wxdataview_row_activated_callback), this);
eb7f97f8 3000
718fd180
RR
3001 g_signal_connect (m_treeview, "test-collapse-row",
3002 G_CALLBACK (wxdataview_test_collapse_row_callback), this);
3003
3004 g_signal_connect_after (m_treeview, "row-collapsed",
3005 G_CALLBACK (wxdataview_row_collapsed_callback), this);
3006
3007 g_signal_connect (m_treeview, "test-expand-row",
3008 G_CALLBACK (wxdataview_test_expand_row_callback), this);
3009
3010 g_signal_connect_after (m_treeview, "row-expanded",
3011 G_CALLBACK (wxdataview_row_expanded_callback), this);
3012
239eaa41
RR
3013 return true;
3014}
3015
31fb32e1
RR
3016void wxDataViewCtrl::OnInternalIdle()
3017{
3018 wxWindow::OnInternalIdle();
f4322df6 3019
9861f022 3020 unsigned int cols = GetColumnCount();
31fb32e1
RR
3021 unsigned int i;
3022 for (i = 0; i < cols; i++)
3023 {
3024 wxDataViewColumn *col = GetColumn( i );
3025 col->OnInternalIdle();
3026 }
3027}
3028
e0062c04 3029bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model )
239eaa41
RR
3030{
3031 if (!wxDataViewCtrlBase::AssociateModel( model ))
3032 return false;
3033
55fbde12
RR
3034 GtkWxTreeModel *gtk_model = wxgtk_tree_model_new();
3035 m_internal = new wxDataViewCtrlInternal( this, model, gtk_model );
3036 gtk_model->internal = m_internal;
6e2e590f 3037
55fbde12 3038 m_notifier = new wxGtkDataViewModelNotifier( gtk_model, model, this );
6e2e590f 3039
93763ad5 3040 model->AddNotifier( m_notifier );
1557c77b 3041
55fbde12
RR
3042 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview), GTK_TREE_MODEL(gtk_model) );
3043
3044 // unref in wxDataViewCtrlInternal
3045 // g_object_unref( gtk_model );
93763ad5 3046
239eaa41
RR
3047 return true;
3048}
790b137e 3049
fa28826d
RR
3050bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col )
3051{
3052 if (!wxDataViewCtrlBase::AppendColumn(col))
3053 return false;
93763ad5 3054
91a6c655
RR
3055 m_cols.Append( col );
3056
3057 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview),
3058 GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) );
3059
3060 return true;
3061}
3062
3063unsigned int wxDataViewCtrl::GetColumnCount() const
3064{
3065 return m_cols.GetCount();
3066}
3067
3068wxDataViewColumn* wxDataViewCtrl::GetColumn( unsigned int pos ) const
3069{
3070 GtkTreeViewColumn *gtk_col = gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview), pos );
3071 if (!gtk_col)
3072 return NULL;
3073
3074 wxDataViewColumnList::const_iterator iter;
3075 for (iter = m_cols.begin(); iter != m_cols.end(); iter++)
3076 {
3077 wxDataViewColumn *col = *iter;
3078 if (GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) == gtk_col)
3079 {
3080 return col;
3081 }
3082 }
3083
3084 return NULL;
3085}
3086
3087bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn *column )
3088{
3089 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview),
3090 GTK_TREE_VIEW_COLUMN(column->GetGtkHandle()) );
3091
3092 m_cols.remove( column );
fa28826d 3093
91a6c655 3094 delete column;
fa28826d
RR
3095
3096 return true;
3097}
3098
91a6c655
RR
3099bool wxDataViewCtrl::ClearColumns()
3100{
3101 wxDataViewColumnList::iterator iter;
3102 for (iter = m_cols.begin(); iter != m_cols.end(); iter++)
3103 {
3104 wxDataViewColumn *col = *iter;
3105 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview),
3106 GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) );
3107 }
3108
3109 m_cols.clear();
3110
3111 return true;
3112}
3113
f71d3ba4
RR
3114void wxDataViewCtrl::Expand( const wxDataViewItem & item )
3115{
3116 GtkTreeIter iter;
3117 iter.user_data = item.GetID();
3118 GtkTreePath *path = m_internal->get_path( &iter );
3119 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview), path, false );
3120 gtk_tree_path_free( path );
3121}
3122
3123void wxDataViewCtrl::Collapse( const wxDataViewItem & item )
3124{
3125 GtkTreeIter iter;
3126 iter.user_data = item.GetID();
3127 GtkTreePath *path = m_internal->get_path( &iter );
3128 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview), path );
3129 gtk_tree_path_free( path );
3130}
3131
fbda518c 3132wxDataViewItem wxDataViewCtrl::GetSelection() const
1e08ad10
RR
3133{
3134 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
3135
3136 if (m_windowStyle & wxDV_MULTIPLE)
3137 {
6848478c
RR
3138 // Report the first one
3139 GtkTreeModel *model;
3140 GList *list = gtk_tree_selection_get_selected_rows( selection, &model );
3141
3142 if (list)
3143 {
3144 GtkTreePath *path = (GtkTreePath*) list->data;
3145 GtkTreeIter iter;
3146 m_internal->get_iter( &iter, path );
3147
3148 // delete list
3149 g_list_foreach( list, (GFunc) gtk_tree_path_free, NULL );
3150 g_list_free( list );
3151
3152 return wxDataViewItem( (void*) iter.user_data );
3153 }
1e08ad10
RR
3154 }
3155 else
3156 {
3157 GtkTreeIter iter;
3158 if (gtk_tree_selection_get_selected( selection, NULL, &iter ))
3159 {
9d52aad3 3160 wxDataViewItem item( (void*) iter.user_data );
1e08ad10
RR
3161 return item;
3162 }
3163 }
3164
3165 return wxDataViewItem(0);
3166}
3167
718fd180
RR
3168int wxDataViewCtrl::GetSelections( wxDataViewItemArray & sel ) const
3169{
6848478c
RR
3170 sel.Clear();
3171
3172 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
3173 if (HasFlag(wxDV_MULTIPLE))
3174 {
3175 GtkTreeModel *model;
3176 GList *list = gtk_tree_selection_get_selected_rows( selection, &model );
3177
3178 int count = 0;
3179 while (list)
3180 {
3181 GtkTreePath *path = (GtkTreePath*) list->data;
3182
3183 GtkTreeIter iter;
3184 m_internal->get_iter( &iter, path );
3185
3186 sel.Add( wxDataViewItem( (void*) iter.user_data ) );
3187
3188 list = g_list_next( list );
3189 count++;
3190 }
3191
3192 // delete list
3193 g_list_foreach( list, (GFunc) gtk_tree_path_free, NULL );
3194 g_list_free( list );
3195
3196 return count;
3197 }
3198 else
3199 {
3200 GtkTreeModel *model;
3201 GtkTreeIter iter;
3202 gboolean has_selection = gtk_tree_selection_get_selected( selection, &model, &iter );
3203 if (has_selection)
3204 {
3205 sel.Add( wxDataViewItem( (void*) iter.user_data) );
3206 return 1;
3207 }
3208 }
3209
718fd180
RR
3210 return 0;
3211}
3212
3213void wxDataViewCtrl::SetSelections( const wxDataViewItemArray & sel )
3214{
6848478c
RR
3215 GtkDisableSelectionEvents();
3216
3217 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
3218
3219 gtk_tree_selection_unselect_all( selection );
3220
3221 size_t i;
3222 for (i = 0; i < sel.GetCount(); i++)
3223 {
3224 GtkTreeIter iter;
3225 iter.user_data = (gpointer) sel[i].GetID();
3226 gtk_tree_selection_select_iter( selection, &iter );
3227 }
3228
3229 GtkEnableSelectionEvents();
718fd180
RR
3230}
3231
3232void wxDataViewCtrl::Select( const wxDataViewItem & item )
3233{
6848478c
RR
3234 GtkDisableSelectionEvents();
3235
3236 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
3237
3238 GtkTreeIter iter;
3239 iter.user_data = (gpointer) item.GetID();
3240 gtk_tree_selection_select_iter( selection, &iter );
3241
3242 GtkEnableSelectionEvents();
718fd180
RR
3243}
3244
3245void wxDataViewCtrl::Unselect( const wxDataViewItem & item )
3246{
6848478c
RR
3247 GtkDisableSelectionEvents();
3248
3249 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
3250
3251 GtkTreeIter iter;
3252 iter.user_data = (gpointer) item.GetID();
3253 gtk_tree_selection_unselect_iter( selection, &iter );
3254
3255 GtkEnableSelectionEvents();
718fd180
RR
3256}
3257
3258bool wxDataViewCtrl::IsSelected( const wxDataViewItem & item ) const
3259{
6848478c
RR
3260 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
3261
3262 GtkTreeIter iter;
3263 iter.user_data = (gpointer) item.GetID();
3264
3265 return gtk_tree_selection_iter_is_selected( selection, &iter );
718fd180
RR
3266}
3267
3268void wxDataViewCtrl::SelectAll()
3269{
6848478c
RR
3270 GtkDisableSelectionEvents();
3271
3272 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
3273
3274 gtk_tree_selection_select_all( selection );
3275
3276 GtkEnableSelectionEvents();
718fd180
RR
3277}
3278
3279void wxDataViewCtrl::UnselectAll()
3280{
6848478c
RR
3281 GtkDisableSelectionEvents();
3282
3283 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
3284
3285 gtk_tree_selection_unselect_all( selection );
3286
3287 GtkEnableSelectionEvents();
718fd180
RR
3288}
3289
fbda518c 3290void wxDataViewCtrl::EnsureVisible( const wxDataViewItem & item, const wxDataViewColumn *column )
718fd180 3291{
6154212e
RR
3292 GtkTreeIter iter;
3293 iter.user_data = (gpointer) item.GetID();
3294 GtkTreePath *path = m_internal->get_path( &iter );
3295 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview), path, NULL, false, 0.0, 0.0 );
3296 gtk_tree_path_free( path );
718fd180
RR
3297}
3298
66e09788 3299void wxDataViewCtrl::HitTest( const wxPoint &point,
a87b466d 3300 wxDataViewItem &item, wxDataViewColumn *&column ) const
66e09788
RR
3301{
3302 item = wxDataViewItem(0);
a87b466d 3303 column = NULL;
66e09788
RR
3304}
3305
3306wxRect wxDataViewCtrl::GetItemRect( const wxDataViewItem &item,
fbda518c 3307 const wxDataViewColumn *column ) const
66e09788
RR
3308{
3309 return wxRect();
3310}
3311
3b6280be
RR
3312void wxDataViewCtrl::DoSetExpanderColumn()
3313{
1b27b2bd
RR
3314 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview),
3315 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
3b6280be
RR
3316}
3317
3318void wxDataViewCtrl::DoSetIndent()
3319{
3320}
3321
b086d55f
RR
3322void wxDataViewCtrl::GtkDisableSelectionEvents()
3323{
3324 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
6848478c
RR
3325 g_signal_handlers_disconnect_by_func( selection,
3326 (gpointer) (wxdataview_selection_changed_callback), this);
b086d55f
RR
3327}
3328
3329void wxDataViewCtrl::GtkEnableSelectionEvents()
3330{
3331 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
6848478c
RR
3332 g_signal_connect_after (selection, "changed",
3333 G_CALLBACK (wxdataview_selection_changed_callback), this);
b086d55f
RR
3334}
3335
b94db696
RR
3336// static
3337wxVisualAttributes
3338wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
3339{
3340 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new);
3341}
3342
6ff7eee7 3343
93763ad5 3344#endif
4ed7af08 3345 // !wxUSE_GENERICDATAVIEWCTRL
790b137e 3346
93763ad5 3347#endif
4ed7af08 3348 // wxUSE_DATAVIEWCTRL