Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / System / Windows / Input / Command / MouseGesture.cs / 1305600 / MouseGesture.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: The MouseGesture class is used by the developer to create Gestures for // Mouse Device // // See spec at : http://avalon/coreUI/Specs/Commanding%20--%20design.htm // // // History: // 03/26/2004 : chandras - Created // //--------------------------------------------------------------------------- using System; using System.Windows.Input; using System.Windows; using System.Windows.Markup; using System.ComponentModel; namespace System.Windows.Input { ////// MouseGesture - MouseAction and Modifier combination. /// Can be set on properties of MouseBinding and RoutedCommand. /// [TypeConverter(typeof(MouseGestureConverter))] [ValueSerializer(typeof(MouseGestureValueSerializer))] public class MouseGesture : InputGesture { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructors ////// Constructor /// public MouseGesture() // Mouse action { } ////// constructor /// /// Mouse Action public MouseGesture(MouseAction mouseAction): this(mouseAction, ModifierKeys.None) { } ////// Constructor /// /// Mouse Action /// Modifiers public MouseGesture( MouseAction mouseAction,ModifierKeys modifiers) // acclerator action { if (!MouseGesture.IsDefinedMouseAction(mouseAction)) throw new InvalidEnumArgumentException("mouseAction", (int)mouseAction, typeof(MouseAction)); if (!ModifierKeysConverter.IsDefinedModifierKeys(modifiers)) throw new InvalidEnumArgumentException("modifiers", (int)modifiers, typeof(ModifierKeys)); _modifiers = modifiers; _mouseAction = mouseAction; //AttachClassListeners(); } #endregion Constructors //------------------------------------------------------ // // Public Methods // //----------------------------------------------------- #region Public Methods ////// Action /// public MouseAction MouseAction { get { return _mouseAction; } set { if (!MouseGesture.IsDefinedMouseAction((MouseAction)value)) throw new InvalidEnumArgumentException("value", (int)value, typeof(MouseAction)); if (_mouseAction != value) { _mouseAction = (MouseAction)value; OnPropertyChanged("MouseAction"); } } } ////// Modifiers /// public ModifierKeys Modifiers { get { return _modifiers; } set { if (!ModifierKeysConverter.IsDefinedModifierKeys((ModifierKeys)value)) throw new InvalidEnumArgumentException("value", (int)value, typeof(ModifierKeys)); if (_modifiers != value) { _modifiers = (ModifierKeys)value; OnPropertyChanged("Modifiers"); } } } ////// Compares InputEventArgs with current Input /// /// the element to receive the command /// inputEventArgs to compare to ///True - if matches, false otherwise. /// public override bool Matches(object targetElement, InputEventArgs inputEventArgs) { MouseAction mouseAction = GetMouseAction(inputEventArgs); if(mouseAction != MouseAction.None) { return ( ( (int)this.MouseAction == (int)mouseAction ) && ( this.Modifiers == Keyboard.Modifiers ) ); } return false; } // Helper like Enum.IsDefined, for MouseAction. internal static bool IsDefinedMouseAction(MouseAction mouseAction) { return (mouseAction >= MouseAction.None && mouseAction <= MouseAction.MiddleDoubleClick); } #endregion Public Methods #region Internal NotifyProperty changed ////// PropertyChanged event Handler /// internal event PropertyChangedEventHandler PropertyChanged; ////// PropertyChanged virtual /// internal virtual void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } #endregion //------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ #region Internal Methods internal static MouseAction GetMouseAction(InputEventArgs inputArgs) { MouseAction MouseAction = MouseAction.None; MouseEventArgs mouseArgs = inputArgs as MouseEventArgs; if(mouseArgs != null) { if(inputArgs is MouseWheelEventArgs) { MouseAction = MouseAction.WheelClick; } else { MouseButtonEventArgs args = inputArgs as MouseButtonEventArgs; switch(args.ChangedButton) { case MouseButton.Left: { if(args.ClickCount == 2) MouseAction = MouseAction.LeftDoubleClick; else if(args.ClickCount == 1) MouseAction = MouseAction.LeftClick; } break; case MouseButton.Right: { if(args.ClickCount == 2) MouseAction = MouseAction.RightDoubleClick; else if(args.ClickCount == 1) MouseAction = MouseAction.RightClick; } break; case MouseButton.Middle: { if(args.ClickCount == 2) MouseAction = MouseAction.MiddleDoubleClick; else if(args.ClickCount == 1) MouseAction = MouseAction.MiddleClick; } break; } } } return MouseAction; } #endregion Internal Methods //----------------------------------------------------- // // Private Fields // //------------------------------------------------------ #region Private Fields private MouseAction _mouseAction = MouseAction.None; private ModifierKeys _modifiers = ModifierKeys.None; // private static bool _classRegistered = false; #endregion Private Fields } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: The MouseGesture class is used by the developer to create Gestures for // Mouse Device // // See spec at : http://avalon/coreUI/Specs/Commanding%20--%20design.htm // // // History: // 03/26/2004 : chandras - Created // //--------------------------------------------------------------------------- using System; using System.Windows.Input; using System.Windows; using System.Windows.Markup; using System.ComponentModel; namespace System.Windows.Input { ////// MouseGesture - MouseAction and Modifier combination. /// Can be set on properties of MouseBinding and RoutedCommand. /// [TypeConverter(typeof(MouseGestureConverter))] [ValueSerializer(typeof(MouseGestureValueSerializer))] public class MouseGesture : InputGesture { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructors ////// Constructor /// public MouseGesture() // Mouse action { } ////// constructor /// /// Mouse Action public MouseGesture(MouseAction mouseAction): this(mouseAction, ModifierKeys.None) { } ////// Constructor /// /// Mouse Action /// Modifiers public MouseGesture( MouseAction mouseAction,ModifierKeys modifiers) // acclerator action { if (!MouseGesture.IsDefinedMouseAction(mouseAction)) throw new InvalidEnumArgumentException("mouseAction", (int)mouseAction, typeof(MouseAction)); if (!ModifierKeysConverter.IsDefinedModifierKeys(modifiers)) throw new InvalidEnumArgumentException("modifiers", (int)modifiers, typeof(ModifierKeys)); _modifiers = modifiers; _mouseAction = mouseAction; //AttachClassListeners(); } #endregion Constructors //------------------------------------------------------ // // Public Methods // //----------------------------------------------------- #region Public Methods ////// Action /// public MouseAction MouseAction { get { return _mouseAction; } set { if (!MouseGesture.IsDefinedMouseAction((MouseAction)value)) throw new InvalidEnumArgumentException("value", (int)value, typeof(MouseAction)); if (_mouseAction != value) { _mouseAction = (MouseAction)value; OnPropertyChanged("MouseAction"); } } } ////// Modifiers /// public ModifierKeys Modifiers { get { return _modifiers; } set { if (!ModifierKeysConverter.IsDefinedModifierKeys((ModifierKeys)value)) throw new InvalidEnumArgumentException("value", (int)value, typeof(ModifierKeys)); if (_modifiers != value) { _modifiers = (ModifierKeys)value; OnPropertyChanged("Modifiers"); } } } ////// Compares InputEventArgs with current Input /// /// the element to receive the command /// inputEventArgs to compare to ///True - if matches, false otherwise. /// public override bool Matches(object targetElement, InputEventArgs inputEventArgs) { MouseAction mouseAction = GetMouseAction(inputEventArgs); if(mouseAction != MouseAction.None) { return ( ( (int)this.MouseAction == (int)mouseAction ) && ( this.Modifiers == Keyboard.Modifiers ) ); } return false; } // Helper like Enum.IsDefined, for MouseAction. internal static bool IsDefinedMouseAction(MouseAction mouseAction) { return (mouseAction >= MouseAction.None && mouseAction <= MouseAction.MiddleDoubleClick); } #endregion Public Methods #region Internal NotifyProperty changed ////// PropertyChanged event Handler /// internal event PropertyChangedEventHandler PropertyChanged; ////// PropertyChanged virtual /// internal virtual void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } #endregion //------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ #region Internal Methods internal static MouseAction GetMouseAction(InputEventArgs inputArgs) { MouseAction MouseAction = MouseAction.None; MouseEventArgs mouseArgs = inputArgs as MouseEventArgs; if(mouseArgs != null) { if(inputArgs is MouseWheelEventArgs) { MouseAction = MouseAction.WheelClick; } else { MouseButtonEventArgs args = inputArgs as MouseButtonEventArgs; switch(args.ChangedButton) { case MouseButton.Left: { if(args.ClickCount == 2) MouseAction = MouseAction.LeftDoubleClick; else if(args.ClickCount == 1) MouseAction = MouseAction.LeftClick; } break; case MouseButton.Right: { if(args.ClickCount == 2) MouseAction = MouseAction.RightDoubleClick; else if(args.ClickCount == 1) MouseAction = MouseAction.RightClick; } break; case MouseButton.Middle: { if(args.ClickCount == 2) MouseAction = MouseAction.MiddleDoubleClick; else if(args.ClickCount == 1) MouseAction = MouseAction.MiddleClick; } break; } } } return MouseAction; } #endregion Internal Methods //----------------------------------------------------- // // Private Fields // //------------------------------------------------------ #region Private Fields private MouseAction _mouseAction = MouseAction.None; private ModifierKeys _modifiers = ModifierKeys.None; // private static bool _classRegistered = false; #endregion Private Fields } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- StylusCaptureWithinProperty.cs
- CompareInfo.cs
- BrowserDefinitionCollection.cs
- TypefaceCollection.cs
- InvokeMethod.cs
- ConfigurationSectionGroup.cs
- SourceFileInfo.cs
- PerformanceCounterManager.cs
- InternalBase.cs
- InternalControlCollection.cs
- CultureSpecificCharacterBufferRange.cs
- Publisher.cs
- WinFormsSecurity.cs
- CqlLexer.cs
- FormViewUpdateEventArgs.cs
- SmtpNtlmAuthenticationModule.cs
- ActivationArguments.cs
- SiteMapDataSourceView.cs
- AdornerLayer.cs
- METAHEADER.cs
- PresentationUIStyleResources.cs
- BitmapEffectGroup.cs
- SamlAttributeStatement.cs
- VerticalConnector.xaml.cs
- AttributeEmitter.cs
- CqlQuery.cs
- PersonalizationState.cs
- DodSequenceMerge.cs
- MapPathBasedVirtualPathProvider.cs
- SecurityResources.cs
- TimelineGroup.cs
- SectionVisual.cs
- GenericEnumerator.cs
- RepeatBehavior.cs
- UnsafeNativeMethods.cs
- DrawingCollection.cs
- EntityType.cs
- AssociatedControlConverter.cs
- AssertSection.cs
- RuntimeArgumentHandle.cs
- WebConfigurationHost.cs
- Track.cs
- SecurityUtils.cs
- SocketElement.cs
- AddingNewEventArgs.cs
- StylusTouchDevice.cs
- BodyGlyph.cs
- TableLayoutPanelCodeDomSerializer.cs
- Dump.cs
- RuleSetDialog.cs
- GeometryGroup.cs
- WindowsListViewSubItem.cs
- AsymmetricCryptoHandle.cs
- ProfileInfo.cs
- GeometryDrawing.cs
- WebPartTransformer.cs
- StorageRoot.cs
- StateFinalizationDesigner.cs
- DataGridToolTip.cs
- HttpFormatExtensions.cs
- MemberPath.cs
- SendSecurityHeaderElementContainer.cs
- FontSizeConverter.cs
- WindowsNonControl.cs
- DateTimeSerializationSection.cs
- AdRotator.cs
- Msmq4PoisonHandler.cs
- ImageList.cs
- HttpListenerPrefixCollection.cs
- JournalNavigationScope.cs
- WebPartsPersonalizationAuthorization.cs
- SpecialTypeDataContract.cs
- GrammarBuilderBase.cs
- Types.cs
- MemberInfoSerializationHolder.cs
- SQLByteStorage.cs
- Animatable.cs
- RoleGroup.cs
- AttachmentCollection.cs
- HotSpot.cs
- Command.cs
- ApplicationManager.cs
- TraceUtility.cs
- DataRowExtensions.cs
- EntityDataSourceView.cs
- filewebrequest.cs
- BuildManager.cs
- XMLSchema.cs
- OperationCanceledException.cs
- ReflectTypeDescriptionProvider.cs
- CompressionTransform.cs
- PartialCachingControl.cs
- CodeDirectionExpression.cs
- HtmlLiteralTextAdapter.cs
- EntityDataSourceDesignerHelper.cs
- NumericUpDown.cs
- Contracts.cs
- CodeRegionDirective.cs
- XmlImplementation.cs
- SymbolDocumentGenerator.cs