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_pressed_event if you needed this information. X events are also
often used to handle key-presses.
These signals behave slightly differently. The value returned from the signal handler indicates whether it has fully "handled"
the event. If the value is false then gtkmm will pass the event on to the next signal handler. If the value is true then no other signal handlers will need to be called.
Handling an X event doesn't affect the Widget's other
signals. If you handle button_pressed_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");
button.signal_button_press_event().connect( SigC::slot(&on_button_press) );
When the mouse is over the button and a mouse button is pressed,
on_button_pressed() will be called.
GdkEventButton is a structure containing the event's parameters,
such as the coordinates of the mouse pointer at the time the button
was pressed. There are several different types of GdkEvent
structures for the various events.
|