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

📄 gtkdnd.c

📁 gtk是linux一款强大的夸平台的图形化开发工具
💻 C
📖 第 1 页 / 共 5 页
字号:
    {      GdkModifierType state = 0;            switch (event->type)	{	case GDK_MOTION_NOTIFY:	  state = event->motion.state;	  break;	case GDK_BUTTON_PRESS:	case GDK_2BUTTON_PRESS:	case GDK_3BUTTON_PRESS:	case GDK_BUTTON_RELEASE:	  state = event->button.state;	  break;	case GDK_KEY_PRESS:	case GDK_KEY_RELEASE:	  state = event->key.state;	  break;	case GDK_ENTER_NOTIFY:	case GDK_LEAVE_NOTIFY:	  state = event->crossing.state;	  break;	default:	  break;	}            if ((button == 2 || button == 3) && (actions & GDK_ACTION_ASK))	{	  *suggested_action = GDK_ACTION_ASK;	  *possible_actions = actions;	}      else if (state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))	{	  if ((state & GDK_SHIFT_MASK) && (state & GDK_CONTROL_MASK))	    {	      if (actions & GDK_ACTION_LINK)		{		  *suggested_action = GDK_ACTION_LINK;		  *possible_actions = GDK_ACTION_LINK;		}	    }	  else if (state & GDK_CONTROL_MASK)	    {	      if (actions & GDK_ACTION_COPY)		{		  *suggested_action = GDK_ACTION_COPY;		  *possible_actions = GDK_ACTION_COPY;		}	      return;	    }	  else	    {	      if (actions & GDK_ACTION_MOVE)		{		  *suggested_action = GDK_ACTION_MOVE;		  *possible_actions = GDK_ACTION_MOVE;		}	      return;	    }	}      else	{	  *possible_actions = actions;	  if ((state & (GDK_MOD1_MASK)) && (actions & GDK_ACTION_ASK))	    *suggested_action = GDK_ACTION_ASK;	  else if (actions & GDK_ACTION_COPY)	    *suggested_action =  GDK_ACTION_COPY;	  else if (actions & GDK_ACTION_MOVE)	    *suggested_action = GDK_ACTION_MOVE;	  else if (actions & GDK_ACTION_LINK)	    *suggested_action = GDK_ACTION_LINK;	}    }    return;}static GdkCursor *gtk_drag_get_cursor (GdkDragAction action){  gint i;    for (i = 0 ; i < n_drag_cursors - 1; i++)    if (drag_cursors[i].action == action)      break;  if (drag_cursors[i].cursor == NULL)    {      GdkColor fg, bg;      GdkPixmap *pixmap = 	gdk_bitmap_create_from_data (NULL, 				     drag_cursors[i].bits,				     CURSOR_WIDTH, CURSOR_HEIGHT);      GdkPixmap *mask = 	gdk_bitmap_create_from_data (NULL, 				     drag_cursors[i].mask,				     CURSOR_WIDTH, CURSOR_HEIGHT);      gdk_color_white (gdk_colormap_get_system (), &bg);      gdk_color_black (gdk_colormap_get_system (), &fg);            drag_cursors[i].cursor = gdk_cursor_new_from_pixmap (pixmap, mask, &fg, &bg, 0, 0);      gdk_pixmap_unref (pixmap);      gdk_pixmap_unref (mask);    }  return drag_cursors[i].cursor;}/******************** * Destination side * ********************//************************************************************* * gtk_drag_get_data: *     Get the data for a drag or drop *   arguments: *     context - drag context *     target  - format to retrieve the data in. *     time    - timestamp of triggering event. *      *   results: *************************************************************/void gtk_drag_get_data (GtkWidget      *widget,		   GdkDragContext *context,		   GdkAtom         target,		   guint32         time){  GtkWidget *selection_widget;  g_return_if_fail (widget != NULL);  g_return_if_fail (context != NULL);  selection_widget = gtk_drag_get_ipc_widget ();  gdk_drag_context_ref (context);  gtk_widget_ref (widget);    gtk_signal_connect (GTK_OBJECT (selection_widget), "selection_received",		      GTK_SIGNAL_FUNC (gtk_drag_selection_received), widget);  gtk_object_set_data (GTK_OBJECT (selection_widget), "drag-context", context);  gtk_selection_convert (selection_widget,			 gdk_drag_get_selection (context),			 target,			 time);}/************************************************************* * gtk_drag_get_source_widget: *     Get the widget the was the source of this drag, if *     the drag originated from this application. *   arguments: *     context: The drag context for this drag *   results: *     The source widget, or NULL if the drag originated from *     a different application. *************************************************************/GtkWidget *gtk_drag_get_source_widget (GdkDragContext *context){  GSList *tmp_list;  tmp_list = source_widgets;  while (tmp_list)    {      GtkWidget *ipc_widget = tmp_list->data;            if (ipc_widget->window == context->source_window)	{	  GtkDragSourceInfo *info;	  info = gtk_object_get_data (GTK_OBJECT (ipc_widget), "gtk-info");	  return info ? info->widget : NULL;	}      tmp_list = tmp_list->next;    }  return NULL;}/************************************************************* * gtk_drag_finish: *     Notify the drag source that the transfer of data *     is complete. *   arguments: *     context: The drag context for this drag *     success: Was the data successfully transferred? *     time:    The timestamp to use when notifying the destination. *   results: *************************************************************/void gtk_drag_finish (GdkDragContext *context,		 gboolean        success,		 gboolean        del,		 guint32         time){  GdkAtom target = GDK_NONE;  g_return_if_fail (context != NULL);  if (success && del)    {      target = gdk_atom_intern ("DELETE", FALSE);    }  else if (context->protocol == GDK_DRAG_PROTO_MOTIF)    {      target = gdk_atom_intern (success ? 				  "XmTRANSFER_SUCCESS" : 				  "XmTRANSFER_FAILURE",				FALSE);    }  if (target != GDK_NONE)    {      GtkWidget *selection_widget = gtk_drag_get_ipc_widget ();      gdk_drag_context_ref (context);            gtk_object_set_data (GTK_OBJECT (selection_widget), "drag-context", context);      gtk_signal_connect (GTK_OBJECT (selection_widget), "selection_received",			  GTK_SIGNAL_FUNC (gtk_drag_selection_received),			  NULL);            gtk_selection_convert (selection_widget,			     gdk_drag_get_selection (context),			     target,			     time);    }    if (!del)    gdk_drop_finish (context, success, time);}/************************************************************* * gtk_drag_highlight_paint: *     Paint a highlight indicating drag status onto the widget. *   arguments: *     widget: *   results: *************************************************************/static void gtk_drag_highlight_paint (GtkWidget  *widget){  gint x, y, width, height;  g_return_if_fail (widget != NULL);  if (GTK_WIDGET_DRAWABLE (widget))    {      if (GTK_WIDGET_NO_WINDOW (widget))	{	  x = widget->allocation.x;	  y = widget->allocation.y;	  width = widget->allocation.width;	  height = widget->allocation.height;	}      else	{	  x = 0;	  y = 0;	  gdk_window_get_size (widget->window, &width, &height);	}            gtk_draw_shadow (widget->style, widget->window,		       GTK_STATE_NORMAL, GTK_SHADOW_OUT,		       x, y, width, height);            gdk_draw_rectangle (widget->window,			  widget->style->black_gc,			  FALSE,			  x, y, width - 1, height - 1);    }}/************************************************************* * gtk_drag_highlight_expose: *     Callback for expose_event for highlighted widgets. *   arguments: *     widget: *     event: *     data: *   results: *************************************************************/static gbooleangtk_drag_highlight_expose (GtkWidget      *widget,			   GdkEventExpose *event,			   gpointer        data){  gtk_drag_highlight_paint (widget);  return TRUE;}/************************************************************* * gtk_drag_highlight: *     Highlight the given widget in the default manner. *   arguments: *     widget: *   results: *************************************************************/void gtk_drag_highlight (GtkWidget  *widget){  gtk_signal_connect_after (GTK_OBJECT (widget), "draw",			    GTK_SIGNAL_FUNC (gtk_drag_highlight_paint),			    NULL);  gtk_signal_connect (GTK_OBJECT (widget), "expose_event",		      GTK_SIGNAL_FUNC (gtk_drag_highlight_expose),		      NULL);  gtk_widget_queue_draw (widget);}/************************************************************* * gtk_drag_unhighlight: *     Refresh the given widget to remove the highlight. *   arguments: *     widget: *   results: *************************************************************/void gtk_drag_unhighlight (GtkWidget *widget){  g_return_if_fail (widget != NULL);  gtk_signal_disconnect_by_func (GTK_OBJECT (widget),				 GTK_SIGNAL_FUNC (gtk_drag_highlight_paint),				 NULL);  gtk_signal_disconnect_by_func (GTK_OBJECT (widget),				 GTK_SIGNAL_FUNC (gtk_drag_highlight_expose),				 NULL);    gtk_widget_queue_clear (widget);}/************************************************************* * gtk_drag_dest_set: *     Register a drop site, and possibly add default behaviors. *   arguments: *     widget:     *     flags:     Which types of default drag behavior to use *     targets:   Table of targets that can be accepted *     n_targets: Number of of entries in targets *     actions:    *   results: *************************************************************/void gtk_drag_dest_set   (GtkWidget            *widget,		     GtkDestDefaults       flags,		     const GtkTargetEntry *targets,		     gint                  n_targets,		     GdkDragAction         actions){  GtkDragDestSite *site;    g_return_if_fail (widget != NULL);  /* HACK, do this in the destroy */  site = gtk_object_get_data (GTK_OBJECT (widget), "gtk-drag-dest");  if (site)    gtk_signal_disconnect_by_data (GTK_OBJECT (widget), site);  if (GTK_WIDGET_REALIZED (widget))    gtk_drag_dest_realized (widget);  gtk_signal_connect (GTK_OBJECT (widget), "realize",		      GTK_SIGNAL_FUNC (gtk_drag_dest_realized), NULL);  site = g_new (GtkDragDestSite, 1);  site->flags = flags;  site->have_drag = FALSE;  if (targets)    site->target_list = gtk_target_list_new (targets, n_targets);  else    site->target_list = NULL;  site->actions = actions;  site->do_proxy = FALSE;  gtk_object_set_data_full (GTK_OBJECT (widget), "gtk-drag-dest",			    site, gtk_drag_dest_site_destroy);}/************************************************************* * gtk_drag_dest_set_proxy: *     Set up this widget to proxy drags elsewhere. *   arguments: *     widget:           *     proxy_window:    window to which forward drag events *     protocol:        Drag protocol which the dest widget accepts *     use_coordinates: If true, send the same coordinates to the *                      destination, because it is a embedded  *                      subwindow. *   results: *************************************************************/void gtk_drag_dest_set_proxy (GtkWidget      *widget,			 GdkWindow      *proxy_window,			 GdkDragProtocol protocol,			 gboolean        use_coordinates){  GtkDragDestSite *site;    g_return_if_fail (widget != NULL);  /* HACK, do this in the destroy */  site = gtk_object_get_data (GTK_OBJECT (widget), "gtk-drag-dest");  if (site)    gtk_signal_disconnect_by_data (GTK_OBJECT (widget), site);  if (GTK_WIDGET_REALIZED (widget))    gtk_drag_dest_realized (widget);  gtk_signal_connect (GTK_OBJECT (widget), "realize",		      GTK_SIGNAL_FUNC (gtk_drag_dest_realized), NULL);  site = g_new (GtkDragDestSite, 1);  site->flags = 0;  site->have_drag = FALSE;  site->target_list = NULL;  site->actions = 0;  site->proxy_window = proxy_window;  if (proxy_window)    gdk_window_ref (proxy_window);  site->do_proxy = TRUE;  site->proxy_protocol = protocol;  site->proxy_coords = use_coordinates;  gtk_object_set_data_full (GTK_OBJECT (widget), "gtk-drag-dest",			    site, gtk_drag_dest_site_destroy);}/************************************************************* * gtk_drag_dest_unset *     Unregister this widget as a drag target. *   arguments: *     widget: *   results: *************************************************************/void gtk_drag_dest_unset (GtkWidget *widget){  g_return_if_fail (widget != NULL);  gtk_object_set_data (GTK_OBJECT (widget), "gtk-drag-dest", NULL);}/************************************************************* * gtk_drag_dest_handle_event: *     Called from widget event handling code on Drag events *     for destinations. * *   arguments: *     toplevel: Toplevel widget that received the event *     event:

⌨️ 快捷键说明

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