private void NativeObject_DropSuccess(object sender, EventArgs e)
        {
            if (!reportedSuccess)
            {
                InputshareDataObject obj = (InputshareDataObject)sender;

                reportedSuccess = true;
                DragDropSuccess?.Invoke(this, null);
            }
        }
        public override void SetClipboardData(ClipboardDataBase data)
        {
            InputshareDataObject obj = new InputshareDataObject(data, false);

            if (data.DataType == ClipboardDataType.File)
            {
                //If two applications paste data, we can't know which of the two we are interacting with.
                //In other words, we don't know if its program A or program B calling GetData() on the InputshareDataObject
                //this means that files will just be corrupted if two programs try to paste the data

                //To fix this, as soon as the data is pasted, we put another InputshareDataObject onto the clipboard.
                //Each dataobject gets their own access token from the host to allow them to have seperate filestreams
                //and allow any number of programs to paste at the same time
                currentClipboardFiles = data as ClipboardVirtualFileData;
                obj.FilesPasted      += Obj_ObjectPasted;
            }


            cbHookWindow.SetClipboardData(obj);
        }
        private void DoDragDrop(ClipboardDataBase data)
        {
            InputshareDataObject nativeObject = null;

            try
            {
                nativeObject    = ClipboardTranslatorWindows.ConvertToWindows(data);
                reportedSuccess = false;
                nativeObject.SetData("InputshareData", new bool());
                dropQueue.Enqueue(nativeObject);

                nativeObject.DropComplete += NativeObject_DropComplete;
                nativeObject.DropSuccess  += NativeObject_DropSuccess;
            }
            catch (Exception ex)
            {
                ISLogger.Write("Could not start drag drop operation: " + ex.Message);
                return;
            }


            this.Show();
            this.BringToFront();
            this.TopMost = true;
            GetCurrentCursorMonitorSize(out Size mSize, out Point mPos);
            this.SetDesktopLocation((int)mPos.X, (int)mPos.Y);
            this.Size = mSize;
            outMan.Send(new InputshareLib.Input.ISInputData(InputshareLib.Input.ISInputCode.IS_MOUSELDOWN, 0, 0));
            outMan.Send(new InputshareLib.Input.ISInputData(InputshareLib.Input.ISInputCode.IS_MOUSERUP, 0, 0));
            Task.Run(() => {
                Thread.Sleep(300); this.Invoke(new Action(() => {
                    if (!registeredDrop)
                    {
                        DoDragDrop(data);
                    }
                }));
            });
        }
Beispiel #4
0
        public virtual void SetClipboardData(InputshareDataObject data)
        {
            if (Closed)
            {
                throw new InvalidOperationException("Window has been closed");
            }

            InvokeAction(new Action(() => {
                for (int i = 0; i < 10; i++)
                {
                    try
                    {
                        System.Windows.Clipboard.SetDataObject(data);
                        return;
                    }catch
                    {
                        Thread.Sleep(25);
                    }
                }

                ISLogger.Write("Failed to set clipboard data!");
            }));
        }