Signal function:
Gint gtk_signal_connect (gtkobject * object, gchar * Name, gtksignalfuncfunc, gpointer func_data );
Format of the return function:
Void callback_func (gtkeidget * widget, gpointer callback_data );
GTK events: actions of the gtk component or events sent by the X server can be associated with the following events:
Button_press_event Button Press
Button_release_event Button release
Motion_policy_event Move the mouse
Delete_event Close with Window Manager
Destroy_event Close
Expose_event Exposure
Key_press_event Press the button
Key_release_event Button release
Enter_policy_event Move the mouse pointer to the component
Leave_policy_event Mouse pointer left component
Configure_event Attribute change
Focus_in_event Get focus
Focus_out_event No focus
Map_event Ing
Unmap_event Disappear
Property_policy_even Attribute change
Selection_clear_event Select clear
Selection_request_event Select request
Selection_policy_event Select notification
Proximity_in_event Approaching
Proximity_out_event Leave
Drag_begin_event Drag start
Drag_request_event Drag request
Drag_end_event Drag end
Drop_enter_event Put in
Drop_leave_event Release
Drop_data_available_eventData available
In addition to the signal mechanism described above, there is also a setEventsReflects x event mechanisms. Callback functions can be connected to these events. These events are:
- Event
- Button_press_event
- Button_release_event
- Scroll_event
- Motion_policy_event
- Delete_event
- Destroy_event
- Expose_event
- Key_press_event
- Key_release_event
- Enter_policy_event
- Leave_policy_event
- Configure_event
- Focus_in_event
- Focus_out_event
- Map_event
- Unmap_event
- Property_policy_event
- Selection_clear_event
- Selection_request_event
- Selection_policy_event
- Proximity_in_event
- Proximity_out_event
- Visibility_policy_event
- Client_event
- No_expose_event
- Window_state_event
To connect a callback function to one of these events, you use the g_signal_connect () function, as described earlier, using one of the above event namesNameParameters. The Event Callback Function is slightly different from the signal callback function:
gint callback_func( GtkWidget *widget,GdkEvent *event,gpointer callback_data );
Gdkevent is a CUnionStructure. Its type depends on the event in the preceding event. Each possible type hasTypeMembers. The rest of the event structure depends on the event type. Possible values of the type include:
GDK_NOTHING GDK_DELETE GDK_DESTROY GDK_EXPOSE GDK_MOTION_NOTIFY GDK_BUTTON_PRESS GDK_2BUTTON_PRESS GDK_3BUTTON_PRESS GDK_BUTTON_RELEASE GDK_KEY_PRESS GDK_KEY_RELEASE GDK_ENTER_NOTIFY GDK_LEAVE_NOTIFY GDK_FOCUS_CHANGE GDK_CONFIGURE GDK_MAP GDK_UNMAP GDK_PROPERTY_NOTIFY GDK_SELECTION_CLEAR GDK_SELECTION_REQUEST GDK_SELECTION_NOTIFY GDK_PROXIMITY_IN GDK_PROXIMITY_OUT GDK_DRAG_ENTER GDK_DRAG_LEAVE GDK_DRAG_MOTION GDK_DRAG_STATUS GDK_DROP_START GDK_DROP_FINISHED GDK_CLIENT_EVENT GDK_VISIBILITY_NOTIFY GDK_NO_EXPOSE GDK_SCROLL GDK_WINDOW_STATE GDK_SETTING |
Therefore, to connect a callback function to one of these events, we will use:
g_signal_connect (G_OBJECT (button), "button_press_event", G_CALLBACK (button_press_callback), NULL); |
It is assumed thatButtonIs a button component. The button_press_callback () function is called when the mouse is placed on the button and clicked. This function should be declared:
static gint button_press_callback( GtkWidget *widget, GdkEventButton *event, gpointer data ); |
Note that we can declare the second parameter typeGdkeventbuttonBecause we know which type of event will happen. The return value of this function indicates whether the event should be further transmitted by the GTK event processor. Returns true to indicate that the event has been processed and should not be further propagated. Returns false to continue normal event processing. For details, see the Advanced event and signal processing chapter. For details about the gdkevent data type, see the appendix gdk event type. The gdk selection area and drag-and-drop interface functions also issue many events, which are reflected by signals in GTK. For details about the following signals, see the signal on the source component and the signal on the target component:
- Selection_received
- Selection_get
- Drag_begin_event
- Drag_end_event
- Drag_data_delete
- Drag_motion
- Drag_drop
- Drag_data_get
- Drag_data_received