"Fossies" - the Fresh Open Source Software Archive

Member "glibmm-2.74.0/untracked/gio/giomm/actionmap.cc" (19 Sep 2022, 13362 Bytes) of package /linux/misc/glibmm-2.74.0.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "actionmap.cc" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes reports: 2.73.2_vs_2.74.0 or 2.72.1_vs_2.74.0.

    1 // Generated by gmmproc 2.74.0 -- DO NOT MODIFY!
    2 
    3 
    4 #include <glibmm.h>
    5 
    6 #include <giomm/actionmap.h>
    7 #include <giomm/private/actionmap_p.h>
    8 
    9 
   10 /* Copyright (C) 2012 The giomm Development Team
   11  *
   12  * This library is free software; you can redistribute it and/or
   13  * modify it under the terms of the GNU Lesser General Public
   14  * License as published by the Free Software Foundation; either
   15  * version 2.1 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  * Lesser General Public License for more details.
   21  *
   22  * You should have received a copy of the GNU Lesser General Public
   23  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
   24  */
   25 
   26 #include <giomm/action.h>
   27 #include <giomm/simpleaction.h>
   28 
   29 namespace Gio
   30 {
   31 
   32 Glib::RefPtr<SimpleAction>
   33 ActionMap::add_action(const Glib::ustring& name)
   34 {
   35   auto action = SimpleAction::create(name);
   36   add_action(action);
   37   return action;
   38 }
   39 
   40 Glib::RefPtr<SimpleAction>
   41 ActionMap::add_action(const Glib::ustring& name, const ActivateSlot& slot)
   42 {
   43   auto action = add_action(name);
   44   action->signal_activate().connect(sigc::hide(slot));
   45   return action;
   46 }
   47 
   48 Glib::RefPtr<SimpleAction>
   49 ActionMap::add_action_with_parameter(
   50   const Glib::ustring& name, const Glib::VariantType& parameter_type, const ActivateWithParameterSlot& slot)
   51 {
   52   auto action = SimpleAction::create(name, parameter_type);
   53   action->signal_activate().connect(slot);
   54   add_action(action);
   55   return action;
   56 }
   57 
   58 Glib::RefPtr<SimpleAction>
   59 ActionMap::add_action_bool(const Glib::ustring& name, bool state)
   60 {
   61   auto action = SimpleAction::create_bool(name, state);
   62   add_action(action);
   63   return action;
   64 }
   65 
   66 // TODO: Use a slot that takes a bool?
   67 Glib::RefPtr<SimpleAction>
   68 ActionMap::add_action_bool(const Glib::ustring& name, const ActivateSlot& slot, bool state)
   69 {
   70   auto action = add_action_bool(name, state);
   71   action->signal_activate().connect(sigc::hide(slot));
   72   return action;
   73 }
   74 
   75 // TODO: Use a slot that takes a string?
   76 Glib::RefPtr<SimpleAction>
   77 ActionMap::add_action_radio_string(const Glib::ustring& name, const Glib::ustring& state)
   78 {
   79   auto action = SimpleAction::create_radio_string(name, state);
   80   add_action(action);
   81   return action;
   82 }
   83 
   84 namespace
   85 {
   86 
   87 // Handle the normal activate signal, calling instead a slot that takes the specific type:
   88 static void
   89 on_action_radio_string(
   90   const Glib::VariantBase& parameter, const Gio::ActionMap::ActivateWithStringParameterSlot& slot)
   91 {
   92   const auto variantDerived = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(parameter);
   93   const auto str = variantDerived.get();
   94   slot(str);
   95 }
   96 
   97 } // anonymous namespace
   98 
   99 Glib::RefPtr<SimpleAction>
  100 ActionMap::add_action_radio_string(const Glib::ustring& name,
  101   const ActivateWithStringParameterSlot& slot, const Glib::ustring& state)
  102 {
  103   auto action = add_action_radio_string(name, state);
  104   action->signal_activate().connect(sigc::bind(sigc::ptr_fun(&on_action_radio_string), slot));
  105   return action;
  106 }
  107 
  108 namespace
  109 {
  110 
  111 // Handle the normal activate signal, calling instead a slot that takes the specific type:
  112 static void
  113 on_action_radio_int(
  114   const Glib::VariantBase& parameter, const Gio::ActionMap::ActivateWithIntParameterSlot& slot)
  115 {
  116   const auto variantDerived = Glib::VariantBase::cast_dynamic<Glib::Variant<int>>(parameter);
  117   const auto str = variantDerived.get();
  118   slot(str);
  119 }
  120 
  121 } // anonymous namespace
  122 
  123 // TODO: Use a slot that takes an integer?
  124 Glib::RefPtr<SimpleAction>
  125 ActionMap::add_action_radio_integer(const Glib::ustring& name, gint32 state)
  126 {
  127   auto action = SimpleAction::create_radio_integer(name, state);
  128   add_action(action);
  129   return action;
  130 }
  131 
  132 Glib::RefPtr<SimpleAction>
  133 ActionMap::add_action_radio_integer(
  134   const Glib::ustring& name, const ActivateWithIntParameterSlot& slot, gint32 state)
  135 {
  136   auto action = add_action_radio_integer(name, state);
  137   action->signal_activate().connect(sigc::bind(sigc::ptr_fun(&on_action_radio_int), slot));
  138   return action;
  139 }
  140 
  141 } // namespace Gio
  142 
  143 namespace
  144 {
  145 } // anonymous namespace
  146 
  147 
  148 namespace Glib
  149 {
  150 
  151 Glib::RefPtr<Gio::ActionMap> wrap(GActionMap* object, bool take_copy)
  152 {
  153   return Glib::make_refptr_for_instance<Gio::ActionMap>( dynamic_cast<Gio::ActionMap*> (Glib::wrap_auto_interface<Gio::ActionMap> ((GObject*)(object), take_copy)) );
  154   //We use dynamic_cast<> in case of multiple inheritance.
  155 }
  156 
  157 } // namespace Glib
  158 
  159 
  160 namespace Gio
  161 {
  162 
  163 
  164 /* The *_Class implementation: */
  165 
  166 const Glib::Interface_Class& ActionMap_Class::init()
  167 {
  168   if(!gtype_) // create the GType if necessary
  169   {
  170     // Glib::Interface_Class has to know the interface init function
  171     // in order to add interfaces to implementing types.
  172     class_init_func_ = &ActionMap_Class::iface_init_function;
  173 
  174     // We can not derive from another interface, and it is not necessary anyway.
  175     gtype_ = g_action_map_get_type();
  176   }
  177 
  178   return *this;
  179 }
  180 
  181 void ActionMap_Class::iface_init_function(void* g_iface, void*)
  182 {
  183   const auto klass = static_cast<BaseClassType*>(g_iface);
  184 
  185   //This is just to avoid an "unused variable" warning when there are no vfuncs or signal handlers to connect.
  186   //This is a temporary fix until I find out why I can not seem to derive a GtkFileChooser interface. murrayc
  187   g_assert(klass != nullptr);
  188 
  189   klass->lookup_action = &lookup_action_vfunc_callback;
  190   klass->add_action = &add_action_vfunc_callback;
  191   klass->remove_action = &remove_action_vfunc_callback;
  192 
  193 }
  194 
  195 GAction* ActionMap_Class::lookup_action_vfunc_callback(GActionMap* self, const gchar* action_name)
  196 {
  197   const auto obj_base = static_cast<Glib::ObjectBase*>(
  198       Glib::ObjectBase::_get_current_wrapper((GObject*)self));
  199 
  200   // Non-gtkmmproc-generated custom classes implicitly call the default
  201   // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
  202   // generated classes can use this optimisation, which avoids the unnecessary
  203   // parameter conversions if there is no possibility of the virtual function
  204   // being overridden:
  205   if(obj_base && obj_base->is_derived_())
  206   {
  207     const auto obj = dynamic_cast<CppObjectType* const>(obj_base);
  208     if(obj) // This can be NULL during destruction.
  209     {
  210       try // Trap C++ exceptions which would normally be lost because this is a C callback.
  211       {
  212         // Call the virtual member method, which derived classes might override.
  213         return Glib::unwrap(obj->lookup_action_vfunc(Glib::convert_const_gchar_ptr_to_ustring(action_name)
  214 ));
  215       }
  216       catch(...)
  217       {
  218         Glib::exception_handlers_invoke();
  219       }
  220     }
  221   }
  222 
  223   BaseClassType *const base = static_cast<BaseClassType*>(
  224       g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C interface).
  225 g_type_interface_peek(G_OBJECT_GET_CLASS(self), CppObjectType::get_type()) // Get the interface.
  226 )  );
  227 
  228   // Call the original underlying C function:
  229   if(base && base->lookup_action)
  230     return (*base->lookup_action)(self, action_name);
  231 
  232   using RType = GAction*;
  233   return RType();
  234 }
  235 void ActionMap_Class::add_action_vfunc_callback(GActionMap* self, GAction* action)
  236 {
  237   const auto obj_base = static_cast<Glib::ObjectBase*>(
  238       Glib::ObjectBase::_get_current_wrapper((GObject*)self));
  239 
  240   // Non-gtkmmproc-generated custom classes implicitly call the default
  241   // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
  242   // generated classes can use this optimisation, which avoids the unnecessary
  243   // parameter conversions if there is no possibility of the virtual function
  244   // being overridden:
  245   if(obj_base && obj_base->is_derived_())
  246   {
  247     const auto obj = dynamic_cast<CppObjectType* const>(obj_base);
  248     if(obj) // This can be NULL during destruction.
  249     {
  250       try // Trap C++ exceptions which would normally be lost because this is a C callback.
  251       {
  252         // Call the virtual member method, which derived classes might override.
  253         obj->add_action_vfunc(Glib::wrap(action, true)
  254 );
  255         return;
  256       }
  257       catch(...)
  258       {
  259         Glib::exception_handlers_invoke();
  260       }
  261     }
  262   }
  263 
  264   BaseClassType *const base = static_cast<BaseClassType*>(
  265       g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C interface).
  266 g_type_interface_peek(G_OBJECT_GET_CLASS(self), CppObjectType::get_type()) // Get the interface.
  267 )  );
  268 
  269   // Call the original underlying C function:
  270   if(base && base->add_action)
  271     (*base->add_action)(self, action);
  272 }
  273 void ActionMap_Class::remove_action_vfunc_callback(GActionMap* self, const gchar* action_name)
  274 {
  275   const auto obj_base = static_cast<Glib::ObjectBase*>(
  276       Glib::ObjectBase::_get_current_wrapper((GObject*)self));
  277 
  278   // Non-gtkmmproc-generated custom classes implicitly call the default
  279   // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
  280   // generated classes can use this optimisation, which avoids the unnecessary
  281   // parameter conversions if there is no possibility of the virtual function
  282   // being overridden:
  283   if(obj_base && obj_base->is_derived_())
  284   {
  285     const auto obj = dynamic_cast<CppObjectType* const>(obj_base);
  286     if(obj) // This can be NULL during destruction.
  287     {
  288       try // Trap C++ exceptions which would normally be lost because this is a C callback.
  289       {
  290         // Call the virtual member method, which derived classes might override.
  291         obj->remove_action_vfunc(Glib::convert_const_gchar_ptr_to_ustring(action_name)
  292 );
  293         return;
  294       }
  295       catch(...)
  296       {
  297         Glib::exception_handlers_invoke();
  298       }
  299     }
  300   }
  301 
  302   BaseClassType *const base = static_cast<BaseClassType*>(
  303       g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C interface).
  304 g_type_interface_peek(G_OBJECT_GET_CLASS(self), CppObjectType::get_type()) // Get the interface.
  305 )  );
  306 
  307   // Call the original underlying C function:
  308   if(base && base->remove_action)
  309     (*base->remove_action)(self, action_name);
  310 }
  311 
  312 
  313 Glib::ObjectBase* ActionMap_Class::wrap_new(GObject* object)
  314 {
  315   return new ActionMap((GActionMap*)(object));
  316 }
  317 
  318 
  319 /* The implementation: */
  320 
  321 ActionMap::ActionMap()
  322 :
  323   Glib::Interface(actionmap_class_.init())
  324 {}
  325 
  326 ActionMap::ActionMap(GActionMap* castitem)
  327 :
  328   Glib::Interface((GObject*)(castitem))
  329 {}
  330 
  331 ActionMap::ActionMap(const Glib::Interface_Class& interface_class)
  332 : Glib::Interface(interface_class)
  333 {
  334 }
  335 
  336 ActionMap::ActionMap(ActionMap&& src) noexcept
  337 : Glib::Interface(std::move(src))
  338 {}
  339 
  340 ActionMap& ActionMap::operator=(ActionMap&& src) noexcept
  341 {
  342   Glib::Interface::operator=(std::move(src));
  343   return *this;
  344 }
  345 
  346 ActionMap::~ActionMap() noexcept
  347 {}
  348 
  349 // static
  350 void ActionMap::add_interface(GType gtype_implementer)
  351 {
  352   actionmap_class_.init().add_interface(gtype_implementer);
  353 }
  354 
  355 ActionMap::CppClassType ActionMap::actionmap_class_; // initialize static member
  356 
  357 GType ActionMap::get_type()
  358 {
  359   return actionmap_class_.init().get_type();
  360 }
  361 
  362 
  363 GType ActionMap::get_base_type()
  364 {
  365   return g_action_map_get_type();
  366 }
  367 
  368 
  369 void ActionMap::add_action(const Glib::RefPtr<Action>& action)
  370 {
  371   g_action_map_add_action(gobj(), Glib::unwrap(action));
  372 }
  373 
  374 void ActionMap::remove_action(const Glib::ustring& action_name)
  375 {
  376   g_action_map_remove_action(gobj(), action_name.c_str());
  377 }
  378 
  379 Glib::RefPtr<Action> ActionMap::lookup_action(const Glib::ustring& action_name)
  380 {
  381   auto retvalue = Glib::wrap(g_action_map_lookup_action(gobj(), action_name.c_str()));
  382   if(retvalue)
  383     retvalue->reference(); //The function does not do a ref for us.
  384   return retvalue;
  385 }
  386 
  387 Glib::RefPtr<const Action> ActionMap::lookup_action(const Glib::ustring& action_name) const
  388 {
  389   return const_cast<ActionMap*>(this)->lookup_action(action_name);
  390 }
  391 
  392 
  393 Glib::RefPtr<Action> Gio::ActionMap::lookup_action_vfunc(const Glib::ustring& name) const
  394 {
  395   const auto base = static_cast<BaseClassType*>(
  396       g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C interface).
  397 g_type_interface_peek(G_OBJECT_GET_CLASS(gobject_), CppObjectType::get_type()) // Get the interface.
  398 )  );
  399 
  400   if(base && base->lookup_action)
  401   {
  402     Glib::RefPtr<Action> retval(Glib::wrap((*base->lookup_action)(const_cast<GActionMap*>(gobj()),name.c_str()), true));
  403     return retval;
  404   }
  405 
  406   using RType = Glib::RefPtr<Action>;
  407   return RType();
  408 }
  409 void Gio::ActionMap::add_action_vfunc(const Glib::RefPtr<Action>& action) const
  410 {
  411   const auto base = static_cast<BaseClassType*>(
  412       g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C interface).
  413 g_type_interface_peek(G_OBJECT_GET_CLASS(gobject_), CppObjectType::get_type()) // Get the interface.
  414 )  );
  415 
  416   if(base && base->add_action)
  417   {
  418     (*base->add_action)(const_cast<GActionMap*>(gobj()),Glib::unwrap(action));
  419   }
  420 }
  421 void Gio::ActionMap::remove_action_vfunc(const Glib::ustring& name) 
  422 {
  423   const auto base = static_cast<BaseClassType*>(
  424       g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C interface).
  425 g_type_interface_peek(G_OBJECT_GET_CLASS(gobject_), CppObjectType::get_type()) // Get the interface.
  426 )  );
  427 
  428   if(base && base->remove_action)
  429   {
  430     (*base->remove_action)(gobj(),name.c_str());
  431   }
  432 }
  433 
  434 
  435 } // namespace Gio
  436 
  437