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