private void OnPageDragStart(Crownwood.DotNetMagic.Controls.TabControl sender, Crownwood.DotNetMagic.Controls.TabPage movePage, MouseEventArgs e) { // Is the user allowed to redock? if (DockingManager.AllowRedocking) { // Use allow to redock this particular content? if (this.RedockAllowed) { // Event page must specify its Content object Content c = movePage.Tag as Content; // Remember the position of the tab before it is removed _dragPageIndex = _tabControl.TabPages.IndexOf(movePage); // Force the entire window to redraw to ensure the Redocker does not start drawing // the XOR indicator before the window repaints itself. Otherwise the repainted // control will interfere with the XOR indicator. this.Refresh(); // Start redocking activity for the single Content of this WindowContent _redocker = Redocker.CreateRedocker(DockingManager.FeedbackStyle, _tabControl, c, this, new Point(e.X, e.Y)); } } }
/// <summary> /// Add our collection of hotzones into redocker. /// </summary> /// <param name="redock">Redocker target.</param> /// <param name="collection">Collection of hotzones.</param> public void AddHotZones(Redocker redock, HotZoneCollection collection) { RedockerContent redocker = redock as RedockerContent; // Allow the contained Zone a chance to expose HotZones foreach (Control c in this.Controls) { IHotZoneSource ag = c as IHotZoneSource; // Does this control expose an interface for its own HotZones? if (ag != null) { ag.AddHotZones(redock, collection); } } }
/// <summary> /// Add the collection of hot zones. /// </summary> /// <param name="redock">Reference to a redocker instance.</param> /// <param name="collection">Collection of hot zones.</param> public void AddHotZones(Redocker redock, HotZoneCollection collection) { RedockerContent redocker = redock as RedockerContent; bool itself = false; bool nullZone = false; // We process differently for WindowContent to redock into itself! if ((redocker.WindowContent != null) && (redocker.WindowContent == this)) { itself = true; } // We do not allow a Content to redock into its existing container if (itself && !Contents.Contains(redocker.Content)) { nullZone = true; } Rectangle newSize = this.RectangleToScreen(this.ClientRectangle); Rectangle hotArea = _tabControl.RectangleToScreen(_tabControl.ClientRectangle);; // Find any caption detail and use that area as the hot area foreach (WindowDetail wd in WindowDetails) { WindowDetailCaption wdc = wd as WindowDetailCaption; if (wdc != null) { hotArea = wdc.RectangleToScreen(wdc.ClientRectangle); hotArea.Inflate(_hotAreaInflate, _hotAreaInflate); break; } } if (nullZone) { collection.Add(new HotZoneNull(hotArea)); } else { collection.Add(new HotZoneTabbed(hotArea, newSize, this, itself)); } }
/// <summary> /// Update the screen indication to reflect new mouse position. /// </summary> /// <param name="dragFeedback">Feedback class.</param> /// <param name="screenPos">New screen position.</param> /// <param name="parent">Parent redocker instance.</param> public override void UpdateForMousePosition(DragFeedback dragFeedback, Point screenPos, Redocker parent) { // Remember the current mouse pos Point newPos = screenPos; // Calculate the new drawing rectangle Rectangle newRect = new Rectangle(newPos.X, newPos.Y, NewSize.Width, NewSize.Height); // Adjust for mouse starting position relative to source control newRect.X -= _offset.X; newRect.Y -= _offset.Y; dragFeedback.DragRectangle(newRect); // Remember new values _drawPos = newPos; _drawRect = newRect; }
/// <summary> /// Update the screen indication to reflect new mouse position. /// </summary> /// <param name="dragFeedback">Feedback class.</param> /// <param name="screenPos">New screen position.</param> /// <param name="parent">Parent redocker instance.</param> public virtual void UpdateForMousePosition(DragFeedback dragFeedback, Point screenPos, Redocker parent) { }
/// <summary> /// Apply the hot zone change. /// </summary> /// <param name="screenPos">Screen position when change applied.</param> /// <param name="parent">Parent redocker instance.</param> /// <returns>true is successful; otherwise false.</returns> public virtual bool ApplyChange(Point screenPos, Redocker parent) { return(false); }
/// <summary> /// Apply the hot zone change. /// </summary> /// <param name="screenPos">Screen position when change applied.</param> /// <param name="parent">Parent redocker instance.</param> /// <returns>true is successful; otherwise false.</returns> public override bool ApplyChange(Point screenPos, Redocker parent) { // Should always be the appropriate type RedockerContent redock = parent as RedockerContent; DockingManager dockingManager = redock.DockingManager; Zone newZone = null; // Manageing Zones should remove display AutoHide windows dockingManager.RemoveShowingAutoHideWindows(); switch (redock.DockingSource) { case RedockerContent.Source.WindowContent: // Perform State specific Restore actions foreach (Content c in redock.WindowContent.Contents) { c.ContentBecomesFloating(); } // Remove WindowContent from old Zone if (redock.WindowContent.ParentZone != null) { redock.WindowContent.ParentZone.Windows.Remove(redock.WindowContent); } // We need to create a Zone for containing the transfered content newZone = dockingManager.CreateZoneForContent(State.Floating); // Add into new Zone newZone.Windows.Add(redock.WindowContent); break; case RedockerContent.Source.ContentInsideWindow: { // Perform State specific Restore actions redock.Content.ContentBecomesFloating(); // Remove Content from existing WindowContent if (redock.Content.ParentWindowContent != null) { redock.Content.ParentWindowContent.Contents.Remove(redock.Content); } // Create a new Window to host Content Window w = dockingManager.CreateWindowForContent(redock.Content); // We need to create a Zone for containing the transfered content newZone = dockingManager.CreateZoneForContent(State.Floating); // Add into Zone newZone.Windows.Add(w); } break; case RedockerContent.Source.FloatingForm: redock.FloatingForm.Location = new Point(screenPos.X - _offset.X, screenPos.Y - _offset.Y); return(false); } dockingManager.UpdateInsideFill(); // Create a new floating form FloatingForm floating = new FloatingForm(redock.DockingManager, newZone, new ContextHandler(dockingManager.OnShowContextMenu)); // Find screen location/size _drawRect = new Rectangle(screenPos.X, screenPos.Y, NewSize.Width, NewSize.Height); // Adjust for mouse starting position relative to source control _drawRect.X -= _offset.X; _drawRect.Y -= _offset.Y; // Define its location/size floating.SetBounds(_drawRect.Left, _drawRect.Top, _drawRect.Width, _drawRect.Height); // Show it! floating.RequestShow(); return(true); }
/// <summary> /// Processes Windows messages. /// </summary> /// <param name="m">The Windows Message to process. </param> protected override void WndProc(ref Message m) { // Want to notice when the window is maximized if (m.Msg == (int)Win32.Msgs.WM_NCLBUTTONDBLCLK) { // Is the user allowed to redock? if (_dockingManager.AllowRedocking) { // Redock and kill ourself Restore(); // Raise event to indicate a double click occured _dockingManager.OnDoubleClickDock(); } // We do not want to let the base process the message as the // restore might fail due to lack of permission to restore to // old state. In that case we do not want to maximize the window return; } else if (m.Msg == (int)Win32.Msgs.WM_NCLBUTTONDOWN) { if (!_intercept) { // Perform a hit test against our own window to determine // which area the mouse press is over at the moment. uint result = User32.SendMessage(this.Handle, (int)Win32.Msgs.WM_NCHITTEST, 0, (uint)m.LParam); // Only want to override the behaviour of moving the window via the caption box if (result == HITTEST_CAPTION) { // Is the user allowed to redock? if (_dockingManager.AllowRedocking) { // Remember new state _intercept = true; // Capture the mouse until the mouse us is received this.Capture = true; // Ensure that we gain focus and look active this.Activate(); // Raise event to indicate a floating form has become active _dockingManager.OnFloatingFormActivated(this); // Get mouse position to inscreen coordinates Win32.POINT mousePos; mousePos.x = (short)((uint)m.LParam & 0x0000FFFFU); mousePos.y = (short)(uint)(((uint)m.LParam & 0xFFFF0000U) >> 16); // Begin a redocking activity _redocker = Redocker.CreateRedocker(DockingManager.FeedbackStyle, this, new Point(mousePos.x - DesktopBounds.X, mousePos.y - DesktopBounds.Y)); return; } } } } else if (m.Msg == (int)Win32.Msgs.WM_MOUSEMOVE) { if (_intercept) { Win32.POINT mousePos; mousePos.x = (short)((uint)m.LParam & 0x0000FFFFU); mousePos.y = (short)(uint)(((uint)m.LParam & 0xFFFF0000U) >> 16); _redocker.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 0, mousePos.x, mousePos.y, 0)); return; } } else if ((m.Msg == (int)Win32.Msgs.WM_RBUTTONDOWN) || (m.Msg == (int)Win32.Msgs.WM_MBUTTONDOWN)) { if (_intercept) { Win32.POINT mousePos; mousePos.x = (short)((uint)m.LParam & 0x0000FFFFU); mousePos.y = (short)(uint)(((uint)m.LParam & 0xFFFF0000U) >> 16); _redocker.QuitTrackingMode(new MouseEventArgs(MouseButtons.Left, 0, mousePos.x, mousePos.y, 0)); // Release capture this.Capture = false; // Reset state _intercept = false; return; } } else if (m.Msg == (int)Win32.Msgs.WM_LBUTTONUP) { if (_intercept) { Win32.POINT mousePos; mousePos.x = (short)((uint)m.LParam & 0x0000FFFFU); mousePos.y = (short)(uint)(((uint)m.LParam & 0xFFFF0000U) >> 16); _redocker.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 0, mousePos.x, mousePos.y, 0)); // Release capture this.Capture = false; // Reset state _intercept = false; return; } } else if ((m.Msg == (int)Win32.Msgs.WM_NCRBUTTONUP) || (m.Msg == (int)Win32.Msgs.WM_NCMBUTTONDOWN) || (m.Msg == (int)Win32.Msgs.WM_NCMBUTTONUP) || (m.Msg == (int)Win32.Msgs.WM_RBUTTONDOWN) || (m.Msg == (int)Win32.Msgs.WM_RBUTTONUP) || (m.Msg == (int)Win32.Msgs.WM_MBUTTONDOWN) || (m.Msg == (int)Win32.Msgs.WM_MBUTTONUP)) { // Prevent middle and right mouse buttons from interrupting // the correct operation of left mouse dragging return; } else if (m.Msg == (int)Win32.Msgs.WM_NCRBUTTONDOWN) { if (!_intercept) { // Get screen coordinates of the mouse Win32.POINT mousePos; mousePos.x = (short)((uint)m.LParam & 0x0000FFFFU); mousePos.y = (short)(uint)(((uint)m.LParam & 0xFFFF0000U) >> 16); // Box to transfer as parameter OnContext(new Point(mousePos.x, mousePos.y)); return; } } base.WndProc(ref m); }
/// <summary> /// Apply the hot zone change. /// </summary> /// <param name="screenPos">Screen position when change applied.</param> /// <param name="parent">Parent redocker instance.</param> /// <returns>true is successful; otherwise false.</returns> public override bool ApplyChange(Point screenPos, Redocker parent) { // If docking back to itself then refuse to apply the change, this will cause the // WindowContentTabbed object to put back the content which is the desired effect if (_itself) { return(false); } // We are only called from the RedockerContent class RedockerContent redock = parent as RedockerContent; DockingManager dockingManager = redock.DockingManager; bool becomeFloating = (_wct.ParentZone.State == State.Floating); // Reduce flicker during transition dockingManager.Container.SuspendLayout(); // Manageing Zones should remove display AutoHide windows dockingManager.RemoveShowingAutoHideWindows(); switch (redock.DockingSource) { case RedockerContent.Source.WindowContent: { // Perform State specific Restore actions if (becomeFloating) { foreach (Content c in redock.WindowContent.Contents) { c.ContentBecomesFloating(); } } else { // If the source is leaving the Floating state then need to record Restore positions if (redock.WindowContent.State == State.Floating) { foreach (Content c in redock.WindowContent.Contents) { c.ContentLeavesFloating(); } } } int count = redock.WindowContent.Contents.Count; for (int index = 0; index < count; index++) { Content c = redock.WindowContent.Contents[0]; // Remove Content from previous WindowContent redock.WindowContent.Contents.RemoveAt(0); // Add into new WindowContent _wct.Contents.Add(c); _wct.BringContentToFront(c); } } break; case RedockerContent.Source.ContentInsideWindow: { // Perform State specific Restore actions if (becomeFloating) { redock.Content.ContentBecomesFloating(); } else { // If the source is leaving the Floating state then need to record Restore position if (redock.Content.ParentWindowContent.State == State.Floating) { redock.Content.ContentLeavesFloating(); } } // Remove Content from existing WindowContent if (redock.Content.ParentWindowContent != null) { redock.Content.ParentWindowContent.Contents.Remove(redock.Content); } _wct.Contents.Add(redock.Content); _wct.BringContentToFront(redock.Content); } break; case RedockerContent.Source.FloatingForm: { // Perform State specific Restore actions if (!becomeFloating) { // Make every Content object in the Floating Zone // record its current state as the Floating state redock.FloatingForm.ExitFloating(); } int wCount = redock.FloatingForm.Zone.Windows.Count; for (int wIndex = 0; wIndex < wCount; wIndex++) { WindowContent wc = redock.FloatingForm.Zone.Windows[0] as WindowContent; if (wc != null) { int cCount = wc.Contents.Count; for (int cIndex = 0; cIndex < cCount; cIndex++) { // Get reference to first content in collection Content c = wc.Contents[0]; // Remove from old WindowContent wc.Contents.RemoveAt(0); // Add into new WindowContentTabbed _wct.Contents.Add(c); _wct.BringContentToFront(c); } } } } break; } dockingManager.UpdateInsideFill(); // Reduce flicker during transition dockingManager.Container.ResumeLayout(); return(true); }
/// <summary> /// Apply the hot zone change. /// </summary> /// <param name="screenPos">Screen position when change applied.</param> /// <param name="parent">Parent redocker instance.</param> /// <returns>true is successful; otherwise false.</returns> public override bool ApplyChange(Point screenPos, Redocker parent) { // We are only called from the RedockerContent class RedockerContent redock = parent as RedockerContent; DockingManager dockingManager = redock.DockingManager; // Reduce flicker during transition dockingManager.Container.SuspendLayout(); // Need to create a new Zone Zone zone; if (redock.DockingSource == RedockerContent.Source.FloatingForm) { // Make every Content object in the Floating Zone // record its current state as the Floating state redock.FloatingForm.ExitFloating(); zone = redock.FloatingForm.Zone; } else { zone = dockingManager.CreateZoneForContent(_state); } // Insert Zone at end of Controls collection dockingManager.Container.Controls.Add(zone); // Adjust ordering switch (_position) { case Position.Inner: dockingManager.ReorderZoneToInnerMost(zone); break; case Position.Index: // Manageing Zones should remove display AutoHide windows dockingManager.RemoveShowingAutoHideWindows(); // Place new Zone AFTER the one given, so need to increase index by one dockingManager.Container.Controls.SetChildIndex(zone, _newIndex + 1); break; case Position.Outer: dockingManager.ReorderZoneToOuterMost(zone); break; } switch (redock.DockingSource) { case RedockerContent.Source.WindowContent: // Remove WindowContent from old Zone if (redock.WindowContent.ParentZone != null) { // If the source is leaving the Floating state then need to record Restore positions if (redock.WindowContent.State == State.Floating) { foreach (Content c in redock.WindowContent.Contents) { c.ContentLeavesFloating(); } } redock.WindowContent.ParentZone.Windows.Remove(redock.WindowContent); } // Add into new Zone zone.Windows.Add(redock.WindowContent); break; case RedockerContent.Source.ContentInsideWindow: { // Remove Content from existing WindowContent if (redock.Content.ParentWindowContent != null) { // If the source is leaving the Floating state then need to record Restore position if (redock.Content.ParentWindowContent.State == State.Floating) { redock.Content.ContentLeavesFloating(); } redock.Content.ParentWindowContent.Contents.Remove(redock.Content); } // Create a new WindowContent to host Content Window w = dockingManager.CreateWindowForContent(redock.Content); // Add into Zone zone.Windows.Add(w); } break; case RedockerContent.Source.FloatingForm: DockStyle ds; LayoutDirection direction; dockingManager.ValuesFromState(_state, out ds, out direction); // Define correct docking style to match state zone.Dock = ds; ZoneSequence zs = zone as ZoneSequence; // Define correct display direction to match state if (zs != null) { zs.Direction = direction; } // Ensure the Zone recalculates contents according to new state zone.State = _state; break; } // Define correct size of the new Zone switch (_state) { case State.DockLeft: case State.DockRight: zone.Width = NewSize.Width; break; case State.DockTop: case State.DockBottom: zone.Height = NewSize.Height; break; } dockingManager.UpdateInsideFill(); // Reduce flicker during transition dockingManager.Container.ResumeLayout(); return(true); }
/// <summary> /// Apply the hot zone change. /// </summary> /// <param name="screenPos">Screen position when change applied.</param> /// <param name="parent">Parent redocker instance.</param> /// <returns>true is successful; otherwise false.</returns> public override bool ApplyChange(Point screenPos, Redocker parent) { // We are only called from the RedockerContent class RedockerContent redock = parent as RedockerContent; DockingManager dockingManager = redock.DockingManager; bool becomeFloating = (_zs.State == State.Floating); // Reduce flicker during transition dockingManager.Container.SuspendLayout(); // Manageing Zones should remove display AutoHide windows dockingManager.RemoveShowingAutoHideWindows(); switch (redock.DockingSource) { case RedockerContent.Source.WindowContent: { // Is the destination Zone in the Floating state? if (becomeFloating) { foreach (Content c in redock.WindowContent.Contents) { c.ContentBecomesFloating(); } } else { if (redock.WindowContent.State == State.Floating) { foreach (Content c in redock.WindowContent.Contents) { c.ContentLeavesFloating(); } } } // Check if the WindowContent source is in same Zone if (redock.WindowContent.ParentZone == _zs) { // Find current position of source WindowContent int currPos = _zs.Windows.IndexOf(redock.WindowContent); // If current window is before the new position then the current // window will disappear before the new one is inserted,so need to // adjust down the new insertion point if (currPos < _index) { _index--; } } // Create a new Window to host Content WindowContent wc = dockingManager.CreateWindowForContent(null) as WindowContent; // Transfer content across int count = redock.WindowContent.Contents.Count; for (int index = 0; index < count; index++) { Content c = redock.WindowContent.Contents[0]; // Remove from existing location redock.WindowContent.Contents.RemoveAt(0); // Add into new WindowContent host wc.Contents.Add(c); } // Add into host into Zone _zs.Windows.Insert(_index, wc); } break; case RedockerContent.Source.ContentInsideWindow: { // Perform State specific Restore actions if (becomeFloating) { redock.Content.ContentBecomesFloating(); } else { if (redock.Content.ParentWindowContent.State == State.Floating) { redock.Content.ContentLeavesFloating(); } } // Remove Content from existing WindowContent if (redock.Content.ParentWindowContent != null) { // Will removing the Content cause the WindowContent to die? if (redock.Content.ParentWindowContent.Contents.Count == 1) { // Check if the WindowContent source is in same Zone if (redock.Content.ParentWindowContent.ParentZone == _zs) { // Find current position of source WindowContent int currPos = _zs.Windows.IndexOf(redock.Content.ParentWindowContent); // If current window is before the new position then the current // window will disappear before the new one is inserted,so need to // adjust down the new insertion point if (currPos < _index) { _index--; } } } redock.Content.ParentWindowContent.Contents.Remove(redock.Content); } // Create a new Window to host Content Window w = dockingManager.CreateWindowForContent(redock.Content); // Add into Zone _zs.Windows.Insert(_index, w); } break; case RedockerContent.Source.FloatingForm: { // Perform State specific Restore actions if (!becomeFloating) { // Make every Content object in the Floating Zone // record its current state as the Floating state redock.FloatingForm.ExitFloating(); } int count = redock.FloatingForm.Zone.Windows.Count; for (int index = count - 1; index >= 0; index--) { // Remember the Window reference Window w = redock.FloatingForm.Zone.Windows[index]; // Remove from floating collection redock.FloatingForm.Zone.Windows.RemoveAt(index); // Add into new ZoneSequence destination _zs.Windows.Insert(_index, w); } } break; } dockingManager.UpdateInsideFill(); // Reduce flicker during transition dockingManager.Container.ResumeLayout(); return(true); }