]>
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(); |
d32332aa RR |
1018 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, dv->GetId() ); |
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 RR |
1166 | wxDataViewCtrl *dv = column->GetOwner(); |
1167 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING, dv->GetId() ); | |
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 ); | |
1708 | ||
1709 | GtkAdjustment* hadjust = gtk_tree_view_get_hadjustment( widget ); | |
1710 | double d = gtk_adjustment_get_value( hadjust ); | |
1711 | int xdiff = (int) d; | |
1712 | ||
9dc44eff PC |
1713 | GtkAllocation a; |
1714 | gtk_widget_get_allocation(GTK_WIDGET(gtk_tree_view_column_get_button(gcolumn)), &a); | |
1715 | int ydiff = a.height; | |
b30ad967 VZ |
1716 | // Redraw |
1717 | gtk_widget_queue_draw_area( GTK_WIDGET(widget), | |
1718 | cell_area.x - xdiff, ydiff + cell_area.y, cell_area.width, cell_area.height ); | |
1719 | } | |
b9db5f30 | 1720 | |
d93cc830 | 1721 | m_internal->ValueChanged( item, model_column ); |
b9db5f30 | 1722 | |
d8331a01 | 1723 | return true; |
8f850e28 | 1724 | } |
8f850e28 | 1725 | } |
93763ad5 | 1726 | |
d8331a01 | 1727 | return false; |
6e2e590f RR |
1728 | } |
1729 | ||
d8090b5e | 1730 | bool wxGtkDataViewModelNotifier::BeforeReset() |
673810ee RR |
1731 | { |
1732 | GtkWidget *treeview = m_internal->GetOwner()->GtkGetTreeView(); | |
1733 | gtk_tree_view_set_model( GTK_TREE_VIEW(treeview), NULL ); | |
d8090b5e | 1734 | |
673810ee RR |
1735 | return true; |
1736 | } | |
1737 | ||
1738 | bool wxGtkDataViewModelNotifier::AfterReset() | |
1739 | { | |
673810ee | 1740 | GtkWidget *treeview = m_internal->GetOwner()->GtkGetTreeView(); |
d8090b5e | 1741 | GtkWxTreeModel *wxgtk_model = m_internal->GetGtkModel(); |
ce00f59b VZ |
1742 | |
1743 | m_internal->Cleared(); | |
1744 | ||
d8090b5e | 1745 | gtk_tree_view_set_model( GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(wxgtk_model) ); |
ce00f59b | 1746 | |
673810ee RR |
1747 | return true; |
1748 | } | |
1749 | ||
e0062c04 | 1750 | bool wxGtkDataViewModelNotifier::Cleared() |
6e2e590f | 1751 | { |
673810ee | 1752 | GtkWxTreeModel *wxgtk_model = m_internal->GetGtkModel(); |
ce00f59b | 1753 | |
c225708f RR |
1754 | // There is no call to tell the model that everything |
1755 | // has been deleted so call row_deleted() for every | |
1756 | // child of root... | |
1757 | ||
673810ee | 1758 | int count = m_internal->iter_n_children( NULL ); // number of children of root |
ce00f59b | 1759 | |
c225708f RR |
1760 | GtkTreePath *path = gtk_tree_path_new_first(); // points to root |
1761 | ||
1762 | int i; | |
1763 | for (i = 0; i < count; i++) | |
673810ee | 1764 | gtk_tree_model_row_deleted( GTK_TREE_MODEL(wxgtk_model), path ); |
ce00f59b | 1765 | |
c225708f | 1766 | gtk_tree_path_free( path ); |
ce00f59b | 1767 | |
673810ee | 1768 | m_internal->Cleared(); |
03647350 | 1769 | |
8a568372 | 1770 | return true; |
6e2e590f RR |
1771 | } |
1772 | ||
93763ad5 | 1773 | // --------------------------------------------------------- |
baa9ebc4 | 1774 | // wxDataViewRenderer |
93763ad5 | 1775 | // --------------------------------------------------------- |
6842a71a | 1776 | |
a912e81f RR |
1777 | static gpointer s_user_data = NULL; |
1778 | ||
1779 | static void | |
c5c5395b | 1780 | wxgtk_cell_editable_editing_done( GtkCellEditable *WXUNUSED(editable), |
a912e81f RR |
1781 | wxDataViewRenderer *wxrenderer ) |
1782 | { | |
1783 | wxDataViewColumn *column = wxrenderer->GetOwner(); | |
1784 | wxDataViewCtrl *dv = column->GetOwner(); | |
1785 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, dv->GetId() ); | |
1786 | event.SetDataViewColumn( column ); | |
1787 | event.SetModel( dv->GetModel() ); | |
1788 | wxDataViewItem item( s_user_data ); | |
1789 | event.SetItem( item ); | |
937013e0 | 1790 | dv->HandleWindowEvent( event ); |
a912e81f RR |
1791 | } |
1792 | ||
b9db5f30 | 1793 | static void |
c5c5395b | 1794 | wxgtk_renderer_editing_started( GtkCellRenderer *WXUNUSED(cell), GtkCellEditable *editable, |
a912e81f RR |
1795 | gchar *path, wxDataViewRenderer *wxrenderer ) |
1796 | { | |
ecc32226 RR |
1797 | if (!editable) |
1798 | return; | |
1799 | ||
a912e81f RR |
1800 | wxDataViewColumn *column = wxrenderer->GetOwner(); |
1801 | wxDataViewCtrl *dv = column->GetOwner(); | |
1802 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, dv->GetId() ); | |
1803 | event.SetDataViewColumn( column ); | |
1804 | event.SetModel( dv->GetModel() ); | |
0c2a7270 | 1805 | wxDataViewItem item(dv->GTKPathToItem(wxGtkTreePath(path))); |
a912e81f | 1806 | event.SetItem( item ); |
937013e0 | 1807 | dv->HandleWindowEvent( event ); |
a912e81f RR |
1808 | |
1809 | if (GTK_IS_CELL_EDITABLE(editable)) | |
1810 | { | |
17d98558 | 1811 | s_user_data = item.GetID(); |
b9db5f30 | 1812 | |
a912e81f RR |
1813 | g_signal_connect (GTK_CELL_EDITABLE (editable), "editing_done", |
1814 | G_CALLBACK (wxgtk_cell_editable_editing_done), | |
1815 | (gpointer) wxrenderer ); | |
b9db5f30 | 1816 | |
a912e81f RR |
1817 | } |
1818 | } | |
1819 | ||
1820 | ||
baa9ebc4 | 1821 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer, wxDataViewRendererBase) |
6842a71a | 1822 | |
9861f022 RR |
1823 | wxDataViewRenderer::wxDataViewRenderer( const wxString &varianttype, wxDataViewCellMode mode, |
1824 | int align ) : | |
1825 | wxDataViewRendererBase( varianttype, mode, align ) | |
6842a71a RR |
1826 | { |
1827 | m_renderer = NULL; | |
9fc221aa | 1828 | m_mode = mode; |
9861f022 | 1829 | |
b74399b9 VZ |
1830 | // we haven't changed them yet |
1831 | m_usingDefaultAttrs = true; | |
1832 | ||
9861f022 RR |
1833 | // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor, |
1834 | // after the m_renderer pointer has been initialized | |
1835 | } | |
1836 | ||
205bdf20 VZ |
1837 | void wxDataViewRenderer::GtkPackIntoColumn(GtkTreeViewColumn *column) |
1838 | { | |
1839 | gtk_tree_view_column_pack_end( column, m_renderer, TRUE /* expand */); | |
1840 | } | |
1841 | ||
a912e81f RR |
1842 | void wxDataViewRenderer::GtkInitHandlers() |
1843 | { | |
9dc44eff | 1844 | #ifndef __WXGTK3__ |
a912e81f | 1845 | if (!gtk_check_version(2,6,0)) |
9dc44eff | 1846 | #endif |
a912e81f RR |
1847 | { |
1848 | g_signal_connect (GTK_CELL_RENDERER(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 | { | |
995d5aa2 | 1974 | #ifdef __WXGTK26__ |
9dc44eff | 1975 | #ifndef __WXGTK3__ |
c937bcac VZ |
1976 | if ( gtk_check_version(2, 6, 0) != NULL ) |
1977 | return; | |
9dc44eff | 1978 | #endif |
c937bcac | 1979 | |
17cbc244 VZ |
1980 | GtkCellRendererText * const rend = GtkGetTextRenderer(); |
1981 | if ( !rend ) | |
1982 | return; | |
1983 | ||
c937bcac VZ |
1984 | // we use the same values in wxEllipsizeMode as PangoEllipsizeMode so we |
1985 | // can just cast between them | |
1986 | GValue gvalue = { 0, }; | |
1987 | g_value_init( &gvalue, PANGO_TYPE_ELLIPSIZE_MODE ); | |
1988 | g_value_set_enum( &gvalue, static_cast<PangoEllipsizeMode>(mode) ); | |
17cbc244 | 1989 | g_object_set_property( G_OBJECT(rend), "ellipsize", &gvalue ); |
c937bcac | 1990 | g_value_unset( &gvalue ); |
995d5aa2 VZ |
1991 | #else // GTK < 2.6 |
1992 | wxUnusedVar(mode); | |
1993 | #endif // GTK 2.6/before | |
c937bcac VZ |
1994 | } |
1995 | ||
1996 | wxEllipsizeMode wxDataViewRenderer::GetEllipsizeMode() const | |
1997 | { | |
995d5aa2 | 1998 | #ifdef __WXGTK26__ |
9dc44eff | 1999 | #ifndef __WXGTK3__ |
c937bcac VZ |
2000 | if ( gtk_check_version(2, 6, 0) != NULL ) |
2001 | return wxELLIPSIZE_NONE; | |
9dc44eff | 2002 | #endif |
c937bcac | 2003 | |
17cbc244 VZ |
2004 | GtkCellRendererText * const rend = GtkGetTextRenderer(); |
2005 | if ( !rend ) | |
2006 | return wxELLIPSIZE_NONE; | |
2007 | ||
c937bcac VZ |
2008 | GValue gvalue = { 0, }; |
2009 | g_value_init( &gvalue, PANGO_TYPE_ELLIPSIZE_MODE ); | |
17cbc244 | 2010 | g_object_get_property( G_OBJECT(rend), "ellipsize", &gvalue ); |
c937bcac VZ |
2011 | wxEllipsizeMode |
2012 | mode = static_cast<wxEllipsizeMode>(g_value_get_enum( &gvalue )); | |
2013 | g_value_unset( &gvalue ); | |
2014 | ||
2015 | return mode; | |
995d5aa2 VZ |
2016 | #else // GTK < 2.6 |
2017 | return wxELLIPSIZE_NONE; | |
2018 | #endif // GTK 2.6/before | |
c937bcac VZ |
2019 | } |
2020 | ||
205bdf20 | 2021 | void |
29e461a2 | 2022 | wxDataViewRenderer::GtkOnTextEdited(const char *itempath, const wxString& str) |
205bdf20 VZ |
2023 | { |
2024 | wxVariant value(str); | |
2025 | if (!Validate( value )) | |
2026 | return; | |
2027 | ||
0c2a7270 VZ |
2028 | wxDataViewItem |
2029 | item(GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(itempath))); | |
205bdf20 VZ |
2030 | |
2031 | GtkOnCellChanged(value, item, GetOwner()->GetModelColumn()); | |
2032 | } | |
2033 | ||
2034 | void | |
2035 | wxDataViewRenderer::GtkOnCellChanged(const wxVariant& value, | |
2036 | const wxDataViewItem& item, | |
2037 | unsigned col) | |
2038 | { | |
2039 | wxDataViewModel *model = GetOwner()->GetOwner()->GetModel(); | |
795dac4c | 2040 | model->ChangeValue( value, item, col ); |
205bdf20 VZ |
2041 | } |
2042 | ||
93763ad5 | 2043 | // --------------------------------------------------------- |
baa9ebc4 | 2044 | // wxDataViewTextRenderer |
93763ad5 | 2045 | // --------------------------------------------------------- |
6842a71a | 2046 | |
205bdf20 VZ |
2047 | extern "C" |
2048 | { | |
a7f61f76 | 2049 | |
c5c5395b | 2050 | static void wxGtkTextRendererEditedCallback( GtkCellRendererText *WXUNUSED(renderer), |
a7f61f76 RR |
2051 | gchar *arg1, gchar *arg2, gpointer user_data ) |
2052 | { | |
7448d67c | 2053 | wxDataViewRenderer *cell = (wxDataViewRenderer*) user_data; |
93763ad5 | 2054 | |
205bdf20 VZ |
2055 | cell->GtkOnTextEdited(arg1, wxGTK_CONV_BACK_FONT( |
2056 | arg2, cell->GetOwner()->GetOwner()->GetFont())); | |
2057 | } | |
93763ad5 | 2058 | |
a7f61f76 RR |
2059 | } |
2060 | ||
c80cde00 VZ |
2061 | namespace |
2062 | { | |
2063 | ||
2064 | // helper function used by wxDataViewTextRenderer and | |
2065 | // wxDataViewCustomRenderer::RenderText(): it applies the attributes to the | |
2066 | // given text renderer and returns true if anything was done | |
2067 | bool GtkApplyAttr(GtkCellRendererText *renderer, const wxDataViewItemAttr& attr) | |
2068 | { | |
2069 | bool usingDefaultAttrs = true; | |
2070 | if (attr.HasColour()) | |
2071 | { | |
2072 | const GdkColor * const gcol = attr.GetColour().GetColor(); | |
2073 | ||
2074 | GValue gvalue = { 0, }; | |
2075 | g_value_init( &gvalue, GDK_TYPE_COLOR ); | |
2076 | g_value_set_boxed( &gvalue, gcol ); | |
2077 | g_object_set_property( G_OBJECT(renderer), "foreground_gdk", &gvalue ); | |
2078 | g_value_unset( &gvalue ); | |
2079 | ||
2080 | usingDefaultAttrs = false; | |
2081 | } | |
2082 | else | |
2083 | { | |
2084 | GValue gvalue = { 0, }; | |
2085 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
2086 | g_value_set_boolean( &gvalue, FALSE ); | |
2087 | g_object_set_property( G_OBJECT(renderer), "foreground-set", &gvalue ); | |
2088 | g_value_unset( &gvalue ); | |
2089 | } | |
2090 | ||
2091 | if (attr.GetItalic()) | |
2092 | { | |
2093 | GValue gvalue = { 0, }; | |
2094 | g_value_init( &gvalue, PANGO_TYPE_STYLE ); | |
2095 | g_value_set_enum( &gvalue, PANGO_STYLE_ITALIC ); | |
2096 | g_object_set_property( G_OBJECT(renderer), "style", &gvalue ); | |
2097 | g_value_unset( &gvalue ); | |
2098 | ||
2099 | usingDefaultAttrs = false; | |
2100 | } | |
2101 | else | |
2102 | { | |
2103 | GValue gvalue = { 0, }; | |
2104 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
2105 | g_value_set_boolean( &gvalue, FALSE ); | |
2106 | g_object_set_property( G_OBJECT(renderer), "style-set", &gvalue ); | |
2107 | g_value_unset( &gvalue ); | |
2108 | } | |
2109 | ||
2110 | ||
2111 | if (attr.GetBold()) | |
2112 | { | |
2113 | GValue gvalue = { 0, }; | |
2114 | g_value_init( &gvalue, PANGO_TYPE_WEIGHT ); | |
2115 | g_value_set_enum( &gvalue, PANGO_WEIGHT_BOLD ); | |
2116 | g_object_set_property( G_OBJECT(renderer), "weight", &gvalue ); | |
2117 | g_value_unset( &gvalue ); | |
2118 | ||
2119 | usingDefaultAttrs = false; | |
2120 | } | |
2121 | else | |
2122 | { | |
2123 | GValue gvalue = { 0, }; | |
2124 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
2125 | g_value_set_boolean( &gvalue, FALSE ); | |
2126 | g_object_set_property( G_OBJECT(renderer), "weight-set", &gvalue ); | |
2127 | g_value_unset( &gvalue ); | |
2128 | } | |
2129 | ||
2130 | #if 0 | |
2131 | if (attr.HasBackgroundColour()) | |
2132 | { | |
2133 | wxColour colour = attr.GetBackgroundColour(); | |
2134 | const GdkColor * const gcol = colour.GetColor(); | |
2135 | ||
2136 | GValue gvalue = { 0, }; | |
2137 | g_value_init( &gvalue, GDK_TYPE_COLOR ); | |
2138 | g_value_set_boxed( &gvalue, gcol ); | |
2139 | g_object_set_property( G_OBJECT(renderer), "cell-background_gdk", &gvalue ); | |
2140 | g_value_unset( &gvalue ); | |
2141 | } | |
2142 | else | |
2143 | { | |
2144 | GValue gvalue = { 0, }; | |
2145 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
2146 | g_value_set_boolean( &gvalue, FALSE ); | |
2147 | g_object_set_property( G_OBJECT(renderer), "cell-background-set", &gvalue ); | |
2148 | g_value_unset( &gvalue ); | |
2149 | } | |
2150 | #endif | |
2151 | ||
2152 | return !usingDefaultAttrs; | |
2153 | } | |
2154 | ||
2155 | } // anonymous namespace | |
2156 | ||
baa9ebc4 | 2157 | IMPLEMENT_CLASS(wxDataViewTextRenderer, wxDataViewRenderer) |
6842a71a | 2158 | |
9861f022 RR |
2159 | wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString &varianttype, wxDataViewCellMode mode, |
2160 | int align ) : | |
2161 | wxDataViewRenderer( varianttype, mode, align ) | |
6842a71a | 2162 | { |
ecc32226 RR |
2163 | GtkWxCellRendererText *text_renderer = gtk_wx_cell_renderer_text_new(); |
2164 | text_renderer->wx_renderer = this; | |
2165 | m_renderer = (GtkCellRenderer*) text_renderer; | |
93763ad5 | 2166 | |
9861f022 | 2167 | if (mode & wxDATAVIEW_CELL_EDITABLE) |
a7f61f76 RR |
2168 | { |
2169 | GValue gvalue = { 0, }; | |
2170 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
2171 | g_value_set_boolean( &gvalue, true ); | |
2172 | g_object_set_property( G_OBJECT(m_renderer), "editable", &gvalue ); | |
2173 | g_value_unset( &gvalue ); | |
93763ad5 | 2174 | |
a7f61f76 | 2175 | g_signal_connect_after( m_renderer, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback), this ); |
b9db5f30 | 2176 | |
a912e81f | 2177 | GtkInitHandlers(); |
a7f61f76 | 2178 | } |
9861f022 RR |
2179 | |
2180 | SetMode(mode); | |
2181 | SetAlignment(align); | |
6842a71a | 2182 | } |
790b137e | 2183 | |
205bdf20 | 2184 | bool wxDataViewTextRenderer::SetTextValue(const wxString& str) |
7b4fde82 | 2185 | { |
7b4fde82 RR |
2186 | GValue gvalue = { 0, }; |
2187 | g_value_init( &gvalue, G_TYPE_STRING ); | |
205bdf20 | 2188 | g_value_set_string( &gvalue, wxGTK_CONV_FONT( str, GetOwner()->GetOwner()->GetFont() ) ); |
7b4fde82 RR |
2189 | g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue ); |
2190 | g_value_unset( &gvalue ); | |
93763ad5 | 2191 | |
7b4fde82 RR |
2192 | return true; |
2193 | } | |
2194 | ||
205bdf20 | 2195 | bool wxDataViewTextRenderer::GetTextValue(wxString& str) const |
a7f61f76 RR |
2196 | { |
2197 | GValue gvalue = { 0, }; | |
2198 | g_value_init( &gvalue, G_TYPE_STRING ); | |
2199 | g_object_get_property( G_OBJECT(m_renderer), "text", &gvalue ); | |
205bdf20 | 2200 | str = wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue ), const_cast<wxDataViewTextRenderer*>(this)->GetOwner()->GetOwner()->GetFont() ); |
a7f61f76 | 2201 | g_value_unset( &gvalue ); |
93763ad5 | 2202 | |
a7f61f76 RR |
2203 | return true; |
2204 | } | |
2205 | ||
9861f022 RR |
2206 | void wxDataViewTextRenderer::SetAlignment( int align ) |
2207 | { | |
2208 | wxDataViewRenderer::SetAlignment(align); | |
2209 | ||
9dc44eff | 2210 | #ifndef __WXGTK3__ |
01705e98 RR |
2211 | if (gtk_check_version(2,10,0)) |
2212 | return; | |
9dc44eff | 2213 | #endif |
9861f022 | 2214 | |
01705e98 | 2215 | // horizontal alignment: |
9861f022 RR |
2216 | PangoAlignment pangoAlign = PANGO_ALIGN_LEFT; |
2217 | if (align & wxALIGN_RIGHT) | |
2218 | pangoAlign = PANGO_ALIGN_RIGHT; | |
2219 | else if (align & wxALIGN_CENTER_HORIZONTAL) | |
2220 | pangoAlign = PANGO_ALIGN_CENTER; | |
2221 | ||
2222 | GValue gvalue = { 0, }; | |
2223 | g_value_init( &gvalue, gtk_cell_renderer_mode_get_type() ); | |
2224 | g_value_set_enum( &gvalue, pangoAlign ); | |
2225 | g_object_set_property( G_OBJECT(m_renderer), "alignment", &gvalue ); | |
2226 | g_value_unset( &gvalue ); | |
2227 | } | |
2228 | ||
c80cde00 VZ |
2229 | bool wxDataViewTextRenderer::GtkSetAttr(const wxDataViewItemAttr& attr) |
2230 | { | |
17cbc244 VZ |
2231 | return GtkApplyAttr(GtkGetTextRenderer(), attr); |
2232 | } | |
2233 | ||
2234 | GtkCellRendererText *wxDataViewTextRenderer::GtkGetTextRenderer() const | |
2235 | { | |
2236 | return GTK_CELL_RENDERER_TEXT(m_renderer); | |
c80cde00 VZ |
2237 | } |
2238 | ||
f4322df6 | 2239 | // --------------------------------------------------------- |
baa9ebc4 | 2240 | // wxDataViewBitmapRenderer |
f4322df6 | 2241 | // --------------------------------------------------------- |
cbc9145c | 2242 | |
205bdf20 VZ |
2243 | namespace |
2244 | { | |
2245 | ||
2246 | // set "pixbuf" property on the given renderer | |
2247 | void SetPixbufProp(GtkCellRenderer *renderer, GdkPixbuf *pixbuf) | |
2248 | { | |
2249 | GValue gvalue = { 0, }; | |
2250 | g_value_init( &gvalue, G_TYPE_OBJECT ); | |
2251 | g_value_set_object( &gvalue, pixbuf ); | |
2252 | g_object_set_property( G_OBJECT(renderer), "pixbuf", &gvalue ); | |
2253 | g_value_unset( &gvalue ); | |
2254 | } | |
2255 | ||
2256 | } // anonymous namespace | |
2257 | ||
baa9ebc4 | 2258 | IMPLEMENT_CLASS(wxDataViewBitmapRenderer, wxDataViewRenderer) |
cbc9145c | 2259 | |
9861f022 RR |
2260 | wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString &varianttype, wxDataViewCellMode mode, |
2261 | int align ) : | |
2262 | wxDataViewRenderer( varianttype, mode, align ) | |
cbc9145c | 2263 | { |
205bdf20 | 2264 | m_renderer = gtk_cell_renderer_pixbuf_new(); |
9861f022 RR |
2265 | |
2266 | SetMode(mode); | |
2267 | SetAlignment(align); | |
cbc9145c RR |
2268 | } |
2269 | ||
baa9ebc4 | 2270 | bool wxDataViewBitmapRenderer::SetValue( const wxVariant &value ) |
cbc9145c RR |
2271 | { |
2272 | if (value.GetType() == wxT("wxBitmap")) | |
2273 | { | |
2586d4a1 RR |
2274 | wxBitmap bitmap; |
2275 | bitmap << value; | |
f4322df6 | 2276 | |
205bdf20 VZ |
2277 | // GetPixbuf() may create a Pixbuf representation in the wxBitmap |
2278 | // object (and it will stay there and remain owned by wxBitmap) | |
2279 | SetPixbufProp(m_renderer, bitmap.GetPixbuf()); | |
2586d4a1 | 2280 | } |
205bdf20 | 2281 | else if (value.GetType() == wxT("wxIcon")) |
2586d4a1 | 2282 | { |
205bdf20 VZ |
2283 | wxIcon icon; |
2284 | icon << value; | |
f4322df6 | 2285 | |
205bdf20 VZ |
2286 | SetPixbufProp(m_renderer, icon.GetPixbuf()); |
2287 | } | |
2288 | else | |
2289 | { | |
2290 | return false; | |
cbc9145c | 2291 | } |
f4322df6 | 2292 | |
205bdf20 | 2293 | return true; |
cbc9145c RR |
2294 | } |
2295 | ||
c5c5395b | 2296 | bool wxDataViewBitmapRenderer::GetValue( wxVariant &WXUNUSED(value) ) const |
cbc9145c RR |
2297 | { |
2298 | return false; | |
2299 | } | |
f4322df6 | 2300 | |
93763ad5 | 2301 | // --------------------------------------------------------- |
baa9ebc4 | 2302 | // wxDataViewToggleRenderer |
93763ad5 | 2303 | // --------------------------------------------------------- |
fa28826d | 2304 | |
605c2c4a | 2305 | extern "C" { |
93763ad5 | 2306 | static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle *renderer, |
605c2c4a RR |
2307 | gchar *path, gpointer user_data ); |
2308 | } | |
2309 | ||
93763ad5 | 2310 | static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle *renderer, |
605c2c4a RR |
2311 | gchar *path, gpointer user_data ) |
2312 | { | |
baa9ebc4 | 2313 | wxDataViewToggleRenderer *cell = (wxDataViewToggleRenderer*) user_data; |
605c2c4a | 2314 | |
93763ad5 | 2315 | // get old value |
605c2c4a RR |
2316 | GValue gvalue = { 0, }; |
2317 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
2318 | g_object_get_property( G_OBJECT(renderer), "active", &gvalue ); | |
605c2c4a | 2319 | // invert it |
d5027818 PC |
2320 | wxVariant value = !g_value_get_boolean( &gvalue ); |
2321 | g_value_unset( &gvalue ); | |
93763ad5 | 2322 | |
605c2c4a RR |
2323 | if (!cell->Validate( value )) |
2324 | return; | |
93763ad5 | 2325 | |
0c2a7270 VZ |
2326 | wxDataViewCtrl * const ctrl = cell->GetOwner()->GetOwner(); |
2327 | wxDataViewModel *model = ctrl->GetModel(); | |
93763ad5 | 2328 | |
0c2a7270 | 2329 | wxDataViewItem item(ctrl->GTKPathToItem(wxGtkTreePath(path))); |
93763ad5 | 2330 | |
0a71f9e9 | 2331 | unsigned int model_col = cell->GetOwner()->GetModelColumn(); |
93763ad5 | 2332 | |
795dac4c | 2333 | model->ChangeValue( value, item, model_col ); |
605c2c4a RR |
2334 | } |
2335 | ||
baa9ebc4 | 2336 | IMPLEMENT_CLASS(wxDataViewToggleRenderer, wxDataViewRenderer) |
605c2c4a | 2337 | |
baa9ebc4 | 2338 | wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString &varianttype, |
9861f022 RR |
2339 | wxDataViewCellMode mode, int align ) : |
2340 | wxDataViewRenderer( varianttype, mode, align ) | |
605c2c4a | 2341 | { |
ed38aa55 | 2342 | m_renderer = (GtkCellRenderer*) gtk_cell_renderer_toggle_new(); |
93763ad5 | 2343 | |
9861f022 | 2344 | if (mode & wxDATAVIEW_CELL_ACTIVATABLE) |
605c2c4a | 2345 | { |
9861f022 RR |
2346 | g_signal_connect_after( m_renderer, "toggled", |
2347 | G_CALLBACK(wxGtkToggleRendererToggledCallback), this ); | |
553f7d8f RR |
2348 | } |
2349 | else | |
2350 | { | |
605c2c4a RR |
2351 | GValue gvalue = { 0, }; |
2352 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
553f7d8f | 2353 | g_value_set_boolean( &gvalue, false ); |
605c2c4a RR |
2354 | g_object_set_property( G_OBJECT(m_renderer), "activatable", &gvalue ); |
2355 | g_value_unset( &gvalue ); | |
605c2c4a | 2356 | } |
9861f022 RR |
2357 | |
2358 | SetMode(mode); | |
2359 | SetAlignment(align); | |
605c2c4a RR |
2360 | } |
2361 | ||
baa9ebc4 | 2362 | bool wxDataViewToggleRenderer::SetValue( const wxVariant &value ) |
605c2c4a RR |
2363 | { |
2364 | bool tmp = value; | |
93763ad5 | 2365 | |
605c2c4a RR |
2366 | GValue gvalue = { 0, }; |
2367 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
2368 | g_value_set_boolean( &gvalue, tmp ); | |
2369 | g_object_set_property( G_OBJECT(m_renderer), "active", &gvalue ); | |
2370 | g_value_unset( &gvalue ); | |
93763ad5 | 2371 | |
605c2c4a RR |
2372 | return true; |
2373 | } | |
2374 | ||
9861f022 | 2375 | bool wxDataViewToggleRenderer::GetValue( wxVariant &value ) const |
605c2c4a RR |
2376 | { |
2377 | GValue gvalue = { 0, }; | |
2378 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
2379 | g_object_get_property( G_OBJECT(m_renderer), "active", &gvalue ); | |
d5027818 | 2380 | value = g_value_get_boolean( &gvalue ) != 0; |
605c2c4a | 2381 | g_value_unset( &gvalue ); |
93763ad5 | 2382 | |
605c2c4a RR |
2383 | return true; |
2384 | } | |
93763ad5 WS |
2385 | |
2386 | // --------------------------------------------------------- | |
baa9ebc4 | 2387 | // wxDataViewCustomRenderer |
93763ad5 | 2388 | // --------------------------------------------------------- |
e152afc3 | 2389 | |
9dc44eff | 2390 | #ifndef __WXGTK3__ |
888dde65 | 2391 | class wxDataViewCtrlDCImpl: public wxWindowDCImpl |
e152afc3 RR |
2392 | { |
2393 | public: | |
888dde65 RR |
2394 | wxDataViewCtrlDCImpl( wxDC *owner, wxDataViewCtrl *window ) : |
2395 | wxWindowDCImpl( owner ) | |
2396 | { | |
1a367564 | 2397 | GtkWidget *widget = window->m_treeview; |
e152afc3 | 2398 | // Set later |
888dde65 | 2399 | m_gdkwindow = NULL; |
7857346a | 2400 | |
888dde65 | 2401 | m_window = window; |
4d496ecb | 2402 | |
496e7ec6 | 2403 | m_context = window->GTKGetPangoDefaultContext(); |
e152afc3 | 2404 | m_layout = pango_layout_new( m_context ); |
385e8575 | 2405 | m_fontdesc = pango_font_description_copy(gtk_widget_get_style(widget)->font_desc); |
e152afc3 RR |
2406 | |
2407 | m_cmap = gtk_widget_get_colormap( widget ? widget : window->m_widget ); | |
888dde65 RR |
2408 | |
2409 | // Set m_gdkwindow later | |
4d496ecb | 2410 | // SetUpDC(); |
e152afc3 RR |
2411 | } |
2412 | }; | |
2413 | ||
888dde65 RR |
2414 | class wxDataViewCtrlDC: public wxWindowDC |
2415 | { | |
2416 | public: | |
c5c5395b RR |
2417 | wxDataViewCtrlDC( wxDataViewCtrl *window ) : |
2418 | wxWindowDC( new wxDataViewCtrlDCImpl( this, window ) ) | |
7857346a | 2419 | { } |
888dde65 | 2420 | }; |
9dc44eff | 2421 | #endif |
888dde65 | 2422 | |
93763ad5 | 2423 | // --------------------------------------------------------- |
baa9ebc4 | 2424 | // wxDataViewCustomRenderer |
93763ad5 | 2425 | // --------------------------------------------------------- |
e152afc3 | 2426 | |
baa9ebc4 | 2427 | IMPLEMENT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer) |
e152afc3 | 2428 | |
baa9ebc4 | 2429 | wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype, |
6eec70b9 VZ |
2430 | wxDataViewCellMode mode, |
2431 | int align, | |
2432 | bool no_init ) | |
2433 | : wxDataViewCustomRendererBase( varianttype, mode, align ) | |
e152afc3 RR |
2434 | { |
2435 | m_dc = NULL; | |
f69c03de | 2436 | m_text_renderer = NULL; |
02800dde | 2437 | m_renderParams = NULL; |
93763ad5 | 2438 | |
ad63bf41 RR |
2439 | if (no_init) |
2440 | m_renderer = NULL; | |
2441 | else | |
9861f022 | 2442 | Init(mode, align); |
ad63bf41 RR |
2443 | } |
2444 | ||
3e81bbbf VZ |
2445 | void wxDataViewCustomRenderer::GtkInitTextRenderer() |
2446 | { | |
2447 | m_text_renderer = GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new()); | |
2448 | g_object_ref_sink(m_text_renderer); | |
2449 | ||
2450 | GtkApplyAlignment(GTK_CELL_RENDERER(m_text_renderer)); | |
2451 | } | |
2452 | ||
17cbc244 VZ |
2453 | GtkCellRendererText *wxDataViewCustomRenderer::GtkGetTextRenderer() const |
2454 | { | |
2455 | if ( !m_text_renderer ) | |
2456 | { | |
2457 | // we create it on demand so need to do it even from a const function | |
3e81bbbf | 2458 | const_cast<wxDataViewCustomRenderer *>(this)->GtkInitTextRenderer(); |
17cbc244 VZ |
2459 | } |
2460 | ||
2461 | return m_text_renderer; | |
2462 | } | |
2463 | ||
2a454ffd VZ |
2464 | void wxDataViewCustomRenderer::RenderText( const wxString &text, |
2465 | int xoffset, | |
2466 | wxRect cell, | |
2467 | wxDC *WXUNUSED(dc), | |
2468 | int WXUNUSED(state) ) | |
52e750fc | 2469 | { |
17cbc244 VZ |
2470 | |
2471 | GtkCellRendererText * const textRenderer = GtkGetTextRenderer(); | |
b9db5f30 | 2472 | |
f69c03de RR |
2473 | GValue gvalue = { 0, }; |
2474 | g_value_init( &gvalue, G_TYPE_STRING ); | |
1bf629bd | 2475 | g_value_set_string( &gvalue, wxGTK_CONV_FONT( text, GetOwner()->GetOwner()->GetFont() ) ); |
17cbc244 | 2476 | g_object_set_property( G_OBJECT(textRenderer), "text", &gvalue ); |
f69c03de RR |
2477 | g_value_unset( &gvalue ); |
2478 | ||
17cbc244 | 2479 | GtkApplyAttr(textRenderer, GetAttr()); |
c80cde00 | 2480 | |
2a454ffd VZ |
2481 | GdkRectangle cell_area; |
2482 | wxRectToGDKRect(cell, cell_area); | |
2483 | cell_area.x += xoffset; | |
2484 | cell_area.width -= xoffset; | |
b9db5f30 | 2485 | |
17cbc244 | 2486 | gtk_cell_renderer_render( GTK_CELL_RENDERER(textRenderer), |
9dc44eff PC |
2487 | #ifdef __WXGTK3__ |
2488 | m_renderParams->cr, | |
2489 | #else | |
02800dde | 2490 | m_renderParams->window, |
9dc44eff | 2491 | #endif |
02800dde PC |
2492 | m_renderParams->widget, |
2493 | m_renderParams->background_area, | |
2a454ffd | 2494 | &cell_area, |
9dc44eff | 2495 | #ifndef __WXGTK3__ |
02800dde | 2496 | m_renderParams->expose_area, |
9dc44eff | 2497 | #endif |
02800dde | 2498 | GtkCellRendererState(m_renderParams->flags)); |
52e750fc RR |
2499 | } |
2500 | ||
9861f022 | 2501 | bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode, int align) |
ad63bf41 | 2502 | { |
e152afc3 RR |
2503 | GtkWxCellRenderer *renderer = (GtkWxCellRenderer *) gtk_wx_cell_renderer_new(); |
2504 | renderer->cell = this; | |
93763ad5 | 2505 | |
ed38aa55 | 2506 | m_renderer = (GtkCellRenderer*) renderer; |
93763ad5 | 2507 | |
9861f022 RR |
2508 | SetMode(mode); |
2509 | SetAlignment(align); | |
93763ad5 | 2510 | |
a912e81f | 2511 | GtkInitHandlers(); |
b9db5f30 | 2512 | |
ad63bf41 | 2513 | return true; |
e152afc3 RR |
2514 | } |
2515 | ||
baa9ebc4 | 2516 | wxDataViewCustomRenderer::~wxDataViewCustomRenderer() |
e152afc3 RR |
2517 | { |
2518 | if (m_dc) | |
2519 | delete m_dc; | |
f69c03de RR |
2520 | |
2521 | if (m_text_renderer) | |
385e8575 | 2522 | g_object_unref(m_text_renderer); |
e152afc3 RR |
2523 | } |
2524 | ||
baa9ebc4 | 2525 | wxDC *wxDataViewCustomRenderer::GetDC() |
e152afc3 RR |
2526 | { |
2527 | if (m_dc == NULL) | |
4d496ecb | 2528 | { |
9dc44eff PC |
2529 | #ifdef __WXGTK3__ |
2530 | wxASSERT(m_renderParams); | |
2531 | cairo_t* cr = m_renderParams->cr; | |
2532 | wxASSERT(cr && cairo_status(cr) == 0); | |
2533 | m_dc = new wxGTKCairoDC(cr); | |
2534 | #else | |
4d496ecb RR |
2535 | if (GetOwner() == NULL) |
2536 | return NULL; | |
2537 | if (GetOwner()->GetOwner() == NULL) | |
2538 | return NULL; | |
e152afc3 | 2539 | m_dc = new wxDataViewCtrlDC( GetOwner()->GetOwner() ); |
9dc44eff | 2540 | #endif |
4d496ecb | 2541 | } |
93763ad5 | 2542 | |
e152afc3 RR |
2543 | return m_dc; |
2544 | } | |
93763ad5 WS |
2545 | |
2546 | // --------------------------------------------------------- | |
baa9ebc4 | 2547 | // wxDataViewProgressRenderer |
93763ad5 | 2548 | // --------------------------------------------------------- |
ad63bf41 | 2549 | |
baa9ebc4 | 2550 | IMPLEMENT_CLASS(wxDataViewProgressRenderer, wxDataViewCustomRenderer) |
ad63bf41 | 2551 | |
baa9ebc4 | 2552 | wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString &label, |
9861f022 RR |
2553 | const wxString &varianttype, wxDataViewCellMode mode, int align ) : |
2554 | wxDataViewCustomRenderer( varianttype, mode, align, true ) | |
ad63bf41 RR |
2555 | { |
2556 | m_label = label; | |
2557 | m_value = 0; | |
93763ad5 | 2558 | |
ad63bf41 | 2559 | #ifdef __WXGTK26__ |
9dc44eff | 2560 | if (GTK_CHECK_VERSION(3,0,0) || gtk_check_version(2,6,0) == NULL) |
ad63bf41 | 2561 | { |
ed38aa55 | 2562 | m_renderer = (GtkCellRenderer*) gtk_cell_renderer_progress_new(); |
93763ad5 | 2563 | |
9861f022 RR |
2564 | SetMode(mode); |
2565 | SetAlignment(align); | |
fdd67a6a VZ |
2566 | |
2567 | #if !wxUSE_UNICODE | |
2568 | // We can't initialize the renderer just yet because we don't have the | |
2569 | // pointer to the column that uses this renderer yet and so attempt to | |
2570 | // dereference GetOwner() to get the font that is used as a source of | |
2571 | // encoding in multibyte-to-Unicode conversion in GTKSetLabel() in | |
2572 | // non-Unicode builds would crash. So simply remember to do it later. | |
2573 | if ( !m_label.empty() ) | |
2574 | m_needsToSetLabel = true; | |
2575 | else | |
2576 | #endif // !wxUSE_UNICODE | |
2577 | GTKSetLabel(); | |
ad63bf41 RR |
2578 | } |
2579 | else | |
2580 | #endif | |
2581 | { | |
2582 | // Use custom cell code | |
9861f022 | 2583 | wxDataViewCustomRenderer::Init(mode, align); |
ad63bf41 RR |
2584 | } |
2585 | } | |
2586 | ||
baa9ebc4 | 2587 | wxDataViewProgressRenderer::~wxDataViewProgressRenderer() |
ad63bf41 RR |
2588 | { |
2589 | } | |
2590 | ||
fdd67a6a VZ |
2591 | void wxDataViewProgressRenderer::GTKSetLabel() |
2592 | { | |
2593 | GValue gvalue = { 0, }; | |
2594 | g_value_init( &gvalue, G_TYPE_STRING ); | |
2595 | ||
2596 | // Take care to not use GetOwner() here if the label is empty, we can be | |
2597 | // called from ctor when GetOwner() is still NULL in this case. | |
4fb1e79b VZ |
2598 | wxScopedCharBuffer buf; |
2599 | if ( m_label.empty() ) | |
2600 | buf = wxScopedCharBuffer::CreateNonOwned(""); | |
2601 | else | |
2602 | buf = wxGTK_CONV_FONT(m_label, GetOwner()->GetOwner()->GetFont()); | |
2603 | ||
2604 | g_value_set_string( &gvalue, buf); | |
fdd67a6a VZ |
2605 | g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue ); |
2606 | g_value_unset( &gvalue ); | |
2607 | ||
2608 | #if !wxUSE_UNICODE | |
2609 | m_needsToSetLabel = false; | |
2610 | #endif // !wxUSE_UNICODE | |
2611 | } | |
2612 | ||
baa9ebc4 | 2613 | bool wxDataViewProgressRenderer::SetValue( const wxVariant &value ) |
ad63bf41 RR |
2614 | { |
2615 | #ifdef __WXGTK26__ | |
9dc44eff | 2616 | if (GTK_CHECK_VERSION(3,0,0) || gtk_check_version(2,6,0) == NULL) |
ad63bf41 | 2617 | { |
fdd67a6a VZ |
2618 | #if !wxUSE_UNICODE |
2619 | if ( m_needsToSetLabel ) | |
2620 | GTKSetLabel(); | |
2621 | #endif // !wxUSE_UNICODE | |
2622 | ||
7226118b | 2623 | gint tmp = (long) value; |
ad63bf41 RR |
2624 | GValue gvalue = { 0, }; |
2625 | g_value_init( &gvalue, G_TYPE_INT ); | |
7226118b | 2626 | g_value_set_int( &gvalue, tmp ); |
ad63bf41 RR |
2627 | g_object_set_property( G_OBJECT(m_renderer), "value", &gvalue ); |
2628 | g_value_unset( &gvalue ); | |
2629 | } | |
2630 | else | |
2631 | #endif | |
2632 | { | |
2633 | m_value = (long) value; | |
93763ad5 | 2634 | |
ad63bf41 RR |
2635 | if (m_value < 0) m_value = 0; |
2636 | if (m_value > 100) m_value = 100; | |
2637 | } | |
93763ad5 | 2638 | |
ad63bf41 RR |
2639 | return true; |
2640 | } | |
93763ad5 | 2641 | |
85136e3b | 2642 | bool wxDataViewProgressRenderer::GetValue( wxVariant &WXUNUSED(value) ) const |
9861f022 RR |
2643 | { |
2644 | return false; | |
2645 | } | |
2646 | ||
85136e3b | 2647 | bool wxDataViewProgressRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) ) |
ad63bf41 RR |
2648 | { |
2649 | double pct = (double)m_value / 100.0; | |
2650 | wxRect bar = cell; | |
2651 | bar.width = (int)(cell.width * pct); | |
2652 | dc->SetPen( *wxTRANSPARENT_PEN ); | |
2653 | dc->SetBrush( *wxBLUE_BRUSH ); | |
2654 | dc->DrawRectangle( bar ); | |
2655 | ||
2656 | dc->SetBrush( *wxTRANSPARENT_BRUSH ); | |
2657 | dc->SetPen( *wxBLACK_PEN ); | |
2658 | dc->DrawRectangle( cell ); | |
93763ad5 | 2659 | |
ad63bf41 RR |
2660 | return true; |
2661 | } | |
2662 | ||
9861f022 | 2663 | wxSize wxDataViewProgressRenderer::GetSize() const |
ad63bf41 RR |
2664 | { |
2665 | return wxSize(40,12); | |
2666 | } | |
93763ad5 | 2667 | |
7448d67c RR |
2668 | // ------------------------------------- |
2669 | // wxDataViewChoiceRenderer | |
2670 | // ------------------------------------- | |
2671 | ||
2672 | wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString &choices, | |
2673 | wxDataViewCellMode mode, int alignment ) : | |
2674 | wxDataViewCustomRenderer( "string", mode, alignment, true ) | |
2675 | { | |
2676 | m_choices = choices; | |
2677 | ||
2678 | #ifdef __WXGTK26__ | |
9dc44eff | 2679 | if (GTK_CHECK_VERSION(3,0,0) || gtk_check_version(2,6,0) == NULL) |
7448d67c RR |
2680 | { |
2681 | m_renderer = (GtkCellRenderer*) gtk_cell_renderer_combo_new(); | |
2682 | ||
2683 | GtkListStore *store = gtk_list_store_new( 1, G_TYPE_STRING ); | |
5baee1f4 VZ |
2684 | for (size_t n = 0; n < m_choices.GetCount(); n++) |
2685 | { | |
2686 | gtk_list_store_insert_with_values( | |
2687 | store, NULL, n, 0, | |
2688 | static_cast<const char *>(m_choices[n].utf8_str()), -1 ); | |
2689 | } | |
bc0289bf | 2690 | |
7448d67c RR |
2691 | g_object_set (m_renderer, |
2692 | "model", store, | |
2693 | "text-column", 0, | |
2694 | "has-entry", FALSE, | |
2695 | NULL); | |
bc0289bf | 2696 | |
d5027818 | 2697 | bool editable = (mode & wxDATAVIEW_CELL_EDITABLE) != 0; |
7448d67c | 2698 | g_object_set (m_renderer, "editable", editable, NULL); |
bc0289bf | 2699 | |
7448d67c | 2700 | SetAlignment(alignment); |
bc0289bf | 2701 | |
7448d67c RR |
2702 | g_signal_connect_after( m_renderer, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback), this ); |
2703 | ||
2704 | GtkInitHandlers(); | |
2705 | } | |
2706 | else | |
2707 | #endif | |
2708 | { | |
2709 | // Use custom cell code | |
2710 | wxDataViewCustomRenderer::Init(mode, alignment); | |
2711 | } | |
2712 | } | |
2713 | ||
2714 | bool wxDataViewChoiceRenderer::Render( wxRect rect, wxDC *dc, int state ) | |
2715 | { | |
2716 | RenderText( m_data, 0, rect, dc, state ); | |
2717 | return true; | |
2718 | } | |
2719 | ||
2720 | wxSize wxDataViewChoiceRenderer::GetSize() const | |
2721 | { | |
2722 | return wxSize(70,20); | |
2723 | } | |
2724 | ||
2725 | bool wxDataViewChoiceRenderer::SetValue( const wxVariant &value ) | |
2726 | { | |
bc0289bf | 2727 | |
7448d67c | 2728 | #ifdef __WXGTK26__ |
9dc44eff | 2729 | if (GTK_CHECK_VERSION(3,0,0) || gtk_check_version(2,6,0) == NULL) |
7448d67c RR |
2730 | { |
2731 | GValue gvalue = { 0, }; | |
2732 | g_value_init( &gvalue, G_TYPE_STRING ); | |
d636e043 VZ |
2733 | g_value_set_string(&gvalue, |
2734 | wxGTK_CONV_FONT(value.GetString(), | |
2735 | GetOwner()->GetOwner()->GetFont())); | |
7448d67c RR |
2736 | g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue ); |
2737 | g_value_unset( &gvalue ); | |
2738 | } | |
2739 | else | |
2740 | #endif | |
2741 | m_data = value.GetString(); | |
2742 | ||
2743 | return true; | |
2744 | } | |
2745 | ||
2746 | bool wxDataViewChoiceRenderer::GetValue( wxVariant &value ) const | |
2747 | { | |
2748 | #ifdef __WXGTK26__ | |
9dc44eff | 2749 | if (GTK_CHECK_VERSION(3,0,0) || gtk_check_version(2,6,0) == NULL) |
7448d67c RR |
2750 | { |
2751 | GValue gvalue = { 0, }; | |
2752 | g_value_init( &gvalue, G_TYPE_STRING ); | |
2753 | g_object_get_property( G_OBJECT(m_renderer), "text", &gvalue ); | |
d636e043 VZ |
2754 | wxString temp = wxGTK_CONV_BACK_FONT(g_value_get_string(&gvalue), |
2755 | GetOwner()->GetOwner()->GetFont()); | |
7448d67c RR |
2756 | g_value_unset( &gvalue ); |
2757 | value = temp; | |
c2489d8e FM |
2758 | |
2759 | //wxPrintf( "temp %s\n", temp ); | |
2760 | // TODO: remove this code | |
7448d67c RR |
2761 | } |
2762 | else | |
2763 | #endif | |
2764 | value = m_data; | |
2765 | ||
2766 | return true; | |
2767 | } | |
2768 | ||
2769 | void wxDataViewChoiceRenderer::SetAlignment( int align ) | |
2770 | { | |
2771 | wxDataViewCustomRenderer::SetAlignment(align); | |
2772 | ||
9dc44eff | 2773 | #ifndef __WXGTK3__ |
7448d67c RR |
2774 | if (gtk_check_version(2,10,0)) |
2775 | return; | |
9dc44eff | 2776 | #endif |
7448d67c RR |
2777 | |
2778 | // horizontal alignment: | |
2779 | PangoAlignment pangoAlign = PANGO_ALIGN_LEFT; | |
2780 | if (align & wxALIGN_RIGHT) | |
2781 | pangoAlign = PANGO_ALIGN_RIGHT; | |
2782 | else if (align & wxALIGN_CENTER_HORIZONTAL) | |
2783 | pangoAlign = PANGO_ALIGN_CENTER; | |
2784 | ||
2785 | GValue gvalue = { 0, }; | |
2786 | g_value_init( &gvalue, gtk_cell_renderer_mode_get_type() ); | |
2787 | g_value_set_enum( &gvalue, pangoAlign ); | |
2788 | g_object_set_property( G_OBJECT(m_renderer), "alignment", &gvalue ); | |
2789 | g_value_unset( &gvalue ); | |
2790 | } | |
bc0289bf | 2791 | |
65887bd0 RR |
2792 | // ---------------------------------------------------------------------------- |
2793 | // wxDataViewChoiceByIndexRenderer | |
2794 | // ---------------------------------------------------------------------------- | |
2795 | ||
2796 | wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString &choices, | |
2797 | wxDataViewCellMode mode, int alignment ) : | |
2798 | wxDataViewChoiceRenderer( choices, mode, alignment ) | |
2799 | { | |
2800 | } | |
ce00f59b | 2801 | |
29e461a2 | 2802 | void wxDataViewChoiceByIndexRenderer::GtkOnTextEdited(const char *itempath, const wxString& str) |
65887bd0 RR |
2803 | { |
2804 | wxVariant value( (long) GetChoices().Index( str ) ); | |
2805 | ||
2806 | if (!Validate( value )) | |
2807 | return; | |
2808 | ||
0c2a7270 VZ |
2809 | wxDataViewItem |
2810 | item(GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(itempath))); | |
65887bd0 RR |
2811 | |
2812 | GtkOnCellChanged(value, item, GetOwner()->GetModelColumn()); | |
2813 | } | |
2814 | ||
2815 | bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant &value ) | |
2816 | { | |
2817 | wxVariant string_value = GetChoice( value.GetLong() ); | |
2818 | return wxDataViewChoiceRenderer::SetValue( string_value ); | |
2819 | } | |
ce00f59b | 2820 | |
65887bd0 RR |
2821 | bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant &value ) const |
2822 | { | |
2823 | wxVariant string_value; | |
2824 | if (!wxDataViewChoiceRenderer::GetValue( string_value )) | |
2825 | return false; | |
ce00f59b | 2826 | |
65887bd0 RR |
2827 | value = (long) GetChoices().Index( string_value.GetString() ); |
2828 | return true; | |
2829 | } | |
2830 | ||
b9db5f30 | 2831 | // --------------------------------------------------------- |
c9c13e70 | 2832 | // wxDataViewIconTextRenderer |
b9db5f30 | 2833 | // --------------------------------------------------------- |
c9c13e70 RR |
2834 | |
2835 | IMPLEMENT_CLASS(wxDataViewIconTextRenderer, wxDataViewCustomRenderer) | |
2836 | ||
205bdf20 VZ |
2837 | wxDataViewIconTextRenderer::wxDataViewIconTextRenderer |
2838 | ( | |
2839 | const wxString &varianttype, | |
2840 | wxDataViewCellMode mode, | |
2841 | int align | |
2842 | ) | |
2843 | : wxDataViewTextRenderer(varianttype, mode, align) | |
c9c13e70 | 2844 | { |
205bdf20 | 2845 | m_rendererIcon = gtk_cell_renderer_pixbuf_new(); |
c9c13e70 RR |
2846 | } |
2847 | ||
2848 | wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer() | |
2849 | { | |
2850 | } | |
b9db5f30 | 2851 | |
205bdf20 | 2852 | void wxDataViewIconTextRenderer::GtkPackIntoColumn(GtkTreeViewColumn *column) |
c9c13e70 | 2853 | { |
205bdf20 VZ |
2854 | // add the icon renderer first |
2855 | gtk_tree_view_column_pack_start(column, m_rendererIcon, FALSE /* !expand */); | |
c9c13e70 | 2856 | |
205bdf20 VZ |
2857 | // add the text renderer too |
2858 | wxDataViewRenderer::GtkPackIntoColumn(column); | |
c9c13e70 | 2859 | } |
b9db5f30 | 2860 | |
205bdf20 | 2861 | bool wxDataViewIconTextRenderer::SetValue( const wxVariant &value ) |
c9c13e70 | 2862 | { |
205bdf20 | 2863 | m_value << value; |
b9db5f30 | 2864 | |
205bdf20 | 2865 | SetTextValue(m_value.GetText()); |
530a50ec VZ |
2866 | |
2867 | const wxIcon& icon = m_value.GetIcon(); | |
2868 | SetPixbufProp(m_rendererIcon, icon.IsOk() ? icon.GetPixbuf() : NULL); | |
c9c13e70 RR |
2869 | |
2870 | return true; | |
2871 | } | |
2872 | ||
205bdf20 | 2873 | bool wxDataViewIconTextRenderer::GetValue(wxVariant& value) const |
c9c13e70 | 2874 | { |
205bdf20 VZ |
2875 | wxString str; |
2876 | if ( !GetTextValue(str) ) | |
2877 | return false; | |
c9c13e70 | 2878 | |
205bdf20 VZ |
2879 | // user doesn't have any way to edit the icon so leave it unchanged |
2880 | value << wxDataViewIconText(str, m_value.GetIcon()); | |
2881 | ||
2882 | return true; | |
c9c13e70 RR |
2883 | } |
2884 | ||
205bdf20 VZ |
2885 | void |
2886 | wxDataViewIconTextRenderer::GtkOnCellChanged(const wxVariant& value, | |
2887 | const wxDataViewItem& item, | |
2888 | unsigned col) | |
c9c13e70 | 2889 | { |
205bdf20 VZ |
2890 | // we receive just the text part of our value as it's the only one which |
2891 | // can be edited, but we need the full wxDataViewIconText value for the | |
2892 | // model | |
2893 | wxVariant valueIconText; | |
2894 | valueIconText << wxDataViewIconText(value.GetString(), m_value.GetIcon()); | |
2895 | wxDataViewTextRenderer::GtkOnCellChanged(valueIconText, item, col); | |
c9c13e70 RR |
2896 | } |
2897 | ||
93763ad5 | 2898 | // --------------------------------------------------------- |
605c2c4a | 2899 | // wxDataViewColumn |
93763ad5 | 2900 | // --------------------------------------------------------- |
7b4fde82 | 2901 | |
31fb32e1 RR |
2902 | |
2903 | static gboolean | |
ad386793 | 2904 | gtk_dataview_header_button_press_callback( GtkWidget *WXUNUSED(widget), |
31fb32e1 RR |
2905 | GdkEventButton *gdk_event, |
2906 | wxDataViewColumn *column ) | |
2907 | { | |
2908 | if (gdk_event->type != GDK_BUTTON_PRESS) | |
94b1f7bc | 2909 | return FALSE; |
f4322df6 | 2910 | |
31fb32e1 RR |
2911 | if (gdk_event->button == 1) |
2912 | { | |
d32332aa | 2913 | gs_lastLeftClickHeader = column; |
7857346a | 2914 | |
31fb32e1 RR |
2915 | wxDataViewCtrl *dv = column->GetOwner(); |
2916 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, dv->GetId() ); | |
2917 | event.SetDataViewColumn( column ); | |
2918 | event.SetModel( dv->GetModel() ); | |
937013e0 | 2919 | if (dv->HandleWindowEvent( event )) |
a84c5b6f | 2920 | return FALSE; |
31fb32e1 | 2921 | } |
f4322df6 | 2922 | |
dadc879e RR |
2923 | if (gdk_event->button == 3) |
2924 | { | |
2925 | wxDataViewCtrl *dv = column->GetOwner(); | |
2926 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, dv->GetId() ); | |
2927 | event.SetDataViewColumn( column ); | |
2928 | event.SetModel( dv->GetModel() ); | |
937013e0 | 2929 | if (dv->HandleWindowEvent( event )) |
dadc879e RR |
2930 | return FALSE; |
2931 | } | |
2932 | ||
94b1f7bc | 2933 | return FALSE; |
31fb32e1 RR |
2934 | } |
2935 | ||
47583ac1 VZ |
2936 | extern "C" |
2937 | { | |
7b4fde82 | 2938 | |
ad386793 | 2939 | static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *WXUNUSED(column), |
7b4fde82 RR |
2940 | GtkCellRenderer *renderer, |
2941 | GtkTreeModel *model, | |
2942 | GtkTreeIter *iter, | |
2943 | gpointer data ) | |
2944 | { | |
e0062c04 RR |
2945 | g_return_if_fail (GTK_IS_WX_TREE_MODEL (model)); |
2946 | GtkWxTreeModel *tree_model = (GtkWxTreeModel *) model; | |
93763ad5 | 2947 | |
baa9ebc4 | 2948 | wxDataViewRenderer *cell = (wxDataViewRenderer*) data; |
a7f61f76 | 2949 | |
9d52aad3 | 2950 | wxDataViewItem item( (void*) iter->user_data ); |
93763ad5 | 2951 | |
a826202e RR |
2952 | wxDataViewModel *wx_model = tree_model->internal->GetDataViewModel(); |
2953 | ||
e39de702 | 2954 | if (!wx_model->IsVirtualListModel()) |
2056dede | 2955 | { |
47583ac1 VZ |
2956 | gboolean visible; |
2957 | if (wx_model->IsContainer( item )) | |
a826202e | 2958 | { |
47583ac1 VZ |
2959 | visible = wx_model->HasContainerColumns( item ) || |
2960 | (cell->GetOwner()->GetModelColumn() == 0); | |
a826202e RR |
2961 | } |
2962 | else | |
2963 | { | |
47583ac1 | 2964 | visible = true; |
a826202e | 2965 | } |
47583ac1 | 2966 | |
a826202e RR |
2967 | GValue gvalue = { 0, }; |
2968 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
47583ac1 | 2969 | g_value_set_boolean( &gvalue, visible ); |
a826202e RR |
2970 | g_object_set_property( G_OBJECT(renderer), "visible", &gvalue ); |
2971 | g_value_unset( &gvalue ); | |
b9db5f30 | 2972 | |
47583ac1 VZ |
2973 | if ( !visible ) |
2974 | return; | |
2056dede | 2975 | } |
a826202e | 2976 | |
3f3af7e7 | 2977 | wxVariant value; |
a826202e | 2978 | wx_model->GetValue( value, item, cell->GetOwner()->GetModelColumn() ); |
7b4fde82 RR |
2979 | |
2980 | if (value.GetType() != cell->GetVariantType()) | |
af588446 | 2981 | { |
f4322df6 VZ |
2982 | wxLogError( wxT("Wrong type, required: %s but: %s"), |
2983 | value.GetType().c_str(), | |
cbc9145c | 2984 | cell->GetVariantType().c_str() ); |
af588446 | 2985 | } |
93763ad5 | 2986 | |
7b4fde82 | 2987 | cell->SetValue( value ); |
e0743e63 | 2988 | |
9c09addd RR |
2989 | // deal with disabled items |
2990 | bool enabled = wx_model->IsEnabled( item, cell->GetOwner()->GetModelColumn() ); | |
2991 | ||
2992 | // a) this sets the appearance to disabled grey | |
2993 | GValue gvalue = { 0, }; | |
2994 | g_value_init( &gvalue, G_TYPE_BOOLEAN ); | |
2995 | g_value_set_boolean( &gvalue, enabled ); | |
2996 | g_object_set_property( G_OBJECT(renderer), "sensitive", &gvalue ); | |
2997 | g_value_unset( &gvalue ); | |
2998 | ||
2999 | // b) this actually disables the control/renderer | |
3000 | if (enabled) | |
3001 | cell->SetMode( cell->GtkGetMode() ); | |
3002 | else | |
3003 | cell->SetMode( wxDATAVIEW_CELL_INERT ); | |
3004 | ||
b74399b9 | 3005 | |
c80cde00 VZ |
3006 | // deal with attributes: if the renderer doesn't support them at all, we |
3007 | // don't even need to query the model for them | |
c2a738e3 VZ |
3008 | if ( !cell->GtkSupportsAttrs() ) |
3009 | return; | |
3010 | ||
c80cde00 | 3011 | // it can support attributes so check if this item has any |
2d0d7813 | 3012 | wxDataViewItemAttr attr; |
c80cde00 VZ |
3013 | if ( wx_model->GetAttr( item, cell->GetOwner()->GetModelColumn(), attr ) |
3014 | || !cell->GtkIsUsingDefaultAttrs() ) | |
b74399b9 | 3015 | { |
c80cde00 VZ |
3016 | bool usingDefaultAttrs = !cell->GtkSetAttr(attr); |
3017 | cell->GtkSetUsingDefaultAttrs(usingDefaultAttrs); | |
b74399b9 | 3018 | } |
c80cde00 VZ |
3019 | // else: no custom attributes specified and we're already using the default |
3020 | // ones -- nothing to do | |
9fc221aa | 3021 | |
7b4fde82 RR |
3022 | } |
3023 | ||
47583ac1 VZ |
3024 | } // extern "C" |
3025 | ||
91a6c655 | 3026 | #include <wx/listimpl.cpp> |
a76c2f37 | 3027 | WX_DEFINE_LIST(wxDataViewColumnList) |
91a6c655 | 3028 | |
f4322df6 VZ |
3029 | wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewRenderer *cell, |
3030 | unsigned int model_column, int width, | |
835d0d55 VZ |
3031 | wxAlignment align, int flags ) |
3032 | : wxDataViewColumnBase( cell, model_column ) | |
fa28826d | 3033 | { |
9861f022 | 3034 | Init( align, flags, width ); |
31fb32e1 | 3035 | |
31fb32e1 | 3036 | SetTitle( title ); |
fa28826d RR |
3037 | } |
3038 | ||
f4322df6 VZ |
3039 | wxDataViewColumn::wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *cell, |
3040 | unsigned int model_column, int width, | |
835d0d55 VZ |
3041 | wxAlignment align, int flags ) |
3042 | : wxDataViewColumnBase( bitmap, cell, model_column ) | |
9861f022 RR |
3043 | { |
3044 | Init( align, flags, width ); | |
3045 | ||
3046 | SetBitmap( bitmap ); | |
3047 | } | |
3048 | ||
3049 | void wxDataViewColumn::Init(wxAlignment align, int flags, int width) | |
07a84e7b | 3050 | { |
31fb32e1 | 3051 | m_isConnected = false; |
07a84e7b RR |
3052 | |
3053 | GtkTreeViewColumn *column = gtk_tree_view_column_new(); | |
9861f022 | 3054 | m_column = (GtkWidget*) column; |
07a84e7b | 3055 | |
9861f022 RR |
3056 | SetFlags( flags ); |
3057 | SetAlignment( align ); | |
07a84e7b | 3058 | |
ad386793 | 3059 | SetWidth( width ); |
07a84e7b | 3060 | |
419a3607 RR |
3061 | // Create container for icon and label |
3062 | GtkWidget *box = gtk_hbox_new( FALSE, 1 ); | |
3063 | gtk_widget_show( box ); | |
3064 | // gtk_container_set_border_width((GtkContainer*)box, 2); | |
3065 | m_image = gtk_image_new(); | |
3066 | gtk_box_pack_start(GTK_BOX(box), m_image, FALSE, FALSE, 1); | |
3067 | m_label = gtk_label_new(""); | |
3068 | gtk_box_pack_end( GTK_BOX(box), GTK_WIDGET(m_label), FALSE, FALSE, 1 ); | |
3069 | gtk_tree_view_column_set_widget( column, box ); | |
bc0289bf | 3070 | |
205bdf20 VZ |
3071 | wxDataViewRenderer * const colRenderer = GetRenderer(); |
3072 | GtkCellRenderer * const cellRenderer = colRenderer->GetGtkHandle(); | |
3073 | ||
3074 | colRenderer->GtkPackIntoColumn(column); | |
07a84e7b | 3075 | |
205bdf20 VZ |
3076 | gtk_tree_view_column_set_cell_data_func( column, cellRenderer, |
3077 | wxGtkTreeCellDataFunc, (gpointer) colRenderer, NULL ); | |
07a84e7b RR |
3078 | } |
3079 | ||
31fb32e1 RR |
3080 | void wxDataViewColumn::OnInternalIdle() |
3081 | { | |
3082 | if (m_isConnected) | |
3083 | return; | |
ce00f59b | 3084 | |
fc9ab22a | 3085 | if (gtk_widget_get_realized(GetOwner()->m_treeview)) |
31fb32e1 | 3086 | { |
9861f022 | 3087 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
9dc44eff PC |
3088 | GtkWidget* button = gtk_tree_view_column_get_button(column); |
3089 | if (button) | |
31fb32e1 | 3090 | { |
9dc44eff | 3091 | g_signal_connect(button, "button_press_event", |
31fb32e1 | 3092 | G_CALLBACK (gtk_dataview_header_button_press_callback), this); |
f4322df6 | 3093 | |
5d9e1605 | 3094 | // otherwise the event will be blocked by GTK+ |
ce00f59b VZ |
3095 | gtk_tree_view_column_set_clickable( column, TRUE ); |
3096 | ||
31fb32e1 RR |
3097 | m_isConnected = true; |
3098 | } | |
3099 | } | |
3100 | } | |
3101 | ||
b94db696 RR |
3102 | void wxDataViewColumn::SetOwner( wxDataViewCtrl *owner ) |
3103 | { | |
3104 | wxDataViewColumnBase::SetOwner( owner ); | |
f4322df6 | 3105 | |
9861f022 | 3106 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
f4322df6 | 3107 | |
b94db696 | 3108 | gtk_tree_view_column_set_title( column, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) ); |
b94db696 RR |
3109 | } |
3110 | ||
fa28826d RR |
3111 | void wxDataViewColumn::SetTitle( const wxString &title ) |
3112 | { | |
09dfa6a0 | 3113 | wxDataViewCtrl *ctrl = GetOwner(); |
419a3607 | 3114 | gtk_label_set_text( GTK_LABEL(m_label), ctrl ? wxGTK_CONV_FONT(title, ctrl->GetFont()) |
09dfa6a0 | 3115 | : wxGTK_CONV_SYS(title) ); |
419a3607 RR |
3116 | if (title.empty()) |
3117 | gtk_widget_hide( m_label ); | |
3118 | else | |
3119 | gtk_widget_show( m_label ); | |
07a84e7b RR |
3120 | } |
3121 | ||
9861f022 RR |
3122 | wxString wxDataViewColumn::GetTitle() const |
3123 | { | |
7f6cbcea VZ |
3124 | return wxGTK_CONV_BACK_FONT( |
3125 | gtk_label_get_text( GTK_LABEL(m_label) ), | |
3126 | GetOwner()->GetFont() | |
3127 | ); | |
9861f022 RR |
3128 | } |
3129 | ||
07a84e7b RR |
3130 | void wxDataViewColumn::SetBitmap( const wxBitmap &bitmap ) |
3131 | { | |
3132 | wxDataViewColumnBase::SetBitmap( bitmap ); | |
3133 | ||
a1b806b9 | 3134 | if (bitmap.IsOk()) |
07a84e7b | 3135 | { |
419a3607 | 3136 | GtkImage *gtk_image = GTK_IMAGE(m_image); |
f4322df6 | 3137 | |
9dc44eff | 3138 | gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image), bitmap.GetPixbuf()); |
419a3607 | 3139 | gtk_widget_show( m_image ); |
07a84e7b RR |
3140 | } |
3141 | else | |
3142 | { | |
419a3607 | 3143 | gtk_widget_hide( m_image ); |
07a84e7b | 3144 | } |
fa28826d RR |
3145 | } |
3146 | ||
9861f022 RR |
3147 | void wxDataViewColumn::SetHidden( bool hidden ) |
3148 | { | |
3149 | gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column), !hidden ); | |
3150 | } | |
3151 | ||
d13b34d3 | 3152 | void wxDataViewColumn::SetResizeable( bool resizable ) |
9861f022 | 3153 | { |
d13b34d3 | 3154 | gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column), resizable ); |
9861f022 RR |
3155 | } |
3156 | ||
47cef10f RR |
3157 | void wxDataViewColumn::SetAlignment( wxAlignment align ) |
3158 | { | |
9861f022 | 3159 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
f4322df6 | 3160 | |
47cef10f RR |
3161 | gfloat xalign = 0.0; |
3162 | if (align == wxALIGN_RIGHT) | |
3163 | xalign = 1.0; | |
9861f022 RR |
3164 | if (align == wxALIGN_CENTER_HORIZONTAL || |
3165 | align == wxALIGN_CENTER) | |
47cef10f | 3166 | xalign = 0.5; |
f4322df6 | 3167 | |
9861f022 | 3168 | gtk_tree_view_column_set_alignment( column, xalign ); |
bc0289bf | 3169 | |
f2b7492a RR |
3170 | if (m_renderer && m_renderer->GetAlignment() == -1) |
3171 | m_renderer->GtkUpdateAlignment(); | |
9861f022 RR |
3172 | } |
3173 | ||
3174 | wxAlignment wxDataViewColumn::GetAlignment() const | |
3175 | { | |
3176 | gfloat xalign = gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column) ); | |
3177 | ||
3178 | if (xalign == 1.0) | |
3179 | return wxALIGN_RIGHT; | |
3180 | if (xalign == 0.5) | |
3181 | return wxALIGN_CENTER_HORIZONTAL; | |
f4322df6 | 3182 | |
9861f022 | 3183 | return wxALIGN_LEFT; |
47cef10f RR |
3184 | } |
3185 | ||
31fb32e1 RR |
3186 | void wxDataViewColumn::SetSortable( bool sortable ) |
3187 | { | |
9861f022 | 3188 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
b9db5f30 | 3189 | |
140a119a VZ |
3190 | if ( sortable ) |
3191 | { | |
3192 | gtk_tree_view_column_set_sort_column_id( column, GetModelColumn() ); | |
3193 | } | |
3194 | else | |
3195 | { | |
3196 | gtk_tree_view_column_set_sort_column_id( column, -1 ); | |
3197 | gtk_tree_view_column_set_sort_indicator( column, FALSE ); | |
3198 | gtk_tree_view_column_set_clickable( column, FALSE ); | |
3199 | } | |
e2bfe673 VZ |
3200 | } |
3201 | ||
3202 | bool wxDataViewColumn::IsSortable() const | |
3203 | { | |
3204 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); | |
d5027818 | 3205 | return gtk_tree_view_column_get_clickable( column ) != 0; |
e2bfe673 VZ |
3206 | } |
3207 | ||
e2bfe673 | 3208 | bool wxDataViewColumn::IsSortKey() const |
31fb32e1 | 3209 | { |
9861f022 | 3210 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
d5027818 | 3211 | return gtk_tree_view_column_get_sort_indicator( column ) != 0; |
31fb32e1 RR |
3212 | } |
3213 | ||
9861f022 RR |
3214 | bool wxDataViewColumn::IsResizeable() const |
3215 | { | |
3216 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); | |
d5027818 | 3217 | return gtk_tree_view_column_get_resizable( column ) != 0; |
9861f022 RR |
3218 | } |
3219 | ||
3220 | bool wxDataViewColumn::IsHidden() const | |
3221 | { | |
3222 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); | |
3223 | return !gtk_tree_view_column_get_visible( column ); | |
3224 | } | |
3225 | ||
47cef10f RR |
3226 | void wxDataViewColumn::SetSortOrder( bool ascending ) |
3227 | { | |
9861f022 | 3228 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
f4322df6 | 3229 | |
47cef10f RR |
3230 | if (ascending) |
3231 | gtk_tree_view_column_set_sort_order( column, GTK_SORT_ASCENDING ); | |
3232 | else | |
3233 | gtk_tree_view_column_set_sort_order( column, GTK_SORT_DESCENDING ); | |
0bd26819 RR |
3234 | |
3235 | gtk_tree_view_column_set_sort_indicator( column, TRUE ); | |
47cef10f RR |
3236 | } |
3237 | ||
87f0efe2 | 3238 | bool wxDataViewColumn::IsSortOrderAscending() const |
31fb32e1 | 3239 | { |
9861f022 | 3240 | GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); |
f4322df6 | 3241 | |
31fb32e1 RR |
3242 | return (gtk_tree_view_column_get_sort_order( column ) != GTK_SORT_DESCENDING); |
3243 | } | |
3244 | ||
9861f022 | 3245 | void wxDataViewColumn::SetMinWidth( int width ) |
533544f2 | 3246 | { |
9861f022 | 3247 | gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column), width ); |
533544f2 RR |
3248 | } |
3249 | ||
9861f022 RR |
3250 | int wxDataViewColumn::GetMinWidth() const |
3251 | { | |
3252 | return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column) ); | |
3253 | } | |
3254 | ||
3255 | int wxDataViewColumn::GetWidth() const | |
533544f2 | 3256 | { |
9861f022 | 3257 | return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column) ); |
533544f2 RR |
3258 | } |
3259 | ||
9861f022 | 3260 | void wxDataViewColumn::SetWidth( int width ) |
533544f2 | 3261 | { |
d0154e3a | 3262 | if ( width == wxCOL_WIDTH_AUTOSIZE ) |
ad386793 | 3263 | { |
d0154e3a | 3264 | // NB: this disables user resizing |
ad386793 RR |
3265 | gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column), GTK_TREE_VIEW_COLUMN_AUTOSIZE ); |
3266 | } | |
3267 | else | |
3268 | { | |
d0154e3a VS |
3269 | if ( width == wxCOL_WIDTH_DEFAULT ) |
3270 | { | |
3271 | // TODO find a better calculation | |
3272 | width = wxDVC_DEFAULT_WIDTH; | |
3273 | } | |
7857346a | 3274 | |
d0154e3a | 3275 | gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column), GTK_TREE_VIEW_COLUMN_FIXED ); |
ad386793 RR |
3276 | gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column), width ); |
3277 | } | |
533544f2 RR |
3278 | } |
3279 | ||
99c75ebc RR |
3280 | void wxDataViewColumn::SetReorderable( bool reorderable ) |
3281 | { | |
3282 | gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column), reorderable ); | |
3283 | } | |
3284 | ||
3285 | bool wxDataViewColumn::IsReorderable() const | |
3286 | { | |
d5027818 | 3287 | return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column) ) != 0; |
99c75ebc | 3288 | } |
9861f022 | 3289 | |
4508fcd2 RR |
3290 | //----------------------------------------------------------------------------- |
3291 | // wxGtkTreeModelNode | |
3292 | //----------------------------------------------------------------------------- | |
3293 | ||
5b276ac1 | 3294 | #if 0 |
1f226ad8 RR |
3295 | class wxGtkTreeModelChildWithPos |
3296 | { | |
3297 | public: | |
3298 | unsigned int pos; | |
3299 | void *id; | |
3300 | }; | |
3301 | ||
3302 | static | |
3303 | int wxGtkTreeModelChildWithPosCmp( const void* data1, const void* data2, const void* user_data ) | |
3304 | { | |
3305 | const wxGtkTreeModelChildWithPos* child1 = (const wxGtkTreeModelChildWithPos*) data1; | |
3306 | const wxGtkTreeModelChildWithPos* child2 = (const wxGtkTreeModelChildWithPos*) data2; | |
3307 | const wxDataViewCtrlInternal *internal = (const wxDataViewCtrlInternal *) user_data; | |
3308 | int ret = internal->GetDataViewModel()->Compare( child1->id, child2->id, | |
5b276ac1 | 3309 | internal->GetSortColumn(), (internal->GetSortOrder() == GTK_SORT_DESCENDING) ); |
1f226ad8 RR |
3310 | |
3311 | return ret; | |
3312 | } | |
5b276ac1 RR |
3313 | #else |
3314 | static | |
3315 | int LINKAGEMODE wxGtkTreeModelChildPtrCmp( void*** data1, void*** data2 ) | |
3316 | { | |
d5c4a81f | 3317 | return gs_internal->GetDataViewModel()->Compare( wxDataViewItem(**data1), wxDataViewItem(**data2), |
5b276ac1 RR |
3318 | gs_internal->GetSortColumn(), (gs_internal->GetSortOrder() == GTK_SORT_ASCENDING) ); |
3319 | } | |
3320 | ||
3321 | WX_DEFINE_ARRAY_PTR( void**, wxGtkTreeModelChildrenPtr ); | |
3322 | #endif | |
1f226ad8 | 3323 | |
4508fcd2 RR |
3324 | void wxGtkTreeModelNode::Resort() |
3325 | { | |
af110130 RR |
3326 | size_t child_count = GetChildCount(); |
3327 | if (child_count == 0) | |
0be79c8a RR |
3328 | return; |
3329 | ||
af110130 RR |
3330 | size_t node_count = GetNodesCount(); |
3331 | ||
3332 | if (child_count == 1) | |
0be79c8a | 3333 | { |
af110130 RR |
3334 | if (node_count == 1) |
3335 | { | |
3336 | wxGtkTreeModelNode *node = m_nodes.Item( 0 ); | |
3337 | node->Resort(); | |
3338 | } | |
0be79c8a RR |
3339 | return; |
3340 | } | |
3341 | ||
5b276ac1 RR |
3342 | gint *new_order = new gint[child_count]; |
3343 | ||
1f226ad8 | 3344 | #if 1 |
5b276ac1 RR |
3345 | // m_children has the original *void |
3346 | // ptrs points to these | |
3347 | wxGtkTreeModelChildrenPtr ptrs; | |
3348 | size_t i; | |
3349 | for (i = 0; i < child_count; i++) | |
3350 | ptrs.Add( &(m_children[i]) ); | |
3351 | // Sort the ptrs | |
3352 | gs_internal = m_internal; | |
3353 | ptrs.Sort( &wxGtkTreeModelChildPtrCmp ); | |
03647350 | 3354 | |
5b276ac1 RR |
3355 | wxGtkTreeModelChildren temp; |
3356 | void** base_ptr = &(m_children[0]); | |
03647350 | 3357 | // Transfer positions to new_order array and |
5b276ac1 RR |
3358 | // IDs to temp |
3359 | for (i = 0; i < child_count; i++) | |
3360 | { | |
3361 | new_order[i] = ptrs[i] - base_ptr; | |
3362 | temp.Add( *ptrs[i] ); | |
3363 | } | |
3364 | ||
3365 | // Transfer IDs back to m_children | |
3366 | m_children.Clear(); | |
3367 | WX_APPEND_ARRAY( temp, m_children ); | |
3368 | #endif | |
3369 | #if 0 | |
3370 | // Too slow | |
3371 | ||
1f226ad8 RR |
3372 | // Build up array with IDs and original positions |
3373 | wxGtkTreeModelChildWithPos* temp = new wxGtkTreeModelChildWithPos[child_count]; | |
3374 | size_t i; | |
3375 | for (i = 0; i < child_count; i++) | |
3376 | { | |
3377 | temp[i].pos = i; | |
3378 | temp[i].id = m_children[i]; | |
3379 | } | |
3380 | // Sort array keeping original positions | |
3381 | wxQsort( temp, child_count, sizeof(wxGtkTreeModelChildWithPos), | |
3382 | &wxGtkTreeModelChildWithPosCmp, m_internal ); | |
e4a8d29c RR |
3383 | // Transfer positions to new_order array and |
3384 | // IDs to m_children | |
3385 | m_children.Clear(); | |
1f226ad8 | 3386 | for (i = 0; i < child_count; i++) |
e4a8d29c | 3387 | { |
1f226ad8 | 3388 | new_order[i] = temp[i].pos; |
1f226ad8 | 3389 | m_children.Add( temp[i].id ); |
e4a8d29c | 3390 | } |
1f226ad8 RR |
3391 | // Delete array |
3392 | delete [] temp; | |
5b276ac1 RR |
3393 | #endif |
3394 | ||
3395 | #if 0 | |
3396 | // Too slow | |
03647350 | 3397 | |
40196b1e RR |
3398 | wxGtkTreeModelChildren temp; |
3399 | WX_APPEND_ARRAY( temp, m_children ); | |
b9db5f30 | 3400 | |
8c2654ce | 3401 | gs_internal = m_internal; |
40196b1e | 3402 | m_children.Sort( &wxGtkTreeModelChildCmp ); |
03647350 | 3403 | |
40196b1e | 3404 | unsigned int pos; |
af110130 | 3405 | for (pos = 0; pos < child_count; pos++) |
4508fcd2 | 3406 | { |
40196b1e RR |
3407 | void *id = m_children.Item( pos ); |
3408 | int old_pos = temp.Index( id ); | |
3409 | new_order[pos] = old_pos; | |
4508fcd2 | 3410 | } |
1f226ad8 | 3411 | #endif |
b9db5f30 | 3412 | |
0be79c8a RR |
3413 | GtkTreeModel *gtk_tree_model = GTK_TREE_MODEL( m_internal->GetGtkModel() ); |
3414 | ||
3415 | GtkTreeIter iter; | |
40196b1e | 3416 | iter.user_data = GetItem().GetID(); |
0be79c8a | 3417 | iter.stamp = m_internal->GetGtkModel()->stamp; |
b9db5f30 | 3418 | |
0c2a7270 VZ |
3419 | gtk_tree_model_rows_reordered( gtk_tree_model, |
3420 | wxGtkTreePath(m_internal->get_path(&iter)), &iter, new_order ); | |
b9db5f30 | 3421 | |
0be79c8a | 3422 | delete [] new_order; |
03647350 | 3423 | |
1f226ad8 | 3424 | unsigned int pos; |
af110130 | 3425 | for (pos = 0; pos < node_count; pos++) |
4508fcd2 | 3426 | { |
af110130 | 3427 | wxGtkTreeModelNode *node = m_nodes.Item( pos ); |
4508fcd2 RR |
3428 | node->Resort(); |
3429 | } | |
3430 | } | |
3431 | ||
55fbde12 RR |
3432 | //----------------------------------------------------------------------------- |
3433 | // wxDataViewCtrlInternal | |
3434 | //----------------------------------------------------------------------------- | |
3435 | ||
673810ee | 3436 | wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl *owner, wxDataViewModel *wx_model ) |
b9db5f30 | 3437 | { |
55fbde12 | 3438 | m_owner = owner; |
b9db5f30 | 3439 | m_wx_model = wx_model; |
ce00f59b | 3440 | |
673810ee | 3441 | m_gtk_model = NULL; |
b9db5f30 | 3442 | m_root = NULL; |
b8b7b087 | 3443 | m_sort_order = GTK_SORT_ASCENDING; |
40196b1e | 3444 | m_sort_column = -1; |
d32332aa | 3445 | m_dataview_sort_column = NULL; |
8c2654ce | 3446 | |
591cc82d RR |
3447 | m_dragDataObject = NULL; |
3448 | m_dropDataObject = NULL; | |
b9db5f30 | 3449 | |
d8090b5e | 3450 | m_dirty = false; |
ce00f59b | 3451 | |
673810ee RR |
3452 | m_gtk_model = wxgtk_tree_model_new(); |
3453 | m_gtk_model->internal = this; | |
3454 | ||
3455 | m_notifier = new wxGtkDataViewModelNotifier( wx_model, this ); | |
3456 | ||
3457 | wx_model->AddNotifier( m_notifier ); | |
3458 | ||
3459 | // g_object_unref( gtk_model ); ??? | |
3460 | ||
e39de702 | 3461 | if (!m_wx_model->IsVirtualListModel()) |
2056dede | 3462 | InitTree(); |
ce00f59b | 3463 | |
673810ee | 3464 | gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner->GtkGetTreeView()), GTK_TREE_MODEL(m_gtk_model) ); |
55fbde12 | 3465 | } |
b9db5f30 | 3466 | |
55fbde12 RR |
3467 | wxDataViewCtrlInternal::~wxDataViewCtrlInternal() |
3468 | { | |
673810ee RR |
3469 | m_wx_model->RemoveNotifier( m_notifier ); |
3470 | ||
ce00f59b | 3471 | // remove the model from the GtkTreeView before it gets destroyed |
673810ee RR |
3472 | gtk_tree_view_set_model( GTK_TREE_VIEW( m_owner->GtkGetTreeView() ), NULL ); |
3473 | ||
55fbde12 | 3474 | g_object_unref( m_gtk_model ); |
8c2654ce | 3475 | |
591cc82d RR |
3476 | delete m_dragDataObject; |
3477 | delete m_dropDataObject; | |
55fbde12 | 3478 | } |
b9db5f30 | 3479 | |
d8090b5e RR |
3480 | void wxDataViewCtrlInternal::ScheduleRefresh() |
3481 | { | |
3482 | m_dirty = true; | |
3483 | } | |
3484 | ||
3485 | void wxDataViewCtrlInternal::OnInternalIdle() | |
3486 | { | |
3487 | if (m_dirty) | |
3488 | { | |
3489 | GtkWidget *widget = m_owner->GtkGetTreeView(); | |
3490 | gtk_widget_queue_draw( widget ); | |
3491 | m_dirty = false; | |
3492 | } | |
3493 | } | |
3494 | ||
ef427989 RR |
3495 | void wxDataViewCtrlInternal::InitTree() |
3496 | { | |
3497 | wxDataViewItem item; | |
0be79c8a | 3498 | m_root = new wxGtkTreeModelNode( NULL, item, this ); |
ef427989 RR |
3499 | |
3500 | BuildBranch( m_root ); | |
3501 | } | |
3502 | ||
55fbde12 RR |
3503 | void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode *node ) |
3504 | { | |
3505 | if (node->GetChildCount() == 0) | |
3506 | { | |
74fe973b RR |
3507 | wxDataViewItemArray children; |
3508 | unsigned int count = m_wx_model->GetChildren( node->GetItem(), children ); | |
ce00f59b | 3509 | |
74fe973b RR |
3510 | unsigned int pos; |
3511 | for (pos = 0; pos < count; pos++) | |
55fbde12 | 3512 | { |
74fe973b | 3513 | wxDataViewItem child = children[pos]; |
b9db5f30 | 3514 | |
af110130 RR |
3515 | if (m_wx_model->IsContainer( child )) |
3516 | node->AddNode( new wxGtkTreeModelNode( node, child, this ) ); | |
3517 | else | |
35219832 | 3518 | node->AddLeaf( child.GetID() ); |
b9db5f30 | 3519 | |
effd54b0 | 3520 | // Don't send any events here |
55fbde12 RR |
3521 | } |
3522 | } | |
3523 | } | |
3524 | ||
f6f0ef85 RR |
3525 | // GTK+ dnd iface |
3526 | ||
15cac64f RR |
3527 | bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat &format ) |
3528 | { | |
3529 | wxGtkString atom_str( gdk_atom_name( format ) ); | |
3530 | m_dragSourceTargetEntryTarget = wxCharBuffer( atom_str ); | |
8c2654ce | 3531 | |
15cac64f RR |
3532 | m_dragSourceTargetEntry.target = m_dragSourceTargetEntryTarget.data(); |
3533 | m_dragSourceTargetEntry.flags = 0; | |
3534 | m_dragSourceTargetEntry.info = static_cast<guint>(-1); | |
8c2654ce | 3535 | |
15cac64f RR |
3536 | gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner->GtkGetTreeView() ), |
3537 | GDK_BUTTON1_MASK, &m_dragSourceTargetEntry, 1, (GdkDragAction) GDK_ACTION_COPY ); | |
8c2654ce | 3538 | |
15cac64f RR |
3539 | return true; |
3540 | } | |
3541 | ||
e4de825e RR |
3542 | bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat &format ) |
3543 | { | |
3544 | wxGtkString atom_str( gdk_atom_name( format ) ); | |
3545 | m_dropTargetTargetEntryTarget = wxCharBuffer( atom_str ); | |
8c2654ce | 3546 | |
b4c40918 | 3547 | m_dropTargetTargetEntry.target = m_dropTargetTargetEntryTarget.data(); |
e4de825e RR |
3548 | m_dropTargetTargetEntry.flags = 0; |
3549 | m_dropTargetTargetEntry.info = static_cast<guint>(-1); | |
8c2654ce | 3550 | |
e4de825e RR |
3551 | gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner->GtkGetTreeView() ), |
3552 | &m_dropTargetTargetEntry, 1, (GdkDragAction) GDK_ACTION_COPY ); | |
8c2654ce | 3553 | |
e4de825e RR |
3554 | return true; |
3555 | } | |
3556 | ||
7857346a | 3557 | gboolean wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource *WXUNUSED(drag_source), |
f6f0ef85 RR |
3558 | GtkTreePath *path ) |
3559 | { | |
591cc82d | 3560 | delete m_dragDataObject; |
41936464 | 3561 | m_dragDataObject = NULL; |
8c2654ce | 3562 | |
17d98558 VZ |
3563 | wxDataViewItem item(GetOwner()->GTKPathToItem(path)); |
3564 | if ( !item ) | |
3565 | return FALSE; | |
f6f0ef85 | 3566 | |
591cc82d | 3567 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG, m_owner->GetId() ); |
e4de825e | 3568 | event.SetEventObject( m_owner ); |
15cac64f RR |
3569 | event.SetItem( item ); |
3570 | event.SetModel( m_wx_model ); | |
08a379c5 RR |
3571 | gint x, y; |
3572 | gtk_widget_get_pointer(m_owner->GtkGetTreeView(), &x, &y); | |
3573 | event.SetPosition(x, y); | |
591cc82d RR |
3574 | if (!m_owner->HandleWindowEvent( event )) |
3575 | return FALSE; | |
8c2654ce | 3576 | |
591cc82d RR |
3577 | if (!event.IsAllowed()) |
3578 | return FALSE; | |
8c2654ce | 3579 | |
591cc82d RR |
3580 | wxDataObject *obj = event.GetDataObject(); |
3581 | if (!obj) | |
3582 | return FALSE; | |
8c2654ce | 3583 | |
591cc82d | 3584 | m_dragDataObject = obj; |
8c2654ce | 3585 | |
591cc82d | 3586 | return TRUE; |
f6f0ef85 RR |
3587 | } |
3588 | ||
7857346a VZ |
3589 | gboolean |
3590 | wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource *WXUNUSED(drag_source), | |
3591 | GtkTreePath *WXUNUSED(path)) | |
f6f0ef85 RR |
3592 | { |
3593 | return FALSE; | |
3594 | } | |
3595 | ||
7857346a | 3596 | gboolean wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource *WXUNUSED(drag_source), |
f6f0ef85 RR |
3597 | GtkTreePath *path, GtkSelectionData *selection_data ) |
3598 | { | |
17d98558 VZ |
3599 | wxDataViewItem item(GetOwner()->GTKPathToItem(path)); |
3600 | if ( !item ) | |
3601 | return FALSE; | |
7857346a | 3602 | |
385e8575 PC |
3603 | GdkAtom target = gtk_selection_data_get_target(selection_data); |
3604 | if (!m_dragDataObject->IsSupported(target)) | |
591cc82d | 3605 | return FALSE; |
7857346a | 3606 | |
385e8575 | 3607 | size_t size = m_dragDataObject->GetDataSize(target); |
591cc82d RR |
3608 | if (size == 0) |
3609 | return FALSE; | |
8c2654ce | 3610 | |
591cc82d | 3611 | void *buf = malloc( size ); |
8c2654ce | 3612 | |
15cac64f | 3613 | gboolean res = FALSE; |
385e8575 | 3614 | if (m_dragDataObject->GetDataHere(target, buf)) |
15cac64f | 3615 | { |
15cac64f | 3616 | res = TRUE; |
8c2654ce | 3617 | |
385e8575 | 3618 | gtk_selection_data_set(selection_data, target, |
591cc82d | 3619 | 8, (const guchar*) buf, size ); |
15cac64f | 3620 | } |
f6f0ef85 | 3621 | |
591cc82d | 3622 | free( buf ); |
7857346a | 3623 | |
15cac64f | 3624 | return res; |
f6f0ef85 RR |
3625 | } |
3626 | ||
7857346a VZ |
3627 | gboolean |
3628 | wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest *WXUNUSED(drag_dest), | |
e4de825e RR |
3629 | GtkTreePath *path, |
3630 | GtkSelectionData *selection_data) | |
f6f0ef85 | 3631 | { |
17d98558 VZ |
3632 | wxDataViewItem item(GetOwner()->GTKPathToItem(path)); |
3633 | if ( !item ) | |
3634 | return FALSE; | |
8c2654ce | 3635 | |
e4de825e RR |
3636 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP, m_owner->GetId() ); |
3637 | event.SetEventObject( m_owner ); | |
3638 | event.SetItem( item ); | |
3639 | event.SetModel( m_wx_model ); | |
385e8575 PC |
3640 | event.SetDataFormat(gtk_selection_data_get_target(selection_data)); |
3641 | event.SetDataSize(gtk_selection_data_get_length(selection_data)); | |
3642 | event.SetDataBuffer(const_cast<guchar*>(gtk_selection_data_get_data(selection_data))); | |
e4de825e RR |
3643 | if (!m_owner->HandleWindowEvent( event )) |
3644 | return FALSE; | |
8c2654ce | 3645 | |
e4de825e RR |
3646 | if (!event.IsAllowed()) |
3647 | return FALSE; | |
3648 | ||
3649 | return TRUE; | |
f6f0ef85 RR |
3650 | } |
3651 | ||
7857346a VZ |
3652 | gboolean |
3653 | wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest *WXUNUSED(drag_dest), | |
e4de825e RR |
3654 | GtkTreePath *path, |
3655 | GtkSelectionData *selection_data) | |
f6f0ef85 | 3656 | { |
17d98558 VZ |
3657 | wxDataViewItem item(GetOwner()->GTKPathToItem(path)); |
3658 | if ( !item ) | |
3659 | return FALSE; | |
8c2654ce | 3660 | |
e4de825e RR |
3661 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE, m_owner->GetId() ); |
3662 | event.SetEventObject( m_owner ); | |
3663 | event.SetItem( item ); | |
3664 | event.SetModel( m_wx_model ); | |
385e8575 | 3665 | event.SetDataFormat(gtk_selection_data_get_target(selection_data)); |
167fc10e | 3666 | event.SetDataSize(gtk_selection_data_get_length(selection_data)); |
e4de825e RR |
3667 | if (!m_owner->HandleWindowEvent( event )) |
3668 | return FALSE; | |
8c2654ce | 3669 | |
e4de825e RR |
3670 | if (!event.IsAllowed()) |
3671 | return FALSE; | |
8c2654ce | 3672 | |
e4de825e | 3673 | return TRUE; |
f6f0ef85 RR |
3674 | } |
3675 | ||
3676 | // notifications from wxDataViewModel | |
3677 | ||
33ba5a05 RR |
3678 | bool wxDataViewCtrlInternal::Cleared() |
3679 | { | |
3680 | if (m_root) | |
3681 | { | |
3682 | delete m_root; | |
c225708f | 3683 | m_root = NULL; |
7857346a | 3684 | } |
ce00f59b | 3685 | |
c225708f | 3686 | InitTree(); |
ce00f59b | 3687 | |
d8090b5e | 3688 | ScheduleRefresh(); |
ce00f59b | 3689 | |
33ba5a05 RR |
3690 | return true; |
3691 | } | |
3692 | ||
4508fcd2 RR |
3693 | void wxDataViewCtrlInternal::Resort() |
3694 | { | |
e39de702 | 3695 | if (!m_wx_model->IsVirtualListModel()) |
2056dede | 3696 | m_root->Resort(); |
ce00f59b | 3697 | |
d8090b5e | 3698 | ScheduleRefresh(); |
4508fcd2 RR |
3699 | } |
3700 | ||
55fbde12 RR |
3701 | bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) |
3702 | { | |
e39de702 | 3703 | if (!m_wx_model->IsVirtualListModel()) |
2056dede RR |
3704 | { |
3705 | wxGtkTreeModelNode *parent_node = FindNode( parent ); | |
35219832 | 3706 | wxCHECK_MSG(parent_node, false, |
c2489d8e FM |
3707 | "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel"); |
3708 | ||
5bb82ad4 VS |
3709 | wxDataViewItemArray modelSiblings; |
3710 | m_wx_model->GetChildren(parent, modelSiblings); | |
3711 | const int modelSiblingsSize = modelSiblings.size(); | |
3712 | ||
3713 | int posInModel = modelSiblings.Index(item, /*fromEnd=*/true); | |
3714 | wxCHECK_MSG( posInModel != wxNOT_FOUND, false, "adding non-existent item?" ); | |
3715 | ||
3716 | const wxGtkTreeModelChildren& nodeSiblings = parent_node->GetChildren(); | |
3717 | const int nodeSiblingsSize = nodeSiblings.size(); | |
3718 | ||
3719 | int nodePos = 0; | |
3720 | ||
3721 | if ( posInModel == modelSiblingsSize - 1 ) | |
3722 | { | |
3723 | nodePos = nodeSiblingsSize; | |
3724 | } | |
3725 | else if ( modelSiblingsSize == nodeSiblingsSize + 1 ) | |
3726 | { | |
3727 | // This is the simple case when our node tree already matches the | |
3728 | // model and only this one item is missing. | |
3729 | nodePos = posInModel; | |
3730 | } | |
3731 | else | |
3732 | { | |
3733 | // It's possible that a larger discrepancy between the model and | |
3734 | // our realization exists. This can happen e.g. when adding a bunch | |
3735 | // of items to the model and then calling ItemsAdded() just once | |
3736 | // afterwards. In this case, we must find the right position by | |
3737 | // looking at sibling items. | |
3738 | ||
3739 | // append to the end if we won't find a better position: | |
3740 | nodePos = nodeSiblingsSize; | |
3741 | ||
3742 | for ( int nextItemPos = posInModel + 1; | |
3743 | nextItemPos < modelSiblingsSize; | |
3744 | nextItemPos++ ) | |
3745 | { | |
3746 | int nextNodePos = parent_node->FindChildByItem(modelSiblings[nextItemPos]); | |
3747 | if ( nextNodePos != wxNOT_FOUND ) | |
3748 | { | |
3749 | nodePos = nextNodePos; | |
3750 | break; | |
3751 | } | |
3752 | } | |
3753 | } | |
35219832 | 3754 | |
2056dede | 3755 | if (m_wx_model->IsContainer( item )) |
5bb82ad4 | 3756 | parent_node->InsertNode( new wxGtkTreeModelNode( parent_node, item, this ), nodePos ); |
2056dede | 3757 | else |
5bb82ad4 | 3758 | parent_node->InsertLeaf( item.GetID(), nodePos ); |
2056dede | 3759 | } |
b9db5f30 | 3760 | |
d8090b5e | 3761 | ScheduleRefresh(); |
ce00f59b | 3762 | |
55fbde12 RR |
3763 | return true; |
3764 | } | |
3765 | ||
469d3e9b | 3766 | bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ) |
55fbde12 | 3767 | { |
e39de702 | 3768 | if (!m_wx_model->IsVirtualListModel()) |
2056dede RR |
3769 | { |
3770 | wxGtkTreeModelNode *parent_node = FindNode( parent ); | |
c2489d8e FM |
3771 | wxASSERT_MSG(parent_node, |
3772 | "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel"); | |
3773 | ||
2056dede RR |
3774 | parent_node->DeleteChild( item.GetID() ); |
3775 | } | |
b9db5f30 | 3776 | |
d8090b5e | 3777 | ScheduleRefresh(); |
ce00f59b | 3778 | |
d8331a01 RR |
3779 | return true; |
3780 | } | |
3781 | ||
3782 | bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem &item ) | |
3783 | { | |
6608fdab | 3784 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, m_owner->GetId() ); |
d8331a01 RR |
3785 | event.SetEventObject( m_owner ); |
3786 | event.SetModel( m_owner->GetModel() ); | |
3787 | event.SetItem( item ); | |
937013e0 | 3788 | m_owner->HandleWindowEvent( event ); |
b9db5f30 | 3789 | |
d8331a01 RR |
3790 | return true; |
3791 | } | |
3792 | ||
d93cc830 | 3793 | bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem &item, unsigned int view_column ) |
d8331a01 | 3794 | { |
6608fdab | 3795 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, m_owner->GetId() ); |
d8331a01 RR |
3796 | event.SetEventObject( m_owner ); |
3797 | event.SetModel( m_owner->GetModel() ); | |
d93cc830 RR |
3798 | event.SetColumn( view_column ); |
3799 | event.SetDataViewColumn( GetOwner()->GetColumn(view_column) ); | |
d8331a01 | 3800 | event.SetItem( item ); |
937013e0 | 3801 | m_owner->HandleWindowEvent( event ); |
b9db5f30 | 3802 | |
d8331a01 RR |
3803 | return true; |
3804 | } | |
3805 | ||
f6f0ef85 RR |
3806 | // GTK+ model iface |
3807 | ||
2056dede RR |
3808 | GtkTreeModelFlags wxDataViewCtrlInternal::get_flags() |
3809 | { | |
ce5abbf9 VS |
3810 | int flags = 0; |
3811 | ||
3812 | if ( m_wx_model->IsListModel() ) | |
3813 | flags |= GTK_TREE_MODEL_LIST_ONLY; | |
3814 | ||
3815 | if ( !m_wx_model->IsVirtualListModel() ) | |
3816 | flags |= GTK_TREE_MODEL_ITERS_PERSIST; | |
3817 | ||
3818 | return GtkTreeModelFlags(flags); | |
2056dede RR |
3819 | } |
3820 | ||
55fbde12 RR |
3821 | gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path ) |
3822 | { | |
9330d5af | 3823 | |
e39de702 | 3824 | if (m_wx_model->IsVirtualListModel()) |
2056dede | 3825 | { |
9330d5af | 3826 | wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model; |
03647350 | 3827 | |
2056dede | 3828 | unsigned int i = (unsigned int)gtk_tree_path_get_indices (path)[0]; |
03647350 | 3829 | |
9330d5af | 3830 | if (i >= wx_model->GetCount()) |
2056dede | 3831 | return FALSE; |
55fbde12 | 3832 | |
2056dede | 3833 | iter->stamp = m_gtk_model->stamp; |
0ae51f62 | 3834 | // user_data is just the index +1 |
6549dd3c | 3835 | iter->user_data = wxUIntToPtr(i+1); |
55fbde12 | 3836 | |
2056dede RR |
3837 | return TRUE; |
3838 | } | |
3839 | else | |
55fbde12 | 3840 | { |
2056dede RR |
3841 | int depth = gtk_tree_path_get_depth( path ); |
3842 | ||
3843 | wxGtkTreeModelNode *node = m_root; | |
3844 | ||
3845 | int i; | |
b9db5f30 | 3846 | for (i = 0; i < depth; i++) |
2056dede RR |
3847 | { |
3848 | BuildBranch( node ); | |
b9db5f30 | 3849 | |
2056dede RR |
3850 | gint pos = gtk_tree_path_get_indices (path)[i]; |
3851 | if (pos < 0) return FALSE; | |
3852 | if ((size_t)pos >= node->GetChildCount()) return FALSE; | |
b9db5f30 | 3853 | |
2056dede | 3854 | void* id = node->GetChildren().Item( (size_t) pos ); |
b9db5f30 | 3855 | |
2056dede | 3856 | if (i == depth-1) |
af110130 | 3857 | { |
2056dede RR |
3858 | iter->stamp = m_gtk_model->stamp; |
3859 | iter->user_data = id; | |
3860 | return TRUE; | |
af110130 | 3861 | } |
2056dede RR |
3862 | |
3863 | size_t count = node->GetNodes().GetCount(); | |
3864 | size_t pos2; | |
3865 | for (pos2 = 0; pos2 < count; pos2++) | |
3866 | { | |
3867 | wxGtkTreeModelNode *child_node = node->GetNodes().Item( pos2 ); | |
3868 | if (child_node->GetItem().GetID() == id) | |
3869 | { | |
3870 | node = child_node; | |
3871 | break; | |
3872 | } | |
b9db5f30 | 3873 | } |
2056dede | 3874 | } |
af110130 | 3875 | } |
55fbde12 | 3876 | |
af110130 | 3877 | return FALSE; |
55fbde12 RR |
3878 | } |
3879 | ||
3880 | GtkTreePath *wxDataViewCtrlInternal::get_path( GtkTreeIter *iter ) | |
3881 | { | |
8650c4ba RR |
3882 | // When this is called from ItemDeleted(), the item is already |
3883 | // deleted in the model. | |
3884 | ||
55fbde12 | 3885 | GtkTreePath *retval = gtk_tree_path_new (); |
b9db5f30 | 3886 | |
e39de702 | 3887 | if (m_wx_model->IsVirtualListModel()) |
2056dede | 3888 | { |
559c42a5 RR |
3889 | // iter is root, add nothing |
3890 | if (!iter->user_data) | |
3891 | return retval; | |
74035a19 | 3892 | |
0ae51f62 RR |
3893 | // user_data is just the index +1 |
3894 | int i = ( (wxUIntPtr) iter->user_data ) -1; | |
2056dede RR |
3895 | gtk_tree_path_append_index (retval, i); |
3896 | } | |
3897 | else | |
55fbde12 | 3898 | { |
b9db5f30 VS |
3899 | void *id = iter->user_data; |
3900 | ||
2056dede RR |
3901 | wxGtkTreeModelNode *node = FindParentNode( iter ); |
3902 | while (node) | |
3903 | { | |
3904 | int pos = node->GetChildren().Index( id ); | |
ce00f59b | 3905 | |
2056dede | 3906 | gtk_tree_path_prepend_index( retval, pos ); |
b9db5f30 | 3907 | |
2056dede RR |
3908 | id = node->GetItem().GetID(); |
3909 | node = node->GetParent(); | |
3910 | } | |
55fbde12 | 3911 | } |
b9db5f30 | 3912 | |
55fbde12 RR |
3913 | return retval; |
3914 | } | |
3915 | ||
3916 | gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter ) | |
3917 | { | |
e39de702 | 3918 | if (m_wx_model->IsVirtualListModel()) |
2056dede | 3919 | { |
9330d5af | 3920 | wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model; |
b9db5f30 | 3921 | |
0ae51f62 RR |
3922 | // user_data is just the index +1 |
3923 | int n = ( (wxUIntPtr) iter->user_data ) -1; | |
69892729 | 3924 | |
2056dede | 3925 | if (n == -1) |
8a568372 RR |
3926 | { |
3927 | iter->user_data = NULL; | |
2056dede | 3928 | return FALSE; |
8a568372 | 3929 | } |
40196b1e | 3930 | |
8a568372 RR |
3931 | if (n >= (int) wx_model->GetCount()-1) |
3932 | { | |
3933 | iter->user_data = NULL; | |
2056dede | 3934 | return FALSE; |
8a568372 | 3935 | } |
03647350 | 3936 | |
0ae51f62 | 3937 | // user_data is just the index +1 (+2 because we need the next) |
6549dd3c | 3938 | iter->user_data = wxUIntToPtr(n+2); |
2056dede RR |
3939 | } |
3940 | else | |
3941 | { | |
3942 | wxGtkTreeModelNode *parent = FindParentNode( iter ); | |
3943 | if( parent == NULL ) | |
8a568372 RR |
3944 | { |
3945 | iter->user_data = NULL; | |
2056dede | 3946 | return FALSE; |
8a568372 | 3947 | } |
2056dede RR |
3948 | |
3949 | int pos = parent->GetChildren().Index( iter->user_data ); | |
3950 | ||
3951 | if (pos == (int) parent->GetChildCount()-1) | |
8a568372 RR |
3952 | { |
3953 | iter->user_data = NULL; | |
2056dede | 3954 | return FALSE; |
8a568372 | 3955 | } |
b9db5f30 | 3956 | |
2056dede RR |
3957 | iter->user_data = parent->GetChildren().Item( pos+1 ); |
3958 | } | |
55fbde12 RR |
3959 | |
3960 | return TRUE; | |
3961 | } | |
3962 | ||
3963 | gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter *parent ) | |
3964 | { | |
e39de702 | 3965 | if (m_wx_model->IsVirtualListModel()) |
2056dede RR |
3966 | { |
3967 | // this is a list, nodes have no children | |
3968 | if (parent) | |
3969 | return FALSE; | |
3970 | ||
3971 | iter->stamp = m_gtk_model->stamp; | |
9330d5af | 3972 | iter->user_data = (gpointer) 1; |
2056dede RR |
3973 | |
3974 | return TRUE; | |
3975 | } | |
3976 | else | |
3977 | { | |
8a568372 RR |
3978 | if (iter == NULL) |
3979 | { | |
3980 | if (m_root->GetChildCount() == 0) return FALSE; | |
3981 | iter->stamp = m_gtk_model->stamp; | |
3982 | iter->user_data = (gpointer) m_root->GetChildren().Item( 0 ); | |
3983 | return TRUE; | |
3984 | } | |
03647350 | 3985 | |
74035a19 | 3986 | |
3556d648 RR |
3987 | wxDataViewItem item; |
3988 | if (parent) | |
3989 | item = wxDataViewItem( (void*) parent->user_data ); | |
b9db5f30 | 3990 | |
2056dede RR |
3991 | if (!m_wx_model->IsContainer( item )) |
3992 | return FALSE; | |
b9db5f30 | 3993 | |
2056dede | 3994 | wxGtkTreeModelNode *parent_node = FindNode( parent ); |
c2489d8e FM |
3995 | wxASSERT_MSG(parent_node, |
3996 | "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel"); | |
3997 | ||
2056dede | 3998 | BuildBranch( parent_node ); |
b9db5f30 | 3999 | |
2056dede RR |
4000 | if (parent_node->GetChildCount() == 0) |
4001 | return FALSE; | |
b9db5f30 | 4002 | |
2056dede RR |
4003 | iter->stamp = m_gtk_model->stamp; |
4004 | iter->user_data = (gpointer) parent_node->GetChildren().Item( 0 ); | |
4005 | } | |
b9db5f30 | 4006 | |
55fbde12 RR |
4007 | return TRUE; |
4008 | } | |
4009 | ||
4010 | gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter ) | |
4011 | { | |
e39de702 | 4012 | if (m_wx_model->IsVirtualListModel()) |
2056dede | 4013 | { |
9330d5af RR |
4014 | wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model; |
4015 | ||
4016 | if (iter == NULL) | |
8a568372 | 4017 | return (wx_model->GetCount() > 0); |
03647350 | 4018 | |
2056dede RR |
4019 | // this is a list, nodes have no children |
4020 | return FALSE; | |
4021 | } | |
4022 | else | |
4023 | { | |
8a568372 RR |
4024 | if (iter == NULL) |
4025 | return (m_root->GetChildCount() > 0); | |
03647350 | 4026 | |
2056dede | 4027 | wxDataViewItem item( (void*) iter->user_data ); |
b9db5f30 | 4028 | |
2056dede | 4029 | bool is_container = m_wx_model->IsContainer( item ); |
b9db5f30 | 4030 | |
2056dede RR |
4031 | if (!is_container) |
4032 | return FALSE; | |
b9db5f30 | 4033 | |
2056dede | 4034 | wxGtkTreeModelNode *node = FindNode( iter ); |
c2489d8e FM |
4035 | wxASSERT_MSG(node, |
4036 | "Did you forget a call to ItemAdded()? The iterator is unknown to the wxGtkTreeModel"); | |
4037 | ||
2056dede | 4038 | BuildBranch( node ); |
b9db5f30 | 4039 | |
2056dede RR |
4040 | return (node->GetChildCount() > 0); |
4041 | } | |
55fbde12 RR |
4042 | } |
4043 | ||
4044 | gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter ) | |
4045 | { | |
e39de702 | 4046 | if (m_wx_model->IsVirtualListModel()) |
2056dede | 4047 | { |
9330d5af | 4048 | wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model; |
b9db5f30 | 4049 | |
2056dede | 4050 | if (iter == NULL) |
9330d5af | 4051 | return (gint) wx_model->GetCount(); |
2056dede | 4052 | |
55fbde12 | 4053 | return 0; |
2056dede RR |
4054 | } |
4055 | else | |
4056 | { | |
11f20f99 RR |
4057 | if (iter == NULL) |
4058 | return m_root->GetChildCount(); | |
c2489d8e | 4059 | |
2056dede | 4060 | wxDataViewItem item( (void*) iter->user_data ); |
b9db5f30 | 4061 | |
2056dede RR |
4062 | if (!m_wx_model->IsContainer( item )) |
4063 | return 0; | |
b9db5f30 | 4064 | |
2056dede | 4065 | wxGtkTreeModelNode *parent_node = FindNode( iter ); |
c2489d8e FM |
4066 | wxASSERT_MSG(parent_node, |
4067 | "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel"); | |
4068 | ||
2056dede | 4069 | BuildBranch( parent_node ); |
ef427989 | 4070 | |
2056dede RR |
4071 | return parent_node->GetChildCount(); |
4072 | } | |
55fbde12 RR |
4073 | } |
4074 | ||
4075 | gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter *parent, gint n ) | |
4076 | { | |
e39de702 | 4077 | if (m_wx_model->IsVirtualListModel()) |
2056dede | 4078 | { |
9330d5af | 4079 | wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model; |
b9db5f30 | 4080 | |
2056dede RR |
4081 | if (parent) |
4082 | return FALSE; | |
4083 | ||
4084 | if (n < 0) | |
4085 | return FALSE; | |
4086 | ||
9330d5af | 4087 | if (n >= (gint) wx_model->GetCount()) |
2056dede RR |
4088 | return FALSE; |
4089 | ||
4090 | iter->stamp = m_gtk_model->stamp; | |
0ae51f62 | 4091 | // user_data is just the index +1 |
6549dd3c | 4092 | iter->user_data = wxUIntToPtr(n+1); |
2056dede RR |
4093 | |
4094 | return TRUE; | |
4095 | } | |
4096 | else | |
4097 | { | |
4098 | void* id = NULL; | |
4099 | if (parent) id = (void*) parent->user_data; | |
4100 | wxDataViewItem item( id ); | |
b9db5f30 | 4101 | |
2056dede RR |
4102 | if (!m_wx_model->IsContainer( item )) |
4103 | return FALSE; | |
b9db5f30 | 4104 | |
2056dede | 4105 | wxGtkTreeModelNode *parent_node = FindNode( parent ); |
c2489d8e FM |
4106 | wxASSERT_MSG(parent_node, |
4107 | "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel"); | |
4108 | ||
2056dede | 4109 | BuildBranch( parent_node ); |
55fbde12 | 4110 | |
2056dede RR |
4111 | iter->stamp = m_gtk_model->stamp; |
4112 | iter->user_data = parent_node->GetChildren().Item( n ); | |
55fbde12 | 4113 | |
2056dede RR |
4114 | return TRUE; |
4115 | } | |
55fbde12 RR |
4116 | } |
4117 | ||
4118 | gboolean wxDataViewCtrlInternal::iter_parent( GtkTreeIter *iter, GtkTreeIter *child ) | |
4119 | { | |
e39de702 | 4120 | if (m_wx_model->IsVirtualListModel()) |
2056dede | 4121 | { |
55fbde12 | 4122 | return FALSE; |
2056dede RR |
4123 | } |
4124 | else | |
4125 | { | |
4126 | wxGtkTreeModelNode *node = FindParentNode( child ); | |
4127 | if (!node) | |
4128 | return FALSE; | |
b9db5f30 | 4129 | |
2056dede RR |
4130 | iter->stamp = m_gtk_model->stamp; |
4131 | iter->user_data = (gpointer) node->GetItem().GetID(); | |
55fbde12 | 4132 | |
2056dede RR |
4133 | return TRUE; |
4134 | } | |
55fbde12 | 4135 | } |
b9db5f30 | 4136 | |
74035a19 | 4137 | // item can be deleted already in the model |
8650c4ba RR |
4138 | int wxDataViewCtrlInternal::GetIndexOf( const wxDataViewItem &parent, const wxDataViewItem &item ) |
4139 | { | |
559c42a5 RR |
4140 | if (m_wx_model->IsVirtualListModel()) |
4141 | { | |
74035a19 | 4142 | return wxPtrToUInt(item.GetID()) - 1; |
559c42a5 RR |
4143 | } |
4144 | else | |
8650c4ba | 4145 | { |
559c42a5 RR |
4146 | wxGtkTreeModelNode *parent_node = FindNode( parent ); |
4147 | wxGtkTreeModelChildren &children = parent_node->GetChildren(); | |
4148 | size_t j; | |
4149 | for (j = 0; j < children.GetCount(); j++) | |
4150 | { | |
4151 | if (children[j] == item.GetID()) | |
4152 | return j; | |
4153 | } | |
8650c4ba RR |
4154 | } |
4155 | return -1; | |
4156 | } | |
4157 | ||
4158 | ||
55fbde12 | 4159 | static wxGtkTreeModelNode* |
69892729 | 4160 | wxDataViewCtrlInternal_FindNode( wxDataViewModel * model, wxGtkTreeModelNode *treeNode, const wxDataViewItem &item ) |
55fbde12 | 4161 | { |
69892729 RR |
4162 | if( model == NULL ) |
4163 | return NULL; | |
55fbde12 | 4164 | |
69892729 RR |
4165 | ItemList list; |
4166 | list.DeleteContents( true ); | |
4167 | wxDataViewItem it( item ); | |
b9db5f30 | 4168 | |
69892729 | 4169 | while( it.IsOk() ) |
55fbde12 | 4170 | { |
69892729 RR |
4171 | wxDataViewItem * pItem = new wxDataViewItem( it ); |
4172 | list.Insert( pItem ); | |
4173 | it = model->GetParent( it ); | |
4174 | } | |
4175 | ||
4176 | wxGtkTreeModelNode * node = treeNode; | |
966cb94d | 4177 | for( ItemList::compatibility_iterator n = list.GetFirst(); n; n = n->GetNext() ) |
69892729 RR |
4178 | { |
4179 | if( node && node->GetNodes().GetCount() != 0 ) | |
ef427989 | 4180 | { |
69892729 | 4181 | int len = node->GetNodes().GetCount(); |
8650c4ba | 4182 | wxGtkTreeModelNodes &nodes = node->GetNodes(); |
69892729 RR |
4183 | int j = 0; |
4184 | for( ; j < len; j ++) | |
4185 | { | |
4186 | if( nodes[j]->GetItem() == *(n->GetData())) | |
4187 | { | |
4188 | node = nodes[j]; | |
4189 | break; | |
b9db5f30 | 4190 | } |
69892729 RR |
4191 | } |
4192 | ||
4193 | if( j == len ) | |
4194 | { | |
4195 | return NULL; | |
4196 | } | |
ef427989 | 4197 | } |
69892729 RR |
4198 | else |
4199 | return NULL; | |
55fbde12 | 4200 | } |
69892729 RR |
4201 | return node; |
4202 | ||
55fbde12 RR |
4203 | } |
4204 | ||
4205 | wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( GtkTreeIter *iter ) | |
4206 | { | |
4207 | if (!iter) | |
4208 | return m_root; | |
4209 | ||
4210 | wxDataViewItem item( (void*) iter->user_data ); | |
0be79c8a RR |
4211 | if (!item.IsOk()) |
4212 | return m_root; | |
b9db5f30 | 4213 | |
69892729 | 4214 | wxGtkTreeModelNode *result = wxDataViewCtrlInternal_FindNode( m_wx_model, m_root, item ); |
b9db5f30 | 4215 | |
c2489d8e | 4216 | /* |
55fbde12 RR |
4217 | if (!result) |
4218 | { | |
26f119eb | 4219 | wxLogDebug( "Not found %p", iter->user_data ); |
55fbde12 RR |
4220 | char *crash = NULL; |
4221 | *crash = 0; | |
4222 | } | |
c2489d8e FM |
4223 | // TODO: remove this code |
4224 | */ | |
b9db5f30 | 4225 | |
55fbde12 RR |
4226 | return result; |
4227 | } | |
4228 | ||
4229 | wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( const wxDataViewItem &item ) | |
4230 | { | |
0be79c8a RR |
4231 | if (!item.IsOk()) |
4232 | return m_root; | |
4233 | ||
69892729 | 4234 | wxGtkTreeModelNode *result = wxDataViewCtrlInternal_FindNode( m_wx_model, m_root, item ); |
b9db5f30 | 4235 | |
c2489d8e | 4236 | /* |
55fbde12 RR |
4237 | if (!result) |
4238 | { | |
26f119eb | 4239 | wxLogDebug( "Not found %p", item.GetID() ); |
55fbde12 RR |
4240 | char *crash = NULL; |
4241 | *crash = 0; | |
4242 | } | |
c2489d8e FM |
4243 | // TODO: remove this code |
4244 | */ | |
b9db5f30 | 4245 | |
55fbde12 RR |
4246 | return result; |
4247 | } | |
4248 | ||
af110130 | 4249 | static wxGtkTreeModelNode* |
69892729 | 4250 | wxDataViewCtrlInternal_FindParentNode( wxDataViewModel * model, wxGtkTreeModelNode *treeNode, const wxDataViewItem &item ) |
af110130 | 4251 | { |
69892729 RR |
4252 | if( model == NULL ) |
4253 | return NULL; | |
4254 | ||
4255 | ItemList list; | |
4256 | list.DeleteContents( true ); | |
4257 | if( !item.IsOk() ) | |
4258 | return NULL; | |
4259 | ||
4260 | wxDataViewItem it( model->GetParent( item ) ); | |
4261 | while( it.IsOk() ) | |
af110130 | 4262 | { |
69892729 RR |
4263 | wxDataViewItem * pItem = new wxDataViewItem( it ); |
4264 | list.Insert( pItem ); | |
4265 | it = model->GetParent( it ); | |
af110130 RR |
4266 | } |
4267 | ||
69892729 | 4268 | wxGtkTreeModelNode * node = treeNode; |
966cb94d | 4269 | for( ItemList::compatibility_iterator n = list.GetFirst(); n; n = n->GetNext() ) |
af110130 | 4270 | { |
69892729 | 4271 | if( node && node->GetNodes().GetCount() != 0 ) |
af110130 | 4272 | { |
69892729 RR |
4273 | int len = node->GetNodes().GetCount(); |
4274 | wxGtkTreeModelNodes nodes = node->GetNodes(); | |
4275 | int j = 0; | |
4276 | for( ; j < len; j ++) | |
4277 | { | |
4278 | if( nodes[j]->GetItem() == *(n->GetData())) | |
4279 | { | |
4280 | node = nodes[j]; | |
4281 | break; | |
b9db5f30 | 4282 | } |
69892729 RR |
4283 | } |
4284 | ||
4285 | if( j == len ) | |
4286 | { | |
4287 | return NULL; | |
4288 | } | |
af110130 | 4289 | } |
69892729 RR |
4290 | else |
4291 | return NULL; | |
4292 | } | |
4293 | //Examine whether the node is item's parent node | |
4294 | int len = node->GetChildCount(); | |
4295 | for( int i = 0; i < len ; i ++ ) | |
4296 | { | |
4297 | if( node->GetChildren().Item( i ) == item.GetID() ) | |
4298 | return node; | |
af110130 | 4299 | } |
af110130 RR |
4300 | return NULL; |
4301 | } | |
4302 | ||
4303 | wxGtkTreeModelNode *wxDataViewCtrlInternal::FindParentNode( GtkTreeIter *iter ) | |
4304 | { | |
4305 | if (!iter) | |
4306 | return NULL; | |
b9db5f30 | 4307 | |
af110130 RR |
4308 | wxDataViewItem item( (void*) iter->user_data ); |
4309 | if (!item.IsOk()) | |
4310 | return NULL; | |
4311 | ||
69892729 | 4312 | return wxDataViewCtrlInternal_FindParentNode( m_wx_model, m_root, item ); |
af110130 RR |
4313 | } |
4314 | ||
4315 | wxGtkTreeModelNode *wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem &item ) | |
4316 | { | |
4317 | if (!item.IsOk()) | |
4318 | return NULL; | |
4319 | ||
69892729 | 4320 | return wxDataViewCtrlInternal_FindParentNode( m_wx_model, m_root, item ); |
af110130 RR |
4321 | } |
4322 | ||
eb7f97f8 RR |
4323 | //----------------------------------------------------------------------------- |
4324 | // wxDataViewCtrl signal callbacks | |
4325 | //----------------------------------------------------------------------------- | |
4326 | ||
4327 | static void | |
ad386793 | 4328 | wxdataview_selection_changed_callback( GtkTreeSelection* WXUNUSED(selection), wxDataViewCtrl *dv ) |
eb7f97f8 | 4329 | { |
fc9ab22a | 4330 | if (!gtk_widget_get_realized(dv->m_widget)) |
b94db696 | 4331 | return; |
f4322df6 | 4332 | |
d86c1870 | 4333 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, dv->GetId() ); |
6848478c | 4334 | event.SetItem( dv->GetSelection() ); |
eb7f97f8 | 4335 | event.SetModel( dv->GetModel() ); |
937013e0 | 4336 | dv->HandleWindowEvent( event ); |
eb7f97f8 RR |
4337 | } |
4338 | ||
f828871d | 4339 | static void |
ad386793 RR |
4340 | wxdataview_row_activated_callback( GtkTreeView* WXUNUSED(treeview), GtkTreePath *path, |
4341 | GtkTreeViewColumn *WXUNUSED(column), wxDataViewCtrl *dv ) | |
f828871d | 4342 | { |
e0062c04 | 4343 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, dv->GetId() ); |
55fbde12 | 4344 | |
17d98558 | 4345 | wxDataViewItem item(dv->GTKPathToItem(path)); |
55fbde12 | 4346 | event.SetItem( item ); |
f828871d | 4347 | event.SetModel( dv->GetModel() ); |
937013e0 | 4348 | dv->HandleWindowEvent( event ); |
f828871d RR |
4349 | } |
4350 | ||
718fd180 | 4351 | static gboolean |
ad386793 RR |
4352 | wxdataview_test_expand_row_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter, |
4353 | GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv ) | |
718fd180 RR |
4354 | { |
4355 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, dv->GetId() ); | |
4356 | ||
4357 | wxDataViewItem item( (void*) iter->user_data );; | |
4358 | event.SetItem( item ); | |
4359 | event.SetModel( dv->GetModel() ); | |
937013e0 | 4360 | dv->HandleWindowEvent( event ); |
b9db5f30 | 4361 | |
718fd180 RR |
4362 | return !event.IsAllowed(); |
4363 | } | |
4364 | ||
4365 | static void | |
ad386793 RR |
4366 | wxdataview_row_expanded_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter, |
4367 | GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv ) | |
718fd180 RR |
4368 | { |
4369 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, dv->GetId() ); | |
4370 | ||
4371 | wxDataViewItem item( (void*) iter->user_data );; | |
4372 | event.SetItem( item ); | |
4373 | event.SetModel( dv->GetModel() ); | |
937013e0 | 4374 | dv->HandleWindowEvent( event ); |
718fd180 RR |
4375 | } |
4376 | ||
4377 | static gboolean | |
ad386793 RR |
4378 | wxdataview_test_collapse_row_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter, |
4379 | GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv ) | |
718fd180 RR |
4380 | { |
4381 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, dv->GetId() ); | |
4382 | ||
4383 | wxDataViewItem item( (void*) iter->user_data );; | |
4384 | event.SetItem( item ); | |
4385 | event.SetModel( dv->GetModel() ); | |
937013e0 | 4386 | dv->HandleWindowEvent( event ); |
b9db5f30 | 4387 | |
718fd180 RR |
4388 | return !event.IsAllowed(); |
4389 | } | |
4390 | ||
4391 | static void | |
ad386793 RR |
4392 | wxdataview_row_collapsed_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter, |
4393 | GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv ) | |
718fd180 RR |
4394 | { |
4395 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, dv->GetId() ); | |
4396 | ||
4397 | wxDataViewItem item( (void*) iter->user_data );; | |
4398 | event.SetItem( item ); | |
4399 | event.SetModel( dv->GetModel() ); | |
937013e0 | 4400 | dv->HandleWindowEvent( event ); |
718fd180 RR |
4401 | } |
4402 | ||
790b137e | 4403 | //----------------------------------------------------------------------------- |
718fd180 | 4404 | // wxDataViewCtrl |
790b137e RR |
4405 | //----------------------------------------------------------------------------- |
4406 | ||
48200154 | 4407 | void wxDataViewCtrl::AddChildGTK(wxWindowGTK* child) |
1e510b1e | 4408 | { |
48200154 | 4409 | GtkWidget* treeview = GtkGetTreeView(); |
1e510b1e RR |
4410 | |
4411 | // Insert widget in GtkTreeView | |
fc9ab22a | 4412 | if (gtk_widget_get_realized(treeview)) |
e8375af8 | 4413 | gtk_widget_set_parent_window( child->m_widget, |
1e510b1e RR |
4414 | gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview) ) ); |
4415 | gtk_widget_set_parent( child->m_widget, treeview ); | |
4416 | } | |
4417 | ||
4418 | static | |
4419 | void gtk_dataviewctrl_size_callback( GtkWidget *WXUNUSED(widget), | |
ad386793 | 4420 | GtkAllocation *WXUNUSED(gtk_alloc), |
1e510b1e RR |
4421 | wxDataViewCtrl *win ) |
4422 | { | |
966cb94d | 4423 | wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst(); |
1e510b1e RR |
4424 | while (node) |
4425 | { | |
4426 | wxWindow *child = node->GetData(); | |
e8375af8 | 4427 | |
1e510b1e RR |
4428 | GtkRequisition req; |
4429 | gtk_widget_size_request( child->m_widget, &req ); | |
e8375af8 | 4430 | |
1e510b1e RR |
4431 | GtkAllocation alloc; |
4432 | alloc.x = child->m_x; | |
4433 | alloc.y = child->m_y; | |
4434 | alloc.width = child->m_width; | |
4435 | alloc.height = child->m_height; | |
4436 | gtk_widget_size_allocate( child->m_widget, &alloc ); | |
e8375af8 | 4437 | |
1e510b1e RR |
4438 | node = node->GetNext(); |
4439 | } | |
4440 | } | |
4441 | ||
4442 | ||
6608fdab RR |
4443 | //----------------------------------------------------------------------------- |
4444 | // "motion_notify_event" | |
4445 | //----------------------------------------------------------------------------- | |
4446 | ||
4447 | static gboolean | |
ad386793 | 4448 | gtk_dataview_motion_notify_callback( GtkWidget *WXUNUSED(widget), |
74dea0de RR |
4449 | GdkEventMotion *gdk_event, |
4450 | wxDataViewCtrl *dv ) | |
6608fdab RR |
4451 | { |
4452 | if (gdk_event->is_hint) | |
4453 | { | |
4454 | int x = 0; | |
4455 | int y = 0; | |
4456 | GdkModifierType state; | |
4457 | gdk_window_get_pointer(gdk_event->window, &x, &y, &state); | |
4458 | gdk_event->x = x; | |
4459 | gdk_event->y = y; | |
4460 | } | |
4461 | ||
0c2a7270 | 4462 | wxGtkTreePath path; |
6608fdab RR |
4463 | GtkTreeViewColumn *column = NULL; |
4464 | gint cell_x = 0; | |
4465 | gint cell_y = 0; | |
b9db5f30 | 4466 | if (gtk_tree_view_get_path_at_pos( |
6608fdab RR |
4467 | GTK_TREE_VIEW(dv->GtkGetTreeView()), |
4468 | (int) gdk_event->x, (int) gdk_event->y, | |
0c2a7270 | 4469 | path.ByRef(), |
6608fdab RR |
4470 | &column, |
4471 | &cell_x, | |
4472 | &cell_y)) | |
4473 | { | |
4474 | if (path) | |
4475 | { | |
4476 | GtkTreeIter iter; | |
4477 | dv->GtkGetInternal()->get_iter( &iter, path ); | |
6608fdab RR |
4478 | } |
4479 | } | |
4480 | ||
4481 | ||
4482 | return FALSE; | |
4483 | } | |
4484 | ||
74dea0de RR |
4485 | //----------------------------------------------------------------------------- |
4486 | // "button_press_event" | |
4487 | //----------------------------------------------------------------------------- | |
4488 | ||
4489 | static gboolean | |
4490 | gtk_dataview_button_press_callback( GtkWidget *WXUNUSED(widget), | |
4491 | GdkEventButton *gdk_event, | |
4492 | wxDataViewCtrl *dv ) | |
4493 | { | |
4494 | if ((gdk_event->button == 3) && (gdk_event->type == GDK_BUTTON_PRESS)) | |
4495 | { | |
0c2a7270 | 4496 | wxGtkTreePath path; |
74dea0de RR |
4497 | GtkTreeViewColumn *column = NULL; |
4498 | gint cell_x = 0; | |
4499 | gint cell_y = 0; | |
7ed24cb6 VZ |
4500 | gtk_tree_view_get_path_at_pos |
4501 | ( | |
74dea0de RR |
4502 | GTK_TREE_VIEW(dv->GtkGetTreeView()), |
4503 | (int) gdk_event->x, (int) gdk_event->y, | |
0c2a7270 | 4504 | path.ByRef(), |
74dea0de RR |
4505 | &column, |
4506 | &cell_x, | |
7ed24cb6 VZ |
4507 | &cell_y |
4508 | ); | |
4509 | ||
4510 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, dv->GetId() ); | |
4511 | if (path) | |
4512 | event.SetItem(dv->GTKPathToItem(path)); | |
4513 | event.SetModel( dv->GetModel() ); | |
4514 | return dv->HandleWindowEvent( event ); | |
74dea0de RR |
4515 | } |
4516 | ||
4517 | return FALSE; | |
4518 | } | |
1e510b1e | 4519 | |
239eaa41 RR |
4520 | IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase) |
4521 | ||
4522 | wxDataViewCtrl::~wxDataViewCtrl() | |
4523 | { | |
b2fd3bea VZ |
4524 | // Stop editing before destroying the control to remove any event handlers |
4525 | // which are added when editing started: if we didn't do this, the base | |
4526 | // class dtor would assert as it checks for any leftover handlers. | |
4527 | if ( m_treeview ) | |
4528 | { | |
4529 | GtkTreeViewColumn *col; | |
4530 | gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview), NULL, &col); | |
4531 | ||
4532 | wxDataViewColumn * const wxcol = FromGTKColumn(col); | |
4533 | if ( wxcol ) | |
4534 | { | |
4535 | // This won't do anything if we're not editing it | |
4536 | wxcol->GetRenderer()->CancelEditing(); | |
4537 | } | |
4538 | } | |
4539 | ||
ef11ea71 RR |
4540 | m_cols.Clear(); |
4541 | ||
55fbde12 | 4542 | delete m_internal; |
239eaa41 RR |
4543 | } |
4544 | ||
4545 | void wxDataViewCtrl::Init() | |
4546 | { | |
33ba5a05 | 4547 | m_internal = NULL; |
bc0289bf | 4548 | |
ef11ea71 | 4549 | m_cols.DeleteContents( true ); |
0f4a54a6 VZ |
4550 | |
4551 | m_uniformRowHeight = -1; | |
239eaa41 RR |
4552 | } |
4553 | ||
62e9285a VZ |
4554 | bool wxDataViewCtrl::Create(wxWindow *parent, |
4555 | wxWindowID id, | |
4556 | const wxPoint& pos, | |
4557 | const wxSize& size, | |
4558 | long style, | |
4559 | const wxValidator& validator, | |
4560 | const wxString& name) | |
239eaa41 | 4561 | { |
239eaa41 | 4562 | if (!PreCreation( parent, pos, size ) || |
62e9285a | 4563 | !CreateBase( parent, id, pos, size, style, validator, name )) |
239eaa41 RR |
4564 | { |
4565 | wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") ); | |
93763ad5 | 4566 | return false; |
239eaa41 | 4567 | } |
1a367564 RR |
4568 | |
4569 | m_widget = gtk_scrolled_window_new (NULL, NULL); | |
9ff9d30c | 4570 | g_object_ref(m_widget); |
6493aaca | 4571 | |
496e7ec6 | 4572 | GTKScrolledWindowSetBorder(m_widget, style); |
1a367564 RR |
4573 | |
4574 | m_treeview = gtk_tree_view_new(); | |
4575 | gtk_container_add (GTK_CONTAINER (m_widget), m_treeview); | |
e8375af8 | 4576 | |
fc55eaa0 VS |
4577 | m_focusWidget = GTK_WIDGET(m_treeview); |
4578 | ||
1e510b1e RR |
4579 | g_signal_connect (m_treeview, "size_allocate", |
4580 | G_CALLBACK (gtk_dataviewctrl_size_callback), this); | |
ed4b0fdc | 4581 | |
b94db696 | 4582 | #ifdef __WXGTK26__ |
9dc44eff | 4583 | #ifndef __WXGTK3__ |
b94db696 | 4584 | if (!gtk_check_version(2,6,0)) |
9dc44eff | 4585 | #endif |
344ed1f3 RR |
4586 | { |
4587 | bool fixed = (style & wxDV_VARIABLE_LINE_HEIGHT) == 0; | |
4588 | gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), fixed ); | |
4589 | } | |
b94db696 RR |
4590 | #endif |
4591 | ||
daebb44c RR |
4592 | if (style & wxDV_MULTIPLE) |
4593 | { | |
4594 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); | |
4595 | gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE ); | |
4596 | } | |
93763ad5 | 4597 | |
9861f022 RR |
4598 | gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview), (style & wxDV_NO_HEADER) == 0 ); |
4599 | ||
4600 | #ifdef __WXGTK210__ | |
9dc44eff | 4601 | #ifndef __WXGTK3__ |
9861f022 | 4602 | if (!gtk_check_version(2,10,0)) |
9dc44eff | 4603 | #endif |
9861f022 RR |
4604 | { |
4605 | GtkTreeViewGridLines grid = GTK_TREE_VIEW_GRID_LINES_NONE; | |
f4322df6 VZ |
4606 | |
4607 | if ((style & wxDV_HORIZ_RULES) != 0 && | |
9861f022 RR |
4608 | (style & wxDV_VERT_RULES) != 0) |
4609 | grid = GTK_TREE_VIEW_GRID_LINES_BOTH; | |
4610 | else if (style & wxDV_VERT_RULES) | |
4611 | grid = GTK_TREE_VIEW_GRID_LINES_VERTICAL; | |
4612 | else if (style & wxDV_HORIZ_RULES) | |
4613 | grid = GTK_TREE_VIEW_GRID_LINES_HORIZONTAL; | |
4614 | ||
1a07a730 RR |
4615 | if (grid != GTK_TREE_VIEW_GRID_LINES_NONE) |
4616 | gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview), grid ); | |
9861f022 | 4617 | } |
9861f022 | 4618 | #endif |
1a07a730 RR |
4619 | |
4620 | gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview), (style & wxDV_ROW_LINES) != 0 ); | |
9861f022 | 4621 | |
1a367564 | 4622 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget), |
16eab2e1 | 4623 | GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |
1a367564 | 4624 | gtk_widget_show (m_treeview); |
93763ad5 | 4625 | |
239eaa41 RR |
4626 | m_parent->DoAddChild( this ); |
4627 | ||
b94db696 RR |
4628 | PostCreation(size); |
4629 | ||
b086d55f RR |
4630 | GtkEnableSelectionEvents(); |
4631 | ||
718fd180 | 4632 | g_signal_connect_after (m_treeview, "row-activated", |
f828871d | 4633 | G_CALLBACK (wxdataview_row_activated_callback), this); |
eb7f97f8 | 4634 | |
718fd180 RR |
4635 | g_signal_connect (m_treeview, "test-collapse-row", |
4636 | G_CALLBACK (wxdataview_test_collapse_row_callback), this); | |
4637 | ||
4638 | g_signal_connect_after (m_treeview, "row-collapsed", | |
4639 | G_CALLBACK (wxdataview_row_collapsed_callback), this); | |
4640 | ||
4641 | g_signal_connect (m_treeview, "test-expand-row", | |
4642 | G_CALLBACK (wxdataview_test_expand_row_callback), this); | |
b9db5f30 | 4643 | |
718fd180 RR |
4644 | g_signal_connect_after (m_treeview, "row-expanded", |
4645 | G_CALLBACK (wxdataview_row_expanded_callback), this); | |
4646 | ||
6608fdab RR |
4647 | g_signal_connect (m_treeview, "motion_notify_event", |
4648 | G_CALLBACK (gtk_dataview_motion_notify_callback), this); | |
4649 | ||
74dea0de RR |
4650 | g_signal_connect (m_treeview, "button_press_event", |
4651 | G_CALLBACK (gtk_dataview_button_press_callback), this); | |
7857346a | 4652 | |
239eaa41 RR |
4653 | return true; |
4654 | } | |
4655 | ||
17d98558 VZ |
4656 | wxDataViewItem wxDataViewCtrl::GTKPathToItem(GtkTreePath *path) const |
4657 | { | |
4658 | GtkTreeIter iter; | |
4659 | return wxDataViewItem(path && m_internal->get_iter(&iter, path) | |
4660 | ? iter.user_data | |
4661 | : NULL); | |
4662 | } | |
4663 | ||
31fb32e1 RR |
4664 | void wxDataViewCtrl::OnInternalIdle() |
4665 | { | |
4666 | wxWindow::OnInternalIdle(); | |
ce00f59b | 4667 | |
d8090b5e | 4668 | m_internal->OnInternalIdle(); |
f4322df6 | 4669 | |
9861f022 | 4670 | unsigned int cols = GetColumnCount(); |
31fb32e1 RR |
4671 | unsigned int i; |
4672 | for (i = 0; i < cols; i++) | |
4673 | { | |
4674 | wxDataViewColumn *col = GetColumn( i ); | |
4675 | col->OnInternalIdle(); | |
4676 | } | |
ce00f59b | 4677 | |
3f53dd3a RR |
4678 | if (m_ensureVisibleDefered.IsOk()) |
4679 | { | |
4680 | ExpandAncestors(m_ensureVisibleDefered); | |
4681 | GtkTreeIter iter; | |
4682 | iter.user_data = (gpointer) m_ensureVisibleDefered.GetID(); | |
4683 | wxGtkTreePath path(m_internal->get_path( &iter )); | |
4684 | gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview), path, NULL, false, 0.0, 0.0 ); | |
4685 | m_ensureVisibleDefered = wxDataViewItem(0); | |
4686 | } | |
31fb32e1 RR |
4687 | } |
4688 | ||
e0062c04 | 4689 | bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model ) |
239eaa41 | 4690 | { |
5276b0a5 | 4691 | wxDELETE(m_internal); |
7857346a | 4692 | |
239eaa41 RR |
4693 | if (!wxDataViewCtrlBase::AssociateModel( model )) |
4694 | return false; | |
4695 | ||
344ed1f3 | 4696 | #ifdef __WXGTK26__ |
9dc44eff | 4697 | #ifndef __WXGTK3__ |
344ed1f3 | 4698 | if (!gtk_check_version(2,6,0)) |
9dc44eff | 4699 | #endif |
344ed1f3 RR |
4700 | { |
4701 | bool fixed = (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) == 0) || (model->IsVirtualListModel())); | |
4702 | gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), fixed ); | |
4703 | } | |
4704 | #endif | |
4705 | ||
673810ee | 4706 | m_internal = new wxDataViewCtrlInternal( this, model ); |
93763ad5 | 4707 | |
239eaa41 RR |
4708 | return true; |
4709 | } | |
790b137e | 4710 | |
15cac64f RR |
4711 | bool wxDataViewCtrl::EnableDragSource( const wxDataFormat &format ) |
4712 | { | |
4713 | return m_internal->EnableDragSource( format ); | |
4714 | } | |
4715 | ||
e4de825e RR |
4716 | bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat &format ) |
4717 | { | |
4718 | return m_internal->EnableDropTarget( format ); | |
4719 | } | |
4720 | ||
fa28826d RR |
4721 | bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col ) |
4722 | { | |
4723 | if (!wxDataViewCtrlBase::AppendColumn(col)) | |
4724 | return false; | |
93763ad5 | 4725 | |
91a6c655 RR |
4726 | m_cols.Append( col ); |
4727 | ||
ad386793 | 4728 | #ifdef __WXGTK26__ |
9dc44eff | 4729 | #ifndef __WXGTK3__ |
ad386793 | 4730 | if (!gtk_check_version(2,6,0)) |
9dc44eff | 4731 | #endif |
ad386793 RR |
4732 | { |
4733 | if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) ) != | |
4734 | GTK_TREE_VIEW_COLUMN_FIXED) | |
4735 | gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), FALSE ); | |
4736 | } | |
4737 | #endif | |
4738 | ||
b9db5f30 | 4739 | gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview), |
91a6c655 RR |
4740 | GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) ); |
4741 | ||
4742 | return true; | |
4743 | } | |
4744 | ||
736fe67c RR |
4745 | bool wxDataViewCtrl::PrependColumn( wxDataViewColumn *col ) |
4746 | { | |
4747 | if (!wxDataViewCtrlBase::PrependColumn(col)) | |
4748 | return false; | |
4749 | ||
4750 | m_cols.Insert( col ); | |
4751 | ||
ad386793 | 4752 | #ifdef __WXGTK26__ |
9dc44eff | 4753 | #ifndef __WXGTK3__ |
ad386793 | 4754 | if (!gtk_check_version(2,6,0)) |
9dc44eff | 4755 | #endif |
ad386793 RR |
4756 | { |
4757 | if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) ) != | |
4758 | GTK_TREE_VIEW_COLUMN_FIXED) | |
4759 | gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), FALSE ); | |
4760 | } | |
4761 | #endif | |
4762 | ||
b9db5f30 | 4763 | gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview), |
736fe67c RR |
4764 | GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()), 0 ); |
4765 | ||
4766 | return true; | |
4767 | } | |
4768 | ||
19723525 RR |
4769 | bool wxDataViewCtrl::InsertColumn( unsigned int pos, wxDataViewColumn *col ) |
4770 | { | |
4771 | if (!wxDataViewCtrlBase::InsertColumn(pos,col)) | |
4772 | return false; | |
4773 | ||
4774 | m_cols.Insert( pos, col ); | |
4775 | ||
4776 | #ifdef __WXGTK26__ | |
9dc44eff | 4777 | #ifndef __WXGTK3__ |
19723525 | 4778 | if (!gtk_check_version(2,6,0)) |
9dc44eff | 4779 | #endif |
19723525 RR |
4780 | { |
4781 | if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) ) != | |
4782 | GTK_TREE_VIEW_COLUMN_FIXED) | |
4783 | gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), FALSE ); | |
4784 | } | |
4785 | #endif | |
4786 | ||
4787 | gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview), | |
4788 | GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()), pos ); | |
4789 | ||
4790 | return true; | |
4791 | } | |
4792 | ||
91a6c655 RR |
4793 | unsigned int wxDataViewCtrl::GetColumnCount() const |
4794 | { | |
4795 | return m_cols.GetCount(); | |
4796 | } | |
4797 | ||
b2fd3bea | 4798 | wxDataViewColumn* wxDataViewCtrl::FromGTKColumn(GtkTreeViewColumn *gtk_col) const |
91a6c655 | 4799 | { |
b2fd3bea | 4800 | if ( !gtk_col ) |
91a6c655 | 4801 | return NULL; |
b9db5f30 | 4802 | |
91a6c655 | 4803 | wxDataViewColumnList::const_iterator iter; |
ef11ea71 | 4804 | for (iter = m_cols.begin(); iter != m_cols.end(); ++iter) |
91a6c655 RR |
4805 | { |
4806 | wxDataViewColumn *col = *iter; | |
4807 | if (GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) == gtk_col) | |
4808 | { | |
4809 | return col; | |
4810 | } | |
4811 | } | |
b9db5f30 | 4812 | |
b2fd3bea VZ |
4813 | wxFAIL_MSG( "No matching column?" ); |
4814 | ||
91a6c655 RR |
4815 | return NULL; |
4816 | } | |
4817 | ||
b2fd3bea VZ |
4818 | wxDataViewColumn* wxDataViewCtrl::GetColumn( unsigned int pos ) const |
4819 | { | |
4820 | GtkTreeViewColumn *gtk_col = gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview), pos ); | |
4821 | ||
4822 | return FromGTKColumn(gtk_col); | |
4823 | } | |
4824 | ||
91a6c655 RR |
4825 | bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn *column ) |
4826 | { | |
b9db5f30 | 4827 | gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview), |
91a6c655 RR |
4828 | GTK_TREE_VIEW_COLUMN(column->GetGtkHandle()) ); |
4829 | ||
ef11ea71 | 4830 | m_cols.DeleteObject( column ); |
fa28826d RR |
4831 | |
4832 | return true; | |
4833 | } | |
4834 | ||
91a6c655 RR |
4835 | bool wxDataViewCtrl::ClearColumns() |
4836 | { | |
4837 | wxDataViewColumnList::iterator iter; | |
ef11ea71 | 4838 | for (iter = m_cols.begin(); iter != m_cols.end(); ++iter) |
91a6c655 RR |
4839 | { |
4840 | wxDataViewColumn *col = *iter; | |
b9db5f30 | 4841 | gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview), |
91a6c655 RR |
4842 | GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) ); |
4843 | } | |
b9db5f30 | 4844 | |
ef11ea71 | 4845 | m_cols.Clear(); |
b9db5f30 | 4846 | |
91a6c655 RR |
4847 | return true; |
4848 | } | |
4849 | ||
453091c2 RR |
4850 | int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn *column ) const |
4851 | { | |
b3a8aa92 | 4852 | GtkTreeViewColumn *gtk_column = GTK_TREE_VIEW_COLUMN(column->GetGtkHandle()); |
aed836f3 | 4853 | |
0eec47e4 | 4854 | wxGtkList list(gtk_tree_view_get_columns(GTK_TREE_VIEW(m_treeview))); |
b9db5f30 | 4855 | |
0eec47e4 | 4856 | return g_list_index( list, (gconstpointer) gtk_column ); |
453091c2 RR |
4857 | } |
4858 | ||
21f47fb9 RR |
4859 | wxDataViewColumn *wxDataViewCtrl::GetSortingColumn() const |
4860 | { | |
d32332aa | 4861 | return m_internal->GetDataViewSortColumn(); |
21f47fb9 RR |
4862 | } |
4863 | ||
f71d3ba4 RR |
4864 | void wxDataViewCtrl::Expand( const wxDataViewItem & item ) |
4865 | { | |
4866 | GtkTreeIter iter; | |
4867 | iter.user_data = item.GetID(); | |
0c2a7270 | 4868 | wxGtkTreePath path(m_internal->get_path( &iter )); |
f71d3ba4 | 4869 | gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview), path, false ); |
f71d3ba4 RR |
4870 | } |
4871 | ||
4872 | void wxDataViewCtrl::Collapse( const wxDataViewItem & item ) | |
4873 | { | |
4874 | GtkTreeIter iter; | |
4875 | iter.user_data = item.GetID(); | |
0c2a7270 | 4876 | wxGtkTreePath path(m_internal->get_path( &iter )); |
f71d3ba4 | 4877 | gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview), path ); |
739a8399 RR |
4878 | } |
4879 | ||
4880 | bool wxDataViewCtrl::IsExpanded( const wxDataViewItem & item ) const | |
4881 | { | |
4882 | GtkTreeIter iter; | |
4883 | iter.user_data = item.GetID(); | |
0c2a7270 | 4884 | wxGtkTreePath path(m_internal->get_path( &iter )); |
d5027818 | 4885 | return gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview), path ) != 0; |
f71d3ba4 RR |
4886 | } |
4887 | ||
80ce465c VZ |
4888 | wxDataViewItem wxDataViewCtrl::DoGetCurrentItem() const |
4889 | { | |
4890 | // The tree doesn't have any current item if it hadn't been created yet but | |
4891 | // it's arguably not an error to call this function in this case so just | |
4892 | // return an invalid item without asserting. | |
4893 | if ( !m_treeview ) | |
4894 | return wxDataViewItem(); | |
4895 | ||
4896 | wxGtkTreePath path; | |
4897 | gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview), path.ByRef(), NULL); | |
4898 | ||
4899 | return GTKPathToItem(path); | |
4900 | } | |
4901 | ||
4902 | void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem& item) | |
4903 | { | |
4904 | wxCHECK_RET( m_treeview, | |
4905 | "Current item can't be set before creating the control." ); | |
4906 | ||
4907 | // We need to make sure the model knows about this item or the path would | |
4908 | // be invalid and gtk_tree_view_set_cursor() would silently do nothing. | |
4909 | ExpandAncestors(item); | |
4910 | ||
4911 | // We also need to preserve the existing selection from changing. | |
4912 | // Unfortunately the only way to do it seems to use our own selection | |
4913 | // function and forbid any selection changes during set cursor call. | |
4914 | wxGtkTreeSelectionLock | |
4915 | lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview))); | |
4916 | ||
4917 | // Do move the cursor now. | |
4918 | GtkTreeIter iter; | |
4919 | iter.user_data = item.GetID(); | |
4920 | wxGtkTreePath path(m_internal->get_path( &iter )); | |
4921 | ||
4922 | gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview), path, NULL, FALSE); | |
4923 | } | |
4924 | ||
ee1377e1 VS |
4925 | wxDataViewColumn *wxDataViewCtrl::GetCurrentColumn() const |
4926 | { | |
4927 | // The tree doesn't have any current item if it hadn't been created yet but | |
4928 | // it's arguably not an error to call this function in this case so just | |
4929 | // return NULL without asserting. | |
4930 | if ( !m_treeview ) | |
4931 | return NULL; | |
4932 | ||
4933 | GtkTreeViewColumn *col; | |
4934 | gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview), NULL, &col); | |
4935 | return FromGTKColumn(col); | |
4936 | } | |
4937 | ||
907f09f4 | 4938 | void wxDataViewCtrl::EditItem(const wxDataViewItem& item, const wxDataViewColumn *column) |
eeea3b03 RD |
4939 | { |
4940 | wxCHECK_RET( m_treeview, | |
4941 | "Current item can't be set before creating the control." ); | |
907f09f4 VS |
4942 | wxCHECK_RET( item.IsOk(), "invalid item" ); |
4943 | wxCHECK_RET( column, "no column provided" ); | |
eeea3b03 RD |
4944 | |
4945 | // We need to make sure the model knows about this item or the path would | |
4946 | // be invalid and gtk_tree_view_set_cursor() would silently do nothing. | |
4947 | ExpandAncestors(item); | |
907f09f4 VS |
4948 | |
4949 | GtkTreeViewColumn *gcolumn = GTK_TREE_VIEW_COLUMN(column->GetGtkHandle()); | |
eeea3b03 RD |
4950 | |
4951 | // We also need to preserve the existing selection from changing. | |
4952 | // Unfortunately the only way to do it seems to use our own selection | |
4953 | // function and forbid any selection changes during set cursor call. | |
4954 | wxGtkTreeSelectionLock | |
4955 | lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview))); | |
4956 | ||
4957 | // Do move the cursor now. | |
4958 | GtkTreeIter iter; | |
4959 | iter.user_data = item.GetID(); | |
4960 | wxGtkTreePath path(m_internal->get_path( &iter )); | |
4961 | ||
4962 | gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview), path, gcolumn, TRUE); | |
4963 | } | |
4964 | ||
fa93d732 | 4965 | int wxDataViewCtrl::GetSelectedItemsCount() const |
1e08ad10 RR |
4966 | { |
4967 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); | |
b9db5f30 | 4968 | |
fa93d732 | 4969 | return gtk_tree_selection_count_selected_rows(selection); |
1e08ad10 RR |
4970 | } |
4971 | ||
718fd180 RR |
4972 | int wxDataViewCtrl::GetSelections( wxDataViewItemArray & sel ) const |
4973 | { | |
6848478c RR |
4974 | sel.Clear(); |
4975 | ||
4976 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); | |
4977 | if (HasFlag(wxDV_MULTIPLE)) | |
4978 | { | |
4979 | GtkTreeModel *model; | |
0eec47e4 | 4980 | wxGtkTreePathList list(gtk_tree_selection_get_selected_rows(selection, &model)); |
6848478c | 4981 | |
0eec47e4 | 4982 | for ( GList* current = list; current; current = g_list_next(current) ) |
6848478c | 4983 | { |
fa93d732 | 4984 | GtkTreePath *path = (GtkTreePath*) current->data; |
b9db5f30 | 4985 | |
17d98558 | 4986 | sel.Add(GTKPathToItem(path)); |
6848478c | 4987 | } |
6848478c RR |
4988 | } |
4989 | else | |
4990 | { | |
6848478c | 4991 | GtkTreeIter iter; |
fa93d732 | 4992 | if (gtk_tree_selection_get_selected( selection, NULL, &iter )) |
6848478c | 4993 | { |
fa93d732 | 4994 | sel.Add( wxDataViewItem(iter.user_data) ); |
6848478c RR |
4995 | } |
4996 | } | |
4997 | ||
fa93d732 | 4998 | return sel.size(); |
718fd180 RR |
4999 | } |
5000 | ||
5001 | void wxDataViewCtrl::SetSelections( const wxDataViewItemArray & sel ) | |
5002 | { | |
6848478c | 5003 | GtkDisableSelectionEvents(); |
b9db5f30 | 5004 | |
6848478c RR |
5005 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); |
5006 | ||
5007 | gtk_tree_selection_unselect_all( selection ); | |
b9db5f30 | 5008 | |
4219d8b0 RR |
5009 | wxDataViewItem last_parent; |
5010 | ||
6848478c RR |
5011 | size_t i; |
5012 | for (i = 0; i < sel.GetCount(); i++) | |
5013 | { | |
4219d8b0 RR |
5014 | wxDataViewItem item = sel[i]; |
5015 | wxDataViewItem parent = GetModel()->GetParent( item ); | |
5016 | if (parent) | |
5017 | { | |
5018 | if (parent != last_parent) | |
5019 | ExpandAncestors(item); | |
5020 | } | |
5021 | last_parent = parent; | |
5022 | ||
6848478c | 5023 | GtkTreeIter iter; |
0e50223f | 5024 | iter.stamp = m_internal->GetGtkModel()->stamp; |
4219d8b0 | 5025 | iter.user_data = (gpointer) item.GetID(); |
6848478c RR |
5026 | gtk_tree_selection_select_iter( selection, &iter ); |
5027 | } | |
b9db5f30 | 5028 | |
6848478c | 5029 | GtkEnableSelectionEvents(); |
718fd180 RR |
5030 | } |
5031 | ||
5032 | void wxDataViewCtrl::Select( const wxDataViewItem & item ) | |
5033 | { | |
4219d8b0 RR |
5034 | ExpandAncestors(item); |
5035 | ||
6848478c RR |
5036 | GtkDisableSelectionEvents(); |
5037 | ||
5038 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); | |
5039 | ||
5040 | GtkTreeIter iter; | |
0e50223f | 5041 | iter.stamp = m_internal->GetGtkModel()->stamp; |
6848478c RR |
5042 | iter.user_data = (gpointer) item.GetID(); |
5043 | gtk_tree_selection_select_iter( selection, &iter ); | |
5044 | ||
5045 | GtkEnableSelectionEvents(); | |
718fd180 RR |
5046 | } |
5047 | ||
5048 | void wxDataViewCtrl::Unselect( const wxDataViewItem & item ) | |
5049 | { | |
6848478c RR |
5050 | GtkDisableSelectionEvents(); |
5051 | ||
5052 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); | |
5053 | ||
5054 | GtkTreeIter iter; | |
0e50223f | 5055 | iter.stamp = m_internal->GetGtkModel()->stamp; |
6848478c RR |
5056 | iter.user_data = (gpointer) item.GetID(); |
5057 | gtk_tree_selection_unselect_iter( selection, &iter ); | |
5058 | ||
5059 | GtkEnableSelectionEvents(); | |
718fd180 RR |
5060 | } |
5061 | ||
5062 | bool wxDataViewCtrl::IsSelected( const wxDataViewItem & item ) const | |
5063 | { | |
6848478c RR |
5064 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); |
5065 | ||
5066 | GtkTreeIter iter; | |
0e50223f | 5067 | iter.stamp = m_internal->GetGtkModel()->stamp; |
6848478c | 5068 | iter.user_data = (gpointer) item.GetID(); |
b9db5f30 | 5069 | |
d5027818 | 5070 | return gtk_tree_selection_iter_is_selected( selection, &iter ) != 0; |
718fd180 RR |
5071 | } |
5072 | ||
5073 | void wxDataViewCtrl::SelectAll() | |
5074 | { | |
6848478c | 5075 | GtkDisableSelectionEvents(); |
b9db5f30 | 5076 | |
6848478c | 5077 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); |
b9db5f30 | 5078 | |
6848478c | 5079 | gtk_tree_selection_select_all( selection ); |
b9db5f30 | 5080 | |
6848478c | 5081 | GtkEnableSelectionEvents(); |
718fd180 RR |
5082 | } |
5083 | ||
5084 | void wxDataViewCtrl::UnselectAll() | |
5085 | { | |
6848478c | 5086 | GtkDisableSelectionEvents(); |
b9db5f30 | 5087 | |
6848478c | 5088 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); |
b9db5f30 | 5089 | |
6848478c | 5090 | gtk_tree_selection_unselect_all( selection ); |
b9db5f30 | 5091 | |
6848478c | 5092 | GtkEnableSelectionEvents(); |
718fd180 RR |
5093 | } |
5094 | ||
7857346a | 5095 | void wxDataViewCtrl::EnsureVisible(const wxDataViewItem& item, |
4219d8b0 | 5096 | const wxDataViewColumn *WXUNUSED(column)) |
718fd180 | 5097 | { |
3f53dd3a | 5098 | m_ensureVisibleDefered = item; |
4219d8b0 | 5099 | ExpandAncestors(item); |
a881f34e | 5100 | |
6154212e RR |
5101 | GtkTreeIter iter; |
5102 | iter.user_data = (gpointer) item.GetID(); | |
0c2a7270 | 5103 | wxGtkTreePath path(m_internal->get_path( &iter )); |
6154212e | 5104 | gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview), path, NULL, false, 0.0, 0.0 ); |
718fd180 RR |
5105 | } |
5106 | ||
cd771560 | 5107 | void wxDataViewCtrl::HitTest(const wxPoint& point, |
7857346a VZ |
5108 | wxDataViewItem& item, |
5109 | wxDataViewColumn *& column) const | |
66e09788 | 5110 | { |
cd771560 RR |
5111 | // gtk_tree_view_get_dest_row_at_pos() is the right one. But it does not tell the column. |
5112 | // gtk_tree_view_get_path_at_pos() is the wrong function. It doesn't mind the header but returns column. | |
5113 | // See http://mail.gnome.org/archives/gtkmm-list/2005-January/msg00080.html | |
5114 | // So we have to use both of them. | |
7e98c451 VZ |
5115 | item = wxDataViewItem(0); |
5116 | column = NULL; | |
cd771560 RR |
5117 | wxGtkTreePath path, pathScratch; |
5118 | GtkTreeViewColumn* GtkColumn = NULL; | |
5119 | GtkTreeViewDropPosition pos = GTK_TREE_VIEW_DROP_INTO_OR_AFTER; | |
5120 | gint cell_x = 0; | |
5121 | gint cell_y = 0; | |
5122 | ||
5123 | // cannot directly call GtkGetTreeView(), HitTest is const and so is this pointer | |
7e98c451 VZ |
5124 | wxDataViewCtrl* self = const_cast<wxDataViewCtrl *>(this); // ugly workaround, self is NOT const |
5125 | GtkTreeView* treeView = GTK_TREE_VIEW(self->GtkGetTreeView()); | |
cd771560 RR |
5126 | |
5127 | // is there possibly a better suited function to get the column? | |
5128 | gtk_tree_view_get_path_at_pos( // and this is the wrong call but it delivers the column | |
5129 | treeView, | |
5130 | (int) point.x, (int) point.y, | |
5131 | pathScratch.ByRef(), | |
5132 | &GtkColumn, // here we get the GtkColumn | |
5133 | &cell_x, | |
5134 | &cell_y ); | |
5135 | ||
5136 | if ( GtkColumn != NULL ) | |
5137 | { | |
5138 | // we got GTK column | |
5139 | // the right call now which takes the header into account | |
5140 | gtk_tree_view_get_dest_row_at_pos( treeView, (int) point.x, (int) point.y, path.ByRef(), &pos); | |
5141 | ||
5142 | if (path) | |
5143 | item = wxDataViewItem(GTKPathToItem(path)); | |
5144 | // else we got a GTK column but the position is not over an item, e.g. below last item | |
5145 | for ( unsigned int i=0, cols=GetColumnCount(); i<cols; ++i ) // search the wx column | |
5146 | { | |
5147 | wxDataViewColumn* col = GetColumn(i); | |
5148 | if ( GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) == GtkColumn ) | |
5149 | { | |
5150 | column = col; // here we get the wx column | |
5151 | break; | |
5152 | } | |
5153 | } | |
5154 | } | |
5155 | // else no column and thus no item, both null | |
66e09788 RR |
5156 | } |
5157 | ||
7857346a VZ |
5158 | wxRect |
5159 | wxDataViewCtrl::GetItemRect(const wxDataViewItem& WXUNUSED(item), | |
5160 | const wxDataViewColumn *WXUNUSED(column)) const | |
66e09788 RR |
5161 | { |
5162 | return wxRect(); | |
5163 | } | |
5164 | ||
0f4a54a6 VZ |
5165 | bool wxDataViewCtrl::SetRowHeight(int rowHeight) |
5166 | { | |
5167 | m_uniformRowHeight = rowHeight; | |
5168 | return true; | |
5169 | } | |
5170 | ||
3b6280be RR |
5171 | void wxDataViewCtrl::DoSetExpanderColumn() |
5172 | { | |
b9db5f30 | 5173 | gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview), |
1b27b2bd | 5174 | GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) ); |
3b6280be RR |
5175 | } |
5176 | ||
5177 | void wxDataViewCtrl::DoSetIndent() | |
5178 | { | |
5179 | } | |
5180 | ||
b086d55f RR |
5181 | void wxDataViewCtrl::GtkDisableSelectionEvents() |
5182 | { | |
5183 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); | |
6848478c RR |
5184 | g_signal_handlers_disconnect_by_func( selection, |
5185 | (gpointer) (wxdataview_selection_changed_callback), this); | |
b086d55f RR |
5186 | } |
5187 | ||
5188 | void wxDataViewCtrl::GtkEnableSelectionEvents() | |
5189 | { | |
5190 | GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); | |
6848478c RR |
5191 | g_signal_connect_after (selection, "changed", |
5192 | G_CALLBACK (wxdataview_selection_changed_callback), this); | |
b086d55f RR |
5193 | } |
5194 | ||
ddb44248 VZ |
5195 | // ---------------------------------------------------------------------------- |
5196 | // visual attributes stuff | |
5197 | // ---------------------------------------------------------------------------- | |
5198 | ||
b94db696 RR |
5199 | // static |
5200 | wxVisualAttributes | |
5201 | wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
5202 | { | |
5203 | return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new); | |
5204 | } | |
5205 | ||
ddb44248 VZ |
5206 | void wxDataViewCtrl::DoApplyWidgetStyle(GtkRcStyle *style) |
5207 | { | |
5208 | wxDataViewCtrlBase::DoApplyWidgetStyle(style); | |
9dc44eff | 5209 | GTKApplyStyle(m_treeview, style); |
ddb44248 | 5210 | } |
6ff7eee7 | 5211 | |
ddb44248 | 5212 | #endif // !wxUSE_GENERICDATAVIEWCTRL |
790b137e | 5213 | |
ddb44248 | 5214 | #endif // wxUSE_DATAVIEWCTRL |