Esempio n. 1
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();
            }
        }