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