Esempio n. 1
0
        public bool Compare(ClipboardVM vm)
        {
            if (vm == null)
            {
                return false;
            }

            if (this.Type != vm.Type)
            {
                return false;
            }

            if (this.TxtContent != vm.TxtContent)
            {
                return false;
            }

            if (vm.Type == ClipboardDataType.File)
            {
                return _fileDropList.SequenceEqual(vm._fileDropList);
            }

            if (vm.Type == ClipboardDataType.Bitmap)
            {
                byte[] x = ClipboardVM.ToByteArray(vm.ImgSource);
                byte[] y = ClipboardVM.ToByteArray(this.ImgSource);
                return x.SequenceEqual(y);
            }

            return true;
        }
Esempio n. 2
0
        public ClipboardVM(IDataObject dataObject)
        {
            _dict = new Dictionary<String, Object>();
            _fileDropList = new List<String>();

            foreach (string format in dataObject.GetFormats())
            {
                if (format == DataFormats.EnhancedMetafile)
                {
                    continue;
                }

                _dict.Add(format, dataObject.GetData(format));
                Debug.WriteLine(String.Format("{0}, {1}", format, dataObject.GetData(format)));
            }

            _dataObjectCount = _dict.Count;
            this.Type = ClipboardDataType.Unknown;

            if (_dict.ContainsKey(ClipboardVM.TYPE_RICHTEXT))
            {
                this.Type = ClipboardVM.GetDataType(ClipboardVM.TYPE_RICHTEXT);
                this.TxtContent = _dict[ClipboardVM.TYPE_RICHTEXT].ToString();
            }

            if (_dict.ContainsKey(ClipboardVM.TYPE_OEMTEXT)
                || _dict.ContainsKey(ClipboardVM.TYPE_TEXT)
                || _dict.ContainsKey(ClipboardVM.TYPE_UNICODETEXT)
                || _dict.ContainsKey(ClipboardVM.TYPE_SYSTEM_STRING)
                || _dict.ContainsKey(ClipboardVM.TYPE_CSV))
            {
                this.Type = ClipboardVM.GetDataType(ClipboardVM.TYPE_SYSTEM_STRING);
                this.TxtContent = _dict[ClipboardVM.TYPE_SYSTEM_STRING].ToString();
            }

            if (_dict.ContainsKey(ClipboardVM.TYPE_FILE_DROP)
                || _dict.ContainsKey(ClipboardVM.TYPE_FILE_NAME)
                || _dict.ContainsKey(ClipboardVM.TYPE_FILE_NAME_W))
            {
                String[] paths = _dict[ClipboardVM.TYPE_FILE_NAME_W] as String[];
                if (paths != null)
                {
                    this.Name = ClipboardVM.TYPE_FILE_NAME;
                    this.Type = ClipboardVM.GetDataType(ClipboardVM.TYPE_FILE_NAME_W);
                    this.TxtContent = paths.ElementAtOrDefault(0);
                    _fileDropList.Clear();
                    foreach (String f in paths)
                    {
                        _fileDropList.Add(f);
                    }
                }
            }
            
            if (_dict.ContainsKey(ClipboardVM.TYPE_DRAWING_BITMAP)
                || _dict.ContainsKey(ClipboardVM.TYPE_BITMAP)
                || _dict.ContainsKey(ClipboardVM.TYPE_DEV_INDP_BITMAP)
                || _dict.ContainsKey(ClipboardVM.TYPE_FORMAT17))
            {
                this.Name = ClipboardVM.TYPE_BITMAP;
                this.Type = ClipboardVM.GetDataType(ClipboardVM.TYPE_BITMAP);
                
                if (dataObject.GetDataPresent(DataFormats.Bitmap))
                {
                    Bitmap bitmap = (Bitmap)dataObject.GetData(DataFormats.Bitmap);
                    IntPtr hBitmap = bitmap.GetHbitmap();
                    try
                    {
                        this.ImgSource= System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero,System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    }
                    finally
                    {
                        Win32Helper.DeleteObject(hBitmap);
                    }
                }
            }

        }