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