gtkmm: Gtk::ShortcutController Class Reference

gtkmm 4.6.0

Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
Gtk::ShortcutController Class Reference
Event Controllers and Gestures

Event controller for shortcuts. More...

`#include <gtkmm/shortcutcontroller.h>`

Inheritance diagram for Gtk::ShortcutController:
[legend]

## Public Member Functions
| ShortcutController (ShortcutController&& src) noexcept
ShortcutController& | operator= (ShortcutController&& src) noexcept
| ~ShortcutController () noexcept override
GtkShortcutController* | gobj ()
| Provides access to the underlying C GObject. More...
const GtkShortcutController* | gobj () const
| Provides access to the underlying C GObject. More...
GtkShortcutController* | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
void | set_mnemonics_modifiers (Gdk::ModifierType modifiers)
| Sets the controller to use the given modifier for mnemonics. More...
Gdk::ModifierType | get_mnemonics_modifiers () const
| Gets the mnemonics modifiers for when this controller activates its shortcuts. More...
void | set_scope (ShortcutScope scope)
| Sets the controller to have the given scope. More...
ShortcutScope | set_scope () const
| Gets the scope for when this controller activates its shortcuts. More...
ShortcutScope | get_scope () const
| Gets the scope for when this controller activates its shortcuts. More...
void | add_shortcut (const Glib::RefPtr< Shortcut >& shortcut)
| Adds shortcut to the list of shortcuts handled by self. More...
void | remove_shortcut (const Glib::RefPtr< const Shortcut >& shortcut)
| Removes shortcut from the list of shortcuts handled by self. More...
Glib::PropertyProxy< Gdk::ModifierType > | property_mnemonic_modifiers ()
| The modifiers that need to be pressed to allow mnemonics activation. More...
Glib::PropertyProxy_ReadOnly< Gdk::ModifierType > | property_mnemonic_modifiers () const
| The modifiers that need to be pressed to allow mnemonics activation. More...
Glib::PropertyProxy< ShortcutScope > | property_scope ()
| What scope the shortcuts will be handled in. More...
Glib::PropertyProxy_ReadOnly< ShortcutScope > | property_scope () const
| What scope the shortcuts will be handled in. More...
Public Member Functions inherited from Gtk::EventController
| EventController (EventController&& src) noexcept
EventController& | operator= (EventController&& src) noexcept
| ~EventController () noexcept override
GtkEventController* | gobj ()
| Provides access to the underlying C GObject. More...
const GtkEventController* | gobj () const
| Provides access to the underlying C GObject. More...
GtkEventController* | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
Widget* | get_widget ()
| Returns the `Gtk::Widget` this controller relates to. More...
const Widget* | get_widget () const
| Returns the `Gtk::Widget` this controller relates to. More...
void | reset ()
| Resets the controller to a clean state. More...
PropagationPhase | get_propagation_phase () const
| Gets the propagation phase at which controller handles events. More...
void | set_propagation_phase (PropagationPhase phase)
| Sets the propagation phase at which a controller handles events. More...
PropagationLimit | get_propagation_limit () const
| Gets the propagation limit of the event controller. More...
void | set_propagation_limit (PropagationLimit limit)
| Sets the event propagation limit on the event controller. More...
Glib::ustring | get_name () const
| Gets the name of controller. More...
void | set_name (const Glib::ustring& name)
| Sets a name on the controller that can be used for debugging. More...
Glib::RefPtr< const Gdk::Event > | get_current_event () const
| Returns the event that is currently being handled by the controller. More...
guint32 | get_current_event_time () const
| Returns the timestamp of the event that is currently being handled by the controller. More...
Glib::RefPtr< Gdk::Device > | get_current_event_device ()
| Returns the device of the event that is currently being handled by the controller. More...
Glib::RefPtr< const Gdk::Device > | get_current_event_device () const
| Returns the event that is currently being handled by the controller. More...
Gdk::ModifierType | get_current_event_state () const
| Returns the modifier state of the event that is currently being handled by the controller. More...
Glib::PropertyProxy_ReadOnly< Widget* > | property_widget () const
| The widget receiving the `Gdk::Events` that the controller will handle. More...
Glib::PropertyProxy< PropagationPhase > | property_propagation_phase ()
| The propagation phase at which this controller will handle events. More...
Glib::PropertyProxy_ReadOnly< PropagationPhase > | property_propagation_phase () const
| The propagation phase at which this controller will handle events. More...
Glib::PropertyProxy< PropagationLimit > | property_propagation_limit ()
| The limit for which events this controller will handle. More...
Glib::PropertyProxy_ReadOnly< PropagationLimit > | property_propagation_limit () const
| The limit for which events this controller will handle. More...
Glib::PropertyProxy< Glib::ustring > | property_name ()
| The name for this controller, typically used for debugging purposes. More...
Glib::PropertyProxy_ReadOnly< Glib::ustring > | property_name () const
| The name for this controller, typically used for debugging purposes. More...
Public Member Functions inherited from Glib::Object
| Object (const Object &)=delete
Object & | operator= (const Object &)=delete
| Object (Object &&src) noexcept
Object & | operator= (Object &&src) noexcept
void * | get_data (const QueryQuark &key)
void | set_data (const Quark &key, void *data)
void | set_data (const Quark &key, void *data, DestroyNotify notify)
void | remove_data (const QueryQuark &quark)
void * | steal_data (const QueryQuark &quark)
Glib::RefPtr< Glib::Object > | wrap (GObject *object, bool take_copy=false)
Public Member Functions inherited from Glib::ObjectBase
| ObjectBase (const ObjectBase &)=delete
ObjectBase & | operator= (const ObjectBase &)=delete
void | set_property_value (const Glib::ustring &property_name, const Glib::ValueBase &value)
void | get_property_value (const Glib::ustring &property_name, Glib::ValueBase &value) const
void | set_property (const Glib::ustring &property_name, const PropertyType &value)
void | get_property (const Glib::ustring &property_name, PropertyType &value) const
PropertyType | get_property (const Glib::ustring &property_name) const
sigc::connection | connect_property_changed (const Glib::ustring &property_name, const sigc::slot< void()> &slot)
sigc::connection | connect_property_changed (const Glib::ustring &property_name, sigc::slot< void()> &&slot)
void | freeze_notify ()
void | thaw_notify ()
virtual void | reference () const
virtual void | unreference () const
GObject * | gobj ()
const GObject * | gobj () const
GObject * | gobj_copy () const
Public Member Functions inherited from Gio::ListModel
| ListModel (ListModel &&src) noexcept
ListModel & | operator= (ListModel &&src) noexcept
| ~ListModel () noexcept override
GListModel * | gobj ()
const GListModel * | gobj () const
GType | get_item_type () const
guint | get_n_items () const
Glib::RefPtr< Glib::ObjectBase > | get_object (guint position)
Glib::RefPtr< const Glib::ObjectBase > | get_object (guint position) const
Glib::SignalProxy< void(guint, guint, guint)> | signal_items_changed ()
Glib::RefPtr< Gio::ListModel > | wrap (GListModel *object, bool take_copy=false)
Public Member Functions inherited from Glib::Interface
| Interface ()
| Interface (Interface &&src) noexcept
Interface & | operator= (Interface &&src) noexcept
| Interface (const Glib::Interface_Class &interface_class)
| Interface (GObject *castitem)
| ~Interface () noexcept override
| Interface (const Interface &)=delete
Interface & | operator= (const Interface &)=delete
GObject * | gobj ()
const GObject * | gobj () const
Public Member Functions inherited from Gtk::Buildable
| Buildable (Buildable&& src) noexcept
Buildable& | operator= (Buildable&& src) noexcept
| ~Buildable () noexcept override
GtkBuildable* | gobj ()
| Provides access to the underlying C GObject. More...
const GtkBuildable* | gobj () const
| Provides access to the underlying C GObject. More...
Glib::ustring | get_buildable_id () const
| Gets the ID of the buildable object. More...

