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