Example #1
0
        /// <summary>
        /// Sets Bar visible property and remembers the auto-hide state.
        /// </summary>
        /// <param name="bar">Bar to set visibility for.</param>
        /// <param name="visible">true if visible otherwise false</param>
        public static void SetBarVisible(Bar bar, bool visible)
        {
            if (bar == null || bar.Visible == visible)
                return;

            DotNetBarManager manager = bar.Owner as DotNetBarManager;
            if (manager != null)
                manager.SuspendLayout = true;

            try
            {
                if (visible)
                {
                    bar.Visible = true;
                    if (bar.PropertyBag.ContainsKey(BarPropertyBagKeys.AutoHideSetting))
                    {
                        bar.PropertyBag.Remove(BarPropertyBagKeys.AutoHideSetting);
                        bar.AutoHide = true;
                    }
                }
                else
                {
                    if (bar.PropertyBag.ContainsKey(BarPropertyBagKeys.AutoHideSetting))
                        bar.PropertyBag.Remove(BarPropertyBagKeys.AutoHideSetting);
                    // Remember auto-hide setting
                    if (bar.AutoHide)
                        bar.PropertyBag.Add(BarPropertyBagKeys.AutoHideSetting, true);
                    bar.CloseBar();
                }
            }
            finally
            {
                if (manager != null)
                    manager.SuspendLayout = false;
                bar.RecalcLayout();
            }
        }
Example #2
0
        /// <summary>
        /// Sets the visible property of DockContainerItem and hides the bar if the given item is the last visible item on the bar.
        /// It will also automatically display the bar if bar is not visible.
        /// </summary>
        /// <param name="item">DockContainerItem to set visibility for.</param>
        /// <param name="visible">Indicates the visibility of the item</param>
        private void SetDockContainerVisible(DevComponents.DotNetBar.DockContainerItem item, bool visible)
        {
            if (item == null || item.Visible == visible)
            {
                return;
            }

            int visibleCount = 0;

            DevComponents.DotNetBar.Bar containerBar = item.ContainerControl as DevComponents.DotNetBar.Bar;
            if (containerBar == null)
            {
                // If bar has not been assigned yet just set the visible property and exit
                item.Visible = visible;
                return;
            }

            DotNetBarManager manager = containerBar.Owner as DotNetBarManager;

            if (manager != null)
            {
                manager.SuspendLayout = true;
            }

            try
            {
                foreach (DevComponents.DotNetBar.BaseItem dockItem in containerBar.Items)
                {
                    if (dockItem.Visible)
                    {
                        visibleCount++;
                    }
                }

                if (visible)
                {
                    item.Visible = true;
                    if (!containerBar.AutoHide && !containerBar.Visible && visibleCount <= 1)
                    {
                        containerBar.Visible = true;
                        if (containerBar.Tag == null)
                        {
                            containerBar.Tag = "";
                        }
                        if (containerBar.Tag.ToString() == "autohide")
                        {
                            containerBar.AutoHide = true;
                        }
                    }
                }
                else
                {
                    item.Visible = false;
                    if (visibleCount == 1)
                    {
                        // Remember auto-hide setting
                        if (containerBar.AutoHide)
                        {
                            containerBar.AutoHide = false;
                            containerBar.Tag      = "autohide";
                        }
                        else
                        {
                            containerBar.Tag = "";
                        }

                        containerBar.Visible = false;
                    }
                }
            }
            finally
            {
                if (manager != null)
                {
                    manager.SuspendLayout = false;
                }
                else
                {
                    containerBar.RecalcLayout();
                }
            }
        }
