/// <summary> /// A <see cref="System.Threading.TimerCallback"/> method invoked to monitor mouse position. /// </summary> /// <remarks> /// Called every 100ms so long as the mouse does not move. /// If the mouse moves, fire the parent TrayIcon's MouseLeave event and changes state to MouseOut. /// </remarks> /// <param name="state"></param> private void MouseMonitor(object state) { lock (SyncLock) { // We may have multiple callbacks pending because the threads in the threadpool were busy waiting for our requests to CCP // As a result, they're going to execute one after the other one, raising ObjectDisposedException when trying to stops the timer if (m_timer == null) { return; } if (Control.MousePosition == MousePosition) { // Mouse hasn't moved so check back in 100ms m_timer.Change(100, Timeout.Infinite); return; } // Mouse has moved, and since we're tracking it over the icon this means its moved away // Dispose of the timer since we're done with it Dispose(); // Switch of mouse tracking DisableMouseTracking(); // Fire the MouseLeave event TrayIcon.OnMouseLeave(new EventArgs()); // Change to MouseOut state ChangeState(States.MouseOut); } }
/// <summary> /// Initialises a new instance of the <see cref="MouseState"/> class with the given trayIcon and mousePosition. /// </summary> /// <param name="trayIcon">The <see cref="TrayIcon"/> whose state is being managed.</param> /// <param name="mousePosition">A <see cref="System.Drawing.Point"/> representing the last known mouse location.</param> public MouseStateHovering(TrayIcon trayIcon, Point mousePosition) : base(trayIcon, mousePosition) { // Fire the MouseHover event TrayIcon.OnMouseHover(new EventArgs()); // Lock the syncLock to make sure the timer is initialised before mouse events are handled lock (SyncLock) { // Start the timer to monitor mouse position m_timer = new Timer(MouseMonitor, null, 100, Timeout.Infinite); // Start tracking the mouse EnableMouseTracking(); } }
/// <summary> /// Initialises a new instance of the <see cref="MouseState"/> class with the given trayIcon and mousePosition. /// </summary> /// <param name="trayIcon">The <see cref="TrayIcon"/> whose state is being managed.</param> /// <param name="mousePosition">A <see cref="System.Drawing.Point"/> representing the last known mouse location.</param> public MouseStateOver(TrayIcon trayIcon, Point mousePosition) : base(trayIcon, mousePosition) { // Store the existing icon text, then reset it if popups aren't disabled trayIcon.m_iconText = trayIcon.notifyIcon.Text; if (Settings.UI.SystemTrayPopup.Style != TrayPopupStyles.Disabled) { trayIcon.notifyIcon.Text = string.Empty; } // Start the timer and enable mouse tracking // Lock the syncLock since we don't know the timeout value and need to ensure // initialisation completes before the timeout occurs lock (SyncLock) { // Start the hover timer m_timer = new Timer(HoverTimeout, null, TrayIcon.m_mouseHoverTime, Timeout.Infinite); // Start tracking the mouse EnableMouseTracking(); } }
/// <summary> /// Initializes a new instance of the <see cref="TrayIcon.MouseStateOut"/> class for a given trayIcon. /// </summary> /// <param name="trayIcon">A <see cref="TrayIcon"/> whose state we are managing.</param> public MouseStateOut(TrayIcon trayIcon) : base(trayIcon, new Point(0, 0)) { EnableMouseTracking(); }
/// <summary> /// Initialises a new instance of the <see cref="MouseState"/> class with the given trayIcon and mousePosition. /// </summary> /// <param name="trayIcon">The <see cref="TrayIcon"/> whose state is being managed.</param> /// <param name="mousePosition">A <see cref="System.Drawing.Point"/> representing the last known mouse location.</param> protected MouseState(TrayIcon trayIcon, Point mousePosition) { TrayIcon = trayIcon; MousePosition = mousePosition; }
/// <summary> /// Initialises a new instance of the <see cref="MouseState"/> class with the given trayIcon and mousePosition. /// </summary> /// <param name="trayIcon">The <see cref="TrayIcon"/> whose state is being managed.</param> /// <param name="mousePosition">A <see cref="System.Drawing.Point"/> representing the last known mouse location.</param> public MouseStateOver(TrayIcon trayIcon, Point mousePosition) : base(trayIcon, mousePosition) { // Store the existing icon text, then reset it if popups aren't disabled trayIcon.m_iconText = trayIcon.notifyIcon.Text; if (Settings.UI.SystemTrayPopup.Style != TrayPopupStyles.Disabled) trayIcon.notifyIcon.Text = String.Empty; // Start the timer and enable mouse tracking // Lock the syncLock since we don't know the timeout value and need to ensure // initialisation completes before the timeout occurs lock (SyncLock) { // Start the hover timer m_timer = new Timer(HoverTimeout, null, TrayIcon.m_mouseHoverTime, Timeout.Infinite); // Start tracking the mouse EnableMouseTracking(); } }