Skip to content

Commit aa3725b

Browse files
committed
feat: Updated EventGenerator.
1 parent cab6216 commit aa3725b

11 files changed

+52
-171
lines changed

src/libs/H.NotifyIcon.Shared/TaskbarIcon.KeyboardEvents.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public partial class TaskbarIcon
1818
/// </summary>
1919
/// <param name="sender"></param>
2020
/// <param name="args">Keyboard event args</param>
21-
private void OnKeyboardEvent(object? sender, KeyboardTrayIconEventArgs args)
21+
private void OnKeyboardEvent(object? sender, MessageWindow.KeyboardEventReceivedEventArgs args)
2222
{
2323
if (IsDisposed)
2424
{

src/libs/H.NotifyIcon.Shared/TaskbarIcon.MouseEvents.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public partial class TaskbarIcon
6565
/// </summary>
6666
/// <param name="sender"></param>
6767
/// <param name="args">Mouse event args.</param>
68-
private void OnMouseEvent(object? sender, MouseTrayIconEventArgs args)
68+
private void OnMouseEvent(object? sender, MessageWindow.MouseEventReceivedEventArgs args)
6969
{
7070
if (IsDisposed)
7171
{

src/libs/H.NotifyIcon.Shared/TaskbarIcon.Notifications.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ public void ClearNotifications()
102102
/// Bubbles events if a balloon ToolTip was displayed
103103
/// or removed.
104104
/// </summary>
105-
/// <param name="visible">Whether the ToolTip was just displayed
105+
/// <param name="args">Whether the ToolTip was just displayed
106106
/// or removed.</param>
107107
/// <param name="sender"></param>
108-
private void OnBalloonToolTipChanged(object? sender, bool visible)
108+
private void OnBalloonToolTipChanged(object? sender, MessageWindow.BalloonToolTipChangedEventArgs args)
109109
{
110-
if (visible)
110+
if (args.IsVisible)
111111
{
112112
_ = OnTrayBalloonTipShown();
113113
}

src/libs/H.NotifyIcon.Shared/TaskbarIcon.ToolTips.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,24 +203,24 @@ private void WriteToolTipSettings()
203203
/// invoked for Windows Vista and above.
204204
/// </summary>
205205
/// <param name="sender"></param>
206-
/// <param name="visible">Whether to show or hide the tooltip.</param>
207-
private void OnToolTipChange(object? sender, bool visible)
206+
/// <param name="args">Whether to show or hide the tooltip.</param>
207+
private void OnToolTipChange(object? sender, MessageWindow.ChangeToolTipStateRequestEventArgs args)
208208
{
209209
if (TrayToolTipResolved == null)
210210
{
211211
return;
212212
}
213213

214-
if (visible)
214+
if (args.IsVisible)
215215
{
216216
if (IsPopupOpen)
217217
{
218218
return;
219219
}
220220

221-
var args = OnPreviewTrayToolTipOpen();
221+
var previewArgs = OnPreviewTrayToolTipOpen();
222222
#if HAS_WPF
223-
if (args.Handled)
223+
if (previewArgs.Handled)
224224
{
225225
return;
226226
}
@@ -244,9 +244,9 @@ private void OnToolTipChange(object? sender, bool visible)
244244
}
245245
else
246246
{
247-
var args = OnPreviewTrayToolTipClose();
247+
var previewArgs = OnPreviewTrayToolTipClose();
248248
#if HAS_WPF
249-
if (args.Handled)
249+
if (previewArgs.Handled)
250250
{
251251
return;
252252
}

src/libs/H.NotifyIcon/Core/MessageWindow.cs

Lines changed: 36 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Drawing;
2+
using EventGenerator;
23
using H.NotifyIcon.Interop;
34

45
namespace H.NotifyIcon.Core;
@@ -13,7 +14,23 @@ namespace H.NotifyIcon.Core;
1314
#else
1415
#error Target Framework is not supported
1516
#endif
16-
public class MessageWindow : IDisposable
17+
[Event<bool>("ChangeToolTipStateRequest",
18+
Description = "The custom tooltip should be closed or hidden.",
19+
PropertyNames = new[] { "IsVisible" })]
20+
[Event<MouseEvent, Point>("MouseEventReceived",
21+
Description = "Fired in case the user clicked or moved within the taskbar icon area.",
22+
PropertyNames = new[] { "MouseEvent", "Point" })]
23+
[Event<KeyboardEvent, Point>("KeyboardEventReceived",
24+
Description = "Fired in case the user interacted with the taskbar icon area with keyboard shortcuts.",
25+
PropertyNames = new[] { "KeyboardEvent", "Point" })]
26+
[Event<bool>("BalloonToolTipChanged",
27+
Description = "Fired if a balloon ToolTip was either displayed or closed (indicated by the boolean flag).",
28+
PropertyNames = new[] { "IsVisible" })]
29+
[Event("TaskbarCreated",
30+
Description = "Fired if the taskbar was created or restarted. Requires the taskbar icon to be reset")]
31+
[Event("DpiChanged",
32+
Description = "Fired if dpi change window message received.")]
33+
public partial class MessageWindow : IDisposable
1734
{
1835
#region Constants
1936

@@ -76,44 +93,6 @@ public class MessageWindow : IDisposable
7693

7794
#endregion
7895

79-
#region Events
80-
81-
/// <summary>
82-
/// The custom tooltip should be closed or hidden.
83-
/// </summary>
84-
public event EventHandler<bool>? ChangeToolTipStateRequest;
85-
86-
/// <summary>
87-
/// Fired in case the user clicked or moved within
88-
/// the taskbar icon area.
89-
/// </summary>
90-
public event EventHandler<MouseTrayIconEventArgs>? MouseEventReceived;
91-
92-
/// <summary>
93-
/// Fired in case the user interacted with the taskbar
94-
/// icon area with keyboard shortcuts.
95-
/// </summary>
96-
public event EventHandler<KeyboardTrayIconEventArgs>? KeyboardEventReceived;
97-
98-
/// <summary>
99-
/// Fired if a balloon ToolTip was either displayed
100-
/// or closed (indicated by the boolean flag).
101-
/// </summary>
102-
public event EventHandler<bool>? BalloonToolTipChanged;
103-
104-
/// <summary>
105-
/// Fired if the taskbar was created or restarted. Requires the taskbar
106-
/// icon to be reset.
107-
/// </summary>
108-
public event EventHandler? TaskbarCreated;
109-
110-
/// <summary>
111-
/// Fired if dpi change window message received.
112-
/// </summary>
113-
public event EventHandler? DpiChanged;
114-
115-
#endregion
116-
11796
#region Constructors
11897

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

185164
ProcessWindowMessage(msg, wParam, lParam);
@@ -199,7 +178,7 @@ private void ProcessWindowMessage(uint msg, WPARAM wParam, LPARAM lParam)
199178
switch (msg)
200179
{
201180
case PInvoke.WM_DPICHANGED:
202-
DpiChanged?.Invoke(this, EventArgs.Empty);
181+
_ = OnDpiChanged();
203182
break;
204183
}
205184
return;
@@ -215,81 +194,81 @@ private void ProcessWindowMessage(uint msg, WPARAM wParam, LPARAM lParam)
215194
{
216195
// Can come from both mouse and keyboard events
217196
case PInvoke.WM_CONTEXTMENU:
218-
KeyboardEventReceived?.Invoke(this, new KeyboardTrayIconEventArgs(KeyboardEvent.ContextMenu, point));
197+
_ = OnKeyboardEventReceived(KeyboardEvent.ContextMenu, point);
219198
break;
220199

221200
case PInvoke.WM_MOUSEMOVE:
222-
MouseEventReceived?.Invoke(this, new MouseTrayIconEventArgs(MouseEvent.MouseMove, point));
201+
_ = OnMouseEventReceived(MouseEvent.MouseMove, point);
223202
break;
224203

225204
case PInvoke.WM_LBUTTONDOWN:
226-
MouseEventReceived?.Invoke(this, new MouseTrayIconEventArgs(MouseEvent.IconLeftMouseDown, point));
205+
_ = OnMouseEventReceived(MouseEvent.IconLeftMouseDown, point);
227206
break;
228207

229208
case PInvoke.WM_LBUTTONUP:
230209
if (!IsDoubleClick)
231210
{
232-
MouseEventReceived?.Invoke(this, new MouseTrayIconEventArgs(MouseEvent.IconLeftMouseUp, point));
211+
_ = OnMouseEventReceived(MouseEvent.IconLeftMouseUp, point);
233212
}
234213
IsDoubleClick = false;
235214
break;
236215

237216
case PInvoke.WM_LBUTTONDBLCLK:
238217
IsDoubleClick = true;
239-
MouseEventReceived?.Invoke(this, new MouseTrayIconEventArgs(MouseEvent.IconDoubleClick, point));
218+
_ = OnMouseEventReceived(MouseEvent.IconDoubleClick, point);
240219
break;
241220

242221
case PInvoke.WM_RBUTTONDOWN:
243-
MouseEventReceived?.Invoke(this, new MouseTrayIconEventArgs(MouseEvent.IconRightMouseDown, point));
222+
_ = OnMouseEventReceived(MouseEvent.IconRightMouseDown, point);
244223
break;
245224

246225
case PInvoke.WM_RBUTTONUP:
247-
MouseEventReceived?.Invoke(this, new MouseTrayIconEventArgs(MouseEvent.IconRightMouseUp, point));
226+
_ = OnMouseEventReceived(MouseEvent.IconRightMouseUp, point);
248227
break;
249228

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

254233
case PInvoke.WM_MBUTTONDOWN:
255-
MouseEventReceived?.Invoke(this, new MouseTrayIconEventArgs(MouseEvent.IconMiddleMouseDown, point));
234+
_ = OnMouseEventReceived(MouseEvent.IconMiddleMouseDown, point);
256235
break;
257236

258237
case PInvoke.WM_MBUTTONUP:
259-
MouseEventReceived?.Invoke(this, new MouseTrayIconEventArgs(MouseEvent.IconMiddleMouseUp, point));
238+
_ = OnMouseEventReceived(MouseEvent.IconMiddleMouseUp, point);
260239
break;
261240

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

266245
case PInvoke.NIN_BALLOONSHOW:
267-
BalloonToolTipChanged?.Invoke(this, true);
246+
_ = OnBalloonToolTipChanged(isVisible: true);
268247
break;
269248

270249
case PInvoke.NIN_BALLOONHIDE:
271250
case PInvoke.NIN_BALLOONTIMEOUT:
272-
BalloonToolTipChanged?.Invoke(this, false);
251+
_ = OnBalloonToolTipChanged(isVisible: false);
273252
break;
274253

275254
case PInvoke.NIN_BALLOONUSERCLICK:
276-
MouseEventReceived?.Invoke(this, new MouseTrayIconEventArgs(MouseEvent.BalloonToolTipClicked, point));
255+
_ = OnMouseEventReceived(MouseEvent.BalloonToolTipClicked, point);
277256
break;
278257

279258
case PInvoke.NIN_POPUPOPEN:
280-
ChangeToolTipStateRequest?.Invoke(this, true);
259+
_ = OnChangeToolTipStateRequest(isVisible: true);
281260
break;
282261

283262
case PInvoke.NIN_POPUPCLOSE:
284-
ChangeToolTipStateRequest?.Invoke(this, false);
263+
_ = OnChangeToolTipStateRequest(isVisible: false);
285264
break;
286265

287266
case PInvoke.NIN_SELECT:
288-
KeyboardEventReceived?.Invoke(this, new KeyboardTrayIconEventArgs(KeyboardEvent.Select, point));
267+
_ = OnKeyboardEventReceived(KeyboardEvent.Select, point);
289268
break;
290269

291270
case PInvoke.NIN_SELECT | PInvoke.NINF_KEY:
292-
KeyboardEventReceived?.Invoke(this, new KeyboardTrayIconEventArgs(KeyboardEvent.KeySelect, point));
271+
_ = OnKeyboardEventReceived(KeyboardEvent.KeySelect, point);
293272
break;
294273

295274
default:

src/libs/H.NotifyIcon/Core/TrayIcon.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace H.NotifyIcon.Core;
2727
[Event<IconVersion>("VersionChanged", Description = @"Version was changed.
2828
This can happen in the following cases:
2929
- Via direct Create call
30-
- Through the ClearNotifications call since its implementation uses TrayIcon re-creation")]
30+
- Through the ClearNotifications call since its implementation uses TrayIcon re-creation", PropertyNames = new[] { "Version" })]
3131
public partial class TrayIcon : IDisposable
3232
{
3333
#region Properties

src/libs/H.NotifyIcon/EventArgs/KeyboardTrayIconEventArgs.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/libs/H.NotifyIcon/EventArgs/MouseTrayIconEventArgs.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/libs/H.NotifyIcon/EventArgs/TrayIconEventArgs.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/libs/H.NotifyIcon/H.NotifyIcon.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>net4.5.1;netstandard2.0;net6.0</TargetFrameworks>
5-
<NoWarn>$(NoWarn);CA1031;CA1003;CA1502</NoWarn>
5+
<NoWarn>$(NoWarn);CA1031;CA1003;CA1502;CS3016</NoWarn>
66
</PropertyGroup>
77

88
<ItemGroup>
@@ -20,7 +20,7 @@
2020
</ItemGroup>
2121

2222
<ItemGroup>
23-
<PackageReference Include="EventGenerator.Generator" Version="0.4.2">
23+
<PackageReference Include="EventGenerator.Generator" Version="0.9.0">
2424
<PrivateAssets>all</PrivateAssets>
2525
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2626
</PackageReference>

0 commit comments

Comments
 (0)