Browse Source

Close #312: Implemented Window Position Validation

pull/313/merge
Daniel Grunwald 14 years ago
parent
commit
43c80f90ea
  1. 1
      ILSpy/ILSpy.csproj
  2. 37
      ILSpy/MainWindow.xaml.cs
  3. 3
      ILSpy/SessionSettings.cs

1
ILSpy/ILSpy.csproj

@ -72,6 +72,7 @@ @@ -72,6 +72,7 @@
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>

37
ILSpy/MainWindow.xaml.cs

@ -31,7 +31,6 @@ using System.Windows.Input; @@ -31,7 +31,6 @@ using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using ICSharpCode.ILSpy.Debugger;
using ICSharpCode.ILSpy.TextView;
using ICSharpCode.ILSpy.TreeNodes;
@ -78,12 +77,6 @@ namespace ICSharpCode.ILSpy @@ -78,12 +77,6 @@ namespace ICSharpCode.ILSpy
this.Icon = new BitmapImage(new Uri("pack://application:,,,/ILSpy;component/images/ILSpy.ico"));
this.DataContext = sessionSettings;
this.Left = sessionSettings.WindowBounds.Left;
this.Top = sessionSettings.WindowBounds.Top;
this.Width = sessionSettings.WindowBounds.Width;
this.Height = sessionSettings.WindowBounds.Height;
// TODO: validate bounds (maybe a monitor was removed...)
this.WindowState = sessionSettings.WindowState;
InitializeComponent();
App.CompositionContainer.ComposeParts(this);
@ -102,6 +95,14 @@ namespace ICSharpCode.ILSpy @@ -102,6 +95,14 @@ namespace ICSharpCode.ILSpy
this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
}
void SetWindowBounds(Rect bounds)
{
this.Left = bounds.Left;
this.Top = bounds.Top;
this.Width = bounds.Width;
this.Height = bounds.Height;
}
#region Toolbar extensibility
[ImportMany("ToolbarCommand", typeof(ICommand))]
Lazy<ICommand, IToolbarCommandMetadata>[] toolbarCommands = null;
@ -187,10 +188,26 @@ namespace ICSharpCode.ILSpy @@ -187,10 +188,26 @@ namespace ICSharpCode.ILSpy
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
if (source != null) {
source.AddHook(WndProc);
PresentationSource source = PresentationSource.FromVisual(this);
HwndSource hwndSource = source as HwndSource;
if (hwndSource != null) {
hwndSource.AddHook(WndProc);
}
// Validate and Set Window Bounds
Rect bounds = Rect.Transform(sessionSettings.WindowBounds, source.CompositionTarget.TransformToDevice);
var boundsRect = new System.Drawing.Rectangle((int)bounds.Left, (int)bounds.Top, (int)bounds.Width, (int)bounds.Height);
bool boundsOK = false;
foreach (var screen in System.Windows.Forms.Screen.AllScreens) {
var intersection = System.Drawing.Rectangle.Intersect(boundsRect, screen.WorkingArea);
if (intersection.Width > 10 && intersection.Height > 10)
boundsOK = true;
}
if (boundsOK)
SetWindowBounds(sessionSettings.WindowBounds);
else
SetWindowBounds(SessionSettings.DefaultWindowBounds);
this.WindowState = sessionSettings.WindowState;
}
unsafe IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)

3
ILSpy/SessionSettings.cs

@ -47,7 +47,7 @@ namespace ICSharpCode.ILSpy @@ -47,7 +47,7 @@ namespace ICSharpCode.ILSpy
}
this.WindowState = FromString((string)doc.Element("WindowState"), WindowState.Normal);
this.WindowBounds = FromString((string)doc.Element("WindowBounds"), new Rect(10, 10, 750, 550));
this.WindowBounds = FromString((string)doc.Element("WindowBounds"), DefaultWindowBounds);
this.SplitterPosition = FromString((string)doc.Element("SplitterPosition"), 0.4);
this.TopPaneSplitterPosition = FromString((string)doc.Element("TopPaneSplitterPosition"), 0.3);
this.BottomPaneSplitterPosition = FromString((string)doc.Element("BottomPaneSplitterPosition"), 0.3);
@ -69,6 +69,7 @@ namespace ICSharpCode.ILSpy @@ -69,6 +69,7 @@ namespace ICSharpCode.ILSpy
public WindowState WindowState = WindowState.Normal;
public Rect WindowBounds;
internal static Rect DefaultWindowBounds = new Rect(10, 10, 750, 550);
/// <summary>
/// position of the left/right splitter
/// </summary>

Loading…
Cancel
Save