| 0: | // DockRegion.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 TimeSprint.Alexandria.UI.Tab; | |
| 22: | ||
| 23: | namespace SharpDevelop.Gui.Docking { | |
| 24: | ||
| 25: | public class DockContainer : UserControl | |
| 26: | { | |
| 27: | AxTabControl tabcontrol = new AxTabControl(); | |
| 28: | public ArrayList docked = new ArrayList(); | |
| 29: | DockRegion region; | |
| 30: | ||
| 31: | public event EventHandler UndockEvent; | |
| 32: | MouseEventArgs meventargs; | |
| 33: | ContextMenu formatmenu = null; | |
| 34: | ||
| 35: | ||
| 36: | protected override void OnMouseDown(MouseEventArgs e) | |
| 37: | { | |
| 38: | meventargs = e; | |
| 39: | base.OnMouseDown(e); | |
| 40: | } | |
| 41: | ||
| 42: | protected override void OnClick(EventArgs e) | |
| 43: | { | |
| 44: | base.OnClick(e); | |
| 45: | ||
| 46: | if (meventargs.Button == MouseButtons.Middle && formatmenu != null) { | |
| 47: | formatmenu.Show(this, new Point(meventargs.X, meventargs.Y)); | |
| 48: | } | |
| 49: | } | |
| 50: | ||
| 51: | public DockContainer(DockRegion region) | |
| 52: | { | |
| 53: | tabcontrol.TabSummary.Visible = false; | |
| 54: | tabcontrol.Dock = DockStyle.Fill; | |
| 55: | this.region = region; | |
| 56: | formatmenu = new ContextMenu( new MenuItem[] { | |
| 57: | new MenuItem("Undock", new EventHandler(Undock)), | |
| 58: | new MenuItem("TabUp", new EventHandler(TabUp)), | |
| 59: | new MenuItem("TabDown", new EventHandler(TabDown)), | |
| 60: | new MenuItem("TabLeft", new EventHandler(TabLeft)), | |
| 61: | new MenuItem("TabRight", new EventHandler(TabRight)), | |
| 62: | // new MenuItem("MoveDown", new EventHandler(MoveDown)), | |
| 63: | // new MenuItem("MoveUp", new EventHandler(MoveUp)) | |
| 64: | }); | |
| 65: | } | |
| 66: | ||
| 67: | public void AddDockableControl(DockableControl control) | |
| 68: | { | |
| 69: | control.formatmenu = new ContextMenu( new MenuItem[] { | |
| 70: | new MenuItem("Undock", new EventHandler(Undock)), | |
| 71: | // new MenuItem("MoveDown", new EventHandler(MoveDown)), | |
| 72: | // new MenuItem("MoveUp", new EventHandler(MoveUp)) | |
| 73: | }); | |
| 74: | ||
| 75: | switch (docked.Count) { | |
| 76: | case 0: | |
| 77: | control.TabControl = null; | |
| 78: | control.TabPage = null; | |
| 79: | Controls.Add(control); | |
| 80: | break; | |
| 81: | case 1: | |
| 82: | Controls.Clear(); | |
| 83: | Controls.Add(tabcontrol); | |
| 84: | DockableControl control2 = (DockableControl)docked[0]; | |
| 85: | AxTabPage page2 = new AxTabPage(control2.TabName); | |
| 86: | ||
| 87: | page2.TabFlap.Image = control2.Icon; | |
| 88: | page2.Controls.Add(control2); | |
| 89: | control2.TabControl = tabcontrol; | |
| 90: | control2.TabPage = page2; | |
| 91: | tabcontrol.TabPages.Add(page2); | |
| 92: | tabcontrol.SelectedTab = page2; | |
| 93: | goto default; | |
| 94: | default: | |
| 95: | AxTabPage page = new AxTabPage(control.TabName); | |
| 96: | page.TabFlap.Image = control.Icon; | |
| 97: | page.Controls.Add(control); | |
| 98: | control.TabControl = tabcontrol; | |
| 99: | control.TabPage = page; | |
| 100: | tabcontrol.TabPages.Add(page); | |
| 101: | break; | |
| 102: | } | |
| 103: | docked.Add(control); | |
| 104: | } | |
| 105: | ||
| 106: | void TabUp(object sender, EventArgs e) | |
| 107: | { | |
| 108: | tabcontrol.Alignment = AxTabAlignment.Top; | |
| 109: | } | |
| 110: | void TabDown(object sender, EventArgs e) | |
| 111: | { | |
| 112: | tabcontrol.Alignment = AxTabAlignment.Bottom; | |
| 113: | } | |
| 114: | void TabLeft(object sender, EventArgs e) | |
| 115: | { | |
| 116: | tabcontrol.Alignment = AxTabAlignment.Left; | |
| 117: | } | |
| 118: | void TabRight(object sender, EventArgs e) | |
| 119: | { | |
| 120: | tabcontrol.Alignment = AxTabAlignment.Right; | |
| 121: | } | |
| 122: | ||
| 123: | // void MoveDown(object sender, EventArgs e) | |
| 124: | // { | |
| 125: | // | |
| 126: | // } | |
| 127: | // | |
| 128: | // void MoveUp(object sender, EventArgs e) | |
| 129: | // { | |
| 130: | // | |
| 131: | // } | |
| 132: | ||
| 133: | void Undock(object sender, EventArgs e) | |
| 134: | { | |
| 135: | DockableControl dc; | |
| 136: | if (docked.Count > 1) { | |
| 137: | dc = (DockableControl)tabcontrol.SelectedTab.Controls[0]; | |
| 138: | tabcontrol.TabPages.Remove(tabcontrol.SelectedTab); | |
| 139: | } else { | |
| 140: | dc = (DockableControl)Controls[0]; | |
| 141: | } | |
| 142: | ||
| 143: | dc.formatmenu = null; | |
| 144: | new FloatingWindow(region.manager, dc).Show(); | |
| 145: | docked.Remove(dc); | |
| 146: | ||
| 147: | if (docked.Count == 1) { | |
| 148: | Controls.Clear(); | |
| 149: | Controls.Add((DockableControl)docked[0]); | |
| 150: | ((DockableControl)docked[0]).TabPage = null; | |
| 151: | tabcontrol.TabPages.Clear(); | |
| 152: | } | |
| 153: | ||
| 154: | if (docked.Count == 0) { | |
| 155: | Visible = false; | |
| 156: | Dock = DockStyle.None; | |
| 157: | } | |
| 158: | if (UndockEvent != null) | |
| 159: | UndockEvent(this, null); | |
| 160: | } | |
| 161: | ||
| 162: | } | |
| 163: | ||
| 164: | public class DockRegion : UserControl | |
| 165: | { | |
| 166: | public DockManager manager; | |
| 167: | Splitter splitter = new Splitter(); | |
| 168: | DockStyle mydockstyle = DockStyle.None; | |
| 169: | ArrayList dockcontainer = new ArrayList(); | |
| 170: | ||
| 171: | ||
| 172: | public DockRegion(DockManager manager) | |
| 173: | { | |
| 174: | this.manager = manager; | |
| 175: | ||
| 176: | ||
| 177: | splitter.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; | |
| 178: | splitter.Location = new System.Drawing.Point(0, 200); | |
| 179: | splitter.TabIndex = 5; | |
| 180: | splitter.TabStop = false; | |
| 181: | splitter.Size = new System.Drawing.Size(3, 273); | |
| 182: | ||
| 183: | Visible = false; | |
| 184: | splitter.Visible = false; | |
| 185: | ||
| 186: | manager.parent.Controls.Add(splitter); | |
| 187: | manager.parent.Controls.Add(this); | |
| 188: | } | |
| 189: | ||
| 190: | void Undock(object sender, EventArgs e) | |
| 191: | { | |
| 192: | ArrayList remove = new ArrayList(); | |
| 193: | for (int i = 0; i < dockcontainer.Count; ++i) { | |
| 194: | DockContainer container = (DockContainer)dockcontainer[i]; | |
| 195: | if (container.docked.Count == 0) { | |
| 196: | remove.Add(container); | |
| 197: | } | |
| 198: | } | |
| 199: | foreach (object o in remove) | |
| 200: | dockcontainer.Remove(o); | |
| 201: | ||
| 202: | if (dockcontainer.Count == 0) { | |
| 203: | splitter.Visible = false; | |
| 204: | Visible = false; | |
| 205: | // manager.parent.Controls.Remove(this); | |
| 206: | } | |
| 207: | } | |
| 208: | ||
| 209: | void ControlsVisibleChanged(object sender, EventArgs e) | |
| 210: | { | |
| 211: | bool somethingvisible = false; | |
| 212: | foreach (DockContainer container in dockcontainer) | |
| 213: | foreach (DockableControl control in container.docked) | |
| 214: | somethingvisible |= control.DockState.Visible; | |
| 215: | ||
| 216: | if (!somethingvisible) { | |
| 217: | Visible = false; | |
| 218: | splitter.Visible = false; | |
| 219: | } else { | |
| 220: | if (!Visible) { | |
| 221: | splitter.Visible = true; | |
| 222: | Visible = true; | |
| 223: | } | |
| 224: | } | |
| 225: | } | |
| 226: | ||
| 227: | ||
| 228: | public void SetDock(DockStyle dock) | |
| 229: | { | |
| 230: | mydockstyle = dock; | |
| 231: | } | |
| 232: | ||
| 233: | public void AddDockableControl(DockableControl control) | |
| 234: | { | |
| 235: | control.DockState.Float = false; | |
| 236: | control.FormContainer = null; | |
| 237: | control.DockedVisibleChanged += new EventHandler(ControlsVisibleChanged); | |
| 238: | ||
| 239: | if (dockcontainer.Count == 0) { | |
| 240: | DockContainer newcontainer = new DockContainer(this); | |
| 241: | dockcontainer.Add(newcontainer); | |
| 242: | Controls.Add(newcontainer); | |
| 243: | newcontainer.UndockEvent += new EventHandler(Undock); | |
| 244: | newcontainer.Dock = DockStyle.Fill; | |
| 245: | } | |
| 246: | ||
| 247: | DockContainer container = (DockContainer)dockcontainer[0]; | |
| 248: | container.AddDockableControl(control); | |
| 249: | if (!Visible) { | |
| 250: | // manager.parent.Controls.Add(this); | |
| 251: | splitter.Dock = mydockstyle; | |
| 252: | Dock = mydockstyle; | |
| 253: | splitter.Visible = true; | |
| 254: | Visible = true; | |
| 255: | } | |
| 256: | } | |
| 257: | } | |
| 258: | } |
This page was automatically generated by SharpDevelop.