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