Ejemplo n.º 1
0
		private void ExpandItem(BaseItem objItem)
		{
			// Set the focus here so it can be properly released...
            Control cc = this.ContainerControl as Control;
			//if(bar!=null && !bar.Focused) // Commented out to fix menu bar taking the focus
			//	bar.Focus();
            if (cc is Bar && !cc.Focused)
                ((Bar)cc).MenuFocus = true;

			if(m_HotSubItem!=null)
				m_HotSubItem.InternalMouseLeave();
			m_HotSubItem=objItem;
			objItem.InternalMouseEnter();
            objItem.InternalMouseMove(new MouseEventArgs(MouseButtons.None, 0, objItem.LeftInternal + 2, objItem.TopInternal + 2, 0));
			objItem.Expanded=true;
			if(objItem is PopupItem)
			{
				this.AutoExpand=true;
				// If it is a menu select first menu item inside...
				PopupItem popup=objItem as PopupItem;
				if(popup.PopupType==ePopupType.Menu && popup.PopupControl is MenuPanel)
				{
					((MenuPanel)popup.PopupControl).SelectFirstItem();
				}
			}
		}
Ejemplo n.º 2
0
		internal void ExKeyDown(KeyEventArgs e)
		{
			if(m_ParentItem==null || m_ParentItem.SubItems.Count==0 || m_ParentItem.DesignMode)
				return;

			if(m_HotSubItem==null || m_HotSubItem!=null && !m_HotSubItem.Expanded)
			{
				if(e.KeyCode==Keys.Down)
				{
                    if (m_ParentItem is ItemContainer)
                    {
                        m_ParentItem.InternalKeyDown(e);
                    }
                    else
                    {
                        if (m_HotSubItem is ItemContainer)
                            m_HotSubItem.InternalKeyDown(e);

                        if (!e.Handled)
                        {
                            int i = 0;
                            if (m_HotSubItem != null)
                            {
                                m_HotSubItem.InternalMouseLeave();
                                i = m_ParentItem.SubItems.IndexOf(m_HotSubItem) + 1;
                                if (i == m_ParentItem.SubItems.Count && m_ExpandButton.ShowExpandButton)
                                {
                                    m_ExpandButton.MouseOver = true;
                                    RefreshExpandButton();
                                }
                                else if (i < 0 || i == m_ParentItem.SubItems.Count)
                                {
                                    i = 0;
                                }
                                m_HotSubItem = null;
                            }
                            else if (m_ExpandButton.MouseOver)
                            {
                                m_ExpandButton.MouseOver = false;
                                RefreshExpandButton();
                                i = 0;
                            }
                            BaseItem objTmp;
                            for (int f = i; f < m_ParentItem.SubItems.Count; f++)
                            {
                                objTmp = m_ParentItem.SubItems[f];
                                if (objTmp.Displayed && objTmp.Visible && CanGetMouseFocus(objTmp))
                                {
                                    m_HotSubItem = objTmp;
                                    m_HotSubItem.InternalMouseEnter();
                                    m_HotSubItem.InternalMouseMove(new MouseEventArgs(MouseButtons.None, 0, m_HotSubItem.LeftInternal + 2, m_HotSubItem.TopInternal + 2, 0));
                                    if (m_HotSubItem.IsContainer)
                                        m_HotSubItem.InternalKeyDown(e);
                                    break;
                                }
                            }
                            if (m_HotSubItem == null && m_ExpandButton.ShowExpandButton && !m_ExpandButton.MouseOver)
                            {
                                m_ExpandButton.MouseOver = true;
                                RefreshExpandButton();
                            }
                        }
                    }
					e.Handled=true;
					m_IgnoreDuplicateMouseMove=true;
				}
				else if(e.KeyCode==Keys.Up)
				{
                    if (m_ParentItem is ItemContainer)
                    {
                        m_ParentItem.InternalKeyDown(e);
                    }
                    else
                    {
                        if (m_HotSubItem is ItemContainer)
                            m_HotSubItem.InternalKeyDown(e);
                        if (!e.Handled)
                        {
                            int i = 0;
                            if (m_HotSubItem != null)
                            {
                                m_HotSubItem.InternalMouseLeave();
                                i = m_ParentItem.SubItems.IndexOf(m_HotSubItem) - 1;
                                if (i < 0 && m_ExpandButton.ShowExpandButton)
                                {
                                    m_ExpandButton.MouseOver = true;
                                    RefreshExpandButton();
                                }
                                else if (i < 0)
                                    i = m_ParentItem.SubItems.Count - 1;
                                m_HotSubItem = null;
                            }
                            else if (m_ExpandButton.MouseOver)
                            {
                                m_ExpandButton.MouseOver = false;
                                RefreshExpandButton();
                                i = m_ParentItem.SubItems.Count - 1;
                            }
                            else if (m_ExpandButton.ShowExpandButton)
                            {
                                m_ExpandButton.MouseOver = true;
                                RefreshExpandButton();
                            }
                            else
                                i = m_ParentItem.SubItems.Count - 1;
                            BaseItem objTmp;
                            for (int f = i; f >= 0; f--)
                            {
                                objTmp = m_ParentItem.SubItems[f];
                                if (objTmp.Displayed && objTmp.Visible && CanGetMouseFocus(objTmp))
                                {
                                    m_HotSubItem = objTmp;
                                    m_HotSubItem.InternalMouseEnter();
                                    m_HotSubItem.InternalMouseMove(new MouseEventArgs(MouseButtons.None, 0, m_HotSubItem.LeftInternal + 2, m_HotSubItem.TopInternal + 2, 0));
                                    if (m_HotSubItem.IsContainer)
                                        m_HotSubItem.InternalKeyDown(e);
                                    break;
                                }
                            }
                            if (m_HotSubItem == null && m_ExpandButton.ShowExpandButton && !m_ExpandButton.MouseOver)
                            {
                                m_ExpandButton.MouseOver = true;
                                RefreshExpandButton();
                            }
                        }
                    }
					e.Handled=true;
					m_IgnoreDuplicateMouseMove=true;
				}
				else if(e.KeyCode==Keys.Right)
				{
					m_IgnoreDuplicateMouseMove=true;
                    if (m_HotSubItem != null && m_HotSubItem.GetEnabled())
                    {
                        ButtonItem objBtn = m_HotSubItem as ButtonItem;
                        if (objBtn != null)
                        {
                            if (objBtn.SubItems.Count > 0 && objBtn.ShowSubItems && !objBtn.Expanded)
                            {
                                objBtn.Expanded = true;
                                if (objBtn.PopupControl is MenuPanel)
                                    ((MenuPanel)objBtn.PopupControl).SelectFirstItem();

                                e.Handled = true;
                            }
                        }
                    }
                    if (m_HotSubItem != null && m_HotSubItem is ItemContainer)
                        m_HotSubItem.InternalKeyDown(e);

                    if (!e.Handled && m_ParentItem!=null)
                    {
                        foreach (BaseItem item in m_ParentItem.SubItems)
                        {
                            if (item is ItemContainer)
                            {
                                item.InternalKeyDown(e);
                                if (e.Handled)
                                    break;
                            }
                        }
                    }
				}
				else if(e.KeyCode==Keys.Left)
				{
                    if (m_HotSubItem != null && m_HotSubItem is ItemContainer)
                        m_HotSubItem.InternalKeyDown(e);
                    if (!e.Handled)
                    {
                        m_IgnoreDuplicateMouseMove = true;
                        // Close this popup
                        if (BaseItem.IsOnPopup(m_ParentItem))
                        {
                            m_ParentItem.Expanded = false;
                            e.Handled = true;
                        }
                    }
				}
				else if(e.KeyCode==Keys.Escape)
				{
                    BaseItem parent = m_ParentItem;
                    parent.Expanded = false;
                    if (parent.Parent != null && parent.Parent is GenericItemContainer && parent.Parent.AutoExpand)
                        parent.Parent.AutoExpand = false;
                    e.Handled = true;
				}
                else if (e.KeyCode == Keys.Enter && m_HotSubItem != null && m_HotSubItem.IsContainer)
                {
                    m_HotSubItem.InternalKeyDown(e);
                }
                else if (e.KeyCode == Keys.Enter && m_HotSubItem != null && m_HotSubItem.SubItems.Count > 0 && m_HotSubItem.ShowSubItems && !m_HotSubItem.Expanded && m_HotSubItem.GetEnabled())
                {
                    m_HotSubItem.Expanded = true;
                    if (m_HotSubItem is PopupItem && ((PopupItem)m_HotSubItem).PopupControl is MenuPanel)
                        ((MenuPanel)((PopupItem)m_HotSubItem).PopupControl).SelectFirstItem();

                    e.Handled = true;
                }
                else if ((e.KeyCode == Keys.Enter || e.KeyCode == Keys.Space) && m_ExpandButton.ShowExpandButton && m_ExpandButton.MouseOver)
                {
                    ExpandRecentlyUsed();
                }
                else
                {
                    int key = 0;
                    if (e.Shift)
                    {
                        try
                        {
                            byte[] keyState = new byte[256];
                            if (NativeFunctions.GetKeyboardState(keyState))
                            {
                                byte[] chars = new byte[2];
                                if (NativeFunctions.ToAscii((uint)e.KeyValue, 0, keyState, chars, 0) != 0)
                                {
                                    key = chars[0];
                                }
                            }
                        }
                        catch (Exception)
                        {
                            key = 0;
                        }
                    }

                    if (key == 0 && !BarFunctions.IsSystemKey(e.KeyCode))
                    {
                        key = (int)NativeFunctions.MapVirtualKey((uint)e.KeyValue, 2);
                        if (key == 0)
                            key = e.KeyValue;
                    }
                    if(e is KeyEventArgsEx && ((KeyEventArgsEx)e).KeyChar!=0)
                    {
                        if (ProcessContainerAccessKey(m_ParentItem, ((KeyEventArgsEx)e).KeyChar))
                            e.Handled = true;
                    }
                    if (!e.Handled && key > 0)
                    {
                        char[] ch = new char[1];
                        byte[] by = new byte[1];
                        by[0] = System.Convert.ToByte(key);
                        System.Text.Encoding.Default.GetDecoder().GetChars(by, 0, 1, ch, 0);
                        string s = ch[0].ToString();
                        ch[0] = (s.ToLower())[0];
                        if (ProcessContainerAccessKey(m_ParentItem, ch[0]))
                            e.Handled = true;
                    }
                }
			}

			if(!e.Handled && m_HotSubItem!=null)
			{
                bool raiseKeyDown=true;
                if (this.Controls.Count > 0)
                {
                    foreach (Control childControl in this.Controls)
                    {
                        if (childControl.Focused)
                        {
                            raiseKeyDown = false;
                            break;
                        }
                    }
                }
                if(raiseKeyDown)
    				m_HotSubItem.InternalKeyDown(e);
			}
		}
