Esempio n. 1
0
        private async void Clipboard_ContentChanged(object sender, object e)
        {
            //handle clipboard data
            ClipboardSnapshot snapshot = ClipboardSnapshot.CreateSnapshot();
            if (snapshot.ContainsData)
            {

                var factory = (ClipboardItemFactory)null;
                IEnumerable<string> priorities = snapshot.FormatPriorities;
                foreach (string format in priorities)
                {

                    if (format == StandardDataFormats.Bitmap)
                    {

                        //images
                        factory = new ClipboardImageFactory(snapshot);
                        break;

                    }
                    else if (format == StandardDataFormats.Text || format == StandardDataFormats.Uri || format == StandardDataFormats.Rtf || format == StandardDataFormats.Html)
                    {

                        //text
                        factory = new ClipboardTextFactory(snapshot);
                        break;

                    }
                    else if (format == StandardDataFormats.StorageItems)
                    {

                        //files
                        factory = new ClipboardFileFactory(snapshot);
                        break;

                    }
                }

                if (factory == null)
                {
                    factory = new ClipboardCustomDataFactory(snapshot);
                }

                ClipboardItem clipboardItem = await factory.CreateNewClipboardItem();
                _clipboardItems.Insert(0, clipboardItem);

                ClipboardDataAdded(clipboardItem);

                if (SettingsHelper.GetSetting("UseIncineration", "1") == "1")
                {
                    App.Incinerate();
                }
            }
        }
        private IntPtr OnWindowMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            try
            {
                if (msg == WM_CLIPBOARDUPDATE)
                {

                    var sequenceNumber = GetClipboardSequenceNumber();
                    if (IsReadyForSnapshotActions && sequenceNumber != _lastSequenceNumber && !IgnoreClipboardActivity)
                    {
                        _lastSequenceNumber = sequenceNumber;

                        IgnoreClipboardActivity = true;

                        //handle clipboard data
                        ClipboardSnapshot snapshot = ClipboardSnapshot.CreateSnapshot(hwnd);
                        if (snapshot.ContainsData &&
                            hwnd != snapshot.OutsideClipboardOwnerHandle)
                        {
                            Trace.WriteLine("A snapshot with data was discovered from source [" +
                                            snapshot.OutsideClipboardOwnerHandle + "]");

                            var factory = (ClipboardItemFactory) null;
                            IEnumerable<uint> priorities = snapshot.FormatPriorities;
                            foreach (uint format in priorities)
                            {
                                if (format == KnownClipboardFormats.CF_DIB || format == KnownClipboardFormats.CF_DIBV5 ||
                                    format == KnownClipboardFormats.CF_DIF ||
                                    format == KnownClipboardFormats.CF_DSPBITMAP ||
                                    format == KnownClipboardFormats.CF_DSPMETAFILEPICT ||
                                    format == KnownClipboardFormats.CF_DSPENHMETAFILE ||
                                    format == KnownClipboardFormats.CF_ENHMETAFILE)
                                {
                                    Trace.WriteLine("The snapshot is an image snapshot");

                                    //images
                                    factory = new ClipboardImageFactory(snapshot);
                                    break;
                                }
                                else if (format == KnownClipboardFormats.CF_DSPTEXT ||
                                         format == KnownClipboardFormats.CF_UNICODETEXT)
                                {
                                    Trace.WriteLine("The snapshot is a text snapshot");

                                    //text
                                    factory = new ClipboardTextFactory(snapshot);
                                    break;
                                }
                                else if (format == KnownClipboardFormats.CF_HDROP)
                                {
                                    Trace.WriteLine("The snapshot is a file snapshot");

                                    //files
                                    factory = new ClipboardFileFactory(snapshot);
                                    break;
                                }
                            }

                            if (factory == null)
                            {
                                Trace.WriteLine("The snapshot is of no known format (custom data)");

                                factory = new ClipboardCustomDataFactory(snapshot);
                            }

                            ClipboardItem clipboardItem = factory.CreateNewClipboardItem(WindowHandle,
                                                                                         _clipboardItems.Take(100));
                            if (clipboardItem != null)
                            {

                                if (_clipboardItems.Contains(clipboardItem))
                                {
                                    SwapClipboardItemPositions(_clipboardItems.IndexOf(clipboardItem), 0);
                                }
                                else
                                {
                                    _clipboardItems.Insert(0, clipboardItem);
                                    if (ClipboardDataAdded != null)
                                    {
                                        ClipboardDataAdded(clipboardItem);
                                    }

                                    switch (_clipboardItems.Count)
                                    {
                                        case 1:
                                            NotificationHelper.ShowInstructions(
                                                "You have 1 item in your clipboard now. Try copying just one more.");
                                            break;

                                        case 2:
                                            string mode = SettingsHelper.GetSetting("ManagementMode", "Mixed");
                                            if (mode == "Integrated")
                                            {
                                                NotificationHelper.ShowInstructions(
                                                    "Nicely done! Now try holding down CTRL + V (it's important that you hold it down).");
                                            }
                                            else if (mode == "External")
                                            {
                                                NotificationHelper.ShowInstructions(
                                                    "Nicely done! Now note the Shapeshifter windows on your taskbar. They represent the clipboard data.");
                                            }
                                            else if (mode == "Mixed")
                                            {
                                                NotificationHelper.ShowInstructions(
                                                    "Nicely done! Now try holding down CTRL + V (it's important that you hold it down), or clicking the Shapeshifter icon on your taskbar.");
                                            }
                                            break;
                                    }
                                }

                                if (SettingsHelper.GetSetting("UseIncineration", "1") == "1")
                                {
                                    App.Incinerate();
                                }
                            }

                        }

                        IgnoreClipboardActivity = false;

                    }
                }
                else if (msg == WM_DWMCOLORIZATIONCOLORCHANGED)
                {
                    if (AeroColorChanged != null)
                    {
                        AeroColorChanged(wParam.ToInt64());
                    }
                }
            }
            catch (NullReferenceException ex)
            {
                if(Debugger.IsAttached)
                {
                    Debugger.Break();
                }
                //caught due to a bug in .NET under Windows 7 when closing the application from tray icon
            }

            return IntPtr.Zero;
        }