Exemplo n.º 1
0
 internal static bool TryGetParentExtensionWindow(FrameworkElement element, out ExtensionWindow window, out ExtensionSurface surface)
 {
     window  = null;
     surface = null;
     if (null != element)
     {
         FrameworkElement current = element;
         window = element.TemplatedParent as ExtensionWindow;
         while (null == window && null != current)
         {
             window  = current as ExtensionWindow;
             current = (FrameworkElement)current.Parent;
         }
         if (null != window)
         {
             current = window;
             surface = window.TemplatedParent as ExtensionSurface;
             while (null == surface && null != current)
             {
                 surface = current as ExtensionSurface;
                 current = (FrameworkElement)current.Parent;
             }
         }
     }
     return(null != window && null != surface);
 }
Exemplo n.º 2
0
        void OnChildWindowLoaded(object sender, EventArgs e)
        {
            ExtensionWindow window = (ExtensionWindow)sender;

            this.OnWindowVisibilityChanged(window, null);
            window.Loaded -= OnChildWindowLoaded;
        }
Exemplo n.º 3
0
        protected override void OnVisualChildrenChanged(DependencyObject visualAdded, DependencyObject visualRemoved)
        {
            ExtensionWindow window = visualRemoved as ExtensionWindow;

            if (null != window)
            {
                window.VisibilityChanged -= OnWindowVisibilityChanged;
                // window.SizeChanged -= OnWindowSizeChanged;
                this.rearangeStartSize.Width  = 0;
                this.rearangeStartSize.Height = 0;
            }

            base.OnVisualChildrenChanged(visualAdded, visualRemoved);

            window = visualAdded as ExtensionWindow;
            if (null != window)
            {
                window.VisibilityChanged += OnWindowVisibilityChanged;
                // window.SizeChanged += OnWindowSizeChanged;
                if (!window.IsLoaded)
                {
                    window.Loaded += OnChildWindowLoaded;
                }
            }
        }
Exemplo n.º 4
0
        static void OnPlacementModeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            ExtensionWindow window = sender as ExtensionWindow;

            if (null != window && null != window.Surface && window.Visibility == Visibility.Visible)
            {
                window.Surface.PlaceWindow(window);
            }
        }
 protected override void OnVisualParentChanged(DependencyObject oldParent)
 {
     base.OnVisualParentChanged(oldParent);
     if (!DesignerProperties.GetIsInDesignMode(this) &&
         !ExtensionWindow.TryGetParentExtensionWindow(this, out this.parent, out this.surface))
     {
         Fx.Assert("ExtensionWindowHeader cannot be used outside ExtensionWindow");
     }
 }
Exemplo n.º 6
0
        internal void SetWindowPosition(ExtensionWindow window, Point position)
        {
            Func <double, double, double, double, double> CalculateInBoundsValue =
                (pos, size, limit, modifier) =>
            {
                if (this.AutoExpandCanvas)
                {
                    return(pos - modifier);
                }
                else
                {
                    pos = Math.Max(0.0, pos);
                    return(pos + size > limit ? limit - size : pos);
                }
            };

            //in case of AutoExpandCanvas == false:
            // - do not allow placing window outside surface bounds
            //in case of AutoExpandCanvas == true:
            // - include possible negative canvas offset
            position.X = CalculateInBoundsValue(position.X, window.DesiredSize.Width, this.ActualWidth, this.selectedChild.Value.X);
            position.Y = CalculateInBoundsValue(position.Y, window.DesiredSize.Height, this.ActualHeight, this.selectedChild.Value.Y);

            //update its position on canvas
            ExtensionSurface.SetPosition(window, position);

            bool requiresMeasure = false;

            if (this.AutoExpandCanvas)
            {
                requiresMeasure     = true;
                this.canvasOffset.X = 0;
                this.canvasOffset.Y = 0;

                foreach (UIElement item in this.Children)
                {
                    FrameworkElement child = item as FrameworkElement;
                    if (null != child)
                    {
                        Point p = ExtensionSurface.GetPosition(child);
                        this.canvasOffset.X = Math.Min(this.canvasOffset.X, p.X);
                        this.canvasOffset.Y = Math.Min(this.canvasOffset.Y, p.Y);
                    }
                }
                this.canvasOffset.X = Math.Abs(this.canvasOffset.X);
                this.canvasOffset.Y = Math.Abs(this.canvasOffset.Y);
            }
            if (requiresMeasure)
            {
                this.InvalidateMeasure();
            }
            else
            {
                this.InvalidateArrange();
            }
        }