Example #3
0
		/// <summary>
		/// build (or rebuild) the toolbar
		/// </summary>
		/// <param name="group"></param>
		/// <param name="toolbar"></param>
		private void FillToolbar(ChoiceGroup group, Bar toolbar)
		{
			bool wantsSeparatorBefore = false;
			string groupName =group.Label;

			ClearOutToolbar(toolbar);
			foreach(ChoiceRelatedClass item  in group)
			{
				string itemName =item.Label;
				if(item is SeparatorChoice)
					wantsSeparatorBefore = true;
				else if(item is ChoiceBase)
				{
					ChoiceBase choice = (ChoiceBase) item;
					UIItemDisplayProperties display = choice.GetDisplayProperties();

					if (!display.Visible)
						continue;
					ButtonItem btn = CreateButtonItem(choice, wantsSeparatorBefore);
					btn.Enabled = display.Enabled;
					btn.Category = group.Label;
					toolbar.Items.Add(btn);
					// DIDN'T WORK
					//					if(!Manager.Items.Contains(btn.Name))
					//							Manager.Items.Add(btn.Copy());
					wantsSeparatorBefore = false;
				}
				else if(item is ChoiceGroup) // Submenu
				{
					ChoiceGroup choiceGroup = (ChoiceGroup)item;

					//nb: the DNB class name, "ComboBoxItem" is very misleading. This is the box itself,
					//not an item in the box.
					ComboBoxItem combo = new ComboBoxItem(/*name*/item.Id,/*text*/item.Label);
					toolbar.Items.Add(combo);
					combo.Tag = item;
					int width = 100;
					// Make this configurable from the xml
					XmlAttribute att = item.ConfigurationNode.Attributes["width"];
					if (att != null)
						width = Int32.Parse(att.Value);
					combo.ComboWidth = width;
					//combo.Stretch = true;//doesn't help

					item.ReferenceWidget = combo;
					//submenu.IsEnabled= true;
					//the drop down the event seems to be ignored by the submenusof this package.
					//submenu.DropDown += new System.EventHandler(((ChoiceGroup)item).OnDisplay);
					//therefore, we need to populate the submenu right now and not wait
					choiceGroup.OnDisplay(m_window, null);

					//hide if no sub items were added

					//submenu.Visible = submenu.SubItems.Count>0;
				}
				else
				{
					// TODO: Add support for other types of toolbar objects.
				}
			}
			toolbar.RecalcLayout();
			toolbar.RecalcSize();
		}
