G_MODULE_EXPORT void gw_settingswindow_drag_begin_cb (GtkWidget *widget, GdkDragContext *context, gpointer data) { cairo_surface_t *surface; GtkTreeView *view; GtkTreeModel *model; GtkTreeSelection *selection; GtkTreePath *path; GList *selectedlist; view = GTK_TREE_VIEW (widget); model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget)); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)); selectedlist = gtk_tree_selection_get_selected_rows (selection, &model); path = (GtkTreePath*) selectedlist->data; surface = gtk_tree_view_create_row_drag_icon (view, path); gtk_drag_set_icon_surface (context, surface); cairo_surface_destroy (surface); g_list_foreach (selectedlist, (GFunc) gtk_tree_path_free, NULL); g_list_free (selectedlist); }
static void drag_begin_callback (GtkWidget *widget, GdkDragContext *context, gpointer data) { NemoIconContainer *container; cairo_surface_t *surface; double x1, y1, x2, y2, winx, winy; int x_offset, y_offset; int start_x, start_y; container = NEMO_ICON_CONTAINER (widget); start_x = container->details->dnd_info->drag_info.start_x + gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container))); start_y = container->details->dnd_info->drag_info.start_y + gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container))); /* create a pixmap and mask to drag with */ surface = nemo_icon_canvas_item_get_drag_surface (container->details->drag_icon->item); /* compute the image's offset */ eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (container->details->drag_icon->item), &x1, &y1, &x2, &y2); eel_canvas_world_to_window (EEL_CANVAS (container), x1, y1, &winx, &winy); x_offset = start_x - winx; y_offset = start_y - winy; cairo_surface_set_device_offset (surface, -x_offset, -y_offset); gtk_drag_set_icon_surface (context, surface); cairo_surface_destroy (surface); }
static void etfci_start_drag (ETableFieldChooserItem *etfci, GdkEvent *event, gdouble x, gdouble y) { GtkWidget *widget = GTK_WIDGET (GNOME_CANVAS_ITEM (etfci)->canvas); GtkTargetList *list; GdkDragContext *context; ETableCol *ecol; cairo_surface_t *cs; cairo_t *cr; gint drag_col; gint button_height; GtkTargetEntry etfci_drag_types[] = { { (gchar *) TARGET_ETABLE_COL_TYPE, 0, TARGET_ETABLE_COL_HEADER }, }; if (etfci->combined_header == NULL) return; drag_col = etfci_find_button (etfci, y); if (drag_col < 0 || drag_col > e_table_header_count (etfci->combined_header)) return; ecol = e_table_header_get_column (etfci->combined_header, drag_col); if (ecol->spec->disabled) return; etfci->drag_col = ecol->spec->model_col; etfci_drag_types[0].target = g_strdup_printf ( "%s-%s", etfci_drag_types[0].target, etfci->dnd_code); d (g_print ("etfci - %s\n", etfci_drag_types[0].target)); list = gtk_target_list_new (etfci_drag_types, G_N_ELEMENTS (etfci_drag_types)); context = gtk_drag_begin (widget, list, GDK_ACTION_MOVE, 1, event); g_free ((gpointer) etfci_drag_types[0].target); button_height = e_table_header_compute_height (ecol, widget); cs = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32, etfci->width, button_height); cr = cairo_create (cs); e_table_header_draw_button ( cr, ecol, widget, 0, 0, etfci->width, button_height, etfci->width, button_height, E_TABLE_COL_ARROW_NONE); gtk_drag_set_icon_surface (context, cs); cairo_surface_destroy (cs); cairo_destroy (cr); etfci->maybe_drag = FALSE; }
static void gcal_event_widget_drag_begin (GtkWidget *widget, GdkDragContext *context) { GcalEventWidget *self; cairo_surface_t *surface; GdkWindow *window; GdkDevice *device; gint x, y; GtkAllocation allocation; self = GCAL_EVENT_WIDGET (widget); window = gtk_widget_get_window (widget); device = gdk_drag_context_get_device (context); if (self->read_only) { gtk_drag_cancel (context); return; } /* Setup the drag n' drop icon */ surface = get_dnd_icon (widget); gtk_drag_set_icon_surface (context, surface); /* reposition drag surface to the point the GCalEvent was */ gtk_widget_get_allocation (widget, &allocation); gdk_window_get_device_position (window, device, &x, &y, NULL); gdk_drag_context_set_hotspot (context, x - allocation.x, y - allocation.y); g_clear_pointer (&surface, cairo_surface_destroy); }
void DragAndDropHandler::startDrag(Ref<SelectionData>&& selection, DragOperation dragOperation, RefPtr<ShareableBitmap>&& dragImage) { #if GTK_CHECK_VERSION(3, 16, 0) m_draggingSelectionData = WTFMove(selection); GRefPtr<GtkTargetList> targetList = PasteboardHelper::singleton().targetListForSelectionData(*m_draggingSelectionData); #else RefPtr<SelectionData> selectionData = WTFMove(selection); GRefPtr<GtkTargetList> targetList = PasteboardHelper::singleton().targetListForSelectionData(*selectionData); #endif GUniquePtr<GdkEvent> currentEvent(gtk_get_current_event()); GdkDragContext* context = gtk_drag_begin(m_page.viewWidget(), targetList.get(), dragOperationToGdkDragActions(dragOperation), GDK_BUTTON_PRIMARY, currentEvent.get()); #if GTK_CHECK_VERSION(3, 16, 0) // WebCore::EventHandler does not support more than one DnD operation at the same time for // a given page, so we should cancel any previous operation whose context we might have // stored, should we receive a new startDrag event before finishing a previous DnD operation. if (m_dragContext) gtk_drag_cancel(m_dragContext.get()); m_dragContext = context; #else // We don't have gtk_drag_cancel() in GTK+ < 3.16, so we use the old code. // See https://bugs.webkit.org/show_bug.cgi?id=138468 m_draggingSelectionDataMap.set(context, WTFMove(selectionData)); #endif if (dragImage) { RefPtr<cairo_surface_t> image(dragImage->createCairoSurface()); // Use the center of the drag image as hotspot. cairo_surface_set_device_offset(image.get(), -cairo_image_surface_get_width(image.get()) / 2, -cairo_image_surface_get_height(image.get()) / 2); gtk_drag_set_icon_surface(context, image.get()); } else gtk_drag_set_icon_default(context); }
static void drag_set_color_icon (GdkDragContext *context, const GdkRGBA *color) { cairo_surface_t *surface; cairo_t *cr; surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 48, 32); cr = cairo_create (surface); gdk_cairo_set_source_rgba (cr, color); cairo_paint (cr); cairo_surface_set_device_offset (surface, -4, -4); gtk_drag_set_icon_surface (context, surface); cairo_destroy (cr); cairo_surface_destroy (surface); }
static gboolean egg_tree_multi_drag_motion_event (GtkWidget *widget, GdkEventMotion *event, gpointer data) { EggTreeMultiDndData *priv_data; priv_data = g_object_get_data (G_OBJECT (widget), EGG_TREE_MULTI_DND_STRING); if (! priv_data->pending_event) return FALSE; if (gtk_drag_check_threshold (widget, priv_data->x, priv_data->y, event->x, event->y)) { GList *path_list = NULL; GtkTreeSelection *selection; GtkTreeModel *model; GdkDragContext *context; stop_drag_check (widget); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)); gtk_tree_selection_selected_foreach (selection, selection_foreach, &path_list); if (path_list == NULL) return FALSE; path_list = g_list_reverse (path_list); model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget)); if (egg_tree_multi_drag_source_row_draggable (EGG_TREE_MULTI_DRAG_SOURCE (model), path_list)) { GtkTargetList *target_list; GtkTreePath *tree_path; int cell_x; int cell_y; target_list = gtk_target_list_new (target_table, G_N_ELEMENTS (target_table)); context = gtk_drag_begin_with_coordinates (widget, target_list, GDK_ACTION_COPY, priv_data->pressed_button, (GdkEvent*) event, event->x, event->y); set_context_data (context, path_list); if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), priv_data->x, priv_data->y, &tree_path, NULL, &cell_x, &cell_y)) { cairo_surface_t *drag_icon; drag_icon = gtk_tree_view_create_row_drag_icon (GTK_TREE_VIEW (widget), tree_path); if (path_list->next != NULL) { /* create a multi row drag icon */ const int icon_offset = DRAG_ICON_OFFSET; GdkRectangle icon_extents; cairo_surface_t *multi_drag_icon; cairo_t *cr; int n_icons, i, offset; n_icons = MIN (DRAG_ICON_MAX_ROWS, g_list_length (path_list)); _gtk_cairo_surface_extents (drag_icon, &icon_extents); multi_drag_icon = gdk_window_create_similar_surface (gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget)), CAIRO_CONTENT_COLOR_ALPHA, icon_extents.width + (icon_offset * (n_icons - 1)), icon_extents.height + (icon_offset * (n_icons - 1))); cr = cairo_create (multi_drag_icon); cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.0); cairo_rectangle(cr, 0, 0, icon_extents.width + icon_offset, icon_extents.height + icon_offset); cairo_fill (cr); offset = icon_offset * (n_icons - 1); for (i = 0; i < n_icons; i++) { cairo_set_source_surface (cr, drag_icon, -icon_extents.x + offset, -icon_extents.y + offset); cairo_rectangle (cr, offset, offset, icon_extents.width, icon_extents.height); cairo_fill (cr); offset -= icon_offset; } cairo_destroy (cr); cairo_surface_set_device_offset (multi_drag_icon, - (cell_x + 1), - (cell_y + 1)); gtk_drag_set_icon_surface (context, multi_drag_icon); cairo_surface_destroy (multi_drag_icon); } else { cairo_surface_set_device_offset (drag_icon, - (cell_x + 1), - (cell_y + 1)); gtk_drag_set_icon_surface (context, drag_icon); } cairo_surface_destroy (drag_icon); gtk_tree_path_free (tree_path); } else gtk_drag_set_icon_default (context); gtk_target_list_unref (target_list); } else { path_list_free (path_list); } } return TRUE; }