📄 dockmanager.cs
字号:
// DockManager.cs
// Copyright (C) 2001 Mike Krueger
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Xml;
using SharpDevelop.Tool.Data;
namespace SharpDevelop.Gui.Docking {
public class DockManagerState : XmlConvertable
{
public Rectangle leftbounds = new Rectangle(0, 0, -1, -1);
public Rectangle rightbounds = new Rectangle(0, 0, -1, -1);
public Rectangle topbounds = new Rectangle(0, 0, -1, -1);
public Rectangle bottombounds = new Rectangle(0, 0, -1, -1);
public DockManagerState()
{
}
public DockManagerState(XmlElement element)
{
string[] boundstr = element["LeftBounds"].InnerText.Split(new char [] {'|'});
leftbounds = new Rectangle (Int32.Parse(boundstr[0]),
Int32.Parse(boundstr[1]),
Int32.Parse(boundstr[2]),
Int32.Parse(boundstr[3]));
boundstr = element["RightBounds"].InnerText.Split(new char [] {'|'});
rightbounds = new Rectangle (Int32.Parse(boundstr[0]),
Int32.Parse(boundstr[1]),
Int32.Parse(boundstr[2]),
Int32.Parse(boundstr[3]));
boundstr = element["TopBounds"].InnerText.Split(new char [] {'|'});
topbounds = new Rectangle (Int32.Parse(boundstr[0]),
Int32.Parse(boundstr[1]),
Int32.Parse(boundstr[2]),
Int32.Parse(boundstr[3]));
boundstr = element["BottomBounds"].InnerText.Split(new char [] {'|'});
bottombounds = new Rectangle (Int32.Parse(boundstr[0]),
Int32.Parse(boundstr[1]),
Int32.Parse(boundstr[2]),
Int32.Parse(boundstr[3]));
}
public object FromXmlElement(XmlElement element)
{
return new DockManagerState(element);
}
public XmlElement ToXmlElement(XmlDocument doc)
{
XmlElement element = doc.CreateElement("DockManagerState");
XmlElement leftboundsel = doc.CreateElement("LeftBounds");
leftboundsel.InnerText = leftbounds.X + "|" +
leftbounds.Y + "|" +
leftbounds.Width + "|" +
leftbounds.Height;
element.AppendChild(leftboundsel);
XmlElement rightboundsel = doc.CreateElement("RightBounds");
rightboundsel.InnerText = rightbounds.X + "|" +
rightbounds.Y + "|" +
rightbounds.Width + "|" +
rightbounds.Height;
element.AppendChild(rightboundsel);
XmlElement topboundsel = doc.CreateElement("TopBounds");
topboundsel.InnerText = topbounds.X + "|" +
topbounds.Y + "|" +
topbounds.Width + "|" +
topbounds.Height;
element.AppendChild(topboundsel);
XmlElement bottomboundsel = doc.CreateElement("BottomBounds");
bottomboundsel.InnerText = bottombounds.X + "|" +
bottombounds.Y + "|" +
bottombounds.Width + "|" +
bottombounds.Height;
element.AppendChild(bottomboundsel);
return element;
}
}
public class DockManager
{
public Form parent;
ArrayList controls = new ArrayList();
public DockRegion left, right, top, bottom;
public DockManagerState DockManagerState {
get {
DockManagerState state = new DockManagerState();
state.leftbounds = left.Bounds;
state.rightbounds = right.Bounds;
state.topbounds = top.Bounds;
state.bottombounds = bottom.Bounds;
return state;
}
set {
if (value.leftbounds.Width != -1)
left.Bounds = value.leftbounds;
if (value.rightbounds.Width != -1)
right.Bounds = value.rightbounds;
if (value.topbounds.Width != -1)
top.Bounds = value.topbounds;
if (value.bottombounds.Width != -1)
bottom.Bounds = value.bottombounds;
}
}
public DockManager(Form parent)
{
this.parent = parent;
top = new DockRegion(this);
top.SetDock(DockStyle.Top);
bottom = new DockRegion(this);
bottom.SetDock(DockStyle.Bottom);
left = new DockRegion(this);
left.SetDock(DockStyle.Left);
right = new DockRegion(this);
right.SetDock(DockStyle.Right);
}
public void Add(DockableControl control, DockState state)
{
controls.Add(control);
control.DockState = state;
InitControl(control, state);
}
void InitControl(DockableControl control, DockState state)
{
if (state == null || state.Float) {
FloatingWindow window = new FloatingWindow(this, control);
if (state != null && state.Bounds.Width != -1) {
window.Bounds = state.Bounds;
}
window.Show();
if (state != null && state.Bounds.Width != -1)
window.Location = new Point(state.Bounds.X, state.Bounds.Y);
} else {
switch (state.DockedIn) {
case DockedIn.LeftContainer:
left.AddDockableControl(control);
break;
case DockedIn.RightContainer:
right.AddDockableControl(control);
break;
case DockedIn.TopContainer:
top.AddDockableControl(control);
break;
case DockedIn.BottomContainer:
bottom.AddDockableControl(control);
break;
}
}
if (state != null && !state.Visible)
control.HideDockedControl();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -