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