Exemplo n.º 1
0
 protected override void OnMouseLeftButtonDown(MouseButtonEventArgs args)
 {
     base.OnMouseLeftButtonDown(args);
     if (ExtensionSurface.PlacementMode.Absolute == ExtensionSurface.GetMode(this.parent))
     {
         this.offset          = Mouse.GetPosition(this);
         Mouse.OverrideCursor = Cursors.Arrow;
         CaptureMouse();
     }
 }
Exemplo n.º 2
0
        void OnBorderMouseMove(object sender, MouseEventArgs e)
        {
            if (!this.border.IsMouseCaptured)
            {
                if (this.border.IsMouseDirectlyOver && this.IsResizable && ExtensionSurface.GetMode(this) == ExtensionSurface.PlacementMode.Absolute)
                {
                    Point position = e.GetPosition(this.border);

                    if (position.X <= BorderOffset && position.Y <= BorderOffset)
                    {
                        this.resizeOption    = ResizeValues.TopLeft;
                        Mouse.OverrideCursor = Cursors.SizeNWSE;
                    }
                    else if (position.X >= this.border.ActualWidth - BorderOffset && position.Y <= BorderOffset)
                    {
                        this.resizeOption    = ResizeValues.TopRight;
                        Mouse.OverrideCursor = Cursors.SizeNESW;
                    }
                    else if (position.X <= BorderOffset && position.Y >= this.border.ActualHeight - BorderOffset)
                    {
                        this.resizeOption    = ResizeValues.BottomLeft;
                        Mouse.OverrideCursor = Cursors.SizeNESW;
                    }
                    else if (position.X >= this.border.ActualWidth - BorderOffset && position.Y >= this.border.ActualHeight - BorderOffset)
                    {
                        this.resizeOption    = ResizeValues.BottomRight;
                        Mouse.OverrideCursor = Cursors.SizeNWSE;
                    }
                    else if (position.Y <= (BorderOffset / 2.0))
                    {
                        this.resizeOption    = ResizeValues.Top;
                        Mouse.OverrideCursor = Cursors.SizeNS;
                    }
                    else if (position.Y >= this.border.ActualHeight - (BorderOffset / 2.0))
                    {
                        this.resizeOption    = ResizeValues.Bottom;
                        Mouse.OverrideCursor = Cursors.SizeNS;
                    }
                    else if (position.X <= (BorderOffset / 2.0))
                    {
                        this.resizeOption    = ResizeValues.Left;
                        Mouse.OverrideCursor = Cursors.SizeWE;
                    }
                    else if (position.X >= this.border.ActualWidth - (BorderOffset / 2.0))
                    {
                        this.resizeOption    = ResizeValues.Right;
                        Mouse.OverrideCursor = Cursors.SizeWE;
                    }
                    else
                    {
                        Mouse.OverrideCursor = null;
                        this.resizeOption    = ResizeValues.NONE;
                    }
                    Point topLeft = ExtensionSurface.GetPosition(this);
                    this.bottomRight = new Point(topLeft.X + Width, topLeft.Y + Height);
                }
                else if (Mouse.OverrideCursor != null)
                {
                    Mouse.OverrideCursor = null;
                    this.resizeOption    = ResizeValues.NONE;
                }
            }
            else if (e.LeftButton == MouseButtonState.Pressed)
            {
                this.HandleWindowResize();
            }
        }
Exemplo n.º 3
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);
            }
        }