Esempio n. 1
0
static gint
gtk_dnd_window_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *WXUNUSED(event), wxDropSource *source )
{
    source->GiveFeedback(ConvertFromGTK(gdk_drag_context_get_selected_action(source->m_dragContext)));

    return 0;
}
static gboolean
individual_drag_received (EmpathyPersonaView *self,
    GdkDragContext *context,
    GtkSelectionData *selection)
{
  EmpathyIndividualManager *manager = NULL;
  FolksIndividual *individual;
  const gchar *individual_id;
  gboolean success = FALSE;

  individual_id = (const gchar *) gtk_selection_data_get_data (selection);
  manager = empathy_individual_manager_dup_singleton ();
  individual = empathy_individual_manager_lookup_member (manager,
      individual_id);

  if (individual == NULL)
    {
      DEBUG ("Failed to find drag event individual with ID '%s'",
          individual_id);
      g_object_unref (manager);
      return FALSE;
    }

  /* Emit a signal notifying of the drag. */
  g_signal_emit (self, signals[DRAG_INDIVIDUAL_RECEIVED], 0,
      gdk_drag_context_get_selected_action (context), individual, &success);

  g_object_unref (manager);

  return success;
}
Esempio n. 3
0
static void
nemo_icon_container_receive_dropped_icons (NemoIconContainer *container,
					       GdkDragContext *context,
					       int x, int y)
{
	char *drop_target;
	gboolean local_move_only;
	double world_x, world_y;
	gboolean icon_hit;
	GdkDragAction action, real_action;

	drop_target = NULL;

	if (container->details->dnd_info->drag_info.selection_list == NULL) {
		return;
	}

	real_action = gdk_drag_context_get_selected_action (context);

	if (real_action == GDK_ACTION_ASK) {
		/* FIXME bugzilla.gnome.org 42485: This belongs in FMDirectoryView, not here. */
		/* Check for special case items in selection list */
		if (nemo_drag_selection_includes_special_link (container->details->dnd_info->drag_info.selection_list)) {
			/* We only want to move the trash */
			action = GDK_ACTION_MOVE;
		} else {
			action = GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK;
		}
		real_action = nemo_drag_drop_action_ask (GTK_WIDGET (container), action);
	}

	if (real_action > 0) {
		eel_canvas_window_to_world (EEL_CANVAS (container),
					    x + gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container))),
					    y + gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container))),
					    &world_x, &world_y);

		drop_target = nemo_icon_container_find_drop_target (container, 
									context, x, y, &icon_hit, FALSE);

		local_move_only = FALSE;
		if (!icon_hit && real_action == GDK_ACTION_MOVE) {
			/* we can just move the icon positions if the move ended up in
			 * the item's parent container
			 */
			local_move_only = nemo_icon_container_selection_items_local
				(container, container->details->dnd_info->drag_info.selection_list);
		}

		if (local_move_only) {
			handle_local_move (container, world_x, world_y);
		} else {
			handle_nonlocal_move (container, real_action, world_x, world_y, drop_target, icon_hit);
		}
	}

	g_free (drop_target);
	nemo_drag_destroy_selection_list (container->details->dnd_info->drag_info.selection_list);
	container->details->dnd_info->drag_info.selection_list = NULL;
}
Esempio n. 4
0
void Ctrl::GtkDragEnd(GtkWidget *widget, GdkDragContext *context, gpointer user_data)
{
    LLOG("GtkDragEnd");
    dnd_result = DND_NONE;
    GdkDragAction a = gdk_drag_context_get_selected_action(context);
    dnd_result = a == GDK_ACTION_MOVE ? DND_MOVE : a == GDK_ACTION_COPY ? DND_COPY : DND_NONE;
    dnd_source = NULL;
}
Esempio n. 5
0
static void
source_drag_data_get  (GtkWidget          *WXUNUSED(widget),
                       GdkDragContext     *context,
                       GtkSelectionData   *selection_data,
                       guint               WXUNUSED(info),
                       guint               WXUNUSED(time),
                       wxDropSource       *drop_source )
{
    wxDataFormat format(gtk_selection_data_get_target(selection_data));

    wxLogTrace(TRACE_DND, wxT("Drop source: format requested: %s"),
               format.GetId().c_str());

    drop_source->m_retValue = wxDragError;

    wxDataObject *data = drop_source->GetDataObject();

    if (!data)
    {
        wxLogTrace(TRACE_DND, wxT("Drop source: no data object") );
        return;
    }

    if (!data->IsSupportedFormat(format))
    {
        wxLogTrace(TRACE_DND, wxT("Drop source: unsupported format") );
        return;
    }

    if (data->GetDataSize(format) == 0)
    {
        wxLogTrace(TRACE_DND, wxT("Drop source: empty data") );
        return;
    }

    size_t size = data->GetDataSize(format);

//  printf( "data size: %d.\n", (int)data_size );

    guchar *d = new guchar[size];

    if (!data->GetDataHere( format, (void*)d ))
    {
        delete[] d;
        return;
    }

    drop_source->m_retValue = ConvertFromGTK(gdk_drag_context_get_selected_action(context));

    gtk_selection_data_set( selection_data,
                            gtk_selection_data_get_target(selection_data),
                            8,   // 8-bit
                            d,
                            size );

    delete[] d;
}
Esempio n. 6
0
void Ctrl::GtkDragEnd(GtkWidget *widget, GdkDragContext *context, gpointer user_data)
{
	LLOG("GtkDragEnd");
	dnd_result = DND_NONE;
#if GTK_CHECK_VERSION(2,22,0) // No drag&drop support before 2.22, sorry...
	GdkDragAction a = gdk_drag_context_get_selected_action(context);
	dnd_result = a == GDK_ACTION_MOVE ? DND_MOVE : a == GDK_ACTION_COPY ? DND_COPY : DND_NONE;
#else
	dnd_result = DND_NONE;
#endif
	dnd_source = NULL;
}
Esempio n. 7
0
/* Emitted when the data has been received from the source. It should check
 * the GtkSelectionData sent by the source, and do something with it. Finally
 * it needs to finish the operation by calling gtk_drag_finish, which will emit
 * the "data-delete" signal if told to. */
