Example #1
0
 public static bool SetFocusToPrevious <T>(Block current)
     where T : Block
 {
     while (current != null)
     {
         current = current.FindPrevFocusableBlock();
         if (current != null && current is T)
         {
             current.SetFocus(true);
             return(true);
         }
     }
     return(false);
 }
Example #2
0
        //public static void SetFocusToTheBeginningOfToken(Block token)
        //{
        //    if (token == null)
        //    {
        //        return;
        //    }

        //    token.SetCursorToTheBeginning();
        //    token.SetFocus(true);
        //}

        //public static void SetFocusToTheEndOfToken(Block token)
        //{
        //    if (token == null)
        //    {
        //        return;
        //    }

        //    token.SetCursorToTheEnd();
        //    token.SetFocus(true);
        //}

        public static void SetCursorToTheEndOfPreviousToken(Block block)
        {
            Block prev = block.FindPrevFocusableBlock();

            if (prev != null)
            {
                prev.SetCursorToTheEnd(true);
            }
            //else
            //{
            //    ContainerBlock parent = block.Parent;
            //    if (parent != null)
            //    {
            //        Block prevParent = parent.Prev;
            //        if (prevParent != null)
            //        {
            //            prevParent.SetCursorToTheEnd();
            //            Block toFocus = prevParent.FindLastFocusableBlock();
            //        }
            //    }
            //}
        }
Example #3
0
        /// <summary>
        /// One of the children of this LinearContainerBlock has received a key click.
        /// </summary>
        /// <param name="Block">Which child has been clicked?</param>
        /// <param name="e">Key event info</param>
        protected virtual void Children_KeyDown(Block block, System.Windows.Forms.KeyEventArgs e)
        {
            Block nextFocusable = null;

            bool isLeft  = e.KeyCode == System.Windows.Forms.Keys.Left;
            bool isUp    = e.KeyCode == System.Windows.Forms.Keys.Up;
            bool isDown  = e.KeyCode == System.Windows.Forms.Keys.Down;
            bool isRight = e.KeyCode == System.Windows.Forms.Keys.Right;

            bool isPrev     = e.KeyCode == PrevKey;
            bool isNext     = e.KeyCode == NextKey;
            bool prevIsUp   = PrevKey == System.Windows.Forms.Keys.Up;
            bool nextIsDown = NextKey == System.Windows.Forms.Keys.Down;

            if (isPrev || (isLeft && prevIsUp))
            {
                nextFocusable = block.FindPrevFocusableBlock();
                if (nextFocusable != null)
                {
                    if (isLeft)
                    {
                        nextFocusable.SetCursorToTheEnd();
                    }
                    else
                    {
                        nextFocusable.SetFocus();
                    }
                    e.Handled = true;
                }
                else
                {
                    if (this.CanGetFocus)
                    {
                        this.SetFocus();
                        e.Handled = true;
                    }
                }
            }
            else if (isNext || (isRight && nextIsDown))
            {
                nextFocusable = block.FindNextFocusableBlock();
                if (nextFocusable != null)
                {
                    if (isRight)
                    {
                        nextFocusable.SetCursorToTheBeginning();
                    }
                    else
                    {
                        nextFocusable.SetFocus();
                    }
                    e.Handled = true;
                }
            }
            else if (e.KeyCode == System.Windows.Forms.Keys.Home)
            {
                if (this.CanGetFocus)
                {
                    this.SetFocus();
                    e.Handled = true;
                }
            }

            if (!e.Handled)
            {
                this.RaiseKeyDown(e);
            }
        }