Ejemplo n.º 3
0
        private bool ProcessContainerAccessKey(BaseItem container, char key)
        {
            List<BaseItem> itemsForMnemonic = GetItemsForMnemonic(container, key);
            if (itemsForMnemonic.Count > 1)
            {
                // Special processing for case when more than one item uses same mnemonic key
                BaseItem newHotSubitem = null;
                if (m_HotSubItem == null)
                    newHotSubitem = itemsForMnemonic[0];
                else
                {
                    int hotItemIndex = itemsForMnemonic.IndexOf(m_HotSubItem);
                    if (hotItemIndex == -1)
                        newHotSubitem = itemsForMnemonic[0];
                    else
                    {
                        if (hotItemIndex == itemsForMnemonic.Count - 1)
                            hotItemIndex = 0;
                        else
                            hotItemIndex++;
                        newHotSubitem = itemsForMnemonic[hotItemIndex];
                    }
                }
                if (newHotSubitem != null)
                {
                    if (m_HotSubItem != null)
                        m_HotSubItem.InternalMouseLeave();
                    m_HotSubItem = newHotSubitem;
                    m_HotSubItem.InternalMouseEnter();
                    m_HotSubItem.InternalMouseMove(new MouseEventArgs(MouseButtons.None, 0, m_HotSubItem.LeftInternal + 2, m_HotSubItem.TopInternal + 2, 0));
                }
                return true;
            }

            BaseItem item = GetItemForMnemonic(container, key, true);
            if (item!=null && item.GetEnabled() && item.Visible)
            {
                if (item is ItemContainer)
                {
                    this.ShowKeyTips = false;
                    this.HotSubItem = item;
                }
                else if (item.SubItems.Count > 0 && item.ShowSubItems && !item.Expanded)
                {
                    if (m_HotSubItem != item)
                    {
                        if (m_HotSubItem != null)
                            m_HotSubItem.InternalMouseLeave();
                        m_HotSubItem = item;
                        m_HotSubItem.InternalMouseEnter();
                        m_HotSubItem.InternalMouseMove(new MouseEventArgs(MouseButtons.None, 0, m_HotSubItem.LeftInternal + 2, m_HotSubItem.TopInternal + 2, 0));
                    }
                    item.Expanded = true;
                    if (item is PopupItem && ((PopupItem)item).PopupControl is MenuPanel)
                    {
                        ((MenuPanel)((PopupItem)item).PopupControl).SelectFirstItem();
                    }
                    m_IgnoreDuplicateMouseMove = true;
                }
                else
                {
                    this.ShowKeyTips = false;
                    if (item is ComboBoxItem)
                    {
                        ((ComboBoxItem)item).ComboBoxEx.Focus();
                        ((ComboBoxItem)item).ComboBoxEx.DroppedDown = true;
                    }
                    else if (item is TextBoxItem)
                    {
                        ((TextBoxItem)item).TextBox.Focus();
                    }
                    else if (item is ControlContainerItem && ((ControlContainerItem)item).Control != null)
                        ((ControlContainerItem)item).Control.Focus();
                    else
                        item.RaiseClick();
                }
                return true;
            }

            return false;
        }
