示例#1
0
        private void CopyToClipboard(object sender, RoutedEventArgs args)
        {
            var dataObject = new DataObject();

            // Copy data from RichTextBox/File content into DataObject
            if ((bool) rbCopyDataFromRichTextBox.IsChecked)
            {
                CopyDataFromRichTextBox(dataObject);
            }
            else
            {
                CopyDataFromFile(dataObject);
            }

            // Copy DataObject on the system Clipboard
            if (dataObject.GetFormats().Length > 0)
            {
                if ((bool) cbFlushOnCopy.IsChecked)
                {
                    // Copy data to the system clipboard with flush
                    Clipboard.SetDataObject(dataObject, true /*copy*/);
                }
                else
                {
                    // Copy data to the system clipboard without flush
                    Clipboard.SetDataObject(dataObject, false /*copy*/);
                }
            }

            // Dump the copied data contents on the information panel
            DumpAllClipboardContentsInternal();
        }
示例#2
0
        protected async override void OnDrop(System.Windows.DragEventArgs e)
        {
            double currMapX = 0;
            double currMapY = 0;

            System.Windows.DataObject d = (System.Windows.DataObject)e.Data;

            string[] dataFormats = d.GetFormats();
            string   dataText    = d.GetText();

            Point position = e.GetPosition(this);

            GMap.NET.PointLatLng curPosition = FromLocalToLatLng((int)position.X, (int)position.Y);
            currMapX = curPosition.Lng;
            currMapY = curPosition.Lat;

            for (int i = 0; i < dataFormats.Length; i++)
            {
                string dragFormat = dataFormats[i];

                if (dragFormat.Contains("FormationTree") && dataText == "Actor")
                {
                    object dragObject = d.GetData(dragFormat);

                    FormationTree formation = dragObject as FormationTree;
                    if (formation == null)
                    {
                        continue;
                    }

                    enOSMhighwayFilter highwayFilter = enOSMhighwayFilter.Undefined;
                    SetHighwayFilter(highwayFilter);
                    shPointId PointId = await clsRoadRoutingWebApi.GetNearestPointIdOnRoad("0", highwayFilter, currMapX, currMapY);

                    if (PointId != null)
                    {
                        shPoint           pnt             = PointId.point;
                        DeployedFormation deployFormation = new DeployedFormation();
                        deployFormation.x         = pnt.x;
                        deployFormation.y         = pnt.y;
                        deployFormation.formation = formation;

                        AtomData atom = await TDSClient.SAGInterface.SAGSignalR.DeployFormationFromTree(VMMainViewModel.Instance.SimulationHubProxy, deployFormation);

                        if (atom != null)
                        {
                            AtomDeployedEventArgs args = new AtomDeployedEventArgs();
                            args.atom = atom;
                            if (AtomDeployedEvent != null)
                            {
                                AtomDeployedEvent(this, args);
                            }
                        }
                    }

                    return;
                }
            }
        }
        private void ProfileTaskList_Drop(object sender, DragEventArgs e)
        {
            if (MainWindow.Instance.AccountGrid.SelectedItem != null)
            {
                CharacterProfile profile      = (CharacterProfile)MainWindow.Instance.AccountGrid.SelectedItem;
                DataObject       dObj         = (DataObject)e.Data;
                BMTask           task         = null;
                bool             removeSource = false;
                // drop originated from the left side 'TaskList'
                if (dObj.GetDataPresent("PersistentObject"))
                {
                    Type taskType = (Type)dObj.GetData("PersistentObject");
                    task = (BMTask)Activator.CreateInstance(taskType);
                    task.SetProfile(profile);
                }
                else if (sender == ProfileTaskList)// drop originated from itself.
                {
                    task         = (BMTask)dObj.GetData(dObj.GetFormats().FirstOrDefault());
                    removeSource = true;
                }
                if (task == null)
                {
                    return;
                }
                ListBoxItem targetItem = FindParent <ListBoxItem>((DependencyObject)e.OriginalSource);

                if (targetItem != null)
                {
                    BMTask targetTask = (BMTask)targetItem.Content;
                    for (int i = ProfileTaskList.Items.Count - 1; i >= 0; i--)
                    {
                        if (ProfileTaskList.Items[i].Equals(targetTask))
                        {
                            if (removeSource)
                            {
                                profile.Tasks.Remove(task);
                            }
                            profile.Tasks.Insert(i, task);
                            break;
                        }
                    }
                }
                else if (!removeSource)
                {
                    profile.Tasks.Add(task);
                }
                _isDragging = false;
                e.Handled   = true;
            }
        }
示例#4
0
		public void Defaults ()
		{
			DataObject dobj = new DataObject ();

			Assert.Throws<SecurityException> (() => dobj.GetFormats (), "GetFormats ()");
			Assert.Throws<SecurityException> (() => dobj.GetFormats (true), "GetFormats (true)");
			Assert.Throws<SecurityException> (() => dobj.GetFormats (false), "GetFormats (false)");

			Assert.Throws<SecurityException> (() => dobj.GetData (DataFormats.FileDrop), "GetData (string)");
			Assert.Throws<SecurityException> (() => dobj.GetData (DataFormats.FileDrop, true), "GetData (string,true)");
			Assert.Throws<SecurityException> (() => dobj.GetData (DataFormats.FileDrop, false), "GetData (string,false)");
			Assert.Throws<SecurityException> (() => dobj.GetData (typeof(string)), "GetData (Type)");

			Assert.Throws<SecurityException> (() => dobj.GetDataPresent (DataFormats.FileDrop), "GetDataPresent (string)");
			Assert.Throws<SecurityException> (() => dobj.GetDataPresent (DataFormats.FileDrop, true), "GetDataPresent (string,true)");
			Assert.Throws<SecurityException> (() => dobj.GetDataPresent (DataFormats.FileDrop, false), "GetDataPresent (string,false)");
			Assert.Throws<SecurityException> (() => dobj.GetDataPresent (typeof (string)), "GetDataPresent (Type)");

			Assert.Throws<SecurityException> (() => dobj.SetData (DataFormats.FileDrop), "SetData (string)");
			Assert.Throws<SecurityException> (() => dobj.SetData (DataFormats.FileDrop, true), "SetData (string,true)");
			Assert.Throws<SecurityException> (() => dobj.SetData (DataFormats.FileDrop, false), "SetData (string,false)");
			Assert.Throws<SecurityException> (() => dobj.SetData (typeof (string)), "SetData (Type)");
		}