Exemplo n.º 7
0
 public void SelectWindow(ExtensionWindow window)
 {
     if (null != window && this.Children.Contains(window))
     {
         this.selectedChild            = new KeyValuePair <FrameworkElement, Point>(window, this.canvasOffset);
         this.rearangeStartSize.Width  = this.ActualWidth;
         this.rearangeStartSize.Height = this.ActualHeight;
         Panel.SetZIndex(window, ++this.currentZIndex);
     }
 }
Exemplo n.º 8
0
        static internal void RaiseWindowCloseEvent(ExtensionWindow sender)
        {
            ExtensionWindowClosingRoutedEventArgs args = new ExtensionWindowClosingRoutedEventArgs(ClosingEvent, sender);

            sender.RaiseEvent(args);
            if (!args.Cancel)
            {
                sender.RaiseEvent(new RoutedEventArgs(CloseEvent, sender));
            }
        }
Exemplo n.º 9
0
        void OnExtensionWindowClosed(object sender, RoutedEventArgs args)
        {
            ExtensionWindow window = args.Source as ExtensionWindow;

            if (null != window)
            {
                //remove window from children collection
                this.Children.Remove(window);
            }
        }
Exemplo n.º 10
0
 public override void OnApplyTemplate()
 {
     base.OnApplyTemplate();
     this.closeButton = this.Template.FindName("PART_CloseButton", this) as Button;
     if (null != this.closeButton)
     {
         this.closeButton.Click += new RoutedEventHandler(delegate(object sender, RoutedEventArgs e)
         {
             ExtensionWindow.RaiseWindowCloseEvent(this.parent);
         }
                                                          );
     }
 }
Exemplo n.º 11
0
        //void OnWindowSizeChanged(object sender, SizeChangedEventArgs e)
        //{
        //    ExtensionWindow window = (ExtensionWindow)sender;
        //   // EnsureWindowIsVisible(window);
        //}

        void OnWindowVisibilityChanged(object sender, RoutedEventArgs args)
        {
            ExtensionWindow window = (ExtensionWindow)sender;

            if (window.IsVisible)
            {
                Func <double, bool> IsInvalid = x => (double.IsInfinity(x) || double.IsNaN(x) || double.Epsilon > x);

                if (IsInvalid(window.ActualWidth) || IsInvalid(window.ActualWidth) || IsInvalid(window.DesiredSize.Width) || IsInvalid(window.DesiredSize.Height))
                {
                    window.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                }
                PlaceWindow(window);
            }
        }
Exemplo n.º 12
0
 protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
 {
     base.OnRenderSizeChanged(sizeInfo);
     foreach (FrameworkElement child in this.Children)
     {
         ExtensionWindow window = child as ExtensionWindow;
         if (null != window)
         {
             if (PlacementMode.Relative == GetMode(window) && null != GetPlacementTarget(window))
             {
                 this.PlaceWindow(window);
                 continue;
             }
             if (!this.AutoExpandCanvas)
             {
                 this.EnsureWindowIsVisible(window);
             }
         }
     }
 }
Exemplo n.º 13
0
        internal void SetSize(ExtensionWindow window, Size size)
        {
            Point pos = ExtensionSurface.GetPosition(window);

            if (!this.AutoExpandCanvas)
            {
                if (IsGreater(pos.X, size.Width, this.ActualWidth))
                {
                    size.Width = this.ActualWidth - pos.X;
                }
                if (IsGreater(pos.Y, size.Height, this.ActualHeight))
                {
                    size.Height = this.ActualHeight - pos.Y;
                }
            }
            System.Diagnostics.Debug.WriteLine("SetSize oldSize (" + window.Width + "," + window.Height + ") newSize (" + size.Width + "," + size.Height + ")");
            window.Width  = size.Width;
            window.Height = size.Height;
            if (this.AutoExpandCanvas)
            {
                // this.InvalidateMeasure();
            }
        }
