Exemple #1
0
        protected override void OnMouseLeave(MouseEventArgs e)
        {
            base.OnMouseLeave(e);

            if (!IsVisible)
            {
                return;
            }
            //
            // HACK: Use DragMoving and DragMoved events to inform an InfoCard that it
            //       is being dragged.
            //
            var infoCardWindow = InfoCardHost.GetInfoCardWindow(this);

            if (infoCardWindow != null && infoCardWindow == Mouse.Captured)
            {
                return;
            }

            if (IsPinned)
            {
                _fader.StartFade(this);
            }
            else if (!IsKeyboardFocusWithin)
            {
                Close();
            }
        }
Exemple #2
0
 private static bool IsOnInfoCard(DependencyObject obj)
 {
     if (obj != null)
     {
         var infoCard = obj.FindVisualAncestorByType <InfoCardWindow>();
         if (infoCard == null)
         {
             return(false);
         }
         return(infoCard == InfoCardHost.GetInfoCardWindow(Current._currentInfoCard));
     }
     return(false);
 }
Exemple #3
0
        private static void OnInfoCardPinned(object sender, RoutedEventArgs e)
        {
            var infoCard = (InfoCard)sender;

            if (infoCard == null)
            {
                return;
            }

            var window = InfoCardHost.GetInfoCardWindow(infoCard) as InfoCardWindow;

            if (window == null)
            {
                return;
            }
            window.ShowInTaskbar = true;
            window.Topmost       = true;
        }
Exemple #4
0
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);

            if (e.Handled)
            {
                return;
            }

            var window = InfoCardHost.GetInfoCardWindow(this);

            if (window != null)
            {
                window.Activate();
                window.DragMove();
                e.Handled = true;
            }
        }
Exemple #5
0
        private void RaiseInfoCardOpeningEvent()
        {
            ResetInfoCardTimer();

            var lastMouseOver = LastMouseOverWithInfoCard;

            if (lastMouseOver != null)
            {
                var showInfoCard = true;
                var inputElement = lastMouseOver as IInputElement;
                if (inputElement != null)
                {
                    // Raise the screen tip opening event
                    var e = new RoutedEventArgs(InfoCardOpeningEvent, this);
                    inputElement.RaiseEvent(e);
                    showInfoCard = !e.Handled;
                }
                if (showInfoCard)
                {
                    if ((_currentInfoCard != null) && !_currentInfoCard.IsOpen)
                    {
                        RetireInfoCard(_currentInfoCard);
                    }

                    _currentInfoCard = CreateInfoCard(lastMouseOver);

                    if (_currentInfoCard != null)
                    {
                        var targetElement = lastMouseOver as UIElement;

                        _currentInfoCard.TargetElement = targetElement;

                        var infoCardPosition = Mouse.GetPosition(inputElement);
                        var infoCardSite     = _currentInfoCard.RegisteredInfoCardSite ??
                                               lastMouseOver.FindVisualAncestorByType <InfoCardSite>();

                        if (infoCardSite == null)
                        {
                            var window = Window.GetWindow(lastMouseOver);
                            if (window != null)
                            {
                                if (!_generatedSites.TryGetValue(window, out infoCardSite))
                                {
                                    infoCardSite            = new InfoCardSite();
                                    _generatedSites[window] = infoCardSite;
                                }
                            }
                            else
                            {
                                RetireInfoCard(_currentInfoCard);
                                _currentInfoCard = null;
                                return;
                            }
                        }

                        if (!_currentInfoCard.IsOpen)
                        {
                            if (!infoCardSite.InfoCards.Contains(_currentInfoCard))
                            {
                                SetUnregisterInfoCardOnClose(_currentInfoCard, true);
                                infoCardSite.InfoCards.Add(_currentInfoCard);
                            }
                        }

                        if (infoCardSite.IsLoaded)
                        {
                            var targetVisual = targetElement;
                            if (targetVisual != null)
                            {
                                var transformToVisual = targetVisual.TransformToVisual(infoCardSite);
                                if (transformToVisual != null)
                                {
                                    infoCardPosition = transformToVisual.Transform(infoCardPosition);
                                }
                            }
                        }

                        if (targetElement != null)
                        {
                            var customPlacementCallback = _currentInfoCard.CustomPlacementCallback ??
                                                          GetCustomInfoCardPlacementCallback(targetElement);
                            if (customPlacementCallback != null)
                            {
                                _currentInfoCard.UpdateLayout();
                                infoCardPosition = customPlacementCallback(
                                    _currentInfoCard.RenderSize,
                                    targetElement,
                                    infoCardPosition);
                            }
                        }

                        _currentInfoCard.Location = new Point(
                            DoubleUtil.DoubleToInt(infoCardPosition.X),
                            DoubleUtil.DoubleToInt(infoCardPosition.Y));

                        if (_currentInfoCard.IsOpen)
                        {
                            var infoCardWindow = InfoCardHost.GetInfoCardWindow(_currentInfoCard);
                            if (infoCardWindow != null)
                            {
                                infoCardWindow.Setup(_currentInfoCard.Location);
                                infoCardWindow.Activate();
                            }
                            return;
                        }

                        _currentInfoCard.Open();
                    }
                }
            }
        }