Esempio n. 1
0
        public TaskbarGroupStackPanel()
        {
            InitializeComponent();
            ThumbPreviewWindow = new Window
            {
                Background         = new SolidColorBrush(Color.FromArgb(0xC0, 0xFF, 0xFF, 0xFF)),
                WindowStyle        = WindowStyle.None,
                AllowsTransparency = true,
                Width      = 400,
                Height     = 35,
                Visibility = Visibility.Hidden,
                Content    = new StackPanel
                {
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    VerticalAlignment   = VerticalAlignment.Top,
                    Orientation         = Orientation.Vertical,
                    Background          = new SolidColorBrush(Color.FromArgb(0x40, 0x0, 0x0, 0x0))
                },
                Topmost       = true,
                ShowActivated = false,
                ShowInTaskbar = false
            };


            ThumbPreviewWindow.MouseLeave += delegate
            {
                if (!IsMouseOver)
                {
                    HideThumbnailPreviewWindow();
                    (ThumbPreviewWindow.Content as StackPanel).Children.Clear();
                }
            };

            MouseLeave += delegate
            {
                if (ThumbPreviewWindow.Visibility == Visibility.Visible && !ThumbPreviewWindow.IsMouseOver)
                {
                    ThumbPreviewWindow.Hide();
                }
            };


            ThumbPreviewWindow.IsVisibleChanged += delegate
            {
                if (ThumbPreviewWindow.Visibility == Visibility.Visible)
                {
                    foreach (var b in ProgramWindowsList)
                    {
                        var windowEntry = new Button
                        {
                            Style   = (Style)Resources["ThumbPreviewButtonStyle"],
                            Content = new Grid
                            {
                                HorizontalAlignment = HorizontalAlignment.Stretch,
                                VerticalAlignment   = VerticalAlignment.Stretch,
                                Margin = new Thickness(6, 0, 0, 0)
                            },
                            Tag = b
                        };

                        var entryContent = windowEntry.Content as Grid;

                        try
                        {
                            entryContent.Children.Add(new Canvas
                            {
                                HorizontalAlignment = HorizontalAlignment.Left,
                                Width      = 16,
                                Height     = 16,
                                Background = new ImageBrush(b.Icon.ToBitmap().ToBitmapSource())
                            });
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex);
                        }
                        ;

                        entryContent.Children.Add(new Label
                        {
                            HorizontalAlignment = HorizontalAlignment.Left,
                            Content             = b.Name,
                            Margin     = new Thickness(16, 0, 0, 0),
                            Foreground = new SolidColorBrush(Colors.White)
                        });

                        var closeButton = new Button
                        {
                            Style = (Style)Resources["ThumbPreviewCloseButtonStyle"]
                        };
                        closeButton.Click += delegate
                        {
                            (windowEntry.Tag as ProgramWindow).Close();
                            (ThumbPreviewWindow.Content as StackPanel).Children.Remove(windowEntry);
                            foreach (Button g in Buttons.Children)
                            {
                                if ((g.Tag as ProgramWindow).Hwnd == (windowEntry.Tag as ProgramWindow).Hwnd)
                                {
                                    Buttons.Children.Remove(g);
                                    return;
                                }
                            }
                            foreach (var p in ProgramWindowsList)
                            {
                                if (p.Hwnd == (windowEntry.Tag as ProgramWindow).Hwnd)
                                {
                                    ProgramWindowsList.Remove(p);
                                    return;
                                }
                            }
                        };


                        entryContent.Children.Add(closeButton);

                        windowEntry.Click += delegate
                        {
                            (windowEntry.Tag as ProgramWindow).Show();

                            /*MiscTools.ShowWindow((WindowEntry.Tag as ProgramWindow).Hwnd, 10);
                             * MiscTools.SetForegroundWindow((WindowEntry.Tag as ProgramWindow).Hwnd);*/
                            ThumbPreviewWindow.Hide();
                        };

                        (ThumbPreviewWindow.Content as StackPanel).Children.Add(windowEntry);
                    }
                }
            };
            //RunningBackgroundButton.Click += delegate { ShowThumbnailPreviewWindow(); };

            var showThumbnailPreviewCounter = 0;

            var mouseGroupContactTimer = new Timer
            {
                Interval = 1
            };

            mouseGroupContactTimer.Elapsed += delegate
            {
                Dispatcher.Invoke(new Action(() =>
                {
                    if (Window.GetWindow(this) == null)
                    {
                        mouseGroupContactTimer.Stop();
                    }
                    else
                    {
                        /*try
                         * {*/
                        if (
                            (MainTools.GetDpiScaledCursorPosition().X > MainTools.GetDpiScaledGlobalControlPosition(this).X) &
                            (MainTools.GetDpiScaledCursorPosition().X < MainTools.GetDpiScaledGlobalControlPosition(this).X + ActualWidth) &
                            (MainTools.GetDpiScaledCursorPosition().Y > MainTools.GetDpiScaledGlobalControlPosition(this).Y) &
                            (MainTools.GetDpiScaledCursorPosition().Y < MainTools.GetDpiScaledGlobalControlPosition(this).Y + ActualHeight)
                            )
                        {
                            if (showThumbnailPreviewCounter < 50)
                            {
                                showThumbnailPreviewCounter = showThumbnailPreviewCounter + 1;
                            }
                            else
                            {
                                showThumbnailPreviewCounter = 0;
                                if ((ThumbPreviewWindow.Visibility == Visibility.Visible) & !ThumbPreviewWindow.IsMouseOver & !IsMouseOver)
                                {
                                    HideThumbnailPreviewWindow();
                                }
                                else
                                {
                                    ShowThumbnailPreviewWindow();
                                }
                            }
                        }

                        /*}
                         * catch
                         * {
                         *
                         * }*/
                    }
                }));
            };

            Loaded += delegate { mouseGroupContactTimer.Start(); };
        }