Skip to content

Commit

Permalink
feat: Updated EventGenerator.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Jan 5, 2023
1 parent cab6216 commit aa3725b
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 171 deletions.
2 changes: 1 addition & 1 deletion src/libs/H.NotifyIcon.Shared/TaskbarIcon.KeyboardEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public partial class TaskbarIcon
/// </summary>
/// <param name="sender"></param>
/// <param name="args">Keyboard event args</param>
private void OnKeyboardEvent(object? sender, KeyboardTrayIconEventArgs args)
private void OnKeyboardEvent(object? sender, MessageWindow.KeyboardEventReceivedEventArgs args)
{
if (IsDisposed)
{
Expand Down
2 changes: 1 addition & 1 deletion src/libs/H.NotifyIcon.Shared/TaskbarIcon.MouseEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public partial class TaskbarIcon
/// </summary>
/// <param name="sender"></param>
/// <param name="args">Mouse event args.</param>
private void OnMouseEvent(object? sender, MouseTrayIconEventArgs args)
private void OnMouseEvent(object? sender, MessageWindow.MouseEventReceivedEventArgs args)
{
if (IsDisposed)
{
Expand Down
6 changes: 3 additions & 3 deletions src/libs/H.NotifyIcon.Shared/TaskbarIcon.Notifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ public void ClearNotifications()
/// Bubbles events if a balloon ToolTip was displayed
/// or removed.
/// </summary>
/// <param name="visible">Whether the ToolTip was just displayed
/// <param name="args">Whether the ToolTip was just displayed
/// or removed.</param>
/// <param name="sender"></param>
private void OnBalloonToolTipChanged(object? sender, bool visible)
private void OnBalloonToolTipChanged(object? sender, MessageWindow.BalloonToolTipChangedEventArgs args)
{
if (visible)
if (args.IsVisible)
{
_ = OnTrayBalloonTipShown();
}
Expand Down
14 changes: 7 additions & 7 deletions src/libs/H.NotifyIcon.Shared/TaskbarIcon.ToolTips.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,24 +203,24 @@ private void WriteToolTipSettings()
/// invoked for Windows Vista and above.
/// </summary>
/// <param name="sender"></param>
/// <param name="visible">Whether to show or hide the tooltip.</param>
private void OnToolTipChange(object? sender, bool visible)
/// <param name="args">Whether to show or hide the tooltip.</param>
private void OnToolTipChange(object? sender, MessageWindow.ChangeToolTipStateRequestEventArgs args)
{
if (TrayToolTipResolved == null)
{
return;
}

if (visible)
if (args.IsVisible)
{
if (IsPopupOpen)
{
return;
}

var args = OnPreviewTrayToolTipOpen();
var previewArgs = OnPreviewTrayToolTipOpen();
#if HAS_WPF
if (args.Handled)
if (previewArgs.Handled)
{
return;
}
Expand All @@ -244,9 +244,9 @@ private void OnToolTipChange(object? sender, bool visible)
}
else
{
var args = OnPreviewTrayToolTipClose();
var previewArgs = OnPreviewTrayToolTipClose();
#if HAS_WPF
if (args.Handled)
if (previewArgs.Handled)
{
return;
}
Expand Down
93 changes: 36 additions & 57 deletions src/libs/H.NotifyIcon/Core/MessageWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Drawing;
using EventGenerator;
using H.NotifyIcon.Interop;

namespace H.NotifyIcon.Core;
Expand All @@ -13,7 +14,23 @@ namespace H.NotifyIcon.Core;
#else
#error Target Framework is not supported
#endif
public class MessageWindow : IDisposable
[Event<bool>("ChangeToolTipStateRequest",
Description = "The custom tooltip should be closed or hidden.",
PropertyNames = new[] { "IsVisible" })]
[Event<MouseEvent, Point>("MouseEventReceived",
Description = "Fired in case the user clicked or moved within the taskbar icon area.",
PropertyNames = new[] { "MouseEvent", "Point" })]
[Event<KeyboardEvent, Point>("KeyboardEventReceived",
Description = "Fired in case the user interacted with the taskbar icon area with keyboard shortcuts.",
PropertyNames = new[] { "KeyboardEvent", "Point" })]
[Event<bool>("BalloonToolTipChanged",
Description = "Fired if a balloon ToolTip was either displayed or closed (indicated by the boolean flag).",
PropertyNames = new[] { "IsVisible" })]
[Event("TaskbarCreated",
Description = "Fired if the taskbar was created or restarted. Requires the taskbar icon to be reset")]
[Event("DpiChanged",
Description = "Fired if dpi change window message received.")]
public partial class MessageWindow : IDisposable
{
#region Constants

Expand Down Expand Up @@ -76,44 +93,6 @@ public class MessageWindow : IDisposable

#endregion

#region Events

/// <summary>
/// The custom tooltip should be closed or hidden.
/// </summary>
public event EventHandler<bool>? ChangeToolTipStateRequest;

/// <summary>
/// Fired in case the user clicked or moved within
/// the taskbar icon area.
/// </summary>
public event EventHandler<MouseTrayIconEventArgs>? MouseEventReceived;

/// <summary>
/// Fired in case the user interacted with the taskbar
/// icon area with keyboard shortcuts.
/// </summary>
public event EventHandler<KeyboardTrayIconEventArgs>? KeyboardEventReceived;

/// <summary>
/// Fired if a balloon ToolTip was either displayed
/// or closed (indicated by the boolean flag).
/// </summary>
public event EventHandler<bool>? BalloonToolTipChanged;

/// <summary>
/// Fired if the taskbar was created or restarted. Requires the taskbar
/// icon to be reset.
/// </summary>
public event EventHandler? TaskbarCreated;

/// <summary>
/// Fired if dpi change window message received.
/// </summary>
public event EventHandler? DpiChanged;

#endregion

#region Constructors

/// <summary>
Expand Down Expand Up @@ -179,7 +158,7 @@ private LRESULT OnWindowMessageReceived(
if (msg == TaskbarRestartMessageId)
{
//recreate the icon if the taskbar was restarted (e.g. due to Win Explorer shutdown)
TaskbarCreated?.Invoke(this, EventArgs.Empty);
_ = OnTaskbarCreated();
}

ProcessWindowMessage(msg, wParam, lParam);
Expand All @@ -199,7 +178,7 @@ private void ProcessWindowMessage(uint msg, WPARAM wParam, LPARAM lParam)
switch (msg)
{
case PInvoke.WM_DPICHANGED:
DpiChanged?.Invoke(this, EventArgs.Empty);
_ = OnDpiChanged();
break;
}
return;
Expand All @@ -215,81 +194,81 @@ private void ProcessWindowMessage(uint msg, WPARAM wParam, LPARAM lParam)
{
// Can come from both mouse and keyboard events
case PInvoke.WM_CONTEXTMENU:
KeyboardEventReceived?.Invoke(this, new KeyboardTrayIconEventArgs(KeyboardEvent.ContextMenu, point));
_ = OnKeyboardEventReceived(KeyboardEvent.ContextMenu, point);
break;

case PInvoke.WM_MOUSEMOVE:
MouseEventReceived?.Invoke(this, new MouseTrayIconEventArgs(MouseEvent.MouseMove, point));
_ = OnMouseEventReceived(MouseEvent.MouseMove, point);
break;

case PInvoke.WM_LBUTTONDOWN:
MouseEventReceived?.Invoke(this, new MouseTrayIconEventArgs(MouseEvent.IconLeftMouseDown, point));
_ = OnMouseEventReceived(MouseEvent.IconLeftMouseDown, point);
break;

case PInvoke.WM_LBUTTONUP:
if (!IsDoubleClick)
{
MouseEventReceived?.Invoke(this, new MouseTrayIconEventArgs(MouseEvent.IconLeftMouseUp, point));
_ = OnMouseEventReceived(MouseEvent.IconLeftMouseUp, point);
}
IsDoubleClick = false;
break;

case PInvoke.WM_LBUTTONDBLCLK:
IsDoubleClick = true;
MouseEventReceived?.Invoke(this, new MouseTrayIconEventArgs(MouseEvent.IconDoubleClick, point));
_ = OnMouseEventReceived(MouseEvent.IconDoubleClick, point);
break;

case PInvoke.WM_RBUTTONDOWN:
MouseEventReceived?.Invoke(this, new MouseTrayIconEventArgs(MouseEvent.IconRightMouseDown, point));
_ = OnMouseEventReceived(MouseEvent.IconRightMouseDown, point);
break;

case PInvoke.WM_RBUTTONUP:
MouseEventReceived?.Invoke(this, new MouseTrayIconEventArgs(MouseEvent.IconRightMouseUp, point));
_ = OnMouseEventReceived(MouseEvent.IconRightMouseUp, point);
break;

case PInvoke.WM_RBUTTONDBLCLK:
//double click with right mouse button - do not trigger event
break;

case PInvoke.WM_MBUTTONDOWN:
MouseEventReceived?.Invoke(this, new MouseTrayIconEventArgs(MouseEvent.IconMiddleMouseDown, point));
_ = OnMouseEventReceived(MouseEvent.IconMiddleMouseDown, point);
break;

case PInvoke.WM_MBUTTONUP:
MouseEventReceived?.Invoke(this, new MouseTrayIconEventArgs(MouseEvent.IconMiddleMouseUp, point));
_ = OnMouseEventReceived(MouseEvent.IconMiddleMouseUp, point);
break;

case PInvoke.WM_MBUTTONDBLCLK:
//double click with middle mouse button - do not trigger event
break;

case PInvoke.NIN_BALLOONSHOW:
BalloonToolTipChanged?.Invoke(this, true);
_ = OnBalloonToolTipChanged(isVisible: true);
break;

case PInvoke.NIN_BALLOONHIDE:
case PInvoke.NIN_BALLOONTIMEOUT:
BalloonToolTipChanged?.Invoke(this, false);
_ = OnBalloonToolTipChanged(isVisible: false);
break;

case PInvoke.NIN_BALLOONUSERCLICK:
MouseEventReceived?.Invoke(this, new MouseTrayIconEventArgs(MouseEvent.BalloonToolTipClicked, point));
_ = OnMouseEventReceived(MouseEvent.BalloonToolTipClicked, point);
break;

case PInvoke.NIN_POPUPOPEN:
ChangeToolTipStateRequest?.Invoke(this, true);
_ = OnChangeToolTipStateRequest(isVisible: true);
break;

case PInvoke.NIN_POPUPCLOSE:
ChangeToolTipStateRequest?.Invoke(this, false);
_ = OnChangeToolTipStateRequest(isVisible: false);
break;

case PInvoke.NIN_SELECT:
KeyboardEventReceived?.Invoke(this, new KeyboardTrayIconEventArgs(KeyboardEvent.Select, point));
_ = OnKeyboardEventReceived(KeyboardEvent.Select, point);
break;

case PInvoke.NIN_SELECT | PInvoke.NINF_KEY:
KeyboardEventReceived?.Invoke(this, new KeyboardTrayIconEventArgs(KeyboardEvent.KeySelect, point));
_ = OnKeyboardEventReceived(KeyboardEvent.KeySelect, point);
break;

default:
Expand Down
2 changes: 1 addition & 1 deletion src/libs/H.NotifyIcon/Core/TrayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace H.NotifyIcon.Core;
[Event<IconVersion>("VersionChanged", Description = @"Version was changed.
This can happen in the following cases:
- Via direct Create call
- Through the ClearNotifications call since its implementation uses TrayIcon re-creation")]
- Through the ClearNotifications call since its implementation uses TrayIcon re-creation", PropertyNames = new[] { "Version" })]
public partial class TrayIcon : IDisposable
{
#region Properties
Expand Down
34 changes: 0 additions & 34 deletions src/libs/H.NotifyIcon/EventArgs/KeyboardTrayIconEventArgs.cs

This file was deleted.

34 changes: 0 additions & 34 deletions src/libs/H.NotifyIcon/EventArgs/MouseTrayIconEventArgs.cs

This file was deleted.

30 changes: 0 additions & 30 deletions src/libs/H.NotifyIcon/EventArgs/TrayIconEventArgs.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/libs/H.NotifyIcon/H.NotifyIcon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>net4.5.1;netstandard2.0;net6.0</TargetFrameworks>
<NoWarn>$(NoWarn);CA1031;CA1003;CA1502</NoWarn>
<NoWarn>$(NoWarn);CA1031;CA1003;CA1502;CS3016</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand All @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="EventGenerator.Generator" Version="0.4.2">
<PackageReference Include="EventGenerator.Generator" Version="0.9.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Loading

0 comments on commit aa3725b

Please sign in to comment.