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; }
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; }
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(); } }