Example #4
0
        public void DockingHandler(DockSiteInfo pDockInfo, Point p)
        {
            IOwner owner = m_Owner as IOwner;

            if (m_TempTabBar != null && pDockInfo.TabDockContainer == m_TempTabBar)
                return;

            if (pDockInfo.objDockSite == null && (m_BarState != eBarState.Floating || m_Float == null))
            {
                m_DockingInProgress = true;

                if (m_TempTabBar != null)
                {
                    RemoveTempTabBarItems();
                    m_TempTabBar.RecalcLayout();
                    m_TempTabBar = null;
                }

                // Remember last docking info
                DockSiteInfo tempInfo = m_LastDockSiteInfo;
                m_LastDockSiteInfo = new DockSiteInfo();
                // Preserve the relative last docked to bar in case the return to same docking position is needed
                m_LastDockSiteInfo.LastRelativeDocumentId = tempInfo.LastRelativeDocumentId;
                m_LastDockSiteInfo.LastRelativeDockToBar = tempInfo.LastRelativeDockToBar;

                m_LastDockSiteInfo.DockedHeight = this.Height;
                m_LastDockSiteInfo.DockedWidth = this.Width;
                m_LastDockSiteInfo.DockLine = this.DockLine;
                m_LastDockSiteInfo.DockOffset = this.DockOffset;
                if (this.Parent != null)
                    m_LastDockSiteInfo.DockSide = this.Parent.Dock;
                else
                    m_LastDockSiteInfo.DockSide = DockStyle.Left;

                if (this.Parent != null && this.Parent is DockSite)
                {
                    m_LastDockSiteInfo.InsertPosition = ((DockSite)this.Parent).Controls.GetChildIndex(this);
                    m_LastDockSiteInfo.objDockSite = (DockSite)this.DockedSite;
                }
                if (m_LastDockSiteInfo.objDockSite == null)
                {
                    IOwnerBarSupport barSupp = m_Owner as IOwnerBarSupport;
                    if (barSupp != null)
                    {
                        switch (m_LastDockSiteInfo.DockSide)
                        {
                            case DockStyle.Left:
                                m_LastDockSiteInfo.objDockSite = barSupp.LeftDockSite;
                                break;
                            case DockStyle.Right:
                                m_LastDockSiteInfo.objDockSite = barSupp.RightDockSite;
                                break;
                            case DockStyle.Top:
                                m_LastDockSiteInfo.objDockSite = barSupp.TopDockSite;
                                break;
                            case DockStyle.Bottom:
                                m_LastDockSiteInfo.objDockSite = barSupp.BottomDockSite;
                                break;
                            case DockStyle.Fill:
                                m_LastDockSiteInfo.objDockSite = barSupp.FillDockSite;
                                break;
                        }
                    }
                }

                // Undock the window
                m_BarState = eBarState.Floating;
                if (m_Float == null)
                {
                    m_Float = new FloatingContainer(this);
                    m_Float.CreateControl();
                }

                // Must reset the ActiveControl to null because on MDI Forms if this was not done
                // MDI form could not be closed if bar that had ActiveControl is floating.
                if (owner.ParentForm != null && owner.ParentForm.ActiveControl == this)
                {
                    owner.ParentForm.ActiveControl = null;
                    this.Focus(); // Fixes the problem on SDI forms
                }
                else if (owner.ParentForm != null && IsAnyControl(this, owner.ParentForm.ActiveControl))
                {
                    owner.ParentForm.ActiveControl = null;
                    this.Focus();
                }

                // Check for parent since if bar is deserialized there is no parent and state is Docked by default

                if (this.Parent != null && this.Parent is DockSite)
                {
                    if (((DockSite)this.Parent).IsDocumentDock || ((DockSite)this.Parent).DocumentDockContainer != null)
                    {
                        ((DockSite)this.Parent).GetDocumentUIManager().UnDock(this);
                    }
                    else
                        ((DockSite)this.Parent).RemoveBar(this);
                }

                this.Parent = null;
                m_Float.Controls.Add(this);
                if (!this.Visible/* && !m_BarDefinitionLoading*/)
                    base.Visible = true;
                // IMPORTANT SINCE WE OVERRIDE BASE LOCATION WE HAVE TO USE BASE HERE TO ACTUALLY MOVE IT
                base.Location = new Point(0, 0);

                m_FloatingRect = new Rectangle(m_FloatingRect.Location, GetFloatingSize());
                this.Size = m_FloatingRect.Size;

                this.DockOrientation = eOrientation.Horizontal;
                if (m_ItemContainer.LayoutType == eLayoutType.DockContainer && m_AlwaysDisplayDockTab)
                    RefreshDockTab(true);
                this.RecalcSize();
                m_FloatingRect.Size = this.Size;

                m_Float.Location = p;
                if (m_ItemContainer.LayoutType != eLayoutType.Toolbar)
                    m_MouseDownPt = new Point(this.Width / 2, 8);
                else
                    m_MouseDownPt = new Point(8, 8);

                if (m_LoadingHideFloating)
                    m_Float.Visible = false;
                else
                    m_Float.Show();

                m_FloatingRect.Location = m_Float.Location;

                // TODO: Bug Width was sometimes not reflected properly
                if (m_Float.Width != m_FloatingRect.Width)
                    m_Float.Width = m_FloatingRect.Width;

                if (owner.ParentForm != null)
                {
                    bool activate = true;
                    if (m_BarDefinitionLoading && owner is DotNetBarManager && !((DotNetBarManager)owner).ActivateOnLayoutLoad)
                        activate = false;
                    if (activate)
                        owner.ParentForm.Activate();
                }
                m_DockingInProgress = false;

                // Raise events
                if (BarUndock != null)
                    BarUndock(this, new EventArgs());
                IOwnerBarSupport ownerDockEvents = m_Owner as IOwnerBarSupport;
                if (ownerDockEvents != null)
                    ownerDockEvents.InvokeBarUndock(this, new EventArgs());
                OnBarStateChanged(new BarStateChangedEventArgs(this, eBarStateChange.BarUndocked));

                // Resize Docking Tab if it exists
                ResizeDockTab();
            }
            else
            {
                // Change the Z-Order of the dock-site if needed
                if ((pDockInfo.FullSizeDock || pDockInfo.PartialSizeDock) && pDockInfo.DockSiteZOrderIndex >= 0 && pDockInfo.objDockSite != null && pDockInfo.objDockSite.Parent != null)
                    pDockInfo.objDockSite.Parent.Controls.SetChildIndex(pDockInfo.objDockSite, pDockInfo.DockSiteZOrderIndex);

                if (m_Owner != null)
                {
                    if (pDockInfo.TabDockContainer != null)
                    {
                        if (m_TempTabBar != null && pDockInfo.TabDockContainer != m_TempTabBar)
                        {
                            RemoveTempTabBarItems();
                            m_TempTabBar.RecalcLayout();
                            m_TempTabBar = null;
                        }
                        if (m_TempTabBar != pDockInfo.TabDockContainer)
                        {
                            m_DockingInProgress = true;

                            if (m_DockTabTearOffIndex == -1)
                            {
                                if (m_Float != null && m_Float.Visible)
                                {
                                    if (owner.ParentForm != null)
                                        owner.ParentForm.Activate();
                                    // Remember undocked size
                                    m_FloatingRect = new Rectangle(m_Float.Location, this.Size);
                                    m_DockOffset = pDockInfo.DockOffset;
                                    m_DockLine = pDockInfo.DockLine;
                                    m_Float.Controls.Remove(this);
                                    m_Float.Hide();
                                    m_Float.Dispose();
                                    m_Float = null;
                                }
                                else if (this.Parent != null && this.Parent is DockSite)
                                    ((DockSite)this.Parent).RemoveBar(this);
                                m_BarState = eBarState.Docked;
                                if (!m_BarDefinitionLoading)
                                    base.Visible = false;

                                foreach (BaseItem item in m_ItemContainer.SubItems)
                                {
                                    DockContainerItem dockitem = item as DockContainerItem;
                                    if (dockitem != null)
                                    {
                                        DockContainerItem temp = new DockContainerItem();
                                        temp.Displayed = false;
                                        temp.Text = item.Text;
                                        temp.Image = dockitem.Image;
                                        temp.ImageIndex = dockitem.ImageIndex;
                                        temp.Icon = dockitem.Icon;
                                        temp.Tag = "systempdockitem";
                                        pDockInfo.TabDockContainer.Items.Add(temp);
                                    }
                                    m_TempTabBar = pDockInfo.TabDockContainer;
                                    m_TempTabBar.RecalcLayout();
                                    m_TempTabBar.Refresh();
                                }
                            }
                            else
                            {
                                DockContainerItem dockitem = m_ItemContainer.SubItems[m_DockTabTearOffIndex] as DockContainerItem;
                                if (dockitem != null)
                                {
                                    DockContainerItem temp = new DockContainerItem();
                                    temp.Displayed = false;
                                    temp.Text = dockitem.Text;
                                    temp.Image = dockitem.Image;
                                    temp.ImageIndex = dockitem.ImageIndex;
                                    temp.Icon = dockitem.Icon;
                                    temp.Tag = "systempdockitem";
                                    pDockInfo.TabDockContainer.Items.Add(temp);
                                }
                                m_TempTabBar = pDockInfo.TabDockContainer;
                                m_TempTabBar.RecalcLayout();
                                m_TempTabBar.Refresh();
                            }
                            m_DockingInProgress = false;
                        }

                    }
                    else
                    {
                        if (m_TempTabBar != null)
                        {
                            // Allow tabbed bar to change position only if it is going to different bar
                            if (pDockInfo.objDockSite == m_TempTabBar.Parent)
                                return;
                            RemoveTempTabBarItems();
                            m_TempTabBar.RecalcLayout();
                            m_TempTabBar = null;
                        }
                        // If coming from the tabs
                        if (!this.Visible && !m_BarDefinitionLoading)
                            this.Visible = true;
                        if (pDockInfo.LastRelativeDockToBar != null && pDockInfo.LastRelativeDockToBar.DockedSite != null && owner is DotNetBarManager)
                        {
                            DotNetBarManager manager = (DotNetBarManager)owner;
                            if (pDockInfo.LastRelativeDockToBar.AutoHide)
                            {
                                if (pDockInfo.objDockSite != null)
                                    pDockInfo.objDockSite.GetDocumentUIManager().Dock(this);
                                else
                                    manager.Dock(this, eDockSide.Right);
                            }
                            else if (!pDockInfo.LastRelativeDockToBar.Visible ||
                                pDockInfo.LastRelativeDockToBar.DockSide == eDockSide.None) // Closed or floating
                            {
                                manager.Dock(this, m_LastDockSiteInfo.LastDockSiteSide);
                            }
                            else if (pDockInfo.LastRelativeDockToBar.DockSide != eDockSide.None &&
                           m_LastDockSiteInfo.LastDockSiteSide != pDockInfo.LastRelativeDockToBar.DockSide) // Reference bar docked somewhere else
                            {
                                manager.Dock(this, m_LastDockSiteInfo.LastDockSiteSide);
                            }
                            else
                                manager.Dock(this, pDockInfo.LastRelativeDockToBar, LastDockSide);
                            if (this.IsDisposed) return;
                            m_BarState = eBarState.Docked;
                            pDockInfo.LastRelativeDockToBar = null;
                        }
                        else if (pDockInfo.objDockSite != null && m_BarState != eBarState.Docked)
                        {
                            m_DockingInProgress = true;
                            if (m_Float != null && m_BarState == eBarState.Floating)
                            {
                                if (owner.ParentForm != null)
                                    owner.ParentForm.Activate();
                                // Remember undocked size
                                m_FloatingRect = new Rectangle(m_Float.Location, this.Size);
                                m_DockOffset = pDockInfo.DockOffset;
                                m_DockLine = pDockInfo.DockLine;
                                m_Float.Controls.Remove(this);
                                m_Float.Hide();
                                m_Float.Dispose();
                                m_Float = null;
                            }
                            m_BarState = eBarState.Docked;

                            if (pDockInfo.objDockSite.IsDocumentDock || pDockInfo.objDockSite.DocumentDockContainer != null)
                            {
                                DockDocumentManager(pDockInfo);
                            }
                            else
                            {
                                if (pDockInfo.InsertPosition == -10)
                                    pDockInfo.objDockSite.AddBar(this);
                                else
                                    pDockInfo.objDockSite.AddBar(this, pDockInfo.InsertPosition);
                            }
                            m_DockingInProgress = false;

                            //							// Raise events
                            //							if(BarDock!=null)
                            //								BarDock(this,new EventArgs());
                            //							IOwnerBarSupport ownerDockEvents=m_Owner as IOwnerBarSupport;
                            //							if(ownerDockEvents!=null)
                            //								ownerDockEvents.InvokeBarDock(this,new EventArgs());
                        }
                        else if (pDockInfo.objDockSite != null && pDockInfo.objDockSite != this.Parent)
                        {
                            m_DockingInProgress = true;
                            // Must reset the ActiveControl to null becouse on MDI Forms if this was not done
                            // MDI form could not be closed if bar that had ActiveControl is floating.
                            if (owner.ParentForm != null && owner.ParentForm.ActiveControl == this)
                            {
                                owner.ParentForm.ActiveControl = null;
                                this.Focus(); // Fixes the problem on SDI forms
                            }
                            else if (owner.ParentForm != null && IsAnyControl(this, owner.ParentForm.ActiveControl))
                            {
                                owner.ParentForm.ActiveControl = null;
                                this.Focus();
                            }

                            // It is docked somewhere else, we need to undockit and dockit on another site
                            // If Bar is deserialized there is no parent
                            if (this.Parent != null && this.Parent is DockSite)
                            {
                                if (((DockSite)this.Parent).IsDocumentDock || ((DockSite)this.Parent).DocumentDockContainer != null)
                                    ((DockSite)this.Parent).GetDocumentUIManager().UnDock(this);
                                else
                                    ((DockSite)this.Parent).RemoveBar(this);
                            }

                            // If coming from the tabs
                            if (!this.Visible && !m_BarDefinitionLoading)
                                this.Visible = true;

                            m_DockOffset = pDockInfo.DockOffset;
                            m_DockLine = pDockInfo.DockLine;

                            if (pDockInfo.objDockSite.IsDocumentDock || pDockInfo.objDockSite.DocumentDockContainer != null)
                            {
                                pDockInfo.objDockSite.GetDocumentUIManager().Dock(pDockInfo.MouseOverBar, this, pDockInfo.MouseOverDockSide);
                            }
                            else
                            {
                                if (pDockInfo.InsertPosition == -10)
                                    pDockInfo.objDockSite.AddBar(this);
                                else
                                    pDockInfo.objDockSite.AddBar(this, pDockInfo.InsertPosition);
                            }
                            // Raise events
                            //							if(BarDock!=null)
                            //								BarDock(this,new EventArgs());
                            //							IOwnerBarSupport ownerDockEvents=m_Owner as IOwnerBarSupport;
                            //							if(ownerDockEvents!=null)
                            //								ownerDockEvents.InvokeBarDock(this,new EventArgs());
                            m_DockingInProgress = false;
                        }
                        else if (this.Parent != null && pDockInfo.objDockSite == this.Parent)
                        {
                            if (pDockInfo.objDockSite.IsDocumentDock || pDockInfo.objDockSite.DocumentDockContainer != null)
                            {
                                pDockInfo.objDockSite.GetDocumentUIManager().Dock(pDockInfo.MouseOverBar, this, pDockInfo.MouseOverDockSide);
                            }
                            else
                            {
                                if (m_DockLine != pDockInfo.DockLine || m_DockOffset != pDockInfo.DockOffset && !this.Stretch || pDockInfo.objDockSite.Controls.GetChildIndex(this) != pDockInfo.InsertPosition || pDockInfo.NewLine)
                                {
                                    m_DockLine = pDockInfo.DockLine;
                                    m_DockOffset = pDockInfo.DockOffset;
                                    // If coming from the tabs
                                    if (!this.Visible && !m_BarDefinitionLoading)
                                        this.Visible = true;
                                    if (pDockInfo.NewLine)
                                        pDockInfo.objDockSite.SetBarPosition(this, pDockInfo.InsertPosition, true);
                                    else if (pDockInfo.InsertPosition == -10)
                                    {
                                        pDockInfo.objDockSite.AdjustBarPosition(this);
                                        pDockInfo.objDockSite.RecalcLayout();
                                    }
                                    else
                                        pDockInfo.objDockSite.SetBarPosition(this, pDockInfo.InsertPosition);
                                }
                            }
                        }
                        else
                        {
                            Point newLocation = new Point(p.X - m_MouseDownPt.X, p.Y - m_MouseDownPt.Y);
                            ScreenInformation screen = BarFunctions.ScreenFromControl(m_Float);
                            if (screen != null)
                            {
                                if (newLocation.Y + 8 >= screen.WorkingArea.Bottom)
                                    newLocation.Y = screen.WorkingArea.Bottom - 8;
                            }
                            m_Float.Location = newLocation;
                            if (((IOwner)m_Owner).ParentForm != null)
                                ((IOwner)m_Owner).ParentForm.Update();
                        }
                    }
                }
                if (m_ItemContainer.LayoutType == eLayoutType.DockContainer && (m_TabDockItems == null || !m_TabDockItems.Visible))
                {
                    int iVisible = m_ItemContainer.VisibleSubItems;
                    if (!(m_BarState == eBarState.Floating && iVisible <= 1) && (m_AlwaysDisplayDockTab || iVisible > 0))
                    {
                        eBarState oldBarState = m_BarState;
                        m_BarState = eBarState.Docked;
                        RefreshDockTab(false);
                        m_BarState = oldBarState;
                    }
                }
                if (m_BarState != eBarState.Floating)
                    InvokeBarDockEvents();
            }
        }
