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