Ejemplo n.º 1
0
        protected override void OnClosed(RoutedEventArgs e)
        {
            if (_popupSiteWindow != null)
            {
                _popupSiteWindow.PreviewMouseDown -= OnPopupSitePreviewMouseDown;
                _popupSiteWindow = null;
            }

            Visibility = Visibility.Collapsed;

            var popupSite = InfoCardSite;

            if (popupSite != null)
            {
                popupSite.RemoveCanvasChild(this);
            }

            InfoCardHost = null;

            base.OnClosed(e);

            var handler = PopupWindowClosedEvent;

            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }

            _isClosing = false;
        }
Ejemplo n.º 2
0
        internal void OpenInfoCardCore(InfoCard infoCard)
        {
            IInfoCardWindow infoCardWindow;

            var infoCardHost = InfoCardHost.GetInfoCardHost(infoCard);

            if ((infoCardHost != null) && infoCardHost.IsVisible)
            {
                infoCardWindow = infoCardHost.InfoCardWindow;
                if (infoCardWindow != null)
                {
                    return;
                }
            }

            if (infoCardHost == null)
            {
                infoCardHost          = CreateInfoCardHost();
                infoCardHost.Location = infoCard.Location;
            }

            infoCardHost.Content = infoCard;

            infoCardWindow = CreateRaftingWindow(infoCardHost);
            infoCardWindow.SnapToScreen();

            infoCardWindow.Show();
            infoCardWindow.Activate();
        }
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
0
 protected internal virtual IInfoCardWindow CreateRaftingWindow(InfoCardHost infoCardHost)
 {
     if (UseHostedInfoCardWindows)
     {
         return(new InfoCardWindowControl(infoCardHost));
     }
     return(CreateRaftingWindowForWindows(infoCardHost));
 }
Ejemplo n.º 5
0
 protected static void SetInfoCardHost(DependencyObject d, InfoCardHost value)
 {
     if (d == null)
     {
         throw new ArgumentNullException("d");
     }
     d.SetValue(InfoCardHostPropertyKey, value);
 }
Ejemplo n.º 6
0
        private void CloseInfoCardWindowIfEmpty(InfoCardHost container)
        {
            var window = container.InfoCardWindow;

            if (!HasVisualContent(container) && (window != null) && (!window.IsClosing))
            {
                window.Close(InfoCardCloseReason.InfoCardWindowClosed);
            }
        }
Ejemplo n.º 7
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);
 }
Ejemplo n.º 8
0
        public InfoCardWindowControl(InfoCardHost container)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            InfoCardHost = container;

            InfoCardHost.SetInfoCardWindow(this, this);

            Setup(container.Location);
        }
Ejemplo n.º 9
0
        private IInfoCardWindow CreateRaftingWindowForWindows(InfoCardHost infoCardHost)
        {
            var window = new InfoCardWindow(infoCardHost);

            window.SetBinding(
                CanInfoCardsPinProperty,
                InfoCardHelper.CreateBinding(this, CanInfoCardsPinProperty));

            window.SetBinding(
                DataContextProperty,
                InfoCardHelper.CreateBinding(this, DataContextProperty));

            return(window);
        }
Ejemplo n.º 10
0
        internal void Subscribe(DependencyObject o)
        {
            if (o == null)
            {
                return;
            }

            var infoCardHost = InfoCardHost.GetInfoCardHost(o);

            if (infoCardHost != null)
            {
                _popupHosts[infoCardHost.UniqueId] = infoCardHost;
            }
        }
Ejemplo n.º 11
0
        private static void OnLocationPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var newValue = (Point?)e.NewValue;

            if (!newValue.HasValue)
            {
                return;
            }

            var infoCardHost = InfoCardHost.GetInfoCardHost(d);

            if (infoCardHost != null)
            {
                infoCardHost.Location = newValue;
            }
        }
Ejemplo n.º 12
0
        internal bool Close(InfoCard infoCard, InfoCardCloseReason closeReason, bool force)
        {
            if ((infoCard == null) || (!infoCard.IsOpen))
            {
                return(false);
            }

            // Raise closing event
            var closingEventArgs = new InfoCardEventArgs(infoCard, InfoCardClosingEvent, this);

            RaiseEvent(closingEventArgs);
            infoCard.RaiseClosingEvent();

            if (!force && closingEventArgs.Cancel)
            {
                return(false);
            }

            var notifier = new EventNotifier();

            notifier.Subscribe(infoCard);

            infoCard.Measure(new Size(0, 0));
            infoCard.ClearValue(Expander.IsExpandedProperty);
            infoCard.ClearValue(InfoCard.IsPinnedProperty);

            var infoCardHost = InfoCardHost.GetInfoCardHost(infoCard);

            if (infoCardHost != null)
            {
                infoCardHost.Content = null;
            }

            notifier.RaiseEvents();

            if (InfoCardService.GetUnregisterInfoCardOnClose(infoCard))
            {
                InfoCards.Remove(infoCard);
            }

            RaiseEvent(new InfoCardEventArgs(infoCard, InfoCardClosedEvent, this));
            infoCard.RaiseClosedEvent();

            infoCard.LastCloseReason = closeReason;

            return(true);
        }
Ejemplo n.º 13
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;
            }
        }
Ejemplo n.º 14
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;
        }
Ejemplo n.º 15
0
        public InfoCardWindow(InfoCardHost container)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            InfoCardHost.SetInfoCardWindow(this, this);

            WindowStyle        = WindowStyle.None;
            ResizeMode         = ResizeMode.NoResize;
            AllowsTransparency = true;
            Background         = Brushes.Transparent;
            Width         = 0;
            Height        = 0;
            SizeToContent = SizeToContent.WidthAndHeight;

            InfoCardHost = container;

            var ownerWindow = GetWindow(InfoCardSite);

            if (ownerWindow != null)
            {
                Owner = ownerWindow;
            }

            var infoCard = (InfoCard)container.Content;
            var location = container.Location ?? new Point(0, 0);

            _transformToDevice = Matrix.Identity;

            var targetWindow = GetWindow(infoCard.TargetElement);

            if (targetWindow != null)
            {
                _transformToDevice.OffsetX = targetWindow.Left;
                _transformToDevice.OffsetY = targetWindow.Top;
                location = _transformToDevice.Transform(location);
            }

            Setup(location);

            Loaded += OnLoaded;
        }
Ejemplo n.º 16
0
        protected override void OnClosed(EventArgs e)
        {
            var popupSite = InfoCardSite;

            if (popupSite != null)
            {
                var window = GetWindow(popupSite);
                if ((window != null) && !window.IsActive)
                {
                    window.Activate();
                }
            }

            InfoCardHost = null;

            base.OnClosed(e);

            BindingOperations.ClearAllBindings(this);

            IsClosing = false;
        }
Ejemplo n.º 17
0
 internal InfoCard GetInfoCardFromHost(InfoCardHost host)
 {
     return(host.Content as InfoCard);
 }
Ejemplo n.º 18
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();
                    }
                }
            }
        }
Ejemplo n.º 19
0
 internal bool HasVisualContent(InfoCardHost infoCardHost)
 {
     return(GetInfoCardFromHost(infoCardHost) != null);
 }