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