context: using System;
  using System.Windows.Forms;
  using System.Drawing;
  using System.ComponentModel;
  using System.Diagnostics.CodeAnalysis;
  
  namespace WeifenLuo.WinFormsUI.Docking
  {
  	public delegate string GetPersistStringCallback();
  
  	public class DockContentHandler : IDisposable, IDockDragSource
  	{
  		public DockContentHandler(Form form) : this(form, null)
  		{
  		}
  
  		public DockContentHandler(Form form, GetPersistStringCallback getPersistStringCallback)
  		{
  			if (!(form is IDockContent))
  				throw new ArgumentException(Strings.DockContent_Constructor_InvalidForm, "form");
  
  			m_form = form;
  			m_getPersistStringCallback = getPersistStringCallback;
  
  			m_events = new EventHandlerList();
  			Form.Disposed +=new EventHandler(Form_Disposed);
  			Form.TextChanged += new EventHandler(Form_TextChanged);
  		}
  
  		public void Dispose()
  		{
  			Dispose(true);
  			GC.SuppressFinalize(this);
  		}
  
  		protected virtual void Dispose(bool disposing)
  		{
  			if(disposing)
  			{
  				lock(this)
  				{
  					DockPanel = null;
  					if (m_autoHideTab != null)
  						m_autoHideTab.Dispose();
  					if (m_tab != null)
  						m_tab.Dispose();
  
  					Form.Disposed -= new EventHandler(Form_Disposed);
  					Form.TextChanged -= new EventHandler(Form_TextChanged);
  					m_events.Dispose();
  				}
  			}
  		}
  
  		private Form m_form;
  		public Form Form
  		{
  			get	{	return m_form;	}
  		}
  
  		public IDockContent Content
  		{
  			get	{	return Form as IDockContent;	}
  		}
  
          private IDockContent m_previousActive = null;
          public IDockContent PreviousActive
          {
              get { return m_previousActive; }
              internal set { m_previousActive = value; }
          }
  
          private IDockContent m_nextActive = null;
          public IDockContent NextActive
          {
              get { return m_nextActive; }
              internal set { m_nextActive = value; }
          }
  
  		private EventHandlerList m_events;
  		private EventHandlerList Events
  		{
  			get	{	return m_events;	}
  		}
  
  		private bool m_allowEndUserDocking = true;
  		public bool AllowEndUserDocking
  		{
  			get	{	return m_allowEndUserDocking;	}
  			set	{	m_allowEndUserDocking = value;	}
  		}
  
  		private double m_autoHidePortion = 0.25;
  		public double AutoHidePortion
  		{
  			get	{	return m_autoHidePortion;	}
  			set
  			{
  				if (value <= 0)
  					throw(new ArgumentOutOfRangeException(Strings.DockContentHandler_AutoHidePortion_OutOfRange));
  
  				if (m_autoHidePortion == value)
  					return;
  
  				m_autoHidePortion = value;
  
  				if (DockPanel == null)
  					return;
  
  				if (DockPanel.ActiveAutoHideContent == Content)
  					DockPanel.PerformLayout();
  			}
  		}
  
  		private bool m_closeButton = true;
  		public bool CloseButton
  		{
  			get	{	return m_closeButton;	}
  			set
  			{
  				if (m_closeButton == value)
  					return;
  
  				m_closeButton = value;
  				if (Pane != null)
  					if (Pane.ActiveContent.DockHandler == this)
  						Pane.RefreshChanges();
  			}
  		}
  		
  		private DockState DefaultDockState
  		{
  			get
  			{
  				if (ShowHint != DockState.Unknown && ShowHint != DockState.Hidden)
  					return ShowHint;
  
  				if ((DockAreas & DockAreas.Document) != 0)
  					return DockState.Document;
  				if ((DockAreas & DockAreas.DockRight) != 0)
  					return DockState.DockRight;
  				if ((DockAreas & DockAreas.DockLeft) != 0)
  					return DockState.DockLeft;
  				if ((DockAreas & DockAreas.DockBottom) != 0)
  					return DockState.DockBottom;
  				if ((DockAreas & DockAreas.DockTop) != 0)
  					return DockState.DockTop;
  
  				return DockState.Unknown;
  			}
  		}
  
  		private DockState DefaultShowState
  		{
  			get
  			{
  				if (ShowHint != DockState.Unknown)
  					return ShowHint;
  
  				if ((DockAreas & DockAreas.Document) != 0)
  					return DockState.Document;
  				if ((DockAreas & DockAreas.DockRight) != 0)
  					return DockState.DockRight;
  				if ((DockAreas & DockAreas.DockLeft) != 0)
  					return DockState.DockLeft;
  				if ((DockAreas & DockAreas.DockBottom) != 0)
  					return DockState.DockBottom;
  				if ((DockAreas & DockAreas.DockTop) != 0)
  					return DockState.DockTop;
  				if ((DockAreas & DockAreas.Float) != 0)
  					return DockState.Float;
  
  				return DockState.Unknown;
  			}
  		}
  
  		private DockAreas m_allowedAreas = DockAreas.DockLeft | DockAreas.DockRight | DockAreas.DockTop | DockAreas.DockBottom | DockAreas.Document | DockAreas.Float;
  		public DockAreas DockAreas
  		{
  			get	{	return m_allowedAreas;	}
  			set
  			{
  				if (m_allowedAreas == value)
  					return;
  
  				if (!DockHelper.IsDockStateValid(DockState, value))
  					throw(new InvalidOperationException(Strings.DockContentHandler_DockAreas_InvalidValue));
  
  				m_allowedAreas = value;
  
  				if (!DockHelper.IsDockStateValid(ShowHint, m_allowedAreas))
  					ShowHint = DockState.Unknown;
  			}
  		}
  
  		private DockState m_dockState = DockState.Unknown;
  		public DockState DockState
  		{
  			get	{	return m_dockState;	}
  			set
  			{
  				if (m_dockState == value)
  					return;
  
                  DockPanel.SuspendLayout(true);
  
  				if (value == DockState.Hidden)
  					IsHidden = true;
  				else
  					SetDockState(false, value, Pane);
  
                  DockPanel.ResumeLayout(true, true);
  			}
  		}
  
  		private DockPanel m_dockPanel = null;
  		public DockPanel DockPanel
  		{
  
gt: 			get { return m_dockPanel; }