"Fossies" - the Fresh Open Source Software Archive

Member "glibmm-2.76.0/gio/src/actionmap.hg" (12 Mar 2023, 7784 Bytes) of package /linux/misc/glibmm-2.76.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 <glibmm/interface.h>
   18 #include <giomm/simpleaction.h>
   19 
   20 _DEFS(giomm,gio)
   21 _PINCLUDE(glibmm/private/interface_p.h)
   22 _PINCLUDE(gio/gio.h)
   23 
   24 #ifndef DOXYGEN_SHOULD_SKIP_THIS
   25 typedef struct _GActionMapInterface GActionMapInterface;
   26 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
   27 
   28 namespace Gio
   29 {
   30 
   31 class GIOMM_API Action;
   32 
   33 /** ActionMap - Interface for action containers.
   34  * The ActionMap interface is implemented by ActionGroup implementations that
   35  * operate by containing a number of named Action instances, such as
   36  * SimpleActionGroup.
   37  *
   38  * One useful application of this interface is to map the names of actions from
   39  * various action groups to unique, prefixed names (e.g. by prepending "app."
   40  * or "win."). This is the motivation for the 'Map' part of the interface name.
   41  * @newin{2,32}
   42  */
   43 class GIOMM_API ActionMap : public Glib::Interface
   44 {
   45   _CLASS_INTERFACE(ActionMap, GActionMap, G_ACTION_MAP, GActionMapInterface, , , GIOMM_API)
   46 
   47   // The various add_action...() methods are our equivalent for g_action_map_add_action_entries().
   48   _IGNORE(g_action_map_add_action_entries)
   49 
   50 public:
   51   _WRAP_METHOD(void add_action(const Glib::RefPtr<Action>& action), g_action_map_add_action)
   52   _WRAP_METHOD(void remove_action(const Glib::ustring& action_name), g_action_map_remove_action)
   53 
   54   _WRAP_METHOD(Glib::RefPtr<Action> lookup_action(const Glib::ustring& action_name), g_action_map_lookup_action, refreturn)
   55   _WRAP_METHOD(Glib::RefPtr<const Action> lookup_action(const Glib::ustring& action_name) const, g_action_map_lookup_action, constversion, refreturn)
   56 
   57 
   58   /** A convenience method for creating a SimpleAction instance
   59    * and adding it to the ActionMap.
   60    *
   61    * @param name The name of the Action.
   62    * @return The Action.
   63    */
   64   Glib::RefPtr<SimpleAction> add_action(const Glib::ustring& name);
   65 
   66   /** A Slot to be called when an action has been activated,
   67    * without passing a parameter to the slot.
   68    * See add_action() and add_action_bool().
   69    *
   70    * For instance,
   71    * void on_slot_activated();
   72    */
   73   using ActivateSlot = sigc::slot<void()>;
   74 
   75   /** A convenience method for creating a SimpleAction instance
   76    * and adding it to the ActionMap.
   77    *
   78    * @param name The name of the Action.
   79    * @param slot The callback method to be called when the action is activated.
   80    * @return The Action.
   81    */
   82   Glib::RefPtr<SimpleAction> add_action(const Glib::ustring& name, const ActivateSlot& slot);
   83 
   84 
   85   /** A Slot to be called when an action has been activated,
   86    * passing a parameter of a specified type.
   87    * See add_action_with_parameter().
   88    *
   89    * For instance,
   90    * void on_slot_activated(const Glib::VariantBase& parameter);
   91    */
   92   using ActivateWithParameterSlot = sigc::slot<void(const Glib::VariantBase&)>;
   93 
   94   /** A convenience method for creating a SimpleAction instance, which when
   95    * activated will call a slot receiving a given type of parameter, and adding
   96    * that SimpleAction to the ActionMap.
   97    *
   98    * @param name The name of the Action.
   99    * @param parameter_type The type of parameter to be passed to the slot.
  100    * @param slot The callback method to be called when the action is activated.
  101    * @return The Action.
  102    */
  103   Glib::RefPtr<SimpleAction> add_action_with_parameter(const Glib::ustring& name, const Glib::VariantType& parameter_type, const ActivateWithParameterSlot& slot);
  104 
  105 
  106   /** A convenience method for creating a boolean-stateful SimpleAction instance
  107    * and adding it to the ActionMap.
  108    *
  109    * @param name The name of the Action.
  110    * @param state The initial state.
  111    * @return The Action.
  112    */
  113   Glib::RefPtr<SimpleAction> add_action_bool(const Glib::ustring& name, bool state = false);
  114 
  115   /** A convenience method for creating a boolean-stateful (toggle) SimpleAction instance
  116    * and adding it to the ActionMap.
  117    *
  118    * @param name The name of the Action.
  119    * @param slot The callback method to be called when the action is activated.
  120    * @param state The initial state.
  121    * @return The Action.
  122    */
  123   Glib::RefPtr<SimpleAction> add_action_bool(const Glib::ustring& name, const ActivateSlot& slot, bool state = false);
  124 
  125 
  126 //TODO: Docs: Add hints about how to specify the various possible states in the GtkBuilder XML.
  127   /** A convenience method for creating a string-based radio SimpleAction instance
  128    * and adding it to the ActionMap.
  129    *
  130    * @param name The name of the Action.
  131    * @param state The initial state.
  132    * @return The Action.
  133    */
  134   Glib::RefPtr<SimpleAction> add_action_radio_string(const Glib::ustring& name, const Glib::ustring& state);
  135 
  136   /** A Slot to be called when an action has been activated.
  137    * See add_action_radio_string().
  138    *
  139    * For instance,
  140    * void on_slot_activated(const Glib::ustring& parameter);
  141    */
  142   using ActivateWithStringParameterSlot = sigc::slot<void(const Glib::ustring&)>;
  143 
  144 //TODO: Docs: Add hints about how to specify the various possible states in the GtkBuilder XML.
  145   /** A convenience method for creating a string-based radio SimpleAction instance
  146    * and adding it to the ActionMap.
  147    *
  148    * @param name The name of the Action.
  149    * @param slot The callback method to be called when the action is activated.
  150    * @param state The initial state.
  151    * @return The Action.
  152    */
  153   Glib::RefPtr<SimpleAction> add_action_radio_string(const Glib::ustring& name, const ActivateWithStringParameterSlot& slot, const Glib::ustring& state);
  154 
  155 
  156 //TODO: Docs: Add hints about how to specify the various possible states in the GtkBuilder XML.
  157   /** A convenience method for creating an integer-based radio SimpleAction instance
  158    * and adding it to the ActionMap.
  159    *
  160    * @param name The name of the Action.
  161    * @param state The initial state.
  162    * @return The Action.
  163    */
  164   Glib::RefPtr<SimpleAction> add_action_radio_integer(const Glib::ustring& name, gint32 state);
  165 
  166   /** A Slot to be called when an action has been activated.
  167    * See add_action_radio_integer().
  168    *
  169    * For instance,
  170    * void on_slot_activated(int parameter);
  171    */
  172   using ActivateWithIntParameterSlot = sigc::slot<void(int)>;
  173   
  174 //TODO: Docs: Add hints about how to specify the various possible states in the GtkBuilder XML.
  175   /** A convenience method for creating an integer-based radio SimpleAction instance
  176    * and adding it to the ActionMap.
  177    *
  178    * @param name The name of the Action.
  179    * @param slot The callback method to be called when the action is activated.
  180    * @param state The initial state.
  181    * @return The Action.
  182    */
  183   Glib::RefPtr<SimpleAction> add_action_radio_integer(const Glib::ustring& name, const ActivateWithIntParameterSlot& slot, gint32 state);
  184 
  185 protected:
  186 #m4 _CONVERSION(`Glib::RefPtr<Action>', `GAction*', `Glib::unwrap($3)')
  187   _WRAP_VFUNC(Glib::RefPtr<Action> lookup_action(const Glib::ustring& name) const, "lookup_action", refreturn)
  188 
  189 #m4 _CONVERSION(`GAction*', `const Glib::RefPtr<Action>&', `Glib::wrap($3, true)')
  190   _WRAP_VFUNC(void add_action(const Glib::RefPtr<Action>& action) const, "add_action")
  191 
  192   _WRAP_VFUNC(void remove_action(const Glib::ustring& name), "remove_action")
  193 };
  194 
  195 } // namespace Gio