Install ardour as a binary, a script and a set of shared
[ardour.git] / libs / gtkmm2 / gtk / gtkmm / treeselection.cc
1 // Generated by gtkmmproc -- DO NOT MODIFY!
2
3 #include <gtkmm/treeselection.h>
4 #include <gtkmm/private/treeselection_p.h>
5
6 // -*- c++ -*-
7 /* $Id$ */
8
9 /* Copyright 1998-2002 The gtkmm Development Team
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the Free
23  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25
26 #include <gtkmm/treeview.h>
27 #include <gtk/gtktreeselection.h>
28
29
30 namespace
31 {
32
33 void proxy_foreach_selection_iter_callback(GtkTreeModel* model, GtkTreePath*, GtkTreeIter* iter, void* data)
34 {
35   typedef Gtk::TreeSelection::SlotForeachIter SlotType;
36   SlotType& slot = *static_cast<SlotType*>(data);
37
38   try
39   {
40     slot(Gtk::TreeModel::iterator(model, iter));
41   }
42   catch(...)
43   {
44     Glib::exception_handlers_invoke();
45   }
46 }
47
48 void proxy_foreach_selection_path_callback(GtkTreeModel*, GtkTreePath* path, GtkTreeIter*, void* data)
49 {
50   typedef Gtk::TreeSelection::SlotForeachPath SlotType;
51   SlotType& slot = *static_cast<SlotType*>(data);
52
53   try
54   {
55     slot(Gtk::TreeModel::Path(path, true));
56   }
57   catch(...)
58   {
59     Glib::exception_handlers_invoke();
60   }
61 }
62
63 void proxy_foreach_selection_path_and_iter_callback(GtkTreeModel* model, GtkTreePath* path,
64                                                     GtkTreeIter* iter, void* data)
65 {
66   typedef Gtk::TreeSelection::SlotForeachPathAndIter SlotType;
67   SlotType& slot = *static_cast<SlotType*>(data);
68
69   try
70   {
71     slot(Gtk::TreeModel::Path(path, true), Gtk::TreeModel::iterator(model, iter));
72   }
73   catch(...)
74   {
75     Glib::exception_handlers_invoke();
76   }
77 }
78
79
80 // This Signal Proxy allows the C++ coder to specify
81 // a sigc::slot instead of a static function.
82 class SignalProxy_Select
83 {
84 public:
85   typedef Gtk::TreeSelection::SlotSelect SlotType;
86
87   SignalProxy_Select(const SlotType& slot) : slot_(slot) {}
88   ~SignalProxy_Select();
89
90   static gboolean gtk_callback(GtkTreeSelection*, GtkTreeModel* model, GtkTreePath* path,
91                                gboolean path_currently_selected, void* data);
92
93   static void gtk_callback_destroy(void* data);
94
95 private:
96   SlotType slot_;
97 };
98
99 SignalProxy_Select::~SignalProxy_Select()
100 {}
101
102 gboolean SignalProxy_Select::gtk_callback(GtkTreeSelection*, GtkTreeModel* model, GtkTreePath* path,
103                                           gboolean path_currently_selected, void* data)
104 {
105   SignalProxy_Select *const self = static_cast<SignalProxy_Select*>(data);
106
107   try
108   {
109     return (self->slot_)(Glib::wrap(model, true),   // take copy
110                          Gtk::TreePath(path, true), // take copy
111                          path_currently_selected);
112   }
113   catch(...)
114   {
115     Glib::exception_handlers_invoke();
116   }
117
118   return 0;
119 }
120
121 void SignalProxy_Select::gtk_callback_destroy(void* data)
122 {
123   delete static_cast<SignalProxy_Select*>(data);
124 }
125
126 } // anonymous namespace
127
128
129 namespace Gtk
130 {
131
132 void TreeSelection::set_select_function(const SlotSelect& slot)
133 {
134   // Create a signal proxy.  A pointer to this will be passed
135   // through the callback's data parameter.  It will be deleted
136   // when SignalProxy_Select::gtk_callback_destroy() is called.
137   SignalProxy_Select *const pSignalProxy = new SignalProxy_Select(slot);
138
139   gtk_tree_selection_set_select_function(gobj(),
140       &SignalProxy_Select::gtk_callback, pSignalProxy,
141       &SignalProxy_Select::gtk_callback_destroy);
142 }
143
144 Glib::RefPtr<TreeModel> TreeSelection::get_model()
145 {
146   GtkTreeView *const tree_view = gtk_tree_selection_get_tree_view(gobj());
147   return Glib::wrap(gtk_tree_view_get_model(tree_view), true);
148 }
149
150 Glib::RefPtr<const TreeModel> TreeSelection::get_model() const
151 {
152   GtkTreeView *const tree_view = gtk_tree_selection_get_tree_view(const_cast<GtkTreeSelection*>(gobj()));
153   return Glib::wrap(gtk_tree_view_get_model(tree_view), true);
154 }
155
156 TreeModel::iterator TreeSelection::get_selected()
157 {
158   TreeModel::iterator iter;
159   GtkTreeModel* model_gobject = 0;
160
161   gtk_tree_selection_get_selected(gobj(), &model_gobject, iter.gobj());
162
163   iter.set_model_gobject(model_gobject);
164   return iter;
165 }
166
167 TreeModel::iterator TreeSelection::get_selected(Glib::RefPtr<TreeModel>& model)
168 {
169   TreeModel::iterator iter;
170   GtkTreeModel* model_gobject = 0;
171
172   gtk_tree_selection_get_selected(gobj(), &model_gobject, iter.gobj());
173
174   model = Glib::wrap(model_gobject, true);
175
176   iter.set_model_refptr(model);
177   return iter;
178 }
179
180 void TreeSelection::selected_foreach_iter(const SlotForeachIter& slot) const
181 {
182   SlotForeachIter slot_copy (slot);
183   gtk_tree_selection_selected_foreach(const_cast<GtkTreeSelection*>(gobj()), &proxy_foreach_selection_iter_callback, &slot_copy);
184 }
185
186 void TreeSelection::selected_foreach_path(const SlotForeachPath& slot) const
187 {
188   SlotForeachPath slot_copy (slot);
189   gtk_tree_selection_selected_foreach(const_cast<GtkTreeSelection*>(gobj()), &proxy_foreach_selection_path_callback, &slot_copy);
190 }
191
192 void TreeSelection::selected_foreach(const SlotForeachPathAndIter& slot) const
193 {
194   SlotForeachPathAndIter slot_copy (slot);
195   gtk_tree_selection_selected_foreach(const_cast<GtkTreeSelection*>(gobj()), &proxy_foreach_selection_path_and_iter_callback, &slot_copy);
196 }
197
198 TreeSelection::ListHandle_Path TreeSelection::get_selected_rows() const
199 {
200   return ListHandle_Path(gtk_tree_selection_get_selected_rows(
201       const_cast<GtkTreeSelection*>(gobj()), 0), Glib::OWNERSHIP_DEEP);
202 }
203
204 TreeSelection::ListHandle_Path TreeSelection::get_selected_rows(Glib::RefPtr<TreeModel>& model)
205 {
206   GtkTreeModel* model_gobject = 0;
207
208   const ListHandle_Path result (gtk_tree_selection_get_selected_rows(
209       const_cast<GtkTreeSelection*>(gobj()), &model_gobject), Glib::OWNERSHIP_DEEP);
210
211   model = Glib::wrap(model_gobject, true);
212   return result;
213 }
214
215 } // namespace Gtk
216
217
218 namespace
219 {
220
221 const Glib::SignalProxyInfo TreeSelection_signal_changed_info =
222 {
223   "changed",
224   (GCallback) &Glib::SignalProxyNormal::slot0_void_callback,
225   (GCallback) &Glib::SignalProxyNormal::slot0_void_callback
226 };
227
228 } // anonymous namespace
229
230
231 namespace Glib
232 {
233
234 Glib::RefPtr<Gtk::TreeSelection> wrap(GtkTreeSelection* object, bool take_copy)
235 {
236   return Glib::RefPtr<Gtk::TreeSelection>( dynamic_cast<Gtk::TreeSelection*> (Glib::wrap_auto ((GObject*)(object), take_copy)) );
237   //We use dynamic_cast<> in case of multiple inheritance.
238 }
239
240 } /* namespace Glib */
241
242
243 namespace Gtk
244 {
245
246
247 /* The *_Class implementation: */
248
249 const Glib::Class& TreeSelection_Class::init()
250 {
251   if(!gtype_) // create the GType if necessary
252   {
253     // Glib::Class has to know the class init function to clone custom types.
254     class_init_func_ = &TreeSelection_Class::class_init_function;
255
256     // This is actually just optimized away, apparently with no harm.
257     // Make sure that the parent type has been created.
258     //CppClassParent::CppObjectType::get_type();
259
260     // Create the wrapper type, with the same class/instance size as the base type.
261     register_derived_type(gtk_tree_selection_get_type());
262
263     // Add derived versions of interfaces, if the C type implements any interfaces:
264   }
265
266   return *this;
267 }
268
269 void TreeSelection_Class::class_init_function(void* g_class, void* class_data)
270 {
271   BaseClassType *const klass = static_cast<BaseClassType*>(g_class);
272   CppClassParent::class_init_function(klass, class_data);
273
274   klass->changed = &changed_callback;
275 }
276
277
278 void TreeSelection_Class::changed_callback(GtkTreeSelection* self)
279 {
280   CppObjectType *const obj = dynamic_cast<CppObjectType*>(
281       Glib::ObjectBase::_get_current_wrapper((GObject*)self));
282
283   // Non-gtkmmproc-generated custom classes implicitly call the default
284   // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
285   // generated classes can use this optimisation, which avoids the unnecessary
286   // parameter conversions if there is no possibility of the virtual function
287   // being overridden:
288   if(obj && obj->is_derived_())
289   {
290     try // Trap C++ exceptions which would normally be lost because this is a C callback.
291     {
292       // Call the virtual member method, which derived classes might override.
293       obj->on_changed();
294     }
295     catch(...)
296     {
297       Glib::exception_handlers_invoke();
298     }
299   }
300   else
301   {
302     BaseClassType *const base = static_cast<BaseClassType*>(
303         g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
304     );
305
306     // Call the original underlying C function:
307     if(base && base->changed)
308       (*base->changed)(self);
309   }
310 }
311
312
313 Glib::ObjectBase* TreeSelection_Class::wrap_new(GObject* object)
314 {
315   return new TreeSelection((GtkTreeSelection*)object);
316 }
317
318
319 /* The implementation: */
320
321 GtkTreeSelection* TreeSelection::gobj_copy()
322 {
323   reference();
324   return gobj();
325 }
326
327 TreeSelection::TreeSelection(const Glib::ConstructParams& construct_params)
328 :
329   Glib::Object(construct_params)
330 {}
331
332 TreeSelection::TreeSelection(GtkTreeSelection* castitem)
333 :
334   Glib::Object((GObject*)(castitem))
335 {}
336
337 TreeSelection::~TreeSelection()
338 {}
339
340
341 TreeSelection::CppClassType TreeSelection::treeselection_class_; // initialize static member
342
343 GType TreeSelection::get_type()
344 {
345   return treeselection_class_.init().get_type();
346 }
347
348 GType TreeSelection::get_base_type()
349 {
350   return gtk_tree_selection_get_type();
351 }
352
353
354 void TreeSelection::set_mode(SelectionMode type)
355 {
356   gtk_tree_selection_set_mode(gobj(), ((GtkSelectionMode)(type)));
357 }
358
359 SelectionMode TreeSelection::get_mode() const
360 {
361   return ((SelectionMode)(gtk_tree_selection_get_mode(const_cast<GtkTreeSelection*>(gobj()))));
362 }
363
364 TreeView* TreeSelection::get_tree_view()
365 {
366   return Glib::wrap(gtk_tree_selection_get_tree_view(gobj()));
367 }
368
369 const TreeView* TreeSelection::get_tree_view() const
370 {
371   return Glib::wrap(gtk_tree_selection_get_tree_view(const_cast<GtkTreeSelection*>(gobj())));
372 }
373
374 int TreeSelection::count_selected_rows() const
375 {
376   return gtk_tree_selection_count_selected_rows(const_cast<GtkTreeSelection*>(gobj()));
377 }
378
379 void TreeSelection::select(const TreeModel::Path& path)
380 {
381   gtk_tree_selection_select_path(gobj(), const_cast<GtkTreePath*>((path).gobj()));
382 }
383
384 void TreeSelection::select(const TreeModel::iterator& iter)
385 {
386   gtk_tree_selection_select_iter(gobj(), const_cast<GtkTreeIter*>((iter).gobj()));
387 }
388
389 void TreeSelection::select(const TreeModel::Row& row)
390 {
391   gtk_tree_selection_select_iter(gobj(), const_cast<GtkTreeIter*>((row).gobj()));
392 }
393
394 void TreeSelection::select(const TreeModel::Path& start_path, const TreeModel::Path& end_path)
395 {
396   gtk_tree_selection_select_range(gobj(), const_cast<GtkTreePath*>((start_path).gobj()), const_cast<GtkTreePath*>((end_path).gobj()));
397 }
398
399 void TreeSelection::unselect(const TreeModel::Path& path)
400 {
401   gtk_tree_selection_unselect_path(gobj(), const_cast<GtkTreePath*>((path).gobj()));
402 }
403
404 void TreeSelection::unselect(const TreeModel::Path& start_path, const TreeModel::Path& end_path)
405 {
406   gtk_tree_selection_unselect_range(gobj(), const_cast<GtkTreePath*>((start_path).gobj()), const_cast<GtkTreePath*>((end_path).gobj()));
407 }
408
409 void TreeSelection::unselect(const TreeModel::iterator& iter)
410 {
411   gtk_tree_selection_unselect_iter(gobj(), const_cast<GtkTreeIter*>((iter).gobj()));
412 }
413
414 bool TreeSelection::is_selected(const TreeModel::Path& path) const
415 {
416   return gtk_tree_selection_path_is_selected(const_cast<GtkTreeSelection*>(gobj()), const_cast<GtkTreePath*>((path).gobj()));
417 }
418
419 bool TreeSelection::is_selected(const TreeModel::iterator& iter) const
420 {
421   return gtk_tree_selection_iter_is_selected(const_cast<GtkTreeSelection*>(gobj()), const_cast<GtkTreeIter*>((iter).gobj()));
422 }
423
424 void TreeSelection::select_all()
425 {
426   gtk_tree_selection_select_all(gobj());
427 }
428
429 void TreeSelection::unselect_all()
430 {
431   gtk_tree_selection_unselect_all(gobj());
432 }
433
434
435 Glib::SignalProxy0< void > TreeSelection::signal_changed()
436 {
437   return Glib::SignalProxy0< void >(this, &TreeSelection_signal_changed_info);
438 }
439
440
441 void Gtk::TreeSelection::on_changed()
442 {
443   BaseClassType *const base = static_cast<BaseClassType*>(
444       g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
445   );
446
447   if(base && base->changed)
448     (*base->changed)(gobj());
449 }
450
451
452 } // namespace Gtk
453
454