Signaux des événements X

The Widget class has some special signals which correspond to the underlying X-Windows events. These are suffixed by _event; for instance, Widget::signal_button_press_event().

You might occasionally find it useful to handle X events when there's something you can't accomplish with normal signals. Gtk::Button, for example, does not send mouse-pointer coordinates with its clicked signal, but you could handle button_press_event if you needed this information. X events are also often used to handle key-presses.

Ces signaux se comportent de façon légèrement différente. La valeur renvoyée par le gestionnaire de signal indique si l'événement a été pleinement « géré ». Si la valeur est false, alors gtkmm passe l'événement au gestionnaire de signal suivant. Si la valeur est true, aucun autre gestionnaire de signal n'est appelé.

Handling an X event doesn't affect the Widget's other signals. If you handle button_press_event for Gtk::Button, you'll still be able to get the clicked signal. They are emitted at (nearly) the same time.

Here's a simple example:

bool on_button_press(GdkEventButton* event);
Gtk::Button button("label");

Quand la souris est au dessus du bouton et qu'un bouton de souris est pressé, on_button_press() est appelé.

GdkEventButton est une structure contenant les paramètres de l'événement, tels que les coordonnées du pointeur de souris et l'heure où le bouton a été pressé. Les structures GdkEvent sont différentes selon les événements.

B.VI.I. Séquencement des gestionnaires de signaux

By default, your signal handlers are called after any previously-connected signal handlers. However, this can be a problem with the X Event signals. For instance, the existing signal handlers, or the default signal handler, might return true to stop other signal handlers from being called. To specify that your signal handler should be called before the other signal handlers, so that it will always be called, you can specify false for the optional after parameter. For instance,

                false );

The event is delivered first to the widget the event occurred in. If all signal handlers in that widget return false (indicating that the event has not been handled), then the signal will be propagated to the parent widget and emitted there. This continues all the way up to the top-level widget if no one handles the event.