示例#5
0
        private void TextSelectionToDataObject(object sender, RoutedEventArgs e)
        {
            // Create a new data object using one of the overloaded constructors.  This particular
            // overload accepts a string specifying the data format (provided by the DataFormats class),
            // and an Object (in this case a string) that represents the data to be stored in the data object.
            var dataObject = new DataObject(DataFormats.Text, sourceTextBox.SelectedText);

            dataObjectInfoTextBox.Clear();

            // Get and display the native data formats (filtering out auto-convertable data formats).
            dataObjectInfoTextBox.Text = "\nNative data formats present:\n";
            foreach (var format in dataObject.GetFormats(false /*autoconvert*/))
                dataObjectInfoTextBox.Text += format + "\n";

            // Display the data in the data object.
            dataObjectInfoTextBox.Text += "\nData contents:\n";
            dataObjectInfoTextBox.Text += dataObject.GetData(DataFormats.Text, false /*autoconvert*/).ToString();
        }
示例#6
0
        void TextEditor_Drop(object sender, DragEventArgs e)
        {
            Point pos = e.GetPosition(sender as IInputElement);

            System.Windows.DataObject o = e.Data as System.Windows.DataObject;
            string[] formats            = o.GetFormats();
            string   SAMPLE_FORMAT      = "DXUnionPacket.ViewModel.Sample";
            string   MSI_INSTALL_FORMAT = "DXInstaller.MSIInstaller";
            string   GONG_DD_FORMAT     = "GongSolutions.Wpf.DragDrop.DropInfo";
            string   text = "";

            foreach (string format in formats)
            {
                if (format.Equals(SAMPLE_FORMAT))
                {
                    if (o.GetDataPresent(SAMPLE_FORMAT))
                    {
                        lock (sync){
                            Object oo = o.GetData(SAMPLE_FORMAT);
                            Sample s  = o.GetData(SAMPLE_FORMAT, true) as Sample;
                            text = s.Text;
                            break;
                        }
                    }
                }
                if (format.Equals(MSI_INSTALL_FORMAT))
                {
                    MSIInstaller i = o.GetData(MSI_INSTALL_FORMAT) as MSIInstaller;
                    text = i.Guid;
                    break;
                }
            }
            if (!String.IsNullOrEmpty(text))
            {
                InsertText(text, pos);
            }
        }
示例#7
0
        public static Bitmap GetImageFromDataObject(DataObject dataObject)
        {
            try
            {
                string[] formats = dataObject.GetFormats(true);
                if (formats == null || formats.Length == 0)
                {
                    return(null);
                }

                //if (formats.Contains("PNG")) // causes errors when trying to save from recents
                //{
                //    Console.WriteLine("PNG");

                //    using (MemoryStream ms = (MemoryStream)dataObject.GetData("PNG"))
                //    {
                //        ms.Position = 0;
                //        return new Bitmap(ms);
                //    }
                //}
                if (formats.Contains("System.Drawing.Bitmap"))
                {
                    Console.WriteLine("System.Drawing.Bitmap");
                    Bitmap bitmap = (Bitmap)dataObject.GetData("System.Drawing.Bitmap");
                    return(bitmap);
                }
                else
                {
                    return(dataObject.GetData(DataFormats.Bitmap) as Bitmap);
                }
            }
            catch
            {
                return(null);
            }
        }
示例#8
0
            //------------------------------------------------------
            //
            //  Constructors
            //
            //------------------------------------------------------

            #region Constructors

            // Creates a new enumerator instance.
            internal FormatEnumerator(DataObject dataObject)
            {
                FORMATETC temp;
                string[] formats;

                formats = dataObject.GetFormats();
                _formats = new FORMATETC[formats == null ? 0 : formats.Length];

                if (formats != null)
                {
                    for (int i = 0; i < formats.Length; i++)
                    {
                        string format;

                        format = formats[i];
                        temp = new FORMATETC();
                        temp.cfFormat = (short)DataFormats.GetDataFormat(format).Id;
                        temp.dwAspect = DVASPECT.DVASPECT_CONTENT;
                        temp.ptd = IntPtr.Zero;
                        temp.lindex = -1;

                        if (IsFormatEqual(format, DataFormats.Bitmap))
                        {
                            temp.tymed = TYMED.TYMED_GDI;
                        }
                        else if (IsFormatEqual(format, DataFormats.EnhancedMetafile))
                        {
                            temp.tymed = TYMED.TYMED_ENHMF;
                        }
                        else
                        {
                            temp.tymed = TYMED.TYMED_HGLOBAL;
                        }

                        _formats[i] = temp;
                    }
                }
            }