]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dataview.cpp
fixed wxXmlResource::Load's detection of filenames to be done as early as possible
[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"
c3c62822
PC
23 #include "wx/settings.h"
24 #include "wx/crt.h"
e4db172a
WS
25#endif
26
790b137e 27#include "wx/stockitem.h"
7ea3a0de
RR
28#include "wx/calctrl.h"
29#include "wx/popupwin.h"
69892729 30#include "wx/listimpl.cpp"
790b137e
RR
31
32#include "wx/gtk/private.h"
888dde65
RR
33#include "wx/gtk/dc.h"
34#include "wx/gtk/dcclient.h"
4d496ecb 35
790b137e 36//-----------------------------------------------------------------------------
790b137e
RR
37//-----------------------------------------------------------------------------
38
8c2654ce 39static wxDataViewCtrlInternal *gs_internal = NULL;
3b6280be
RR
40
41class wxGtkTreeModelNode;
ef427989 42
0be79c8a
RR
43extern "C" {
44typedef struct _GtkWxTreeModel GtkWxTreeModel;
45}
46
af110130
RR
47//-----------------------------------------------------------------------------
48// wxDataViewCtrlInternal
49//-----------------------------------------------------------------------------
50
69892729 51WX_DECLARE_LIST(wxDataViewItem, ItemList);
a76c2f37 52WX_DEFINE_LIST(ItemList)
69892729 53
8c2654ce 54class WXDLLIMPEXP_ADV wxDataViewCtrlInternal
af110130
RR
55{
56public:
7dea20f6 57 wxDataViewCtrlInternal( wxDataViewCtrl *owner, wxDataViewModel *wx_model, GtkWxTreeModel *gtk_model );
af110130 58 ~wxDataViewCtrlInternal();
b9db5f30 59
f6f0ef85 60 // model iface
2056dede 61 GtkTreeModelFlags get_flags();
af110130
RR
62 gboolean get_iter( GtkTreeIter *iter, GtkTreePath *path );
63 GtkTreePath *get_path( GtkTreeIter *iter);
af110130
RR
64 gboolean iter_next( GtkTreeIter *iter );
65 gboolean iter_children( GtkTreeIter *iter, GtkTreeIter *parent);
66 gboolean iter_has_child( GtkTreeIter *iter );
67 gint iter_n_children( GtkTreeIter *iter );
68 gboolean iter_nth_child( GtkTreeIter *iter, GtkTreeIter *parent, gint n );
69 gboolean iter_parent( GtkTreeIter *iter, GtkTreeIter *child );
b9db5f30 70
f6f0ef85 71 // dnd iface
8c2654ce 72
15cac64f 73 bool EnableDragSource( const wxDataFormat &format );
e4de825e 74 bool EnableDropTarget( const wxDataFormat &format );
8c2654ce 75
f6f0ef85
RR
76 gboolean row_draggable( GtkTreeDragSource *drag_source, GtkTreePath *path );
77 gboolean drag_data_delete( GtkTreeDragSource *drag_source, GtkTreePath* path );
7857346a 78 gboolean drag_data_get( GtkTreeDragSource *drag_source, GtkTreePath *path,
f6f0ef85 79 GtkSelectionData *selection_data );
7857346a 80 gboolean drag_data_received( GtkTreeDragDest *drag_dest, GtkTreePath *dest,
f6f0ef85 81 GtkSelectionData *selection_data );
7857346a 82 gboolean row_drop_possible( GtkTreeDragDest *drag_dest, GtkTreePath *dest_path,
f6f0ef85
RR
83 GtkSelectionData *selection_data );
84
85 // notifactions from wxDataViewModel
af110130 86 bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
469d3e9b 87 bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item );
d8331a01
RR
88 bool ItemChanged( const wxDataViewItem &item );
89 bool ValueChanged( const wxDataViewItem &item, unsigned int col );
90 bool Cleared();
af110130 91 void Resort();
b9db5f30 92
f6f0ef85 93 // sorting interface
b8b7b087
RR
94 void SetSortOrder( GtkSortType sort_order ) { m_sort_order = sort_order; }
95 GtkSortType GetSortOrder() { return m_sort_order; }
7ee7191c 96
40196b1e
RR
97 void SetSortColumn( int column ) { m_sort_column = column; }
98 int GetSortColumn() { return m_sort_column; }
b9db5f30 99
d32332aa
RR
100 void SetDataViewSortColumn( wxDataViewColumn *column ) { m_dataview_sort_column = column; }
101 wxDataViewColumn *GetDataViewSortColumn() { return m_dataview_sort_column; }
b9db5f30 102
40196b1e 103 bool IsSorted() { return (m_sort_column >= 0); }
b9db5f30 104
f6f0ef85
RR
105 // accessors
106 wxDataViewModel* GetDataViewModel() { return m_wx_model; }
107 wxDataViewCtrl* GetOwner() { return m_owner; }
108 GtkWxTreeModel* GetGtkModel() { return m_gtk_model; }
b9db5f30 109
af110130
RR
110protected:
111 void InitTree();
112 wxGtkTreeModelNode *FindNode( const wxDataViewItem &item );
113 wxGtkTreeModelNode *FindNode( GtkTreeIter *iter );
114 wxGtkTreeModelNode *FindParentNode( const wxDataViewItem &item );
115 wxGtkTreeModelNode *FindParentNode( GtkTreeIter *iter );
116 void BuildBranch( wxGtkTreeModelNode *branch );
b9db5f30 117
af110130
RR
118private:
119 wxGtkTreeModelNode *m_root;
120 wxDataViewModel *m_wx_model;
121 GtkWxTreeModel *m_gtk_model;
122 wxDataViewCtrl *m_owner;
b8b7b087 123 GtkSortType m_sort_order;
d32332aa 124 wxDataViewColumn *m_dataview_sort_column;
40196b1e 125 int m_sort_column;
8c2654ce 126
15cac64f
RR
127 GtkTargetEntry m_dragSourceTargetEntry;
128 wxCharBuffer m_dragSourceTargetEntryTarget;
591cc82d 129 wxDataObject *m_dragDataObject;
8c2654ce 130
e4de825e
RR
131 GtkTargetEntry m_dropTargetTargetEntry;
132 wxCharBuffer m_dropTargetTargetEntryTarget;
591cc82d 133 wxDataObject *m_dropDataObject;
af110130 134};
ef427989 135
af110130
RR
136
137//-----------------------------------------------------------------------------
138// wxGtkTreeModelNode
139//-----------------------------------------------------------------------------
140
8c2654ce 141static
40196b1e
RR
142int LINKAGEMODE wxGtkTreeModelChildCmp( void** id1, void** id2 )
143{
8c2654ce
PC
144 int ret = gs_internal->GetDataViewModel()->Compare( *id1, *id2,
145 gs_internal->GetSortColumn(), (gs_internal->GetSortOrder() == GTK_SORT_ASCENDING) );
b9db5f30 146
40196b1e
RR
147 return ret;
148}
af110130
RR
149
150WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode*, wxGtkTreeModelNodes );
40196b1e 151WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren );
3b6280be
RR
152
153class wxGtkTreeModelNode
154{
155public:
ef427989 156 wxGtkTreeModelNode( wxGtkTreeModelNode* parent, const wxDataViewItem &item,
0be79c8a 157 wxDataViewCtrlInternal *internal )
b9db5f30
VS
158 {
159 m_parent = parent;
d5025dc0 160 m_item = item;
0be79c8a 161 m_internal = internal;
3b6280be 162 }
b9db5f30 163
3b6280be 164 ~wxGtkTreeModelNode()
b9db5f30 165 {
023eecb7 166 size_t count = m_nodes.GetCount();
3b6280be
RR
167 size_t i;
168 for (i = 0; i < count; i++)
169 {
af110130 170 wxGtkTreeModelNode *child = m_nodes.Item( i );
3b6280be
RR
171 delete child;
172 }
173 }
174
b9db5f30
VS
175 unsigned int AddNode( wxGtkTreeModelNode* child )
176 {
af110130 177 m_nodes.Add( child );
b9db5f30 178
40196b1e 179 void *id = child->GetItem().GetID();
b9db5f30 180
40196b1e 181 m_children.Add( id );
0bd26819
RR
182
183 if (m_internal->IsSorted() || m_internal->GetDataViewModel()->HasDefaultCompare())
40196b1e 184 {
8c2654ce 185 gs_internal = m_internal;
40196b1e
RR
186 m_children.Sort( &wxGtkTreeModelChildCmp );
187 return m_children.Index( id );
188 }
0bd26819 189
40196b1e 190 return m_children.GetCount()-1;
af110130 191 }
b9db5f30 192
af110130
RR
193 unsigned int AddLeave( void* id )
194 {
40196b1e 195 m_children.Add( id );
0bd26819
RR
196
197 if (m_internal->IsSorted() || m_internal->GetDataViewModel()->HasDefaultCompare())
40196b1e 198 {
8c2654ce 199 gs_internal = m_internal;
40196b1e
RR
200 m_children.Sort( &wxGtkTreeModelChildCmp );
201 return m_children.Index( id );
202 }
0bd26819 203
40196b1e 204 return m_children.GetCount()-1;
af110130 205 }
b9db5f30 206
af110130
RR
207 void DeleteChild( void* id )
208 {
40196b1e 209 m_children.Remove( id );
b9db5f30 210
40196b1e
RR
211 unsigned int count = m_nodes.GetCount();
212 unsigned int pos;
af110130 213 for (pos = 0; pos < count; pos++)
b9db5f30 214 {
af110130
RR
215 wxGtkTreeModelNode *node = m_nodes.Item( pos );
216 if (node->GetItem().GetID() == id)
217 {
218 m_nodes.RemoveAt( pos );
219 delete node;
220 break;
221 }
222 }
b9db5f30 223
af110130 224 }
b9db5f30
VS
225
226 wxGtkTreeModelNode* GetParent()
3b6280be 227 { return m_parent; }
b9db5f30 228 wxGtkTreeModelNodes &GetNodes()
af110130 229 { return m_nodes; }
b9db5f30 230 wxGtkTreeModelChildren &GetChildren()
40196b1e 231 { return m_children; }
b9db5f30 232
40196b1e 233 unsigned int GetChildCount() { return m_children.GetCount(); }
af110130 234 unsigned int GetNodesCount() { return m_nodes.GetCount(); }
3b6280be
RR
235
236 wxDataViewItem &GetItem() { return m_item; }
0be79c8a 237 wxDataViewCtrlInternal *GetInternal() { return m_internal; }
b9db5f30 238
4508fcd2 239 void Resort();
b9db5f30 240
3b6280be 241private:
0be79c8a 242 wxGtkTreeModelNode *m_parent;
af110130 243 wxGtkTreeModelNodes m_nodes;
40196b1e 244 wxGtkTreeModelChildren m_children;
b9db5f30 245 wxDataViewItem m_item;
0be79c8a 246 wxDataViewCtrlInternal *m_internal;
3b6280be
RR
247};
248
ef427989 249
790b137e
RR
250//-----------------------------------------------------------------------------
251// data
252//-----------------------------------------------------------------------------
253
254extern bool g_blockEventsOnDrag;
255
256//-----------------------------------------------------------------------------
e0062c04 257// define new GTK+ class wxGtkTreeModel
790b137e
RR
258//-----------------------------------------------------------------------------
259
260extern "C" {
261
e0062c04
RR
262#define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ())
263#define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel))
264#define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
265#define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL))
266#define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL))
267#define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
790b137e 268
e0062c04 269GType gtk_wx_tree_model_get_type (void);
790b137e 270
e0062c04 271typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass;
790b137e 272
e0062c04 273struct _GtkWxTreeModel
790b137e
RR
274{
275 GObject parent;
276
277 /*< private >*/
278 gint stamp;
55fbde12 279 wxDataViewCtrlInternal *internal;
790b137e
RR
280};
281
e0062c04 282struct _GtkWxTreeModelClass
790b137e 283{
e152afc3 284 GObjectClass list_parent_class;
790b137e
RR
285};
286
e0062c04 287static GtkWxTreeModel *wxgtk_tree_model_new (void);
773cca48
RR
288static void wxgtk_tree_model_init (GtkWxTreeModel *tree_model);
289static void wxgtk_tree_model_class_init (GtkWxTreeModelClass *klass);
85136e3b
RR
290
291static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface *iface);
292static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface *iface);
293static void wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface *iface);
294static void wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface *iface);
295
e0062c04
RR
296static void wxgtk_tree_model_finalize (GObject *object);
297static GtkTreeModelFlags wxgtk_tree_model_get_flags (GtkTreeModel *tree_model);
298static gint wxgtk_tree_model_get_n_columns (GtkTreeModel *tree_model);
299static GType wxgtk_tree_model_get_column_type (GtkTreeModel *tree_model,
93763ad5 300 gint index);
e0062c04 301static gboolean wxgtk_tree_model_get_iter (GtkTreeModel *tree_model,
93763ad5
WS
302 GtkTreeIter *iter,
303 GtkTreePath *path);
e0062c04 304static GtkTreePath *wxgtk_tree_model_get_path (GtkTreeModel *tree_model,
93763ad5 305 GtkTreeIter *iter);
e0062c04 306static void wxgtk_tree_model_get_value (GtkTreeModel *tree_model,
93763ad5
WS
307 GtkTreeIter *iter,
308 gint column,
309 GValue *value);
e0062c04 310static gboolean wxgtk_tree_model_iter_next (GtkTreeModel *tree_model,
93763ad5 311 GtkTreeIter *iter);
e0062c04 312static gboolean wxgtk_tree_model_iter_children (GtkTreeModel *tree_model,
93763ad5
WS
313 GtkTreeIter *iter,
314 GtkTreeIter *parent);
e0062c04 315static gboolean wxgtk_tree_model_iter_has_child (GtkTreeModel *tree_model,
93763ad5 316 GtkTreeIter *iter);
e0062c04 317static gint wxgtk_tree_model_iter_n_children (GtkTreeModel *tree_model,
93763ad5 318 GtkTreeIter *iter);
e0062c04 319static gboolean wxgtk_tree_model_iter_nth_child (GtkTreeModel *tree_model,
93763ad5
WS
320 GtkTreeIter *iter,
321 GtkTreeIter *parent,
322 gint n);
e0062c04 323static gboolean wxgtk_tree_model_iter_parent (GtkTreeModel *tree_model,
93763ad5
WS
324 GtkTreeIter *iter,
325 GtkTreeIter *child);
790b137e 326
773cca48
RR
327/* sortable */
328static gboolean wxgtk_tree_model_get_sort_column_id (GtkTreeSortable *sortable,
85136e3b
RR
329 gint *sort_column_id,
330 GtkSortType *order);
773cca48 331static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable *sortable,
85136e3b
RR
332 gint sort_column_id,
333 GtkSortType order);
773cca48 334static void wxgtk_tree_model_set_sort_func (GtkTreeSortable *sortable,
85136e3b
RR
335 gint sort_column_id,
336 GtkTreeIterCompareFunc func,
337 gpointer data,
338 GtkDestroyNotify destroy);
773cca48 339static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable *sortable,
85136e3b
RR
340 GtkTreeIterCompareFunc func,
341 gpointer data,
342 GtkDestroyNotify destroy);
773cca48
RR
343static gboolean wxgtk_tree_model_has_default_sort_func (GtkTreeSortable *sortable);
344
85136e3b
RR
345/* drag'n'drop */
346static gboolean wxgtk_tree_model_row_draggable (GtkTreeDragSource *drag_source,
347 GtkTreePath *path);
348static gboolean wxgtk_tree_model_drag_data_delete (GtkTreeDragSource *drag_source,
349 GtkTreePath *path);
350static gboolean wxgtk_tree_model_drag_data_get (GtkTreeDragSource *drag_source,
351 GtkTreePath *path,
352 GtkSelectionData *selection_data);
353static gboolean wxgtk_tree_model_drag_data_received (GtkTreeDragDest *drag_dest,
354 GtkTreePath *dest,
355 GtkSelectionData *selection_data);
356static gboolean wxgtk_tree_model_row_drop_possible (GtkTreeDragDest *drag_dest,
357 GtkTreePath *dest_path,
358 GtkSelectionData *selection_data);
773cca48
RR
359
360
e152afc3 361static GObjectClass *list_parent_class = NULL;
790b137e
RR
362
363GType
e0062c04 364gtk_wx_tree_model_get_type (void)
790b137e 365{
e0062c04 366 static GType tree_model_type = 0;
790b137e 367
e0062c04 368 if (!tree_model_type)
790b137e 369 {
e0062c04 370 const GTypeInfo tree_model_info =
93763ad5 371 {
e0062c04 372 sizeof (GtkWxTreeModelClass),
93763ad5
WS
373 NULL, /* base_init */
374 NULL, /* base_finalize */
e0062c04 375 (GClassInitFunc) wxgtk_tree_model_class_init,
93763ad5
WS
376 NULL, /* class_finalize */
377 NULL, /* class_data */
e0062c04 378 sizeof (GtkWxTreeModel),
93763ad5 379 0,
e0062c04 380 (GInstanceInitFunc) wxgtk_tree_model_init,
93763ad5 381 };
790b137e 382
773cca48
RR
383 static const GInterfaceInfo tree_model_iface_info =
384 {
385 (GInterfaceInitFunc) wxgtk_tree_model_tree_model_init,
386 NULL,
387 NULL
388 };
389
390 static const GInterfaceInfo sortable_iface_info =
391 {
392 (GInterfaceInitFunc) wxgtk_tree_model_sortable_init,
393 NULL,
394 NULL
395 };
790b137e 396
85136e3b
RR
397 static const GInterfaceInfo drag_source_iface_info =
398 {
399 (GInterfaceInitFunc) wxgtk_tree_model_drag_source_init,
400 NULL,
401 NULL
402 };
403
404 static const GInterfaceInfo drag_dest_iface_info =
405 {
406 (GInterfaceInitFunc) wxgtk_tree_model_drag_dest_init,
407 NULL,
408 NULL
409 };
410
773cca48 411 tree_model_type = g_type_register_static (G_TYPE_OBJECT, "GtkWxTreeModel",
e0062c04 412 &tree_model_info, (GTypeFlags)0 );
790b137e 413
773cca48
RR
414 g_type_add_interface_static (tree_model_type,
415 GTK_TYPE_TREE_MODEL,
416 &tree_model_iface_info);
417 g_type_add_interface_static (tree_model_type,
418 GTK_TYPE_TREE_SORTABLE,
419 &sortable_iface_info);
85136e3b
RR
420 g_type_add_interface_static (tree_model_type,
421 GTK_TYPE_TREE_DRAG_DEST,
422 &drag_dest_iface_info);
423 g_type_add_interface_static (tree_model_type,
424 GTK_TYPE_TREE_DRAG_SOURCE,
425 &drag_source_iface_info);
790b137e
RR
426 }
427
773cca48 428 return tree_model_type;
790b137e
RR
429}
430
e0062c04
RR
431static GtkWxTreeModel *
432wxgtk_tree_model_new(void)
1557c77b 433{
e0062c04 434 GtkWxTreeModel *retval = (GtkWxTreeModel *) g_object_new (GTK_TYPE_WX_TREE_MODEL, NULL);
e152afc3 435 return retval;
1557c77b
RR
436}
437
790b137e 438static void
e0062c04 439wxgtk_tree_model_class_init (GtkWxTreeModelClass *klass)
790b137e 440{
e152afc3
RR
441 list_parent_class = (GObjectClass*) g_type_class_peek_parent (klass);
442 GObjectClass *object_class = (GObjectClass*) klass;
e0062c04 443 object_class->finalize = wxgtk_tree_model_finalize;
790b137e
RR
444}
445
446static void
e0062c04
RR
447wxgtk_tree_model_tree_model_init (GtkTreeModelIface *iface)
448{
449 iface->get_flags = wxgtk_tree_model_get_flags;
450 iface->get_n_columns = wxgtk_tree_model_get_n_columns;
451 iface->get_column_type = wxgtk_tree_model_get_column_type;
452 iface->get_iter = wxgtk_tree_model_get_iter;
453 iface->get_path = wxgtk_tree_model_get_path;
454 iface->get_value = wxgtk_tree_model_get_value;
455 iface->iter_next = wxgtk_tree_model_iter_next;
456 iface->iter_children = wxgtk_tree_model_iter_children;
457 iface->iter_has_child = wxgtk_tree_model_iter_has_child;
458 iface->iter_n_children = wxgtk_tree_model_iter_n_children;
459 iface->iter_nth_child = wxgtk_tree_model_iter_nth_child;
460 iface->iter_parent = wxgtk_tree_model_iter_parent;
790b137e
RR
461}
462
773cca48
RR
463static void
464wxgtk_tree_model_sortable_init (GtkTreeSortableIface *iface)
465{
94b1f7bc
RR
466 iface->get_sort_column_id = wxgtk_tree_model_get_sort_column_id;
467 iface->set_sort_column_id = wxgtk_tree_model_set_sort_column_id;
468 iface->set_sort_func = wxgtk_tree_model_set_sort_func;
469 iface->set_default_sort_func = wxgtk_tree_model_set_default_sort_func;
470 iface->has_default_sort_func = wxgtk_tree_model_has_default_sort_func;
773cca48
RR
471}
472
7857346a 473static void
85136e3b
RR
474wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface *iface)
475{
476 iface->row_draggable = wxgtk_tree_model_row_draggable;
477 iface->drag_data_delete = wxgtk_tree_model_drag_data_delete;
478 iface->drag_data_get = wxgtk_tree_model_drag_data_get;
479}
480
7857346a 481static void
85136e3b
RR
482wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface *iface)
483{
484 iface->drag_data_received = wxgtk_tree_model_drag_data_received;
485 iface->row_drop_possible = wxgtk_tree_model_row_drop_possible;
486}
487
790b137e 488static void
e0062c04 489wxgtk_tree_model_init (GtkWxTreeModel *tree_model)
790b137e 490{
55fbde12 491 tree_model->internal = NULL;
e0062c04 492 tree_model->stamp = g_random_int();
790b137e
RR
493}
494
495static void
e0062c04 496wxgtk_tree_model_finalize (GObject *object)
790b137e 497{
790b137e 498 /* must chain up */
e152afc3 499 (* list_parent_class->finalize) (object);
790b137e 500}
93763ad5 501
790b137e
RR
502} // extern "C"
503
504//-----------------------------------------------------------------------------
e0062c04
RR
505// implement callbacks from wxGtkTreeModel class by letting
506// them call the methods of wxWidgets' wxDataViewModel
790b137e
RR
507//-----------------------------------------------------------------------------
508
509static GtkTreeModelFlags
e0062c04 510wxgtk_tree_model_get_flags (GtkTreeModel *tree_model)
790b137e 511{
2056dede
RR
512 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
513 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), (GtkTreeModelFlags)0 );
790b137e 514
2056dede 515 return wxtree_model->internal->get_flags();
790b137e
RR
516}
517
518static gint
e0062c04 519wxgtk_tree_model_get_n_columns (GtkTreeModel *tree_model)
790b137e 520{
e0062c04
RR
521 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
522 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), 0);
790b137e 523
55fbde12 524 return wxtree_model->internal->GetDataViewModel()->GetColumnCount();
790b137e
RR
525}
526
527static GType
e0062c04 528wxgtk_tree_model_get_column_type (GtkTreeModel *tree_model,
93763ad5 529 gint index)
790b137e 530{
e0062c04
RR
531 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
532 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), G_TYPE_INVALID);
790b137e 533
1557c77b 534 GType gtype = G_TYPE_INVALID;
93763ad5 535
55fbde12 536 wxString wxtype = wxtree_model->internal->GetDataViewModel()->GetColumnType( (unsigned int) index );
93763ad5 537
15cac64f
RR
538 wxPrintf( "get_column_type %s\n", wxtype );
539
1557c77b
RR
540 if (wxtype == wxT("string"))
541 gtype = G_TYPE_STRING;
72a3ac9b
VZ
542 else
543 {
e94d0c1e
RR
544 gtype = G_TYPE_STRING;
545 // wxFAIL_MSG( _T("non-string columns not supported yet") );
72a3ac9b 546 }
790b137e
RR
547
548 return gtype;
549}
550
551static gboolean
e0062c04 552wxgtk_tree_model_get_iter (GtkTreeModel *tree_model,
93763ad5
WS
553 GtkTreeIter *iter,
554 GtkTreePath *path)
790b137e 555{
e0062c04
RR
556 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
557 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
790b137e
RR
558 g_return_val_if_fail (gtk_tree_path_get_depth (path) > 0, FALSE);
559
55fbde12 560 return wxtree_model->internal->get_iter( iter, path );
790b137e
RR
561}
562
563static GtkTreePath *
e0062c04 564wxgtk_tree_model_get_path (GtkTreeModel *tree_model,
93763ad5 565 GtkTreeIter *iter)
790b137e 566{
e0062c04
RR
567 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
568 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), NULL);
569 g_return_val_if_fail (iter->stamp == GTK_WX_TREE_MODEL (wxtree_model)->stamp, NULL);
93763ad5 570
55fbde12 571 return wxtree_model->internal->get_path( iter );
790b137e
RR
572}
573
574static void
e0062c04 575wxgtk_tree_model_get_value (GtkTreeModel *tree_model,
93763ad5
WS
576 GtkTreeIter *iter,
577 gint column,
578 GValue *value)
790b137e 579{
e0062c04
RR
580 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
581 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model) );
239eaa41 582
55fbde12 583 wxDataViewModel *model = wxtree_model->internal->GetDataViewModel();
9861f022 584 wxString mtype = model->GetColumnType( (unsigned int) column );
1557c77b
RR
585 if (mtype == wxT("string"))
586 {
3f3af7e7 587 wxVariant variant;
1557c77b 588 g_value_init( value, G_TYPE_STRING );
9d52aad3 589 wxDataViewItem item( (void*) iter->user_data );
e0062c04 590 model->GetValue( variant, item, (unsigned int) column );
72a3ac9b 591
e0062c04 592 g_value_set_string( value, variant.GetString().utf8_str() );
1557c77b
RR
593 }
594 else
595 {
72a3ac9b 596 wxFAIL_MSG( _T("non-string columns not supported yet") );
1557c77b 597 }
790b137e
RR
598}
599
600static gboolean
e0062c04 601wxgtk_tree_model_iter_next (GtkTreeModel *tree_model,
93763ad5 602 GtkTreeIter *iter)
790b137e 603{
e0062c04 604 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
7857346a 605
33ba5a05
RR
606 if (wxtree_model->stamp != iter->stamp)
607 wxPrintf( "crash\n" );
608
e0062c04 609 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
e0062c04 610 g_return_val_if_fail (wxtree_model->stamp == iter->stamp, FALSE);
7857346a 611
55fbde12 612 return wxtree_model->internal->iter_next( iter );
790b137e
RR
613}
614
615static gboolean
e0062c04 616wxgtk_tree_model_iter_children (GtkTreeModel *tree_model,
93763ad5
WS
617 GtkTreeIter *iter,
618 GtkTreeIter *parent)
790b137e 619{
e0062c04
RR
620 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
621 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
e0062c04 622 g_return_val_if_fail (wxtree_model->stamp == parent->stamp, FALSE);
790b137e 623
55fbde12 624 return wxtree_model->internal->iter_children( iter, parent );
790b137e
RR
625}
626
627static gboolean
e0062c04 628wxgtk_tree_model_iter_has_child (GtkTreeModel *tree_model,
93763ad5 629 GtkTreeIter *iter)
790b137e 630{
e0062c04
RR
631 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
632 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
e0062c04 633 g_return_val_if_fail (wxtree_model->stamp == iter->stamp, FALSE);
d5025dc0 634
55fbde12 635 return wxtree_model->internal->iter_has_child( iter );
790b137e
RR
636}
637
638static gint
e0062c04 639wxgtk_tree_model_iter_n_children (GtkTreeModel *tree_model,
93763ad5 640 GtkTreeIter *iter)
790b137e 641{
e0062c04
RR
642 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
643 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
11f20f99
RR
644
645 if (iter != NULL)
646 g_return_val_if_fail (wxtree_model->stamp == iter->stamp, 0);
647
55fbde12 648 return wxtree_model->internal->iter_n_children( iter );
790b137e
RR
649}
650
651static gboolean
e0062c04 652wxgtk_tree_model_iter_nth_child (GtkTreeModel *tree_model,
93763ad5
WS
653 GtkTreeIter *iter,
654 GtkTreeIter *parent,
655 gint n)
790b137e 656{
e0062c04
RR
657 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
658 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
659
55fbde12 660 return wxtree_model->internal->iter_nth_child( iter, parent, n );
790b137e
RR
661}
662
663static gboolean
e0062c04 664wxgtk_tree_model_iter_parent (GtkTreeModel *tree_model,
93763ad5
WS
665 GtkTreeIter *iter,
666 GtkTreeIter *child)
790b137e 667{
e0062c04
RR
668 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
669 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
e0062c04 670 g_return_val_if_fail (wxtree_model->stamp == child->stamp, FALSE);
b9db5f30 671
55fbde12 672 return wxtree_model->internal->iter_parent( iter, child );
790b137e
RR
673}
674
85136e3b 675/* drag'n'drop iface */
7857346a 676static gboolean
85136e3b
RR
677wxgtk_tree_model_row_draggable (GtkTreeDragSource *drag_source,
678 GtkTreePath *path)
679{
f6f0ef85
RR
680 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) drag_source;
681 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
7857346a 682
f6f0ef85 683 return wxtree_model->internal->row_draggable( drag_source, path );
85136e3b
RR
684}
685
7857346a 686static gboolean
85136e3b
RR
687wxgtk_tree_model_drag_data_delete (GtkTreeDragSource *drag_source,
688 GtkTreePath *path)
689{
f6f0ef85
RR
690 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) drag_source;
691 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
7857346a 692
f6f0ef85 693 return wxtree_model->internal->drag_data_delete( drag_source, path );
85136e3b
RR
694}
695
7857346a 696static gboolean
85136e3b
RR
697wxgtk_tree_model_drag_data_get (GtkTreeDragSource *drag_source,
698 GtkTreePath *path,
699 GtkSelectionData *selection_data)
700{
f6f0ef85
RR
701 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) drag_source;
702 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
7857346a 703
f6f0ef85 704#if 0
85136e3b 705 wxPrintf( "drag_get_data\n");
7857346a 706
f6f0ef85
RR
707 wxGtkString atom_selection(gdk_atom_name(selection_data->selection));
708 wxPrintf( "selection %s\n", wxString::FromAscii(atom_selection) );
7857346a 709
f6f0ef85
RR
710 wxGtkString atom_target(gdk_atom_name(selection_data->target));
711 wxPrintf( "target %s\n", wxString::FromAscii(atom_target) );
7857346a 712
f6f0ef85
RR
713 wxGtkString atom_type(gdk_atom_name(selection_data->type));
714 wxPrintf( "type %s\n", wxString::FromAscii(atom_type) );
715
716 wxPrintf( "format %d\n", selection_data->format );
717#endif
7857346a 718
f6f0ef85 719 return wxtree_model->internal->drag_data_get( drag_source, path, selection_data );
85136e3b
RR
720}
721
7857346a 722static gboolean
85136e3b
RR
723wxgtk_tree_model_drag_data_received (GtkTreeDragDest *drag_dest,
724 GtkTreePath *dest,
725 GtkSelectionData *selection_data)
726{
f6f0ef85
RR
727 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) drag_dest;
728 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
7857346a 729
f6f0ef85 730 return wxtree_model->internal->drag_data_received( drag_dest, dest, selection_data );
85136e3b
RR
731}
732
7857346a 733static gboolean
85136e3b
RR
734wxgtk_tree_model_row_drop_possible (GtkTreeDragDest *drag_dest,
735 GtkTreePath *dest_path,
736 GtkSelectionData *selection_data)
737{
f6f0ef85
RR
738 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) drag_dest;
739 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
7857346a 740
f6f0ef85 741 return wxtree_model->internal->row_drop_possible( drag_dest, dest_path, selection_data );
85136e3b
RR
742}
743
744/* sortable iface */
7857346a 745static gboolean
85136e3b
RR
746wxgtk_tree_model_get_sort_column_id (GtkTreeSortable *sortable,
747 gint *sort_column_id,
748 GtkSortType *order)
773cca48 749{
f6f0ef85 750 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) sortable;
94b1f7bc
RR
751
752 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable), FALSE);
753
f6f0ef85 754 if (!wxtree_model->internal->IsSorted())
40196b1e
RR
755 {
756 if (sort_column_id)
757 *sort_column_id = -1;
b9db5f30 758
40196b1e
RR
759 return TRUE;
760 }
761
762
94b1f7bc 763 if (sort_column_id)
f6f0ef85 764 *sort_column_id = wxtree_model->internal->GetSortColumn();
b9db5f30 765
94b1f7bc 766 if (order)
f6f0ef85 767 *order = wxtree_model->internal->GetSortOrder();
b9db5f30 768
94b1f7bc 769 return TRUE;
773cca48
RR
770}
771
d32332aa
RR
772wxDataViewColumn *gs_lastLeftClickHeader = NULL;
773
7857346a 774static void
85136e3b
RR
775wxgtk_tree_model_set_sort_column_id (GtkTreeSortable *sortable,
776 gint sort_column_id,
777 GtkSortType order)
773cca48 778{
94b1f7bc 779 GtkWxTreeModel *tree_model = (GtkWxTreeModel *) sortable;
94b1f7bc
RR
780 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) );
781
d32332aa 782 tree_model->internal->SetDataViewSortColumn( gs_lastLeftClickHeader );
b9db5f30 783
d32332aa
RR
784 if ((sort_column_id != (gint) tree_model->internal->GetSortColumn()) ||
785 (order != tree_model->internal->GetSortOrder()))
786 {
787 tree_model->internal->SetSortColumn( sort_column_id );
788 tree_model->internal->SetSortOrder( order );
b9db5f30 789
d32332aa 790 gtk_tree_sortable_sort_column_changed (sortable);
b9db5f30 791
d32332aa
RR
792 tree_model->internal->GetDataViewModel()->Resort();
793 }
a84c5b6f 794
d32332aa
RR
795 if (gs_lastLeftClickHeader)
796 {
b9db5f30 797 wxDataViewCtrl *dv = tree_model->internal->GetOwner();
d32332aa
RR
798 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, dv->GetId() );
799 event.SetDataViewColumn( gs_lastLeftClickHeader );
800 event.SetModel( dv->GetModel() );
937013e0 801 dv->HandleWindowEvent( event );
d32332aa 802 }
b9db5f30 803
d32332aa 804 gs_lastLeftClickHeader = NULL;
773cca48
RR
805}
806
7857346a 807static void
85136e3b
RR
808wxgtk_tree_model_set_sort_func (GtkTreeSortable *sortable,
809 gint WXUNUSED(sort_column_id),
810 GtkTreeIterCompareFunc func,
811 gpointer WXUNUSED(data),
812 GtkDestroyNotify WXUNUSED(destroy) )
773cca48 813{
94b1f7bc
RR
814 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) );
815 g_return_if_fail (func != NULL);
773cca48
RR
816}
817
c5c5395b
RR
818void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable *sortable,
819 GtkTreeIterCompareFunc func,
820 gpointer WXUNUSED(data),
821 GtkDestroyNotify WXUNUSED(destroy) )
773cca48 822{
94b1f7bc 823 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) );
94b1f7bc
RR
824 g_return_if_fail (func != NULL);
825
94b1f7bc 826 wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
773cca48
RR
827}
828
829gboolean wxgtk_tree_model_has_default_sort_func (GtkTreeSortable *sortable)
830{
c5c5395b 831 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable), FALSE );
7857346a 832
773cca48
RR
833 return FALSE;
834}
835
e152afc3 836//-----------------------------------------------------------------------------
baa9ebc4 837// define new GTK+ class wxGtkRendererRenderer
e152afc3
RR
838//-----------------------------------------------------------------------------
839
840extern "C" {
841
842#define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
843#define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
844#define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
845#define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
846#define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
847#define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
848
849GType gtk_wx_cell_renderer_get_type (void);
850
851typedef struct _GtkWxCellRenderer GtkWxCellRenderer;
852typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass;
853
854struct _GtkWxCellRenderer
855{
856 GtkCellRenderer parent;
857
858 /*< private >*/
baa9ebc4 859 wxDataViewCustomRenderer *cell;
4d496ecb 860 guint32 last_click;
e152afc3
RR
861};
862
863struct _GtkWxCellRendererClass
864{
865 GtkCellRendererClass cell_parent_class;
e152afc3
RR
866};
867
868
869static GtkCellRenderer *gtk_wx_cell_renderer_new (void);
553f7d8f
RR
870static void gtk_wx_cell_renderer_init (
871 GtkWxCellRenderer *cell );
872static void gtk_wx_cell_renderer_class_init(
873 GtkWxCellRendererClass *klass );
874static void gtk_wx_cell_renderer_finalize (
875 GObject *object );
876static void gtk_wx_cell_renderer_get_size (
877 GtkCellRenderer *cell,
93763ad5
WS
878 GtkWidget *widget,
879 GdkRectangle *rectangle,
880 gint *x_offset,
881 gint *y_offset,
882 gint *width,
883 gint *height );
553f7d8f
RR
884static void gtk_wx_cell_renderer_render (
885 GtkCellRenderer *cell,
93763ad5
WS
886 GdkWindow *window,
887 GtkWidget *widget,
888 GdkRectangle *background_area,
889 GdkRectangle *cell_area,
890 GdkRectangle *expose_area,
891 GtkCellRendererState flags );
553f7d8f
RR
892static gboolean gtk_wx_cell_renderer_activate(
893 GtkCellRenderer *cell,
894 GdkEvent *event,
895 GtkWidget *widget,
896 const gchar *path,
897 GdkRectangle *background_area,
898 GdkRectangle *cell_area,
899 GtkCellRendererState flags );
1e510b1e
RR
900static GtkCellEditable *gtk_wx_cell_renderer_start_editing(
901 GtkCellRenderer *cell,
902 GdkEvent *event,
903 GtkWidget *widget,
904 const gchar *path,
905 GdkRectangle *background_area,
906 GdkRectangle *cell_area,
907 GtkCellRendererState flags );
e8375af8 908
e152afc3
RR
909
910static GObjectClass *cell_parent_class = NULL;
911
912} // extern "C"
913
93763ad5 914GType
e152afc3
RR
915gtk_wx_cell_renderer_get_type (void)
916{
553f7d8f 917 static GType cell_wx_type = 0;
e152afc3 918
553f7d8f 919 if (!cell_wx_type)
e152afc3 920 {
de4a74e2 921 const GTypeInfo cell_wx_info =
553f7d8f
RR
922 {
923 sizeof (GtkWxCellRendererClass),
93763ad5
WS
924 NULL, /* base_init */
925 NULL, /* base_finalize */
553f7d8f 926 (GClassInitFunc) gtk_wx_cell_renderer_class_init,
93763ad5
WS
927 NULL, /* class_finalize */
928 NULL, /* class_data */
553f7d8f
RR
929 sizeof (GtkWxCellRenderer),
930 0, /* n_preallocs */
931 (GInstanceInitFunc) gtk_wx_cell_renderer_init,
932 };
933
93763ad5 934 cell_wx_type = g_type_register_static( GTK_TYPE_CELL_RENDERER,
553f7d8f 935 "GtkWxCellRenderer", &cell_wx_info, (GTypeFlags)0 );
e152afc3
RR
936 }
937
553f7d8f 938 return cell_wx_type;
e152afc3
RR
939}
940
941static void
942gtk_wx_cell_renderer_init (GtkWxCellRenderer *cell)
943{
944 cell->cell = NULL;
4d496ecb 945 cell->last_click = 0;
e152afc3
RR
946}
947
948static void
949gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass *klass)
950{
951 GObjectClass *object_class = G_OBJECT_CLASS (klass);
952 GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass);
953
954 cell_parent_class = (GObjectClass*) g_type_class_peek_parent (klass);
955
956 object_class->finalize = gtk_wx_cell_renderer_finalize;
957
958 cell_class->get_size = gtk_wx_cell_renderer_get_size;
959 cell_class->render = gtk_wx_cell_renderer_render;
553f7d8f 960 cell_class->activate = gtk_wx_cell_renderer_activate;
1e510b1e 961 cell_class->start_editing = gtk_wx_cell_renderer_start_editing;
e152afc3
RR
962}
963
964static void
965gtk_wx_cell_renderer_finalize (GObject *object)
966{
967 /* must chain up */
968 (* G_OBJECT_CLASS (cell_parent_class)->finalize) (object);
969}
970
971GtkCellRenderer*
972gtk_wx_cell_renderer_new (void)
973{
974 return (GtkCellRenderer*) g_object_new (GTK_TYPE_WX_CELL_RENDERER, NULL);
975}
976
1e510b1e
RR
977
978
979static GtkCellEditable *gtk_wx_cell_renderer_start_editing(
980 GtkCellRenderer *renderer,
c5c5395b 981 GdkEvent *WXUNUSED(event),
1e510b1e
RR
982 GtkWidget *widget,
983 const gchar *path,
c5c5395b 984 GdkRectangle *WXUNUSED(background_area),
1e510b1e 985 GdkRectangle *cell_area,
c5c5395b 986 GtkCellRendererState WXUNUSED(flags) )
1e510b1e
RR
987{
988 GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer;
989 wxDataViewCustomRenderer *cell = wxrenderer->cell;
bc0289bf 990
c232dfe5 991 // Renderer doesn't support in-place editing
1e510b1e
RR
992 if (!cell->HasEditorCtrl())
993 return NULL;
bc0289bf 994
c232dfe5
RR
995 // An in-place editing control is still around
996 if (cell->GetEditorCtrl())
997 return NULL;
e8375af8 998
1e510b1e
RR
999 GdkRectangle rect;
1000 gtk_wx_cell_renderer_get_size (renderer, widget, cell_area,
1001 &rect.x,
1002 &rect.y,
1003 &rect.width,
1004 &rect.height);
1005
1006 rect.x += cell_area->x;
1007 rect.y += cell_area->y;
1008// rect.width -= renderer->xpad * 2;
1009// rect.height -= renderer->ypad * 2;
1010
1011// wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
1012 wxRect renderrect( cell_area->x, cell_area->y, cell_area->width, cell_area->height );
1013
1e510b1e 1014 GtkTreePath *treepath = gtk_tree_path_new_from_string( path );
55fbde12
RR
1015 GtkTreeIter iter;
1016 cell->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter, treepath );
1017 wxDataViewItem item( (void*) iter.user_data );
1e510b1e
RR
1018 gtk_tree_path_free( treepath );
1019
9d52aad3 1020 cell->StartEditing( item, renderrect );
30715fa1 1021
1e510b1e
RR
1022 return NULL;
1023}
1024
e152afc3
RR
1025static void
1026gtk_wx_cell_renderer_get_size (GtkCellRenderer *renderer,
c5c5395b 1027 GtkWidget *WXUNUSED(widget),
93763ad5
WS
1028 GdkRectangle *cell_area,
1029 gint *x_offset,
1030 gint *y_offset,
1031 gint *width,
1032 gint *height)
e152afc3
RR
1033{
1034 GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer;
baa9ebc4 1035 wxDataViewCustomRenderer *cell = wxrenderer->cell;
93763ad5 1036
e152afc3
RR
1037 wxSize size = cell->GetSize();
1038
1039 gint calc_width = (gint) renderer->xpad * 2 + size.x;
1040 gint calc_height = (gint) renderer->ypad * 2 + size.y;
93763ad5
WS
1041
1042 if (x_offset)
e152afc3 1043 *x_offset = 0;
93763ad5 1044 if (y_offset)
e152afc3
RR
1045 *y_offset = 0;
1046
1047 if (cell_area && size.x > 0 && size.y > 0)
1048 {
1049 if (x_offset)
93763ad5 1050 {
e152afc3
RR
1051 *x_offset = (gint)((renderer->xalign *
1052 (cell_area->width - calc_width - 2 * renderer->xpad)));
1053 *x_offset = MAX (*x_offset, 0) + renderer->xpad;
93763ad5 1054 }
e152afc3
RR
1055 if (y_offset)
1056 {
1057 *y_offset = (gint)((renderer->yalign *
1058 (cell_area->height - calc_height - 2 * renderer->ypad)));
1059 *y_offset = MAX (*y_offset, 0) + renderer->ypad;
1060 }
1061 }
1062
1063 if (width)
1064 *width = calc_width;
93763ad5 1065
e152afc3
RR
1066 if (height)
1067 *height = calc_height;
1068}
1069
1070static void
1071gtk_wx_cell_renderer_render (GtkCellRenderer *renderer,
93763ad5
WS
1072 GdkWindow *window,
1073 GtkWidget *widget,
1074 GdkRectangle *background_area,
1075 GdkRectangle *cell_area,
1076 GdkRectangle *expose_area,
1077 GtkCellRendererState flags)
e152afc3
RR
1078
1079{
1080 GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer;
baa9ebc4 1081 wxDataViewCustomRenderer *cell = wxrenderer->cell;
93763ad5 1082
f69c03de
RR
1083 cell->window = window;
1084 cell->widget = widget;
1085 cell->background_area = (void*) background_area;
1086 cell->cell_area = (void*) cell_area;
1087 cell->expose_area = (void*) expose_area;
1088 cell->flags = (int) flags;
1089
e152afc3
RR
1090 GdkRectangle rect;
1091 gtk_wx_cell_renderer_get_size (renderer, widget, cell_area,
93763ad5
WS
1092 &rect.x,
1093 &rect.y,
1094 &rect.width,
1095 &rect.height);
e152afc3
RR
1096
1097 rect.x += cell_area->x;
1098 rect.y += cell_area->y;
1099 rect.width -= renderer->xpad * 2;
1100 rect.height -= renderer->ypad * 2;
bc0289bf 1101
e152afc3
RR
1102 GdkRectangle dummy;
1103 if (gdk_rectangle_intersect (expose_area, &rect, &dummy))
1104 {
1105 wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
1106 wxWindowDC* dc = (wxWindowDC*) cell->GetDC();
888dde65 1107 wxWindowDCImpl *impl = (wxWindowDCImpl *) dc->GetImpl();
e90d2e83
RR
1108 // Reinitilise GDK window everytime as drawing can also
1109 // be done into DnD drop window.
1110 impl->m_gdkwindow = window;
1111 impl->SetUpDC();
93763ad5 1112
e152afc3
RR
1113 int state = 0;
1114 if (flags & GTK_CELL_RENDERER_SELECTED)
1115 state |= wxDATAVIEW_CELL_SELECTED;
1116 if (flags & GTK_CELL_RENDERER_PRELIT)
1117 state |= wxDATAVIEW_CELL_PRELIT;
1118 if (flags & GTK_CELL_RENDERER_INSENSITIVE)
1119 state |= wxDATAVIEW_CELL_INSENSITIVE;
1120 if (flags & GTK_CELL_RENDERER_INSENSITIVE)
1121 state |= wxDATAVIEW_CELL_INSENSITIVE;
1122 if (flags & GTK_CELL_RENDERER_FOCUSED)
1123 state |= wxDATAVIEW_CELL_FOCUSED;
1124 cell->Render( renderrect, dc, state );
93763ad5 1125 }
e152afc3
RR
1126}
1127
93763ad5 1128static gboolean
553f7d8f
RR
1129gtk_wx_cell_renderer_activate(
1130 GtkCellRenderer *renderer,
1131 GdkEvent *event,
1132 GtkWidget *widget,
1133 const gchar *path,
c5c5395b 1134 GdkRectangle *WXUNUSED(background_area),
553f7d8f 1135 GdkRectangle *cell_area,
c5c5395b 1136 GtkCellRendererState WXUNUSED(flags) )
553f7d8f
RR
1137{
1138 GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer;
baa9ebc4 1139 wxDataViewCustomRenderer *cell = wxrenderer->cell;
93763ad5 1140
553f7d8f
RR
1141 GdkRectangle rect;
1142 gtk_wx_cell_renderer_get_size (renderer, widget, cell_area,
93763ad5
WS
1143 &rect.x,
1144 &rect.y,
1145 &rect.width,
1146 &rect.height);
553f7d8f
RR
1147
1148 rect.x += cell_area->x;
1149 rect.y += cell_area->y;
1150 rect.width -= renderer->xpad * 2;
1151 rect.height -= renderer->ypad * 2;
93763ad5 1152
553f7d8f 1153 wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
93763ad5 1154
e0062c04 1155 wxDataViewModel *model = cell->GetOwner()->GetOwner()->GetModel();
93763ad5 1156
4d496ecb 1157 GtkTreePath *treepath = gtk_tree_path_new_from_string( path );
71c6b455
RR
1158
1159 GtkTreeIter iter;
f69c03de 1160 cell->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter, treepath );
71c6b455 1161 wxDataViewItem item( iter.user_data );
4d496ecb 1162 gtk_tree_path_free( treepath );
93763ad5 1163
0a71f9e9 1164 unsigned int model_col = cell->GetOwner()->GetModelColumn();
93763ad5 1165
456e5c21
RR
1166 if (!event)
1167 {
1168 bool ret = false;
e8375af8 1169
456e5c21 1170 // activated by <ENTER>
9d52aad3 1171 if (cell->Activate( renderrect, model, item, model_col ))
456e5c21 1172 ret = true;
e8375af8 1173
456e5c21
RR
1174 return ret;
1175 }
1176 else if (event->type == GDK_BUTTON_PRESS)
4d496ecb
RR
1177 {
1178 GdkEventButton *button_event = (GdkEventButton*) event;
93763ad5 1179 wxPoint pt( ((int) button_event->x) - renderrect.x,
4d496ecb 1180 ((int) button_event->y) - renderrect.y );
93763ad5 1181
4d496ecb
RR
1182 bool ret = false;
1183 if (button_event->button == 1)
1184 {
9d52aad3 1185 if (cell->LeftClick( pt, renderrect, model, item, model_col ))
4d496ecb 1186 ret = true;
7ea3a0de 1187 // TODO: query system double-click time
4d496ecb 1188 if (button_event->time - wxrenderer->last_click < 400)
9d52aad3 1189 if (cell->Activate( renderrect, model, item, model_col ))
4d496ecb
RR
1190 ret = true;
1191 }
4d496ecb 1192 wxrenderer->last_click = button_event->time;
93763ad5 1193
4d496ecb
RR
1194 return ret;
1195 }
93763ad5 1196
4d496ecb 1197 return false;
553f7d8f
RR
1198}
1199
93763ad5 1200// ---------------------------------------------------------
e0062c04 1201// wxGtkDataViewModelNotifier
93763ad5 1202// ---------------------------------------------------------
6e2e590f 1203
e0062c04 1204class wxGtkDataViewModelNotifier: public wxDataViewModelNotifier
6e2e590f
RR
1205{
1206public:
e0062c04
RR
1207 wxGtkDataViewModelNotifier( GtkWxTreeModel *wxgtk_model,
1208 wxDataViewModel *wx_model,
1209 wxDataViewCtrl *ctrl );
1210 ~wxGtkDataViewModelNotifier();
1211
1212 virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
469d3e9b 1213 virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item );
e0062c04
RR
1214 virtual bool ItemChanged( const wxDataViewItem &item );
1215 virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col );
6e2e590f 1216 virtual bool Cleared();
4508fcd2 1217 virtual void Resort();
93763ad5 1218
33ba5a05
RR
1219 void SetGtkModel( GtkWxTreeModel *model ) { m_wxgtk_model = model; }
1220
1221private:
e0062c04
RR
1222 GtkWxTreeModel *m_wxgtk_model;
1223 wxDataViewModel *m_wx_model;
63415a42 1224 wxDataViewCtrl *m_owner;
6e2e590f
RR
1225};
1226
93763ad5 1227// ---------------------------------------------------------
6e2e590f 1228// wxGtkDataViewListModelNotifier
93763ad5 1229// ---------------------------------------------------------
6e2e590f 1230
e0062c04
RR
1231wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1232 GtkWxTreeModel* wxgtk_model, wxDataViewModel *wx_model,
63415a42 1233 wxDataViewCtrl *ctrl )
6e2e590f 1234{
e0062c04 1235 m_wxgtk_model = wxgtk_model;
6e2e590f 1236 m_wx_model = wx_model;
63415a42 1237 m_owner = ctrl;
6e2e590f 1238}
93763ad5 1239
e0062c04 1240wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
f7ed8c89
RR
1241{
1242 m_wx_model = NULL;
e0062c04 1243 m_wxgtk_model = NULL;
f7ed8c89
RR
1244}
1245
e0062c04 1246bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item )
6e2e590f 1247{
55fbde12 1248 m_owner->GtkGetInternal()->ItemAdded( parent, item );
1e08ad10 1249
6e2e590f 1250 GtkTreeIter iter;
e0062c04
RR
1251 iter.stamp = m_wxgtk_model->stamp;
1252 iter.user_data = (gpointer) item.GetID();
93763ad5 1253
b9db5f30 1254 GtkTreePath *path = wxgtk_tree_model_get_path(
e0062c04 1255 GTK_TREE_MODEL(m_wxgtk_model), &iter );
b9db5f30 1256 gtk_tree_model_row_inserted(
e0062c04 1257 GTK_TREE_MODEL(m_wxgtk_model), path, &iter);
6e2e590f 1258 gtk_tree_path_free (path);
93763ad5 1259
6e2e590f
RR
1260 return true;
1261}
1262
469d3e9b 1263bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item )
6e2e590f 1264{
605c2c4a 1265 GtkTreeIter iter;
e0062c04
RR
1266 iter.stamp = m_wxgtk_model->stamp;
1267 iter.user_data = (gpointer) item.GetID();
93763ad5 1268
b9db5f30 1269 GtkTreePath *path = wxgtk_tree_model_get_path(
e0062c04
RR
1270 GTK_TREE_MODEL(m_wxgtk_model), &iter );
1271 gtk_tree_model_row_deleted(
1272 GTK_TREE_MODEL(m_wxgtk_model), path );
605c2c4a 1273 gtk_tree_path_free (path);
93763ad5 1274
469d3e9b 1275 m_owner->GtkGetInternal()->ItemDeleted( parent, item );
b9db5f30 1276
605c2c4a 1277 return true;
6e2e590f
RR
1278}
1279
4508fcd2
RR
1280void wxGtkDataViewModelNotifier::Resort()
1281{
1282 m_owner->GtkGetInternal()->Resort();
1283}
1284
e0062c04 1285bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem &item )
6e2e590f 1286{
4627af27 1287 GtkTreeIter iter;
e0062c04
RR
1288 iter.stamp = m_wxgtk_model->stamp;
1289 iter.user_data = (gpointer) item.GetID();
6e2e590f 1290
b9db5f30 1291 GtkTreePath *path = wxgtk_tree_model_get_path(
e0062c04
RR
1292 GTK_TREE_MODEL(m_wxgtk_model), &iter );
1293 gtk_tree_model_row_changed(
1294 GTK_TREE_MODEL(m_wxgtk_model), path, &iter );
a7f61f76
RR
1295 gtk_tree_path_free (path);
1296
d8331a01 1297 m_owner->GtkGetInternal()->ItemChanged( item );
b9db5f30 1298
a7f61f76 1299 return true;
6e2e590f
RR
1300}
1301
e0062c04 1302bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem &item, unsigned int model_col )
6e2e590f 1303{
4eccd3a1 1304 // This adds GTK+'s missing MVC logic for ValueChanged
63415a42
RR
1305 unsigned int index;
1306 for (index = 0; index < m_owner->GetColumnCount(); index++)
8f850e28 1307 {
63415a42
RR
1308 wxDataViewColumn *column = m_owner->GetColumn( index );
1309 if (column->GetModelColumn() == model_col)
8f850e28 1310 {
63415a42
RR
1311 GtkTreeView *widget = GTK_TREE_VIEW(m_owner->m_treeview);
1312 GtkTreeViewColumn *gcolumn = GTK_TREE_VIEW_COLUMN(column->GetGtkHandle());
8f850e28
RR
1313
1314 // Get cell area
e0062c04
RR
1315 GtkTreeIter iter;
1316 iter.stamp = m_wxgtk_model->stamp;
1317 iter.user_data = (gpointer) item.GetID();
b9db5f30 1318 GtkTreePath *path = wxgtk_tree_model_get_path(
e0062c04 1319 GTK_TREE_MODEL(m_wxgtk_model), &iter );
8f850e28 1320 GdkRectangle cell_area;
63415a42 1321 gtk_tree_view_get_cell_area( widget, path, gcolumn, &cell_area );
93763ad5 1322 gtk_tree_path_free( path );
8f850e28 1323
1a64259d
RR
1324 GtkAdjustment* hadjust = gtk_tree_view_get_hadjustment( widget );
1325 double d = gtk_adjustment_get_value( hadjust );
1326 int xdiff = (int) d;
1327
63415a42 1328 int ydiff = gcolumn->button->allocation.height;
8f850e28 1329 // Redraw
93763ad5 1330 gtk_widget_queue_draw_area( GTK_WIDGET(widget),
1a64259d 1331 cell_area.x - xdiff, ydiff + cell_area.y, cell_area.width, cell_area.height );
b9db5f30 1332
d8331a01 1333 m_owner->GtkGetInternal()->ValueChanged( item, model_col );
b9db5f30 1334
d8331a01 1335 return true;
8f850e28 1336 }
8f850e28 1337 }
93763ad5 1338
d8331a01 1339 return false;
6e2e590f
RR
1340}
1341
e0062c04 1342bool wxGtkDataViewModelNotifier::Cleared()
6e2e590f 1343{
33ba5a05 1344 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner->m_treeview), NULL );
7857346a 1345
33ba5a05 1346 // this will create a new GTK model
d8331a01 1347 m_owner->GtkGetInternal()->Cleared();
7857346a 1348
33ba5a05 1349 SetGtkModel( m_owner->GtkGetInternal()->GetGtkModel() );
b9db5f30 1350
33ba5a05 1351 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner->m_treeview), GTK_TREE_MODEL(m_wxgtk_model) );
7857346a 1352
6e2e590f
RR
1353 return false;
1354}
1355
93763ad5 1356// ---------------------------------------------------------
baa9ebc4 1357// wxDataViewRenderer
93763ad5 1358// ---------------------------------------------------------
6842a71a 1359
a912e81f
RR
1360static gpointer s_user_data = NULL;
1361
1362static void
c5c5395b 1363wxgtk_cell_editable_editing_done( GtkCellEditable *WXUNUSED(editable),
a912e81f
RR
1364 wxDataViewRenderer *wxrenderer )
1365{
1366 wxDataViewColumn *column = wxrenderer->GetOwner();
1367 wxDataViewCtrl *dv = column->GetOwner();
1368 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, dv->GetId() );
1369 event.SetDataViewColumn( column );
1370 event.SetModel( dv->GetModel() );
1371 wxDataViewItem item( s_user_data );
1372 event.SetItem( item );
937013e0 1373 dv->HandleWindowEvent( event );
a912e81f
RR
1374}
1375
b9db5f30 1376static void
c5c5395b 1377wxgtk_renderer_editing_started( GtkCellRenderer *WXUNUSED(cell), GtkCellEditable *editable,
a912e81f
RR
1378 gchar *path, wxDataViewRenderer *wxrenderer )
1379{
1380 wxDataViewColumn *column = wxrenderer->GetOwner();
1381 wxDataViewCtrl *dv = column->GetOwner();
1382 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, dv->GetId() );
1383 event.SetDataViewColumn( column );
1384 event.SetModel( dv->GetModel() );
1385 GtkTreePath *tree_path = gtk_tree_path_new_from_string( path );
1386 GtkTreeIter iter;
1387 dv->GtkGetInternal()->get_iter( &iter, tree_path );
1388 gtk_tree_path_free( tree_path );
1389 wxDataViewItem item( iter.user_data );
1390 event.SetItem( item );
937013e0 1391 dv->HandleWindowEvent( event );
a912e81f
RR
1392
1393 if (GTK_IS_CELL_EDITABLE(editable))
1394 {
1395 s_user_data = iter.user_data;
b9db5f30 1396
a912e81f
RR
1397 g_signal_connect (GTK_CELL_EDITABLE (editable), "editing_done",
1398 G_CALLBACK (wxgtk_cell_editable_editing_done),
1399 (gpointer) wxrenderer );
b9db5f30 1400
a912e81f
RR
1401 }
1402}
1403
1404
baa9ebc4 1405IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer, wxDataViewRendererBase)
6842a71a 1406
9861f022
RR
1407wxDataViewRenderer::wxDataViewRenderer( const wxString &varianttype, wxDataViewCellMode mode,
1408 int align ) :
1409 wxDataViewRendererBase( varianttype, mode, align )
6842a71a
RR
1410{
1411 m_renderer = NULL;
9861f022
RR
1412
1413 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1414 // after the m_renderer pointer has been initialized
1415}
1416
a912e81f
RR
1417void wxDataViewRenderer::GtkInitHandlers()
1418{
1419 if (!gtk_check_version(2,6,0))
1420 {
1421 g_signal_connect (GTK_CELL_RENDERER(m_renderer), "editing_started",
1422 G_CALLBACK (wxgtk_renderer_editing_started),
1423 this);
1424 }
1425}
1426
9861f022
RR
1427void wxDataViewRenderer::SetMode( wxDataViewCellMode mode )
1428{
1429 GtkCellRendererMode gtkMode;
1430 switch (mode)
1431 {
25bc5c55
VZ
1432 case wxDATAVIEW_CELL_INERT:
1433 gtkMode = GTK_CELL_RENDERER_MODE_INERT;
1434 break;
1435
1436 case wxDATAVIEW_CELL_ACTIVATABLE:
1437 gtkMode = GTK_CELL_RENDERER_MODE_ACTIVATABLE;
1438 break;
1439
1440 case wxDATAVIEW_CELL_EDITABLE:
1441 gtkMode = GTK_CELL_RENDERER_MODE_EDITABLE;
1442 break;
1443
1444 default:
1445 wxFAIL_MSG( "unknown wxDataViewCellMode value" );
1446 return;
9861f022
RR
1447 }
1448
b9db5f30 1449 // This value is most often ignored in GtkTreeView
9861f022
RR
1450 GValue gvalue = { 0, };
1451 g_value_init( &gvalue, gtk_cell_renderer_mode_get_type() );
1452 g_value_set_enum( &gvalue, gtkMode );
1453 g_object_set_property( G_OBJECT(m_renderer), "mode", &gvalue );
1454 g_value_unset( &gvalue );
1455}
1456
1457wxDataViewCellMode wxDataViewRenderer::GetMode() const
1458{
1459 wxDataViewCellMode ret;
1460
1461 GValue gvalue;
1462 g_object_get( G_OBJECT(m_renderer), "mode", &gvalue, NULL);
1463
1464 switch (g_value_get_enum(&gvalue))
1465 {
25bc5c55
VZ
1466 default:
1467 wxFAIL_MSG( "unknown GtkCellRendererMode value" );
1468 // fall through (we have to return something)
1469
1470 case GTK_CELL_RENDERER_MODE_INERT:
1471 ret = wxDATAVIEW_CELL_INERT;
1472 break;
1473
1474 case GTK_CELL_RENDERER_MODE_ACTIVATABLE:
1475 ret = wxDATAVIEW_CELL_ACTIVATABLE;
1476 break;
1477
1478 case GTK_CELL_RENDERER_MODE_EDITABLE:
1479 ret = wxDATAVIEW_CELL_EDITABLE;
1480 break;
9861f022
RR
1481 }
1482
1483 g_value_unset( &gvalue );
1484
1485 return ret;
1486}
1487
f2b7492a 1488void wxDataViewRenderer::GtkUpdateAlignment()
9861f022 1489{
f2b7492a 1490 int align = m_alignment;
bc0289bf 1491
f2b7492a
RR
1492 // query alignment from column ?
1493 if (align == -1)
1494 {
1495 // None there yet
1496 if (GetOwner() == NULL)
1497 return;
bc0289bf 1498
f2b7492a
RR
1499 align = GetOwner()->GetAlignment();
1500 align |= wxALIGN_CENTRE_VERTICAL;
1501 }
bc0289bf 1502
9861f022
RR
1503 // horizontal alignment:
1504
1505 gfloat xalign = 0.0;
1506 if (align & wxALIGN_RIGHT)
1507 xalign = 1.0;
1508 else if (align & wxALIGN_CENTER_HORIZONTAL)
1509 xalign = 0.5;
1510
1511 GValue gvalue = { 0, };
1512 g_value_init( &gvalue, G_TYPE_FLOAT );
1513 g_value_set_float( &gvalue, xalign );
1514 g_object_set_property( G_OBJECT(m_renderer), "xalign", &gvalue );
1515 g_value_unset( &gvalue );
1516
1517 // vertical alignment:
1518
1519 gfloat yalign = 0.0;
1520 if (align & wxALIGN_BOTTOM)
1521 yalign = 1.0;
1522 else if (align & wxALIGN_CENTER_VERTICAL)
1523 yalign = 0.5;
1524
1525 GValue gvalue2 = { 0, };
1526 g_value_init( &gvalue2, G_TYPE_FLOAT );
1527 g_value_set_float( &gvalue2, yalign );
1528 g_object_set_property( G_OBJECT(m_renderer), "yalign", &gvalue2 );
1529 g_value_unset( &gvalue2 );
6842a71a
RR
1530}
1531
f2b7492a 1532void wxDataViewRenderer::SetAlignment( int align )
9861f022 1533{
f2b7492a
RR
1534 m_alignment = align;
1535 GtkUpdateAlignment();
9861f022
RR
1536}
1537
f2b7492a
RR
1538int wxDataViewRenderer::GetAlignment() const
1539{
1540 return m_alignment;
1541}
9861f022 1542
93763ad5 1543// ---------------------------------------------------------
baa9ebc4 1544// wxDataViewTextRenderer
93763ad5 1545// ---------------------------------------------------------
6842a71a 1546
a7f61f76 1547extern "C" {
93763ad5 1548static void wxGtkTextRendererEditedCallback( GtkCellRendererText *renderer,
a7f61f76
RR
1549 gchar *arg1, gchar *arg2, gpointer user_data );
1550}
1551
c5c5395b 1552static void wxGtkTextRendererEditedCallback( GtkCellRendererText *WXUNUSED(renderer),
a7f61f76
RR
1553 gchar *arg1, gchar *arg2, gpointer user_data )
1554{
7448d67c 1555 wxDataViewRenderer *cell = (wxDataViewRenderer*) user_data;
93763ad5 1556
1a74f561 1557 wxString tmp = wxGTK_CONV_BACK_FONT(arg2, cell->GetOwner()->GetOwner()->GetFont());
a7f61f76
RR
1558 wxVariant value = tmp;
1559 if (!cell->Validate( value ))
1560 return;
93763ad5 1561
e0062c04 1562 wxDataViewModel *model = cell->GetOwner()->GetOwner()->GetModel();
93763ad5 1563
a7f61f76 1564 GtkTreePath *path = gtk_tree_path_new_from_string( arg1 );
9d52aad3 1565 GtkTreeIter iter;
55fbde12
RR
1566 cell->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter, path );
1567 wxDataViewItem item( (void*) iter.user_data );;
a7f61f76 1568 gtk_tree_path_free( path );
93763ad5 1569
0a71f9e9 1570 unsigned int model_col = cell->GetOwner()->GetModelColumn();
93763ad5 1571
9d52aad3
RR
1572 model->SetValue( value, item, model_col );
1573 model->ValueChanged( item, model_col );
a7f61f76
RR
1574}
1575
baa9ebc4 1576IMPLEMENT_CLASS(wxDataViewTextRenderer, wxDataViewRenderer)
6842a71a 1577
9861f022
RR
1578wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString &varianttype, wxDataViewCellMode mode,
1579 int align ) :
1580 wxDataViewRenderer( varianttype, mode, align )
6842a71a 1581{
ed38aa55 1582 m_renderer = (GtkCellRenderer*) gtk_cell_renderer_text_new();
93763ad5 1583
9861f022 1584 if (mode & wxDATAVIEW_CELL_EDITABLE)
a7f61f76
RR
1585 {
1586 GValue gvalue = { 0, };
1587 g_value_init( &gvalue, G_TYPE_BOOLEAN );
1588 g_value_set_boolean( &gvalue, true );
1589 g_object_set_property( G_OBJECT(m_renderer), "editable", &gvalue );
1590 g_value_unset( &gvalue );
93763ad5 1591
a7f61f76 1592 g_signal_connect_after( m_renderer, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback), this );
b9db5f30 1593
a912e81f 1594 GtkInitHandlers();
a7f61f76 1595 }
9861f022
RR
1596
1597 SetMode(mode);
1598 SetAlignment(align);
6842a71a 1599}
790b137e 1600
baa9ebc4 1601bool wxDataViewTextRenderer::SetValue( const wxVariant &value )
7b4fde82
RR
1602{
1603 wxString tmp = value;
93763ad5 1604
7b4fde82
RR
1605 GValue gvalue = { 0, };
1606 g_value_init( &gvalue, G_TYPE_STRING );
1bf629bd 1607 g_value_set_string( &gvalue, wxGTK_CONV_FONT( tmp, GetOwner()->GetOwner()->GetFont() ) );
7b4fde82
RR
1608 g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue );
1609 g_value_unset( &gvalue );
93763ad5 1610
7b4fde82
RR
1611 return true;
1612}
1613
9861f022 1614bool wxDataViewTextRenderer::GetValue( wxVariant &value ) const
a7f61f76
RR
1615{
1616 GValue gvalue = { 0, };
1617 g_value_init( &gvalue, G_TYPE_STRING );
1618 g_object_get_property( G_OBJECT(m_renderer), "text", &gvalue );
5c33522f 1619 wxString tmp = wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue ), const_cast<wxDataViewTextRenderer*>(this)->GetOwner()->GetOwner()->GetFont() );
a7f61f76 1620 g_value_unset( &gvalue );
93763ad5 1621
a7f61f76
RR
1622 value = tmp;
1623
1624 return true;
1625}
1626
9861f022
RR
1627void wxDataViewTextRenderer::SetAlignment( int align )
1628{
1629 wxDataViewRenderer::SetAlignment(align);
1630
01705e98
RR
1631 if (gtk_check_version(2,10,0))
1632 return;
9861f022 1633
01705e98 1634 // horizontal alignment:
9861f022
RR
1635 PangoAlignment pangoAlign = PANGO_ALIGN_LEFT;
1636 if (align & wxALIGN_RIGHT)
1637 pangoAlign = PANGO_ALIGN_RIGHT;
1638 else if (align & wxALIGN_CENTER_HORIZONTAL)
1639 pangoAlign = PANGO_ALIGN_CENTER;
1640
1641 GValue gvalue = { 0, };
1642 g_value_init( &gvalue, gtk_cell_renderer_mode_get_type() );
1643 g_value_set_enum( &gvalue, pangoAlign );
1644 g_object_set_property( G_OBJECT(m_renderer), "alignment", &gvalue );
1645 g_value_unset( &gvalue );
1646}
1647
b9db5f30 1648// ---------------------------------------------------------
4264606e 1649// wxDataViewTextRendererAttr
b9db5f30 1650// ---------------------------------------------------------
4264606e
RR
1651
1652IMPLEMENT_CLASS(wxDataViewTextRendererAttr,wxDataViewTextRenderer)
1653
b9db5f30 1654wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString &varianttype,
4264606e
RR
1655 wxDataViewCellMode mode, int align ) :
1656 wxDataViewTextRenderer( varianttype, mode, align )
1657{
1658}
b9db5f30 1659
f4322df6 1660// ---------------------------------------------------------
baa9ebc4 1661// wxDataViewBitmapRenderer
f4322df6 1662// ---------------------------------------------------------
cbc9145c 1663
baa9ebc4 1664IMPLEMENT_CLASS(wxDataViewBitmapRenderer, wxDataViewRenderer)
cbc9145c 1665
9861f022
RR
1666wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString &varianttype, wxDataViewCellMode mode,
1667 int align ) :
1668 wxDataViewRenderer( varianttype, mode, align )
cbc9145c 1669{
ed38aa55 1670 m_renderer = (GtkCellRenderer*) gtk_cell_renderer_pixbuf_new();
9861f022
RR
1671
1672 SetMode(mode);
1673 SetAlignment(align);
cbc9145c
RR
1674}
1675
baa9ebc4 1676bool wxDataViewBitmapRenderer::SetValue( const wxVariant &value )
cbc9145c
RR
1677{
1678 if (value.GetType() == wxT("wxBitmap"))
1679 {
2586d4a1
RR
1680 wxBitmap bitmap;
1681 bitmap << value;
f4322df6 1682
2586d4a1
RR
1683 // This may create a Pixbuf representation in the
1684 // wxBitmap object (and it will stay there)
1685 GdkPixbuf *pixbuf = bitmap.GetPixbuf();
f4322df6 1686
2586d4a1
RR
1687 GValue gvalue = { 0, };
1688 g_value_init( &gvalue, G_TYPE_OBJECT );
1689 g_value_set_object( &gvalue, pixbuf );
1690 g_object_set_property( G_OBJECT(m_renderer), "pixbuf", &gvalue );
1691 g_value_unset( &gvalue );
f4322df6 1692
2586d4a1
RR
1693 return true;
1694 }
f4322df6 1695
2586d4a1
RR
1696 if (value.GetType() == wxT("wxIcon"))
1697 {
1698 wxIcon bitmap;
1699 bitmap << value;
f4322df6 1700
cbc9145c
RR
1701 // This may create a Pixbuf representation in the
1702 // wxBitmap object (and it will stay there)
2586d4a1 1703 GdkPixbuf *pixbuf = bitmap.GetPixbuf();
f4322df6 1704
cbc9145c
RR
1705 GValue gvalue = { 0, };
1706 g_value_init( &gvalue, G_TYPE_OBJECT );
1707 g_value_set_object( &gvalue, pixbuf );
1708 g_object_set_property( G_OBJECT(m_renderer), "pixbuf", &gvalue );
1709 g_value_unset( &gvalue );
f4322df6 1710
cbc9145c
RR
1711 return true;
1712 }
f4322df6 1713
cbc9145c
RR
1714 return false;
1715}
1716
c5c5395b 1717bool wxDataViewBitmapRenderer::GetValue( wxVariant &WXUNUSED(value) ) const
cbc9145c
RR
1718{
1719 return false;
1720}
f4322df6 1721
93763ad5 1722// ---------------------------------------------------------
baa9ebc4 1723// wxDataViewToggleRenderer
93763ad5 1724// ---------------------------------------------------------
fa28826d 1725
605c2c4a 1726extern "C" {
93763ad5 1727static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle *renderer,
605c2c4a
RR
1728 gchar *path, gpointer user_data );
1729}
1730
93763ad5 1731static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle *renderer,
605c2c4a
RR
1732 gchar *path, gpointer user_data )
1733{
baa9ebc4 1734 wxDataViewToggleRenderer *cell = (wxDataViewToggleRenderer*) user_data;
605c2c4a 1735
93763ad5 1736 // get old value
605c2c4a
RR
1737 GValue gvalue = { 0, };
1738 g_value_init( &gvalue, G_TYPE_BOOLEAN );
1739 g_object_get_property( G_OBJECT(renderer), "active", &gvalue );
93763ad5 1740 bool tmp = g_value_get_boolean( &gvalue );
605c2c4a
RR
1741 g_value_unset( &gvalue );
1742 // invert it
1743 tmp = !tmp;
93763ad5 1744
605c2c4a
RR
1745 wxVariant value = tmp;
1746 if (!cell->Validate( value ))
1747 return;
93763ad5 1748
e0062c04 1749 wxDataViewModel *model = cell->GetOwner()->GetOwner()->GetModel();
93763ad5 1750
605c2c4a 1751 GtkTreePath *gtk_path = gtk_tree_path_new_from_string( path );
55fbde12
RR
1752 GtkTreeIter iter;
1753 cell->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter, gtk_path );
1754 wxDataViewItem item( (void*) iter.user_data );;
605c2c4a 1755 gtk_tree_path_free( gtk_path );
93763ad5 1756
0a71f9e9 1757 unsigned int model_col = cell->GetOwner()->GetModelColumn();
93763ad5 1758
9d52aad3
RR
1759 model->SetValue( value, item, model_col );
1760 model->ValueChanged( item, model_col );
605c2c4a
RR
1761}
1762
baa9ebc4 1763IMPLEMENT_CLASS(wxDataViewToggleRenderer, wxDataViewRenderer)
605c2c4a 1764
baa9ebc4 1765wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString &varianttype,
9861f022
RR
1766 wxDataViewCellMode mode, int align ) :
1767 wxDataViewRenderer( varianttype, mode, align )
605c2c4a 1768{
ed38aa55 1769 m_renderer = (GtkCellRenderer*) gtk_cell_renderer_toggle_new();
93763ad5 1770
9861f022 1771 if (mode & wxDATAVIEW_CELL_ACTIVATABLE)
605c2c4a 1772 {
9861f022
RR
1773 g_signal_connect_after( m_renderer, "toggled",
1774 G_CALLBACK(wxGtkToggleRendererToggledCallback), this );
553f7d8f
RR
1775 }
1776 else
1777 {
605c2c4a
RR
1778 GValue gvalue = { 0, };
1779 g_value_init( &gvalue, G_TYPE_BOOLEAN );
553f7d8f 1780 g_value_set_boolean( &gvalue, false );
605c2c4a
RR
1781 g_object_set_property( G_OBJECT(m_renderer), "activatable", &gvalue );
1782 g_value_unset( &gvalue );
605c2c4a 1783 }
9861f022
RR
1784
1785 SetMode(mode);
1786 SetAlignment(align);
605c2c4a
RR
1787}
1788
baa9ebc4 1789bool wxDataViewToggleRenderer::SetValue( const wxVariant &value )
605c2c4a
RR
1790{
1791 bool tmp = value;
93763ad5 1792
605c2c4a
RR
1793 GValue gvalue = { 0, };
1794 g_value_init( &gvalue, G_TYPE_BOOLEAN );
1795 g_value_set_boolean( &gvalue, tmp );
1796 g_object_set_property( G_OBJECT(m_renderer), "active", &gvalue );
1797 g_value_unset( &gvalue );
93763ad5 1798
605c2c4a
RR
1799 return true;
1800}
1801
9861f022 1802bool wxDataViewToggleRenderer::GetValue( wxVariant &value ) const
605c2c4a
RR
1803{
1804 GValue gvalue = { 0, };
1805 g_value_init( &gvalue, G_TYPE_BOOLEAN );
1806 g_object_get_property( G_OBJECT(m_renderer), "active", &gvalue );
93763ad5 1807 bool tmp = g_value_get_boolean( &gvalue );
605c2c4a 1808 g_value_unset( &gvalue );
93763ad5 1809
605c2c4a
RR
1810 value = tmp;
1811
1812 return true;
1813}
93763ad5
WS
1814
1815// ---------------------------------------------------------
baa9ebc4 1816// wxDataViewCustomRenderer
93763ad5 1817// ---------------------------------------------------------
e152afc3 1818
888dde65 1819class wxDataViewCtrlDCImpl: public wxWindowDCImpl
e152afc3
RR
1820{
1821public:
888dde65
RR
1822 wxDataViewCtrlDCImpl( wxDC *owner, wxDataViewCtrl *window ) :
1823 wxWindowDCImpl( owner )
1824 {
1a367564 1825 GtkWidget *widget = window->m_treeview;
e152afc3 1826 // Set later
888dde65 1827 m_gdkwindow = NULL;
7857346a 1828
888dde65 1829 m_window = window;
4d496ecb 1830
496e7ec6 1831 m_context = window->GTKGetPangoDefaultContext();
e152afc3
RR
1832 m_layout = pango_layout_new( m_context );
1833 m_fontdesc = pango_font_description_copy( widget->style->font_desc );
1834
1835 m_cmap = gtk_widget_get_colormap( widget ? widget : window->m_widget );
888dde65
RR
1836
1837 // Set m_gdkwindow later
4d496ecb 1838 // SetUpDC();
e152afc3
RR
1839 }
1840};
1841
888dde65
RR
1842class wxDataViewCtrlDC: public wxWindowDC
1843{
1844public:
c5c5395b
RR
1845 wxDataViewCtrlDC( wxDataViewCtrl *window ) :
1846 wxWindowDC( new wxDataViewCtrlDCImpl( this, window ) )
7857346a 1847 { }
888dde65 1848};
7857346a 1849
888dde65 1850
93763ad5 1851// ---------------------------------------------------------
baa9ebc4 1852// wxDataViewCustomRenderer
93763ad5 1853// ---------------------------------------------------------
e152afc3 1854
baa9ebc4 1855IMPLEMENT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer)
e152afc3 1856
baa9ebc4 1857wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype,
9861f022
RR
1858 wxDataViewCellMode mode, int align,
1859 bool no_init ) :
1860 wxDataViewRenderer( varianttype, mode, align )
e152afc3
RR
1861{
1862 m_dc = NULL;
f69c03de 1863 m_text_renderer = NULL;
93763ad5 1864
ad63bf41
RR
1865 if (no_init)
1866 m_renderer = NULL;
1867 else
9861f022 1868 Init(mode, align);
ad63bf41
RR
1869}
1870
7857346a 1871void wxDataViewCustomRenderer::RenderText( const wxString &text, int xoffset,
85136e3b 1872 wxRect WXUNUSED(cell), wxDC *WXUNUSED(dc), int WXUNUSED(state) )
52e750fc 1873{
f69c03de 1874#if 0
52e750fc
RR
1875 wxDataViewCtrl *view = GetOwner()->GetOwner();
1876 wxColour col = (state & wxDATAVIEW_CELL_SELECTED) ?
1877 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) :
1878 view->GetForegroundColour();
1879 dc->SetTextForeground(col);
1880 dc->DrawText( text, cell.x + xoffset, cell.y + ((cell.height - dc->GetCharHeight()) / 2));
f69c03de
RR
1881#else
1882 if (!m_text_renderer)
1883 m_text_renderer = gtk_cell_renderer_text_new();
b9db5f30 1884
f69c03de
RR
1885 GValue gvalue = { 0, };
1886 g_value_init( &gvalue, G_TYPE_STRING );
1bf629bd 1887 g_value_set_string( &gvalue, wxGTK_CONV_FONT( text, GetOwner()->GetOwner()->GetFont() ) );
f69c03de
RR
1888 g_object_set_property( G_OBJECT(m_text_renderer), "text", &gvalue );
1889 g_value_unset( &gvalue );
1890
1891 ((GdkRectangle*) cell_area)->x += xoffset;
1892 ((GdkRectangle*) cell_area)->width -= xoffset;
b9db5f30 1893
f69c03de
RR
1894 gtk_cell_renderer_render( m_text_renderer,
1895 window,
1896 widget,
1897 (GdkRectangle*) background_area,
1898 (GdkRectangle*) cell_area,
1899 (GdkRectangle*) expose_area,
1900 (GtkCellRendererState) flags );
b9db5f30 1901
f69c03de
RR
1902 ((GdkRectangle*) cell_area)->x -= xoffset;
1903 ((GdkRectangle*) cell_area)->width += xoffset;
1904#endif
52e750fc
RR
1905}
1906
9861f022 1907bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode, int align)
ad63bf41 1908{
e152afc3
RR
1909 GtkWxCellRenderer *renderer = (GtkWxCellRenderer *) gtk_wx_cell_renderer_new();
1910 renderer->cell = this;
93763ad5 1911
ed38aa55 1912 m_renderer = (GtkCellRenderer*) renderer;
93763ad5 1913
9861f022
RR
1914 SetMode(mode);
1915 SetAlignment(align);
93763ad5 1916
a912e81f 1917 GtkInitHandlers();
b9db5f30 1918
ad63bf41 1919 return true;
e152afc3
RR
1920}
1921
baa9ebc4 1922wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
e152afc3
RR
1923{
1924 if (m_dc)
1925 delete m_dc;
f69c03de
RR
1926
1927 if (m_text_renderer)
352cd79f 1928 gtk_object_sink( GTK_OBJECT(m_text_renderer) );
e152afc3
RR
1929}
1930
baa9ebc4 1931wxDC *wxDataViewCustomRenderer::GetDC()
e152afc3
RR
1932{
1933 if (m_dc == NULL)
4d496ecb
RR
1934 {
1935 if (GetOwner() == NULL)
1936 return NULL;
1937 if (GetOwner()->GetOwner() == NULL)
1938 return NULL;
e152afc3 1939 m_dc = new wxDataViewCtrlDC( GetOwner()->GetOwner() );
4d496ecb 1940 }
93763ad5 1941
e152afc3
RR
1942 return m_dc;
1943}
93763ad5
WS
1944
1945// ---------------------------------------------------------
baa9ebc4 1946// wxDataViewProgressRenderer
93763ad5 1947// ---------------------------------------------------------
ad63bf41 1948
baa9ebc4 1949IMPLEMENT_CLASS(wxDataViewProgressRenderer, wxDataViewCustomRenderer)
ad63bf41 1950
baa9ebc4 1951wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString &label,
9861f022
RR
1952 const wxString &varianttype, wxDataViewCellMode mode, int align ) :
1953 wxDataViewCustomRenderer( varianttype, mode, align, true )
ad63bf41
RR
1954{
1955 m_label = label;
1956 m_value = 0;
93763ad5 1957
ad63bf41
RR
1958#ifdef __WXGTK26__
1959 if (!gtk_check_version(2,6,0))
1960 {
ed38aa55 1961 m_renderer = (GtkCellRenderer*) gtk_cell_renderer_progress_new();
93763ad5 1962
ad63bf41
RR
1963 GValue gvalue = { 0, };
1964 g_value_init( &gvalue, G_TYPE_STRING );
09dfa6a0 1965
1bf629bd 1966 g_value_set_string( &gvalue, wxGTK_CONV_FONT( m_label, GetOwner()->GetOwner()->GetFont() ) );
ad63bf41
RR
1967 g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue );
1968 g_value_unset( &gvalue );
9861f022
RR
1969
1970 SetMode(mode);
1971 SetAlignment(align);
ad63bf41
RR
1972 }
1973 else
1974#endif
1975 {
1976 // Use custom cell code
9861f022 1977 wxDataViewCustomRenderer::Init(mode, align);
ad63bf41
RR
1978 }
1979}
1980
baa9ebc4 1981wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
ad63bf41
RR
1982{
1983}
1984
baa9ebc4 1985bool wxDataViewProgressRenderer::SetValue( const wxVariant &value )
ad63bf41
RR
1986{
1987#ifdef __WXGTK26__
1988 if (!gtk_check_version(2,6,0))
1989 {
7226118b 1990 gint tmp = (long) value;
ad63bf41
RR
1991 GValue gvalue = { 0, };
1992 g_value_init( &gvalue, G_TYPE_INT );
7226118b 1993 g_value_set_int( &gvalue, tmp );
ad63bf41
RR
1994 g_object_set_property( G_OBJECT(m_renderer), "value", &gvalue );
1995 g_value_unset( &gvalue );
1996 }
1997 else
1998#endif
1999 {
2000 m_value = (long) value;
93763ad5 2001
ad63bf41
RR
2002 if (m_value < 0) m_value = 0;
2003 if (m_value > 100) m_value = 100;
2004 }
93763ad5 2005
ad63bf41
RR
2006 return true;
2007}
93763ad5 2008
85136e3b 2009bool wxDataViewProgressRenderer::GetValue( wxVariant &WXUNUSED(value) ) const
9861f022
RR
2010{
2011 return false;
2012}
2013
85136e3b 2014bool wxDataViewProgressRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) )
ad63bf41
RR
2015{
2016 double pct = (double)m_value / 100.0;
2017 wxRect bar = cell;
2018 bar.width = (int)(cell.width * pct);
2019 dc->SetPen( *wxTRANSPARENT_PEN );
2020 dc->SetBrush( *wxBLUE_BRUSH );
2021 dc->DrawRectangle( bar );
2022
2023 dc->SetBrush( *wxTRANSPARENT_BRUSH );
2024 dc->SetPen( *wxBLACK_PEN );
2025 dc->DrawRectangle( cell );
93763ad5 2026
ad63bf41
RR
2027 return true;
2028}
2029
9861f022 2030wxSize wxDataViewProgressRenderer::GetSize() const
ad63bf41
RR
2031{
2032 return wxSize(40,12);
2033}
93763ad5 2034
7448d67c
RR
2035// -------------------------------------
2036// wxDataViewChoiceRenderer
2037// -------------------------------------
2038
2039wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString &choices,
2040 wxDataViewCellMode mode, int alignment ) :
2041 wxDataViewCustomRenderer( "string", mode, alignment, true )
2042{
2043 m_choices = choices;
2044
2045#ifdef __WXGTK26__
2046 if (!gtk_check_version(2,6,0))
2047 {
2048 m_renderer = (GtkCellRenderer*) gtk_cell_renderer_combo_new();
2049
2050 GtkListStore *store = gtk_list_store_new( 1, G_TYPE_STRING );
2051 size_t n;
2052 for (n = 0; n < m_choices.GetCount(); n++)
2053 gtk_list_store_insert_with_values( store, NULL, n, 0, m_choices[n].utf8_str(), -1 );
bc0289bf 2054
7448d67c
RR
2055 g_object_set (m_renderer,
2056 "model", store,
2057 "text-column", 0,
2058 "has-entry", FALSE,
2059 NULL);
bc0289bf 2060
7448d67c
RR
2061 bool editable = (mode & wxDATAVIEW_CELL_EDITABLE);
2062 g_object_set (m_renderer, "editable", editable, NULL);
bc0289bf 2063
7448d67c 2064 SetAlignment(alignment);
bc0289bf 2065
7448d67c
RR
2066 g_signal_connect_after( m_renderer, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback), this );
2067
2068 GtkInitHandlers();
2069 }
2070 else
2071#endif
2072 {
2073 // Use custom cell code
2074 wxDataViewCustomRenderer::Init(mode, alignment);
2075 }
2076}
2077
2078bool wxDataViewChoiceRenderer::Render( wxRect rect, wxDC *dc, int state )
2079{
2080 RenderText( m_data, 0, rect, dc, state );
2081 return true;
2082}
2083
2084wxSize wxDataViewChoiceRenderer::GetSize() const
2085{
2086 return wxSize(70,20);
2087}
2088
2089bool wxDataViewChoiceRenderer::SetValue( const wxVariant &value )
2090{
bc0289bf 2091
7448d67c
RR
2092#ifdef __WXGTK26__
2093 if (!gtk_check_version(2,6,0))
2094 {
2095 GValue gvalue = { 0, };
2096 g_value_init( &gvalue, G_TYPE_STRING );
2097 g_value_set_string( &gvalue, wxGTK_CONV_FONT( value.GetString(), GetOwner()->GetOwner()->GetFont() ) );
2098 g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue );
2099 g_value_unset( &gvalue );
2100 }
2101 else
2102#endif
2103 m_data = value.GetString();
2104
2105 return true;
2106}
2107
2108bool wxDataViewChoiceRenderer::GetValue( wxVariant &value ) const
2109{
2110#ifdef __WXGTK26__
2111 if (!gtk_check_version(2,6,0))
2112 {
2113 GValue gvalue = { 0, };
2114 g_value_init( &gvalue, G_TYPE_STRING );
2115 g_object_get_property( G_OBJECT(m_renderer), "text", &gvalue );
2116 wxString temp = wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue ), const_cast<wxDataViewTextRenderer*>(this)->GetOwner()->GetOwner()->GetFont() );
2117 g_value_unset( &gvalue );
2118 value = temp;
2119 wxPrintf( "temp %s\n", temp );
2120 }
2121 else
2122#endif
2123 value = m_data;
2124
2125 return true;
2126}
2127
2128void wxDataViewChoiceRenderer::SetAlignment( int align )
2129{
2130 wxDataViewCustomRenderer::SetAlignment(align);
2131
2132 if (gtk_check_version(2,10,0))
2133 return;
2134
2135 // horizontal alignment:
2136 PangoAlignment pangoAlign = PANGO_ALIGN_LEFT;
2137 if (align & wxALIGN_RIGHT)
2138 pangoAlign = PANGO_ALIGN_RIGHT;
2139 else if (align & wxALIGN_CENTER_HORIZONTAL)
2140 pangoAlign = PANGO_ALIGN_CENTER;
2141
2142 GValue gvalue = { 0, };
2143 g_value_init( &gvalue, gtk_cell_renderer_mode_get_type() );
2144 g_value_set_enum( &gvalue, pangoAlign );
2145 g_object_set_property( G_OBJECT(m_renderer), "alignment", &gvalue );
2146 g_value_unset( &gvalue );
2147}
bc0289bf 2148
93763ad5 2149// ---------------------------------------------------------
baa9ebc4 2150// wxDataViewDateRenderer
93763ad5 2151// ---------------------------------------------------------
4d496ecb 2152
baa9ebc4 2153class wxDataViewDateRendererPopupTransient: public wxPopupTransientWindow
7ea3a0de 2154{
93763ad5 2155public:
baa9ebc4 2156 wxDataViewDateRendererPopupTransient( wxWindow* parent, wxDateTime *value,
e0062c04 2157 wxDataViewModel *model, const wxDataViewItem &item, unsigned int col ) :
7ea3a0de
RR
2158 wxPopupTransientWindow( parent, wxBORDER_SIMPLE )
2159 {
2160 m_model = model;
e0062c04 2161 m_item = item;
7ea3a0de 2162 m_col = col;
7ea3a0de
RR
2163 m_cal = new wxCalendarCtrl( this, -1, *value );
2164 wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
2165 sizer->Add( m_cal, 1, wxGROW );
2166 SetSizer( sizer );
2167 sizer->Fit( this );
2168 }
93763ad5 2169
7ea3a0de
RR
2170 virtual void OnDismiss()
2171 {
2172 }
93763ad5 2173
7ea3a0de 2174 void OnCalendar( wxCalendarEvent &event );
93763ad5 2175
e0062c04
RR
2176 wxCalendarCtrl *m_cal;
2177 wxDataViewModel *m_model;
2178 wxDataViewItem m_item;
2179 unsigned int m_col;
93763ad5 2180
7ea3a0de
RR
2181private:
2182 DECLARE_EVENT_TABLE()
2183};
2184
baa9ebc4
RR
2185BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient,wxPopupTransientWindow)
2186 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar )
7ea3a0de
RR
2187END_EVENT_TABLE()
2188
baa9ebc4 2189void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent &event )
7ea3a0de
RR
2190{
2191 wxDateTime date = event.GetDate();
2192 wxVariant value = date;
e0062c04
RR
2193 m_model->SetValue( value, m_item, m_col );
2194 m_model->ValueChanged( m_item, m_col );
7ea3a0de
RR
2195 DismissAndNotify();
2196}
2197
baa9ebc4 2198IMPLEMENT_CLASS(wxDataViewDateRenderer, wxDataViewCustomRenderer)
4d496ecb 2199
baa9ebc4 2200wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString &varianttype,
9861f022
RR
2201 wxDataViewCellMode mode, int align ) :
2202 wxDataViewCustomRenderer( varianttype, mode, align )
4d496ecb 2203{
9861f022
RR
2204 SetMode(mode);
2205 SetAlignment(align);
4d496ecb 2206}
93763ad5 2207
baa9ebc4 2208bool wxDataViewDateRenderer::SetValue( const wxVariant &value )
4d496ecb
RR
2209{
2210 m_date = value.GetDateTime();
93763ad5 2211
4d496ecb
RR
2212 return true;
2213}
2214
85136e3b 2215bool wxDataViewDateRenderer::GetValue( wxVariant &WXUNUSED(value) ) const
9861f022
RR
2216{
2217 return false;
2218}
2219
baa9ebc4 2220bool wxDataViewDateRenderer::Render( wxRect cell, wxDC *dc, int state )
4d496ecb
RR
2221{
2222 dc->SetFont( GetOwner()->GetOwner()->GetFont() );
2223 wxString tmp = m_date.FormatDate();
52e750fc 2224 RenderText( tmp, 0, cell, dc, state );
4d496ecb
RR
2225 return true;
2226}
2227
9861f022 2228wxSize wxDataViewDateRenderer::GetSize() const
4d496ecb 2229{
4d496ecb
RR
2230 wxString tmp = m_date.FormatDate();
2231 wxCoord x,y,d;
9861f022 2232 GetView()->GetTextExtent( tmp, &x, &y, &d );
4d496ecb
RR
2233 return wxSize(x,y+d);
2234}
2235
85136e3b 2236bool wxDataViewDateRenderer::Activate( wxRect WXUNUSED(cell), wxDataViewModel *model,
e0062c04 2237 const wxDataViewItem &item, unsigned int col )
4d496ecb 2238{
3f3af7e7 2239 wxVariant variant;
e0062c04 2240 model->GetValue( variant, item, col );
7ea3a0de
RR
2241 wxDateTime value = variant.GetDateTime();
2242
baa9ebc4 2243 wxDataViewDateRendererPopupTransient *popup = new wxDataViewDateRendererPopupTransient(
e0062c04 2244 GetOwner()->GetOwner()->GetParent(), &value, model, item, col );
7ea3a0de
RR
2245 wxPoint pos = wxGetMousePosition();
2246 popup->Move( pos );
2247 popup->Layout();
2248 popup->Popup( popup->m_cal );
4d496ecb
RR
2249
2250 return true;
2251}
2252
c9c13e70 2253
b9db5f30 2254// ---------------------------------------------------------
c9c13e70 2255// wxDataViewIconTextRenderer
b9db5f30 2256// ---------------------------------------------------------
c9c13e70
RR
2257
2258IMPLEMENT_CLASS(wxDataViewIconTextRenderer, wxDataViewCustomRenderer)
2259
b9db5f30 2260wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
c9c13e70
RR
2261 const wxString &varianttype, wxDataViewCellMode mode, int align ) :
2262 wxDataViewCustomRenderer( varianttype, mode, align )
2263{
2264 SetMode(mode);
2265 SetAlignment(align);
2266}
2267
2268wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2269{
2270}
b9db5f30 2271
c9c13e70
RR
2272bool wxDataViewIconTextRenderer::SetValue( const wxVariant &value )
2273{
2274 m_value << value;
2275 return true;
2276}
2277
ad386793 2278bool wxDataViewIconTextRenderer::GetValue( wxVariant &WXUNUSED(value) ) const
c9c13e70
RR
2279{
2280 return false;
2281}
b9db5f30 2282
c9c13e70
RR
2283bool wxDataViewIconTextRenderer::Render( wxRect cell, wxDC *dc, int state )
2284{
c9c13e70 2285 const wxIcon &icon = m_value.GetIcon();
52e750fc 2286 int offset = 0;
c9c13e70
RR
2287 if (icon.IsOk())
2288 {
52e750fc
RR
2289 int yoffset = wxMax( 0, (cell.height - icon.GetHeight()) / 2 );
2290 dc->DrawIcon( icon, cell.x, cell.y + yoffset );
2291 offset = icon.GetWidth() + 4;
c9c13e70 2292 }
b9db5f30 2293
52e750fc 2294 RenderText( m_value.GetText(), offset, cell, dc, state );
c9c13e70
RR
2295
2296 return true;
2297}
2298
2299wxSize wxDataViewIconTextRenderer::GetSize() const
2300{
52e750fc
RR
2301 wxSize size;
2302 if (m_value.GetIcon().IsOk())
2303 size.x = 4 + m_value.GetIcon().GetWidth();
2304 wxCoord x,y,d;
2305 GetView()->GetTextExtent( m_value.GetText(), &x, &y, &d );
2306 size.x += x;
2307 size.y = y+d;
b9db5f30 2308 return size;
c9c13e70
RR
2309}
2310
7857346a 2311wxControl* wxDataViewIconTextRenderer::CreateEditorCtrl(
ad386793 2312 wxWindow *WXUNUSED(parent), wxRect WXUNUSED(labelRect), const wxVariant &WXUNUSED(value) )
c9c13e70
RR
2313{
2314 return NULL;
2315}
2316
7857346a 2317bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl(
ad386793 2318 wxControl* WXUNUSED(editor), wxVariant &WXUNUSED(value) )
c9c13e70
RR
2319{
2320 return false;
2321}
2322
93763ad5 2323// ---------------------------------------------------------
605c2c4a 2324// wxDataViewColumn
93763ad5 2325// ---------------------------------------------------------
7b4fde82 2326
31fb32e1
RR
2327
2328static gboolean
ad386793 2329gtk_dataview_header_button_press_callback( GtkWidget *WXUNUSED(widget),
31fb32e1
RR
2330 GdkEventButton *gdk_event,
2331 wxDataViewColumn *column )
2332{
2333 if (gdk_event->type != GDK_BUTTON_PRESS)
94b1f7bc 2334 return FALSE;
f4322df6 2335
31fb32e1
RR
2336 if (gdk_event->button == 1)
2337 {
d32332aa 2338 gs_lastLeftClickHeader = column;
7857346a 2339
31fb32e1
RR
2340 wxDataViewCtrl *dv = column->GetOwner();
2341 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, dv->GetId() );
2342 event.SetDataViewColumn( column );
2343 event.SetModel( dv->GetModel() );
937013e0 2344 if (dv->HandleWindowEvent( event ))
a84c5b6f 2345 return FALSE;
31fb32e1 2346 }
f4322df6 2347
dadc879e
RR
2348 if (gdk_event->button == 3)
2349 {
2350 wxDataViewCtrl *dv = column->GetOwner();
2351 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, dv->GetId() );
2352 event.SetDataViewColumn( column );
2353 event.SetModel( dv->GetModel() );
937013e0 2354 if (dv->HandleWindowEvent( event ))
dadc879e
RR
2355 return FALSE;
2356 }
2357
94b1f7bc 2358 return FALSE;
31fb32e1
RR
2359}
2360
7b4fde82
RR
2361extern "C" {
2362static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column,
2363 GtkCellRenderer *cell,
2364 GtkTreeModel *model,
2365 GtkTreeIter *iter,
2366 gpointer data );
2367}
2368
2369
ad386793 2370static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *WXUNUSED(column),
7b4fde82
RR
2371 GtkCellRenderer *renderer,
2372 GtkTreeModel *model,
2373 GtkTreeIter *iter,
2374 gpointer data )
2375{
e0062c04
RR
2376 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model));
2377 GtkWxTreeModel *tree_model = (GtkWxTreeModel *) model;
93763ad5 2378
baa9ebc4 2379 wxDataViewRenderer *cell = (wxDataViewRenderer*) data;
a7f61f76 2380
9d52aad3 2381 wxDataViewItem item( (void*) iter->user_data );
93763ad5 2382
a826202e
RR
2383 wxDataViewModel *wx_model = tree_model->internal->GetDataViewModel();
2384
e39de702 2385 if (!wx_model->IsVirtualListModel())
2056dede 2386 {
b9db5f30 2387
a826202e
RR
2388 if (wx_model->IsContainer( item ))
2389 {
2390 if (wx_model->HasContainerColumns( item ) || (cell->GetOwner()->GetModelColumn() == 0))
2391 {
2392 GValue gvalue = { 0, };
2393 g_value_init( &gvalue, G_TYPE_BOOLEAN );
2394 g_value_set_boolean( &gvalue, TRUE );
2395 g_object_set_property( G_OBJECT(renderer), "visible", &gvalue );
2396 g_value_unset( &gvalue );
2397 }
2398 else
2399 {
2400 GValue gvalue = { 0, };
2401 g_value_init( &gvalue, G_TYPE_BOOLEAN );
2402 g_value_set_boolean( &gvalue, FALSE );
2403 g_object_set_property( G_OBJECT(renderer), "visible", &gvalue );
2404 g_value_unset( &gvalue );
b9db5f30 2405
a826202e
RR
2406 return;
2407 }
2408 }
2409 else
2410 {
2411 GValue gvalue = { 0, };
2412 g_value_init( &gvalue, G_TYPE_BOOLEAN );
2413 g_value_set_boolean( &gvalue, TRUE );
2414 g_object_set_property( G_OBJECT(renderer), "visible", &gvalue );
2415 g_value_unset( &gvalue );
2416 }
b9db5f30 2417
2056dede 2418 }
a826202e 2419
3f3af7e7 2420 wxVariant value;
a826202e 2421 wx_model->GetValue( value, item, cell->GetOwner()->GetModelColumn() );
7b4fde82
RR
2422
2423 if (value.GetType() != cell->GetVariantType())
f4322df6
VZ
2424 wxLogError( wxT("Wrong type, required: %s but: %s"),
2425 value.GetType().c_str(),
cbc9145c 2426 cell->GetVariantType().c_str() );
93763ad5 2427
7b4fde82 2428 cell->SetValue( value );
e0743e63 2429
4264606e
RR
2430 if (cell->GtkHasAttributes())
2431 {
2432 wxDataViewItemAttr attr;
2433 bool colour_set = false;
2434 bool style_set = false;
2435 bool weight_set = false;
b9db5f30 2436
4264606e
RR
2437 if (wx_model->GetAttr( item, cell->GetOwner()->GetModelColumn(), attr ))
2438 {
2439 // this must be a GtkCellRendererText
2440 wxColour colour = attr.GetColour();
2441 if (colour.IsOk())
2442 {
2443 const GdkColor * const gcol = colour.GetColor();
2a5e6d1b 2444
4264606e
RR
2445 GValue gvalue = { 0, };
2446 g_value_init( &gvalue, GDK_TYPE_COLOR );
2447 g_value_set_boxed( &gvalue, gcol );
2448 g_object_set_property( G_OBJECT(renderer), "foreground_gdk", &gvalue );
2449 g_value_unset( &gvalue );
b9db5f30 2450
4264606e
RR
2451 colour_set = true;
2452 }
b9db5f30 2453
4264606e
RR
2454 if (attr.GetItalic())
2455 {
2456 GValue gvalue = { 0, };
2457 g_value_init( &gvalue, PANGO_TYPE_STYLE );
2458 g_value_set_enum( &gvalue, PANGO_STYLE_ITALIC );
2459 g_object_set_property( G_OBJECT(renderer), "style", &gvalue );
2460 g_value_unset( &gvalue );
b9db5f30 2461
4264606e
RR
2462 style_set = true;
2463 }
b9db5f30 2464
4264606e
RR
2465 if (attr.GetBold())
2466 {
2467 GValue gvalue = { 0, };
2468 g_value_init( &gvalue, PANGO_TYPE_WEIGHT );
2469 g_value_set_enum( &gvalue, PANGO_WEIGHT_BOLD );
2470 g_object_set_property( G_OBJECT(renderer), "weight", &gvalue );
2471 g_value_unset( &gvalue );
b9db5f30 2472
4264606e
RR
2473 weight_set = true;
2474 }
2475 }
b9db5f30 2476
4264606e
RR
2477 if (!style_set)
2478 {
2479 GValue gvalue = { 0, };
2480 g_value_init( &gvalue, G_TYPE_BOOLEAN );
2481 g_value_set_boolean( &gvalue, FALSE );
2482 g_object_set_property( G_OBJECT(renderer), "style-set", &gvalue );
2483 g_value_unset( &gvalue );
2484 }
b9db5f30 2485
4264606e
RR
2486 if (!weight_set)
2487 {
2488 GValue gvalue = { 0, };
2489 g_value_init( &gvalue, G_TYPE_BOOLEAN );
2490 g_value_set_boolean( &gvalue, FALSE );
2491 g_object_set_property( G_OBJECT(renderer), "weight-set", &gvalue );
2492 g_value_unset( &gvalue );
2493 }
b9db5f30 2494
4264606e
RR
2495 if (!colour_set)
2496 {
2497 GValue gvalue = { 0, };
2498 g_value_init( &gvalue, G_TYPE_BOOLEAN );
2499 g_value_set_boolean( &gvalue, FALSE );
2500 g_object_set_property( G_OBJECT(renderer), "foreground-set", &gvalue );
2501 g_value_unset( &gvalue );
2502 }
2503 }
2504
2505#if 0
2a5e6d1b
RR
2506 if (attr.HasBackgroundColour())
2507 {
2508 wxColour colour = attr.GetBackgroundColour();
1cd5e95c 2509 const GdkColor * const gcol = colour.GetColor();
e0743e63 2510
2a5e6d1b
RR
2511 GValue gvalue = { 0, };
2512 g_value_init( &gvalue, GDK_TYPE_COLOR );
2513 g_value_set_boxed( &gvalue, gcol );
2514 g_object_set_property( G_OBJECT(renderer), "cell-background_gdk", &gvalue );
2515 g_value_unset( &gvalue );
2516 }
2517 else
2518 {
2519 GValue gvalue = { 0, };
2520 g_value_init( &gvalue, G_TYPE_BOOLEAN );
2521 g_value_set_boolean( &gvalue, FALSE );
2522 g_object_set_property( G_OBJECT(renderer), "cell-background-set", &gvalue );
2523 g_value_unset( &gvalue );
2524 }
e0062c04
RR
2525#endif
2526
7b4fde82
RR
2527}
2528
91a6c655 2529#include <wx/listimpl.cpp>
a76c2f37 2530WX_DEFINE_LIST(wxDataViewColumnList)
91a6c655 2531
f4322df6
VZ
2532wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewRenderer *cell,
2533 unsigned int model_column, int width,
835d0d55
VZ
2534 wxAlignment align, int flags )
2535 : wxDataViewColumnBase( cell, model_column )
fa28826d 2536{
9861f022 2537 Init( align, flags, width );
31fb32e1 2538
31fb32e1 2539 SetTitle( title );
fa28826d
RR
2540}
2541
f4322df6
VZ
2542wxDataViewColumn::wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *cell,
2543 unsigned int model_column, int width,
835d0d55
VZ
2544 wxAlignment align, int flags )
2545 : wxDataViewColumnBase( bitmap, cell, model_column )
9861f022
RR
2546{
2547 Init( align, flags, width );
2548
2549 SetBitmap( bitmap );
2550}
2551
2552void wxDataViewColumn::Init(wxAlignment align, int flags, int width)
07a84e7b 2553{
31fb32e1 2554 m_isConnected = false;
07a84e7b 2555
9861f022 2556 GtkCellRenderer *renderer = (GtkCellRenderer *) GetRenderer()->GetGtkHandle();
07a84e7b 2557 GtkTreeViewColumn *column = gtk_tree_view_column_new();
9861f022 2558 m_column = (GtkWidget*) column;
07a84e7b 2559
9861f022
RR
2560 SetFlags( flags );
2561 SetAlignment( align );
07a84e7b 2562
ad386793 2563 SetWidth( width );
07a84e7b 2564
419a3607
RR
2565 // Create container for icon and label
2566 GtkWidget *box = gtk_hbox_new( FALSE, 1 );
2567 gtk_widget_show( box );
2568 // gtk_container_set_border_width((GtkContainer*)box, 2);
2569 m_image = gtk_image_new();
2570 gtk_box_pack_start(GTK_BOX(box), m_image, FALSE, FALSE, 1);
2571 m_label = gtk_label_new("");
2572 gtk_box_pack_end( GTK_BOX(box), GTK_WIDGET(m_label), FALSE, FALSE, 1 );
2573 gtk_tree_view_column_set_widget( column, box );
bc0289bf 2574
9861f022 2575 gtk_tree_view_column_pack_end( column, renderer, TRUE );
07a84e7b
RR
2576
2577 gtk_tree_view_column_set_cell_data_func( column, renderer,
9861f022 2578 wxGtkTreeCellDataFunc, (gpointer) GetRenderer(), NULL );
07a84e7b
RR
2579}
2580
31fb32e1
RR
2581void wxDataViewColumn::OnInternalIdle()
2582{
2583 if (m_isConnected)
2584 return;
f4322df6 2585
31fb32e1
RR
2586 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview))
2587 {
9861f022 2588 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
31fb32e1
RR
2589 if (column->button)
2590 {
2591 g_signal_connect(column->button, "button_press_event",
2592 G_CALLBACK (gtk_dataview_header_button_press_callback), this);
f4322df6 2593
31fb32e1
RR
2594 m_isConnected = true;
2595 }
2596 }
2597}
2598
b94db696
RR
2599void wxDataViewColumn::SetOwner( wxDataViewCtrl *owner )
2600{
2601 wxDataViewColumnBase::SetOwner( owner );
f4322df6 2602
9861f022 2603 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
f4322df6 2604
b94db696 2605 gtk_tree_view_column_set_title( column, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
b94db696
RR
2606}
2607
fa28826d
RR
2608void wxDataViewColumn::SetTitle( const wxString &title )
2609{
09dfa6a0 2610 wxDataViewCtrl *ctrl = GetOwner();
419a3607 2611 gtk_label_set_text( GTK_LABEL(m_label), ctrl ? wxGTK_CONV_FONT(title, ctrl->GetFont())
09dfa6a0 2612 : wxGTK_CONV_SYS(title) );
419a3607
RR
2613 if (title.empty())
2614 gtk_widget_hide( m_label );
2615 else
2616 gtk_widget_show( m_label );
07a84e7b
RR
2617}
2618
9861f022
RR
2619wxString wxDataViewColumn::GetTitle() const
2620{
7f6cbcea
VZ
2621 return wxGTK_CONV_BACK_FONT(
2622 gtk_label_get_text( GTK_LABEL(m_label) ),
2623 GetOwner()->GetFont()
2624 );
9861f022
RR
2625}
2626
07a84e7b
RR
2627void wxDataViewColumn::SetBitmap( const wxBitmap &bitmap )
2628{
2629 wxDataViewColumnBase::SetBitmap( bitmap );
2630
07a84e7b
RR
2631 if (bitmap.Ok())
2632 {
419a3607 2633 GtkImage *gtk_image = GTK_IMAGE(m_image);
f4322df6 2634
d3b9f782 2635 GdkBitmap *mask = NULL;
07a84e7b
RR
2636 if (bitmap.GetMask())
2637 mask = bitmap.GetMask()->GetBitmap();
2638
2639 if (bitmap.HasPixbuf())
2640 {
2641 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image),
2642 bitmap.GetPixbuf());
2643 }
2644 else
2645 {
2646 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image),
2647 bitmap.GetPixmap(), mask);
2648 }
419a3607 2649 gtk_widget_show( m_image );
07a84e7b
RR
2650 }
2651 else
2652 {
419a3607 2653 gtk_widget_hide( m_image );
07a84e7b 2654 }
fa28826d
RR
2655}
2656
9861f022
RR
2657void wxDataViewColumn::SetHidden( bool hidden )
2658{
2659 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column), !hidden );
2660}
2661
2662void wxDataViewColumn::SetResizeable( bool resizeable )
2663{
2664 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column), resizeable );
2665}
2666
47cef10f
RR
2667void wxDataViewColumn::SetAlignment( wxAlignment align )
2668{
9861f022 2669 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
f4322df6 2670
47cef10f
RR
2671 gfloat xalign = 0.0;
2672 if (align == wxALIGN_RIGHT)
2673 xalign = 1.0;
9861f022
RR
2674 if (align == wxALIGN_CENTER_HORIZONTAL ||
2675 align == wxALIGN_CENTER)
47cef10f 2676 xalign = 0.5;
f4322df6 2677
9861f022 2678 gtk_tree_view_column_set_alignment( column, xalign );
bc0289bf 2679
f2b7492a
RR
2680 if (m_renderer && m_renderer->GetAlignment() == -1)
2681 m_renderer->GtkUpdateAlignment();
9861f022
RR
2682}
2683
2684wxAlignment wxDataViewColumn::GetAlignment() const
2685{
2686 gfloat xalign = gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column) );
2687
2688 if (xalign == 1.0)
2689 return wxALIGN_RIGHT;
2690 if (xalign == 0.5)
2691 return wxALIGN_CENTER_HORIZONTAL;
f4322df6 2692
9861f022 2693 return wxALIGN_LEFT;
47cef10f
RR
2694}
2695
31fb32e1
RR
2696void wxDataViewColumn::SetSortable( bool sortable )
2697{
9861f022 2698 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
b9db5f30 2699
140a119a
VZ
2700 if ( sortable )
2701 {
2702 gtk_tree_view_column_set_sort_column_id( column, GetModelColumn() );
2703 }
2704 else
2705 {
2706 gtk_tree_view_column_set_sort_column_id( column, -1 );
2707 gtk_tree_view_column_set_sort_indicator( column, FALSE );
2708 gtk_tree_view_column_set_clickable( column, FALSE );
2709 }
e2bfe673
VZ
2710}
2711
2712bool wxDataViewColumn::IsSortable() const
2713{
2714 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
2715 return gtk_tree_view_column_get_clickable( column );
2716}
2717
140a119a 2718void wxDataViewColumn::SetAsSortKey( bool WXUNUSED(sort) )
e2bfe673 2719{
dcb6cbec 2720 // it might not make sense to have this function in wxHeaderColumn at
140a119a
VZ
2721 // all in fact, changing of the sort order should only be done using the
2722 // associated control API
2723 wxFAIL_MSG( "not implemented" );
31fb32e1
RR
2724}
2725
e2bfe673 2726bool wxDataViewColumn::IsSortKey() const
31fb32e1 2727{
9861f022 2728 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
140a119a 2729 return gtk_tree_view_column_get_sort_indicator( column );
31fb32e1
RR
2730}
2731
9861f022
RR
2732bool wxDataViewColumn::IsResizeable() const
2733{
2734 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
2735 return gtk_tree_view_column_get_resizable( column );
2736}
2737
2738bool wxDataViewColumn::IsHidden() const
2739{
2740 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
2741 return !gtk_tree_view_column_get_visible( column );
2742}
2743
47cef10f
RR
2744void wxDataViewColumn::SetSortOrder( bool ascending )
2745{
9861f022 2746 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
f4322df6 2747
47cef10f
RR
2748 if (ascending)
2749 gtk_tree_view_column_set_sort_order( column, GTK_SORT_ASCENDING );
2750 else
2751 gtk_tree_view_column_set_sort_order( column, GTK_SORT_DESCENDING );
0bd26819
RR
2752
2753 gtk_tree_view_column_set_sort_indicator( column, TRUE );
47cef10f
RR
2754}
2755
87f0efe2 2756bool wxDataViewColumn::IsSortOrderAscending() const
31fb32e1 2757{
9861f022 2758 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
f4322df6 2759
31fb32e1
RR
2760 return (gtk_tree_view_column_get_sort_order( column ) != GTK_SORT_DESCENDING);
2761}
2762
9861f022 2763void wxDataViewColumn::SetMinWidth( int width )
533544f2 2764{
9861f022 2765 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column), width );
533544f2
RR
2766}
2767
9861f022
RR
2768int wxDataViewColumn::GetMinWidth() const
2769{
2770 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column) );
2771}
2772
2773int wxDataViewColumn::GetWidth() const
533544f2 2774{
9861f022 2775 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column) );
533544f2
RR
2776}
2777
9861f022 2778void wxDataViewColumn::SetWidth( int width )
533544f2 2779{
ad386793
RR
2780 if (width < 0)
2781 {
973dc907
RR
2782#if 1
2783 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column), GTK_TREE_VIEW_COLUMN_FIXED );
2784
2785 // TODO find a better calculation
97e89e29 2786 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column), wxDVC_DEFAULT_WIDTH );
973dc907
RR
2787#else
2788 // this is unpractical for large numbers of items and disables
2789 // user resizing, which is totally unexpected
ad386793 2790 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column), GTK_TREE_VIEW_COLUMN_AUTOSIZE );
973dc907 2791#endif
ad386793
RR
2792 }
2793 else
2794 {
2795 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column), GTK_TREE_VIEW_COLUMN_FIXED );
7857346a 2796
ad386793
RR
2797 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column), width );
2798 }
533544f2
RR
2799}
2800
99c75ebc
RR
2801void wxDataViewColumn::SetReorderable( bool reorderable )
2802{
2803 gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column), reorderable );
2804}
2805
2806bool wxDataViewColumn::IsReorderable() const
2807{
2808 return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column) );
2809}
9861f022 2810
4508fcd2
RR
2811//-----------------------------------------------------------------------------
2812// wxGtkTreeModelNode
2813//-----------------------------------------------------------------------------
2814
2815void wxGtkTreeModelNode::Resort()
2816{
af110130
RR
2817 size_t child_count = GetChildCount();
2818 if (child_count == 0)
0be79c8a
RR
2819 return;
2820
af110130
RR
2821 size_t node_count = GetNodesCount();
2822
2823 if (child_count == 1)
0be79c8a 2824 {
af110130
RR
2825 if (node_count == 1)
2826 {
2827 wxGtkTreeModelNode *node = m_nodes.Item( 0 );
2828 node->Resort();
2829 }
0be79c8a
RR
2830 return;
2831 }
2832
40196b1e
RR
2833 wxGtkTreeModelChildren temp;
2834 WX_APPEND_ARRAY( temp, m_children );
b9db5f30 2835
8c2654ce 2836 gs_internal = m_internal;
40196b1e 2837 m_children.Sort( &wxGtkTreeModelChildCmp );
0be79c8a 2838
af110130 2839 gint *new_order = new gint[child_count];
b9db5f30 2840
40196b1e 2841 unsigned int pos;
af110130 2842 for (pos = 0; pos < child_count; pos++)
4508fcd2 2843 {
40196b1e
RR
2844 void *id = m_children.Item( pos );
2845 int old_pos = temp.Index( id );
2846 new_order[pos] = old_pos;
4508fcd2 2847 }
b9db5f30 2848
0be79c8a
RR
2849 GtkTreeModel *gtk_tree_model = GTK_TREE_MODEL( m_internal->GetGtkModel() );
2850
2851 GtkTreeIter iter;
40196b1e 2852 iter.user_data = GetItem().GetID();
0be79c8a 2853 iter.stamp = m_internal->GetGtkModel()->stamp;
b9db5f30 2854
40196b1e 2855 GtkTreePath *path = m_internal->get_path( &iter );
b9db5f30 2856
0be79c8a 2857 gtk_tree_model_rows_reordered( gtk_tree_model, path, &iter, new_order );
b9db5f30 2858
0be79c8a 2859 gtk_tree_path_free (path);
b9db5f30 2860
0be79c8a 2861 delete [] new_order;
b9db5f30 2862
af110130 2863 for (pos = 0; pos < node_count; pos++)
4508fcd2 2864 {
af110130 2865 wxGtkTreeModelNode *node = m_nodes.Item( pos );
4508fcd2
RR
2866 node->Resort();
2867 }
2868}
2869
55fbde12
RR
2870//-----------------------------------------------------------------------------
2871// wxDataViewCtrlInternal
2872//-----------------------------------------------------------------------------
2873
b9db5f30 2874wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl *owner,
55fbde12 2875 wxDataViewModel *wx_model, GtkWxTreeModel *gtk_model )
b9db5f30 2876{
55fbde12 2877 m_owner = owner;
b9db5f30
VS
2878 m_wx_model = wx_model;
2879 m_gtk_model = gtk_model;
2880 m_root = NULL;
b8b7b087 2881 m_sort_order = GTK_SORT_ASCENDING;
40196b1e 2882 m_sort_column = -1;
d32332aa 2883 m_dataview_sort_column = NULL;
8c2654ce 2884
591cc82d
RR
2885 m_dragDataObject = NULL;
2886 m_dropDataObject = NULL;
b9db5f30 2887
e39de702 2888 if (!m_wx_model->IsVirtualListModel())
2056dede 2889 InitTree();
55fbde12 2890}
b9db5f30 2891
55fbde12
RR
2892wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
2893{
2894 g_object_unref( m_gtk_model );
8c2654ce 2895
591cc82d
RR
2896 delete m_dragDataObject;
2897 delete m_dropDataObject;
55fbde12 2898}
b9db5f30 2899
ef427989
RR
2900void wxDataViewCtrlInternal::InitTree()
2901{
2902 wxDataViewItem item;
0be79c8a 2903 m_root = new wxGtkTreeModelNode( NULL, item, this );
ef427989
RR
2904
2905 BuildBranch( m_root );
2906}
2907
55fbde12
RR
2908void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode *node )
2909{
2910 if (node->GetChildCount() == 0)
2911 {
74fe973b
RR
2912 wxDataViewItemArray children;
2913 unsigned int count = m_wx_model->GetChildren( node->GetItem(), children );
2914 unsigned int pos;
2915 for (pos = 0; pos < count; pos++)
55fbde12 2916 {
74fe973b 2917 wxDataViewItem child = children[pos];
b9db5f30 2918
af110130
RR
2919 if (m_wx_model->IsContainer( child ))
2920 node->AddNode( new wxGtkTreeModelNode( node, child, this ) );
2921 else
2922 node->AddLeave( child.GetID() );
b9db5f30 2923
effd54b0 2924 // Don't send any events here
55fbde12
RR
2925 }
2926 }
2927}
2928
f6f0ef85
RR
2929// GTK+ dnd iface
2930
15cac64f
RR
2931bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat &format )
2932{
2933 wxGtkString atom_str( gdk_atom_name( format ) );
2934 m_dragSourceTargetEntryTarget = wxCharBuffer( atom_str );
8c2654ce 2935
15cac64f
RR
2936 m_dragSourceTargetEntry.target = m_dragSourceTargetEntryTarget.data();
2937 m_dragSourceTargetEntry.flags = 0;
2938 m_dragSourceTargetEntry.info = static_cast<guint>(-1);
8c2654ce 2939
15cac64f
RR
2940 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner->GtkGetTreeView() ),
2941 GDK_BUTTON1_MASK, &m_dragSourceTargetEntry, 1, (GdkDragAction) GDK_ACTION_COPY );
8c2654ce 2942
15cac64f
RR
2943 return true;
2944}
2945
e4de825e
RR
2946bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat &format )
2947{
2948 wxGtkString atom_str( gdk_atom_name( format ) );
2949 m_dropTargetTargetEntryTarget = wxCharBuffer( atom_str );
8c2654ce 2950
b4c40918 2951 m_dropTargetTargetEntry.target = m_dropTargetTargetEntryTarget.data();
e4de825e
RR
2952 m_dropTargetTargetEntry.flags = 0;
2953 m_dropTargetTargetEntry.info = static_cast<guint>(-1);
8c2654ce 2954
e4de825e
RR
2955 gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner->GtkGetTreeView() ),
2956 &m_dropTargetTargetEntry, 1, (GdkDragAction) GDK_ACTION_COPY );
8c2654ce 2957
e4de825e
RR
2958 return true;
2959}
2960
7857346a 2961gboolean wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource *WXUNUSED(drag_source),
f6f0ef85
RR
2962 GtkTreePath *path )
2963{
591cc82d 2964 delete m_dragDataObject;
8c2654ce 2965
f6f0ef85
RR
2966 GtkTreeIter iter;
2967 if (!get_iter( &iter, path )) return FALSE;
f6f0ef85
RR
2968 wxDataViewItem item( (void*) iter.user_data );
2969
591cc82d 2970 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG, m_owner->GetId() );
e4de825e 2971 event.SetEventObject( m_owner );
15cac64f
RR
2972 event.SetItem( item );
2973 event.SetModel( m_wx_model );
591cc82d
RR
2974 if (!m_owner->HandleWindowEvent( event ))
2975 return FALSE;
8c2654ce 2976
591cc82d
RR
2977 if (!event.IsAllowed())
2978 return FALSE;
8c2654ce 2979
591cc82d
RR
2980 wxDataObject *obj = event.GetDataObject();
2981 if (!obj)
2982 return FALSE;
8c2654ce 2983
591cc82d 2984 m_dragDataObject = obj;
8c2654ce 2985
591cc82d 2986 return TRUE;
f6f0ef85
RR
2987}
2988
7857346a
VZ
2989gboolean
2990wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource *WXUNUSED(drag_source),
2991 GtkTreePath *WXUNUSED(path))
f6f0ef85
RR
2992{
2993 return FALSE;
2994}
2995
7857346a 2996gboolean wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource *WXUNUSED(drag_source),
f6f0ef85
RR
2997 GtkTreePath *path, GtkSelectionData *selection_data )
2998{
2999 GtkTreeIter iter;
3000 if (!get_iter( &iter, path )) return FALSE;
f6f0ef85 3001 wxDataViewItem item( (void*) iter.user_data );
7857346a 3002
591cc82d
RR
3003 if (!m_dragDataObject->IsSupported( selection_data->target ))
3004 return FALSE;
7857346a 3005
591cc82d
RR
3006 size_t size = m_dragDataObject->GetDataSize( selection_data->target );
3007 if (size == 0)
3008 return FALSE;
8c2654ce 3009
591cc82d 3010 void *buf = malloc( size );
8c2654ce 3011
15cac64f 3012 gboolean res = FALSE;
591cc82d 3013 if (m_dragDataObject->GetDataHere( selection_data->target, buf ))
15cac64f 3014 {
15cac64f 3015 res = TRUE;
8c2654ce 3016
591cc82d
RR
3017 gtk_selection_data_set( selection_data, selection_data->target,
3018 8, (const guchar*) buf, size );
15cac64f 3019 }
f6f0ef85 3020
591cc82d 3021 free( buf );
7857346a 3022
15cac64f 3023 return res;
f6f0ef85
RR
3024}
3025
7857346a
VZ
3026gboolean
3027wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest *WXUNUSED(drag_dest),
e4de825e
RR
3028 GtkTreePath *path,
3029 GtkSelectionData *selection_data)
f6f0ef85 3030{
e4de825e
RR
3031 GtkTreeIter iter;
3032 if (!get_iter( &iter, path )) return FALSE;
3033 wxDataViewItem item( (void*) iter.user_data );
8c2654ce 3034
e4de825e
RR
3035 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP, m_owner->GetId() );
3036 event.SetEventObject( m_owner );
3037 event.SetItem( item );
3038 event.SetModel( m_wx_model );
3039 event.SetDataFormat( selection_data->target );
3040 event.SetDataSize( selection_data->length );
3041 event.SetDataBuffer( selection_data->data );
3042 if (!m_owner->HandleWindowEvent( event ))
3043 return FALSE;
8c2654ce 3044
e4de825e
RR
3045 if (!event.IsAllowed())
3046 return FALSE;
3047
3048 return TRUE;
f6f0ef85
RR
3049}
3050
7857346a
VZ
3051gboolean
3052wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest *WXUNUSED(drag_dest),
e4de825e
RR
3053 GtkTreePath *path,
3054 GtkSelectionData *selection_data)
f6f0ef85 3055{
e4de825e
RR
3056 GtkTreeIter iter;
3057 if (!get_iter( &iter, path )) return FALSE;
3058 wxDataViewItem item( (void*) iter.user_data );
8c2654ce 3059
e4de825e
RR
3060 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE, m_owner->GetId() );
3061 event.SetEventObject( m_owner );
3062 event.SetItem( item );
3063 event.SetModel( m_wx_model );
3064 event.SetDataFormat( selection_data->target );
3065 if (!m_owner->HandleWindowEvent( event ))
3066 return FALSE;
8c2654ce 3067
e4de825e
RR
3068 if (!event.IsAllowed())
3069 return FALSE;
8c2654ce 3070
e4de825e 3071 return TRUE;
f6f0ef85
RR
3072}
3073
3074// notifications from wxDataViewModel
3075
33ba5a05
RR
3076bool wxDataViewCtrlInternal::Cleared()
3077{
3078 if (m_root)
3079 {
3080 delete m_root;
3081 InitTree();
7857346a
VZ
3082 }
3083
33ba5a05
RR
3084 // Create new GTK model
3085 g_object_unref( m_gtk_model );
3086 m_gtk_model = wxgtk_tree_model_new();
3087 m_gtk_model->internal = this;
7857346a 3088
33ba5a05
RR
3089 return true;
3090}
3091
4508fcd2
RR
3092void wxDataViewCtrlInternal::Resort()
3093{
e39de702 3094 if (!m_wx_model->IsVirtualListModel())
2056dede 3095 m_root->Resort();
4508fcd2
RR
3096}
3097
55fbde12
RR
3098bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item )
3099{
e39de702 3100 if (!m_wx_model->IsVirtualListModel())
2056dede
RR
3101 {
3102 wxGtkTreeModelNode *parent_node = FindNode( parent );
3103 if (m_wx_model->IsContainer( item ))
3104 parent_node->AddNode( new wxGtkTreeModelNode( parent_node, item, this ) );
3105 else
3106 parent_node->AddLeave( item.GetID() );
3107 }
b9db5f30 3108
55fbde12
RR
3109 return true;
3110}
3111
469d3e9b 3112bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item )
55fbde12 3113{
e39de702 3114 if (!m_wx_model->IsVirtualListModel())
2056dede
RR
3115 {
3116 wxGtkTreeModelNode *parent_node = FindNode( parent );
3117 parent_node->DeleteChild( item.GetID() );
3118 }
b9db5f30 3119
d8331a01
RR
3120 return true;
3121}
3122
3123bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem &item )
3124{
6608fdab 3125 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, m_owner->GetId() );
d8331a01
RR
3126 event.SetEventObject( m_owner );
3127 event.SetModel( m_owner->GetModel() );
3128 event.SetItem( item );
937013e0 3129 m_owner->HandleWindowEvent( event );
b9db5f30 3130
d8331a01
RR
3131 return true;
3132}
3133
3134bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem &item, unsigned int col )
3135{
6608fdab 3136 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, m_owner->GetId() );
d8331a01
RR
3137 event.SetEventObject( m_owner );
3138 event.SetModel( m_owner->GetModel() );
3139 event.SetColumn( col );
6608fdab 3140 event.SetDataViewColumn( GetOwner()->GetColumn(col) );
d8331a01 3141 event.SetItem( item );
937013e0 3142 m_owner->HandleWindowEvent( event );
b9db5f30 3143
d8331a01
RR
3144 return true;
3145}
3146
f6f0ef85
RR
3147// GTK+ model iface
3148
2056dede
RR
3149GtkTreeModelFlags wxDataViewCtrlInternal::get_flags()
3150{
e39de702 3151 if (m_wx_model->IsVirtualListModel())
2056dede
RR
3152 return GTK_TREE_MODEL_LIST_ONLY;
3153 else
3154 return GTK_TREE_MODEL_ITERS_PERSIST;
3155}
3156
55fbde12
RR
3157gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path )
3158{
e39de702 3159 if (m_wx_model->IsVirtualListModel())
2056dede
RR
3160 {
3161 wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
b9db5f30 3162
2056dede
RR
3163 unsigned int i = (unsigned int)gtk_tree_path_get_indices (path)[0];
3164
f52984b8 3165 if (i >= wx_model->GetLastIndex() + 1)
2056dede 3166 return FALSE;
55fbde12 3167
2056dede
RR
3168 iter->stamp = m_gtk_model->stamp;
3169 // user_data is just the index
3170 iter->user_data = (gpointer) i;
55fbde12 3171
2056dede
RR
3172 return TRUE;
3173 }
3174 else
55fbde12 3175 {
2056dede
RR
3176 int depth = gtk_tree_path_get_depth( path );
3177
3178 wxGtkTreeModelNode *node = m_root;
3179
3180 int i;
b9db5f30 3181 for (i = 0; i < depth; i++)
2056dede
RR
3182 {
3183 BuildBranch( node );
b9db5f30 3184
2056dede
RR
3185 gint pos = gtk_tree_path_get_indices (path)[i];
3186 if (pos < 0) return FALSE;
3187 if ((size_t)pos >= node->GetChildCount()) return FALSE;
b9db5f30 3188
2056dede 3189 void* id = node->GetChildren().Item( (size_t) pos );
b9db5f30 3190
2056dede 3191 if (i == depth-1)
af110130 3192 {
2056dede
RR
3193 iter->stamp = m_gtk_model->stamp;
3194 iter->user_data = id;
3195 return TRUE;
af110130 3196 }
2056dede
RR
3197
3198 size_t count = node->GetNodes().GetCount();
3199 size_t pos2;
3200 for (pos2 = 0; pos2 < count; pos2++)
3201 {
3202 wxGtkTreeModelNode *child_node = node->GetNodes().Item( pos2 );
3203 if (child_node->GetItem().GetID() == id)
3204 {
3205 node = child_node;
3206 break;
3207 }
b9db5f30 3208 }
2056dede 3209 }
af110130 3210 }
55fbde12 3211
af110130 3212 return FALSE;
55fbde12
RR
3213}
3214
3215GtkTreePath *wxDataViewCtrlInternal::get_path( GtkTreeIter *iter )
3216{
3217 GtkTreePath *retval = gtk_tree_path_new ();
b9db5f30 3218
e39de702 3219 if (m_wx_model->IsVirtualListModel())
2056dede
RR
3220 {
3221 // user_data is just the index
3222 int i = (wxUIntPtr) iter->user_data;
3223 gtk_tree_path_append_index (retval, i);
3224 }
3225 else
55fbde12 3226 {
b9db5f30
VS
3227 void *id = iter->user_data;
3228
2056dede
RR
3229 wxGtkTreeModelNode *node = FindParentNode( iter );
3230 while (node)
3231 {
3232 int pos = node->GetChildren().Index( id );
40196b1e 3233
2056dede 3234 gtk_tree_path_prepend_index( retval, pos );
b9db5f30 3235
2056dede
RR
3236 id = node->GetItem().GetID();
3237 node = node->GetParent();
3238 }
55fbde12 3239 }
b9db5f30 3240
55fbde12
RR
3241 return retval;
3242}
3243
3244gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter )
3245{
e39de702 3246 if (m_wx_model->IsVirtualListModel())
2056dede
RR
3247 {
3248 wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
b9db5f30 3249
2056dede 3250 int n = (wxUIntPtr) iter->user_data;
69892729 3251
2056dede
RR
3252 if (n == -1)
3253 return FALSE;
40196b1e 3254
f52984b8 3255 if (n >= (int) wx_model->GetLastIndex())
2056dede
RR
3256 return FALSE;
3257
3258 iter->user_data = (gpointer) ++n;
3259 }
3260 else
3261 {
3262 wxGtkTreeModelNode *parent = FindParentNode( iter );
3263 if( parent == NULL )
3264 return FALSE;
3265
3266 int pos = parent->GetChildren().Index( iter->user_data );
3267
3268 if (pos == (int) parent->GetChildCount()-1)
3269 return FALSE;
b9db5f30 3270
2056dede
RR
3271 iter->stamp = m_gtk_model->stamp;
3272 iter->user_data = parent->GetChildren().Item( pos+1 );
3273 }
55fbde12
RR
3274
3275 return TRUE;
3276}
3277
3278gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter *parent )
3279{
e39de702 3280 if (m_wx_model->IsVirtualListModel())
2056dede
RR
3281 {
3282 // this is a list, nodes have no children
3283 if (parent)
3284 return FALSE;
3285
3286 iter->stamp = m_gtk_model->stamp;
3287 iter->user_data = (gpointer) -1;
3288
3289 return TRUE;
3290 }
3291 else
3292 {
3293 wxDataViewItem item( (void*) parent->user_data );
b9db5f30 3294
2056dede
RR
3295 if (!m_wx_model->IsContainer( item ))
3296 return FALSE;
b9db5f30 3297
2056dede
RR
3298 wxGtkTreeModelNode *parent_node = FindNode( parent );
3299 BuildBranch( parent_node );
b9db5f30 3300
2056dede
RR
3301 if (parent_node->GetChildCount() == 0)
3302 return FALSE;
b9db5f30 3303
2056dede
RR
3304 iter->stamp = m_gtk_model->stamp;
3305 iter->user_data = (gpointer) parent_node->GetChildren().Item( 0 );
3306 }
b9db5f30 3307
55fbde12
RR
3308 return TRUE;
3309}
3310
3311gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter )
3312{
e39de702 3313 if (m_wx_model->IsVirtualListModel())
2056dede
RR
3314 {
3315 // this is a list, nodes have no children
3316 return FALSE;
3317 }
3318 else
3319 {
3320 wxDataViewItem item( (void*) iter->user_data );
b9db5f30 3321
2056dede 3322 bool is_container = m_wx_model->IsContainer( item );
b9db5f30 3323
2056dede
RR
3324 if (!is_container)
3325 return FALSE;
b9db5f30 3326
2056dede
RR
3327 wxGtkTreeModelNode *node = FindNode( iter );
3328 BuildBranch( node );
b9db5f30 3329
2056dede
RR
3330 return (node->GetChildCount() > 0);
3331 }
55fbde12
RR
3332}
3333
3334gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter )
3335{
e39de702 3336 if (m_wx_model->IsVirtualListModel())
2056dede
RR
3337 {
3338 wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
b9db5f30 3339
2056dede 3340 if (iter == NULL)
f52984b8 3341 return (gint) wx_model->GetLastIndex() + 1;
2056dede 3342
55fbde12 3343 return 0;
2056dede
RR
3344 }
3345 else
3346 {
11f20f99
RR
3347 if (iter == NULL)
3348 return m_root->GetChildCount();
3349
2056dede 3350 wxDataViewItem item( (void*) iter->user_data );
b9db5f30 3351
2056dede
RR
3352 if (!m_wx_model->IsContainer( item ))
3353 return 0;
b9db5f30 3354
2056dede
RR
3355 wxGtkTreeModelNode *parent_node = FindNode( iter );
3356 BuildBranch( parent_node );
ef427989 3357
2056dede 3358 // wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() );
b9db5f30 3359
2056dede
RR
3360 return parent_node->GetChildCount();
3361 }
55fbde12
RR
3362}
3363
3364gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter *parent, gint n )
3365{
e39de702 3366 if (m_wx_model->IsVirtualListModel())
2056dede
RR
3367 {
3368 wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
b9db5f30 3369
2056dede
RR
3370 if (parent)
3371 return FALSE;
3372
3373 if (n < 0)
3374 return FALSE;
3375
f52984b8 3376 if (n >= (gint) wx_model->GetLastIndex() + 1)
2056dede
RR
3377 return FALSE;
3378
3379 iter->stamp = m_gtk_model->stamp;
3380 iter->user_data = (gpointer) n;
3381
3382 return TRUE;
3383 }
3384 else
3385 {
3386 void* id = NULL;
3387 if (parent) id = (void*) parent->user_data;
3388 wxDataViewItem item( id );
b9db5f30 3389
2056dede
RR
3390 if (!m_wx_model->IsContainer( item ))
3391 return FALSE;
b9db5f30 3392
2056dede
RR
3393 wxGtkTreeModelNode *parent_node = FindNode( parent );
3394 BuildBranch( parent_node );
55fbde12 3395
2056dede 3396 // wxPrintf( "iter_nth_child %d\n", n );
b9db5f30 3397
2056dede
RR
3398 iter->stamp = m_gtk_model->stamp;
3399 iter->user_data = parent_node->GetChildren().Item( n );
55fbde12 3400
2056dede
RR
3401 return TRUE;
3402 }
55fbde12
RR
3403}
3404
3405gboolean wxDataViewCtrlInternal::iter_parent( GtkTreeIter *iter, GtkTreeIter *child )
3406{
e39de702 3407 if (m_wx_model->IsVirtualListModel())
2056dede 3408 {
55fbde12 3409 return FALSE;
2056dede
RR
3410 }
3411 else
3412 {
3413 wxGtkTreeModelNode *node = FindParentNode( child );
3414 if (!node)
3415 return FALSE;
b9db5f30 3416
2056dede
RR
3417 iter->stamp = m_gtk_model->stamp;
3418 iter->user_data = (gpointer) node->GetItem().GetID();
55fbde12 3419
2056dede
RR
3420 return TRUE;
3421 }
55fbde12 3422}
b9db5f30 3423
55fbde12 3424static wxGtkTreeModelNode*
69892729 3425wxDataViewCtrlInternal_FindNode( wxDataViewModel * model, wxGtkTreeModelNode *treeNode, const wxDataViewItem &item )
55fbde12 3426{
69892729
RR
3427 if( model == NULL )
3428 return NULL;
55fbde12 3429
69892729
RR
3430 ItemList list;
3431 list.DeleteContents( true );
3432 wxDataViewItem it( item );
b9db5f30 3433
69892729 3434 while( it.IsOk() )
55fbde12 3435 {
69892729
RR
3436 wxDataViewItem * pItem = new wxDataViewItem( it );
3437 list.Insert( pItem );
3438 it = model->GetParent( it );
3439 }
3440
3441 wxGtkTreeModelNode * node = treeNode;
966cb94d 3442 for( ItemList::compatibility_iterator n = list.GetFirst(); n; n = n->GetNext() )
69892729
RR
3443 {
3444 if( node && node->GetNodes().GetCount() != 0 )
ef427989 3445 {
69892729
RR
3446 int len = node->GetNodes().GetCount();
3447 wxGtkTreeModelNodes nodes = node->GetNodes();
3448 int j = 0;
3449 for( ; j < len; j ++)
3450 {
3451 if( nodes[j]->GetItem() == *(n->GetData()))
3452 {
3453 node = nodes[j];
3454 break;
b9db5f30 3455 }
69892729
RR
3456 }
3457
3458 if( j == len )
3459 {
3460 return NULL;
3461 }
ef427989 3462 }
69892729
RR
3463 else
3464 return NULL;
55fbde12 3465 }
69892729
RR
3466 return node;
3467
55fbde12
RR
3468}
3469
3470wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( GtkTreeIter *iter )
3471{
3472 if (!iter)
3473 return m_root;
3474
3475 wxDataViewItem item( (void*) iter->user_data );
0be79c8a
RR
3476 if (!item.IsOk())
3477 return m_root;
b9db5f30 3478
69892729 3479 wxGtkTreeModelNode *result = wxDataViewCtrlInternal_FindNode( m_wx_model, m_root, item );
b9db5f30 3480
55fbde12
RR
3481 if (!result)
3482 {
26f119eb 3483 wxLogDebug( "Not found %p", iter->user_data );
55fbde12
RR
3484 char *crash = NULL;
3485 *crash = 0;
3486 }
b9db5f30 3487
55fbde12
RR
3488 return result;
3489}
3490
3491wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( const wxDataViewItem &item )
3492{
0be79c8a
RR
3493 if (!item.IsOk())
3494 return m_root;
3495
69892729 3496 wxGtkTreeModelNode *result = wxDataViewCtrlInternal_FindNode( m_wx_model, m_root, item );
b9db5f30 3497
55fbde12
RR
3498 if (!result)
3499 {
26f119eb 3500 wxLogDebug( "Not found %p", item.GetID() );
55fbde12
RR
3501 char *crash = NULL;
3502 *crash = 0;
3503 }
b9db5f30 3504
55fbde12
RR
3505 return result;
3506}
3507
af110130 3508static wxGtkTreeModelNode*
69892729 3509wxDataViewCtrlInternal_FindParentNode( wxDataViewModel * model, wxGtkTreeModelNode *treeNode, const wxDataViewItem &item )
af110130 3510{
69892729
RR
3511 if( model == NULL )
3512 return NULL;
3513
3514 ItemList list;
3515 list.DeleteContents( true );
3516 if( !item.IsOk() )
3517 return NULL;
3518
3519 wxDataViewItem it( model->GetParent( item ) );
3520 while( it.IsOk() )
af110130 3521 {
69892729
RR
3522 wxDataViewItem * pItem = new wxDataViewItem( it );
3523 list.Insert( pItem );
3524 it = model->GetParent( it );
af110130
RR
3525 }
3526
69892729 3527 wxGtkTreeModelNode * node = treeNode;
966cb94d 3528 for( ItemList::compatibility_iterator n = list.GetFirst(); n; n = n->GetNext() )
af110130 3529 {
69892729 3530 if( node && node->GetNodes().GetCount() != 0 )
af110130 3531 {
69892729
RR
3532 int len = node->GetNodes().GetCount();
3533 wxGtkTreeModelNodes nodes = node->GetNodes();
3534 int j = 0;
3535 for( ; j < len; j ++)
3536 {
3537 if( nodes[j]->GetItem() == *(n->GetData()))
3538 {
3539 node = nodes[j];
3540 break;
b9db5f30 3541 }
69892729
RR
3542 }
3543
3544 if( j == len )
3545 {
3546 return NULL;
3547 }
af110130 3548 }
69892729
RR
3549 else
3550 return NULL;
3551 }
3552 //Examine whether the node is item's parent node
3553 int len = node->GetChildCount();
3554 for( int i = 0; i < len ; i ++ )
3555 {
3556 if( node->GetChildren().Item( i ) == item.GetID() )
3557 return node;
af110130 3558 }
af110130
RR
3559 return NULL;
3560}
3561
3562wxGtkTreeModelNode *wxDataViewCtrlInternal::FindParentNode( GtkTreeIter *iter )
3563{
3564 if (!iter)
3565 return NULL;
b9db5f30 3566
af110130
RR
3567 wxDataViewItem item( (void*) iter->user_data );
3568 if (!item.IsOk())
3569 return NULL;
3570
69892729 3571 return wxDataViewCtrlInternal_FindParentNode( m_wx_model, m_root, item );
af110130
RR
3572}
3573
3574wxGtkTreeModelNode *wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem &item )
3575{
3576 if (!item.IsOk())
3577 return NULL;
3578
69892729 3579 return wxDataViewCtrlInternal_FindParentNode( m_wx_model, m_root, item );
af110130
RR
3580}
3581
eb7f97f8
RR
3582//-----------------------------------------------------------------------------
3583// wxDataViewCtrl signal callbacks
3584//-----------------------------------------------------------------------------
3585
3586static void
ad386793 3587wxdataview_selection_changed_callback( GtkTreeSelection* WXUNUSED(selection), wxDataViewCtrl *dv )
eb7f97f8 3588{
b94db696
RR
3589 if (!GTK_WIDGET_REALIZED(dv->m_widget))
3590 return;
f4322df6 3591
d86c1870 3592 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, dv->GetId() );
6848478c 3593 event.SetItem( dv->GetSelection() );
eb7f97f8 3594 event.SetModel( dv->GetModel() );
937013e0 3595 dv->HandleWindowEvent( event );
eb7f97f8
RR
3596}
3597
f828871d 3598static void
ad386793
RR
3599wxdataview_row_activated_callback( GtkTreeView* WXUNUSED(treeview), GtkTreePath *path,
3600 GtkTreeViewColumn *WXUNUSED(column), wxDataViewCtrl *dv )
f828871d 3601{
e0062c04 3602 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, dv->GetId() );
55fbde12
RR
3603
3604 GtkTreeIter iter;
3605 dv->GtkGetInternal()->get_iter( &iter, path );
3606 wxDataViewItem item( (void*) iter.user_data );;
3607 event.SetItem( item );
f828871d 3608 event.SetModel( dv->GetModel() );
937013e0 3609 dv->HandleWindowEvent( event );
f828871d
RR
3610}
3611
718fd180 3612static gboolean
ad386793
RR
3613wxdataview_test_expand_row_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter,
3614 GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv )
718fd180
RR
3615{
3616 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, dv->GetId() );
3617
3618 wxDataViewItem item( (void*) iter->user_data );;
3619 event.SetItem( item );
3620 event.SetModel( dv->GetModel() );
937013e0 3621 dv->HandleWindowEvent( event );
b9db5f30 3622
718fd180
RR
3623 return !event.IsAllowed();
3624}
3625
3626static void
ad386793
RR
3627wxdataview_row_expanded_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter,
3628 GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv )
718fd180
RR
3629{
3630 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, dv->GetId() );
3631
3632 wxDataViewItem item( (void*) iter->user_data );;
3633 event.SetItem( item );
3634 event.SetModel( dv->GetModel() );
937013e0 3635 dv->HandleWindowEvent( event );
718fd180
RR
3636}
3637
3638static gboolean
ad386793
RR
3639wxdataview_test_collapse_row_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter,
3640 GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv )
718fd180
RR
3641{
3642 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, dv->GetId() );
3643
3644 wxDataViewItem item( (void*) iter->user_data );;
3645 event.SetItem( item );
3646 event.SetModel( dv->GetModel() );
937013e0 3647 dv->HandleWindowEvent( event );
b9db5f30 3648
718fd180
RR
3649 return !event.IsAllowed();
3650}
3651
3652static void
ad386793
RR
3653wxdataview_row_collapsed_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter,
3654 GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv )
718fd180
RR
3655{
3656 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, dv->GetId() );
3657
3658 wxDataViewItem item( (void*) iter->user_data );;
3659 event.SetItem( item );
3660 event.SetModel( dv->GetModel() );
937013e0 3661 dv->HandleWindowEvent( event );
718fd180
RR
3662}
3663
790b137e 3664//-----------------------------------------------------------------------------
718fd180 3665 // wxDataViewCtrl
790b137e
RR
3666//-----------------------------------------------------------------------------
3667
48200154 3668void wxDataViewCtrl::AddChildGTK(wxWindowGTK* child)
1e510b1e 3669{
48200154 3670 GtkWidget* treeview = GtkGetTreeView();
1e510b1e
RR
3671
3672 // Insert widget in GtkTreeView
3673 if (GTK_WIDGET_REALIZED(treeview))
e8375af8 3674 gtk_widget_set_parent_window( child->m_widget,
1e510b1e
RR
3675 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview) ) );
3676 gtk_widget_set_parent( child->m_widget, treeview );
3677}
3678
3679static
3680void gtk_dataviewctrl_size_callback( GtkWidget *WXUNUSED(widget),
ad386793 3681 GtkAllocation *WXUNUSED(gtk_alloc),
1e510b1e
RR
3682 wxDataViewCtrl *win )
3683{
966cb94d 3684 wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst();
1e510b1e
RR
3685 while (node)
3686 {
3687 wxWindow *child = node->GetData();
e8375af8 3688
1e510b1e
RR
3689 GtkRequisition req;
3690 gtk_widget_size_request( child->m_widget, &req );
e8375af8 3691
1e510b1e
RR
3692 GtkAllocation alloc;
3693 alloc.x = child->m_x;
3694 alloc.y = child->m_y;
3695 alloc.width = child->m_width;
3696 alloc.height = child->m_height;
3697 gtk_widget_size_allocate( child->m_widget, &alloc );
e8375af8 3698
1e510b1e
RR
3699 node = node->GetNext();
3700 }
3701}
3702
3703
6608fdab
RR
3704//-----------------------------------------------------------------------------
3705// "motion_notify_event"
3706//-----------------------------------------------------------------------------
3707
3708static gboolean
ad386793 3709gtk_dataview_motion_notify_callback( GtkWidget *WXUNUSED(widget),
74dea0de
RR
3710 GdkEventMotion *gdk_event,
3711 wxDataViewCtrl *dv )
6608fdab
RR
3712{
3713 if (gdk_event->is_hint)
3714 {
3715 int x = 0;
3716 int y = 0;
3717 GdkModifierType state;
3718 gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
3719 gdk_event->x = x;
3720 gdk_event->y = y;
3721 }
3722
3723 GtkTreePath *path = NULL;
3724 GtkTreeViewColumn *column = NULL;
3725 gint cell_x = 0;
3726 gint cell_y = 0;
b9db5f30 3727 if (gtk_tree_view_get_path_at_pos(
6608fdab
RR
3728 GTK_TREE_VIEW(dv->GtkGetTreeView()),
3729 (int) gdk_event->x, (int) gdk_event->y,
3730 &path,
3731 &column,
3732 &cell_x,
3733 &cell_y))
3734 {
3735 if (path)
3736 {
3737 GtkTreeIter iter;
3738 dv->GtkGetInternal()->get_iter( &iter, path );
b9db5f30 3739
6608fdab 3740 // wxPrintf( "mouse %d %d\n", (int) gdk_event->x, (int) gdk_event->y );
b9db5f30 3741
6608fdab
RR
3742 gtk_tree_path_free( path );
3743 }
3744 }
3745
3746
3747 return FALSE;
3748}
3749
74dea0de
RR
3750//-----------------------------------------------------------------------------
3751// "button_press_event"
3752//-----------------------------------------------------------------------------
3753
3754static gboolean
3755gtk_dataview_button_press_callback( GtkWidget *WXUNUSED(widget),
3756 GdkEventButton *gdk_event,
3757 wxDataViewCtrl *dv )
3758{
3759 if ((gdk_event->button == 3) && (gdk_event->type == GDK_BUTTON_PRESS))
3760 {
3761 GtkTreePath *path = NULL;
3762 GtkTreeViewColumn *column = NULL;
3763 gint cell_x = 0;
3764 gint cell_y = 0;
3765 if (gtk_tree_view_get_path_at_pos(
3766 GTK_TREE_VIEW(dv->GtkGetTreeView()),
3767 (int) gdk_event->x, (int) gdk_event->y,
3768 &path,
3769 &column,
3770 &cell_x,
3771 &cell_y))
3772 {
3773 if (path)
3774 {
3775 GtkTreeIter iter;
3776 dv->GtkGetInternal()->get_iter( &iter, path );
3777
3778 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, dv->GetId() );
3779 wxDataViewItem item( (void*) iter.user_data );;
3780 event.SetItem( item );
3781 event.SetModel( dv->GetModel() );
3782 bool ret = dv->HandleWindowEvent( event );
3783 gtk_tree_path_free( path );
3784 return ret;
3785 }
3786 }
3787 }
3788
3789 return FALSE;
3790}
1e510b1e 3791
239eaa41
RR
3792IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase)
3793
3794wxDataViewCtrl::~wxDataViewCtrl()
3795{
8f850e28
RR
3796 if (m_notifier)
3797 GetModel()->RemoveNotifier( m_notifier );
87f0efe2 3798
ef11ea71
RR
3799 m_cols.Clear();
3800
87f0efe2
RR
3801 // remove the model from the GtkTreeView before it gets destroyed by the
3802 // wxDataViewCtrlBase's dtor
3803 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview), NULL );
b9db5f30 3804
55fbde12 3805 delete m_internal;
239eaa41
RR
3806}
3807
3808void wxDataViewCtrl::Init()
3809{
8f850e28 3810 m_notifier = NULL;
33ba5a05 3811 m_internal = NULL;
bc0289bf 3812
ef11ea71 3813 m_cols.DeleteContents( true );
239eaa41
RR
3814}
3815
3816bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
93763ad5 3817 const wxPoint& pos, const wxSize& size,
239eaa41
RR
3818 long style, const wxValidator& validator )
3819{
3820 Init();
93763ad5 3821
239eaa41
RR
3822 if (!PreCreation( parent, pos, size ) ||
3823 !CreateBase( parent, id, pos, size, style, validator ))
3824 {
3825 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
93763ad5 3826 return false;
239eaa41 3827 }
1a367564
RR
3828
3829 m_widget = gtk_scrolled_window_new (NULL, NULL);
9ff9d30c 3830 g_object_ref(m_widget);
6493aaca 3831
496e7ec6 3832 GTKScrolledWindowSetBorder(m_widget, style);
1a367564
RR
3833
3834 m_treeview = gtk_tree_view_new();
3835 gtk_container_add (GTK_CONTAINER (m_widget), m_treeview);
e8375af8 3836
1e510b1e
RR
3837 g_signal_connect (m_treeview, "size_allocate",
3838 G_CALLBACK (gtk_dataviewctrl_size_callback), this);
ed4b0fdc 3839
b94db696
RR
3840#ifdef __WXGTK26__
3841 if (!gtk_check_version(2,6,0))
344ed1f3
RR
3842 {
3843 bool fixed = (style & wxDV_VARIABLE_LINE_HEIGHT) == 0;
3844 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), fixed );
3845 }
b94db696
RR
3846#endif
3847
daebb44c
RR
3848 if (style & wxDV_MULTIPLE)
3849 {
3850 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
3851 gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE );
3852 }
93763ad5 3853
9861f022
RR
3854 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview), (style & wxDV_NO_HEADER) == 0 );
3855
3856#ifdef __WXGTK210__
3857 if (!gtk_check_version(2,10,0))
3858 {
3859 GtkTreeViewGridLines grid = GTK_TREE_VIEW_GRID_LINES_NONE;
f4322df6
VZ
3860
3861 if ((style & wxDV_HORIZ_RULES) != 0 &&
9861f022
RR
3862 (style & wxDV_VERT_RULES) != 0)
3863 grid = GTK_TREE_VIEW_GRID_LINES_BOTH;
3864 else if (style & wxDV_VERT_RULES)
3865 grid = GTK_TREE_VIEW_GRID_LINES_VERTICAL;
3866 else if (style & wxDV_HORIZ_RULES)
3867 grid = GTK_TREE_VIEW_GRID_LINES_HORIZONTAL;
3868
1a07a730
RR
3869 if (grid != GTK_TREE_VIEW_GRID_LINES_NONE)
3870 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview), grid );
9861f022 3871 }
9861f022 3872#endif
1a07a730
RR
3873
3874 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview), (style & wxDV_ROW_LINES) != 0 );
9861f022 3875
1a367564 3876 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget),
16eab2e1 3877 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1a367564 3878 gtk_widget_show (m_treeview);
93763ad5 3879
239eaa41
RR
3880 m_parent->DoAddChild( this );
3881
b94db696
RR
3882 PostCreation(size);
3883
b086d55f
RR
3884 GtkEnableSelectionEvents();
3885
718fd180 3886 g_signal_connect_after (m_treeview, "row-activated",
f828871d 3887 G_CALLBACK (wxdataview_row_activated_callback), this);
eb7f97f8 3888
718fd180
RR
3889 g_signal_connect (m_treeview, "test-collapse-row",
3890 G_CALLBACK (wxdataview_test_collapse_row_callback), this);
3891
3892 g_signal_connect_after (m_treeview, "row-collapsed",
3893 G_CALLBACK (wxdataview_row_collapsed_callback), this);
3894
3895 g_signal_connect (m_treeview, "test-expand-row",
3896 G_CALLBACK (wxdataview_test_expand_row_callback), this);
b9db5f30 3897
718fd180
RR
3898 g_signal_connect_after (m_treeview, "row-expanded",
3899 G_CALLBACK (wxdataview_row_expanded_callback), this);
3900
6608fdab
RR
3901 g_signal_connect (m_treeview, "motion_notify_event",
3902 G_CALLBACK (gtk_dataview_motion_notify_callback), this);
3903
74dea0de
RR
3904 g_signal_connect (m_treeview, "button_press_event",
3905 G_CALLBACK (gtk_dataview_button_press_callback), this);
7857346a 3906
239eaa41
RR
3907 return true;
3908}
3909
31fb32e1
RR
3910void wxDataViewCtrl::OnInternalIdle()
3911{
3912 wxWindow::OnInternalIdle();
f4322df6 3913
9861f022 3914 unsigned int cols = GetColumnCount();
31fb32e1
RR
3915 unsigned int i;
3916 for (i = 0; i < cols; i++)
3917 {
3918 wxDataViewColumn *col = GetColumn( i );
3919 col->OnInternalIdle();
3920 }
3921}
3922
e0062c04 3923bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model )
239eaa41 3924{
33ba5a05
RR
3925 if (GetModel())
3926 {
3927 delete m_internal;
3928 m_internal = NULL;
7857346a 3929
33ba5a05
RR
3930 delete m_notifier;
3931 m_notifier = NULL;
3932 }
7857346a 3933
239eaa41
RR
3934 if (!wxDataViewCtrlBase::AssociateModel( model ))
3935 return false;
3936
344ed1f3
RR
3937#ifdef __WXGTK26__
3938 if (!gtk_check_version(2,6,0))
3939 {
3940 bool fixed = (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) == 0) || (model->IsVirtualListModel()));
3941 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), fixed );
3942 }
3943#endif
3944
55fbde12
RR
3945 GtkWxTreeModel *gtk_model = wxgtk_tree_model_new();
3946 m_internal = new wxDataViewCtrlInternal( this, model, gtk_model );
3947 gtk_model->internal = m_internal;
6e2e590f 3948
55fbde12 3949 m_notifier = new wxGtkDataViewModelNotifier( gtk_model, model, this );
6e2e590f 3950
93763ad5 3951 model->AddNotifier( m_notifier );
1557c77b 3952
55fbde12 3953 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview), GTK_TREE_MODEL(gtk_model) );
b9db5f30 3954
55fbde12
RR
3955 // unref in wxDataViewCtrlInternal
3956 // g_object_unref( gtk_model );
93763ad5 3957
239eaa41
RR
3958 return true;
3959}
790b137e 3960
15cac64f
RR
3961bool wxDataViewCtrl::EnableDragSource( const wxDataFormat &format )
3962{
3963 return m_internal->EnableDragSource( format );
3964}
3965
e4de825e
RR
3966bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat &format )
3967{
3968 return m_internal->EnableDropTarget( format );
3969}
3970
fa28826d
RR
3971bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col )
3972{
3973 if (!wxDataViewCtrlBase::AppendColumn(col))
3974 return false;
93763ad5 3975
91a6c655
RR
3976 m_cols.Append( col );
3977
ad386793
RR
3978#ifdef __WXGTK26__
3979 if (!gtk_check_version(2,6,0))
3980 {
3981 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) ) !=
3982 GTK_TREE_VIEW_COLUMN_FIXED)
3983 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), FALSE );
3984 }
3985#endif
3986
b9db5f30 3987 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview),
91a6c655
RR
3988 GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) );
3989
3990 return true;
3991}
3992
736fe67c
RR
3993bool wxDataViewCtrl::PrependColumn( wxDataViewColumn *col )
3994{
3995 if (!wxDataViewCtrlBase::PrependColumn(col))
3996 return false;
3997
3998 m_cols.Insert( col );
3999
ad386793
RR
4000#ifdef __WXGTK26__
4001 if (!gtk_check_version(2,6,0))
4002 {
4003 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) ) !=
4004 GTK_TREE_VIEW_COLUMN_FIXED)
4005 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), FALSE );
4006 }
4007#endif
4008
b9db5f30 4009 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview),
736fe67c
RR
4010 GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()), 0 );
4011
4012 return true;
4013}
4014
19723525
RR
4015bool wxDataViewCtrl::InsertColumn( unsigned int pos, wxDataViewColumn *col )
4016{
4017 if (!wxDataViewCtrlBase::InsertColumn(pos,col))
4018 return false;
4019
4020 m_cols.Insert( pos, col );
4021
4022#ifdef __WXGTK26__
4023 if (!gtk_check_version(2,6,0))
4024 {
4025 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) ) !=
4026 GTK_TREE_VIEW_COLUMN_FIXED)
4027 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), FALSE );
4028 }
4029#endif
4030
4031 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview),
4032 GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()), pos );
4033
4034 return true;
4035}
4036
91a6c655
RR
4037unsigned int wxDataViewCtrl::GetColumnCount() const
4038{
4039 return m_cols.GetCount();
4040}
4041
4042wxDataViewColumn* wxDataViewCtrl::GetColumn( unsigned int pos ) const
4043{
4044 GtkTreeViewColumn *gtk_col = gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview), pos );
4045 if (!gtk_col)
4046 return NULL;
b9db5f30 4047
91a6c655 4048 wxDataViewColumnList::const_iterator iter;
ef11ea71 4049 for (iter = m_cols.begin(); iter != m_cols.end(); ++iter)
91a6c655
RR
4050 {
4051 wxDataViewColumn *col = *iter;
4052 if (GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) == gtk_col)
4053 {
4054 return col;
4055 }
4056 }
b9db5f30 4057
91a6c655
RR
4058 return NULL;
4059}
4060
4061bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn *column )
4062{
b9db5f30 4063 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview),
91a6c655
RR
4064 GTK_TREE_VIEW_COLUMN(column->GetGtkHandle()) );
4065
ef11ea71 4066 m_cols.DeleteObject( column );
fa28826d
RR
4067
4068 return true;
4069}
4070
91a6c655
RR
4071bool wxDataViewCtrl::ClearColumns()
4072{
4073 wxDataViewColumnList::iterator iter;
ef11ea71 4074 for (iter = m_cols.begin(); iter != m_cols.end(); ++iter)
91a6c655
RR
4075 {
4076 wxDataViewColumn *col = *iter;
b9db5f30 4077 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview),
91a6c655
RR
4078 GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) );
4079 }
b9db5f30 4080
ef11ea71 4081 m_cols.Clear();
b9db5f30 4082
91a6c655
RR
4083 return true;
4084}
4085
453091c2
RR
4086int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn *column ) const
4087{
aed836f3
RR
4088 GtkTreeViewColumn *gtk_column = GTK_TREE_VIEW_COLUMN(column->GetConstGtkHandle());
4089
4090 GList *list = gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview) );
b9db5f30 4091
aed836f3 4092 gint pos = g_list_index( list, (gconstpointer) gtk_column );
b9db5f30 4093
aed836f3
RR
4094 g_list_free( list );
4095
4096 return pos;
453091c2
RR
4097}
4098
21f47fb9
RR
4099wxDataViewColumn *wxDataViewCtrl::GetSortingColumn() const
4100{
d32332aa 4101 return m_internal->GetDataViewSortColumn();
21f47fb9
RR
4102}
4103
f71d3ba4
RR
4104void wxDataViewCtrl::Expand( const wxDataViewItem & item )
4105{
4106 GtkTreeIter iter;
4107 iter.user_data = item.GetID();
4108 GtkTreePath *path = m_internal->get_path( &iter );
4109 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview), path, false );
4110 gtk_tree_path_free( path );
4111}
4112
4113void wxDataViewCtrl::Collapse( const wxDataViewItem & item )
4114{
4115 GtkTreeIter iter;
4116 iter.user_data = item.GetID();
4117 GtkTreePath *path = m_internal->get_path( &iter );
4118 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview), path );
4119 gtk_tree_path_free( path );
739a8399
RR
4120}
4121
4122bool wxDataViewCtrl::IsExpanded( const wxDataViewItem & item ) const
4123{
4124 GtkTreeIter iter;
4125 iter.user_data = item.GetID();
4126 GtkTreePath *path = m_internal->get_path( &iter );
10ab6d4f 4127 bool res = gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview), path );
739a8399 4128 gtk_tree_path_free( path );
8c2654ce 4129
10ab6d4f 4130 return res;
f71d3ba4
RR
4131}
4132
fbda518c 4133wxDataViewItem wxDataViewCtrl::GetSelection() const
1e08ad10
RR
4134{
4135 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
b9db5f30 4136
1e08ad10
RR
4137 if (m_windowStyle & wxDV_MULTIPLE)
4138 {
6848478c
RR
4139 // Report the first one
4140 GtkTreeModel *model;
4141 GList *list = gtk_tree_selection_get_selected_rows( selection, &model );
b9db5f30 4142
6848478c
RR
4143 if (list)
4144 {
4145 GtkTreePath *path = (GtkTreePath*) list->data;
4146 GtkTreeIter iter;
4147 m_internal->get_iter( &iter, path );
b9db5f30 4148
6848478c
RR
4149 // delete list
4150 g_list_foreach( list, (GFunc) gtk_tree_path_free, NULL );
4151 g_list_free( list );
b9db5f30 4152
6848478c
RR
4153 return wxDataViewItem( (void*) iter.user_data );
4154 }
1e08ad10
RR
4155 }
4156 else
4157 {
4158 GtkTreeIter iter;
4159 if (gtk_tree_selection_get_selected( selection, NULL, &iter ))
4160 {
9d52aad3 4161 wxDataViewItem item( (void*) iter.user_data );
1e08ad10
RR
4162 return item;
4163 }
4164 }
b9db5f30 4165
1e08ad10
RR
4166 return wxDataViewItem(0);
4167}
4168
718fd180
RR
4169int wxDataViewCtrl::GetSelections( wxDataViewItemArray & sel ) const
4170{
6848478c
RR
4171 sel.Clear();
4172
4173 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
4174 if (HasFlag(wxDV_MULTIPLE))
4175 {
4176 GtkTreeModel *model;
4177 GList *list = gtk_tree_selection_get_selected_rows( selection, &model );
4178
4179 int count = 0;
4180 while (list)
4181 {
4182 GtkTreePath *path = (GtkTreePath*) list->data;
b9db5f30 4183
6848478c
RR
4184 GtkTreeIter iter;
4185 m_internal->get_iter( &iter, path );
4186
4187 sel.Add( wxDataViewItem( (void*) iter.user_data ) );
4188
4189 list = g_list_next( list );
4190 count++;
4191 }
4192
4193 // delete list
4194 g_list_foreach( list, (GFunc) gtk_tree_path_free, NULL );
4195 g_list_free( list );
4196
4197 return count;
4198 }
4199 else
4200 {
4201 GtkTreeModel *model;
4202 GtkTreeIter iter;
4203 gboolean has_selection = gtk_tree_selection_get_selected( selection, &model, &iter );
4204 if (has_selection)
4205 {
4206 sel.Add( wxDataViewItem( (void*) iter.user_data) );
4207 return 1;
4208 }
4209 }
4210
718fd180
RR
4211 return 0;
4212}
4213
4214void wxDataViewCtrl::SetSelections( const wxDataViewItemArray & sel )
4215{
6848478c 4216 GtkDisableSelectionEvents();
b9db5f30 4217
6848478c
RR
4218 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
4219
4220 gtk_tree_selection_unselect_all( selection );
b9db5f30 4221
4219d8b0
RR
4222 wxDataViewItem last_parent;
4223
6848478c
RR
4224 size_t i;
4225 for (i = 0; i < sel.GetCount(); i++)
4226 {
4219d8b0
RR
4227 wxDataViewItem item = sel[i];
4228 wxDataViewItem parent = GetModel()->GetParent( item );
4229 if (parent)
4230 {
4231 if (parent != last_parent)
4232 ExpandAncestors(item);
4233 }
4234 last_parent = parent;
4235
6848478c 4236 GtkTreeIter iter;
0e50223f 4237 iter.stamp = m_internal->GetGtkModel()->stamp;
4219d8b0 4238 iter.user_data = (gpointer) item.GetID();
6848478c
RR
4239 gtk_tree_selection_select_iter( selection, &iter );
4240 }
b9db5f30 4241
6848478c 4242 GtkEnableSelectionEvents();
718fd180
RR
4243}
4244
4245void wxDataViewCtrl::Select( const wxDataViewItem & item )
4246{
4219d8b0
RR
4247 ExpandAncestors(item);
4248
6848478c
RR
4249 GtkDisableSelectionEvents();
4250
4251 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
4252
4253 GtkTreeIter iter;
0e50223f 4254 iter.stamp = m_internal->GetGtkModel()->stamp;
6848478c
RR
4255 iter.user_data = (gpointer) item.GetID();
4256 gtk_tree_selection_select_iter( selection, &iter );
4257
4258 GtkEnableSelectionEvents();
718fd180
RR
4259}
4260
4261void wxDataViewCtrl::Unselect( const wxDataViewItem & item )
4262{
6848478c
RR
4263 GtkDisableSelectionEvents();
4264
4265 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
4266
4267 GtkTreeIter iter;
0e50223f 4268 iter.stamp = m_internal->GetGtkModel()->stamp;
6848478c
RR
4269 iter.user_data = (gpointer) item.GetID();
4270 gtk_tree_selection_unselect_iter( selection, &iter );
4271
4272 GtkEnableSelectionEvents();
718fd180
RR
4273}
4274
4275bool wxDataViewCtrl::IsSelected( const wxDataViewItem & item ) const
4276{
6848478c
RR
4277 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
4278
4279 GtkTreeIter iter;
0e50223f 4280 iter.stamp = m_internal->GetGtkModel()->stamp;
6848478c 4281 iter.user_data = (gpointer) item.GetID();
b9db5f30 4282
6848478c 4283 return gtk_tree_selection_iter_is_selected( selection, &iter );
718fd180
RR
4284}
4285
4286void wxDataViewCtrl::SelectAll()
4287{
6848478c 4288 GtkDisableSelectionEvents();
b9db5f30 4289
6848478c 4290 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
b9db5f30 4291
6848478c 4292 gtk_tree_selection_select_all( selection );
b9db5f30 4293
6848478c 4294 GtkEnableSelectionEvents();
718fd180
RR
4295}
4296
4297void wxDataViewCtrl::UnselectAll()
4298{
6848478c 4299 GtkDisableSelectionEvents();
b9db5f30 4300
6848478c 4301 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
b9db5f30 4302
6848478c 4303 gtk_tree_selection_unselect_all( selection );
b9db5f30 4304
6848478c 4305 GtkEnableSelectionEvents();
718fd180
RR
4306}
4307
7857346a 4308void wxDataViewCtrl::EnsureVisible(const wxDataViewItem& item,
4219d8b0 4309 const wxDataViewColumn *WXUNUSED(column))
718fd180 4310{
4219d8b0 4311 ExpandAncestors(item);
a881f34e 4312
6154212e
RR
4313 GtkTreeIter iter;
4314 iter.user_data = (gpointer) item.GetID();
4315 GtkTreePath *path = m_internal->get_path( &iter );
4316 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview), path, NULL, false, 0.0, 0.0 );
4317 gtk_tree_path_free( path );
718fd180
RR
4318}
4319
7857346a
VZ
4320void wxDataViewCtrl::HitTest(const wxPoint& WXUNUSED(point),
4321 wxDataViewItem& item,
4322 wxDataViewColumn *& column) const
66e09788
RR
4323{
4324 item = wxDataViewItem(0);
a87b466d 4325 column = NULL;
66e09788
RR
4326}
4327
7857346a
VZ
4328wxRect
4329wxDataViewCtrl::GetItemRect(const wxDataViewItem& WXUNUSED(item),
4330 const wxDataViewColumn *WXUNUSED(column)) const
66e09788
RR
4331{
4332 return wxRect();
4333}
4334
3b6280be
RR
4335void wxDataViewCtrl::DoSetExpanderColumn()
4336{
b9db5f30 4337 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview),
1b27b2bd 4338 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
3b6280be
RR
4339}
4340
4341void wxDataViewCtrl::DoSetIndent()
4342{
4343}
4344
b086d55f
RR
4345void wxDataViewCtrl::GtkDisableSelectionEvents()
4346{
4347 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
6848478c
RR
4348 g_signal_handlers_disconnect_by_func( selection,
4349 (gpointer) (wxdataview_selection_changed_callback), this);
b086d55f
RR
4350}
4351
4352void wxDataViewCtrl::GtkEnableSelectionEvents()
4353{
4354 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
6848478c
RR
4355 g_signal_connect_after (selection, "changed",
4356 G_CALLBACK (wxdataview_selection_changed_callback), this);
b086d55f
RR
4357}
4358
b94db696
RR
4359// static
4360wxVisualAttributes
4361wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
4362{
4363 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new);
4364}
4365
6ff7eee7 4366
93763ad5 4367#endif
4ed7af08 4368 // !wxUSE_GENERICDATAVIEWCTRL
790b137e 4369
93763ad5 4370#endif
4ed7af08 4371 // wxUSE_DATAVIEWCTRL