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