⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sec-events.html

📁 gtk 开发手册和参考文档。 包括gtk glib gdk等
💻 HTML
字号:
<HTML><HEAD><TITLE>Events</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.49"><LINKREL="HOME"TITLE="GTK+ 1.2 Tutorial"HREF="gtk-tut.html"><LINKREL="UP"TITLE="Getting Started"HREF="ch-gettingstarted.html"><LINKREL="PREVIOUS"TITLE="Theory of Signals and Callbacks"HREF="sec-theoryofsignalsandcallbacks.html"><LINKREL="NEXT"TITLE="Stepping Through Hello World"HREF="sec-steppingthroughhelloworld.html"></HEAD></head><body bgcolor="#FFFFFF" marginheight=0 marginwidth=0 width="100%"><table cellspacing=6 border=0 cellpadding=0 width="100%">  <tr>    <td bgcolor="#FFFFFF" valign=top nowrap>    <centeR><A HREF="/"><img src="/images/gtk-logo-rgb.gif" width=107 height=140 border=0></A>      <font face="helvetica,lucidia" color="#000000"><BR><BR><b>GTK+<BR>The GIMP Toolkit</b></center><BR><table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>General</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/">Introduction</A><BR><A HREF="/screenshots/">Screenshots</A><br><A HREF="/download/">Download</A><br><A HREF="/mailinglists.html">Mailing Lists</A><BR><A HREF="/bindings.html">Language Bindings</A><BR><A HREF="http://gtk.themes.org/">Themes</A><BR><A HREF="/bugs.html">Bug Tracker</A><BR></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Documentation</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/faq/">FAQ</A><br><A HREF="/tutorial/">Tutorial</A><BR><A HREF="/api/">API Reference</A><br><A HREF="/books.html">Published Books</A><BR></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Projects</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.pango.org/">Pango</A><BR><A HREF="http://sources.redhat.com/inti/">Inti</A><BR><A HREF="http://www.gnome.org/">GNOME</A><BR><A HREF="http://user.sgic.fi/~tml/gimp/win32/">GTK+ for Win32</A><br><A HREF="http://people.redhat.com/sopwith/gtkfb/">GtkFB (Framebuffer)</A><br><A HREF="http://www.directfb.org/gtk.xml">GTK+ on DirectFB</A><BR><A HREF="/beos/">GTK+ for BeOS</A></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B><B>Applications</B></B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.gimp.org/">GIMP</A><BR><A HREF="http://www.abiword.org/">Abiword</A><BR><A HREF="http://www.lysator.liu.se/~alla/dia/dia.html">Dia</A><BR><A HREF="http://glade.pn.org/">Glade</A><BR><A HREF="http://www.gnucash.org/">GnuCash</A><BR><A HREF="http://www.gnome.org/projects/gnumeric/">Gnumeric</A><BR><BR><A HREF="http://www.gnome.org/applist/">GNOME Software Map</A><br></td></tr></table></td></tr></table><BR>      </td>  <td bgcolor="#ffffff" valign=top width="99%"><font face="lucida,helvetica"><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">GTK+ 1.2 Tutorial</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="sec-theoryofsignalsandcallbacks.html">&#60;&#60;&#60; Previous</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 2. Getting Started</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sec-steppingthroughhelloworld.html">Next &#62;&#62;&#62;</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SEC-EVENTS">2.4. Events</A></H1><P>In addition to the signal mechanism described above, there is a setof <ICLASS="EMPHASIS">events</I> that reflect the X event mechanism. Callbacks mayalso be attached to these events. These events are:</P><P></P><ULCOMPACT="COMPACT"><LI><SPAN> event</SPAN></LI><LI><SPAN> button_press_event</SPAN></LI><LI><SPAN> button_release_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> drag_begin_event</SPAN></LI><LI><SPAN> drag_request_event</SPAN></LI><LI><SPAN> drag_end_event</SPAN></LI><LI><SPAN> drop_enter_event</SPAN></LI><LI><SPAN> drop_leave_event</SPAN></LI><LI><SPAN> drop_data_available_event</SPAN></LI><LI><SPAN> other_event</SPAN></LI></UL><P>In order to connect a callback function to one of these events youuse the function gtk_signal_connect, as described above, using one ofthe above event names as the <TTCLASS="LITERAL">name</TT> parameter. The callbackfunction for events has a slightly different form than that forsignals:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">gint callback_func( GtkWidget *widget,                    GdkEvent  *event,                    gpointer   callback_data );</PRE></TD></TR></TABLE><P>GdkEvent is a C <TTCLASS="LITERAL">union</TT> structure whose type will depend upon whichof the above events has occurred. In order for us to tell which eventhas been issued each of the possible alternatives has a <TTCLASS="LITERAL">type</TT>member that reflects the event being issued. The other componentsof the event structure will depend upon the type of theevent. Possible values for the type are:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="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_BEGIN  GDK_DRAG_REQUEST  GDK_DROP_ENTER  GDK_DROP_LEAVE  GDK_DROP_DATA_AVAIL  GDK_CLIENT_EVENT  GDK_VISIBILITY_NOTIFY  GDK_NO_EXPOSE  GDK_OTHER_EVENT	/* Deprecated, use filters instead */</PRE></TD></TR></TABLE><P>So, to connect a callback function to one of these events we would usesomething like:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">gtk_signal_connect( GTK_OBJECT(button), "button_press_event",                    GTK_SIGNAL_FUNC(button_press_callback), 		    NULL);</PRE></TD></TR></TABLE><P>This assumes that <TTCLASS="LITERAL">button</TT> is a Button widget. Now, when themouse is over the button and a mouse button is pressed, the function<TTCLASS="LITERAL">button_press_callback</TT> will be called. This function may bedeclared as:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">static gint button_press_callback( GtkWidget      *widget,                                    GdkEventButton *event,                                   gpointer        data );</PRE></TD></TR></TABLE><P>Note that we can declare the second argument as type<TTCLASS="LITERAL">GdkEventButton</TT> as we know what type of event will occur for thisfunction to be called.</P><P>The value returned from this function indicates whether the eventshould be propagated further by the GTK event handlingmechanism. Returning TRUE indicates that the event has been handled,and that it should not propagate further. Returning FALSE continuesthe normal event handling.  See the section on<AHREF="ch-advancedeventsandsignals.html">Advanced Event and Signal Handling</A> for more details on thispropagation process.</P><P>For details on the GdkEvent data types, see the appendix entitled<AHREF="app-gdkeventtypes.html">GDK Event Types</A>.</P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="sec-theoryofsignalsandcallbacks.html">&#60;&#60;&#60; Previous</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="gtk-tut.html">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="sec-steppingthroughhelloworld.html">Next &#62;&#62;&#62;</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Theory of Signals and Callbacks</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ch-gettingstarted.html">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Stepping Through Hello World</TD></TR></TABLE></DIV>        </td>    </tr></table>  </td>  </tr></table></body></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -