add new sigc++2 directory
[ardour.git] / libs / gtkmm2 / gtk / src / treedragsource.ccg
1 // -*- c++ -*-
2 /* $Id: treedragsource.ccg,v 1.4 2006/05/11 11:40:24 murrayc Exp $ */
3
4 /* Copyright 1998-2002 The gtkmm Development Team
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20
21 #include <gtkmm/treepath.h>
22 #include <gtkmm/selectiondata_private.h> //For SelectionData_WithoutOwnership
23 #include <gtk/gtktreednd.h>
24
25
26 namespace Gtk
27 {
28
29 #ifdef GLIBMM_VFUNCS_ENABLED
30 //This vfunc wrapper is manually written, so that we can use a temporary instance for the SelectionData& output parameter:
31
32 gboolean TreeDragSource_Class::drag_data_get_vfunc_callback(GtkTreeDragSource* self, GtkTreePath* path, GtkSelectionData* selection_data)
33 {
34   CppObjectType *const obj = dynamic_cast<CppObjectType*>(
35       Glib::ObjectBase::_get_current_wrapper((GObject*)self));
36
37   // Non-gtkmmproc-generated custom classes implicitly call the default
38   // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
39   // generated classes can use this optimisation, which avoids the unnecessary
40   // parameter conversions if there is no possibility of the virtual function
41   // being overridden:
42   if(obj && obj->is_derived_())
43   {
44     #ifdef GLIBMM_EXCEPTIONS_ENABLED
45     try // Trap C++ exceptions which would normally be lost because this is a C callback.
46     {
47     #endif //GLIBMM_EXCEPTIONS_ENABLED
48       // Call the virtual member method, which derived classes might override.
49       SelectionData_WithoutOwnership temp_instance(selection_data);
50       return static_cast<int>(obj->drag_data_get_vfunc(Gtk::TreePath(path, true), temp_instance));
51     #ifdef GLIBMM_EXCEPTIONS_ENABLED
52     }
53     catch(...)
54     {
55       Glib::exception_handlers_invoke();
56     }
57     #endif //GLIBMM_EXCEPTIONS_ENABLED
58   }
59   else
60   {
61     BaseClassType *const base = static_cast<BaseClassType*>(
62         g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C interface).
63 g_type_interface_peek(G_OBJECT_GET_CLASS(self), CppObjectType::get_type()) // Get the interface.
64 )    );
65
66     // Call the original underlying C function:
67     if(base && base->drag_data_get)
68       return (*base->drag_data_get)(self, path, selection_data);
69   }
70
71   typedef gboolean RType;
72   return RType();
73 }
74
75 bool Gtk::TreeDragSource::drag_data_get_vfunc(const TreeModel::Path& path, SelectionData& selection_data) const
76 {
77   BaseClassType *const base = static_cast<BaseClassType*>(
78       g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C interface).
79 g_type_interface_peek(G_OBJECT_GET_CLASS(gobject_), CppObjectType::get_type()) // Get the interface.
80 )  );
81
82   if(base && base->drag_data_get)
83     return (*base->drag_data_get)(const_cast<GtkTreeDragSource*>(gobj()),const_cast<GtkTreePath*>((path).gobj()), selection_data.gobj());
84
85   typedef bool RType;
86   return RType();
87 }
88 #endif //GLIBMM_VFUNCS_ENABLED
89
90 } //namespace Gtk
91