Exemplo n.º 14
0
 internal static bool TryGetParentExtensionWindow(FrameworkElement element, out ExtensionWindow window, out ExtensionSurface surface)
 {
     window = null;
     surface = null;
     if (null != element)
     {
         FrameworkElement current = element;
         window = element.TemplatedParent as ExtensionWindow;
         while (null == window && null != current)
         {
             window = current as ExtensionWindow;
             current = (FrameworkElement)current.Parent;
         }
         if (null != window)
         {
             current = window;
             surface = window.TemplatedParent as ExtensionSurface;
             while (null == surface && null != current)
             {
                 surface = current as ExtensionSurface;
                 current = (FrameworkElement)current.Parent;
             }
         }
     }
     return (null != window && null != surface);
 }
Exemplo n.º 15
0
 static internal void RaiseWindowCloseEvent(ExtensionWindow sender)
 {
     ExtensionWindowClosingRoutedEventArgs args = new ExtensionWindowClosingRoutedEventArgs(ClosingEvent, sender);
     sender.RaiseEvent(args);
     if (!args.Cancel)
     {
         sender.RaiseEvent(new RoutedEventArgs(CloseEvent, sender));
     }
 }
Exemplo n.º 16
0
        void PlaceWindow(ExtensionWindow window)
        {
            if (null != window)
            {
                FrameworkElement  target    = ExtensionSurface.GetPlacementTarget(window);
                PositionAlignment alignment = ExtensionSurface.GetAlignment(window);
                PlacementMode     mode      = ExtensionSurface.GetMode(window);
                Point             position  = ExtensionSurface.GetPosition(window);

                Point            calculatedPosition = new Point();
                FrameworkElement commonRoot         = null;
                MatrixTransform  transform          = null;

                switch (mode)
                {
                case PlacementMode.Relative:
                    if (null != target)
                    {
                        commonRoot = target.FindCommonVisualAncestor(this) as FrameworkElement;
                        if (null == commonRoot)
                        {
                            return;
                        }
                        transform = (MatrixTransform)target.TransformToAncestor(commonRoot);
                    }
                    else
                    {
                        if (!DesignerProperties.GetIsInDesignMode(this))
                        {
                            Fx.Assert(string.Format(CultureInfo.InvariantCulture, "PlacementTarget must be set in RelativeMode on ExtensionSurface '{0}'", this.Name));
                        }
                    }
                    break;

                case PlacementMode.Absolute:
                    calculatedPosition = position;
                    break;

                default:
                    Fx.Assert(string.Format(CultureInfo.CurrentCulture, "ExtensionWindowPlacement.Mode {0} specified in ExtensionWindow '{1}' is not supported for ExtensionSurface", mode, window.Name));
                    return;
                }

                if (PlacementMode.Relative == mode)
                {
                    if (null != target)
                    {
                        double x;
                        double y;
                        switch (alignment)
                        {
                        case PositionAlignment.LeftTop:
                            calculatedPosition = transform.Transform(calculatedPosition);
                            break;

                        case PositionAlignment.LeftBottom:
                            calculatedPosition = transform.Transform(new Point(0.0, target.ActualHeight));
                            break;

                        case PositionAlignment.RightTop:
                            calculatedPosition = transform.Transform(new Point(target.ActualWidth, 0.0));
                            break;

                        case PositionAlignment.RightBottom:
                            calculatedPosition = transform.Transform(new Point(target.ActualWidth, target.ActualHeight));
                            break;

                        case PositionAlignment.Center:
                            calculatedPosition = transform.Transform(calculatedPosition);
                            x = ((target.ActualWidth * transform.Matrix.M11) - window.Width) / 2.0;
                            y = ((target.ActualHeight * transform.Matrix.M22) - window.Height) / 2.0;
                            calculatedPosition.Offset(x, y);
                            break;

                        case PositionAlignment.CenterHorizontal:
                            calculatedPosition = transform.Transform(calculatedPosition);
                            x = ((target.ActualWidth * transform.Matrix.M11) - window.Width) / 2.0;
                            calculatedPosition.Offset(x, 0.0);
                            break;

                        case PositionAlignment.CenterVertical:
                            calculatedPosition = transform.Transform(calculatedPosition);
                            y = ((target.ActualHeight * transform.Matrix.M22) - window.Height) / 2.0;
                            calculatedPosition.Offset(0.0, y);
                            break;

                        default:
                            Fx.Assert(string.Format(CultureInfo.CurrentCulture, "ExtensionWindowPlacement.Position = '{0}' is not supported", alignment));
                            return;
                        }
                    }
                }
                SetWindowPosition(window, calculatedPosition);
            }
        }
