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