Esempio n. 1
0
        public MainWindow()
        {
            InitializeComponent();

            System.Windows.IDataObject data = System.Windows.Clipboard.GetDataObject();

            string[] formats = data.GetFormats();

#if !DEBUG
            // Makes it a royal pain to debug...
            this.Topmost       = true;
            this.ShowInTaskbar = false;
            //this.CaptureButton.Visibility = Visibility.Collapsed;
#endif

            new Dragger(Toolbar);

            ToleranceSlider.Value = ScreenCoordinates.ColorTolerance;

            ToleranceSlider.ValueChanged += delegate
            {
                ScreenCoordinates.ColorTolerance = ToleranceSlider.Value;
            };

            DataContext = this;

            IntRect screenBounds = ScreenShot.FullScreenBounds;
            Top    = screenBounds.Top;
            Left   = screenBounds.Left;
            Width  = screenBounds.Width;
            Height = screenBounds.Height;
        }
        public static MemoryStream[]? GetFileContents(this System.Windows.IDataObject dataObject)
        {
            var w            = new DataObjectWrapper(dataObject);
            var fileContents = "FileContents";

            return((MemoryStream[])w.GetData(fileContents));
        }
Esempio n. 3
0
        public void LoadDroppedFile(IDataObject data)
        {
            if (!data.GetDataPresent(DataFormats.FileDrop))
            {
                return;
            }
            var filePaths = (string[])(data.GetData(DataFormats.FileDrop));

            if (filePaths == null || filePaths.Length <= 0)
            {
                return;
            }

            var filePath = filePaths[0];

            if (filePath == null)
            {
                return;
            }

            var ext = Path.GetExtension(filePath);

            ext = ext.ToLower();
            if (String.Compare(ext, ".sdf", StringComparison.OrdinalIgnoreCase) != 0)
            {
                return;
            }

            dataSource = filePaths[0];
            AnalyzeDatabase();
        }
Esempio n. 4
0
        private async void OnDropItem(IDataObject data)
        {
            var filePath = (string[])data.GetData(DataFormats.FileDrop);

            if (filePath != null)
            {
                var fileList        = new List <string>(filePath);
                var fileSystemItems = await AddFileSystemItems(fileList);

                if (fileSystemItems != null)
                {
                    if (FileList == null)
                    {
                        FileList = FileList.Create();
                    }
                    foreach (var item in fileSystemItems)
                    {
                        FileList.Items.Add(item);
                    }
                }
            }
            if (FileList.Items.Count == 0)
            {
                FileList = null;
            }
        }
        public DataObjectWrapper(System.Windows.IDataObject underlyingDataObject)
        {
            this.underlyingDataObject    = underlyingDataObject;
            this.comUnderlyingDataObject = (System.Runtime.InteropServices.ComTypes.IDataObject) this.underlyingDataObject;

            FieldInfo innerDataField = this.underlyingDataObject.GetType().GetField("innerData", BindingFlags.NonPublic | BindingFlags.Instance);
        }
