NS_IMETHODIMP nsDragService::InvokeDragSession(nsIDOMNode *aDOMNode, nsISupportsArray * aArrayTransferables, nsIScriptableRegion * aRegion, PRUint32 aActionType) { PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::InvokeDragSession")); nsresult rv = nsBaseDragService::InvokeDragSession(aDOMNode, aArrayTransferables, aRegion, aActionType); NS_ENSURE_SUCCESS(rv, rv); // make sure that we have an array of transferables to use if (!aArrayTransferables) return NS_ERROR_INVALID_ARG; // set our reference to the transferables. this will also addref // the transferables since we're going to hang onto this beyond the // length of this call mSourceDataItems = aArrayTransferables; // get the list of items we offer for drags GtkTargetList *sourceList = 0; sourceList = GetSourceList(); if (sourceList) { // save our action type GdkDragAction action = GDK_ACTION_DEFAULT; if (aActionType & DRAGDROP_ACTION_COPY) action = (GdkDragAction)(action | GDK_ACTION_COPY); if (aActionType & DRAGDROP_ACTION_MOVE) action = (GdkDragAction)(action | GDK_ACTION_MOVE); if (aActionType & DRAGDROP_ACTION_LINK) action = (GdkDragAction)(action | GDK_ACTION_LINK); // Create a fake event for the drag so we can pass the time // (so to speak.) If we don't do this the drag can end as a // result of a button release that is actually _earlier_ than // CurrentTime. So we use the time on the last button press // event, as that will always be older than the button release // that ends any drag. GdkEvent event; memset(&event, 0, sizeof(GdkEvent)); event.type = GDK_BUTTON_PRESS; event.button.window = mHiddenWidget->window; event.button.time = nsWindow::mLastButtonPressTime; // start our drag. GdkDragContext *context = gtk_drag_begin(mHiddenWidget, sourceList, action, 1, &event); // make sure to set our default icon gtk_drag_set_icon_default(context); gtk_target_list_unref(sourceList); } return NS_OK; }
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 gint __gevasevh_group_selector_leave_notify_cb( GtkWidget *widget, GdkEventCrossing *event, GtkgEvasEvHGroupSelector* ev ) { /* printf("__gevasevh_group_selector_leave_notify_cb() w:%p event:%p ev:%p gevas:%p gwin:%d\n", widget, event, ev, GTK_WIDGET (ev->rect->gevas), GTK_WIDGET_NO_WINDOW(GTK_WIDGET (ev->rect->gevas)) ); */ if( ev->drag_targets && ev->drag_is_dragging ) { ev->drag_context = gtk_drag_begin (GTK_WIDGET (ev->rect->gevas), ev->drag_targets, GDK_ACTION_MOVE | GDK_ACTION_COPY, 1, (GdkEvent*)event); gtk_drag_set_icon_default (ev->drag_context); /* printf("__gevasevh_group_selector_leave_notify_cb() context:%p\n",ev->drag_context);*/ } return 0; }
static gboolean _view_map_motion_notify_callback(GtkWidget *w, GdkEventMotion *e, dt_view_t *self) { dt_map_t *lib = (dt_map_t*)self->data; const int ts = 64; if(lib->start_drag && lib->selected_image > 0) { for(GSList *iter = lib->images; iter != NULL; iter = iter->next) { dt_map_image_t *entry = (dt_map_image_t*)iter->data; OsmGpsMapImage *image = entry->image; if(entry->imgid == lib->selected_image) { osm_gps_map_image_remove(lib->map, image); break; } } lib->start_drag = FALSE; GtkTargetList *targets = gtk_target_list_new(target_list_all, n_targets_all); dt_mipmap_buffer_t buf; dt_mipmap_size_t mip = dt_mipmap_cache_get_matching_size(darktable.mipmap_cache, ts, ts); dt_mipmap_cache_read_get(darktable.mipmap_cache, &buf, lib->selected_image, mip, DT_MIPMAP_BLOCKING); if(buf.buf) { uint8_t *scratchmem = dt_mipmap_cache_alloc_scratchmem(darktable.mipmap_cache); uint8_t *buf_decompressed = dt_mipmap_cache_decompress(&buf, scratchmem); uint8_t *rgbbuf = g_malloc((buf.width+2)*(buf.height+2)*3); memset(rgbbuf, 64, (buf.width+2)*(buf.height+2)*3); for(int i=1; i<=buf.height; i++) for(int j=1; j<=buf.width; j++) for(int k=0; k<3; k++) rgbbuf[(i*(buf.width+2)+j)*3+k] = buf_decompressed[((i-1)*buf.width+j-1)*4+2-k]; int w=ts, h=ts; if(buf.width < buf.height) w = (buf.width*ts)/buf.height; // portrait else h = (buf.height*ts)/buf.width; // landscape GdkPixbuf *source = gdk_pixbuf_new_from_data(rgbbuf, GDK_COLORSPACE_RGB, FALSE, 8, (buf.width+2), (buf.height+2), (buf.width+2)*3, NULL, NULL); GdkPixbuf *scaled = gdk_pixbuf_scale_simple(source, w, h, GDK_INTERP_HYPER); GdkDragContext * context = gtk_drag_begin(GTK_WIDGET(lib->map), targets, GDK_ACTION_COPY, 1, (GdkEvent*)e); gtk_drag_set_icon_pixbuf(context, scaled, 0, 0); if(source) g_object_unref(source); if(scaled) g_object_unref(scaled); g_free(rgbbuf); } dt_mipmap_cache_read_release(darktable.mipmap_cache, &buf); gtk_target_list_unref(targets); return TRUE; } return FALSE; }
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 gint e_minicard_view_drag_begin (EAddressbookReflowAdapter *adapter, GdkEvent *event, EMinicardView *view) { GdkDragContext *context; GtkTargetList *target_list; GdkDragAction actions = GDK_ACTION_MOVE | GDK_ACTION_COPY; clear_drag_data (view); view->drag_list = e_minicard_view_get_card_list (view); target_list = gtk_target_list_new (drag_types, G_N_ELEMENTS (drag_types)); context = gtk_drag_begin ( GTK_WIDGET (GNOME_CANVAS_ITEM (view)->canvas), target_list, actions, 1/*XXX */, event); if (!view->canvas_drag_data_get_id) view->canvas_drag_data_get_id = g_signal_connect ( GNOME_CANVAS_ITEM (view)->canvas, "drag_data_get", G_CALLBACK (e_minicard_view_drag_data_get), view); gtk_drag_set_icon_default (context); return TRUE; }
void nemo_icon_dnd_begin_drag (NemoIconContainer *container, GdkDragAction actions, int button, GdkEventMotion *event, int start_x, int start_y) { NemoIconDndInfo *dnd_info; g_return_if_fail (NEMO_IS_ICON_CONTAINER (container)); g_return_if_fail (event != NULL); dnd_info = container->details->dnd_info; g_return_if_fail (dnd_info != NULL); /* Notice that the event is in bin_window coordinates, because of the way the canvas handles events. */ dnd_info->drag_info.start_x = start_x - gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container))); dnd_info->drag_info.start_y = start_y - gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container))); /* start the drag */ gtk_drag_begin (GTK_WIDGET (container), dnd_info->drag_info.target_list, actions, button, (GdkEvent *) event); }
static gboolean hand_display_motion (GtkWidget *hand, GdkEventMotion *event) { HandDisplay *handdisp = HAND_DISPLAY(hand); int card = which_card(handdisp, event->x, event->y); if (handdisp->drag && handdisp->cur_click >= 0 && handdisp->cur_click < 52 && gtk_drag_check_threshold (hand, handdisp->drag_x, handdisp->drag_y, event->x, event->y)) { if (! target_list) target_list = gtk_target_list_new (target_entry, 1); handdisp->cur_drag = handdisp->cur_click; gtk_drag_begin (hand, target_list, GDK_ACTION_COPY, 1, (GdkEvent *) event); } if (handdisp->cur_focus != card) { if (handdisp->cur_focus != -1) { redraw_card (hand, handdisp->cur_focus); g_signal_emit_by_name (handdisp, "card-leave", handdisp->cur_focus); } handdisp->cur_focus = card; if (card != -1) { redraw_card (hand, card); g_signal_emit_by_name (handdisp, "card-enter", card); } } gdk_window_get_pointer(gtk_widget_get_window (hand), NULL, NULL, NULL); /* request more pointer hints */ return FALSE; }
static VALUE rg_m_begin(G_GNUC_UNUSED VALUE self, VALUE widget, VALUE target_list, VALUE actions, VALUE button, VALUE event) { return GOBJ2RVAL(gtk_drag_begin(RVAL2WIDGET(widget), RVAL2BOXED(target_list, GTK_TYPE_TARGET_LIST), RVAL2GFLAGS(actions, GDK_TYPE_DRAG_ACTION), NUM2INT(button), RVAL2GEV(event))); }
JNIEXPORT void JNICALL Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_nativeStartDrag (JNIEnv *env, jobject obj, jobject img, jint x, jint y, jint act, jstring target) { void *ptr; const gchar *data; GtkTargetEntry tar[1]; GdkEvent *event; GdkPixbuf *image = NULL; GdkDragContext *context = NULL; GdkDragAction action = GDK_ACTION_DEFAULT; gdk_threads_enter (); ptr = NSA_GET_GLOBAL_REF (env, obj); data = (*env)->GetStringUTFChars (env, target, NULL); tar[0].target = (gchar *) data; event = gdk_event_new (GDK_ALL_EVENTS_MASK); switch (act) { case ACTION_COPY: action = GDK_ACTION_COPY; break; case ACTION_MOVE: action = GDK_ACTION_MOVE; break; case ACTION_COPY_OR_MOVE: action = GDK_ACTION_COPY | GDK_ACTION_MOVE; break; case ACTION_LINK: action = GDK_ACTION_LINK; break; default: action = GDK_ACTION_DEFAULT; } gtk_drag_highlight (widget); context = gtk_drag_begin (widget, gtk_target_list_new (tar, sizeof (tar) / sizeof (GtkTargetEntry)), action, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, event); if (img != NULL) { image = cp_gtk_image_get_pixbuf (env, img); gtk_drag_set_icon_pixbuf (context, image, x, y); } gdk_event_free (event); (*env)->ReleaseStringUTFChars (env, target, data); gdk_threads_leave (); }
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 (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; TreeViewDragInfo *di; di = get_info (GTK_TREE_VIEW (widget)); if (di == NULL) return FALSE; selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)); stop_drag_check (widget); gtk_tree_selection_selected_foreach (selection, selection_foreach, &path_list); 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)) { context = gtk_drag_begin (widget, #if GTK_CHECK_VERSION (2, 14, 0) gtk_drag_source_get_target_list (widget), #else di->source_target_list, #endif di->source_actions, priv_data->pressed_button, (GdkEvent*)event); set_context_data (context, path_list); gtk_drag_set_icon_default (context); } else { path_list_free (path_list); } } return TRUE; }
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 (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 = gtk_target_list_new (target_table, G_N_ELEMENTS (target_table)); context = gtk_drag_begin (widget, target_list, GDK_ACTION_COPY, priv_data->pressed_button, (GdkEvent*)event); set_context_data (context, path_list); gtk_drag_set_icon_default (context); gtk_target_list_unref (target_list); } else { path_list_free (path_list); } } return TRUE; }
int Ctrl::DoDragAndDrop(const char *fmts, const Image& sample, dword actions, const VectorMap<String, ClipData>& data) { LLOG("------------------------------"); LLOG("DoDragAndDrop " << fmts); TopWindow *w = GetTopWindow(); if(!w || !w->top) return DND_NONE; int gdk_actions = 0; if(actions & DND_MOVE) gdk_actions |= GDK_ACTION_MOVE; if(actions & DND_COPY) gdk_actions |= GDK_ACTION_COPY; GtkTargetList *list = CreateTargetList(data); dnd_fmts.Clear(); for(int i = 0; i < data.GetCount(); i++) AddFmt(list, data.GetKey(i), i); Vector<String> f = Split(fmts, ';'); for(int i = 0; i < f.GetCount(); i++) { AddFmt(list, f[i], data.GetCount() + i); dnd_fmts.Add(f[i]); } dnd_source_data = &data; dnd_result = DND_NONE; dnd_source = this; if(IsNull(sample)) dnd_icon = Null; else { Size sz = sample.GetSize(); if(sz.cx > 128) sz.cx = 128; if(sz.cy > 128) sz.cy = 128; sz += 2; ImageDraw iw(sz); iw.DrawRect(sz, White()); DrawFrame(iw, sz, Black()); iw.DrawImage(1, 1, sz.cx, sz.cy, sample); ImageBuffer b(128, 128); dnd_icon = iw; } gtk_drag_begin(w->top->window, list, GdkDragAction(gdk_actions), GetMouseLeft() ? 1 : GetMouseMiddle() ? 2 : 3, CurrentEvent.event); while(dnd_source && GetTopCtrls().GetCount()) ProcessEvents(); dnd_source_data = NULL; gtk_target_list_unref (list); LLOG("-------- DoDragAndDrop"); return dnd_result; }
static void mimeview_start_drag(GtkWidget *widget, gint button, GdkEvent *event, MimeView *mimeview) { GdkDragContext *context; MimeInfo *partinfo; g_return_if_fail(mimeview != NULL); partinfo = mimeview_get_selected_part(mimeview); if (partinfo->disposition == DISPOSITIONTYPE_INLINE) return; context = gtk_drag_begin(widget, mimeview->target_list, GDK_ACTION_COPY, button, event); gtk_drag_set_icon_default(context); }
void DragAndDropHandler::startDrag(const DragData& dragData, PassRefPtr<ShareableBitmap> dragImage) { RefPtr<DataObjectGtk> dataObject = adoptRef(dragData.platformData()); GRefPtr<GtkTargetList> targetList = adoptGRef(PasteboardHelper::defaultPasteboardHelper()->targetListForDataObject(dataObject.get())); GUniquePtr<GdkEvent> currentEvent(gtk_get_current_event()); GdkDragContext* context = gtk_drag_begin(m_page.viewWidget(), targetList.get(), dragOperationToGdkDragActions(dragData.draggingSourceOperationMask()), GDK_BUTTON_PRIMARY, currentEvent.get()); m_draggingDataObjects.set(context, dataObject.get()); if (dragImage) { RefPtr<cairo_surface_t> image(dragImage->createCairoSurface()); m_dragIcon.setImage(image.get()); m_dragIcon.useForDrag(context); } else gtk_drag_set_icon_default(context); }
static void mouse_click_cb(GtkWidget *widget, GdkEventButton *event, FileView *view) { if (event->button == 1) { /* Left Button: selection */ if (curr_view != view) { switch_views(); gtk_widget_grab_focus(view->clist); } } else if (event->button == 2) { /* Middle Button: Drag and Drop */ GtkTargetList *list; GdkDragContext *context; list = gtk_target_list_new(target_table, n_targets); context = gtk_drag_begin(curr_view->clist, list, GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK, event->button, (GdkEvent *)event); gtk_drag_set_icon_default(context); } else if (event->button == 3) { /* Right Button: Menu */ if (cfg.windows_right_click && (view->tagged == NULL)) { /* if windows right click is enabled, we want to select the file */ gint xmouse,ymouse,row,column; GdkModifierType mask; gdk_window_get_pointer(GTK_CLIST(view->clist)->clist_window, &xmouse, &ymouse, &mask); gtk_clist_get_selection_info(GTK_CLIST(view->clist), xmouse, ymouse, &row, &column); /* don't screw up the current selection */ if (!clist_row_is_selected(view->clist, row)) gtk_clist_unselect_all(GTK_CLIST(view->clist)); focus_row(view, row, FALSE, FALSE, TRUE); } if (event->state & GDK_CONTROL_MASK) show_user_command_menu(event->button, event->time); else show_menu(event->button, event->time); } }
void DragClient::startDrag(DragImageRef image, const IntPoint& dragImageOrigin, const IntPoint& eventPos, Clipboard*, Frame* frame, bool linkDrag) { Element* targetElement = frame->document()->elementFromPoint(m_startPos.x(), m_startPos.y()); bool imageDrag = false; if (targetElement) imageDrag = targetElement->renderer()->isImage(); GdkAtom textHtml = gdk_atom_intern_static_string("text/html"); GdkAtom netscapeUrl = gdk_atom_intern_static_string("_NETSCAPE_URL"); GtkTargetList* targetList = gtk_target_list_new(NULL, 0); gtk_target_list_add(targetList, textHtml, 0, WEBKIT_WEB_VIEW_TARGET_INFO_HTML); gtk_target_list_add_text_targets(targetList, WEBKIT_WEB_VIEW_TARGET_INFO_TEXT); if (linkDrag || imageDrag) { gtk_target_list_add(targetList, netscapeUrl, 0, WEBKIT_WEB_VIEW_TARGET_INFO_NETSCAPE_URL); gtk_target_list_add_uri_targets(targetList, WEBKIT_WEB_VIEW_TARGET_INFO_URI_LIST); } if (imageDrag) gtk_target_list_add_image_targets(targetList, WEBKIT_WEB_VIEW_TARGET_INFO_IMAGE, false); GdkDragAction dragAction = GDK_ACTION_COPY; if (linkDrag) { dragAction = GDK_ACTION_LINK; if (imageDrag) dragAction = (GdkDragAction)(dragAction | GDK_ACTION_COPY); } GdkEvent* event = gdk_event_new(GDK_BUTTON_PRESS); reinterpret_cast<GdkEventButton*>(event)->window = gtk_widget_get_window(GTK_WIDGET(m_webView)); reinterpret_cast<GdkEventButton*>(event)->time = GDK_CURRENT_TIME; GdkDragContext* context = gtk_drag_begin(GTK_WIDGET(m_webView), targetList, dragAction, 1, event); g_object_ref(context); if (image) gtk_drag_set_icon_pixbuf(context, image, eventPos.x() - dragImageOrigin.x(), eventPos.y() - dragImageOrigin.y()); else gtk_drag_set_icon_default(context); gtk_target_list_unref(targetList); }
static gboolean rb_tree_dnd_motion_notify_event_cb (GtkWidget *widget, GdkEventMotion *event, gpointer data) { RbTreeDndData *priv_data; priv_data = g_object_get_data (G_OBJECT (widget), RB_TREE_DND_STRING); 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; selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)); stop_drag_check (widget); gtk_tree_selection_selected_foreach (selection, selection_foreach, &path_list); path_list = g_list_reverse (path_list); model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget)); if (rb_tree_drag_source_row_draggable (RB_TREE_DRAG_SOURCE (model), path_list)) { rb_debug ("drag begin"); context = gtk_drag_begin (widget, priv_data->source_target_list, priv_data->source_actions, priv_data->pressed_button, (GdkEvent*)event); set_context_data (context, path_list); gtk_drag_set_icon_default (context); } else { path_list_free (path_list); } } return TRUE; }
gboolean uni_dragger_motion_notify (UniDragger * tool, GdkEventMotion * ev) { if (tool->pressed) tool->dragging = TRUE; else return FALSE; tool->drag_ofs_x = ev->x; tool->drag_ofs_y = ev->y; int dx, dy; uni_dragger_get_drag_delta (tool, &dx, &dy); if (abs (dx) < 1 && abs (dy) < 1) return FALSE; if ( pow(dx, 2) + pow(dy, 2) > 7 && UNI_IMAGE_VIEW(tool->view)->pixbuf != NULL && UNI_IMAGE_VIEW(tool->view)->vadj->upper <= UNI_IMAGE_VIEW(tool->view)->vadj->page_size && UNI_IMAGE_VIEW(tool->view)->hadj->upper <= UNI_IMAGE_VIEW(tool->view)->hadj->page_size ) { uni_dragger_button_release (tool, (GdkEventButton*)ev); gtk_drag_begin (GTK_WIDGET(tool->view), gtk_target_list_new(target_table, G_N_ELEMENTS(target_table)), GDK_ACTION_COPY, 1, (GdkEvent*)ev); return TRUE; } GdkRectangle viewport; uni_image_view_get_viewport (UNI_IMAGE_VIEW (tool->view), &viewport); int offset_x = viewport.x + dx; int offset_y = viewport.y + dy; uni_image_view_set_offset (UNI_IMAGE_VIEW (tool->view), offset_x, offset_y, FALSE); tool->drag_base_x = tool->drag_ofs_x; tool->drag_base_y = tool->drag_ofs_y; return TRUE; }
static gboolean on_motion_event( GtkWidget *widget, GdkEventMotion *event, EggTreeMultiDragSource *drag_source ) { EggTreeMultiDndData *priv_data; priv_data = g_object_get_data( G_OBJECT( widget ), EGG_TREE_MULTI_DND_STRING ); 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, ( GtkTreeSelectionForeachFunc ) selection_foreach, &path_list ); 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 = v_get_target_list( drag_source ); GdkDragAction actions = v_get_drag_actions( drag_source ); context = gtk_drag_begin( widget, target_list, actions, priv_data->pressed_button, ( GdkEvent * ) event ); set_treeview_data( widget, path_list ); gtk_drag_set_icon_default( context ); v_free_target_list( drag_source, target_list ); } else { path_list_free( path_list ); } } return( TRUE ); }
void DragClient::startDrag(DragImageRef image, const IntPoint& dragImageOrigin, const IntPoint& eventPos, Clipboard* clipboard, Frame* frame, bool linkDrag) { WebKitWebView* webView = webkit_web_frame_get_web_view(kit(frame)); RefPtr<DataObjectGtk> dataObject = clipboard->pasteboard().dataObject(); GRefPtr<GtkTargetList> targetList = adoptGRef(PasteboardHelper::defaultPasteboardHelper()->targetListForDataObject(dataObject.get())); GOwnPtr<GdkEvent> currentEvent(gtk_get_current_event()); GdkDragContext* context = gtk_drag_begin(GTK_WIDGET(m_webView), targetList.get(), dragOperationToGdkDragActions(clipboard->sourceOperation()), 1, currentEvent.get()); webView->priv->dragAndDropHelper.startedDrag(context, dataObject.get()); // A drag starting should prevent a double-click from happening. This might // happen if a drag is followed very quickly by another click (like in the DRT). webView->priv->clickCounter.reset(); if (image) { m_dragIcon.setImage(image); m_dragIcon.useForDrag(context, IntPoint(eventPos - dragImageOrigin)); } else gtk_drag_set_icon_default(context); }
static void move_item_cb (GtkAction *action, EggEditableToolbar *etoolbar) { GtkWidget *toolitem = gtk_widget_get_ancestor (egg_editable_toolbar_get_selected (etoolbar), GTK_TYPE_TOOL_ITEM); GtkTargetList *list = gtk_target_list_new (dest_drag_types, G_N_ELEMENTS (dest_drag_types)); GdkEvent *realevent = gtk_get_current_event(); GdkEventMotion event; event.type = GDK_MOTION_NOTIFY; event.window = realevent->any.window; event.send_event = FALSE; event.axes = NULL; event.time = gdk_event_get_time (realevent); gdk_event_get_state (realevent, &event.state); gdk_event_get_coords (realevent, &event.x, &event.y); gdk_event_get_root_coords (realevent, &event.x_root, &event.y_root); gtk_drag_begin (toolitem, list, GDK_ACTION_MOVE, 1, (GdkEvent *)&event); gtk_target_list_unref (list); }
static gboolean motion_notify_cb (GtkWidget *widget, GdkEventMotion *event, EphyNodeView *view) { GdkDragContext *context; GList *ref_list; if (event->window != gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget))) { return FALSE; } if (view->priv->drag_button != 0) { if (gtk_drag_check_threshold (widget, view->priv->drag_x, view->priv->drag_y, event->x, event->y) && can_drag_selection (view)) { context = gtk_drag_begin (widget, view->priv->source_target_list, GDK_ACTION_ASK | GDK_ACTION_COPY | GDK_ACTION_LINK, view->priv->drag_button, (GdkEvent*)event); stop_drag_check (view); view->priv->drag_started = TRUE; ref_list = get_selection_refs (GTK_TREE_VIEW (widget)); g_object_set_data_full (G_OBJECT (context), "drag-info", ref_list, (GDestroyNotify)ref_list_free); gtk_drag_set_icon_default (context); } } return TRUE; }
int clip_GTK_DRAGBEGIN(ClipMachine * cm) { C_widget *cwid = _fetch_cw_arg(cm); C_object *ctlist = _fetch_cobject(cm, _clip_spar(cm, 2)); GdkDragAction actions = _clip_parni(cm, 3); gint button = _clip_parni(cm, 4); C_object *cevent = _fetch_cobject(cm, _clip_spar(cm, 5)); GdkDragContext *context ; C_object *ccontext ; CHECKCWID(cwid, GTK_IS_WIDGET); if (!ctlist || ctlist->type != GTK_TYPE_TARGET_LIST) goto err; CHECKARG(3, NUMERIC_t); CHECKARG(4, NUMERIC_t); if (!cevent || cevent->type != GDK_TYPE_EVENT) goto err; context = gtk_drag_begin(GTK_WIDGET(cwid->widget), (GtkTargetList*)ctlist->object, actions, button, (GdkEvent*)cevent->object); if (context) { ccontext = _list_get_cobject(cm, context); if (!ccontext) ccontext = _register_object(cm, context, GDK_TYPE_DRAG_CONTEXT, NULL, NULL); if (ccontext) _clip_mclone(cm, RETPTR(cm), &ccontext->obj); } return 0; err: return 1; }
void FV_UnixFrameEdit::mouseDrag(UT_sint32 x, UT_sint32 y) { UT_DEBUGMSG(("Mouse drag x=%d y=%d \n",x,y)); bool bYOK = ( (y > 0) && (y < getView()->getWindowHeight())); if(!bYOK || (x> 0 && x < getView()->getWindowWidth())) { m_bDragOut = false; _mouseDrag(x,y); return; } if(FV_DragWhole != getDragWhat()) { m_bDragOut = false; _mouseDrag(x,y); return; } if(FV_FrameEdit_DRAG_EXISTING != getFrameEditMode()) { m_bDragOut = false; _mouseDrag(x,y); return; } if(!isImageWrapper()) { m_bDragOut = false; _mouseDrag(x,y); return; } if(!m_bDragOut) { const UT_ByteBuf * pBuf = NULL; const char * pszData = getPNGImage(&pBuf); UT_DEBUGMSG(("Got image buffer %p pszData %p \n",pBuf,pszData)); if(pBuf) { // // write the image to a temperary file // XAP_UnixApp * pXApp = static_cast<XAP_UnixApp *>(XAP_App::getApp()); pXApp->removeTmpFile(); char ** pszTmpName = pXApp->getTmpFile(); UT_UTF8String sTmpF = g_get_tmp_dir(); sTmpF += "/"; sTmpF += pszData; sTmpF += ".png"; // // Now write the contents of the buffer to a temp file. // FILE * fd = fopen(sTmpF.utf8_str(),"w"); fwrite(pBuf->getPointer(0),sizeof(UT_Byte),pBuf->getLength(),fd); fclose(fd); // // OK set up the gtk drag and drop code to andle this // XAP_Frame * pFrame = static_cast<XAP_Frame*>(getView()->getParentData()); XAP_UnixFrameImpl * pFrameImpl =static_cast<XAP_UnixFrameImpl *>( pFrame->getFrameImpl()); GtkWidget * pWindow = pFrameImpl->getTopLevelWindow(); GtkTargetList *target_list = gtk_target_list_new(targets, G_N_ELEMENTS(targets)); GdkDragContext *context = gtk_drag_begin(pWindow, target_list, (GdkDragAction)(GDK_ACTION_COPY ), 1, NULL); gdk_drag_status(context, GDK_ACTION_COPY, 0); gtk_target_list_unref(target_list); *pszTmpName = g_strdup(sTmpF.utf8_str()); UT_DEBUGMSG(("Created Tmp File %s XApp %s \n",sTmpF.utf8_str(),*pXApp->getTmpFile())); } // // OK quit dragging the image and return to the previous state // m_bDragOut = true; abortDrag(); } m_bDragOut = true; }
wxDragResult wxDropSource::DoDragDrop(int flags) { wxCHECK_MSG( m_data && m_data->GetFormatCount(), wxDragNone, wxT("Drop source: no data") ); // still in drag if (g_blockEventsOnDrag) return wxDragNone; // don't start dragging if no button is down if (g_lastButtonNumber == 0) return wxDragNone; // we can only start a drag after a mouse event if (g_lastMouseEvent == NULL) return wxDragNone; // disabled for now g_blockEventsOnDrag = true; RegisterWindow(); m_waiting = true; GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 ); wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ]; m_data->GetAllFormats( array ); size_t count = m_data->GetFormatCount(); for (size_t i = 0; i < count; i++) { GdkAtom atom = array[i]; #ifdef __WXDEBUG__ wxLogTrace(TRACE_DND, wxT("Drop source: Supported atom %s"), gdk_atom_name( atom )); #endif gtk_target_list_add( target_list, atom, 0, 0 ); } delete[] array; int action = GDK_ACTION_COPY; if ( flags & wxDrag_AllowMove ) action |= GDK_ACTION_MOVE; // VZ: as we already use g_blockEventsOnDrag it shouldn't be that bad // to use a global to pass the flags to the drop target but I'd // surely prefer a better way to do it gs_flagsForDrag = flags; GdkDragContext *context = gtk_drag_begin( m_widget, target_list, (GdkDragAction)action, g_lastButtonNumber, // number of mouse button which started drag (GdkEvent*) g_lastMouseEvent ); m_dragContext = context; PrepareIcon( action, context ); while (m_waiting) gtk_main_iteration(); m_retValue = ConvertFromGTK(context->action); if ( m_retValue == wxDragNone ) m_retValue = wxDragCancel; g_blockEventsOnDrag = false; UnregisterWindow(); return m_retValue; }
wxDragResult wxDropSource::DoDragDrop(int flags) { wxCHECK_MSG( m_data && m_data->GetFormatCount(), wxDragNone, wxT("Drop source: no data") ); // still in drag if (g_blockEventsOnDrag) return wxDragNone; // don't start dragging if no button is down if (g_lastButtonNumber == 0) return wxDragNone; // we can only start a drag after a mouse event if (g_lastMouseEvent == NULL) return wxDragNone; GTKConnectDragSignals(); wxON_BLOCK_EXIT_OBJ0(*this, wxDropSource::GTKDisconnectDragSignals); m_waiting = true; GtkTargetList *target_list = gtk_target_list_new( NULL, 0 ); wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ]; m_data->GetAllFormats( array ); size_t count = m_data->GetFormatCount(); for (size_t i = 0; i < count; i++) { GdkAtom atom = array[i]; wxLogTrace(TRACE_DND, wxT("Drop source: Supported atom %s"), gdk_atom_name( atom )); gtk_target_list_add( target_list, atom, 0, 0 ); } delete[] array; int allowed_actions = GDK_ACTION_COPY; if ( flags & wxDrag_AllowMove ) allowed_actions |= GDK_ACTION_MOVE; // VZ: as we already use g_blockEventsOnDrag it shouldn't be that bad // to use a global to pass the flags to the drop target but I'd // surely prefer a better way to do it gs_flagsForDrag = flags; m_retValue = wxDragCancel; GdkDragContext *context = gtk_drag_begin( m_widget, target_list, (GdkDragAction)allowed_actions, g_lastButtonNumber, // number of mouse button which started drag (GdkEvent*) g_lastMouseEvent ); if ( !context ) { // this can happen e.g. if gdk_pointer_grab() failed return wxDragError; } m_dragContext = context; PrepareIcon( allowed_actions, context ); while (m_waiting) gtk_main_iteration(); g_signal_handlers_disconnect_by_func (m_iconWindow, (gpointer) gtk_dnd_window_configure_callback, this); return m_retValue; }
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 (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; TreeViewDragInfo *di; di = get_info (GTK_TREE_VIEW (widget)); if (di == NULL) return FALSE; selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)); if (priv_data->motion_notify_handler) { g_signal_handler_disconnect (widget, priv_data->motion_notify_handler); priv_data->motion_notify_handler = 0; } if (priv_data->button_release_handler) { g_signal_handler_disconnect (widget, priv_data->button_release_handler); priv_data->button_release_handler = 0; } stop_drag_check (widget); gtk_tree_selection_selected_foreach (selection, selection_foreach, &path_list); 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)) { gulong sig; /* This is to disconnect the default signal handler for treeviews as * it sometimes gives a warning. The default handler just sets the * icon which we do as well in our callback so it is fine. */ sig = g_signal_connect (widget, "drag-begin", G_CALLBACK (egg_tree_multi_drag_begin), NULL); context = gtk_drag_begin (widget, gtk_drag_source_get_target_list (widget), di->source_actions, priv_data->pressed_button, (GdkEvent*)event); g_signal_handler_disconnect (widget, sig); set_context_data (context, path_list); } else { path_list_free (path_list); } } return TRUE; }