/// <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; }
/// <summary> /// Must be called by any sub item that implements the image when image has changed /// </summary> // public override void OnSubItemImageSizeChanged(BaseItem objItem) // { // base.OnSubItemImageSizeChanged(objItem); // if(this.Expanded) // { // this.RecalcSize(); // this.Refresh(); // } // } //*********************************************** // IDesignTimeProvider Implementation //*********************************************** InsertPosition IDesignTimeProvider.GetInsertPosition(Point pScreen, BaseItem DragItem) { InsertPosition objInsertPos=null; System.Windows.Forms.Control objContainer=this.ContainerControl as System.Windows.Forms.Control; if(objContainer==null || !this.CanCustomize) return null; Point pClient=objContainer.PointToClient(pScreen); Rectangle thisRect=this.DisplayRectangle; if(thisRect.Contains(pClient)) { Rectangle r=thisRect; r.Size=m_PanelRect.Size; r.X+=m_PanelRect.Left; r.Y+=m_PanelRect.Top; if(r.Contains(pClient) && !this.Expanded) { this.Expanded=true; objInsertPos=new InsertPosition(); objInsertPos.TargetProvider=this; if(this.SubItems.Count==0) objInsertPos.Position=-1; else { objInsertPos.Position=0; objInsertPos.Before=true; } return objInsertPos; } BaseItem objItem; // Check first inside any expanded items objItem=this.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<this.SubItems.Count;i++) { objItem=this.SubItems[i]; r=objItem.DisplayRectangle; r.Inflate(2,2); if(objItem.Visible && objItem.Displayed && r.Contains(pClient)) { if(objItem.SystemItem && this.SubItems.Count!=1) { return null; } if(objItem==DragItem) return new InsertPosition(); objInsertPos=new InsertPosition(); objInsertPos.TargetProvider=this; objInsertPos.Position=i; 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=this.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.Expanded=true; } else { CollapseSubItems(this); } break; } } if(objInsertPos==null) { // Container is empty but it can contain the items if(this.SubItems.Count>1 && this.SubItems[this.SubItems.Count-1].SystemItem) objInsertPos=new InsertPosition(this.SubItems.Count-2,true,this); else objInsertPos=new InsertPosition(this.SubItems.Count-1,false,this); } } else { foreach(BaseItem objItem in this.SubItems) { if(objItem==DragItem) continue; IDesignTimeProvider provider=objItem as IDesignTimeProvider; if(provider!=null) { objInsertPos=provider.GetInsertPosition(pScreen, DragItem); if(objInsertPos!=null) break; } } } return objInsertPos; }