## Static Public Member Functions
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system. More...
static Glib::RefPtr< ShortcutController > | create ()
static Glib::RefPtr< ShortcutController > | create (const Glib::RefPtr< Gio::ListModel >& model)
| Creates a new shortcut controller that takes its shortcuts from the given list model. More...
Static Public Member Functions inherited from Gtk::EventController
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system. More...
Static Public Member Functions inherited from Gio::ListModel
static void | add_interface (GType gtype_implementer)
static GType | get_type ()
Static Public Member Functions inherited from Gtk::Buildable
static void | add_interface (GType gtype_implementer)
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system. More...

## Protected Member Functions
| ShortcutController ()
| ShortcutController (const Glib::RefPtr< Gio::ListModel >& model)
Protected Member Functions inherited from Gtk::EventController
| EventController ()
| There is no create() method that corresponds to this constructor, because only derived classes shall be created. More...
Protected Member Functions inherited from Glib::Object
| Object ()
| Object (const Glib::ConstructParams &construct_params)
| Object (GObject *castitem)
| ~Object () noexcept override
Protected Member Functions inherited from Glib::ObjectBase
| ObjectBase ()
| ObjectBase (const char *custom_type_name)
| ObjectBase (const std::type_info &custom_type_info)
| ObjectBase (ObjectBase &&src) noexcept
ObjectBase & | operator= (ObjectBase &&src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject *castitem)
void | initialize_move (GObject *castitem, Glib::ObjectBase *previous_wrapper)
Protected Member Functions inherited from Gio::ListModel
| ListModel ()
void | items_changed (guint position, guint removed, guint added)
virtual GType | get_item_type_vfunc ()
virtual guint | get_n_items_vfunc ()
virtual gpointer | get_item_vfunc (guint position)
Protected Member Functions inherited from Gtk::Buildable
| Buildable ()
| You should derive from this class to use it. More...