static void drag_data_received_handler(GtkWidget *widget, GdkDragContext *context, 
    gint x, gint y, GtkSelectionData *selection_data, guint target_type, guint time,
    gpointer data)
{
    char *filename, *p, *lfn;
    gboolean dnd_success = FALSE;
    gboolean delete_selection_data = FALSE;
    DBG(("drag_data_received_handler"));

    /* Deal with what we are given from source */
    if(dropdata && (selection_data != NULL) && (gtk_selection_data_get_length (selection_data) >= 0))
    {
        dropdata = 0;
        if (gdk_drag_context_get_selected_action(context) == GDK_ACTION_MOVE) {
            delete_selection_data = TRUE;
        }

        /* FIXME; Check that we got a format we can use */
        filename = (char*)gtk_selection_data_get_data(selection_data);
        DBG(("DnD got string: %s", filename));
        dnd_success = TRUE;
        /* incase we got a list of files, terminate the list after the first
           file */
        p = filename;
        while (*p) {
            if ((*p == '\n') || (*p == '\r')) {
                *p = 0;
                break;
            }
            p++;
        }
	lfn = g_filename_from_uri(filename, NULL, NULL);
	if (!lfn) {
	    log_error(ui_log, "URI conversion failed: %s", filename);
	}
	
        DBG(("DnD using filename: '%s'", lfn));
        /* finally call the drop callback set by the individual ui */
        if (drop_cb) {
            drop_cb(lfn);
        }
        DBG(("DnD done"));
	if (lfn) {
	    free(lfn);
	}
    }

    if (dnd_success == FALSE) {
        DBG(("DnD data transfer failed!"));
    }

    gtk_drag_finish (context, dnd_success, delete_selection_data, time);
}
Esempio n. 8
0
static void gtkDragDataGet(GtkWidget *widget, GdkDragContext *drag_context, GtkSelectionData *seldata, guint info, guint time, Ihandle* ih)
{
  IFnsCi cbDragData = (IFnsCi)IupGetCallback(ih, "DRAGDATA_CB");
  IFns cbDragDataSize = (IFns)IupGetCallback(ih, "DRAGDATASIZE_CB");
  if(cbDragData && cbDragDataSize)
  {
    void* sourceData;
    char *type;
    int size;
    GdkDragAction action;

#if GTK_CHECK_VERSION(2, 22, 0)
    action = gdk_drag_context_get_selected_action(drag_context);
#else
    action = drag_context->action;
#endif

#if GTK_CHECK_VERSION(2, 14, 0)
    type = gdk_atom_name(gtk_selection_data_get_target(seldata));
#else
    type = seldata->type;
#endif
    if (action != GDK_ACTION_MOVE && action != GDK_ACTION_COPY)
      return;

    size = cbDragDataSize(ih, type);
    if (size <= 0)
      return;

    sourceData = malloc(size+1);

    /* fill data */
    cbDragData(ih, type, sourceData, size);

    /* Zero-terminates the stored data. */
    ((guchar*)sourceData)[size] = 0;

    gtk_selection_data_set(seldata, gdk_atom_intern(type, 0), 8, (guchar*)sourceData, size+1);

    /* gtk_selection_data_set will copy the data */
    free(sourceData);
  }

  (void)widget;
  (void)drag_context;
  (void)time;
  (void)info;
}
Esempio n. 9
0
static void target_drag_data_received( GtkWidget *WXUNUSED(widget),
                                       GdkDragContext *context,
                                       gint x,
                                       gint y,
                                       GtkSelectionData *data,
                                       guint WXUNUSED(info),
                                       guint time,
                                       wxDropTarget *drop_target )
{
    /* Owen Taylor: "call gtk_drag_finish() with
       success == TRUE" */

    if (gtk_selection_data_get_length(data) <= 0 || gtk_selection_data_get_format(data) != 8)
    {
        /* negative data length and non 8-bit data format
           qualifies for junk */
        gtk_drag_finish (context, FALSE, FALSE, time);

        return;
    }

    wxLogTrace(TRACE_DND, wxT( "Drop target: data received event") );

    /* inform the wxDropTarget about the current GtkSelectionData.
       this is only valid for the duration of this call */
    drop_target->GTKSetDragData( data );

    wxDragResult result = ConvertFromGTK(gdk_drag_context_get_selected_action(context));

    if ( wxIsDragResultOk( drop_target->OnData( x, y, result ) ) )
    {
        wxLogTrace(TRACE_DND, wxT( "Drop target: OnData returned true") );

        /* tell GTK that data transfer was successful */
        gtk_drag_finish( context, TRUE, FALSE, time );
    }
    else
    {
        wxLogTrace(TRACE_DND, wxT( "Drop target: OnData returned FALSE") );

        /* tell GTK that data transfer was not successful */
        gtk_drag_finish( context, FALSE, FALSE, time );
    }

    /* after this, invalidate the drop_target's drag data */
    drop_target->GTKSetDragData( NULL );
}
Esempio n. 10
0
static void gtkDragDataReceived(GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y,
                            GtkSelectionData *seldata, guint info, guint time, Ihandle *ih)
{
  IFnsCiii cbDrop = (IFnsCiii)IupGetCallback(ih, "DROPDATA_CB");
  void* targetData = NULL;
  char* type;
  int size, format, res;
  GdkDragAction action;

#if GTK_CHECK_VERSION(2, 22, 0)
  action = gdk_drag_context_get_selected_action(drag_context);
#else
  action = drag_context->action;
#endif

#if GTK_CHECK_VERSION(2, 14, 0)
  type = gdk_atom_name(gtk_selection_data_get_target(seldata));
  targetData = (void*)gtk_selection_data_get_data(seldata);
  size = gtk_selection_data_get_length(seldata);
  format = gtk_selection_data_get_format(seldata);
#else
  type = gdk_atom_name(seldata->type);
  targetData = (void*)seldata->data;
  size = seldata->length;
  format = seldata->format;
#endif

  if(size <= 0 || format != 8 ||
    (action != GDK_ACTION_MOVE && action != GDK_ACTION_COPY))
  {
    gtk_drag_finish(drag_context, FALSE, FALSE, time);
    return;
  }

  if(cbDrop)
    res = cbDrop(ih, type, targetData, size, x, y);

  gtk_drag_finish(drag_context, TRUE, FALSE, time);

  (void)info;
  (void)widget;
  (void)time;
}
static void
receive_uris (NautilusTreeViewDragDest *dest,
              GdkDragContext *context,
              GList *source_uris,
              int x, int y)
{
    char *drop_target;
    GdkDragAction action, real_action;

    drop_target = get_drop_target_uri_at_pos (dest, x, y);
    g_assert (drop_target != NULL);

    real_action = gdk_drag_context_get_selected_action (context);

    if (real_action == GDK_ACTION_ASK) {
        if (nautilus_drag_selection_includes_special_link (dest->details->drag_list)) {
            /* We only want to move the trash */
            action = GDK_ACTION_MOVE;
        } else {
            action = GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK;
        }
        real_action = nautilus_drag_drop_action_ask
                      (GTK_WIDGET (dest->details->tree_view), action);
    }

    /* We only want to copy external uris */
    if (dest->details->drag_type == NAUTILUS_ICON_DND_URI_LIST) {
        real_action = GDK_ACTION_COPY;
    }

    if (real_action > 0) {
        if (!nautilus_drag_uris_local (drop_target, source_uris)
                || real_action != GDK_ACTION_MOVE) {
            g_signal_emit (dest, signals[MOVE_COPY_ITEMS], 0,
                           source_uris,
                           drop_target,
                           real_action,
                           x, y);
        }
    }

    g_free (drop_target);
}
Esempio n. 12
0
/* handle dropped text */
static void
receive_dropped_text (NemoIconContainer *container, const char *text, GdkDragContext *context, int x, int y)
{	
	char *drop_target;

	if (text == NULL) {
		return;
	}

	drop_target = nemo_icon_container_find_drop_target (container, context, x, y, NULL, TRUE);
	
	g_signal_emit_by_name (container, "handle_text",
			       text,
			       drop_target,
			       gdk_drag_context_get_selected_action (context),
			       x, y);

	g_free (drop_target);
}
Esempio n. 13
0
static void dispatchEvent(GdkEvent* event)
{
    webkit_web_frame_layout(mainFrame);
    WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
    if (!view) {
        gdk_event_free(event);
        return;
    }

    gtk_main_do_event(event);

    if (!currentDragSourceContext) {
        gdk_event_free(event);
        return;
    }

    if (event->type == GDK_MOTION_NOTIFY) {
        // WebKit has called gtk_drag_start(), but because the main loop isn't
        // running GDK internals don't know that the drag has started yet. Pump
        // the main loop a little bit so that GDK is in the correct state.
        while (gtk_events_pending())
            gtk_main_iteration();

        // Simulate a drag motion on the top-level GDK window.
        GtkWidget* parentWidget = gtk_widget_get_parent(GTK_WIDGET(view));
        GdkWindow* parentWidgetWindow = gtk_widget_get_window(parentWidget);
        gdk_drag_motion(currentDragSourceContext, parentWidgetWindow, GDK_DRAG_PROTO_XDND,
            event->motion.x_root, event->motion.y_root,
            gdk_drag_context_get_selected_action(currentDragSourceContext),
            gdk_drag_context_get_actions(currentDragSourceContext),
            GDK_CURRENT_TIME);

    } else if (currentDragSourceContext && event->type == GDK_BUTTON_RELEASE) {
        // We've released the mouse button, we should just be able to spin the
        // event loop here and have GTK+ send the appropriate notifications for
        // the end of the drag.
        while (gtk_events_pending())
            gtk_main_iteration();
    }

    gdk_event_free(event);
}
Esempio n. 14
0
/* handle dropped raw data */
static void
receive_dropped_raw (NemoIconContainer *container, const char *raw_data, int length, const char *direct_save_uri, GdkDragContext *context, int x, int y)
{
	char *drop_target;

	if (raw_data == NULL) {
		return;
	}

	drop_target = nemo_icon_container_find_drop_target (container, context, x, y, NULL, TRUE);

	g_signal_emit_by_name (container, "handle_raw",
			       raw_data,
			       length,
			       drop_target,
			       direct_save_uri,
			       gdk_drag_context_get_selected_action (context),
			       x, y);

	g_free (drop_target);
}
static void
receive_dropped_netscape_url (NautilusTreeViewDragDest *dest,
                              GdkDragContext *context,
                              int x, int y)
{
    char *drop_target;

    if (!dest->details->drag_data) {
        return;
    }

    drop_target = get_drop_target_uri_at_pos (dest, x, y);
    g_assert (drop_target != NULL);

    g_signal_emit (dest, signals[HANDLE_NETSCAPE_URL], 0,
                   (char*) gtk_selection_data_get_data (dest->details->drag_data),
                   drop_target,
                   gdk_drag_context_get_selected_action (context),
                   x, y);

    g_free (drop_target);
}
static void
receive_dropped_raw (NautilusTreeViewDragDest *dest,
                     const char *raw_data, int length,
                     GdkDragContext *context,
                     int x, int y)
{
    char *drop_target;

    if (!dest->details->drag_data) {
        return;
    }

    drop_target = get_drop_target_uri_at_pos (dest, x, y);
    g_assert (drop_target != NULL);

    g_signal_emit (dest, signals[HANDLE_RAW], 0,
                   raw_data, length, drop_target,
                   dest->details->direct_save_uri,
                   gdk_drag_context_get_selected_action (context),
                   x, y);

    g_free (drop_target);
}
static void
receive_dropped_text (NemoTreeViewDragDest *dest,
		      GdkDragContext *context,
		      int x, int y)
{
	char *drop_target;
	char *text;

	if (!dest->details->drag_data) {
		return;
	}

	drop_target = get_drop_target_uri_at_pos (dest, x, y);
	g_assert (drop_target != NULL);

	text = gtk_selection_data_get_text (dest->details->drag_data);
	g_signal_emit (dest, signals[HANDLE_TEXT], 0,
		       (char *) text, drop_target,
		       gdk_drag_context_get_selected_action (context),
		       x, y);

	g_free (text);
	g_free (drop_target);
}
Esempio n. 18
0
static void gtkDragEnd(GtkWidget *widget, GdkDragContext *drag_context, Ihandle *ih)
{
  IFni cbDrag = (IFni)IupGetCallback(ih, "DRAGEND_CB");
  if(cbDrag)
  {
    GdkDragAction action;
    int remove = -1;

#if GTK_CHECK_VERSION(2, 22, 0)
    action = gdk_drag_context_get_selected_action(drag_context);
#else
    action = drag_context->action;
#endif

    if (action == GDK_ACTION_MOVE)
      remove = 1;
    else if (action == GDK_ACTION_COPY)
      remove = 0;

    cbDrag(ih, remove);
  }

  (void)widget;
}
Esempio n. 19
0
static void
gth_file_list_drag_data_received (GtkWidget        *file_view,
				  GdkDragContext   *context,
				  int               x,
				  int               y,
				  GtkSelectionData *selection_data,
				  guint             info,
				  guint             time,
				  gpointer          user_data)
{
	GthBrowser     *browser = user_data;
	gboolean        success = FALSE;
	char          **uris;
	GList          *selected_files;
	GdkDragAction   action;

	g_signal_stop_emission_by_name (file_view, "drag-data-received");

	action = gdk_drag_context_get_suggested_action (context);
	if (action == GDK_ACTION_COPY || action == GDK_ACTION_MOVE) {
		success = TRUE;
	}

	if (action == GDK_ACTION_ASK) {
		GdkDragAction actions =
			_gtk_menu_ask_drag_drop_action (file_view,
							gdk_drag_context_get_actions (context),
							time);
		gdk_drag_status (context, actions, time);
		success = gdk_drag_context_get_selected_action (context) != 0;
	}

	if (gtk_selection_data_get_data_type (selection_data) == XDND_ACTION_DIRECT_SAVE_ATOM) {
		const guchar *data;
		int           format;
		int           length;

		data = gtk_selection_data_get_data (selection_data);
		format = gtk_selection_data_get_format (selection_data);
		length = gtk_selection_data_get_length (selection_data);

		if ((format == 8) && (length == 1) && (data[0] == 'S')) {
			success = TRUE;
		}
		else {
			gdk_property_change (gdk_drag_context_get_dest_window (context),
					     XDND_ACTION_DIRECT_SAVE_ATOM,
					     TEXT_PLAIN_ATOM,
					     8,
					     GDK_PROP_MODE_REPLACE,
					     (const guchar *) "",
					     0);
			success = FALSE;
		}

		gtk_drag_finish (context, success, FALSE, time);
		return;
	}

	gtk_drag_finish (context, success, FALSE, time);
	if (! success)
		return;

	uris = gtk_selection_data_get_uris (selection_data);
	selected_files = _g_file_list_new_from_uriv (uris);
	if (selected_files != NULL) {
		if (gtk_drag_get_source_widget (context) == file_view) {
			GList       *file_data_list;
			GList       *visible_files;
			BrowserData *data;
			GthTask     *task;

			file_data_list = gth_file_store_get_visibles (gth_browser_get_file_store (browser));
			visible_files = gth_file_data_list_to_file_list (file_data_list);

			data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
			task = gth_reorder_task_new (gth_browser_get_location_source (browser),
						     gth_browser_get_location_data (browser),
						     visible_files,
						     selected_files,
						     data->drop_pos);
			gth_browser_exec_task (browser, task, FALSE);

			g_object_unref (task);
			_g_object_list_unref (visible_files);
			_g_object_list_unref (file_data_list);
		}
		else {
			GthFileSource *file_source;
			gboolean       cancel = FALSE;
			gboolean       move;

			file_source = gth_browser_get_location_source (browser);
			move = gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE;
			if (move && ! gth_file_source_can_cut (file_source, (GFile *) selected_files->data)) {
				GtkWidget *dialog;
				int        response;

				dialog = _gtk_message_dialog_new (GTK_WINDOW (browser),
								  GTK_DIALOG_MODAL,
								  GTK_STOCK_DIALOG_QUESTION,
								  _("Could not move the files"),
								  _("Files cannot be moved to the current location, as alternative you can choose to copy them."),
								  GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
								  GTK_STOCK_COPY, GTK_RESPONSE_OK,
								  NULL);
				response = gtk_dialog_run (GTK_DIALOG (dialog));
				gtk_widget_destroy (dialog);

				if (response == GTK_RESPONSE_CANCEL)
					cancel = TRUE;

				move = FALSE;
			}

			if (! cancel) {
				GthFileSource *location_source;
				BrowserData   *data;
				GthTask       *task;

				location_source = gth_main_get_file_source (gth_browser_get_location (browser));
				data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
				task = gth_copy_task_new (location_source,
							  gth_browser_get_location_data (browser),
							  move,
							  selected_files,
							  data->drop_pos);
				gth_browser_exec_task (browser, task, FALSE);

				g_object_unref (task);
				g_object_unref (location_source);
			}
		}
	}

	_g_object_list_unref (selected_files);
	g_strfreev (uris);
}
Esempio n. 20
0
gboolean on_dir_tree_view_drag_motion ( GtkWidget *widget,
                                      GdkDragContext *drag_context,
                                      gint x,
                                      gint y,
                                      guint time,
                                      PtkFileBrowser* file_browser )  //MOD added
{
    GdkDragAction suggested_action;
    GdkAtom target;
    GtkTargetList* target_list;

    target_list = gtk_target_list_new( drag_targets, G_N_ELEMENTS(drag_targets) );
    target = gtk_drag_dest_find_target( widget, drag_context, target_list );
    gtk_target_list_unref( target_list );

    if (target == GDK_NONE)
        gdk_drag_status( drag_context, 0, time);
    else
    {
        // Need to set suggested_action because default handler assumes copy
        /* Only 'move' is available. The user force move action by pressing Shift key */
        if( (gdk_drag_context_get_actions ( drag_context ) & GDK_ACTION_ALL) == GDK_ACTION_MOVE )
            suggested_action = GDK_ACTION_MOVE;
        /* Only 'copy' is available. The user force copy action by pressing Ctrl key */
        else if( (gdk_drag_context_get_actions ( drag_context ) & GDK_ACTION_ALL) == GDK_ACTION_COPY )
            suggested_action = GDK_ACTION_COPY;
        /* Only 'link' is available. The user force link action by pressing Shift+Ctrl key */
        else if( (gdk_drag_context_get_actions ( drag_context ) & GDK_ACTION_ALL) == GDK_ACTION_LINK )
            suggested_action = GDK_ACTION_LINK;
        /* Several different actions are available. We have to figure out a good default action. */
        else
        {
            int drag_action = xset_get_int( "drag_action", "x" );
            if ( drag_action == 1 )
                suggested_action = GDK_ACTION_COPY;
            else if ( drag_action == 2 )
                suggested_action = GDK_ACTION_MOVE;
            else if ( drag_action == 3 )
                suggested_action = GDK_ACTION_LINK;
            else
            {
                // automatic
                file_browser->pending_drag_status_tree = 1;
                gtk_drag_get_data (widget, drag_context, target, time);
                suggested_action = gdk_drag_context_get_selected_action( drag_context );
            }
        }
#if GTK_CHECK_VERSION (3, 0, 0)
        /* hack to be able to call the default handler with the correct suggested_action */
        struct _GdkDragContext {
          GObject parent_instance;

          /*< private >*/
          GdkDragProtocol protocol;
#if GTK_CHECK_VERSION (3, 22, 0)
          /* 1.0.6 per Teklad: _GdkDragContext appears to change between
           * different versions of GTK3 which causes the crash. It appears they
           * added/removed some variables from that struct.
           * https://github.com/IgnorantGuru/spacefm/issues/670 */
          GdkDisplay *display;
#endif
          gboolean is_source;
          GdkWindow *source_window;
          GdkWindow *dest_window;

          GList *targets;
          GdkDragAction actions;
          GdkDragAction suggested_action;
          GdkDragAction action;

          guint32 start_time;

          GdkDevice *device;
#if GTK_CHECK_VERSION (3, 22, 0)
          /* 1.0.6 per Teklad: _GdkDragContext appears to change between
           * different versions of GTK3 which causes the crash. It appears they
           * added/removed some variables from that struct.
           * https://github.com/IgnorantGuru/spacefm/issues/670 */
          guint drop_done : 1; /* Whether gdk_drag_drop_done() was performed */
#endif
        };
        ((struct _GdkDragContext *)drag_context)->suggested_action = suggested_action;
#else
        drag_context->suggested_action = suggested_action; // needed for default handler
#endif
        gdk_drag_status( drag_context, suggested_action, gtk_get_current_event_time() );
    }
    return FALSE;
}
Esempio n. 21
0
static void
slot_proxy_handle_drop (GtkWidget                *widget,
                        GdkDragContext           *context,
                        unsigned int              time,
                        NautilusDragSlotProxyInfo *drag_info)
{
    GtkWidget *window;
    NautilusWindowSlot *target_slot;
    NautilusFilesView *target_view;
    char *target_uri;
    GList *uri_list;
    GFile *location;

    if (!drag_info->have_data ||
            !drag_info->have_valid_data) {
        gtk_drag_finish (context, FALSE, FALSE, time);
        drag_info_clear (drag_info);
        return;
    }

    window = gtk_widget_get_toplevel (widget);
    g_assert (NAUTILUS_IS_WINDOW (window));

    if (drag_info->target_slot != NULL) {
        target_slot = drag_info->target_slot;
    } else {
        target_slot = nautilus_window_get_active_slot (NAUTILUS_WINDOW (window));
    }

    target_uri = NULL;
    if (drag_info->target_file != NULL) {
        target_uri = nautilus_file_get_uri (drag_info->target_file);
    } else if (target_slot != NULL) {
        location = nautilus_window_slot_get_location (target_slot);
        target_uri = g_file_get_uri (location);
    }

    target_view = NULL;
    if (target_slot != NULL) {
        NautilusView *view;

        view = nautilus_window_slot_get_current_view (target_slot);

        if (view && NAUTILUS_IS_FILES_VIEW (view)) {
            target_view = NAUTILUS_FILES_VIEW (view);
        }
    }

    if (target_slot != NULL && target_view != NULL) {
        if (drag_info->info == NAUTILUS_ICON_DND_GNOME_ICON_LIST) {
            uri_list = nautilus_drag_uri_list_from_selection_list (drag_info->data.selection_list);
            g_assert (uri_list != NULL);

            nautilus_files_view_drop_proxy_received_uris (target_view,
                    uri_list,
                    target_uri,
                    gdk_drag_context_get_selected_action (context));
            g_list_free_full (uri_list, g_free);
        } else if (drag_info->info == NAUTILUS_ICON_DND_URI_LIST) {
            nautilus_files_view_drop_proxy_received_uris (target_view,
                    drag_info->data.uri_list,
                    target_uri,
                    gdk_drag_context_get_selected_action (context));
        }
        if (drag_info->info == NAUTILUS_ICON_DND_NETSCAPE_URL) {
            nautilus_files_view_handle_netscape_url_drop (target_view,
                    drag_info->data.netscape_url,
                    target_uri,
                    gdk_drag_context_get_selected_action (context),
                    0, 0);
        }


        gtk_drag_finish (context, TRUE, FALSE, time);
    } else {
        gtk_drag_finish (context, FALSE, FALSE, time);
    }

    g_free (target_uri);

    drag_info_clear (drag_info);
}
Esempio n. 22
0
void on_dir_tree_view_drag_data_received ( GtkWidget *widget,
                                         GdkDragContext *drag_context,
                                         gint x,
                                         gint y,
                                         GtkSelectionData *sel_data,
                                         guint info,
                                         guint time,
                                         gpointer user_data )  //MOD added
{
    gchar **list, **puri;
    GList* files = NULL;
    PtkFileTask* task;
    VFSFileTaskType file_action = VFS_FILE_TASK_MOVE;
    PtkFileBrowser* file_browser = ( PtkFileBrowser* ) user_data;
    char* dest_dir;
    char* file_path;
    GtkWidget* parent_win;

    /*  Don't call the default handler  */
    g_signal_stop_emission_by_name( widget, "drag-data-received" );

    if ( ( gtk_selection_data_get_length( sel_data ) >= 0 ) && ( gtk_selection_data_get_format( sel_data ) == 8 ) )
    {
        dest_dir = dir_tree_view_get_drop_dir( widget, x, y );
        if ( dest_dir )
        {
            puri = list = gtk_selection_data_get_uris( sel_data );
            if( file_browser->pending_drag_status_tree )
            {
                // We only want to update drag status, not really want to drop
                dev_t dest_dev;
                struct stat statbuf;    // skip stat64
                if( stat( dest_dir, &statbuf ) == 0 )
                {
                    dest_dev = statbuf.st_dev;
                    if( 0 == file_browser->drag_source_dev_tree )
                    {
                        file_browser->drag_source_dev_tree = dest_dev;
                        for( ; *puri; ++puri )
                        {
                            file_path = g_filename_from_uri( *puri, NULL, NULL );
                            if( stat( file_path, &statbuf ) == 0 && statbuf.st_dev != dest_dev )
                            {
                                file_browser->drag_source_dev_tree = statbuf.st_dev;
                                g_free( file_path );
                                break;
                            }
                            g_free( file_path );
                        }
                    }
                    if( file_browser->drag_source_dev_tree != dest_dev )
                        // src and dest are on different devices */
                        gdk_drag_status( drag_context, GDK_ACTION_COPY, time);
                    else
                        gdk_drag_status( drag_context, GDK_ACTION_MOVE, time);
                }
                else
                    // stat failed
                    gdk_drag_status( drag_context, GDK_ACTION_COPY, time);

                g_free( dest_dir );
                g_strfreev( list );
                file_browser->pending_drag_status_tree = 0;
                return;
            }

            if ( puri )
            {
                if ( 0 == ( gdk_drag_context_get_selected_action ( drag_context ) &
                            ( GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK ) ) )
                {
                    gdk_drag_status( drag_context, GDK_ACTION_MOVE, time);
                }
                gtk_drag_finish ( drag_context, TRUE, FALSE, time );

                while ( *puri )
                {
                    if ( **puri == '/' )
                        file_path = g_strdup( *puri );
                    else
                        file_path = g_filename_from_uri( *puri, NULL, NULL );

                    if ( file_path )
                        files = g_list_prepend( files, file_path );
                    ++puri;
                }
                g_strfreev( list );

                switch ( gdk_drag_context_get_selected_action ( drag_context ) )
                {
                case GDK_ACTION_COPY:
                    file_action = VFS_FILE_TASK_COPY;
                    break;
                case GDK_ACTION_LINK:
                    file_action = VFS_FILE_TASK_LINK;
                    break;
                    /* FIXME:
                      GDK_ACTION_DEFAULT, GDK_ACTION_PRIVATE, and GDK_ACTION_ASK are not handled */
                default:
                    break;
                }
                if ( files )
                {
                    /* Accept the drop and perform file actions */
                    {
                        parent_win = gtk_widget_get_toplevel( GTK_WIDGET( file_browser ) );
                        task = ptk_file_task_new( file_action,
                                                  files,
                                                  dest_dir,
                                                  GTK_WINDOW( parent_win ),
                                                  file_browser->task_view );
                        ptk_file_task_run( task );
                    }
                }
                g_free( dest_dir );
                gtk_drag_finish ( drag_context, TRUE, FALSE, time );
                return ;
            }
            g_free( dest_dir );
        }
        //else
        //    g_warning ("bad dest_dir in on_dir_tree_view_drag_data_received");
    }
    /* If we are only getting drag status, not finished. */
    if( file_browser->pending_drag_status_tree )
    {
        gdk_drag_status ( drag_context, GDK_ACTION_COPY, time );
        file_browser->pending_drag_status_tree = 0;
        return;
    }
    gtk_drag_finish ( drag_context, FALSE, FALSE, time );
}
Esempio n. 23
0
void DragAndDropHandler::finishDrag(GdkDragContext* context)
{
    if (!m_draggingDataObjects.remove(context))
        return;

    GdkDevice* device = gdk_drag_context_get_device(context);
    int x = 0, y = 0;
    gdk_device_get_window_at_position(device, &x, &y);
    int xRoot = 0, yRoot = 0;
    gdk_device_get_position(device, nullptr, &xRoot, &yRoot);
    m_page.dragEnded(IntPoint(x, y), IntPoint(xRoot, yRoot), gdkDragActionToDragOperation(gdk_drag_context_get_selected_action(context)));
}
Esempio n. 24
0
static void
dia_dnd_file_drag_data_received (GtkWidget        *widget,
                                 GdkDragContext   *context,
                                 gint              x,
                                 gint              y,
                                 GtkSelectionData *data,
                                 guint             info,
                                 guint             time,
				 DDisplay         *ddisp)
{
#if GTK_CHECK_VERSION(2,22,0)
  switch (gdk_drag_context_get_selected_action(context))
#else
  switch (context->action)
#endif
    {
    case GDK_ACTION_DEFAULT:
    case GDK_ACTION_COPY:
    case GDK_ACTION_MOVE:
    case GDK_ACTION_LINK:
    case GDK_ACTION_ASK:
    default:
      {
        Diagram *diagram = NULL;
        gchar *sPath = NULL, *pFrom, *pTo; 

        pFrom = strstr((gchar *) gtk_selection_data_get_data(data), "file:");
        while (pFrom) {
          GError *error = NULL;

          pTo = pFrom;
          while (*pTo != 0 && *pTo != 0xd && *pTo != 0xa) pTo ++;
          sPath = g_strndup(pFrom, pTo - pFrom);

          /* format changed with Gtk+2.0, use conversion */
          pFrom = g_filename_from_uri (sPath, NULL, &error);
	  if (!ddisp)
            diagram = diagram_load (pFrom, NULL);
	  else {
	    diagram = ddisp->diagram;
	    if (!diagram_load_into (diagram, pFrom, NULL)) {
	      /* the import filter is supposed to show the error message */
              gtk_drag_finish (context, TRUE, FALSE, time);
	      break;
	    }
	  }

          g_free (pFrom);
          g_free(sPath);

          if (diagram != NULL) {
            diagram_update_extents(diagram);
            layer_dialog_set_diagram(diagram);
            
	    if (diagram->displays == NULL) {
	      new_display(diagram);
	    }
          }

          pFrom = strstr(pTo, "file:");
        } /* while */
        gtk_drag_finish (context, TRUE, FALSE, time);
      }
      break;
    }
  return;
}
Esempio n. 25
0
void
panel_receive_dnd_data (PanelWidget      *panel,
			guint             info,
			int               pos,
			GtkSelectionData *selection_data,
			GdkDragContext   *context,
			guint             time_)
{
	const guchar *data;
	gboolean      success = FALSE;

	if (panel_lockdown_get_locked_down ()) {
		gtk_drag_finish (context, FALSE, FALSE, time_);
		return;
	}

	data = gtk_selection_data_get_data (selection_data);

	switch (info) {
	case TARGET_URL:
		success = drop_urilist (panel, pos, (char *)data);
		break;
	case TARGET_NETSCAPE_URL:
		success = drop_url (panel, pos, (char *)data);
		break;
	case TARGET_COLOR:
		success = set_background_color (panel->toplevel, (guint16 *) data);
		break;
	case TARGET_BGIMAGE:
		success = set_background_image_from_uri (panel->toplevel, (char *) data);
		break;
	case TARGET_BACKGROUND_RESET:
		if (panel_profile_background_key_is_writable (panel->toplevel, "type")) {
			panel_profile_set_background_type (panel->toplevel, PANEL_BACK_NONE);
			success = TRUE;
		} else {
			success = FALSE;
		}
		break;
	case TARGET_DIRECTORY:
		success = drop_uri (panel, pos, (char *)data,
				    PANEL_ICON_FOLDER);
		break;
	case TARGET_APPLET:
		if (!gtk_selection_data_get_data (selection_data)) {
			gtk_drag_finish (context, FALSE, FALSE, time_);
			return;
		}
		if (panel_profile_id_lists_are_writable ()) {
			mate_panel_applet_frame_create (panel->toplevel, pos, (char *) data);
			success = TRUE;
		} else {
			success = FALSE;
		}
		break;
	case TARGET_APPLET_INTERNAL:
		success = drop_internal_applet (panel, pos, (char *)data,
						gdk_drag_context_get_selected_action (context));
		break;
	case TARGET_ICON_INTERNAL:
		success = drop_internal_icon (panel, pos, (char *)data,
					      gdk_drag_context_get_selected_action (context));
		break;
	default:
		gtk_drag_finish (context, FALSE, FALSE, time_);
		return;
	}

	gtk_drag_finish (context, success, FALSE, time_);
}
Esempio n. 26
0
void DragAndDropHandler::finishDrag(GdkDragContext* context)
{
#if GTK_CHECK_VERSION(3, 16, 0)
    // This can happen when attempting to call finish drag from webkitWebViewBaseDragEnd()
    // for a obsolete DnD operation that got previously cancelled in startDrag().
    if (m_dragContext.get() != context)
        return;

    if (!m_draggingSelectionData)
        return;

    m_dragContext = nullptr;
    m_draggingSelectionData = nullptr;
#else
    if (!m_draggingSelectionDataMap.remove(context))
        return;
#endif

    GdkDevice* device = gdk_drag_context_get_device(context);
    int x = 0, y = 0;
    gdk_device_get_window_at_position(device, &x, &y);
    int xRoot = 0, yRoot = 0;
    gdk_device_get_position(device, nullptr, &xRoot, &yRoot);
    m_page.dragEnded(IntPoint(x, y), IntPoint(xRoot, yRoot), gdkDragActionToDragOperation(gdk_drag_context_get_selected_action(context)));
}