Toasts – Diff between revs 35 and 40

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 35 Rev 40
Line 16... Line 16...
16 using System.Threading.Tasks; 16 using System.Threading.Tasks;
17 using System.Windows.Forms; 17 using System.Windows.Forms;
18 using TheArtOfDev.HtmlRenderer.WinForms; 18 using TheArtOfDev.HtmlRenderer.WinForms;
19 using Toasts.Properties; 19 using Toasts.Properties;
20 using static System.Windows.Forms.VisualStyles.VisualStyleElement; 20 using static System.Windows.Forms.VisualStyles.VisualStyleElement;
-   21 using static TheArtOfDev.HtmlRenderer.Adapters.RGraphicsPath;
-   22 using static Toasts.FormAnimator;
Line 21... Line 23...
21   23  
22 namespace Toasts 24 namespace Toasts
23 { 25 {
24 public partial class ToastForm : Form 26 public partial class ToastForm : Form
Line 27... Line 29...
27 29
Line 28... Line 30...
28 public bool EnableChime { get; set; } = true; 30 public bool EnableChime { get; set; } = true;
Line -... Line 31...
-   31  
-   32 public int LingerTime { get; set; } = 5000;
-   33  
-   34 public FormAnimator.AnimationMethod AnimationMethodDetached { get; set; } = FormAnimator.AnimationMethod.Fade;
29   35  
Line 30... Line 36...
30 public int LingerTime { get; set; } = 5000; 36 public FormAnimator.AnimationDirection AnimationDirectionDetached { get; set; } = FormAnimator.AnimationDirection.None;
Line 31... Line 37...
31   37  
Line 76... Line 82...
76   82  
Line 77... Line 83...
77 private static readonly HashSet<ToastForm> OpenNotifications = new HashSet<ToastForm>(); 83 private static readonly HashSet<ToastForm> OpenNotifications = new HashSet<ToastForm>();
Line -... Line 84...
-   84  
-   85 #endregion
-   86  
-   87 #region Private Fields and Properties
-   88  
-   89 private bool _toastDetached;
-   90 private object _toastDetachedLock = new object();
-   91 private bool _mouseDown;
-   92 private Point _lastLocation;
78   93  
Line 79... Line 94...
79 #endregion 94 #endregion
80   95  
81 #region Private Overrides 96 #region Private Overrides
82   97  
83 protected override bool ShowWithoutActivation => true; 98 protected override bool ShowWithoutActivation => true;
Line 84... Line 99...
84 protected override CreateParams CreateParams 99 protected override CreateParams CreateParams
Line 85... Line 100...
85 { 100 {
86 get 101 get
87 { 102 {
88 103
Line 89... Line 104...
89 var baseParams = base.CreateParams; 104 var baseParams = base.CreateParams;
90 105
91 const int WS_EX_NOACTIVATE = 0x08000000; 106 //const int WS_EX_NOACTIVATE = 0x08000000;
Line 92... Line -...
92 const int WS_EX_TOOLWINDOW = 0x00000080; -  
-   107 const int WS_EX_TOOLWINDOW = 0x00000080;
-   108 const int WS_EX_TOPMOST = 0x00000008;
Line 93... Line 109...
93 const int WS_EX_TOPMOST = 0x00000008; 109 baseParams.ExStyle |= WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
Line 94... Line 110...
94 baseParams.ExStyle |= WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST; 110
Line 353... Line 369...
353 if (IsDisposed) 369 if (IsDisposed)
354 { 370 {
355 return; 371 return;
356 } 372 }
Line -... Line 373...
-   373  
-   374 lock(_toastDetachedLock)
-   375 {
-   376 if(_toastDetached)
-   377 {
-   378 return;
-   379 }
-   380 }
357   381  
358 try 382 try
359 { 383 {
-   384 _toastTimer.Stop();
360 _toastTimer.Stop(); 385  
361 BeginInvoke(new MethodInvoker(() => 386 BeginInvoke(new MethodInvoker(() =>
362 { 387 {
363 lock (OpenNotificationsLock) 388 lock (OpenNotificationsLock)
364 { 389 {
Line 370... Line 395...
370 { 395 {
371 Debug.WriteLine("Error in timer elapsed event."); 396 Debug.WriteLine("Error in timer elapsed event.");
372 } 397 }
373 } 398 }
Line -... Line 399...
-   399  
-   400 private void labelTitle_MouseDown(object sender, MouseEventArgs e)
-   401 {
-   402 _mouseDown = true;
-   403 _lastLocation = e.Location;
-   404 }
-   405  
-   406 private void labelTitle_MouseMove(object sender, MouseEventArgs e)
-   407 {
-   408 if (!_mouseDown)
-   409 {
-   410 return;
-   411  
-   412 }
-   413  
-   414 Location = new Point((Location.X - _lastLocation.X) + e.X, (Location.Y - _lastLocation.Y) + e.Y);
-   415  
-   416 Update();
-   417  
-   418 lock (_toastDetachedLock)
-   419 {
-   420 if (_toastDetached)
-   421 {
-   422 return;
-   423 }
-   424  
-   425 _toastDetached = true;
-   426  
-   427 _toastTimer.Elapsed -= ToastTimer_Elapsed;
-   428 _toastTimer.Stop();
-   429 _toastTimer.Dispose();
-   430  
-   431 BeginInvoke(new MethodInvoker(() =>
-   432 {
-   433 lock (OpenNotificationsLock)
-   434 {
-   435 if (OpenNotifications.Contains(this))
-   436 {
-   437 OpenNotifications.Remove(this);
-   438 }
-   439 }
-   440 }));
-   441  
-   442 // remove top-most
-   443 SetWindowPos(Handle, -2, 0, 0, 0, 0, 0x0001 | 0x0002);
-   444  
-   445 _formAnimator.Method = AnimationMethodDetached;
-   446 _formAnimator.Direction = AnimationDirectionDetached;
-   447 }
-   448 }
-   449  
-   450 private void labelTitle_MouseUp(object sender, MouseEventArgs e)
-   451 {
-   452 _mouseDown = false;
-   453 }
-   454  
-   455  
-   456 #endregion
374   457  
375 private void Toast_Click(object sender, EventArgs e) 458 private void panel1_Click(object sender, EventArgs e)
376 { 459 {
377 try 460 try
378 { 461 {
379 BeginInvoke(new MethodInvoker(() => 462 BeginInvoke(new MethodInvoker(() =>
Line 388... Line 471...
388 { 471 {
389 Debug.WriteLine("Error in form click event."); 472 Debug.WriteLine("Error in form click event.");
390 } 473 }
391 } 474 }
Line 392... Line -...
392   -  
393 #endregion -  
394   475  
395 private void htmlPanel1_TextChanged(object sender, EventArgs e) 476 private void Toast_Click(object sender, EventArgs e)
-   477 {
-   478 lock (_toastDetachedLock)
-   479 {
-   480 if(!_toastDetached)
-   481 {
-   482 return;
Line -... Line 483...
-   483 }
-   484  
396 { 485 BringToFront();
397   486 }
398 } 487 }
399 } 488 }