Exemplo n.º 17
0
 public void SelectWindow(ExtensionWindow window)
 {
     if (null != window && this.Children.Contains(window))
     {
         this.selectedChild = new KeyValuePair<FrameworkElement, Point>(window, this.canvasOffset);
         this.rearangeStartSize.Width = this.ActualWidth;
         this.rearangeStartSize.Height = this.ActualHeight;
         Panel.SetZIndex(window, ++this.currentZIndex);
     }
 }
Exemplo n.º 18
0
 internal void SetSize(ExtensionWindow window, Size size)
 {
     Point pos = ExtensionSurface.GetPosition(window);
     if (!this.AutoExpandCanvas)
     {
         if (IsGreater(pos.X, size.Width, this.ActualWidth))
         {
             size.Width = this.ActualWidth - pos.X;
         }
         if (IsGreater(pos.Y, size.Height, this.ActualHeight))
         {
             size.Height = this.ActualHeight - pos.Y;
         }
     }
     System.Diagnostics.Debug.WriteLine("SetSize oldSize (" + window.Width + "," + window.Height + ") newSize (" + size.Width + "," + size.Height + ")");
     window.Width = size.Width;
     window.Height = size.Height;
     if (this.AutoExpandCanvas)
     {
         // this.InvalidateMeasure();
     }
 }
Exemplo n.º 19
0
 void EnsureWindowIsVisible(ExtensionWindow window)
 {
     SetWindowPosition(window, ExtensionSurface.GetPosition(window));
 }
Exemplo n.º 20
0
        internal void SetWindowPosition(ExtensionWindow window, Point position)
        {
            Func<double, double, double, double, double> CalculateInBoundsValue =
                (pos, size, limit, modifier) =>
                {
                    if (this.AutoExpandCanvas)
                    {
                        return pos - modifier;
                    }
                    else
                    {
                        pos = Math.Max(0.0, pos);
                        return pos + size > limit ? limit - size : pos;
                    }
                };

            //in case of AutoExpandCanvas == false:
            // - do not allow placing window outside surface bounds
            //in case of AutoExpandCanvas == true:
            // - include possible negative canvas offset
            position.X = CalculateInBoundsValue(position.X, window.DesiredSize.Width, this.ActualWidth, this.selectedChild.Value.X);
            position.Y = CalculateInBoundsValue(position.Y, window.DesiredSize.Height, this.ActualHeight, this.selectedChild.Value.Y);

            //update its position on canvas
            ExtensionSurface.SetPosition(window, position);

            bool requiresMeasure = false;
            if (this.AutoExpandCanvas)
            {
                requiresMeasure = true;
                this.canvasOffset.X = 0;
                this.canvasOffset.Y = 0;

                foreach (UIElement item in this.Children)
                {
                    FrameworkElement child = item as FrameworkElement;
                    if (null != child)
                    {
                        Point p = ExtensionSurface.GetPosition(child);
                        this.canvasOffset.X = Math.Min(this.canvasOffset.X, p.X);
                        this.canvasOffset.Y = Math.Min(this.canvasOffset.Y, p.Y);
                    }
                }
                this.canvasOffset.X = Math.Abs(this.canvasOffset.X);
                this.canvasOffset.Y = Math.Abs(this.canvasOffset.Y);
            }
            if (requiresMeasure)
            {
                this.InvalidateMeasure();
            }
            else
            {
                this.InvalidateArrange();
            }
        }