Esempio n. 6
0
        private void InsertAnswerImage()
        {
            //获取剪切板上的图片,如果剪切板上的图片为空,则提示
            System.Windows.IDataObject clip1 = System.Windows.Clipboard.GetDataObject();
            bool ifCanGetClilp = clip1.GetDataPresent(typeof(System.Drawing.Bitmap));

            if (true == ifCanGetClilp)
            {
                Bitmap clipBitMap = (Bitmap)clip1.GetData(typeof(System.Drawing.Bitmap));
                String imagePath  = @"../../TestCases/temp.png";
                clipBitMap.Save(imagePath, System.Drawing.Imaging.ImageFormat.Png);
                int QuestionID = 0;
                int.TryParse(textBox4.Text, out QuestionID);
                try
                {
                    Question u = Question.Find(QuestionID);
                    u.AnswerMedia_width  = clipBitMap.Width;
                    u.AnswerMedia_height = clipBitMap.Height;
                    clipBitMap.Dispose();
                    FileStream fs1       = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
                    Byte[]     tempFile3 = new Byte[fs1.Length];
                    fs1.Read(tempFile3, 0, (int)fs1.Length);
                    u.AnswerMediaContent = tempFile3;
                    u.UpdateAndFlush();
                    fs1.Close();
                    textBlock1.Text = "答案图片:" + u.AnswerMedia_width.ToString();
                }
                catch
                {
                    MessageBox.Show("找不到题序");
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        ///  PasteTextToRow.
        /// </summary>
        protected override void PasteTextToRow()
        {
            System.Windows.IDataObject dataObject = null;
            dataObject = Clipboard.GetDataObject();
            var clipBoardContent = dataObject.GetData(DataFormats.UnicodeText) as string;

            string[] records = Regex.Split(clipBoardContent.ToString(), @"\r\n");
            if (dataGrid.SelectionUnit == GridSelectionUnit.Row)
            {
                dataGrid.Focus();
                bool isAddNewRow = this.dataGrid.IsAddNewIndex(this.dataGrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.RowIndex);

                if (isAddNewRow)
                {
                    PasteNewRow(records);
                }
                else
                {
                    base.PasteTextToRow();
                }
            }
            else
            {
                base.PasteTextToRow();
            }
        }
 public static IEnumerable <IFile> GetFileDescriptorFiles(this System.Windows.IDataObject data)
 {
     if (data == null || !data.GetDataPresent(WideFileGroupDescriptorFormat))
     {
         return(new IFile[0]);
     }
     return(NamesWithPositions(data).Select(i => new LazyStreamFile(i.Item2, () => GetFileByIndex(data, i.Item1))));
 }
Esempio n. 9
0
        public OutlookDataObject(System.Windows.IDataObject underlyingDataObject)
        {
            this.underlyingDataObject    = underlyingDataObject;
            this.comUnderlyingDataObject = (System.Runtime.InteropServices.ComTypes.IDataObject) this.underlyingDataObject;
            FieldInfo innerDataField = this.underlyingDataObject.GetType().GetField("_innerData", BindingFlags.NonPublic | BindingFlags.Instance);

            this.oleUnderlyingDataObject  = (System.Windows.IDataObject)innerDataField.GetValue(this.underlyingDataObject);
            this.getDataFromHGLOBALMethod = this.oleUnderlyingDataObject.GetType().GetMethod("GetDataFromHGLOBAL", BindingFlags.NonPublic | BindingFlags.Instance);
        }
        public static Stream GetFileByIndex(System.Windows.IDataObject target, int position)
        {
            var       comDataObject = (System.Runtime.InteropServices.ComTypes.IDataObject)target;
            FORMATETC fmtCC         = CreateStructToRequestStream(position);
            STGMEDIUM result        = new STGMEDIUM();

            comDataObject.GetData(ref fmtCC, out result);
            return(result.ExtractFileStream());
        }
Esempio n. 11
0
        public override void GetApplicationDragDropInformation(System.Windows.IDataObject data, out string[] filenames, out MemoryStream[] filestreams)
        {
            //wrap standard IDataObject in OutlookDataObject
            OutlookDataObject dataObject = new OutlookDataObject(data);

            //get the names and data streams of the files dropped
            filenames   = (string[])dataObject.GetData("FileGroupDescriptorW");
            filestreams = (MemoryStream[])dataObject.GetData("FileContents");
        }
Esempio n. 12
0
        /// <summary>
        /// Sets the drag image from a BitmapSource.
        /// </summary>
        /// <param name="dataObject">The DataObject on which to set the drag image.</param>
        /// <param name="image">The image source.</param>
        /// <param name="cursorOffset">The offset relative to the bitmap image.</param>
        public static void SetDragImage(this IDataObject dataObject, BitmapSource image, Point cursorOffset)
        {
            // Our internal routine requires an HBITMAP, so we'll convert the
            // BitmapSource to a System.Drawing.Bitmap.
            Bitmap bmp = GetBitmapFromBitmapSource(image, Colors.Magenta);

            // Sets the drag image from a Bitmap
            SetDragImage(dataObject, bmp, cursorOffset);
        }
Esempio n. 13
0
 /// <summary>
 /// コピーした項目を貼り付け
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void PasteItem_Execute(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)
 {
     // クリップボードの文字列をItemにパースして追加
     System.Windows.IDataObject data = System.Windows.Clipboard.GetDataObject();
     if (data.GetDataPresent(System.Windows.DataFormats.CommaSeparatedValue))
     {
         string str = (string)data.GetData(System.Windows.DataFormats.CommaSeparatedValue);
         mViewModel.Items.Add(ViewModel.Item.Parse(str));
     }
 }
Esempio n. 14
0
        private string GetStringData()
        {
            string ret = "";

            System.Windows.IDataObject iData = System.Windows.Clipboard.GetDataObject();
            if (iData.GetDataPresent(System.Windows.DataFormats.Text))
            {
                ret = (string)iData.GetData(System.Windows.DataFormats.Text);
            }
            return(ret);
        }
        public override void GetApplicationDragDropInformation(System.Windows.IDataObject data, out string[] filenames, out MemoryStream[] filestreams)
        {
            List <string>       _fileNames   = new List <string>();
            List <MemoryStream> _filestreams = new List <MemoryStream>();

            string sourceFolder = ConfigurationManager.GetInstance().CreateATempFolder();

            Microsoft.Office.Interop.Outlook.Application application = Application as Microsoft.Office.Interop.Outlook.Application;
            for (int i = 1; i <= application.ActiveExplorer().Selection.Count; i++)
            {
                Object temp = application.ActiveExplorer().Selection[i];
                if (temp is Microsoft.Office.Interop.Outlook.MailItem)
                {
                    Microsoft.Office.Interop.Outlook.MailItem mailitem = (temp as Microsoft.Office.Interop.Outlook.MailItem);
                    string fileName = mailitem.Subject + ".msg";
                    string invalid  = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());

                    foreach (char c in invalid)
                    {
                        fileName = fileName.Replace(c.ToString(), "");
                    }
                    string filePath = sourceFolder + "\\" + fileName;
                    mailitem.SaveAs(filePath);
                    MemoryStream ms = new MemoryStream();
                    using (FileStream fs = File.OpenRead(filePath))
                    {
                        fs.CopyTo(ms);
                    }

                    _fileNames.Add(fileName);
                    _filestreams.Add(ms);
                }
            }
            filenames   = _fileNames.ToArray();
            filestreams = _filestreams.ToArray();

            /*
             * //wrap standard IDataObject in OutlookDataObject
             * OutlookDataObject dataObject = new OutlookDataObject(data);
             *
             * try
             * {
             *  //get the names and data streams of the files dropped
             *  filenames = (string[])dataObject.GetData("FileGroupDescriptorW");
             *  filestreams = (MemoryStream[])dataObject.GetData("FileContents");
             * }
             * catch (Exception ex)
             * {
             *  string subject = ((string)dataObject.GetData("Text")).Split(new char[]{'\n'})[1].Split(new char[]{'\t'})[1];
             *  filenames = new string[]{subject};
             *  filestreams = new MemoryStream[] { (MemoryStream)dataObject.GetData("Object Descriptor") };
             * }
             */
        }
Esempio n. 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OutlookDataObject"/> class.
        /// </summary>
        /// <param name="underlyingDataObject">The underlying data object to wrap.</param>
        public OutlookDataObject(System.Windows.IDataObject underlyingDataObject)
        {
            //get the underlying dataobject and its ComType IDataObject interface to it
            this.underlyingDataObject    = underlyingDataObject;
            this.comUnderlyingDataObject = (System.Runtime.InteropServices.ComTypes.IDataObject) this.underlyingDataObject;

            //get the internal ole dataobject and its GetDataFromHGLOBLAL so it can be called later
            FieldInfo innerDataField = this.underlyingDataObject.GetType().GetField("innerData", BindingFlags.NonPublic | BindingFlags.Instance);

            this.oleUnderlyingDataObject   = (System.Windows.IDataObject)innerDataField.GetValue(this.underlyingDataObject);
            this.getDataFromHGLOBLALMethod = this.oleUnderlyingDataObject.GetType().GetMethod("GetDataFromHGLOBLAL", BindingFlags.NonPublic | BindingFlags.Instance);
        }
        private static IEnumerable <Tuple <int, string> > NamesWithPositions(this System.Windows.IDataObject target)
        {
            var files = InnerGetNamesWithPosition(target,
                                                  WideFileGroupDescriptorFormat, Encoding.Unicode, 0x250).ToArray();

            if (files.Any())
            {
                return(files);
            }
            return(InnerGetNamesWithPosition(target,
                                             NarrowFileGroupDescriptorFormat, Encoding.ASCII, 0x14C));
        }
Esempio n. 18
0
        private void BasicTest()
        {
            Question u = Question.Find(3);

            //label1.Content = u.用户名;



            u = Question.Find(3);



            //通过剪切板进入到数据库
            System.Windows.IDataObject clip1 = System.Windows.Clipboard.GetDataObject();

            bool ifCanGetClilp = clip1.GetDataPresent(typeof(System.Drawing.Bitmap));
            //object clipBitMap = clip1.GetData(DataFormats.Bitmap);
            Bitmap clipBitMap = (Bitmap)clip1.GetData(typeof(System.Drawing.Bitmap));

            String imagePath = @"../../TestCases/temp.png";

            //另存为临时文件
            clipBitMap.Save(imagePath, System.Drawing.Imaging.ImageFormat.Png);
            u.Media_width  = clipBitMap.Width;
            u.Media_height = clipBitMap.Height;
            clipBitMap.Dispose();

            //读一个二进制文件,将该文件内容写入到DB中

            FileStream fs1 = new FileStream(imagePath, FileMode.Open, FileAccess.Read);

            Byte[] tempFile3 = new Byte[fs1.Length];
            fs1.Read(tempFile3, 0, (int)fs1.Length);

            u.MediaContent = tempFile3;
            u.AnswerText   = "测试";
            u.UpdateAndFlush();
            fs1.Close();

            u = Question.TryFind(4);
            if (u == null)
            {
                u            = new Question();
                u.QuestionID = 4;
                //u.用户名 = "u4";
                u.CreateAndFlush();
            }
            else
            {
                u.DeleteAndFlush();
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Sets managed data to a clipboard DataObject.
        /// </summary>
        /// <param name="dataObject">The DataObject to set the data on.</param>
        /// <param name="format">The clipboard format.</param>
        /// <param name="data">The data object.</param>
        /// <remarks>
        /// Because the underlying data store is not storing managed objects, but
        /// unmanaged ones, this function provides intelligent conversion, allowing
        /// you to set unmanaged data into the COM implemented IDataObject.</remarks>
        public static void SetDataEx(this IDataObject dataObject, string format, object data)
        {
            DataFormat dataFormat = DataFormats.GetDataFormat(format);

            // Initialize the format structure
            var formatETC = new FORMATETC();

            formatETC.cfFormat = (short)dataFormat.Id;
            formatETC.dwAspect = DVASPECT.DVASPECT_CONTENT;
            formatETC.lindex   = -1;
            formatETC.ptd      = IntPtr.Zero;

            // Try to discover the TYMED from the format and data
            TYMED tymed = GetCompatibleTymed(format, data);

            // If a TYMED was found, we can use the system DataObject
            // to convert our value for us.
            if (tymed != TYMED.TYMED_NULL)
            {
                formatETC.tymed = tymed;

                // Set data on an empty DataObject instance
                var conv = new System.Windows.DataObject();
                conv.SetData(format, data, true);

                // Now retrieve the data, using the COM interface.
                // This will perform a managed to unmanaged conversion for us.
                STGMEDIUM medium;
                ((ComIDataObject)conv).GetData(ref formatETC, out medium);
                try
                {
                    // Now set the data on our data object
                    ((ComIDataObject)dataObject).SetData(ref formatETC, ref medium, true);
                }
                catch
                {
                    // On exceptions, release the medium
                    ReleaseStgMedium(ref medium);
                    throw;
                }
            }
            else
            {
                // Since we couldn't determine a TYMED, this data
                // is likely custom managed data, and won't be used
                // by unmanaged code, so we'll use our custom marshaling
                // implemented by our COM IDataObject extensions.

                ComDataObjectExtensions.SetManagedData((ComIDataObject)dataObject, format, data);
            }
        }
Esempio n. 20
0
        protected override void OnDrop(DragEventArgs e)
        {
            Win32Point wp;

            e.Effects = DragDropEffects.Copy;
            Point p = e.GetPosition(this);

            wp.x = (int)p.X;
            wp.y = (int)p.Y;
            IDropTargetHelper dropHelper = (IDropTargetHelper) new DragDropHelper();

            dropHelper.Drop((ComIDataObject)e.Data, ref wp, (int)e.Effects);
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] files = e.Data.GetData(DataFormats.FileDrop) as string[];
                this.OpenImage(files[0]);
            }

            System.Windows.IDataObject data = e.Data;
            string[] formats = data.GetFormats();
            if (formats.Contains("text/html"))
            {
                var    obj  = data.GetData("text/html");
                string html = string.Empty;
                if (obj is string)
                {
                    html = (string)obj;
                }
                else if (obj is MemoryStream)
                {
                    MemoryStream ms     = (MemoryStream)obj;
                    byte[]       buffer = new byte[ms.Length];
                    ms.Read(buffer, 0, (int)ms.Length);
                    if (buffer[1] == (byte)0)  // Detecting unicode
                    {
                        html = System.Text.Encoding.Unicode.GetString(buffer);
                    }
                    else
                    {
                        html = System.Text.Encoding.ASCII.GetString(buffer);
                    }
                }
                // Using a regex to parse HTML, but JUST FOR THIS EXAMPLE :-)
                var match = new Regex(@"<img[^>]+src=""([^""]*)""").Match(html);
                if (match.Success)
                {
                    Uri uri = new Uri(match.Groups[1].Value);
                    SetImageFromUri(uri);
                }
            }
        }
Esempio n. 21
0
        private bool AcceptDragData(System.Windows.IDataObject data)
        {
            IFileContainer dropTarget = Model as IFileContainer;

            if (dropTarget == null)
            {
                dropTarget = Parent;
            }
            var  draggedItem = data.GetData(MenuLayoutViewModel.DragDataFormat) as IFile;
            bool accept      = draggedItem != null;

            if (accept)
            {
                accept = ShouldAcceptDraggedItem(draggedItem);

                /*
                 * var draggedItemParent = draggedItem.Parent;
                 * accept = (draggedItem != this.Model);
                 * if (accept && (dropTarget != null))
                 * {
                 *  var draggedContainer = draggedItem as IFileContainer;
                 *  if (draggedContainer != null)
                 *  {
                 *      accept = !draggedContainer.ContainsChild(dropTarget) && (draggedContainer != dropTarget);
                 *  }
                 *  if (accept)
                 *  {
                 *      accept = (dropTarget.Size < FileSystemConstants.MaxItemCount) || (dropTarget == draggedItemParent);
                 *  }
                 *  if (accept)
                 *  {
                 *      int currentDepth = DepthFromRoot;
                 *      int draggedItemDepth = draggedItem.Depth;
                 *      if (draggedContainer != null)
                 *      {
                 ++draggedItemDepth; // count folders as one extra layer of depth, since they are pointless w/o containing any items
                 *      }
                 *      accept = currentDepth + draggedItemDepth <= FileSystemConstants.MaximumDepth;
                 *  }
                 * }
                 */
            }
            else
            {
                IEnumerable <ProgramDescription> draggedPrograms = data.GetData(ProgramDescriptionViewModel.DragDataFormat) as IEnumerable <ProgramDescription>;
                accept = (draggedPrograms != null) && (draggedPrograms.Any() && ((draggedPrograms.Count() + dropTarget.Size) <= FileSystemConstants.MaxItemCount));
            }

            return(accept);
        }
Esempio n. 22
0
        void pnlResult_ItemDropEvent(Result result, IDataObject dropDataObject, DragEventArgs args)
        {
            PluginPair pluginPair = PluginManager.AllPlugins.FirstOrDefault(o => o.Metadata.ID == result.PluginID);

            if (ResultItemDropEvent != null && pluginPair != null)
            {
                foreach (var delegateHandler in ResultItemDropEvent.GetInvocationList())
                {
                    if (delegateHandler.Target == pluginPair.Plugin)
                    {
                        delegateHandler.DynamicInvoke(result, dropDataObject, args);
                    }
                }
            }
        }
Esempio n. 23
0
        public static List <string[]> ParseClipboardData()
        {
            List <string[]> clipboardData    = null;
            object          clipboardRawData = null;
            ParseFormat     parseFormat      = null;

            // get the data and set the parsing method based on the format
            // currently works with CSV and Text DataFormats
            System.Windows.IDataObject dataObj = Clipboard.GetDataObject();
            if ((clipboardRawData = dataObj.GetData(DataFormats.CommaSeparatedValue)) != null)
            {
                parseFormat = ParseCsvFormat;
            }
            else if ((clipboardRawData = dataObj.GetData(DataFormats.Text)) != null)
            {
                parseFormat = ParseTextFormat;
            }

            if (parseFormat != null)
            {
                string rawDataStr = clipboardRawData as string;

                if (rawDataStr == null && clipboardRawData is MemoryStream)
                {
                    // cannot convert to a string so try a MemoryStream
                    MemoryStream ms = clipboardRawData as MemoryStream;
                    StreamReader sr = new StreamReader(ms);
                    rawDataStr = sr.ReadToEnd();
                }
                Debug.Assert(rawDataStr != null, string.Format("clipboardRawData: {0}, could not be converted to a string or memorystream.", clipboardRawData));

                string[] rows = rawDataStr.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                if (rows != null && rows.Length > 0)
                {
                    clipboardData = new List <string[]>();
                    foreach (string row in rows)
                    {
                        clipboardData.Add(parseFormat(row));
                    }
                }
                else
                {
                    Debug.WriteLine("unable to parse row data.  possibly null or contains zero rows.");
                }
            }

            return(clipboardData);
        }
Esempio n. 24
0
        /// <summary>
        /// Sets the drag image.
        /// </summary>
        /// <param name="dataObject">The DataObject to set the drag image on.</param>
        /// <param name="image">The drag image.</param>
        /// <param name="cursorOffset">The location of the cursor relative to the image.</param>
        private static void SetDragImage(this IDataObject dataObject, Bitmap bitmap, Point cursorOffset)
        {
            var shdi = new ShDragImage();

            Win32Size size;

            size.cx            = bitmap.Width;
            size.cy            = bitmap.Height;
            shdi.sizeDragImage = size;

            Win32Point wpt;

            wpt.x         = (int)cursorOffset.X;
            wpt.y         = (int)cursorOffset.Y;
            shdi.ptOffset = wpt;

            shdi.crColorKey = DrawingColor.Magenta.ToArgb();

            // This HBITMAP will be managed by the DragDropHelper
            // as soon as we pass it to InitializeFromBitmap. If we fail
            // to make the hand off, we'll delete it to prevent a mem leak.
            IntPtr hbmp = bitmap.GetHbitmap();

            shdi.hbmpDragImage = hbmp;

            try
            {
                var sourceHelper = (IDragSourceHelper) new DragDropHelper();

                try
                {
                    sourceHelper.InitializeFromBitmap(ref shdi, (ComIDataObject)dataObject);
                }
                catch (NotImplementedException ex)
                {
                    throw new Exception("A NotImplementedException was caught. This could be because you forgot to construct your DataObject using a DragDropLib.DataObject", ex);
                }
            }
            catch
            {
                // We failed to initialize the drag image, so the DragDropHelper
                // won't be managing our memory. Release the HBITMAP we allocated.
                DeleteObject(hbmp);
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Gets managed data from a clipboard DataObject.
        /// </summary>
        /// <param name="dataObject">The DataObject to obtain the data from.</param>
        /// <param name="format">The format for which to get the data in.</param>
        /// <returns>The data object instance.</returns>
        public static object GetDataEx(this IDataObject dataObject, string format)
        {
            // Get the data
            object data = dataObject.GetData(format, true);

            // If the data is a stream, we'll check to see if it
            // is stamped by us for custom marshaling
            if (data is Stream)
            {
                object data2 = ComDataObjectExtensions.GetManagedData((ComIDataObject)dataObject, format);
                if (data2 != null)
                {
                    return(data2);
                }
            }

            return(data);
        }
Esempio n. 26
0
        public static string GetTextPath()
        {
            System.Windows.IDataObject data = Clipboard.GetDataObject();

            string ClipboardText = "";

            if (data.GetDataPresent(DataFormats.Text))
            {
                ClipboardText = (string)data.GetData(DataFormats.Text);
                // クリップボードのテキストを改行毎に配列に設定
                string[] ClipBoardList = ClipboardText.Split('\n');

                foreach (string file in ClipBoardList)
                {
                    FileInfo      fileinfo = new FileInfo(file);
                    DirectoryInfo dirinfo  = new DirectoryInfo(file);

                    if (fileinfo.Exists || dirinfo.Exists)
                    {
                        ClipboardText = fileinfo.FullName;
                        break;
                    }
                }
            }

            if (data.GetDataPresent(DataFormats.FileDrop))
            {
                foreach (string file in (string[])data.GetData(DataFormats.FileDrop))
                {
                    FileInfo      fileinfo = new FileInfo(file);
                    DirectoryInfo dirinfo  = new DirectoryInfo(file);

                    if (fileinfo.Exists || dirinfo.Exists)
                    {
                        ClipboardText = fileinfo.FullName;
                        break;
                    }
                }
            }

            return(ClipboardText);
        }
Esempio n. 27
0
        /// <summary>
        /// Sets the drop description for the drag image manager.
        /// </summary>
        /// <param name="dataObject">The DataObject to set.</param>
        /// <param name="type">The type of the drop image.</param>
        /// <param name="format">The format string for the description.</param>
        /// <param name="insert">The parameter for the drop description.</param>
        /// <remarks>
        /// When setting the drop description, the text can be set in two part,
        /// which will be rendered slightly differently to distinguish the description
        /// from the subject. For example, the format can be set as "Move to %1" and
        /// the insert as "Temp". When rendered, the "%1" in format will be replaced
        /// with "Temp", but "Temp" will be rendered slightly different from "Move to ".
        /// </remarks>
        public static void SetDropDescription(this IDataObject dataObject, DropImageType type, string format, string insert)
        {
            if (format != null && format.Length > 259)
            {
                throw new ArgumentException("Format string exceeds the maximum allowed length of 259.", "format");
            }
            if (insert != null && insert.Length > 259)
            {
                throw new ArgumentException("Insert string exceeds the maximum allowed length of 259.", "insert");
            }

            // Fill the structure
            DropDescription dd;

            dd.type      = (int)type;
            dd.szMessage = format;
            dd.szInsert  = insert;

            ComDataObjectExtensions.SetDropDescription((ComIDataObject)dataObject, dd);
        }
Esempio n. 28
0
        /// <summary>
        /// Sets the drag image by rendering the specified UIElement.
        /// </summary>
        /// <param name="dataObject">The DataObject to set the drag image for.</param>
        /// <param name="element">The element to render as the drag image.</param>
        /// <param name="cursorOffset">The offset of the cursor relative to the UIElement.</param>
        public static void SetDragImage(this IDataObject dataObject, UIElement element, Point cursorOffset)
        {
            // Get the device's DPI so we render at full size
            double dpiX, dpiY;

            GetDeviceDpi(element, out dpiX, out dpiY);

            // Create our renderer at full size
            var bounds = VisualTreeHelper.GetDescendantBounds(element);
            var rtb    = new RenderTargetBitmap((int)Math.Ceiling(bounds.Width * dpiX / 96.0), (int)Math.Ceiling(bounds.Height * dpiY / 96.0),
                                                dpiX, dpiY, PixelFormats.Pbgra32);

            // Render the element
            var dv = new DrawingVisual();

            using (var ctx = dv.RenderOpen()) ctx.DrawRectangle(new VisualBrush(element), null, new Rect(new Point(), bounds.Size));
            rtb.Render(dv);

            // Set the drag image by the bitmap source
            SetDragImage(dataObject, rtb, cursorOffset);
        }
        /// <summary>
        /// Initialize a new instance of the <see cref="FormatEnumerator"/> class.
        /// </summary>
        /// <param name="dataObject">The <see cref="System.Windows.IDataObject"/></param>
        internal FormatEnumerator(System.Windows.IDataObject dataObject)
        {
            var formats = dataObject.GetFormats();

            _formats = new FORMATETC[formats == null ? 0 : formats.Length];

            if (formats != null)
            {
                for (var i = 0; i < formats.Length; i++)
                {
                    var format = formats[i];
                    var temp   = new FORMATETC();
                    temp.cfFormat = (short)DataFormats.GetDataFormat(format).Id;
                    temp.dwAspect = DVASPECT.DVASPECT_CONTENT;
                    temp.ptd      = IntPtr.Zero;
                    temp.lindex   = -1;
                    temp.tymed    = TYMED.TYMED_HGLOBAL;

                    _formats[i] = temp;
                }
            }
        }
Esempio n. 30
0
        public static string GetText()
        {
            System.Windows.IDataObject data = Clipboard.GetDataObject();

            string ClipboardText = "";

            if (data.GetDataPresent(DataFormats.Text))
            {
                ClipboardText = (string)data.GetData(DataFormats.Text);
                // クリップボードのテキストを改行毎に配列に設定
                string[] ClipBoardList = ClipboardText.Split('\n');

                ClipboardText = string.Join(" ", ClipBoardList);

                /*
                 * foreach (string text in ClipBoardList)
                 * {
                 *  if (text.Trim().Length > 0)
                 *      ClipboardText = text;
                 * }
                 */
            }
            if (data.GetDataPresent(DataFormats.FileDrop))
            {
                foreach (string file in (string[])data.GetData(DataFormats.FileDrop))
                {
                    FileInfo      fileinfo = new FileInfo(file);
                    DirectoryInfo dirinfo  = new DirectoryInfo(file);

                    if (fileinfo.Exists || dirinfo.Exists)
                    {
                        ClipboardText = fileinfo.Name;
                        break;
                    }
                }
            }

            return(ClipboardText);
        }
Esempio n. 31
0
 void pnlResult_ItemDropEvent(Result result, IDataObject dropDataObject, DragEventArgs args)
 {
     PluginPair pluginPair = PluginManager.AllPlugins.FirstOrDefault(o => o.Metadata.ID == result.PluginID);
     if (ResultItemDropEvent != null && pluginPair != null)
     {
         foreach (var delegateHandler in ResultItemDropEvent.GetInvocationList())
         {
             if (delegateHandler.Target == pluginPair.Plugin)
             {
                 delegateHandler.DynamicInvoke(result, dropDataObject, args);
             }
         }
     }
 }
Esempio n. 32
0
 public DragSourceEntry(System.Windows.IDataObject data)
 {
     this.Data = data;
 }
Esempio n. 33
0
 public AdviseSink(System.Windows.IDataObject data)
 {
     this.data = data;
 }