Example #1
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);
			}
		}