Beispiel #1
0
		/// <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;
		}
Beispiel #2
0
		/// <summary>
		/// Inserts drag&drop item at specified position.
		/// </summary>
		/// <param name="containerItem">Container item.</param>
		/// <param name="objItem">Item being inserted</param>
		/// <param name="iPos">Insertion position</param>
		/// <param name="Before">Indicates whether item is inserted before the specified insertion position</param>
		public static void InsertItemAt(BaseItem containerItem, BaseItem objItem, int iPos, bool Before)
		{
			if(containerItem.ExpandedItem()!=null)
			{
				containerItem.ExpandedItem().Expanded=false;
			}
			if(!Before)
			{
				if(iPos+1>=containerItem.SubItems.Count)
				{
					containerItem.SubItems.Add(objItem,GetAppendPosition(containerItem));
				}
				else
				{
					containerItem.SubItems.Add(objItem,iPos+1);
				}
			}
			else
			{
				if(iPos>=containerItem.SubItems.Count)
				{
					containerItem.SubItems.Add(objItem, GetAppendPosition(containerItem));
				}
				else
				{
					containerItem.SubItems.Add(objItem,iPos);
				}
			}
			if(containerItem.ContainerControl is Bar)
				((Bar)containerItem.ContainerControl).RecalcLayout();
			else if(containerItem.ContainerControl is MenuPanel)
				((MenuPanel)containerItem.ContainerControl).RecalcSize();
			else if(containerItem.ContainerControl is BarBaseControl)
				((BarBaseControl)containerItem.ContainerControl).RecalcLayout();
			else if(containerItem.ContainerControl is ItemControl)
				((ItemControl)containerItem.ContainerControl).RecalcLayout();
			else
			{
				containerItem.RecalcSize();
				containerItem.Refresh();
			}
		}
Beispiel #3
0
        internal static void ProcessKeyDown(BaseItem container, System.Windows.Forms.KeyEventArgs objArg)
        {
            if (container.SubItems.Count == 0 || objArg.Handled)
                return;

            BaseItem objExpanded = container.ExpandedItem();

            if (objExpanded != null)
            {
                objExpanded.InternalKeyDown(objArg);
                if (objArg.Handled)
                    return;
            }

            eOrientation containerOrientation = container.Orientation;
            if (container is ItemContainer)
                containerOrientation = ((ItemContainer)container).LayoutOrientation;

            if (containerOrientation == eOrientation.Horizontal && (objArg.KeyCode == Keys.Left || objArg.KeyCode == Keys.Right || container.HotSubItem == null && (objArg.KeyCode == Keys.Down || objArg.KeyCode == Keys.Up)) ||
               (containerOrientation == eOrientation.Vertical && (objArg.KeyCode == Keys.Up || objArg.KeyCode == Keys.Down || container.HotSubItem == null && (objArg.KeyCode == Keys.Right || objArg.KeyCode == Keys.Left))))
            {
                // Select next object
                if (container.HotSubItem != null)
                {
                    container.HotSubItem.InternalMouseLeave();
                    if (container.AutoExpand && container.HotSubItem.Expanded)
                    {
                        container.HotSubItem.Expanded = false;
                    }
                }
                if (objArg.KeyCode == System.Windows.Forms.Keys.Left || objArg.KeyCode == Keys.Up)
                {
                    int iIndex = 0;
                    if (container.HotSubItem != null)
                        iIndex = container.SubItems.IndexOf(container.HotSubItem) - 1;
                    if (iIndex < 0)
                        iIndex = container.SubItems.Count - 1;
                    BaseItem objNew = null;
                    bool bRepeat = false;
                    do
                    {
                        for (int i = iIndex; i >= 0; i--)
                        {
                            objNew = container.SubItems[i];
                            if (CanFocus(objNew))
                            {
                                iIndex = i;
                                break;
                            }
                        }
                        if (!CanFocus(container.SubItems[iIndex]))
                        {
                            if (!bRepeat)
                            {
                                iIndex = container.SubItems.Count - 1;
                                bRepeat = true;
                            }
                            else
                                bRepeat = false;
                        }
                        else
                            bRepeat = false;
                    } while (bRepeat);
                    container.HotSubItem = container.SubItems[iIndex];
                }
                else
                {
                    int iIndex = 0;
                    if (container.HotSubItem != null)
                        iIndex = container.SubItems.IndexOf(container.HotSubItem) + 1;

                    while (iIndex < container.SubItems.Count && !CanFocus(container.SubItems[iIndex]))
                        iIndex++;
                    if (iIndex >= container.SubItems.Count)
                        iIndex = 0;
                    BaseItem objNew = null;
                    for (int i = iIndex; i < container.SubItems.Count; i++)
                    {
                        objNew = container.SubItems[i];
                        if (CanFocus(objNew))
                        {
                            iIndex = i;
                            break;
                        }
                    }
                    container.HotSubItem = container.SubItems[iIndex];
                }
                
                if (container.HotSubItem != null)
                {
                    if (container.HotSubItem is ItemContainer)
                    {
                        ((ItemContainer)container.HotSubItem).SelectFirstItem();
                    }
                    else
                    {
                        container.HotSubItem.InternalMouseEnter();
                        container.HotSubItem.InternalMouseMove(new MouseEventArgs(MouseButtons.None, 0, container.HotSubItem.LeftInternal + 1, container.HotSubItem.TopInternal + 1, 0));
                        IScrollableItemControl isc = container.ContainerControl as IScrollableItemControl;
                        if (isc != null)
                            isc.KeyboardItemSelected(container.HotSubItem);
                    }
                }

                objArg.Handled = true;
            }
            else if (objArg.KeyCode == System.Windows.Forms.Keys.Escape)
            {
                if (objExpanded != null)
                {
                    objExpanded.Expanded = false;
                    objArg.Handled = true;
                }
                else
                {
                    Control cc = container.ContainerControl as Control;
                    if (cc is Bar)
                    {
                        Bar bar = cc as Bar;
                        if (bar.BarState == eBarState.Popup)
                        {
                            bar.ParentItem.Expanded = false;
                        }
                        else
                        {
                            if (container.AutoExpand)
                                container.AutoExpand = false;
                            else if (bar.Focused || bar.MenuFocus)
                            {
                                bar.MenuFocus = false;
                                bar.ReleaseFocus();
                            }
                        }
                        objArg.Handled = true;
                    }
                    else if (cc is ItemControl)
                    {
                        ItemControl ic = cc as ItemControl;
                        if (container.AutoExpand)
                            container.AutoExpand = false;
                        else if (ic.Focused || ic.MenuFocus)
                        {
                            ic.MenuFocus = false;
                            ic.ReleaseFocus();
                        }
                    }
                }
            }
            else
            {
                BaseItem objItem = container.ExpandedItem();
                if (objItem != null)
                    objItem.InternalKeyDown(objArg);
                else
                {
                    int key = 0;
                    if (objArg.Shift)
                    {
                        try
                        {
                            byte[] keyState = new byte[256];
                            if (NativeFunctions.GetKeyboardState(keyState))
                            {
                                byte[] chars = new byte[2];
                                if (NativeFunctions.ToAscii((uint)objArg.KeyValue, 0, keyState, chars, 0) != 0)
                                {
                                    key = chars[0];
                                }
                            }
                        }
                        catch (Exception)
                        {
                            key = 0;
                        }
                    }

                    if (key == 0)
                        key = (int)NativeFunctions.MapVirtualKey((uint)objArg.KeyValue, 2);

                    if (container.HotSubItem != null)
                        container.HotSubItem.InternalKeyDown(objArg);
                }
            }
        }