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