Example #5
0
        /// <summary>
        /// Docks the bar to the specified side of the reference bar.
        /// </summary>
        /// <param name="barToDock">Bar to dock.</param>
        /// <param name="referenceBar">Reference bar.</param>
        /// <param name="dockToReferenceBarSide">Side of the reference bar to dock the bar to.</param>
        public void Dock(Bar barToDock, Bar referenceBar, eDockSide dockToReferenceBarSide)
        {
            if (dockToReferenceBarSide == eDockSide.None)
                throw new ArgumentException("eDockSide.None is not supported value for dockToReferenceBarSide parameter. Use Float method to make floating bar.");
            if (referenceBar.DockSide == eDockSide.None)
                throw new ArgumentException("referenceBar must be docked to be used as reference for docking.");

            if (barToDock.LayoutType != eLayoutType.DockContainer)
            {
                barToDock.DockSide = dockToReferenceBarSide;
                return;
            }

            if (dockToReferenceBarSide == eDockSide.Document)
            {
                System.Collections.ArrayList list = new System.Collections.ArrayList(barToDock.Items.Count);
                barToDock.Items.CopyTo(list);
                DockContainerItem firstItem = null;
                foreach (BaseItem item in list)
                {
                    DockContainerItem dockitem = item as DockContainerItem;
                    if (dockitem != null)
                    {
                        if (firstItem == null) firstItem = dockitem;
                        dockitem.Displayed = false;
                        if (dockitem.OriginalBarName == "")
                        {
                            dockitem.OriginalBarName = barToDock.Name;
                            dockitem.OriginalPosition = barToDock.Items.IndexOf(dockitem);
                        }
                        barToDock.Items.Remove(dockitem);
                        referenceBar.Items.Add(dockitem);
                    }
                }
                referenceBar.RecalcLayout();

                if (firstItem != null)
                    referenceBar.SelectedDockContainerItem = firstItem;
                referenceBar.InvokeBarDockEvents();

                if (barToDock.CustomBar)
                {
                    this.Bars.Remove(barToDock);
                    barToDock.Dispose();
                }
                else
                {
                    barToDock.Visible = false;
                }
            }
            else
            {
                DocumentDockUIManager dockManager = GetDocumentUIManager(referenceBar.DockSide);
                if (!this.Bars.Contains(barToDock))
                    this.Bars.Add(barToDock);
                dockManager.Dock(referenceBar, barToDock, dockToReferenceBarSide);
            }
        }