/// <summary> /// Returns information about insertion position for an item given screen coordinates. Used internally for drag&drop support. /// </summary> /// <param name="containerItem">Container item</param> /// <param name="pScreen">Screen coordinates</param> /// <param name="DragItem">Item that is being dragged</param> /// <returns>Information about insertion position or null if item cannot be inserted to the container.</returns> public static InsertPosition GetInsertPosition(BaseItem containerItem, Point pScreen, BaseItem DragItem) { InsertPosition objInsertPos=null; Control objContainer = null; if (containerItem is PopupItem && containerItem.Expanded) objContainer = ((PopupItem)containerItem).PopupControl; else objContainer = containerItem.ContainerControl as Control; if (objContainer == null) return null; Point pClient=objContainer.PointToClient(pScreen); Rectangle thisRect=containerItem.DisplayRectangle; if (containerItem is PopupItem && containerItem.Expanded) thisRect = objContainer.DisplayRectangle; if(thisRect.Contains(pClient) || containerItem.SubItems.Count==0 && objContainer.ClientRectangle.Contains(pClient) || containerItem is ItemContainer && ((ItemContainer)containerItem).SystemContainer && objContainer.ClientRectangle.Contains(pClient)) { Rectangle r; BaseItem objItem; // Check first inside any expanded items objItem=containerItem.ExpandedItem(); if(objItem!=null) { IDesignTimeProvider provider=objItem as IDesignTimeProvider; if(provider!=null) { objInsertPos=provider.GetInsertPosition(pScreen, DragItem); if(objInsertPos!=null) return objInsertPos; } } for(int i=0;i<containerItem.SubItems.Count;i++) { objItem=containerItem.SubItems[i]; r=objItem.DisplayRectangle; r.Inflate(2,2); if(objItem.Visible && r.Contains(pClient)) { if(objItem.SystemItem && containerItem.SubItems.Count!=1) { return null; } if(objItem==DragItem) return new InsertPosition(); if(objItem.IsContainer && objItem is IDesignTimeProvider) { Rectangle inner=r; inner.Inflate(-8,-8); if (inner.Contains(pClient)) { return ((IDesignTimeProvider)objItem).GetInsertPosition(pScreen, DragItem); } } if (containerItem.AllowDrop) { objInsertPos = new InsertPosition(); objInsertPos.TargetProvider = (IDesignTimeProvider)containerItem; objInsertPos.Position = i; if (objItem.Orientation == eOrientation.Horizontal && !objItem.IsOnMenu) { if (pClient.X <= objItem.LeftInternal + objItem.WidthInternal / 2 || objItem.SystemItem) objInsertPos.Before = true; } else { if (pClient.Y <= objItem.TopInternal + objItem.HeightInternal / 2 || objItem.SystemItem) objInsertPos.Before = true; } // We need to collapse any expanded items that are not on this bar IOwner owner = containerItem.GetOwner() as IOwner; if (owner != null) { BaseItem objExp = owner.GetExpandedItem(); if (objExp != null) { while (objExp.Parent != null) objExp = objExp.Parent; BaseItem objParent = objItem; while (objParent.Parent != null) objParent = objParent.Parent; if (objExp != objParent) owner.SetExpandedItem(null); } } if (objItem is PopupItem && (objItem.SubItems.Count > 0 || objItem.IsOnMenuBar)) { if (!objItem.Expanded && objItem.CanCustomize) objItem.Expanded = true; } else { BaseItem.CollapseSubItems(containerItem); } break; } } } if(objInsertPos==null && containerItem.AllowDrop) { // Container is empty but it can contain the items if(containerItem.SubItems.Count>1 && containerItem.SubItems[containerItem.SubItems.Count-1].SystemItem) objInsertPos=new InsertPosition(containerItem.SubItems.Count-2,true,(IDesignTimeProvider)containerItem); else objInsertPos=new InsertPosition(containerItem.SubItems.Count-1,false,(IDesignTimeProvider)containerItem); } } else { foreach(BaseItem objItem in containerItem.SubItems) { if(objItem==DragItem) continue; IDesignTimeProvider provider=objItem as IDesignTimeProvider; if(provider!=null) { objInsertPos=provider.GetInsertPosition(pScreen, DragItem); if(objInsertPos!=null) break; } } } return objInsertPos; }
private static object GetOwner(BaseItem item) { object owner = item.GetOwner(); if (owner is RibbonBar && ((RibbonBar)owner).IsOverflowRibbon) { if (((RibbonBar)owner).IsOnQat) owner = ((RibbonBar)owner).QatButtonParent.GetOwner(); else owner = ((RibbonBar)owner).OverflowParent; } return owner; }