1
1
using System . Drawing ;
2
+ using EventGenerator ;
2
3
using H . NotifyIcon . Interop ;
3
4
4
5
namespace H . NotifyIcon . Core ;
@@ -13,7 +14,23 @@ namespace H.NotifyIcon.Core;
13
14
#else
14
15
#error Target Framework is not supported
15
16
#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
17
34
{
18
35
#region Constants
19
36
@@ -76,44 +93,6 @@ public class MessageWindow : IDisposable
76
93
77
94
#endregion
78
95
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
-
117
96
#region Constructors
118
97
119
98
/// <summary>
@@ -179,7 +158,7 @@ private LRESULT OnWindowMessageReceived(
179
158
if ( msg == TaskbarRestartMessageId )
180
159
{
181
160
//recreate the icon if the taskbar was restarted (e.g. due to Win Explorer shutdown)
182
- TaskbarCreated ? . Invoke ( this , EventArgs . Empty ) ;
161
+ _ = OnTaskbarCreated ( ) ;
183
162
}
184
163
185
164
ProcessWindowMessage ( msg , wParam , lParam ) ;
@@ -199,7 +178,7 @@ private void ProcessWindowMessage(uint msg, WPARAM wParam, LPARAM lParam)
199
178
switch ( msg )
200
179
{
201
180
case PInvoke . WM_DPICHANGED :
202
- DpiChanged ? . Invoke ( this , EventArgs . Empty ) ;
181
+ _ = OnDpiChanged ( ) ;
203
182
break ;
204
183
}
205
184
return ;
@@ -215,81 +194,81 @@ private void ProcessWindowMessage(uint msg, WPARAM wParam, LPARAM lParam)
215
194
{
216
195
// Can come from both mouse and keyboard events
217
196
case PInvoke . WM_CONTEXTMENU :
218
- KeyboardEventReceived ? . Invoke ( this , new KeyboardTrayIconEventArgs ( KeyboardEvent . ContextMenu , point ) ) ;
197
+ _ = OnKeyboardEventReceived ( KeyboardEvent . ContextMenu , point ) ;
219
198
break ;
220
199
221
200
case PInvoke . WM_MOUSEMOVE :
222
- MouseEventReceived ? . Invoke ( this , new MouseTrayIconEventArgs ( MouseEvent . MouseMove , point ) ) ;
201
+ _ = OnMouseEventReceived ( MouseEvent . MouseMove , point ) ;
223
202
break ;
224
203
225
204
case PInvoke . WM_LBUTTONDOWN :
226
- MouseEventReceived ? . Invoke ( this , new MouseTrayIconEventArgs ( MouseEvent . IconLeftMouseDown , point ) ) ;
205
+ _ = OnMouseEventReceived ( MouseEvent . IconLeftMouseDown , point ) ;
227
206
break ;
228
207
229
208
case PInvoke . WM_LBUTTONUP :
230
209
if ( ! IsDoubleClick )
231
210
{
232
- MouseEventReceived ? . Invoke ( this , new MouseTrayIconEventArgs ( MouseEvent . IconLeftMouseUp , point ) ) ;
211
+ _ = OnMouseEventReceived ( MouseEvent . IconLeftMouseUp , point ) ;
233
212
}
234
213
IsDoubleClick = false ;
235
214
break ;
236
215
237
216
case PInvoke . WM_LBUTTONDBLCLK :
238
217
IsDoubleClick = true ;
239
- MouseEventReceived ? . Invoke ( this , new MouseTrayIconEventArgs ( MouseEvent . IconDoubleClick , point ) ) ;
218
+ _ = OnMouseEventReceived ( MouseEvent . IconDoubleClick , point ) ;
240
219
break ;
241
220
242
221
case PInvoke . WM_RBUTTONDOWN :
243
- MouseEventReceived ? . Invoke ( this , new MouseTrayIconEventArgs ( MouseEvent . IconRightMouseDown , point ) ) ;
222
+ _ = OnMouseEventReceived ( MouseEvent . IconRightMouseDown , point ) ;
244
223
break ;
245
224
246
225
case PInvoke . WM_RBUTTONUP :
247
- MouseEventReceived ? . Invoke ( this , new MouseTrayIconEventArgs ( MouseEvent . IconRightMouseUp , point ) ) ;
226
+ _ = OnMouseEventReceived ( MouseEvent . IconRightMouseUp , point ) ;
248
227
break ;
249
228
250
229
case PInvoke . WM_RBUTTONDBLCLK :
251
230
//double click with right mouse button - do not trigger event
252
231
break ;
253
232
254
233
case PInvoke . WM_MBUTTONDOWN :
255
- MouseEventReceived ? . Invoke ( this , new MouseTrayIconEventArgs ( MouseEvent . IconMiddleMouseDown , point ) ) ;
234
+ _ = OnMouseEventReceived ( MouseEvent . IconMiddleMouseDown , point ) ;
256
235
break ;
257
236
258
237
case PInvoke . WM_MBUTTONUP :
259
- MouseEventReceived ? . Invoke ( this , new MouseTrayIconEventArgs ( MouseEvent . IconMiddleMouseUp , point ) ) ;
238
+ _ = OnMouseEventReceived ( MouseEvent . IconMiddleMouseUp , point ) ;
260
239
break ;
261
240
262
241
case PInvoke . WM_MBUTTONDBLCLK :
263
242
//double click with middle mouse button - do not trigger event
264
243
break ;
265
244
266
245
case PInvoke . NIN_BALLOONSHOW :
267
- BalloonToolTipChanged ? . Invoke ( this , true ) ;
246
+ _ = OnBalloonToolTipChanged ( isVisible : true ) ;
268
247
break ;
269
248
270
249
case PInvoke . NIN_BALLOONHIDE :
271
250
case PInvoke . NIN_BALLOONTIMEOUT :
272
- BalloonToolTipChanged ? . Invoke ( this , false ) ;
251
+ _ = OnBalloonToolTipChanged ( isVisible : false ) ;
273
252
break ;
274
253
275
254
case PInvoke . NIN_BALLOONUSERCLICK :
276
- MouseEventReceived ? . Invoke ( this , new MouseTrayIconEventArgs ( MouseEvent . BalloonToolTipClicked , point ) ) ;
255
+ _ = OnMouseEventReceived ( MouseEvent . BalloonToolTipClicked , point ) ;
277
256
break ;
278
257
279
258
case PInvoke . NIN_POPUPOPEN :
280
- ChangeToolTipStateRequest ? . Invoke ( this , true ) ;
259
+ _ = OnChangeToolTipStateRequest ( isVisible : true ) ;
281
260
break ;
282
261
283
262
case PInvoke . NIN_POPUPCLOSE :
284
- ChangeToolTipStateRequest ? . Invoke ( this , false ) ;
263
+ _ = OnChangeToolTipStateRequest ( isVisible : false ) ;
285
264
break ;
286
265
287
266
case PInvoke . NIN_SELECT :
288
- KeyboardEventReceived ? . Invoke ( this , new KeyboardTrayIconEventArgs ( KeyboardEvent . Select , point ) ) ;
267
+ _ = OnKeyboardEventReceived ( KeyboardEvent . Select , point ) ;
289
268
break ;
290
269
291
270
case PInvoke . NIN_SELECT | PInvoke . NINF_KEY :
292
- KeyboardEventReceived ? . Invoke ( this , new KeyboardTrayIconEventArgs ( KeyboardEvent . KeySelect , point ) ) ;
271
+ _ = OnKeyboardEventReceived ( KeyboardEvent . KeySelect , point ) ;
293
272
break ;
294
273
295
274
default :
0 commit comments