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.RawContent: { // Create a new Window to host Content Window w = dockingManager.CreateWindowForContent(redock.Content); // Add into Zone zone.Windows.Add(w); } break; 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; Direction 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); }
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.RawContent: { // Perform State specific Restore actions redock.Content.ContentBecomesFloating(); // 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.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.Location = new Point(_drawRect.Left, _drawRect.Top); floating.Size = new Size(_drawRect.Width, _drawRect.Height); // Show it! floating.Show(); return(true); }
public override void PerformRestore(DockingManager dm) { int count = dm.Container.Controls.Count; int min = -1; int max = count; if (dm.InnerControl != null) { min = dm.Container.Controls.IndexOf(dm.InnerControl); } if (dm.OuterControl != null) { max = dm.OuterControlIndex(); } int beforeIndex = -1; int afterIndex = max; int beforeAllIndex = -1; int afterAllIndex = max; // Create a collection of the Zones in the appropriate direction for (int index = 0; index < count; index++) { Zone z = dm.Container.Controls[index] as Zone; if (z != null) { StringCollection sc = ZoneHelper.ContentNames(z); if (_state == z.State) { if (sc.Contains(_best)) { // Can we delegate to a child Restore object if (_child != null) { _child.PerformRestore(z); } else { // Just add an appropriate Window to start of the Zone dm.AddContentToZone(_content, z, 0); } return; } // If the WindowContent contains a Content previous to the target if (sc.Contains(_previous)) { if (index > beforeIndex) { beforeIndex = index; } } // If the WindowContent contains a Content next to the target if (sc.Contains(_next)) { if (index < afterIndex) { afterIndex = index; } } } else { // If the WindowContent contains a Content previous to the target if (sc.Contains(_previousAll)) { if (index > beforeAllIndex) { beforeAllIndex = index; } } // If the WindowContent contains a Content next to the target if (sc.Contains(_nextAll)) { if (index < afterAllIndex) { afterAllIndex = index; } } } } } dm.Container.SuspendLayout(); // Create a new Zone with correct State Zone newZ = dm.CreateZoneForContent(_state); // Restore the correct content size/location values _content.DisplaySize = _size; _content.DisplayLocation = _location; // Add an appropriate Window to start of the Zone dm.AddContentToZone(_content, newZ, 0); // Did we find a valid 'before' Zone? if (beforeIndex != -1) { // Try and place more accurately according to other edge Zones if (beforeAllIndex > beforeIndex) { beforeIndex = beforeAllIndex; } // Check against limits if (beforeIndex >= max) { beforeIndex = max - 1; } dm.Container.Controls.SetChildIndex(newZ, beforeIndex + 1); } else { // Try and place more accurately according to other edge Zones if (afterAllIndex < afterIndex) { afterIndex = afterAllIndex; } // Check against limits if (afterIndex <= min) { afterIndex = min + 1; } if (afterIndex > min) { dm.Container.Controls.SetChildIndex(newZ, afterIndex); } else { // Set the Zone to be the least important of our Zones dm.ReorderZoneToInnerMost(newZ); } } dm.Container.ResumeLayout(); }