Updating branch with imported PR from master.

This commit is contained in:
Philipp Sumi
2016-01-01 23:10:00 +01:00
5 changed files with 121 additions and 59 deletions

View File

@@ -70,9 +70,17 @@ namespace Hardcodet.Wpf.TaskbarNotification
/// <summary>
/// Maintains opened tooltip popups.
/// The time we should wait for a double click.
/// </summary>
private ToolTipObserver toolTipObserver;
/// <summary>
/// </summary>
private int doubleClickWaitTime
{
get { return NoLeftClickDelay ? 0 : WinApi.GetDoubleClickTime(); }
}
/// <summary>
/// A timer that is used to close open balloon tooltips.
/// </summary>
@@ -151,6 +159,14 @@ namespace Hardcodet.Wpf.TaskbarNotification
#endregion
#region Custom Balloons
public delegate Point GetCustomPopupPosition();
public GetCustomPopupPosition CustomPopupPosition;
public Point GetPopupTrayPosition()
{
return TrayInfo.GetTrayLocation();
}
/// <summary>
/// Shows a custom control as a tooltip in the tray location.
@@ -223,8 +239,8 @@ namespace Hardcodet.Wpf.TaskbarNotification
popup.Placement = PlacementMode.AbsolutePoint;
popup.StaysOpen = true;
Point position = TrayInfo.GetTrayLocation();
position = GetDeviceCoordinates(position);
Point position = this.CustomPopupPosition != null ? this.CustomPopupPosition() : this.GetPopupTrayPosition();
popup.HorizontalOffset = position.X - 1;
popup.VerticalOffset = position.Y - 1;
@@ -400,7 +416,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
WinApi.GetCursorPos(ref cursorPosition);
}
cursorPosition = GetDeviceCoordinates(cursorPosition);
cursorPosition = TrayInfo.GetDeviceCoordinates(cursorPosition);
bool isLeftClickCommandInvoked = false;
@@ -415,7 +431,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this);
ShowTrayPopup(cursorPosition);
};
singleClickTimer.Change(WinApi.GetDoubleClickTime(), Timeout.Infinite);
singleClickTimer.Change(doubleClickWaitTime, Timeout.Infinite);
isLeftClickCommandInvoked = true;
}
else
@@ -437,7 +453,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this);
ShowContextMenu(cursorPosition);
};
singleClickTimer.Change(WinApi.GetDoubleClickTime(), Timeout.Infinite);
singleClickTimer.Change(doubleClickWaitTime, Timeout.Infinite);
isLeftClickCommandInvoked = true;
}
else
@@ -456,7 +472,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
{
LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this);
};
singleClickTimer.Change(WinApi.GetDoubleClickTime(), Timeout.Infinite);
singleClickTimer.Change(doubleClickWaitTime, Timeout.Infinite);
}
}
@@ -820,7 +836,6 @@ namespace Hardcodet.Wpf.TaskbarNotification
}
}
/// <summary>
/// Displays a balloon tip with the specified title,
/// text, and a custom icon in the taskbar for the specified time period.
@@ -828,15 +843,21 @@ namespace Hardcodet.Wpf.TaskbarNotification
/// <param name="title">The title to display on the balloon tip.</param>
/// <param name="message">The text to display on the balloon tip.</param>
/// <param name="customIcon">A custom icon.</param>
/// <param name="largeIcon">True to allow large icons (Windows Vista and later).</param>
/// <exception cref="ArgumentNullException">If <paramref name="customIcon"/>
/// is a null reference.</exception>
public void ShowBalloonTip(string title, string message, Icon customIcon)
public void ShowBalloonTip(string title, string message, Icon customIcon, bool largeIcon = false)
{
if (customIcon == null) throw new ArgumentNullException("customIcon");
lock (this)
{
ShowBalloonTip(title, message, BalloonFlags.User, customIcon.Handle);
var flags = BalloonFlags.User;
if (largeIcon)
flags |= BalloonFlags.LargeIcon;
ShowBalloonTip(title, message, flags, customIcon.Handle);
}
}
@@ -998,34 +1019,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
#endregion
/// <summary>
/// Recalculates OS coordinates in order to support WPFs coordinate
/// system if OS scaling (DPIs) is not 100%.
/// </summary>
/// <param name="point"></param>
/// <returns></returns>
private Point GetDeviceCoordinates(Point point)
{
if (double.IsNaN(scalingFactor))
{
//calculate scaling factor in order to support non-standard DPIs
var presentationSource = PresentationSource.FromVisual(this);
if (presentationSource == null)
{
scalingFactor = 1;
}
else
{
var transform = presentationSource.CompositionTarget.TransformToDevice;
scalingFactor = 1/transform.M11;
}
}
//on standard DPI settings, just return the point
if (scalingFactor == 1.0) return point;
return new Point() {X = (int) (point.X*scalingFactor), Y = (int) (point.Y*scalingFactor)};
}
#region Dispose / Exit