Ejemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();
            HostedWindow        = null;
            MagicArrow          = new MagicArrow.MagicArrow();
            MagicArrow.MoveOut += (s, e) =>
            {
                HideEqualizer();
                HostedWindow.DisableWindow();
            };
            MagicArrow.MoveIn       += (s, e) => { HostedWindow.EnableWindow(); };
            MagicArrow.FilesDropped +=
                (s, e) => { MainViewModel.Instance.DragDropFiles((string[])e.Data.GetData(DataFormats.FileDrop)); };
            MagicArrow.Register(this);

            Closing      += MainWindow_Closing;
            Loaded       += MainWindow_Loaded;
            StateChanged += MainWindow_StateChanged;

            MagicArrow.DockManager.Docked      += (s, e) => { ApplyHostWindow(SmartWindowSkin); };
            MagicArrow.DockManager.Undocked    += (s, e) => { ApplyHostWindow(AdvancedWindowSkin); };
            MagicArrow.DockManager.DragStopped += DockManagerOnDragStopped;

            var appsettings = AnyListenSettings.Instance.CurrentState;

            if (appsettings.ApplicationState == null)
            {
                WindowStartupLocation        = WindowStartupLocation.CenterScreen;
                appsettings.ApplicationState = new DockingApplicationState
                {
                    CurrentSide = DockingSide.None,
                    Height      = 600,
                    Width       = 1000,
                    Left        = Left,
                    Top         = Top
                };
            }

            if (appsettings.ApplicationState.CurrentSide == DockingSide.None)
            {
                if (appsettings.ApplicationState.Left < WpfScreen.MostRightX)
                //To prevent that the window is out of view when the user unplugs a monitor
                {
                    Height      = appsettings.ApplicationState.Height;
                    Width       = appsettings.ApplicationState.Width;
                    Left        = appsettings.ApplicationState.Left;
                    Top         = appsettings.ApplicationState.Top;
                    WindowState = appsettings.ApplicationState.WindowState;
                }
                else
                {
                    WindowStartupLocation = WindowStartupLocation.CenterScreen;
                }
            }

            MagicArrow.DockManager.CurrentSide = appsettings.ApplicationState.CurrentSide;
            WindowDialogService            = new WindowDialogService(this);
            SystemEvents.PowerModeChanged += SystemEventsOnPowerModeChanged;
        }
Ejemplo n.º 2
0
        protected void ApplyHostWindow(IWindowSkin skin, bool saveinformation = true)
        {
            if (skin == HostedWindow) return;
            if (HostedWindow != null)
            {
                HostedWindow.DragMoveStart -= skin_DragMoveStart;
                HostedWindow.DragMoveStop -= skin_DragMoveStop;
                HostedWindow.ToggleWindowState -= skin_ToggleWindowState;
                HostedWindow.TitleBarMouseMove -= skin_TitleBarMouseMove;
                HostedWindow.DisableWindow();

                var element = (FrameworkElement) HostedWindow;
                ContentGrid.Children.Remove(element);
            }

            skin.CloseRequest += (s, e) => Close();
            skin.DragMoveStart += skin_DragMoveStart;
            skin.DragMoveStop += skin_DragMoveStop;
            skin.ToggleWindowState += skin_ToggleWindowState;
            skin.TitleBarMouseMove += skin_TitleBarMouseMove;

            var appstate = AnyListenSettings.Instance.CurrentState.ApplicationState;
            if (skin != AdvancedWindowSkin && saveinformation)
            {
                appstate.Height = Height;
                appstate.Width = Width;
            }

            HideEqualizer();

            MaxHeight = skin.Configuration.MaxHeight;
            MinHeight = skin.Configuration.MinHeight;
            MaxWidth = skin.Configuration.MaxWidth;
            MinWidth = skin.Configuration.MinWidth;
            ShowTitleBar = skin.Configuration.ShowTitleBar;
            ShowSystemMenuOnRightClick = skin.Configuration.ShowSystemMenuOnRightClick;

            if (!_isDragging)
            {
                if (skin.Configuration.IsResizable)
                {
                    WindowHelper.ShowMinimizeAndMaximizeButtons(this);
                    ResizeMode = ResizeMode.CanResize;
                }
                else
                {
                    WindowHelper.HideMinimizeAndMaximizeButtons(this);
                    ResizeMode = ResizeMode.NoResize;
                }
            }

            if (skin == AdvancedWindowSkin && saveinformation)
            {
                Width = appstate.Width;
                Height = appstate.Height;
            }

            if (skin.Configuration.SupportsCustomBackground)
            {
                SetBackground().Forget();
            }
            else
            {
                BackgroundImage.Visibility = Visibility.Collapsed;
                BackgroundImage.Source = null;
                BackgroundMediaElement.Stop();
                BackgroundMediaElement.Source = null;
                BackgroundMediaElement.Visibility = Visibility.Collapsed;
            }
            BackgroundImage.Visibility = skin.Configuration.SupportsCustomBackground ? Visibility.Visible : Visibility.Collapsed;

            if (skin == SmartWindowSkin)
            {
                Width = 300;
                Height = MagicArrow.DockManager.WindowHeight;
                if (MainViewModel.Instance.MusicManager != null)
                    MainViewModel.Instance.MusicManager.DownloadManager.IsOpen = false;
            }

            ShowMinButton = skin.Configuration.ShowWindowControls;
            ShowMaxRestoreButton = skin.Configuration.ShowWindowControls;
            ShowCloseButton = skin.Configuration.ShowWindowControls;

            var newUserControl = (FrameworkElement) skin;
            ContentGrid.Children.Add(newUserControl);
            var animation = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200));
            newUserControl.BeginAnimation(OpacityProperty, animation);
            HostedWindow = skin;
            HostedWindow.EnableWindow();
        }
