]>
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" |
e4db172a WS |
23 | #endif |
24 | ||
790b137e | 25 | #include "wx/stockitem.h" |
7ea3a0de RR |
26 | #include "wx/calctrl.h" |
27 | #include "wx/popupwin.h" | |
2586d4a1 RR |
28 | #include "wx/icon.h" |
29 | ||
790b137e RR |
30 | |
31 | #include "wx/gtk/private.h" | |
32 | #include "wx/gtk/win_gtk.h" | |
33 | ||
34 | #include <gobject/gvaluecollector.h> | |
1557c77b RR |
35 | #include <gtk/gtktreemodel.h> |
36 | #include <gtk/gtktreednd.h> | |
790b137e | 37 | |
4d496ecb RR |
38 | #include <gdk/gdkkeysyms.h> |
39 | ||
790b137e RR |
40 | //----------------------------------------------------------------------------- |
41 | // classes | |
42 | //----------------------------------------------------------------------------- | |
43 | ||
44 | class wxDataViewCtrl; | |
45 | ||
790b137e RR |
46 | //----------------------------------------------------------------------------- |
47 | // data | |
48 | //----------------------------------------------------------------------------- | |
49 | ||
50 | extern bool g_blockEventsOnDrag; | |
51 | ||
52 | //----------------------------------------------------------------------------- | |
53 | // define new GTK+ class wxGtkListStore | |
54 | //----------------------------------------------------------------------------- | |
55 | ||
56 | extern "C" { | |
57 | ||
58 | #define GTK_TYPE_WX_LIST_STORE (gtk_wx_list_store_get_type ()) | |
59 | #define GTK_WX_LIST_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_LIST_STORE, GtkWxListStore)) | |
60 | #define GTK_WX_LIST_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_LIST_STORE, GtkWxListStoreClass)) | |
61 | #define GTK_IS_WX_LIST_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_LIST_STORE)) | |
62 | #define GTK_IS_WX_LIST_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_LIST_STORE)) | |
63 | #define GTK_WX_LIST_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_LIST_STORE, GtkWxListStoreClass)) | |
64 | ||
65 | GType gtk_wx_list_store_get_type (void); | |
66 | ||
67 | typedef struct _GtkWxListStore GtkWxListStore; | |
68 | typedef struct _GtkWxListStoreClass GtkWxListStoreClass; | |
69 | ||
70 | struct _GtkWxListStore | |
71 | { | |
72 | GObject parent; | |
73 | ||
74 | /*< private >*/ | |
75 | gint stamp; | |
76 | wxDataViewListModel *model; | |
77 | }; | |
78 | ||
79 | struct _GtkWxListStoreClass | |
80 | { | |
e152afc3 | 81 | GObjectClass list_parent_class; |
790b137e RR |
82 | }; |
83 | ||
e152afc3 | 84 | static GtkWxListStore *wxgtk_list_store_new (void); |
790b137e | 85 | static void wxgtk_list_store_init (GtkWxListStore *list_store); |
1557c77b | 86 | static void wxgtk_list_store_class_init (GtkWxListStoreClass *klass); |
790b137e RR |
87 | static void wxgtk_list_store_tree_model_init (GtkTreeModelIface *iface); |
88 | static void wxgtk_list_store_finalize (GObject *object); | |
89 | static GtkTreeModelFlags wxgtk_list_store_get_flags (GtkTreeModel *tree_model); | |
90 | static gint wxgtk_list_store_get_n_columns (GtkTreeModel *tree_model); | |
91 | static GType wxgtk_list_store_get_column_type (GtkTreeModel *tree_model, | |
93763ad5 | 92 | gint index); |
790b137e | 93 | static gboolean wxgtk_list_store_get_iter (GtkTreeModel *tree_model, |
93763ad5 WS |
94 | GtkTreeIter *iter, |
95 | GtkTreePath *path); | |
790b137e | 96 | static GtkTreePath *wxgtk_list_store_get_path (GtkTreeModel *tree_model, |
93763ad5 | 97 | GtkTreeIter *iter); |
790b137e | 98 | static void wxgtk_list_store_get_value (GtkTreeModel *tree_model, |
93763ad5 WS |
99 | GtkTreeIter *iter, |
100 | gint column, | |
101 | GValue *value); | |
790b137e | 102 | static gboolean wxgtk_list_store_iter_next (GtkTreeModel *tree_model, |
93763ad5 | 103 | GtkTreeIter *iter); |
790b137e | 104 | static gboolean wxgtk_list_store_iter_children (GtkTreeModel *tree_model, |
93763ad5 WS |
105 | GtkTreeIter *iter, |
106 | GtkTreeIter *parent); | |
790b137e | 107 | static gboolean wxgtk_list_store_iter_has_child (GtkTreeModel *tree_model, |
93763ad5 | 108 | GtkTreeIter *iter); |
790b137e | 109 | static gint wxgtk_list_store_iter_n_children (GtkTreeModel *tree_model, |
93763ad5 | 110 | GtkTreeIter *iter); |
790b137e | 111 | static gboolean wxgtk_list_store_iter_nth_child (GtkTreeModel *tree_model, |
93763ad5 WS |
112 | GtkTreeIter *iter, |
113 | GtkTreeIter *parent, | |
114 | gint n); | |
790b137e | 115 | static gboolean wxgtk_list_store_iter_parent (GtkTreeModel *tree_model, |
93763ad5 WS |
116 | GtkTreeIter *iter, |
117 | GtkTreeIter *child); | |
790b137e | 118 | |
e152afc3 | 119 | static GObjectClass *list_parent_class = NULL; |
790b137e RR |
120 | |
121 | GType | |
111f83c4 | 122 | gtk_wx_list_store_get_type (void) |
790b137e | 123 | { |
93763ad5 | 124 | static GType list_store_type = 0; |
790b137e | 125 | |
93763ad5 | 126 | if (!list_store_type) |
790b137e | 127 | { |
93763ad5 WS |
128 | static const GTypeInfo list_store_info = |
129 | { | |
130 | sizeof (GtkWxListStoreClass), | |
131 | NULL, /* base_init */ | |
132 | NULL, /* base_finalize */ | |
133 | (GClassInitFunc) wxgtk_list_store_class_init, | |
134 | NULL, /* class_finalize */ | |
135 | NULL, /* class_data */ | |
136 | sizeof (GtkWxListStore), | |
137 | 0, | |
138 | (GInstanceInitFunc) wxgtk_list_store_init, | |
139 | }; | |
790b137e RR |
140 | |
141 | static const GInterfaceInfo tree_model_info = | |
142 | { | |
93763ad5 WS |
143 | (GInterfaceInitFunc) wxgtk_list_store_tree_model_init, |
144 | NULL, | |
145 | NULL | |
790b137e RR |
146 | }; |
147 | ||
148 | list_store_type = g_type_register_static (G_TYPE_OBJECT, "GtkWxListStore", | |
93763ad5 | 149 | &list_store_info, (GTypeFlags)0 ); |
790b137e RR |
150 | |
151 | g_type_add_interface_static (list_store_type, | |
93763ad5 WS |
152 | GTK_TYPE_TREE_MODEL, |
153 | &tree_model_info); | |
790b137e RR |
154 | } |
155 | ||
156 | return list_store_type; | |
157 | } | |
158 | ||
1557c77b | 159 | static GtkWxListStore * |
e152afc3 | 160 | wxgtk_list_store_new(void) |
1557c77b | 161 | { |
e152afc3 RR |
162 | GtkWxListStore *retval = (GtkWxListStore *) g_object_new (GTK_TYPE_WX_LIST_STORE, NULL); |
163 | return retval; | |
1557c77b RR |
164 | } |
165 | ||
790b137e | 166 | static void |
1557c77b | 167 | wxgtk_list_store_class_init (GtkWxListStoreClass *klass) |
790b137e | 168 | { |
e152afc3 RR |
169 | list_parent_class = (GObjectClass*) g_type_class_peek_parent (klass); |
170 | GObjectClass *object_class = (GObjectClass*) klass; | |
790b137e RR |
171 | object_class->finalize = wxgtk_list_store_finalize; |
172 | } | |
173 | ||
174 | static void | |
175 | wxgtk_list_store_tree_model_init (GtkTreeModelIface *iface) | |
176 | { | |
177 | iface->get_flags = wxgtk_list_store_get_flags; | |
178 | iface->get_n_columns = wxgtk_list_store_get_n_columns; | |
179 | iface->get_column_type = wxgtk_list_store_get_column_type; | |
180 | iface->get_iter = wxgtk_list_store_get_iter; | |
181 | iface->get_path = wxgtk_list_store_get_path; | |
182 | iface->get_value = wxgtk_list_store_get_value; | |
183 | iface->iter_next = wxgtk_list_store_iter_next; | |
184 | iface->iter_children = wxgtk_list_store_iter_children; | |
185 | iface->iter_has_child = wxgtk_list_store_iter_has_child; | |
186 | iface->iter_n_children = wxgtk_list_store_iter_n_children; | |
187 | iface->iter_nth_child = wxgtk_list_store_iter_nth_child; | |
188 | iface->iter_parent = wxgtk_list_store_iter_parent; | |
189 | } | |
190 | ||
191 | static void | |
192 | wxgtk_list_store_init (GtkWxListStore *list_store) | |
193 | { | |
194 | list_store->model = NULL; | |
1557c77b | 195 | list_store->stamp = g_random_int(); |
790b137e RR |
196 | } |
197 | ||
198 | static void | |
199 | wxgtk_list_store_finalize (GObject *object) | |
200 | { | |
1557c77b | 201 | /* GtkWxListStore *list_store = GTK_WX_LIST_STORE (object); */ |
790b137e RR |
202 | |
203 | /* we need to sort out, which class deletes what */ | |
111f83c4 | 204 | /* delete list_store->model; */ |
790b137e RR |
205 | |
206 | /* must chain up */ | |
e152afc3 | 207 | (* list_parent_class->finalize) (object); |
790b137e | 208 | } |
93763ad5 | 209 | |
790b137e RR |
210 | } // extern "C" |
211 | ||
212 | //----------------------------------------------------------------------------- | |
213 | // implement callbacks from wxGtkListStore class by letting | |
214 | // them call the methods of wxWidgets' wxDataViewListModel | |
215 | //----------------------------------------------------------------------------- | |
216 | ||
217 | static GtkTreeModelFlags | |
218 | wxgtk_list_store_get_flags (GtkTreeModel *tree_model) | |
219 | { | |
1557c77b | 220 | g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model), (GtkTreeModelFlags)0 ); |
790b137e | 221 | |
67cbdfc1 RR |
222 | // GTK+ list store uses a linked list for storing the |
223 | // items and a pointer to a child is used as the member | |
224 | // field of a GtkTreeIter. This means that the iter is | |
225 | // valid in the GtkListStore as long as the child exists. | |
226 | // We use the index of the row and since the index of a | |
227 | // specific row will change if a row above is deleted, | |
228 | // the iter does not persist | |
229 | return /* GTK_TREE_MODEL_ITERS_PERSIST | */ GTK_TREE_MODEL_LIST_ONLY; | |
790b137e RR |
230 | } |
231 | ||
232 | static gint | |
233 | wxgtk_list_store_get_n_columns (GtkTreeModel *tree_model) | |
234 | { | |
235 | GtkWxListStore *list_store = (GtkWxListStore *) tree_model; | |
236 | g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model), 0); | |
237 | ||
239eaa41 | 238 | return list_store->model->GetNumberOfCols(); |
790b137e RR |
239 | } |
240 | ||
241 | static GType | |
242 | wxgtk_list_store_get_column_type (GtkTreeModel *tree_model, | |
93763ad5 | 243 | gint index) |
790b137e RR |
244 | { |
245 | GtkWxListStore *list_store = (GtkWxListStore *) tree_model; | |
246 | g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model), G_TYPE_INVALID); | |
247 | ||
1557c77b | 248 | GType gtype = G_TYPE_INVALID; |
93763ad5 | 249 | |
0a71f9e9 | 250 | wxString wxtype = list_store->model->GetColType( (unsigned int) index ); |
93763ad5 | 251 | |
1557c77b RR |
252 | if (wxtype == wxT("string")) |
253 | gtype = G_TYPE_STRING; | |
790b137e RR |
254 | |
255 | return gtype; | |
256 | } | |
257 | ||
258 | static gboolean | |
259 | wxgtk_list_store_get_iter (GtkTreeModel *tree_model, | |
93763ad5 WS |
260 | GtkTreeIter *iter, |
261 | GtkTreePath *path) | |
790b137e RR |
262 | { |
263 | GtkWxListStore *list_store = (GtkWxListStore *) tree_model; | |
264 | g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model), FALSE); | |
265 | g_return_val_if_fail (gtk_tree_path_get_depth (path) > 0, FALSE); | |
266 | ||
0a71f9e9 | 267 | unsigned int i = (unsigned int)gtk_tree_path_get_indices (path)[0]; |
790b137e | 268 | |
1557c77b | 269 | if (i >= list_store->model->GetNumberOfRows()) |
239eaa41 | 270 | return FALSE; |
790b137e | 271 | |
239eaa41 RR |
272 | iter->stamp = list_store->stamp; |
273 | // user_data is just the index | |
274 | iter->user_data = (gpointer) i; | |
790b137e RR |
275 | |
276 | return TRUE; | |
277 | } | |
278 | ||
279 | static GtkTreePath * | |
280 | wxgtk_list_store_get_path (GtkTreeModel *tree_model, | |
93763ad5 | 281 | GtkTreeIter *iter) |
790b137e | 282 | { |
790b137e | 283 | g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model), NULL); |
239eaa41 | 284 | g_return_val_if_fail (iter->stamp == GTK_WX_LIST_STORE (tree_model)->stamp, NULL); |
93763ad5 | 285 | |
239eaa41 RR |
286 | GtkTreePath *retval = gtk_tree_path_new (); |
287 | // user_data is just the index | |
7a9f5d5a | 288 | int i = (wxUIntPtr) iter->user_data; |
239eaa41 RR |
289 | gtk_tree_path_append_index (retval, i); |
290 | return retval; | |
790b137e RR |
291 | } |
292 | ||
293 | static void | |
294 | wxgtk_list_store_get_value (GtkTreeModel *tree_model, | |
93763ad5 WS |
295 | GtkTreeIter *iter, |
296 | gint column, | |
297 | GValue *value) | |
790b137e | 298 | { |
1557c77b | 299 | GtkWxListStore *list_store = (GtkWxListStore *) tree_model; |
790b137e | 300 | g_return_if_fail (GTK_IS_WX_LIST_STORE (tree_model) ); |
239eaa41 | 301 | |
1557c77b | 302 | wxDataViewListModel *model = list_store->model; |
0a71f9e9 | 303 | wxString mtype = model->GetColType( (unsigned int) column ); |
1557c77b RR |
304 | if (mtype == wxT("string")) |
305 | { | |
3f3af7e7 | 306 | wxVariant variant; |
1557c77b | 307 | g_value_init( value, G_TYPE_STRING ); |
0a71f9e9 | 308 | model->GetValue( variant, (unsigned int) column, (unsigned int) iter->user_data ); |
1557c77b RR |
309 | g_value_set_string( value, wxGTK_CONV(variant.GetString()) ); |
310 | } | |
311 | else | |
312 | { | |
313 | } | |
93763ad5 | 314 | |
790b137e RR |
315 | #if 0 |
316 | GtkTreeDataList *list; | |
317 | gint tmp_column = column; | |
318 | ||
319 | g_return_if_fail (column < GTK_LIST_STORE (tree_model)->n_columns); | |
320 | g_return_if_fail (GTK_LIST_STORE (tree_model)->stamp == iter->stamp); | |
321 | ||
322 | list = G_SLIST (iter->user_data)->data; | |
323 | ||
324 | while (tmp_column-- > 0 && list) | |
325 | list = list->next; | |
326 | ||
327 | if (list == NULL) | |
328 | g_value_init (value, GTK_LIST_STORE (tree_model)->column_headers[column]); | |
329 | else | |
330 | _gtk_tree_data_list_node_to_value (list, | |
93763ad5 WS |
331 | GTK_LIST_STORE (tree_model)->column_headers[column], |
332 | value); | |
790b137e RR |
333 | #endif |
334 | ||
335 | } | |
336 | ||
337 | static gboolean | |
338 | wxgtk_list_store_iter_next (GtkTreeModel *tree_model, | |
93763ad5 | 339 | GtkTreeIter *iter) |
790b137e | 340 | { |
790b137e | 341 | g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model), FALSE); |
1557c77b | 342 | GtkWxListStore *list_store = (GtkWxListStore *) tree_model; |
93763ad5 | 343 | |
67cbdfc1 | 344 | g_return_val_if_fail (list_store->stamp == iter->stamp, FALSE); |
790b137e | 345 | |
7a9f5d5a | 346 | int n = (wxUIntPtr) iter->user_data; |
93763ad5 | 347 | |
67cbdfc1 RR |
348 | if (n == -1) |
349 | return FALSE; | |
93763ad5 | 350 | |
1a367564 | 351 | if (n >= (int) list_store->model->GetNumberOfRows()-1) |
67cbdfc1 | 352 | return FALSE; |
93763ad5 | 353 | |
111f83c4 | 354 | iter->user_data = (gpointer) ++n; |
790b137e | 355 | |
67cbdfc1 | 356 | return TRUE; |
790b137e RR |
357 | } |
358 | ||
359 | static gboolean | |
360 | wxgtk_list_store_iter_children (GtkTreeModel *tree_model, | |
93763ad5 WS |
361 | GtkTreeIter *iter, |
362 | GtkTreeIter *parent) | |
790b137e | 363 | { |
67cbdfc1 | 364 | g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model), FALSE); |
1557c77b | 365 | GtkWxListStore *list_store = (GtkWxListStore *) tree_model; |
93763ad5 | 366 | |
67cbdfc1 | 367 | // this is a list, nodes have no children |
790b137e RR |
368 | if (parent) |
369 | return FALSE; | |
370 | ||
67cbdfc1 RR |
371 | iter->stamp = list_store->stamp; |
372 | iter->user_data = (gpointer) -1; | |
93763ad5 | 373 | |
67cbdfc1 | 374 | return TRUE; |
790b137e RR |
375 | } |
376 | ||
377 | static gboolean | |
378 | wxgtk_list_store_iter_has_child (GtkTreeModel *tree_model, | |
93763ad5 | 379 | GtkTreeIter *iter) |
790b137e RR |
380 | { |
381 | return FALSE; | |
382 | } | |
383 | ||
384 | static gint | |
385 | wxgtk_list_store_iter_n_children (GtkTreeModel *tree_model, | |
93763ad5 | 386 | GtkTreeIter *iter) |
790b137e RR |
387 | { |
388 | g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model), -1); | |
1557c77b | 389 | GtkWxListStore *list_store = (GtkWxListStore *) tree_model; |
93763ad5 | 390 | |
790b137e | 391 | if (iter == NULL) |
1557c77b | 392 | return (gint) list_store->model->GetNumberOfRows(); |
790b137e | 393 | |
67cbdfc1 | 394 | g_return_val_if_fail (list_store->stamp == iter->stamp, -1); |
93763ad5 | 395 | |
790b137e RR |
396 | return 0; |
397 | } | |
398 | ||
399 | static gboolean | |
400 | wxgtk_list_store_iter_nth_child (GtkTreeModel *tree_model, | |
93763ad5 WS |
401 | GtkTreeIter *iter, |
402 | GtkTreeIter *parent, | |
403 | gint n) | |
790b137e | 404 | { |
67cbdfc1 | 405 | g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model), FALSE); |
1557c77b | 406 | GtkWxListStore *list_store = (GtkWxListStore *) tree_model; |
93763ad5 | 407 | |
67cbdfc1 RR |
408 | if (parent) |
409 | return FALSE; | |
790b137e | 410 | |
67cbdfc1 RR |
411 | if (n < 0) |
412 | return FALSE; | |
93763ad5 | 413 | |
1557c77b | 414 | if (n >= (gint) list_store->model->GetNumberOfRows()) |
67cbdfc1 | 415 | return FALSE; |
790b137e | 416 | |
67cbdfc1 RR |
417 | iter->stamp = list_store->stamp; |
418 | iter->user_data = (gpointer) n; | |
93763ad5 | 419 | |
67cbdfc1 | 420 | return TRUE; |
790b137e RR |
421 | } |
422 | ||
423 | static gboolean | |
424 | wxgtk_list_store_iter_parent (GtkTreeModel *tree_model, | |
93763ad5 WS |
425 | GtkTreeIter *iter, |
426 | GtkTreeIter *child) | |
790b137e RR |
427 | { |
428 | return FALSE; | |
429 | } | |
430 | ||
e152afc3 | 431 | //----------------------------------------------------------------------------- |
baa9ebc4 | 432 | // define new GTK+ class wxGtkRendererRenderer |
e152afc3 RR |
433 | //----------------------------------------------------------------------------- |
434 | ||
435 | extern "C" { | |
436 | ||
437 | #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ()) | |
438 | #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer)) | |
439 | #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass)) | |
440 | #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER)) | |
441 | #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER)) | |
442 | #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass)) | |
443 | ||
444 | GType gtk_wx_cell_renderer_get_type (void); | |
445 | ||
446 | typedef struct _GtkWxCellRenderer GtkWxCellRenderer; | |
447 | typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass; | |
448 | ||
449 | struct _GtkWxCellRenderer | |
450 | { | |
451 | GtkCellRenderer parent; | |
452 | ||
453 | /*< private >*/ | |
baa9ebc4 | 454 | wxDataViewCustomRenderer *cell; |
4d496ecb | 455 | guint32 last_click; |
e152afc3 RR |
456 | }; |
457 | ||
458 | struct _GtkWxCellRendererClass | |
459 | { | |
460 | GtkCellRendererClass cell_parent_class; | |
e152afc3 RR |
461 | }; |
462 | ||
463 | ||
464 | static GtkCellRenderer *gtk_wx_cell_renderer_new (void); | |
553f7d8f RR |
465 | static void gtk_wx_cell_renderer_init ( |
466 | GtkWxCellRenderer *cell ); | |
467 | static void gtk_wx_cell_renderer_class_init( | |
468 | GtkWxCellRendererClass *klass ); | |
469 | static void gtk_wx_cell_renderer_finalize ( | |
470 | GObject *object ); | |
471 | static void gtk_wx_cell_renderer_get_size ( | |
472 | GtkCellRenderer *cell, | |
93763ad5 WS |
473 | GtkWidget *widget, |
474 | GdkRectangle *rectangle, | |
475 | gint *x_offset, | |
476 | gint *y_offset, | |
477 | gint *width, | |
478 | gint *height ); | |
553f7d8f RR |
479 | static void gtk_wx_cell_renderer_render ( |
480 | GtkCellRenderer *cell, | |
93763ad5 WS |
481 | GdkWindow *window, |
482 | GtkWidget *widget, | |
483 | GdkRectangle *background_area, | |
484 | GdkRectangle *cell_area, | |
485 | GdkRectangle *expose_area, | |
486 | GtkCellRendererState flags ); | |
553f7d8f RR |
487 | static gboolean gtk_wx_cell_renderer_activate( |
488 | GtkCellRenderer *cell, | |
489 | GdkEvent *event, | |
490 | GtkWidget *widget, | |
491 | const gchar *path, | |
492 | GdkRectangle *background_area, | |
493 | GdkRectangle *cell_area, | |
494 | GtkCellRendererState flags ); | |
e152afc3 RR |
495 | |
496 | static GObjectClass *cell_parent_class = NULL; | |
497 | ||
498 | } // extern "C" | |
499 | ||
93763ad5 | 500 | GType |
e152afc3 RR |
501 | gtk_wx_cell_renderer_get_type (void) |
502 | { | |
553f7d8f | 503 | static GType cell_wx_type = 0; |
e152afc3 | 504 | |
553f7d8f | 505 | if (!cell_wx_type) |
e152afc3 | 506 | { |
553f7d8f RR |
507 | static const GTypeInfo cell_wx_info = |
508 | { | |
509 | sizeof (GtkWxCellRendererClass), | |
93763ad5 WS |
510 | NULL, /* base_init */ |
511 | NULL, /* base_finalize */ | |
553f7d8f | 512 | (GClassInitFunc) gtk_wx_cell_renderer_class_init, |
93763ad5 WS |
513 | NULL, /* class_finalize */ |
514 | NULL, /* class_data */ | |
553f7d8f RR |
515 | sizeof (GtkWxCellRenderer), |
516 | 0, /* n_preallocs */ | |
517 | (GInstanceInitFunc) gtk_wx_cell_renderer_init, | |
518 | }; | |
519 | ||
93763ad5 | 520 | cell_wx_type = g_type_register_static( GTK_TYPE_CELL_RENDERER, |
553f7d8f | 521 | "GtkWxCellRenderer", &cell_wx_info, (GTypeFlags)0 ); |
e152afc3 RR |
522 | } |
523 | ||
553f7d8f | 524 | return cell_wx_type; |
e152afc3 RR |
525 | } |
526 | ||
527 | static void | |
528 | gtk_wx_cell_renderer_init (GtkWxCellRenderer *cell) | |
529 | { | |
530 | cell->cell = NULL; | |
4d496ecb | 531 | cell->last_click = 0; |
e152afc3 RR |
532 | } |
533 | ||
534 | static void | |
535 | gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass *klass) | |
536 | { | |
537 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
538 | GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass); | |
539 | ||
540 | cell_parent_class = (GObjectClass*) g_type_class_peek_parent (klass); | |
541 | ||
542 | object_class->finalize = gtk_wx_cell_renderer_finalize; | |
543 | ||
544 | cell_class->get_size = gtk_wx_cell_renderer_get_size; | |
545 | cell_class->render = gtk_wx_cell_renderer_render; | |
553f7d8f | 546 | cell_class->activate = gtk_wx_cell_renderer_activate; |
e152afc3 RR |
547 | } |
548 | ||
549 | static void | |
550 | gtk_wx_cell_renderer_finalize (GObject *object) | |
551 | { | |
552 | /* must chain up */ | |
553 | (* G_OBJECT_CLASS (cell_parent_class)->finalize) (object); | |
554 | } | |
555 | ||
556 | GtkCellRenderer* | |
557 | gtk_wx_cell_renderer_new (void) | |
558 | { | |
559 | return (GtkCellRenderer*) g_object_new (GTK_TYPE_WX_CELL_RENDERER, NULL); | |
560 | } | |
561 | ||
562 | static void | |
563 | gtk_wx_cell_renderer_get_size (GtkCellRenderer *renderer, | |
93763ad5 WS |
564 | GtkWidget *widget, |
565 | GdkRectangle *cell_area, | |
566 | gint *x_offset, | |
567 | gint *y_offset, | |
568 | gint *width, | |
569 | gint *height) | |
e152afc3 RR |
570 | { |
571 | GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer; | |
baa9ebc4 | 572 | wxDataViewCustomRenderer *cell = wxrenderer->cell; |
93763ad5 | 573 | |
e152afc3 RR |
574 | wxSize size = cell->GetSize(); |
575 | ||
576 | gint calc_width = (gint) renderer->xpad * 2 + size.x; | |
577 | gint calc_height = (gint) renderer->ypad * 2 + size.y; | |
93763ad5 WS |
578 | |
579 | if (x_offset) | |
e152afc3 | 580 | *x_offset = 0; |
93763ad5 | 581 | if (y_offset) |
e152afc3 RR |
582 | *y_offset = 0; |
583 | ||
584 | if (cell_area && size.x > 0 && size.y > 0) | |
585 | { | |
586 | if (x_offset) | |
93763ad5 | 587 | { |
e152afc3 RR |
588 | *x_offset = (gint)((renderer->xalign * |
589 | (cell_area->width - calc_width - 2 * renderer->xpad))); | |
590 | *x_offset = MAX (*x_offset, 0) + renderer->xpad; | |
93763ad5 | 591 | } |
e152afc3 RR |
592 | if (y_offset) |
593 | { | |
594 | *y_offset = (gint)((renderer->yalign * | |
595 | (cell_area->height - calc_height - 2 * renderer->ypad))); | |
596 | *y_offset = MAX (*y_offset, 0) + renderer->ypad; | |
597 | } | |
598 | } | |
599 | ||
600 | if (width) | |
601 | *width = calc_width; | |
93763ad5 | 602 | |
e152afc3 RR |
603 | if (height) |
604 | *height = calc_height; | |
605 | } | |
606 | ||
607 | static void | |
608 | gtk_wx_cell_renderer_render (GtkCellRenderer *renderer, | |
93763ad5 WS |
609 | GdkWindow *window, |
610 | GtkWidget *widget, | |
611 | GdkRectangle *background_area, | |
612 | GdkRectangle *cell_area, | |
613 | GdkRectangle *expose_area, | |
614 | GtkCellRendererState flags) | |
e152afc3 RR |
615 | |
616 | { | |
617 | GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer; | |
baa9ebc4 | 618 | wxDataViewCustomRenderer *cell = wxrenderer->cell; |
93763ad5 | 619 | |
e152afc3 RR |
620 | GdkRectangle rect; |
621 | gtk_wx_cell_renderer_get_size (renderer, widget, cell_area, | |
93763ad5 WS |
622 | &rect.x, |
623 | &rect.y, | |
624 | &rect.width, | |
625 | &rect.height); | |
e152afc3 RR |
626 | |
627 | rect.x += cell_area->x; | |
628 | rect.y += cell_area->y; | |
629 | rect.width -= renderer->xpad * 2; | |
630 | rect.height -= renderer->ypad * 2; | |
93763ad5 | 631 | |
e152afc3 RR |
632 | GdkRectangle dummy; |
633 | if (gdk_rectangle_intersect (expose_area, &rect, &dummy)) | |
634 | { | |
635 | wxRect renderrect( rect.x, rect.y, rect.width, rect.height ); | |
636 | wxWindowDC* dc = (wxWindowDC*) cell->GetDC(); | |
4d496ecb RR |
637 | if (dc->m_window == NULL) |
638 | { | |
639 | dc->m_window = window; | |
640 | dc->SetUpDC(); | |
641 | } | |
93763ad5 | 642 | |
e152afc3 RR |
643 | int state = 0; |
644 | if (flags & GTK_CELL_RENDERER_SELECTED) | |
645 | state |= wxDATAVIEW_CELL_SELECTED; | |
646 | if (flags & GTK_CELL_RENDERER_PRELIT) | |
647 | state |= wxDATAVIEW_CELL_PRELIT; | |
648 | if (flags & GTK_CELL_RENDERER_INSENSITIVE) | |
649 | state |= wxDATAVIEW_CELL_INSENSITIVE; | |
650 | if (flags & GTK_CELL_RENDERER_INSENSITIVE) | |
651 | state |= wxDATAVIEW_CELL_INSENSITIVE; | |
652 | if (flags & GTK_CELL_RENDERER_FOCUSED) | |
653 | state |= wxDATAVIEW_CELL_FOCUSED; | |
654 | cell->Render( renderrect, dc, state ); | |
93763ad5 | 655 | } |
e152afc3 RR |
656 | } |
657 | ||
93763ad5 | 658 | static gboolean |
553f7d8f RR |
659 | gtk_wx_cell_renderer_activate( |
660 | GtkCellRenderer *renderer, | |
661 | GdkEvent *event, | |
662 | GtkWidget *widget, | |
663 | const gchar *path, | |
664 | GdkRectangle *background_area, | |
665 | GdkRectangle *cell_area, | |
666 | GtkCellRendererState flags ) | |
667 | { | |
668 | GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer; | |
baa9ebc4 | 669 | wxDataViewCustomRenderer *cell = wxrenderer->cell; |
93763ad5 | 670 | |
553f7d8f RR |
671 | GdkRectangle rect; |
672 | gtk_wx_cell_renderer_get_size (renderer, widget, cell_area, | |
93763ad5 WS |
673 | &rect.x, |
674 | &rect.y, | |
675 | &rect.width, | |
676 | &rect.height); | |
553f7d8f RR |
677 | |
678 | rect.x += cell_area->x; | |
679 | rect.y += cell_area->y; | |
680 | rect.width -= renderer->xpad * 2; | |
681 | rect.height -= renderer->ypad * 2; | |
93763ad5 | 682 | |
553f7d8f | 683 | wxRect renderrect( rect.x, rect.y, rect.width, rect.height ); |
93763ad5 | 684 | |
4d496ecb | 685 | wxDataViewListModel *model = cell->GetOwner()->GetOwner()->GetModel(); |
93763ad5 | 686 | |
4d496ecb | 687 | GtkTreePath *treepath = gtk_tree_path_new_from_string( path ); |
0a71f9e9 | 688 | unsigned int model_row = (unsigned int)gtk_tree_path_get_indices (treepath)[0]; |
4d496ecb | 689 | gtk_tree_path_free( treepath ); |
93763ad5 | 690 | |
0a71f9e9 | 691 | unsigned int model_col = cell->GetOwner()->GetModelColumn(); |
93763ad5 | 692 | |
4d496ecb RR |
693 | if (event->type == GDK_BUTTON_PRESS) |
694 | { | |
695 | GdkEventButton *button_event = (GdkEventButton*) event; | |
93763ad5 | 696 | wxPoint pt( ((int) button_event->x) - renderrect.x, |
4d496ecb | 697 | ((int) button_event->y) - renderrect.y ); |
93763ad5 | 698 | |
4d496ecb RR |
699 | bool ret = false; |
700 | if (button_event->button == 1) | |
701 | { | |
702 | if (cell->LeftClick( pt, renderrect, model, model_col, model_row )) | |
703 | ret = true; | |
7ea3a0de | 704 | // TODO: query system double-click time |
4d496ecb RR |
705 | if (button_event->time - wxrenderer->last_click < 400) |
706 | if (cell->Activate( renderrect, model, model_col, model_row )) | |
707 | ret = true; | |
708 | } | |
709 | if (button_event->button == 3) | |
710 | { | |
711 | if (cell->RightClick( pt, renderrect, model, model_col, model_row )) | |
712 | ret = true; | |
713 | } | |
93763ad5 | 714 | |
4d496ecb | 715 | wxrenderer->last_click = button_event->time; |
93763ad5 | 716 | |
4d496ecb RR |
717 | return ret; |
718 | } | |
93763ad5 | 719 | |
4d496ecb | 720 | return false; |
553f7d8f RR |
721 | } |
722 | ||
93763ad5 | 723 | // --------------------------------------------------------- |
6e2e590f | 724 | // wxGtkDataViewListModelNotifier |
93763ad5 | 725 | // --------------------------------------------------------- |
6e2e590f RR |
726 | |
727 | class wxGtkDataViewListModelNotifier: public wxDataViewListModelNotifier | |
728 | { | |
729 | public: | |
730 | wxGtkDataViewListModelNotifier( GtkWxListStore* gtk_store, wxDataViewListModel *wx_model ); | |
93763ad5 | 731 | |
6e2e590f RR |
732 | virtual bool RowAppended(); |
733 | virtual bool RowPrepended(); | |
0a71f9e9 RR |
734 | virtual bool RowInserted( unsigned int before ); |
735 | virtual bool RowDeleted( unsigned int row ); | |
736 | virtual bool RowChanged( unsigned int row ); | |
737 | virtual bool ValueChanged( unsigned int col, unsigned int row ); | |
738 | virtual bool RowsReordered( unsigned int *new_order ); | |
6e2e590f | 739 | virtual bool Cleared(); |
93763ad5 | 740 | |
6e2e590f RR |
741 | GtkWxListStore *m_gtk_store; |
742 | wxDataViewListModel *m_wx_model; | |
743 | }; | |
744 | ||
93763ad5 | 745 | // --------------------------------------------------------- |
6e2e590f | 746 | // wxGtkDataViewListModelNotifier |
93763ad5 | 747 | // --------------------------------------------------------- |
6e2e590f | 748 | |
93763ad5 | 749 | wxGtkDataViewListModelNotifier::wxGtkDataViewListModelNotifier( |
6e2e590f RR |
750 | GtkWxListStore* gtk_store, wxDataViewListModel *wx_model ) |
751 | { | |
752 | m_gtk_store = gtk_store; | |
753 | m_wx_model = wx_model; | |
754 | } | |
93763ad5 | 755 | |
6e2e590f RR |
756 | bool wxGtkDataViewListModelNotifier::RowAppended() |
757 | { | |
0a71f9e9 | 758 | unsigned int pos = m_wx_model->GetNumberOfRows()-1; |
93763ad5 | 759 | |
6e2e590f RR |
760 | GtkTreeIter iter; |
761 | iter.stamp = m_gtk_store->stamp; | |
762 | iter.user_data = (gpointer) pos; | |
93763ad5 | 763 | |
6e2e590f RR |
764 | GtkTreePath *path = gtk_tree_path_new (); |
765 | gtk_tree_path_append_index (path, (gint) pos); | |
766 | gtk_tree_model_row_inserted (GTK_TREE_MODEL (m_gtk_store), path, &iter); | |
767 | gtk_tree_path_free (path); | |
93763ad5 | 768 | |
6e2e590f RR |
769 | return true; |
770 | } | |
771 | ||
772 | bool wxGtkDataViewListModelNotifier::RowPrepended() | |
773 | { | |
605c2c4a RR |
774 | GtkTreeIter iter; |
775 | iter.stamp = m_gtk_store->stamp; | |
776 | iter.user_data = (gpointer) 0; | |
93763ad5 | 777 | |
605c2c4a RR |
778 | GtkTreePath *path = gtk_tree_path_new (); |
779 | gtk_tree_path_append_index (path, (gint) 0); | |
780 | gtk_tree_model_row_inserted (GTK_TREE_MODEL (m_gtk_store), path, &iter); | |
781 | gtk_tree_path_free (path); | |
93763ad5 | 782 | |
605c2c4a | 783 | return true; |
6e2e590f RR |
784 | } |
785 | ||
0a71f9e9 | 786 | bool wxGtkDataViewListModelNotifier::RowInserted( unsigned int before ) |
6e2e590f | 787 | { |
4627af27 RR |
788 | GtkTreeIter iter; |
789 | iter.stamp = m_gtk_store->stamp; | |
790 | iter.user_data = (gpointer) before; | |
791 | ||
792 | GtkTreePath *path = gtk_tree_path_new (); | |
793 | gtk_tree_path_append_index (path, (gint) before); | |
794 | gtk_tree_model_row_inserted (GTK_TREE_MODEL (m_gtk_store), path, &iter); | |
795 | gtk_tree_path_free (path); | |
796 | ||
797 | return true; | |
6e2e590f RR |
798 | } |
799 | ||
0a71f9e9 | 800 | bool wxGtkDataViewListModelNotifier::RowDeleted( unsigned int row ) |
6e2e590f | 801 | { |
4627af27 RR |
802 | GtkTreePath *path = gtk_tree_path_new (); |
803 | gtk_tree_path_append_index (path, (gint) row); | |
804 | gtk_tree_model_row_deleted (GTK_TREE_MODEL (m_gtk_store), path); | |
805 | gtk_tree_path_free (path); | |
806 | ||
807 | return true; | |
6e2e590f RR |
808 | } |
809 | ||
0a71f9e9 | 810 | bool wxGtkDataViewListModelNotifier::RowChanged( unsigned int row ) |
6e2e590f | 811 | { |
a7f61f76 RR |
812 | GtkTreeIter iter; |
813 | iter.stamp = m_gtk_store->stamp; | |
814 | iter.user_data = (gpointer) row; | |
815 | GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (m_gtk_store), &iter); | |
816 | gtk_tree_model_row_changed (GTK_TREE_MODEL (m_gtk_store), path, &iter); | |
817 | gtk_tree_path_free (path); | |
818 | ||
819 | return true; | |
6e2e590f RR |
820 | } |
821 | ||
0a71f9e9 | 822 | bool wxGtkDataViewListModelNotifier::ValueChanged( unsigned int model_col, unsigned int model_row ) |
6e2e590f | 823 | { |
4eccd3a1 | 824 | // This adds GTK+'s missing MVC logic for ValueChanged |
8f850e28 RR |
825 | wxNode *node = GetOwner()->m_viewingColumns.GetFirst(); |
826 | while (node) | |
827 | { | |
828 | wxDataViewViewingColumn* viewing_column = (wxDataViewViewingColumn*) node->GetData(); | |
829 | if (viewing_column->m_modelColumn == model_col) | |
830 | { | |
831 | GtkTreeView *widget = GTK_TREE_VIEW(viewing_column->m_viewColumn->GetOwner()->m_treeview); | |
832 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(viewing_column->m_viewColumn->GetGtkHandle()); | |
833 | ||
834 | // Get cell area | |
835 | GtkTreePath *path = gtk_tree_path_new(); | |
836 | gtk_tree_path_append_index( path, model_row ); | |
837 | GdkRectangle cell_area; | |
838 | gtk_tree_view_get_cell_area( widget, path, column, &cell_area ); | |
93763ad5 | 839 | gtk_tree_path_free( path ); |
8f850e28 RR |
840 | |
841 | int ydiff = column->button->allocation.height; | |
842 | // Redraw | |
93763ad5 | 843 | gtk_widget_queue_draw_area( GTK_WIDGET(widget), |
8f850e28 RR |
844 | cell_area.x, ydiff + cell_area.y, cell_area.width, cell_area.height ); |
845 | } | |
846 | ||
847 | node = node->GetNext(); | |
848 | } | |
93763ad5 | 849 | |
8f850e28 | 850 | return true; |
6e2e590f RR |
851 | } |
852 | ||
0a71f9e9 | 853 | bool wxGtkDataViewListModelNotifier::RowsReordered( unsigned int *new_order ) |
4eccd3a1 | 854 | { |
0a71f9e9 | 855 | // Assume sizeof(unsigned int)= == sizeof(gint) |
4eccd3a1 RR |
856 | |
857 | GtkTreePath *path = gtk_tree_path_new (); | |
858 | gtk_tree_model_rows_reordered (GTK_TREE_MODEL (m_gtk_store), path, NULL, (gint*)new_order); | |
859 | gtk_tree_path_free (path); | |
860 | ||
861 | // This adds GTK+'s missing MVC logic for RowsReordered | |
862 | wxNode *node = GetOwner()->m_viewingColumns.GetFirst(); | |
863 | while (node) | |
864 | { | |
865 | wxDataViewViewingColumn* viewing_column = (wxDataViewViewingColumn*) node->GetData(); | |
866 | GtkTreeView *widget = GTK_TREE_VIEW(viewing_column->m_viewColumn->GetOwner()->m_treeview); | |
867 | // Doesn't work yet... | |
93763ad5 | 868 | gtk_widget_queue_draw( GTK_WIDGET(widget) ); |
4eccd3a1 RR |
869 | |
870 | node = node->GetNext(); | |
871 | } | |
93763ad5 | 872 | |
4eccd3a1 RR |
873 | return true; |
874 | } | |
875 | ||
6e2e590f RR |
876 | bool wxGtkDataViewListModelNotifier::Cleared() |
877 | { | |
878 | return false; | |
879 | } | |
880 | ||
93763ad5 | 881 | // --------------------------------------------------------- |
baa9ebc4 | 882 | // wxDataViewRenderer |
93763ad5 | 883 | // --------------------------------------------------------- |
6842a71a | 884 | |
baa9ebc4 | 885 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer, wxDataViewRendererBase) |
6842a71a | 886 | |
baa9ebc4 RR |
887 | wxDataViewRenderer::wxDataViewRenderer( const wxString &varianttype, wxDataViewCellMode mode ) : |
888 | wxDataViewRendererBase( varianttype, mode ) | |
6842a71a RR |
889 | { |
890 | m_renderer = NULL; | |
891 | } | |
892 | ||
93763ad5 | 893 | // --------------------------------------------------------- |
baa9ebc4 | 894 | // wxDataViewTextRenderer |
93763ad5 | 895 | // --------------------------------------------------------- |
6842a71a | 896 | |
a7f61f76 | 897 | extern "C" { |
93763ad5 | 898 | static void wxGtkTextRendererEditedCallback( GtkCellRendererText *renderer, |
a7f61f76 RR |
899 | gchar *arg1, gchar *arg2, gpointer user_data ); |
900 | } | |
901 | ||
93763ad5 | 902 | static void wxGtkTextRendererEditedCallback( GtkCellRendererText *renderer, |
a7f61f76 RR |
903 | gchar *arg1, gchar *arg2, gpointer user_data ) |
904 | { | |
baa9ebc4 | 905 | wxDataViewTextRenderer *cell = (wxDataViewTextRenderer*) user_data; |
93763ad5 | 906 | |
a7f61f76 RR |
907 | wxString tmp = wxGTK_CONV_BACK( arg2 ); |
908 | wxVariant value = tmp; | |
909 | if (!cell->Validate( value )) | |
910 | return; | |
93763ad5 | 911 | |
a7f61f76 | 912 | wxDataViewListModel *model = cell->GetOwner()->GetOwner()->GetModel(); |
93763ad5 | 913 | |
a7f61f76 | 914 | GtkTreePath *path = gtk_tree_path_new_from_string( arg1 ); |
0a71f9e9 | 915 | unsigned int model_row = (unsigned int)gtk_tree_path_get_indices (path)[0]; |
a7f61f76 | 916 | gtk_tree_path_free( path ); |
93763ad5 | 917 | |
0a71f9e9 | 918 | unsigned int model_col = cell->GetOwner()->GetModelColumn(); |
93763ad5 | 919 | |
a7f61f76 RR |
920 | model->SetValue( value, model_col, model_row ); |
921 | model->ValueChanged( model_col, model_row ); | |
922 | } | |
923 | ||
baa9ebc4 | 924 | IMPLEMENT_CLASS(wxDataViewTextRenderer, wxDataViewRenderer) |
6842a71a | 925 | |
baa9ebc4 RR |
926 | wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString &varianttype, wxDataViewCellMode mode ) : |
927 | wxDataViewRenderer( varianttype, mode ) | |
6842a71a RR |
928 | { |
929 | m_renderer = (void*) gtk_cell_renderer_text_new(); | |
93763ad5 | 930 | |
a7f61f76 RR |
931 | if (m_mode & wxDATAVIEW_CELL_EDITABLE) |
932 | { | |
933 | GValue gvalue = { 0, }; | |
934 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
935 | g_value_set_boolean( &gvalue, true ); | |
936 | g_object_set_property( G_OBJECT(m_renderer), "editable", &gvalue ); | |
937 | g_value_unset( &gvalue ); | |
93763ad5 | 938 | |
a7f61f76 RR |
939 | g_signal_connect_after( m_renderer, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback), this ); |
940 | } | |
6842a71a | 941 | } |
790b137e | 942 | |
baa9ebc4 | 943 | bool wxDataViewTextRenderer::SetValue( const wxVariant &value ) |
7b4fde82 RR |
944 | { |
945 | wxString tmp = value; | |
93763ad5 | 946 | |
7b4fde82 RR |
947 | GValue gvalue = { 0, }; |
948 | g_value_init( &gvalue, G_TYPE_STRING ); | |
949 | g_value_set_string( &gvalue, wxGTK_CONV( tmp ) ); | |
950 | g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue ); | |
951 | g_value_unset( &gvalue ); | |
93763ad5 | 952 | |
7b4fde82 RR |
953 | return true; |
954 | } | |
955 | ||
baa9ebc4 | 956 | bool wxDataViewTextRenderer::GetValue( wxVariant &value ) |
a7f61f76 RR |
957 | { |
958 | GValue gvalue = { 0, }; | |
959 | g_value_init( &gvalue, G_TYPE_STRING ); | |
960 | g_object_get_property( G_OBJECT(m_renderer), "text", &gvalue ); | |
93763ad5 | 961 | wxString tmp = wxGTK_CONV_BACK( g_value_get_string( &gvalue ) ); |
a7f61f76 | 962 | g_value_unset( &gvalue ); |
93763ad5 | 963 | |
a7f61f76 RR |
964 | value = tmp; |
965 | ||
966 | return true; | |
967 | } | |
968 | ||
cbc9145c | 969 | // --------------------------------------------------------- |
baa9ebc4 | 970 | // wxDataViewBitmapRenderer |
cbc9145c RR |
971 | // --------------------------------------------------------- |
972 | ||
baa9ebc4 | 973 | IMPLEMENT_CLASS(wxDataViewBitmapRenderer, wxDataViewRenderer) |
cbc9145c | 974 | |
baa9ebc4 RR |
975 | wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString &varianttype, wxDataViewCellMode mode ) : |
976 | wxDataViewRenderer( varianttype, mode ) | |
cbc9145c RR |
977 | { |
978 | m_renderer = (void*) gtk_cell_renderer_pixbuf_new(); | |
979 | } | |
980 | ||
baa9ebc4 | 981 | bool wxDataViewBitmapRenderer::SetValue( const wxVariant &value ) |
cbc9145c RR |
982 | { |
983 | if (value.GetType() == wxT("wxBitmap")) | |
984 | { | |
2586d4a1 RR |
985 | wxBitmap bitmap; |
986 | bitmap << value; | |
987 | ||
988 | // This may create a Pixbuf representation in the | |
989 | // wxBitmap object (and it will stay there) | |
990 | GdkPixbuf *pixbuf = bitmap.GetPixbuf(); | |
991 | ||
992 | GValue gvalue = { 0, }; | |
993 | g_value_init( &gvalue, G_TYPE_OBJECT ); | |
994 | g_value_set_object( &gvalue, pixbuf ); | |
995 | g_object_set_property( G_OBJECT(m_renderer), "pixbuf", &gvalue ); | |
996 | g_value_unset( &gvalue ); | |
997 | ||
998 | return true; | |
999 | } | |
1000 | ||
1001 | if (value.GetType() == wxT("wxIcon")) | |
1002 | { | |
1003 | wxIcon bitmap; | |
1004 | bitmap << value; | |
cbc9145c RR |
1005 | |
1006 | // This may create a Pixbuf representation in the | |
1007 | // wxBitmap object (and it will stay there) | |
2586d4a1 | 1008 | GdkPixbuf *pixbuf = bitmap.GetPixbuf(); |
cbc9145c RR |
1009 | |
1010 | GValue gvalue = { 0, }; | |
1011 | g_value_init( &gvalue, G_TYPE_OBJECT ); | |
1012 | g_value_set_object( &gvalue, pixbuf ); | |
1013 | g_object_set_property( G_OBJECT(m_renderer), "pixbuf", &gvalue ); | |
1014 | g_value_unset( &gvalue ); | |
1015 | ||
1016 | return true; | |
1017 | } | |
1018 | ||
1019 | return false; | |
1020 | } | |
1021 | ||
baa9ebc4 | 1022 | bool wxDataViewBitmapRenderer::GetValue( wxVariant &value ) |
cbc9145c RR |
1023 | { |
1024 | return false; | |
1025 | } | |
1026 | ||
93763ad5 | 1027 | // --------------------------------------------------------- |
baa9ebc4 | 1028 | // wxDataViewToggleRenderer |
93763ad5 | 1029 | // --------------------------------------------------------- |
fa28826d | 1030 | |
605c2c4a | 1031 | extern "C" { |
93763ad5 | 1032 | static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle *renderer, |
605c2c4a RR |
1033 | gchar *path, gpointer user_data ); |
1034 | } | |
1035 | ||
93763ad5 | 1036 | static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle *renderer, |
605c2c4a RR |
1037 | gchar *path, gpointer user_data ) |
1038 | { | |
baa9ebc4 | 1039 | wxDataViewToggleRenderer *cell = (wxDataViewToggleRenderer*) user_data; |
605c2c4a | 1040 | |
93763ad5 | 1041 | // get old value |
605c2c4a RR |
1042 | GValue gvalue = { 0, }; |
1043 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
1044 | g_object_get_property( G_OBJECT(renderer), "active", &gvalue ); | |
93763ad5 | 1045 | bool tmp = g_value_get_boolean( &gvalue ); |
605c2c4a RR |
1046 | g_value_unset( &gvalue ); |
1047 | // invert it | |
1048 | tmp = !tmp; | |
93763ad5 | 1049 | |
605c2c4a RR |
1050 | wxVariant value = tmp; |
1051 | if (!cell->Validate( value )) | |
1052 | return; | |
93763ad5 | 1053 | |
605c2c4a | 1054 | wxDataViewListModel *model = cell->GetOwner()->GetOwner()->GetModel(); |
93763ad5 | 1055 | |
605c2c4a | 1056 | GtkTreePath *gtk_path = gtk_tree_path_new_from_string( path ); |
0a71f9e9 | 1057 | unsigned int model_row = (unsigned int)gtk_tree_path_get_indices (gtk_path)[0]; |
605c2c4a | 1058 | gtk_tree_path_free( gtk_path ); |
93763ad5 | 1059 | |
0a71f9e9 | 1060 | unsigned int model_col = cell->GetOwner()->GetModelColumn(); |
93763ad5 | 1061 | |
605c2c4a RR |
1062 | model->SetValue( value, model_col, model_row ); |
1063 | model->ValueChanged( model_col, model_row ); | |
1064 | } | |
1065 | ||
baa9ebc4 | 1066 | IMPLEMENT_CLASS(wxDataViewToggleRenderer, wxDataViewRenderer) |
605c2c4a | 1067 | |
baa9ebc4 | 1068 | wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString &varianttype, |
605c2c4a | 1069 | wxDataViewCellMode mode ) : |
baa9ebc4 | 1070 | wxDataViewRenderer( varianttype, mode ) |
605c2c4a RR |
1071 | { |
1072 | m_renderer = (void*) gtk_cell_renderer_toggle_new(); | |
93763ad5 | 1073 | |
0fdc2321 | 1074 | if (m_mode & wxDATAVIEW_CELL_ACTIVATABLE) |
605c2c4a | 1075 | { |
553f7d8f RR |
1076 | g_signal_connect_after( m_renderer, "toggled", G_CALLBACK(wxGtkToggleRendererToggledCallback), this ); |
1077 | } | |
1078 | else | |
1079 | { | |
1080 | ||
605c2c4a RR |
1081 | GValue gvalue = { 0, }; |
1082 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
553f7d8f | 1083 | g_value_set_boolean( &gvalue, false ); |
605c2c4a RR |
1084 | g_object_set_property( G_OBJECT(m_renderer), "activatable", &gvalue ); |
1085 | g_value_unset( &gvalue ); | |
553f7d8f RR |
1086 | |
1087 | GValue gvalue2 = { 0, }; | |
1088 | g_value_init( &gvalue2, gtk_cell_renderer_mode_get_type() ); | |
1089 | g_value_set_enum( &gvalue2, GTK_CELL_RENDERER_MODE_INERT ); | |
1090 | g_object_set_property( G_OBJECT(m_renderer), "mode", &gvalue2 ); | |
1091 | g_value_unset( &gvalue2 ); | |
1092 | ||
605c2c4a RR |
1093 | } |
1094 | } | |
1095 | ||
baa9ebc4 | 1096 | bool wxDataViewToggleRenderer::SetValue( const wxVariant &value ) |
605c2c4a RR |
1097 | { |
1098 | bool tmp = value; | |
93763ad5 | 1099 | |
605c2c4a RR |
1100 | GValue gvalue = { 0, }; |
1101 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
1102 | g_value_set_boolean( &gvalue, tmp ); | |
1103 | g_object_set_property( G_OBJECT(m_renderer), "active", &gvalue ); | |
1104 | g_value_unset( &gvalue ); | |
93763ad5 | 1105 | |
605c2c4a RR |
1106 | return true; |
1107 | } | |
1108 | ||
baa9ebc4 | 1109 | bool wxDataViewToggleRenderer::GetValue( wxVariant &value ) |
605c2c4a RR |
1110 | { |
1111 | GValue gvalue = { 0, }; | |
1112 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
1113 | g_object_get_property( G_OBJECT(m_renderer), "active", &gvalue ); | |
93763ad5 | 1114 | bool tmp = g_value_get_boolean( &gvalue ); |
605c2c4a | 1115 | g_value_unset( &gvalue ); |
93763ad5 | 1116 | |
605c2c4a RR |
1117 | value = tmp; |
1118 | ||
1119 | return true; | |
1120 | } | |
93763ad5 WS |
1121 | |
1122 | // --------------------------------------------------------- | |
baa9ebc4 | 1123 | // wxDataViewCustomRenderer |
93763ad5 | 1124 | // --------------------------------------------------------- |
e152afc3 RR |
1125 | |
1126 | class wxDataViewCtrlDC: public wxWindowDC | |
1127 | { | |
1128 | public: | |
1129 | wxDataViewCtrlDC( wxDataViewCtrl *window ) | |
1130 | { | |
1a367564 | 1131 | GtkWidget *widget = window->m_treeview; |
e152afc3 RR |
1132 | // Set later |
1133 | m_window = NULL; | |
4d496ecb | 1134 | |
e152afc3 RR |
1135 | m_context = window->GtkGetPangoDefaultContext(); |
1136 | m_layout = pango_layout_new( m_context ); | |
1137 | m_fontdesc = pango_font_description_copy( widget->style->font_desc ); | |
1138 | ||
1139 | m_cmap = gtk_widget_get_colormap( widget ? widget : window->m_widget ); | |
1140 | ||
4d496ecb RR |
1141 | // Set m_window later |
1142 | // SetUpDC(); | |
1143 | // m_owner = window; | |
e152afc3 RR |
1144 | } |
1145 | }; | |
1146 | ||
93763ad5 | 1147 | // --------------------------------------------------------- |
baa9ebc4 | 1148 | // wxDataViewCustomRenderer |
93763ad5 | 1149 | // --------------------------------------------------------- |
e152afc3 | 1150 | |
baa9ebc4 | 1151 | IMPLEMENT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer) |
e152afc3 | 1152 | |
baa9ebc4 | 1153 | wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype, |
ad63bf41 | 1154 | wxDataViewCellMode mode, bool no_init ) : |
baa9ebc4 | 1155 | wxDataViewRenderer( varianttype, mode ) |
e152afc3 RR |
1156 | { |
1157 | m_dc = NULL; | |
93763ad5 | 1158 | |
ad63bf41 RR |
1159 | if (no_init) |
1160 | m_renderer = NULL; | |
1161 | else | |
1162 | Init(); | |
1163 | } | |
1164 | ||
baa9ebc4 | 1165 | bool wxDataViewCustomRenderer::Init() |
ad63bf41 | 1166 | { |
e152afc3 RR |
1167 | GtkWxCellRenderer *renderer = (GtkWxCellRenderer *) gtk_wx_cell_renderer_new(); |
1168 | renderer->cell = this; | |
93763ad5 | 1169 | |
e152afc3 | 1170 | m_renderer = (void*) renderer; |
93763ad5 | 1171 | |
553f7d8f RR |
1172 | if (m_mode & wxDATAVIEW_CELL_ACTIVATABLE) |
1173 | { | |
1174 | GValue gvalue = { 0, }; | |
1175 | g_value_init( &gvalue, gtk_cell_renderer_mode_get_type() ); | |
1176 | g_value_set_enum( &gvalue, GTK_CELL_RENDERER_MODE_ACTIVATABLE ); | |
1177 | g_object_set_property( G_OBJECT(m_renderer), "mode", &gvalue ); | |
1178 | g_value_unset( &gvalue ); | |
1179 | } | |
93763ad5 | 1180 | |
ad63bf41 | 1181 | return true; |
e152afc3 RR |
1182 | } |
1183 | ||
baa9ebc4 | 1184 | wxDataViewCustomRenderer::~wxDataViewCustomRenderer() |
e152afc3 RR |
1185 | { |
1186 | if (m_dc) | |
1187 | delete m_dc; | |
1188 | } | |
1189 | ||
baa9ebc4 | 1190 | wxDC *wxDataViewCustomRenderer::GetDC() |
e152afc3 RR |
1191 | { |
1192 | if (m_dc == NULL) | |
4d496ecb RR |
1193 | { |
1194 | if (GetOwner() == NULL) | |
1195 | return NULL; | |
1196 | if (GetOwner()->GetOwner() == NULL) | |
1197 | return NULL; | |
e152afc3 | 1198 | m_dc = new wxDataViewCtrlDC( GetOwner()->GetOwner() ); |
4d496ecb | 1199 | } |
93763ad5 | 1200 | |
e152afc3 RR |
1201 | return m_dc; |
1202 | } | |
93763ad5 WS |
1203 | |
1204 | // --------------------------------------------------------- | |
baa9ebc4 | 1205 | // wxDataViewProgressRenderer |
93763ad5 | 1206 | // --------------------------------------------------------- |
ad63bf41 | 1207 | |
baa9ebc4 | 1208 | IMPLEMENT_CLASS(wxDataViewProgressRenderer, wxDataViewCustomRenderer) |
ad63bf41 | 1209 | |
baa9ebc4 | 1210 | wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString &label, |
ad63bf41 | 1211 | const wxString &varianttype, wxDataViewCellMode mode ) : |
baa9ebc4 | 1212 | wxDataViewCustomRenderer( varianttype, mode, true ) |
ad63bf41 RR |
1213 | { |
1214 | m_label = label; | |
1215 | m_value = 0; | |
93763ad5 | 1216 | |
ad63bf41 RR |
1217 | #ifdef __WXGTK26__ |
1218 | if (!gtk_check_version(2,6,0)) | |
1219 | { | |
1220 | m_renderer = (void*) gtk_cell_renderer_progress_new(); | |
93763ad5 | 1221 | |
ad63bf41 RR |
1222 | GValue gvalue = { 0, }; |
1223 | g_value_init( &gvalue, G_TYPE_STRING ); | |
1224 | g_value_set_boolean( &gvalue, wxGTK_CONV(m_label) ); | |
1225 | g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue ); | |
1226 | g_value_unset( &gvalue ); | |
1227 | } | |
1228 | else | |
1229 | #endif | |
1230 | { | |
1231 | // Use custom cell code | |
baa9ebc4 | 1232 | wxDataViewCustomRenderer::Init(); |
ad63bf41 RR |
1233 | } |
1234 | } | |
1235 | ||
baa9ebc4 | 1236 | wxDataViewProgressRenderer::~wxDataViewProgressRenderer() |
ad63bf41 RR |
1237 | { |
1238 | } | |
1239 | ||
baa9ebc4 | 1240 | bool wxDataViewProgressRenderer::SetValue( const wxVariant &value ) |
ad63bf41 RR |
1241 | { |
1242 | #ifdef __WXGTK26__ | |
1243 | if (!gtk_check_version(2,6,0)) | |
1244 | { | |
1245 | gint tmp = (int) value; | |
1246 | GValue gvalue = { 0, }; | |
1247 | g_value_init( &gvalue, G_TYPE_INT ); | |
1248 | g_value_set_boolean( &gvalue, tmp ); | |
1249 | g_object_set_property( G_OBJECT(m_renderer), "value", &gvalue ); | |
1250 | g_value_unset( &gvalue ); | |
1251 | } | |
1252 | else | |
1253 | #endif | |
1254 | { | |
1255 | m_value = (long) value; | |
93763ad5 | 1256 | |
ad63bf41 RR |
1257 | if (m_value < 0) m_value = 0; |
1258 | if (m_value > 100) m_value = 100; | |
1259 | } | |
93763ad5 | 1260 | |
ad63bf41 RR |
1261 | return true; |
1262 | } | |
93763ad5 | 1263 | |
baa9ebc4 | 1264 | bool wxDataViewProgressRenderer::Render( wxRect cell, wxDC *dc, int state ) |
ad63bf41 RR |
1265 | { |
1266 | double pct = (double)m_value / 100.0; | |
1267 | wxRect bar = cell; | |
1268 | bar.width = (int)(cell.width * pct); | |
1269 | dc->SetPen( *wxTRANSPARENT_PEN ); | |
1270 | dc->SetBrush( *wxBLUE_BRUSH ); | |
1271 | dc->DrawRectangle( bar ); | |
1272 | ||
1273 | dc->SetBrush( *wxTRANSPARENT_BRUSH ); | |
1274 | dc->SetPen( *wxBLACK_PEN ); | |
1275 | dc->DrawRectangle( cell ); | |
93763ad5 | 1276 | |
ad63bf41 RR |
1277 | return true; |
1278 | } | |
1279 | ||
baa9ebc4 | 1280 | wxSize wxDataViewProgressRenderer::GetSize() |
ad63bf41 RR |
1281 | { |
1282 | return wxSize(40,12); | |
1283 | } | |
93763ad5 WS |
1284 | |
1285 | // --------------------------------------------------------- | |
baa9ebc4 | 1286 | // wxDataViewDateRenderer |
93763ad5 | 1287 | // --------------------------------------------------------- |
4d496ecb | 1288 | |
baa9ebc4 | 1289 | class wxDataViewDateRendererPopupTransient: public wxPopupTransientWindow |
7ea3a0de | 1290 | { |
93763ad5 | 1291 | public: |
baa9ebc4 | 1292 | wxDataViewDateRendererPopupTransient( wxWindow* parent, wxDateTime *value, |
0a71f9e9 | 1293 | wxDataViewListModel *model, unsigned int col, unsigned int row ) : |
7ea3a0de RR |
1294 | wxPopupTransientWindow( parent, wxBORDER_SIMPLE ) |
1295 | { | |
1296 | m_model = model; | |
1297 | m_col = col; | |
1298 | m_row = row; | |
1299 | m_cal = new wxCalendarCtrl( this, -1, *value ); | |
1300 | wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL ); | |
1301 | sizer->Add( m_cal, 1, wxGROW ); | |
1302 | SetSizer( sizer ); | |
1303 | sizer->Fit( this ); | |
1304 | } | |
93763ad5 | 1305 | |
7ea3a0de RR |
1306 | virtual void OnDismiss() |
1307 | { | |
1308 | } | |
93763ad5 | 1309 | |
7ea3a0de | 1310 | void OnCalendar( wxCalendarEvent &event ); |
93763ad5 | 1311 | |
7ea3a0de | 1312 | wxCalendarCtrl *m_cal; |
93763ad5 | 1313 | wxDataViewListModel *m_model; |
0a71f9e9 RR |
1314 | unsigned int m_col; |
1315 | unsigned int m_row; | |
93763ad5 | 1316 | |
7ea3a0de RR |
1317 | private: |
1318 | DECLARE_EVENT_TABLE() | |
1319 | }; | |
1320 | ||
baa9ebc4 RR |
1321 | BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient,wxPopupTransientWindow) |
1322 | EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar ) | |
7ea3a0de RR |
1323 | END_EVENT_TABLE() |
1324 | ||
baa9ebc4 | 1325 | void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent &event ) |
7ea3a0de RR |
1326 | { |
1327 | wxDateTime date = event.GetDate(); | |
1328 | wxVariant value = date; | |
1329 | m_model->SetValue( value, m_col, m_row ); | |
1330 | m_model->ValueChanged( m_col, m_row ); | |
1331 | DismissAndNotify(); | |
1332 | } | |
1333 | ||
baa9ebc4 | 1334 | IMPLEMENT_CLASS(wxDataViewDateRenderer, wxDataViewCustomRenderer) |
4d496ecb | 1335 | |
baa9ebc4 | 1336 | wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString &varianttype, |
4d496ecb | 1337 | wxDataViewCellMode mode ) : |
baa9ebc4 | 1338 | wxDataViewCustomRenderer( varianttype, mode ) |
4d496ecb RR |
1339 | { |
1340 | } | |
93763ad5 | 1341 | |
baa9ebc4 | 1342 | bool wxDataViewDateRenderer::SetValue( const wxVariant &value ) |
4d496ecb RR |
1343 | { |
1344 | m_date = value.GetDateTime(); | |
93763ad5 | 1345 | |
4d496ecb RR |
1346 | return true; |
1347 | } | |
1348 | ||
baa9ebc4 | 1349 | bool wxDataViewDateRenderer::Render( wxRect cell, wxDC *dc, int state ) |
4d496ecb RR |
1350 | { |
1351 | dc->SetFont( GetOwner()->GetOwner()->GetFont() ); | |
1352 | wxString tmp = m_date.FormatDate(); | |
1353 | dc->DrawText( tmp, cell.x, cell.y ); | |
1354 | ||
1355 | return true; | |
1356 | } | |
1357 | ||
baa9ebc4 | 1358 | wxSize wxDataViewDateRenderer::GetSize() |
4d496ecb RR |
1359 | { |
1360 | wxDataViewCtrl* view = GetOwner()->GetOwner(); | |
1361 | wxString tmp = m_date.FormatDate(); | |
1362 | wxCoord x,y,d; | |
1363 | view->GetTextExtent( tmp, &x, &y, &d ); | |
1364 | return wxSize(x,y+d); | |
1365 | } | |
1366 | ||
baa9ebc4 | 1367 | bool wxDataViewDateRenderer::Activate( wxRect cell, wxDataViewListModel *model, unsigned int col, unsigned int row ) |
4d496ecb | 1368 | { |
3f3af7e7 RR |
1369 | wxVariant variant; |
1370 | model->GetValue( variant, col, row ); | |
7ea3a0de RR |
1371 | wxDateTime value = variant.GetDateTime(); |
1372 | ||
baa9ebc4 | 1373 | wxDataViewDateRendererPopupTransient *popup = new wxDataViewDateRendererPopupTransient( |
7ea3a0de RR |
1374 | GetOwner()->GetOwner()->GetParent(), &value, model, col, row ); |
1375 | wxPoint pos = wxGetMousePosition(); | |
1376 | popup->Move( pos ); | |
1377 | popup->Layout(); | |
1378 | popup->Popup( popup->m_cal ); | |
4d496ecb RR |
1379 | |
1380 | return true; | |
1381 | } | |
1382 | ||
93763ad5 | 1383 | // --------------------------------------------------------- |
605c2c4a | 1384 | // wxDataViewColumn |
93763ad5 | 1385 | // --------------------------------------------------------- |
7b4fde82 | 1386 | |
31fb32e1 RR |
1387 | |
1388 | static gboolean | |
1389 | gtk_dataview_header_button_press_callback( GtkWidget *widget, | |
1390 | GdkEventButton *gdk_event, | |
1391 | wxDataViewColumn *column ) | |
1392 | { | |
1393 | if (gdk_event->type != GDK_BUTTON_PRESS) | |
1394 | return TRUE; | |
1395 | ||
1396 | if (gdk_event->button == 1) | |
1397 | { | |
1398 | wxDataViewCtrl *dv = column->GetOwner(); | |
1399 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, dv->GetId() ); | |
1400 | event.SetDataViewColumn( column ); | |
1401 | event.SetModel( dv->GetModel() ); | |
1402 | dv->GetEventHandler()->ProcessEvent( event ); | |
1403 | } | |
1404 | ||
1405 | return TRUE; | |
1406 | } | |
1407 | ||
7b4fde82 RR |
1408 | extern "C" { |
1409 | static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column, | |
1410 | GtkCellRenderer *cell, | |
1411 | GtkTreeModel *model, | |
1412 | GtkTreeIter *iter, | |
1413 | gpointer data ); | |
1414 | } | |
1415 | ||
1416 | ||
1417 | static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column, | |
1418 | GtkCellRenderer *renderer, | |
1419 | GtkTreeModel *model, | |
1420 | GtkTreeIter *iter, | |
1421 | gpointer data ) | |
1422 | { | |
1423 | g_return_if_fail (GTK_IS_WX_LIST_STORE (model)); | |
1424 | GtkWxListStore *list_store = (GtkWxListStore *) model; | |
93763ad5 | 1425 | |
baa9ebc4 | 1426 | wxDataViewRenderer *cell = (wxDataViewRenderer*) data; |
a7f61f76 | 1427 | |
0a71f9e9 | 1428 | unsigned int model_row = (unsigned int) iter->user_data; |
93763ad5 | 1429 | |
3f3af7e7 RR |
1430 | wxVariant value; |
1431 | list_store->model->GetValue( value, cell->GetOwner()->GetModelColumn(), model_row ); | |
7b4fde82 RR |
1432 | |
1433 | if (value.GetType() != cell->GetVariantType()) | |
cbc9145c RR |
1434 | wxLogError( wxT("Wrong type, required: %s but: %s"), |
1435 | value.GetType().c_str(), | |
1436 | cell->GetVariantType().c_str() ); | |
93763ad5 | 1437 | |
7b4fde82 RR |
1438 | cell->SetValue( value ); |
1439 | } | |
1440 | ||
cbc9145c | 1441 | IMPLEMENT_CLASS(wxDataViewColumn, wxDataViewColumnBase) |
fa28826d | 1442 | |
baa9ebc4 | 1443 | wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewRenderer *cell, unsigned int model_column, |
008b5a66 RR |
1444 | int width, int flags ) : |
1445 | wxDataViewColumnBase( title, cell, model_column, width, flags ) | |
fa28826d | 1446 | { |
31fb32e1 RR |
1447 | m_isConnected = false; |
1448 | ||
6842a71a | 1449 | GtkCellRenderer *renderer = (GtkCellRenderer *) cell->GetGtkHandle(); |
93763ad5 | 1450 | |
6842a71a | 1451 | GtkTreeViewColumn *column = gtk_tree_view_column_new(); |
31fb32e1 RR |
1452 | m_column = (void*) column; |
1453 | ||
1454 | gtk_tree_view_column_set_clickable( column, true ); | |
1455 | ||
1456 | SetTitle( title ); | |
e4db172a | 1457 | |
008b5a66 RR |
1458 | if (flags & wxDATAVIEW_COL_RESIZABLE) |
1459 | gtk_tree_view_column_set_resizable( column, true ); | |
1460 | if (flags & wxDATAVIEW_COL_HIDDEN) | |
1461 | gtk_tree_view_column_set_visible( column, false ); | |
1462 | if (flags & wxDATAVIEW_COL_SORTABLE) | |
1463 | gtk_tree_view_column_set_sort_indicator( column, true ); | |
e4db172a | 1464 | |
008b5a66 RR |
1465 | if (width > 0) |
1466 | { | |
1467 | gtk_tree_view_column_set_fixed_width( column, width ); | |
1468 | gtk_tree_view_column_set_sizing( column, GTK_TREE_VIEW_COLUMN_FIXED ); | |
1469 | } | |
e4db172a | 1470 | |
008b5a66 | 1471 | gtk_tree_view_column_pack_end( column, renderer, FALSE ); |
93763ad5 WS |
1472 | |
1473 | gtk_tree_view_column_set_cell_data_func( column, renderer, | |
7b4fde82 | 1474 | wxGtkTreeCellDataFunc, (gpointer) cell, NULL ); |
93763ad5 | 1475 | |
fa28826d RR |
1476 | } |
1477 | ||
07a84e7b RR |
1478 | wxDataViewColumn::wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *cell, unsigned int model_column, |
1479 | int width, int flags ) : | |
1480 | wxDataViewColumnBase( bitmap, cell, model_column, width, flags ) | |
1481 | { | |
31fb32e1 RR |
1482 | m_isConnected = false; |
1483 | ||
07a84e7b RR |
1484 | GtkCellRenderer *renderer = (GtkCellRenderer *) cell->GetGtkHandle(); |
1485 | ||
1486 | GtkTreeViewColumn *column = gtk_tree_view_column_new(); | |
1487 | m_column = (void*) column; | |
1488 | ||
1489 | SetBitmap( bitmap ); | |
1490 | ||
1491 | if (flags & wxDATAVIEW_COL_RESIZABLE) | |
1492 | gtk_tree_view_column_set_resizable( column, true ); | |
1493 | if (flags & wxDATAVIEW_COL_HIDDEN) | |
1494 | gtk_tree_view_column_set_visible( column, false ); | |
1495 | if (flags & wxDATAVIEW_COL_SORTABLE) | |
1496 | gtk_tree_view_column_set_sort_indicator( column, true ); | |
1497 | ||
1498 | if (width > 0) | |
1499 | { | |
1500 | gtk_tree_view_column_set_fixed_width( column, width ); | |
1501 | gtk_tree_view_column_set_sizing( column, GTK_TREE_VIEW_COLUMN_FIXED ); | |
1502 | } | |
1503 | ||
1504 | gtk_tree_view_column_pack_end( column, renderer, FALSE ); | |
1505 | ||
1506 | gtk_tree_view_column_set_cell_data_func( column, renderer, | |
1507 | wxGtkTreeCellDataFunc, (gpointer) cell, NULL ); | |
1508 | } | |
1509 | ||
fa28826d RR |
1510 | wxDataViewColumn::~wxDataViewColumn() |
1511 | { | |
1512 | } | |
1513 | ||
31fb32e1 RR |
1514 | void wxDataViewColumn::OnInternalIdle() |
1515 | { | |
1516 | if (m_isConnected) | |
1517 | return; | |
1518 | ||
1519 | if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview)) | |
1520 | { | |
1521 | GtkTreeViewColumn *column = (GtkTreeViewColumn *)m_column; | |
1522 | if (column->button) | |
1523 | { | |
1524 | g_signal_connect(column->button, "button_press_event", | |
1525 | G_CALLBACK (gtk_dataview_header_button_press_callback), this); | |
1526 | ||
1527 | m_isConnected = true; | |
1528 | } | |
1529 | } | |
1530 | } | |
1531 | ||
fa28826d RR |
1532 | void wxDataViewColumn::SetTitle( const wxString &title ) |
1533 | { | |
1534 | wxDataViewColumnBase::SetTitle( title ); | |
93763ad5 | 1535 | |
fa28826d | 1536 | GtkTreeViewColumn *column = (GtkTreeViewColumn *)m_column; |
07a84e7b | 1537 | |
31fb32e1 RR |
1538 | if (m_isConnected) |
1539 | { | |
1540 | // disconnect before column->button gets recreated | |
1541 | g_signal_handlers_disconnect_by_func( column->button, | |
1542 | (void*) gtk_dataview_header_button_press_callback, this); | |
1543 | ||
1544 | m_isConnected = false; | |
1545 | } | |
1546 | ||
1547 | gtk_tree_view_column_set_title( column, wxGTK_CONV(title) ); | |
1548 | ||
07a84e7b RR |
1549 | gtk_tree_view_column_set_widget( column, NULL ); |
1550 | } | |
1551 | ||
1552 | void wxDataViewColumn::SetBitmap( const wxBitmap &bitmap ) | |
1553 | { | |
1554 | wxDataViewColumnBase::SetBitmap( bitmap ); | |
1555 | ||
1556 | GtkTreeViewColumn *column = (GtkTreeViewColumn *)m_column; | |
1557 | if (bitmap.Ok()) | |
1558 | { | |
1559 | GtkImage *gtk_image = GTK_IMAGE( gtk_image_new() ); | |
1560 | ||
1561 | GdkBitmap *mask = (GdkBitmap *) NULL; | |
1562 | if (bitmap.GetMask()) | |
1563 | mask = bitmap.GetMask()->GetBitmap(); | |
1564 | ||
1565 | if (bitmap.HasPixbuf()) | |
1566 | { | |
1567 | gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image), | |
1568 | bitmap.GetPixbuf()); | |
1569 | } | |
1570 | else | |
1571 | { | |
1572 | gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image), | |
1573 | bitmap.GetPixmap(), mask); | |
1574 | } | |
1575 | gtk_widget_show( GTK_WIDGET(gtk_image) ); | |
1576 | ||
1577 | gtk_tree_view_column_set_widget( column, GTK_WIDGET(gtk_image) ); | |
1578 | } | |
1579 | else | |
1580 | { | |
1581 | gtk_tree_view_column_set_widget( column, NULL ); | |
1582 | } | |
fa28826d RR |
1583 | } |
1584 | ||
47cef10f RR |
1585 | void wxDataViewColumn::SetAlignment( wxAlignment align ) |
1586 | { | |
1587 | GtkTreeViewColumn *column = (GtkTreeViewColumn *)m_column; | |
1588 | ||
1589 | gfloat xalign = 0.0; | |
1590 | if (align == wxALIGN_RIGHT) | |
1591 | xalign = 1.0; | |
1592 | if (align == wxALIGN_CENTER) | |
1593 | xalign = 0.5; | |
1594 | ||
1595 | gtk_tree_view_column_set_alignment( column, xalign ); | |
1596 | } | |
1597 | ||
31fb32e1 RR |
1598 | void wxDataViewColumn::SetSortable( bool sortable ) |
1599 | { | |
1600 | GtkTreeViewColumn *column = (GtkTreeViewColumn *)m_column; | |
1601 | gtk_tree_view_column_set_sort_indicator( column, sortable ); | |
1602 | } | |
1603 | ||
1604 | bool wxDataViewColumn::GetSortable() | |
1605 | { | |
1606 | GtkTreeViewColumn *column = (GtkTreeViewColumn *)m_column; | |
1607 | return gtk_tree_view_column_get_sort_indicator( column ); | |
1608 | } | |
1609 | ||
47cef10f RR |
1610 | void wxDataViewColumn::SetSortOrder( bool ascending ) |
1611 | { | |
1612 | GtkTreeViewColumn *column = (GtkTreeViewColumn *)m_column; | |
1613 | ||
1614 | if (ascending) | |
1615 | gtk_tree_view_column_set_sort_order( column, GTK_SORT_ASCENDING ); | |
1616 | else | |
1617 | gtk_tree_view_column_set_sort_order( column, GTK_SORT_DESCENDING ); | |
1618 | } | |
1619 | ||
31fb32e1 RR |
1620 | bool wxDataViewColumn::IsSortOrderAscending() |
1621 | { | |
1622 | GtkTreeViewColumn *column = (GtkTreeViewColumn *)m_column; | |
1623 | ||
1624 | return (gtk_tree_view_column_get_sort_order( column ) != GTK_SORT_DESCENDING); | |
1625 | } | |
1626 | ||
533544f2 RR |
1627 | int wxDataViewColumn::GetWidth() |
1628 | { | |
1629 | return gtk_tree_view_column_get_width( (GtkTreeViewColumn *)m_column ); | |
1630 | } | |
1631 | ||
1632 | void wxDataViewColumn::SetFixedWidth( int width ) | |
1633 | { | |
1634 | gtk_tree_view_column_set_fixed_width( (GtkTreeViewColumn *)m_column, width ); | |
1635 | } | |
1636 | ||
1637 | int wxDataViewColumn::GetFixedWidth() | |
1638 | { | |
1639 | return gtk_tree_view_column_get_fixed_width( (GtkTreeViewColumn *)m_column ); | |
1640 | } | |
1641 | ||
eb7f97f8 RR |
1642 | //----------------------------------------------------------------------------- |
1643 | // wxDataViewCtrl signal callbacks | |
1644 | //----------------------------------------------------------------------------- | |
1645 | ||
1646 | static void | |
1647 | wxdataview_selection_changed_callback( GtkTreeSelection* selection, wxDataViewCtrl *dv ) | |
1648 | { | |
1649 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ROW_SELECTED, dv->GetId() ); | |
6ee2c58b | 1650 | event.SetRow( dv->GetSelection() ); |
eb7f97f8 RR |
1651 | event.SetModel( dv->GetModel() ); |
1652 | dv->GetEventHandler()->ProcessEvent( event ); | |
1653 | } | |
1654 | ||
f828871d RR |
1655 | static void |
1656 | wxdataview_row_activated_callback( GtkTreeView* treeview, GtkTreePath *path, | |
1657 | GtkTreeViewColumn *column, wxDataViewCtrl *dv ) | |
1658 | { | |
1659 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ROW_ACTIVATED, dv->GetId() ); | |
1660 | unsigned int row = (unsigned int)gtk_tree_path_get_indices (path)[0]; | |
1661 | event.SetRow( row ); | |
1662 | event.SetModel( dv->GetModel() ); | |
1663 | dv->GetEventHandler()->ProcessEvent( event ); | |
1664 | } | |
1665 | ||
790b137e RR |
1666 | //----------------------------------------------------------------------------- |
1667 | // wxDataViewCtrl | |
1668 | //----------------------------------------------------------------------------- | |
1669 | ||
239eaa41 RR |
1670 | IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase) |
1671 | ||
1672 | wxDataViewCtrl::~wxDataViewCtrl() | |
1673 | { | |
8f850e28 RR |
1674 | if (m_notifier) |
1675 | GetModel()->RemoveNotifier( m_notifier ); | |
239eaa41 RR |
1676 | } |
1677 | ||
1678 | void wxDataViewCtrl::Init() | |
1679 | { | |
8f850e28 | 1680 | m_notifier = NULL; |
239eaa41 RR |
1681 | } |
1682 | ||
1683 | bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, | |
93763ad5 | 1684 | const wxPoint& pos, const wxSize& size, |
239eaa41 RR |
1685 | long style, const wxValidator& validator ) |
1686 | { | |
1687 | Init(); | |
93763ad5 WS |
1688 | |
1689 | m_needParent = true; | |
1690 | m_acceptsFocus = true; | |
239eaa41 RR |
1691 | |
1692 | if (!PreCreation( parent, pos, size ) || | |
1693 | !CreateBase( parent, id, pos, size, style, validator )) | |
1694 | { | |
1695 | wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") ); | |
93763ad5 | 1696 | return false; |
239eaa41 | 1697 | } |
1a367564 RR |
1698 | |
1699 | m_widget = gtk_scrolled_window_new (NULL, NULL); | |
6493aaca VZ |
1700 | |
1701 | GtkScrolledWindowSetBorder(m_widget, style); | |
1a367564 RR |
1702 | |
1703 | m_treeview = gtk_tree_view_new(); | |
1704 | gtk_container_add (GTK_CONTAINER (m_widget), m_treeview); | |
ed4b0fdc | 1705 | |
daebb44c RR |
1706 | if (style & wxDV_MULTIPLE) |
1707 | { | |
1708 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); | |
1709 | gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE ); | |
1710 | } | |
93763ad5 | 1711 | |
1a367564 RR |
1712 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget), |
1713 | GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
1714 | gtk_widget_show (m_treeview); | |
93763ad5 | 1715 | |
239eaa41 RR |
1716 | m_parent->DoAddChild( this ); |
1717 | ||
eb7f97f8 RR |
1718 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); |
1719 | g_signal_connect_after (selection, "changed", | |
1720 | G_CALLBACK (wxdataview_selection_changed_callback), this); | |
f828871d RR |
1721 | g_signal_connect_after (m_treeview, "row_activated", |
1722 | G_CALLBACK (wxdataview_row_activated_callback), this); | |
eb7f97f8 | 1723 | |
239eaa41 RR |
1724 | PostCreation(size); |
1725 | ||
1726 | return true; | |
1727 | } | |
1728 | ||
31fb32e1 RR |
1729 | void wxDataViewCtrl::OnInternalIdle() |
1730 | { | |
1731 | wxWindow::OnInternalIdle(); | |
1732 | ||
1733 | unsigned int cols = GetNumberOfColumns(); | |
1734 | unsigned int i; | |
1735 | for (i = 0; i < cols; i++) | |
1736 | { | |
1737 | wxDataViewColumn *col = GetColumn( i ); | |
1738 | col->OnInternalIdle(); | |
1739 | } | |
1740 | } | |
1741 | ||
6e2e590f | 1742 | bool wxDataViewCtrl::AssociateModel( wxDataViewListModel *model ) |
239eaa41 RR |
1743 | { |
1744 | if (!wxDataViewCtrlBase::AssociateModel( model )) | |
1745 | return false; | |
1746 | ||
6e2e590f RR |
1747 | GtkWxListStore *gtk_store = wxgtk_list_store_new(); |
1748 | gtk_store->model = model; | |
1749 | ||
8f850e28 | 1750 | m_notifier = new wxGtkDataViewListModelNotifier( gtk_store, model ); |
6e2e590f | 1751 | |
93763ad5 | 1752 | model->AddNotifier( m_notifier ); |
1557c77b | 1753 | |
1a367564 RR |
1754 | gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview), GTK_TREE_MODEL(gtk_store) ); |
1755 | g_object_unref( gtk_store ); | |
93763ad5 | 1756 | |
239eaa41 RR |
1757 | return true; |
1758 | } | |
790b137e | 1759 | |
fa28826d RR |
1760 | bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col ) |
1761 | { | |
1762 | if (!wxDataViewCtrlBase::AppendColumn(col)) | |
1763 | return false; | |
93763ad5 | 1764 | |
fa28826d RR |
1765 | GtkTreeViewColumn *column = (GtkTreeViewColumn *)col->GetGtkHandle(); |
1766 | ||
1a367564 | 1767 | gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview), column ); |
fa28826d RR |
1768 | |
1769 | return true; | |
1770 | } | |
1771 | ||
6ff7eee7 RR |
1772 | void wxDataViewCtrl::SetSelection( int row ) |
1773 | { | |
fc211fe5 RR |
1774 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); |
1775 | ||
1776 | if (row < 0) | |
1777 | { | |
1778 | gtk_tree_selection_unselect_all( selection ); | |
1779 | } | |
1780 | else | |
1781 | { | |
1782 | GtkTreePath *path = gtk_tree_path_new (); | |
1783 | gtk_tree_path_append_index( path, row ); | |
1784 | ||
1785 | gtk_tree_selection_select_path( selection, path ); | |
1786 | ||
1787 | gtk_tree_path_free( path ); | |
1788 | } | |
1789 | } | |
1790 | ||
1791 | void wxDataViewCtrl::Unselect( unsigned int row ) | |
1792 | { | |
1793 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); | |
1794 | ||
1795 | GtkTreePath *path = gtk_tree_path_new (); | |
1796 | gtk_tree_path_append_index( path, row ); | |
1797 | ||
1798 | gtk_tree_selection_unselect_path( selection, path ); | |
1799 | ||
1800 | gtk_tree_path_free( path ); | |
6ff7eee7 RR |
1801 | } |
1802 | ||
1803 | void wxDataViewCtrl::SetSelectionRange( unsigned int from, unsigned int to ) | |
1804 | { | |
1805 | } | |
1806 | ||
1807 | void wxDataViewCtrl::SetSelections( const wxArrayInt& aSelections) | |
1808 | { | |
1809 | } | |
1810 | ||
1811 | bool wxDataViewCtrl::IsSelected( unsigned int row ) const | |
1812 | { | |
fc211fe5 RR |
1813 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); |
1814 | ||
1815 | GtkTreePath *path = gtk_tree_path_new (); | |
1816 | gtk_tree_path_append_index( path, row ); | |
1817 | ||
1818 | gboolean ret = gtk_tree_selection_path_is_selected( selection, path ); | |
1819 | ||
1820 | gtk_tree_path_free( path ); | |
1821 | ||
1822 | return ret; | |
6ff7eee7 RR |
1823 | } |
1824 | ||
1825 | int wxDataViewCtrl::GetSelection() const | |
1826 | { | |
6ee2c58b RR |
1827 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); |
1828 | if (HasFlag(wxDV_MULTIPLE)) | |
1829 | { | |
1830 | GtkTreeModel *model; | |
1831 | GList *list = gtk_tree_selection_get_selected_rows( selection, &model ); | |
1832 | ||
1833 | // do something | |
1834 | if (list) | |
1835 | { | |
1836 | // list = g_list_nth( list, 0 ); should be a noop | |
1837 | GtkTreePath *path = (GtkTreePath*) list->data; | |
1838 | ||
1839 | unsigned int row = (unsigned int)gtk_tree_path_get_indices (path)[0]; | |
1840 | ||
1841 | // delete list | |
1842 | g_list_foreach( list, (GFunc) gtk_tree_path_free, NULL ); | |
1843 | g_list_free( list ); | |
1844 | ||
1845 | return (int) row; | |
1846 | } | |
1847 | } | |
1848 | else | |
1849 | { | |
1850 | ||
1851 | GtkTreeModel *model; | |
1852 | GtkTreeIter iter; | |
1853 | gboolean has_selection = gtk_tree_selection_get_selected( selection, &model, &iter ); | |
1854 | if (has_selection) | |
1855 | { | |
1856 | unsigned int row = (wxUIntPtr) iter.user_data; | |
1857 | return (int) row; | |
1858 | } | |
1859 | } | |
1860 | ||
6ff7eee7 RR |
1861 | return -1; |
1862 | } | |
1863 | ||
1864 | int wxDataViewCtrl::GetSelections(wxArrayInt& aSelections) const | |
1865 | { | |
6ee2c58b RR |
1866 | aSelections.Clear(); |
1867 | ||
1868 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); | |
1869 | if (HasFlag(wxDV_MULTIPLE)) | |
1870 | { | |
1871 | GtkTreeModel *model; | |
1872 | GList *list = gtk_tree_selection_get_selected_rows( selection, &model ); | |
1873 | ||
1874 | int count = 0; | |
1875 | while (list) | |
1876 | { | |
1877 | ||
1878 | // list = g_list_nth( list, 0 ); should be a noop | |
1879 | GtkTreePath *path = (GtkTreePath*) list->data; | |
1880 | ||
1881 | unsigned int row = (unsigned int)gtk_tree_path_get_indices (path)[0]; | |
1882 | ||
1883 | aSelections.Add( (int) row ); | |
1884 | ||
1885 | list = g_list_next( list ); | |
1886 | } | |
1887 | ||
1888 | // delete list | |
1889 | g_list_foreach( list, (GFunc) gtk_tree_path_free, NULL ); | |
1890 | g_list_free( list ); | |
1891 | ||
1892 | return count; | |
1893 | } | |
1894 | else | |
1895 | { | |
1896 | GtkTreeModel *model; | |
1897 | GtkTreeIter iter; | |
1898 | gboolean has_selection = gtk_tree_selection_get_selected( selection, &model, &iter ); | |
1899 | if (has_selection) | |
1900 | { | |
1901 | unsigned int row = (wxUIntPtr) iter.user_data; | |
1902 | aSelections.Add( (int) row ); | |
1903 | return 1; | |
1904 | } | |
1905 | } | |
1906 | ||
6ff7eee7 RR |
1907 | return 0; |
1908 | } | |
1909 | ||
1910 | ||
93763ad5 | 1911 | #endif |
4ed7af08 | 1912 | // !wxUSE_GENERICDATAVIEWCTRL |
790b137e | 1913 | |
93763ad5 | 1914 | #endif |
4ed7af08 | 1915 | // wxUSE_DATAVIEWCTRL |