Ejemplo n.º 1
0
        public HooksModule(View chart, DrawingCanvas HooksLayer, DrawingCanvas HookPriceLayer, DrawingCanvas HookTimeLayer,
                           Func <Pen> GetCursorPen, CenterIndicatorManger CenterIndicatorManger, List <FrameworkElement> OtherLayers) : base(chart)
        {
            this.OtherLayers    = OtherLayers;
            this.HooksLayer     = HooksLayer;
            this.HookPriceLayer = HookPriceLayer;
            this.HookTimeLayer  = HookTimeLayer;
            this.GetCursorPen   = GetCursorPen;
            this.CIM            = CenterIndicatorManger;

            this.SetMenuAct = chart.Shell.SetMenu;

            Chart.VerticalСhanges   += () => Task.Run(() => ResizeHook?.Invoke());
            Chart.HorizontalСhanges += () => Task.Run(() => ResizeHook?.Invoke());

            Chart.ChartGrid.MouseEnter += (s, e) => Chart.Interaction = MoveHook;
            Chart.ChartGrid.MouseLeave += (s, e) => { if (Chart.Interaction == MoveHook)
                                                      {
                                                          Chart.Interaction = null;
                                                      }
            };
            Chart.HookElement              = HookElement;
            Chart.Shell.RemoveHooks       += () => Task.Run(() => RemoveHook?.Invoke());
            Chart.Shell.ToggleInteraction += b =>
            {
                if (b)
                {
                    RemoveHook = null;
                }
                else
                {
                    Task.Run(() =>
                    {
                        if (Manipulating)
                        {
                            Chart.Window.EndMoving(Dispatcher);
                        }

                        RemoveHook = RemoveLastHook;

                        Dispatcher.Invoke(() =>
                        {
                            foreach (var l in OtherLayers)
                            {
                                l.Visibility = Visibility.Visible;
                            }

                            ShadowVisual.RenderOpen().Close();
                            ShadowPriceVisual.RenderOpen().Close();
                            ShadowTimeVisual.RenderOpen().Close();
                            OverVisual.RenderOpen().Close();
                            OverPriceVisual.RenderOpen().Close();
                            OverTimeVisual.RenderOpen().Close();
                        });
                    });
                }
            };

            HooksLayer.AddVisual(ShadowVisual);
            HooksLayer.AddVisual(OverVisual);
            HooksLayer.AddVisual(PointVisual);
            HookPriceLayer.AddVisual(ShadowPriceVisual);
            HookPriceLayer.AddVisual(OverPriceVisual);
            HookTimeLayer.AddVisual(OverTimeVisual);
            HookTimeLayer.AddVisual(ShadowTimeVisual);
        }
Ejemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();
            // Set the viewmodel as this view isn't invoked by ReactiveUI
            ViewModel = new MainViewModel();

            this.OneWayBind(ViewModel, x => x.Title, x => x.Title);
            this.OneWayBind(ViewModel, x => x.Title, x => x.Tray.ToolTipText);

            // TaskbarIcon context menu bindings
            this.BindCommand(ViewModel, x => x.Profile, x => x.MenuProfile);
            this.BindCommand(ViewModel, x => x.Dashboard, x => x.MenuDash);
            this.BindCommand(ViewModel, x => x.Community, x => x.MenuForums);
            this.BindCommand(ViewModel, x => x.Exit, x => x.MenuExit);
            this.WhenAnyObservable(x => x.ViewModel.Exit).Subscribe(_ => Close());

            // Lowest level UserError handler, any UserError's thrown that aren't handled will hit this.
            UserError.RegisterHandler(error => {
                Tray.ShowBalloonTip("Error", error.ErrorMessage, BalloonIcon.Error);
                return(Observable.Return(RecoveryOptionResult.CancelOperation));
            });

            // Change the content in the ViewModelViewHost based on the `Content` property in the ViewModel
            this.WhenAnyValue(x => x.ViewModel.Content)
            .Where(x => x != null)
            .Subscribe(model => ContentView.ViewModel = model);

            // Sets the position of the window when the height changes.
            this.WhenAnyValue(x => x.Height)
            .Subscribe(_ => SetWindowLocation());

            // TaskbarIcon left-click handler
            // Will show the window, or do nothing, based on the `_shouldNotShow` property
            Observable.FromEventPattern <RoutedEventHandler, RoutedEventArgs>(
                h => Tray.TrayLeftMouseUp += h, h => Tray.TrayLeftMouseUp -= h)
            .Subscribe(_ => {
                if (!_shouldNotShow)
                {
                    SetWindowLocation();
                    Show();
                    Activate();
                }
                _shouldNotShow = false;
            });

            // TaskbarIcon right-click handler
            // Sets the `_shouldNotShow` property to false so that the window will show next left-click
            // Logic here:
            //  Right-click is outside the bounds of the window so the `Deactivated` event is fired
            //  `Deactivated` event will hide the window and set `_shouldNotShow` to true
            //  This event handler is hit and sets `_shouldNotShow` to false so the application works as expected.
            Observable.FromEventPattern <RoutedEventHandler, RoutedEventArgs>(
                h => Tray.TrayRightMouseDown += h, h => Tray.TrayRightMouseDown -= h)
            .Subscribe(_ => _shouldNotShow    = false);

            // Hides the window when the user clicks anywhere outside the Window
            // Sets the `_shouldNotShow` property based on whether the cursor is within the TaskbarIcon's rect.
            this.Events().Deactivated.Subscribe(_ => {
                _shouldNotShow = WindowPosition.IsCursorOverNotifyIcon(Tray) && WindowPosition.IsNotificationAreaActive;
                Hide();
            });

            this.Events().SourceInitialized.Subscribe(_ => {
                // The following code disables the ability to resize the window
                // while still retaining the chrome border
                var windowHandle = new WindowInteropHelper(this).Handle;
                var windowSource = HwndSource.FromHwnd(windowHandle);
                if (windowSource == null)
                {
                    return;
                }

                var resizeHook = new ResizeHook();
                windowSource.AddHook(resizeHook.WndProc);
            });
        }