Skip to content

Commit

Permalink
Fixed issue where move/resize did not always save for good.
Browse files Browse the repository at this point in the history
  • Loading branch information
mscrivo committed Jul 25, 2015
1 parent b2da6e1 commit 09d7b45
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 25 deletions.
26 changes: 21 additions & 5 deletions OutlookDesktop/Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 23 additions & 16 deletions OutlookDesktop/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -38,7 +37,6 @@ public partial class MainForm : Form
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
// ReSharper disable once NotAccessedField.Local
private StickyWindow _stickyWindow;
private bool _formMovedOrResized;

/// <summary>
/// Sets up the form for the current instance.
Expand Down Expand Up @@ -73,8 +71,18 @@ public MainForm(string instanceName)
ResumeLayout();
SendWindowToBack();

// hook up sticky window instance and events to let us know when resizing/moving
// has ended so we can update the form dimensions in the preferences.
_stickyWindow = new StickyWindow(this);

_stickyWindow.MoveEnded += (sender, args) =>
{
SaveFormDimensions();
};
_stickyWindow.ResizeEnded += (sender, args) =>
{
SaveFormDimensions();
};

// hook up event to keep the date in the header bar up to date
OutlookViewControl.SelectionChange += OnAxOutlookViewControlOnSelectionChange;
}
Expand Down Expand Up @@ -120,7 +128,6 @@ protected override CreateParams CreateParams
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x80; // Turn on WS_EX_TOOLWINDOW style bit to hide window from alt-tab
//cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED to turn on double-buffering for the entire form and controls.
return cp;
}
}
Expand Down Expand Up @@ -622,7 +629,6 @@ private void ResizeForm(ResizeDirection direction)
{
UnsafeNativeMethods.ReleaseCapture();
UnsafeNativeMethods.SendMessage(Handle, UnsafeNativeMethods.WM_NCLBUTTONDOWN, (IntPtr)dir, IntPtr.Zero);
_formMovedOrResized = true;
}
}

Expand All @@ -633,8 +639,6 @@ private void MoveForm()

UnsafeNativeMethods.ReleaseCapture();
UnsafeNativeMethods.SendMessage(Handle, UnsafeNativeMethods.WM_NCLBUTTONDOWN, (IntPtr)UnsafeNativeMethods.HTCAPTION, IntPtr.Zero);

_formMovedOrResized = true;
}

#region Event Handlers
Expand Down Expand Up @@ -765,16 +769,19 @@ private void UpdateTimer_Tick(object sender, EventArgs e)
}
}
_previousDate = DateTime.Now;
}

// Update our position in the settings
if (_formMovedOrResized)
{
Preferences.Left = Left;
Preferences.Top = Top;
Preferences.Width = Width;
Preferences.Height = Height;
_formMovedOrResized = false;
}
private void SaveFormDimensions()
{
Debug.WriteLine("Saving window position");
Debug.WriteLine("Left: {0}", Left);
Debug.WriteLine("Top: {0}", Top);
Debug.WriteLine("Width: {0}", Width);
Debug.WriteLine("Height: {0}", Height);
Preferences.Left = Left;
Preferences.Top = Top;
Preferences.Width = Width;
Preferences.Height = Height;
}

private void ExitMenu_Click(object sender, EventArgs e)
Expand Down
9 changes: 9 additions & 0 deletions OutlookDesktop/Forms/MainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@
<metadata name="ToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>355, 17</value>
</metadata>
<metadata name="ToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>355, 17</value>
</metadata>
<metadata name="ToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>355, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="MonthButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Expand All @@ -142,6 +148,9 @@
Rb/fGQZAu092OCV66NLZAAAAAElFTkSuQmCC
</value>
</data>
<metadata name="ToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>355, 17</value>
</metadata>
<data name="OutlookViewControl.OcxState" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
Expand Down
4 changes: 2 additions & 2 deletions OutlookDesktop/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:

[assembly: AssemblyVersion("3.2.3.1")]
[assembly: AssemblyFileVersion("3.2.3.1")]
[assembly: AssemblyVersion("3.2.4.0")]
[assembly: AssemblyFileVersion("3.2.4.0")]

//
// In order to sign your assembly you must specify a key to use. Refer to the
Expand Down
20 changes: 18 additions & 2 deletions OutlookDesktop/Utility/StickyWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Security.Permissions;
Expand Down Expand Up @@ -139,6 +140,9 @@ public class StickyWindow : NativeWindow
// public properties
private static int _stickGap = 10; // distance to stick

public event EventHandler ResizeEnded;
public event EventHandler MoveEnded;

#region StickyWindow Constructor

/// <summary>
Expand Down Expand Up @@ -477,6 +481,7 @@ private bool ResizeMsgProcessor(ref Message m)
private void EndResize()
{
Cancel();
OnResizeEnded();
}

#endregion
Expand Down Expand Up @@ -686,6 +691,7 @@ private bool MoveMsgProcessor(ref Message m)
private void EndMove()
{
Cancel();
OnMoveEnded();
}

#endregion
Expand Down Expand Up @@ -774,12 +780,12 @@ private void Move_Stick(Rectangle toRect, bool bInsideStick)
{
if (bInsideStick)
{
if (Math.Abs(_formRect.Top - toRect.Bottom) <= Math.Abs(_formOffsetPoint.Y) && bInsideStick)
if (Math.Abs(_formRect.Top - toRect.Bottom) <= Math.Abs(_formOffsetPoint.Y))
{
// Stick Top to Bottom
_formOffsetPoint.Y = toRect.Bottom - _formRect.Top;
}
if (Math.Abs(_formRect.Top + _formRect.Height - toRect.Top) <= Math.Abs(_formOffsetPoint.Y) && bInsideStick)
if (Math.Abs(_formRect.Top + _formRect.Height - toRect.Top) <= Math.Abs(_formOffsetPoint.Y))
{
// snap Bottom to Top
_formOffsetPoint.Y = toRect.Top - _formRect.Height - _formRect.Top;
Expand All @@ -801,5 +807,15 @@ private void Move_Stick(Rectangle toRect, bool bInsideStick)
}

#endregion

protected virtual void OnResizeEnded()
{
ResizeEnded?.Invoke(this, EventArgs.Empty);
}

protected virtual void OnMoveEnded()
{
MoveEnded?.Invoke(this, EventArgs.Empty);
}
}
}

0 comments on commit 09d7b45

Please sign in to comment.