]>
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" |
c3c62822 PC |
23 | #include "wx/icon.h" |
24 | #include "wx/list.h" | |
25 | #include "wx/settings.h" | |
5e6f8927 | 26 | #include "wx/dataobj.h" |
c3c62822 | 27 | #include "wx/crt.h" |
e4db172a WS |
28 | #endif |
29 | ||
790b137e | 30 | #include "wx/stockitem.h" |
7ea3a0de RR |
31 | #include "wx/calctrl.h" |
32 | #include "wx/popupwin.h" | |
69892729 | 33 | #include "wx/listimpl.cpp" |
790b137e RR |
34 | |
35 | #include "wx/gtk/private.h" | |
888dde65 RR |
36 | #include "wx/gtk/dc.h" |
37 | #include "wx/gtk/dcclient.h" | |
4d496ecb | 38 | |
790b137e | 39 | //----------------------------------------------------------------------------- |
790b137e RR |
40 | //----------------------------------------------------------------------------- |
41 | ||
b8b7b087 RR |
42 | class wxDataViewCtrlInternal; |
43 | ||
44 | wxDataViewCtrlInternal *g_internal = NULL; | |
3b6280be RR |
45 | |
46 | class wxGtkTreeModelNode; | |
ef427989 | 47 | |
0be79c8a RR |
48 | extern "C" { |
49 | typedef struct _GtkWxTreeModel GtkWxTreeModel; | |
50 | } | |
51 | ||
af110130 RR |
52 | //----------------------------------------------------------------------------- |
53 | // wxDataViewCtrlInternal | |
54 | //----------------------------------------------------------------------------- | |
55 | ||
69892729 | 56 | WX_DECLARE_LIST(wxDataViewItem, ItemList); |
a76c2f37 | 57 | WX_DEFINE_LIST(ItemList) |
69892729 | 58 | |
af110130 RR |
59 | class wxDataViewCtrlInternal |
60 | { | |
61 | public: | |
7dea20f6 | 62 | wxDataViewCtrlInternal( wxDataViewCtrl *owner, wxDataViewModel *wx_model, GtkWxTreeModel *gtk_model ); |
af110130 | 63 | ~wxDataViewCtrlInternal(); |
b9db5f30 | 64 | |
f6f0ef85 | 65 | // model iface |
2056dede | 66 | GtkTreeModelFlags get_flags(); |
af110130 RR |
67 | gboolean get_iter( GtkTreeIter *iter, GtkTreePath *path ); |
68 | GtkTreePath *get_path( GtkTreeIter *iter); | |
af110130 RR |
69 | gboolean iter_next( GtkTreeIter *iter ); |
70 | gboolean iter_children( GtkTreeIter *iter, GtkTreeIter *parent); | |
71 | gboolean iter_has_child( GtkTreeIter *iter ); | |
72 | gint iter_n_children( GtkTreeIter *iter ); | |
73 | gboolean iter_nth_child( GtkTreeIter *iter, GtkTreeIter *parent, gint n ); | |
74 | gboolean iter_parent( GtkTreeIter *iter, GtkTreeIter *child ); | |
b9db5f30 | 75 | |
f6f0ef85 RR |
76 | // dnd iface |
77 | gboolean row_draggable( GtkTreeDragSource *drag_source, GtkTreePath *path ); | |
78 | gboolean drag_data_delete( GtkTreeDragSource *drag_source, GtkTreePath* path ); | |
79 | gboolean drag_data_get( GtkTreeDragSource *drag_source, GtkTreePath *path, | |
80 | GtkSelectionData *selection_data ); | |
81 | gboolean drag_data_received( GtkTreeDragDest *drag_dest, GtkTreePath *dest, | |
82 | GtkSelectionData *selection_data ); | |
83 | gboolean row_drop_possible( GtkTreeDragDest *drag_dest, GtkTreePath *dest_path, | |
84 | GtkSelectionData *selection_data ); | |
85 | ||
86 | // notifactions from wxDataViewModel | |
af110130 | 87 | bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ); |
469d3e9b | 88 | bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ); |
d8331a01 RR |
89 | bool ItemChanged( const wxDataViewItem &item ); |
90 | bool ValueChanged( const wxDataViewItem &item, unsigned int col ); | |
91 | bool Cleared(); | |
af110130 | 92 | void Resort(); |
b9db5f30 | 93 | |
f6f0ef85 | 94 | // sorting interface |
b8b7b087 RR |
95 | void SetSortOrder( GtkSortType sort_order ) { m_sort_order = sort_order; } |
96 | GtkSortType GetSortOrder() { return m_sort_order; } | |
7ee7191c | 97 | |
40196b1e RR |
98 | void SetSortColumn( int column ) { m_sort_column = column; } |
99 | int GetSortColumn() { return m_sort_column; } | |
b9db5f30 | 100 | |
d32332aa RR |
101 | void SetDataViewSortColumn( wxDataViewColumn *column ) { m_dataview_sort_column = column; } |
102 | wxDataViewColumn *GetDataViewSortColumn() { return m_dataview_sort_column; } | |
b9db5f30 | 103 | |
40196b1e | 104 | bool IsSorted() { return (m_sort_column >= 0); } |
b9db5f30 | 105 | |
f6f0ef85 RR |
106 | // accessors |
107 | wxDataViewModel* GetDataViewModel() { return m_wx_model; } | |
108 | wxDataViewCtrl* GetOwner() { return m_owner; } | |
109 | GtkWxTreeModel* GetGtkModel() { return m_gtk_model; } | |
b9db5f30 | 110 | |
af110130 RR |
111 | protected: |
112 | void InitTree(); | |
113 | wxGtkTreeModelNode *FindNode( const wxDataViewItem &item ); | |
114 | wxGtkTreeModelNode *FindNode( GtkTreeIter *iter ); | |
115 | wxGtkTreeModelNode *FindParentNode( const wxDataViewItem &item ); | |
116 | wxGtkTreeModelNode *FindParentNode( GtkTreeIter *iter ); | |
117 | void BuildBranch( wxGtkTreeModelNode *branch ); | |
b9db5f30 | 118 | |
af110130 RR |
119 | private: |
120 | wxGtkTreeModelNode *m_root; | |
121 | wxDataViewModel *m_wx_model; | |
122 | GtkWxTreeModel *m_gtk_model; | |
123 | wxDataViewCtrl *m_owner; | |
b8b7b087 | 124 | GtkSortType m_sort_order; |
d32332aa | 125 | wxDataViewColumn *m_dataview_sort_column; |
40196b1e | 126 | int m_sort_column; |
af110130 | 127 | }; |
ef427989 | 128 | |
af110130 RR |
129 | |
130 | //----------------------------------------------------------------------------- | |
131 | // wxGtkTreeModelNode | |
132 | //----------------------------------------------------------------------------- | |
133 | ||
40196b1e RR |
134 | int LINKAGEMODE wxGtkTreeModelChildCmp( void** id1, void** id2 ) |
135 | { | |
b9db5f30 | 136 | int ret = g_internal->GetDataViewModel()->Compare( *id1, *id2, |
40196b1e | 137 | g_internal->GetSortColumn(), (g_internal->GetSortOrder() == GTK_SORT_ASCENDING) ); |
b9db5f30 | 138 | |
40196b1e RR |
139 | return ret; |
140 | } | |
af110130 RR |
141 | |
142 | WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode*, wxGtkTreeModelNodes ); | |
40196b1e | 143 | WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren ); |
3b6280be RR |
144 | |
145 | class wxGtkTreeModelNode | |
146 | { | |
147 | public: | |
ef427989 | 148 | wxGtkTreeModelNode( wxGtkTreeModelNode* parent, const wxDataViewItem &item, |
0be79c8a | 149 | wxDataViewCtrlInternal *internal ) |
b9db5f30 VS |
150 | { |
151 | m_parent = parent; | |
d5025dc0 | 152 | m_item = item; |
0be79c8a | 153 | m_internal = internal; |
3b6280be | 154 | } |
b9db5f30 | 155 | |
3b6280be | 156 | ~wxGtkTreeModelNode() |
b9db5f30 | 157 | { |
40196b1e | 158 | size_t count = m_children.GetCount(); |
3b6280be RR |
159 | size_t i; |
160 | for (i = 0; i < count; i++) | |
161 | { | |
af110130 | 162 | wxGtkTreeModelNode *child = m_nodes.Item( i ); |
3b6280be RR |
163 | delete child; |
164 | } | |
165 | } | |
166 | ||
b9db5f30 VS |
167 | unsigned int AddNode( wxGtkTreeModelNode* child ) |
168 | { | |
af110130 | 169 | m_nodes.Add( child ); |
b9db5f30 | 170 | |
40196b1e | 171 | void *id = child->GetItem().GetID(); |
b9db5f30 | 172 | |
40196b1e | 173 | m_children.Add( id ); |
0bd26819 RR |
174 | |
175 | if (m_internal->IsSorted() || m_internal->GetDataViewModel()->HasDefaultCompare()) | |
40196b1e RR |
176 | { |
177 | g_internal = m_internal; | |
178 | m_children.Sort( &wxGtkTreeModelChildCmp ); | |
179 | return m_children.Index( id ); | |
180 | } | |
0bd26819 | 181 | |
40196b1e | 182 | return m_children.GetCount()-1; |
af110130 | 183 | } |
b9db5f30 | 184 | |
af110130 RR |
185 | unsigned int AddLeave( void* id ) |
186 | { | |
40196b1e | 187 | m_children.Add( id ); |
0bd26819 RR |
188 | |
189 | if (m_internal->IsSorted() || m_internal->GetDataViewModel()->HasDefaultCompare()) | |
40196b1e RR |
190 | { |
191 | g_internal = m_internal; | |
192 | m_children.Sort( &wxGtkTreeModelChildCmp ); | |
193 | return m_children.Index( id ); | |
194 | } | |
0bd26819 | 195 | |
40196b1e | 196 | return m_children.GetCount()-1; |
af110130 | 197 | } |
b9db5f30 | 198 | |
af110130 RR |
199 | void DeleteChild( void* id ) |
200 | { | |
40196b1e | 201 | m_children.Remove( id ); |
b9db5f30 | 202 | |
40196b1e RR |
203 | unsigned int count = m_nodes.GetCount(); |
204 | unsigned int pos; | |
af110130 | 205 | for (pos = 0; pos < count; pos++) |
b9db5f30 | 206 | { |
af110130 RR |
207 | wxGtkTreeModelNode *node = m_nodes.Item( pos ); |
208 | if (node->GetItem().GetID() == id) | |
209 | { | |
210 | m_nodes.RemoveAt( pos ); | |
211 | delete node; | |
212 | break; | |
213 | } | |
214 | } | |
b9db5f30 | 215 | |
af110130 | 216 | } |
b9db5f30 VS |
217 | |
218 | wxGtkTreeModelNode* GetParent() | |
3b6280be | 219 | { return m_parent; } |
b9db5f30 | 220 | wxGtkTreeModelNodes &GetNodes() |
af110130 | 221 | { return m_nodes; } |
b9db5f30 | 222 | wxGtkTreeModelChildren &GetChildren() |
40196b1e | 223 | { return m_children; } |
b9db5f30 | 224 | |
40196b1e | 225 | unsigned int GetChildCount() { return m_children.GetCount(); } |
af110130 | 226 | unsigned int GetNodesCount() { return m_nodes.GetCount(); } |
3b6280be RR |
227 | |
228 | wxDataViewItem &GetItem() { return m_item; } | |
0be79c8a | 229 | wxDataViewCtrlInternal *GetInternal() { return m_internal; } |
b9db5f30 | 230 | |
4508fcd2 | 231 | void Resort(); |
b9db5f30 | 232 | |
3b6280be | 233 | private: |
0be79c8a | 234 | wxGtkTreeModelNode *m_parent; |
af110130 | 235 | wxGtkTreeModelNodes m_nodes; |
40196b1e | 236 | wxGtkTreeModelChildren m_children; |
b9db5f30 | 237 | wxDataViewItem m_item; |
0be79c8a | 238 | wxDataViewCtrlInternal *m_internal; |
3b6280be RR |
239 | }; |
240 | ||
ef427989 | 241 | |
790b137e RR |
242 | //----------------------------------------------------------------------------- |
243 | // data | |
244 | //----------------------------------------------------------------------------- | |
245 | ||
246 | extern bool g_blockEventsOnDrag; | |
247 | ||
248 | //----------------------------------------------------------------------------- | |
e0062c04 | 249 | // define new GTK+ class wxGtkTreeModel |
790b137e RR |
250 | //----------------------------------------------------------------------------- |
251 | ||
252 | extern "C" { | |
253 | ||
e0062c04 RR |
254 | #define GTK_TYPE_WX_TREE_MODEL (gtk_wx_tree_model_get_type ()) |
255 | #define GTK_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModel)) | |
256 | #define GTK_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass)) | |
257 | #define GTK_IS_WX_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_TREE_MODEL)) | |
258 | #define GTK_IS_WX_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_TREE_MODEL)) | |
259 | #define GTK_WX_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_TREE_MODEL, GtkWxTreeModelClass)) | |
790b137e | 260 | |
e0062c04 | 261 | GType gtk_wx_tree_model_get_type (void); |
790b137e | 262 | |
e0062c04 | 263 | typedef struct _GtkWxTreeModelClass GtkWxTreeModelClass; |
790b137e | 264 | |
e0062c04 | 265 | struct _GtkWxTreeModel |
790b137e RR |
266 | { |
267 | GObject parent; | |
268 | ||
269 | /*< private >*/ | |
270 | gint stamp; | |
55fbde12 | 271 | wxDataViewCtrlInternal *internal; |
790b137e RR |
272 | }; |
273 | ||
e0062c04 | 274 | struct _GtkWxTreeModelClass |
790b137e | 275 | { |
e152afc3 | 276 | GObjectClass list_parent_class; |
790b137e RR |
277 | }; |
278 | ||
e0062c04 | 279 | static GtkWxTreeModel *wxgtk_tree_model_new (void); |
773cca48 RR |
280 | static void wxgtk_tree_model_init (GtkWxTreeModel *tree_model); |
281 | static void wxgtk_tree_model_class_init (GtkWxTreeModelClass *klass); | |
85136e3b RR |
282 | |
283 | static void wxgtk_tree_model_tree_model_init (GtkTreeModelIface *iface); | |
284 | static void wxgtk_tree_model_sortable_init (GtkTreeSortableIface *iface); | |
285 | static void wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface *iface); | |
286 | static void wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface *iface); | |
287 | ||
e0062c04 RR |
288 | static void wxgtk_tree_model_finalize (GObject *object); |
289 | static GtkTreeModelFlags wxgtk_tree_model_get_flags (GtkTreeModel *tree_model); | |
290 | static gint wxgtk_tree_model_get_n_columns (GtkTreeModel *tree_model); | |
291 | static GType wxgtk_tree_model_get_column_type (GtkTreeModel *tree_model, | |
93763ad5 | 292 | gint index); |
e0062c04 | 293 | static gboolean wxgtk_tree_model_get_iter (GtkTreeModel *tree_model, |
93763ad5 WS |
294 | GtkTreeIter *iter, |
295 | GtkTreePath *path); | |
e0062c04 | 296 | static GtkTreePath *wxgtk_tree_model_get_path (GtkTreeModel *tree_model, |
93763ad5 | 297 | GtkTreeIter *iter); |
e0062c04 | 298 | static void wxgtk_tree_model_get_value (GtkTreeModel *tree_model, |
93763ad5 WS |
299 | GtkTreeIter *iter, |
300 | gint column, | |
301 | GValue *value); | |
e0062c04 | 302 | static gboolean wxgtk_tree_model_iter_next (GtkTreeModel *tree_model, |
93763ad5 | 303 | GtkTreeIter *iter); |
e0062c04 | 304 | static gboolean wxgtk_tree_model_iter_children (GtkTreeModel *tree_model, |
93763ad5 WS |
305 | GtkTreeIter *iter, |
306 | GtkTreeIter *parent); | |
e0062c04 | 307 | static gboolean wxgtk_tree_model_iter_has_child (GtkTreeModel *tree_model, |
93763ad5 | 308 | GtkTreeIter *iter); |
e0062c04 | 309 | static gint wxgtk_tree_model_iter_n_children (GtkTreeModel *tree_model, |
93763ad5 | 310 | GtkTreeIter *iter); |
e0062c04 | 311 | static gboolean wxgtk_tree_model_iter_nth_child (GtkTreeModel *tree_model, |
93763ad5 WS |
312 | GtkTreeIter *iter, |
313 | GtkTreeIter *parent, | |
314 | gint n); | |
e0062c04 | 315 | static gboolean wxgtk_tree_model_iter_parent (GtkTreeModel *tree_model, |
93763ad5 WS |
316 | GtkTreeIter *iter, |
317 | GtkTreeIter *child); | |
790b137e | 318 | |
773cca48 RR |
319 | /* sortable */ |
320 | static gboolean wxgtk_tree_model_get_sort_column_id (GtkTreeSortable *sortable, | |
85136e3b RR |
321 | gint *sort_column_id, |
322 | GtkSortType *order); | |
773cca48 | 323 | static void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable *sortable, |
85136e3b RR |
324 | gint sort_column_id, |
325 | GtkSortType order); | |
773cca48 | 326 | static void wxgtk_tree_model_set_sort_func (GtkTreeSortable *sortable, |
85136e3b RR |
327 | gint sort_column_id, |
328 | GtkTreeIterCompareFunc func, | |
329 | gpointer data, | |
330 | GtkDestroyNotify destroy); | |
773cca48 | 331 | static void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable *sortable, |
85136e3b RR |
332 | GtkTreeIterCompareFunc func, |
333 | gpointer data, | |
334 | GtkDestroyNotify destroy); | |
773cca48 RR |
335 | static gboolean wxgtk_tree_model_has_default_sort_func (GtkTreeSortable *sortable); |
336 | ||
85136e3b RR |
337 | /* drag'n'drop */ |
338 | static gboolean wxgtk_tree_model_row_draggable (GtkTreeDragSource *drag_source, | |
339 | GtkTreePath *path); | |
340 | static gboolean wxgtk_tree_model_drag_data_delete (GtkTreeDragSource *drag_source, | |
341 | GtkTreePath *path); | |
342 | static gboolean wxgtk_tree_model_drag_data_get (GtkTreeDragSource *drag_source, | |
343 | GtkTreePath *path, | |
344 | GtkSelectionData *selection_data); | |
345 | static gboolean wxgtk_tree_model_drag_data_received (GtkTreeDragDest *drag_dest, | |
346 | GtkTreePath *dest, | |
347 | GtkSelectionData *selection_data); | |
348 | static gboolean wxgtk_tree_model_row_drop_possible (GtkTreeDragDest *drag_dest, | |
349 | GtkTreePath *dest_path, | |
350 | GtkSelectionData *selection_data); | |
773cca48 RR |
351 | |
352 | ||
e152afc3 | 353 | static GObjectClass *list_parent_class = NULL; |
790b137e RR |
354 | |
355 | GType | |
e0062c04 | 356 | gtk_wx_tree_model_get_type (void) |
790b137e | 357 | { |
e0062c04 | 358 | static GType tree_model_type = 0; |
790b137e | 359 | |
e0062c04 | 360 | if (!tree_model_type) |
790b137e | 361 | { |
e0062c04 | 362 | const GTypeInfo tree_model_info = |
93763ad5 | 363 | { |
e0062c04 | 364 | sizeof (GtkWxTreeModelClass), |
93763ad5 WS |
365 | NULL, /* base_init */ |
366 | NULL, /* base_finalize */ | |
e0062c04 | 367 | (GClassInitFunc) wxgtk_tree_model_class_init, |
93763ad5 WS |
368 | NULL, /* class_finalize */ |
369 | NULL, /* class_data */ | |
e0062c04 | 370 | sizeof (GtkWxTreeModel), |
93763ad5 | 371 | 0, |
e0062c04 | 372 | (GInstanceInitFunc) wxgtk_tree_model_init, |
93763ad5 | 373 | }; |
790b137e | 374 | |
773cca48 RR |
375 | static const GInterfaceInfo tree_model_iface_info = |
376 | { | |
377 | (GInterfaceInitFunc) wxgtk_tree_model_tree_model_init, | |
378 | NULL, | |
379 | NULL | |
380 | }; | |
381 | ||
382 | static const GInterfaceInfo sortable_iface_info = | |
383 | { | |
384 | (GInterfaceInitFunc) wxgtk_tree_model_sortable_init, | |
385 | NULL, | |
386 | NULL | |
387 | }; | |
790b137e | 388 | |
85136e3b RR |
389 | static const GInterfaceInfo drag_source_iface_info = |
390 | { | |
391 | (GInterfaceInitFunc) wxgtk_tree_model_drag_source_init, | |
392 | NULL, | |
393 | NULL | |
394 | }; | |
395 | ||
396 | static const GInterfaceInfo drag_dest_iface_info = | |
397 | { | |
398 | (GInterfaceInitFunc) wxgtk_tree_model_drag_dest_init, | |
399 | NULL, | |
400 | NULL | |
401 | }; | |
402 | ||
773cca48 | 403 | tree_model_type = g_type_register_static (G_TYPE_OBJECT, "GtkWxTreeModel", |
e0062c04 | 404 | &tree_model_info, (GTypeFlags)0 ); |
790b137e | 405 | |
773cca48 RR |
406 | g_type_add_interface_static (tree_model_type, |
407 | GTK_TYPE_TREE_MODEL, | |
408 | &tree_model_iface_info); | |
409 | g_type_add_interface_static (tree_model_type, | |
410 | GTK_TYPE_TREE_SORTABLE, | |
411 | &sortable_iface_info); | |
85136e3b RR |
412 | g_type_add_interface_static (tree_model_type, |
413 | GTK_TYPE_TREE_DRAG_DEST, | |
414 | &drag_dest_iface_info); | |
415 | g_type_add_interface_static (tree_model_type, | |
416 | GTK_TYPE_TREE_DRAG_SOURCE, | |
417 | &drag_source_iface_info); | |
790b137e RR |
418 | } |
419 | ||
773cca48 | 420 | return tree_model_type; |
790b137e RR |
421 | } |
422 | ||
e0062c04 RR |
423 | static GtkWxTreeModel * |
424 | wxgtk_tree_model_new(void) | |
1557c77b | 425 | { |
e0062c04 | 426 | GtkWxTreeModel *retval = (GtkWxTreeModel *) g_object_new (GTK_TYPE_WX_TREE_MODEL, NULL); |
e152afc3 | 427 | return retval; |
1557c77b RR |
428 | } |
429 | ||
790b137e | 430 | static void |
e0062c04 | 431 | wxgtk_tree_model_class_init (GtkWxTreeModelClass *klass) |
790b137e | 432 | { |
e152afc3 RR |
433 | list_parent_class = (GObjectClass*) g_type_class_peek_parent (klass); |
434 | GObjectClass *object_class = (GObjectClass*) klass; | |
e0062c04 | 435 | object_class->finalize = wxgtk_tree_model_finalize; |
790b137e RR |
436 | } |
437 | ||
438 | static void | |
e0062c04 RR |
439 | wxgtk_tree_model_tree_model_init (GtkTreeModelIface *iface) |
440 | { | |
441 | iface->get_flags = wxgtk_tree_model_get_flags; | |
442 | iface->get_n_columns = wxgtk_tree_model_get_n_columns; | |
443 | iface->get_column_type = wxgtk_tree_model_get_column_type; | |
444 | iface->get_iter = wxgtk_tree_model_get_iter; | |
445 | iface->get_path = wxgtk_tree_model_get_path; | |
446 | iface->get_value = wxgtk_tree_model_get_value; | |
447 | iface->iter_next = wxgtk_tree_model_iter_next; | |
448 | iface->iter_children = wxgtk_tree_model_iter_children; | |
449 | iface->iter_has_child = wxgtk_tree_model_iter_has_child; | |
450 | iface->iter_n_children = wxgtk_tree_model_iter_n_children; | |
451 | iface->iter_nth_child = wxgtk_tree_model_iter_nth_child; | |
452 | iface->iter_parent = wxgtk_tree_model_iter_parent; | |
790b137e RR |
453 | } |
454 | ||
773cca48 RR |
455 | static void |
456 | wxgtk_tree_model_sortable_init (GtkTreeSortableIface *iface) | |
457 | { | |
94b1f7bc RR |
458 | iface->get_sort_column_id = wxgtk_tree_model_get_sort_column_id; |
459 | iface->set_sort_column_id = wxgtk_tree_model_set_sort_column_id; | |
460 | iface->set_sort_func = wxgtk_tree_model_set_sort_func; | |
461 | iface->set_default_sort_func = wxgtk_tree_model_set_default_sort_func; | |
462 | iface->has_default_sort_func = wxgtk_tree_model_has_default_sort_func; | |
773cca48 RR |
463 | } |
464 | ||
85136e3b RR |
465 | static void |
466 | wxgtk_tree_model_drag_source_init(GtkTreeDragSourceIface *iface) | |
467 | { | |
468 | iface->row_draggable = wxgtk_tree_model_row_draggable; | |
469 | iface->drag_data_delete = wxgtk_tree_model_drag_data_delete; | |
470 | iface->drag_data_get = wxgtk_tree_model_drag_data_get; | |
471 | } | |
472 | ||
473 | static void | |
474 | wxgtk_tree_model_drag_dest_init (GtkTreeDragDestIface *iface) | |
475 | { | |
476 | iface->drag_data_received = wxgtk_tree_model_drag_data_received; | |
477 | iface->row_drop_possible = wxgtk_tree_model_row_drop_possible; | |
478 | } | |
479 | ||
790b137e | 480 | static void |
e0062c04 | 481 | wxgtk_tree_model_init (GtkWxTreeModel *tree_model) |
790b137e | 482 | { |
55fbde12 | 483 | tree_model->internal = NULL; |
e0062c04 | 484 | tree_model->stamp = g_random_int(); |
790b137e RR |
485 | } |
486 | ||
487 | static void | |
e0062c04 | 488 | wxgtk_tree_model_finalize (GObject *object) |
790b137e | 489 | { |
790b137e | 490 | /* must chain up */ |
e152afc3 | 491 | (* list_parent_class->finalize) (object); |
790b137e | 492 | } |
93763ad5 | 493 | |
790b137e RR |
494 | } // extern "C" |
495 | ||
496 | //----------------------------------------------------------------------------- | |
e0062c04 RR |
497 | // implement callbacks from wxGtkTreeModel class by letting |
498 | // them call the methods of wxWidgets' wxDataViewModel | |
790b137e RR |
499 | //----------------------------------------------------------------------------- |
500 | ||
501 | static GtkTreeModelFlags | |
e0062c04 | 502 | wxgtk_tree_model_get_flags (GtkTreeModel *tree_model) |
790b137e | 503 | { |
2056dede RR |
504 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
505 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), (GtkTreeModelFlags)0 ); | |
790b137e | 506 | |
2056dede | 507 | return wxtree_model->internal->get_flags(); |
790b137e RR |
508 | } |
509 | ||
510 | static gint | |
e0062c04 | 511 | wxgtk_tree_model_get_n_columns (GtkTreeModel *tree_model) |
790b137e | 512 | { |
e0062c04 RR |
513 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
514 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), 0); | |
790b137e | 515 | |
55fbde12 | 516 | return wxtree_model->internal->GetDataViewModel()->GetColumnCount(); |
790b137e RR |
517 | } |
518 | ||
519 | static GType | |
e0062c04 | 520 | wxgtk_tree_model_get_column_type (GtkTreeModel *tree_model, |
93763ad5 | 521 | gint index) |
790b137e | 522 | { |
e0062c04 RR |
523 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
524 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), G_TYPE_INVALID); | |
790b137e | 525 | |
1557c77b | 526 | GType gtype = G_TYPE_INVALID; |
93763ad5 | 527 | |
55fbde12 | 528 | wxString wxtype = wxtree_model->internal->GetDataViewModel()->GetColumnType( (unsigned int) index ); |
93763ad5 | 529 | |
1557c77b RR |
530 | if (wxtype == wxT("string")) |
531 | gtype = G_TYPE_STRING; | |
72a3ac9b VZ |
532 | else |
533 | { | |
e94d0c1e RR |
534 | gtype = G_TYPE_STRING; |
535 | // wxFAIL_MSG( _T("non-string columns not supported yet") ); | |
72a3ac9b | 536 | } |
790b137e RR |
537 | |
538 | return gtype; | |
539 | } | |
540 | ||
541 | static gboolean | |
e0062c04 | 542 | wxgtk_tree_model_get_iter (GtkTreeModel *tree_model, |
93763ad5 WS |
543 | GtkTreeIter *iter, |
544 | GtkTreePath *path) | |
790b137e | 545 | { |
e0062c04 RR |
546 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
547 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE); | |
790b137e RR |
548 | g_return_val_if_fail (gtk_tree_path_get_depth (path) > 0, FALSE); |
549 | ||
55fbde12 | 550 | return wxtree_model->internal->get_iter( iter, path ); |
790b137e RR |
551 | } |
552 | ||
553 | static GtkTreePath * | |
e0062c04 | 554 | wxgtk_tree_model_get_path (GtkTreeModel *tree_model, |
93763ad5 | 555 | GtkTreeIter *iter) |
790b137e | 556 | { |
e0062c04 RR |
557 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
558 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), NULL); | |
559 | g_return_val_if_fail (iter->stamp == GTK_WX_TREE_MODEL (wxtree_model)->stamp, NULL); | |
93763ad5 | 560 | |
55fbde12 | 561 | return wxtree_model->internal->get_path( iter ); |
790b137e RR |
562 | } |
563 | ||
564 | static void | |
e0062c04 | 565 | wxgtk_tree_model_get_value (GtkTreeModel *tree_model, |
93763ad5 WS |
566 | GtkTreeIter *iter, |
567 | gint column, | |
568 | GValue *value) | |
790b137e | 569 | { |
e0062c04 RR |
570 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
571 | g_return_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model) ); | |
239eaa41 | 572 | |
55fbde12 | 573 | wxDataViewModel *model = wxtree_model->internal->GetDataViewModel(); |
9861f022 | 574 | wxString mtype = model->GetColumnType( (unsigned int) column ); |
1557c77b RR |
575 | if (mtype == wxT("string")) |
576 | { | |
3f3af7e7 | 577 | wxVariant variant; |
1557c77b | 578 | g_value_init( value, G_TYPE_STRING ); |
9d52aad3 | 579 | wxDataViewItem item( (void*) iter->user_data ); |
e0062c04 | 580 | model->GetValue( variant, item, (unsigned int) column ); |
72a3ac9b | 581 | |
e0062c04 | 582 | g_value_set_string( value, variant.GetString().utf8_str() ); |
1557c77b RR |
583 | } |
584 | else | |
585 | { | |
72a3ac9b | 586 | wxFAIL_MSG( _T("non-string columns not supported yet") ); |
1557c77b | 587 | } |
790b137e RR |
588 | } |
589 | ||
590 | static gboolean | |
e0062c04 | 591 | wxgtk_tree_model_iter_next (GtkTreeModel *tree_model, |
93763ad5 | 592 | GtkTreeIter *iter) |
790b137e | 593 | { |
e0062c04 | 594 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
33ba5a05 RR |
595 | |
596 | if (wxtree_model->stamp != iter->stamp) | |
597 | wxPrintf( "crash\n" ); | |
598 | ||
e0062c04 | 599 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE); |
e0062c04 | 600 | g_return_val_if_fail (wxtree_model->stamp == iter->stamp, FALSE); |
33ba5a05 | 601 | |
55fbde12 | 602 | return wxtree_model->internal->iter_next( iter ); |
790b137e RR |
603 | } |
604 | ||
605 | static gboolean | |
e0062c04 | 606 | wxgtk_tree_model_iter_children (GtkTreeModel *tree_model, |
93763ad5 WS |
607 | GtkTreeIter *iter, |
608 | GtkTreeIter *parent) | |
790b137e | 609 | { |
e0062c04 RR |
610 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
611 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE); | |
e0062c04 | 612 | g_return_val_if_fail (wxtree_model->stamp == parent->stamp, FALSE); |
790b137e | 613 | |
55fbde12 | 614 | return wxtree_model->internal->iter_children( iter, parent ); |
790b137e RR |
615 | } |
616 | ||
617 | static gboolean | |
e0062c04 | 618 | wxgtk_tree_model_iter_has_child (GtkTreeModel *tree_model, |
93763ad5 | 619 | GtkTreeIter *iter) |
790b137e | 620 | { |
e0062c04 RR |
621 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
622 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE); | |
e0062c04 | 623 | g_return_val_if_fail (wxtree_model->stamp == iter->stamp, FALSE); |
d5025dc0 | 624 | |
55fbde12 | 625 | return wxtree_model->internal->iter_has_child( iter ); |
790b137e RR |
626 | } |
627 | ||
628 | static gint | |
e0062c04 | 629 | wxgtk_tree_model_iter_n_children (GtkTreeModel *tree_model, |
93763ad5 | 630 | GtkTreeIter *iter) |
790b137e | 631 | { |
e0062c04 RR |
632 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
633 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE); | |
e0062c04 | 634 | g_return_val_if_fail (wxtree_model->stamp == iter->stamp, 0); |
d5025dc0 | 635 | |
55fbde12 | 636 | return wxtree_model->internal->iter_n_children( iter ); |
790b137e RR |
637 | } |
638 | ||
639 | static gboolean | |
e0062c04 | 640 | wxgtk_tree_model_iter_nth_child (GtkTreeModel *tree_model, |
93763ad5 WS |
641 | GtkTreeIter *iter, |
642 | GtkTreeIter *parent, | |
643 | gint n) | |
790b137e | 644 | { |
e0062c04 RR |
645 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
646 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE); | |
647 | ||
55fbde12 | 648 | return wxtree_model->internal->iter_nth_child( iter, parent, n ); |
790b137e RR |
649 | } |
650 | ||
651 | static gboolean | |
e0062c04 | 652 | wxgtk_tree_model_iter_parent (GtkTreeModel *tree_model, |
93763ad5 WS |
653 | GtkTreeIter *iter, |
654 | GtkTreeIter *child) | |
790b137e | 655 | { |
e0062c04 RR |
656 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; |
657 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE); | |
e0062c04 | 658 | g_return_val_if_fail (wxtree_model->stamp == child->stamp, FALSE); |
b9db5f30 | 659 | |
55fbde12 | 660 | return wxtree_model->internal->iter_parent( iter, child ); |
790b137e RR |
661 | } |
662 | ||
85136e3b RR |
663 | /* drag'n'drop iface */ |
664 | static gboolean | |
665 | wxgtk_tree_model_row_draggable (GtkTreeDragSource *drag_source, | |
666 | GtkTreePath *path) | |
667 | { | |
f6f0ef85 RR |
668 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) drag_source; |
669 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE); | |
85136e3b | 670 | |
f6f0ef85 | 671 | return wxtree_model->internal->row_draggable( drag_source, path ); |
85136e3b RR |
672 | } |
673 | ||
674 | static gboolean | |
675 | wxgtk_tree_model_drag_data_delete (GtkTreeDragSource *drag_source, | |
676 | GtkTreePath *path) | |
677 | { | |
f6f0ef85 RR |
678 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) drag_source; |
679 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE); | |
85136e3b | 680 | |
f6f0ef85 | 681 | return wxtree_model->internal->drag_data_delete( drag_source, path ); |
85136e3b RR |
682 | } |
683 | ||
684 | static gboolean | |
685 | wxgtk_tree_model_drag_data_get (GtkTreeDragSource *drag_source, | |
686 | GtkTreePath *path, | |
687 | GtkSelectionData *selection_data) | |
688 | { | |
f6f0ef85 RR |
689 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) drag_source; |
690 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE); | |
85136e3b | 691 | |
f6f0ef85 | 692 | #if 0 |
85136e3b RR |
693 | wxPrintf( "drag_get_data\n"); |
694 | ||
f6f0ef85 RR |
695 | wxGtkString atom_selection(gdk_atom_name(selection_data->selection)); |
696 | wxPrintf( "selection %s\n", wxString::FromAscii(atom_selection) ); | |
85136e3b | 697 | |
f6f0ef85 RR |
698 | wxGtkString atom_target(gdk_atom_name(selection_data->target)); |
699 | wxPrintf( "target %s\n", wxString::FromAscii(atom_target) ); | |
700 | ||
701 | wxGtkString atom_type(gdk_atom_name(selection_data->type)); | |
702 | wxPrintf( "type %s\n", wxString::FromAscii(atom_type) ); | |
703 | ||
704 | wxPrintf( "format %d\n", selection_data->format ); | |
705 | #endif | |
706 | ||
707 | return wxtree_model->internal->drag_data_get( drag_source, path, selection_data ); | |
85136e3b RR |
708 | } |
709 | ||
710 | static gboolean | |
711 | wxgtk_tree_model_drag_data_received (GtkTreeDragDest *drag_dest, | |
712 | GtkTreePath *dest, | |
713 | GtkSelectionData *selection_data) | |
714 | { | |
f6f0ef85 RR |
715 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) drag_dest; |
716 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE); | |
85136e3b | 717 | |
f6f0ef85 | 718 | return wxtree_model->internal->drag_data_received( drag_dest, dest, selection_data ); |
85136e3b RR |
719 | } |
720 | ||
721 | static gboolean | |
722 | wxgtk_tree_model_row_drop_possible (GtkTreeDragDest *drag_dest, | |
723 | GtkTreePath *dest_path, | |
724 | GtkSelectionData *selection_data) | |
725 | { | |
f6f0ef85 RR |
726 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) drag_dest; |
727 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE); | |
85136e3b | 728 | |
f6f0ef85 | 729 | return wxtree_model->internal->row_drop_possible( drag_dest, dest_path, selection_data ); |
85136e3b RR |
730 | } |
731 | ||
732 | /* sortable iface */ | |
733 | static gboolean | |
734 | wxgtk_tree_model_get_sort_column_id (GtkTreeSortable *sortable, | |
735 | gint *sort_column_id, | |
736 | GtkSortType *order) | |
773cca48 | 737 | { |
f6f0ef85 | 738 | GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) sortable; |
94b1f7bc RR |
739 | |
740 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable), FALSE); | |
741 | ||
f6f0ef85 | 742 | if (!wxtree_model->internal->IsSorted()) |
40196b1e RR |
743 | { |
744 | if (sort_column_id) | |
745 | *sort_column_id = -1; | |
b9db5f30 | 746 | |
40196b1e RR |
747 | return TRUE; |
748 | } | |
749 | ||
750 | ||
94b1f7bc | 751 | if (sort_column_id) |
f6f0ef85 | 752 | *sort_column_id = wxtree_model->internal->GetSortColumn(); |
b9db5f30 | 753 | |
94b1f7bc | 754 | if (order) |
f6f0ef85 | 755 | *order = wxtree_model->internal->GetSortOrder(); |
b9db5f30 | 756 | |
94b1f7bc | 757 | return TRUE; |
773cca48 RR |
758 | } |
759 | ||
d32332aa RR |
760 | wxDataViewColumn *gs_lastLeftClickHeader = NULL; |
761 | ||
85136e3b RR |
762 | static void |
763 | wxgtk_tree_model_set_sort_column_id (GtkTreeSortable *sortable, | |
764 | gint sort_column_id, | |
765 | GtkSortType order) | |
773cca48 | 766 | { |
94b1f7bc | 767 | GtkWxTreeModel *tree_model = (GtkWxTreeModel *) sortable; |
94b1f7bc RR |
768 | g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) ); |
769 | ||
d32332aa | 770 | tree_model->internal->SetDataViewSortColumn( gs_lastLeftClickHeader ); |
b9db5f30 | 771 | |
d32332aa RR |
772 | if ((sort_column_id != (gint) tree_model->internal->GetSortColumn()) || |
773 | (order != tree_model->internal->GetSortOrder())) | |
774 | { | |
775 | tree_model->internal->SetSortColumn( sort_column_id ); | |
776 | tree_model->internal->SetSortOrder( order ); | |
b9db5f30 | 777 | |
d32332aa | 778 | gtk_tree_sortable_sort_column_changed (sortable); |
b9db5f30 | 779 | |
d32332aa RR |
780 | tree_model->internal->GetDataViewModel()->Resort(); |
781 | } | |
a84c5b6f | 782 | |
d32332aa RR |
783 | if (gs_lastLeftClickHeader) |
784 | { | |
b9db5f30 | 785 | wxDataViewCtrl *dv = tree_model->internal->GetOwner(); |
d32332aa RR |
786 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, dv->GetId() ); |
787 | event.SetDataViewColumn( gs_lastLeftClickHeader ); | |
788 | event.SetModel( dv->GetModel() ); | |
937013e0 | 789 | dv->HandleWindowEvent( event ); |
d32332aa | 790 | } |
b9db5f30 | 791 | |
d32332aa | 792 | gs_lastLeftClickHeader = NULL; |
773cca48 RR |
793 | } |
794 | ||
85136e3b RR |
795 | static void |
796 | wxgtk_tree_model_set_sort_func (GtkTreeSortable *sortable, | |
797 | gint WXUNUSED(sort_column_id), | |
798 | GtkTreeIterCompareFunc func, | |
799 | gpointer WXUNUSED(data), | |
800 | GtkDestroyNotify WXUNUSED(destroy) ) | |
773cca48 | 801 | { |
94b1f7bc RR |
802 | g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) ); |
803 | g_return_if_fail (func != NULL); | |
773cca48 RR |
804 | } |
805 | ||
c5c5395b RR |
806 | void wxgtk_tree_model_set_default_sort_func (GtkTreeSortable *sortable, |
807 | GtkTreeIterCompareFunc func, | |
808 | gpointer WXUNUSED(data), | |
809 | GtkDestroyNotify WXUNUSED(destroy) ) | |
773cca48 | 810 | { |
94b1f7bc | 811 | g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) ); |
94b1f7bc RR |
812 | g_return_if_fail (func != NULL); |
813 | ||
94b1f7bc | 814 | wxPrintf( "wxgtk_tree_model_set_default_sort_func\n" ); |
773cca48 RR |
815 | } |
816 | ||
817 | gboolean wxgtk_tree_model_has_default_sort_func (GtkTreeSortable *sortable) | |
818 | { | |
c5c5395b RR |
819 | g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable), FALSE ); |
820 | ||
773cca48 RR |
821 | return FALSE; |
822 | } | |
823 | ||
e152afc3 | 824 | //----------------------------------------------------------------------------- |
baa9ebc4 | 825 | // define new GTK+ class wxGtkRendererRenderer |
e152afc3 RR |
826 | //----------------------------------------------------------------------------- |
827 | ||
828 | extern "C" { | |
829 | ||
830 | #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ()) | |
831 | #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer)) | |
832 | #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass)) | |
833 | #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER)) | |
834 | #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER)) | |
835 | #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass)) | |
836 | ||
837 | GType gtk_wx_cell_renderer_get_type (void); | |
838 | ||
839 | typedef struct _GtkWxCellRenderer GtkWxCellRenderer; | |
840 | typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass; | |
841 | ||
842 | struct _GtkWxCellRenderer | |
843 | { | |
844 | GtkCellRenderer parent; | |
845 | ||
846 | /*< private >*/ | |
baa9ebc4 | 847 | wxDataViewCustomRenderer *cell; |
4d496ecb | 848 | guint32 last_click; |
e152afc3 RR |
849 | }; |
850 | ||
851 | struct _GtkWxCellRendererClass | |
852 | { | |
853 | GtkCellRendererClass cell_parent_class; | |
e152afc3 RR |
854 | }; |
855 | ||
856 | ||
857 | static GtkCellRenderer *gtk_wx_cell_renderer_new (void); | |
553f7d8f RR |
858 | static void gtk_wx_cell_renderer_init ( |
859 | GtkWxCellRenderer *cell ); | |
860 | static void gtk_wx_cell_renderer_class_init( | |
861 | GtkWxCellRendererClass *klass ); | |
862 | static void gtk_wx_cell_renderer_finalize ( | |
863 | GObject *object ); | |
864 | static void gtk_wx_cell_renderer_get_size ( | |
865 | GtkCellRenderer *cell, | |
93763ad5 WS |
866 | GtkWidget *widget, |
867 | GdkRectangle *rectangle, | |
868 | gint *x_offset, | |
869 | gint *y_offset, | |
870 | gint *width, | |
871 | gint *height ); | |
553f7d8f RR |
872 | static void gtk_wx_cell_renderer_render ( |
873 | GtkCellRenderer *cell, | |
93763ad5 WS |
874 | GdkWindow *window, |
875 | GtkWidget *widget, | |
876 | GdkRectangle *background_area, | |
877 | GdkRectangle *cell_area, | |
878 | GdkRectangle *expose_area, | |
879 | GtkCellRendererState flags ); | |
553f7d8f RR |
880 | static gboolean gtk_wx_cell_renderer_activate( |
881 | GtkCellRenderer *cell, | |
882 | GdkEvent *event, | |
883 | GtkWidget *widget, | |
884 | const gchar *path, | |
885 | GdkRectangle *background_area, | |
886 | GdkRectangle *cell_area, | |
887 | GtkCellRendererState flags ); | |
1e510b1e RR |
888 | static GtkCellEditable *gtk_wx_cell_renderer_start_editing( |
889 | GtkCellRenderer *cell, | |
890 | GdkEvent *event, | |
891 | GtkWidget *widget, | |
892 | const gchar *path, | |
893 | GdkRectangle *background_area, | |
894 | GdkRectangle *cell_area, | |
895 | GtkCellRendererState flags ); | |
e8375af8 | 896 | |
e152afc3 RR |
897 | |
898 | static GObjectClass *cell_parent_class = NULL; | |
899 | ||
900 | } // extern "C" | |
901 | ||
93763ad5 | 902 | GType |
e152afc3 RR |
903 | gtk_wx_cell_renderer_get_type (void) |
904 | { | |
553f7d8f | 905 | static GType cell_wx_type = 0; |
e152afc3 | 906 | |
553f7d8f | 907 | if (!cell_wx_type) |
e152afc3 | 908 | { |
de4a74e2 | 909 | const GTypeInfo cell_wx_info = |
553f7d8f RR |
910 | { |
911 | sizeof (GtkWxCellRendererClass), | |
93763ad5 WS |
912 | NULL, /* base_init */ |
913 | NULL, /* base_finalize */ | |
553f7d8f | 914 | (GClassInitFunc) gtk_wx_cell_renderer_class_init, |
93763ad5 WS |
915 | NULL, /* class_finalize */ |
916 | NULL, /* class_data */ | |
553f7d8f RR |
917 | sizeof (GtkWxCellRenderer), |
918 | 0, /* n_preallocs */ | |
919 | (GInstanceInitFunc) gtk_wx_cell_renderer_init, | |
920 | }; | |
921 | ||
93763ad5 | 922 | cell_wx_type = g_type_register_static( GTK_TYPE_CELL_RENDERER, |
553f7d8f | 923 | "GtkWxCellRenderer", &cell_wx_info, (GTypeFlags)0 ); |
e152afc3 RR |
924 | } |
925 | ||
553f7d8f | 926 | return cell_wx_type; |
e152afc3 RR |
927 | } |
928 | ||
929 | static void | |
930 | gtk_wx_cell_renderer_init (GtkWxCellRenderer *cell) | |
931 | { | |
932 | cell->cell = NULL; | |
4d496ecb | 933 | cell->last_click = 0; |
e152afc3 RR |
934 | } |
935 | ||
936 | static void | |
937 | gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass *klass) | |
938 | { | |
939 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
940 | GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass); | |
941 | ||
942 | cell_parent_class = (GObjectClass*) g_type_class_peek_parent (klass); | |
943 | ||
944 | object_class->finalize = gtk_wx_cell_renderer_finalize; | |
945 | ||
946 | cell_class->get_size = gtk_wx_cell_renderer_get_size; | |
947 | cell_class->render = gtk_wx_cell_renderer_render; | |
553f7d8f | 948 | cell_class->activate = gtk_wx_cell_renderer_activate; |
1e510b1e | 949 | cell_class->start_editing = gtk_wx_cell_renderer_start_editing; |
e152afc3 RR |
950 | } |
951 | ||
952 | static void | |
953 | gtk_wx_cell_renderer_finalize (GObject *object) | |
954 | { | |
955 | /* must chain up */ | |
956 | (* G_OBJECT_CLASS (cell_parent_class)->finalize) (object); | |
957 | } | |
958 | ||
959 | GtkCellRenderer* | |
960 | gtk_wx_cell_renderer_new (void) | |
961 | { | |
962 | return (GtkCellRenderer*) g_object_new (GTK_TYPE_WX_CELL_RENDERER, NULL); | |
963 | } | |
964 | ||
1e510b1e RR |
965 | |
966 | ||
967 | static GtkCellEditable *gtk_wx_cell_renderer_start_editing( | |
968 | GtkCellRenderer *renderer, | |
c5c5395b | 969 | GdkEvent *WXUNUSED(event), |
1e510b1e RR |
970 | GtkWidget *widget, |
971 | const gchar *path, | |
c5c5395b | 972 | GdkRectangle *WXUNUSED(background_area), |
1e510b1e | 973 | GdkRectangle *cell_area, |
c5c5395b | 974 | GtkCellRendererState WXUNUSED(flags) ) |
1e510b1e RR |
975 | { |
976 | GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer; | |
977 | wxDataViewCustomRenderer *cell = wxrenderer->cell; | |
978 | if (!cell->HasEditorCtrl()) | |
979 | return NULL; | |
e8375af8 | 980 | |
1e510b1e RR |
981 | GdkRectangle rect; |
982 | gtk_wx_cell_renderer_get_size (renderer, widget, cell_area, | |
983 | &rect.x, | |
984 | &rect.y, | |
985 | &rect.width, | |
986 | &rect.height); | |
987 | ||
988 | rect.x += cell_area->x; | |
989 | rect.y += cell_area->y; | |
990 | // rect.width -= renderer->xpad * 2; | |
991 | // rect.height -= renderer->ypad * 2; | |
992 | ||
993 | // wxRect renderrect( rect.x, rect.y, rect.width, rect.height ); | |
994 | wxRect renderrect( cell_area->x, cell_area->y, cell_area->width, cell_area->height ); | |
995 | ||
1e510b1e | 996 | GtkTreePath *treepath = gtk_tree_path_new_from_string( path ); |
55fbde12 RR |
997 | GtkTreeIter iter; |
998 | cell->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter, treepath ); | |
999 | wxDataViewItem item( (void*) iter.user_data ); | |
1e510b1e RR |
1000 | gtk_tree_path_free( treepath ); |
1001 | ||
9d52aad3 | 1002 | cell->StartEditing( item, renderrect ); |
30715fa1 | 1003 | |
1e510b1e RR |
1004 | return NULL; |
1005 | } | |
1006 | ||
e152afc3 RR |
1007 | static void |
1008 | gtk_wx_cell_renderer_get_size (GtkCellRenderer *renderer, | |
c5c5395b | 1009 | GtkWidget *WXUNUSED(widget), |
93763ad5 WS |
1010 | GdkRectangle *cell_area, |
1011 | gint *x_offset, | |
1012 | gint *y_offset, | |
1013 | gint *width, | |
1014 | gint *height) | |
e152afc3 RR |
1015 | { |
1016 | GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer; | |
baa9ebc4 | 1017 | wxDataViewCustomRenderer *cell = wxrenderer->cell; |
93763ad5 | 1018 | |
e152afc3 RR |
1019 | wxSize size = cell->GetSize(); |
1020 | ||
1021 | gint calc_width = (gint) renderer->xpad * 2 + size.x; | |
1022 | gint calc_height = (gint) renderer->ypad * 2 + size.y; | |
93763ad5 WS |
1023 | |
1024 | if (x_offset) | |
e152afc3 | 1025 | *x_offset = 0; |
93763ad5 | 1026 | if (y_offset) |
e152afc3 RR |
1027 | *y_offset = 0; |
1028 | ||
1029 | if (cell_area && size.x > 0 && size.y > 0) | |
1030 | { | |
1031 | if (x_offset) | |
93763ad5 | 1032 | { |
e152afc3 RR |
1033 | *x_offset = (gint)((renderer->xalign * |
1034 | (cell_area->width - calc_width - 2 * renderer->xpad))); | |
1035 | *x_offset = MAX (*x_offset, 0) + renderer->xpad; | |
93763ad5 | 1036 | } |
e152afc3 RR |
1037 | if (y_offset) |
1038 | { | |
1039 | *y_offset = (gint)((renderer->yalign * | |
1040 | (cell_area->height - calc_height - 2 * renderer->ypad))); | |
1041 | *y_offset = MAX (*y_offset, 0) + renderer->ypad; | |
1042 | } | |
1043 | } | |
1044 | ||
1045 | if (width) | |
1046 | *width = calc_width; | |
93763ad5 | 1047 | |
e152afc3 RR |
1048 | if (height) |
1049 | *height = calc_height; | |
1050 | } | |
1051 | ||
1052 | static void | |
1053 | gtk_wx_cell_renderer_render (GtkCellRenderer *renderer, | |
93763ad5 WS |
1054 | GdkWindow *window, |
1055 | GtkWidget *widget, | |
1056 | GdkRectangle *background_area, | |
1057 | GdkRectangle *cell_area, | |
1058 | GdkRectangle *expose_area, | |
1059 | GtkCellRendererState flags) | |
e152afc3 RR |
1060 | |
1061 | { | |
1062 | GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer; | |
baa9ebc4 | 1063 | wxDataViewCustomRenderer *cell = wxrenderer->cell; |
93763ad5 | 1064 | |
f69c03de RR |
1065 | cell->window = window; |
1066 | cell->widget = widget; | |
1067 | cell->background_area = (void*) background_area; | |
1068 | cell->cell_area = (void*) cell_area; | |
1069 | cell->expose_area = (void*) expose_area; | |
1070 | cell->flags = (int) flags; | |
1071 | ||
e152afc3 RR |
1072 | GdkRectangle rect; |
1073 | gtk_wx_cell_renderer_get_size (renderer, widget, cell_area, | |
93763ad5 WS |
1074 | &rect.x, |
1075 | &rect.y, | |
1076 | &rect.width, | |
1077 | &rect.height); | |
e152afc3 RR |
1078 | |
1079 | rect.x += cell_area->x; | |
1080 | rect.y += cell_area->y; | |
1081 | rect.width -= renderer->xpad * 2; | |
1082 | rect.height -= renderer->ypad * 2; | |
93763ad5 | 1083 | |
e152afc3 RR |
1084 | GdkRectangle dummy; |
1085 | if (gdk_rectangle_intersect (expose_area, &rect, &dummy)) | |
1086 | { | |
1087 | wxRect renderrect( rect.x, rect.y, rect.width, rect.height ); | |
1088 | wxWindowDC* dc = (wxWindowDC*) cell->GetDC(); | |
888dde65 RR |
1089 | wxWindowDCImpl *impl = (wxWindowDCImpl *) dc->GetImpl(); |
1090 | if (impl->m_gdkwindow == NULL) | |
4f37154e | 1091 | { |
888dde65 RR |
1092 | impl->m_gdkwindow = window; |
1093 | impl->SetUpDC(); | |
4f37154e | 1094 | } |
93763ad5 | 1095 | |
e152afc3 RR |
1096 | int state = 0; |
1097 | if (flags & GTK_CELL_RENDERER_SELECTED) | |
1098 | state |= wxDATAVIEW_CELL_SELECTED; | |
1099 | if (flags & GTK_CELL_RENDERER_PRELIT) | |
1100 | state |= wxDATAVIEW_CELL_PRELIT; | |
1101 | if (flags & GTK_CELL_RENDERER_INSENSITIVE) | |
1102 | state |= wxDATAVIEW_CELL_INSENSITIVE; | |
1103 | if (flags & GTK_CELL_RENDERER_INSENSITIVE) | |
1104 | state |= wxDATAVIEW_CELL_INSENSITIVE; | |
1105 | if (flags & GTK_CELL_RENDERER_FOCUSED) | |
1106 | state |= wxDATAVIEW_CELL_FOCUSED; | |
1107 | cell->Render( renderrect, dc, state ); | |
93763ad5 | 1108 | } |
e152afc3 RR |
1109 | } |
1110 | ||
93763ad5 | 1111 | static gboolean |
553f7d8f RR |
1112 | gtk_wx_cell_renderer_activate( |
1113 | GtkCellRenderer *renderer, | |
1114 | GdkEvent *event, | |
1115 | GtkWidget *widget, | |
1116 | const gchar *path, | |
c5c5395b | 1117 | GdkRectangle *WXUNUSED(background_area), |
553f7d8f | 1118 | GdkRectangle *cell_area, |
c5c5395b | 1119 | GtkCellRendererState WXUNUSED(flags) ) |
553f7d8f RR |
1120 | { |
1121 | GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer; | |
baa9ebc4 | 1122 | wxDataViewCustomRenderer *cell = wxrenderer->cell; |
93763ad5 | 1123 | |
553f7d8f RR |
1124 | GdkRectangle rect; |
1125 | gtk_wx_cell_renderer_get_size (renderer, widget, cell_area, | |
93763ad5 WS |
1126 | &rect.x, |
1127 | &rect.y, | |
1128 | &rect.width, | |
1129 | &rect.height); | |
553f7d8f RR |
1130 | |
1131 | rect.x += cell_area->x; | |
1132 | rect.y += cell_area->y; | |
1133 | rect.width -= renderer->xpad * 2; | |
1134 | rect.height -= renderer->ypad * 2; | |
93763ad5 | 1135 | |
553f7d8f | 1136 | wxRect renderrect( rect.x, rect.y, rect.width, rect.height ); |
93763ad5 | 1137 | |
e0062c04 | 1138 | wxDataViewModel *model = cell->GetOwner()->GetOwner()->GetModel(); |
93763ad5 | 1139 | |
4d496ecb | 1140 | GtkTreePath *treepath = gtk_tree_path_new_from_string( path ); |
71c6b455 RR |
1141 | |
1142 | GtkTreeIter iter; | |
f69c03de | 1143 | cell->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter, treepath ); |
71c6b455 | 1144 | wxDataViewItem item( iter.user_data ); |
4d496ecb | 1145 | gtk_tree_path_free( treepath ); |
93763ad5 | 1146 | |
0a71f9e9 | 1147 | unsigned int model_col = cell->GetOwner()->GetModelColumn(); |
93763ad5 | 1148 | |
456e5c21 RR |
1149 | if (!event) |
1150 | { | |
1151 | bool ret = false; | |
e8375af8 | 1152 | |
456e5c21 | 1153 | // activated by <ENTER> |
9d52aad3 | 1154 | if (cell->Activate( renderrect, model, item, model_col )) |
456e5c21 | 1155 | ret = true; |
e8375af8 | 1156 | |
456e5c21 RR |
1157 | return ret; |
1158 | } | |
1159 | else if (event->type == GDK_BUTTON_PRESS) | |
4d496ecb RR |
1160 | { |
1161 | GdkEventButton *button_event = (GdkEventButton*) event; | |
93763ad5 | 1162 | wxPoint pt( ((int) button_event->x) - renderrect.x, |
4d496ecb | 1163 | ((int) button_event->y) - renderrect.y ); |
93763ad5 | 1164 | |
4d496ecb RR |
1165 | bool ret = false; |
1166 | if (button_event->button == 1) | |
1167 | { | |
9d52aad3 | 1168 | if (cell->LeftClick( pt, renderrect, model, item, model_col )) |
4d496ecb | 1169 | ret = true; |
7ea3a0de | 1170 | // TODO: query system double-click time |
4d496ecb | 1171 | if (button_event->time - wxrenderer->last_click < 400) |
9d52aad3 | 1172 | if (cell->Activate( renderrect, model, item, model_col )) |
4d496ecb RR |
1173 | ret = true; |
1174 | } | |
1175 | if (button_event->button == 3) | |
1176 | { | |
9d52aad3 | 1177 | if (cell->RightClick( pt, renderrect, model, item, model_col )) |
4d496ecb RR |
1178 | ret = true; |
1179 | } | |
93763ad5 | 1180 | |
4d496ecb | 1181 | wxrenderer->last_click = button_event->time; |
93763ad5 | 1182 | |
4d496ecb RR |
1183 | return ret; |
1184 | } | |
93763ad5 | 1185 | |
4d496ecb | 1186 | return false; |
553f7d8f RR |
1187 | } |
1188 | ||
93763ad5 | 1189 | // --------------------------------------------------------- |
e0062c04 | 1190 | // wxGtkDataViewModelNotifier |
93763ad5 | 1191 | // --------------------------------------------------------- |
6e2e590f | 1192 | |
e0062c04 | 1193 | class wxGtkDataViewModelNotifier: public wxDataViewModelNotifier |
6e2e590f RR |
1194 | { |
1195 | public: | |
e0062c04 RR |
1196 | wxGtkDataViewModelNotifier( GtkWxTreeModel *wxgtk_model, |
1197 | wxDataViewModel *wx_model, | |
1198 | wxDataViewCtrl *ctrl ); | |
1199 | ~wxGtkDataViewModelNotifier(); | |
1200 | ||
1201 | virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ); | |
469d3e9b | 1202 | virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ); |
e0062c04 RR |
1203 | virtual bool ItemChanged( const wxDataViewItem &item ); |
1204 | virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ); | |
6e2e590f | 1205 | virtual bool Cleared(); |
4508fcd2 | 1206 | virtual void Resort(); |
93763ad5 | 1207 | |
33ba5a05 RR |
1208 | void SetGtkModel( GtkWxTreeModel *model ) { m_wxgtk_model = model; } |
1209 | ||
1210 | private: | |
e0062c04 RR |
1211 | GtkWxTreeModel *m_wxgtk_model; |
1212 | wxDataViewModel *m_wx_model; | |
63415a42 | 1213 | wxDataViewCtrl *m_owner; |
6e2e590f RR |
1214 | }; |
1215 | ||
93763ad5 | 1216 | // --------------------------------------------------------- |
6e2e590f | 1217 | // wxGtkDataViewListModelNotifier |
93763ad5 | 1218 | // --------------------------------------------------------- |
6e2e590f | 1219 | |
e0062c04 RR |
1220 | wxGtkDataViewModelNotifier::wxGtkDataViewModelNotifier( |
1221 | GtkWxTreeModel* wxgtk_model, wxDataViewModel *wx_model, | |
63415a42 | 1222 | wxDataViewCtrl *ctrl ) |
6e2e590f | 1223 | { |
e0062c04 | 1224 | m_wxgtk_model = wxgtk_model; |
6e2e590f | 1225 | m_wx_model = wx_model; |
63415a42 | 1226 | m_owner = ctrl; |
6e2e590f | 1227 | } |
93763ad5 | 1228 | |
e0062c04 | 1229 | wxGtkDataViewModelNotifier::~wxGtkDataViewModelNotifier() |
f7ed8c89 RR |
1230 | { |
1231 | m_wx_model = NULL; | |
e0062c04 | 1232 | m_wxgtk_model = NULL; |
f7ed8c89 RR |
1233 | } |
1234 | ||
e0062c04 | 1235 | bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) |
6e2e590f | 1236 | { |
55fbde12 | 1237 | m_owner->GtkGetInternal()->ItemAdded( parent, item ); |
1e08ad10 | 1238 | |
6e2e590f | 1239 | GtkTreeIter iter; |
e0062c04 RR |
1240 | iter.stamp = m_wxgtk_model->stamp; |
1241 | iter.user_data = (gpointer) item.GetID(); | |
93763ad5 | 1242 | |
b9db5f30 | 1243 | GtkTreePath *path = wxgtk_tree_model_get_path( |
e0062c04 | 1244 | GTK_TREE_MODEL(m_wxgtk_model), &iter ); |
b9db5f30 | 1245 | gtk_tree_model_row_inserted( |
e0062c04 | 1246 | GTK_TREE_MODEL(m_wxgtk_model), path, &iter); |
6e2e590f | 1247 | gtk_tree_path_free (path); |
93763ad5 | 1248 | |
6e2e590f RR |
1249 | return true; |
1250 | } | |
1251 | ||
469d3e9b | 1252 | bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ) |
6e2e590f | 1253 | { |
605c2c4a | 1254 | GtkTreeIter iter; |
e0062c04 RR |
1255 | iter.stamp = m_wxgtk_model->stamp; |
1256 | iter.user_data = (gpointer) item.GetID(); | |
93763ad5 | 1257 | |
b9db5f30 | 1258 | GtkTreePath *path = wxgtk_tree_model_get_path( |
e0062c04 RR |
1259 | GTK_TREE_MODEL(m_wxgtk_model), &iter ); |
1260 | gtk_tree_model_row_deleted( | |
1261 | GTK_TREE_MODEL(m_wxgtk_model), path ); | |
605c2c4a | 1262 | gtk_tree_path_free (path); |
93763ad5 | 1263 | |
469d3e9b | 1264 | m_owner->GtkGetInternal()->ItemDeleted( parent, item ); |
b9db5f30 | 1265 | |
605c2c4a | 1266 | return true; |
6e2e590f RR |
1267 | } |
1268 | ||
4508fcd2 RR |
1269 | void wxGtkDataViewModelNotifier::Resort() |
1270 | { | |
1271 | m_owner->GtkGetInternal()->Resort(); | |
1272 | } | |
1273 | ||
e0062c04 | 1274 | bool wxGtkDataViewModelNotifier::ItemChanged( const wxDataViewItem &item ) |
6e2e590f | 1275 | { |
4627af27 | 1276 | GtkTreeIter iter; |
e0062c04 RR |
1277 | iter.stamp = m_wxgtk_model->stamp; |
1278 | iter.user_data = (gpointer) item.GetID(); | |
6e2e590f | 1279 | |
b9db5f30 | 1280 | GtkTreePath *path = wxgtk_tree_model_get_path( |
e0062c04 RR |
1281 | GTK_TREE_MODEL(m_wxgtk_model), &iter ); |
1282 | gtk_tree_model_row_changed( | |
1283 | GTK_TREE_MODEL(m_wxgtk_model), path, &iter ); | |
a7f61f76 RR |
1284 | gtk_tree_path_free (path); |
1285 | ||
d8331a01 | 1286 | m_owner->GtkGetInternal()->ItemChanged( item ); |
b9db5f30 | 1287 | |
a7f61f76 | 1288 | return true; |
6e2e590f RR |
1289 | } |
1290 | ||
e0062c04 | 1291 | bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem &item, unsigned int model_col ) |
6e2e590f | 1292 | { |
4eccd3a1 | 1293 | // This adds GTK+'s missing MVC logic for ValueChanged |
63415a42 RR |
1294 | unsigned int index; |
1295 | for (index = 0; index < m_owner->GetColumnCount(); index++) | |
8f850e28 | 1296 | { |
63415a42 RR |
1297 | wxDataViewColumn *column = m_owner->GetColumn( index ); |
1298 | if (column->GetModelColumn() == model_col) | |
8f850e28 | 1299 | { |
63415a42 RR |
1300 | GtkTreeView *widget = GTK_TREE_VIEW(m_owner->m_treeview); |
1301 | GtkTreeViewColumn *gcolumn = GTK_TREE_VIEW_COLUMN(column->GetGtkHandle()); | |
8f850e28 RR |
1302 | |
1303 | // Get cell area | |
e0062c04 RR |
1304 | GtkTreeIter iter; |
1305 | iter.stamp = m_wxgtk_model->stamp; | |
1306 | iter.user_data = (gpointer) item.GetID(); | |
b9db5f30 | 1307 | GtkTreePath *path = wxgtk_tree_model_get_path( |
e0062c04 | 1308 | GTK_TREE_MODEL(m_wxgtk_model), &iter ); |
8f850e28 | 1309 | GdkRectangle cell_area; |
63415a42 | 1310 | gtk_tree_view_get_cell_area( widget, path, gcolumn, &cell_area ); |
93763ad5 | 1311 | gtk_tree_path_free( path ); |
8f850e28 | 1312 | |
1a64259d RR |
1313 | GtkAdjustment* hadjust = gtk_tree_view_get_hadjustment( widget ); |
1314 | double d = gtk_adjustment_get_value( hadjust ); | |
1315 | int xdiff = (int) d; | |
1316 | ||
63415a42 | 1317 | int ydiff = gcolumn->button->allocation.height; |
8f850e28 | 1318 | // Redraw |
93763ad5 | 1319 | gtk_widget_queue_draw_area( GTK_WIDGET(widget), |
1a64259d | 1320 | cell_area.x - xdiff, ydiff + cell_area.y, cell_area.width, cell_area.height ); |
b9db5f30 | 1321 | |
d8331a01 | 1322 | m_owner->GtkGetInternal()->ValueChanged( item, model_col ); |
b9db5f30 | 1323 | |
d8331a01 | 1324 | return true; |
8f850e28 | 1325 | } |
8f850e28 | 1326 | } |
93763ad5 | 1327 | |
d8331a01 | 1328 | return false; |
6e2e590f RR |
1329 | } |
1330 | ||
e0062c04 | 1331 | bool wxGtkDataViewModelNotifier::Cleared() |
6e2e590f | 1332 | { |
33ba5a05 RR |
1333 | gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner->m_treeview), NULL ); |
1334 | ||
1335 | // this will create a new GTK model | |
d8331a01 | 1336 | m_owner->GtkGetInternal()->Cleared(); |
33ba5a05 RR |
1337 | |
1338 | SetGtkModel( m_owner->GtkGetInternal()->GetGtkModel() ); | |
b9db5f30 | 1339 | |
33ba5a05 RR |
1340 | gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner->m_treeview), GTK_TREE_MODEL(m_wxgtk_model) ); |
1341 | ||
6e2e590f RR |
1342 | return false; |
1343 | } | |
1344 | ||
93763ad5 | 1345 | // --------------------------------------------------------- |
baa9ebc4 | 1346 | // wxDataViewRenderer |
93763ad5 | 1347 | // --------------------------------------------------------- |
6842a71a | 1348 | |
a912e81f RR |
1349 | static gpointer s_user_data = NULL; |
1350 | ||
1351 | static void | |
c5c5395b | 1352 | wxgtk_cell_editable_editing_done( GtkCellEditable *WXUNUSED(editable), |
a912e81f RR |
1353 | wxDataViewRenderer *wxrenderer ) |
1354 | { | |
1355 | wxDataViewColumn *column = wxrenderer->GetOwner(); | |
1356 | wxDataViewCtrl *dv = column->GetOwner(); | |
1357 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, dv->GetId() ); | |
1358 | event.SetDataViewColumn( column ); | |
1359 | event.SetModel( dv->GetModel() ); | |
1360 | wxDataViewItem item( s_user_data ); | |
1361 | event.SetItem( item ); | |
937013e0 | 1362 | dv->HandleWindowEvent( event ); |
a912e81f RR |
1363 | } |
1364 | ||
b9db5f30 | 1365 | static void |
c5c5395b | 1366 | wxgtk_renderer_editing_started( GtkCellRenderer *WXUNUSED(cell), GtkCellEditable *editable, |
a912e81f RR |
1367 | gchar *path, wxDataViewRenderer *wxrenderer ) |
1368 | { | |
1369 | wxDataViewColumn *column = wxrenderer->GetOwner(); | |
1370 | wxDataViewCtrl *dv = column->GetOwner(); | |
1371 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, dv->GetId() ); | |
1372 | event.SetDataViewColumn( column ); | |
1373 | event.SetModel( dv->GetModel() ); | |
1374 | GtkTreePath *tree_path = gtk_tree_path_new_from_string( path ); | |
1375 | GtkTreeIter iter; | |
1376 | dv->GtkGetInternal()->get_iter( &iter, tree_path ); | |
1377 | gtk_tree_path_free( tree_path ); | |
1378 | wxDataViewItem item( iter.user_data ); | |
1379 | event.SetItem( item ); | |
937013e0 | 1380 | dv->HandleWindowEvent( event ); |
a912e81f RR |
1381 | |
1382 | if (GTK_IS_CELL_EDITABLE(editable)) | |
1383 | { | |
1384 | s_user_data = iter.user_data; | |
b9db5f30 | 1385 | |
a912e81f RR |
1386 | g_signal_connect (GTK_CELL_EDITABLE (editable), "editing_done", |
1387 | G_CALLBACK (wxgtk_cell_editable_editing_done), | |
1388 | (gpointer) wxrenderer ); | |
b9db5f30 | 1389 | |
a912e81f RR |
1390 | } |
1391 | } | |
1392 | ||
1393 | ||
baa9ebc4 | 1394 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer, wxDataViewRendererBase) |
6842a71a | 1395 | |
9861f022 RR |
1396 | wxDataViewRenderer::wxDataViewRenderer( const wxString &varianttype, wxDataViewCellMode mode, |
1397 | int align ) : | |
1398 | wxDataViewRendererBase( varianttype, mode, align ) | |
6842a71a RR |
1399 | { |
1400 | m_renderer = NULL; | |
9861f022 RR |
1401 | |
1402 | // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor, | |
1403 | // after the m_renderer pointer has been initialized | |
1404 | } | |
1405 | ||
a912e81f RR |
1406 | void wxDataViewRenderer::GtkInitHandlers() |
1407 | { | |
1408 | if (!gtk_check_version(2,6,0)) | |
1409 | { | |
1410 | g_signal_connect (GTK_CELL_RENDERER(m_renderer), "editing_started", | |
1411 | G_CALLBACK (wxgtk_renderer_editing_started), | |
1412 | this); | |
1413 | } | |
1414 | } | |
1415 | ||
9861f022 RR |
1416 | void wxDataViewRenderer::SetMode( wxDataViewCellMode mode ) |
1417 | { | |
1418 | GtkCellRendererMode gtkMode; | |
1419 | switch (mode) | |
1420 | { | |
1421 | case wxDATAVIEW_CELL_INERT: | |
1422 | gtkMode = GTK_CELL_RENDERER_MODE_INERT; | |
1423 | break; | |
1424 | case wxDATAVIEW_CELL_ACTIVATABLE: | |
1425 | gtkMode = GTK_CELL_RENDERER_MODE_ACTIVATABLE; | |
1426 | break; | |
1427 | case wxDATAVIEW_CELL_EDITABLE: | |
1428 | gtkMode = GTK_CELL_RENDERER_MODE_EDITABLE; | |
1429 | break; | |
1430 | } | |
1431 | ||
b9db5f30 | 1432 | // This value is most often ignored in GtkTreeView |
9861f022 RR |
1433 | GValue gvalue = { 0, }; |
1434 | g_value_init( &gvalue, gtk_cell_renderer_mode_get_type() ); | |
1435 | g_value_set_enum( &gvalue, gtkMode ); | |
1436 | g_object_set_property( G_OBJECT(m_renderer), "mode", &gvalue ); | |
1437 | g_value_unset( &gvalue ); | |
1438 | } | |
1439 | ||
1440 | wxDataViewCellMode wxDataViewRenderer::GetMode() const | |
1441 | { | |
1442 | wxDataViewCellMode ret; | |
1443 | ||
1444 | GValue gvalue; | |
1445 | g_object_get( G_OBJECT(m_renderer), "mode", &gvalue, NULL); | |
1446 | ||
1447 | switch (g_value_get_enum(&gvalue)) | |
1448 | { | |
1449 | case GTK_CELL_RENDERER_MODE_INERT: | |
1450 | ret = wxDATAVIEW_CELL_INERT; | |
1451 | break; | |
1452 | case GTK_CELL_RENDERER_MODE_ACTIVATABLE: | |
1453 | ret = wxDATAVIEW_CELL_ACTIVATABLE; | |
1454 | break; | |
1455 | case GTK_CELL_RENDERER_MODE_EDITABLE: | |
1456 | ret = wxDATAVIEW_CELL_EDITABLE; | |
1457 | break; | |
1458 | } | |
1459 | ||
1460 | g_value_unset( &gvalue ); | |
1461 | ||
1462 | return ret; | |
1463 | } | |
1464 | ||
1465 | void wxDataViewRenderer::SetAlignment( int align ) | |
1466 | { | |
1467 | // horizontal alignment: | |
1468 | ||
1469 | gfloat xalign = 0.0; | |
1470 | if (align & wxALIGN_RIGHT) | |
1471 | xalign = 1.0; | |
1472 | else if (align & wxALIGN_CENTER_HORIZONTAL) | |
1473 | xalign = 0.5; | |
1474 | ||
1475 | GValue gvalue = { 0, }; | |
1476 | g_value_init( &gvalue, G_TYPE_FLOAT ); | |
1477 | g_value_set_float( &gvalue, xalign ); | |
1478 | g_object_set_property( G_OBJECT(m_renderer), "xalign", &gvalue ); | |
1479 | g_value_unset( &gvalue ); | |
1480 | ||
1481 | // vertical alignment: | |
1482 | ||
1483 | gfloat yalign = 0.0; | |
1484 | if (align & wxALIGN_BOTTOM) | |
1485 | yalign = 1.0; | |
1486 | else if (align & wxALIGN_CENTER_VERTICAL) | |
1487 | yalign = 0.5; | |
1488 | ||
1489 | GValue gvalue2 = { 0, }; | |
1490 | g_value_init( &gvalue2, G_TYPE_FLOAT ); | |
1491 | g_value_set_float( &gvalue2, yalign ); | |
1492 | g_object_set_property( G_OBJECT(m_renderer), "yalign", &gvalue2 ); | |
1493 | g_value_unset( &gvalue2 ); | |
6842a71a RR |
1494 | } |
1495 | ||
9861f022 RR |
1496 | int wxDataViewRenderer::GetAlignment() const |
1497 | { | |
1498 | int ret = 0; | |
1499 | GValue gvalue; | |
1500 | ||
1501 | // horizontal alignment: | |
1502 | ||
1503 | g_object_get( G_OBJECT(m_renderer), "xalign", &gvalue, NULL ); | |
1504 | float xalign = g_value_get_float( &gvalue ); | |
1505 | if (xalign < 0.5) | |
1506 | ret |= wxALIGN_LEFT; | |
1507 | else if (xalign == 0.5) | |
1508 | ret |= wxALIGN_CENTER_HORIZONTAL; | |
1509 | else | |
1510 | ret |= wxALIGN_RIGHT; | |
1511 | g_value_unset( &gvalue ); | |
1512 | ||
1513 | ||
1514 | // vertical alignment: | |
1515 | ||
1516 | g_object_get( G_OBJECT(m_renderer), "yalign", &gvalue, NULL ); | |
1517 | float yalign = g_value_get_float( &gvalue ); | |
1518 | if (yalign < 0.5) | |
1519 | ret |= wxALIGN_TOP; | |
1520 | else if (yalign == 0.5) | |
1521 | ret |= wxALIGN_CENTER_VERTICAL; | |
1522 | else | |
1523 | ret |= wxALIGN_BOTTOM; | |
1524 | g_value_unset( &gvalue ); | |
1525 | ||
1526 | return ret; | |
1527 | } | |
1528 | ||
1529 | ||
1530 | ||
93763ad5 | 1531 | // --------------------------------------------------------- |
baa9ebc4 | 1532 | // wxDataViewTextRenderer |
93763ad5 | 1533 | // --------------------------------------------------------- |
6842a71a | 1534 | |
a7f61f76 | 1535 | extern "C" { |
93763ad5 | 1536 | static void wxGtkTextRendererEditedCallback( GtkCellRendererText *renderer, |
a7f61f76 RR |
1537 | gchar *arg1, gchar *arg2, gpointer user_data ); |
1538 | } | |
1539 | ||
c5c5395b | 1540 | static void wxGtkTextRendererEditedCallback( GtkCellRendererText *WXUNUSED(renderer), |
a7f61f76 RR |
1541 | gchar *arg1, gchar *arg2, gpointer user_data ) |
1542 | { | |
baa9ebc4 | 1543 | wxDataViewTextRenderer *cell = (wxDataViewTextRenderer*) user_data; |
93763ad5 | 1544 | |
1a74f561 | 1545 | wxString tmp = wxGTK_CONV_BACK_FONT(arg2, cell->GetOwner()->GetOwner()->GetFont()); |
a7f61f76 RR |
1546 | wxVariant value = tmp; |
1547 | if (!cell->Validate( value )) | |
1548 | return; | |
93763ad5 | 1549 | |
e0062c04 | 1550 | wxDataViewModel *model = cell->GetOwner()->GetOwner()->GetModel(); |
93763ad5 | 1551 | |
a7f61f76 | 1552 | GtkTreePath *path = gtk_tree_path_new_from_string( arg1 ); |
9d52aad3 | 1553 | GtkTreeIter iter; |
55fbde12 RR |
1554 | cell->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter, path ); |
1555 | wxDataViewItem item( (void*) iter.user_data );; | |
a7f61f76 | 1556 | gtk_tree_path_free( path ); |
93763ad5 | 1557 | |
0a71f9e9 | 1558 | unsigned int model_col = cell->GetOwner()->GetModelColumn(); |
93763ad5 | 1559 | |
9d52aad3 RR |
1560 | model->SetValue( value, item, model_col ); |
1561 | model->ValueChanged( item, model_col ); | |
a7f61f76 RR |
1562 | } |
1563 | ||
baa9ebc4 | 1564 | IMPLEMENT_CLASS(wxDataViewTextRenderer, wxDataViewRenderer) |
6842a71a | 1565 | |
9861f022 RR |
1566 | wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString &varianttype, wxDataViewCellMode mode, |
1567 | int align ) : | |
1568 | wxDataViewRenderer( varianttype, mode, align ) | |
6842a71a | 1569 | { |
ed38aa55 | 1570 | m_renderer = (GtkCellRenderer*) gtk_cell_renderer_text_new(); |
93763ad5 | 1571 | |
9861f022 | 1572 | if (mode & wxDATAVIEW_CELL_EDITABLE) |
a7f61f76 RR |
1573 | { |
1574 | GValue gvalue = { 0, }; | |
1575 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
1576 | g_value_set_boolean( &gvalue, true ); | |
1577 | g_object_set_property( G_OBJECT(m_renderer), "editable", &gvalue ); | |
1578 | g_value_unset( &gvalue ); | |
93763ad5 | 1579 | |
a7f61f76 | 1580 | g_signal_connect_after( m_renderer, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback), this ); |
b9db5f30 | 1581 | |
a912e81f | 1582 | GtkInitHandlers(); |
a7f61f76 | 1583 | } |
9861f022 RR |
1584 | |
1585 | SetMode(mode); | |
1586 | SetAlignment(align); | |
6842a71a | 1587 | } |
790b137e | 1588 | |
baa9ebc4 | 1589 | bool wxDataViewTextRenderer::SetValue( const wxVariant &value ) |
7b4fde82 RR |
1590 | { |
1591 | wxString tmp = value; | |
93763ad5 | 1592 | |
7b4fde82 RR |
1593 | GValue gvalue = { 0, }; |
1594 | g_value_init( &gvalue, G_TYPE_STRING ); | |
1bf629bd | 1595 | g_value_set_string( &gvalue, wxGTK_CONV_FONT( tmp, GetOwner()->GetOwner()->GetFont() ) ); |
7b4fde82 RR |
1596 | g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue ); |
1597 | g_value_unset( &gvalue ); | |
93763ad5 | 1598 | |
7b4fde82 RR |
1599 | return true; |
1600 | } | |
1601 | ||
9861f022 | 1602 | bool wxDataViewTextRenderer::GetValue( wxVariant &value ) const |
a7f61f76 RR |
1603 | { |
1604 | GValue gvalue = { 0, }; | |
1605 | g_value_init( &gvalue, G_TYPE_STRING ); | |
1606 | g_object_get_property( G_OBJECT(m_renderer), "text", &gvalue ); | |
1bf629bd | 1607 | wxString tmp = wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue ), wx_const_cast(wxDataViewTextRenderer*, this)->GetOwner()->GetOwner()->GetFont() ); |
a7f61f76 | 1608 | g_value_unset( &gvalue ); |
93763ad5 | 1609 | |
a7f61f76 RR |
1610 | value = tmp; |
1611 | ||
1612 | return true; | |
1613 | } | |
1614 | ||
9861f022 RR |
1615 | void wxDataViewTextRenderer::SetAlignment( int align ) |
1616 | { | |
1617 | wxDataViewRenderer::SetAlignment(align); | |
1618 | ||
01705e98 RR |
1619 | if (gtk_check_version(2,10,0)) |
1620 | return; | |
9861f022 | 1621 | |
01705e98 | 1622 | // horizontal alignment: |
9861f022 RR |
1623 | PangoAlignment pangoAlign = PANGO_ALIGN_LEFT; |
1624 | if (align & wxALIGN_RIGHT) | |
1625 | pangoAlign = PANGO_ALIGN_RIGHT; | |
1626 | else if (align & wxALIGN_CENTER_HORIZONTAL) | |
1627 | pangoAlign = PANGO_ALIGN_CENTER; | |
1628 | ||
1629 | GValue gvalue = { 0, }; | |
1630 | g_value_init( &gvalue, gtk_cell_renderer_mode_get_type() ); | |
1631 | g_value_set_enum( &gvalue, pangoAlign ); | |
1632 | g_object_set_property( G_OBJECT(m_renderer), "alignment", &gvalue ); | |
1633 | g_value_unset( &gvalue ); | |
1634 | } | |
1635 | ||
b9db5f30 | 1636 | // --------------------------------------------------------- |
4264606e | 1637 | // wxDataViewTextRendererAttr |
b9db5f30 | 1638 | // --------------------------------------------------------- |
4264606e RR |
1639 | |
1640 | IMPLEMENT_CLASS(wxDataViewTextRendererAttr,wxDataViewTextRenderer) | |
1641 | ||
b9db5f30 | 1642 | wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString &varianttype, |
4264606e RR |
1643 | wxDataViewCellMode mode, int align ) : |
1644 | wxDataViewTextRenderer( varianttype, mode, align ) | |
1645 | { | |
1646 | } | |
b9db5f30 | 1647 | |
f4322df6 | 1648 | // --------------------------------------------------------- |
baa9ebc4 | 1649 | // wxDataViewBitmapRenderer |
f4322df6 | 1650 | // --------------------------------------------------------- |
cbc9145c | 1651 | |
baa9ebc4 | 1652 | IMPLEMENT_CLASS(wxDataViewBitmapRenderer, wxDataViewRenderer) |
cbc9145c | 1653 | |
9861f022 RR |
1654 | wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString &varianttype, wxDataViewCellMode mode, |
1655 | int align ) : | |
1656 | wxDataViewRenderer( varianttype, mode, align ) | |
cbc9145c | 1657 | { |
ed38aa55 | 1658 | m_renderer = (GtkCellRenderer*) gtk_cell_renderer_pixbuf_new(); |
9861f022 RR |
1659 | |
1660 | SetMode(mode); | |
1661 | SetAlignment(align); | |
cbc9145c RR |
1662 | } |
1663 | ||
baa9ebc4 | 1664 | bool wxDataViewBitmapRenderer::SetValue( const wxVariant &value ) |
cbc9145c RR |
1665 | { |
1666 | if (value.GetType() == wxT("wxBitmap")) | |
1667 | { | |
2586d4a1 RR |
1668 | wxBitmap bitmap; |
1669 | bitmap << value; | |
f4322df6 | 1670 | |
2586d4a1 RR |
1671 | // This may create a Pixbuf representation in the |
1672 | // wxBitmap object (and it will stay there) | |
1673 | GdkPixbuf *pixbuf = bitmap.GetPixbuf(); | |
f4322df6 | 1674 | |
2586d4a1 RR |
1675 | GValue gvalue = { 0, }; |
1676 | g_value_init( &gvalue, G_TYPE_OBJECT ); | |
1677 | g_value_set_object( &gvalue, pixbuf ); | |
1678 | g_object_set_property( G_OBJECT(m_renderer), "pixbuf", &gvalue ); | |
1679 | g_value_unset( &gvalue ); | |
f4322df6 | 1680 | |
2586d4a1 RR |
1681 | return true; |
1682 | } | |
f4322df6 | 1683 | |
2586d4a1 RR |
1684 | if (value.GetType() == wxT("wxIcon")) |
1685 | { | |
1686 | wxIcon bitmap; | |
1687 | bitmap << value; | |
f4322df6 | 1688 | |
cbc9145c RR |
1689 | // This may create a Pixbuf representation in the |
1690 | // wxBitmap object (and it will stay there) | |
2586d4a1 | 1691 | GdkPixbuf *pixbuf = bitmap.GetPixbuf(); |
f4322df6 | 1692 | |
cbc9145c RR |
1693 | GValue gvalue = { 0, }; |
1694 | g_value_init( &gvalue, G_TYPE_OBJECT ); | |
1695 | g_value_set_object( &gvalue, pixbuf ); | |
1696 | g_object_set_property( G_OBJECT(m_renderer), "pixbuf", &gvalue ); | |
1697 | g_value_unset( &gvalue ); | |
f4322df6 | 1698 | |
cbc9145c RR |
1699 | return true; |
1700 | } | |
f4322df6 | 1701 | |
cbc9145c RR |
1702 | return false; |
1703 | } | |
1704 | ||
c5c5395b | 1705 | bool wxDataViewBitmapRenderer::GetValue( wxVariant &WXUNUSED(value) ) const |
cbc9145c RR |
1706 | { |
1707 | return false; | |
1708 | } | |
f4322df6 | 1709 | |
93763ad5 | 1710 | // --------------------------------------------------------- |
baa9ebc4 | 1711 | // wxDataViewToggleRenderer |
93763ad5 | 1712 | // --------------------------------------------------------- |
fa28826d | 1713 | |
605c2c4a | 1714 | extern "C" { |
93763ad5 | 1715 | static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle *renderer, |
605c2c4a RR |
1716 | gchar *path, gpointer user_data ); |
1717 | } | |
1718 | ||
93763ad5 | 1719 | static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle *renderer, |
605c2c4a RR |
1720 | gchar *path, gpointer user_data ) |
1721 | { | |
baa9ebc4 | 1722 | wxDataViewToggleRenderer *cell = (wxDataViewToggleRenderer*) user_data; |
605c2c4a | 1723 | |
93763ad5 | 1724 | // get old value |
605c2c4a RR |
1725 | GValue gvalue = { 0, }; |
1726 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
1727 | g_object_get_property( G_OBJECT(renderer), "active", &gvalue ); | |
93763ad5 | 1728 | bool tmp = g_value_get_boolean( &gvalue ); |
605c2c4a RR |
1729 | g_value_unset( &gvalue ); |
1730 | // invert it | |
1731 | tmp = !tmp; | |
93763ad5 | 1732 | |
605c2c4a RR |
1733 | wxVariant value = tmp; |
1734 | if (!cell->Validate( value )) | |
1735 | return; | |
93763ad5 | 1736 | |
e0062c04 | 1737 | wxDataViewModel *model = cell->GetOwner()->GetOwner()->GetModel(); |
93763ad5 | 1738 | |
605c2c4a | 1739 | GtkTreePath *gtk_path = gtk_tree_path_new_from_string( path ); |
55fbde12 RR |
1740 | GtkTreeIter iter; |
1741 | cell->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter, gtk_path ); | |
1742 | wxDataViewItem item( (void*) iter.user_data );; | |
605c2c4a | 1743 | gtk_tree_path_free( gtk_path ); |
93763ad5 | 1744 | |
0a71f9e9 | 1745 | unsigned int model_col = cell->GetOwner()->GetModelColumn(); |
93763ad5 | 1746 | |
9d52aad3 RR |
1747 | model->SetValue( value, item, model_col ); |
1748 | model->ValueChanged( item, model_col ); | |
605c2c4a RR |
1749 | } |
1750 | ||
baa9ebc4 | 1751 | IMPLEMENT_CLASS(wxDataViewToggleRenderer, wxDataViewRenderer) |
605c2c4a | 1752 | |
baa9ebc4 | 1753 | wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString &varianttype, |
9861f022 RR |
1754 | wxDataViewCellMode mode, int align ) : |
1755 | wxDataViewRenderer( varianttype, mode, align ) | |
605c2c4a | 1756 | { |
ed38aa55 | 1757 | m_renderer = (GtkCellRenderer*) gtk_cell_renderer_toggle_new(); |
93763ad5 | 1758 | |
9861f022 | 1759 | if (mode & wxDATAVIEW_CELL_ACTIVATABLE) |
605c2c4a | 1760 | { |
9861f022 RR |
1761 | g_signal_connect_after( m_renderer, "toggled", |
1762 | G_CALLBACK(wxGtkToggleRendererToggledCallback), this ); | |
553f7d8f RR |
1763 | } |
1764 | else | |
1765 | { | |
605c2c4a RR |
1766 | GValue gvalue = { 0, }; |
1767 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
553f7d8f | 1768 | g_value_set_boolean( &gvalue, false ); |
605c2c4a RR |
1769 | g_object_set_property( G_OBJECT(m_renderer), "activatable", &gvalue ); |
1770 | g_value_unset( &gvalue ); | |
605c2c4a | 1771 | } |
9861f022 RR |
1772 | |
1773 | SetMode(mode); | |
1774 | SetAlignment(align); | |
605c2c4a RR |
1775 | } |
1776 | ||
baa9ebc4 | 1777 | bool wxDataViewToggleRenderer::SetValue( const wxVariant &value ) |
605c2c4a RR |
1778 | { |
1779 | bool tmp = value; | |
93763ad5 | 1780 | |
605c2c4a RR |
1781 | GValue gvalue = { 0, }; |
1782 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
1783 | g_value_set_boolean( &gvalue, tmp ); | |
1784 | g_object_set_property( G_OBJECT(m_renderer), "active", &gvalue ); | |
1785 | g_value_unset( &gvalue ); | |
93763ad5 | 1786 | |
605c2c4a RR |
1787 | return true; |
1788 | } | |
1789 | ||
9861f022 | 1790 | bool wxDataViewToggleRenderer::GetValue( wxVariant &value ) const |
605c2c4a RR |
1791 | { |
1792 | GValue gvalue = { 0, }; | |
1793 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
1794 | g_object_get_property( G_OBJECT(m_renderer), "active", &gvalue ); | |
93763ad5 | 1795 | bool tmp = g_value_get_boolean( &gvalue ); |
605c2c4a | 1796 | g_value_unset( &gvalue ); |
93763ad5 | 1797 | |
605c2c4a RR |
1798 | value = tmp; |
1799 | ||
1800 | return true; | |
1801 | } | |
93763ad5 WS |
1802 | |
1803 | // --------------------------------------------------------- | |
baa9ebc4 | 1804 | // wxDataViewCustomRenderer |
93763ad5 | 1805 | // --------------------------------------------------------- |
e152afc3 | 1806 | |
888dde65 | 1807 | class wxDataViewCtrlDCImpl: public wxWindowDCImpl |
e152afc3 RR |
1808 | { |
1809 | public: | |
888dde65 RR |
1810 | wxDataViewCtrlDCImpl( wxDC *owner, wxDataViewCtrl *window ) : |
1811 | wxWindowDCImpl( owner ) | |
1812 | { | |
1a367564 | 1813 | GtkWidget *widget = window->m_treeview; |
e152afc3 | 1814 | // Set later |
888dde65 RR |
1815 | m_gdkwindow = NULL; |
1816 | ||
1817 | m_window = window; | |
4d496ecb | 1818 | |
e152afc3 RR |
1819 | m_context = window->GtkGetPangoDefaultContext(); |
1820 | m_layout = pango_layout_new( m_context ); | |
1821 | m_fontdesc = pango_font_description_copy( widget->style->font_desc ); | |
1822 | ||
1823 | m_cmap = gtk_widget_get_colormap( widget ? widget : window->m_widget ); | |
888dde65 RR |
1824 | |
1825 | // Set m_gdkwindow later | |
4d496ecb | 1826 | // SetUpDC(); |
e152afc3 RR |
1827 | } |
1828 | }; | |
1829 | ||
888dde65 RR |
1830 | class wxDataViewCtrlDC: public wxWindowDC |
1831 | { | |
1832 | public: | |
c5c5395b RR |
1833 | wxDataViewCtrlDC( wxDataViewCtrl *window ) : |
1834 | wxWindowDC( new wxDataViewCtrlDCImpl( this, window ) ) | |
1835 | { } | |
888dde65 RR |
1836 | }; |
1837 | ||
1838 | ||
93763ad5 | 1839 | // --------------------------------------------------------- |
baa9ebc4 | 1840 | // wxDataViewCustomRenderer |
93763ad5 | 1841 | // --------------------------------------------------------- |
e152afc3 | 1842 | |
baa9ebc4 | 1843 | IMPLEMENT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer) |
e152afc3 | 1844 | |
baa9ebc4 | 1845 | wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype, |
9861f022 RR |
1846 | wxDataViewCellMode mode, int align, |
1847 | bool no_init ) : | |
1848 | wxDataViewRenderer( varianttype, mode, align ) | |
e152afc3 RR |
1849 | { |
1850 | m_dc = NULL; | |
f69c03de | 1851 | m_text_renderer = NULL; |
93763ad5 | 1852 | |
ad63bf41 RR |
1853 | if (no_init) |
1854 | m_renderer = NULL; | |
1855 | else | |
9861f022 | 1856 | Init(mode, align); |
ad63bf41 RR |
1857 | } |
1858 | ||
85136e3b RR |
1859 | void wxDataViewCustomRenderer::RenderText( const wxString &text, int xoffset, |
1860 | wxRect WXUNUSED(cell), wxDC *WXUNUSED(dc), int WXUNUSED(state) ) | |
52e750fc | 1861 | { |
f69c03de | 1862 | #if 0 |
52e750fc RR |
1863 | wxDataViewCtrl *view = GetOwner()->GetOwner(); |
1864 | wxColour col = (state & wxDATAVIEW_CELL_SELECTED) ? | |
1865 | wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) : | |
1866 | view->GetForegroundColour(); | |
1867 | dc->SetTextForeground(col); | |
1868 | dc->DrawText( text, cell.x + xoffset, cell.y + ((cell.height - dc->GetCharHeight()) / 2)); | |
f69c03de RR |
1869 | #else |
1870 | if (!m_text_renderer) | |
1871 | m_text_renderer = gtk_cell_renderer_text_new(); | |
b9db5f30 | 1872 | |
f69c03de RR |
1873 | GValue gvalue = { 0, }; |
1874 | g_value_init( &gvalue, G_TYPE_STRING ); | |
1bf629bd | 1875 | g_value_set_string( &gvalue, wxGTK_CONV_FONT( text, GetOwner()->GetOwner()->GetFont() ) ); |
f69c03de RR |
1876 | g_object_set_property( G_OBJECT(m_text_renderer), "text", &gvalue ); |
1877 | g_value_unset( &gvalue ); | |
1878 | ||
1879 | ((GdkRectangle*) cell_area)->x += xoffset; | |
1880 | ((GdkRectangle*) cell_area)->width -= xoffset; | |
b9db5f30 | 1881 | |
f69c03de RR |
1882 | gtk_cell_renderer_render( m_text_renderer, |
1883 | window, | |
1884 | widget, | |
1885 | (GdkRectangle*) background_area, | |
1886 | (GdkRectangle*) cell_area, | |
1887 | (GdkRectangle*) expose_area, | |
1888 | (GtkCellRendererState) flags ); | |
b9db5f30 | 1889 | |
f69c03de RR |
1890 | ((GdkRectangle*) cell_area)->x -= xoffset; |
1891 | ((GdkRectangle*) cell_area)->width += xoffset; | |
1892 | #endif | |
52e750fc RR |
1893 | } |
1894 | ||
9861f022 | 1895 | bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode, int align) |
ad63bf41 | 1896 | { |
e152afc3 RR |
1897 | GtkWxCellRenderer *renderer = (GtkWxCellRenderer *) gtk_wx_cell_renderer_new(); |
1898 | renderer->cell = this; | |
93763ad5 | 1899 | |
ed38aa55 | 1900 | m_renderer = (GtkCellRenderer*) renderer; |
93763ad5 | 1901 | |
9861f022 RR |
1902 | SetMode(mode); |
1903 | SetAlignment(align); | |
93763ad5 | 1904 | |
a912e81f | 1905 | GtkInitHandlers(); |
b9db5f30 | 1906 | |
ad63bf41 | 1907 | return true; |
e152afc3 RR |
1908 | } |
1909 | ||
baa9ebc4 | 1910 | wxDataViewCustomRenderer::~wxDataViewCustomRenderer() |
e152afc3 RR |
1911 | { |
1912 | if (m_dc) | |
1913 | delete m_dc; | |
f69c03de RR |
1914 | |
1915 | if (m_text_renderer) | |
1916 | gtk_object_sink( GTK_OBJECT(m_text_renderer) ); | |
e152afc3 RR |
1917 | } |
1918 | ||
baa9ebc4 | 1919 | wxDC *wxDataViewCustomRenderer::GetDC() |
e152afc3 RR |
1920 | { |
1921 | if (m_dc == NULL) | |
4d496ecb RR |
1922 | { |
1923 | if (GetOwner() == NULL) | |
1924 | return NULL; | |
1925 | if (GetOwner()->GetOwner() == NULL) | |
1926 | return NULL; | |
e152afc3 | 1927 | m_dc = new wxDataViewCtrlDC( GetOwner()->GetOwner() ); |
4d496ecb | 1928 | } |
93763ad5 | 1929 | |
e152afc3 RR |
1930 | return m_dc; |
1931 | } | |
93763ad5 WS |
1932 | |
1933 | // --------------------------------------------------------- | |
baa9ebc4 | 1934 | // wxDataViewProgressRenderer |
93763ad5 | 1935 | // --------------------------------------------------------- |
ad63bf41 | 1936 | |
baa9ebc4 | 1937 | IMPLEMENT_CLASS(wxDataViewProgressRenderer, wxDataViewCustomRenderer) |
ad63bf41 | 1938 | |
baa9ebc4 | 1939 | wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString &label, |
9861f022 RR |
1940 | const wxString &varianttype, wxDataViewCellMode mode, int align ) : |
1941 | wxDataViewCustomRenderer( varianttype, mode, align, true ) | |
ad63bf41 RR |
1942 | { |
1943 | m_label = label; | |
1944 | m_value = 0; | |
93763ad5 | 1945 | |
ad63bf41 RR |
1946 | #ifdef __WXGTK26__ |
1947 | if (!gtk_check_version(2,6,0)) | |
1948 | { | |
ed38aa55 | 1949 | m_renderer = (GtkCellRenderer*) gtk_cell_renderer_progress_new(); |
93763ad5 | 1950 | |
ad63bf41 RR |
1951 | GValue gvalue = { 0, }; |
1952 | g_value_init( &gvalue, G_TYPE_STRING ); | |
09dfa6a0 | 1953 | |
1bf629bd | 1954 | g_value_set_string( &gvalue, wxGTK_CONV_FONT( m_label, GetOwner()->GetOwner()->GetFont() ) ); |
ad63bf41 RR |
1955 | g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue ); |
1956 | g_value_unset( &gvalue ); | |
9861f022 RR |
1957 | |
1958 | SetMode(mode); | |
1959 | SetAlignment(align); | |
ad63bf41 RR |
1960 | } |
1961 | else | |
1962 | #endif | |
1963 | { | |
1964 | // Use custom cell code | |
9861f022 | 1965 | wxDataViewCustomRenderer::Init(mode, align); |
ad63bf41 RR |
1966 | } |
1967 | } | |
1968 | ||
baa9ebc4 | 1969 | wxDataViewProgressRenderer::~wxDataViewProgressRenderer() |
ad63bf41 RR |
1970 | { |
1971 | } | |
1972 | ||
baa9ebc4 | 1973 | bool wxDataViewProgressRenderer::SetValue( const wxVariant &value ) |
ad63bf41 RR |
1974 | { |
1975 | #ifdef __WXGTK26__ | |
1976 | if (!gtk_check_version(2,6,0)) | |
1977 | { | |
7226118b | 1978 | gint tmp = (long) value; |
ad63bf41 RR |
1979 | GValue gvalue = { 0, }; |
1980 | g_value_init( &gvalue, G_TYPE_INT ); | |
7226118b | 1981 | g_value_set_int( &gvalue, tmp ); |
ad63bf41 RR |
1982 | g_object_set_property( G_OBJECT(m_renderer), "value", &gvalue ); |
1983 | g_value_unset( &gvalue ); | |
1984 | } | |
1985 | else | |
1986 | #endif | |
1987 | { | |
1988 | m_value = (long) value; | |
93763ad5 | 1989 | |
ad63bf41 RR |
1990 | if (m_value < 0) m_value = 0; |
1991 | if (m_value > 100) m_value = 100; | |
1992 | } | |
93763ad5 | 1993 | |
ad63bf41 RR |
1994 | return true; |
1995 | } | |
93763ad5 | 1996 | |
85136e3b | 1997 | bool wxDataViewProgressRenderer::GetValue( wxVariant &WXUNUSED(value) ) const |
9861f022 RR |
1998 | { |
1999 | return false; | |
2000 | } | |
2001 | ||
85136e3b | 2002 | bool wxDataViewProgressRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) ) |
ad63bf41 RR |
2003 | { |
2004 | double pct = (double)m_value / 100.0; | |
2005 | wxRect bar = cell; | |
2006 | bar.width = (int)(cell.width * pct); | |
2007 | dc->SetPen( *wxTRANSPARENT_PEN ); | |
2008 | dc->SetBrush( *wxBLUE_BRUSH ); | |
2009 | dc->DrawRectangle( bar ); | |
2010 | ||
2011 | dc->SetBrush( *wxTRANSPARENT_BRUSH ); | |
2012 | dc->SetPen( *wxBLACK_PEN ); | |
2013 | dc->DrawRectangle( cell ); | |
93763ad5 | 2014 | |
ad63bf41 RR |
2015 | return true; |
2016 | } | |
2017 | ||
9861f022 | 2018 | wxSize wxDataViewProgressRenderer::GetSize() const |
ad63bf41 RR |
2019 | { |
2020 | return wxSize(40,12); | |
2021 | } | |
93763ad5 WS |
2022 | |
2023 | // --------------------------------------------------------- | |
baa9ebc4 | 2024 | // wxDataViewDateRenderer |
93763ad5 | 2025 | // --------------------------------------------------------- |
4d496ecb | 2026 | |
baa9ebc4 | 2027 | class wxDataViewDateRendererPopupTransient: public wxPopupTransientWindow |
7ea3a0de | 2028 | { |
93763ad5 | 2029 | public: |
baa9ebc4 | 2030 | wxDataViewDateRendererPopupTransient( wxWindow* parent, wxDateTime *value, |
e0062c04 | 2031 | wxDataViewModel *model, const wxDataViewItem &item, unsigned int col ) : |
7ea3a0de RR |
2032 | wxPopupTransientWindow( parent, wxBORDER_SIMPLE ) |
2033 | { | |
2034 | m_model = model; | |
e0062c04 | 2035 | m_item = item; |
7ea3a0de | 2036 | m_col = col; |
7ea3a0de RR |
2037 | m_cal = new wxCalendarCtrl( this, -1, *value ); |
2038 | wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL ); | |
2039 | sizer->Add( m_cal, 1, wxGROW ); | |
2040 | SetSizer( sizer ); | |
2041 | sizer->Fit( this ); | |
2042 | } | |
93763ad5 | 2043 | |
7ea3a0de RR |
2044 | virtual void OnDismiss() |
2045 | { | |
2046 | } | |
93763ad5 | 2047 | |
7ea3a0de | 2048 | void OnCalendar( wxCalendarEvent &event ); |
93763ad5 | 2049 | |
e0062c04 RR |
2050 | wxCalendarCtrl *m_cal; |
2051 | wxDataViewModel *m_model; | |
2052 | wxDataViewItem m_item; | |
2053 | unsigned int m_col; | |
93763ad5 | 2054 | |
7ea3a0de RR |
2055 | private: |
2056 | DECLARE_EVENT_TABLE() | |
2057 | }; | |
2058 | ||
baa9ebc4 RR |
2059 | BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient,wxPopupTransientWindow) |
2060 | EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar ) | |
7ea3a0de RR |
2061 | END_EVENT_TABLE() |
2062 | ||
baa9ebc4 | 2063 | void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent &event ) |
7ea3a0de RR |
2064 | { |
2065 | wxDateTime date = event.GetDate(); | |
2066 | wxVariant value = date; | |
e0062c04 RR |
2067 | m_model->SetValue( value, m_item, m_col ); |
2068 | m_model->ValueChanged( m_item, m_col ); | |
7ea3a0de RR |
2069 | DismissAndNotify(); |
2070 | } | |
2071 | ||
baa9ebc4 | 2072 | IMPLEMENT_CLASS(wxDataViewDateRenderer, wxDataViewCustomRenderer) |
4d496ecb | 2073 | |
baa9ebc4 | 2074 | wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString &varianttype, |
9861f022 RR |
2075 | wxDataViewCellMode mode, int align ) : |
2076 | wxDataViewCustomRenderer( varianttype, mode, align ) | |
4d496ecb | 2077 | { |
9861f022 RR |
2078 | SetMode(mode); |
2079 | SetAlignment(align); | |
4d496ecb | 2080 | } |
93763ad5 | 2081 | |
baa9ebc4 | 2082 | bool wxDataViewDateRenderer::SetValue( const wxVariant &value ) |
4d496ecb RR |
2083 | { |
2084 | m_date = value.GetDateTime(); | |
93763ad5 | 2085 | |
4d496ecb RR |
2086 | return true; |
2087 | } | |
2088 | ||
85136e3b | 2089 | bool wxDataViewDateRenderer::GetValue( wxVariant &WXUNUSED(value) ) const |
9861f022 RR |
2090 | { |
2091 | return false; | |
2092 | } | |
2093 | ||
baa9ebc4 | 2094 | bool wxDataViewDateRenderer::Render( wxRect cell, wxDC *dc, int state ) |
4d496ecb RR |
2095 | { |
2096 | dc->SetFont( GetOwner()->GetOwner()->GetFont() ); | |
2097 | wxString tmp = m_date.FormatDate(); | |
52e750fc | 2098 | RenderText( tmp, 0, cell, dc, state ); |
4d496ecb RR |
2099 | return true; |
2100 | } | |
2101 | ||
9861f022 | 2102 | wxSize wxDataViewDateRenderer::GetSize() const |
4d496ecb | 2103 | { |
4d496ecb RR |
2104 | wxString tmp = m_date.FormatDate(); |
2105 | wxCoord x,y,d; | |
9861f022 | 2106 | GetView()->GetTextExtent( tmp, &x, &y, &d ); |
4d496ecb RR |
2107 | return wxSize(x,y+d); |
2108 | } | |
2109 | ||
85136e3b | 2110 | bool wxDataViewDateRenderer::Activate( wxRect WXUNUSED(cell), wxDataViewModel *model, |
e0062c04 | 2111 | const wxDataViewItem &item, unsigned int col ) |
4d496ecb | 2112 | { |
3f3af7e7 | 2113 | wxVariant variant; |
e0062c04 | 2114 | model->GetValue( variant, item, col ); |
7ea3a0de RR |
2115 | wxDateTime value = variant.GetDateTime(); |
2116 | ||
baa9ebc4 | 2117 | wxDataViewDateRendererPopupTransient *popup = new wxDataViewDateRendererPopupTransient( |
e0062c04 | 2118 | GetOwner()->GetOwner()->GetParent(), &value, model, item, col ); |
7ea3a0de RR |
2119 | wxPoint pos = wxGetMousePosition(); |
2120 | popup->Move( pos ); | |
2121 | popup->Layout(); | |
2122 | popup->Popup( popup->m_cal ); | |
4d496ecb RR |
2123 | |
2124 | return true; | |
2125 | } | |
2126 | ||
c9c13e70 | 2127 | |
b9db5f30 | 2128 | // --------------------------------------------------------- |
c9c13e70 | 2129 | // wxDataViewIconTextRenderer |
b9db5f30 | 2130 | // --------------------------------------------------------- |
c9c13e70 RR |
2131 | |
2132 | IMPLEMENT_CLASS(wxDataViewIconTextRenderer, wxDataViewCustomRenderer) | |
2133 | ||
b9db5f30 | 2134 | wxDataViewIconTextRenderer::wxDataViewIconTextRenderer( |
c9c13e70 RR |
2135 | const wxString &varianttype, wxDataViewCellMode mode, int align ) : |
2136 | wxDataViewCustomRenderer( varianttype, mode, align ) | |
2137 | { | |
2138 | SetMode(mode); | |
2139 | SetAlignment(align); | |
2140 | } | |
2141 | ||
2142 | wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer() | |
2143 | { | |
2144 | } | |
b9db5f30 | 2145 | |
c9c13e70 RR |
2146 | bool wxDataViewIconTextRenderer::SetValue( const wxVariant &value ) |
2147 | { | |
2148 | m_value << value; | |
2149 | return true; | |
2150 | } | |
2151 | ||
2152 | bool wxDataViewIconTextRenderer::GetValue( wxVariant &value ) const | |
2153 | { | |
2154 | return false; | |
2155 | } | |
b9db5f30 | 2156 | |
c9c13e70 RR |
2157 | bool wxDataViewIconTextRenderer::Render( wxRect cell, wxDC *dc, int state ) |
2158 | { | |
c9c13e70 | 2159 | const wxIcon &icon = m_value.GetIcon(); |
52e750fc | 2160 | int offset = 0; |
c9c13e70 RR |
2161 | if (icon.IsOk()) |
2162 | { | |
52e750fc RR |
2163 | int yoffset = wxMax( 0, (cell.height - icon.GetHeight()) / 2 ); |
2164 | dc->DrawIcon( icon, cell.x, cell.y + yoffset ); | |
2165 | offset = icon.GetWidth() + 4; | |
c9c13e70 | 2166 | } |
b9db5f30 | 2167 | |
52e750fc | 2168 | RenderText( m_value.GetText(), offset, cell, dc, state ); |
c9c13e70 RR |
2169 | |
2170 | return true; | |
2171 | } | |
2172 | ||
2173 | wxSize wxDataViewIconTextRenderer::GetSize() const | |
2174 | { | |
52e750fc RR |
2175 | wxSize size; |
2176 | if (m_value.GetIcon().IsOk()) | |
2177 | size.x = 4 + m_value.GetIcon().GetWidth(); | |
2178 | wxCoord x,y,d; | |
2179 | GetView()->GetTextExtent( m_value.GetText(), &x, &y, &d ); | |
2180 | size.x += x; | |
2181 | size.y = y+d; | |
b9db5f30 | 2182 | return size; |
c9c13e70 RR |
2183 | } |
2184 | ||
2185 | wxControl* wxDataViewIconTextRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ) | |
2186 | { | |
2187 | return NULL; | |
2188 | } | |
2189 | ||
2190 | bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVariant &value ) | |
2191 | { | |
2192 | return false; | |
2193 | } | |
2194 | ||
93763ad5 | 2195 | // --------------------------------------------------------- |
605c2c4a | 2196 | // wxDataViewColumn |
93763ad5 | 2197 | // --------------------------------------------------------- |
7b4fde82 | 2198 | |
31fb32e1 RR |
2199 | |
2200 | static gboolean | |
2201 | gtk_dataview_header_button_press_callback( GtkWidget *widget, | |
2202 | GdkEventButton *gdk_event, | |
2203 | wxDataViewColumn *column ) | |
2204 | { | |
2205 | if (gdk_event->type != GDK_BUTTON_PRESS) | |
94b1f7bc | 2206 | return FALSE; |
f4322df6 | 2207 | |
31fb32e1 RR |
2208 | if (gdk_event->button == 1) |
2209 | { | |
d32332aa RR |
2210 | gs_lastLeftClickHeader = column; |
2211 | ||
31fb32e1 RR |
2212 | wxDataViewCtrl *dv = column->GetOwner(); |
2213 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, dv->GetId() ); | |
2214 | event.SetDataViewColumn( column ); | |
2215 | event.SetModel( dv->GetModel() ); | |
937013e0 | 2216 | if (dv->HandleWindowEvent( event )) |
a84c5b6f | 2217 | return FALSE; |
31fb32e1 | 2218 | } |
f4322df6 | 2219 | |
dadc879e RR |
2220 | if (gdk_event->button == 3) |
2221 | { | |
2222 | wxDataViewCtrl *dv = column->GetOwner(); | |
2223 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, dv->GetId() ); | |
2224 | event.SetDataViewColumn( column ); | |
2225 | event.SetModel( dv->GetModel() ); | |
937013e0 | 2226 | if (dv->HandleWindowEvent( event )) |
dadc879e RR |
2227 | return FALSE; |
2228 | } | |
2229 | ||
94b1f7bc | 2230 | return FALSE; |
31fb32e1 RR |
2231 | } |
2232 | ||
7b4fde82 RR |
2233 | extern "C" { |
2234 | static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column, | |
2235 | GtkCellRenderer *cell, | |
2236 | GtkTreeModel *model, | |
2237 | GtkTreeIter *iter, | |
2238 | gpointer data ); | |
2239 | } | |
2240 | ||
2241 | ||
2242 | static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column, | |
2243 | GtkCellRenderer *renderer, | |
2244 | GtkTreeModel *model, | |
2245 | GtkTreeIter *iter, | |
2246 | gpointer data ) | |
2247 | { | |
e0062c04 RR |
2248 | g_return_if_fail (GTK_IS_WX_TREE_MODEL (model)); |
2249 | GtkWxTreeModel *tree_model = (GtkWxTreeModel *) model; | |
93763ad5 | 2250 | |
baa9ebc4 | 2251 | wxDataViewRenderer *cell = (wxDataViewRenderer*) data; |
a7f61f76 | 2252 | |
9d52aad3 | 2253 | wxDataViewItem item( (void*) iter->user_data ); |
93763ad5 | 2254 | |
a826202e RR |
2255 | wxDataViewModel *wx_model = tree_model->internal->GetDataViewModel(); |
2256 | ||
2056dede RR |
2257 | if (!wx_model->IsIndexListModel()) |
2258 | { | |
b9db5f30 | 2259 | |
a826202e RR |
2260 | if (wx_model->IsContainer( item )) |
2261 | { | |
2262 | if (wx_model->HasContainerColumns( item ) || (cell->GetOwner()->GetModelColumn() == 0)) | |
2263 | { | |
2264 | GValue gvalue = { 0, }; | |
2265 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
2266 | g_value_set_boolean( &gvalue, TRUE ); | |
2267 | g_object_set_property( G_OBJECT(renderer), "visible", &gvalue ); | |
2268 | g_value_unset( &gvalue ); | |
2269 | } | |
2270 | else | |
2271 | { | |
2272 | GValue gvalue = { 0, }; | |
2273 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
2274 | g_value_set_boolean( &gvalue, FALSE ); | |
2275 | g_object_set_property( G_OBJECT(renderer), "visible", &gvalue ); | |
2276 | g_value_unset( &gvalue ); | |
b9db5f30 | 2277 | |
a826202e RR |
2278 | return; |
2279 | } | |
2280 | } | |
2281 | else | |
2282 | { | |
2283 | GValue gvalue = { 0, }; | |
2284 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
2285 | g_value_set_boolean( &gvalue, TRUE ); | |
2286 | g_object_set_property( G_OBJECT(renderer), "visible", &gvalue ); | |
2287 | g_value_unset( &gvalue ); | |
2288 | } | |
b9db5f30 | 2289 | |
2056dede | 2290 | } |
a826202e | 2291 | |
3f3af7e7 | 2292 | wxVariant value; |
a826202e | 2293 | wx_model->GetValue( value, item, cell->GetOwner()->GetModelColumn() ); |
7b4fde82 RR |
2294 | |
2295 | if (value.GetType() != cell->GetVariantType()) | |
f4322df6 VZ |
2296 | wxLogError( wxT("Wrong type, required: %s but: %s"), |
2297 | value.GetType().c_str(), | |
cbc9145c | 2298 | cell->GetVariantType().c_str() ); |
93763ad5 | 2299 | |
7b4fde82 | 2300 | cell->SetValue( value ); |
e0743e63 | 2301 | |
4264606e RR |
2302 | if (cell->GtkHasAttributes()) |
2303 | { | |
2304 | wxDataViewItemAttr attr; | |
2305 | bool colour_set = false; | |
2306 | bool style_set = false; | |
2307 | bool weight_set = false; | |
b9db5f30 | 2308 | |
4264606e RR |
2309 | if (wx_model->GetAttr( item, cell->GetOwner()->GetModelColumn(), attr )) |
2310 | { | |
2311 | // this must be a GtkCellRendererText | |
2312 | wxColour colour = attr.GetColour(); | |
2313 | if (colour.IsOk()) | |
2314 | { | |
2315 | const GdkColor * const gcol = colour.GetColor(); | |
2a5e6d1b | 2316 | |
4264606e RR |
2317 | GValue gvalue = { 0, }; |
2318 | g_value_init( &gvalue, GDK_TYPE_COLOR ); | |
2319 | g_value_set_boxed( &gvalue, gcol ); | |
2320 | g_object_set_property( G_OBJECT(renderer), "foreground_gdk", &gvalue ); | |
2321 | g_value_unset( &gvalue ); | |
b9db5f30 | 2322 | |
4264606e RR |
2323 | colour_set = true; |
2324 | } | |
b9db5f30 | 2325 | |
4264606e RR |
2326 | if (attr.GetItalic()) |
2327 | { | |
2328 | GValue gvalue = { 0, }; | |
2329 | g_value_init( &gvalue, PANGO_TYPE_STYLE ); | |
2330 | g_value_set_enum( &gvalue, PANGO_STYLE_ITALIC ); | |
2331 | g_object_set_property( G_OBJECT(renderer), "style", &gvalue ); | |
2332 | g_value_unset( &gvalue ); | |
b9db5f30 | 2333 | |
4264606e RR |
2334 | style_set = true; |
2335 | } | |
b9db5f30 | 2336 | |
4264606e RR |
2337 | if (attr.GetBold()) |
2338 | { | |
2339 | GValue gvalue = { 0, }; | |
2340 | g_value_init( &gvalue, PANGO_TYPE_WEIGHT ); | |
2341 | g_value_set_enum( &gvalue, PANGO_WEIGHT_BOLD ); | |
2342 | g_object_set_property( G_OBJECT(renderer), "weight", &gvalue ); | |
2343 | g_value_unset( &gvalue ); | |
b9db5f30 | 2344 | |
4264606e RR |
2345 | weight_set = true; |
2346 | } | |
2347 | } | |
b9db5f30 | 2348 | |
4264606e RR |
2349 | if (!style_set) |
2350 | { | |
2351 | GValue gvalue = { 0, }; | |
2352 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
2353 | g_value_set_boolean( &gvalue, FALSE ); | |
2354 | g_object_set_property( G_OBJECT(renderer), "style-set", &gvalue ); | |
2355 | g_value_unset( &gvalue ); | |
2356 | } | |
b9db5f30 | 2357 | |
4264606e RR |
2358 | if (!weight_set) |
2359 | { | |
2360 | GValue gvalue = { 0, }; | |
2361 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
2362 | g_value_set_boolean( &gvalue, FALSE ); | |
2363 | g_object_set_property( G_OBJECT(renderer), "weight-set", &gvalue ); | |
2364 | g_value_unset( &gvalue ); | |
2365 | } | |
b9db5f30 | 2366 | |
4264606e RR |
2367 | if (!colour_set) |
2368 | { | |
2369 | GValue gvalue = { 0, }; | |
2370 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
2371 | g_value_set_boolean( &gvalue, FALSE ); | |
2372 | g_object_set_property( G_OBJECT(renderer), "foreground-set", &gvalue ); | |
2373 | g_value_unset( &gvalue ); | |
2374 | } | |
2375 | } | |
2376 | ||
2377 | #if 0 | |
2a5e6d1b RR |
2378 | if (attr.HasBackgroundColour()) |
2379 | { | |
2380 | wxColour colour = attr.GetBackgroundColour(); | |
1cd5e95c | 2381 | const GdkColor * const gcol = colour.GetColor(); |
e0743e63 | 2382 | |
2a5e6d1b RR |
2383 | GValue gvalue = { 0, }; |
2384 | g_value_init( &gvalue, GDK_TYPE_COLOR ); | |
2385 | g_value_set_boxed( &gvalue, gcol ); | |
2386 | g_object_set_property( G_OBJECT(renderer), "cell-background_gdk", &gvalue ); | |
2387 | g_value_unset( &gvalue ); | |
2388 | } | |
2389 | else | |
2390 | { | |
2391 | GValue gvalue = { 0, }; | |
2392 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
2393 | g_value_set_boolean( &gvalue, FALSE ); | |
2394 | g_object_set_property( G_OBJECT(renderer), "cell-background-set", &gvalue ); | |
2395 | g_value_unset( &gvalue ); | |
2396 | } | |
e0062c04 RR |
2397 | #endif |
2398 | ||
7b4fde82 RR |
2399 | } |
2400 | ||
cbc9145c | 2401 | IMPLEMENT_CLASS(wxDataViewColumn, wxDataViewColumnBase) |
fa28826d | 2402 | |
91a6c655 | 2403 | #include <wx/listimpl.cpp> |
a76c2f37 | 2404 | WX_DEFINE_LIST(wxDataViewColumnList) |
91a6c655 | 2405 | |
f4322df6 VZ |
2406 | wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewRenderer *cell, |
2407 | unsigned int model_column, int width, | |
87f0efe2 RR |
2408 | wxAlignment align, int flags ) : |
2409 | wxDataViewColumnBase( title, cell, model_column, width, align, flags ) | |
fa28826d | 2410 | { |
9861f022 | 2411 | Init( align, flags, width ); |
31fb32e1 | 2412 | |
9861f022 | 2413 | gtk_tree_view_column_set_clickable( GTK_TREE_VIEW_COLUMN(m_column), TRUE ); |
31fb32e1 | 2414 | SetTitle( title ); |
fa28826d RR |
2415 | } |
2416 | ||
f4322df6 VZ |
2417 | wxDataViewColumn::wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *cell, |
2418 | unsigned int model_column, int width, | |
87f0efe2 RR |
2419 | wxAlignment align, int flags ) : |
2420 | wxDataViewColumnBase( bitmap, cell, model_column, width, align, flags ) | |
9861f022 RR |
2421 | { |
2422 | Init( align, flags, width ); | |
2423 | ||
2424 | SetBitmap( bitmap ); | |
2425 | } | |
2426 | ||
2427 | void wxDataViewColumn::Init(wxAlignment align, int flags, int width) | |
07a84e7b | 2428 | { |
31fb32e1 | 2429 | m_isConnected = false; |
07a84e7b | 2430 | |
9861f022 | 2431 | GtkCellRenderer *renderer = (GtkCellRenderer *) GetRenderer()->GetGtkHandle(); |
07a84e7b | 2432 | GtkTreeViewColumn *column = gtk_tree_view_column_new(); |
9861f022 | 2433 | m_column = (GtkWidget*) column; |
07a84e7b | 2434 | |
9861f022 RR |
2435 | SetFlags( flags ); |
2436 | SetAlignment( align ); | |
07a84e7b | 2437 | |
9861f022 RR |
2438 | // NOTE: we prefer not to call SetMinWidth(wxDVC_DEFAULT_MINWIDTH); |
2439 | // as GTK+ is smart and unless explicitely told, will set the minimal | |
2440 | // width to the title's lenght, which is a better default | |
07a84e7b | 2441 | |
9861f022 RR |
2442 | // the GTK_TREE_VIEW_COLUMN_FIXED is required by the "fixed height" mode |
2443 | // that we use for the wxDataViewCtrl | |
2444 | gtk_tree_view_column_set_fixed_width( column, width < 0 ? wxDVC_DEFAULT_WIDTH : width ); | |
b94db696 | 2445 | gtk_tree_view_column_set_sizing( column, GTK_TREE_VIEW_COLUMN_FIXED ); |
07a84e7b | 2446 | |
9861f022 | 2447 | gtk_tree_view_column_pack_end( column, renderer, TRUE ); |
07a84e7b RR |
2448 | |
2449 | gtk_tree_view_column_set_cell_data_func( column, renderer, | |
9861f022 | 2450 | wxGtkTreeCellDataFunc, (gpointer) GetRenderer(), NULL ); |
07a84e7b RR |
2451 | } |
2452 | ||
fa28826d RR |
2453 | wxDataViewColumn::~wxDataViewColumn() |
2454 | { | |
2455 | } | |
2456 | ||
31fb32e1 RR |
2457 | void wxDataViewColumn::OnInternalIdle() |
2458 | { | |
2459 | if (m_isConnected) | |
2460 | return; | |
f4322df6 | 2461 | |
31fb32e1 RR |
2462 | if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview)) |
2463 | { | |
9861f022 | 2464 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
31fb32e1 RR |
2465 | if (column->button) |
2466 | { | |
2467 | g_signal_connect(column->button, "button_press_event", | |
2468 | G_CALLBACK (gtk_dataview_header_button_press_callback), this); | |
f4322df6 | 2469 | |
31fb32e1 RR |
2470 | m_isConnected = true; |
2471 | } | |
2472 | } | |
2473 | } | |
2474 | ||
b94db696 RR |
2475 | void wxDataViewColumn::SetOwner( wxDataViewCtrl *owner ) |
2476 | { | |
2477 | wxDataViewColumnBase::SetOwner( owner ); | |
f4322df6 | 2478 | |
9861f022 | 2479 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
f4322df6 | 2480 | |
b94db696 | 2481 | gtk_tree_view_column_set_title( column, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) ); |
b94db696 RR |
2482 | } |
2483 | ||
fa28826d RR |
2484 | void wxDataViewColumn::SetTitle( const wxString &title ) |
2485 | { | |
9861f022 | 2486 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
f4322df6 | 2487 | |
31fb32e1 RR |
2488 | if (m_isConnected) |
2489 | { | |
2490 | // disconnect before column->button gets recreated | |
f4322df6 | 2491 | g_signal_handlers_disconnect_by_func( column->button, |
9861f022 | 2492 | (GtkWidget*) gtk_dataview_header_button_press_callback, this); |
f4322df6 | 2493 | |
31fb32e1 RR |
2494 | m_isConnected = false; |
2495 | } | |
2496 | ||
09dfa6a0 VZ |
2497 | // FIXME: can it really happen that we don't have the owner here?? |
2498 | wxDataViewCtrl *ctrl = GetOwner(); | |
2499 | gtk_tree_view_column_set_title( column, ctrl ? wxGTK_CONV_FONT(title, ctrl->GetFont()) | |
2500 | : wxGTK_CONV_SYS(title) ); | |
31fb32e1 | 2501 | |
07a84e7b RR |
2502 | gtk_tree_view_column_set_widget( column, NULL ); |
2503 | } | |
2504 | ||
9861f022 RR |
2505 | wxString wxDataViewColumn::GetTitle() const |
2506 | { | |
2507 | const gchar *str = gtk_tree_view_column_get_title( GTK_TREE_VIEW_COLUMN(m_column) ); | |
2508 | return wxConvFileName->cMB2WX(str); | |
2509 | } | |
2510 | ||
07a84e7b RR |
2511 | void wxDataViewColumn::SetBitmap( const wxBitmap &bitmap ) |
2512 | { | |
2513 | wxDataViewColumnBase::SetBitmap( bitmap ); | |
2514 | ||
9861f022 | 2515 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
07a84e7b RR |
2516 | if (bitmap.Ok()) |
2517 | { | |
2518 | GtkImage *gtk_image = GTK_IMAGE( gtk_image_new() ); | |
f4322df6 | 2519 | |
07a84e7b RR |
2520 | GdkBitmap *mask = (GdkBitmap *) NULL; |
2521 | if (bitmap.GetMask()) | |
2522 | mask = bitmap.GetMask()->GetBitmap(); | |
2523 | ||
2524 | if (bitmap.HasPixbuf()) | |
2525 | { | |
2526 | gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image), | |
2527 | bitmap.GetPixbuf()); | |
2528 | } | |
2529 | else | |
2530 | { | |
2531 | gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image), | |
2532 | bitmap.GetPixmap(), mask); | |
2533 | } | |
2534 | gtk_widget_show( GTK_WIDGET(gtk_image) ); | |
f4322df6 | 2535 | |
07a84e7b RR |
2536 | gtk_tree_view_column_set_widget( column, GTK_WIDGET(gtk_image) ); |
2537 | } | |
2538 | else | |
2539 | { | |
2540 | gtk_tree_view_column_set_widget( column, NULL ); | |
2541 | } | |
fa28826d RR |
2542 | } |
2543 | ||
9861f022 RR |
2544 | void wxDataViewColumn::SetHidden( bool hidden ) |
2545 | { | |
2546 | gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column), !hidden ); | |
2547 | } | |
2548 | ||
2549 | void wxDataViewColumn::SetResizeable( bool resizeable ) | |
2550 | { | |
2551 | gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column), resizeable ); | |
2552 | } | |
2553 | ||
47cef10f RR |
2554 | void wxDataViewColumn::SetAlignment( wxAlignment align ) |
2555 | { | |
9861f022 | 2556 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
f4322df6 | 2557 | |
47cef10f RR |
2558 | gfloat xalign = 0.0; |
2559 | if (align == wxALIGN_RIGHT) | |
2560 | xalign = 1.0; | |
9861f022 RR |
2561 | if (align == wxALIGN_CENTER_HORIZONTAL || |
2562 | align == wxALIGN_CENTER) | |
47cef10f | 2563 | xalign = 0.5; |
f4322df6 | 2564 | |
9861f022 RR |
2565 | gtk_tree_view_column_set_alignment( column, xalign ); |
2566 | } | |
2567 | ||
2568 | wxAlignment wxDataViewColumn::GetAlignment() const | |
2569 | { | |
2570 | gfloat xalign = gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column) ); | |
2571 | ||
2572 | if (xalign == 1.0) | |
2573 | return wxALIGN_RIGHT; | |
2574 | if (xalign == 0.5) | |
2575 | return wxALIGN_CENTER_HORIZONTAL; | |
f4322df6 | 2576 | |
9861f022 | 2577 | return wxALIGN_LEFT; |
47cef10f RR |
2578 | } |
2579 | ||
31fb32e1 RR |
2580 | void wxDataViewColumn::SetSortable( bool sortable ) |
2581 | { | |
9861f022 | 2582 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
b9db5f30 | 2583 | |
94b1f7bc | 2584 | if (sortable) |
0bd26819 | 2585 | { |
94b1f7bc | 2586 | gtk_tree_view_column_set_sort_column_id( column, GetModelColumn() ); |
0bd26819 | 2587 | } |
94b1f7bc | 2588 | else |
0bd26819 | 2589 | { |
94b1f7bc | 2590 | gtk_tree_view_column_set_sort_column_id( column, -1 ); |
0bd26819 RR |
2591 | gtk_tree_view_column_set_sort_indicator( column, FALSE ); |
2592 | } | |
31fb32e1 RR |
2593 | } |
2594 | ||
87f0efe2 | 2595 | bool wxDataViewColumn::IsSortable() const |
31fb32e1 | 2596 | { |
9861f022 | 2597 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
94b1f7bc | 2598 | return (gtk_tree_view_column_get_sort_column_id( column ) != -1); |
31fb32e1 RR |
2599 | } |
2600 | ||
9861f022 RR |
2601 | bool wxDataViewColumn::IsResizeable() const |
2602 | { | |
2603 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); | |
2604 | return gtk_tree_view_column_get_resizable( column ); | |
2605 | } | |
2606 | ||
2607 | bool wxDataViewColumn::IsHidden() const | |
2608 | { | |
2609 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); | |
2610 | return !gtk_tree_view_column_get_visible( column ); | |
2611 | } | |
2612 | ||
47cef10f RR |
2613 | void wxDataViewColumn::SetSortOrder( bool ascending ) |
2614 | { | |
9861f022 | 2615 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
f4322df6 | 2616 | |
47cef10f RR |
2617 | if (ascending) |
2618 | gtk_tree_view_column_set_sort_order( column, GTK_SORT_ASCENDING ); | |
2619 | else | |
2620 | gtk_tree_view_column_set_sort_order( column, GTK_SORT_DESCENDING ); | |
0bd26819 RR |
2621 | |
2622 | gtk_tree_view_column_set_sort_indicator( column, TRUE ); | |
47cef10f RR |
2623 | } |
2624 | ||
87f0efe2 | 2625 | bool wxDataViewColumn::IsSortOrderAscending() const |
31fb32e1 | 2626 | { |
9861f022 | 2627 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
f4322df6 | 2628 | |
31fb32e1 RR |
2629 | return (gtk_tree_view_column_get_sort_order( column ) != GTK_SORT_DESCENDING); |
2630 | } | |
2631 | ||
9861f022 | 2632 | void wxDataViewColumn::SetMinWidth( int width ) |
533544f2 | 2633 | { |
9861f022 | 2634 | gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column), width ); |
533544f2 RR |
2635 | } |
2636 | ||
9861f022 RR |
2637 | int wxDataViewColumn::GetMinWidth() const |
2638 | { | |
2639 | return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column) ); | |
2640 | } | |
2641 | ||
2642 | int wxDataViewColumn::GetWidth() const | |
533544f2 | 2643 | { |
9861f022 | 2644 | return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column) ); |
533544f2 RR |
2645 | } |
2646 | ||
9861f022 | 2647 | void wxDataViewColumn::SetWidth( int width ) |
533544f2 | 2648 | { |
9861f022 | 2649 | gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column), width ); |
533544f2 RR |
2650 | } |
2651 | ||
99c75ebc RR |
2652 | void wxDataViewColumn::SetReorderable( bool reorderable ) |
2653 | { | |
2654 | gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column), reorderable ); | |
2655 | } | |
2656 | ||
2657 | bool wxDataViewColumn::IsReorderable() const | |
2658 | { | |
2659 | return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column) ); | |
2660 | } | |
9861f022 | 2661 | |
4508fcd2 RR |
2662 | //----------------------------------------------------------------------------- |
2663 | // wxGtkTreeModelNode | |
2664 | //----------------------------------------------------------------------------- | |
2665 | ||
2666 | void wxGtkTreeModelNode::Resort() | |
2667 | { | |
af110130 RR |
2668 | size_t child_count = GetChildCount(); |
2669 | if (child_count == 0) | |
0be79c8a RR |
2670 | return; |
2671 | ||
af110130 RR |
2672 | size_t node_count = GetNodesCount(); |
2673 | ||
2674 | if (child_count == 1) | |
0be79c8a | 2675 | { |
af110130 RR |
2676 | if (node_count == 1) |
2677 | { | |
2678 | wxGtkTreeModelNode *node = m_nodes.Item( 0 ); | |
2679 | node->Resort(); | |
2680 | } | |
0be79c8a RR |
2681 | return; |
2682 | } | |
2683 | ||
40196b1e RR |
2684 | wxGtkTreeModelChildren temp; |
2685 | WX_APPEND_ARRAY( temp, m_children ); | |
b9db5f30 | 2686 | |
40196b1e RR |
2687 | g_internal = m_internal; |
2688 | m_children.Sort( &wxGtkTreeModelChildCmp ); | |
0be79c8a | 2689 | |
af110130 | 2690 | gint *new_order = new gint[child_count]; |
b9db5f30 | 2691 | |
40196b1e | 2692 | unsigned int pos; |
af110130 | 2693 | for (pos = 0; pos < child_count; pos++) |
4508fcd2 | 2694 | { |
40196b1e RR |
2695 | void *id = m_children.Item( pos ); |
2696 | int old_pos = temp.Index( id ); | |
2697 | new_order[pos] = old_pos; | |
4508fcd2 | 2698 | } |
b9db5f30 | 2699 | |
0be79c8a RR |
2700 | GtkTreeModel *gtk_tree_model = GTK_TREE_MODEL( m_internal->GetGtkModel() ); |
2701 | ||
2702 | GtkTreeIter iter; | |
40196b1e | 2703 | iter.user_data = GetItem().GetID(); |
0be79c8a | 2704 | iter.stamp = m_internal->GetGtkModel()->stamp; |
b9db5f30 | 2705 | |
40196b1e | 2706 | GtkTreePath *path = m_internal->get_path( &iter ); |
b9db5f30 | 2707 | |
0be79c8a | 2708 | gtk_tree_model_rows_reordered( gtk_tree_model, path, &iter, new_order ); |
b9db5f30 | 2709 | |
0be79c8a | 2710 | gtk_tree_path_free (path); |
b9db5f30 | 2711 | |
0be79c8a | 2712 | delete [] new_order; |
b9db5f30 | 2713 | |
af110130 | 2714 | for (pos = 0; pos < node_count; pos++) |
4508fcd2 | 2715 | { |
af110130 | 2716 | wxGtkTreeModelNode *node = m_nodes.Item( pos ); |
4508fcd2 RR |
2717 | node->Resort(); |
2718 | } | |
2719 | } | |
2720 | ||
55fbde12 RR |
2721 | //----------------------------------------------------------------------------- |
2722 | // wxDataViewCtrlInternal | |
2723 | //----------------------------------------------------------------------------- | |
2724 | ||
b9db5f30 | 2725 | wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl *owner, |
55fbde12 | 2726 | wxDataViewModel *wx_model, GtkWxTreeModel *gtk_model ) |
b9db5f30 | 2727 | { |
55fbde12 | 2728 | m_owner = owner; |
b9db5f30 VS |
2729 | m_wx_model = wx_model; |
2730 | m_gtk_model = gtk_model; | |
2731 | m_root = NULL; | |
b8b7b087 | 2732 | m_sort_order = GTK_SORT_ASCENDING; |
40196b1e | 2733 | m_sort_column = -1; |
d32332aa | 2734 | m_dataview_sort_column = NULL; |
b9db5f30 | 2735 | |
2056dede RR |
2736 | if (!m_wx_model->IsIndexListModel()) |
2737 | InitTree(); | |
55fbde12 | 2738 | } |
b9db5f30 | 2739 | |
55fbde12 RR |
2740 | wxDataViewCtrlInternal::~wxDataViewCtrlInternal() |
2741 | { | |
2742 | g_object_unref( m_gtk_model ); | |
2743 | } | |
b9db5f30 | 2744 | |
ef427989 RR |
2745 | void wxDataViewCtrlInternal::InitTree() |
2746 | { | |
2747 | wxDataViewItem item; | |
0be79c8a | 2748 | m_root = new wxGtkTreeModelNode( NULL, item, this ); |
ef427989 RR |
2749 | |
2750 | BuildBranch( m_root ); | |
2751 | } | |
2752 | ||
55fbde12 RR |
2753 | void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode *node ) |
2754 | { | |
2755 | if (node->GetChildCount() == 0) | |
2756 | { | |
74fe973b RR |
2757 | wxDataViewItemArray children; |
2758 | unsigned int count = m_wx_model->GetChildren( node->GetItem(), children ); | |
2759 | unsigned int pos; | |
2760 | for (pos = 0; pos < count; pos++) | |
55fbde12 | 2761 | { |
74fe973b | 2762 | wxDataViewItem child = children[pos]; |
b9db5f30 | 2763 | |
af110130 RR |
2764 | if (m_wx_model->IsContainer( child )) |
2765 | node->AddNode( new wxGtkTreeModelNode( node, child, this ) ); | |
2766 | else | |
2767 | node->AddLeave( child.GetID() ); | |
b9db5f30 | 2768 | |
effd54b0 | 2769 | // Don't send any events here |
55fbde12 RR |
2770 | } |
2771 | } | |
2772 | } | |
2773 | ||
f6f0ef85 RR |
2774 | // GTK+ dnd iface |
2775 | ||
2776 | gboolean wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource *WXUNUSED(drag_source), | |
2777 | GtkTreePath *path ) | |
2778 | { | |
2779 | GtkTreeIter iter; | |
2780 | if (!get_iter( &iter, path )) return FALSE; | |
2781 | ||
2782 | wxDataViewItem item( (void*) iter.user_data ); | |
2783 | ||
2784 | return m_wx_model->IsDraggable( item ); | |
2785 | } | |
2786 | ||
2787 | gboolean wxDataViewCtrlInternal::drag_data_delete( GtkTreeDragSource *WXUNUSED(drag_source), | |
2788 | GtkTreePath* path ) | |
2789 | { | |
2790 | return FALSE; | |
2791 | } | |
2792 | ||
2793 | gboolean wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource *WXUNUSED(drag_source), | |
2794 | GtkTreePath *path, GtkSelectionData *selection_data ) | |
2795 | { | |
2796 | GtkTreeIter iter; | |
2797 | if (!get_iter( &iter, path )) return FALSE; | |
2798 | ||
2799 | wxDataViewItem item( (void*) iter.user_data ); | |
2800 | ||
2801 | wxDataFormat format( selection_data->target ); | |
2802 | ||
2803 | size_t size = m_wx_model->GetDragDataSize( item, format ); | |
2804 | if (size == 0) return FALSE; | |
2805 | ||
2806 | void *data = malloc( size ); | |
2807 | ||
2808 | m_wx_model->GetDragData( item, format, data, size ); | |
2809 | ||
2810 | gtk_selection_data_set( selection_data, selection_data->target, | |
2811 | 8, (const guchar*) data, size ); | |
2812 | ||
2813 | free( data ); | |
2814 | ||
2815 | return TRUE; | |
2816 | } | |
2817 | ||
2818 | gboolean wxDataViewCtrlInternal::drag_data_received( GtkTreeDragDest *WXUNUSED(drag_dest), | |
2819 | GtkTreePath *dest, GtkSelectionData *selection_data ) | |
2820 | { | |
2821 | return FALSE; | |
2822 | } | |
2823 | ||
2824 | gboolean wxDataViewCtrlInternal::row_drop_possible( GtkTreeDragDest *WXUNUSED(drag_dest), | |
2825 | GtkTreePath *dest_path, GtkSelectionData *selection_data ) | |
2826 | { | |
2827 | return FALSE; | |
2828 | } | |
2829 | ||
2830 | // notifications from wxDataViewModel | |
2831 | ||
33ba5a05 RR |
2832 | bool wxDataViewCtrlInternal::Cleared() |
2833 | { | |
2834 | if (m_root) | |
2835 | { | |
2836 | delete m_root; | |
2837 | InitTree(); | |
2838 | } | |
2839 | ||
2840 | // Create new GTK model | |
2841 | g_object_unref( m_gtk_model ); | |
2842 | m_gtk_model = wxgtk_tree_model_new(); | |
2843 | m_gtk_model->internal = this; | |
2844 | ||
2845 | return true; | |
2846 | } | |
2847 | ||
4508fcd2 RR |
2848 | void wxDataViewCtrlInternal::Resort() |
2849 | { | |
2056dede RR |
2850 | if (!m_wx_model->IsIndexListModel()) |
2851 | m_root->Resort(); | |
4508fcd2 RR |
2852 | } |
2853 | ||
55fbde12 RR |
2854 | bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) |
2855 | { | |
2056dede RR |
2856 | if (!m_wx_model->IsIndexListModel()) |
2857 | { | |
2858 | wxGtkTreeModelNode *parent_node = FindNode( parent ); | |
2859 | if (m_wx_model->IsContainer( item )) | |
2860 | parent_node->AddNode( new wxGtkTreeModelNode( parent_node, item, this ) ); | |
2861 | else | |
2862 | parent_node->AddLeave( item.GetID() ); | |
2863 | } | |
b9db5f30 | 2864 | |
55fbde12 RR |
2865 | return true; |
2866 | } | |
2867 | ||
469d3e9b | 2868 | bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ) |
55fbde12 | 2869 | { |
2056dede RR |
2870 | if (!m_wx_model->IsIndexListModel()) |
2871 | { | |
2872 | wxGtkTreeModelNode *parent_node = FindNode( parent ); | |
2873 | parent_node->DeleteChild( item.GetID() ); | |
2874 | } | |
b9db5f30 | 2875 | |
d8331a01 RR |
2876 | return true; |
2877 | } | |
2878 | ||
2879 | bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem &item ) | |
2880 | { | |
6608fdab | 2881 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, m_owner->GetId() ); |
d8331a01 RR |
2882 | event.SetEventObject( m_owner ); |
2883 | event.SetModel( m_owner->GetModel() ); | |
2884 | event.SetItem( item ); | |
937013e0 | 2885 | m_owner->HandleWindowEvent( event ); |
b9db5f30 | 2886 | |
d8331a01 RR |
2887 | return true; |
2888 | } | |
2889 | ||
2890 | bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem &item, unsigned int col ) | |
2891 | { | |
6608fdab | 2892 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, m_owner->GetId() ); |
d8331a01 RR |
2893 | event.SetEventObject( m_owner ); |
2894 | event.SetModel( m_owner->GetModel() ); | |
2895 | event.SetColumn( col ); | |
6608fdab | 2896 | event.SetDataViewColumn( GetOwner()->GetColumn(col) ); |
d8331a01 | 2897 | event.SetItem( item ); |
937013e0 | 2898 | m_owner->HandleWindowEvent( event ); |
b9db5f30 | 2899 | |
d8331a01 RR |
2900 | return true; |
2901 | } | |
2902 | ||
f6f0ef85 RR |
2903 | // GTK+ model iface |
2904 | ||
2056dede RR |
2905 | GtkTreeModelFlags wxDataViewCtrlInternal::get_flags() |
2906 | { | |
2907 | if (m_wx_model->IsIndexListModel()) | |
2908 | return GTK_TREE_MODEL_LIST_ONLY; | |
2909 | else | |
2910 | return GTK_TREE_MODEL_ITERS_PERSIST; | |
2911 | } | |
2912 | ||
55fbde12 RR |
2913 | gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path ) |
2914 | { | |
2056dede RR |
2915 | if (m_wx_model->IsIndexListModel()) |
2916 | { | |
2917 | wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model; | |
b9db5f30 | 2918 | |
2056dede RR |
2919 | unsigned int i = (unsigned int)gtk_tree_path_get_indices (path)[0]; |
2920 | ||
f52984b8 | 2921 | if (i >= wx_model->GetLastIndex() + 1) |
2056dede | 2922 | return FALSE; |
55fbde12 | 2923 | |
2056dede RR |
2924 | iter->stamp = m_gtk_model->stamp; |
2925 | // user_data is just the index | |
2926 | iter->user_data = (gpointer) i; | |
55fbde12 | 2927 | |
2056dede RR |
2928 | return TRUE; |
2929 | } | |
2930 | else | |
55fbde12 | 2931 | { |
2056dede RR |
2932 | int depth = gtk_tree_path_get_depth( path ); |
2933 | ||
2934 | wxGtkTreeModelNode *node = m_root; | |
2935 | ||
2936 | int i; | |
b9db5f30 | 2937 | for (i = 0; i < depth; i++) |
2056dede RR |
2938 | { |
2939 | BuildBranch( node ); | |
b9db5f30 | 2940 | |
2056dede RR |
2941 | gint pos = gtk_tree_path_get_indices (path)[i]; |
2942 | if (pos < 0) return FALSE; | |
2943 | if ((size_t)pos >= node->GetChildCount()) return FALSE; | |
b9db5f30 | 2944 | |
2056dede | 2945 | void* id = node->GetChildren().Item( (size_t) pos ); |
b9db5f30 | 2946 | |
2056dede | 2947 | if (i == depth-1) |
af110130 | 2948 | { |
2056dede RR |
2949 | iter->stamp = m_gtk_model->stamp; |
2950 | iter->user_data = id; | |
2951 | return TRUE; | |
af110130 | 2952 | } |
2056dede RR |
2953 | |
2954 | size_t count = node->GetNodes().GetCount(); | |
2955 | size_t pos2; | |
2956 | for (pos2 = 0; pos2 < count; pos2++) | |
2957 | { | |
2958 | wxGtkTreeModelNode *child_node = node->GetNodes().Item( pos2 ); | |
2959 | if (child_node->GetItem().GetID() == id) | |
2960 | { | |
2961 | node = child_node; | |
2962 | break; | |
2963 | } | |
b9db5f30 | 2964 | } |
2056dede | 2965 | } |
af110130 | 2966 | } |
55fbde12 | 2967 | |
af110130 | 2968 | return FALSE; |
55fbde12 RR |
2969 | } |
2970 | ||
2971 | GtkTreePath *wxDataViewCtrlInternal::get_path( GtkTreeIter *iter ) | |
2972 | { | |
2973 | GtkTreePath *retval = gtk_tree_path_new (); | |
b9db5f30 | 2974 | |
2056dede RR |
2975 | if (m_wx_model->IsIndexListModel()) |
2976 | { | |
2977 | // user_data is just the index | |
2978 | int i = (wxUIntPtr) iter->user_data; | |
2979 | gtk_tree_path_append_index (retval, i); | |
2980 | } | |
2981 | else | |
55fbde12 | 2982 | { |
b9db5f30 VS |
2983 | void *id = iter->user_data; |
2984 | ||
2056dede RR |
2985 | wxGtkTreeModelNode *node = FindParentNode( iter ); |
2986 | while (node) | |
2987 | { | |
2988 | int pos = node->GetChildren().Index( id ); | |
40196b1e | 2989 | |
2056dede | 2990 | gtk_tree_path_prepend_index( retval, pos ); |
b9db5f30 | 2991 | |
2056dede RR |
2992 | id = node->GetItem().GetID(); |
2993 | node = node->GetParent(); | |
2994 | } | |
55fbde12 | 2995 | } |
b9db5f30 | 2996 | |
55fbde12 RR |
2997 | return retval; |
2998 | } | |
2999 | ||
3000 | gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter ) | |
3001 | { | |
2056dede RR |
3002 | if (m_wx_model->IsIndexListModel()) |
3003 | { | |
3004 | wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model; | |
b9db5f30 | 3005 | |
2056dede | 3006 | int n = (wxUIntPtr) iter->user_data; |
69892729 | 3007 | |
2056dede RR |
3008 | if (n == -1) |
3009 | return FALSE; | |
40196b1e | 3010 | |
f52984b8 | 3011 | if (n >= (int) wx_model->GetLastIndex()) |
2056dede RR |
3012 | return FALSE; |
3013 | ||
3014 | iter->user_data = (gpointer) ++n; | |
3015 | } | |
3016 | else | |
3017 | { | |
3018 | wxGtkTreeModelNode *parent = FindParentNode( iter ); | |
3019 | if( parent == NULL ) | |
3020 | return FALSE; | |
3021 | ||
3022 | int pos = parent->GetChildren().Index( iter->user_data ); | |
3023 | ||
3024 | if (pos == (int) parent->GetChildCount()-1) | |
3025 | return FALSE; | |
b9db5f30 | 3026 | |
2056dede RR |
3027 | iter->stamp = m_gtk_model->stamp; |
3028 | iter->user_data = parent->GetChildren().Item( pos+1 ); | |
3029 | } | |
55fbde12 RR |
3030 | |
3031 | return TRUE; | |
3032 | } | |
3033 | ||
3034 | gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter *parent ) | |
3035 | { | |
2056dede RR |
3036 | if (m_wx_model->IsIndexListModel()) |
3037 | { | |
3038 | // this is a list, nodes have no children | |
3039 | if (parent) | |
3040 | return FALSE; | |
3041 | ||
3042 | iter->stamp = m_gtk_model->stamp; | |
3043 | iter->user_data = (gpointer) -1; | |
3044 | ||
3045 | return TRUE; | |
3046 | } | |
3047 | else | |
3048 | { | |
3049 | wxDataViewItem item( (void*) parent->user_data ); | |
b9db5f30 | 3050 | |
2056dede RR |
3051 | if (!m_wx_model->IsContainer( item )) |
3052 | return FALSE; | |
b9db5f30 | 3053 | |
2056dede RR |
3054 | wxGtkTreeModelNode *parent_node = FindNode( parent ); |
3055 | BuildBranch( parent_node ); | |
b9db5f30 | 3056 | |
2056dede RR |
3057 | if (parent_node->GetChildCount() == 0) |
3058 | return FALSE; | |
b9db5f30 | 3059 | |
2056dede RR |
3060 | iter->stamp = m_gtk_model->stamp; |
3061 | iter->user_data = (gpointer) parent_node->GetChildren().Item( 0 ); | |
3062 | } | |
b9db5f30 | 3063 | |
55fbde12 RR |
3064 | return TRUE; |
3065 | } | |
3066 | ||
3067 | gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter ) | |
3068 | { | |
2056dede RR |
3069 | if (m_wx_model->IsIndexListModel()) |
3070 | { | |
3071 | // this is a list, nodes have no children | |
3072 | return FALSE; | |
3073 | } | |
3074 | else | |
3075 | { | |
3076 | wxDataViewItem item( (void*) iter->user_data ); | |
b9db5f30 | 3077 | |
2056dede | 3078 | bool is_container = m_wx_model->IsContainer( item ); |
b9db5f30 | 3079 | |
2056dede RR |
3080 | if (!is_container) |
3081 | return FALSE; | |
b9db5f30 | 3082 | |
2056dede RR |
3083 | wxGtkTreeModelNode *node = FindNode( iter ); |
3084 | BuildBranch( node ); | |
b9db5f30 | 3085 | |
2056dede RR |
3086 | return (node->GetChildCount() > 0); |
3087 | } | |
55fbde12 RR |
3088 | } |
3089 | ||
3090 | gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter ) | |
3091 | { | |
2056dede RR |
3092 | if (m_wx_model->IsIndexListModel()) |
3093 | { | |
3094 | wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model; | |
b9db5f30 | 3095 | |
2056dede | 3096 | if (iter == NULL) |
f52984b8 | 3097 | return (gint) wx_model->GetLastIndex() + 1; |
2056dede | 3098 | |
55fbde12 | 3099 | return 0; |
2056dede RR |
3100 | } |
3101 | else | |
3102 | { | |
3103 | wxDataViewItem item( (void*) iter->user_data ); | |
b9db5f30 | 3104 | |
2056dede RR |
3105 | if (!m_wx_model->IsContainer( item )) |
3106 | return 0; | |
b9db5f30 | 3107 | |
2056dede RR |
3108 | wxGtkTreeModelNode *parent_node = FindNode( iter ); |
3109 | BuildBranch( parent_node ); | |
ef427989 | 3110 | |
2056dede | 3111 | // wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() ); |
b9db5f30 | 3112 | |
2056dede RR |
3113 | return parent_node->GetChildCount(); |
3114 | } | |
55fbde12 RR |
3115 | } |
3116 | ||
3117 | gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter *parent, gint n ) | |
3118 | { | |
2056dede RR |
3119 | if (m_wx_model->IsIndexListModel()) |
3120 | { | |
3121 | wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model; | |
b9db5f30 | 3122 | |
2056dede RR |
3123 | if (parent) |
3124 | return FALSE; | |
3125 | ||
3126 | if (n < 0) | |
3127 | return FALSE; | |
3128 | ||
f52984b8 | 3129 | if (n >= (gint) wx_model->GetLastIndex() + 1) |
2056dede RR |
3130 | return FALSE; |
3131 | ||
3132 | iter->stamp = m_gtk_model->stamp; | |
3133 | iter->user_data = (gpointer) n; | |
3134 | ||
3135 | return TRUE; | |
3136 | } | |
3137 | else | |
3138 | { | |
3139 | void* id = NULL; | |
3140 | if (parent) id = (void*) parent->user_data; | |
3141 | wxDataViewItem item( id ); | |
b9db5f30 | 3142 | |
2056dede RR |
3143 | if (!m_wx_model->IsContainer( item )) |
3144 | return FALSE; | |
b9db5f30 | 3145 | |
2056dede RR |
3146 | wxGtkTreeModelNode *parent_node = FindNode( parent ); |
3147 | BuildBranch( parent_node ); | |
55fbde12 | 3148 | |
2056dede | 3149 | // wxPrintf( "iter_nth_child %d\n", n ); |
b9db5f30 | 3150 | |
2056dede RR |
3151 | iter->stamp = m_gtk_model->stamp; |
3152 | iter->user_data = parent_node->GetChildren().Item( n ); | |
55fbde12 | 3153 | |
2056dede RR |
3154 | return TRUE; |
3155 | } | |
55fbde12 RR |
3156 | } |
3157 | ||
3158 | gboolean wxDataViewCtrlInternal::iter_parent( GtkTreeIter *iter, GtkTreeIter *child ) | |
3159 | { | |
2056dede RR |
3160 | if (m_wx_model->IsIndexListModel()) |
3161 | { | |
55fbde12 | 3162 | return FALSE; |
2056dede RR |
3163 | } |
3164 | else | |
3165 | { | |
3166 | wxGtkTreeModelNode *node = FindParentNode( child ); | |
3167 | if (!node) | |
3168 | return FALSE; | |
b9db5f30 | 3169 | |
2056dede RR |
3170 | iter->stamp = m_gtk_model->stamp; |
3171 | iter->user_data = (gpointer) node->GetItem().GetID(); | |
55fbde12 | 3172 | |
2056dede RR |
3173 | return TRUE; |
3174 | } | |
55fbde12 | 3175 | } |
b9db5f30 | 3176 | |
55fbde12 | 3177 | static wxGtkTreeModelNode* |
69892729 | 3178 | wxDataViewCtrlInternal_FindNode( wxDataViewModel * model, wxGtkTreeModelNode *treeNode, const wxDataViewItem &item ) |
55fbde12 | 3179 | { |
69892729 RR |
3180 | if( model == NULL ) |
3181 | return NULL; | |
55fbde12 | 3182 | |
69892729 RR |
3183 | ItemList list; |
3184 | list.DeleteContents( true ); | |
3185 | wxDataViewItem it( item ); | |
b9db5f30 | 3186 | |
69892729 | 3187 | while( it.IsOk() ) |
55fbde12 | 3188 | { |
69892729 RR |
3189 | wxDataViewItem * pItem = new wxDataViewItem( it ); |
3190 | list.Insert( pItem ); | |
3191 | it = model->GetParent( it ); | |
3192 | } | |
3193 | ||
3194 | wxGtkTreeModelNode * node = treeNode; | |
966cb94d | 3195 | for( ItemList::compatibility_iterator n = list.GetFirst(); n; n = n->GetNext() ) |
69892729 RR |
3196 | { |
3197 | if( node && node->GetNodes().GetCount() != 0 ) | |
ef427989 | 3198 | { |
69892729 RR |
3199 | int len = node->GetNodes().GetCount(); |
3200 | wxGtkTreeModelNodes nodes = node->GetNodes(); | |
3201 | int j = 0; | |
3202 | for( ; j < len; j ++) | |
3203 | { | |
3204 | if( nodes[j]->GetItem() == *(n->GetData())) | |
3205 | { | |
3206 | node = nodes[j]; | |
3207 | break; | |
b9db5f30 | 3208 | } |
69892729 RR |
3209 | } |
3210 | ||
3211 | if( j == len ) | |
3212 | { | |
3213 | return NULL; | |
3214 | } | |
ef427989 | 3215 | } |
69892729 RR |
3216 | else |
3217 | return NULL; | |
55fbde12 | 3218 | } |
69892729 RR |
3219 | return node; |
3220 | ||
55fbde12 RR |
3221 | } |
3222 | ||
3223 | wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( GtkTreeIter *iter ) | |
3224 | { | |
3225 | if (!iter) | |
3226 | return m_root; | |
3227 | ||
3228 | wxDataViewItem item( (void*) iter->user_data ); | |
0be79c8a RR |
3229 | if (!item.IsOk()) |
3230 | return m_root; | |
b9db5f30 | 3231 | |
69892729 | 3232 | wxGtkTreeModelNode *result = wxDataViewCtrlInternal_FindNode( m_wx_model, m_root, item ); |
b9db5f30 | 3233 | |
55fbde12 RR |
3234 | if (!result) |
3235 | { | |
26f119eb | 3236 | wxLogDebug( "Not found %p", iter->user_data ); |
55fbde12 RR |
3237 | char *crash = NULL; |
3238 | *crash = 0; | |
3239 | } | |
b9db5f30 | 3240 | |
55fbde12 RR |
3241 | return result; |
3242 | } | |
3243 | ||
3244 | wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( const wxDataViewItem &item ) | |
3245 | { | |
0be79c8a RR |
3246 | if (!item.IsOk()) |
3247 | return m_root; | |
3248 | ||
69892729 | 3249 | wxGtkTreeModelNode *result = wxDataViewCtrlInternal_FindNode( m_wx_model, m_root, item ); |
b9db5f30 | 3250 | |
55fbde12 RR |
3251 | if (!result) |
3252 | { | |
26f119eb | 3253 | wxLogDebug( "Not found %p", item.GetID() ); |
55fbde12 RR |
3254 | char *crash = NULL; |
3255 | *crash = 0; | |
3256 | } | |
b9db5f30 | 3257 | |
55fbde12 RR |
3258 | return result; |
3259 | } | |
3260 | ||
af110130 | 3261 | static wxGtkTreeModelNode* |
69892729 | 3262 | wxDataViewCtrlInternal_FindParentNode( wxDataViewModel * model, wxGtkTreeModelNode *treeNode, const wxDataViewItem &item ) |
af110130 | 3263 | { |
69892729 RR |
3264 | if( model == NULL ) |
3265 | return NULL; | |
3266 | ||
3267 | ItemList list; | |
3268 | list.DeleteContents( true ); | |
3269 | if( !item.IsOk() ) | |
3270 | return NULL; | |
3271 | ||
3272 | wxDataViewItem it( model->GetParent( item ) ); | |
3273 | while( it.IsOk() ) | |
af110130 | 3274 | { |
69892729 RR |
3275 | wxDataViewItem * pItem = new wxDataViewItem( it ); |
3276 | list.Insert( pItem ); | |
3277 | it = model->GetParent( it ); | |
af110130 RR |
3278 | } |
3279 | ||
69892729 | 3280 | wxGtkTreeModelNode * node = treeNode; |
966cb94d | 3281 | for( ItemList::compatibility_iterator n = list.GetFirst(); n; n = n->GetNext() ) |
af110130 | 3282 | { |
69892729 | 3283 | if( node && node->GetNodes().GetCount() != 0 ) |
af110130 | 3284 | { |
69892729 RR |
3285 | int len = node->GetNodes().GetCount(); |
3286 | wxGtkTreeModelNodes nodes = node->GetNodes(); | |
3287 | int j = 0; | |
3288 | for( ; j < len; j ++) | |
3289 | { | |
3290 | if( nodes[j]->GetItem() == *(n->GetData())) | |
3291 | { | |
3292 | node = nodes[j]; | |
3293 | break; | |
b9db5f30 | 3294 | } |
69892729 RR |
3295 | } |
3296 | ||
3297 | if( j == len ) | |
3298 | { | |
3299 | return NULL; | |
3300 | } | |
af110130 | 3301 | } |
69892729 RR |
3302 | else |
3303 | return NULL; | |
3304 | } | |
3305 | //Examine whether the node is item's parent node | |
3306 | int len = node->GetChildCount(); | |
3307 | for( int i = 0; i < len ; i ++ ) | |
3308 | { | |
3309 | if( node->GetChildren().Item( i ) == item.GetID() ) | |
3310 | return node; | |
af110130 | 3311 | } |
af110130 RR |
3312 | return NULL; |
3313 | } | |
3314 | ||
3315 | wxGtkTreeModelNode *wxDataViewCtrlInternal::FindParentNode( GtkTreeIter *iter ) | |
3316 | { | |
3317 | if (!iter) | |
3318 | return NULL; | |
b9db5f30 | 3319 | |
af110130 RR |
3320 | wxDataViewItem item( (void*) iter->user_data ); |
3321 | if (!item.IsOk()) | |
3322 | return NULL; | |
3323 | ||
69892729 | 3324 | return wxDataViewCtrlInternal_FindParentNode( m_wx_model, m_root, item ); |
af110130 RR |
3325 | } |
3326 | ||
3327 | wxGtkTreeModelNode *wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem &item ) | |
3328 | { | |
3329 | if (!item.IsOk()) | |
3330 | return NULL; | |
3331 | ||
69892729 | 3332 | return wxDataViewCtrlInternal_FindParentNode( m_wx_model, m_root, item ); |
af110130 RR |
3333 | } |
3334 | ||
eb7f97f8 RR |
3335 | //----------------------------------------------------------------------------- |
3336 | // wxDataViewCtrl signal callbacks | |
3337 | //----------------------------------------------------------------------------- | |
3338 | ||
3339 | static void | |
3340 | wxdataview_selection_changed_callback( GtkTreeSelection* selection, wxDataViewCtrl *dv ) | |
3341 | { | |
b94db696 RR |
3342 | if (!GTK_WIDGET_REALIZED(dv->m_widget)) |
3343 | return; | |
f4322df6 | 3344 | |
d86c1870 | 3345 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, dv->GetId() ); |
6848478c | 3346 | event.SetItem( dv->GetSelection() ); |
eb7f97f8 | 3347 | event.SetModel( dv->GetModel() ); |
937013e0 | 3348 | dv->HandleWindowEvent( event ); |
eb7f97f8 RR |
3349 | } |
3350 | ||
f828871d | 3351 | static void |
f4322df6 | 3352 | wxdataview_row_activated_callback( GtkTreeView* treeview, GtkTreePath *path, |
f828871d RR |
3353 | GtkTreeViewColumn *column, wxDataViewCtrl *dv ) |
3354 | { | |
e0062c04 | 3355 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, dv->GetId() ); |
55fbde12 RR |
3356 | |
3357 | GtkTreeIter iter; | |
3358 | dv->GtkGetInternal()->get_iter( &iter, path ); | |
3359 | wxDataViewItem item( (void*) iter.user_data );; | |
3360 | event.SetItem( item ); | |
f828871d | 3361 | event.SetModel( dv->GetModel() ); |
937013e0 | 3362 | dv->HandleWindowEvent( event ); |
f828871d RR |
3363 | } |
3364 | ||
718fd180 RR |
3365 | static gboolean |
3366 | wxdataview_test_expand_row_callback( GtkTreeView* treeview, GtkTreeIter* iter, | |
3367 | GtkTreePath *path, wxDataViewCtrl *dv ) | |
3368 | { | |
3369 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, dv->GetId() ); | |
3370 | ||
3371 | wxDataViewItem item( (void*) iter->user_data );; | |
3372 | event.SetItem( item ); | |
3373 | event.SetModel( dv->GetModel() ); | |
937013e0 | 3374 | dv->HandleWindowEvent( event ); |
b9db5f30 | 3375 | |
718fd180 RR |
3376 | return !event.IsAllowed(); |
3377 | } | |
3378 | ||
3379 | static void | |
3380 | wxdataview_row_expanded_callback( GtkTreeView* treeview, GtkTreeIter* iter, | |
3381 | GtkTreePath *path, wxDataViewCtrl *dv ) | |
3382 | { | |
3383 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, dv->GetId() ); | |
3384 | ||
3385 | wxDataViewItem item( (void*) iter->user_data );; | |
3386 | event.SetItem( item ); | |
3387 | event.SetModel( dv->GetModel() ); | |
937013e0 | 3388 | dv->HandleWindowEvent( event ); |
718fd180 RR |
3389 | } |
3390 | ||
3391 | static gboolean | |
3392 | wxdataview_test_collapse_row_callback( GtkTreeView* treeview, GtkTreeIter* iter, | |
3393 | GtkTreePath *path, wxDataViewCtrl *dv ) | |
3394 | { | |
3395 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, dv->GetId() ); | |
3396 | ||
3397 | wxDataViewItem item( (void*) iter->user_data );; | |
3398 | event.SetItem( item ); | |
3399 | event.SetModel( dv->GetModel() ); | |
937013e0 | 3400 | dv->HandleWindowEvent( event ); |
b9db5f30 | 3401 | |
718fd180 RR |
3402 | return !event.IsAllowed(); |
3403 | } | |
3404 | ||
3405 | static void | |
3406 | wxdataview_row_collapsed_callback( GtkTreeView* treeview, GtkTreeIter* iter, | |
3407 | GtkTreePath *path, wxDataViewCtrl *dv ) | |
3408 | { | |
3409 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, dv->GetId() ); | |
3410 | ||
3411 | wxDataViewItem item( (void*) iter->user_data );; | |
3412 | event.SetItem( item ); | |
3413 | event.SetModel( dv->GetModel() ); | |
937013e0 | 3414 | dv->HandleWindowEvent( event ); |
718fd180 RR |
3415 | } |
3416 | ||
790b137e | 3417 | //----------------------------------------------------------------------------- |
718fd180 | 3418 | // wxDataViewCtrl |
790b137e RR |
3419 | //----------------------------------------------------------------------------- |
3420 | ||
1e510b1e RR |
3421 | //----------------------------------------------------------------------------- |
3422 | // InsertChild for wxDataViewCtrl | |
3423 | //----------------------------------------------------------------------------- | |
3424 | ||
3425 | static void wxInsertChildInDataViewCtrl( wxWindowGTK* parent, wxWindowGTK* child ) | |
3426 | { | |
3427 | wxDataViewCtrl * dvc = (wxDataViewCtrl*) parent; | |
3428 | GtkWidget *treeview = dvc->GtkGetTreeView(); | |
3429 | ||
3430 | // Insert widget in GtkTreeView | |
3431 | if (GTK_WIDGET_REALIZED(treeview)) | |
e8375af8 | 3432 | gtk_widget_set_parent_window( child->m_widget, |
1e510b1e RR |
3433 | gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview) ) ); |
3434 | gtk_widget_set_parent( child->m_widget, treeview ); | |
3435 | } | |
3436 | ||
3437 | static | |
3438 | void gtk_dataviewctrl_size_callback( GtkWidget *WXUNUSED(widget), | |
3439 | GtkAllocation *alloc, | |
3440 | wxDataViewCtrl *win ) | |
3441 | { | |
966cb94d | 3442 | wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst(); |
1e510b1e RR |
3443 | while (node) |
3444 | { | |
3445 | wxWindow *child = node->GetData(); | |
e8375af8 | 3446 | |
1e510b1e RR |
3447 | GtkRequisition req; |
3448 | gtk_widget_size_request( child->m_widget, &req ); | |
e8375af8 | 3449 | |
1e510b1e RR |
3450 | GtkAllocation alloc; |
3451 | alloc.x = child->m_x; | |
3452 | alloc.y = child->m_y; | |
3453 | alloc.width = child->m_width; | |
3454 | alloc.height = child->m_height; | |
3455 | gtk_widget_size_allocate( child->m_widget, &alloc ); | |
e8375af8 | 3456 | |
1e510b1e RR |
3457 | node = node->GetNext(); |
3458 | } | |
3459 | } | |
3460 | ||
3461 | ||
6608fdab RR |
3462 | //----------------------------------------------------------------------------- |
3463 | // "motion_notify_event" | |
3464 | //----------------------------------------------------------------------------- | |
3465 | ||
3466 | static gboolean | |
3467 | gtk_dataview_motion_notify_callback( GtkWidget *widget, | |
74dea0de RR |
3468 | GdkEventMotion *gdk_event, |
3469 | wxDataViewCtrl *dv ) | |
6608fdab RR |
3470 | { |
3471 | if (gdk_event->is_hint) | |
3472 | { | |
3473 | int x = 0; | |
3474 | int y = 0; | |
3475 | GdkModifierType state; | |
3476 | gdk_window_get_pointer(gdk_event->window, &x, &y, &state); | |
3477 | gdk_event->x = x; | |
3478 | gdk_event->y = y; | |
3479 | } | |
3480 | ||
3481 | GtkTreePath *path = NULL; | |
3482 | GtkTreeViewColumn *column = NULL; | |
3483 | gint cell_x = 0; | |
3484 | gint cell_y = 0; | |
b9db5f30 | 3485 | if (gtk_tree_view_get_path_at_pos( |
6608fdab RR |
3486 | GTK_TREE_VIEW(dv->GtkGetTreeView()), |
3487 | (int) gdk_event->x, (int) gdk_event->y, | |
3488 | &path, | |
3489 | &column, | |
3490 | &cell_x, | |
3491 | &cell_y)) | |
3492 | { | |
3493 | if (path) | |
3494 | { | |
3495 | GtkTreeIter iter; | |
3496 | dv->GtkGetInternal()->get_iter( &iter, path ); | |
b9db5f30 | 3497 | |
6608fdab | 3498 | // wxPrintf( "mouse %d %d\n", (int) gdk_event->x, (int) gdk_event->y ); |
b9db5f30 | 3499 | |
6608fdab RR |
3500 | gtk_tree_path_free( path ); |
3501 | } | |
3502 | } | |
3503 | ||
3504 | ||
3505 | return FALSE; | |
3506 | } | |
3507 | ||
74dea0de RR |
3508 | //----------------------------------------------------------------------------- |
3509 | // "button_press_event" | |
3510 | //----------------------------------------------------------------------------- | |
3511 | ||
3512 | static gboolean | |
3513 | gtk_dataview_button_press_callback( GtkWidget *WXUNUSED(widget), | |
3514 | GdkEventButton *gdk_event, | |
3515 | wxDataViewCtrl *dv ) | |
3516 | { | |
3517 | if ((gdk_event->button == 3) && (gdk_event->type == GDK_BUTTON_PRESS)) | |
3518 | { | |
3519 | GtkTreePath *path = NULL; | |
3520 | GtkTreeViewColumn *column = NULL; | |
3521 | gint cell_x = 0; | |
3522 | gint cell_y = 0; | |
3523 | if (gtk_tree_view_get_path_at_pos( | |
3524 | GTK_TREE_VIEW(dv->GtkGetTreeView()), | |
3525 | (int) gdk_event->x, (int) gdk_event->y, | |
3526 | &path, | |
3527 | &column, | |
3528 | &cell_x, | |
3529 | &cell_y)) | |
3530 | { | |
3531 | if (path) | |
3532 | { | |
3533 | GtkTreeIter iter; | |
3534 | dv->GtkGetInternal()->get_iter( &iter, path ); | |
3535 | ||
3536 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, dv->GetId() ); | |
3537 | wxDataViewItem item( (void*) iter.user_data );; | |
3538 | event.SetItem( item ); | |
3539 | event.SetModel( dv->GetModel() ); | |
3540 | bool ret = dv->HandleWindowEvent( event ); | |
3541 | gtk_tree_path_free( path ); | |
3542 | return ret; | |
3543 | } | |
3544 | } | |
3545 | } | |
3546 | ||
3547 | return FALSE; | |
3548 | } | |
1e510b1e | 3549 | |
239eaa41 RR |
3550 | IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase) |
3551 | ||
3552 | wxDataViewCtrl::~wxDataViewCtrl() | |
3553 | { | |
8f850e28 RR |
3554 | if (m_notifier) |
3555 | GetModel()->RemoveNotifier( m_notifier ); | |
87f0efe2 RR |
3556 | |
3557 | // remove the model from the GtkTreeView before it gets destroyed by the | |
3558 | // wxDataViewCtrlBase's dtor | |
3559 | gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview), NULL ); | |
b9db5f30 | 3560 | |
55fbde12 | 3561 | delete m_internal; |
239eaa41 RR |
3562 | } |
3563 | ||
3564 | void wxDataViewCtrl::Init() | |
3565 | { | |
8f850e28 | 3566 | m_notifier = NULL; |
33ba5a05 | 3567 | m_internal = NULL; |
239eaa41 RR |
3568 | } |
3569 | ||
f6f0ef85 RR |
3570 | static GtkTargetEntry gs_target; |
3571 | ||
239eaa41 | 3572 | bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, |
93763ad5 | 3573 | const wxPoint& pos, const wxSize& size, |
239eaa41 RR |
3574 | long style, const wxValidator& validator ) |
3575 | { | |
3576 | Init(); | |
93763ad5 | 3577 | |
239eaa41 RR |
3578 | if (!PreCreation( parent, pos, size ) || |
3579 | !CreateBase( parent, id, pos, size, style, validator )) | |
3580 | { | |
3581 | wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") ); | |
93763ad5 | 3582 | return false; |
239eaa41 | 3583 | } |
1a367564 | 3584 | |
1e510b1e RR |
3585 | m_insertCallback = wxInsertChildInDataViewCtrl; |
3586 | ||
1a367564 | 3587 | m_widget = gtk_scrolled_window_new (NULL, NULL); |
6493aaca VZ |
3588 | |
3589 | GtkScrolledWindowSetBorder(m_widget, style); | |
1a367564 RR |
3590 | |
3591 | m_treeview = gtk_tree_view_new(); | |
3592 | gtk_container_add (GTK_CONTAINER (m_widget), m_treeview); | |
e8375af8 | 3593 | |
1e510b1e RR |
3594 | g_signal_connect (m_treeview, "size_allocate", |
3595 | G_CALLBACK (gtk_dataviewctrl_size_callback), this); | |
ed4b0fdc | 3596 | |
f6f0ef85 RR |
3597 | gs_target.target = "UTF8_STRING"; |
3598 | gs_target.flags = 0; | |
3599 | gs_target.info = -1; | |
3600 | gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_treeview), | |
3601 | GDK_BUTTON1_MASK, &gs_target, 1, (GdkDragAction) GDK_ACTION_COPY ); | |
3602 | ||
3603 | ||
b94db696 RR |
3604 | #ifdef __WXGTK26__ |
3605 | if (!gtk_check_version(2,6,0)) | |
3606 | gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), TRUE ); | |
3607 | #endif | |
3608 | ||
daebb44c RR |
3609 | if (style & wxDV_MULTIPLE) |
3610 | { | |
3611 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); | |
3612 | gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE ); | |
3613 | } | |
93763ad5 | 3614 | |
9861f022 RR |
3615 | gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview), (style & wxDV_NO_HEADER) == 0 ); |
3616 | ||
3617 | #ifdef __WXGTK210__ | |
3618 | if (!gtk_check_version(2,10,0)) | |
3619 | { | |
3620 | GtkTreeViewGridLines grid = GTK_TREE_VIEW_GRID_LINES_NONE; | |
f4322df6 VZ |
3621 | |
3622 | if ((style & wxDV_HORIZ_RULES) != 0 && | |
9861f022 RR |
3623 | (style & wxDV_VERT_RULES) != 0) |
3624 | grid = GTK_TREE_VIEW_GRID_LINES_BOTH; | |
3625 | else if (style & wxDV_VERT_RULES) | |
3626 | grid = GTK_TREE_VIEW_GRID_LINES_VERTICAL; | |
3627 | else if (style & wxDV_HORIZ_RULES) | |
3628 | grid = GTK_TREE_VIEW_GRID_LINES_HORIZONTAL; | |
3629 | ||
1a07a730 RR |
3630 | if (grid != GTK_TREE_VIEW_GRID_LINES_NONE) |
3631 | gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview), grid ); | |
9861f022 | 3632 | } |
9861f022 | 3633 | #endif |
1a07a730 RR |
3634 | |
3635 | gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview), (style & wxDV_ROW_LINES) != 0 ); | |
9861f022 | 3636 | |
1a367564 RR |
3637 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget), |
3638 | GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
3639 | gtk_widget_show (m_treeview); | |
93763ad5 | 3640 | |
239eaa41 RR |
3641 | m_parent->DoAddChild( this ); |
3642 | ||
b94db696 RR |
3643 | PostCreation(size); |
3644 | ||
b086d55f RR |
3645 | GtkEnableSelectionEvents(); |
3646 | ||
718fd180 | 3647 | g_signal_connect_after (m_treeview, "row-activated", |
f828871d | 3648 | G_CALLBACK (wxdataview_row_activated_callback), this); |
eb7f97f8 | 3649 | |
718fd180 RR |
3650 | g_signal_connect (m_treeview, "test-collapse-row", |
3651 | G_CALLBACK (wxdataview_test_collapse_row_callback), this); | |
3652 | ||
3653 | g_signal_connect_after (m_treeview, "row-collapsed", | |
3654 | G_CALLBACK (wxdataview_row_collapsed_callback), this); | |
3655 | ||
3656 | g_signal_connect (m_treeview, "test-expand-row", | |
3657 | G_CALLBACK (wxdataview_test_expand_row_callback), this); | |
b9db5f30 | 3658 | |
718fd180 RR |
3659 | g_signal_connect_after (m_treeview, "row-expanded", |
3660 | G_CALLBACK (wxdataview_row_expanded_callback), this); | |
3661 | ||
6608fdab RR |
3662 | g_signal_connect (m_treeview, "motion_notify_event", |
3663 | G_CALLBACK (gtk_dataview_motion_notify_callback), this); | |
3664 | ||
74dea0de RR |
3665 | g_signal_connect (m_treeview, "button_press_event", |
3666 | G_CALLBACK (gtk_dataview_button_press_callback), this); | |
3667 | ||
239eaa41 RR |
3668 | return true; |
3669 | } | |
3670 | ||
31fb32e1 RR |
3671 | void wxDataViewCtrl::OnInternalIdle() |
3672 | { | |
3673 | wxWindow::OnInternalIdle(); | |
f4322df6 | 3674 | |
9861f022 | 3675 | unsigned int cols = GetColumnCount(); |
31fb32e1 RR |
3676 | unsigned int i; |
3677 | for (i = 0; i < cols; i++) | |
3678 | { | |
3679 | wxDataViewColumn *col = GetColumn( i ); | |
3680 | col->OnInternalIdle(); | |
3681 | } | |
3682 | } | |
3683 | ||
e0062c04 | 3684 | bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model ) |
239eaa41 | 3685 | { |
33ba5a05 RR |
3686 | if (GetModel()) |
3687 | { | |
3688 | delete m_internal; | |
3689 | m_internal = NULL; | |
3690 | ||
3691 | delete m_notifier; | |
3692 | m_notifier = NULL; | |
3693 | } | |
3694 | ||
239eaa41 RR |
3695 | if (!wxDataViewCtrlBase::AssociateModel( model )) |
3696 | return false; | |
3697 | ||
55fbde12 RR |
3698 | GtkWxTreeModel *gtk_model = wxgtk_tree_model_new(); |
3699 | m_internal = new wxDataViewCtrlInternal( this, model, gtk_model ); | |
3700 | gtk_model->internal = m_internal; | |
6e2e590f | 3701 | |
55fbde12 | 3702 | m_notifier = new wxGtkDataViewModelNotifier( gtk_model, model, this ); |
6e2e590f | 3703 | |
93763ad5 | 3704 | model->AddNotifier( m_notifier ); |
1557c77b | 3705 | |
55fbde12 | 3706 | gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview), GTK_TREE_MODEL(gtk_model) ); |
b9db5f30 | 3707 | |
55fbde12 RR |
3708 | // unref in wxDataViewCtrlInternal |
3709 | // g_object_unref( gtk_model ); | |
93763ad5 | 3710 | |
239eaa41 RR |
3711 | return true; |
3712 | } | |
790b137e | 3713 | |
fa28826d RR |
3714 | bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col ) |
3715 | { | |
3716 | if (!wxDataViewCtrlBase::AppendColumn(col)) | |
3717 | return false; | |
93763ad5 | 3718 | |
91a6c655 RR |
3719 | m_cols.Append( col ); |
3720 | ||
b9db5f30 | 3721 | gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview), |
91a6c655 RR |
3722 | GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) ); |
3723 | ||
3724 | return true; | |
3725 | } | |
3726 | ||
736fe67c RR |
3727 | bool wxDataViewCtrl::PrependColumn( wxDataViewColumn *col ) |
3728 | { | |
3729 | if (!wxDataViewCtrlBase::PrependColumn(col)) | |
3730 | return false; | |
3731 | ||
3732 | m_cols.Insert( col ); | |
3733 | ||
b9db5f30 | 3734 | gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview), |
736fe67c RR |
3735 | GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()), 0 ); |
3736 | ||
3737 | return true; | |
3738 | } | |
3739 | ||
91a6c655 RR |
3740 | unsigned int wxDataViewCtrl::GetColumnCount() const |
3741 | { | |
3742 | return m_cols.GetCount(); | |
3743 | } | |
3744 | ||
3745 | wxDataViewColumn* wxDataViewCtrl::GetColumn( unsigned int pos ) const | |
3746 | { | |
3747 | GtkTreeViewColumn *gtk_col = gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview), pos ); | |
3748 | if (!gtk_col) | |
3749 | return NULL; | |
b9db5f30 | 3750 | |
91a6c655 RR |
3751 | wxDataViewColumnList::const_iterator iter; |
3752 | for (iter = m_cols.begin(); iter != m_cols.end(); iter++) | |
3753 | { | |
3754 | wxDataViewColumn *col = *iter; | |
3755 | if (GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) == gtk_col) | |
3756 | { | |
3757 | return col; | |
3758 | } | |
3759 | } | |
b9db5f30 | 3760 | |
91a6c655 RR |
3761 | return NULL; |
3762 | } | |
3763 | ||
3764 | bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn *column ) | |
3765 | { | |
b9db5f30 | 3766 | gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview), |
91a6c655 RR |
3767 | GTK_TREE_VIEW_COLUMN(column->GetGtkHandle()) ); |
3768 | ||
3769 | m_cols.remove( column ); | |
fa28826d | 3770 | |
91a6c655 | 3771 | delete column; |
fa28826d RR |
3772 | |
3773 | return true; | |
3774 | } | |
3775 | ||
91a6c655 RR |
3776 | bool wxDataViewCtrl::ClearColumns() |
3777 | { | |
3778 | wxDataViewColumnList::iterator iter; | |
3779 | for (iter = m_cols.begin(); iter != m_cols.end(); iter++) | |
3780 | { | |
3781 | wxDataViewColumn *col = *iter; | |
b9db5f30 | 3782 | gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview), |
91a6c655 RR |
3783 | GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) ); |
3784 | } | |
b9db5f30 | 3785 | |
91a6c655 | 3786 | m_cols.clear(); |
b9db5f30 | 3787 | |
91a6c655 RR |
3788 | return true; |
3789 | } | |
3790 | ||
453091c2 RR |
3791 | int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn *column ) const |
3792 | { | |
aed836f3 RR |
3793 | GtkTreeViewColumn *gtk_column = GTK_TREE_VIEW_COLUMN(column->GetConstGtkHandle()); |
3794 | ||
3795 | GList *list = gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview) ); | |
b9db5f30 | 3796 | |
aed836f3 | 3797 | gint pos = g_list_index( list, (gconstpointer) gtk_column ); |
b9db5f30 | 3798 | |
aed836f3 RR |
3799 | g_list_free( list ); |
3800 | ||
3801 | return pos; | |
453091c2 RR |
3802 | } |
3803 | ||
21f47fb9 RR |
3804 | wxDataViewColumn *wxDataViewCtrl::GetSortingColumn() const |
3805 | { | |
d32332aa | 3806 | return m_internal->GetDataViewSortColumn(); |
21f47fb9 RR |
3807 | } |
3808 | ||
f71d3ba4 RR |
3809 | void wxDataViewCtrl::Expand( const wxDataViewItem & item ) |
3810 | { | |
3811 | GtkTreeIter iter; | |
3812 | iter.user_data = item.GetID(); | |
3813 | GtkTreePath *path = m_internal->get_path( &iter ); | |
3814 | gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview), path, false ); | |
3815 | gtk_tree_path_free( path ); | |
3816 | } | |
3817 | ||
3818 | void wxDataViewCtrl::Collapse( const wxDataViewItem & item ) | |
3819 | { | |
3820 | GtkTreeIter iter; | |
3821 | iter.user_data = item.GetID(); | |
3822 | GtkTreePath *path = m_internal->get_path( &iter ); | |
3823 | gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview), path ); | |
3824 | gtk_tree_path_free( path ); | |
3825 | } | |
3826 | ||
fbda518c | 3827 | wxDataViewItem wxDataViewCtrl::GetSelection() const |
1e08ad10 RR |
3828 | { |
3829 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); | |
b9db5f30 | 3830 | |
1e08ad10 RR |
3831 | if (m_windowStyle & wxDV_MULTIPLE) |
3832 | { | |
6848478c RR |
3833 | // Report the first one |
3834 | GtkTreeModel *model; | |
3835 | GList *list = gtk_tree_selection_get_selected_rows( selection, &model ); | |
b9db5f30 | 3836 | |
6848478c RR |
3837 | if (list) |
3838 | { | |
3839 | GtkTreePath *path = (GtkTreePath*) list->data; | |
3840 | GtkTreeIter iter; | |
3841 | m_internal->get_iter( &iter, path ); | |
b9db5f30 | 3842 | |
6848478c RR |
3843 | // delete list |
3844 | g_list_foreach( list, (GFunc) gtk_tree_path_free, NULL ); | |
3845 | g_list_free( list ); | |
b9db5f30 | 3846 | |
6848478c RR |
3847 | return wxDataViewItem( (void*) iter.user_data ); |
3848 | } | |
1e08ad10 RR |
3849 | } |
3850 | else | |
3851 | { | |
3852 | GtkTreeIter iter; | |
3853 | if (gtk_tree_selection_get_selected( selection, NULL, &iter )) | |
3854 | { | |
9d52aad3 | 3855 | wxDataViewItem item( (void*) iter.user_data ); |
1e08ad10 RR |
3856 | return item; |
3857 | } | |
3858 | } | |
b9db5f30 | 3859 | |
1e08ad10 RR |
3860 | return wxDataViewItem(0); |
3861 | } | |
3862 | ||
718fd180 RR |
3863 | int wxDataViewCtrl::GetSelections( wxDataViewItemArray & sel ) const |
3864 | { | |
6848478c RR |
3865 | sel.Clear(); |
3866 | ||
3867 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); | |
3868 | if (HasFlag(wxDV_MULTIPLE)) | |
3869 | { | |
3870 | GtkTreeModel *model; | |
3871 | GList *list = gtk_tree_selection_get_selected_rows( selection, &model ); | |
3872 | ||
3873 | int count = 0; | |
3874 | while (list) | |
3875 | { | |
3876 | GtkTreePath *path = (GtkTreePath*) list->data; | |
b9db5f30 | 3877 | |
6848478c RR |
3878 | GtkTreeIter iter; |
3879 | m_internal->get_iter( &iter, path ); | |
3880 | ||
3881 | sel.Add( wxDataViewItem( (void*) iter.user_data ) ); | |
3882 | ||
3883 | list = g_list_next( list ); | |
3884 | count++; | |
3885 | } | |
3886 | ||
3887 | // delete list | |
3888 | g_list_foreach( list, (GFunc) gtk_tree_path_free, NULL ); | |
3889 | g_list_free( list ); | |
3890 | ||
3891 | return count; | |
3892 | } | |
3893 | else | |
3894 | { | |
3895 | GtkTreeModel *model; | |
3896 | GtkTreeIter iter; | |
3897 | gboolean has_selection = gtk_tree_selection_get_selected( selection, &model, &iter ); | |
3898 | if (has_selection) | |
3899 | { | |
3900 | sel.Add( wxDataViewItem( (void*) iter.user_data) ); | |
3901 | return 1; | |
3902 | } | |
3903 | } | |
3904 | ||
718fd180 RR |
3905 | return 0; |
3906 | } | |
3907 | ||
3908 | void wxDataViewCtrl::SetSelections( const wxDataViewItemArray & sel ) | |
3909 | { | |
6848478c | 3910 | GtkDisableSelectionEvents(); |
b9db5f30 | 3911 | |
6848478c RR |
3912 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); |
3913 | ||
3914 | gtk_tree_selection_unselect_all( selection ); | |
b9db5f30 | 3915 | |
6848478c RR |
3916 | size_t i; |
3917 | for (i = 0; i < sel.GetCount(); i++) | |
3918 | { | |
3919 | GtkTreeIter iter; | |
3920 | iter.user_data = (gpointer) sel[i].GetID(); | |
3921 | gtk_tree_selection_select_iter( selection, &iter ); | |
3922 | } | |
b9db5f30 | 3923 | |
6848478c | 3924 | GtkEnableSelectionEvents(); |
718fd180 RR |
3925 | } |
3926 | ||
3927 | void wxDataViewCtrl::Select( const wxDataViewItem & item ) | |
3928 | { | |
6848478c RR |
3929 | GtkDisableSelectionEvents(); |
3930 | ||
3931 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); | |
3932 | ||
3933 | GtkTreeIter iter; | |
3934 | iter.user_data = (gpointer) item.GetID(); | |
3935 | gtk_tree_selection_select_iter( selection, &iter ); | |
3936 | ||
3937 | GtkEnableSelectionEvents(); | |
718fd180 RR |
3938 | } |
3939 | ||
3940 | void wxDataViewCtrl::Unselect( const wxDataViewItem & item ) | |
3941 | { | |
6848478c RR |
3942 | GtkDisableSelectionEvents(); |
3943 | ||
3944 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); | |
3945 | ||
3946 | GtkTreeIter iter; | |
3947 | iter.user_data = (gpointer) item.GetID(); | |
3948 | gtk_tree_selection_unselect_iter( selection, &iter ); | |
3949 | ||
3950 | GtkEnableSelectionEvents(); | |
718fd180 RR |
3951 | } |
3952 | ||
3953 | bool wxDataViewCtrl::IsSelected( const wxDataViewItem & item ) const | |
3954 | { | |
6848478c RR |
3955 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); |
3956 | ||
3957 | GtkTreeIter iter; | |
3958 | iter.user_data = (gpointer) item.GetID(); | |
b9db5f30 | 3959 | |
6848478c | 3960 | return gtk_tree_selection_iter_is_selected( selection, &iter ); |
718fd180 RR |
3961 | } |
3962 | ||
3963 | void wxDataViewCtrl::SelectAll() | |
3964 | { | |
6848478c | 3965 | GtkDisableSelectionEvents(); |
b9db5f30 | 3966 | |
6848478c | 3967 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); |
b9db5f30 | 3968 | |
6848478c | 3969 | gtk_tree_selection_select_all( selection ); |
b9db5f30 | 3970 | |
6848478c | 3971 | GtkEnableSelectionEvents(); |
718fd180 RR |
3972 | } |
3973 | ||
3974 | void wxDataViewCtrl::UnselectAll() | |
3975 | { | |
6848478c | 3976 | GtkDisableSelectionEvents(); |
b9db5f30 | 3977 | |
6848478c | 3978 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); |
b9db5f30 | 3979 | |
6848478c | 3980 | gtk_tree_selection_unselect_all( selection ); |
b9db5f30 | 3981 | |
6848478c | 3982 | GtkEnableSelectionEvents(); |
718fd180 RR |
3983 | } |
3984 | ||
fbda518c | 3985 | void wxDataViewCtrl::EnsureVisible( const wxDataViewItem & item, const wxDataViewColumn *column ) |
718fd180 | 3986 | { |
6154212e RR |
3987 | GtkTreeIter iter; |
3988 | iter.user_data = (gpointer) item.GetID(); | |
3989 | GtkTreePath *path = m_internal->get_path( &iter ); | |
3990 | gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview), path, NULL, false, 0.0, 0.0 ); | |
3991 | gtk_tree_path_free( path ); | |
718fd180 RR |
3992 | } |
3993 | ||
b9db5f30 | 3994 | void wxDataViewCtrl::HitTest( const wxPoint &point, |
a87b466d | 3995 | wxDataViewItem &item, wxDataViewColumn *&column ) const |
66e09788 RR |
3996 | { |
3997 | item = wxDataViewItem(0); | |
a87b466d | 3998 | column = NULL; |
66e09788 RR |
3999 | } |
4000 | ||
b9db5f30 | 4001 | wxRect wxDataViewCtrl::GetItemRect( const wxDataViewItem &item, |
fbda518c | 4002 | const wxDataViewColumn *column ) const |
66e09788 RR |
4003 | { |
4004 | return wxRect(); | |
4005 | } | |
4006 | ||
3b6280be RR |
4007 | void wxDataViewCtrl::DoSetExpanderColumn() |
4008 | { | |
b9db5f30 | 4009 | gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview), |
1b27b2bd | 4010 | GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) ); |
3b6280be RR |
4011 | } |
4012 | ||
4013 | void wxDataViewCtrl::DoSetIndent() | |
4014 | { | |
4015 | } | |
4016 | ||
b086d55f RR |
4017 | void wxDataViewCtrl::GtkDisableSelectionEvents() |
4018 | { | |
4019 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); | |
6848478c RR |
4020 | g_signal_handlers_disconnect_by_func( selection, |
4021 | (gpointer) (wxdataview_selection_changed_callback), this); | |
b086d55f RR |
4022 | } |
4023 | ||
4024 | void wxDataViewCtrl::GtkEnableSelectionEvents() | |
4025 | { | |
4026 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); | |
6848478c RR |
4027 | g_signal_connect_after (selection, "changed", |
4028 | G_CALLBACK (wxdataview_selection_changed_callback), this); | |
b086d55f RR |
4029 | } |
4030 | ||
b94db696 RR |
4031 | // static |
4032 | wxVisualAttributes | |
4033 | wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
4034 | { | |
4035 | return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new); | |
4036 | } | |
4037 | ||
6ff7eee7 | 4038 | |
93763ad5 | 4039 | #endif |
4ed7af08 | 4040 | // !wxUSE_GENERICDATAVIEWCTRL |
790b137e | 4041 | |
93763ad5 | 4042 | #endif |
4ed7af08 | 4043 | // wxUSE_DATAVIEWCTRL |