void OnMouseDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left && MouseGestureBase.IsOnlyButtonPressed(e, MouseButton.Left)) { e.Handled = true; IDesignPanel designPanel = (IDesignPanel)sender; DesignPanelHitTestResult result = designPanel.HitTest(e.GetPosition(designPanel), false, true, HitTestType.Default); if (result.ModelHit != null) { var darwItemBehaviors = result.ModelHit.Extensions.OfType <IDrawItemExtension>(); var drawItembehavior = darwItemBehaviors.FirstOrDefault(x => x.CanItemBeDrawn(componentType)); if (drawItembehavior != null && drawItembehavior.CanItemBeDrawn(componentType)) { drawItembehavior.StartDrawItem(result.ModelHit, componentType, designPanel, e, SetPropertiesForDrawnItem); } else { var placementBehavior = result.ModelHit.GetBehavior <IPlacementBehavior>(); if (placementBehavior != null) { var createdItem = CreateItem(designPanel.Context); new CreateComponentMouseGesture(result.ModelHit, createdItem, changeGroup).Start(designPanel, e); // CreateComponentMouseGesture now is responsible for the changeGroup created by CreateItem() changeGroup = null; } } } } }
void OnMouseDown(object sender, MouseButtonEventArgs e) { IDesignPanel designPanel = (IDesignPanel)sender; DesignPanelHitTestResult result = designPanel.HitTest(e.GetPosition(designPanel), false, true); if (result.ModelHit != null) { IHandlePointerToolMouseDown b = result.ModelHit.GetBehavior <IHandlePointerToolMouseDown>(); if (b != null) { b.HandleSelectionMouseDown(designPanel, e, result); } if (!e.Handled) { if (e.ChangedButton == MouseButton.Left && MouseGestureBase.IsOnlyButtonPressed(e, MouseButton.Left)) { e.Handled = true; ISelectionService selectionService = designPanel.Context.Services.Selection; selectionService.SetSelectedComponents(new DesignItem[] { result.ModelHit }, SelectionTypes.Auto); if (selectionService.IsComponentSelected(result.ModelHit)) { new DragMoveMouseGesture(result.ModelHit, e.ClickCount == 2).Start(designPanel, e); } } } } }
void designPanel_DragOver(object sender, DragEventArgs e) { try { IDesignPanel designPanel = (IDesignPanel)sender; e.Effects = DragDropEffects.Copy; e.Handled = true; Point p = e.GetPosition(designPanel); if (moveLogic == null) { if (e.Data.GetData(typeof(CreateComponentTool)) != this) { return; } // TODO: dropLayer in designPanel designPanel.IsAdornerLayerHitTestVisible = false; DesignPanelHitTestResult result = designPanel.HitTest(p, false, true, HitTestType.Default); if (result.ModelHit != null) { designPanel.Focus(); DesignItem createdItem = CreateItem(designPanel.Context); if (AddItemWithDefaultSize(result.ModelHit, createdItem, e.GetPosition(result.ModelHit.View))) { moveLogic = new MoveLogic(createdItem); if (designPanel.Context.Services.Component is XamlComponentService) { ((XamlComponentService)designPanel.Context.Services.Component) .RaiseComponentRegisteredAndAddedToContainer(createdItem); } createPoint = p; // We'll keep the ChangeGroup open as long as the moveLogic is active. } else { // Abort the ChangeGroup created by the CreateItem() call. changeGroup.Abort(); } } } else if ((moveLogic.ClickedOn.View as FrameworkElement).IsLoaded) { if (moveLogic.Operation == null) { moveLogic.Start(createPoint); } else { moveLogic.Move(p); } } } catch (Exception x) { DragDropExceptionHandler.RaiseUnhandledException(x); } }
void OnMouseDown(object sender, MouseButtonEventArgs e) { IDesignPanel designPanel = (IDesignPanel)sender; DesignPanelHitTestResult result = designPanel.HitTest(e.GetPosition(designPanel), false, true, HitTestType.ElementSelection); if (result.ModelHit != null) { IHandlePointerToolMouseDown b = result.ModelHit.GetBehavior <IHandlePointerToolMouseDown>(); if (b != null) { b.HandleSelectionMouseDown(designPanel, e, result); } if (!e.Handled) { if (e.ChangedButton == MouseButton.Left && MouseGestureBase.IsOnlyButtonPressed(e, MouseButton.Left)) { e.Handled = true; ISelectionService selectionService = designPanel.Context.Services.Selection; bool setSelectionIfNotMoving = false; if (selectionService.IsComponentSelected(result.ModelHit)) { setSelectionIfNotMoving = true; // There might be multiple components selected. We might have // to set the selection to only the item clicked on // (or deselect the item clicked on if Ctrl is pressed), // but we should do so only if the user isn't performing a drag operation. } else { selectionService.SetSelectedComponents(new DesignItem[] { result.ModelHit }, SelectionTypes.Auto); } if (selectionService.IsComponentSelected(result.ModelHit)) { new DragMoveMouseGesture(result.ModelHit, e.ClickCount == 2, setSelectionIfNotMoving).Start(designPanel, e); } } } } }
void OnMouseDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left && MouseGestureBase.IsOnlyButtonPressed(e, MouseButton.Left)) { e.Handled = true; IDesignPanel designPanel = (IDesignPanel)sender; DesignPanelHitTestResult result = designPanel.HitTest(e.GetPosition(designPanel), false, true, HitTestType.Default); if (result.ModelHit != null) { IPlacementBehavior behavior = result.ModelHit.GetBehavior <IPlacementBehavior>(); if (behavior != null) { DesignItem createdItem = CreateItem(designPanel.Context); new CreateComponentMouseGesture(result.ModelHit, createdItem, changeGroup).Start(designPanel, e); // CreateComponentMouseGesture now is responsible for the changeGroup created by CreateItem() changeGroup = null; } } } }
void designPanel_DragOver(object sender, DragEventArgs e) { try { IDesignPanel designPanel = (IDesignPanel)sender; e.Effects = DragDropEffects.Copy; e.Handled = true; Point p = e.GetPosition(designPanel); if (moveLogic == null) { if (ChangeGroup != null) { ChangeGroup.Abort(); ChangeGroup = null; } ChangeGroup = designPanel.Context.RootItem.OpenGroup("Add Control"); designPanel.IsAdornerLayerHitTestVisible = false; DesignPanelHitTestResult result = designPanel.HitTest(p, false, true, HitTestType.Default); if (result.ModelHit != null) { designPanel.Focus(); var items = CreateItemsWithPosition(designPanel.Context, e.GetPosition(result.ModelHit.View), e); if (items != null) { if (AddItems(result.ModelHit, items)) { moveLogic = new MoveLogic(items[0]); foreach (var designItem in items) { if (designPanel.Context.Services.Component is XamlComponentService) { ((XamlComponentService)designPanel.Context.Services.Component).RaiseComponentRegisteredAndAddedToContainer(designItem); } } createPoint = p; } else { ChangeGroup.Abort(); ChangeGroup = null; } } else { e.Effects = DragDropEffects.None; } } } else if ((moveLogic.ClickedOn.View as FrameworkElement).IsLoaded) { if (moveLogic.Operation == null) { moveLogic.Start(createPoint); } else { moveLogic.Move(p); } } } catch (Exception x) { DragDropExceptionHandler.RaiseUnhandledException(x); } }