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