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