/// <summary> /// Initiates a drag/drop operation. /// </summary> private void designerDataGrid_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (IsEditing || e.ClickCount > 1) { return; } // Find our starting point var row = TreeHelper.TryFindFromPoint <DataGridRow>((UIElement)sender, e.GetPosition(designerDataGrid)); // cancel operation if a) doesn't exist or b) is being edited if (row == null || row.IsEditing) { return; } // otherwise, continue ... IsDragging = true; if (row.Item is DesignerItemBaseVM) { DraggedItem = (DesignerItemBaseVM)row.Item; } else { ResetDragDrop(); } }
static void Fe_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { if ((e.LeftButton == MouseButtonState.Pressed) || (e.RightButton == MouseButtonState.Pressed)) { DesignerItemBaseVM item = (DesignerItemBaseVM)((FrameworkElement)sender).DataContext; if (item != null) { if ((Keyboard.Modifiers & (ModifierKeys.Control)) != ModifierKeys.None) { item.IsSelected = !item.IsSelected; } else if (!item.IsSelected) // item clicked on was NOT selected and no modifier keys were used { foreach (DesignerItemBaseVM i in item.ParentTab.SelectedItems) { i.IsSelected = false; // for items in selected list, turn their IsSelected flag off } item.ParentTab.SelectedItems.Clear(); // empty the selected items list item.IsSelected = true; // mark this item as selected item.ParentTab.SelectedItem = item; // set the parent's SelectedItem to this object } } } }
/// <summary> /// Closes the popup and resets the /// grid to read-enabled mode. /// </summary> private void ResetDragDrop() { IsDragging = false; DragDropPopup.IsOpen = false; designerDataGrid.IsReadOnly = false; DraggedItem = null; }
private void ExecuteAddItemCommand(object parameter) { //System.Diagnostics.Debug.WriteLine("Reached ExecuteAddItemCommand in DesignerTabVM.cs"); if (parameter is DesignerItemBaseVM) { DesignerItemBaseVM item = (DesignerItemBaseVM)parameter; item.ParentTab = this; item.ParentForm = this.ParentForm; if (item.IsMedcinItem) { // force user to assign a MedcinTerm ChooseMedcinTermDialog dlg = new ChooseMedcinTermDialog(item); if (dlg.ShowDialog() == false) { // user canceled return; } else { // item has a Medcin code (presumably) } } items.Add(item); } }
private bool CanShrinkWidth(DesignerItemBaseVM item, double amount) { if (item.Width - Math.Abs(amount) <= item.MinWidth) { return(false); } else { return(true); } }
private bool CanShrinkHeight(DesignerItemBaseVM item, double amount) { if (item.Height - Math.Abs(amount) <= item.MinHeight) { return(false); } else { return(true); } }
private bool CanGrowDown(DesignerItemBaseVM item, double amount) { if ((item.Height + Math.Abs(amount) >= item.MaxHeight) || (item.Top + item.Height + Math.Abs(amount) > item.ParentForm.Height)) { return(false); } else { return(true); } }
private bool CanGrowUp(DesignerItemBaseVM item, double amount) { if ((item.Height + Math.Abs(amount) >= item.MaxHeight) || (item.Top - Math.Abs(amount) < 0)) { return(false); } else { return(true); } }
private bool CanGrowLeft(DesignerItemBaseVM item, double amount) { if ((item.Width + Math.Abs(amount) >= item.MaxWidth) || (item.Left - Math.Abs(amount) < 0)) { return(false); } else { return(true); } }
private bool CanGrowRight(DesignerItemBaseVM item, double amount) { if ((item.Width + Math.Abs(amount) >= item.MaxWidth) || (item.Left + item.Width + Math.Abs(amount) > item.ParentForm.Width)) { return(false); } else { return(true); } }
private void AdjustDown(DesignerItemBaseVM item, double amount) { double delta = Math.Abs(amount); if (amount < 0 && CanShrinkHeight(item, delta)) { item.Height -= delta; } if (amount > 0 && CanGrowDown(item, delta)) { item.Height += delta; } }
private void AdjustRight(DesignerItemBaseVM item, double amount) { double delta = Math.Abs(amount); if (amount < 0 && CanShrinkWidth(item, delta)) { item.Width -= delta; } if (amount > 0 && CanGrowRight(item, delta)) { item.Width += delta; } }
private void ExecuteRemoveItemCommand(object parameter) { //System.Diagnostics.Debug.WriteLine("Reached ExecuteRemoveItemCommand in DesignerTabVM.cs"); if (parameter is DesignerItemBaseVM) { DesignerItemBaseVM item = (DesignerItemBaseVM)parameter; if (SelectedItem == item) { SelectedItem = null; } items.Remove(item); } }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject; if (dragObject != null) { DesignerVM dc = (DataContext as DesignerVM); dc.ActiveTab.ClearSelection(); Point position = e.GetPosition(this); DesignerItemBaseVM item = (DesignerItemBaseVM)Activator.CreateInstance(dragObject.ContentType); item.Left = Math.Max(0, position.X - item.Width / 2); // want drop point to be upper left corner, not center of item item.Top = Math.Max(0, position.Y - item.Height / 2); item.IsSelected = true; dc.ActiveTab.AddItemCommand.Execute(item); dc.ActiveTab.SelectedItem = item; // Give the DesignerCanvas focus so it can receive arrow key presses this.Focus(); } e.Handled = true; }
private Type GetTypeOfDesignerItem(DesignerItemBaseVM vmType) { //System.Diagnostics.Debug.WriteLine("Reached GetTypeOfDesignerItem in MainWindowVM.cs"); // Not quite sure I understand this; might be due to VM vs M confusion if (vmType is DesignerItemBaseVM) { return(typeof(DesignerItemBaseVM)); } if (vmType is FrameVM) { return(typeof(FrameVM)); } if (vmType is DI8449VM) { return(typeof(DI8449VM)); } if (vmType is GridVM) { return(typeof(GridVM)); } if (vmType is LabelVM) { return(typeof(LabelVM)); } if (vmType is RibbonVM) { return(typeof(RibbonVM)); } // Add additional item types here as you create them // Throw an exception if the item type is not supported throw new InvalidOperationException(string.Format("Unknown item type. Currently supported types include: {0}, {1}, {2}, {3}, {4}, {5}", typeof(DesignerItemBaseVM).AssemblyQualifiedName, typeof(FrameVM).AssemblyQualifiedName, typeof(DI8449VM).AssemblyQualifiedName, typeof(GridVM).AssemblyQualifiedName, typeof(LabelVM).AssemblyQualifiedName, typeof(RibbonVM).AssemblyQualifiedName)); }
/// <summary> /// Completes a drag/drop operation. /// </summary> private void windowGrid_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { // Do nothing if not dragging an item OR user editing something if (!IsDragging || IsEditing) { return; } // get the DataGridRow that we're dropping on top of Point posInDataGrid = e.GetPosition(designerDataGrid); var row = TreeHelper.TryFindFromPoint <DataGridRow>(designerDataGrid, posInDataGrid); // Only proceed if user dragged to another row if (row != null) { //get the target item DesignerItemBaseVM targetItem = (DesignerItemBaseVM)designerDataGrid.SelectedItem; if (targetItem == null || !ReferenceEquals(DraggedItem, targetItem)) { mainWindowVM.DesignerVM.ActiveTab.Items.Remove(DraggedItem); // remove the dragged item // determine whether we want to insert above or below Point posInDataGridRow = e.GetPosition(row); bool towardTop = TreeHelper.PointIsCloserToTopHalf(row, posInDataGridRow); int targetIndex = mainWindowVM.DesignerVM.ActiveTab.Items.IndexOf(targetItem); // inserting above if (!towardTop) { targetIndex += 1; // inserting below } mainWindowVM.DesignerVM.ActiveTab.Items.Insert(targetIndex, DraggedItem); // re-insert the dropped item designerDataGrid.SelectedItem = DraggedItem; // and select it } } ResetDragDrop(); }
public ChooseMedcinTermDialog(DesignerItemBaseVM item) { InitializeComponent(); this.DataContext = item; }
void ResizeThumb_DragDelta(object sender, DragDeltaEventArgs e) { DesignerItemBaseVM item = this.DataContext as DesignerItemBaseVM; if (item != null) { // TOP LEFT if (VerticalAlignment == VerticalAlignment.Top && HorizontalAlignment == HorizontalAlignment.Left) { AdjustUp(item, e.VerticalChange); AdjustLeft(item, e.HorizontalChange); } // TOP if (VerticalAlignment == VerticalAlignment.Top && HorizontalAlignment == HorizontalAlignment.Stretch) { AdjustUp(item, e.VerticalChange); } // TOP RIGHT if (VerticalAlignment == VerticalAlignment.Top && HorizontalAlignment == HorizontalAlignment.Right) { AdjustUp(item, e.VerticalChange); AdjustRight(item, e.HorizontalChange); } // LEFT if (HorizontalAlignment == HorizontalAlignment.Left && VerticalAlignment == VerticalAlignment.Stretch) { AdjustLeft(item, e.HorizontalChange); } // RIGHT if (HorizontalAlignment == HorizontalAlignment.Right && VerticalAlignment == VerticalAlignment.Stretch) { AdjustRight(item, e.HorizontalChange); } // BOTTOM LEFT if (VerticalAlignment == VerticalAlignment.Bottom && HorizontalAlignment == HorizontalAlignment.Left) { AdjustDown(item, e.VerticalChange); AdjustLeft(item, e.HorizontalChange); } // BOTTOM if (VerticalAlignment == VerticalAlignment.Bottom && HorizontalAlignment == HorizontalAlignment.Stretch) { AdjustDown(item, e.VerticalChange); } // BOTTOM RIGHT if (VerticalAlignment == VerticalAlignment.Bottom && HorizontalAlignment == HorizontalAlignment.Right) { AdjustDown(item, e.VerticalChange); AdjustRight(item, e.HorizontalChange); } e.Handled = true; } }
void DragThumb_DragDelta(object sender, DragDeltaEventArgs e) { // Set up the data sources we'll need to work with DesignerItemBaseVM sourceItem = this.DataContext as DesignerItemBaseVM; DesignerVM vm = sourceItem.ParentForm; // Make sure something exists and is selected if (sourceItem != null && sourceItem.IsSelected) { // Set up the selected items var selectedItems = vm.ActiveTab.SelectedItems; double minLeft = double.MaxValue; double minTop = double.MaxValue; /* * // if more than one item is selected, treat them as a group - * // when one stops moving, they all do * double TopmostItemTop = vm.Height; * double LeftmostItemLeft = 0; * double RightmostItemLeft = 0; * double BottomMostItemTop = 0; * * if (vm.SelectedItems.Count > 1) * { * foreach (DesignerItemBaseVM item in selectedItems.OfType<DesignerItemBaseVM>()) * { * * if (item.Top < TopmostItemTop) TopmostItemTop = item.Top; * if (item.Left < LeftmostItemLeft) LeftmostItemLeft = item.Left; * if (item.Top > BottomMostItemTop) BottomMostItemTop = item.Top; * if (item.Left < RightmostItemLeft) RightmostItemLeft = item.Left; * * } * System.Console.WriteLine("Extreme edges: Top({0}), Left({1}), Right({2}), Bottom({3})", TopmostItemTop, LeftmostItemLeft, RightmostItemLeft, BottomMostItemTop); * } */ foreach (DesignerItemBaseVM item in selectedItems.OfType <DesignerItemBaseVM>()) { double maxItemLeft = vm.Width - item.Width; double maxItemTop = vm.Height - item.Height; minLeft = double.IsNaN(item.Left) ? 0 : Math.Min(item.Left, minLeft); minTop = double.IsNaN(item.Top) ? 0 : Math.Min(item.Top, minTop); double deltaHorizontal = Math.Max(-minLeft, e.HorizontalChange); double deltaVertical = Math.Max(-minTop, e.VerticalChange); double desiredLeft = item.Left + deltaHorizontal; double desiredTop = item.Top + deltaVertical; if (desiredLeft > maxItemLeft) { item.Left = maxItemLeft; } else { item.Left += deltaHorizontal; } if (desiredTop > maxItemTop) { item.Top = maxItemTop; } else { item.Top += deltaVertical; } } e.Handled = true; } }