Exemplo n.º 21
0
        void PlaceWindow(ExtensionWindow window)
        {
            if (null != window)
            {
                FrameworkElement target = ExtensionSurface.GetPlacementTarget(window);
                PositionAlignment alignment = ExtensionSurface.GetAlignment(window);
                PlacementMode mode = ExtensionSurface.GetMode(window);
                Point position = ExtensionSurface.GetPosition(window);

                Point calculatedPosition = new Point();
                FrameworkElement commonRoot = null;
                MatrixTransform transform = null;

                switch (mode)
                {
                    case PlacementMode.Relative:
                        if (null != target)
                        {
                            commonRoot = target.FindCommonVisualAncestor(this) as FrameworkElement;
                            if (null == commonRoot)
                            {
                                return;
                            }
                            transform = (MatrixTransform)target.TransformToAncestor(commonRoot);
                        }
                        else
                        {
                            if (!DesignerProperties.GetIsInDesignMode(this))
                            {
                                Fx.Assert(string.Format(CultureInfo.InvariantCulture, "PlacementTarget must be set in RelativeMode on ExtensionSurface '{0}'", this.Name));
                            }
                        }
                        break;

                    case PlacementMode.Absolute:
                        calculatedPosition = position;
                        break;

                    default:
                        Fx.Assert(string.Format(CultureInfo.CurrentCulture, "ExtensionWindowPlacement.Mode {0} specified in ExtensionWindow '{1}' is not supported for ExtensionSurface", mode, window.Name));
                        return;
                }

                if (PlacementMode.Relative == mode)
                {
                    if (null != target)
                    {
                        double x;
                        double y;
                        switch (alignment)
                        {
                            case PositionAlignment.LeftTop:
                                calculatedPosition = transform.Transform(calculatedPosition);
                                break;

                            case PositionAlignment.LeftBottom:
                                calculatedPosition = transform.Transform(new Point(0.0, target.ActualHeight));
                                break;

                            case PositionAlignment.RightTop:
                                calculatedPosition = transform.Transform(new Point(target.ActualWidth, 0.0));
                                break;

                            case PositionAlignment.RightBottom:
                                calculatedPosition = transform.Transform(new Point(target.ActualWidth, target.ActualHeight));
                                break;

                            case PositionAlignment.Center:
                                calculatedPosition = transform.Transform(calculatedPosition);
                                x = ((target.ActualWidth * transform.Matrix.M11) - window.Width) / 2.0;
                                y = ((target.ActualHeight * transform.Matrix.M22) - window.Height) / 2.0;
                                calculatedPosition.Offset(x, y);
                                break;

                            case PositionAlignment.CenterHorizontal:
                                calculatedPosition = transform.Transform(calculatedPosition);
                                x = ((target.ActualWidth * transform.Matrix.M11) - window.Width) / 2.0;
                                calculatedPosition.Offset(x, 0.0);
                                break;

                            case PositionAlignment.CenterVertical:
                                calculatedPosition = transform.Transform(calculatedPosition);
                                y = ((target.ActualHeight * transform.Matrix.M22) - window.Height) / 2.0;
                                calculatedPosition.Offset(0.0, y);
                                break;

                            default:
                                Fx.Assert(string.Format(CultureInfo.CurrentCulture, "ExtensionWindowPlacement.Position = '{0}' is not supported", alignment));
                                return;
                        }
                    }
                }
                SetWindowPosition(window, calculatedPosition);
            }
        }
Exemplo n.º 22
0
 void EnsureWindowIsVisible(ExtensionWindow window)
 {
     SetWindowPosition(window, ExtensionSurface.GetPosition(window));
 }