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