/// <summary> /// Processes mouse events, which are bubbled /// through the class' routed events, trigger /// certain actions (e.g. show a popup), or /// both. /// </summary> /// <param name="me">Event flag.</param> private void OnMouseEvent(MouseEvent me) { if (IsDisposed) return; switch (me) { case MouseEvent.MouseMove: RaiseTrayMouseMoveEvent(); //immediately return - there's nothing left to evaluate return; case MouseEvent.IconRightMouseDown: RaiseTrayRightMouseDownEvent(); break; case MouseEvent.IconLeftMouseDown: RaiseTrayLeftMouseDownEvent(); break; case MouseEvent.IconRightMouseUp: RaiseTrayRightMouseUpEvent(); break; case MouseEvent.IconLeftMouseUp: RaiseTrayLeftMouseUpEvent(); break; case MouseEvent.IconMiddleMouseDown: RaiseTrayMiddleMouseDownEvent(); break; case MouseEvent.IconMiddleMouseUp: RaiseTrayMiddleMouseUpEvent(); break; case MouseEvent.IconDoubleClick: //cancel single click timer singleClickTimer.Change(Timeout.Infinite, Timeout.Infinite); //bubble event RaiseTrayMouseDoubleClickEvent(); break; case MouseEvent.BalloonToolTipClicked: RaiseTrayBalloonTipClickedEvent(); break; default: throw new ArgumentOutOfRangeException("me", "Missing handler for mouse event flag: " + me); } //get mouse coordinates Point cursorPosition = new Point(); if (messageSink.Version == NotifyIconVersion.Vista) { //physical cursor position is supported for Vista and above WinApi.GetPhysicalCursorPos(ref cursorPosition); } else { WinApi.GetCursorPos(ref cursorPosition); } cursorPosition = GetDeviceCoordinates(cursorPosition); bool isLeftClickCommandInvoked = false; //show popup, if requested if (me.IsMatch(PopupActivation)) { if (me == MouseEvent.IconLeftMouseUp) { //show popup once we are sure it's not a double click singleClickTimerAction = () => { LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this); ShowTrayPopup(cursorPosition); }; singleClickTimer.Change(WinApi.GetDoubleClickTime(), Timeout.Infinite); isLeftClickCommandInvoked = true; } else { //show popup immediately ShowTrayPopup(cursorPosition); } } //show context menu, if requested if (me.IsMatch(MenuActivation)) { if (me == MouseEvent.IconLeftMouseUp) { //show context menu once we are sure it's not a double click singleClickTimerAction = () => { LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this); ShowContextMenu(cursorPosition); }; singleClickTimer.Change(WinApi.GetDoubleClickTime(), Timeout.Infinite); isLeftClickCommandInvoked = true; } else { //show context menu immediately ShowContextMenu(cursorPosition); } } //make sure the left click command is invoked on mouse clicks if (me == MouseEvent.IconLeftMouseUp && !isLeftClickCommandInvoked) { //show context menu once we are sure it's not a double click singleClickTimerAction = () => { LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this); }; singleClickTimer.Change(WinApi.GetDoubleClickTime(), Timeout.Infinite); } }
/// <summary> /// Processes mouse events, which are bubbled /// through the class' routed events, trigger /// certain actions (e.g. show a popup), or /// both. /// </summary> /// <param name="me">Event flag.</param> private void OnMouseEvent(MouseEvent me) { if (IsDisposed) { return; } switch (me) { case MouseEvent.MouseMove: RaiseTrayMouseMoveEvent(); //immediately return - there's nothing left to evaluate return; case MouseEvent.IconRightMouseDown: RaiseTrayRightMouseDownEvent(); break; case MouseEvent.IconLeftMouseDown: RaiseTrayLeftMouseDownEvent(); break; case MouseEvent.IconRightMouseUp: RaiseTrayRightMouseUpEvent(); break; case MouseEvent.IconLeftMouseUp: RaiseTrayLeftMouseUpEvent(); break; case MouseEvent.IconMiddleMouseDown: RaiseTrayMiddleMouseDownEvent(); break; case MouseEvent.IconMiddleMouseUp: RaiseTrayMiddleMouseUpEvent(); break; case MouseEvent.IconDoubleClick: //cancel single click timer singleClickTimer.Change(Timeout.Infinite, Timeout.Infinite); //bubble event RaiseTrayMouseDoubleClickEvent(); break; case MouseEvent.BalloonToolTipClicked: RaiseTrayBalloonTipClickedEvent(); break; default: throw new ArgumentOutOfRangeException("me", "Missing handler for mouse event flag: " + me); } //get mouse coordinates Interop.Point cursorPosition = new Interop.Point(); Interop.WinApi.GetCursorPos(ref cursorPosition); bool isLeftClickCommandInvoked = false; //show popup, if requested if (me.IsMatch(PopupActivation)) { if (me == MouseEvent.IconLeftMouseUp) { //show popup once we are sure it's not a double click delayedTimerAction = () => { LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this); ShowTrayPopup(cursorPosition); }; singleClickTimer.Change(Interop.WinApi.GetDoubleClickTime(), Timeout.Infinite); isLeftClickCommandInvoked = true; } else { //show popup immediately ShowTrayPopup(cursorPosition); } } //show context menu, if requested if (me.IsMatch(MenuActivation)) { if (me == MouseEvent.IconLeftMouseUp) { //show context menu once we are sure it's not a double click delayedTimerAction = () => { LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this); ShowContextMenu(cursorPosition); }; singleClickTimer.Change(Interop.WinApi.GetDoubleClickTime(), Timeout.Infinite); isLeftClickCommandInvoked = true; } else { //show context menu immediately ShowContextMenu(cursorPosition); } } //make sure the left click command is invoked on mouse clicks if (me == MouseEvent.IconLeftMouseUp && !isLeftClickCommandInvoked) { //show context menu once we are sure it's not a double click delayedTimerAction = () => LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this); singleClickTimer.Change(Interop.WinApi.GetDoubleClickTime(), Timeout.Infinite); } }
/// <summary> /// Processes mouse events, which are bubbled /// through the class' routed events, trigger /// certain actions (e.g. show a popup), or /// both. /// </summary> /// <param name="me">Event flag.</param> private void OnMouseEvent(MouseEvent me) { if (this.IsDisposed) { return; } switch (me) { case MouseEvent.MouseMove: this.RaiseTrayMouseMoveEvent(); //immediately return - there's nothing left to evaluate return; case MouseEvent.IconRightMouseDown: this.RaiseTrayRightMouseDownEvent(); break; case MouseEvent.IconLeftMouseDown: this.RaiseTrayLeftMouseDownEvent(); break; case MouseEvent.IconRightMouseUp: this.RaiseTrayRightMouseUpEvent(); break; case MouseEvent.IconLeftMouseUp: this.RaiseTrayLeftMouseUpEvent(); break; case MouseEvent.IconMiddleMouseDown: this.RaiseTrayMiddleMouseDownEvent(); break; case MouseEvent.IconMiddleMouseUp: this.RaiseTrayMiddleMouseUpEvent(); break; case MouseEvent.IconDoubleClick: //cancel single click timer this.singleClickTimer.Change(Timeout.Infinite, Timeout.Infinite); //bubble event this.RaiseTrayMouseDoubleClickEvent(); break; case MouseEvent.BalloonToolTipClicked: this.RaiseTrayBalloonTipClickedEvent(); break; //default: // throw new ArgumentOutOfRangeException("me", "Missing handler for mouse event flag: " + me); } //get mouse coordinates Point cursorPosition = new Point(); if (messageSink.Version == NotifyIconVersion.Vista) { //physical cursor position is supported for Vista and above WinApi.GetPhysicalCursorPos(ref cursorPosition); } else { WinApi.GetCursorPos(ref cursorPosition); } cursorPosition = this.GetDeviceCoordinates(cursorPosition); bool isLeftClickCommandInvoked = false; //show popup, if requested if (me.IsMatch(this.PopupActivation)) { if (me == MouseEvent.IconLeftMouseUp) { //show popup once we are sure it's not a double click singleClickTimerAction = () => { this.LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this); this.ShowTrayPopup(cursorPosition); }; this.singleClickTimer.Change(WinApi.GetDoubleClickTime(), Timeout.Infinite); isLeftClickCommandInvoked = true; } else { //show popup immediately this.ShowTrayPopup(cursorPosition); } } //show context menu, if requested if (me.IsMatch(this.MenuActivation)) { if (me == MouseEvent.IconLeftMouseUp) { //show context menu once we are sure it's not a double click singleClickTimerAction = () => { LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this); ShowContextMenu(cursorPosition); }; singleClickTimer.Change(WinApi.GetDoubleClickTime(), Timeout.Infinite); isLeftClickCommandInvoked = true; } else { //show context menu immediately ShowContextMenu(cursorPosition); } } //make sure the left click command is invoked on mouse clicks if (me == MouseEvent.IconLeftMouseUp && !isLeftClickCommandInvoked) { //show context menu once we are sure it's not a double click this.singleClickTimerAction = () => { this.LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this); }; this.singleClickTimer.Change(WinApi.GetDoubleClickTime(), Timeout.Infinite); } }
private void OnMouseEvent(object sender, MouseEvent me) { if (this.IsDisposed) { return; } switch (me) { case MouseEvent.MouseMove: this.RaiseTrayMouseMoveEvent(); // immediately return - there's nothing left to evaluate return; case MouseEvent.IconRightMouseDown: this.RaiseTrayRightMouseDownEvent(); break; case MouseEvent.IconLeftMouseDown: this.RaiseTrayLeftMouseDownEvent(); break; case MouseEvent.IconRightMouseUp: this.RaiseTrayRightMouseUpEvent(); break; case MouseEvent.IconLeftMouseUp: this.RaiseTrayLeftMouseUpEvent(); break; case MouseEvent.IconMiddleMouseDown: this.RaiseTrayMiddleMouseDownEvent(); break; case MouseEvent.IconMiddleMouseUp: this.RaiseTrayMiddleMouseUpEvent(); break; case MouseEvent.IconDoubleClick: // cancel single click timer this.singleClickTimer.Change(Timeout.Infinite, Timeout.Infinite); // bubble event this.RaiseTrayMouseDoubleClickEvent(); break; case MouseEvent.BalloonToolTipClicked: this.RaiseTrayBalloonTipClickedEvent(); break; default: var message = string.Format(CultureInfo.CurrentUICulture, Properties.Resources.MissingHandlerForMouseEventFlag_, me); throw new ArgumentOutOfRangeException("me", message); } // get mouse coordinates // var cursorPositionInterop = new Interop.Point(); // var cursorPosition = NativeMethods.GetCursorPos(ref cursorPositionInterop); var cursorPosition = new Point(); NativeMethods.GetCursorPos(ref cursorPosition); var isLeftClickCommandInvoked = false; // show popup, if requested if (me.IsMatch(this.PopupActivation)) { if (me == MouseEvent.IconLeftMouseUp) { // show popup once we are sure it's not a double click this.delayedTimerAction = () => { this.LeftClickCommand.ExecuteIfEnabled(this.LeftClickCommandParameter, this.LeftClickCommandTarget ?? this); this.ShowTrayPopup(cursorPosition); }; this.singleClickTimer.Change(NativeMethods.GetDoubleClickTime(), Timeout.Infinite); isLeftClickCommandInvoked = true; } else { // show popup immediately this.ShowTrayPopup(cursorPosition); } } // show context menu, if requested if (me.IsMatch(this.MenuActivation)) { if (me == MouseEvent.IconLeftMouseUp) { // show context menu once we are sure it's not a double click this.delayedTimerAction = () => { this.LeftClickCommand.ExecuteIfEnabled(this.LeftClickCommandParameter, this.LeftClickCommandTarget ?? this); this.ShowContextMenu(cursorPosition); // ReSharper disable LocalizableElement this.ShowBalloonTip("test", "testmessage", BalloonIconStates.Warning, this.Handle); // ReSharper restore LocalizableElement }; this.singleClickTimer.Change(NativeMethods.GetDoubleClickTime(), Timeout.Infinite); isLeftClickCommandInvoked = true; } else { // show context menu immediately this.ShowContextMenu(cursorPosition); } } // make sure the left click command is invoked on mouse clicks if (me == MouseEvent.IconLeftMouseUp && !isLeftClickCommandInvoked) { // show context menu once we are sure it's not a double click this.delayedTimerAction = () => this.LeftClickCommand.ExecuteIfEnabled(this.LeftClickCommandParameter, this.LeftClickCommandTarget ?? this); this.singleClickTimer.Change(NativeMethods.GetDoubleClickTime(), Timeout.Infinite); } }