"Fossies" - the Fresh Open Source Software Archive

Member "glibmm-2.74.0/gio/src/actionmap.ccg" (19 Sep 2022, 4008 Bytes) of package /linux/misc/glibmm-2.74.0.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 /* Copyright (C) 2012 The giomm Development Team
    2  *
    3  * This library is free software; you can redistribute it and/or
    4  * modify it under the terms of the GNU Lesser General Public
    5  * License as published by the Free Software Foundation; either
    6  * version 2.1 of the License, or (at your option) any later version.
    7  *
    8  * This library is distributed in the hope that it will be useful,
    9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   11  * Lesser General Public License for more details.
   12  *
   13  * You should have received a copy of the GNU Lesser General Public
   14  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
   15  */
   16 
   17 #include <giomm/action.h>
   18 #include <giomm/simpleaction.h>
   19 
   20 namespace Gio
   21 {
   22 
   23 Glib::RefPtr<SimpleAction>
   24 ActionMap::add_action(const Glib::ustring& name)
   25 {
   26   auto action = SimpleAction::create(name);
   27   add_action(action);
   28   return action;
   29 }
   30 
   31 Glib::RefPtr<SimpleAction>
   32 ActionMap::add_action(const Glib::ustring& name, const ActivateSlot& slot)
   33 {
   34   auto action = add_action(name);
   35   action->signal_activate().connect(sigc::hide(slot));
   36   return action;
   37 }
   38 
   39 Glib::RefPtr<SimpleAction>
   40 ActionMap::add_action_with_parameter(
   41   const Glib::ustring& name, const Glib::VariantType& parameter_type, const ActivateWithParameterSlot& slot)
   42 {
   43   auto action = SimpleAction::create(name, parameter_type);
   44   action->signal_activate().connect(slot);
   45   add_action(action);
   46   return action;
   47 }
   48 
   49 Glib::RefPtr<SimpleAction>
   50 ActionMap::add_action_bool(const Glib::ustring& name, bool state)
   51 {
   52   auto action = SimpleAction::create_bool(name, state);
   53   add_action(action);
   54   return action;
   55 }
   56 
   57 // TODO: Use a slot that takes a bool?
   58 Glib::RefPtr<SimpleAction>
   59 ActionMap::add_action_bool(const Glib::ustring& name, const ActivateSlot& slot, bool state)
   60 {
   61   auto action = add_action_bool(name, state);
   62   action->signal_activate().connect(sigc::hide(slot));
   63   return action;
   64 }
   65 
   66 // TODO: Use a slot that takes a string?
   67 Glib::RefPtr<SimpleAction>
   68 ActionMap::add_action_radio_string(const Glib::ustring& name, const Glib::ustring& state)
   69 {
   70   auto action = SimpleAction::create_radio_string(name, state);
   71   add_action(action);
   72   return action;
   73 }
   74 
   75 namespace
   76 {
   77 
   78 // Handle the normal activate signal, calling instead a slot that takes the specific type:
   79 static void
   80 on_action_radio_string(
   81   const Glib::VariantBase& parameter, const Gio::ActionMap::ActivateWithStringParameterSlot& slot)
   82 {
   83   const auto variantDerived = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(parameter);
   84   const auto str = variantDerived.get();
   85   slot(str);
   86 }
   87 
   88 } // anonymous namespace
   89 
   90 Glib::RefPtr<SimpleAction>
   91 ActionMap::add_action_radio_string(const Glib::ustring& name,
   92   const ActivateWithStringParameterSlot& slot, const Glib::ustring& state)
   93 {
   94   auto action = add_action_radio_string(name, state);
   95   action->signal_activate().connect(sigc::bind(sigc::ptr_fun(&on_action_radio_string), slot));
   96   return action;
   97 }
   98 
   99 namespace
  100 {
  101 
  102 // Handle the normal activate signal, calling instead a slot that takes the specific type:
  103 static void
  104 on_action_radio_int(
  105   const Glib::VariantBase& parameter, const Gio::ActionMap::ActivateWithIntParameterSlot& slot)
  106 {
  107   const auto variantDerived = Glib::VariantBase::cast_dynamic<Glib::Variant<int>>(parameter);
  108   const auto str = variantDerived.get();
  109   slot(str);
  110 }
  111 
  112 } // anonymous namespace
  113 
  114 // TODO: Use a slot that takes an integer?
  115 Glib::RefPtr<SimpleAction>
  116 ActionMap::add_action_radio_integer(const Glib::ustring& name, gint32 state)
  117 {
  118   auto action = SimpleAction::create_radio_integer(name, state);
  119   add_action(action);
  120   return action;
  121 }
  122 
  123 Glib::RefPtr<SimpleAction>
  124 ActionMap::add_action_radio_integer(
  125   const Glib::ustring& name, const ActivateWithIntParameterSlot& slot, gint32 state)
  126 {
  127   auto action = add_action_radio_integer(name, state);
  128   action->signal_activate().connect(sigc::bind(sigc::ptr_fun(&on_action_radio_int), slot));
  129   return action;
  130 }
  131 
  132 } // namespace Gio