📄 sec-draganddropfunctions.html
字号:
<HTML><HEAD><TITLE>Functions</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="Drag-and-drop (DND)"HREF="ch-dragangdrop.html"><LINKREL="PREVIOUS"TITLE="Properties"HREF="sec-draganddropproperties.html"><LINKREL="NEXT"TITLE="GLib"HREF="ch-glib.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-draganddropproperties.html"><<< Previous</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 21. Drag-and-drop (DND)</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="ch-glib.html">Next >>></A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SEC-DRAGANDDROPFUNCTIONS">21.3. Functions</A></H1><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="SEC-DNDSOURCEWIDGETS">21.3.1. Setting up the source widget</A></H2><P>The function <TTCLASS="LITERAL">gtk_drag_source_set()</TT> specifies aset of target types for a drag operation on a widget.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_drag_source_set( GtkWidget *widget, GdkModifierType start_button_mask, const GtkTargetEntry *targets, gint n_targets, GdkDragAction actions );</PRE></TD></TR></TABLE><P>The parameters signify the following:</P><P></P><UL><LI><P><TTCLASS="LITERAL">widget</TT> specifies the drag sourcewidget</P></LI><LI><P><TTCLASS="LITERAL">start_button_mask</TT> specifies abitmask of buttons that can start the drag (e.g. GDK_BUTTON1_MASK)</P></LI><LI><P><TTCLASS="LITERAL">targets</TT> specifies a table oftarget data types the drag will support</P></LI><LI><P><TTCLASS="LITERAL">n_targets</TT> specifies the number oftargets above</P></LI><LI><P><TTCLASS="LITERAL">actions</TT> specifies a bitmask ofpossible actions for a drag from this window</P></LI></UL><P>The <TTCLASS="LITERAL">targets</TT> parameter is an array of thefollowing structure:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">struct GtkTargetEntry { gchar *target; guint flags; guint info; };</PRE></TD></TR></TABLE><P>The fields specify a string representing the drag type, optionalflags and application assigned integer identifier.</P><P>If a widget is no longer required to act as a source fordrag-and-drop operations, the function<TTCLASS="LITERAL">gtk_drag_source_unset()</TT> can be used to remove a setof drag-and-drop target types.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_drag_source_unset( GtkWidget *widget );</PRE></TD></TR></TABLE></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="SEC-SIGNALSONSOURCEWIDGETS">21.3.2. Signals on the source widget:</A></H2><P>The source widget is sent the following signals during adrag-and-drop operation.</P><DIVCLASS="TABLE"><P><B>Table 21-1. Source widget signals</B></P><TABLEBORDER="1"WIDTH="100%"BGCOLOR="#E0E0E0"CELLSPACING="0"CELLPADDING="4"CLASS="CALSTABLE"><TR><TDWIDTH="150"ALIGN="LEFT"VALIGN="MIDDLE">drag_begin</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="MIDDLE"><TTCLASS="LITERAL">void (*drag_begin)(GtkWidget *widget,GdkDragContext *dc, gpointer data)</TT></TD></TR><TR><TDWIDTH="150"ALIGN="LEFT"VALIGN="MIDDLE">drag_motion</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="MIDDLE"><TTCLASS="LITERAL">gboolean (*drag_motion)(GtkWidget *widget,GdkDragContext *dc, gint x, gint y, guint t, gpointer data)</TT></TD></TR><TR><TDWIDTH="150"ALIGN="LEFT"VALIGN="MIDDLE">drag_data_get</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="MIDDLE"><TTCLASS="LITERAL">void (*drag_data_get)(GtkWidget *widget,GdkDragContext *dc, GtkSelectionData *selection_data, guint info, guint t, gpointer data)</TT></TD></TR><TR><TDWIDTH="150"ALIGN="LEFT"VALIGN="MIDDLE">drag_data_delete</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="MIDDLE"><TTCLASS="LITERAL">void (*drag_data_delete)(GtkWidget *widget,GdkDragContext *dc, gpointer data)</TT></TD></TR><TR><TDWIDTH="150"ALIGN="LEFT"VALIGN="MIDDLE">drag_drop</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="MIDDLE"><TTCLASS="LITERAL">gboolean (*drag_drop)(GtkWidget *widget,GdkDragContext *dc, gint x, gint y, guint t, gpointer data)</TT></TD></TR><TR><TDWIDTH="150"ALIGN="LEFT"VALIGN="MIDDLE">drag_end</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="MIDDLE"><TTCLASS="LITERAL">void (*drag_end)(GtkWidget *widget,GdkDragContext *dc, gpointer data)</TT></TD></TR></TABLE></DIV></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="SEC-DNDDESTWIDGETS">21.3.3. Setting up a destination widget:</A></H2><P> <TTCLASS="LITERAL"> gtk_drag_dest_set()</TT> specifiesthat this widget can receive drops and specifies what types of drops itcan receive.</P><P> <TTCLASS="LITERAL"> gtk_drag_dest_unset()</TT> specifiesthat the widget can no longer receive drops.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_drag_dest_set( GtkWidget *widget, GtkDestDefaults flags, const GtkTargetEntry *targets, gint n_targets, GdkDragAction actions );void gtk_drag_dest_unset( GtkWidget *widget );</PRE></TD></TR></TABLE></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="SEC-SIGNALSONDESTWIDGETS">21.3.4. Signals on the destination widget:</A></H2><P>The destination widget is sent the following signals during adrag-and-drop operation.</P><DIVCLASS="TABLE"><P><B>Table 21-2. Destination widget signals</B></P><TABLEBORDER="1"WIDTH="100%"BGCOLOR="#E0E0E0"CELLSPACING="0"CELLPADDING="4"CLASS="CALSTABLE"><TR><TDWIDTH="150"ALIGN="LEFT"VALIGN="MIDDLE">drag_data_received</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="MIDDLE"><TTCLASS="LITERAL">void (*drag_data_received)(GtkWidget *widget,GdkDragContext *dc, gint x, gint y, GtkSelectionData *selection_data, guint info, guint t,gpointer data)</TT></TD></TR></TABLE></DIV></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="sec-draganddropproperties.html"><<< Previous</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="gtk-tut.html">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="ch-glib.html">Next >>></A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Properties</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ch-dragangdrop.html">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">GLib</TD></TR></TABLE></DIV> </td> </tr></table> </td> </tr></table></body></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -