gboolean Ctrl::GtkDragDrop(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data) { LLOG("GtkDragDrop"); PasteClip clip = GtkDnd(widget, context, x, y, time, user_data, true); gtk_drag_finish(context, clip.IsAccepted(), clip.IsAccepted() && clip.GetAction() == DND_MOVE, time); g_object_unref(widget); g_object_unref(context); DnDLeave(); return TRUE; }
PasteClip Ctrl::GtkDnd(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data, bool paste) { DndTargets(context); g_object_ref(context); // make sure these always survive the action... g_object_ref(widget); dnd_context = context; dnd_widget = widget; dnd_time = time; PasteClip clip; clip.type = 1; clip.paste = paste; clip.accepted = false; clip.allowed = DND_MOVE|DND_COPY; gint dummy; GdkModifierType mod; gdk_window_get_pointer(gdk_get_default_root_window(), &dummy, &dummy, &mod); clip.action = mod & GDK_CONTROL_MASK ? DND_COPY : DND_MOVE; Ctrl *w = DragWnd(user_data); if(w) { gint mx, my; GdkModifierType mod; gdk_window_get_pointer(gdk_get_default_root_window(), &mx, &my, &mod); CurrentState = mod; CurrentMousePos = Point(x, y) + w->GetScreenRect().TopLeft(); w->DnD(CurrentMousePos, clip); } gdk_drag_status(context, clip.IsAccepted() ? clip.GetAction() == DND_MOVE ? GDK_ACTION_MOVE : GDK_ACTION_COPY : GdkDragAction(0), time); return clip; }
void DnDLoop::DnD(bool paste) { PasteClip d; d.paste = paste; d.accepted = false; d.allowed = (byte)actions; d.action = GetCtrl() ? DND_COPY : DND_MOVE; d.dnd = true; if(target) target->DnD(GetMousePos(), d); action = d.IsAccepted() ? d.GetAction() : DND_NONE; }
void LineEdit::DragAndDrop(Point p, PasteClip& d) { if(IsReadOnly()) return; int c = GetMousePos(p); if(AcceptText(d)) { NextUndo(); int a = sb.y; int sell, selh; WString text = GetWString(d); if(GetSelection(sell, selh)) { if(c >= sell && c < selh) { if(!IsReadOnly()) RemoveSelection(); if(IsDragAndDropSource()) d.SetAction(DND_COPY); c = sell; } else if(d.GetAction() == DND_MOVE && IsDragAndDropSource()) { if(c > sell) c -= selh - sell; if(!IsReadOnly()) RemoveSelection(); d.SetAction(DND_COPY); } } int count = Insert(c, text); sb.y = a; SetFocus(); SetSelection(c, c + count); Action(); return; } if(!d.IsAccepted()) return; if(!isdrag) { isdrag = true; ScrollIntoCursor(); } Point dc = Null; if(c >= 0) dc = GetColumnLine(c); if(dc != dropcaret) { RefreshDropCaret(); dropcaret = dc; RefreshDropCaret(); } }
void DocEdit::DragAndDrop(Point p, PasteClip& d) { if(IsReadOnly()) return; int c = GetMousePos(p); if(AcceptText(d)) { NextUndo(); int a = sb; int sell, selh; WString txt = GetWString(d); if(GetSelection(sell, selh)) { if(c >= sell && c < selh) { if(!IsReadOnly()) RemoveSelection(); if(IsDragAndDropSource()) d.SetAction(DND_COPY); c = sell; } else if(d.GetAction() == DND_MOVE && IsDragAndDropSource()) { if(c > sell) c -= selh - sell; if(!IsReadOnly()) RemoveSelection(); d.SetAction(DND_COPY); } } int count = Insert(c, txt); sb = a; SetFocus(); SetSelection(c, c + count); Action(); return; } if(!d.IsAccepted()) return; Point dc = Null; if(c >= 0) { Point cr = GetCaret(c); dc = Point(cr.x + 1, cr.y); } if(dc != dropcaret) { RefreshDropCaret(); dropcaret = dc; RefreshDropCaret(); } }
void MyApp::DragAndDrop(Point p, PasteClip& clip) { if(clip.Accept("MyAppData")) { String bin = clip; if(bin.GetLength() > sizeof(Color)) { // prudent check pos = p; memcpy(&data.color, ~bin, sizeof(Color)); data.text = bin.Mid(sizeof(Color)); } Refresh(); } if(AcceptText(clip)) { pos = p; data.text = GetString(clip); } dragpos = clip.IsAccepted() ? p : Null; Refresh(); }
void UDropTarget::DnD(POINTL pl, bool drop, DWORD *effect, DWORD keys) { GuiLock __; LLOG("DnD effect: " << *effect); dword e = *effect; *effect = DROPEFFECT_NONE; if(!ctrl) return; PasteClip d; d.dt = this; d.paste = drop; d.accepted = false; d.allowed = 0; d.action = 0; if(e & DROPEFFECT_COPY) { LLOG("DnD DROPEFFECT_COPY"); d.allowed = DND_COPY; d.action = DND_COPY; } if(e & DROPEFFECT_MOVE) { LLOG("DnD DROPEFFECT_MOVE"); d.allowed |= DND_MOVE; if(Ctrl::GetDragAndDropSource()) d.action = DND_MOVE; } LLOG("DnD keys & MK_CONTROL:" << (keys & MK_CONTROL)); if((keys & MK_CONTROL) && (d.allowed & DND_COPY)) d.action = DND_COPY; if((keys & (MK_ALT|MK_SHIFT)) && (d.allowed & DND_MOVE)) d.action = DND_MOVE; ctrl->DnD(Point(pl.x, pl.y), d); if(d.IsAccepted()) { LLOG("DnD accepted, action: " << (int)d.action); if(d.action == DND_MOVE) *effect = DROPEFFECT_MOVE; if(d.action == DND_COPY) *effect = DROPEFFECT_COPY; } }