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