]>
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 | 35 | #include <gtk/gtktreemodel.h> |
773cca48 | 36 | #include <gtk/gtktreesortable.h> |
1557c77b | 37 | #include <gtk/gtktreednd.h> |
790b137e | 38 | |
4d496ecb RR |
39 | #include <gdk/gdkkeysyms.h> |
40 | ||
790b137e RR |
41 | //----------------------------------------------------------------------------- |
42 | // classes | |
43 | //----------------------------------------------------------------------------- | |
44 | ||
3b6280be RR |
45 | //----------------------------------------------------------------------------- |
46 | // wxGtkTreeModelNode | |
47 | //----------------------------------------------------------------------------- | |
48 | ||
49 | class wxGtkTreeModelNode; | |
50 | WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode*, wxGtkTreeModelNodes ); | |
51 | ||
52 | class wxGtkTreeModelNode | |
53 | { | |
54 | public: | |
d5025dc0 | 55 | wxGtkTreeModelNode( wxGtkTreeModelNode* parent, const wxDataViewItem &item ) |
3b6280be RR |
56 | { |
57 | m_parent = parent; | |
d5025dc0 | 58 | m_item = item; |
3b6280be RR |
59 | } |
60 | ||
61 | ~wxGtkTreeModelNode() | |
62 | { | |
63 | size_t count = m_children.GetCount(); | |
64 | size_t i; | |
65 | for (i = 0; i < count; i++) | |
66 | { | |
67 | wxGtkTreeModelNode *child = m_children[i]; | |
68 | delete child; | |
69 | } | |
70 | } | |
71 | ||
72 | wxGtkTreeModelNode* GetParent() | |
73 | { return m_parent; } | |
74 | wxGtkTreeModelNodes &GetChildren() | |
75 | { return m_children; } | |
76 | wxGtkTreeModelNode* GetNthChild( unsigned int n ) | |
77 | { return m_children.Item( n ); } | |
78 | void Insert( wxGtkTreeModelNode* child, unsigned int n) | |
79 | { m_children.Insert( child, n); } | |
80 | void Append( wxGtkTreeModelNode* child ) | |
81 | { m_children.Add( child ); } | |
82 | ||
83 | unsigned int GetChildCount() { return m_children.GetCount(); } | |
84 | ||
85 | wxDataViewItem &GetItem() { return m_item; } | |
3b6280be RR |
86 | |
87 | bool HasChildren() { return m_hasChildren; } | |
88 | void SetHasChildren( bool has ) { m_hasChildren = has; } | |
89 | ||
90 | private: | |
91 | wxGtkTreeModelNode *m_parent; | |
92 | wxGtkTreeModelNodes m_children; | |
93 | wxDataViewItem m_item; | |
94 | bool m_hasChildren; | |
95 | }; | |
96 | ||
97 | ||
98 | extern "C" { | |
99 | typedef struct _GtkWxTreeModel GtkWxTreeModel; | |
100 | } | |
101 | ||
102 | class wxGtkTreeModel | |
103 | { | |
104 | public: | |
d5025dc0 | 105 | wxGtkTreeModel( wxDataViewModel *wx_model, GtkWxTreeModel *owner ); |
3b6280be RR |
106 | ~wxGtkTreeModel(); |
107 | ||
108 | gboolean get_iter( GtkTreeIter *iter, GtkTreePath *path ); | |
109 | GtkTreePath *get_path( GtkTreeIter *iter); | |
110 | gboolean iter_next( GtkTreeIter *iter ); | |
111 | gboolean iter_children( GtkTreeIter *iter, GtkTreeIter *parent); | |
112 | gboolean iter_has_child( GtkTreeIter *iter ); | |
113 | gint iter_n_children( GtkTreeIter *iter ); | |
114 | gboolean iter_nth_child( GtkTreeIter *iter, GtkTreeIter *parent, gint n ); | |
115 | gboolean iter_parent( GtkTreeIter *iter, GtkTreeIter *child ); | |
116 | ||
d5025dc0 RR |
117 | wxDataViewModel* GetDataViewModel() { return m_wx_model; } |
118 | GtkWxTreeModel* GetOwner() { return m_owner; } | |
119 | ||
3b6280be RR |
120 | protected: |
121 | void InitTree(); | |
122 | wxGtkTreeModelNode *FindNode( GtkTreeIter *iter ); | |
d5025dc0 | 123 | void BuildBranch( wxGtkTreeModelNode *branch ); |
3b6280be RR |
124 | |
125 | private: | |
126 | wxGtkTreeModelNode *m_root; | |
127 | wxDataViewModel *m_wx_model; | |
d5025dc0 | 128 | GtkWxTreeModel *m_owner; |
3b6280be | 129 | }; |
790b137e | 130 | |
790b137e RR |
131 | //----------------------------------------------------------------------------- |
132 | // data | |
133 | //----------------------------------------------------------------------------- | |
134 | ||
135 | extern bool g_blockEventsOnDrag; | |
136 | ||
137 | //----------------------------------------------------------------------------- | |
e0062c04 | 138 | // define new GTK+ class wxGtkTreeModel |
790b137e RR |
139 | //----------------------------------------------------------------------------- |
140 | ||
141 | extern "C" { | |
142 | ||
e0062c04 RR |
143 | #define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ()) |
144 | #define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel)) | |
145 | #define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass)) | |
146 | #define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL)) | |
147 | #define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL)) | |
148 | #define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass)) | |
790b137e | 149 | |
e0062c04 | 150 | GType gtk_wx_tree_model_get_type (void); |
790b137e | 151 | |
e0062c04 | 152 | typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass; |
790b137e | 153 | |
e0062c04 | 154 | struct _GtkWxTreeModel |
790b137e RR |
155 | { |
156 | GObject parent; | |
157 | ||
158 | /*< private >*/ | |
159 | gint stamp; | |
d5025dc0 | 160 | wxGtkTreeModel *model; |
773cca48 RR |
161 | |
162 | gint sort_column_id; | |
163 | GtkSortType order; | |
790b137e RR |
164 | }; |
165 | ||
e0062c04 | 166 | struct _GtkWxTreeModelClass |
790b137e | 167 | { |
e152afc3 | 168 | GObjectClass list_parent_class; |
790b137e RR |
169 | }; |
170 | ||
e0062c04 | 171 | static GtkWxTreeModel *wxgtk_tree_model_new (void); |
773cca48 RR |
172 | static void wxgtk_tree_model_init (GtkWxTreeModel *tree_model); |
173 | static void wxgtk_tree_model_class_init (GtkWxTreeModelClass *klass); | |
174 | static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface *iface); | |
175 | static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface *iface); | |
e0062c04 RR |
176 | static void wxgtk_tree_model_finalize (GObject *object); |
177 | static GtkTreeModelFlags wxgtk_tree_model_get_flags (GtkTreeModel *tree_model); | |
178 | static gint wxgtk_tree_model_get_n_columns (GtkTreeModel *tree_model); | |
179 | static GType wxgtk_tree_model_get_column_type (GtkTreeModel *tree_model, | |
93763ad5 | 180 | gint index); |
e0062c04 | 181 | static gboolean wxgtk_tree_model_get_iter (GtkTreeModel *tree_model, |
93763ad5 WS |
182 | GtkTreeIter *iter, |
183 | GtkTreePath *path); | |
e0062c04 | 184 | static GtkTreePath *wxgtk_tree_model_get_path (GtkTreeModel *tree_model, |
93763ad5 | 185 | GtkTreeIter *iter); |
e0062c04 | 186 | static void wxgtk_tree_model_get_value (GtkTreeModel *tree_model, |
93763ad5 WS |
187 | GtkTreeIter *iter, |
188 | gint column, | |
189 | GValue *value); | |
e0062c04 | 190 | static gboolean wxgtk_tree_model_iter_next (GtkTreeModel *tree_model, |
93763ad5 | 191 | GtkTreeIter *iter); |
e0062c04 | 192 | static gboolean wxgtk_tree_model_iter_children (GtkTreeModel *tree_model, |
93763ad5 WS |
193 | GtkTreeIter *iter, |
194 | GtkTreeIter *parent); | |
e0062c04 | 195 | static gboolean wxgtk_tree_model_iter_has_child (GtkTreeModel *tree_model, |
93763ad5 | 196 | GtkTreeIter *iter); |
e0062c04 | 197 | static gint wxgtk_tree_model_iter_n_children (GtkTreeModel *tree_model, |
93763ad5 | 198 | GtkTreeIter *iter); |
e0062c04 | 199 | static gboolean wxgtk_tree_model_iter_nth_child (GtkTreeModel *tree_model, |
93763ad5 WS |
200 | GtkTreeIter *iter, |
201 | GtkTreeIter *parent, | |
202 | gint n); | |
e0062c04 | 203 | static gboolean wxgtk_tree_model_iter_parent (GtkTreeModel *tree_model, |
93763ad5 WS |
204 | GtkTreeIter *iter, |
205 | GtkTreeIter *child); | |
790b137e | 206 | |
773cca48 RR |
207 | /* sortable */ |
208 | static gboolean wxgtk_tree_model_get_sort_column_id (GtkTreeSortable *sortable, | |
209 | gint *sort_column_id, | |
210 | GtkSortType *order); | |
211 | static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable *sortable, | |
212 | gint sort_column_id, | |
213 | GtkSortType order); | |
214 | static void wxgtk_tree_model_set_sort_func (GtkTreeSortable *sortable, | |
215 | gint sort_column_id, | |
216 | GtkTreeIterCompareFunc func, | |
217 | gpointer data, | |
218 | GtkDestroyNotify destroy); | |
219 | static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable *sortable, | |
220 | GtkTreeIterCompareFunc func, | |
221 | gpointer data, | |
222 | GtkDestroyNotify destroy); | |
223 | static gboolean wxgtk_tree_model_has_default_sort_func (GtkTreeSortable *sortable); | |
224 | ||
225 | ||
226 | ||
e152afc3 | 227 | static GObjectClass *list_parent_class = NULL; |
790b137e RR |
228 | |
229 | GType | |
e0062c04 | 230 | gtk_wx_tree_model_get_type (void) |
790b137e | 231 | { |
e0062c04 | 232 | static GType tree_model_type = 0; |
790b137e | 233 | |
e0062c04 | 234 | if (!tree_model_type) |
790b137e | 235 | { |
e0062c04 | 236 | const GTypeInfo tree_model_info = |
93763ad5 | 237 | { |
e0062c04 | 238 | sizeof (GtkWxTreeModelClass), |
93763ad5 WS |
239 | NULL, /* base_init */ |
240 | NULL, /* base_finalize */ | |
e0062c04 | 241 | (GClassInitFunc) wxgtk_tree_model_class_init, |
93763ad5 WS |
242 | NULL, /* class_finalize */ |
243 | NULL, /* class_data */ | |
e0062c04 | 244 | sizeof (GtkWxTreeModel), |
93763ad5 | 245 | 0, |
e0062c04 | 246 | (GInstanceInitFunc) wxgtk_tree_model_init, |
93763ad5 | 247 | }; |
790b137e | 248 | |
773cca48 RR |
249 | static const GInterfaceInfo tree_model_iface_info = |
250 | { | |
251 | (GInterfaceInitFunc) wxgtk_tree_model_tree_model_init, | |
252 | NULL, | |
253 | NULL | |
254 | }; | |
255 | ||
256 | static const GInterfaceInfo sortable_iface_info = | |
257 | { | |
258 | (GInterfaceInitFunc) wxgtk_tree_model_sortable_init, | |
259 | NULL, | |
260 | NULL | |
261 | }; | |
790b137e | 262 | |
773cca48 | 263 | tree_model_type = g_type_register_static (G_TYPE_OBJECT, "GtkWxTreeModel", |
e0062c04 | 264 | &tree_model_info, (GTypeFlags)0 ); |
790b137e | 265 | |
773cca48 RR |
266 | g_type_add_interface_static (tree_model_type, |
267 | GTK_TYPE_TREE_MODEL, | |
268 | &tree_model_iface_info); | |
269 | g_type_add_interface_static (tree_model_type, | |
270 | GTK_TYPE_TREE_SORTABLE, | |
271 | &sortable_iface_info); | |
790b137e RR |
272 | } |
273 | ||
773cca48 | 274 | return tree_model_type; |
790b137e RR |
275 | } |
276 | ||
e0062c04 RR |
277 | static GtkWxTreeModel * |
278 | wxgtk_tree_model_new(void) | |
1557c77b | 279 | { |
e0062c04 | 280 | GtkWxTreeModel *retval = (GtkWxTreeModel *) g_object_new (GTK_TYPE_WX_TREE_MODEL, NULL); |
e152afc3 | 281 | return retval; |
1557c77b RR |
282 | } |
283 | ||
790b137e | 284 | static void |
e0062c04 | 285 | wxgtk_tree_model_class_init (GtkWxTreeModelClass *klass) |
790b137e | 286 | { |
e152afc3 RR |
287 | list_parent_class = (GObjectClass*) g_type_class_peek_parent (klass); |
288 | GObjectClass *object_class = (GObjectClass*) klass; | |
e0062c04 | 289 | object_class->finalize = wxgtk_tree_model_finalize; |
790b137e RR |
290 | } |
291 | ||
292 | static void | |
e0062c04 RR |
293 | wxgtk_tree_model_tree_model_init (GtkTreeModelIface *iface) |
294 | { | |
295 | iface->get_flags = wxgtk_tree_model_get_flags; | |
296 | iface->get_n_columns = wxgtk_tree_model_get_n_columns; | |
297 | iface->get_column_type = wxgtk_tree_model_get_column_type; | |
298 | iface->get_iter = wxgtk_tree_model_get_iter; | |
299 | iface->get_path = wxgtk_tree_model_get_path; | |
300 | iface->get_value = wxgtk_tree_model_get_value; | |
301 | iface->iter_next = wxgtk_tree_model_iter_next; | |
302 | iface->iter_children = wxgtk_tree_model_iter_children; | |
303 | iface->iter_has_child = wxgtk_tree_model_iter_has_child; | |
304 | iface->iter_n_children = wxgtk_tree_model_iter_n_children; | |
305 | iface->iter_nth_child = wxgtk_tree_model_iter_nth_child; | |
306 | iface->iter_parent = wxgtk_tree_model_iter_parent; | |
790b137e RR |
307 | } |
308 | ||
773cca48 RR |
309 | static void |
310 | wxgtk_tree_model_sortable_init (GtkTreeSortableIface *iface) | |
311 | { | |
94b1f7bc RR |
312 | iface->get_sort_column_id = wxgtk_tree_model_get_sort_column_id; |
313 | iface->set_sort_column_id = wxgtk_tree_model_set_sort_column_id; | |
314 | iface->set_sort_func = wxgtk_tree_model_set_sort_func; | |
315 | iface->set_default_sort_func = wxgtk_tree_model_set_default_sort_func; | |
316 | iface->has_default_sort_func = wxgtk_tree_model_has_default_sort_func; | |
773cca48 RR |
317 | } |
318 | ||
790b137e | 319 | static void |
e0062c04 | 320 | wxgtk_tree_model_init (GtkWxTreeModel *tree_model) |
790b137e | 321 | { |
e0062c04 RR |
322 | tree_model->model = NULL; |
323 | tree_model->stamp = g_random_int(); | |
773cca48 RR |
324 | tree_model->sort_column_id = -2; |
325 | tree_model->order = GTK_SORT_ASCENDING; | |
790b137e RR |
326 | } |
327 | ||
328 | static void | |
e0062c04 | 329 | wxgtk_tree_model_finalize (GObject *object) |
790b137e | 330 | { |
d5025dc0 | 331 | GtkWxTreeModel *tree_model = GTK_WX_TREE_MODEL(object); |
790b137e RR |
332 | |
333 | /* we need to sort out, which class deletes what */ | |
d5025dc0 | 334 | delete tree_model->model; |
790b137e RR |
335 | |
336 | /* must chain up */ | |
e152afc3 | 337 | (* list_parent_class->finalize) (object); |
790b137e | 338 | } |
93763ad5 | 339 | |
790b137e RR |
340 | } // extern "C" |
341 | ||
342 | //----------------------------------------------------------------------------- | |
e0062c04 RR |
343 | // implement callbacks from wxGtkTreeModel class by letting |
344 | // them call the methods of wxWidgets' wxDataViewModel | |
790b137e RR |
345 | //----------------------------------------------------------------------------- |
346 | ||
347 | static GtkTreeModelFlags | |
e0062c04 | 348 | wxgtk_tree_model_get_flags (GtkTreeModel *tree_model) |
790b137e | 349 | { |
e0062c04 | 350 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (tree_model), (GtkTreeModelFlags)0 ); |
790b137e | 351 | |
e0062c04 | 352 | return GTK_TREE_MODEL_ITERS_PERSIST; |
790b137e RR |
353 | } |
354 | ||
355 | static gint | |
e0062c04 | 356 | wxgtk_tree_model_get_n_columns (GtkTreeModel *tree_model) |
790b137e | 357 | { |
e0062c04 RR |
358 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
359 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), 0); | |
790b137e | 360 | |
d5025dc0 | 361 | return wxtree_model->model->GetDataViewModel()->GetColumnCount(); |
790b137e RR |
362 | } |
363 | ||
364 | static GType | |
e0062c04 | 365 | wxgtk_tree_model_get_column_type (GtkTreeModel *tree_model, |
93763ad5 | 366 | gint index) |
790b137e | 367 | { |
e0062c04 RR |
368 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
369 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), G_TYPE_INVALID); | |
790b137e | 370 | |
1557c77b | 371 | GType gtype = G_TYPE_INVALID; |
93763ad5 | 372 | |
d5025dc0 | 373 | wxString wxtype = wxtree_model->model->GetDataViewModel()->GetColumnType( (unsigned int) index ); |
93763ad5 | 374 | |
1557c77b RR |
375 | if (wxtype == wxT("string")) |
376 | gtype = G_TYPE_STRING; | |
72a3ac9b VZ |
377 | else |
378 | { | |
379 | wxFAIL_MSG( _T("non-string columns not supported yet") ); | |
380 | } | |
790b137e RR |
381 | |
382 | return gtype; | |
383 | } | |
384 | ||
385 | static gboolean | |
e0062c04 | 386 | wxgtk_tree_model_get_iter (GtkTreeModel *tree_model, |
93763ad5 WS |
387 | GtkTreeIter *iter, |
388 | GtkTreePath *path) | |
790b137e | 389 | { |
e0062c04 RR |
390 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
391 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE); | |
790b137e RR |
392 | g_return_val_if_fail (gtk_tree_path_get_depth (path) > 0, FALSE); |
393 | ||
d5025dc0 | 394 | return wxtree_model->model->get_iter( iter, path ); |
790b137e RR |
395 | } |
396 | ||
397 | static GtkTreePath * | |
e0062c04 | 398 | wxgtk_tree_model_get_path (GtkTreeModel *tree_model, |
93763ad5 | 399 | GtkTreeIter *iter) |
790b137e | 400 | { |
e0062c04 RR |
401 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
402 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), NULL); | |
403 | g_return_val_if_fail (iter->stamp == GTK_WX_TREE_MODEL (wxtree_model)->stamp, NULL); | |
93763ad5 | 404 | |
d5025dc0 | 405 | return wxtree_model->model->get_path( iter ); |
790b137e RR |
406 | } |
407 | ||
408 | static void | |
e0062c04 | 409 | wxgtk_tree_model_get_value (GtkTreeModel *tree_model, |
93763ad5 WS |
410 | GtkTreeIter *iter, |
411 | gint column, | |
412 | GValue *value) | |
790b137e | 413 | { |
e0062c04 RR |
414 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
415 | g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model) ); | |
239eaa41 | 416 | |
d5025dc0 | 417 | wxDataViewModel *model = wxtree_model->model->GetDataViewModel(); |
9861f022 | 418 | wxString mtype = model->GetColumnType( (unsigned int) column ); |
1557c77b RR |
419 | if (mtype == wxT("string")) |
420 | { | |
3f3af7e7 | 421 | wxVariant variant; |
1557c77b | 422 | g_value_init( value, G_TYPE_STRING ); |
e0062c04 RR |
423 | wxDataViewItem item( (wxUint32) iter->user_data ); |
424 | model->GetValue( variant, item, (unsigned int) column ); | |
72a3ac9b | 425 | |
e0062c04 | 426 | g_value_set_string( value, variant.GetString().utf8_str() ); |
1557c77b RR |
427 | } |
428 | else | |
429 | { | |
72a3ac9b | 430 | wxFAIL_MSG( _T("non-string columns not supported yet") ); |
1557c77b | 431 | } |
790b137e RR |
432 | } |
433 | ||
434 | static gboolean | |
e0062c04 | 435 | wxgtk_tree_model_iter_next (GtkTreeModel *tree_model, |
93763ad5 | 436 | GtkTreeIter *iter) |
790b137e | 437 | { |
e0062c04 RR |
438 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
439 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE); | |
e0062c04 | 440 | g_return_val_if_fail (wxtree_model->stamp == iter->stamp, FALSE); |
93763ad5 | 441 | |
d5025dc0 | 442 | return wxtree_model->model->iter_next( iter ); |
790b137e RR |
443 | } |
444 | ||
445 | static gboolean | |
e0062c04 | 446 | wxgtk_tree_model_iter_children (GtkTreeModel *tree_model, |
93763ad5 WS |
447 | GtkTreeIter *iter, |
448 | GtkTreeIter *parent) | |
790b137e | 449 | { |
e0062c04 RR |
450 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
451 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE); | |
e0062c04 | 452 | g_return_val_if_fail (wxtree_model->stamp == parent->stamp, FALSE); |
790b137e | 453 | |
d5025dc0 | 454 | return wxtree_model->model->iter_children( iter, parent ); |
790b137e RR |
455 | } |
456 | ||
457 | static gboolean | |
e0062c04 | 458 | wxgtk_tree_model_iter_has_child (GtkTreeModel *tree_model, |
93763ad5 | 459 | GtkTreeIter *iter) |
790b137e | 460 | { |
e0062c04 RR |
461 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
462 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE); | |
e0062c04 | 463 | g_return_val_if_fail (wxtree_model->stamp == iter->stamp, FALSE); |
d5025dc0 RR |
464 | |
465 | return wxtree_model->model->iter_has_child( iter ); | |
790b137e RR |
466 | } |
467 | ||
468 | static gint | |
e0062c04 | 469 | wxgtk_tree_model_iter_n_children (GtkTreeModel *tree_model, |
93763ad5 | 470 | GtkTreeIter *iter) |
790b137e | 471 | { |
e0062c04 RR |
472 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
473 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE); | |
e0062c04 | 474 | g_return_val_if_fail (wxtree_model->stamp == iter->stamp, 0); |
d5025dc0 RR |
475 | |
476 | return wxtree_model->model->iter_n_children( iter ); | |
790b137e RR |
477 | } |
478 | ||
479 | static gboolean | |
e0062c04 | 480 | wxgtk_tree_model_iter_nth_child (GtkTreeModel *tree_model, |
93763ad5 WS |
481 | GtkTreeIter *iter, |
482 | GtkTreeIter *parent, | |
483 | gint n) | |
790b137e | 484 | { |
e0062c04 RR |
485 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
486 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE); | |
487 | ||
d5025dc0 | 488 | return wxtree_model->model->iter_nth_child( iter, parent, n ); |
790b137e RR |
489 | } |
490 | ||
491 | static gboolean | |
e0062c04 | 492 | wxgtk_tree_model_iter_parent (GtkTreeModel *tree_model, |
93763ad5 WS |
493 | GtkTreeIter *iter, |
494 | GtkTreeIter *child) | |
790b137e | 495 | { |
e0062c04 RR |
496 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
497 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE); | |
e0062c04 RR |
498 | g_return_val_if_fail (wxtree_model->stamp == child->stamp, FALSE); |
499 | ||
d5025dc0 | 500 | return wxtree_model->model->iter_parent( iter, child ); |
790b137e RR |
501 | } |
502 | ||
773cca48 RR |
503 | /* sortable */ |
504 | gboolean wxgtk_tree_model_get_sort_column_id (GtkTreeSortable *sortable, | |
505 | gint *sort_column_id, | |
506 | GtkSortType *order) | |
507 | { | |
94b1f7bc RR |
508 | GtkWxTreeModel *tree_model = (GtkWxTreeModel *) sortable; |
509 | ||
510 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable), FALSE); | |
511 | ||
512 | if (tree_model->sort_column_id == GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID) | |
513 | return FALSE; | |
514 | ||
515 | if (sort_column_id) | |
516 | *sort_column_id = tree_model->sort_column_id; | |
517 | ||
518 | if (order) | |
519 | *order = tree_model->order; | |
520 | ||
521 | return TRUE; | |
773cca48 RR |
522 | } |
523 | ||
524 | void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable *sortable, | |
525 | gint sort_column_id, | |
526 | GtkSortType order) | |
527 | { | |
94b1f7bc RR |
528 | GtkWxTreeModel *tree_model = (GtkWxTreeModel *) sortable; |
529 | ||
530 | g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) ); | |
531 | ||
532 | if ((tree_model->sort_column_id == sort_column_id) && | |
533 | (tree_model->order == order)) | |
534 | return; | |
535 | ||
94b1f7bc RR |
536 | tree_model->sort_column_id = sort_column_id; |
537 | tree_model->order = order; | |
538 | ||
539 | gtk_tree_sortable_sort_column_changed (sortable); | |
540 | ||
541 | wxPrintf( "wxgtk_tree_model_set_column_id, sort_column_id = %d, order = %d\n", sort_column_id, (int)order ); | |
542 | // sort | |
773cca48 RR |
543 | } |
544 | ||
545 | void wxgtk_tree_model_set_sort_func (GtkTreeSortable *sortable, | |
546 | gint sort_column_id, | |
547 | GtkTreeIterCompareFunc func, | |
548 | gpointer data, | |
549 | GtkDestroyNotify destroy) | |
550 | { | |
94b1f7bc RR |
551 | g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) ); |
552 | g_return_if_fail (func != NULL); | |
553 | ||
94b1f7bc RR |
554 | wxPrintf( "wxgtk_tree_model_set_sort_func, sort_column_id = %d\n", sort_column_id ); |
555 | // sort | |
773cca48 RR |
556 | } |
557 | ||
558 | void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable *sortable, | |
559 | GtkTreeIterCompareFunc func, | |
560 | gpointer data, | |
561 | GtkDestroyNotify destroy) | |
562 | { | |
94b1f7bc | 563 | g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) ); |
94b1f7bc RR |
564 | g_return_if_fail (func != NULL); |
565 | ||
94b1f7bc | 566 | wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" ); |
773cca48 RR |
567 | } |
568 | ||
569 | gboolean wxgtk_tree_model_has_default_sort_func (GtkTreeSortable *sortable) | |
570 | { | |
571 | return FALSE; | |
572 | } | |
573 | ||
d5025dc0 RR |
574 | |
575 | //----------------------------------------------------------------------------- | |
576 | // wxGtkTreeModel | |
577 | //----------------------------------------------------------------------------- | |
578 | ||
579 | wxGtkTreeModel::wxGtkTreeModel( wxDataViewModel *wx_model, GtkWxTreeModel *owner ) | |
580 | { | |
581 | m_wx_model = wx_model; | |
582 | m_owner = owner; | |
583 | m_root = NULL; | |
584 | InitTree(); | |
585 | } | |
586 | ||
587 | wxGtkTreeModel::~wxGtkTreeModel() | |
588 | { | |
589 | } | |
590 | ||
591 | void wxGtkTreeModel::BuildBranch( wxGtkTreeModelNode *node ) | |
592 | { | |
593 | if (node->GetChildCount() == 0) | |
594 | { | |
595 | wxDataViewItem child = m_wx_model->GetFirstChild( node->GetItem() ); | |
596 | while (child.IsOk()) | |
597 | { | |
598 | // wxPrintf( "AddItem %d\n", (int) child.GetID() ); | |
599 | node->Append( new wxGtkTreeModelNode( node, child ) ); | |
600 | child = m_wx_model->GetNextSibling( child ); | |
601 | } | |
602 | } | |
603 | } | |
604 | ||
605 | gboolean wxGtkTreeModel::get_iter( GtkTreeIter *iter, GtkTreePath *path ) | |
606 | { | |
607 | int depth = gtk_tree_path_get_depth( path ); | |
608 | ||
609 | wxGtkTreeModelNode *node = m_root; | |
610 | ||
611 | int i; | |
612 | for (i = 0; i < depth; i++) | |
613 | { | |
614 | BuildBranch( node ); | |
615 | ||
616 | gint pos = gtk_tree_path_get_indices (path)[i]; | |
617 | if (pos < 0) return FALSE; | |
618 | if ((size_t)pos >= node->GetChildCount()) return FALSE; | |
619 | ||
620 | node = node->GetChildren().Item( (size_t) pos ); | |
621 | } | |
622 | ||
623 | iter->stamp = m_owner->stamp; | |
624 | iter->user_data = (gpointer) node->GetItem().GetID(); | |
625 | ||
626 | return TRUE; | |
627 | } | |
628 | ||
629 | GtkTreePath *wxGtkTreeModel::get_path( GtkTreeIter *iter ) | |
630 | { | |
631 | GtkTreePath *retval = gtk_tree_path_new (); | |
632 | ||
633 | wxGtkTreeModelNode *node = FindNode( iter ); | |
634 | while (node->GetParent()) | |
635 | { | |
636 | wxGtkTreeModelNode *parent = node->GetParent(); | |
637 | int pos = parent->GetChildren().Index( parent ); | |
638 | ||
639 | gtk_tree_path_prepend_index( retval, pos ); | |
640 | ||
641 | node = parent; | |
642 | } | |
643 | ||
644 | return retval; | |
645 | } | |
646 | ||
647 | gboolean wxGtkTreeModel::iter_next( GtkTreeIter *iter ) | |
648 | { | |
649 | wxDataViewItem item( (wxUint32) iter->user_data ); | |
650 | item = m_wx_model->GetNextSibling( item ); | |
651 | if (!item.IsOk()) | |
652 | return FALSE; | |
653 | ||
654 | iter->user_data = (gpointer) item.GetID(); | |
655 | ||
656 | return TRUE; | |
657 | } | |
658 | ||
659 | gboolean wxGtkTreeModel::iter_children( GtkTreeIter *iter, GtkTreeIter *parent ) | |
660 | { | |
661 | wxDataViewItem item( (wxUint32) parent->user_data ); | |
662 | ||
663 | if (!m_wx_model->HasChildren( item )) | |
664 | return FALSE; | |
665 | ||
666 | wxGtkTreeModelNode *parent_node = FindNode( parent ); | |
667 | BuildBranch( parent_node ); | |
668 | ||
669 | wxGtkTreeModelNode *first_child_node = parent_node->GetChildren().Item( 0 ); | |
670 | ||
671 | iter->stamp = m_owner->stamp; | |
672 | iter->user_data = (gpointer) first_child_node->GetItem().GetID(); | |
673 | ||
674 | return TRUE; | |
675 | } | |
676 | ||
677 | gboolean wxGtkTreeModel::iter_has_child( GtkTreeIter *iter ) | |
678 | { | |
679 | wxDataViewItem item( (wxUint32) iter->user_data ); | |
680 | ||
681 | return m_wx_model->HasChildren( item ); | |
682 | } | |
683 | ||
684 | gint wxGtkTreeModel::iter_n_children( GtkTreeIter *iter ) | |
685 | { | |
686 | wxDataViewItem item( (wxUint32) iter->user_data ); | |
687 | ||
688 | if (!m_wx_model->HasChildren( item )) | |
689 | return 0; | |
690 | ||
691 | wxGtkTreeModelNode *parent_node = FindNode( iter ); | |
692 | BuildBranch( parent_node ); | |
693 | ||
694 | return parent_node->GetChildCount(); | |
695 | } | |
696 | ||
697 | gboolean wxGtkTreeModel::iter_nth_child( GtkTreeIter *iter, GtkTreeIter *parent, gint n ) | |
698 | { | |
699 | wxUint32 id = 0; | |
700 | if (parent) id = (wxUint32) parent->user_data; | |
701 | wxDataViewItem item( id ); | |
702 | ||
703 | if (!m_wx_model->HasChildren( item )) | |
704 | return FALSE; | |
705 | ||
706 | wxGtkTreeModelNode *parent_node = FindNode( parent ); | |
707 | BuildBranch( parent_node ); | |
708 | ||
709 | wxGtkTreeModelNode *child_node = parent_node->GetChildren().Item( (size_t) n ); | |
710 | if (!child_node) | |
711 | return FALSE; | |
712 | ||
713 | iter->stamp = m_owner->stamp; | |
714 | iter->user_data = (gpointer) child_node->GetItem().GetID(); | |
715 | ||
716 | return TRUE; | |
717 | } | |
718 | ||
719 | gboolean wxGtkTreeModel::iter_parent( GtkTreeIter *iter, GtkTreeIter *child ) | |
720 | { | |
721 | wxDataViewItem item( (wxUint32) child->user_data ); | |
722 | ||
723 | wxGtkTreeModelNode *node = FindNode( child ); | |
724 | node = node->GetParent(); | |
725 | if (!node) | |
726 | return FALSE; | |
727 | ||
728 | iter->stamp = m_owner->stamp; | |
729 | iter->user_data = (gpointer) node->GetItem().GetID(); | |
730 | ||
731 | return TRUE; | |
732 | } | |
733 | ||
734 | void wxGtkTreeModel::InitTree() | |
735 | { | |
736 | wxDataViewItem item; | |
737 | m_root = new wxGtkTreeModelNode( NULL, item ); | |
738 | ||
739 | BuildBranch( m_root ); | |
740 | } | |
741 | ||
742 | static wxGtkTreeModelNode* | |
743 | wxGtkTreeModel_FindNode( wxGtkTreeModelNode *node, const wxDataViewItem &item ) | |
744 | { | |
745 | if (!node) return NULL; | |
746 | ||
747 | size_t count = node->GetChildCount(); | |
748 | size_t i; | |
749 | for (i = 0; i < count; i++) | |
750 | { | |
751 | wxGtkTreeModelNode *child = node->GetChildren().Item( i ); | |
752 | if (child->GetItem().GetID() == item.GetID()) | |
753 | return child; | |
754 | ||
755 | wxGtkTreeModelNode *node2 = wxGtkTreeModel_FindNode( child, item ); | |
756 | if (node2) | |
757 | return node2; | |
758 | } | |
759 | ||
760 | return NULL; | |
761 | } | |
762 | ||
763 | wxGtkTreeModelNode *wxGtkTreeModel::FindNode( GtkTreeIter *iter ) | |
764 | { | |
765 | if (!iter) | |
766 | return m_root; | |
767 | ||
768 | wxDataViewItem item( (wxUint32) iter->user_data ); | |
769 | ||
770 | wxGtkTreeModelNode *result = wxGtkTreeModel_FindNode( m_root, item ); | |
771 | ||
772 | if (!result) | |
773 | { | |
774 | wxPrintf( "Not found %d\n", (int) iter->user_data ); | |
775 | char *crash = NULL; | |
776 | *crash = 0; | |
777 | } | |
778 | ||
779 | return result; | |
780 | } | |
781 | ||
e152afc3 | 782 | //----------------------------------------------------------------------------- |
baa9ebc4 | 783 | // define new GTK+ class wxGtkRendererRenderer |
e152afc3 RR |
784 | //----------------------------------------------------------------------------- |
785 | ||
786 | extern "C" { | |
787 | ||
788 | #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ()) | |
789 | #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer)) | |
790 | #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass)) | |
791 | #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER)) | |
792 | #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER)) | |
793 | #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass)) | |
794 | ||
795 | GType gtk_wx_cell_renderer_get_type (void); | |
796 | ||
797 | typedef struct _GtkWxCellRenderer GtkWxCellRenderer; | |
798 | typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass; | |
799 | ||
800 | struct _GtkWxCellRenderer | |
801 | { | |
802 | GtkCellRenderer parent; | |
803 | ||
804 | /*< private >*/ | |
baa9ebc4 | 805 | wxDataViewCustomRenderer *cell; |
4d496ecb | 806 | guint32 last_click; |
e152afc3 RR |
807 | }; |
808 | ||
809 | struct _GtkWxCellRendererClass | |
810 | { | |
811 | GtkCellRendererClass cell_parent_class; | |
e152afc3 RR |
812 | }; |
813 | ||
814 | ||
815 | static GtkCellRenderer *gtk_wx_cell_renderer_new (void); | |
553f7d8f RR |
816 | static void gtk_wx_cell_renderer_init ( |
817 | GtkWxCellRenderer *cell ); | |
818 | static void gtk_wx_cell_renderer_class_init( | |
819 | GtkWxCellRendererClass *klass ); | |
820 | static void gtk_wx_cell_renderer_finalize ( | |
821 | GObject *object ); | |
822 | static void gtk_wx_cell_renderer_get_size ( | |
823 | GtkCellRenderer *cell, | |
93763ad5 WS |
824 | GtkWidget *widget, |
825 | GdkRectangle *rectangle, | |
826 | gint *x_offset, | |
827 | gint *y_offset, | |
828 | gint *width, | |
829 | gint *height ); | |
553f7d8f RR |
830 | static void gtk_wx_cell_renderer_render ( |
831 | GtkCellRenderer *cell, | |
93763ad5 WS |
832 | GdkWindow *window, |
833 | GtkWidget *widget, | |
834 | GdkRectangle *background_area, | |
835 | GdkRectangle *cell_area, | |
836 | GdkRectangle *expose_area, | |
837 | GtkCellRendererState flags ); | |
553f7d8f RR |
838 | static gboolean gtk_wx_cell_renderer_activate( |
839 | GtkCellRenderer *cell, | |
840 | GdkEvent *event, | |
841 | GtkWidget *widget, | |
842 | const gchar *path, | |
843 | GdkRectangle *background_area, | |
844 | GdkRectangle *cell_area, | |
845 | GtkCellRendererState flags ); | |
1e510b1e RR |
846 | static GtkCellEditable *gtk_wx_cell_renderer_start_editing( |
847 | GtkCellRenderer *cell, | |
848 | GdkEvent *event, | |
849 | GtkWidget *widget, | |
850 | const gchar *path, | |
851 | GdkRectangle *background_area, | |
852 | GdkRectangle *cell_area, | |
853 | GtkCellRendererState flags ); | |
e8375af8 | 854 | |
e152afc3 RR |
855 | |
856 | static GObjectClass *cell_parent_class = NULL; | |
857 | ||
858 | } // extern "C" | |
859 | ||
93763ad5 | 860 | GType |
e152afc3 RR |
861 | gtk_wx_cell_renderer_get_type (void) |
862 | { | |
553f7d8f | 863 | static GType cell_wx_type = 0; |
e152afc3 | 864 | |
553f7d8f | 865 | if (!cell_wx_type) |
e152afc3 | 866 | { |
de4a74e2 | 867 | const GTypeInfo cell_wx_info = |
553f7d8f RR |
868 | { |
869 | sizeof (GtkWxCellRendererClass), | |
93763ad5 WS |
870 | NULL, /* base_init */ |
871 | NULL, /* base_finalize */ | |
553f7d8f | 872 | (GClassInitFunc) gtk_wx_cell_renderer_class_init, |
93763ad5 WS |
873 | NULL, /* class_finalize */ |
874 | NULL, /* class_data */ | |
553f7d8f RR |
875 | sizeof (GtkWxCellRenderer), |
876 | 0, /* n_preallocs */ | |
877 | (GInstanceInitFunc) gtk_wx_cell_renderer_init, | |
878 | }; | |
879 | ||
93763ad5 | 880 | cell_wx_type = g_type_register_static( GTK_TYPE_CELL_RENDERER, |
553f7d8f | 881 | "GtkWxCellRenderer", &cell_wx_info, (GTypeFlags)0 ); |
e152afc3 RR |
882 | } |
883 | ||
553f7d8f | 884 | return cell_wx_type; |
e152afc3 RR |
885 | } |
886 | ||
887 | static void | |
888 | gtk_wx_cell_renderer_init (GtkWxCellRenderer *cell) | |
889 | { | |
890 | cell->cell = NULL; | |
4d496ecb | 891 | cell->last_click = 0; |
e152afc3 RR |
892 | } |
893 | ||
894 | static void | |
895 | gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass *klass) | |
896 | { | |
897 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
898 | GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass); | |
899 | ||
900 | cell_parent_class = (GObjectClass*) g_type_class_peek_parent (klass); | |
901 | ||
902 | object_class->finalize = gtk_wx_cell_renderer_finalize; | |
903 | ||
904 | cell_class->get_size = gtk_wx_cell_renderer_get_size; | |
905 | cell_class->render = gtk_wx_cell_renderer_render; | |
553f7d8f | 906 | cell_class->activate = gtk_wx_cell_renderer_activate; |
1e510b1e | 907 | cell_class->start_editing = gtk_wx_cell_renderer_start_editing; |
e152afc3 RR |
908 | } |
909 | ||
910 | static void | |
911 | gtk_wx_cell_renderer_finalize (GObject *object) | |
912 | { | |
913 | /* must chain up */ | |
914 | (* G_OBJECT_CLASS (cell_parent_class)->finalize) (object); | |
915 | } | |
916 | ||
917 | GtkCellRenderer* | |
918 | gtk_wx_cell_renderer_new (void) | |
919 | { | |
920 | return (GtkCellRenderer*) g_object_new (GTK_TYPE_WX_CELL_RENDERER, NULL); | |
921 | } | |
922 | ||
1e510b1e RR |
923 | |
924 | ||
925 | static GtkCellEditable *gtk_wx_cell_renderer_start_editing( | |
926 | GtkCellRenderer *renderer, | |
927 | GdkEvent *event, | |
928 | GtkWidget *widget, | |
929 | const gchar *path, | |
930 | GdkRectangle *background_area, | |
931 | GdkRectangle *cell_area, | |
932 | GtkCellRendererState flags ) | |
933 | { | |
934 | GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer; | |
935 | wxDataViewCustomRenderer *cell = wxrenderer->cell; | |
936 | if (!cell->HasEditorCtrl()) | |
937 | return NULL; | |
e8375af8 | 938 | |
1e510b1e RR |
939 | GdkRectangle rect; |
940 | gtk_wx_cell_renderer_get_size (renderer, widget, cell_area, | |
941 | &rect.x, | |
942 | &rect.y, | |
943 | &rect.width, | |
944 | &rect.height); | |
945 | ||
946 | rect.x += cell_area->x; | |
947 | rect.y += cell_area->y; | |
948 | // rect.width -= renderer->xpad * 2; | |
949 | // rect.height -= renderer->ypad * 2; | |
950 | ||
951 | // wxRect renderrect( rect.x, rect.y, rect.width, rect.height ); | |
952 | wxRect renderrect( cell_area->x, cell_area->y, cell_area->width, cell_area->height ); | |
953 | ||
63415a42 | 954 | // wxDataViewListModel *model = cell->GetOwner()->GetOwner()->GetModel(); |
1e510b1e RR |
955 | |
956 | GtkTreePath *treepath = gtk_tree_path_new_from_string( path ); | |
957 | unsigned int model_row = (unsigned int)gtk_tree_path_get_indices (treepath)[0]; | |
958 | gtk_tree_path_free( treepath ); | |
959 | ||
960 | cell->StartEditing( model_row, renderrect ); | |
30715fa1 | 961 | |
1e510b1e RR |
962 | return NULL; |
963 | } | |
964 | ||
e152afc3 RR |
965 | static void |
966 | gtk_wx_cell_renderer_get_size (GtkCellRenderer *renderer, | |
93763ad5 WS |
967 | GtkWidget *widget, |
968 | GdkRectangle *cell_area, | |
969 | gint *x_offset, | |
970 | gint *y_offset, | |
971 | gint *width, | |
972 | gint *height) | |
e152afc3 RR |
973 | { |
974 | GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer; | |
baa9ebc4 | 975 | wxDataViewCustomRenderer *cell = wxrenderer->cell; |
93763ad5 | 976 | |
e152afc3 RR |
977 | wxSize size = cell->GetSize(); |
978 | ||
979 | gint calc_width = (gint) renderer->xpad * 2 + size.x; | |
980 | gint calc_height = (gint) renderer->ypad * 2 + size.y; | |
93763ad5 WS |
981 | |
982 | if (x_offset) | |
e152afc3 | 983 | *x_offset = 0; |
93763ad5 | 984 | if (y_offset) |
e152afc3 RR |
985 | *y_offset = 0; |
986 | ||
987 | if (cell_area && size.x > 0 && size.y > 0) | |
988 | { | |
989 | if (x_offset) | |
93763ad5 | 990 | { |
e152afc3 RR |
991 | *x_offset = (gint)((renderer->xalign * |
992 | (cell_area->width - calc_width - 2 * renderer->xpad))); | |
993 | *x_offset = MAX (*x_offset, 0) + renderer->xpad; | |
93763ad5 | 994 | } |
e152afc3 RR |
995 | if (y_offset) |
996 | { | |
997 | *y_offset = (gint)((renderer->yalign * | |
998 | (cell_area->height - calc_height - 2 * renderer->ypad))); | |
999 | *y_offset = MAX (*y_offset, 0) + renderer->ypad; | |
1000 | } | |
1001 | } | |
1002 | ||
1003 | if (width) | |
1004 | *width = calc_width; | |
93763ad5 | 1005 | |
e152afc3 RR |
1006 | if (height) |
1007 | *height = calc_height; | |
1008 | } | |
1009 | ||
1010 | static void | |
1011 | gtk_wx_cell_renderer_render (GtkCellRenderer *renderer, | |
93763ad5 WS |
1012 | GdkWindow *window, |
1013 | GtkWidget *widget, | |
1014 | GdkRectangle *background_area, | |
1015 | GdkRectangle *cell_area, | |
1016 | GdkRectangle *expose_area, | |
1017 | GtkCellRendererState flags) | |
e152afc3 RR |
1018 | |
1019 | { | |
1020 | GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer; | |
baa9ebc4 | 1021 | wxDataViewCustomRenderer *cell = wxrenderer->cell; |
93763ad5 | 1022 | |
e152afc3 RR |
1023 | GdkRectangle rect; |
1024 | gtk_wx_cell_renderer_get_size (renderer, widget, cell_area, | |
93763ad5 WS |
1025 | &rect.x, |
1026 | &rect.y, | |
1027 | &rect.width, | |
1028 | &rect.height); | |
e152afc3 RR |
1029 | |
1030 | rect.x += cell_area->x; | |
1031 | rect.y += cell_area->y; | |
1032 | rect.width -= renderer->xpad * 2; | |
1033 | rect.height -= renderer->ypad * 2; | |
93763ad5 | 1034 | |
e152afc3 RR |
1035 | GdkRectangle dummy; |
1036 | if (gdk_rectangle_intersect (expose_area, &rect, &dummy)) | |
1037 | { | |
1038 | wxRect renderrect( rect.x, rect.y, rect.width, rect.height ); | |
1039 | wxWindowDC* dc = (wxWindowDC*) cell->GetDC(); | |
4d496ecb RR |
1040 | if (dc->m_window == NULL) |
1041 | { | |
1042 | dc->m_window = window; | |
1043 | dc->SetUpDC(); | |
1044 | } | |
93763ad5 | 1045 | |
e152afc3 RR |
1046 | int state = 0; |
1047 | if (flags & GTK_CELL_RENDERER_SELECTED) | |
1048 | state |= wxDATAVIEW_CELL_SELECTED; | |
1049 | if (flags & GTK_CELL_RENDERER_PRELIT) | |
1050 | state |= wxDATAVIEW_CELL_PRELIT; | |
1051 | if (flags & GTK_CELL_RENDERER_INSENSITIVE) | |
1052 | state |= wxDATAVIEW_CELL_INSENSITIVE; | |
1053 | if (flags & GTK_CELL_RENDERER_INSENSITIVE) | |
1054 | state |= wxDATAVIEW_CELL_INSENSITIVE; | |
1055 | if (flags & GTK_CELL_RENDERER_FOCUSED) | |
1056 | state |= wxDATAVIEW_CELL_FOCUSED; | |
1057 | cell->Render( renderrect, dc, state ); | |
93763ad5 | 1058 | } |
e152afc3 RR |
1059 | } |
1060 | ||
93763ad5 | 1061 | static gboolean |
553f7d8f RR |
1062 | gtk_wx_cell_renderer_activate( |
1063 | GtkCellRenderer *renderer, | |
1064 | GdkEvent *event, | |
1065 | GtkWidget *widget, | |
1066 | const gchar *path, | |
1067 | GdkRectangle *background_area, | |
1068 | GdkRectangle *cell_area, | |
1069 | GtkCellRendererState flags ) | |
1070 | { | |
1071 | GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer; | |
baa9ebc4 | 1072 | wxDataViewCustomRenderer *cell = wxrenderer->cell; |
93763ad5 | 1073 | |
553f7d8f RR |
1074 | GdkRectangle rect; |
1075 | gtk_wx_cell_renderer_get_size (renderer, widget, cell_area, | |
93763ad5 WS |
1076 | &rect.x, |
1077 | &rect.y, | |
1078 | &rect.width, | |
1079 | &rect.height); | |
553f7d8f RR |
1080 | |
1081 | rect.x += cell_area->x; | |
1082 | rect.y += cell_area->y; | |
1083 | rect.width -= renderer->xpad * 2; | |
1084 | rect.height -= renderer->ypad * 2; | |
93763ad5 | 1085 | |
553f7d8f | 1086 | wxRect renderrect( rect.x, rect.y, rect.width, rect.height ); |
93763ad5 | 1087 | |
e0062c04 | 1088 | wxDataViewModel *model = cell->GetOwner()->GetOwner()->GetModel(); |
93763ad5 | 1089 | |
4d496ecb | 1090 | GtkTreePath *treepath = gtk_tree_path_new_from_string( path ); |
0a71f9e9 | 1091 | unsigned int model_row = (unsigned int)gtk_tree_path_get_indices (treepath)[0]; |
4d496ecb | 1092 | gtk_tree_path_free( treepath ); |
93763ad5 | 1093 | |
0a71f9e9 | 1094 | unsigned int model_col = cell->GetOwner()->GetModelColumn(); |
93763ad5 | 1095 | |
456e5c21 RR |
1096 | if (!event) |
1097 | { | |
1098 | bool ret = false; | |
e8375af8 | 1099 | |
456e5c21 RR |
1100 | // activated by <ENTER> |
1101 | if (cell->Activate( renderrect, model, model_col, model_row )) | |
1102 | ret = true; | |
e8375af8 | 1103 | |
456e5c21 RR |
1104 | return ret; |
1105 | } | |
1106 | else if (event->type == GDK_BUTTON_PRESS) | |
4d496ecb RR |
1107 | { |
1108 | GdkEventButton *button_event = (GdkEventButton*) event; | |
93763ad5 | 1109 | wxPoint pt( ((int) button_event->x) - renderrect.x, |
4d496ecb | 1110 | ((int) button_event->y) - renderrect.y ); |
93763ad5 | 1111 | |
4d496ecb RR |
1112 | bool ret = false; |
1113 | if (button_event->button == 1) | |
1114 | { | |
1115 | if (cell->LeftClick( pt, renderrect, model, model_col, model_row )) | |
1116 | ret = true; | |
7ea3a0de | 1117 | // TODO: query system double-click time |
4d496ecb RR |
1118 | if (button_event->time - wxrenderer->last_click < 400) |
1119 | if (cell->Activate( renderrect, model, model_col, model_row )) | |
1120 | ret = true; | |
1121 | } | |
1122 | if (button_event->button == 3) | |
1123 | { | |
1124 | if (cell->RightClick( pt, renderrect, model, model_col, model_row )) | |
1125 | ret = true; | |
1126 | } | |
93763ad5 | 1127 | |
4d496ecb | 1128 | wxrenderer->last_click = button_event->time; |
93763ad5 | 1129 | |
4d496ecb RR |
1130 | return ret; |
1131 | } | |
93763ad5 | 1132 | |
4d496ecb | 1133 | return false; |
553f7d8f RR |
1134 | } |
1135 | ||
93763ad5 | 1136 | // --------------------------------------------------------- |
e0062c04 | 1137 | // wxGtkDataViewModelNotifier |
93763ad5 | 1138 | // --------------------------------------------------------- |
6e2e590f | 1139 | |
e0062c04 | 1140 | class wxGtkDataViewModelNotifier: public wxDataViewModelNotifier |
6e2e590f RR |
1141 | { |
1142 | public: | |
e0062c04 RR |
1143 | wxGtkDataViewModelNotifier( GtkWxTreeModel *wxgtk_model, |
1144 | wxDataViewModel *wx_model, | |
1145 | wxDataViewCtrl *ctrl ); | |
1146 | ~wxGtkDataViewModelNotifier(); | |
1147 | ||
1148 | virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ); | |
1149 | virtual bool ItemDeleted( const wxDataViewItem &item ); | |
1150 | virtual bool ItemChanged( const wxDataViewItem &item ); | |
1151 | virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ); | |
6e2e590f | 1152 | virtual bool Cleared(); |
93763ad5 | 1153 | |
e0062c04 RR |
1154 | GtkWxTreeModel *m_wxgtk_model; |
1155 | wxDataViewModel *m_wx_model; | |
63415a42 | 1156 | wxDataViewCtrl *m_owner; |
6e2e590f RR |
1157 | }; |
1158 | ||
93763ad5 | 1159 | // --------------------------------------------------------- |
6e2e590f | 1160 | // wxGtkDataViewListModelNotifier |
93763ad5 | 1161 | // --------------------------------------------------------- |
6e2e590f | 1162 | |
e0062c04 RR |
1163 | wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier( |
1164 | GtkWxTreeModel* wxgtk_model, wxDataViewModel *wx_model, | |
63415a42 | 1165 | wxDataViewCtrl *ctrl ) |
6e2e590f | 1166 | { |
e0062c04 | 1167 | m_wxgtk_model = wxgtk_model; |
6e2e590f | 1168 | m_wx_model = wx_model; |
63415a42 | 1169 | m_owner = ctrl; |
6e2e590f | 1170 | } |
93763ad5 | 1171 | |
e0062c04 | 1172 | wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier() |
f7ed8c89 RR |
1173 | { |
1174 | m_wx_model = NULL; | |
e0062c04 | 1175 | m_wxgtk_model = NULL; |
f7ed8c89 RR |
1176 | } |
1177 | ||
e0062c04 | 1178 | bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) |
6e2e590f | 1179 | { |
6e2e590f | 1180 | GtkTreeIter iter; |
e0062c04 RR |
1181 | iter.stamp = m_wxgtk_model->stamp; |
1182 | iter.user_data = (gpointer) item.GetID(); | |
93763ad5 | 1183 | |
e0062c04 RR |
1184 | GtkTreePath *path = wxgtk_tree_model_get_path( |
1185 | GTK_TREE_MODEL(m_wxgtk_model), &iter ); | |
1186 | gtk_tree_model_row_inserted( | |
1187 | GTK_TREE_MODEL(m_wxgtk_model), path, &iter); | |
6e2e590f | 1188 | gtk_tree_path_free (path); |
93763ad5 | 1189 | |
6e2e590f RR |
1190 | return true; |
1191 | } | |
1192 | ||
e0062c04 | 1193 | bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem &item ) |
6e2e590f | 1194 | { |
605c2c4a | 1195 | GtkTreeIter iter; |
e0062c04 RR |
1196 | iter.stamp = m_wxgtk_model->stamp; |
1197 | iter.user_data = (gpointer) item.GetID(); | |
93763ad5 | 1198 | |
e0062c04 RR |
1199 | GtkTreePath *path = wxgtk_tree_model_get_path( |
1200 | GTK_TREE_MODEL(m_wxgtk_model), &iter ); | |
1201 | gtk_tree_model_row_deleted( | |
1202 | GTK_TREE_MODEL(m_wxgtk_model), path ); | |
605c2c4a | 1203 | gtk_tree_path_free (path); |
93763ad5 | 1204 | |
605c2c4a | 1205 | return true; |
6e2e590f RR |
1206 | } |
1207 | ||
e0062c04 | 1208 | bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem &item ) |
6e2e590f | 1209 | { |
4627af27 | 1210 | GtkTreeIter iter; |
e0062c04 RR |
1211 | iter.stamp = m_wxgtk_model->stamp; |
1212 | iter.user_data = (gpointer) item.GetID(); | |
6e2e590f | 1213 | |
e0062c04 RR |
1214 | GtkTreePath *path = wxgtk_tree_model_get_path( |
1215 | GTK_TREE_MODEL(m_wxgtk_model), &iter ); | |
1216 | gtk_tree_model_row_changed( | |
1217 | GTK_TREE_MODEL(m_wxgtk_model), path, &iter ); | |
a7f61f76 RR |
1218 | gtk_tree_path_free (path); |
1219 | ||
1220 | return true; | |
6e2e590f RR |
1221 | } |
1222 | ||
e0062c04 | 1223 | bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem &item, unsigned int model_col ) |
6e2e590f | 1224 | { |
4eccd3a1 | 1225 | // This adds GTK+'s missing MVC logic for ValueChanged |
63415a42 RR |
1226 | unsigned int index; |
1227 | for (index = 0; index < m_owner->GetColumnCount(); index++) | |
8f850e28 | 1228 | { |
63415a42 RR |
1229 | wxDataViewColumn *column = m_owner->GetColumn( index ); |
1230 | if (column->GetModelColumn() == model_col) | |
8f850e28 | 1231 | { |
63415a42 RR |
1232 | GtkTreeView *widget = GTK_TREE_VIEW(m_owner->m_treeview); |
1233 | GtkTreeViewColumn *gcolumn = GTK_TREE_VIEW_COLUMN(column->GetGtkHandle()); | |
8f850e28 RR |
1234 | |
1235 | // Get cell area | |
e0062c04 RR |
1236 | GtkTreeIter iter; |
1237 | iter.stamp = m_wxgtk_model->stamp; | |
1238 | iter.user_data = (gpointer) item.GetID(); | |
1239 | GtkTreePath *path = wxgtk_tree_model_get_path( | |
1240 | GTK_TREE_MODEL(m_wxgtk_model), &iter ); | |
8f850e28 | 1241 | GdkRectangle cell_area; |
63415a42 | 1242 | gtk_tree_view_get_cell_area( widget, path, gcolumn, &cell_area ); |
93763ad5 | 1243 | gtk_tree_path_free( path ); |
8f850e28 | 1244 | |
1a64259d RR |
1245 | GtkAdjustment* hadjust = gtk_tree_view_get_hadjustment( widget ); |
1246 | double d = gtk_adjustment_get_value( hadjust ); | |
1247 | int xdiff = (int) d; | |
1248 | ||
63415a42 | 1249 | int ydiff = gcolumn->button->allocation.height; |
8f850e28 | 1250 | // Redraw |
93763ad5 | 1251 | gtk_widget_queue_draw_area( GTK_WIDGET(widget), |
1a64259d | 1252 | cell_area.x - xdiff, ydiff + cell_area.y, cell_area.width, cell_area.height ); |
8f850e28 | 1253 | } |
8f850e28 | 1254 | } |
93763ad5 | 1255 | |
8f850e28 | 1256 | return true; |
6e2e590f RR |
1257 | } |
1258 | ||
e0062c04 | 1259 | bool wxGtkDataViewModelNotifier::Cleared() |
6e2e590f RR |
1260 | { |
1261 | return false; | |
1262 | } | |
1263 | ||
93763ad5 | 1264 | // --------------------------------------------------------- |
baa9ebc4 | 1265 | // wxDataViewRenderer |
93763ad5 | 1266 | // --------------------------------------------------------- |
6842a71a | 1267 | |
baa9ebc4 | 1268 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer, wxDataViewRendererBase) |
6842a71a | 1269 | |
9861f022 RR |
1270 | wxDataViewRenderer::wxDataViewRenderer( const wxString &varianttype, wxDataViewCellMode mode, |
1271 | int align ) : | |
1272 | wxDataViewRendererBase( varianttype, mode, align ) | |
6842a71a RR |
1273 | { |
1274 | m_renderer = NULL; | |
9861f022 RR |
1275 | |
1276 | // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor, | |
1277 | // after the m_renderer pointer has been initialized | |
1278 | } | |
1279 | ||
1280 | void wxDataViewRenderer::SetMode( wxDataViewCellMode mode ) | |
1281 | { | |
1282 | GtkCellRendererMode gtkMode; | |
1283 | switch (mode) | |
1284 | { | |
1285 | case wxDATAVIEW_CELL_INERT: | |
1286 | gtkMode = GTK_CELL_RENDERER_MODE_INERT; | |
1287 | break; | |
1288 | case wxDATAVIEW_CELL_ACTIVATABLE: | |
1289 | gtkMode = GTK_CELL_RENDERER_MODE_ACTIVATABLE; | |
1290 | break; | |
1291 | case wxDATAVIEW_CELL_EDITABLE: | |
1292 | gtkMode = GTK_CELL_RENDERER_MODE_EDITABLE; | |
1293 | break; | |
1294 | } | |
1295 | ||
1296 | GValue gvalue = { 0, }; | |
1297 | g_value_init( &gvalue, gtk_cell_renderer_mode_get_type() ); | |
1298 | g_value_set_enum( &gvalue, gtkMode ); | |
1299 | g_object_set_property( G_OBJECT(m_renderer), "mode", &gvalue ); | |
1300 | g_value_unset( &gvalue ); | |
1301 | } | |
1302 | ||
1303 | wxDataViewCellMode wxDataViewRenderer::GetMode() const | |
1304 | { | |
1305 | wxDataViewCellMode ret; | |
1306 | ||
1307 | GValue gvalue; | |
1308 | g_object_get( G_OBJECT(m_renderer), "mode", &gvalue, NULL); | |
1309 | ||
1310 | switch (g_value_get_enum(&gvalue)) | |
1311 | { | |
1312 | case GTK_CELL_RENDERER_MODE_INERT: | |
1313 | ret = wxDATAVIEW_CELL_INERT; | |
1314 | break; | |
1315 | case GTK_CELL_RENDERER_MODE_ACTIVATABLE: | |
1316 | ret = wxDATAVIEW_CELL_ACTIVATABLE; | |
1317 | break; | |
1318 | case GTK_CELL_RENDERER_MODE_EDITABLE: | |
1319 | ret = wxDATAVIEW_CELL_EDITABLE; | |
1320 | break; | |
1321 | } | |
1322 | ||
1323 | g_value_unset( &gvalue ); | |
1324 | ||
1325 | return ret; | |
1326 | } | |
1327 | ||
1328 | void wxDataViewRenderer::SetAlignment( int align ) | |
1329 | { | |
1330 | // horizontal alignment: | |
1331 | ||
1332 | gfloat xalign = 0.0; | |
1333 | if (align & wxALIGN_RIGHT) | |
1334 | xalign = 1.0; | |
1335 | else if (align & wxALIGN_CENTER_HORIZONTAL) | |
1336 | xalign = 0.5; | |
1337 | ||
1338 | GValue gvalue = { 0, }; | |
1339 | g_value_init( &gvalue, G_TYPE_FLOAT ); | |
1340 | g_value_set_float( &gvalue, xalign ); | |
1341 | g_object_set_property( G_OBJECT(m_renderer), "xalign", &gvalue ); | |
1342 | g_value_unset( &gvalue ); | |
1343 | ||
1344 | // vertical alignment: | |
1345 | ||
1346 | gfloat yalign = 0.0; | |
1347 | if (align & wxALIGN_BOTTOM) | |
1348 | yalign = 1.0; | |
1349 | else if (align & wxALIGN_CENTER_VERTICAL) | |
1350 | yalign = 0.5; | |
1351 | ||
1352 | GValue gvalue2 = { 0, }; | |
1353 | g_value_init( &gvalue2, G_TYPE_FLOAT ); | |
1354 | g_value_set_float( &gvalue2, yalign ); | |
1355 | g_object_set_property( G_OBJECT(m_renderer), "yalign", &gvalue2 ); | |
1356 | g_value_unset( &gvalue2 ); | |
6842a71a RR |
1357 | } |
1358 | ||
9861f022 RR |
1359 | int wxDataViewRenderer::GetAlignment() const |
1360 | { | |
1361 | int ret = 0; | |
1362 | GValue gvalue; | |
1363 | ||
1364 | // horizontal alignment: | |
1365 | ||
1366 | g_object_get( G_OBJECT(m_renderer), "xalign", &gvalue, NULL ); | |
1367 | float xalign = g_value_get_float( &gvalue ); | |
1368 | if (xalign < 0.5) | |
1369 | ret |= wxALIGN_LEFT; | |
1370 | else if (xalign == 0.5) | |
1371 | ret |= wxALIGN_CENTER_HORIZONTAL; | |
1372 | else | |
1373 | ret |= wxALIGN_RIGHT; | |
1374 | g_value_unset( &gvalue ); | |
1375 | ||
1376 | ||
1377 | // vertical alignment: | |
1378 | ||
1379 | g_object_get( G_OBJECT(m_renderer), "yalign", &gvalue, NULL ); | |
1380 | float yalign = g_value_get_float( &gvalue ); | |
1381 | if (yalign < 0.5) | |
1382 | ret |= wxALIGN_TOP; | |
1383 | else if (yalign == 0.5) | |
1384 | ret |= wxALIGN_CENTER_VERTICAL; | |
1385 | else | |
1386 | ret |= wxALIGN_BOTTOM; | |
1387 | g_value_unset( &gvalue ); | |
1388 | ||
1389 | return ret; | |
1390 | } | |
1391 | ||
1392 | ||
1393 | ||
93763ad5 | 1394 | // --------------------------------------------------------- |
baa9ebc4 | 1395 | // wxDataViewTextRenderer |
93763ad5 | 1396 | // --------------------------------------------------------- |
6842a71a | 1397 | |
a7f61f76 | 1398 | extern "C" { |
93763ad5 | 1399 | static void wxGtkTextRendererEditedCallback( GtkCellRendererText *renderer, |
a7f61f76 RR |
1400 | gchar *arg1, gchar *arg2, gpointer user_data ); |
1401 | } | |
1402 | ||
93763ad5 | 1403 | static void wxGtkTextRendererEditedCallback( GtkCellRendererText *renderer, |
a7f61f76 RR |
1404 | gchar *arg1, gchar *arg2, gpointer user_data ) |
1405 | { | |
baa9ebc4 | 1406 | wxDataViewTextRenderer *cell = (wxDataViewTextRenderer*) user_data; |
93763ad5 | 1407 | |
1a74f561 | 1408 | wxString tmp = wxGTK_CONV_BACK_FONT(arg2, cell->GetOwner()->GetOwner()->GetFont()); |
a7f61f76 RR |
1409 | wxVariant value = tmp; |
1410 | if (!cell->Validate( value )) | |
1411 | return; | |
93763ad5 | 1412 | |
e0062c04 | 1413 | wxDataViewModel *model = cell->GetOwner()->GetOwner()->GetModel(); |
93763ad5 | 1414 | |
a7f61f76 | 1415 | GtkTreePath *path = gtk_tree_path_new_from_string( arg1 ); |
0a71f9e9 | 1416 | unsigned int model_row = (unsigned int)gtk_tree_path_get_indices (path)[0]; |
a7f61f76 | 1417 | gtk_tree_path_free( path ); |
93763ad5 | 1418 | |
0a71f9e9 | 1419 | unsigned int model_col = cell->GetOwner()->GetModelColumn(); |
93763ad5 | 1420 | |
a7f61f76 RR |
1421 | model->SetValue( value, model_col, model_row ); |
1422 | model->ValueChanged( model_col, model_row ); | |
1423 | } | |
1424 | ||
baa9ebc4 | 1425 | IMPLEMENT_CLASS(wxDataViewTextRenderer, wxDataViewRenderer) |
6842a71a | 1426 | |
9861f022 RR |
1427 | wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString &varianttype, wxDataViewCellMode mode, |
1428 | int align ) : | |
1429 | wxDataViewRenderer( varianttype, mode, align ) | |
6842a71a | 1430 | { |
ed38aa55 | 1431 | m_renderer = (GtkCellRenderer*) gtk_cell_renderer_text_new(); |
93763ad5 | 1432 | |
9861f022 | 1433 | if (mode & wxDATAVIEW_CELL_EDITABLE) |
a7f61f76 RR |
1434 | { |
1435 | GValue gvalue = { 0, }; | |
1436 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
1437 | g_value_set_boolean( &gvalue, true ); | |
1438 | g_object_set_property( G_OBJECT(m_renderer), "editable", &gvalue ); | |
1439 | g_value_unset( &gvalue ); | |
93763ad5 | 1440 | |
a7f61f76 RR |
1441 | g_signal_connect_after( m_renderer, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback), this ); |
1442 | } | |
9861f022 RR |
1443 | |
1444 | SetMode(mode); | |
1445 | SetAlignment(align); | |
6842a71a | 1446 | } |
790b137e | 1447 | |
baa9ebc4 | 1448 | bool wxDataViewTextRenderer::SetValue( const wxVariant &value ) |
7b4fde82 RR |
1449 | { |
1450 | wxString tmp = value; | |
93763ad5 | 1451 | |
7b4fde82 RR |
1452 | GValue gvalue = { 0, }; |
1453 | g_value_init( &gvalue, G_TYPE_STRING ); | |
b94db696 | 1454 | g_value_set_string( &gvalue, wxGTK_CONV_FONT( tmp, GetOwner()->GetOwner()->GetFont() ) ); |
7b4fde82 RR |
1455 | g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue ); |
1456 | g_value_unset( &gvalue ); | |
93763ad5 | 1457 | |
7b4fde82 RR |
1458 | return true; |
1459 | } | |
1460 | ||
9861f022 | 1461 | bool wxDataViewTextRenderer::GetValue( wxVariant &value ) const |
a7f61f76 RR |
1462 | { |
1463 | GValue gvalue = { 0, }; | |
1464 | g_value_init( &gvalue, G_TYPE_STRING ); | |
1465 | g_object_get_property( G_OBJECT(m_renderer), "text", &gvalue ); | |
1a74f561 VZ |
1466 | wxString tmp = wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue ), |
1467 | wx_const_cast(wxDataViewTextRenderer*, this)->GetOwner()->GetOwner()->GetFont() ); | |
a7f61f76 | 1468 | g_value_unset( &gvalue ); |
93763ad5 | 1469 | |
a7f61f76 RR |
1470 | value = tmp; |
1471 | ||
1472 | return true; | |
1473 | } | |
1474 | ||
9861f022 RR |
1475 | void wxDataViewTextRenderer::SetAlignment( int align ) |
1476 | { | |
1477 | wxDataViewRenderer::SetAlignment(align); | |
1478 | ||
01705e98 RR |
1479 | if (gtk_check_version(2,10,0)) |
1480 | return; | |
9861f022 | 1481 | |
01705e98 | 1482 | // horizontal alignment: |
9861f022 RR |
1483 | PangoAlignment pangoAlign = PANGO_ALIGN_LEFT; |
1484 | if (align & wxALIGN_RIGHT) | |
1485 | pangoAlign = PANGO_ALIGN_RIGHT; | |
1486 | else if (align & wxALIGN_CENTER_HORIZONTAL) | |
1487 | pangoAlign = PANGO_ALIGN_CENTER; | |
1488 | ||
1489 | GValue gvalue = { 0, }; | |
1490 | g_value_init( &gvalue, gtk_cell_renderer_mode_get_type() ); | |
1491 | g_value_set_enum( &gvalue, pangoAlign ); | |
1492 | g_object_set_property( G_OBJECT(m_renderer), "alignment", &gvalue ); | |
1493 | g_value_unset( &gvalue ); | |
1494 | } | |
1495 | ||
f4322df6 | 1496 | // --------------------------------------------------------- |
baa9ebc4 | 1497 | // wxDataViewBitmapRenderer |
f4322df6 | 1498 | // --------------------------------------------------------- |
cbc9145c | 1499 | |
baa9ebc4 | 1500 | IMPLEMENT_CLASS(wxDataViewBitmapRenderer, wxDataViewRenderer) |
cbc9145c | 1501 | |
9861f022 RR |
1502 | wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString &varianttype, wxDataViewCellMode mode, |
1503 | int align ) : | |
1504 | wxDataViewRenderer( varianttype, mode, align ) | |
cbc9145c | 1505 | { |
ed38aa55 | 1506 | m_renderer = (GtkCellRenderer*) gtk_cell_renderer_pixbuf_new(); |
9861f022 RR |
1507 | |
1508 | SetMode(mode); | |
1509 | SetAlignment(align); | |
cbc9145c RR |
1510 | } |
1511 | ||
baa9ebc4 | 1512 | bool wxDataViewBitmapRenderer::SetValue( const wxVariant &value ) |
cbc9145c RR |
1513 | { |
1514 | if (value.GetType() == wxT("wxBitmap")) | |
1515 | { | |
2586d4a1 RR |
1516 | wxBitmap bitmap; |
1517 | bitmap << value; | |
f4322df6 | 1518 | |
2586d4a1 RR |
1519 | // This may create a Pixbuf representation in the |
1520 | // wxBitmap object (and it will stay there) | |
1521 | GdkPixbuf *pixbuf = bitmap.GetPixbuf(); | |
f4322df6 | 1522 | |
2586d4a1 RR |
1523 | GValue gvalue = { 0, }; |
1524 | g_value_init( &gvalue, G_TYPE_OBJECT ); | |
1525 | g_value_set_object( &gvalue, pixbuf ); | |
1526 | g_object_set_property( G_OBJECT(m_renderer), "pixbuf", &gvalue ); | |
1527 | g_value_unset( &gvalue ); | |
f4322df6 | 1528 | |
2586d4a1 RR |
1529 | return true; |
1530 | } | |
f4322df6 | 1531 | |
2586d4a1 RR |
1532 | if (value.GetType() == wxT("wxIcon")) |
1533 | { | |
1534 | wxIcon bitmap; | |
1535 | bitmap << value; | |
f4322df6 | 1536 | |
cbc9145c RR |
1537 | // This may create a Pixbuf representation in the |
1538 | // wxBitmap object (and it will stay there) | |
2586d4a1 | 1539 | GdkPixbuf *pixbuf = bitmap.GetPixbuf(); |
f4322df6 | 1540 | |
cbc9145c RR |
1541 | GValue gvalue = { 0, }; |
1542 | g_value_init( &gvalue, G_TYPE_OBJECT ); | |
1543 | g_value_set_object( &gvalue, pixbuf ); | |
1544 | g_object_set_property( G_OBJECT(m_renderer), "pixbuf", &gvalue ); | |
1545 | g_value_unset( &gvalue ); | |
f4322df6 | 1546 | |
cbc9145c RR |
1547 | return true; |
1548 | } | |
f4322df6 | 1549 | |
cbc9145c RR |
1550 | return false; |
1551 | } | |
1552 | ||
9861f022 | 1553 | bool wxDataViewBitmapRenderer::GetValue( wxVariant &value ) const |
cbc9145c RR |
1554 | { |
1555 | return false; | |
1556 | } | |
f4322df6 | 1557 | |
93763ad5 | 1558 | // --------------------------------------------------------- |
baa9ebc4 | 1559 | // wxDataViewToggleRenderer |
93763ad5 | 1560 | // --------------------------------------------------------- |
fa28826d | 1561 | |
605c2c4a | 1562 | extern "C" { |
93763ad5 | 1563 | static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle *renderer, |
605c2c4a RR |
1564 | gchar *path, gpointer user_data ); |
1565 | } | |
1566 | ||
93763ad5 | 1567 | static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle *renderer, |
605c2c4a RR |
1568 | gchar *path, gpointer user_data ) |
1569 | { | |
baa9ebc4 | 1570 | wxDataViewToggleRenderer *cell = (wxDataViewToggleRenderer*) user_data; |
605c2c4a | 1571 | |
93763ad5 | 1572 | // get old value |
605c2c4a RR |
1573 | GValue gvalue = { 0, }; |
1574 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
1575 | g_object_get_property( G_OBJECT(renderer), "active", &gvalue ); | |
93763ad5 | 1576 | bool tmp = g_value_get_boolean( &gvalue ); |
605c2c4a RR |
1577 | g_value_unset( &gvalue ); |
1578 | // invert it | |
1579 | tmp = !tmp; | |
93763ad5 | 1580 | |
605c2c4a RR |
1581 | wxVariant value = tmp; |
1582 | if (!cell->Validate( value )) | |
1583 | return; | |
93763ad5 | 1584 | |
e0062c04 | 1585 | wxDataViewModel *model = cell->GetOwner()->GetOwner()->GetModel(); |
93763ad5 | 1586 | |
605c2c4a | 1587 | GtkTreePath *gtk_path = gtk_tree_path_new_from_string( path ); |
0a71f9e9 | 1588 | unsigned int model_row = (unsigned int)gtk_tree_path_get_indices (gtk_path)[0]; |
605c2c4a | 1589 | gtk_tree_path_free( gtk_path ); |
93763ad5 | 1590 | |
0a71f9e9 | 1591 | unsigned int model_col = cell->GetOwner()->GetModelColumn(); |
93763ad5 | 1592 | |
605c2c4a RR |
1593 | model->SetValue( value, model_col, model_row ); |
1594 | model->ValueChanged( model_col, model_row ); | |
1595 | } | |
1596 | ||
baa9ebc4 | 1597 | IMPLEMENT_CLASS(wxDataViewToggleRenderer, wxDataViewRenderer) |
605c2c4a | 1598 | |
baa9ebc4 | 1599 | wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString &varianttype, |
9861f022 RR |
1600 | wxDataViewCellMode mode, int align ) : |
1601 | wxDataViewRenderer( varianttype, mode, align ) | |
605c2c4a | 1602 | { |
ed38aa55 | 1603 | m_renderer = (GtkCellRenderer*) gtk_cell_renderer_toggle_new(); |
93763ad5 | 1604 | |
9861f022 | 1605 | if (mode & wxDATAVIEW_CELL_ACTIVATABLE) |
605c2c4a | 1606 | { |
9861f022 RR |
1607 | g_signal_connect_after( m_renderer, "toggled", |
1608 | G_CALLBACK(wxGtkToggleRendererToggledCallback), this ); | |
553f7d8f RR |
1609 | } |
1610 | else | |
1611 | { | |
605c2c4a RR |
1612 | GValue gvalue = { 0, }; |
1613 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
553f7d8f | 1614 | g_value_set_boolean( &gvalue, false ); |
605c2c4a RR |
1615 | g_object_set_property( G_OBJECT(m_renderer), "activatable", &gvalue ); |
1616 | g_value_unset( &gvalue ); | |
605c2c4a | 1617 | } |
9861f022 RR |
1618 | |
1619 | SetMode(mode); | |
1620 | SetAlignment(align); | |
605c2c4a RR |
1621 | } |
1622 | ||
baa9ebc4 | 1623 | bool wxDataViewToggleRenderer::SetValue( const wxVariant &value ) |
605c2c4a RR |
1624 | { |
1625 | bool tmp = value; | |
93763ad5 | 1626 | |
605c2c4a RR |
1627 | GValue gvalue = { 0, }; |
1628 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
1629 | g_value_set_boolean( &gvalue, tmp ); | |
1630 | g_object_set_property( G_OBJECT(m_renderer), "active", &gvalue ); | |
1631 | g_value_unset( &gvalue ); | |
93763ad5 | 1632 | |
605c2c4a RR |
1633 | return true; |
1634 | } | |
1635 | ||
9861f022 | 1636 | bool wxDataViewToggleRenderer::GetValue( wxVariant &value ) const |
605c2c4a RR |
1637 | { |
1638 | GValue gvalue = { 0, }; | |
1639 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
1640 | g_object_get_property( G_OBJECT(m_renderer), "active", &gvalue ); | |
93763ad5 | 1641 | bool tmp = g_value_get_boolean( &gvalue ); |
605c2c4a | 1642 | g_value_unset( &gvalue ); |
93763ad5 | 1643 | |
605c2c4a RR |
1644 | value = tmp; |
1645 | ||
1646 | return true; | |
1647 | } | |
93763ad5 WS |
1648 | |
1649 | // --------------------------------------------------------- | |
baa9ebc4 | 1650 | // wxDataViewCustomRenderer |
93763ad5 | 1651 | // --------------------------------------------------------- |
e152afc3 RR |
1652 | |
1653 | class wxDataViewCtrlDC: public wxWindowDC | |
1654 | { | |
1655 | public: | |
1656 | wxDataViewCtrlDC( wxDataViewCtrl *window ) | |
1657 | { | |
1a367564 | 1658 | GtkWidget *widget = window->m_treeview; |
e152afc3 RR |
1659 | // Set later |
1660 | m_window = NULL; | |
4d496ecb | 1661 | |
e152afc3 RR |
1662 | m_context = window->GtkGetPangoDefaultContext(); |
1663 | m_layout = pango_layout_new( m_context ); | |
1664 | m_fontdesc = pango_font_description_copy( widget->style->font_desc ); | |
1665 | ||
1666 | m_cmap = gtk_widget_get_colormap( widget ? widget : window->m_widget ); | |
1667 | ||
4d496ecb RR |
1668 | // Set m_window later |
1669 | // SetUpDC(); | |
1670 | // m_owner = window; | |
e152afc3 RR |
1671 | } |
1672 | }; | |
1673 | ||
93763ad5 | 1674 | // --------------------------------------------------------- |
baa9ebc4 | 1675 | // wxDataViewCustomRenderer |
93763ad5 | 1676 | // --------------------------------------------------------- |
e152afc3 | 1677 | |
baa9ebc4 | 1678 | IMPLEMENT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer) |
e152afc3 | 1679 | |
baa9ebc4 | 1680 | wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype, |
9861f022 RR |
1681 | wxDataViewCellMode mode, int align, |
1682 | bool no_init ) : | |
1683 | wxDataViewRenderer( varianttype, mode, align ) | |
e152afc3 RR |
1684 | { |
1685 | m_dc = NULL; | |
93763ad5 | 1686 | |
ad63bf41 RR |
1687 | if (no_init) |
1688 | m_renderer = NULL; | |
1689 | else | |
9861f022 | 1690 | Init(mode, align); |
ad63bf41 RR |
1691 | } |
1692 | ||
9861f022 | 1693 | bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode, int align) |
ad63bf41 | 1694 | { |
e152afc3 RR |
1695 | GtkWxCellRenderer *renderer = (GtkWxCellRenderer *) gtk_wx_cell_renderer_new(); |
1696 | renderer->cell = this; | |
93763ad5 | 1697 | |
ed38aa55 | 1698 | m_renderer = (GtkCellRenderer*) renderer; |
93763ad5 | 1699 | |
9861f022 RR |
1700 | SetMode(mode); |
1701 | SetAlignment(align); | |
93763ad5 | 1702 | |
ad63bf41 | 1703 | return true; |
e152afc3 RR |
1704 | } |
1705 | ||
baa9ebc4 | 1706 | wxDataViewCustomRenderer::~wxDataViewCustomRenderer() |
e152afc3 RR |
1707 | { |
1708 | if (m_dc) | |
1709 | delete m_dc; | |
1710 | } | |
1711 | ||
baa9ebc4 | 1712 | wxDC *wxDataViewCustomRenderer::GetDC() |
e152afc3 RR |
1713 | { |
1714 | if (m_dc == NULL) | |
4d496ecb RR |
1715 | { |
1716 | if (GetOwner() == NULL) | |
1717 | return NULL; | |
1718 | if (GetOwner()->GetOwner() == NULL) | |
1719 | return NULL; | |
e152afc3 | 1720 | m_dc = new wxDataViewCtrlDC( GetOwner()->GetOwner() ); |
4d496ecb | 1721 | } |
93763ad5 | 1722 | |
e152afc3 RR |
1723 | return m_dc; |
1724 | } | |
93763ad5 WS |
1725 | |
1726 | // --------------------------------------------------------- | |
baa9ebc4 | 1727 | // wxDataViewProgressRenderer |
93763ad5 | 1728 | // --------------------------------------------------------- |
ad63bf41 | 1729 | |
baa9ebc4 | 1730 | IMPLEMENT_CLASS(wxDataViewProgressRenderer, wxDataViewCustomRenderer) |
ad63bf41 | 1731 | |
baa9ebc4 | 1732 | wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString &label, |
9861f022 RR |
1733 | const wxString &varianttype, wxDataViewCellMode mode, int align ) : |
1734 | wxDataViewCustomRenderer( varianttype, mode, align, true ) | |
ad63bf41 RR |
1735 | { |
1736 | m_label = label; | |
1737 | m_value = 0; | |
93763ad5 | 1738 | |
ad63bf41 RR |
1739 | #ifdef __WXGTK26__ |
1740 | if (!gtk_check_version(2,6,0)) | |
1741 | { | |
ed38aa55 | 1742 | m_renderer = (GtkCellRenderer*) gtk_cell_renderer_progress_new(); |
93763ad5 | 1743 | |
ad63bf41 RR |
1744 | GValue gvalue = { 0, }; |
1745 | g_value_init( &gvalue, G_TYPE_STRING ); | |
09dfa6a0 VZ |
1746 | |
1747 | // FIXME: font encoding support | |
b94db696 | 1748 | g_value_set_string( &gvalue, wxGTK_CONV_SYS(m_label) ); |
ad63bf41 RR |
1749 | g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue ); |
1750 | g_value_unset( &gvalue ); | |
9861f022 RR |
1751 | |
1752 | SetMode(mode); | |
1753 | SetAlignment(align); | |
ad63bf41 RR |
1754 | } |
1755 | else | |
1756 | #endif | |
1757 | { | |
1758 | // Use custom cell code | |
9861f022 | 1759 | wxDataViewCustomRenderer::Init(mode, align); |
ad63bf41 RR |
1760 | } |
1761 | } | |
1762 | ||
baa9ebc4 | 1763 | wxDataViewProgressRenderer::~wxDataViewProgressRenderer() |
ad63bf41 RR |
1764 | { |
1765 | } | |
1766 | ||
baa9ebc4 | 1767 | bool wxDataViewProgressRenderer::SetValue( const wxVariant &value ) |
ad63bf41 RR |
1768 | { |
1769 | #ifdef __WXGTK26__ | |
1770 | if (!gtk_check_version(2,6,0)) | |
1771 | { | |
7226118b | 1772 | gint tmp = (long) value; |
ad63bf41 RR |
1773 | GValue gvalue = { 0, }; |
1774 | g_value_init( &gvalue, G_TYPE_INT ); | |
7226118b | 1775 | g_value_set_int( &gvalue, tmp ); |
ad63bf41 RR |
1776 | g_object_set_property( G_OBJECT(m_renderer), "value", &gvalue ); |
1777 | g_value_unset( &gvalue ); | |
1778 | } | |
1779 | else | |
1780 | #endif | |
1781 | { | |
1782 | m_value = (long) value; | |
93763ad5 | 1783 | |
ad63bf41 RR |
1784 | if (m_value < 0) m_value = 0; |
1785 | if (m_value > 100) m_value = 100; | |
1786 | } | |
93763ad5 | 1787 | |
ad63bf41 RR |
1788 | return true; |
1789 | } | |
93763ad5 | 1790 | |
9861f022 RR |
1791 | bool wxDataViewProgressRenderer::GetValue( wxVariant &value ) const |
1792 | { | |
1793 | return false; | |
1794 | } | |
1795 | ||
baa9ebc4 | 1796 | bool wxDataViewProgressRenderer::Render( wxRect cell, wxDC *dc, int state ) |
ad63bf41 RR |
1797 | { |
1798 | double pct = (double)m_value / 100.0; | |
1799 | wxRect bar = cell; | |
1800 | bar.width = (int)(cell.width * pct); | |
1801 | dc->SetPen( *wxTRANSPARENT_PEN ); | |
1802 | dc->SetBrush( *wxBLUE_BRUSH ); | |
1803 | dc->DrawRectangle( bar ); | |
1804 | ||
1805 | dc->SetBrush( *wxTRANSPARENT_BRUSH ); | |
1806 | dc->SetPen( *wxBLACK_PEN ); | |
1807 | dc->DrawRectangle( cell ); | |
93763ad5 | 1808 | |
ad63bf41 RR |
1809 | return true; |
1810 | } | |
1811 | ||
9861f022 | 1812 | wxSize wxDataViewProgressRenderer::GetSize() const |
ad63bf41 RR |
1813 | { |
1814 | return wxSize(40,12); | |
1815 | } | |
93763ad5 WS |
1816 | |
1817 | // --------------------------------------------------------- | |
baa9ebc4 | 1818 | // wxDataViewDateRenderer |
93763ad5 | 1819 | // --------------------------------------------------------- |
4d496ecb | 1820 | |
baa9ebc4 | 1821 | class wxDataViewDateRendererPopupTransient: public wxPopupTransientWindow |
7ea3a0de | 1822 | { |
93763ad5 | 1823 | public: |
baa9ebc4 | 1824 | wxDataViewDateRendererPopupTransient( wxWindow* parent, wxDateTime *value, |
e0062c04 | 1825 | wxDataViewModel *model, const wxDataViewItem &item, unsigned int col ) : |
7ea3a0de RR |
1826 | wxPopupTransientWindow( parent, wxBORDER_SIMPLE ) |
1827 | { | |
1828 | m_model = model; | |
e0062c04 | 1829 | m_item = item; |
7ea3a0de | 1830 | m_col = col; |
7ea3a0de RR |
1831 | m_cal = new wxCalendarCtrl( this, -1, *value ); |
1832 | wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL ); | |
1833 | sizer->Add( m_cal, 1, wxGROW ); | |
1834 | SetSizer( sizer ); | |
1835 | sizer->Fit( this ); | |
1836 | } | |
93763ad5 | 1837 | |
7ea3a0de RR |
1838 | virtual void OnDismiss() |
1839 | { | |
1840 | } | |
93763ad5 | 1841 | |
7ea3a0de | 1842 | void OnCalendar( wxCalendarEvent &event ); |
93763ad5 | 1843 | |
e0062c04 RR |
1844 | wxCalendarCtrl *m_cal; |
1845 | wxDataViewModel *m_model; | |
1846 | wxDataViewItem m_item; | |
1847 | unsigned int m_col; | |
93763ad5 | 1848 | |
7ea3a0de RR |
1849 | private: |
1850 | DECLARE_EVENT_TABLE() | |
1851 | }; | |
1852 | ||
baa9ebc4 RR |
1853 | BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient,wxPopupTransientWindow) |
1854 | EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar ) | |
7ea3a0de RR |
1855 | END_EVENT_TABLE() |
1856 | ||
baa9ebc4 | 1857 | void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent &event ) |
7ea3a0de RR |
1858 | { |
1859 | wxDateTime date = event.GetDate(); | |
1860 | wxVariant value = date; | |
e0062c04 RR |
1861 | m_model->SetValue( value, m_item, m_col ); |
1862 | m_model->ValueChanged( m_item, m_col ); | |
7ea3a0de RR |
1863 | DismissAndNotify(); |
1864 | } | |
1865 | ||
baa9ebc4 | 1866 | IMPLEMENT_CLASS(wxDataViewDateRenderer, wxDataViewCustomRenderer) |
4d496ecb | 1867 | |
baa9ebc4 | 1868 | wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString &varianttype, |
9861f022 RR |
1869 | wxDataViewCellMode mode, int align ) : |
1870 | wxDataViewCustomRenderer( varianttype, mode, align ) | |
4d496ecb | 1871 | { |
9861f022 RR |
1872 | SetMode(mode); |
1873 | SetAlignment(align); | |
4d496ecb | 1874 | } |
93763ad5 | 1875 | |
baa9ebc4 | 1876 | bool wxDataViewDateRenderer::SetValue( const wxVariant &value ) |
4d496ecb RR |
1877 | { |
1878 | m_date = value.GetDateTime(); | |
93763ad5 | 1879 | |
4d496ecb RR |
1880 | return true; |
1881 | } | |
1882 | ||
9861f022 RR |
1883 | bool wxDataViewDateRenderer::GetValue( wxVariant &value ) const |
1884 | { | |
1885 | return false; | |
1886 | } | |
1887 | ||
baa9ebc4 | 1888 | bool wxDataViewDateRenderer::Render( wxRect cell, wxDC *dc, int state ) |
4d496ecb RR |
1889 | { |
1890 | dc->SetFont( GetOwner()->GetOwner()->GetFont() ); | |
1891 | wxString tmp = m_date.FormatDate(); | |
1892 | dc->DrawText( tmp, cell.x, cell.y ); | |
1893 | ||
1894 | return true; | |
1895 | } | |
1896 | ||
9861f022 | 1897 | wxSize wxDataViewDateRenderer::GetSize() const |
4d496ecb | 1898 | { |
4d496ecb RR |
1899 | wxString tmp = m_date.FormatDate(); |
1900 | wxCoord x,y,d; | |
9861f022 | 1901 | GetView()->GetTextExtent( tmp, &x, &y, &d ); |
4d496ecb RR |
1902 | return wxSize(x,y+d); |
1903 | } | |
1904 | ||
e0062c04 RR |
1905 | bool wxDataViewDateRenderer::Activate( wxRect cell, wxDataViewModel *model, |
1906 | const wxDataViewItem &item, unsigned int col ) | |
4d496ecb | 1907 | { |
3f3af7e7 | 1908 | wxVariant variant; |
e0062c04 | 1909 | model->GetValue( variant, item, col ); |
7ea3a0de RR |
1910 | wxDateTime value = variant.GetDateTime(); |
1911 | ||
baa9ebc4 | 1912 | wxDataViewDateRendererPopupTransient *popup = new wxDataViewDateRendererPopupTransient( |
e0062c04 | 1913 | GetOwner()->GetOwner()->GetParent(), &value, model, item, col ); |
7ea3a0de RR |
1914 | wxPoint pos = wxGetMousePosition(); |
1915 | popup->Move( pos ); | |
1916 | popup->Layout(); | |
1917 | popup->Popup( popup->m_cal ); | |
4d496ecb RR |
1918 | |
1919 | return true; | |
1920 | } | |
1921 | ||
93763ad5 | 1922 | // --------------------------------------------------------- |
605c2c4a | 1923 | // wxDataViewColumn |
93763ad5 | 1924 | // --------------------------------------------------------- |
7b4fde82 | 1925 | |
31fb32e1 RR |
1926 | |
1927 | static gboolean | |
1928 | gtk_dataview_header_button_press_callback( GtkWidget *widget, | |
1929 | GdkEventButton *gdk_event, | |
1930 | wxDataViewColumn *column ) | |
1931 | { | |
1932 | if (gdk_event->type != GDK_BUTTON_PRESS) | |
94b1f7bc | 1933 | return FALSE; |
f4322df6 | 1934 | |
31fb32e1 RR |
1935 | if (gdk_event->button == 1) |
1936 | { | |
1937 | wxDataViewCtrl *dv = column->GetOwner(); | |
1938 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, dv->GetId() ); | |
1939 | event.SetDataViewColumn( column ); | |
1940 | event.SetModel( dv->GetModel() ); | |
94b1f7bc RR |
1941 | if (dv->GetEventHandler()->ProcessEvent( event )) |
1942 | return TRUE; | |
31fb32e1 | 1943 | } |
f4322df6 | 1944 | |
94b1f7bc | 1945 | return FALSE; |
31fb32e1 RR |
1946 | } |
1947 | ||
7b4fde82 RR |
1948 | extern "C" { |
1949 | static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column, | |
1950 | GtkCellRenderer *cell, | |
1951 | GtkTreeModel *model, | |
1952 | GtkTreeIter *iter, | |
1953 | gpointer data ); | |
1954 | } | |
1955 | ||
1956 | ||
1957 | static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column, | |
1958 | GtkCellRenderer *renderer, | |
1959 | GtkTreeModel *model, | |
1960 | GtkTreeIter *iter, | |
1961 | gpointer data ) | |
1962 | { | |
e0062c04 RR |
1963 | g_return_if_fail (GTK_IS_WX_TREE_MODEL (model)); |
1964 | GtkWxTreeModel *tree_model = (GtkWxTreeModel *) model; | |
93763ad5 | 1965 | |
baa9ebc4 | 1966 | wxDataViewRenderer *cell = (wxDataViewRenderer*) data; |
a7f61f76 | 1967 | |
e0062c04 | 1968 | wxDataViewItem item( (wxUint32) iter->user_data ); |
93763ad5 | 1969 | |
3f3af7e7 | 1970 | wxVariant value; |
d5025dc0 | 1971 | tree_model->model->GetDataViewModel()->GetValue( value, item, cell->GetOwner()->GetModelColumn() ); |
7b4fde82 RR |
1972 | |
1973 | if (value.GetType() != cell->GetVariantType()) | |
f4322df6 VZ |
1974 | wxLogError( wxT("Wrong type, required: %s but: %s"), |
1975 | value.GetType().c_str(), | |
cbc9145c | 1976 | cell->GetVariantType().c_str() ); |
93763ad5 | 1977 | |
7b4fde82 | 1978 | cell->SetValue( value ); |
e0743e63 | 1979 | |
e0062c04 | 1980 | #if 0 |
2a5e6d1b | 1981 | wxListItemAttr attr; |
e0062c04 | 1982 | tree_model->model->GetAttr( attr, cell->GetOwner()->GetModelColumn(), model_row ); |
2a5e6d1b RR |
1983 | |
1984 | if (attr.HasBackgroundColour()) | |
1985 | { | |
1986 | wxColour colour = attr.GetBackgroundColour(); | |
1cd5e95c | 1987 | const GdkColor * const gcol = colour.GetColor(); |
e0743e63 | 1988 | |
2a5e6d1b RR |
1989 | GValue gvalue = { 0, }; |
1990 | g_value_init( &gvalue, GDK_TYPE_COLOR ); | |
1991 | g_value_set_boxed( &gvalue, gcol ); | |
1992 | g_object_set_property( G_OBJECT(renderer), "cell-background_gdk", &gvalue ); | |
1993 | g_value_unset( &gvalue ); | |
1994 | } | |
1995 | else | |
1996 | { | |
1997 | GValue gvalue = { 0, }; | |
1998 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
1999 | g_value_set_boolean( &gvalue, FALSE ); | |
2000 | g_object_set_property( G_OBJECT(renderer), "cell-background-set", &gvalue ); | |
2001 | g_value_unset( &gvalue ); | |
2002 | } | |
e0062c04 RR |
2003 | #endif |
2004 | ||
7b4fde82 RR |
2005 | } |
2006 | ||
cbc9145c | 2007 | IMPLEMENT_CLASS(wxDataViewColumn, wxDataViewColumnBase) |
fa28826d | 2008 | |
f4322df6 VZ |
2009 | wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewRenderer *cell, |
2010 | unsigned int model_column, int width, | |
87f0efe2 RR |
2011 | wxAlignment align, int flags ) : |
2012 | wxDataViewColumnBase( title, cell, model_column, width, align, flags ) | |
fa28826d | 2013 | { |
9861f022 | 2014 | Init( align, flags, width ); |
31fb32e1 | 2015 | |
9861f022 | 2016 | gtk_tree_view_column_set_clickable( GTK_TREE_VIEW_COLUMN(m_column), TRUE ); |
31fb32e1 | 2017 | SetTitle( title ); |
fa28826d RR |
2018 | } |
2019 | ||
f4322df6 VZ |
2020 | wxDataViewColumn::wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *cell, |
2021 | unsigned int model_column, int width, | |
87f0efe2 RR |
2022 | wxAlignment align, int flags ) : |
2023 | wxDataViewColumnBase( bitmap, cell, model_column, width, align, flags ) | |
9861f022 RR |
2024 | { |
2025 | Init( align, flags, width ); | |
2026 | ||
2027 | SetBitmap( bitmap ); | |
2028 | } | |
2029 | ||
2030 | void wxDataViewColumn::Init(wxAlignment align, int flags, int width) | |
07a84e7b | 2031 | { |
31fb32e1 | 2032 | m_isConnected = false; |
07a84e7b | 2033 | |
9861f022 | 2034 | GtkCellRenderer *renderer = (GtkCellRenderer *) GetRenderer()->GetGtkHandle(); |
07a84e7b | 2035 | GtkTreeViewColumn *column = gtk_tree_view_column_new(); |
9861f022 | 2036 | m_column = (GtkWidget*) column; |
07a84e7b | 2037 | |
9861f022 RR |
2038 | SetFlags( flags ); |
2039 | SetAlignment( align ); | |
07a84e7b | 2040 | |
9861f022 RR |
2041 | // NOTE: we prefer not to call SetMinWidth(wxDVC_DEFAULT_MINWIDTH); |
2042 | // as GTK+ is smart and unless explicitely told, will set the minimal | |
2043 | // width to the title's lenght, which is a better default | |
07a84e7b | 2044 | |
9861f022 RR |
2045 | // the GTK_TREE_VIEW_COLUMN_FIXED is required by the "fixed height" mode |
2046 | // that we use for the wxDataViewCtrl | |
2047 | gtk_tree_view_column_set_fixed_width( column, width < 0 ? wxDVC_DEFAULT_WIDTH : width ); | |
b94db696 | 2048 | gtk_tree_view_column_set_sizing( column, GTK_TREE_VIEW_COLUMN_FIXED ); |
07a84e7b | 2049 | |
9861f022 | 2050 | gtk_tree_view_column_pack_end( column, renderer, TRUE ); |
07a84e7b RR |
2051 | |
2052 | gtk_tree_view_column_set_cell_data_func( column, renderer, | |
9861f022 | 2053 | wxGtkTreeCellDataFunc, (gpointer) GetRenderer(), NULL ); |
07a84e7b RR |
2054 | } |
2055 | ||
fa28826d RR |
2056 | wxDataViewColumn::~wxDataViewColumn() |
2057 | { | |
2058 | } | |
2059 | ||
31fb32e1 RR |
2060 | void wxDataViewColumn::OnInternalIdle() |
2061 | { | |
2062 | if (m_isConnected) | |
2063 | return; | |
f4322df6 | 2064 | |
31fb32e1 RR |
2065 | if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview)) |
2066 | { | |
9861f022 | 2067 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
31fb32e1 RR |
2068 | if (column->button) |
2069 | { | |
2070 | g_signal_connect(column->button, "button_press_event", | |
2071 | G_CALLBACK (gtk_dataview_header_button_press_callback), this); | |
f4322df6 | 2072 | |
31fb32e1 RR |
2073 | m_isConnected = true; |
2074 | } | |
2075 | } | |
2076 | } | |
2077 | ||
b94db696 RR |
2078 | void wxDataViewColumn::SetOwner( wxDataViewCtrl *owner ) |
2079 | { | |
2080 | wxDataViewColumnBase::SetOwner( owner ); | |
f4322df6 | 2081 | |
9861f022 | 2082 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
f4322df6 | 2083 | |
b94db696 | 2084 | gtk_tree_view_column_set_title( column, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) ); |
b94db696 RR |
2085 | } |
2086 | ||
fa28826d RR |
2087 | void wxDataViewColumn::SetTitle( const wxString &title ) |
2088 | { | |
9861f022 | 2089 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
f4322df6 | 2090 | |
31fb32e1 RR |
2091 | if (m_isConnected) |
2092 | { | |
2093 | // disconnect before column->button gets recreated | |
f4322df6 | 2094 | g_signal_handlers_disconnect_by_func( column->button, |
9861f022 | 2095 | (GtkWidget*) gtk_dataview_header_button_press_callback, this); |
f4322df6 | 2096 | |
31fb32e1 RR |
2097 | m_isConnected = false; |
2098 | } | |
2099 | ||
09dfa6a0 VZ |
2100 | // FIXME: can it really happen that we don't have the owner here?? |
2101 | wxDataViewCtrl *ctrl = GetOwner(); | |
2102 | gtk_tree_view_column_set_title( column, ctrl ? wxGTK_CONV_FONT(title, ctrl->GetFont()) | |
2103 | : wxGTK_CONV_SYS(title) ); | |
31fb32e1 | 2104 | |
07a84e7b RR |
2105 | gtk_tree_view_column_set_widget( column, NULL ); |
2106 | } | |
2107 | ||
9861f022 RR |
2108 | wxString wxDataViewColumn::GetTitle() const |
2109 | { | |
2110 | const gchar *str = gtk_tree_view_column_get_title( GTK_TREE_VIEW_COLUMN(m_column) ); | |
2111 | return wxConvFileName->cMB2WX(str); | |
2112 | } | |
2113 | ||
07a84e7b RR |
2114 | void wxDataViewColumn::SetBitmap( const wxBitmap &bitmap ) |
2115 | { | |
2116 | wxDataViewColumnBase::SetBitmap( bitmap ); | |
2117 | ||
9861f022 | 2118 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
07a84e7b RR |
2119 | if (bitmap.Ok()) |
2120 | { | |
2121 | GtkImage *gtk_image = GTK_IMAGE( gtk_image_new() ); | |
f4322df6 | 2122 | |
07a84e7b RR |
2123 | GdkBitmap *mask = (GdkBitmap *) NULL; |
2124 | if (bitmap.GetMask()) | |
2125 | mask = bitmap.GetMask()->GetBitmap(); | |
2126 | ||
2127 | if (bitmap.HasPixbuf()) | |
2128 | { | |
2129 | gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image), | |
2130 | bitmap.GetPixbuf()); | |
2131 | } | |
2132 | else | |
2133 | { | |
2134 | gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image), | |
2135 | bitmap.GetPixmap(), mask); | |
2136 | } | |
2137 | gtk_widget_show( GTK_WIDGET(gtk_image) ); | |
f4322df6 | 2138 | |
07a84e7b RR |
2139 | gtk_tree_view_column_set_widget( column, GTK_WIDGET(gtk_image) ); |
2140 | } | |
2141 | else | |
2142 | { | |
2143 | gtk_tree_view_column_set_widget( column, NULL ); | |
2144 | } | |
fa28826d RR |
2145 | } |
2146 | ||
9861f022 RR |
2147 | void wxDataViewColumn::SetHidden( bool hidden ) |
2148 | { | |
2149 | gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column), !hidden ); | |
2150 | } | |
2151 | ||
2152 | void wxDataViewColumn::SetResizeable( bool resizeable ) | |
2153 | { | |
2154 | gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column), resizeable ); | |
2155 | } | |
2156 | ||
47cef10f RR |
2157 | void wxDataViewColumn::SetAlignment( wxAlignment align ) |
2158 | { | |
9861f022 | 2159 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
f4322df6 | 2160 | |
47cef10f RR |
2161 | gfloat xalign = 0.0; |
2162 | if (align == wxALIGN_RIGHT) | |
2163 | xalign = 1.0; | |
9861f022 RR |
2164 | if (align == wxALIGN_CENTER_HORIZONTAL || |
2165 | align == wxALIGN_CENTER) | |
47cef10f | 2166 | xalign = 0.5; |
f4322df6 | 2167 | |
9861f022 RR |
2168 | gtk_tree_view_column_set_alignment( column, xalign ); |
2169 | } | |
2170 | ||
2171 | wxAlignment wxDataViewColumn::GetAlignment() const | |
2172 | { | |
2173 | gfloat xalign = gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column) ); | |
2174 | ||
2175 | if (xalign == 1.0) | |
2176 | return wxALIGN_RIGHT; | |
2177 | if (xalign == 0.5) | |
2178 | return wxALIGN_CENTER_HORIZONTAL; | |
f4322df6 | 2179 | |
9861f022 | 2180 | return wxALIGN_LEFT; |
47cef10f RR |
2181 | } |
2182 | ||
31fb32e1 RR |
2183 | void wxDataViewColumn::SetSortable( bool sortable ) |
2184 | { | |
9861f022 | 2185 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
94b1f7bc RR |
2186 | |
2187 | if (sortable) | |
2188 | gtk_tree_view_column_set_sort_column_id( column, GetModelColumn() ); | |
2189 | else | |
2190 | gtk_tree_view_column_set_sort_column_id( column, -1 ); | |
31fb32e1 RR |
2191 | } |
2192 | ||
87f0efe2 | 2193 | bool wxDataViewColumn::IsSortable() const |
31fb32e1 | 2194 | { |
9861f022 | 2195 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
94b1f7bc | 2196 | return (gtk_tree_view_column_get_sort_column_id( column ) != -1); |
31fb32e1 RR |
2197 | } |
2198 | ||
9861f022 RR |
2199 | bool wxDataViewColumn::IsResizeable() const |
2200 | { | |
2201 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); | |
2202 | return gtk_tree_view_column_get_resizable( column ); | |
2203 | } | |
2204 | ||
2205 | bool wxDataViewColumn::IsHidden() const | |
2206 | { | |
2207 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); | |
2208 | return !gtk_tree_view_column_get_visible( column ); | |
2209 | } | |
2210 | ||
47cef10f RR |
2211 | void wxDataViewColumn::SetSortOrder( bool ascending ) |
2212 | { | |
9861f022 | 2213 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
f4322df6 | 2214 | |
47cef10f RR |
2215 | if (ascending) |
2216 | gtk_tree_view_column_set_sort_order( column, GTK_SORT_ASCENDING ); | |
2217 | else | |
2218 | gtk_tree_view_column_set_sort_order( column, GTK_SORT_DESCENDING ); | |
2219 | } | |
2220 | ||
87f0efe2 | 2221 | bool wxDataViewColumn::IsSortOrderAscending() const |
31fb32e1 | 2222 | { |
9861f022 | 2223 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
f4322df6 | 2224 | |
31fb32e1 RR |
2225 | return (gtk_tree_view_column_get_sort_order( column ) != GTK_SORT_DESCENDING); |
2226 | } | |
2227 | ||
9861f022 | 2228 | void wxDataViewColumn::SetMinWidth( int width ) |
533544f2 | 2229 | { |
9861f022 | 2230 | gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column), width ); |
533544f2 RR |
2231 | } |
2232 | ||
9861f022 RR |
2233 | int wxDataViewColumn::GetMinWidth() const |
2234 | { | |
2235 | return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column) ); | |
2236 | } | |
2237 | ||
2238 | int wxDataViewColumn::GetWidth() const | |
533544f2 | 2239 | { |
9861f022 | 2240 | return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column) ); |
533544f2 RR |
2241 | } |
2242 | ||
9861f022 | 2243 | void wxDataViewColumn::SetWidth( int width ) |
533544f2 | 2244 | { |
9861f022 | 2245 | gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column), width ); |
533544f2 RR |
2246 | } |
2247 | ||
9861f022 | 2248 | |
eb7f97f8 RR |
2249 | //----------------------------------------------------------------------------- |
2250 | // wxDataViewCtrl signal callbacks | |
2251 | //----------------------------------------------------------------------------- | |
2252 | ||
2253 | static void | |
2254 | wxdataview_selection_changed_callback( GtkTreeSelection* selection, wxDataViewCtrl *dv ) | |
2255 | { | |
b94db696 RR |
2256 | if (!GTK_WIDGET_REALIZED(dv->m_widget)) |
2257 | return; | |
f4322df6 | 2258 | |
e0062c04 RR |
2259 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_SELECTED, dv->GetId() ); |
2260 | // TODO: item | |
eb7f97f8 RR |
2261 | event.SetModel( dv->GetModel() ); |
2262 | dv->GetEventHandler()->ProcessEvent( event ); | |
2263 | } | |
2264 | ||
f828871d | 2265 | static void |
f4322df6 | 2266 | wxdataview_row_activated_callback( GtkTreeView* treeview, GtkTreePath *path, |
f828871d RR |
2267 | GtkTreeViewColumn *column, wxDataViewCtrl *dv ) |
2268 | { | |
e0062c04 RR |
2269 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, dv->GetId() ); |
2270 | // TODO: item | |
f828871d RR |
2271 | event.SetModel( dv->GetModel() ); |
2272 | dv->GetEventHandler()->ProcessEvent( event ); | |
2273 | } | |
2274 | ||
790b137e RR |
2275 | //----------------------------------------------------------------------------- |
2276 | // wxDataViewCtrl | |
2277 | //----------------------------------------------------------------------------- | |
2278 | ||
1e510b1e RR |
2279 | //----------------------------------------------------------------------------- |
2280 | // InsertChild for wxDataViewCtrl | |
2281 | //----------------------------------------------------------------------------- | |
2282 | ||
2283 | static void wxInsertChildInDataViewCtrl( wxWindowGTK* parent, wxWindowGTK* child ) | |
2284 | { | |
2285 | wxDataViewCtrl * dvc = (wxDataViewCtrl*) parent; | |
2286 | GtkWidget *treeview = dvc->GtkGetTreeView(); | |
2287 | ||
2288 | // Insert widget in GtkTreeView | |
2289 | if (GTK_WIDGET_REALIZED(treeview)) | |
e8375af8 | 2290 | gtk_widget_set_parent_window( child->m_widget, |
1e510b1e RR |
2291 | gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview) ) ); |
2292 | gtk_widget_set_parent( child->m_widget, treeview ); | |
2293 | } | |
2294 | ||
2295 | static | |
2296 | void gtk_dataviewctrl_size_callback( GtkWidget *WXUNUSED(widget), | |
2297 | GtkAllocation *alloc, | |
2298 | wxDataViewCtrl *win ) | |
2299 | { | |
e8375af8 | 2300 | |
1e510b1e RR |
2301 | wxWindowList::Node *node = win->GetChildren().GetFirst(); |
2302 | while (node) | |
2303 | { | |
2304 | wxWindow *child = node->GetData(); | |
e8375af8 | 2305 | |
1e510b1e RR |
2306 | GtkRequisition req; |
2307 | gtk_widget_size_request( child->m_widget, &req ); | |
e8375af8 | 2308 | |
1e510b1e RR |
2309 | GtkAllocation alloc; |
2310 | alloc.x = child->m_x; | |
2311 | alloc.y = child->m_y; | |
2312 | alloc.width = child->m_width; | |
2313 | alloc.height = child->m_height; | |
2314 | gtk_widget_size_allocate( child->m_widget, &alloc ); | |
e8375af8 | 2315 | |
1e510b1e RR |
2316 | node = node->GetNext(); |
2317 | } | |
2318 | } | |
2319 | ||
2320 | ||
2321 | ||
239eaa41 RR |
2322 | IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase) |
2323 | ||
2324 | wxDataViewCtrl::~wxDataViewCtrl() | |
2325 | { | |
8f850e28 RR |
2326 | if (m_notifier) |
2327 | GetModel()->RemoveNotifier( m_notifier ); | |
87f0efe2 RR |
2328 | |
2329 | // remove the model from the GtkTreeView before it gets destroyed by the | |
2330 | // wxDataViewCtrlBase's dtor | |
2331 | gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview), NULL ); | |
239eaa41 RR |
2332 | } |
2333 | ||
2334 | void wxDataViewCtrl::Init() | |
2335 | { | |
8f850e28 | 2336 | m_notifier = NULL; |
239eaa41 RR |
2337 | } |
2338 | ||
2339 | bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, | |
93763ad5 | 2340 | const wxPoint& pos, const wxSize& size, |
239eaa41 RR |
2341 | long style, const wxValidator& validator ) |
2342 | { | |
2343 | Init(); | |
93763ad5 | 2344 | |
239eaa41 RR |
2345 | if (!PreCreation( parent, pos, size ) || |
2346 | !CreateBase( parent, id, pos, size, style, validator )) | |
2347 | { | |
2348 | wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") ); | |
93763ad5 | 2349 | return false; |
239eaa41 | 2350 | } |
1a367564 | 2351 | |
1e510b1e RR |
2352 | m_insertCallback = wxInsertChildInDataViewCtrl; |
2353 | ||
1a367564 | 2354 | m_widget = gtk_scrolled_window_new (NULL, NULL); |
6493aaca VZ |
2355 | |
2356 | GtkScrolledWindowSetBorder(m_widget, style); | |
1a367564 RR |
2357 | |
2358 | m_treeview = gtk_tree_view_new(); | |
2359 | gtk_container_add (GTK_CONTAINER (m_widget), m_treeview); | |
e8375af8 | 2360 | |
1e510b1e RR |
2361 | g_signal_connect (m_treeview, "size_allocate", |
2362 | G_CALLBACK (gtk_dataviewctrl_size_callback), this); | |
ed4b0fdc | 2363 | |
b94db696 RR |
2364 | #ifdef __WXGTK26__ |
2365 | if (!gtk_check_version(2,6,0)) | |
2366 | gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), TRUE ); | |
2367 | #endif | |
2368 | ||
daebb44c RR |
2369 | if (style & wxDV_MULTIPLE) |
2370 | { | |
2371 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); | |
2372 | gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE ); | |
2373 | } | |
93763ad5 | 2374 | |
9861f022 RR |
2375 | gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview), (style & wxDV_NO_HEADER) == 0 ); |
2376 | ||
2377 | #ifdef __WXGTK210__ | |
2378 | if (!gtk_check_version(2,10,0)) | |
2379 | { | |
2380 | GtkTreeViewGridLines grid = GTK_TREE_VIEW_GRID_LINES_NONE; | |
f4322df6 VZ |
2381 | |
2382 | if ((style & wxDV_HORIZ_RULES) != 0 && | |
9861f022 RR |
2383 | (style & wxDV_VERT_RULES) != 0) |
2384 | grid = GTK_TREE_VIEW_GRID_LINES_BOTH; | |
2385 | else if (style & wxDV_VERT_RULES) | |
2386 | grid = GTK_TREE_VIEW_GRID_LINES_VERTICAL; | |
2387 | else if (style & wxDV_HORIZ_RULES) | |
2388 | grid = GTK_TREE_VIEW_GRID_LINES_HORIZONTAL; | |
2389 | ||
2390 | gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview), grid ); | |
2391 | } | |
2392 | else | |
2393 | #endif | |
2fa73716 | 2394 | { |
9861f022 | 2395 | gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview), (style & wxDV_HORIZ_RULES) != 0 ); |
2fa73716 | 2396 | } |
9861f022 | 2397 | |
1a367564 RR |
2398 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget), |
2399 | GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
2400 | gtk_widget_show (m_treeview); | |
93763ad5 | 2401 | |
239eaa41 RR |
2402 | m_parent->DoAddChild( this ); |
2403 | ||
b94db696 RR |
2404 | PostCreation(size); |
2405 | ||
b086d55f RR |
2406 | GtkEnableSelectionEvents(); |
2407 | ||
f828871d RR |
2408 | g_signal_connect_after (m_treeview, "row_activated", |
2409 | G_CALLBACK (wxdataview_row_activated_callback), this); | |
eb7f97f8 | 2410 | |
239eaa41 RR |
2411 | return true; |
2412 | } | |
2413 | ||
31fb32e1 RR |
2414 | void wxDataViewCtrl::OnInternalIdle() |
2415 | { | |
2416 | wxWindow::OnInternalIdle(); | |
f4322df6 | 2417 | |
9861f022 | 2418 | unsigned int cols = GetColumnCount(); |
31fb32e1 RR |
2419 | unsigned int i; |
2420 | for (i = 0; i < cols; i++) | |
2421 | { | |
2422 | wxDataViewColumn *col = GetColumn( i ); | |
2423 | col->OnInternalIdle(); | |
2424 | } | |
2425 | } | |
2426 | ||
e0062c04 | 2427 | bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model ) |
239eaa41 RR |
2428 | { |
2429 | if (!wxDataViewCtrlBase::AssociateModel( model )) | |
2430 | return false; | |
2431 | ||
d5025dc0 RR |
2432 | GtkWxTreeModel *gtkwx_tree_model = wxgtk_tree_model_new(); |
2433 | wxGtkTreeModel *wxgtk_tree_model = new wxGtkTreeModel( model, gtkwx_tree_model ); | |
2434 | ||
2435 | gtkwx_tree_model->model = wxgtk_tree_model; | |
6e2e590f | 2436 | |
d5025dc0 | 2437 | m_notifier = new wxGtkDataViewModelNotifier( gtkwx_tree_model, model, this ); |
6e2e590f | 2438 | |
93763ad5 | 2439 | model->AddNotifier( m_notifier ); |
1557c77b | 2440 | |
d5025dc0 RR |
2441 | gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview), GTK_TREE_MODEL(gtkwx_tree_model) ); |
2442 | g_object_unref( gtkwx_tree_model ); | |
93763ad5 | 2443 | |
239eaa41 RR |
2444 | return true; |
2445 | } | |
790b137e | 2446 | |
fa28826d RR |
2447 | bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col ) |
2448 | { | |
2449 | if (!wxDataViewCtrlBase::AppendColumn(col)) | |
2450 | return false; | |
93763ad5 | 2451 | |
fa28826d RR |
2452 | GtkTreeViewColumn *column = (GtkTreeViewColumn *)col->GetGtkHandle(); |
2453 | ||
1a367564 | 2454 | gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview), column ); |
fa28826d RR |
2455 | |
2456 | return true; | |
2457 | } | |
2458 | ||
3b6280be RR |
2459 | void wxDataViewCtrl::DoSetExpanderColumn() |
2460 | { | |
2461 | } | |
2462 | ||
2463 | void wxDataViewCtrl::DoSetIndent() | |
2464 | { | |
2465 | } | |
2466 | ||
b086d55f RR |
2467 | void wxDataViewCtrl::GtkDisableSelectionEvents() |
2468 | { | |
2469 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); | |
2470 | g_signal_connect_after (selection, "changed", | |
2471 | G_CALLBACK (wxdataview_selection_changed_callback), this); | |
2472 | } | |
2473 | ||
2474 | void wxDataViewCtrl::GtkEnableSelectionEvents() | |
2475 | { | |
2476 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); | |
e0743e63 | 2477 | g_signal_handlers_disconnect_by_func( selection, |
b086d55f RR |
2478 | (gpointer) (wxdataview_selection_changed_callback), this); |
2479 | } | |
2480 | ||
b94db696 RR |
2481 | // static |
2482 | wxVisualAttributes | |
2483 | wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
2484 | { | |
2485 | return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new); | |
2486 | } | |
2487 | ||
6ff7eee7 | 2488 | |
93763ad5 | 2489 | #endif |
4ed7af08 | 2490 | // !wxUSE_GENERICDATAVIEWCTRL |
790b137e | 2491 | |
93763ad5 | 2492 | #endif |
4ed7af08 | 2493 | // wxUSE_DATAVIEWCTRL |