internal void OnInkCanvasDeviceDown(object sender, InputEventArgs args) { MouseButtonEventArgs mouseButtonEventArgs = args as MouseButtonEventArgs; bool resetDynamicRenderer = false; if (mouseButtonEventArgs != null) { if (this._inkCanvas.Focus() && this.ActiveEditingMode != InkCanvasEditingMode.None) { mouseButtonEventArgs.Handled = true; } if (mouseButtonEventArgs.ChangedButton != MouseButton.Left) { return; } if (mouseButtonEventArgs.StylusDevice != null) { this.UpdateInvertedState(mouseButtonEventArgs.StylusDevice, mouseButtonEventArgs.StylusDevice.Inverted); } } else { StylusEventArgs stylusEventArgs = args as StylusEventArgs; this.UpdateInvertedState(stylusEventArgs.StylusDevice, stylusEventArgs.Inverted); } IStylusEditing stylusEditing = this.ActiveEditingBehavior as IStylusEditing; if (!this.IsInMidStroke && stylusEditing != null) { bool flag = false; try { InputDevice inputDevice; if (mouseButtonEventArgs != null && mouseButtonEventArgs.StylusDevice != null) { inputDevice = mouseButtonEventArgs.StylusDevice; resetDynamicRenderer = true; } else { inputDevice = args.Device; } this.InitializeCapture(inputDevice, stylusEditing, args.UserInitiated, resetDynamicRenderer); flag = true; } finally { if (!flag) { this.ActiveEditingBehavior.Commit(false); this.ReleaseCapture(this.IsInMidStroke); } } } }
private void InitializeCapture(InputDevice inputDevice, IStylusEditing stylusEditingBehavior, bool userInitiated, bool resetDynamicRenderer) { this._capturedStylus = (inputDevice as StylusDevice); this._capturedMouse = (inputDevice as MouseDevice); if (this._capturedStylus != null) { StylusPointCollection stylusPoints = this._capturedStylus.GetStylusPoints(this._inkCanvas); this._commonDescription = StylusPointDescription.GetCommonDescription(this._inkCanvas.DefaultStylusPointDescription, stylusPoints.Description); StylusPointCollection stylusPoints2 = stylusPoints.Reformat(this._commonDescription); if (resetDynamicRenderer) { InkCollectionBehavior inkCollectionBehavior = stylusEditingBehavior as InkCollectionBehavior; if (inkCollectionBehavior != null) { inkCollectionBehavior.ResetDynamicRenderer(); } } stylusEditingBehavior.AddStylusPoints(stylusPoints2, userInitiated); this._inkCanvas.CaptureStylus(); if (this._inkCanvas.IsStylusCaptured && this.ActiveEditingMode != InkCanvasEditingMode.None) { this._inkCanvas.AddHandler(Stylus.StylusMoveEvent, new StylusEventHandler(this.OnInkCanvasDeviceMove <StylusEventArgs>)); this._inkCanvas.AddHandler(UIElement.LostStylusCaptureEvent, new StylusEventHandler(this.OnInkCanvasLostDeviceCapture <StylusEventArgs>)); return; } this._capturedStylus = null; return; } else { this._commonDescription = null; Point[] points = new Point[] { this._capturedMouse.GetPosition(this._inkCanvas) }; StylusPointCollection stylusPoints2 = new StylusPointCollection(points); stylusEditingBehavior.AddStylusPoints(stylusPoints2, userInitiated); this._inkCanvas.CaptureMouse(); if (this._inkCanvas.IsMouseCaptured && this.ActiveEditingMode != InkCanvasEditingMode.None) { this._inkCanvas.AddHandler(Mouse.MouseMoveEvent, new MouseEventHandler(this.OnInkCanvasDeviceMove <MouseEventArgs>)); this._inkCanvas.AddHandler(UIElement.LostMouseCaptureEvent, new MouseEventHandler(this.OnInkCanvasLostDeviceCapture <MouseEventArgs>)); return; } this._capturedMouse = null; return; } }
private void OnInkCanvasDeviceMove <TEventArgs>(object sender, TEventArgs args) where TEventArgs : InputEventArgs { if (this.IsInputDeviceCaptured(args.Device)) { IStylusEditing stylusEditing = this.ActiveEditingBehavior as IStylusEditing; if (stylusEditing != null) { StylusPointCollection stylusPoints; if (this._capturedStylus != null) { stylusPoints = this._capturedStylus.GetStylusPoints(this._inkCanvas, this._commonDescription); } else { MouseEventArgs mouseEventArgs = args as MouseEventArgs; if (mouseEventArgs != null && mouseEventArgs.StylusDevice != null) { return; } stylusPoints = new StylusPointCollection(new Point[] { this._capturedMouse.GetPosition(this._inkCanvas) }); } bool flag = false; try { stylusEditing.AddStylusPoints(stylusPoints, args.UserInitiated); flag = true; } finally { if (!flag) { this.ActiveEditingBehavior.Commit(false); this.ReleaseCapture(true); } } } } }
// Token: 0x06006D63 RID: 28003 RVA: 0x001F66D4 File Offset: 0x001F48D4 protected override void OnSwitchToMode(InkCanvasEditingMode mode) { switch (mode) { case InkCanvasEditingMode.None: base.Commit(true); base.EditingCoordinator.ChangeStylusEditingMode(this, mode); break; case InkCanvasEditingMode.Ink: case InkCanvasEditingMode.GestureOnly: case InkCanvasEditingMode.InkAndGesture: base.Commit(true); base.EditingCoordinator.ChangeStylusEditingMode(this, mode); return; case InkCanvasEditingMode.Select: { StylusPointCollection stylusPointCollection = (this._stylusPoints != null) ? this._stylusPoints.Clone() : null; base.Commit(true); IStylusEditing stylusEditing = base.EditingCoordinator.ChangeStylusEditingMode(this, mode); if (stylusPointCollection != null && stylusEditing != null) { stylusEditing.AddStylusPoints(stylusPointCollection, false); return; } break; } case InkCanvasEditingMode.EraseByPoint: case InkCanvasEditingMode.EraseByStroke: base.Commit(true); base.EditingCoordinator.ChangeStylusEditingMode(this, mode); return; default: return; } }
//------------------------------------------------------------------------------- // // Protected Methods // //------------------------------------------------------------------------------- #region Protected Methods /// <summary> /// Overrides SwitchToMode /// As the following expected results /// 1. From Ink To InkAndGesture /// Packets between StylusDown and StylusUp are sent to the gesture reco. On StylusUp gesture event fires. If it’s not a gesture, StrokeCollected event fires. /// 2. From Ink To GestureOnly /// Packets between StylusDown and StylusUp are send to the gesture reco. On StylusUp gesture event fires. Stroke gets removed on StylusUp even if it’s not a gesture. /// 3. From Ink To EraseByPoint /// Stroke is discarded. PointErasing is performed after changing the mode. /// 4. From Ink To EraseByStroke /// Stroke is discarded. StrokeErasing is performed after changing the mode. /// 5. From Ink To Select /// Stroke is discarded. Lasso is drawn for all packets between StylusDown and StylusUp. Strokes/elements within the lasso will be selected. /// 6. From Ink To None /// Stroke is discarded. /// 7. From InkAndGesture To Ink /// Stroke is collected for all packets between StylusDown and StylusUp. Gesture event does not fire. /// 8. From InkAndGesture To GestureOnly /// Packets between StylusDown and StylusUp are sent to the gesture reco. Stroke gets removed on StylusUp even if it’s not a gesture. /// 9. From InkAndGesture To EraseByPoint /// Stroke is discarded. PointErasing is performed after changing the mode, gesture event does not fire. /// 10. From InkAndGesture To EraseByStroke /// Stroke is discarded. StrokeErasing is performed after changing the mode, gesture event does not fire. /// 11. From InkAndGesture To Select /// Lasso is drawn for all packets between StylusDown and StylusUp. Strokes/elements within the lasso will be selected. /// 12. From InkAndGesture To None /// Stroke is discarded, no gesture is recognized. /// 13. From GestureOnly To InkAndGesture /// Packets between StylusDown and StylusUp are sent to the gesture reco. On StylusUp gesture event fires. If it’s not a gesture, StrokeCollected event fires. /// 14. From GestureOnly To Ink /// Stroke is collected. Gesture event does not fire. /// 15. From GestureOnly To EraseByPoint /// Stroke is discarded PointErasing is performed after changing the mode, gesture event does not fire /// 16. From GestureOnly To EraseByStroke /// Stroke is discarded. StrokeErasing is performed after changing the mode, gesture event does not fire. /// 17. From GestureOnly To Select /// Lasso is drawn for all packets between StylusDown and StylusUp. Strokes/elements within the lasso will be selected. /// 18. From GestureOnly To None /// Stroke is discarded. Gesture event does not fire. /// </summary> /// <param name="mode"></param> protected override void OnSwitchToMode(InkCanvasEditingMode mode) { Debug.Assert(EditingCoordinator.IsInMidStroke, "SwitchToMode should only be called in a mid-stroke"); switch (mode) { case InkCanvasEditingMode.Ink: case InkCanvasEditingMode.InkAndGesture: case InkCanvasEditingMode.GestureOnly: { // We are under one of those Ink modes now. Nothing to change here except raising the mode change event. InkCanvas.RaiseActiveEditingModeChanged(new RoutedEventArgs(InkCanvas.ActiveEditingModeChangedEvent, InkCanvas)); break; } case InkCanvasEditingMode.EraseByPoint: case InkCanvasEditingMode.EraseByStroke: { // Discard the collected ink. Commit(false); // Change the Erase mode EditingCoordinator.ChangeStylusEditingMode(this, mode); break; } case InkCanvasEditingMode.Select: { // Make a copy of the current cached points. StylusPointCollection cachedPoints = _stylusPoints != null? _stylusPoints.Clone() : null; // Discard the collected ink. Commit(false); // Change the Select mode IStylusEditing newBehavior = EditingCoordinator.ChangeStylusEditingMode(this, mode); if (cachedPoints != null // NOTICE-2006/04/27-WAYNEZEN, // EditingCoordinator.ChangeStylusEditingMode raises external event. // The user code could take any arbitrary action for instance calling InkCanvas.ReleaseMouseCapture() // So there is no guarantee that we could receive the newBehavior. && newBehavior != null) { // Now add the previous points to the lasso behavior // The SelectionBehavior doesn't check userInitiated, pass false // even if our _userInitiated flag is true newBehavior.AddStylusPoints(cachedPoints, false /*userInitiated*/); } break; } case InkCanvasEditingMode.None: { // Discard the collected ink. Commit(false); // Change to the None mode EditingCoordinator.ChangeStylusEditingMode(this, mode); break; } default: Debug.Assert(false, "Unknown InkCanvasEditingMode!"); break; } }
//------------------------------------------------------------------------------- // // Protected Methods // //------------------------------------------------------------------------------- #region Protected Methods /// <summary> /// Overrides SwitchToMode as the following expectations /// 19. From EraseByPoint To InkAndGesture /// After mode change ink is being collected. On StylusUp gesture event fires. If it’s not a gesture, StrokeCollected event fires. /// 20. From EraseByPoint To GestureOnly /// After mode change ink is being collected. On StylusUp gesture event fires. Stroke gets removed on StylusUp even if it’s not a gesture. /// 21. From EraseByPoint To Ink /// Ink collection starts when changing the mode. /// 22. From EraseByPoint To EraseByStroke /// After mode change StrokeErasing is performed. /// 23. From EraseByPoint To Select /// Lasso is drawn for all packets between StylusDown and StylusUp. Strokes/elements within the lasso will be selected. /// 24. From EraseByPoint To None /// No erasing is performed after mode change. /// 25. From EraseByStroke To InkAndGesture /// After mode change ink is being collected. On StylusUp gesture event fires. If it’s not a gesture, StrokeCollected event fires. /// 26. From EraseByStroke To GestureOnly /// After mode change ink is being collected. On StylusUp gesture event fires. Stroke gets removed on StylusUp even if it’s not a gesture. /// 27. From EraseByStroke To EraseByPoint /// After mode change PointErasing is performed. /// 28. From EraseByStroke To Ink /// Ink collection starts when changing the mode. /// 29. From EraseByStroke To Select /// Lasso is drawn for all packets between StylusDown and StylusUp. Strokes/elements within the lasso will be selected /// 30. From EraseByStroke To None /// No erasing is performed after mode change. /// </summary> /// <param name="mode"></param> protected override void OnSwitchToMode(InkCanvasEditingMode mode) { Debug.Assert(EditingCoordinator.IsInMidStroke, "SwitchToMode should only be called in a mid-stroke"); switch (mode) { case InkCanvasEditingMode.Ink: case InkCanvasEditingMode.InkAndGesture: case InkCanvasEditingMode.GestureOnly: { // Commit the current behavior Commit(true); // Change the mode. The dynamic renderer will be reset automatically. EditingCoordinator.ChangeStylusEditingMode(this, mode); break; } case InkCanvasEditingMode.EraseByPoint: case InkCanvasEditingMode.EraseByStroke: { Debug.Assert(_cachedEraseMode != mode); // Commit the current behavior Commit(true); // Change the mode EditingCoordinator.ChangeStylusEditingMode(this, mode); break; } case InkCanvasEditingMode.Select: { // Make a copy of the current cached points. StylusPointCollection cachedPoints = _stylusPoints != null? _stylusPoints.Clone() : null; // Commit the current behavior. Commit(true); // Change the Select mode IStylusEditing newBehavior = EditingCoordinator.ChangeStylusEditingMode(this, mode); if (cachedPoints != null // NOTICE-2006/04/27-WAYNEZEN, // EditingCoordinator.ChangeStylusEditingMode raises external event. // The user code could take any arbitrary action for instance calling InkCanvas.ReleaseMouseCapture() // So there is no guarantee that we could receive the newBehavior. && newBehavior != null) { // Now add the previous points to the lasso behavior newBehavior.AddStylusPoints(cachedPoints, false /*userInitiated*/); } break; } case InkCanvasEditingMode.None: { // Discard the collected ink. Commit(true); // Change to the None mode EditingCoordinator.ChangeStylusEditingMode(this, mode); break; } default: Debug.Assert(false, "Unknown InkCanvasEditingMode!"); break; } }