protected override void OnMouseDragMove(int x, int y) { if(!this.IsDockableWindow && !this.IsDockableToolbar || !m_DragDrop) { base.OnMouseDragMove(x,y); return; } Point screenPos=new Point(x,y); Bar bar=this.Control as Bar; if(bar==null) return; if (this.IsDockableToolbar) { IOwnerBarSupport ownerDock = bar.Owner as IOwnerBarSupport; m_DockInfo = ownerDock.GetDockInfo(bar, screenPos.X, screenPos.Y); if (m_DockInfo.objDockSite != null) { IComponentChangeService cc = this.GetService(typeof(IComponentChangeService)) as IComponentChangeService; Control oldParent = null; bool offsetChange = false; if (m_DockInfo.objDockSite != bar.Parent) { oldParent = bar.Parent; cc.OnComponentChanging(bar.Parent, null); cc.OnComponentChanging(bar, TypeDescriptor.GetProperties(bar)["DockSide"]); } cc.OnComponentChanging(m_DockInfo.objDockSite, null); if (m_DockInfo.DockOffset != bar.DockOffset) { offsetChange = true; cc.OnComponentChanging(bar, TypeDescriptor.GetProperties(bar)["DockOffset"]); cc.OnComponentChanging(bar, TypeDescriptor.GetProperties(bar)["Location"]); } bar.DockingHandler(m_DockInfo, screenPos); if (oldParent != null) { cc.OnComponentChanged(bar, TypeDescriptor.GetProperties(bar)["DockSide"], null, null); cc.OnComponentChanged(oldParent, null, null, null); } cc.OnComponentChanged(m_DockInfo.objDockSite, null, null, null); if (offsetChange) { cc.OnComponentChanged(bar, TypeDescriptor.GetProperties(bar)["DockOffset"], null, null); cc.OnComponentChanged(bar, TypeDescriptor.GetProperties(bar)["Location"], null, null); } } bar.Refresh(); return; } Point tabPos = Point.Empty; if (bar.DockTabControl != null) tabPos = bar.DockTabControl.PointToClient(screenPos); if(bar.DockTabControl!=null && bar.DockTabControl.ClientRectangle.Contains(tabPos)) { if(m_IsDocking) { EndBarOwnerDocking(bar); m_IsDocking=false; m_DockInfo=new DockSiteInfo(); } MouseEventArgs e=new MouseEventArgs(MouseButtons.Left,0,tabPos.X,tabPos.Y,0); bar.DockTabControl.InternalOnMouseMove(e); } else { m_IsDocking=true; IOwnerBarSupport ownerDock=bar.Owner as IOwnerBarSupport; m_DockInfo=ownerDock.GetDockInfo(bar,screenPos.X,screenPos.Y); if(m_DockInfo.objDockSite==null) { if(m_OutlineForm!=null) m_OutlineForm.Hide(); } else { Rectangle r=m_DockInfo.objDockSite.GetBarDockRectangle(bar,ref m_DockInfo); if(!r.IsEmpty) { if(m_OutlineForm==null) m_OutlineForm=bar.CreateOutlineForm(); WinApi.SetWindowPos(m_OutlineForm.Handle, WinApi.HWND_TOP, r.X, r.Y, r.Width, r.Height, WinApi.SWP_SHOWWINDOW | WinApi.SWP_NOACTIVATE); } else if(m_OutlineForm!=null) m_OutlineForm.Hide(); } } }
protected override void OnMouseDragEnd(bool cancel) { if(!this.IsDockableWindow) { base.OnMouseDragEnd(cancel); return; } this.Control.Capture = false; Cursor.Clip = Rectangle.Empty; Bar bar=this.Control as Bar; if(cancel || bar==null || !m_DragDrop) { base.OnMouseDragEnd(cancel); return; } m_DragDrop=false; IDesignerHost designerHost=this.GetService(typeof(IDesignerHost)) as IDesignerHost; if(designerHost==null) { EndBarOwnerDocking(bar); m_IsDocking=false; m_MouseDownSelectedTabIndex=-1; base.OnMouseDragEnd(cancel); return; } if(m_IsDocking) { EndBarOwnerDocking(bar); // Moves and docks the selected DockContainerItem or bar Bar referenceBar=m_DockInfo.MouseOverBar; if(m_DockInfo.MouseOverDockSide!=eDockSide.None && m_DockInfo.MouseOverDockSide!=eDockSide.Document && (referenceBar!=bar || m_MouseDownSelectedTabIndex!=-1 && bar.VisibleItemCount>1) || m_DockInfo.DockSide != DockStyle.None && m_DockInfo.MouseOverDockSide != eDockSide.Document) { DesignerTransaction trans=designerHost.CreateTransaction("DotNetBar Docking"); IComponentChangeService cc=(IComponentChangeService)GetService(typeof(IComponentChangeService)); try { Bar newBar=null; DockSite newDockSite = m_DockInfo.objDockSite; DockSite oldDockSite = bar.Parent as DockSite; if (m_MouseDownSelectedTabIndex != -1 && bar.VisibleItemCount > 1) { Bar copy = designerHost.CreateComponent(typeof(Bar)) as Bar; newBar = BarFunctions.CreateDuplicateDockBar(bar, copy); } else newBar = bar; cc.OnComponentChanging(bar,TypeDescriptor.GetProperties(typeof(Bar))["SelectedDockTab"]); if(m_MouseDownSelectedTabIndex!=-1 && bar.VisibleItemCount>1) { DockContainerItem item=bar.Items[bar.SelectedDockTab] as DockContainerItem; cc.OnComponentChanging(bar,TypeDescriptor.GetProperties(typeof(Bar))["Controls"]); cc.OnComponentChanging(bar,TypeDescriptor.GetProperties(typeof(Bar))["Items"]); bar.Items.Remove(item); cc.OnComponentChanged(bar,TypeDescriptor.GetProperties(typeof(Bar))["Items"],null,null); cc.OnComponentChanged(bar,TypeDescriptor.GetProperties(typeof(Bar))["Controls"],null,null); cc.OnComponentChanging(newBar,TypeDescriptor.GetProperties(typeof(Bar))["Controls"]); cc.OnComponentChanging(newBar,TypeDescriptor.GetProperties(typeof(Bar))["Items"]); newBar.Items.Add(item); cc.OnComponentChanged(newBar,TypeDescriptor.GetProperties(typeof(Bar))["Items"],null,null); cc.OnComponentChanged(newBar,TypeDescriptor.GetProperties(typeof(Bar))["Controls"],null,null); } cc.OnComponentChanging(newDockSite,TypeDescriptor.GetProperties(typeof(DockSite))["Controls"]); cc.OnComponentChanging(newBar,null); if(referenceBar!=null) cc.OnComponentChanging(referenceBar,null); cc.OnComponentChanging(newDockSite,TypeDescriptor.GetProperties(typeof(DockSite))["DocumentDockContainer"]); if (newDockSite != oldDockSite && oldDockSite != null) { cc.OnComponentChanging(oldDockSite, TypeDescriptor.GetProperties(typeof(DockSite))["Controls"]); cc.OnComponentChanging(oldDockSite, TypeDescriptor.GetProperties(typeof(DockSite))["DocumentDockContainer"]); } m_DockInfo.MouseOverBar = referenceBar; newBar.DockDocumentManager(m_DockInfo); //newDockSite.GetDocumentUIManager().Dock(referenceBar,newBar,m_DockInfo.MouseOverDockSide); if (newDockSite.Width == 0 && (newDockSite.Dock == DockStyle.Left || newDockSite.Dock == DockStyle.Right)) newDockSite.Width = newBar.GetBarDockedSize(eOrientation.Vertical); else if (newDockSite.Height == 0 && (newDockSite.Dock == DockStyle.Top || newDockSite.Dock == DockStyle.Bottom)) newDockSite.Height = newBar.GetBarDockedSize(eOrientation.Horizontal); if (newDockSite != oldDockSite && oldDockSite != null) { cc.OnComponentChanged(oldDockSite, TypeDescriptor.GetProperties(typeof(DockSite))["DocumentDockContainer"], null, null); cc.OnComponentChanged(oldDockSite, TypeDescriptor.GetProperties(typeof(DockSite))["Controls"], null, null); } cc.OnComponentChanged(newDockSite,TypeDescriptor.GetProperties(typeof(DockSite))["DocumentDockContainer"],null,null); if (referenceBar != null) cc.OnComponentChanged(referenceBar,null,null,null); cc.OnComponentChanged(newBar,null,null,null); cc.OnComponentChanged(newDockSite,TypeDescriptor.GetProperties(typeof(DockSite))["Controls"],null,null); Form f = newBar.FindForm(); if(f!=null) f.Refresh(); } catch { trans.Cancel(); throw; } finally { if(!trans.Canceled) trans.Commit(); } } else if(m_DockInfo.MouseOverDockSide==eDockSide.Document && bar!=referenceBar) { BarDesigner referenceDesigner=designerHost.GetDesigner(referenceBar) as BarDesigner; if(referenceDesigner!=null) referenceDesigner.DelayedDockTabs(bar,m_MouseDownSelectedTabIndex); } m_DockInfo=new DockSiteInfo(); } else if(m_MouseDownSelectedTabIndex!=-1) { if(m_MouseDownSelectedTabIndex!=bar.SelectedDockTab) { IComponentChangeService cc=(IComponentChangeService)GetService(typeof(IComponentChangeService)); if(cc!=null) { cc.OnComponentChanged(bar,TypeDescriptor.GetProperties(typeof(Bar))["Items"],null,null); cc.OnComponentChanged(bar,TypeDescriptor.GetProperties(typeof(Bar))["SelectedDockTab"],null,null); cc.OnComponentChanged(bar,TypeDescriptor.GetProperties(typeof(Bar))["Controls"],null,null); } } } m_IsDocking=false; m_MouseDownSelectedTabIndex=-1; base.OnMouseDragEnd(cancel); }
public BarDesigner():base() { m_DockInfo=new DockSiteInfo(); this.EnableItemDragDrop=true; }