Beispiel #1
0
        public void StartDragAndDrop(View sourceView, View shadowView, DragData dragData, SourceEventHandler callback)
        {
            if (null == shadowView)
            {
                throw new ArgumentNullException(nameof(shadowView));
            }

            if (null == mDragWindow)
            {
                mDragWindow = new Window("DragWindow", new Rectangle(-shadowWidth, -shadowHeight, shadowWidth, shadowHeight), true)
                {
                    BackgroundColor = Color.Transparent,
                };
            }

            shadowView.SetSize(shadowWidth, shadowHeight);
            shadowView.SetOpacity(0.9f);

            if (mShadowView)
            {
                mDragWindow.Remove(mShadowView);
            }

            mShadowView = shadowView;
            mDragWindow.Add(mShadowView);
            mDragWindow.Show();

            sourceEventCb = (sourceEventType) =>
            {
                callback((SourceEventType)sourceEventType);
            };

            if (!Interop.DragAndDrop.StartDragAndDrop(SwigCPtr, View.getCPtr(sourceView), Window.getCPtr(mDragWindow), dragData.MimeType, dragData.Data,
                                                      new global::System.Runtime.InteropServices.HandleRef(this, Marshal.GetFunctionPointerForDelegate <Delegate>(sourceEventCb))))
            {
                throw new InvalidOperationException("Fail to StartDragAndDrop");
            }
        }
Beispiel #2
0
        public void StartDragAndDrop(View sourceView, View shadowView, DragData dragData, SourceEventHandler callback)
        {
            if (null == shadowView)
            {
                throw new ArgumentNullException(nameof(shadowView));
            }

            shadowWidth  = (int)shadowView.Size.Width;
            shadowHeight = (int)shadowView.Size.Height;

            // Prevents shadowView size from being smaller than 100 pixel
            if (shadowView.Size.Width < 100)
            {
                shadowWidth = 100;
            }

            if (shadowView.Size.Height < 100)
            {
                shadowHeight = 100;
            }

            if (null == mDragWindow)
            {
                mDragWindow = new Window("DragWindow", new Rectangle(-shadowWidth, -shadowHeight, shadowWidth, shadowHeight), true)
                {
                    BackgroundColor = Color.Transparent,
                };
            }

            //Initialize Drag Window Position and Size based on Shadow View Position and Size
            mDragWindow.SetPosition(new Position2D((int)shadowView.Position.X, (int)shadowView.Position.Y));
            mDragWindow.SetWindowSize(new Size(shadowWidth, shadowHeight));

            //Make Shadow View Transparent
            shadowView.SetOpacity(0.9f);

            //Make Position 0, 0 for Moving into Drag Window
            shadowView.Position = new Position(0, 0);

            if (mShadowView)
            {
                mShadowView.Hide();
                mDragWindow.Remove(mShadowView);
                mShadowView.Dispose();
            }

            mShadowView = shadowView;
            mDragWindow.Add(mShadowView);

            //Update Window Directly
            mDragWindow.VisibiltyChangedSignalEmit(true);
            mDragWindow.RenderOnce();

            sourceEventCb = (sourceEventType) =>
            {
                if ((SourceEventType)sourceEventType == SourceEventType.Finish)
                {
                    if (mShadowView)
                    {
                        mShadowView.Hide();
                        mDragWindow.Remove(mShadowView);
                        mShadowView.Dispose();
                    }

                    //Update Window Directly
                    mDragWindow.VisibiltyChangedSignalEmit(true);
                    mDragWindow.RenderOnce();
                }

                callback((SourceEventType)sourceEventType);
            };

            if (!Interop.DragAndDrop.StartDragAndDrop(SwigCPtr, View.getCPtr(sourceView), Window.getCPtr(mDragWindow), dragData.MimeType, dragData.Data,
                                                      new global::System.Runtime.InteropServices.HandleRef(this, Marshal.GetFunctionPointerForDelegate <Delegate>(sourceEventCb))))
            {
                throw new InvalidOperationException("Fail to StartDragAndDrop");
            }

            mDragWindow.Show();
        }