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