## Related Functions
(Note that these are not member functions.)
Glib::RefPtr< Gtk::ShortcutController > | wrap (GtkShortcutController* object, bool take_copy=false)
| A Glib::wrap() method for this object. More...
Related Functions inherited from Gtk::EventController
Glib::RefPtr< Gtk::EventController > | wrap (GtkEventController* object, bool take_copy=false)
| A Glib::wrap() method for this object. More...
Related Functions inherited from Gtk::Buildable
Glib::RefPtr< Gtk::Buildable > | wrap (GtkBuildable* object, bool take_copy=false)
| A Glib::wrap() method for this object. More...

## Additional Inherited Members
Public Types inherited from Glib::Object
typedef void(*)(gpointer data | DestroyNotify)

## Detailed Description

Event controller for shortcuts.

Gtk::ShortcutController is an event controller that manages shortcuts.

Most common shortcuts are using this controller implicitly, e.g. by adding a mnemonic underline to a Gtk::Label, or by installing a key binding using gtk_widget_class_add_binding(), or by adding accelerators to global actions using Gtk::Application::set_accels_for_action().

But it is possible to create your own shortcut controller, and add shortcuts to it.

Gtk::ShortcutController implements Gio::ListModel for querying the shortcuts that have been added to it.

## ShortcutController as a Buildable

ShortcutControllers can be created in ui files to set up shortcuts in the same place as the widgets.

An example of a UI definition fragment with GtkShortcutController:

<object class='GtkButton'>
<child>
<object class='GtkShortcutController'>
<property name='scope'>managed</property>
<child>
<object class='GtkShortcut'>
<property name='trigger'>&lt;Control&gt;k</property>
<property name='action'>activate</property>
</object>
</child>
</object>
</child>
</object>
Gtk::Accelerator::name
Glib::ustring name(guint accelerator_key, Gdk::ModifierType accelerator_mods)
Converts an accelerator keyval and modifier mask into a string parseable by parse().

Since gtkmm 3.98:

## Constructor & Destructor Documentation

## ◆ ShortcutController() [1/3]

Gtk::ShortcutController::ShortcutController | ( | ShortcutController&& | src | ) |
| noexcept

## ◆ ~ShortcutController()

Gtk::ShortcutController::~ShortcutController | ( |  | ) |
| overridenoexcept

## ◆ ShortcutController() [2/3]

Gtk::ShortcutController::ShortcutController | ( |  | ) |
| protected

## ◆ ShortcutController() [3/3]

Gtk::ShortcutController::ShortcutController | ( | const Glib::RefPtr< Gio::ListModel > & | model | ) |
| explicitprotected

## Member Function Documentation

## ◆ add_shortcut()

void Gtk::ShortcutController::add_shortcut | ( | const Glib::RefPtr< Shortcut >& | shortcut | ) |

Adds shortcut to the list of shortcuts handled by self.

If this controller uses an external shortcut list, this function does nothing.

Parameters

  shortcut | A `Gtk::Shortcut`.

## ◆ create() [1/2]

static Glib::RefPtr< ShortcutController > Gtk::ShortcutController::create | ( |  | ) |
| static

## ◆ create() [2/2]

static Glib::RefPtr< ShortcutController > Gtk::ShortcutController::create | ( | const Glib::RefPtr< Gio::ListModel > & | model | ) |
| static

Creates a new shortcut controller that takes its shortcuts from the given list model.

A controller created by this function does not let you add or remove individual shortcuts using the shortcut controller api, but you can change the contents of the model.

Parameters

  model | A ListModel containing shortcuts.

Returns
  A newly created shortcut controller.

## ◆ get_mnemonics_modifiers()

Gdk::ModifierType Gtk::ShortcutController::get_mnemonics_modifiers | ( |  | ) | const

Gets the mnemonics modifiers for when this controller activates its shortcuts.