Ejemplo n.º 4
0
		protected override void OnMouseLeave(EventArgs e)
		{
			if(m_ParentItem!=null && m_ParentItem.DesignMode || m_ParentItem==null)
				return;
			// If we had hot sub item pass the mouse leave message to it...
			if(m_HotSubItem!=null) // && !m_HotSubItem.Expanded)
			{
				// Handle the case when child control of the item gets the mouse
				Point mp=this.PointToClient(Control.MousePosition);
                if (!m_HotSubItem.DisplayRectangle.Contains(mp))
				{
                    if (!(m_HotSubItem is PopupItem && m_HotSubItem.Expanded))
                    {
                        m_HotSubItem.InternalMouseLeave();
                        m_HotSubItem = null;
                    }
				}
			}
			else if(m_ExpandButton.ShowExpandButton && m_ExpandButton.MouseOver)
			{
				m_ExpandButton.MouseOver=false;
				RefreshExpandButton();
			}

            if (m_HotSubItem == null)
            {
                BaseItem exp = ExpandedItem();
                if (exp != null && exp is PopupItem)
                {
                    m_HotSubItem = exp;
                    m_HotSubItem.InternalMouseEnter();
                    m_HotSubItem.InternalMouseMove(new MouseEventArgs(MouseButtons.None, 0, m_HotSubItem.DisplayRectangle.X+4, m_HotSubItem.DisplayRectangle.Y+4, 0));
                }
            }

			base.OnMouseLeave(e);
		}