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