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