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