| 0: | // DockManager.cs | |
| 1: | // Copyright (C) 2001 Mike Krueger | |
| 2: | // | |
| 3: | // This program is free software; you can redistribute it and/or modify | |
| 4: | // it under the terms of the GNU General Public License as published by | |
| 5: | // the Free Software Foundation; either version 2 of the License, or | |
| 6: | // (at your option) any later version. | |
| 7: | // | |
| 8: | // This program is distributed in the hope that it will be useful, | |
| 9: | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10: | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 11: | // GNU General Public License for more details. | |
| 12: | // | |
| 13: | // You should have received a copy of the GNU General Public License | |
| 14: | // along with this program; if not, write to the Free Software | |
| 15: | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 16: | ||
| 17: | using System; | |
| 18: | using System.Drawing; | |
| 19: | using System.Collections; | |
| 20: | using System.Windows.Forms; | |
| 21: | using System.Xml; | |
| 22: | ||
| 23: | using SharpDevelop.Tool.Data; | |
| 24: | ||
| 25: | namespace SharpDevelop.Gui.Docking { | |
| 26: | ||
| 27: | public class DockManagerState : IXmlConvertable | |
| 28: | { | |
| 29: | public Rectangle leftbounds = new Rectangle(0, 0, -1, -1); | |
| 30: | public Rectangle rightbounds = new Rectangle(0, 0, -1, -1); | |
| 31: | public Rectangle topbounds = new Rectangle(0, 0, -1, -1); | |
| 32: | public Rectangle bottombounds = new Rectangle(0, 0, -1, -1); | |
| 33: | ||
| 34: | public DockManagerState() | |
| 35: | { | |
| 36: | } | |
| 37: | ||
| 38: | public DockManagerState(XmlElement element) | |
| 39: | { | |
| 40: | string[] boundstr = element["LeftBounds"].InnerText.Split(new char [] {'|'}); | |
| 41: | leftbounds = new Rectangle (Int32.Parse(boundstr[0]), | |
| 42: | Int32.Parse(boundstr[1]), | |
| 43: | Int32.Parse(boundstr[2]), | |
| 44: | Int32.Parse(boundstr[3])); | |
| 45: | ||
| 46: | boundstr = element["RightBounds"].InnerText.Split(new char [] {'|'}); | |
| 47: | rightbounds = new Rectangle (Int32.Parse(boundstr[0]), | |
| 48: | Int32.Parse(boundstr[1]), | |
| 49: | Int32.Parse(boundstr[2]), | |
| 50: | Int32.Parse(boundstr[3])); | |
| 51: | ||
| 52: | boundstr = element["TopBounds"].InnerText.Split(new char [] {'|'}); | |
| 53: | topbounds = new Rectangle (Int32.Parse(boundstr[0]), | |
| 54: | Int32.Parse(boundstr[1]), | |
| 55: | Int32.Parse(boundstr[2]), | |
| 56: | Int32.Parse(boundstr[3])); | |
| 57: | ||
| 58: | boundstr = element["BottomBounds"].InnerText.Split(new char [] {'|'}); | |
| 59: | bottombounds = new Rectangle (Int32.Parse(boundstr[0]), | |
| 60: | Int32.Parse(boundstr[1]), | |
| 61: | Int32.Parse(boundstr[2]), | |
| 62: | Int32.Parse(boundstr[3])); | |
| 63: | ||
| 64: | } | |
| 65: | ||
| 66: | public object FromXmlElement(XmlElement element) | |
| 67: | { | |
| 68: | return new DockManagerState(element); | |
| 69: | } | |
| 70: | ||
| 71: | public XmlElement ToXmlElement(XmlDocument doc) | |
| 72: | { | |
| 73: | XmlElement element = doc.CreateElement("DockManagerState"); | |
| 74: | ||
| 75: | XmlElement leftboundsel = doc.CreateElement("LeftBounds"); | |
| 76: | leftboundsel.InnerText = leftbounds.X + "|" + | |
| 77: | leftbounds.Y + "|" + | |
| 78: | leftbounds.Width + "|" + | |
| 79: | leftbounds.Height; | |
| 80: | element.AppendChild(leftboundsel); | |
| 81: | ||
| 82: | XmlElement rightboundsel = doc.CreateElement("RightBounds"); | |
| 83: | rightboundsel.InnerText = rightbounds.X + "|" + | |
| 84: | rightbounds.Y + "|" + | |
| 85: | rightbounds.Width + "|" + | |
| 86: | rightbounds.Height; | |
| 87: | element.AppendChild(rightboundsel); | |
| 88: | ||
| 89: | XmlElement topboundsel = doc.CreateElement("TopBounds"); | |
| 90: | topboundsel.InnerText = topbounds.X + "|" + | |
| 91: | topbounds.Y + "|" + | |
| 92: | topbounds.Width + "|" + | |
| 93: | topbounds.Height; | |
| 94: | element.AppendChild(topboundsel); | |
| 95: | ||
| 96: | XmlElement bottomboundsel = doc.CreateElement("BottomBounds"); | |
| 97: | bottomboundsel.InnerText = bottombounds.X + "|" + | |
| 98: | bottombounds.Y + "|" + | |
| 99: | bottombounds.Width + "|" + | |
| 100: | bottombounds.Height; | |
| 101: | element.AppendChild(bottomboundsel); | |
| 102: | ||
| 103: | return element; | |
| 104: | } | |
| 105: | } | |
| 106: | ||
| 107: | public class DockManager | |
| 108: | { | |
| 109: | public Form parent; | |
| 110: | ArrayList controls = new ArrayList(); | |
| 111: | public DockRegion left, right, top, bottom; | |
| 112: | ||
| 113: | public DockManagerState DockManagerState { | |
| 114: | get { | |
| 115: | DockManagerState state = new DockManagerState(); | |
| 116: | state.leftbounds = left.Bounds; | |
| 117: | state.rightbounds = right.Bounds; | |
| 118: | state.topbounds = top.Bounds; | |
| 119: | state.bottombounds = bottom.Bounds; | |
| 120: | return state; | |
| 121: | } | |
| 122: | set { | |
| 123: | if (value.leftbounds.Width != -1) | |
| 124: | left.Bounds = value.leftbounds; | |
| 125: | if (value.rightbounds.Width != -1) | |
| 126: | right.Bounds = value.rightbounds; | |
| 127: | if (value.topbounds.Width != -1) | |
| 128: | top.Bounds = value.topbounds; | |
| 129: | if (value.bottombounds.Width != -1) | |
| 130: | bottom.Bounds = value.bottombounds; | |
| 131: | } | |
| 132: | ||
| 133: | } | |
| 134: | ||
| 135: | public DockManager(Form parent) | |
| 136: | { | |
| 137: | this.parent = parent; | |
| 138: | ||
| 139: | top = new DockRegion(this); | |
| 140: | top.SetDock(DockStyle.Top); | |
| 141: | ||
| 142: | bottom = new DockRegion(this); | |
| 143: | bottom.SetDock(DockStyle.Bottom); | |
| 144: | ||
| 145: | left = new DockRegion(this); | |
| 146: | left.SetDock(DockStyle.Left); | |
| 147: | ||
| 148: | right = new DockRegion(this); | |
| 149: | right.SetDock(DockStyle.Right); | |
| 150: | } | |
| 151: | ||
| 152: | public void Add(DockableControl control, DockState state) | |
| 153: | { | |
| 154: | controls.Add(control); | |
| 155: | control.DockState = state; | |
| 156: | InitControl(control, state); | |
| 157: | } | |
| 158: | ||
| 159: | void InitControl(DockableControl control, DockState state) | |
| 160: | { | |
| 161: | if (state == null || state.Float) { | |
| 162: | FloatingWindow window = new FloatingWindow(this, control); | |
| 163: | if (state != null && state.Bounds.Width != -1) { | |
| 164: | window.Bounds = state.Bounds; | |
| 165: | } | |
| 166: | window.Show(); | |
| 167: | if (state != null && state.Bounds.Width != -1) | |
| 168: | window.Location = new Point(state.Bounds.X, state.Bounds.Y); | |
| 169: | } else { | |
| 170: | switch (state.DockedIn) { | |
| 171: | case DockedIn.LeftContainer: | |
| 172: | left.AddDockableControl(control); | |
| 173: | break; | |
| 174: | case DockedIn.RightContainer: | |
| 175: | right.AddDockableControl(control); | |
| 176: | break; | |
| 177: | case DockedIn.TopContainer: | |
| 178: | top.AddDockableControl(control); | |
| 179: | break; | |
| 180: | case DockedIn.BottomContainer: | |
| 181: | bottom.AddDockableControl(control); | |
| 182: | break; | |
| 183: | } | |
| 184: | } | |
| 185: | if (state != null && !state.Visible) | |
| 186: | control.HideDockedControl(); | |
| 187: | } | |
| 188: | } | |
| 189: | } |
This page was automatically generated by SharpDevelop.