| Server IP : 182.53.201.61 / Your IP : 216.73.217.175 Web Server : Apache/2.2.15 (Fedora) System : Linux km10.dyndns.org 2.6.31.5-127.fc12.i686.PAE #1 SMP Sat Nov 7 21:25:57 EST 2009 i686 User : apache ( 48) PHP Version : 5.3.3 Disable Function : NONE MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/share/doc/gtk2-devel-docs-2.18.3/tutorial/ |
Upload File : |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Events</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="GTK+ 2.0 Tutorial"
HREF="book1.html"><LINK
REL="UP"
TITLE="Getting Started"
HREF="c39.html"><LINK
REL="PREVIOUS"
TITLE="Theory of Signals and Callbacks"
HREF="x159.html"><LINK
REL="NEXT"
TITLE="Stepping Through Hello World"
HREF="x281.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>GTK+ 2.0 Tutorial</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x159.html"
ACCESSKEY="P"
><<< Previous</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Getting Started</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x281.html"
ACCESSKEY="N"
>Next >>></A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="SEC-EVENTS"
>Events</A
></H1
><P
>In addition to the signal mechanism described above, there is a set
of <I
CLASS="EMPHASIS"
>events</I
> that reflect the X event mechanism. Callbacks may
also be attached to these events. These events are:</P
><P
></P
><UL
COMPACT="COMPACT"
><LI
><SPAN
> event</SPAN
></LI
><LI
><SPAN
> button_press_event</SPAN
></LI
><LI
><SPAN
> button_release_event</SPAN
></LI
><LI
><SPAN
> scroll_event</SPAN
></LI
><LI
><SPAN
> motion_notify_event</SPAN
></LI
><LI
><SPAN
> delete_event</SPAN
></LI
><LI
><SPAN
> destroy_event</SPAN
></LI
><LI
><SPAN
> expose_event</SPAN
></LI
><LI
><SPAN
> key_press_event</SPAN
></LI
><LI
><SPAN
> key_release_event</SPAN
></LI
><LI
><SPAN
> enter_notify_event</SPAN
></LI
><LI
><SPAN
> leave_notify_event</SPAN
></LI
><LI
><SPAN
> configure_event</SPAN
></LI
><LI
><SPAN
> focus_in_event</SPAN
></LI
><LI
><SPAN
> focus_out_event</SPAN
></LI
><LI
><SPAN
> map_event</SPAN
></LI
><LI
><SPAN
> unmap_event</SPAN
></LI
><LI
><SPAN
> property_notify_event</SPAN
></LI
><LI
><SPAN
> selection_clear_event</SPAN
></LI
><LI
><SPAN
> selection_request_event</SPAN
></LI
><LI
><SPAN
> selection_notify_event</SPAN
></LI
><LI
><SPAN
> proximity_in_event</SPAN
></LI
><LI
><SPAN
> proximity_out_event</SPAN
></LI
><LI
><SPAN
> visibility_notify_event</SPAN
></LI
><LI
><SPAN
> client_event</SPAN
></LI
><LI
><SPAN
> no_expose_event</SPAN
></LI
><LI
><SPAN
> window_state_event</SPAN
></LI
></UL
><P
>In order to connect a callback function to one of these events you
use the function g_signal_connect(), as described above, using one of
the above event names as the <TT
CLASS="LITERAL"
>name</TT
> parameter. The callback
function for events has a slightly different form than that for
signals:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>gint callback_func( GtkWidget *widget,
GdkEvent *event,
gpointer callback_data );</PRE
></TD
></TR
></TABLE
><P
>GdkEvent is a C <TT
CLASS="LITERAL"
>union</TT
> structure whose type will depend upon
which of the above events has occurred. In order for us to tell which event
has been issued each of the possible alternatives has a <TT
CLASS="LITERAL"
>type</TT
>
member that reflects the event being issued. The other components
of the event structure will depend upon the type of the
event. Possible values for the type are:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
> 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</PRE
></TD
></TR
></TABLE
><P
>So, to connect a callback function to one of these events we would use
something like:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>g_signal_connect (G_OBJECT (button), "button_press_event",
G_CALLBACK (button_press_callback), NULL);</PRE
></TD
></TR
></TABLE
><P
>This assumes that <TT
CLASS="LITERAL"
>button</TT
> is a Button widget. Now, when the
mouse is over the button and a mouse button is pressed, the function
button_press_callback() will be called. This function may be declared as:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>static gboolean button_press_callback( GtkWidget *widget,
GdkEventButton *event,
gpointer data );</PRE
></TD
></TR
></TABLE
><P
>Note that we can declare the second argument as type
<TT
CLASS="LITERAL"
>GdkEventButton</TT
> as we know what type of event will occur for this
function to be called.</P
><P
>The value returned from this function indicates whether the event
should be propagated further by the GTK event handling
mechanism. Returning TRUE indicates that the event has been handled,
and that it should not propagate further. Returning FALSE continues
the normal event handling. See the section on
<A
HREF="c1799.html"
>Advanced Event and Signal Handling</A
>
for more details on this propagation process.</P
><P
>For details on the GdkEvent data types, see the appendix entitled
<A
HREF="a2769.html"
>GDK Event Types</A
>.</P
><P
>The GDK selection and drag-and-drop APIs also emit a number of events which
are reflected in GTK by the signals. See <A
HREF="x1941.html#SEC-SIGNALSONSOURCEWIDGETS"
>Signals on the source widget</A
> and <A
HREF="x1941.html#SEC-SIGNALSONDESTWIDGETS"
>Signals on the destination widget</A
>
for details on the signatures of the callback functions for these signals:</P
><P
></P
><UL
COMPACT="COMPACT"
><LI
><SPAN
> selection_received</SPAN
></LI
><LI
><SPAN
> selection_get</SPAN
></LI
><LI
><SPAN
> drag_begin_event</SPAN
></LI
><LI
><SPAN
> drag_end_event</SPAN
></LI
><LI
><SPAN
> drag_data_delete</SPAN
></LI
><LI
><SPAN
> drag_motion</SPAN
></LI
><LI
><SPAN
> drag_drop</SPAN
></LI
><LI
><SPAN
> drag_data_get</SPAN
></LI
><LI
><SPAN
> drag_data_received</SPAN
></LI
></UL
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x159.html"
ACCESSKEY="P"
><<< Previous</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="book1.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x281.html"
ACCESSKEY="N"
>Next >>></A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Theory of Signals and Callbacks</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="c39.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Stepping Through Hello World</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>