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