[8616] | 1 | using System;
|
---|
| 2 | using System.ComponentModel;
|
---|
| 3 | using System.Drawing;
|
---|
| 4 | using System.Windows.Forms;
|
---|
| 5 | using System.Runtime.InteropServices;
|
---|
| 6 | using System.Diagnostics.CodeAnalysis;
|
---|
| 7 |
|
---|
| 8 | namespace WeifenLuo.WinFormsUI.Docking
|
---|
| 9 | {
|
---|
| 10 | public class DockContent : Form, IDockContent
|
---|
| 11 | {
|
---|
| 12 | public DockContent()
|
---|
| 13 | {
|
---|
| 14 | m_dockHandler = new DockContentHandler(this, new GetPersistStringCallback(GetPersistString));
|
---|
| 15 | m_dockHandler.DockStateChanged += new EventHandler(DockHandler_DockStateChanged);
|
---|
| 16 | //Suggested as a fix by bensty regarding form resize
|
---|
| 17 | this.ParentChanged += new EventHandler(DockContent_ParentChanged);
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | //Suggested as a fix by bensty regarding form resize
|
---|
| 21 | private void DockContent_ParentChanged(object Sender, EventArgs e)
|
---|
| 22 | {
|
---|
| 23 | if (this.Parent != null)
|
---|
| 24 | this.Font = this.Parent.Font;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | private DockContentHandler m_dockHandler = null;
|
---|
| 28 | [Browsable(false)]
|
---|
| 29 | public DockContentHandler DockHandler
|
---|
| 30 | {
|
---|
| 31 | get { return m_dockHandler; }
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | [LocalizedCategory("Category_Docking")]
|
---|
| 35 | [LocalizedDescription("DockContent_AllowEndUserDocking_Description")]
|
---|
| 36 | [DefaultValue(true)]
|
---|
| 37 | public bool AllowEndUserDocking
|
---|
| 38 | {
|
---|
| 39 | get { return DockHandler.AllowEndUserDocking; }
|
---|
| 40 | set { DockHandler.AllowEndUserDocking = value; }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | [LocalizedCategory("Category_Docking")]
|
---|
| 44 | [LocalizedDescription("DockContent_DockAreas_Description")]
|
---|
| 45 | [DefaultValue(DockAreas.DockLeft|DockAreas.DockRight|DockAreas.DockTop|DockAreas.DockBottom|DockAreas.Document|DockAreas.Float)]
|
---|
| 46 | public DockAreas DockAreas
|
---|
| 47 | {
|
---|
| 48 | get { return DockHandler.DockAreas; }
|
---|
| 49 | set { DockHandler.DockAreas = value; }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | [LocalizedCategory("Category_Docking")]
|
---|
| 53 | [LocalizedDescription("DockContent_AutoHidePortion_Description")]
|
---|
| 54 | [DefaultValue(0.25)]
|
---|
| 55 | public double AutoHidePortion
|
---|
| 56 | {
|
---|
| 57 | get { return DockHandler.AutoHidePortion; }
|
---|
| 58 | set { DockHandler.AutoHidePortion = value; }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | private string m_tabText = null;
|
---|
| 62 | [Localizable(true)]
|
---|
| 63 | [LocalizedCategory("Category_Docking")]
|
---|
| 64 | [LocalizedDescription("DockContent_TabText_Description")]
|
---|
| 65 | [DefaultValue(null)]
|
---|
| 66 | public string TabText
|
---|
| 67 | {
|
---|
| 68 | get { return m_tabText; }
|
---|
| 69 | set { DockHandler.TabText = m_tabText = value; }
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | private bool ShouldSerializeTabText()
|
---|
| 73 | {
|
---|
| 74 | return (m_tabText != null);
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | [LocalizedCategory("Category_Docking")]
|
---|
| 78 | [LocalizedDescription("DockContent_CloseButton_Description")]
|
---|
| 79 | [DefaultValue(true)]
|
---|
| 80 | public bool CloseButton
|
---|
| 81 | {
|
---|
| 82 | get { return DockHandler.CloseButton; }
|
---|
| 83 | set { DockHandler.CloseButton = value; }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | [LocalizedCategory("Category_Docking")]
|
---|
| 87 | [LocalizedDescription("DockContent_CloseButtonVisible_Description")]
|
---|
| 88 | [DefaultValue(true)]
|
---|
| 89 | public bool CloseButtonVisible
|
---|
| 90 | {
|
---|
| 91 | get { return DockHandler.CloseButtonVisible; }
|
---|
| 92 | set { DockHandler.CloseButtonVisible = value; }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | [Browsable(false)]
|
---|
| 96 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
---|
| 97 | public DockPanel DockPanel
|
---|
| 98 | {
|
---|
| 99 | get { return DockHandler.DockPanel; }
|
---|
| 100 | set { DockHandler.DockPanel = value; }
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | [Browsable(false)]
|
---|
| 104 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
---|
| 105 | public DockState DockState
|
---|
| 106 | {
|
---|
| 107 | get { return DockHandler.DockState; }
|
---|
| 108 | set { DockHandler.DockState = value; }
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | [Browsable(false)]
|
---|
| 112 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
---|
| 113 | public DockPane Pane
|
---|
| 114 | {
|
---|
| 115 | get { return DockHandler.Pane; }
|
---|
| 116 | set { DockHandler.Pane = value; }
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | [Browsable(false)]
|
---|
| 120 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
---|
| 121 | public bool IsHidden
|
---|
| 122 | {
|
---|
| 123 | get { return DockHandler.IsHidden; }
|
---|
| 124 | set { DockHandler.IsHidden = value; }
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | [Browsable(false)]
|
---|
| 128 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
---|
| 129 | public DockState VisibleState
|
---|
| 130 | {
|
---|
| 131 | get { return DockHandler.VisibleState; }
|
---|
| 132 | set { DockHandler.VisibleState = value; }
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | [Browsable(false)]
|
---|
| 136 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
---|
| 137 | public bool IsFloat
|
---|
| 138 | {
|
---|
| 139 | get { return DockHandler.IsFloat; }
|
---|
| 140 | set { DockHandler.IsFloat = value; }
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | [Browsable(false)]
|
---|
| 144 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
---|
| 145 | public DockPane PanelPane
|
---|
| 146 | {
|
---|
| 147 | get { return DockHandler.PanelPane; }
|
---|
| 148 | set { DockHandler.PanelPane = value; }
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | [Browsable(false)]
|
---|
| 152 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
---|
| 153 | public DockPane FloatPane
|
---|
| 154 | {
|
---|
| 155 | get { return DockHandler.FloatPane; }
|
---|
| 156 | set { DockHandler.FloatPane = value; }
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
|
---|
| 160 | protected virtual string GetPersistString()
|
---|
| 161 | {
|
---|
| 162 | return GetType().ToString();
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | [LocalizedCategory("Category_Docking")]
|
---|
| 166 | [LocalizedDescription("DockContent_HideOnClose_Description")]
|
---|
| 167 | [DefaultValue(false)]
|
---|
| 168 | public bool HideOnClose
|
---|
| 169 | {
|
---|
| 170 | get { return DockHandler.HideOnClose; }
|
---|
| 171 | set { DockHandler.HideOnClose = value; }
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | [LocalizedCategory("Category_Docking")]
|
---|
| 175 | [LocalizedDescription("DockContent_ShowHint_Description")]
|
---|
| 176 | [DefaultValue(DockState.Unknown)]
|
---|
| 177 | public DockState ShowHint
|
---|
| 178 | {
|
---|
| 179 | get { return DockHandler.ShowHint; }
|
---|
| 180 | set { DockHandler.ShowHint = value; }
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | [Browsable(false)]
|
---|
| 184 | public bool IsActivated
|
---|
| 185 | {
|
---|
| 186 | get { return DockHandler.IsActivated; }
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | public bool IsDockStateValid(DockState dockState)
|
---|
| 190 | {
|
---|
| 191 | return DockHandler.IsDockStateValid(dockState);
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | [LocalizedCategory("Category_Docking")]
|
---|
| 195 | [LocalizedDescription("DockContent_TabPageContextMenu_Description")]
|
---|
| 196 | [DefaultValue(null)]
|
---|
| 197 | public ContextMenu TabPageContextMenu
|
---|
| 198 | {
|
---|
| 199 | get { return DockHandler.TabPageContextMenu; }
|
---|
| 200 | set { DockHandler.TabPageContextMenu = value; }
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | [LocalizedCategory("Category_Docking")]
|
---|
| 204 | [LocalizedDescription("DockContent_TabPageContextMenuStrip_Description")]
|
---|
| 205 | [DefaultValue(null)]
|
---|
| 206 | public ContextMenuStrip TabPageContextMenuStrip
|
---|
| 207 | {
|
---|
| 208 | get { return DockHandler.TabPageContextMenuStrip; }
|
---|
| 209 | set { DockHandler.TabPageContextMenuStrip = value; }
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | [Localizable(true)]
|
---|
| 213 | [Category("Appearance")]
|
---|
| 214 | [LocalizedDescription("DockContent_ToolTipText_Description")]
|
---|
| 215 | [DefaultValue(null)]
|
---|
| 216 | public string ToolTipText
|
---|
| 217 | {
|
---|
| 218 | get { return DockHandler.ToolTipText; }
|
---|
| 219 | set { DockHandler.ToolTipText = value; }
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | public new void Activate()
|
---|
| 223 | {
|
---|
| 224 | DockHandler.Activate();
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | public new void Hide()
|
---|
| 228 | {
|
---|
| 229 | DockHandler.Hide();
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | public new void Show()
|
---|
| 233 | {
|
---|
| 234 | DockHandler.Show();
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | public void Show(DockPanel dockPanel)
|
---|
| 238 | {
|
---|
| 239 | DockHandler.Show(dockPanel);
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | public void Show(DockPanel dockPanel, DockState dockState)
|
---|
| 243 | {
|
---|
| 244 | DockHandler.Show(dockPanel, dockState);
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | [SuppressMessage("Microsoft.Naming", "CA1720:AvoidTypeNamesInParameters")]
|
---|
| 248 | public void Show(DockPanel dockPanel, Rectangle floatWindowBounds)
|
---|
| 249 | {
|
---|
| 250 | DockHandler.Show(dockPanel, floatWindowBounds);
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | public void Show(DockPane pane, IDockContent beforeContent)
|
---|
| 254 | {
|
---|
| 255 | DockHandler.Show(pane, beforeContent);
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | public void Show(DockPane previousPane, DockAlignment alignment, double proportion)
|
---|
| 259 | {
|
---|
| 260 | DockHandler.Show(previousPane, alignment, proportion);
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 | [SuppressMessage("Microsoft.Naming", "CA1720:AvoidTypeNamesInParameters")]
|
---|
| 264 | public void FloatAt(Rectangle floatWindowBounds)
|
---|
| 265 | {
|
---|
| 266 | DockHandler.FloatAt(floatWindowBounds);
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | public void DockTo(DockPane paneTo, DockStyle dockStyle, int contentIndex)
|
---|
| 270 | {
|
---|
| 271 | DockHandler.DockTo(paneTo, dockStyle, contentIndex);
|
---|
| 272 | }
|
---|
| 273 |
|
---|
| 274 | public void DockTo(DockPanel panel, DockStyle dockStyle)
|
---|
| 275 | {
|
---|
| 276 | DockHandler.DockTo(panel, dockStyle);
|
---|
| 277 | }
|
---|
| 278 |
|
---|
| 279 | #region IDockContent Members
|
---|
| 280 | void IDockContent.OnActivated(EventArgs e)
|
---|
| 281 | {
|
---|
| 282 | this.OnActivated(e);
|
---|
| 283 | }
|
---|
| 284 |
|
---|
| 285 | void IDockContent.OnDeactivate(EventArgs e)
|
---|
| 286 | {
|
---|
| 287 | this.OnDeactivate(e);
|
---|
| 288 | }
|
---|
| 289 | #endregion
|
---|
| 290 |
|
---|
| 291 | #region Events
|
---|
| 292 | private void DockHandler_DockStateChanged(object sender, EventArgs e)
|
---|
| 293 | {
|
---|
| 294 | OnDockStateChanged(e);
|
---|
| 295 | }
|
---|
| 296 |
|
---|
| 297 | private static readonly object DockStateChangedEvent = new object();
|
---|
| 298 | [LocalizedCategory("Category_PropertyChanged")]
|
---|
| 299 | [LocalizedDescription("Pane_DockStateChanged_Description")]
|
---|
| 300 | public event EventHandler DockStateChanged
|
---|
| 301 | {
|
---|
| 302 | add { Events.AddHandler(DockStateChangedEvent, value); }
|
---|
| 303 | remove { Events.RemoveHandler(DockStateChangedEvent, value); }
|
---|
| 304 | }
|
---|
| 305 | protected virtual void OnDockStateChanged(EventArgs e)
|
---|
| 306 | {
|
---|
| 307 | EventHandler handler = (EventHandler)Events[DockStateChangedEvent];
|
---|
| 308 | if (handler != null)
|
---|
| 309 | handler(this, e);
|
---|
| 310 | }
|
---|
| 311 | #endregion
|
---|
| 312 |
|
---|
| 313 | /// <summary>
|
---|
| 314 | /// Overridden to avoid resize issues with nested controls
|
---|
| 315 | /// </summary>
|
---|
| 316 | /// <remarks>
|
---|
| 317 | /// http://blogs.msdn.com/b/alejacma/archive/2008/11/20/controls-won-t-get-resized-once-the-nesting-hierarchy-of-windows-exceeds-a-certain-depth-x64.aspx
|
---|
| 318 | /// http://support.microsoft.com/kb/953934
|
---|
| 319 | /// </remarks>
|
---|
| 320 | protected override void OnSizeChanged(EventArgs e)
|
---|
| 321 | {
|
---|
| 322 | if (DockPanel != null && DockPanel.SupportDeeplyNestedContent && IsHandleCreated)
|
---|
| 323 | {
|
---|
| 324 | BeginInvoke((MethodInvoker)delegate
|
---|
| 325 | {
|
---|
| 326 | base.OnSizeChanged(e);
|
---|
| 327 | });
|
---|
| 328 | }
|
---|
| 329 | else
|
---|
| 330 | {
|
---|
| 331 | base.OnSizeChanged(e);
|
---|
| 332 | }
|
---|
| 333 | }
|
---|
| 334 | }
|
---|
| 335 | }
|
---|