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