public override void MouseDragged(NSEvent ev) { _callbacks.OnDragged().MatchWith( data => { var pasteBoardItem = new NSPasteboardItem(); pasteBoardItem.SetStringForType("fuse-drag-n-drop", "public.data"); var draggingItem = new NSDraggingItem(pasteBoardItem); var imgCache = BitmapImageRepForCachingDisplayInRect(Bounds); CacheDisplay(Bounds, imgCache); var img = new NSImage(imgCache.Size); img.LockFocus(); imgCache.DrawInRect(Bounds, Bounds, NSCompositingOperation.Copy, 0.5f, true, new NSDictionary()); img.UnlockFocus(); draggingItem.SetDraggingFrame(new CGRect(Bounds.Location, img.Size), img); BeginDraggingSession(new[] { draggingItem }, ev, new DragSource(this, _space, _callbacks, data)); }, () => { BeginDraggingSession(new NSDraggingItem[0], ev, new DragSource(this, _space, _callbacks, null)); }); }
static IControl MakeHittable(IControl control, Space space, Pointer.Callbacks callbacks) { return(Control.Create(location => { var view = new Canvas() { Background = Brushes.Transparent, }; view.MouseDown += (s, a) => { view.CaptureMouse(); callbacks.OnPressed(new Pointer.OnPressedArgs(ToPoint(a, view, space), a.ClickCount)); a.Handled = true; }; view.MouseUp += (s, a) => { callbacks.OnReleased(); a.Handled = true; view.ReleaseMouseCapture(); if (a.ChangedButton == MouseButton.Right) { if (view.ContextMenu == null) { return; } view.ContextMenu.IsOpen = true; } }; view.MouseMove += (s, a) => { callbacks.OnMoved(ToPoint(a, view, space)); a.Handled = true; if (view.IsMouseCaptured && a.LeftButton == MouseButtonState.Pressed) { callbacks.OnDragged().Do(data => DragDrop.DoDragDrop(view, new DraggingImplementation.DragData(data), DragDropEffects.All)); } }; view.MouseEnter += (s, a) => { callbacks.OnEntered(ToPoint(a, view, space)); a.Handled = true; }; view.MouseLeave += (s, a) => { callbacks.OnExited(ToPoint(a, view, space)); a.Handled = true; }; view.GotMouseCapture += (s, a) => { callbacks.OnGotFocus(); a.Handled = true; }; view.LostMouseCapture += (s, a) => { callbacks.OnLostFocus(); a.Handled = true; }; location.BindNativeDefaults(view, _dispatcher); control.Mount( new MountLocation.Mutable { AvailableSize = location.AvailableSize, IsRooted = location.IsRooted, NativeFrame = ObservableMath.RectangleWithSize(location.NativeFrame.Size), }); var contentHandle = control.NativeHandle as FrameworkElement; if (contentHandle != null) { _dispatcher.Enqueue(() => view.Children.Add(contentHandle)); } return view; }).WithSize(control.DesiredSize)); }