?? zonesequence.cs
字號:
// *****************************************************************************
//
// (c) Crownwood Consulting Limited 2002
// All rights reserved. The software and associated documentation
// supplied hereunder are the proprietary information of Crownwood Consulting
// Limited, Haxey, North Lincolnshire, England and are supplied subject to
// licence terms.
//
// Magic Version 1.7 www.dotnetmagic.com
// *****************************************************************************
using System;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using Crownwood.Magic.Common;
using Crownwood.Magic.Docking;
using Crownwood.Magic.Controls;
using Crownwood.Magic.Collections;
namespace Crownwood.Magic.Docking
{
[ToolboxItem(false)]
public class ZoneSequence : Zone, IHotZoneSource, IZoneMaximizeWindow, IResizeSource
{
protected struct Position
{
public int length;
}
// Class constants
protected const int _spacePrecision = 3;
protected const int _hotVectorBeforeControl = 5;
// Instance fields
protected VisualStyle _style;
protected Direction _direction;
protected ResizeBar _resizeBar;
protected Window _maximizedWindow;
protected bool _suppressReposition;
protected bool _zoneMinMax;
// Instance events
public event EventHandler RefreshMaximize;
public ZoneSequence(DockingManager manager)
: base(manager)
{
InternalConstruct(VisualStyle.IDE, Direction.Vertical, true);
}
public ZoneSequence(DockingManager manager, State state, VisualStyle style, Direction direction, bool zoneMinMax)
: base(manager, state)
{
InternalConstruct(style, direction, zoneMinMax);
}
protected void InternalConstruct(VisualStyle style, Direction direction, bool zoneMinMax)
{
// Remember initial state
_style = style;
_direction = direction;
_maximizedWindow = null;
_suppressReposition = false;
_zoneMinMax = zoneMinMax;
// Create the control used to resize the whole Zone
_resizeBar = new ResizeBar(_direction, this);
// Place last in the list of child Controls
Controls.Add(_resizeBar);
// Start of very small and let first content determine new size
this.Size = new Size(0,0);
// Do not inherit the parent BackColor, we want the .Control color as
// this blends in with the way all the docking windows are drawn
this.BackColor = SystemColors.Control;
this.ForeColor = SystemColors.ControlText;
}
public override int MinimumWidth
{
get { return _resizeBar.Width * 5; }
}
public override int MinimumHeight
{
get { return _resizeBar.Height * 6; }
}
public override DockStyle Dock
{
get { return base.Dock; }
set
{
base.Dock = value;
RepositionControls();
}
}
public Direction Direction
{
get { return _direction; }
set
{
if (_direction != value)
_direction = value;
}
}
public override State State
{
set
{
base.State = value;
// Inform each Window of the new requried state
foreach(Window w in _windows)
w.State = value;
RepositionControls();
}
}
public void SuppressReposition()
{
_suppressReposition = true;
}
public bool IsMaximizeAvailable()
{
return (_windows.Count > 1) && _zoneMinMax;
}
public bool IsWindowMaximized(Window w)
{
return (w == _maximizedWindow);
}
public void MaximizeWindow(Window w)
{
// Remember the newly maximized Window
_maximizedWindow = w;
// Inform all interested parties of change
OnRefreshMaximize(EventArgs.Empty);
RepositionControls();
}
public void RestoreWindow()
{
// Remember the newly maximized Window
_maximizedWindow = null;
// Inform all interested parties of change
OnRefreshMaximize(EventArgs.Empty);
RepositionControls();
}
public virtual void OnRefreshMaximize(EventArgs e)
{
// Any attached event handlers?
if (RefreshMaximize != null)
RefreshMaximize(this, e);
}
public Color ResizeBarColor
{
get { return _manager.ResizeBarColor; }
}
public int ResizeBarVector
{
get { return _manager.ResizeBarVector; }
}
public VisualStyle Style
{
get { return _manager.Style; }
}
public Color BackgroundColor
{
get { return _manager.BackColor; }
}
public bool CanResize(ResizeBar bar)
{
// Is this the Window resize bar?
if (bar != _resizeBar)
{
// Find position of this ResizeBar in the Controls collection
int barIndex = Controls.IndexOf(bar);
// The Window before this bar must be the one before it in the collection
Window wBefore = Controls[barIndex - 1] as Window;
// The Window after this bar must be the one after it in the Window collection
Window wAfter = _windows[_windows.IndexOf(wBefore) + 1];
// If Windows either side of the bar have no space then cannot resize there relative positions
if (((wBefore.ZoneArea <= 0m) && (wAfter.ZoneArea <= 0m)))
return false;
// If in maximized state and the bar is not connected to the maximized window
if ((_maximizedWindow != null) && (_maximizedWindow != wBefore) && (_maximizedWindow != wAfter))
return false;
}
return true;
}
public bool StartResizeOperation(ResizeBar bar, ref Rectangle screenBoundary)
{
// Is this the Zone level resize bar?
if (bar == _resizeBar)
{
// Define resize boundary as the inner area of the Form containing the Zone
screenBoundary = this.Parent.RectangleToScreen(_manager.InnerResizeRectangle(this));
// Find the screen limits of this Zone
Rectangle zoneBoundary = RectangleToScreen(this.ClientRectangle);
int minHeight = this.MinimumHeight;
int minWidth = this.MinimumWidth;
// Restrict resize based on which edge we are attached against
switch(_state)
{
case State.DockTop:
{
// Restrict Zone being made smaller than its minimum height
int diff = zoneBoundary.Top - screenBoundary.Top + minHeight;
screenBoundary.Y += diff;
screenBoundary.Height -= diff;
// Restrict Zone from making inner control smaller than minimum allowed
int innerMinimumWidth = _manager.InnerMinimum.Height;
screenBoundary.Height -= innerMinimumWidth;
}
break;
case State.DockBottom:
{
// Restrict Zone being made smaller than its minimum height
int diff = zoneBoundary.Bottom - screenBoundary.Bottom - minHeight;
screenBoundary.Height += diff;
// Restrict Zone from making inner control smaller than minimum allowed
int innerMinimumWidth = _manager.InnerMinimum.Height;
screenBoundary.Y += innerMinimumWidth;
screenBoundary.Height -= innerMinimumWidth;
}
break;
case State.DockLeft:
{
// Restrict Zone being made smaller than its minimum width
int diff = zoneBoundary.Left - screenBoundary.Left + minWidth;
screenBoundary.X += diff;
screenBoundary.Width -= diff;
// Restrict Zone from making inner control smaller than minimum allowed
int innerMinimumWidth = _manager.InnerMinimum.Width;
screenBoundary.Width -= innerMinimumWidth;
}
break;
case State.DockRight:
{
// Restrict Zone being made smaller than its minimum width
int diff = zoneBoundary.Right - screenBoundary.Right - minWidth;
screenBoundary.Width += diff;
// Restrict Zone from making inner control smaller than minimum allowed
int innerMinimumWidth = _manager.InnerMinimum.Width;
screenBoundary.X += innerMinimumWidth;
screenBoundary.Width -= innerMinimumWidth;
}
break;
}
}
else
{
// Find position of this ResizeBar in the Controls collection
int barIndex = Controls.IndexOf(bar);
// Define resize boundary as the client area of the Zone
screenBoundary = RectangleToScreen(this.ClientRectangle);
// The Window before this bar must be the one before it in the collection
Window wBefore = Controls[barIndex - 1] as Window;
// The Window after this bar must be the one after it in the Window collection
Window wAfter = _windows[_windows.IndexOf(wBefore) + 1];
// Find screen rectangle for the Windows either side of the bar
Rectangle rectBefore = wBefore.RectangleToScreen(wBefore.ClientRectangle);
Rectangle rectAfter = wAfter.RectangleToScreen(wAfter.ClientRectangle);
// Reduce the boundary in the appropriate direction
if (_direction == Direction.Vertical)
{
screenBoundary.Y = rectBefore.Y + wBefore.MinimalSize.Height;
screenBoundary.Height -= screenBoundary.Bottom - rectAfter.Bottom;
screenBoundary.Height -= wAfter.MinimalSize.Height;
}
else
{
screenBoundary.X = rectBefore.X + wBefore.MinimalSize.Width;
screenBoundary.Width -= screenBoundary.Right - rectAfter.Right;
screenBoundary.Width -= wAfter.MinimalSize.Width;
}
}
// Allow resize operation to occur
return true;
}
public void EndResizeOperation(ResizeBar bar, int delta)
{
// Is this the Zone level resize bar?
if (bar == _resizeBar)
{
switch(this.Dock)
{
case DockStyle.Left:
this.Width += delta;
break;
case DockStyle.Right:
this.Width -= delta;
break;
case DockStyle.Top:
this.Height += delta;
break;
case DockStyle.Bottom:
this.Height -= delta;
break;
}
}
else
{
// Find position of this ResizeBar in the Controls collection
int barIndex = Controls.IndexOf(bar);
// The Window relating to this bar must be the one before it in the collection
Window w = Controls[barIndex - 1] as Window;
// Is the Window being expanded
ModifyWindowSpace(w, delta);
}
}
public override Restore RecordRestore(Window w, object child, Restore childRestore)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -