|
|
@ -6,7 +6,7 @@ |
|
|
|
// </file>
|
|
|
|
// </file>
|
|
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.Drawing; |
|
|
|
using System.Windows; |
|
|
|
using System.Windows.Forms; |
|
|
|
using System.Windows.Forms; |
|
|
|
|
|
|
|
|
|
|
|
using ICSharpCode.Core; |
|
|
|
using ICSharpCode.Core; |
|
|
@ -37,13 +37,40 @@ namespace ICSharpCode.SharpDevelop.Gui |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
static Rectangle Validate(Rectangle bounds) |
|
|
|
|
|
|
|
|
|
|
|
public static void ApplyWindow(Window window, string propertyName, bool isResizable) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
window.WindowStartupLocation = WindowStartupLocation.Manual; |
|
|
|
|
|
|
|
if (isResizable) { |
|
|
|
|
|
|
|
Rect bounds = Validate(PropertyService.Get(propertyName, GetDefaultBounds(window))); |
|
|
|
|
|
|
|
window.Left = bounds.X; |
|
|
|
|
|
|
|
window.Top = bounds.Y; |
|
|
|
|
|
|
|
window.Width = bounds.Width; |
|
|
|
|
|
|
|
window.Height = bounds.Height; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Size size = new Size(window.ActualWidth, window.ActualHeight); |
|
|
|
|
|
|
|
Point location = Validate(PropertyService.Get(propertyName, GetDefaultLocation(window)), size); |
|
|
|
|
|
|
|
window.Left = location.X; |
|
|
|
|
|
|
|
window.Top = location.Y; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
window.Closing += delegate { |
|
|
|
|
|
|
|
if (isResizable) { |
|
|
|
|
|
|
|
if (window.WindowState == System.Windows.WindowState.Normal) { |
|
|
|
|
|
|
|
PropertyService.Set(propertyName, new Rect(window.Left, window.Top, window.ActualWidth, window.ActualHeight)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
PropertyService.Set(propertyName, new Point(window.Left, window.Top)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Rect Validate(Rect bounds) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Check if form is outside the screen and get it back if necessary.
|
|
|
|
// Check if form is outside the screen and get it back if necessary.
|
|
|
|
// This is important when the user uses multiple screens, a window stores its location
|
|
|
|
// This is important when the user uses multiple screens, a window stores its location
|
|
|
|
// on the secondary monitor and then the secondary monitor is removed.
|
|
|
|
// on the secondary monitor and then the secondary monitor is removed.
|
|
|
|
Rectangle screen1 = Screen.FromPoint(new Point(bounds.X, bounds.Y)).WorkingArea; |
|
|
|
Rect screen1 = Screen.FromPoint(bounds.TopLeft.ToSystemDrawing()).WorkingArea.ToWpf(); |
|
|
|
Rectangle screen2 = Screen.FromPoint(new Point(bounds.X + bounds.Width, bounds.Y)).WorkingArea; |
|
|
|
Rect screen2 = Screen.FromPoint(bounds.TopRight.ToSystemDrawing()).WorkingArea.ToWpf(); |
|
|
|
if (bounds.Y < screen1.Y - 5 && bounds.Y < screen2.Y - 5) |
|
|
|
if (bounds.Y < screen1.Y - 5 && bounds.Y < screen2.Y - 5) |
|
|
|
bounds.Y = screen1.Y - 5; |
|
|
|
bounds.Y = screen1.Y - 5; |
|
|
|
if (bounds.X < screen1.X - bounds.Width / 2) |
|
|
|
if (bounds.X < screen1.X - bounds.Width / 2) |
|
|
@ -55,23 +82,49 @@ namespace ICSharpCode.SharpDevelop.Gui |
|
|
|
|
|
|
|
|
|
|
|
static Point Validate(Point location, Size size) |
|
|
|
static Point Validate(Point location, Size size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Validate(new Rectangle(location, size)).Location; |
|
|
|
return Validate(new Rect(location, size)).Location; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static System.Drawing.Rectangle Validate(System.Drawing.Rectangle bounds) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return Validate(bounds.ToWpf()).ToSystemDrawing(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static System.Drawing.Point Validate(System.Drawing.Point location, System.Drawing.Size size) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return Validate(location.ToWpf(), size.ToWpf()).ToSystemDrawing(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static System.Drawing.Rectangle GetDefaultBounds(Form form) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return new System.Drawing.Rectangle(GetDefaultLocation(form.Size.ToWpf()).ToSystemDrawing(), form.Size); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Rect GetDefaultBounds(Window window) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Size size = new Size(window.Width, window.Height); |
|
|
|
|
|
|
|
return new Rect(GetDefaultLocation(size), size); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static System.Drawing.Point GetDefaultLocation(Form form) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return GetDefaultLocation(form.Size.ToWpf()).ToSystemDrawing(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static Rectangle GetDefaultBounds(Form form) |
|
|
|
static Point GetDefaultLocation(Window window) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return new Rectangle(GetDefaultLocation(form), form.Size); |
|
|
|
Size size = new Size(window.Width, window.Height); |
|
|
|
|
|
|
|
return GetDefaultLocation(size); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static Point GetDefaultLocation(Form form) |
|
|
|
static Point GetDefaultLocation(Size formSize) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var mainWindow = WorkbenchSingleton.MainWindow; |
|
|
|
var mainWindow = WorkbenchSingleton.MainWindow; |
|
|
|
Rectangle parent = new Rectangle( |
|
|
|
Rect parent = new Rect( |
|
|
|
(int)mainWindow.Left, (int)mainWindow.Top, (int)mainWindow.Width, (int)mainWindow.Height |
|
|
|
mainWindow.Left, mainWindow.Top, mainWindow.Width, mainWindow.Height |
|
|
|
); |
|
|
|
); |
|
|
|
Size size = form.Size; |
|
|
|
return new Point(parent.Left + (parent.Width - formSize.Width) / 2, |
|
|
|
return new Point(parent.Left + (parent.Width - size.Width) / 2, |
|
|
|
parent.Top + (parent.Height - formSize.Height) / 2); |
|
|
|
parent.Top + (parent.Height - size.Height) / 2); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|