//-----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Implements HelpWindow.
//
//-----------------------------------------------------------------------
namespace Microsoft.Management.UI
{
using System.Windows;
///
/// Utilities in common in this assembly
///
internal static class CommonHelper
{
///
/// Restore the values from the settings to the actual window position, size and state.
///
/// the window we are setting position and size of
/// the value for top from the user settings
/// the value for left from the user settings
/// the value for width from the user settings
/// the value for height from the user settings
/// the with used if is not valid
/// the height used if is not valid
/// true if the window is maximized in the user setting
internal static void SetStartingPositionAndSize(Window target, double userSettingTop, double userSettingLeft, double userSettingWidth, double userSettingHeight, double defaultWidth, double defaultHeight, bool userSettingMaximized)
{
bool leftInvalid = userSettingLeft < System.Windows.SystemParameters.VirtualScreenLeft ||
userSettingWidth > System.Windows.SystemParameters.VirtualScreenLeft +
System.Windows.SystemParameters.VirtualScreenWidth;
bool topInvalid = userSettingTop < System.Windows.SystemParameters.VirtualScreenTop ||
userSettingTop > System.Windows.SystemParameters.VirtualScreenTop +
System.Windows.SystemParameters.VirtualScreenHeight;
bool widthInvalid = userSettingWidth < 0 ||
userSettingWidth > System.Windows.SystemParameters.VirtualScreenWidth;
bool heightInvalid = userSettingHeight < 0 ||
userSettingHeight > System.Windows.SystemParameters.VirtualScreenHeight;
if (leftInvalid || topInvalid)
{
target.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
}
else
{
target.Left = userSettingLeft;
target.Top = userSettingTop;
}
// If any saved coordinate is invalid, we set the window to the default position
if (widthInvalid || heightInvalid)
{
target.Width = defaultWidth;
target.Height = defaultHeight;
}
else
{
target.Width = userSettingWidth;
target.Height = userSettingHeight;
}
if (userSettingMaximized)
{
target.WindowState = WindowState.Maximized;
}
}
}
}