Re: GtkToolbar drag and drop



On Mon, 2003-09-29 at 15:40, Soeren Sandmann wrote:

> 	- 116298, toolbar should not handle arbitrary targets
> 
> 	The issue here is that the toolbar claims to handle arbitrary
> 	drags.  This means it will look like you can drop strings or
> 	colors or or dates on the toolbar.
> 
> 	Owen suggests that we should define a new drop type of things
> 	that can be dropped on the toolbar, but the problem with that
> 	is that for example epiphany wants to drop URI's on the
> 	toolbar and have them turn into bookmarks. I can also imagine
> 	interfaces where it would be possible to select something and
> 	temporarily store it on the toolbar.
[snip]

>         * Make the application responsible for handling drops on the
>           toolbar. This means remove all drag_motion handler etc. from
>           the toolbar and require the application to implement it
>           through the standard gtk_drag_* API.

This would be quite a pain in the butt.  It should be possible to extend
or completely override what a widget can take as drops.  Imagine that
toolbars take in data of type "application/x-gtk-toolbar" by default. 
One should be able to do something like this:

  GtkTargetEntry extra_entries[] = {
    { "text/uri-list", 0, TEXT_URI_LIST }
  };

  gtk_drag_dest_add_targets (toolbar, 
			     extra_entries, 
			     G_N_ELEMENTS (extra_entries));

  g_signal_connect (toolbar, "drag_motion", 
		    G_CALLBACK (drag_motion_cb), NULL);

  g_signal_connect (toolbar, "drag_data_received",
		    G_CALLBACK (drag_data_received_cb), NULL);

  ...

  static gboolean
  drag_motion_cb (GtkWidget *widget, GdkDragContext *context,
		  gint x, gint y, guint time_, gpointer data)
  {
    if (gdk_drag_context_has_type (context, "text/uri-list")
	&& (context->actions & GDK_ACTION_COPY)) {
      gdk_drag_status (context, GDK_ACTION_COPY, time_);
      return TRUE;
    } else
      return FALSE; /* let the default handler deal with it */
  }

  static void
  drag_data_received_cb (GtkWidget *widget, GdkDragContext *context,
			 gint x, gint y, GtkSelectionData *sel_data,
			 guint info, guint time_, gpointer data)
  {
    if (info == TEXT_URI_LIST)
      add_uri_to_toolbar (GTK_TOOLBAR (widget), sel_data->data);
    else
      return; /* Just let the parent handle it */
  }

It should be easy to extend the types that a drag destination can
accept.  In the drag_data_received_cb() above, we also need a way to
say, "I already handled it; don't do anything", or "I didn't handle it;
let the default handler deal with it".

  Federico




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]