/// <summary> /// Is called if the user begins a drag operation on the canvas and there is no other /// mouse handler (eg, AssociationMouseHandler) currently activated. /// /// Otherwise, the OnShapeDragBegin method of the other mouse handler is executed and /// this method is completely ignorred for the current drag operation. /// </summary> /// <param name="position"></param> /// <param name="shape"></param> void ICanvasViewMouseHandler.OnShapeDragBegin(Point position, ShapeViewModelBase shape) { if (shape != null) { // Activate shape selection if user starts to drag a shape if (shape.IsSelected == false) { ((ICanvasViewMouseHandler)this).OnShapeClick(this.mDragShape); } } else // user starts a drag operation on the canvas so we setup a rubber band adorner command { // to implement multi object selection via rubber band if (this.mCurrentMouseHandler == this) { // Clear current selection if no control key is pressed on the keyboard (which would allow adding selected items) if ((Keyboard.IsKeyDown(Key.LeftCtrl) == false && Keyboard.IsKeyDown(Key.RightCtrl) == false)) { CanvasViewModel.SelectedItem.SelectShape(null); } RubberBandViewModel vm = this.GetRubberBand(position); // Create a new mouse handler command, attach event on completion, and hook it into the system CreateRubberBandMouseHandler handler = new CreateRubberBandMouseHandler(vm, this.CanvasViewModel); handler.RubberBandSelection += handler_RubberBandSelection; // Hook up into frame work system this.CanvasViewModel.BeginCanvasViewMouseHandler(handler); this.BeginMouseOperation(); //this.mCurrentMouseHandler = this.CanvasViewModel.CanvasViewMouseHandler; } } }
private void handler_RubberBandSelection(object sender, RubberBandSelectionEventArgs e) { if (this.mCurrentMouseHandler is CreateRubberBandMouseHandler) { CreateRubberBandMouseHandler handler = this.mCurrentMouseHandler as CreateRubberBandMouseHandler; handler.RubberBandSelection -= this.handler_RubberBandSelection; } this.CanvasViewModel.Handle_RubberBandSelection(e); this.EndMouseOperation(); this.DestroyRubberband(); }
/// <summary> /// This method is called when the association drawing mode is cancelled /// (either via explicit command [click on Select Mode button] or /// because the source or target may be in-appropriate). /// </summary> public void CancelCanvasViewMouseHandler() { var handler = this.CanvasViewMouseHandler; this.CanvasViewMouseHandler = null; try { handler.OnCancelMouseHandler(); CreateRubberBandMouseHandler rbh = handler as CreateRubberBandMouseHandler; // Make sure event completion handler is detached when mouse command handler is finished //// if (rbh != null) //// rbh.RubberBandSelection -= this.handle_RubberBandSelection; } finally { DocumentViewModel.dm_DocumentDataModel.EndOperation("CanvasViewMouseHandler session"); } }