/// <summary> /// Saves the specified <see cref="IDockTabItem"/>. /// </summary> /// <param name="context">The serialization context.</param> /// <param name="dockTabItem">The <see cref="IDockTabItem"/>.</param> /// <param name="onlyReference"> /// If set to <see langword="true"/>, only the dock ID is written. /// </param> /// <returns> /// The XML element representing <paramref name="dockTabItem"/>. /// </returns> private static XElement Save(SerializationContext context, IDockTabItem dockTabItem, bool onlyReference) { if (dockTabItem == null) { return(null); } if (!context.SaveNonPersistentItems && !dockTabItem.IsPersistent) { return(null); } var xElement = new XElement("DockTabItem"); xElement.Add(new XAttribute("DockId", dockTabItem.DockId)); if (onlyReference) { return(xElement); } if (context.DockControl.ActiveDockTabItem == dockTabItem) { xElement.Add(new XAttribute("IsActive", true)); } xElement.Add(new XAttribute("DockState", dockTabItem.DockState)); xElement.Add(new XAttribute("LastDockState", dockTabItem.LastDockState)); xElement.Add(new XAttribute("DockWidth", ConvertToString(dockTabItem.DockWidth))); xElement.Add(new XAttribute("DockHeight", ConvertToString(dockTabItem.DockHeight))); xElement.Add(new XAttribute("AutoHideWidth", dockTabItem.AutoHideWidth)); xElement.Add(new XAttribute("AutoHideHeight", dockTabItem.AutoHideHeight)); xElement.Add(new XAttribute("LastActivation", dockTabItem.LastActivation)); return(xElement); }
/// <summary> /// Resets all fields. /// </summary> private void Reset() { Debug.Assert(Mouse.Captured == null); Debug.Assert(_borderDockIndicators == null); Debug.Assert(_paneDockIndicators == null); Debug.Assert( _dockStrategy == null || !_dockStrategy.DockControl.GetDockElements().OfType <DockTabItemProxy>().Any(), "All item proxies should have been removed."); _dockStrategy = null; _draggedItems.Clear(); _activeItem = null; _floatWindow = null; _targetDockTabPane = null; _layoutChanged = false; _initialMousePosition = new Point(double.NaN, double.NaN); _dragDeltaExceeded = false; _mouseOffset = new Vector(double.NaN, double.NaN); _initialSize = new Size(double.NaN, double.NaN); _canFloat = true; _originalDockState = DockState.Hide; _originalFloatWindow = null; _originalFloatLeft = 0; _originalFloatTop = 0; }
private void ShowAutoHidePane(IDockTabPane dockTabPane, IDockTabItem dockTabItem) { CloseAutoHidePanesExcept(dockTabPane); foreach (var autoHideBar in _autoHideBars) { var autoHidePane = autoHideBar.ShowAutoHidePane(dockTabPane, dockTabItem, true); if (autoHidePane != null) { break; } } }
/// <summary> /// Gets the view for a view model. /// </summary> /// <param name="viewModel">The view model.</param> /// <returns>The <see cref="DockTabItem"/>.</returns> public DockTabItem GetView(IDockTabItem viewModel) { for (int i = 0; i < _dockTabItems.Count; i++) { if (_dockTabItems[i].DataContext == viewModel) { return(_dockTabItems[i]); } } return(null); }
/// <inheritdoc/> public override bool CanClose(IDockTabItem dockTabItem) { // Screen conduction: IGuardClose var guardClose = dockTabItem as IGuardClose; if (guardClose != null) { var canClose = guardClose.CanCloseAsync(); Debug.Assert(canClose.IsCompleted, "CanCloseAsync expected to be synchronous operation."); return(canClose.Result); } return(base.CanClose(dockTabItem)); }
protected override void OnClose(IDockTabItem dockTabItem) { base.OnClose(dockTabItem); // Screen conduction: IActivatable (dockTabItem as IActivatable)?.OnDeactivate(true); // Screen conduction: IScreen var screen = dockTabItem as IScreen; if (screen != null) { screen.Conductor = null; } }
internal AutoHidePane ShowAutoHidePane(IDockTabPane dockTabPane, IDockTabItem dockTabItem, bool focus) { if (dockTabPane == null || !Items.Contains(dockTabPane)) { return(null); } var dockControl = DockHelper.GetDockControl(this); // Ensure that correct item is selected. if (dockTabItem != null) { Debug.Assert(dockTabPane.Items.Contains(dockTabItem)); dockTabPane.SelectedItem = dockTabItem; } // Get or create AutoHidePane that shows the DockTabItem. var autoHidePane = GetAutoHidePane(dockTabPane); if (autoHidePane == null) { // Create a new AutoHidePane if necessary. autoHidePane = new AutoHidePane { Content = dockTabPane, Dock = Dock, }; var autoHideOverlay = new AutoHideOverlay(dockControl, TargetArea) { Content = autoHidePane }; autoHideOverlay.Show(); _autoHideOverlays.Add(autoHideOverlay); } // Slide-in AutoHidePane. autoHidePane.Show(); if (focus) { dockControl?.DockStrategy?.Activate(dockTabPane); } return(autoHidePane); }
/// <summary> /// Starts a drag operation. /// </summary> /// <param name="floatWindow">The <see cref="FloatWindow"/> to be dragged.</param> /// <param name="dockTabPane">The <see cref="DockTabPane"/> to be dragged.</param> /// <param name="dockTabItem">The <see cref="DockTabItem"/> to be dragged.</param> /// <returns> /// <see langword="true" /> if the drag operation has been started; otherwise, /// <see langword="false" /> if the drag operation could not be started (e.g. because the /// mouse could not be captured). /// </returns> private bool BeginDrag(FloatWindow floatWindow, DockTabPane dockTabPane, DockTabItem dockTabItem) { _dockStrategy = _dockControl.GetViewModel()?.DockStrategy; if (_dockStrategy == null || _dockStrategy.DockControl.IsLocked) { Reset(); return(false); } FrameworkElement element = null; IDockTabPane draggedPane = null; IDockTabItem draggedItem = null; if (floatWindow != null) { // User is dragging a FloatWindow. // (Note: Dragging of FloatWindows with nested layouts is not supported.) draggedPane = floatWindow.GetViewModel()?.RootPane as IDockTabPane; element = floatWindow; _floatWindow = floatWindow; _initialSize = floatWindow.RenderSize; // Start dragging immediately. _dragDeltaExceeded = true; } else if (dockTabItem != null) { // User is dragging a DockTabItem in a DockTabPanel. draggedItem = dockTabItem.GetViewModel(); element = dockTabItem; _targetDockTabPane = dockTabPane; _initialSize = dockTabPane.RenderSize; // Start dragging when threshold is exceeded. _initialMousePosition = WindowsHelper.GetMousePosition(_dockControl); _dragDeltaExceeded = false; } else if (dockTabPane != null) { // User is dragging a DockTabPane. draggedPane = dockTabPane.GetViewModel(); element = dockTabPane; _initialSize = dockTabPane.RenderSize; _initialMousePosition = WindowsHelper.GetMousePosition(_dockControl); // Start dragging when threshold is exceeded. _initialMousePosition = WindowsHelper.GetMousePosition(_dockControl); _dragDeltaExceeded = false; } if (draggedPane == null && draggedItem == null) { Reset(); return(false); } // When the user is dragging the FloatWindow, the mouse is captured by Win32 move window // loop. When dragging a DockTabPane or DockTabItem, the mouse needs to be // captured to receive mouse events. if (_floatWindow == null) { if (!_dockControl.CaptureMouse()) { // Failed to capture the mouse. Reset(); return(false); } _dockControl.LostMouseCapture += OnLostMouseCapture; _dockControl.MouseLeftButtonUp += OnMouseLeftButtonUp; _dockControl.MouseMove += OnMouseMove; _dockControl.PreviewKeyDown += OnPreviewKeyDown; if (_targetDockTabPane != null) { _targetDockTabPane.PreviewKeyDown += OnPreviewKeyDown; } } _dockStrategy.Begin(); if (draggedPane != null) { _dockStrategy.Activate(draggedPane); _activeItem = draggedPane.SelectedItem; foreach (var item in draggedPane.Items) { if (item.DockState == draggedPane.DockState) { _draggedItems.Add(item); } } } else { Debug.Assert(draggedItem != null); _dockStrategy.Activate(draggedItem); _activeItem = draggedItem; _draggedItems.Add(draggedItem); } Debug.Assert(_draggedItems.Count > 0); // Determine whether dragged items may end in a FloatWindow. _canFloat = CanFloat(); // Store the mouse offset relative to the dragged element. _mouseOffset = (Vector)WindowsHelper.GetMousePosition(element); // Remember information needed for a rollback. ReplaceItemsWithProxies(draggedPane ?? _targetDockTabPane.GetViewModel()); _originalDockState = _draggedItems[0].DockState; BackupFloatWindowPosition(); // Override mouse cursors. (Mouse cursor should not change to caret over text editor.) Mouse.OverrideCursor = Cursors.Arrow; return(true); }
public DockTabItemProxy(IDockTabItem item) { Debug.Assert(item != null); Item = item; }
internal AutoHidePane ShowAutoHidePane(IDockTabPane dockTabPane, IDockTabItem dockTabItem, bool focus) { if (dockTabPane == null || !Items.Contains(dockTabPane)) return null; var dockControl = DockHelper.GetDockControl(this); // Ensure that correct item is selected. if (dockTabItem != null) { Debug.Assert(dockTabPane.Items.Contains(dockTabItem)); dockTabPane.SelectedItem = dockTabItem; } // Get or create AutoHidePane that shows the DockTabItem. var autoHidePane = GetAutoHidePane(dockTabPane); if (autoHidePane == null) { // Create a new AutoHidePane if necessary. autoHidePane = new AutoHidePane { Content = dockTabPane, Dock = Dock, }; var autoHideOverlay = new AutoHideOverlay(dockControl, TargetArea) { Content = autoHidePane }; autoHideOverlay.Show(); _autoHideOverlays.Add(autoHideOverlay); } // Slide-in AutoHidePane. autoHidePane.Show(); if (focus) dockControl?.DockStrategy?.Activate(dockTabPane); return autoHidePane; }
/// <summary> /// Saves the specified <see cref="IDockTabItem"/>. /// </summary> /// <param name="context">The serialization context.</param> /// <param name="dockTabItem">The <see cref="IDockTabItem"/>.</param> /// <param name="onlyReference"> /// If set to <see langword="true"/>, only the dock ID is written. /// </param> /// <returns> /// The XML element representing <paramref name="dockTabItem"/>. /// </returns> private static XElement Save(SerializationContext context, IDockTabItem dockTabItem, bool onlyReference) { if (dockTabItem == null) return null; if (!context.SaveNonPersistentItems && !dockTabItem.IsPersistent) return null; var xElement = new XElement("DockTabItem"); xElement.Add(new XAttribute("DockId", dockTabItem.DockId)); if (onlyReference) return xElement; if (context.DockControl.ActiveDockTabItem == dockTabItem) xElement.Add(new XAttribute("IsActive", true)); xElement.Add(new XAttribute("DockState", dockTabItem.DockState)); xElement.Add(new XAttribute("LastDockState", dockTabItem.LastDockState)); xElement.Add(new XAttribute("DockWidth", ConvertToString(dockTabItem.DockWidth))); xElement.Add(new XAttribute("DockHeight", ConvertToString(dockTabItem.DockHeight))); xElement.Add(new XAttribute("AutoHideWidth", dockTabItem.AutoHideWidth)); xElement.Add(new XAttribute("AutoHideHeight", dockTabItem.AutoHideHeight)); xElement.Add(new XAttribute("LastActivation", dockTabItem.LastActivation)); return xElement; }
//-------------------------------------------------------------- /// <summary> /// Resets all fields. /// </summary> private void Reset() { Debug.Assert(Mouse.Captured == null); Debug.Assert(_borderDockIndicators == null); Debug.Assert(_paneDockIndicators == null); Debug.Assert( _dockStrategy == null || !_dockStrategy.DockControl.GetDockElements().OfType<DockTabItemProxy>().Any(), "All item proxies should have been removed."); _dockStrategy = null; _draggedItems.Clear(); _activeItem = null; _floatWindow = null; _targetDockTabPane = null; _layoutChanged = false; _initialMousePosition = new Point(double.NaN, double.NaN); _dragDeltaExceeded = false; _mouseOffset = new Vector(double.NaN, double.NaN); _initialSize = new Size(double.NaN, double.NaN); _canFloat = true; _originalDockState = DockState.Hide; _originalFloatWindow = null; _originalFloatLeft = 0; _originalFloatTop = 0; }
/// <summary> /// Starts a drag operation. /// </summary> /// <param name="floatWindow">The <see cref="FloatWindow"/> to be dragged.</param> /// <param name="dockTabPane">The <see cref="DockTabPane"/> to be dragged.</param> /// <param name="dockTabItem">The <see cref="DockTabItem"/> to be dragged.</param> /// <returns> /// <see langword="true" /> if the drag operation has been started; otherwise, /// <see langword="false" /> if the drag operation could not be started (e.g. because the /// mouse could not be captured). /// </returns> private bool BeginDrag(FloatWindow floatWindow, DockTabPane dockTabPane, DockTabItem dockTabItem) { _dockStrategy = _dockControl.GetViewModel()?.DockStrategy; if (_dockStrategy == null || _dockStrategy.DockControl.IsLocked) { Reset(); return false; } FrameworkElement element = null; IDockTabPane draggedPane = null; IDockTabItem draggedItem = null; if (floatWindow != null) { // User is dragging a FloatWindow. // (Note: Dragging of FloatWindows with nested layouts is not supported.) draggedPane = floatWindow.GetViewModel()?.RootPane as IDockTabPane; element = floatWindow; _floatWindow = floatWindow; _initialSize = floatWindow.RenderSize; // Start dragging immediately. _dragDeltaExceeded = true; } else if (dockTabItem != null) { // User is dragging a DockTabItem in a DockTabPanel. draggedItem = dockTabItem.GetViewModel(); element = dockTabItem; _targetDockTabPane = dockTabPane; _initialSize = dockTabPane.RenderSize; // Start dragging when threshold is exceeded. _initialMousePosition = WindowsHelper.GetMousePosition(_dockControl); _dragDeltaExceeded = false; } else if (dockTabPane != null) { // User is dragging a DockTabPane. draggedPane = dockTabPane.GetViewModel(); element = dockTabPane; _initialSize = dockTabPane.RenderSize; _initialMousePosition = WindowsHelper.GetMousePosition(_dockControl); // Start dragging when threshold is exceeded. _initialMousePosition = WindowsHelper.GetMousePosition(_dockControl); _dragDeltaExceeded = false; } if (draggedPane == null && draggedItem == null) { Reset(); return false; } // When the user is dragging the FloatWindow, the mouse is captured by Win32 move window // loop. When dragging a DockTabPane or DockTabItem, the mouse needs to be // captured to receive mouse events. if (_floatWindow == null) { if (!_dockControl.CaptureMouse()) { // Failed to capture the mouse. Reset(); return false; } _dockControl.LostMouseCapture += OnLostMouseCapture; _dockControl.MouseLeftButtonUp += OnMouseLeftButtonUp; _dockControl.MouseMove += OnMouseMove; _dockControl.PreviewKeyDown += OnPreviewKeyDown; if (_targetDockTabPane != null) _targetDockTabPane.PreviewKeyDown += OnPreviewKeyDown; } _dockStrategy.Begin(); if (draggedPane != null) { _dockStrategy.Activate(draggedPane); _activeItem = draggedPane.SelectedItem; foreach (var item in draggedPane.Items) if (item.DockState == draggedPane.DockState) _draggedItems.Add(item); } else { Debug.Assert(draggedItem != null); _dockStrategy.Activate(draggedItem); _activeItem = draggedItem; _draggedItems.Add(draggedItem); } Debug.Assert(_draggedItems.Count > 0); // Determine whether dragged items may end in a FloatWindow. _canFloat = CanFloat(); // Store the mouse offset relative to the dragged element. _mouseOffset = (Vector)WindowsHelper.GetMousePosition(element); // Remember information needed for a rollback. ReplaceItemsWithProxies(draggedPane ?? _targetDockTabPane.GetViewModel()); _originalDockState = _draggedItems[0].DockState; BackupFloatWindowPosition(); // Override mouse cursors. (Mouse cursor should not change to caret over text editor.) Mouse.OverrideCursor = Cursors.Arrow; return true; }
private void ShowAutoHidePane(IDockTabPane dockTabPane, IDockTabItem dockTabItem) { CloseAutoHidePanesExcept(dockTabPane); foreach (var autoHideBar in _autoHideBars) { var autoHidePane = autoHideBar.ShowAutoHidePane(dockTabPane, dockTabItem, true); if (autoHidePane != null) break; } }
//-------------------------------------------------------------- /// <summary> /// Gets the view for a view model. /// </summary> /// <param name="viewModel">The view model.</param> /// <returns>The <see cref="DockTabItem"/>.</returns> public DockTabItem GetView(IDockTabItem viewModel) { for (int i = 0; i < _dockTabItems.Count; i++) if (_dockTabItems[i].DataContext == viewModel) return _dockTabItems[i]; return null; }
public DockTabItemProxy(IDockTabItem item) { Debug.Assert(item != null); Item = item; }