]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/dataview.cpp
e8025a76a8a96454c9e6706b7e32a0812bba67df
[wxWidgets.git] / src / gtk / dataview.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/dataview.cpp
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
13 #if wxUSE_DATAVIEWCTRL
14
15 #include "wx/dataview.h"
16
17 #ifndef wxUSE_GENERICDATAVIEWCTRL
18
19 #ifndef WX_PRECOMP
20 #include "wx/log.h"
21 #include "wx/dcclient.h"
22 #include "wx/sizer.h"
23 #include "wx/settings.h"
24 #include "wx/crt.h"
25 #endif
26
27 #include "wx/stockitem.h"
28 #include "wx/popupwin.h"
29 #include "wx/listimpl.cpp"
30
31 #include "wx/gtk/private.h"
32 #include "wx/gtk/dc.h"
33 #include "wx/gtk/dcclient.h"
34
35 #include "wx/gtk/private/gdkconv.h"
36 #include "wx/gtk/private/list.h"
37 using namespace wxGTKImpl;
38
39 class wxGtkDataViewModelNotifier;
40
41 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
43
44 static wxDataViewCtrlInternal *gs_internal = NULL;
45
46 class wxGtkTreeModelNode;
47
48 extern "C" {
49 typedef struct _GtkWxTreeModel GtkWxTreeModel;
50 }
51
52 // ----------------------------------------------------------------------------
53 // wxGtkTreePath: self-destroying GtkTreePath
54 // ----------------------------------------------------------------------------
55
56 // Usually this object is initialized with the associated GtkTreePath
57 // immediately when it's constructed but it can also be changed later either by
58 // using Assign() or by getting the pointer to the internally stored pointer
59 // value using ByRef(). The latter should be avoided but is very convenient
60 // when using GTK functions with GtkTreePath output parameters.
61 class wxGtkTreePath
62 {
63 public:
64 // Ctor takes ownership of the given path and will free it if non-NULL.
65 wxGtkTreePath(GtkTreePath *path = NULL) : m_path(path) { }
66
67 // Creates a tree path for the given string path.
68 wxGtkTreePath(const gchar *strpath)
69 : m_path(gtk_tree_path_new_from_string(strpath))
70 {
71 }
72
73 // Set the stored pointer if not done by ctor.
74 void Assign(GtkTreePath *path)
75 {
76 wxASSERT_MSG( !m_path, "shouldn't be already initialized" );
77
78 m_path = path;
79 }
80
81 // Return the pointer to the internally stored pointer. This should only be
82 // used to initialize the object by passing it to some GTK function.
83 GtkTreePath **ByRef()
84 {
85 wxASSERT_MSG( !m_path, "shouldn't be already initialized" );
86
87 return &m_path;
88 }
89
90
91 operator GtkTreePath *() const { return m_path; }
92
93 ~wxGtkTreePath() { if ( m_path ) gtk_tree_path_free(m_path); }
94
95 private:
96 GtkTreePath *m_path;
97
98 wxDECLARE_NO_COPY_CLASS(wxGtkTreePath);
99 };
100
101 // ----------------------------------------------------------------------------
102 // wxGtkTreePathList: self-destroying list of GtkTreePath objects.
103 // ----------------------------------------------------------------------------
104
105 class wxGtkTreePathList : public wxGtkList
106 {
107 public:
108 // Ctor takes ownership of the list.
109 explicit wxGtkTreePathList(GList* list)
110 : wxGtkList(list)
111 {
112 }
113
114 ~wxGtkTreePathList()
115 {
116 // Delete the list contents, wxGtkList will delete the list itself.
117 g_list_foreach(m_list, (GFunc)gtk_tree_path_free, NULL);
118 }
119 };
120
121 // ----------------------------------------------------------------------------
122 // wxGtkTreeSelectionLock: prevent selection from changing during the
123 // lifetime of this object
124 // ----------------------------------------------------------------------------
125
126 // Implementation note: it could be expected that setting the selection
127 // function in this class ctor and resetting it back to the old value in its
128 // dtor would work. However currently gtk_tree_selection_get_select_function()
129 // can't be passed NULL (see https://bugzilla.gnome.org/show_bug.cgi?id=626276)
130 // so we can't do this. Instead, we always use the selection function (which
131 // imposes extra overhead, albeit minimal one, on all selection operations) and
132 // just set/reset the flag telling it whether it should allow or forbid the
133 // selection.
134 //
135 // Also notice that currently only a single object of this class may exist at
136 // any given moment. It's just simpler like this and we don't need anything
137 // more for now.
138
139 extern "C"
140 gboolean wxdataview_selection_func(GtkTreeSelection * WXUNUSED(selection),
141 GtkTreeModel * WXUNUSED(model),
142 GtkTreePath * WXUNUSED(path),
143 gboolean WXUNUSED(path_currently_selected),
144 gpointer data)
145 {
146 return data == NULL;
147 }
148
149 class wxGtkTreeSelectionLock
150 {
151 public:
152 wxGtkTreeSelectionLock(GtkTreeSelection *selection)
153 : m_selection(selection)
154 {
155 wxASSERT_MSG( !ms_instance, "this class is not reentrant currently" );
156
157 ms_instance = this;
158
159 CheckCurrentSelectionFunc(NULL);
160
161 // Pass some non-NULL pointer as "data" for the callback, it doesn't
162 // matter what it is as long as it's non-NULL.
163 gtk_tree_selection_set_select_function(selection,
164 wxdataview_selection_func,
165 this,
166 NULL);
167 }
168
169 ~wxGtkTreeSelectionLock()
170 {
171 CheckCurrentSelectionFunc(wxdataview_selection_func);
172
173 gtk_tree_selection_set_select_function(m_selection,
174 wxdataview_selection_func,
175 NULL,
176 NULL);
177
178 ms_instance = NULL;
179 }
180
181 private:
182 void CheckCurrentSelectionFunc(GtkTreeSelectionFunc func)
183 {
184 // We can only use gtk_tree_selection_get_select_function() with 2.14+
185 // so check for its availability both during compile- and run-time.
186 #if GTK_CHECK_VERSION(2, 14, 0)
187 if ( gtk_check_version(2, 14, 0) != NULL )
188 return;
189
190 // If this assert is triggered, it means the code elsewhere has called
191 // gtk_tree_selection_set_select_function() but currently doing this
192 // breaks this class so the code here needs to be changed.
193 wxASSERT_MSG
194 (
195 gtk_tree_selection_get_select_function(m_selection) == func,
196 "selection function has changed unexpectedly, review this code!"
197 );
198 #endif // GTK+ 2.14+
199
200 wxUnusedVar(func);
201 }
202
203 static wxGtkTreeSelectionLock *ms_instance;
204
205 GtkTreeSelection * const m_selection;
206
207 wxDECLARE_NO_COPY_CLASS(wxGtkTreeSelectionLock);
208 };
209
210 wxGtkTreeSelectionLock *wxGtkTreeSelectionLock::ms_instance = NULL;
211
212 //-----------------------------------------------------------------------------
213 // wxDataViewCtrlInternal
214 //-----------------------------------------------------------------------------
215
216 WX_DECLARE_LIST(wxDataViewItem, ItemList);
217 WX_DEFINE_LIST(ItemList)
218
219 class wxDataViewCtrlInternal
220 {
221 public:
222 wxDataViewCtrlInternal( wxDataViewCtrl *owner, wxDataViewModel *wx_model );
223 ~wxDataViewCtrlInternal();
224
225 // model iface
226 GtkTreeModelFlags get_flags();
227 gboolean get_iter( GtkTreeIter *iter, GtkTreePath *path );
228 GtkTreePath *get_path( GtkTreeIter *iter);
229 gboolean iter_next( GtkTreeIter *iter );
230 gboolean iter_children( GtkTreeIter *iter, GtkTreeIter *parent);
231 gboolean iter_has_child( GtkTreeIter *iter );
232 gint iter_n_children( GtkTreeIter *iter );
233 gboolean iter_nth_child( GtkTreeIter *iter, GtkTreeIter *parent, gint n );
234 gboolean iter_parent( GtkTreeIter *iter, GtkTreeIter *child );
235
236 // dnd iface
237
238 bool EnableDragSource( const wxDataFormat &format );
239 bool EnableDropTarget( const wxDataFormat &format );
240
241 gboolean row_draggable( GtkTreeDragSource *drag_source, GtkTreePath *path );
242 gboolean drag_data_delete( GtkTreeDragSource *drag_source, GtkTreePath* path );
243 gboolean drag_data_get( GtkTreeDragSource *drag_source, GtkTreePath *path,
244 GtkSelectionData *selection_data );
245 gboolean drag_data_received( GtkTreeDragDest *drag_dest, GtkTreePath *dest,
246 GtkSelectionData *selection_data );
247 gboolean row_drop_possible( GtkTreeDragDest *drag_dest, GtkTreePath *dest_path,
248 GtkSelectionData *selection_data );
249
250 // notifactions from wxDataViewModel
251 bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
252 bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item );
253 bool ItemChanged( const wxDataViewItem &item );
254 bool ValueChanged( const wxDataViewItem &item, unsigned int model_column );
255 bool Cleared();
256 bool BeforeReset();
257 bool AfterReset();
258 void Resort();
259
260 // sorting interface
261 void SetSortOrder( GtkSortType sort_order ) { m_sort_order = sort_order; }
262 GtkSortType GetSortOrder() const { return m_sort_order; }
263
264 void SetSortColumn( int column ) { m_sort_column = column; }
265 int GetSortColumn() const { return m_sort_column; }
266
267 void SetDataViewSortColumn( wxDataViewColumn *column ) { m_dataview_sort_column = column; }
268 wxDataViewColumn *GetDataViewSortColumn() { return m_dataview_sort_column; }
269
270 bool IsSorted() { return (m_sort_column >= 0); }
271
272 // accessors
273 wxDataViewModel* GetDataViewModel() { return m_wx_model; }
274 const wxDataViewModel* GetDataViewModel() const { return m_wx_model; }
275 wxDataViewCtrl* GetOwner() { return m_owner; }
276 GtkWxTreeModel* GetGtkModel() { return m_gtk_model; }
277
278 // item can be deleted already in the model
279 int GetIndexOf( const wxDataViewItem &parent, const wxDataViewItem &item );
280
281 virtual void OnInternalIdle();
282
283 protected:
284 void InitTree();
285 void ScheduleRefresh();
286
287 wxGtkTreeModelNode *FindNode( const wxDataViewItem &item );
288 wxGtkTreeModelNode *FindNode( GtkTreeIter *iter );
289 wxGtkTreeModelNode *FindParentNode( const wxDataViewItem &item );
290 wxGtkTreeModelNode *FindParentNode( GtkTreeIter *iter );
291 void BuildBranch( wxGtkTreeModelNode *branch );
292
293 private:
294 wxGtkTreeModelNode *m_root;
295 wxDataViewModel *m_wx_model;
296 GtkWxTreeModel *m_gtk_model;
297 wxDataViewCtrl *m_owner;
298 GtkSortType m_sort_order;
299 wxDataViewColumn *m_dataview_sort_column;
300 int m_sort_column;
301
302 GtkTargetEntry m_dragSourceTargetEntry;
303 wxCharBuffer m_dragSourceTargetEntryTarget;
304 wxDataObject *m_dragDataObject;
305
306 GtkTargetEntry m_dropTargetTargetEntry;
307 wxCharBuffer m_dropTargetTargetEntryTarget;
308 wxDataObject *m_dropDataObject;
309
310 wxGtkDataViewModelNotifier *m_notifier;
311
312 bool m_dirty;
313 };
314
315
316 //-----------------------------------------------------------------------------
317 // wxGtkTreeModelNode
318 //-----------------------------------------------------------------------------
319
320 static
321 int LINKAGEMODE wxGtkTreeModelChildCmp( void** id1, void** id2 )
322 {
323 int ret = gs_internal->GetDataViewModel()->Compare( wxDataViewItem(*id1), wxDataViewItem(*id2),
324 gs_internal->GetSortColumn(), (gs_internal->GetSortOrder() == GTK_SORT_ASCENDING) );
325
326 return ret;
327 }
328
329 WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode*, wxGtkTreeModelNodes );
330 WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren );
331
332 class wxGtkTreeModelNode
333 {
334 public:
335 wxGtkTreeModelNode( wxGtkTreeModelNode* parent, const wxDataViewItem &item,
336 wxDataViewCtrlInternal *internal )
337 {
338 m_parent = parent;
339 m_item = item;
340 m_internal = internal;
341 }
342
343 ~wxGtkTreeModelNode()
344 {
345 size_t count = m_nodes.GetCount();
346 size_t i;
347 for (i = 0; i < count; i++)
348 {
349 wxGtkTreeModelNode *child = m_nodes.Item( i );
350 delete child;
351 }
352 }
353
354 void AddNode( wxGtkTreeModelNode* child )
355 {
356 m_nodes.Add( child );
357
358 void *id = child->GetItem().GetID();
359
360 m_children.Add( id );
361
362 if (m_internal->IsSorted() || m_internal->GetDataViewModel()->HasDefaultCompare())
363 {
364 gs_internal = m_internal;
365 m_children.Sort( &wxGtkTreeModelChildCmp );
366 }
367 }
368
369 void InsertNode( wxGtkTreeModelNode* child, unsigned pos )
370 {
371 if (m_internal->IsSorted() || m_internal->GetDataViewModel()->HasDefaultCompare())
372 {
373 AddNode(child);
374 return;
375 }
376
377 void *id = child->GetItem().GetID();
378
379 // Insert into m_nodes so that the order of nodes in m_nodes is the
380 // same as the order of their corresponding IDs in m_children:
381 const unsigned int count = m_nodes.GetCount();
382 bool inserted = false;
383 for (unsigned i = 0; i < count; i++)
384 {
385 wxGtkTreeModelNode *node = m_nodes[i];
386 int posInChildren = m_children.Index(node->GetItem().GetID());
387 if ( (unsigned)posInChildren >= pos )
388 {
389 m_nodes.Insert(child, i);
390 inserted = true;
391 break;
392 }
393 }
394 if ( !inserted )
395 m_nodes.Add(child);
396
397 m_children.Insert( id, pos );
398 }
399
400 void AddLeaf( void* id )
401 {
402 InsertLeaf(id, m_children.size());
403 }
404
405 void InsertLeaf( void* id, unsigned pos )
406 {
407 m_children.Insert( id, pos );
408
409 if (m_internal->IsSorted() || m_internal->GetDataViewModel()->HasDefaultCompare())
410 {
411 gs_internal = m_internal;
412 m_children.Sort( &wxGtkTreeModelChildCmp );
413 }
414 }
415
416 void DeleteChild( void* id )
417 {
418 m_children.Remove( id );
419
420 unsigned int count = m_nodes.GetCount();
421 unsigned int pos;
422 for (pos = 0; pos < count; pos++)
423 {
424 wxGtkTreeModelNode *node = m_nodes.Item( pos );
425 if (node->GetItem().GetID() == id)
426 {
427 m_nodes.RemoveAt( pos );
428 delete node;
429 break;
430 }
431 }
432 }
433
434 wxGtkTreeModelNode* GetParent()
435 { return m_parent; }
436 wxGtkTreeModelNodes &GetNodes()
437 { return m_nodes; }
438 wxGtkTreeModelChildren &GetChildren()
439 { return m_children; }
440
441 unsigned int GetChildCount() const { return m_children.GetCount(); }
442 unsigned int GetNodesCount() const { return m_nodes.GetCount(); }
443
444 wxDataViewItem &GetItem() { return m_item; }
445 wxDataViewCtrlInternal *GetInternal() { return m_internal; }
446
447 void Resort();
448
449 private:
450 wxGtkTreeModelNode *m_parent;
451 wxGtkTreeModelNodes m_nodes;
452 wxGtkTreeModelChildren m_children;
453 wxDataViewItem m_item;
454 wxDataViewCtrlInternal *m_internal;
455 };
456
457
458 //-----------------------------------------------------------------------------
459 // data
460 //-----------------------------------------------------------------------------
461
462 extern bool g_blockEventsOnDrag;
463
464 //-----------------------------------------------------------------------------
465 // define new GTK+ class wxGtkTreeModel
466 //-----------------------------------------------------------------------------
467
468 extern "C" {
469
470 #define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ())
471 #define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel))
472 #define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
473 #define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL))
474 #define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL))
475 #define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass))
476
477 GType gtk_wx_tree_model_get_type (void);
478
479 typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass;
480
481 struct _GtkWxTreeModel
482 {
483 GObject parent;
484
485 /*< private >*/
486 gint stamp;
487 wxDataViewCtrlInternal *internal;
488 };
489
490 struct _GtkWxTreeModelClass
491 {
492 GObjectClass list_parent_class;
493 };
494
495 static GtkWxTreeModel *wxgtk_tree_model_new (void);
496 static void wxgtk_tree_model_init (GtkWxTreeModel *tree_model);
497 static void wxgtk_tree_model_class_init (GtkWxTreeModelClass *klass);
498
499 static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface *iface);
500 static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface *iface);
501 static void wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface *iface);
502 static void wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface *iface);
503
504 static void wxgtk_tree_model_finalize (GObject *object);
505 static GtkTreeModelFlags wxgtk_tree_model_get_flags (GtkTreeModel *tree_model);
506 static gint wxgtk_tree_model_get_n_columns (GtkTreeModel *tree_model);
507 static GType wxgtk_tree_model_get_column_type (GtkTreeModel *tree_model,
508 gint index);
509 static gboolean wxgtk_tree_model_get_iter (GtkTreeModel *tree_model,
510 GtkTreeIter *iter,
511 GtkTreePath *path);
512 static GtkTreePath *wxgtk_tree_model_get_path (GtkTreeModel *tree_model,
513 GtkTreeIter *iter);
514 static void wxgtk_tree_model_get_value (GtkTreeModel *tree_model,
515 GtkTreeIter *iter,
516 gint column,
517 GValue *value);
518 static gboolean wxgtk_tree_model_iter_next (GtkTreeModel *tree_model,
519 GtkTreeIter *iter);
520 static gboolean wxgtk_tree_model_iter_children (GtkTreeModel *tree_model,
521 GtkTreeIter *iter,
522 GtkTreeIter *parent);
523 static gboolean wxgtk_tree_model_iter_has_child (GtkTreeModel *tree_model,
524 GtkTreeIter *iter);
525 static gint wxgtk_tree_model_iter_n_children (GtkTreeModel *tree_model,
526 GtkTreeIter *iter);
527 static gboolean wxgtk_tree_model_iter_nth_child (GtkTreeModel *tree_model,
528 GtkTreeIter *iter,
529 GtkTreeIter *parent,
530 gint n);
531 static gboolean wxgtk_tree_model_iter_parent (GtkTreeModel *tree_model,
532 GtkTreeIter *iter,
533 GtkTreeIter *child);
534
535 /* sortable */
536 static gboolean wxgtk_tree_model_get_sort_column_id (GtkTreeSortable *sortable,
537 gint *sort_column_id,
538 GtkSortType *order);
539 static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable *sortable,
540 gint sort_column_id,
541 GtkSortType order);
542 static void wxgtk_tree_model_set_sort_func (GtkTreeSortable *sortable,
543 gint sort_column_id,
544 GtkTreeIterCompareFunc func,
545 gpointer data,
546 GDestroyNotify destroy);
547 static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable *sortable,
548 GtkTreeIterCompareFunc func,
549 gpointer data,
550 GDestroyNotify destroy);
551 static gboolean wxgtk_tree_model_has_default_sort_func (GtkTreeSortable *sortable);
552
553 /* drag'n'drop */
554 static gboolean wxgtk_tree_model_row_draggable (GtkTreeDragSource *drag_source,
555 GtkTreePath *path);
556 static gboolean wxgtk_tree_model_drag_data_delete (GtkTreeDragSource *drag_source,
557 GtkTreePath *path);
558 static gboolean wxgtk_tree_model_drag_data_get (GtkTreeDragSource *drag_source,
559 GtkTreePath *path,
560 GtkSelectionData *selection_data);
561 static gboolean wxgtk_tree_model_drag_data_received (GtkTreeDragDest *drag_dest,
562 GtkTreePath *dest,
563 GtkSelectionData *selection_data);
564 static gboolean wxgtk_tree_model_row_drop_possible (GtkTreeDragDest *drag_dest,
565 GtkTreePath *dest_path,
566 GtkSelectionData *selection_data);
567
568
569 static GObjectClass *list_parent_class = NULL;
570
571 GType
572 gtk_wx_tree_model_get_type (void)
573 {
574 static GType tree_model_type = 0;
575
576 if (!tree_model_type)
577 {
578 const GTypeInfo tree_model_info =
579 {
580 sizeof (GtkWxTreeModelClass),
581 NULL, /* base_init */
582 NULL, /* base_finalize */
583 (GClassInitFunc) wxgtk_tree_model_class_init,
584 NULL, /* class_finalize */
585 NULL, /* class_data */
586 sizeof (GtkWxTreeModel),
587 0,
588 (GInstanceInitFunc) wxgtk_tree_model_init,
589 };
590
591 static const GInterfaceInfo tree_model_iface_info =
592 {
593 (GInterfaceInitFunc) wxgtk_tree_model_tree_model_init,
594 NULL,
595 NULL
596 };
597
598 static const GInterfaceInfo sortable_iface_info =
599 {
600 (GInterfaceInitFunc) wxgtk_tree_model_sortable_init,
601 NULL,
602 NULL
603 };
604
605 static const GInterfaceInfo drag_source_iface_info =
606 {
607 (GInterfaceInitFunc) wxgtk_tree_model_drag_source_init,
608 NULL,
609 NULL
610 };
611
612 static const GInterfaceInfo drag_dest_iface_info =
613 {
614 (GInterfaceInitFunc) wxgtk_tree_model_drag_dest_init,
615 NULL,
616 NULL
617 };
618
619 tree_model_type = g_type_register_static (G_TYPE_OBJECT, "GtkWxTreeModel",
620 &tree_model_info, (GTypeFlags)0 );
621
622 g_type_add_interface_static (tree_model_type,
623 GTK_TYPE_TREE_MODEL,
624 &tree_model_iface_info);
625 g_type_add_interface_static (tree_model_type,
626 GTK_TYPE_TREE_SORTABLE,
627 &sortable_iface_info);
628 g_type_add_interface_static (tree_model_type,
629 GTK_TYPE_TREE_DRAG_DEST,
630 &drag_dest_iface_info);
631 g_type_add_interface_static (tree_model_type,
632 GTK_TYPE_TREE_DRAG_SOURCE,
633 &drag_source_iface_info);
634 }
635
636 return tree_model_type;
637 }
638
639 static GtkWxTreeModel *
640 wxgtk_tree_model_new(void)
641 {
642 GtkWxTreeModel *retval = (GtkWxTreeModel *) g_object_new (GTK_TYPE_WX_TREE_MODEL, NULL);
643 return retval;
644 }
645
646 static void
647 wxgtk_tree_model_class_init (GtkWxTreeModelClass *klass)
648 {
649 list_parent_class = (GObjectClass*) g_type_class_peek_parent (klass);
650 GObjectClass *object_class = (GObjectClass*) klass;
651 object_class->finalize = wxgtk_tree_model_finalize;
652 }
653
654 static void
655 wxgtk_tree_model_tree_model_init (GtkTreeModelIface *iface)
656 {
657 iface->get_flags = wxgtk_tree_model_get_flags;
658 iface->get_n_columns = wxgtk_tree_model_get_n_columns;
659 iface->get_column_type = wxgtk_tree_model_get_column_type;
660 iface->get_iter = wxgtk_tree_model_get_iter;
661 iface->get_path = wxgtk_tree_model_get_path;
662 iface->get_value = wxgtk_tree_model_get_value;
663 iface->iter_next = wxgtk_tree_model_iter_next;
664 iface->iter_children = wxgtk_tree_model_iter_children;
665 iface->iter_has_child = wxgtk_tree_model_iter_has_child;
666 iface->iter_n_children = wxgtk_tree_model_iter_n_children;
667 iface->iter_nth_child = wxgtk_tree_model_iter_nth_child;
668 iface->iter_parent = wxgtk_tree_model_iter_parent;
669 }
670
671 static void
672 wxgtk_tree_model_sortable_init (GtkTreeSortableIface *iface)
673 {
674 iface->get_sort_column_id = wxgtk_tree_model_get_sort_column_id;
675 iface->set_sort_column_id = wxgtk_tree_model_set_sort_column_id;
676 iface->set_sort_func = wxgtk_tree_model_set_sort_func;
677 iface->set_default_sort_func = wxgtk_tree_model_set_default_sort_func;
678 iface->has_default_sort_func = wxgtk_tree_model_has_default_sort_func;
679 }
680
681 static void
682 wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface *iface)
683 {
684 iface->row_draggable = wxgtk_tree_model_row_draggable;
685 iface->drag_data_delete = wxgtk_tree_model_drag_data_delete;
686 iface->drag_data_get = wxgtk_tree_model_drag_data_get;
687 }
688
689 static void
690 wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface *iface)
691 {
692 iface->drag_data_received = wxgtk_tree_model_drag_data_received;
693 iface->row_drop_possible = wxgtk_tree_model_row_drop_possible;
694 }
695
696 static void
697 wxgtk_tree_model_init (GtkWxTreeModel *tree_model)
698 {
699 tree_model->internal = NULL;
700 tree_model->stamp = g_random_int();
701 }
702
703 static void
704 wxgtk_tree_model_finalize (GObject *object)
705 {
706 /* must chain up */
707 (* list_parent_class->finalize) (object);
708 }
709
710 } // extern "C"
711
712 //-----------------------------------------------------------------------------
713 // implement callbacks from wxGtkTreeModel class by letting
714 // them call the methods of wxWidgets' wxDataViewModel
715 //-----------------------------------------------------------------------------
716
717 static GtkTreeModelFlags
718 wxgtk_tree_model_get_flags (GtkTreeModel *tree_model)
719 {
720 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
721 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), (GtkTreeModelFlags)0 );
722
723 return wxtree_model->internal->get_flags();
724 }
725
726 static gint
727 wxgtk_tree_model_get_n_columns (GtkTreeModel *tree_model)
728 {
729 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
730 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), 0);
731
732 return wxtree_model->internal->GetDataViewModel()->GetColumnCount();
733 }
734
735 static GType
736 wxgtk_tree_model_get_column_type (GtkTreeModel *tree_model,
737 gint index)
738 {
739 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
740 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), G_TYPE_INVALID);
741
742 GType gtype = G_TYPE_INVALID;
743
744 wxString wxtype = wxtree_model->internal->GetDataViewModel()->GetColumnType( (unsigned int) index );
745
746 if (wxtype == wxT("string"))
747 gtype = G_TYPE_STRING;
748 else
749 {
750 gtype = G_TYPE_POINTER;
751 // wxFAIL_MSG( wxT("non-string columns not supported for searching yet") );
752 }
753
754 return gtype;
755 }
756
757 static gboolean
758 wxgtk_tree_model_get_iter (GtkTreeModel *tree_model,
759 GtkTreeIter *iter,
760 GtkTreePath *path)
761 {
762 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
763 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
764 g_return_val_if_fail (gtk_tree_path_get_depth (path) > 0, FALSE);
765
766 return wxtree_model->internal->get_iter( iter, path );
767 }
768
769 static GtkTreePath *
770 wxgtk_tree_model_get_path (GtkTreeModel *tree_model,
771 GtkTreeIter *iter)
772 {
773 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
774 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), NULL);
775 g_return_val_if_fail (iter->stamp == GTK_WX_TREE_MODEL (wxtree_model)->stamp, NULL);
776
777 return wxtree_model->internal->get_path( iter );
778 }
779
780 static void
781 wxgtk_tree_model_get_value (GtkTreeModel *tree_model,
782 GtkTreeIter *iter,
783 gint column,
784 GValue *value)
785 {
786 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
787 g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model) );
788
789 wxDataViewModel *model = wxtree_model->internal->GetDataViewModel();
790 wxString mtype = model->GetColumnType( (unsigned int) column );
791 if (mtype == wxT("string"))
792 {
793 wxVariant variant;
794 g_value_init( value, G_TYPE_STRING );
795 wxDataViewItem item( (void*) iter->user_data );
796 model->GetValue( variant, item, (unsigned int) column );
797
798 g_value_set_string( value, variant.GetString().utf8_str() );
799 }
800 else
801 {
802 wxFAIL_MSG( wxT("non-string columns not supported yet") );
803 }
804 }
805
806 static gboolean
807 wxgtk_tree_model_iter_next (GtkTreeModel *tree_model,
808 GtkTreeIter *iter)
809 {
810 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
811
812 // This happens when clearing the view by calling .._set_model( NULL );
813 if (iter->stamp == 0) return FALSE;
814
815 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
816 g_return_val_if_fail (wxtree_model->stamp == iter->stamp, FALSE);
817
818 return wxtree_model->internal->iter_next( iter );
819 }
820
821 static gboolean
822 wxgtk_tree_model_iter_children (GtkTreeModel *tree_model,
823 GtkTreeIter *iter,
824 GtkTreeIter *parent)
825 {
826 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
827 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
828 if (parent)
829 {
830 g_return_val_if_fail (wxtree_model->stamp == parent->stamp, FALSE);
831 }
832
833 return wxtree_model->internal->iter_children( iter, parent );
834 }
835
836 static gboolean
837 wxgtk_tree_model_iter_has_child (GtkTreeModel *tree_model,
838 GtkTreeIter *iter)
839 {
840 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
841 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
842 g_return_val_if_fail (wxtree_model->stamp == iter->stamp, FALSE);
843
844 return wxtree_model->internal->iter_has_child( iter );
845 }
846
847 static gint
848 wxgtk_tree_model_iter_n_children (GtkTreeModel *tree_model,
849 GtkTreeIter *iter)
850 {
851 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
852 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), 0);
853 g_return_val_if_fail ( !iter || wxtree_model->stamp == iter->stamp, 0);
854
855 return wxtree_model->internal->iter_n_children( iter );
856 }
857
858 static gboolean
859 wxgtk_tree_model_iter_nth_child (GtkTreeModel *tree_model,
860 GtkTreeIter *iter,
861 GtkTreeIter *parent,
862 gint n)
863 {
864 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
865 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
866
867 return wxtree_model->internal->iter_nth_child( iter, parent, n );
868 }
869
870 static gboolean
871 wxgtk_tree_model_iter_parent (GtkTreeModel *tree_model,
872 GtkTreeIter *iter,
873 GtkTreeIter *child)
874 {
875 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
876 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
877 g_return_val_if_fail (wxtree_model->stamp == child->stamp, FALSE);
878
879 return wxtree_model->internal->iter_parent( iter, child );
880 }
881
882 /* drag'n'drop iface */
883 static gboolean
884 wxgtk_tree_model_row_draggable (GtkTreeDragSource *drag_source,
885 GtkTreePath *path)
886 {
887 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) drag_source;
888 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
889
890 return wxtree_model->internal->row_draggable( drag_source, path );
891 }
892
893 static gboolean
894 wxgtk_tree_model_drag_data_delete (GtkTreeDragSource *drag_source,
895 GtkTreePath *path)
896 {
897 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) drag_source;
898 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
899
900 return wxtree_model->internal->drag_data_delete( drag_source, path );
901 }
902
903 static gboolean
904 wxgtk_tree_model_drag_data_get (GtkTreeDragSource *drag_source,
905 GtkTreePath *path,
906 GtkSelectionData *selection_data)
907 {
908 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) drag_source;
909 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
910
911 #if 0
912 wxPrintf( "drag_get_data\n");
913
914 wxGtkString atom_selection(gdk_atom_name(selection_data->selection));
915 wxPrintf( "selection %s\n", wxString::FromAscii(atom_selection) );
916
917 wxGtkString atom_target(gdk_atom_name(selection_data->target));
918 wxPrintf( "target %s\n", wxString::FromAscii(atom_target) );
919
920 wxGtkString atom_type(gdk_atom_name(selection_data->type));
921 wxPrintf( "type %s\n", wxString::FromAscii(atom_type) );
922
923 wxPrintf( "format %d\n", selection_data->format );
924 #endif
925
926 return wxtree_model->internal->drag_data_get( drag_source, path, selection_data );
927 }
928
929 static gboolean
930 wxgtk_tree_model_drag_data_received (GtkTreeDragDest *drag_dest,
931 GtkTreePath *dest,
932 GtkSelectionData *selection_data)
933 {
934 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) drag_dest;
935 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
936
937 return wxtree_model->internal->drag_data_received( drag_dest, dest, selection_data );
938 }
939
940 static gboolean
941 wxgtk_tree_model_row_drop_possible (GtkTreeDragDest *drag_dest,
942 GtkTreePath *dest_path,
943 GtkSelectionData *selection_data)
944 {
945 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) drag_dest;
946 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
947
948 return wxtree_model->internal->row_drop_possible( drag_dest, dest_path, selection_data );
949 }
950
951 /* sortable iface */
952 static gboolean
953 wxgtk_tree_model_get_sort_column_id (GtkTreeSortable *sortable,
954 gint *sort_column_id,
955 GtkSortType *order)
956 {
957 GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) sortable;
958
959 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable), FALSE);
960
961 if (!wxtree_model->internal->IsSorted())
962 {
963 if (sort_column_id)
964 *sort_column_id = -1;
965
966 return TRUE;
967 }
968
969
970 if (sort_column_id)
971 *sort_column_id = wxtree_model->internal->GetSortColumn();
972
973 if (order)
974 *order = wxtree_model->internal->GetSortOrder();
975
976 return TRUE;
977 }
978
979 wxDataViewColumn *gs_lastLeftClickHeader = NULL;
980
981 static void
982 wxgtk_tree_model_set_sort_column_id (GtkTreeSortable *sortable,
983 gint sort_column_id,
984 GtkSortType order)
985 {
986 GtkWxTreeModel *tree_model = (GtkWxTreeModel *) sortable;
987 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) );
988
989 tree_model->internal->SetDataViewSortColumn( gs_lastLeftClickHeader );
990
991 if ((sort_column_id != (gint) tree_model->internal->GetSortColumn()) ||
992 (order != tree_model->internal->GetSortOrder()))
993 {
994 tree_model->internal->SetSortColumn( sort_column_id );
995 tree_model->internal->SetSortOrder( order );
996
997 gtk_tree_sortable_sort_column_changed (sortable);
998
999 tree_model->internal->GetDataViewModel()->Resort();
1000 }
1001
1002 if (gs_lastLeftClickHeader)
1003 {
1004 wxDataViewCtrl *dv = tree_model->internal->GetOwner();
1005 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, dv->GetId() );
1006 event.SetDataViewColumn( gs_lastLeftClickHeader );
1007 event.SetModel( dv->GetModel() );
1008 dv->HandleWindowEvent( event );
1009 }
1010
1011 gs_lastLeftClickHeader = NULL;
1012 }
1013
1014 static void
1015 wxgtk_tree_model_set_sort_func (GtkTreeSortable *sortable,
1016 gint WXUNUSED(sort_column_id),
1017 GtkTreeIterCompareFunc func,
1018 gpointer WXUNUSED(data),
1019 GDestroyNotify WXUNUSED(destroy))
1020 {
1021 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) );
1022 g_return_if_fail (func != NULL);
1023 }
1024
1025 static void
1026 wxgtk_tree_model_set_default_sort_func (GtkTreeSortable *sortable,
1027 GtkTreeIterCompareFunc func,
1028 gpointer WXUNUSED(data),
1029 GDestroyNotify WXUNUSED(destroy))
1030 {
1031 g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) );
1032 g_return_if_fail (func != NULL);
1033
1034 //wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" );
1035 // TODO: remove this code
1036 }
1037
1038 static gboolean
1039 wxgtk_tree_model_has_default_sort_func (GtkTreeSortable *sortable)
1040 {
1041 g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable), FALSE );
1042
1043 return FALSE;
1044 }
1045
1046 //-----------------------------------------------------------------------------
1047 // define new GTK+ class GtkWxRendererText
1048 //-----------------------------------------------------------------------------
1049
1050 extern "C" {
1051
1052 #define GTK_TYPE_WX_CELL_RENDERER_TEXT (gtk_wx_cell_renderer_text_get_type ())
1053 #define GTK_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererText))
1054 #define GTK_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
1055 #define GTK_IS_WX_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT))
1056 #define GTK_IS_WX_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER_TEXT))
1057 #define GTK_WX_CELL_RENDERER_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER_TEXT, GtkWxCellRendererTextClass))
1058
1059 GType gtk_wx_cell_renderer_text_get_type (void);
1060
1061 typedef struct _GtkWxCellRendererText GtkWxCellRendererText;
1062 typedef struct _GtkWxCellRendererTextClass GtkWxCellRendererTextClass;
1063
1064 struct _GtkWxCellRendererText
1065 {
1066 GtkCellRendererText parent;
1067
1068 wxDataViewRenderer *wx_renderer;
1069 };
1070
1071 struct _GtkWxCellRendererTextClass
1072 {
1073 GtkCellRendererTextClass cell_parent_class;
1074 };
1075
1076
1077 static GtkWxCellRendererText *gtk_wx_cell_renderer_text_new (void);
1078 static void gtk_wx_cell_renderer_text_init (
1079 GtkWxCellRendererText *cell );
1080 static void gtk_wx_cell_renderer_text_class_init(
1081 GtkWxCellRendererTextClass *klass );
1082 static void gtk_wx_cell_renderer_text_finalize (
1083 GObject *object );
1084 static GtkCellEditable *gtk_wx_cell_renderer_text_start_editing(
1085 GtkCellRenderer *cell,
1086 GdkEvent *event,
1087 GtkWidget *widget,
1088 const gchar *path,
1089 GdkRectangle *background_area,
1090 GdkRectangle *cell_area,
1091 GtkCellRendererState flags );
1092
1093
1094 static GObjectClass *text_cell_parent_class = NULL;
1095
1096 } // extern "C"
1097
1098 GType
1099 gtk_wx_cell_renderer_text_get_type (void)
1100 {
1101 static GType cell_wx_type = 0;
1102
1103 if (!cell_wx_type)
1104 {
1105 const GTypeInfo cell_wx_info =
1106 {
1107 sizeof (GtkWxCellRendererTextClass),
1108 NULL, /* base_init */
1109 NULL, /* base_finalize */
1110 (GClassInitFunc) gtk_wx_cell_renderer_text_class_init,
1111 NULL, /* class_finalize */
1112 NULL, /* class_data */
1113 sizeof (GtkWxCellRendererText),
1114 0, /* n_preallocs */
1115 (GInstanceInitFunc) gtk_wx_cell_renderer_text_init,
1116 };
1117
1118 cell_wx_type = g_type_register_static( GTK_TYPE_CELL_RENDERER_TEXT,
1119 "GtkWxCellRendererText", &cell_wx_info, (GTypeFlags)0 );
1120 }
1121
1122 return cell_wx_type;
1123 }
1124
1125 static void
1126 gtk_wx_cell_renderer_text_init (GtkWxCellRendererText *cell)
1127 {
1128 cell->wx_renderer = NULL;
1129 }
1130
1131 static void
1132 gtk_wx_cell_renderer_text_class_init (GtkWxCellRendererTextClass *klass)
1133 {
1134 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1135 GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass);
1136
1137 text_cell_parent_class = (GObjectClass*) g_type_class_peek_parent (klass);
1138
1139 object_class->finalize = gtk_wx_cell_renderer_text_finalize;
1140
1141 cell_class->start_editing = gtk_wx_cell_renderer_text_start_editing;
1142 }
1143
1144 static void
1145 gtk_wx_cell_renderer_text_finalize (GObject *object)
1146 {
1147 /* must chain up */
1148 (* G_OBJECT_CLASS (text_cell_parent_class)->finalize) (object);
1149 }
1150
1151 GtkWxCellRendererText*
1152 gtk_wx_cell_renderer_text_new (void)
1153 {
1154 return (GtkWxCellRendererText*) g_object_new (GTK_TYPE_WX_CELL_RENDERER_TEXT, NULL);
1155 }
1156
1157 static GtkCellEditable *gtk_wx_cell_renderer_text_start_editing(
1158 GtkCellRenderer *gtk_renderer,
1159 GdkEvent *gdk_event,
1160 GtkWidget *widget,
1161 const gchar *path,
1162 GdkRectangle *background_area,
1163 GdkRectangle *cell_area,
1164 GtkCellRendererState flags )
1165 {
1166 GtkWxCellRendererText *wxgtk_renderer = (GtkWxCellRendererText *) gtk_renderer;
1167 wxDataViewRenderer *wx_renderer = wxgtk_renderer->wx_renderer;
1168 wxDataViewColumn *column = wx_renderer->GetOwner();
1169
1170 wxDataViewItem
1171 item(column->GetOwner()->GTKPathToItem(wxGtkTreePath(path)));
1172
1173 wxDataViewCtrl *dv = column->GetOwner();
1174 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING, dv->GetId() );
1175 event.SetDataViewColumn( column );
1176 event.SetModel( dv->GetModel() );
1177 event.SetColumn( column->GetModelColumn() );
1178 event.SetItem( item );
1179 dv->HandleWindowEvent( event );
1180
1181 if (event.IsAllowed())
1182 return GTK_CELL_RENDERER_CLASS(text_cell_parent_class)->
1183 start_editing( gtk_renderer, gdk_event, widget, path, background_area, cell_area, flags );
1184 else
1185 return NULL;
1186 }
1187
1188 //-----------------------------------------------------------------------------
1189 // define new GTK+ class GtkWxCellRenderer
1190 //-----------------------------------------------------------------------------
1191
1192 extern "C" {
1193
1194 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
1195 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
1196 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
1197 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
1198 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
1199 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
1200
1201 GType gtk_wx_cell_renderer_get_type (void);
1202
1203 typedef struct _GtkWxCellRenderer GtkWxCellRenderer;
1204 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass;
1205
1206 struct _GtkWxCellRenderer
1207 {
1208 GtkCellRenderer parent;
1209
1210 /*< private >*/
1211 wxDataViewCustomRenderer *cell;
1212 guint32 last_click;
1213 };
1214
1215 struct _GtkWxCellRendererClass
1216 {
1217 GtkCellRendererClass cell_parent_class;
1218 };
1219
1220
1221 static GtkCellRenderer *gtk_wx_cell_renderer_new (void);
1222 static void gtk_wx_cell_renderer_init (
1223 GtkWxCellRenderer *cell );
1224 static void gtk_wx_cell_renderer_class_init(
1225 GtkWxCellRendererClass *klass );
1226 static void gtk_wx_cell_renderer_finalize (
1227 GObject *object );
1228 static void gtk_wx_cell_renderer_get_size (
1229 GtkCellRenderer *cell,
1230 GtkWidget *widget,
1231 GdkRectangle *rectangle,
1232 gint *x_offset,
1233 gint *y_offset,
1234 gint *width,
1235 gint *height );
1236 static void gtk_wx_cell_renderer_render (
1237 GtkCellRenderer *cell,
1238 GdkWindow *window,
1239 GtkWidget *widget,
1240 GdkRectangle *background_area,
1241 GdkRectangle *cell_area,
1242 GdkRectangle *expose_area,
1243 GtkCellRendererState flags );
1244 static gboolean gtk_wx_cell_renderer_activate(
1245 GtkCellRenderer *cell,
1246 GdkEvent *event,
1247 GtkWidget *widget,
1248 const gchar *path,
1249 GdkRectangle *background_area,
1250 GdkRectangle *cell_area,
1251 GtkCellRendererState flags );
1252 static GtkCellEditable *gtk_wx_cell_renderer_start_editing(
1253 GtkCellRenderer *cell,
1254 GdkEvent *event,
1255 GtkWidget *widget,
1256 const gchar *path,
1257 GdkRectangle *background_area,
1258 GdkRectangle *cell_area,
1259 GtkCellRendererState flags );
1260
1261
1262 static GObjectClass *cell_parent_class = NULL;
1263
1264 } // extern "C"
1265
1266 GType
1267 gtk_wx_cell_renderer_get_type (void)
1268 {
1269 static GType cell_wx_type = 0;
1270
1271 if (!cell_wx_type)
1272 {
1273 const GTypeInfo cell_wx_info =
1274 {
1275 sizeof (GtkWxCellRendererClass),
1276 NULL, /* base_init */
1277 NULL, /* base_finalize */
1278 (GClassInitFunc) gtk_wx_cell_renderer_class_init,
1279 NULL, /* class_finalize */
1280 NULL, /* class_data */
1281 sizeof (GtkWxCellRenderer),
1282 0, /* n_preallocs */
1283 (GInstanceInitFunc) gtk_wx_cell_renderer_init,
1284 };
1285
1286 cell_wx_type = g_type_register_static( GTK_TYPE_CELL_RENDERER,
1287 "GtkWxCellRenderer", &cell_wx_info, (GTypeFlags)0 );
1288 }
1289
1290 return cell_wx_type;
1291 }
1292
1293 static void
1294 gtk_wx_cell_renderer_init (GtkWxCellRenderer *cell)
1295 {
1296 cell->cell = NULL;
1297 cell->last_click = 0;
1298 }
1299
1300 static void
1301 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass *klass)
1302 {
1303 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1304 GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass);
1305
1306 cell_parent_class = (GObjectClass*) g_type_class_peek_parent (klass);
1307
1308 object_class->finalize = gtk_wx_cell_renderer_finalize;
1309
1310 cell_class->get_size = gtk_wx_cell_renderer_get_size;
1311 cell_class->render = gtk_wx_cell_renderer_render;
1312 cell_class->activate = gtk_wx_cell_renderer_activate;
1313 cell_class->start_editing = gtk_wx_cell_renderer_start_editing;
1314 }
1315
1316 static void
1317 gtk_wx_cell_renderer_finalize (GObject *object)
1318 {
1319 /* must chain up */
1320 (* G_OBJECT_CLASS (cell_parent_class)->finalize) (object);
1321 }
1322
1323 GtkCellRenderer*
1324 gtk_wx_cell_renderer_new (void)
1325 {
1326 return (GtkCellRenderer*) g_object_new (GTK_TYPE_WX_CELL_RENDERER, NULL);
1327 }
1328
1329 static GtkCellEditable *gtk_wx_cell_renderer_start_editing(
1330 GtkCellRenderer *renderer,
1331 GdkEvent *WXUNUSED(event),
1332 GtkWidget *widget,
1333 const gchar *path,
1334 GdkRectangle *WXUNUSED(background_area),
1335 GdkRectangle *cell_area,
1336 GtkCellRendererState WXUNUSED(flags) )
1337 {
1338 GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer;
1339 wxDataViewCustomRenderer *cell = wxrenderer->cell;
1340
1341 // Renderer doesn't support in-place editing
1342 if (!cell->HasEditorCtrl())
1343 return NULL;
1344
1345 // An in-place editing control is still around
1346 if (cell->GetEditorCtrl())
1347 return NULL;
1348
1349 GdkRectangle rect;
1350 gtk_wx_cell_renderer_get_size (renderer, widget, cell_area,
1351 &rect.x,
1352 &rect.y,
1353 &rect.width,
1354 &rect.height);
1355
1356 rect.x += cell_area->x;
1357 rect.y += cell_area->y;
1358 // rect.width -= renderer->xpad * 2;
1359 // rect.height -= renderer->ypad * 2;
1360
1361 // wxRect renderrect(wxRectFromGDKRect(&rect));
1362 wxRect renderrect(wxRectFromGDKRect(cell_area));
1363
1364 wxDataViewItem
1365 item(cell->GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(path)));
1366
1367 cell->StartEditing( item, renderrect );
1368
1369 return NULL;
1370 }
1371
1372 static void
1373 gtk_wx_cell_renderer_get_size (GtkCellRenderer *renderer,
1374 GtkWidget *WXUNUSED(widget),
1375 GdkRectangle *cell_area,
1376 gint *x_offset,
1377 gint *y_offset,
1378 gint *width,
1379 gint *height)
1380 {
1381 GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer;
1382 wxDataViewCustomRenderer *cell = wxrenderer->cell;
1383
1384 wxSize size = cell->GetSize();
1385
1386 wxDataViewCtrl * const ctrl = cell->GetOwner()->GetOwner();
1387
1388 // Uniform row height, if specified, overrides the value returned by the
1389 // renderer.
1390 if ( !ctrl->HasFlag(wxDV_VARIABLE_LINE_HEIGHT) )
1391 {
1392 const int uniformHeight = ctrl->GTKGetUniformRowHeight();
1393 if ( uniformHeight > 0 )
1394 size.y = uniformHeight;
1395 }
1396
1397 int xpad, ypad;
1398 gtk_cell_renderer_get_padding(renderer, &xpad, &ypad);
1399 int calc_width = xpad * 2 + size.x;
1400 int calc_height = ypad * 2 + size.y;
1401
1402 if (x_offset)
1403 *x_offset = 0;
1404 if (y_offset)
1405 *y_offset = 0;
1406
1407 if (cell_area && size.x > 0 && size.y > 0)
1408 {
1409 float xalign, yalign;
1410 gtk_cell_renderer_get_alignment(renderer, &xalign, &yalign);
1411 if (x_offset)
1412 {
1413 *x_offset = int(xalign * (cell_area->width - calc_width - 2 * xpad));
1414 *x_offset = MAX(*x_offset, 0) + xpad;
1415 }
1416 if (y_offset)
1417 {
1418 *y_offset = int(yalign * (cell_area->height - calc_height - 2 * ypad));
1419 *y_offset = MAX(*y_offset, 0) + ypad;
1420 }
1421 }
1422
1423 if (width)
1424 *width = calc_width;
1425
1426 if (height)
1427 *height = calc_height;
1428 }
1429
1430 static void
1431 gtk_wx_cell_renderer_render (GtkCellRenderer *renderer,
1432 GdkWindow *window,
1433 GtkWidget *widget,
1434 GdkRectangle *background_area,
1435 GdkRectangle *cell_area,
1436 GdkRectangle *expose_area,
1437 GtkCellRendererState flags)
1438
1439 {
1440 GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer;
1441 wxDataViewCustomRenderer *cell = wxrenderer->cell;
1442
1443 cell->GTKStashRenderParams(window, widget,
1444 background_area, expose_area, flags);
1445
1446 wxRect rect(wxRectFromGDKRect(cell_area));
1447 int xpad, ypad;
1448 gtk_cell_renderer_get_padding(renderer, &xpad, &ypad);
1449 rect = rect.Deflate(xpad, ypad);
1450
1451 wxWindowDC* dc = (wxWindowDC*) cell->GetDC();
1452 wxWindowDCImpl *impl = (wxWindowDCImpl *) dc->GetImpl();
1453
1454 // Reinitialize wxWindowDC's GDK window if drawing occurs into a different
1455 // window such as a DnD drop window.
1456 if (window != impl->m_gdkwindow)
1457 {
1458 impl->Destroy();
1459 impl->m_gdkwindow = window;
1460 impl->SetUpDC();
1461 }
1462
1463 int state = 0;
1464 if (flags & GTK_CELL_RENDERER_SELECTED)
1465 state |= wxDATAVIEW_CELL_SELECTED;
1466 if (flags & GTK_CELL_RENDERER_PRELIT)
1467 state |= wxDATAVIEW_CELL_PRELIT;
1468 if (flags & GTK_CELL_RENDERER_INSENSITIVE)
1469 state |= wxDATAVIEW_CELL_INSENSITIVE;
1470 if (flags & GTK_CELL_RENDERER_INSENSITIVE)
1471 state |= wxDATAVIEW_CELL_INSENSITIVE;
1472 if (flags & GTK_CELL_RENDERER_FOCUSED)
1473 state |= wxDATAVIEW_CELL_FOCUSED;
1474 cell->WXCallRender( rect, dc, state );
1475 }
1476
1477 static gboolean
1478 gtk_wx_cell_renderer_activate(
1479 GtkCellRenderer *renderer,
1480 GdkEvent *event,
1481 GtkWidget *widget,
1482 const gchar *path,
1483 GdkRectangle *WXUNUSED(background_area),
1484 GdkRectangle *cell_area,
1485 GtkCellRendererState WXUNUSED(flags) )
1486 {
1487 GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer;
1488 wxDataViewCustomRenderer *cell = wxrenderer->cell;
1489
1490 GdkRectangle rect;
1491 gtk_wx_cell_renderer_get_size (renderer, widget, cell_area,
1492 &rect.x,
1493 &rect.y,
1494 &rect.width,
1495 &rect.height);
1496
1497 rect.x += cell_area->x;
1498 rect.y += cell_area->y;
1499 int xpad, ypad;
1500 gtk_cell_renderer_get_padding(renderer, &xpad, &ypad);
1501 rect.width -= xpad * 2;
1502 rect.height -= ypad * 2;
1503
1504 wxRect renderrect(wxRectFromGDKRect(&rect));
1505
1506 wxDataViewCtrl * const ctrl = cell->GetOwner()->GetOwner();
1507 wxDataViewModel *model = ctrl->GetModel();
1508
1509 wxDataViewItem item(ctrl->GTKPathToItem(wxGtkTreePath(path)));
1510
1511 unsigned int model_col = cell->GetOwner()->GetModelColumn();
1512
1513 if (!event)
1514 {
1515 bool ret = false;
1516
1517 // activated by <ENTER>
1518 if (cell->Activate( renderrect, model, item, model_col ))
1519 ret = true;
1520
1521 return ret;
1522 }
1523 else if (event->type == GDK_BUTTON_PRESS)
1524 {
1525 GdkEventButton *button_event = (GdkEventButton*) event;
1526 wxPoint pt( ((int) button_event->x) - renderrect.x,
1527 ((int) button_event->y) - renderrect.y );
1528
1529 bool ret = false;
1530 if (button_event->button == 1)
1531 {
1532 if (cell->LeftClick( pt, renderrect, model, item, model_col ))
1533 ret = true;
1534 // TODO: query system double-click time
1535 if (button_event->time - wxrenderer->last_click < 400)
1536 if (cell->Activate( renderrect, model, item, model_col ))
1537 ret = true;
1538 }
1539 wxrenderer->last_click = button_event->time;
1540
1541 return ret;
1542 }
1543
1544 return false;
1545 }
1546
1547 // ---------------------------------------------------------
1548 // wxGtkDataViewModelNotifier
1549 // ---------------------------------------------------------
1550
1551 class wxGtkDataViewModelNotifier: public wxDataViewModelNotifier
1552 {
1553 public:
1554 wxGtkDataViewModelNotifier( wxDataViewModel *wx_model, wxDataViewCtrlInternal *internal );
1555 ~wxGtkDataViewModelNotifier();
1556
1557 virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
1558 virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item );
1559 virtual bool ItemChanged( const wxDataViewItem &item );
1560 virtual bool ValueChanged( const wxDataViewItem &item, unsigned int model_column );
1561 virtual bool Cleared();
1562 virtual void Resort();
1563 virtual bool BeforeReset();
1564 virtual bool AfterReset();
1565
1566 void UpdateLastCount();
1567
1568 private:
1569 wxDataViewModel *m_wx_model;
1570 wxDataViewCtrlInternal *m_internal;
1571 };
1572
1573 // ---------------------------------------------------------
1574 // wxGtkDataViewListModelNotifier
1575 // ---------------------------------------------------------
1576
1577 wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier(
1578 wxDataViewModel *wx_model, wxDataViewCtrlInternal *internal )
1579 {
1580 m_wx_model = wx_model;
1581 m_internal = internal;
1582 }
1583
1584 wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier()
1585 {
1586 m_wx_model = NULL;
1587 m_internal = NULL;
1588 }
1589
1590 bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item )
1591 {
1592 m_internal->ItemAdded( parent, item );
1593 GtkWxTreeModel *wxgtk_model = m_internal->GetGtkModel();
1594
1595 GtkTreeIter iter;
1596 iter.stamp = wxgtk_model->stamp;
1597 iter.user_data = item.GetID();
1598
1599 wxGtkTreePath path(wxgtk_tree_model_get_path(
1600 GTK_TREE_MODEL(wxgtk_model), &iter ));
1601 gtk_tree_model_row_inserted(
1602 GTK_TREE_MODEL(wxgtk_model), path, &iter);
1603
1604 return true;
1605 }
1606
1607 bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item )
1608 {
1609 GtkWxTreeModel *wxgtk_model = m_internal->GetGtkModel();
1610 #if 0
1611 // using _get_path for a deleted item cannot be
1612 // a good idea
1613 GtkTreeIter iter;
1614 iter.stamp = wxgtk_model->stamp;
1615 iter.user_data = (gpointer) item.GetID();
1616 wxGtkTreePath path(wxgtk_tree_model_get_path(
1617 GTK_TREE_MODEL(wxgtk_model), &iter ));
1618 #else
1619 // so get the path from the parent
1620 GtkTreeIter parentIter;
1621 parentIter.stamp = wxgtk_model->stamp;
1622 parentIter.user_data = (gpointer) parent.GetID();
1623 wxGtkTreePath parentPath(wxgtk_tree_model_get_path(
1624 GTK_TREE_MODEL(wxgtk_model), &parentIter ));
1625
1626 // and add the final index ourselves
1627 wxGtkTreePath path(gtk_tree_path_copy(parentPath));
1628 int index = m_internal->GetIndexOf( parent, item );
1629 gtk_tree_path_append_index( path, index );
1630 #endif
1631
1632 gtk_tree_model_row_deleted(
1633 GTK_TREE_MODEL(wxgtk_model), path );
1634
1635 m_internal->ItemDeleted( parent, item );
1636
1637 // Did we remove the last child, causing 'parent' to become a leaf?
1638 if ( !m_wx_model->IsContainer(parent) )
1639 {
1640 gtk_tree_model_row_has_child_toggled
1641 (
1642 GTK_TREE_MODEL(wxgtk_model),
1643 parentPath,
1644 &parentIter
1645 );
1646 }
1647
1648 return true;
1649 }
1650
1651 void wxGtkDataViewModelNotifier::Resort()
1652 {
1653 m_internal->Resort();
1654 }
1655
1656 bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem &item )
1657 {
1658 GtkWxTreeModel *wxgtk_model = m_internal->GetGtkModel();
1659
1660 GtkTreeIter iter;
1661 iter.stamp = wxgtk_model->stamp;
1662 iter.user_data = (gpointer) item.GetID();
1663
1664 wxGtkTreePath path(wxgtk_tree_model_get_path(
1665 GTK_TREE_MODEL(wxgtk_model), &iter ));
1666 gtk_tree_model_row_changed(
1667 GTK_TREE_MODEL(wxgtk_model), path, &iter );
1668
1669 m_internal->ItemChanged( item );
1670
1671 return true;
1672 }
1673
1674 bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem &item, unsigned int model_column )
1675 {
1676 GtkWxTreeModel *wxgtk_model = m_internal->GetGtkModel();
1677 wxDataViewCtrl *ctrl = m_internal->GetOwner();
1678
1679 // This adds GTK+'s missing MVC logic for ValueChanged
1680 unsigned int index;
1681 for (index = 0; index < ctrl->GetColumnCount(); index++)
1682 {
1683 wxDataViewColumn *column = ctrl->GetColumn( index );
1684 if (column->GetModelColumn() == model_column)
1685 {
1686 GtkTreeView *widget = GTK_TREE_VIEW(ctrl->GtkGetTreeView());
1687 GtkTreeViewColumn *gcolumn = GTK_TREE_VIEW_COLUMN(column->GetGtkHandle());
1688
1689 // Don't attempt to refresh not yet realized tree, it is useless
1690 // and results in GTK errors.
1691 if ( gtk_widget_get_realized(ctrl->GtkGetTreeView()) )
1692 {
1693 // Get cell area
1694 GtkTreeIter iter;
1695 iter.stamp = wxgtk_model->stamp;
1696 iter.user_data = (gpointer) item.GetID();
1697 wxGtkTreePath path(wxgtk_tree_model_get_path(
1698 GTK_TREE_MODEL(wxgtk_model), &iter ));
1699 GdkRectangle cell_area;
1700 gtk_tree_view_get_cell_area( widget, path, gcolumn, &cell_area );
1701
1702 GtkAdjustment* hadjust = gtk_tree_view_get_hadjustment( widget );
1703 double d = gtk_adjustment_get_value( hadjust );
1704 int xdiff = (int) d;
1705
1706 int ydiff = gcolumn->button->allocation.height;
1707 // Redraw
1708 gtk_widget_queue_draw_area( GTK_WIDGET(widget),
1709 cell_area.x - xdiff, ydiff + cell_area.y, cell_area.width, cell_area.height );
1710 }
1711
1712 m_internal->ValueChanged( item, model_column );
1713
1714 return true;
1715 }
1716 }
1717
1718 return false;
1719 }
1720
1721 bool wxGtkDataViewModelNotifier::BeforeReset()
1722 {
1723 GtkWidget *treeview = m_internal->GetOwner()->GtkGetTreeView();
1724 gtk_tree_view_set_model( GTK_TREE_VIEW(treeview), NULL );
1725
1726 return true;
1727 }
1728
1729 bool wxGtkDataViewModelNotifier::AfterReset()
1730 {
1731 GtkWidget *treeview = m_internal->GetOwner()->GtkGetTreeView();
1732 GtkWxTreeModel *wxgtk_model = m_internal->GetGtkModel();
1733
1734 m_internal->Cleared();
1735
1736 gtk_tree_view_set_model( GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(wxgtk_model) );
1737
1738 return true;
1739 }
1740
1741 bool wxGtkDataViewModelNotifier::Cleared()
1742 {
1743 GtkWxTreeModel *wxgtk_model = m_internal->GetGtkModel();
1744
1745 // There is no call to tell the model that everything
1746 // has been deleted so call row_deleted() for every
1747 // child of root...
1748
1749 int count = m_internal->iter_n_children( NULL ); // number of children of root
1750
1751 GtkTreePath *path = gtk_tree_path_new_first(); // points to root
1752
1753 int i;
1754 for (i = 0; i < count; i++)
1755 gtk_tree_model_row_deleted( GTK_TREE_MODEL(wxgtk_model), path );
1756
1757 gtk_tree_path_free( path );
1758
1759 m_internal->Cleared();
1760
1761 return true;
1762 }
1763
1764 // ---------------------------------------------------------
1765 // wxDataViewRenderer
1766 // ---------------------------------------------------------
1767
1768 static gpointer s_user_data = NULL;
1769
1770 static void
1771 wxgtk_cell_editable_editing_done( GtkCellEditable *WXUNUSED(editable),
1772 wxDataViewRenderer *wxrenderer )
1773 {
1774 wxDataViewColumn *column = wxrenderer->GetOwner();
1775 wxDataViewCtrl *dv = column->GetOwner();
1776 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, dv->GetId() );
1777 event.SetDataViewColumn( column );
1778 event.SetModel( dv->GetModel() );
1779 wxDataViewItem item( s_user_data );
1780 event.SetItem( item );
1781 dv->HandleWindowEvent( event );
1782 }
1783
1784 static void
1785 wxgtk_renderer_editing_started( GtkCellRenderer *WXUNUSED(cell), GtkCellEditable *editable,
1786 gchar *path, wxDataViewRenderer *wxrenderer )
1787 {
1788 if (!editable)
1789 return;
1790
1791 wxDataViewColumn *column = wxrenderer->GetOwner();
1792 wxDataViewCtrl *dv = column->GetOwner();
1793 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, dv->GetId() );
1794 event.SetDataViewColumn( column );
1795 event.SetModel( dv->GetModel() );
1796 wxDataViewItem item(dv->GTKPathToItem(wxGtkTreePath(path)));
1797 event.SetItem( item );
1798 dv->HandleWindowEvent( event );
1799
1800 if (GTK_IS_CELL_EDITABLE(editable))
1801 {
1802 s_user_data = item.GetID();
1803
1804 g_signal_connect (GTK_CELL_EDITABLE (editable), "editing_done",
1805 G_CALLBACK (wxgtk_cell_editable_editing_done),
1806 (gpointer) wxrenderer );
1807
1808 }
1809 }
1810
1811
1812 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer, wxDataViewRendererBase)
1813
1814 wxDataViewRenderer::wxDataViewRenderer( const wxString &varianttype, wxDataViewCellMode mode,
1815 int align ) :
1816 wxDataViewRendererBase( varianttype, mode, align )
1817 {
1818 m_renderer = NULL;
1819 m_mode = mode;
1820
1821 // we haven't changed them yet
1822 m_usingDefaultAttrs = true;
1823
1824 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
1825 // after the m_renderer pointer has been initialized
1826 }
1827
1828 void wxDataViewRenderer::GtkPackIntoColumn(GtkTreeViewColumn *column)
1829 {
1830 gtk_tree_view_column_pack_end( column, m_renderer, TRUE /* expand */);
1831 }
1832
1833 void wxDataViewRenderer::GtkInitHandlers()
1834 {
1835 if (!gtk_check_version(2,6,0))
1836 {
1837 g_signal_connect (GTK_CELL_RENDERER(m_renderer), "editing_started",
1838 G_CALLBACK (wxgtk_renderer_editing_started),
1839 this);
1840 }
1841 }
1842
1843 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode )
1844 {
1845 GtkCellRendererMode gtkMode;
1846 switch (mode)
1847 {
1848 case wxDATAVIEW_CELL_INERT:
1849 gtkMode = GTK_CELL_RENDERER_MODE_INERT;
1850 break;
1851
1852 case wxDATAVIEW_CELL_ACTIVATABLE:
1853 gtkMode = GTK_CELL_RENDERER_MODE_ACTIVATABLE;
1854 break;
1855
1856 case wxDATAVIEW_CELL_EDITABLE:
1857 gtkMode = GTK_CELL_RENDERER_MODE_EDITABLE;
1858 break;
1859
1860 default:
1861 wxFAIL_MSG( "unknown wxDataViewCellMode value" );
1862 return;
1863 }
1864
1865 m_mode = mode;
1866
1867 // This value is most often ignored in GtkTreeView
1868 GValue gvalue = { 0, };
1869 g_value_init( &gvalue, gtk_cell_renderer_mode_get_type() );
1870 g_value_set_enum( &gvalue, gtkMode );
1871 g_object_set_property( G_OBJECT(m_renderer), "mode", &gvalue );
1872 g_value_unset( &gvalue );
1873 }
1874
1875 wxDataViewCellMode wxDataViewRenderer::GetMode() const
1876 {
1877 wxDataViewCellMode ret;
1878
1879 GValue gvalue;
1880 g_object_get( G_OBJECT(m_renderer), "mode", &gvalue, NULL);
1881
1882 switch (g_value_get_enum(&gvalue))
1883 {
1884 default:
1885 wxFAIL_MSG( "unknown GtkCellRendererMode value" );
1886 // fall through (we have to return something)
1887
1888 case GTK_CELL_RENDERER_MODE_INERT:
1889 ret = wxDATAVIEW_CELL_INERT;
1890 break;
1891
1892 case GTK_CELL_RENDERER_MODE_ACTIVATABLE:
1893 ret = wxDATAVIEW_CELL_ACTIVATABLE;
1894 break;
1895
1896 case GTK_CELL_RENDERER_MODE_EDITABLE:
1897 ret = wxDATAVIEW_CELL_EDITABLE;
1898 break;
1899 }
1900
1901 g_value_unset( &gvalue );
1902
1903 return ret;
1904 }
1905
1906 void wxDataViewRenderer::GtkApplyAlignment(GtkCellRenderer *renderer)
1907 {
1908 int align = m_alignment;
1909
1910 // query alignment from column ?
1911 if (align == -1)
1912 {
1913 // None there yet
1914 if (GetOwner() == NULL)
1915 return;
1916
1917 align = GetOwner()->GetAlignment();
1918 align |= wxALIGN_CENTRE_VERTICAL;
1919 }
1920
1921 // horizontal alignment:
1922
1923 gfloat xalign = 0.0;
1924 if (align & wxALIGN_RIGHT)
1925 xalign = 1.0;
1926 else if (align & wxALIGN_CENTER_HORIZONTAL)
1927 xalign = 0.5;
1928
1929 GValue gvalue = { 0, };
1930 g_value_init( &gvalue, G_TYPE_FLOAT );
1931 g_value_set_float( &gvalue, xalign );
1932 g_object_set_property( G_OBJECT(renderer), "xalign", &gvalue );
1933 g_value_unset( &gvalue );
1934
1935 // vertical alignment:
1936
1937 gfloat yalign = 0.0;
1938 if (align & wxALIGN_BOTTOM)
1939 yalign = 1.0;
1940 else if (align & wxALIGN_CENTER_VERTICAL)
1941 yalign = 0.5;
1942
1943 GValue gvalue2 = { 0, };
1944 g_value_init( &gvalue2, G_TYPE_FLOAT );
1945 g_value_set_float( &gvalue2, yalign );
1946 g_object_set_property( G_OBJECT(renderer), "yalign", &gvalue2 );
1947 g_value_unset( &gvalue2 );
1948 }
1949
1950 void wxDataViewRenderer::SetAlignment( int align )
1951 {
1952 m_alignment = align;
1953 GtkUpdateAlignment();
1954 }
1955
1956 int wxDataViewRenderer::GetAlignment() const
1957 {
1958 return m_alignment;
1959 }
1960
1961 void wxDataViewRenderer::EnableEllipsize(wxEllipsizeMode mode)
1962 {
1963 #ifdef __WXGTK26__
1964 if ( gtk_check_version(2, 6, 0) != NULL )
1965 return;
1966
1967 GtkCellRendererText * const rend = GtkGetTextRenderer();
1968 if ( !rend )
1969 return;
1970
1971 // we use the same values in wxEllipsizeMode as PangoEllipsizeMode so we
1972 // can just cast between them
1973 GValue gvalue = { 0, };
1974 g_value_init( &gvalue, PANGO_TYPE_ELLIPSIZE_MODE );
1975 g_value_set_enum( &gvalue, static_cast<PangoEllipsizeMode>(mode) );
1976 g_object_set_property( G_OBJECT(rend), "ellipsize", &gvalue );
1977 g_value_unset( &gvalue );
1978 #else // GTK < 2.6
1979 wxUnusedVar(mode);
1980 #endif // GTK 2.6/before
1981 }
1982
1983 wxEllipsizeMode wxDataViewRenderer::GetEllipsizeMode() const
1984 {
1985 #ifdef __WXGTK26__
1986 if ( gtk_check_version(2, 6, 0) != NULL )
1987 return wxELLIPSIZE_NONE;
1988
1989 GtkCellRendererText * const rend = GtkGetTextRenderer();
1990 if ( !rend )
1991 return wxELLIPSIZE_NONE;
1992
1993 GValue gvalue = { 0, };
1994 g_value_init( &gvalue, PANGO_TYPE_ELLIPSIZE_MODE );
1995 g_object_get_property( G_OBJECT(rend), "ellipsize", &gvalue );
1996 wxEllipsizeMode
1997 mode = static_cast<wxEllipsizeMode>(g_value_get_enum( &gvalue ));
1998 g_value_unset( &gvalue );
1999
2000 return mode;
2001 #else // GTK < 2.6
2002 return wxELLIPSIZE_NONE;
2003 #endif // GTK 2.6/before
2004 }
2005
2006 void
2007 wxDataViewRenderer::GtkOnTextEdited(const char *itempath, const wxString& str)
2008 {
2009 wxVariant value(str);
2010 if (!Validate( value ))
2011 return;
2012
2013 wxDataViewItem
2014 item(GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(itempath)));
2015
2016 GtkOnCellChanged(value, item, GetOwner()->GetModelColumn());
2017 }
2018
2019 void
2020 wxDataViewRenderer::GtkOnCellChanged(const wxVariant& value,
2021 const wxDataViewItem& item,
2022 unsigned col)
2023 {
2024 wxDataViewModel *model = GetOwner()->GetOwner()->GetModel();
2025 model->ChangeValue( value, item, col );
2026 }
2027
2028 // ---------------------------------------------------------
2029 // wxDataViewTextRenderer
2030 // ---------------------------------------------------------
2031
2032 extern "C"
2033 {
2034
2035 static void wxGtkTextRendererEditedCallback( GtkCellRendererText *WXUNUSED(renderer),
2036 gchar *arg1, gchar *arg2, gpointer user_data )
2037 {
2038 wxDataViewRenderer *cell = (wxDataViewRenderer*) user_data;
2039
2040 cell->GtkOnTextEdited(arg1, wxGTK_CONV_BACK_FONT(
2041 arg2, cell->GetOwner()->GetOwner()->GetFont()));
2042 }
2043
2044 }
2045
2046 namespace
2047 {
2048
2049 // helper function used by wxDataViewTextRenderer and
2050 // wxDataViewCustomRenderer::RenderText(): it applies the attributes to the
2051 // given text renderer and returns true if anything was done
2052 bool GtkApplyAttr(GtkCellRendererText *renderer, const wxDataViewItemAttr& attr)
2053 {
2054 bool usingDefaultAttrs = true;
2055 if (attr.HasColour())
2056 {
2057 const GdkColor * const gcol = attr.GetColour().GetColor();
2058
2059 GValue gvalue = { 0, };
2060 g_value_init( &gvalue, GDK_TYPE_COLOR );
2061 g_value_set_boxed( &gvalue, gcol );
2062 g_object_set_property( G_OBJECT(renderer), "foreground_gdk", &gvalue );
2063 g_value_unset( &gvalue );
2064
2065 usingDefaultAttrs = false;
2066 }
2067 else
2068 {
2069 GValue gvalue = { 0, };
2070 g_value_init( &gvalue, G_TYPE_BOOLEAN );
2071 g_value_set_boolean( &gvalue, FALSE );
2072 g_object_set_property( G_OBJECT(renderer), "foreground-set", &gvalue );
2073 g_value_unset( &gvalue );
2074 }
2075
2076 if (attr.GetItalic())
2077 {
2078 GValue gvalue = { 0, };
2079 g_value_init( &gvalue, PANGO_TYPE_STYLE );
2080 g_value_set_enum( &gvalue, PANGO_STYLE_ITALIC );
2081 g_object_set_property( G_OBJECT(renderer), "style", &gvalue );
2082 g_value_unset( &gvalue );
2083
2084 usingDefaultAttrs = false;
2085 }
2086 else
2087 {
2088 GValue gvalue = { 0, };
2089 g_value_init( &gvalue, G_TYPE_BOOLEAN );
2090 g_value_set_boolean( &gvalue, FALSE );
2091 g_object_set_property( G_OBJECT(renderer), "style-set", &gvalue );
2092 g_value_unset( &gvalue );
2093 }
2094
2095
2096 if (attr.GetBold())
2097 {
2098 GValue gvalue = { 0, };
2099 g_value_init( &gvalue, PANGO_TYPE_WEIGHT );
2100 g_value_set_enum( &gvalue, PANGO_WEIGHT_BOLD );
2101 g_object_set_property( G_OBJECT(renderer), "weight", &gvalue );
2102 g_value_unset( &gvalue );
2103
2104 usingDefaultAttrs = false;
2105 }
2106 else
2107 {
2108 GValue gvalue = { 0, };
2109 g_value_init( &gvalue, G_TYPE_BOOLEAN );
2110 g_value_set_boolean( &gvalue, FALSE );
2111 g_object_set_property( G_OBJECT(renderer), "weight-set", &gvalue );
2112 g_value_unset( &gvalue );
2113 }
2114
2115 #if 0
2116 if (attr.HasBackgroundColour())
2117 {
2118 wxColour colour = attr.GetBackgroundColour();
2119 const GdkColor * const gcol = colour.GetColor();
2120
2121 GValue gvalue = { 0, };
2122 g_value_init( &gvalue, GDK_TYPE_COLOR );
2123 g_value_set_boxed( &gvalue, gcol );
2124 g_object_set_property( G_OBJECT(renderer), "cell-background_gdk", &gvalue );
2125 g_value_unset( &gvalue );
2126 }
2127 else
2128 {
2129 GValue gvalue = { 0, };
2130 g_value_init( &gvalue, G_TYPE_BOOLEAN );
2131 g_value_set_boolean( &gvalue, FALSE );
2132 g_object_set_property( G_OBJECT(renderer), "cell-background-set", &gvalue );
2133 g_value_unset( &gvalue );
2134 }
2135 #endif
2136
2137 return !usingDefaultAttrs;
2138 }
2139
2140 } // anonymous namespace
2141
2142 IMPLEMENT_CLASS(wxDataViewTextRenderer, wxDataViewRenderer)
2143
2144 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString &varianttype, wxDataViewCellMode mode,
2145 int align ) :
2146 wxDataViewRenderer( varianttype, mode, align )
2147 {
2148 GtkWxCellRendererText *text_renderer = gtk_wx_cell_renderer_text_new();
2149 text_renderer->wx_renderer = this;
2150 m_renderer = (GtkCellRenderer*) text_renderer;
2151
2152 if (mode & wxDATAVIEW_CELL_EDITABLE)
2153 {
2154 GValue gvalue = { 0, };
2155 g_value_init( &gvalue, G_TYPE_BOOLEAN );
2156 g_value_set_boolean( &gvalue, true );
2157 g_object_set_property( G_OBJECT(m_renderer), "editable", &gvalue );
2158 g_value_unset( &gvalue );
2159
2160 g_signal_connect_after( m_renderer, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback), this );
2161
2162 GtkInitHandlers();
2163 }
2164
2165 SetMode(mode);
2166 SetAlignment(align);
2167 }
2168
2169 bool wxDataViewTextRenderer::SetTextValue(const wxString& str)
2170 {
2171 GValue gvalue = { 0, };
2172 g_value_init( &gvalue, G_TYPE_STRING );
2173 g_value_set_string( &gvalue, wxGTK_CONV_FONT( str, GetOwner()->GetOwner()->GetFont() ) );
2174 g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue );
2175 g_value_unset( &gvalue );
2176
2177 return true;
2178 }
2179
2180 bool wxDataViewTextRenderer::GetTextValue(wxString& str) const
2181 {
2182 GValue gvalue = { 0, };
2183 g_value_init( &gvalue, G_TYPE_STRING );
2184 g_object_get_property( G_OBJECT(m_renderer), "text", &gvalue );
2185 str = wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue ), const_cast<wxDataViewTextRenderer*>(this)->GetOwner()->GetOwner()->GetFont() );
2186 g_value_unset( &gvalue );
2187
2188 return true;
2189 }
2190
2191 void wxDataViewTextRenderer::SetAlignment( int align )
2192 {
2193 wxDataViewRenderer::SetAlignment(align);
2194
2195 if (gtk_check_version(2,10,0))
2196 return;
2197
2198 // horizontal alignment:
2199 PangoAlignment pangoAlign = PANGO_ALIGN_LEFT;
2200 if (align & wxALIGN_RIGHT)
2201 pangoAlign = PANGO_ALIGN_RIGHT;
2202 else if (align & wxALIGN_CENTER_HORIZONTAL)
2203 pangoAlign = PANGO_ALIGN_CENTER;
2204
2205 GValue gvalue = { 0, };
2206 g_value_init( &gvalue, gtk_cell_renderer_mode_get_type() );
2207 g_value_set_enum( &gvalue, pangoAlign );
2208 g_object_set_property( G_OBJECT(m_renderer), "alignment", &gvalue );
2209 g_value_unset( &gvalue );
2210 }
2211
2212 bool wxDataViewTextRenderer::GtkSetAttr(const wxDataViewItemAttr& attr)
2213 {
2214 return GtkApplyAttr(GtkGetTextRenderer(), attr);
2215 }
2216
2217 GtkCellRendererText *wxDataViewTextRenderer::GtkGetTextRenderer() const
2218 {
2219 return GTK_CELL_RENDERER_TEXT(m_renderer);
2220 }
2221
2222 // ---------------------------------------------------------
2223 // wxDataViewBitmapRenderer
2224 // ---------------------------------------------------------
2225
2226 namespace
2227 {
2228
2229 // set "pixbuf" property on the given renderer
2230 void SetPixbufProp(GtkCellRenderer *renderer, GdkPixbuf *pixbuf)
2231 {
2232 GValue gvalue = { 0, };
2233 g_value_init( &gvalue, G_TYPE_OBJECT );
2234 g_value_set_object( &gvalue, pixbuf );
2235 g_object_set_property( G_OBJECT(renderer), "pixbuf", &gvalue );
2236 g_value_unset( &gvalue );
2237 }
2238
2239 } // anonymous namespace
2240
2241 IMPLEMENT_CLASS(wxDataViewBitmapRenderer, wxDataViewRenderer)
2242
2243 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString &varianttype, wxDataViewCellMode mode,
2244 int align ) :
2245 wxDataViewRenderer( varianttype, mode, align )
2246 {
2247 m_renderer = gtk_cell_renderer_pixbuf_new();
2248
2249 SetMode(mode);
2250 SetAlignment(align);
2251 }
2252
2253 bool wxDataViewBitmapRenderer::SetValue( const wxVariant &value )
2254 {
2255 if (value.GetType() == wxT("wxBitmap"))
2256 {
2257 wxBitmap bitmap;
2258 bitmap << value;
2259
2260 // GetPixbuf() may create a Pixbuf representation in the wxBitmap
2261 // object (and it will stay there and remain owned by wxBitmap)
2262 SetPixbufProp(m_renderer, bitmap.GetPixbuf());
2263 }
2264 else if (value.GetType() == wxT("wxIcon"))
2265 {
2266 wxIcon icon;
2267 icon << value;
2268
2269 SetPixbufProp(m_renderer, icon.GetPixbuf());
2270 }
2271 else
2272 {
2273 return false;
2274 }
2275
2276 return true;
2277 }
2278
2279 bool wxDataViewBitmapRenderer::GetValue( wxVariant &WXUNUSED(value) ) const
2280 {
2281 return false;
2282 }
2283
2284 // ---------------------------------------------------------
2285 // wxDataViewToggleRenderer
2286 // ---------------------------------------------------------
2287
2288 extern "C" {
2289 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle *renderer,
2290 gchar *path, gpointer user_data );
2291 }
2292
2293 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle *renderer,
2294 gchar *path, gpointer user_data )
2295 {
2296 wxDataViewToggleRenderer *cell = (wxDataViewToggleRenderer*) user_data;
2297
2298 // get old value
2299 GValue gvalue = { 0, };
2300 g_value_init( &gvalue, G_TYPE_BOOLEAN );
2301 g_object_get_property( G_OBJECT(renderer), "active", &gvalue );
2302 bool tmp = g_value_get_boolean( &gvalue );
2303 g_value_unset( &gvalue );
2304 // invert it
2305 tmp = !tmp;
2306
2307 wxVariant value = tmp;
2308 if (!cell->Validate( value ))
2309 return;
2310
2311 wxDataViewCtrl * const ctrl = cell->GetOwner()->GetOwner();
2312 wxDataViewModel *model = ctrl->GetModel();
2313
2314 wxDataViewItem item(ctrl->GTKPathToItem(wxGtkTreePath(path)));
2315
2316 unsigned int model_col = cell->GetOwner()->GetModelColumn();
2317
2318 model->ChangeValue( value, item, model_col );
2319 }
2320
2321 IMPLEMENT_CLASS(wxDataViewToggleRenderer, wxDataViewRenderer)
2322
2323 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString &varianttype,
2324 wxDataViewCellMode mode, int align ) :
2325 wxDataViewRenderer( varianttype, mode, align )
2326 {
2327 m_renderer = (GtkCellRenderer*) gtk_cell_renderer_toggle_new();
2328
2329 if (mode & wxDATAVIEW_CELL_ACTIVATABLE)
2330 {
2331 g_signal_connect_after( m_renderer, "toggled",
2332 G_CALLBACK(wxGtkToggleRendererToggledCallback), this );
2333 }
2334 else
2335 {
2336 GValue gvalue = { 0, };
2337 g_value_init( &gvalue, G_TYPE_BOOLEAN );
2338 g_value_set_boolean( &gvalue, false );
2339 g_object_set_property( G_OBJECT(m_renderer), "activatable", &gvalue );
2340 g_value_unset( &gvalue );
2341 }
2342
2343 SetMode(mode);
2344 SetAlignment(align);
2345 }
2346
2347 bool wxDataViewToggleRenderer::SetValue( const wxVariant &value )
2348 {
2349 bool tmp = value;
2350
2351 GValue gvalue = { 0, };
2352 g_value_init( &gvalue, G_TYPE_BOOLEAN );
2353 g_value_set_boolean( &gvalue, tmp );
2354 g_object_set_property( G_OBJECT(m_renderer), "active", &gvalue );
2355 g_value_unset( &gvalue );
2356
2357 return true;
2358 }
2359
2360 bool wxDataViewToggleRenderer::GetValue( wxVariant &value ) const
2361 {
2362 GValue gvalue = { 0, };
2363 g_value_init( &gvalue, G_TYPE_BOOLEAN );
2364 g_object_get_property( G_OBJECT(m_renderer), "active", &gvalue );
2365 bool tmp = g_value_get_boolean( &gvalue );
2366 g_value_unset( &gvalue );
2367
2368 value = tmp;
2369
2370 return true;
2371 }
2372
2373 // ---------------------------------------------------------
2374 // wxDataViewCustomRenderer
2375 // ---------------------------------------------------------
2376
2377 class wxDataViewCtrlDCImpl: public wxWindowDCImpl
2378 {
2379 public:
2380 wxDataViewCtrlDCImpl( wxDC *owner, wxDataViewCtrl *window ) :
2381 wxWindowDCImpl( owner )
2382 {
2383 GtkWidget *widget = window->m_treeview;
2384 // Set later
2385 m_gdkwindow = NULL;
2386
2387 m_window = window;
2388
2389 m_context = window->GTKGetPangoDefaultContext();
2390 m_layout = pango_layout_new( m_context );
2391 m_fontdesc = pango_font_description_copy(gtk_widget_get_style(widget)->font_desc);
2392
2393 m_cmap = gtk_widget_get_colormap( widget ? widget : window->m_widget );
2394
2395 // Set m_gdkwindow later
2396 // SetUpDC();
2397 }
2398 };
2399
2400 class wxDataViewCtrlDC: public wxWindowDC
2401 {
2402 public:
2403 wxDataViewCtrlDC( wxDataViewCtrl *window ) :
2404 wxWindowDC( new wxDataViewCtrlDCImpl( this, window ) )
2405 { }
2406 };
2407
2408
2409 // ---------------------------------------------------------
2410 // wxDataViewCustomRenderer
2411 // ---------------------------------------------------------
2412
2413 IMPLEMENT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer)
2414
2415 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype,
2416 wxDataViewCellMode mode,
2417 int align,
2418 bool no_init )
2419 : wxDataViewCustomRendererBase( varianttype, mode, align )
2420 {
2421 m_dc = NULL;
2422 m_text_renderer = NULL;
2423
2424 if (no_init)
2425 m_renderer = NULL;
2426 else
2427 Init(mode, align);
2428 }
2429
2430 void wxDataViewCustomRenderer::GtkInitTextRenderer()
2431 {
2432 m_text_renderer = GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new());
2433 g_object_ref_sink(m_text_renderer);
2434
2435 GtkApplyAlignment(GTK_CELL_RENDERER(m_text_renderer));
2436 }
2437
2438 GtkCellRendererText *wxDataViewCustomRenderer::GtkGetTextRenderer() const
2439 {
2440 if ( !m_text_renderer )
2441 {
2442 // we create it on demand so need to do it even from a const function
2443 const_cast<wxDataViewCustomRenderer *>(this)->GtkInitTextRenderer();
2444 }
2445
2446 return m_text_renderer;
2447 }
2448
2449 void wxDataViewCustomRenderer::RenderText( const wxString &text,
2450 int xoffset,
2451 wxRect cell,
2452 wxDC *WXUNUSED(dc),
2453 int WXUNUSED(state) )
2454 {
2455
2456 GtkCellRendererText * const textRenderer = GtkGetTextRenderer();
2457
2458 GValue gvalue = { 0, };
2459 g_value_init( &gvalue, G_TYPE_STRING );
2460 g_value_set_string( &gvalue, wxGTK_CONV_FONT( text, GetOwner()->GetOwner()->GetFont() ) );
2461 g_object_set_property( G_OBJECT(textRenderer), "text", &gvalue );
2462 g_value_unset( &gvalue );
2463
2464 GtkApplyAttr(textRenderer, GetAttr());
2465
2466 GdkRectangle cell_area;
2467 wxRectToGDKRect(cell, cell_area);
2468 cell_area.x += xoffset;
2469 cell_area.width -= xoffset;
2470
2471 gtk_cell_renderer_render( GTK_CELL_RENDERER(textRenderer),
2472 m_renderParams.window,
2473 m_renderParams.widget,
2474 m_renderParams.background_area,
2475 &cell_area,
2476 m_renderParams.expose_area,
2477 (GtkCellRendererState) m_renderParams.flags );
2478 }
2479
2480 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode, int align)
2481 {
2482 GtkWxCellRenderer *renderer = (GtkWxCellRenderer *) gtk_wx_cell_renderer_new();
2483 renderer->cell = this;
2484
2485 m_renderer = (GtkCellRenderer*) renderer;
2486
2487 SetMode(mode);
2488 SetAlignment(align);
2489
2490 GtkInitHandlers();
2491
2492 return true;
2493 }
2494
2495 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
2496 {
2497 if (m_dc)
2498 delete m_dc;
2499
2500 if (m_text_renderer)
2501 g_object_unref(m_text_renderer);
2502 }
2503
2504 wxDC *wxDataViewCustomRenderer::GetDC()
2505 {
2506 if (m_dc == NULL)
2507 {
2508 if (GetOwner() == NULL)
2509 return NULL;
2510 if (GetOwner()->GetOwner() == NULL)
2511 return NULL;
2512 m_dc = new wxDataViewCtrlDC( GetOwner()->GetOwner() );
2513 }
2514
2515 return m_dc;
2516 }
2517
2518 // ---------------------------------------------------------
2519 // wxDataViewProgressRenderer
2520 // ---------------------------------------------------------
2521
2522 IMPLEMENT_CLASS(wxDataViewProgressRenderer, wxDataViewCustomRenderer)
2523
2524 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString &label,
2525 const wxString &varianttype, wxDataViewCellMode mode, int align ) :
2526 wxDataViewCustomRenderer( varianttype, mode, align, true )
2527 {
2528 m_label = label;
2529 m_value = 0;
2530
2531 #ifdef __WXGTK26__
2532 if (!gtk_check_version(2,6,0))
2533 {
2534 m_renderer = (GtkCellRenderer*) gtk_cell_renderer_progress_new();
2535
2536 SetMode(mode);
2537 SetAlignment(align);
2538
2539 #if !wxUSE_UNICODE
2540 // We can't initialize the renderer just yet because we don't have the
2541 // pointer to the column that uses this renderer yet and so attempt to
2542 // dereference GetOwner() to get the font that is used as a source of
2543 // encoding in multibyte-to-Unicode conversion in GTKSetLabel() in
2544 // non-Unicode builds would crash. So simply remember to do it later.
2545 if ( !m_label.empty() )
2546 m_needsToSetLabel = true;
2547 else
2548 #endif // !wxUSE_UNICODE
2549 GTKSetLabel();
2550 }
2551 else
2552 #endif
2553 {
2554 // Use custom cell code
2555 wxDataViewCustomRenderer::Init(mode, align);
2556 }
2557 }
2558
2559 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
2560 {
2561 }
2562
2563 void wxDataViewProgressRenderer::GTKSetLabel()
2564 {
2565 GValue gvalue = { 0, };
2566 g_value_init( &gvalue, G_TYPE_STRING );
2567
2568 // Take care to not use GetOwner() here if the label is empty, we can be
2569 // called from ctor when GetOwner() is still NULL in this case.
2570 g_value_set_string( &gvalue,
2571 m_label.empty() ? ""
2572 : wxGTK_CONV_FONT(m_label,
2573 GetOwner()->GetOwner()->GetFont())
2574 );
2575 g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue );
2576 g_value_unset( &gvalue );
2577
2578 #if !wxUSE_UNICODE
2579 m_needsToSetLabel = false;
2580 #endif // !wxUSE_UNICODE
2581 }
2582
2583 bool wxDataViewProgressRenderer::SetValue( const wxVariant &value )
2584 {
2585 #ifdef __WXGTK26__
2586 if (!gtk_check_version(2,6,0))
2587 {
2588 #if !wxUSE_UNICODE
2589 if ( m_needsToSetLabel )
2590 GTKSetLabel();
2591 #endif // !wxUSE_UNICODE
2592
2593 gint tmp = (long) value;
2594 GValue gvalue = { 0, };
2595 g_value_init( &gvalue, G_TYPE_INT );
2596 g_value_set_int( &gvalue, tmp );
2597 g_object_set_property( G_OBJECT(m_renderer), "value", &gvalue );
2598 g_value_unset( &gvalue );
2599 }
2600 else
2601 #endif
2602 {
2603 m_value = (long) value;
2604
2605 if (m_value < 0) m_value = 0;
2606 if (m_value > 100) m_value = 100;
2607 }
2608
2609 return true;
2610 }
2611
2612 bool wxDataViewProgressRenderer::GetValue( wxVariant &WXUNUSED(value) ) const
2613 {
2614 return false;
2615 }
2616
2617 bool wxDataViewProgressRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) )
2618 {
2619 double pct = (double)m_value / 100.0;
2620 wxRect bar = cell;
2621 bar.width = (int)(cell.width * pct);
2622 dc->SetPen( *wxTRANSPARENT_PEN );
2623 dc->SetBrush( *wxBLUE_BRUSH );
2624 dc->DrawRectangle( bar );
2625
2626 dc->SetBrush( *wxTRANSPARENT_BRUSH );
2627 dc->SetPen( *wxBLACK_PEN );
2628 dc->DrawRectangle( cell );
2629
2630 return true;
2631 }
2632
2633 wxSize wxDataViewProgressRenderer::GetSize() const
2634 {
2635 return wxSize(40,12);
2636 }
2637
2638 // -------------------------------------
2639 // wxDataViewChoiceRenderer
2640 // -------------------------------------
2641
2642 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString &choices,
2643 wxDataViewCellMode mode, int alignment ) :
2644 wxDataViewCustomRenderer( "string", mode, alignment, true )
2645 {
2646 m_choices = choices;
2647
2648 #ifdef __WXGTK26__
2649 if (!gtk_check_version(2,6,0))
2650 {
2651 m_renderer = (GtkCellRenderer*) gtk_cell_renderer_combo_new();
2652
2653 GtkListStore *store = gtk_list_store_new( 1, G_TYPE_STRING );
2654 for (size_t n = 0; n < m_choices.GetCount(); n++)
2655 {
2656 gtk_list_store_insert_with_values(
2657 store, NULL, n, 0,
2658 static_cast<const char *>(m_choices[n].utf8_str()), -1 );
2659 }
2660
2661 g_object_set (m_renderer,
2662 "model", store,
2663 "text-column", 0,
2664 "has-entry", FALSE,
2665 NULL);
2666
2667 bool editable = (mode & wxDATAVIEW_CELL_EDITABLE);
2668 g_object_set (m_renderer, "editable", editable, NULL);
2669
2670 SetAlignment(alignment);
2671
2672 g_signal_connect_after( m_renderer, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback), this );
2673
2674 GtkInitHandlers();
2675 }
2676 else
2677 #endif
2678 {
2679 // Use custom cell code
2680 wxDataViewCustomRenderer::Init(mode, alignment);
2681 }
2682 }
2683
2684 bool wxDataViewChoiceRenderer::Render( wxRect rect, wxDC *dc, int state )
2685 {
2686 RenderText( m_data, 0, rect, dc, state );
2687 return true;
2688 }
2689
2690 wxSize wxDataViewChoiceRenderer::GetSize() const
2691 {
2692 return wxSize(70,20);
2693 }
2694
2695 bool wxDataViewChoiceRenderer::SetValue( const wxVariant &value )
2696 {
2697
2698 #ifdef __WXGTK26__
2699 if (!gtk_check_version(2,6,0))
2700 {
2701 GValue gvalue = { 0, };
2702 g_value_init( &gvalue, G_TYPE_STRING );
2703 g_value_set_string(&gvalue,
2704 wxGTK_CONV_FONT(value.GetString(),
2705 GetOwner()->GetOwner()->GetFont()));
2706 g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue );
2707 g_value_unset( &gvalue );
2708 }
2709 else
2710 #endif
2711 m_data = value.GetString();
2712
2713 return true;
2714 }
2715
2716 bool wxDataViewChoiceRenderer::GetValue( wxVariant &value ) const
2717 {
2718 #ifdef __WXGTK26__
2719 if (!gtk_check_version(2,6,0))
2720 {
2721 GValue gvalue = { 0, };
2722 g_value_init( &gvalue, G_TYPE_STRING );
2723 g_object_get_property( G_OBJECT(m_renderer), "text", &gvalue );
2724 wxString temp = wxGTK_CONV_BACK_FONT(g_value_get_string(&gvalue),
2725 GetOwner()->GetOwner()->GetFont());
2726 g_value_unset( &gvalue );
2727 value = temp;
2728
2729 //wxPrintf( "temp %s\n", temp );
2730 // TODO: remove this code
2731 }
2732 else
2733 #endif
2734 value = m_data;
2735
2736 return true;
2737 }
2738
2739 void wxDataViewChoiceRenderer::SetAlignment( int align )
2740 {
2741 wxDataViewCustomRenderer::SetAlignment(align);
2742
2743 if (gtk_check_version(2,10,0))
2744 return;
2745
2746 // horizontal alignment:
2747 PangoAlignment pangoAlign = PANGO_ALIGN_LEFT;
2748 if (align & wxALIGN_RIGHT)
2749 pangoAlign = PANGO_ALIGN_RIGHT;
2750 else if (align & wxALIGN_CENTER_HORIZONTAL)
2751 pangoAlign = PANGO_ALIGN_CENTER;
2752
2753 GValue gvalue = { 0, };
2754 g_value_init( &gvalue, gtk_cell_renderer_mode_get_type() );
2755 g_value_set_enum( &gvalue, pangoAlign );
2756 g_object_set_property( G_OBJECT(m_renderer), "alignment", &gvalue );
2757 g_value_unset( &gvalue );
2758 }
2759
2760 // ----------------------------------------------------------------------------
2761 // wxDataViewChoiceByIndexRenderer
2762 // ----------------------------------------------------------------------------
2763
2764 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString &choices,
2765 wxDataViewCellMode mode, int alignment ) :
2766 wxDataViewChoiceRenderer( choices, mode, alignment )
2767 {
2768 }
2769
2770 void wxDataViewChoiceByIndexRenderer::GtkOnTextEdited(const char *itempath, const wxString& str)
2771 {
2772 wxVariant value( (long) GetChoices().Index( str ) );
2773
2774 if (!Validate( value ))
2775 return;
2776
2777 wxDataViewItem
2778 item(GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(itempath)));
2779
2780 GtkOnCellChanged(value, item, GetOwner()->GetModelColumn());
2781 }
2782
2783 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant &value )
2784 {
2785 wxVariant string_value = GetChoice( value.GetLong() );
2786 return wxDataViewChoiceRenderer::SetValue( string_value );
2787 }
2788
2789 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant &value ) const
2790 {
2791 wxVariant string_value;
2792 if (!wxDataViewChoiceRenderer::GetValue( string_value ))
2793 return false;
2794
2795 value = (long) GetChoices().Index( string_value.GetString() );
2796 return true;
2797 }
2798
2799 // ---------------------------------------------------------
2800 // wxDataViewIconTextRenderer
2801 // ---------------------------------------------------------
2802
2803 IMPLEMENT_CLASS(wxDataViewIconTextRenderer, wxDataViewCustomRenderer)
2804
2805 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer
2806 (
2807 const wxString &varianttype,
2808 wxDataViewCellMode mode,
2809 int align
2810 )
2811 : wxDataViewTextRenderer(varianttype, mode, align)
2812 {
2813 m_rendererIcon = gtk_cell_renderer_pixbuf_new();
2814 }
2815
2816 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
2817 {
2818 }
2819
2820 void wxDataViewIconTextRenderer::GtkPackIntoColumn(GtkTreeViewColumn *column)
2821 {
2822 // add the icon renderer first
2823 gtk_tree_view_column_pack_start(column, m_rendererIcon, FALSE /* !expand */);
2824
2825 // add the text renderer too
2826 wxDataViewRenderer::GtkPackIntoColumn(column);
2827 }
2828
2829 bool wxDataViewIconTextRenderer::SetValue( const wxVariant &value )
2830 {
2831 m_value << value;
2832
2833 SetTextValue(m_value.GetText());
2834 SetPixbufProp(m_rendererIcon, m_value.GetIcon().GetPixbuf());
2835
2836 return true;
2837 }
2838
2839 bool wxDataViewIconTextRenderer::GetValue(wxVariant& value) const
2840 {
2841 wxString str;
2842 if ( !GetTextValue(str) )
2843 return false;
2844
2845 // user doesn't have any way to edit the icon so leave it unchanged
2846 value << wxDataViewIconText(str, m_value.GetIcon());
2847
2848 return true;
2849 }
2850
2851 void
2852 wxDataViewIconTextRenderer::GtkOnCellChanged(const wxVariant& value,
2853 const wxDataViewItem& item,
2854 unsigned col)
2855 {
2856 // we receive just the text part of our value as it's the only one which
2857 // can be edited, but we need the full wxDataViewIconText value for the
2858 // model
2859 wxVariant valueIconText;
2860 valueIconText << wxDataViewIconText(value.GetString(), m_value.GetIcon());
2861 wxDataViewTextRenderer::GtkOnCellChanged(valueIconText, item, col);
2862 }
2863
2864 // ---------------------------------------------------------
2865 // wxDataViewColumn
2866 // ---------------------------------------------------------
2867
2868
2869 static gboolean
2870 gtk_dataview_header_button_press_callback( GtkWidget *WXUNUSED(widget),
2871 GdkEventButton *gdk_event,
2872 wxDataViewColumn *column )
2873 {
2874 if (gdk_event->type != GDK_BUTTON_PRESS)
2875 return FALSE;
2876
2877 if (gdk_event->button == 1)
2878 {
2879 gs_lastLeftClickHeader = column;
2880
2881 wxDataViewCtrl *dv = column->GetOwner();
2882 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, dv->GetId() );
2883 event.SetDataViewColumn( column );
2884 event.SetModel( dv->GetModel() );
2885 if (dv->HandleWindowEvent( event ))
2886 return FALSE;
2887 }
2888
2889 if (gdk_event->button == 3)
2890 {
2891 wxDataViewCtrl *dv = column->GetOwner();
2892 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, dv->GetId() );
2893 event.SetDataViewColumn( column );
2894 event.SetModel( dv->GetModel() );
2895 if (dv->HandleWindowEvent( event ))
2896 return FALSE;
2897 }
2898
2899 return FALSE;
2900 }
2901
2902 extern "C"
2903 {
2904
2905 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *WXUNUSED(column),
2906 GtkCellRenderer *renderer,
2907 GtkTreeModel *model,
2908 GtkTreeIter *iter,
2909 gpointer data )
2910 {
2911 g_return_if_fail (GTK_IS_WX_TREE_MODEL (model));
2912 GtkWxTreeModel *tree_model = (GtkWxTreeModel *) model;
2913
2914 wxDataViewRenderer *cell = (wxDataViewRenderer*) data;
2915
2916 wxDataViewItem item( (void*) iter->user_data );
2917
2918 wxDataViewModel *wx_model = tree_model->internal->GetDataViewModel();
2919
2920 if (!wx_model->IsVirtualListModel())
2921 {
2922 gboolean visible;
2923 if (wx_model->IsContainer( item ))
2924 {
2925 visible = wx_model->HasContainerColumns( item ) ||
2926 (cell->GetOwner()->GetModelColumn() == 0);
2927 }
2928 else
2929 {
2930 visible = true;
2931 }
2932
2933 GValue gvalue = { 0, };
2934 g_value_init( &gvalue, G_TYPE_BOOLEAN );
2935 g_value_set_boolean( &gvalue, visible );
2936 g_object_set_property( G_OBJECT(renderer), "visible", &gvalue );
2937 g_value_unset( &gvalue );
2938
2939 if ( !visible )
2940 return;
2941 }
2942
2943 wxVariant value;
2944 wx_model->GetValue( value, item, cell->GetOwner()->GetModelColumn() );
2945
2946 if (value.GetType() != cell->GetVariantType())
2947 {
2948 wxLogError( wxT("Wrong type, required: %s but: %s"),
2949 value.GetType().c_str(),
2950 cell->GetVariantType().c_str() );
2951 }
2952
2953 cell->SetValue( value );
2954
2955 // deal with disabled items
2956 bool enabled = wx_model->IsEnabled( item, cell->GetOwner()->GetModelColumn() );
2957
2958 // a) this sets the appearance to disabled grey
2959 GValue gvalue = { 0, };
2960 g_value_init( &gvalue, G_TYPE_BOOLEAN );
2961 g_value_set_boolean( &gvalue, enabled );
2962 g_object_set_property( G_OBJECT(renderer), "sensitive", &gvalue );
2963 g_value_unset( &gvalue );
2964
2965 // b) this actually disables the control/renderer
2966 if (enabled)
2967 cell->SetMode( cell->GtkGetMode() );
2968 else
2969 cell->SetMode( wxDATAVIEW_CELL_INERT );
2970
2971
2972 // deal with attributes: if the renderer doesn't support them at all, we
2973 // don't even need to query the model for them
2974 if ( !cell->GtkSupportsAttrs() )
2975 return;
2976
2977 // it can support attributes so check if this item has any
2978 wxDataViewItemAttr attr;
2979 if ( wx_model->GetAttr( item, cell->GetOwner()->GetModelColumn(), attr )
2980 || !cell->GtkIsUsingDefaultAttrs() )
2981 {
2982 bool usingDefaultAttrs = !cell->GtkSetAttr(attr);
2983 cell->GtkSetUsingDefaultAttrs(usingDefaultAttrs);
2984 }
2985 // else: no custom attributes specified and we're already using the default
2986 // ones -- nothing to do
2987
2988 }
2989
2990 } // extern "C"
2991
2992 #include <wx/listimpl.cpp>
2993 WX_DEFINE_LIST(wxDataViewColumnList)
2994
2995 wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewRenderer *cell,
2996 unsigned int model_column, int width,
2997 wxAlignment align, int flags )
2998 : wxDataViewColumnBase( cell, model_column )
2999 {
3000 Init( align, flags, width );
3001
3002 SetTitle( title );
3003 }
3004
3005 wxDataViewColumn::wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *cell,
3006 unsigned int model_column, int width,
3007 wxAlignment align, int flags )
3008 : wxDataViewColumnBase( bitmap, cell, model_column )
3009 {
3010 Init( align, flags, width );
3011
3012 SetBitmap( bitmap );
3013 }
3014
3015 void wxDataViewColumn::Init(wxAlignment align, int flags, int width)
3016 {
3017 m_isConnected = false;
3018
3019 GtkTreeViewColumn *column = gtk_tree_view_column_new();
3020 m_column = (GtkWidget*) column;
3021
3022 SetFlags( flags );
3023 SetAlignment( align );
3024
3025 SetWidth( width );
3026
3027 // Create container for icon and label
3028 GtkWidget *box = gtk_hbox_new( FALSE, 1 );
3029 gtk_widget_show( box );
3030 // gtk_container_set_border_width((GtkContainer*)box, 2);
3031 m_image = gtk_image_new();
3032 gtk_box_pack_start(GTK_BOX(box), m_image, FALSE, FALSE, 1);
3033 m_label = gtk_label_new("");
3034 gtk_box_pack_end( GTK_BOX(box), GTK_WIDGET(m_label), FALSE, FALSE, 1 );
3035 gtk_tree_view_column_set_widget( column, box );
3036
3037 wxDataViewRenderer * const colRenderer = GetRenderer();
3038 GtkCellRenderer * const cellRenderer = colRenderer->GetGtkHandle();
3039
3040 colRenderer->GtkPackIntoColumn(column);
3041
3042 gtk_tree_view_column_set_cell_data_func( column, cellRenderer,
3043 wxGtkTreeCellDataFunc, (gpointer) colRenderer, NULL );
3044 }
3045
3046 void wxDataViewColumn::OnInternalIdle()
3047 {
3048 if (m_isConnected)
3049 return;
3050
3051 if (gtk_widget_get_realized(GetOwner()->m_treeview))
3052 {
3053 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
3054 if (column->button)
3055 {
3056 g_signal_connect(column->button, "button_press_event",
3057 G_CALLBACK (gtk_dataview_header_button_press_callback), this);
3058
3059 // otherwise the event will be blocked by GTK+
3060 gtk_tree_view_column_set_clickable( column, TRUE );
3061
3062 m_isConnected = true;
3063 }
3064 }
3065 }
3066
3067 void wxDataViewColumn::SetOwner( wxDataViewCtrl *owner )
3068 {
3069 wxDataViewColumnBase::SetOwner( owner );
3070
3071 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
3072
3073 gtk_tree_view_column_set_title( column, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
3074 }
3075
3076 void wxDataViewColumn::SetTitle( const wxString &title )
3077 {
3078 wxDataViewCtrl *ctrl = GetOwner();
3079 gtk_label_set_text( GTK_LABEL(m_label), ctrl ? wxGTK_CONV_FONT(title, ctrl->GetFont())
3080 : wxGTK_CONV_SYS(title) );
3081 if (title.empty())
3082 gtk_widget_hide( m_label );
3083 else
3084 gtk_widget_show( m_label );
3085 }
3086
3087 wxString wxDataViewColumn::GetTitle() const
3088 {
3089 return wxGTK_CONV_BACK_FONT(
3090 gtk_label_get_text( GTK_LABEL(m_label) ),
3091 GetOwner()->GetFont()
3092 );
3093 }
3094
3095 void wxDataViewColumn::SetBitmap( const wxBitmap &bitmap )
3096 {
3097 wxDataViewColumnBase::SetBitmap( bitmap );
3098
3099 if (bitmap.IsOk())
3100 {
3101 GtkImage *gtk_image = GTK_IMAGE(m_image);
3102
3103 GdkBitmap *mask = NULL;
3104 if (bitmap.GetMask())
3105 mask = bitmap.GetMask()->GetBitmap();
3106
3107 if (bitmap.HasPixbuf())
3108 {
3109 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image),
3110 bitmap.GetPixbuf());
3111 }
3112 else
3113 {
3114 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image),
3115 bitmap.GetPixmap(), mask);
3116 }
3117 gtk_widget_show( m_image );
3118 }
3119 else
3120 {
3121 gtk_widget_hide( m_image );
3122 }
3123 }
3124
3125 void wxDataViewColumn::SetHidden( bool hidden )
3126 {
3127 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column), !hidden );
3128 }
3129
3130 void wxDataViewColumn::SetResizeable( bool resizable )
3131 {
3132 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column), resizable );
3133 }
3134
3135 void wxDataViewColumn::SetAlignment( wxAlignment align )
3136 {
3137 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
3138
3139 gfloat xalign = 0.0;
3140 if (align == wxALIGN_RIGHT)
3141 xalign = 1.0;
3142 if (align == wxALIGN_CENTER_HORIZONTAL ||
3143 align == wxALIGN_CENTER)
3144 xalign = 0.5;
3145
3146 gtk_tree_view_column_set_alignment( column, xalign );
3147
3148 if (m_renderer && m_renderer->GetAlignment() == -1)
3149 m_renderer->GtkUpdateAlignment();
3150 }
3151
3152 wxAlignment wxDataViewColumn::GetAlignment() const
3153 {
3154 gfloat xalign = gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column) );
3155
3156 if (xalign == 1.0)
3157 return wxALIGN_RIGHT;
3158 if (xalign == 0.5)
3159 return wxALIGN_CENTER_HORIZONTAL;
3160
3161 return wxALIGN_LEFT;
3162 }
3163
3164 void wxDataViewColumn::SetSortable( bool sortable )
3165 {
3166 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
3167
3168 if ( sortable )
3169 {
3170 gtk_tree_view_column_set_sort_column_id( column, GetModelColumn() );
3171 }
3172 else
3173 {
3174 gtk_tree_view_column_set_sort_column_id( column, -1 );
3175 gtk_tree_view_column_set_sort_indicator( column, FALSE );
3176 gtk_tree_view_column_set_clickable( column, FALSE );
3177 }
3178 }
3179
3180 bool wxDataViewColumn::IsSortable() const
3181 {
3182 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
3183 return gtk_tree_view_column_get_clickable( column );
3184 }
3185
3186 bool wxDataViewColumn::IsSortKey() const
3187 {
3188 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
3189 return gtk_tree_view_column_get_sort_indicator( column );
3190 }
3191
3192 bool wxDataViewColumn::IsResizeable() const
3193 {
3194 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
3195 return gtk_tree_view_column_get_resizable( column );
3196 }
3197
3198 bool wxDataViewColumn::IsHidden() const
3199 {
3200 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
3201 return !gtk_tree_view_column_get_visible( column );
3202 }
3203
3204 void wxDataViewColumn::SetSortOrder( bool ascending )
3205 {
3206 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
3207
3208 if (ascending)
3209 gtk_tree_view_column_set_sort_order( column, GTK_SORT_ASCENDING );
3210 else
3211 gtk_tree_view_column_set_sort_order( column, GTK_SORT_DESCENDING );
3212
3213 gtk_tree_view_column_set_sort_indicator( column, TRUE );
3214 }
3215
3216 bool wxDataViewColumn::IsSortOrderAscending() const
3217 {
3218 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
3219
3220 return (gtk_tree_view_column_get_sort_order( column ) != GTK_SORT_DESCENDING);
3221 }
3222
3223 void wxDataViewColumn::SetMinWidth( int width )
3224 {
3225 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column), width );
3226 }
3227
3228 int wxDataViewColumn::GetMinWidth() const
3229 {
3230 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column) );
3231 }
3232
3233 int wxDataViewColumn::GetWidth() const
3234 {
3235 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column) );
3236 }
3237
3238 void wxDataViewColumn::SetWidth( int width )
3239 {
3240 if ( width == wxCOL_WIDTH_AUTOSIZE )
3241 {
3242 // NB: this disables user resizing
3243 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column), GTK_TREE_VIEW_COLUMN_AUTOSIZE );
3244 }
3245 else
3246 {
3247 if ( width == wxCOL_WIDTH_DEFAULT )
3248 {
3249 // TODO find a better calculation
3250 width = wxDVC_DEFAULT_WIDTH;
3251 }
3252
3253 gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column), GTK_TREE_VIEW_COLUMN_FIXED );
3254 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column), width );
3255 }
3256 }
3257
3258 void wxDataViewColumn::SetReorderable( bool reorderable )
3259 {
3260 gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column), reorderable );
3261 }
3262
3263 bool wxDataViewColumn::IsReorderable() const
3264 {
3265 return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column) );
3266 }
3267
3268 //-----------------------------------------------------------------------------
3269 // wxGtkTreeModelNode
3270 //-----------------------------------------------------------------------------
3271
3272 #if 0
3273 class wxGtkTreeModelChildWithPos
3274 {
3275 public:
3276 unsigned int pos;
3277 void *id;
3278 };
3279
3280 static
3281 int wxGtkTreeModelChildWithPosCmp( const void* data1, const void* data2, const void* user_data )
3282 {
3283 const wxGtkTreeModelChildWithPos* child1 = (const wxGtkTreeModelChildWithPos*) data1;
3284 const wxGtkTreeModelChildWithPos* child2 = (const wxGtkTreeModelChildWithPos*) data2;
3285 const wxDataViewCtrlInternal *internal = (const wxDataViewCtrlInternal *) user_data;
3286 int ret = internal->GetDataViewModel()->Compare( child1->id, child2->id,
3287 internal->GetSortColumn(), (internal->GetSortOrder() == GTK_SORT_DESCENDING) );
3288
3289 return ret;
3290 }
3291 #else
3292 static
3293 int LINKAGEMODE wxGtkTreeModelChildPtrCmp( void*** data1, void*** data2 )
3294 {
3295 return gs_internal->GetDataViewModel()->Compare( wxDataViewItem(**data1), wxDataViewItem(**data2),
3296 gs_internal->GetSortColumn(), (gs_internal->GetSortOrder() == GTK_SORT_ASCENDING) );
3297 }
3298
3299 WX_DEFINE_ARRAY_PTR( void**, wxGtkTreeModelChildrenPtr );
3300 #endif
3301
3302 void wxGtkTreeModelNode::Resort()
3303 {
3304 size_t child_count = GetChildCount();
3305 if (child_count == 0)
3306 return;
3307
3308 size_t node_count = GetNodesCount();
3309
3310 if (child_count == 1)
3311 {
3312 if (node_count == 1)
3313 {
3314 wxGtkTreeModelNode *node = m_nodes.Item( 0 );
3315 node->Resort();
3316 }
3317 return;
3318 }
3319
3320 gint *new_order = new gint[child_count];
3321
3322 #if 1
3323 // m_children has the original *void
3324 // ptrs points to these
3325 wxGtkTreeModelChildrenPtr ptrs;
3326 size_t i;
3327 for (i = 0; i < child_count; i++)
3328 ptrs.Add( &(m_children[i]) );
3329 // Sort the ptrs
3330 gs_internal = m_internal;
3331 ptrs.Sort( &wxGtkTreeModelChildPtrCmp );
3332
3333 wxGtkTreeModelChildren temp;
3334 void** base_ptr = &(m_children[0]);
3335 // Transfer positions to new_order array and
3336 // IDs to temp
3337 for (i = 0; i < child_count; i++)
3338 {
3339 new_order[i] = ptrs[i] - base_ptr;
3340 temp.Add( *ptrs[i] );
3341 }
3342
3343 // Transfer IDs back to m_children
3344 m_children.Clear();
3345 WX_APPEND_ARRAY( temp, m_children );
3346 #endif
3347 #if 0
3348 // Too slow
3349
3350 // Build up array with IDs and original positions
3351 wxGtkTreeModelChildWithPos* temp = new wxGtkTreeModelChildWithPos[child_count];
3352 size_t i;
3353 for (i = 0; i < child_count; i++)
3354 {
3355 temp[i].pos = i;
3356 temp[i].id = m_children[i];
3357 }
3358 // Sort array keeping original positions
3359 wxQsort( temp, child_count, sizeof(wxGtkTreeModelChildWithPos),
3360 &wxGtkTreeModelChildWithPosCmp, m_internal );
3361 // Transfer positions to new_order array and
3362 // IDs to m_children
3363 m_children.Clear();
3364 for (i = 0; i < child_count; i++)
3365 {
3366 new_order[i] = temp[i].pos;
3367 m_children.Add( temp[i].id );
3368 }
3369 // Delete array
3370 delete [] temp;
3371 #endif
3372
3373 #if 0
3374 // Too slow
3375
3376 wxGtkTreeModelChildren temp;
3377 WX_APPEND_ARRAY( temp, m_children );
3378
3379 gs_internal = m_internal;
3380 m_children.Sort( &wxGtkTreeModelChildCmp );
3381
3382 unsigned int pos;
3383 for (pos = 0; pos < child_count; pos++)
3384 {
3385 void *id = m_children.Item( pos );
3386 int old_pos = temp.Index( id );
3387 new_order[pos] = old_pos;
3388 }
3389 #endif
3390
3391 GtkTreeModel *gtk_tree_model = GTK_TREE_MODEL( m_internal->GetGtkModel() );
3392
3393 GtkTreeIter iter;
3394 iter.user_data = GetItem().GetID();
3395 iter.stamp = m_internal->GetGtkModel()->stamp;
3396
3397 gtk_tree_model_rows_reordered( gtk_tree_model,
3398 wxGtkTreePath(m_internal->get_path(&iter)), &iter, new_order );
3399
3400 delete [] new_order;
3401
3402 unsigned int pos;
3403 for (pos = 0; pos < node_count; pos++)
3404 {
3405 wxGtkTreeModelNode *node = m_nodes.Item( pos );
3406 node->Resort();
3407 }
3408 }
3409
3410 //-----------------------------------------------------------------------------
3411 // wxDataViewCtrlInternal
3412 //-----------------------------------------------------------------------------
3413
3414 wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl *owner, wxDataViewModel *wx_model )
3415 {
3416 m_owner = owner;
3417 m_wx_model = wx_model;
3418
3419 m_gtk_model = NULL;
3420 m_root = NULL;
3421 m_sort_order = GTK_SORT_ASCENDING;
3422 m_sort_column = -1;
3423 m_dataview_sort_column = NULL;
3424
3425 m_dragDataObject = NULL;
3426 m_dropDataObject = NULL;
3427
3428 m_dirty = false;
3429
3430 m_gtk_model = wxgtk_tree_model_new();
3431 m_gtk_model->internal = this;
3432
3433 m_notifier = new wxGtkDataViewModelNotifier( wx_model, this );
3434
3435 wx_model->AddNotifier( m_notifier );
3436
3437 // g_object_unref( gtk_model ); ???
3438
3439 if (!m_wx_model->IsVirtualListModel())
3440 InitTree();
3441
3442 gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner->GtkGetTreeView()), GTK_TREE_MODEL(m_gtk_model) );
3443 }
3444
3445 wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
3446 {
3447 m_wx_model->RemoveNotifier( m_notifier );
3448
3449 // remove the model from the GtkTreeView before it gets destroyed
3450 gtk_tree_view_set_model( GTK_TREE_VIEW( m_owner->GtkGetTreeView() ), NULL );
3451
3452 g_object_unref( m_gtk_model );
3453
3454 delete m_dragDataObject;
3455 delete m_dropDataObject;
3456 }
3457
3458 void wxDataViewCtrlInternal::ScheduleRefresh()
3459 {
3460 m_dirty = true;
3461 }
3462
3463 void wxDataViewCtrlInternal::OnInternalIdle()
3464 {
3465 if (m_dirty)
3466 {
3467 GtkWidget *widget = m_owner->GtkGetTreeView();
3468 gtk_widget_queue_draw( widget );
3469 m_dirty = false;
3470 }
3471 }
3472
3473 void wxDataViewCtrlInternal::InitTree()
3474 {
3475 wxDataViewItem item;
3476 m_root = new wxGtkTreeModelNode( NULL, item, this );
3477
3478 BuildBranch( m_root );
3479 }
3480
3481 void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode *node )
3482 {
3483 if (node->GetChildCount() == 0)
3484 {
3485 wxDataViewItemArray children;
3486 unsigned int count = m_wx_model->GetChildren( node->GetItem(), children );
3487
3488 unsigned int pos;
3489 for (pos = 0; pos < count; pos++)
3490 {
3491 wxDataViewItem child = children[pos];
3492
3493 if (m_wx_model->IsContainer( child ))
3494 node->AddNode( new wxGtkTreeModelNode( node, child, this ) );
3495 else
3496 node->AddLeaf( child.GetID() );
3497
3498 // Don't send any events here
3499 }
3500 }
3501 }
3502
3503 // GTK+ dnd iface
3504
3505 bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat &format )
3506 {
3507 wxGtkString atom_str( gdk_atom_name( format ) );
3508 m_dragSourceTargetEntryTarget = wxCharBuffer( atom_str );
3509
3510 m_dragSourceTargetEntry.target = m_dragSourceTargetEntryTarget.data();
3511 m_dragSourceTargetEntry.flags = 0;
3512 m_dragSourceTargetEntry.info = static_cast<guint>(-1);
3513
3514 gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner->GtkGetTreeView() ),
3515 GDK_BUTTON1_MASK, &m_dragSourceTargetEntry, 1, (GdkDragAction) GDK_ACTION_COPY );
3516
3517 return true;
3518 }
3519
3520 bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat &format )
3521 {
3522 wxGtkString atom_str( gdk_atom_name( format ) );
3523 m_dropTargetTargetEntryTarget = wxCharBuffer( atom_str );
3524
3525 m_dropTargetTargetEntry.target = m_dropTargetTargetEntryTarget.data();
3526 m_dropTargetTargetEntry.flags = 0;
3527 m_dropTargetTargetEntry.info = static_cast<guint>(-1);
3528
3529 gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner->GtkGetTreeView() ),
3530 &m_dropTargetTargetEntry, 1, (GdkDragAction) GDK_ACTION_COPY );
3531
3532 return true;
3533 }
3534
3535 gboolean wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource *WXUNUSED(drag_source),
3536 GtkTreePath *path )
3537 {
3538 delete m_dragDataObject;
3539 m_dragDataObject = NULL;
3540
3541 wxDataViewItem item(GetOwner()->GTKPathToItem(path));
3542 if ( !item )
3543 return FALSE;
3544
3545 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG, m_owner->GetId() );
3546 event.SetEventObject( m_owner );
3547 event.SetItem( item );
3548 event.SetModel( m_wx_model );
3549 gint x, y;
3550 gtk_widget_get_pointer(m_owner->GtkGetTreeView(), &x, &y);
3551 event.SetPosition(x, y);
3552 if (!m_owner->HandleWindowEvent( event ))
3553 return FALSE;
3554
3555 if (!event.IsAllowed())
3556 return FALSE;
3557
3558 wxDataObject *obj = event.GetDataObject();
3559 if (!obj)
3560 return FALSE;
3561
3562 m_dragDataObject = obj;
3563
3564 return TRUE;
3565 }
3566
3567 gboolean
3568 wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource *WXUNUSED(drag_source),
3569 GtkTreePath *WXUNUSED(path))
3570 {
3571 return FALSE;
3572 }
3573
3574 gboolean wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource *WXUNUSED(drag_source),
3575 GtkTreePath *path, GtkSelectionData *selection_data )
3576 {
3577 wxDataViewItem item(GetOwner()->GTKPathToItem(path));
3578 if ( !item )
3579 return FALSE;
3580
3581 GdkAtom target = gtk_selection_data_get_target(selection_data);
3582 if (!m_dragDataObject->IsSupported(target))
3583 return FALSE;
3584
3585 size_t size = m_dragDataObject->GetDataSize(target);
3586 if (size == 0)
3587 return FALSE;
3588
3589 void *buf = malloc( size );
3590
3591 gboolean res = FALSE;
3592 if (m_dragDataObject->GetDataHere(target, buf))
3593 {
3594 res = TRUE;
3595
3596 gtk_selection_data_set(selection_data, target,
3597 8, (const guchar*) buf, size );
3598 }
3599
3600 free( buf );
3601
3602 return res;
3603 }
3604
3605 gboolean
3606 wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest *WXUNUSED(drag_dest),
3607 GtkTreePath *path,
3608 GtkSelectionData *selection_data)
3609 {
3610 wxDataViewItem item(GetOwner()->GTKPathToItem(path));
3611 if ( !item )
3612 return FALSE;
3613
3614 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP, m_owner->GetId() );
3615 event.SetEventObject( m_owner );
3616 event.SetItem( item );
3617 event.SetModel( m_wx_model );
3618 event.SetDataFormat(gtk_selection_data_get_target(selection_data));
3619 event.SetDataSize(gtk_selection_data_get_length(selection_data));
3620 event.SetDataBuffer(const_cast<guchar*>(gtk_selection_data_get_data(selection_data)));
3621 if (!m_owner->HandleWindowEvent( event ))
3622 return FALSE;
3623
3624 if (!event.IsAllowed())
3625 return FALSE;
3626
3627 return TRUE;
3628 }
3629
3630 gboolean
3631 wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest *WXUNUSED(drag_dest),
3632 GtkTreePath *path,
3633 GtkSelectionData *selection_data)
3634 {
3635 wxDataViewItem item(GetOwner()->GTKPathToItem(path));
3636 if ( !item )
3637 return FALSE;
3638
3639 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE, m_owner->GetId() );
3640 event.SetEventObject( m_owner );
3641 event.SetItem( item );
3642 event.SetModel( m_wx_model );
3643 event.SetDataFormat(gtk_selection_data_get_target(selection_data));
3644 if (!m_owner->HandleWindowEvent( event ))
3645 return FALSE;
3646
3647 if (!event.IsAllowed())
3648 return FALSE;
3649
3650 return TRUE;
3651 }
3652
3653 // notifications from wxDataViewModel
3654
3655 bool wxDataViewCtrlInternal::Cleared()
3656 {
3657 if (m_root)
3658 {
3659 delete m_root;
3660 m_root = NULL;
3661 }
3662
3663 InitTree();
3664
3665 ScheduleRefresh();
3666
3667 return true;
3668 }
3669
3670 void wxDataViewCtrlInternal::Resort()
3671 {
3672 if (!m_wx_model->IsVirtualListModel())
3673 m_root->Resort();
3674
3675 ScheduleRefresh();
3676 }
3677
3678 bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item )
3679 {
3680 if (!m_wx_model->IsVirtualListModel())
3681 {
3682 wxGtkTreeModelNode *parent_node = FindNode( parent );
3683 wxCHECK_MSG(parent_node, false,
3684 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3685
3686 wxDataViewItemArray siblings;
3687 m_wx_model->GetChildren(parent, siblings);
3688 int itemPos = siblings.Index(item, /*fromEnd=*/true);
3689 wxCHECK_MSG( itemPos != wxNOT_FOUND, false, "adding non-existent item?" );
3690
3691 if (m_wx_model->IsContainer( item ))
3692 parent_node->InsertNode( new wxGtkTreeModelNode( parent_node, item, this ), itemPos );
3693 else
3694 parent_node->InsertLeaf( item.GetID(), itemPos );
3695 }
3696
3697 ScheduleRefresh();
3698
3699 return true;
3700 }
3701
3702 bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item )
3703 {
3704 if (!m_wx_model->IsVirtualListModel())
3705 {
3706 wxGtkTreeModelNode *parent_node = FindNode( parent );
3707 wxASSERT_MSG(parent_node,
3708 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3709
3710 parent_node->DeleteChild( item.GetID() );
3711 }
3712
3713 ScheduleRefresh();
3714
3715 return true;
3716 }
3717
3718 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem &item )
3719 {
3720 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, m_owner->GetId() );
3721 event.SetEventObject( m_owner );
3722 event.SetModel( m_owner->GetModel() );
3723 event.SetItem( item );
3724 m_owner->HandleWindowEvent( event );
3725
3726 return true;
3727 }
3728
3729 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem &item, unsigned int view_column )
3730 {
3731 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, m_owner->GetId() );
3732 event.SetEventObject( m_owner );
3733 event.SetModel( m_owner->GetModel() );
3734 event.SetColumn( view_column );
3735 event.SetDataViewColumn( GetOwner()->GetColumn(view_column) );
3736 event.SetItem( item );
3737 m_owner->HandleWindowEvent( event );
3738
3739 return true;
3740 }
3741
3742 // GTK+ model iface
3743
3744 GtkTreeModelFlags wxDataViewCtrlInternal::get_flags()
3745 {
3746 int flags = 0;
3747
3748 if ( m_wx_model->IsListModel() )
3749 flags |= GTK_TREE_MODEL_LIST_ONLY;
3750
3751 if ( !m_wx_model->IsVirtualListModel() )
3752 flags |= GTK_TREE_MODEL_ITERS_PERSIST;
3753
3754 return GtkTreeModelFlags(flags);
3755 }
3756
3757 gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path )
3758 {
3759
3760 if (m_wx_model->IsVirtualListModel())
3761 {
3762 wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
3763
3764 unsigned int i = (unsigned int)gtk_tree_path_get_indices (path)[0];
3765
3766 if (i >= wx_model->GetCount())
3767 return FALSE;
3768
3769 iter->stamp = m_gtk_model->stamp;
3770 // user_data is just the index +1
3771 iter->user_data = (gpointer) (i+1);
3772
3773 return TRUE;
3774 }
3775 else
3776 {
3777 int depth = gtk_tree_path_get_depth( path );
3778
3779 wxGtkTreeModelNode *node = m_root;
3780
3781 int i;
3782 for (i = 0; i < depth; i++)
3783 {
3784 BuildBranch( node );
3785
3786 gint pos = gtk_tree_path_get_indices (path)[i];
3787 if (pos < 0) return FALSE;
3788 if ((size_t)pos >= node->GetChildCount()) return FALSE;
3789
3790 void* id = node->GetChildren().Item( (size_t) pos );
3791
3792 if (i == depth-1)
3793 {
3794 iter->stamp = m_gtk_model->stamp;
3795 iter->user_data = id;
3796 return TRUE;
3797 }
3798
3799 size_t count = node->GetNodes().GetCount();
3800 size_t pos2;
3801 for (pos2 = 0; pos2 < count; pos2++)
3802 {
3803 wxGtkTreeModelNode *child_node = node->GetNodes().Item( pos2 );
3804 if (child_node->GetItem().GetID() == id)
3805 {
3806 node = child_node;
3807 break;
3808 }
3809 }
3810 }
3811 }
3812
3813 return FALSE;
3814 }
3815
3816 GtkTreePath *wxDataViewCtrlInternal::get_path( GtkTreeIter *iter )
3817 {
3818 // When this is called from ItemDeleted(), the item is already
3819 // deleted in the model.
3820
3821 GtkTreePath *retval = gtk_tree_path_new ();
3822
3823 if (m_wx_model->IsVirtualListModel())
3824 {
3825 // iter is root, add nothing
3826 if (!iter->user_data)
3827 return retval;
3828
3829 // user_data is just the index +1
3830 int i = ( (wxUIntPtr) iter->user_data ) -1;
3831 gtk_tree_path_append_index (retval, i);
3832 }
3833 else
3834 {
3835 void *id = iter->user_data;
3836
3837 wxGtkTreeModelNode *node = FindParentNode( iter );
3838 while (node)
3839 {
3840 int pos = node->GetChildren().Index( id );
3841
3842 gtk_tree_path_prepend_index( retval, pos );
3843
3844 id = node->GetItem().GetID();
3845 node = node->GetParent();
3846 }
3847 }
3848
3849 return retval;
3850 }
3851
3852 gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter )
3853 {
3854 if (m_wx_model->IsVirtualListModel())
3855 {
3856 wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
3857
3858 // user_data is just the index +1
3859 int n = ( (wxUIntPtr) iter->user_data ) -1;
3860
3861 if (n == -1)
3862 {
3863 iter->user_data = NULL;
3864 return FALSE;
3865 }
3866
3867 if (n >= (int) wx_model->GetCount()-1)
3868 {
3869 iter->user_data = NULL;
3870 return FALSE;
3871 }
3872
3873 // user_data is just the index +1 (+2 because we need the next)
3874 iter->user_data = (gpointer) (n+2);
3875 }
3876 else
3877 {
3878 wxGtkTreeModelNode *parent = FindParentNode( iter );
3879 if( parent == NULL )
3880 {
3881 iter->user_data = NULL;
3882 return FALSE;
3883 }
3884
3885 int pos = parent->GetChildren().Index( iter->user_data );
3886
3887 if (pos == (int) parent->GetChildCount()-1)
3888 {
3889 iter->user_data = NULL;
3890 return FALSE;
3891 }
3892
3893 iter->user_data = parent->GetChildren().Item( pos+1 );
3894 }
3895
3896 return TRUE;
3897 }
3898
3899 gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter *parent )
3900 {
3901 if (m_wx_model->IsVirtualListModel())
3902 {
3903 // this is a list, nodes have no children
3904 if (parent)
3905 return FALSE;
3906
3907 iter->stamp = m_gtk_model->stamp;
3908 iter->user_data = (gpointer) 1;
3909
3910 return TRUE;
3911 }
3912 else
3913 {
3914 if (iter == NULL)
3915 {
3916 if (m_root->GetChildCount() == 0) return FALSE;
3917 iter->stamp = m_gtk_model->stamp;
3918 iter->user_data = (gpointer) m_root->GetChildren().Item( 0 );
3919 return TRUE;
3920 }
3921
3922
3923 wxDataViewItem item;
3924 if (parent)
3925 item = wxDataViewItem( (void*) parent->user_data );
3926
3927 if (!m_wx_model->IsContainer( item ))
3928 return FALSE;
3929
3930 wxGtkTreeModelNode *parent_node = FindNode( parent );
3931 wxASSERT_MSG(parent_node,
3932 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
3933
3934 BuildBranch( parent_node );
3935
3936 if (parent_node->GetChildCount() == 0)
3937 return FALSE;
3938
3939 iter->stamp = m_gtk_model->stamp;
3940 iter->user_data = (gpointer) parent_node->GetChildren().Item( 0 );
3941 }
3942
3943 return TRUE;
3944 }
3945
3946 gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter )
3947 {
3948 if (m_wx_model->IsVirtualListModel())
3949 {
3950 wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
3951
3952 if (iter == NULL)
3953 return (wx_model->GetCount() > 0);
3954
3955 // this is a list, nodes have no children
3956 return FALSE;
3957 }
3958 else
3959 {
3960 if (iter == NULL)
3961 return (m_root->GetChildCount() > 0);
3962
3963 wxDataViewItem item( (void*) iter->user_data );
3964
3965 bool is_container = m_wx_model->IsContainer( item );
3966
3967 if (!is_container)
3968 return FALSE;
3969
3970 wxGtkTreeModelNode *node = FindNode( iter );
3971 wxASSERT_MSG(node,
3972 "Did you forget a call to ItemAdded()? The iterator is unknown to the wxGtkTreeModel");
3973
3974 BuildBranch( node );
3975
3976 return (node->GetChildCount() > 0);
3977 }
3978 }
3979
3980 gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter )
3981 {
3982 if (m_wx_model->IsVirtualListModel())
3983 {
3984 wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
3985
3986 if (iter == NULL)
3987 return (gint) wx_model->GetCount();
3988
3989 return 0;
3990 }
3991 else
3992 {
3993 if (iter == NULL)
3994 return m_root->GetChildCount();
3995
3996 wxDataViewItem item( (void*) iter->user_data );
3997
3998 if (!m_wx_model->IsContainer( item ))
3999 return 0;
4000
4001 wxGtkTreeModelNode *parent_node = FindNode( iter );
4002 wxASSERT_MSG(parent_node,
4003 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
4004
4005 BuildBranch( parent_node );
4006
4007 return parent_node->GetChildCount();
4008 }
4009 }
4010
4011 gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter *parent, gint n )
4012 {
4013 if (m_wx_model->IsVirtualListModel())
4014 {
4015 wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
4016
4017 if (parent)
4018 return FALSE;
4019
4020 if (n < 0)
4021 return FALSE;
4022
4023 if (n >= (gint) wx_model->GetCount())
4024 return FALSE;
4025
4026 iter->stamp = m_gtk_model->stamp;
4027 // user_data is just the index +1
4028 iter->user_data = (gpointer) (n+1);
4029
4030 return TRUE;
4031 }
4032 else
4033 {
4034 void* id = NULL;
4035 if (parent) id = (void*) parent->user_data;
4036 wxDataViewItem item( id );
4037
4038 if (!m_wx_model->IsContainer( item ))
4039 return FALSE;
4040
4041 wxGtkTreeModelNode *parent_node = FindNode( parent );
4042 wxASSERT_MSG(parent_node,
4043 "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
4044
4045 BuildBranch( parent_node );
4046
4047 iter->stamp = m_gtk_model->stamp;
4048 iter->user_data = parent_node->GetChildren().Item( n );
4049
4050 return TRUE;
4051 }
4052 }
4053
4054 gboolean wxDataViewCtrlInternal::iter_parent( GtkTreeIter *iter, GtkTreeIter *child )
4055 {
4056 if (m_wx_model->IsVirtualListModel())
4057 {
4058 return FALSE;
4059 }
4060 else
4061 {
4062 wxGtkTreeModelNode *node = FindParentNode( child );
4063 if (!node)
4064 return FALSE;
4065
4066 iter->stamp = m_gtk_model->stamp;
4067 iter->user_data = (gpointer) node->GetItem().GetID();
4068
4069 return TRUE;
4070 }
4071 }
4072
4073 // item can be deleted already in the model
4074 int wxDataViewCtrlInternal::GetIndexOf( const wxDataViewItem &parent, const wxDataViewItem &item )
4075 {
4076 if (m_wx_model->IsVirtualListModel())
4077 {
4078 return wxPtrToUInt(item.GetID()) - 1;
4079 }
4080 else
4081 {
4082 wxGtkTreeModelNode *parent_node = FindNode( parent );
4083 wxGtkTreeModelChildren &children = parent_node->GetChildren();
4084 size_t j;
4085 for (j = 0; j < children.GetCount(); j++)
4086 {
4087 if (children[j] == item.GetID())
4088 return j;
4089 }
4090 }
4091 return -1;
4092 }
4093
4094
4095 static wxGtkTreeModelNode*
4096 wxDataViewCtrlInternal_FindNode( wxDataViewModel * model, wxGtkTreeModelNode *treeNode, const wxDataViewItem &item )
4097 {
4098 if( model == NULL )
4099 return NULL;
4100
4101 ItemList list;
4102 list.DeleteContents( true );
4103 wxDataViewItem it( item );
4104
4105 while( it.IsOk() )
4106 {
4107 wxDataViewItem * pItem = new wxDataViewItem( it );
4108 list.Insert( pItem );
4109 it = model->GetParent( it );
4110 }
4111
4112 wxGtkTreeModelNode * node = treeNode;
4113 for( ItemList::compatibility_iterator n = list.GetFirst(); n; n = n->GetNext() )
4114 {
4115 if( node && node->GetNodes().GetCount() != 0 )
4116 {
4117 int len = node->GetNodes().GetCount();
4118 wxGtkTreeModelNodes &nodes = node->GetNodes();
4119 int j = 0;
4120 for( ; j < len; j ++)
4121 {
4122 if( nodes[j]->GetItem() == *(n->GetData()))
4123 {
4124 node = nodes[j];
4125 break;
4126 }
4127 }
4128
4129 if( j == len )
4130 {
4131 return NULL;
4132 }
4133 }
4134 else
4135 return NULL;
4136 }
4137 return node;
4138
4139 }
4140
4141 wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( GtkTreeIter *iter )
4142 {
4143 if (!iter)
4144 return m_root;
4145
4146 wxDataViewItem item( (void*) iter->user_data );
4147 if (!item.IsOk())
4148 return m_root;
4149
4150 wxGtkTreeModelNode *result = wxDataViewCtrlInternal_FindNode( m_wx_model, m_root, item );
4151
4152 /*
4153 if (!result)
4154 {
4155 wxLogDebug( "Not found %p", iter->user_data );
4156 char *crash = NULL;
4157 *crash = 0;
4158 }
4159 // TODO: remove this code
4160 */
4161
4162 return result;
4163 }
4164
4165 wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( const wxDataViewItem &item )
4166 {
4167 if (!item.IsOk())
4168 return m_root;
4169
4170 wxGtkTreeModelNode *result = wxDataViewCtrlInternal_FindNode( m_wx_model, m_root, item );
4171
4172 /*
4173 if (!result)
4174 {
4175 wxLogDebug( "Not found %p", item.GetID() );
4176 char *crash = NULL;
4177 *crash = 0;
4178 }
4179 // TODO: remove this code
4180 */
4181
4182 return result;
4183 }
4184
4185 static wxGtkTreeModelNode*
4186 wxDataViewCtrlInternal_FindParentNode( wxDataViewModel * model, wxGtkTreeModelNode *treeNode, const wxDataViewItem &item )
4187 {
4188 if( model == NULL )
4189 return NULL;
4190
4191 ItemList list;
4192 list.DeleteContents( true );
4193 if( !item.IsOk() )
4194 return NULL;
4195
4196 wxDataViewItem it( model->GetParent( item ) );
4197 while( it.IsOk() )
4198 {
4199 wxDataViewItem * pItem = new wxDataViewItem( it );
4200 list.Insert( pItem );
4201 it = model->GetParent( it );
4202 }
4203
4204 wxGtkTreeModelNode * node = treeNode;
4205 for( ItemList::compatibility_iterator n = list.GetFirst(); n; n = n->GetNext() )
4206 {
4207 if( node && node->GetNodes().GetCount() != 0 )
4208 {
4209 int len = node->GetNodes().GetCount();
4210 wxGtkTreeModelNodes nodes = node->GetNodes();
4211 int j = 0;
4212 for( ; j < len; j ++)
4213 {
4214 if( nodes[j]->GetItem() == *(n->GetData()))
4215 {
4216 node = nodes[j];
4217 break;
4218 }
4219 }
4220
4221 if( j == len )
4222 {
4223 return NULL;
4224 }
4225 }
4226 else
4227 return NULL;
4228 }
4229 //Examine whether the node is item's parent node
4230 int len = node->GetChildCount();
4231 for( int i = 0; i < len ; i ++ )
4232 {
4233 if( node->GetChildren().Item( i ) == item.GetID() )
4234 return node;
4235 }
4236 return NULL;
4237 }
4238
4239 wxGtkTreeModelNode *wxDataViewCtrlInternal::FindParentNode( GtkTreeIter *iter )
4240 {
4241 if (!iter)
4242 return NULL;
4243
4244 wxDataViewItem item( (void*) iter->user_data );
4245 if (!item.IsOk())
4246 return NULL;
4247
4248 return wxDataViewCtrlInternal_FindParentNode( m_wx_model, m_root, item );
4249 }
4250
4251 wxGtkTreeModelNode *wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem &item )
4252 {
4253 if (!item.IsOk())
4254 return NULL;
4255
4256 return wxDataViewCtrlInternal_FindParentNode( m_wx_model, m_root, item );
4257 }
4258
4259 //-----------------------------------------------------------------------------
4260 // wxDataViewCtrl signal callbacks
4261 //-----------------------------------------------------------------------------
4262
4263 static void
4264 wxdataview_selection_changed_callback( GtkTreeSelection* WXUNUSED(selection), wxDataViewCtrl *dv )
4265 {
4266 if (!gtk_widget_get_realized(dv->m_widget))
4267 return;
4268
4269 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, dv->GetId() );
4270 event.SetItem( dv->GetSelection() );
4271 event.SetModel( dv->GetModel() );
4272 dv->HandleWindowEvent( event );
4273 }
4274
4275 static void
4276 wxdataview_row_activated_callback( GtkTreeView* WXUNUSED(treeview), GtkTreePath *path,
4277 GtkTreeViewColumn *WXUNUSED(column), wxDataViewCtrl *dv )
4278 {
4279 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, dv->GetId() );
4280
4281 wxDataViewItem item(dv->GTKPathToItem(path));
4282 event.SetItem( item );
4283 event.SetModel( dv->GetModel() );
4284 dv->HandleWindowEvent( event );
4285 }
4286
4287 static gboolean
4288 wxdataview_test_expand_row_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter,
4289 GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv )
4290 {
4291 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, dv->GetId() );
4292
4293 wxDataViewItem item( (void*) iter->user_data );;
4294 event.SetItem( item );
4295 event.SetModel( dv->GetModel() );
4296 dv->HandleWindowEvent( event );
4297
4298 return !event.IsAllowed();
4299 }
4300
4301 static void
4302 wxdataview_row_expanded_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter,
4303 GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv )
4304 {
4305 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, dv->GetId() );
4306
4307 wxDataViewItem item( (void*) iter->user_data );;
4308 event.SetItem( item );
4309 event.SetModel( dv->GetModel() );
4310 dv->HandleWindowEvent( event );
4311 }
4312
4313 static gboolean
4314 wxdataview_test_collapse_row_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter,
4315 GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv )
4316 {
4317 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, dv->GetId() );
4318
4319 wxDataViewItem item( (void*) iter->user_data );;
4320 event.SetItem( item );
4321 event.SetModel( dv->GetModel() );
4322 dv->HandleWindowEvent( event );
4323
4324 return !event.IsAllowed();
4325 }
4326
4327 static void
4328 wxdataview_row_collapsed_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter,
4329 GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv )
4330 {
4331 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, dv->GetId() );
4332
4333 wxDataViewItem item( (void*) iter->user_data );;
4334 event.SetItem( item );
4335 event.SetModel( dv->GetModel() );
4336 dv->HandleWindowEvent( event );
4337 }
4338
4339 //-----------------------------------------------------------------------------
4340 // wxDataViewCtrl
4341 //-----------------------------------------------------------------------------
4342
4343 void wxDataViewCtrl::AddChildGTK(wxWindowGTK* child)
4344 {
4345 GtkWidget* treeview = GtkGetTreeView();
4346
4347 // Insert widget in GtkTreeView
4348 if (gtk_widget_get_realized(treeview))
4349 gtk_widget_set_parent_window( child->m_widget,
4350 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview) ) );
4351 gtk_widget_set_parent( child->m_widget, treeview );
4352 }
4353
4354 static
4355 void gtk_dataviewctrl_size_callback( GtkWidget *WXUNUSED(widget),
4356 GtkAllocation *WXUNUSED(gtk_alloc),
4357 wxDataViewCtrl *win )
4358 {
4359 wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst();
4360 while (node)
4361 {
4362 wxWindow *child = node->GetData();
4363
4364 GtkRequisition req;
4365 gtk_widget_size_request( child->m_widget, &req );
4366
4367 GtkAllocation alloc;
4368 alloc.x = child->m_x;
4369 alloc.y = child->m_y;
4370 alloc.width = child->m_width;
4371 alloc.height = child->m_height;
4372 gtk_widget_size_allocate( child->m_widget, &alloc );
4373
4374 node = node->GetNext();
4375 }
4376 }
4377
4378
4379 //-----------------------------------------------------------------------------
4380 // "motion_notify_event"
4381 //-----------------------------------------------------------------------------
4382
4383 static gboolean
4384 gtk_dataview_motion_notify_callback( GtkWidget *WXUNUSED(widget),
4385 GdkEventMotion *gdk_event,
4386 wxDataViewCtrl *dv )
4387 {
4388 if (gdk_event->is_hint)
4389 {
4390 int x = 0;
4391 int y = 0;
4392 GdkModifierType state;
4393 gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
4394 gdk_event->x = x;
4395 gdk_event->y = y;
4396 }
4397
4398 wxGtkTreePath path;
4399 GtkTreeViewColumn *column = NULL;
4400 gint cell_x = 0;
4401 gint cell_y = 0;
4402 if (gtk_tree_view_get_path_at_pos(
4403 GTK_TREE_VIEW(dv->GtkGetTreeView()),
4404 (int) gdk_event->x, (int) gdk_event->y,
4405 path.ByRef(),
4406 &column,
4407 &cell_x,
4408 &cell_y))
4409 {
4410 if (path)
4411 {
4412 GtkTreeIter iter;
4413 dv->GtkGetInternal()->get_iter( &iter, path );
4414 }
4415 }
4416
4417
4418 return FALSE;
4419 }
4420
4421 //-----------------------------------------------------------------------------
4422 // "button_press_event"
4423 //-----------------------------------------------------------------------------
4424
4425 static gboolean
4426 gtk_dataview_button_press_callback( GtkWidget *WXUNUSED(widget),
4427 GdkEventButton *gdk_event,
4428 wxDataViewCtrl *dv )
4429 {
4430 if ((gdk_event->button == 3) && (gdk_event->type == GDK_BUTTON_PRESS))
4431 {
4432 wxGtkTreePath path;
4433 GtkTreeViewColumn *column = NULL;
4434 gint cell_x = 0;
4435 gint cell_y = 0;
4436 gtk_tree_view_get_path_at_pos
4437 (
4438 GTK_TREE_VIEW(dv->GtkGetTreeView()),
4439 (int) gdk_event->x, (int) gdk_event->y,
4440 path.ByRef(),
4441 &column,
4442 &cell_x,
4443 &cell_y
4444 );
4445
4446 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, dv->GetId() );
4447 if (path)
4448 event.SetItem(dv->GTKPathToItem(path));
4449 event.SetModel( dv->GetModel() );
4450 return dv->HandleWindowEvent( event );
4451 }
4452
4453 return FALSE;
4454 }
4455
4456 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase)
4457
4458 wxDataViewCtrl::~wxDataViewCtrl()
4459 {
4460 // Stop editing before destroying the control to remove any event handlers
4461 // which are added when editing started: if we didn't do this, the base
4462 // class dtor would assert as it checks for any leftover handlers.
4463 if ( m_treeview )
4464 {
4465 GtkTreeViewColumn *col;
4466 gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview), NULL, &col);
4467
4468 wxDataViewColumn * const wxcol = FromGTKColumn(col);
4469 if ( wxcol )
4470 {
4471 // This won't do anything if we're not editing it
4472 wxcol->GetRenderer()->CancelEditing();
4473 }
4474 }
4475
4476 m_cols.Clear();
4477
4478 delete m_internal;
4479 }
4480
4481 void wxDataViewCtrl::Init()
4482 {
4483 m_internal = NULL;
4484
4485 m_cols.DeleteContents( true );
4486
4487 m_uniformRowHeight = -1;
4488 }
4489
4490 bool wxDataViewCtrl::Create(wxWindow *parent,
4491 wxWindowID id,
4492 const wxPoint& pos,
4493 const wxSize& size,
4494 long style,
4495 const wxValidator& validator,
4496 const wxString& name)
4497 {
4498 if (!PreCreation( parent, pos, size ) ||
4499 !CreateBase( parent, id, pos, size, style, validator, name ))
4500 {
4501 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
4502 return false;
4503 }
4504
4505 m_widget = gtk_scrolled_window_new (NULL, NULL);
4506 g_object_ref(m_widget);
4507
4508 GTKScrolledWindowSetBorder(m_widget, style);
4509
4510 m_treeview = gtk_tree_view_new();
4511 gtk_container_add (GTK_CONTAINER (m_widget), m_treeview);
4512
4513 m_focusWidget = GTK_WIDGET(m_treeview);
4514
4515 g_signal_connect (m_treeview, "size_allocate",
4516 G_CALLBACK (gtk_dataviewctrl_size_callback), this);
4517
4518 #ifdef __WXGTK26__
4519 if (!gtk_check_version(2,6,0))
4520 {
4521 bool fixed = (style & wxDV_VARIABLE_LINE_HEIGHT) == 0;
4522 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), fixed );
4523 }
4524 #endif
4525
4526 if (style & wxDV_MULTIPLE)
4527 {
4528 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
4529 gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE );
4530 }
4531
4532 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview), (style & wxDV_NO_HEADER) == 0 );
4533
4534 #ifdef __WXGTK210__
4535 if (!gtk_check_version(2,10,0))
4536 {
4537 GtkTreeViewGridLines grid = GTK_TREE_VIEW_GRID_LINES_NONE;
4538
4539 if ((style & wxDV_HORIZ_RULES) != 0 &&
4540 (style & wxDV_VERT_RULES) != 0)
4541 grid = GTK_TREE_VIEW_GRID_LINES_BOTH;
4542 else if (style & wxDV_VERT_RULES)
4543 grid = GTK_TREE_VIEW_GRID_LINES_VERTICAL;
4544 else if (style & wxDV_HORIZ_RULES)
4545 grid = GTK_TREE_VIEW_GRID_LINES_HORIZONTAL;
4546
4547 if (grid != GTK_TREE_VIEW_GRID_LINES_NONE)
4548 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview), grid );
4549 }
4550 #endif
4551
4552 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview), (style & wxDV_ROW_LINES) != 0 );
4553
4554 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget),
4555 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
4556 gtk_widget_show (m_treeview);
4557
4558 m_parent->DoAddChild( this );
4559
4560 PostCreation(size);
4561
4562 GtkEnableSelectionEvents();
4563
4564 g_signal_connect_after (m_treeview, "row-activated",
4565 G_CALLBACK (wxdataview_row_activated_callback), this);
4566
4567 g_signal_connect (m_treeview, "test-collapse-row",
4568 G_CALLBACK (wxdataview_test_collapse_row_callback), this);
4569
4570 g_signal_connect_after (m_treeview, "row-collapsed",
4571 G_CALLBACK (wxdataview_row_collapsed_callback), this);
4572
4573 g_signal_connect (m_treeview, "test-expand-row",
4574 G_CALLBACK (wxdataview_test_expand_row_callback), this);
4575
4576 g_signal_connect_after (m_treeview, "row-expanded",
4577 G_CALLBACK (wxdataview_row_expanded_callback), this);
4578
4579 g_signal_connect (m_treeview, "motion_notify_event",
4580 G_CALLBACK (gtk_dataview_motion_notify_callback), this);
4581
4582 g_signal_connect (m_treeview, "button_press_event",
4583 G_CALLBACK (gtk_dataview_button_press_callback), this);
4584
4585 return true;
4586 }
4587
4588 wxDataViewItem wxDataViewCtrl::GTKPathToItem(GtkTreePath *path) const
4589 {
4590 GtkTreeIter iter;
4591 return wxDataViewItem(path && m_internal->get_iter(&iter, path)
4592 ? iter.user_data
4593 : NULL);
4594 }
4595
4596 void wxDataViewCtrl::OnInternalIdle()
4597 {
4598 wxWindow::OnInternalIdle();
4599
4600 m_internal->OnInternalIdle();
4601
4602 unsigned int cols = GetColumnCount();
4603 unsigned int i;
4604 for (i = 0; i < cols; i++)
4605 {
4606 wxDataViewColumn *col = GetColumn( i );
4607 col->OnInternalIdle();
4608 }
4609
4610 if (m_ensureVisibleDefered.IsOk())
4611 {
4612 ExpandAncestors(m_ensureVisibleDefered);
4613 GtkTreeIter iter;
4614 iter.user_data = (gpointer) m_ensureVisibleDefered.GetID();
4615 wxGtkTreePath path(m_internal->get_path( &iter ));
4616 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview), path, NULL, false, 0.0, 0.0 );
4617 m_ensureVisibleDefered = wxDataViewItem(0);
4618 }
4619 }
4620
4621 bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model )
4622 {
4623 wxDELETE(m_internal);
4624
4625 if (!wxDataViewCtrlBase::AssociateModel( model ))
4626 return false;
4627
4628 #ifdef __WXGTK26__
4629 if (!gtk_check_version(2,6,0))
4630 {
4631 bool fixed = (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) == 0) || (model->IsVirtualListModel()));
4632 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), fixed );
4633 }
4634 #endif
4635
4636 m_internal = new wxDataViewCtrlInternal( this, model );
4637
4638 return true;
4639 }
4640
4641 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat &format )
4642 {
4643 return m_internal->EnableDragSource( format );
4644 }
4645
4646 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat &format )
4647 {
4648 return m_internal->EnableDropTarget( format );
4649 }
4650
4651 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col )
4652 {
4653 if (!wxDataViewCtrlBase::AppendColumn(col))
4654 return false;
4655
4656 m_cols.Append( col );
4657
4658 #ifdef __WXGTK26__
4659 if (!gtk_check_version(2,6,0))
4660 {
4661 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) ) !=
4662 GTK_TREE_VIEW_COLUMN_FIXED)
4663 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), FALSE );
4664 }
4665 #endif
4666
4667 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview),
4668 GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) );
4669
4670 return true;
4671 }
4672
4673 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn *col )
4674 {
4675 if (!wxDataViewCtrlBase::PrependColumn(col))
4676 return false;
4677
4678 m_cols.Insert( col );
4679
4680 #ifdef __WXGTK26__
4681 if (!gtk_check_version(2,6,0))
4682 {
4683 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) ) !=
4684 GTK_TREE_VIEW_COLUMN_FIXED)
4685 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), FALSE );
4686 }
4687 #endif
4688
4689 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview),
4690 GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()), 0 );
4691
4692 return true;
4693 }
4694
4695 bool wxDataViewCtrl::InsertColumn( unsigned int pos, wxDataViewColumn *col )
4696 {
4697 if (!wxDataViewCtrlBase::InsertColumn(pos,col))
4698 return false;
4699
4700 m_cols.Insert( pos, col );
4701
4702 #ifdef __WXGTK26__
4703 if (!gtk_check_version(2,6,0))
4704 {
4705 if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) ) !=
4706 GTK_TREE_VIEW_COLUMN_FIXED)
4707 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), FALSE );
4708 }
4709 #endif
4710
4711 gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview),
4712 GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()), pos );
4713
4714 return true;
4715 }
4716
4717 unsigned int wxDataViewCtrl::GetColumnCount() const
4718 {
4719 return m_cols.GetCount();
4720 }
4721
4722 wxDataViewColumn* wxDataViewCtrl::FromGTKColumn(GtkTreeViewColumn *gtk_col) const
4723 {
4724 if ( !gtk_col )
4725 return NULL;
4726
4727 wxDataViewColumnList::const_iterator iter;
4728 for (iter = m_cols.begin(); iter != m_cols.end(); ++iter)
4729 {
4730 wxDataViewColumn *col = *iter;
4731 if (GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) == gtk_col)
4732 {
4733 return col;
4734 }
4735 }
4736
4737 wxFAIL_MSG( "No matching column?" );
4738
4739 return NULL;
4740 }
4741
4742 wxDataViewColumn* wxDataViewCtrl::GetColumn( unsigned int pos ) const
4743 {
4744 GtkTreeViewColumn *gtk_col = gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview), pos );
4745
4746 return FromGTKColumn(gtk_col);
4747 }
4748
4749 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn *column )
4750 {
4751 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview),
4752 GTK_TREE_VIEW_COLUMN(column->GetGtkHandle()) );
4753
4754 m_cols.DeleteObject( column );
4755
4756 return true;
4757 }
4758
4759 bool wxDataViewCtrl::ClearColumns()
4760 {
4761 wxDataViewColumnList::iterator iter;
4762 for (iter = m_cols.begin(); iter != m_cols.end(); ++iter)
4763 {
4764 wxDataViewColumn *col = *iter;
4765 gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview),
4766 GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) );
4767 }
4768
4769 m_cols.Clear();
4770
4771 return true;
4772 }
4773
4774 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn *column ) const
4775 {
4776 GtkTreeViewColumn *gtk_column = GTK_TREE_VIEW_COLUMN(column->GetGtkHandle());
4777
4778 wxGtkList list(gtk_tree_view_get_columns(GTK_TREE_VIEW(m_treeview)));
4779
4780 return g_list_index( list, (gconstpointer) gtk_column );
4781 }
4782
4783 wxDataViewColumn *wxDataViewCtrl::GetSortingColumn() const
4784 {
4785 return m_internal->GetDataViewSortColumn();
4786 }
4787
4788 void wxDataViewCtrl::Expand( const wxDataViewItem & item )
4789 {
4790 GtkTreeIter iter;
4791 iter.user_data = item.GetID();
4792 wxGtkTreePath path(m_internal->get_path( &iter ));
4793 gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview), path, false );
4794 }
4795
4796 void wxDataViewCtrl::Collapse( const wxDataViewItem & item )
4797 {
4798 GtkTreeIter iter;
4799 iter.user_data = item.GetID();
4800 wxGtkTreePath path(m_internal->get_path( &iter ));
4801 gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview), path );
4802 }
4803
4804 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem & item ) const
4805 {
4806 GtkTreeIter iter;
4807 iter.user_data = item.GetID();
4808 wxGtkTreePath path(m_internal->get_path( &iter ));
4809 return gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview), path );
4810 }
4811
4812 wxDataViewItem wxDataViewCtrl::DoGetCurrentItem() const
4813 {
4814 // The tree doesn't have any current item if it hadn't been created yet but
4815 // it's arguably not an error to call this function in this case so just
4816 // return an invalid item without asserting.
4817 if ( !m_treeview )
4818 return wxDataViewItem();
4819
4820 wxGtkTreePath path;
4821 gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview), path.ByRef(), NULL);
4822
4823 return GTKPathToItem(path);
4824 }
4825
4826 void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem& item)
4827 {
4828 wxCHECK_RET( m_treeview,
4829 "Current item can't be set before creating the control." );
4830
4831 // We need to make sure the model knows about this item or the path would
4832 // be invalid and gtk_tree_view_set_cursor() would silently do nothing.
4833 ExpandAncestors(item);
4834
4835 // We also need to preserve the existing selection from changing.
4836 // Unfortunately the only way to do it seems to use our own selection
4837 // function and forbid any selection changes during set cursor call.
4838 wxGtkTreeSelectionLock
4839 lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview)));
4840
4841 // Do move the cursor now.
4842 GtkTreeIter iter;
4843 iter.user_data = item.GetID();
4844 wxGtkTreePath path(m_internal->get_path( &iter ));
4845
4846 gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview), path, NULL, FALSE);
4847 }
4848
4849 void wxDataViewCtrl::StartEditor(const wxDataViewItem& item, unsigned int column)
4850 {
4851 wxCHECK_RET( m_treeview,
4852 "Current item can't be set before creating the control." );
4853
4854 // We need to make sure the model knows about this item or the path would
4855 // be invalid and gtk_tree_view_set_cursor() would silently do nothing.
4856 ExpandAncestors(item);
4857
4858 wxDataViewColumn *dvcolumn = GetColumn(column);
4859 wxASSERT_MSG(dvcolumn, "Could not retrieve column");
4860 GtkTreeViewColumn *gcolumn = GTK_TREE_VIEW_COLUMN(dvcolumn->GetGtkHandle());
4861
4862 // We also need to preserve the existing selection from changing.
4863 // Unfortunately the only way to do it seems to use our own selection
4864 // function and forbid any selection changes during set cursor call.
4865 wxGtkTreeSelectionLock
4866 lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview)));
4867
4868 // Do move the cursor now.
4869 GtkTreeIter iter;
4870 iter.user_data = item.GetID();
4871 wxGtkTreePath path(m_internal->get_path( &iter ));
4872
4873 gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview), path, gcolumn, TRUE);
4874 }
4875
4876 int wxDataViewCtrl::GetSelectedItemsCount() const
4877 {
4878 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
4879
4880 return gtk_tree_selection_count_selected_rows(selection);
4881 }
4882
4883 int wxDataViewCtrl::GetSelections( wxDataViewItemArray & sel ) const
4884 {
4885 sel.Clear();
4886
4887 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
4888 if (HasFlag(wxDV_MULTIPLE))
4889 {
4890 GtkTreeModel *model;
4891 wxGtkTreePathList list(gtk_tree_selection_get_selected_rows(selection, &model));
4892
4893 for ( GList* current = list; current; current = g_list_next(current) )
4894 {
4895 GtkTreePath *path = (GtkTreePath*) current->data;
4896
4897 sel.Add(GTKPathToItem(path));
4898 }
4899 }
4900 else
4901 {
4902 GtkTreeIter iter;
4903 if (gtk_tree_selection_get_selected( selection, NULL, &iter ))
4904 {
4905 sel.Add( wxDataViewItem(iter.user_data) );
4906 }
4907 }
4908
4909 return sel.size();
4910 }
4911
4912 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray & sel )
4913 {
4914 GtkDisableSelectionEvents();
4915
4916 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
4917
4918 gtk_tree_selection_unselect_all( selection );
4919
4920 wxDataViewItem last_parent;
4921
4922 size_t i;
4923 for (i = 0; i < sel.GetCount(); i++)
4924 {
4925 wxDataViewItem item = sel[i];
4926 wxDataViewItem parent = GetModel()->GetParent( item );
4927 if (parent)
4928 {
4929 if (parent != last_parent)
4930 ExpandAncestors(item);
4931 }
4932 last_parent = parent;
4933
4934 GtkTreeIter iter;
4935 iter.stamp = m_internal->GetGtkModel()->stamp;
4936 iter.user_data = (gpointer) item.GetID();
4937 gtk_tree_selection_select_iter( selection, &iter );
4938 }
4939
4940 GtkEnableSelectionEvents();
4941 }
4942
4943 void wxDataViewCtrl::Select( const wxDataViewItem & item )
4944 {
4945 ExpandAncestors(item);
4946
4947 GtkDisableSelectionEvents();
4948
4949 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
4950
4951 GtkTreeIter iter;
4952 iter.stamp = m_internal->GetGtkModel()->stamp;
4953 iter.user_data = (gpointer) item.GetID();
4954 gtk_tree_selection_select_iter( selection, &iter );
4955
4956 GtkEnableSelectionEvents();
4957 }
4958
4959 void wxDataViewCtrl::Unselect( const wxDataViewItem & item )
4960 {
4961 GtkDisableSelectionEvents();
4962
4963 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
4964
4965 GtkTreeIter iter;
4966 iter.stamp = m_internal->GetGtkModel()->stamp;
4967 iter.user_data = (gpointer) item.GetID();
4968 gtk_tree_selection_unselect_iter( selection, &iter );
4969
4970 GtkEnableSelectionEvents();
4971 }
4972
4973 bool wxDataViewCtrl::IsSelected( const wxDataViewItem & item ) const
4974 {
4975 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
4976
4977 GtkTreeIter iter;
4978 iter.stamp = m_internal->GetGtkModel()->stamp;
4979 iter.user_data = (gpointer) item.GetID();
4980
4981 return gtk_tree_selection_iter_is_selected( selection, &iter );
4982 }
4983
4984 void wxDataViewCtrl::SelectAll()
4985 {
4986 GtkDisableSelectionEvents();
4987
4988 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
4989
4990 gtk_tree_selection_select_all( selection );
4991
4992 GtkEnableSelectionEvents();
4993 }
4994
4995 void wxDataViewCtrl::UnselectAll()
4996 {
4997 GtkDisableSelectionEvents();
4998
4999 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
5000
5001 gtk_tree_selection_unselect_all( selection );
5002
5003 GtkEnableSelectionEvents();
5004 }
5005
5006 void wxDataViewCtrl::EnsureVisible(const wxDataViewItem& item,
5007 const wxDataViewColumn *WXUNUSED(column))
5008 {
5009 m_ensureVisibleDefered = item;
5010 ExpandAncestors(item);
5011
5012 GtkTreeIter iter;
5013 iter.user_data = (gpointer) item.GetID();
5014 wxGtkTreePath path(m_internal->get_path( &iter ));
5015 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview), path, NULL, false, 0.0, 0.0 );
5016 }
5017
5018 void wxDataViewCtrl::HitTest(const wxPoint& point,
5019 wxDataViewItem& item,
5020 wxDataViewColumn *& column) const
5021 {
5022 // gtk_tree_view_get_dest_row_at_pos() is the right one. But it does not tell the column.
5023 // gtk_tree_view_get_path_at_pos() is the wrong function. It doesn't mind the header but returns column.
5024 // See http://mail.gnome.org/archives/gtkmm-list/2005-January/msg00080.html
5025 // So we have to use both of them.
5026 // Friedrich Haase 2010-9-20
5027 wxGtkTreePath path, pathScratch;
5028 GtkTreeViewColumn* GtkColumn = NULL;
5029 GtkTreeViewDropPosition pos = GTK_TREE_VIEW_DROP_INTO_OR_AFTER;
5030 gint cell_x = 0;
5031 gint cell_y = 0;
5032
5033 // cannot directly call GtkGetTreeView(), HitTest is const and so is this pointer
5034 wxDataViewCtrl* ctrl = (wxDataViewCtrl*)this; // ugly workaround, ctrl is NOT const
5035 GtkTreeView* treeView = GTK_TREE_VIEW(ctrl->GtkGetTreeView());
5036
5037 // is there possibly a better suited function to get the column?
5038 gtk_tree_view_get_path_at_pos( // and this is the wrong call but it delivers the column
5039 treeView,
5040 (int) point.x, (int) point.y,
5041 pathScratch.ByRef(),
5042 &GtkColumn, // here we get the GtkColumn
5043 &cell_x,
5044 &cell_y );
5045
5046 if ( GtkColumn != NULL )
5047 {
5048 // we got GTK column
5049 // the right call now which takes the header into account
5050 gtk_tree_view_get_dest_row_at_pos( treeView, (int) point.x, (int) point.y, path.ByRef(), &pos);
5051
5052 if (path)
5053 item = wxDataViewItem(GTKPathToItem(path));
5054 // else we got a GTK column but the position is not over an item, e.g. below last item
5055 for ( unsigned int i=0, cols=GetColumnCount(); i<cols; ++i ) // search the wx column
5056 {
5057 wxDataViewColumn* col = GetColumn(i);
5058 if ( GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) == GtkColumn )
5059 {
5060 column = col; // here we get the wx column
5061 break;
5062 }
5063 }
5064 }
5065 // else no column and thus no item, both null
5066 }
5067
5068 wxRect
5069 wxDataViewCtrl::GetItemRect(const wxDataViewItem& WXUNUSED(item),
5070 const wxDataViewColumn *WXUNUSED(column)) const
5071 {
5072 return wxRect();
5073 }
5074
5075 bool wxDataViewCtrl::SetRowHeight(int rowHeight)
5076 {
5077 m_uniformRowHeight = rowHeight;
5078 return true;
5079 }
5080
5081 void wxDataViewCtrl::DoSetExpanderColumn()
5082 {
5083 gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview),
5084 GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
5085 }
5086
5087 void wxDataViewCtrl::DoSetIndent()
5088 {
5089 }
5090
5091 void wxDataViewCtrl::GtkDisableSelectionEvents()
5092 {
5093 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
5094 g_signal_handlers_disconnect_by_func( selection,
5095 (gpointer) (wxdataview_selection_changed_callback), this);
5096 }
5097
5098 void wxDataViewCtrl::GtkEnableSelectionEvents()
5099 {
5100 GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
5101 g_signal_connect_after (selection, "changed",
5102 G_CALLBACK (wxdataview_selection_changed_callback), this);
5103 }
5104
5105 // ----------------------------------------------------------------------------
5106 // visual attributes stuff
5107 // ----------------------------------------------------------------------------
5108
5109 // static
5110 wxVisualAttributes
5111 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
5112 {
5113 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new);
5114 }
5115
5116 void wxDataViewCtrl::DoApplyWidgetStyle(GtkRcStyle *style)
5117 {
5118 wxDataViewCtrlBase::DoApplyWidgetStyle(style);
5119 gtk_widget_modify_style(m_treeview, style);
5120 }
5121
5122 #endif // !wxUSE_GENERICDATAVIEWCTRL
5123
5124 #endif // wxUSE_DATAVIEWCTRL