Ejemplo n.º 3
0
        protected void ApplyHostWindow(IWindowSkin skin, bool saveinformation = true)
        {
            if (skin == HostedWindow) return;
            if (HostedWindow != null)
            {
                HostedWindow.DragMoveStart -= skin_DragMoveStart;
                HostedWindow.DragMoveStop -= skin_DragMoveStop;
                HostedWindow.ToggleWindowState -= skin_ToggleWindowState;
                HostedWindow.TitleBarMouseMove -= skin_TitleBarMouseMove;
                HostedWindow.DisableWindow();

                var element = (FrameworkElement) HostedWindow;
                ContentGrid.Children.Remove(element);
            }

            skin.CloseRequest += (s, e) => Close();
            skin.DragMoveStart += skin_DragMoveStart;
            skin.DragMoveStop += skin_DragMoveStop;
            skin.ToggleWindowState += skin_ToggleWindowState;
            skin.TitleBarMouseMove += skin_TitleBarMouseMove;

            var appstate = HurricaneSettings.Instance.CurrentState.ApplicationState;
            if (skin != AdvancedWindowSkin && saveinformation)
            {
                appstate.Height = Height;
                appstate.Width = Width;
            }

            HideEqualizer();

            MaxHeight = skin.Configuration.MaxHeight;
            MinHeight = skin.Configuration.MinHeight;
            MaxWidth = skin.Configuration.MaxWidth;
            MinWidth = skin.Configuration.MinWidth;
            ShowTitleBar = skin.Configuration.ShowTitleBar;
            ShowSystemMenuOnRightClick = skin.Configuration.ShowSystemMenuOnRightClick;

            if (!_isDragging)
            {
                if (skin.Configuration.IsResizable)
                {
                    SetResizeMode(ResizeMode.CanResize);
                }
                else
                {
                    SetResizeMode(ResizeMode.NoResize);
                }
            }

            if (skin == AdvancedWindowSkin && saveinformation)
            {
                Width = appstate.Width;
                Height = appstate.Height;
            }

            if (skin.Configuration.SupportsCustomBackground)
            {
                SetBackground().Forget();
            }
            else
            {
                BackgroundImage.Visibility = Visibility.Collapsed;
                BackgroundImage.Source = null;
                BackgroundMediaElement.Stop();
                BackgroundMediaElement.Source = null;
                BackgroundMediaElement.Visibility = Visibility.Collapsed;
            }
            BackgroundImage.Visibility = skin.Configuration.SupportsCustomBackground ? Visibility.Visible : Visibility.Collapsed;

            if (skin == SmartWindowSkin)
            {
                Width = 300;
                Height = MagicArrow.DockManager.WindowHeight;
                if (MainViewModel.Instance.MusicManager != null)
                    MainViewModel.Instance.MusicManager.DownloadManager.IsOpen = false;
            }

            ShowMinButton = skin.Configuration.ShowWindowControls;
            ShowMaxRestoreButton = skin.Configuration.ShowWindowControls;
            ShowCloseButton = skin.Configuration.ShowWindowControls;

            var newUserControl = (FrameworkElement) skin;
            ContentGrid.Children.Add(newUserControl);
            var animation = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200));
            newUserControl.BeginAnimation(OpacityProperty, animation);
            HostedWindow = skin;
            HostedWindow.EnableWindow();
        }