Ejemplo n.º 1
0
        /// <summary>
        /// Retrieve the WindowPlacement from the configuration
        /// </summary>
        /// <param name="editorConfiguration">IEditorConfiguration</param>
        /// <returns>WindowPlacement</returns>
        public static WindowPlacement GetEditorPlacement(this IEditorConfiguration editorConfiguration)
        {
            var placement = WindowPlacement.Create();

            placement.NormalPosition = editorConfiguration.WindowNormalPosition;
            placement.MaxPosition    = editorConfiguration.WindowMaxPosition;
            placement.MinPosition    = editorConfiguration.WindowMinPosition;
            placement.ShowCmd        = editorConfiguration.ShowWindowCommand;
            placement.Flags          = editorConfiguration.WindowPlacementFlags;
            return(placement);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Get the WindowPlacement
        /// </summary>
        /// <param name="interopWindow">InteropWindow</param>
        /// <param name="forceUpdate">set to true to make sure the value is updated</param>
        /// <returns>WindowPlacement</returns>
        public static WindowPlacement GetPlacement(this IInteropWindow interopWindow, bool forceUpdate = false)
        {
            if (interopWindow.Placement.HasValue && !forceUpdate)
            {
                return(interopWindow.Placement.Value);
            }
            var placement = WindowPlacement.Create();

            User32Api.GetWindowPlacement(interopWindow.Handle, ref placement);
            interopWindow.Placement = placement;
            return(interopWindow.Placement.Value);
        }
        /// <inheritdoc />
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string windowPlacementString)
            {
                string[] cmdMinMaxNormal = windowPlacementString.Split('|');
                if (cmdMinMaxNormal.Length == 4 && Enum.TryParse(cmdMinMaxNormal[0], true, out ShowWindowCommands showCommand))
                {
                    var windowPlacement = WindowPlacement.Create();
                    windowPlacement.ShowCmd        = showCommand;
                    windowPlacement.MinPosition    = (NativePoint?)_nativePointTypeConverter.ConvertFromInvariantString(cmdMinMaxNormal[1]) ?? NativePoint.Empty;
                    windowPlacement.MaxPosition    = (NativePoint?)_nativePointTypeConverter.ConvertFromInvariantString(cmdMinMaxNormal[2]) ?? NativePoint.Empty;
                    windowPlacement.NormalPosition = (NativeRect?)_nativeRectTypeConverter.ConvertFromInvariantString(cmdMinMaxNormal[3]) ?? NativeRect.Empty;

                    return(windowPlacement);
                }
            }
            return(base.ConvertFrom(context, culture, value));
        }
Ejemplo n.º 4
0
        private void TestWindowPlacement_TypeConverter()
        {
            var windowPlacement = WindowPlacement.Create();

            windowPlacement.MinPosition    = new NativePoint(10, 10);
            windowPlacement.MaxPosition    = new NativePoint(100, 100);
            windowPlacement.NormalPosition = new NativeRect(100, 100, 200, 200);
            windowPlacement.ShowCmd        = ShowWindowCommands.Normal;

            var typeConverter = TypeDescriptor.GetConverter(typeof(WindowPlacement));

            Assert.NotNull(typeConverter);
            var stringRepresentation = typeConverter.ConvertToInvariantString(windowPlacement);

            Assert.Equal("Normal|10,10|100,100|100,100,200,200", stringRepresentation);
            var windowPlacementResult = (WindowPlacement?)typeConverter.ConvertFromInvariantString(stringRepresentation);

            Assert.True(windowPlacementResult.HasValue);
            if (windowPlacementResult.HasValue)
            {
                Assert.Equal(windowPlacement, windowPlacementResult.Value);
            }
        }