Skip to content

Commit

Permalink
Merge pull request #1 from iterate-ch/bugfix/upstream-95
Browse files Browse the repository at this point in the history
Fix tooltip positioning issue (hardcodet#106)
  • Loading branch information
exomkeuck authored Jul 17, 2024
2 parents 4004e88 + c08e179 commit c020b6d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/NotifyIconWpf/TaskbarIcon.Declarations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public Icon Icon
icon = value;
iconData.IconHandle = value == null ? IntPtr.Zero : icon.Handle;

Util.WriteIconData(ref iconData, NotifyCommand.Modify, IconDataMembers.Icon);
Util.WriteIconData(ref iconData, NotifyCommand.Modify, WithTrayToolTip(IconDataMembers.Icon));
}
}

Expand Down
39 changes: 26 additions & 13 deletions src/NotifyIconWpf/TaskbarIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public partial class TaskbarIcon : FrameworkElement, IDisposable
/// </summary>
public bool SupportsCustomToolTips => messageSink.Version == NotifyIconVersion.Vista;

/// <summary>
/// Indicates that ToolTipText should be displayed.
/// </summary>
private bool showSystemToolTip = false;


/// <summary>
/// Checks whether a non-tooltip popup is currently opened.
Expand Down Expand Up @@ -554,14 +559,6 @@ private void CreateCustomToolTip()
Content = TrayToolTip
};
}
else if (tt == null && !string.IsNullOrEmpty(ToolTipText))
{
// create a simple tooltip for the ToolTipText string
tt = new ToolTip
{
Content = ToolTipText
};
}

// the tooltip explicitly gets the DataContext of this instance.
// If there is no DataContext, the TaskbarIcon assigns itself
Expand All @@ -574,6 +571,21 @@ private void CreateCustomToolTip()
SetTrayToolTipResolved(tt);
}

/// <summary>
/// Shell_NotifyIcon requires NIF_SHOWTIP to be specified for every call to Shell_NotifyIcon.
/// This modifies <paramref name="flags"/> to include this if required.
/// </summary>
/// <param name="flags">Passed through flags fo Shell_NotifyIcon.</param>
/// <returns>Flags amended with NIF_SHOWTIP if required.</returns>
private IconDataMembers WithTrayToolTip(IconDataMembers flags)
{
if (showSystemToolTip)
{
flags |= IconDataMembers.UseLegacyToolTips;
}

return flags;
}

/// <summary>
/// Sets tooltip settings for the class depending on defined
Expand All @@ -583,6 +595,7 @@ private void WriteToolTipSettings()
{
const IconDataMembers flags = IconDataMembers.Tip;
iconData.ToolTipText = ToolTipText;
showSystemToolTip = TrayToolTip is null;

if (messageSink.Version == NotifyIconVersion.Vista)
{
Expand All @@ -597,7 +610,7 @@ private void WriteToolTipSettings()
}

// update the tooltip text
Util.WriteIconData(ref iconData, NotifyCommand.Modify, flags);
Util.WriteIconData(ref iconData, NotifyCommand.Modify, WithTrayToolTip(flags));
}

#endregion
Expand Down Expand Up @@ -871,7 +884,7 @@ private void ShowBalloonTip(string title, string message, BalloonFlags flags, In

iconData.BalloonFlags = flags;
iconData.CustomBalloonIconHandle = balloonIconHandle;
Util.WriteIconData(ref iconData, NotifyCommand.Modify, IconDataMembers.Info | IconDataMembers.Icon);
Util.WriteIconData(ref iconData, NotifyCommand.Modify, WithTrayToolTip(IconDataMembers.Info | IconDataMembers.Icon));
}


Expand All @@ -884,7 +897,7 @@ public void HideBalloonTip()

// reset balloon by just setting the info to an empty string
iconData.BalloonText = iconData.BalloonTitle = string.Empty;
Util.WriteIconData(ref iconData, NotifyCommand.Modify, IconDataMembers.Info);
Util.WriteIconData(ref iconData, NotifyCommand.Modify, WithTrayToolTip(IconDataMembers.Info));
}

#endregion
Expand Down Expand Up @@ -975,7 +988,7 @@ private void CreateTaskbarIcon()
| IconDataMembers.Tip;

//write initial configuration
var status = Util.WriteIconData(ref iconData, NotifyCommand.Add, members);
var status = Util.WriteIconData(ref iconData, NotifyCommand.Add, WithTrayToolTip(members));
if (!status)
{
// couldn't create the icon - we can assume this is because explorer is not running (yet!)
Expand Down Expand Up @@ -1007,7 +1020,7 @@ private void RemoveTaskbarIcon()
return;
}

Util.WriteIconData(ref iconData, NotifyCommand.Delete, IconDataMembers.Message);
Util.WriteIconData(ref iconData, NotifyCommand.Delete, WithTrayToolTip(IconDataMembers.Message));
IsTaskbarIconCreated = false;
}
}
Expand Down

0 comments on commit c020b6d

Please sign in to comment.