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