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