Returns
  The controller's mnemonics modifiers.

## ◆ get_scope()

ShortcutScope Gtk::ShortcutController::get_scope | ( |  | ) | const

Gets the scope for when this controller activates its shortcuts.

See set_scope() for details.

Since gtkmm 4.2:

Returns
  The controller's scope.

## ◆ get_type()

static GType Gtk::ShortcutController::get_type | ( |  | ) |
| static

Get the GType for this class, for use with the underlying GObject type system.

## ◆ gobj() [1/2]

GtkShortcutController * Gtk::ShortcutController::gobj | ( |  | ) |
| inline

Provides access to the underlying C GObject.

## ◆ gobj() [2/2]

const GtkShortcutController * Gtk::ShortcutController::gobj | ( |  | ) | const
| inline

Provides access to the underlying C GObject.

## ◆ gobj_copy()

GtkShortcutController * Gtk::ShortcutController::gobj_copy | ( |  | ) |

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

## ◆ operator=()

ShortcutController& Gtk::ShortcutController::operator= | ( | ShortcutController&& | src | ) |
| noexcept

## ◆ property_mnemonic_modifiers() [1/2]

Glib::PropertyProxy< Gdk::ModifierType > Gtk::ShortcutController::property_mnemonic_modifiers | ( |  | ) |

The modifiers that need to be pressed to allow mnemonics activation.

Default value: Gdk::ModifierType::ALT_MASK

Returns
  A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

## ◆ property_mnemonic_modifiers() [2/2]

Glib::PropertyProxy_ReadOnly< Gdk::ModifierType > Gtk::ShortcutController::property_mnemonic_modifiers | ( |  | ) | const

The modifiers that need to be pressed to allow mnemonics activation.

Default value: Gdk::ModifierType::ALT_MASK

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ property_scope() [1/2]

Glib::PropertyProxy< ShortcutScope > Gtk::ShortcutController::property_scope | ( |  | ) |

What scope the shortcuts will be handled in.

Default value: Gtk::ShortcutScope::LOCAL

Returns
  A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

## ◆ property_scope() [2/2]

Glib::PropertyProxy_ReadOnly< ShortcutScope > Gtk::ShortcutController::property_scope | ( |  | ) | const

What scope the shortcuts will be handled in.

Default value: Gtk::ShortcutScope::LOCAL

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ remove_shortcut()

void Gtk::ShortcutController::remove_shortcut | ( | const Glib::RefPtr< const Shortcut >& | shortcut | ) |

Removes shortcut from the list of shortcuts handled by self.

If shortcut had not been added to controller or this controller uses an external shortcut list, this function does nothing.

Parameters

  shortcut | A `Gtk::Shortcut`.

## ◆ set_mnemonics_modifiers()

void Gtk::ShortcutController::set_mnemonics_modifiers | ( | Gdk::ModifierType | modifiers | ) |

Sets the controller to use the given modifier for mnemonics.

The mnemonics modifiers determines which modifiers need to be pressed to allow activation of shortcuts with mnemonics triggers.

GTK normally uses the Alt modifier for mnemonics, except in `Gtk::PopoverMenu`s, where mnemonics can be triggered without any modifiers. It should be very rarely necessary to change this, and doing so is likely to interfere with other shortcuts.

This value is only relevant for local shortcut controllers. Global and managed shortcut controllers will have their shortcuts activated from other places which have their own modifiers for activating mnemonics.

Parameters

  modifiers | The new mnemonics_modifiers to use.

## ◆ set_scope() [1/2]

ShortcutScope Gtk::ShortcutController::set_scope | ( |  | ) | const

Gets the scope for when this controller activates its shortcuts.

See set_scope() for details.

Deprecated:
  Use get_scope() instead.

Returns
  The controller's scope.

## ◆ set_scope() [2/2]

void Gtk::ShortcutController::set_scope | ( | ShortcutScope | scope | ) |

Sets the controller to have the given scope.

The scope allows shortcuts to be activated outside of the normal event propagation. In particular, it allows installing global keyboard shortcuts that can be activated even when a widget does not have focus.

With Gtk::ShortcutScope::LOCAL, shortcuts will only be activated when the widget has focus.

Parameters

  scope | The new scope to use.

## Friends And Related Function Documentation

## ◆ wrap()

Glib::RefPtr< Gtk::ShortcutController > wrap | ( | GtkShortcutController * | object,
|  | bool | take_copy = `false`
| ) |  |
| related

A Glib::wrap() method for this object.

Parameters

  object | The C instance.
  take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns
  A C++ instance that wraps this C instance.