/// <summary>
        /// Returns a <see cref="System.String"/> that represents this Gdk key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        /// <remarks>
        /// This is taken from MonoDevelop's code.
        /// </remarks>
        public static string ToString(Key key)
        {
            // Pull out the unicode value for the key. If we have one, we use
            // that instead.
            var c = (char)Keyval.ToUnicode((uint)key);

            if (c != 0)
            {
                return(c == ' '
                                        ? "Space"
                                        : Char.ToUpper(c).ToString());
            }

            // Some keys do not convert directly because there are multiple
            // values for the enumeration. This is used to normalize the values.
            switch (key)
            {
            case Key.Next:
                return("Page_Down");

            case Key.L1:
                return("F11");

            case Key.L2:
                return("F12");
            }

            // Return the string representation of the key.
            return(key.ToString());
        }
示例#2
0
        void OnInputKeyPressEvent(EventKey evnt)
        {
            if (im_context.FilterKeypress(evnt) || ((evnt.State & ModifierType.ControlMask) != 0))
            {
                return;
            }

            char c;

            if (evnt.Key == Key.Return)
            {
                c = '\n';
            }
            else
            {
                c = (char)Keyval.ToUnicode(evnt.KeyValue);
            }
            if (char.IsLetterOrDigit(c) ||
                char.IsPunctuation(c) ||
                c == '\n' ||
                (c == ' ' && SearchController.Query.Length > 0) ||
                char.IsSymbol(c))
            {
                SearchController.AddChar(c);
            }
        }
        public static bool CombinationValid(AccelKey accelKey)
        {
            char         key      = (char)Keyval.ToUnicode((uint)accelKey.Key);
            ModifierType modifier = GetAllowedModifier(accelKey.AccelMods);

            return(IsFunctional(accelKey.Key) || accelKey.Key == Key.Delete ||
                   (((modifier & ControlModifier) != 0 || (modifier & AltModifier) != 0) && (key != char.MinValue || accelKey.Key == Key.BackSpace)));
        }
        /// <summary>
        /// Breaks apart an event key into the individual and normalized key and
        /// any modifiers.
        /// </summary>
        /// <param name="evt">The evt.</param>
        /// <param name="key">The key.</param>
        /// <param name="modifiers">The mod.</param>
        public static void DecomposeKeys(
            EventKey evt,
            out Key key,
            out ModifierType modifiers)
        {
            // Use the keymap to decompose various elements of the hardware keys.
            uint keyval;
            int  effectiveGroup,
                 level;
            ModifierType consumedModifiers;

            keymap.TranslateKeyboardState(
                evt.HardwareKeycode,
                evt.State,
                evt.Group,
                out keyval,
                out effectiveGroup,
                out level,
                out consumedModifiers);

            // Break out the identified keys and modifiers.
            key       = (Key)keyval;
            modifiers = evt.State & ~consumedModifiers;

            // Normalize some of the keys that don't make sense.
            if (key == Key.ISO_Left_Tab)
            {
                key        = Key.Tab;
                modifiers |= ModifierType.ShiftMask;
            }

            // Check to see if we are a character and pull out the shift key if
            // it is a capital letter. This is used to normalize so all the
            // keys are uppercase with a shift modifier.
            bool shiftWasConsumed = ((evt.State ^ modifiers) & ModifierType.ShiftMask)
                                    != 0;
            var unicode = (char)Keyval.ToUnicode((uint)key);

            if (shiftWasConsumed && Char.IsUpper(unicode))
            {
                modifiers |= ModifierType.ShiftMask;
            }

            if (Char.IsLetter(unicode) &&
                Char.IsLower(unicode))
            {
                key = (Key)Char.ToUpper(unicode);
            }
        }
示例#5
0
        /// <summary>
        /// Called when a key is pressed.
        /// </summary>
        /// <param name="eventKey">The event key.</param>
        /// <returns></returns>
        protected override bool OnKeyPressEvent(EventKey eventKey)
        {
            // If we don't have a line buffer, don't do anything.
            if (LineBuffer == null)
            {
                return(false);
            }

            // Decompose the key into its components.
            ModifierType modifier;
            Key          key;

            GdkUtility.DecomposeKeys(eventKey, out key, out modifier);

            // Get the unicode character for this key.
            uint unicodeChar = Keyval.ToUnicode(eventKey.KeyValue);

            // Pass it on to the controller.
            return(controller.HandleKeyPress(key, modifier, unicodeChar));
        }
        public static bool CombinationValidForItem(AccelKey accelKey)
        {
            char key = (char)Keyval.ToUnicode((uint)accelKey.Key);

            return(IsFunctional(accelKey.Key) || key != char.MinValue);
        }
        private bool OnCellKeyPressEvent(CellKeyPressEventArgs args)
        {
            if (eventLock)
            {
                return(true);
            }

            try {
                eventLock = true;
                if (cellsFucusable && args.Cell.IsValid)
                {
                    column_cache [args.Cell.Column].Column.ListCell.OnKeyPressEvent(args);
                }

                if (CellKeyPressEvent != null)
                {
                    CellKeyPressEvent(this, args);
                }

#if DEBUG_LISTVIEW
                Debug.WriteLine(string.Format("ListView received {0}", "OnCellKeyPressEvent"));
#endif

                bool ret;
                // Don't send arrow keys to the parent because the focus gets lost
                switch (args.GdkKey)
                {
                case Gdk.Key.Up:
                case Gdk.Key.KP_Up:
                case Gdk.Key.Down:
                case Gdk.Key.KP_Down:
                case Gdk.Key.Left:
                case Gdk.Key.Right:
                    ret = true;
                    break;

                default:
                    ret = base.OnKeyPressEvent(args.EventKey);
                    break;
                }

                switch (args.GdkKey)
                {
                case Gdk.Key.Up:
                case Gdk.Key.KP_Up:
                    if (!manualFucusChange)
                    {
                        return(KeyboardScroll(args.EventKey.State, -1));
                    }
                    break;

                case Gdk.Key.Down:
                case Gdk.Key.KP_Down:
                    if (!manualFucusChange)
                    {
                        return(KeyboardScroll(args.EventKey.State, 1));
                    }
                    break;

                case Gdk.Key.Left:
                    if (!manualFucusChange && cellsFucusable)
                    {
                        FocusCell(selection.FocusedCell.Column - 1, selection.FocusedCell.Row);
                        InvalidateList();
                    }
                    break;

                case Gdk.Key.Right:
                    if (!manualFucusChange && cellsFucusable)
                    {
                        FocusCell(selection.FocusedCell.Column + 1, selection.FocusedCell.Row);
                        InvalidateList();
                    }
                    break;

                case Gdk.Key.Page_Up:
                case Gdk.Key.KP_Page_Up:
                    if (!manualFucusChange)
                    {
                        return(KeyboardScroll(args.EventKey.State,
                                              (int)(-vadjustment.PageIncrement / RowHeight)));
                    }
                    break;

                case Gdk.Key.Page_Down:
                case Gdk.Key.KP_Page_Down:
                    if (!manualFucusChange)
                    {
                        return(KeyboardScroll(args.EventKey.State,
                                              (int)(vadjustment.PageIncrement / RowHeight)));
                    }
                    break;

                case Gdk.Key.Home:
                case Gdk.Key.KP_Home:
                    if (!manualFucusChange)
                    {
                        return(KeyboardScroll(args.EventKey.State, -10000000));
                    }
                    break;

                case Gdk.Key.End:
                case Gdk.Key.KP_End:
                    if (!manualFucusChange)
                    {
                        return(KeyboardScroll(args.EventKey.State, 10000000));
                    }
                    break;

                case Gdk.Key.Return:
                case Gdk.Key.KP_Enter:
                    ActivateRow();
                    break;

                default:
                    char keyChar = (char)Keyval.ToUnicode((uint)args.GdkKey);

                    if (char.ToLower(keyChar) == 'a' && (args.EventKey.State & KeyShortcuts.ControlModifier) != 0)
                    {
                        if (allowMultipleSelect)
                        {
                            if ((args.EventKey.State & ModifierType.ShiftMask) != 0)
                            {
                                selection.Clear();
                            }
                            else
                            {
                                selection.SelectAll();
                            }
                            QueueDraw();
                        }
                        return(ret);
                    }

                    if (!editedCell.IsValid)
                    {
                        if (keyChar != '\0')
                        {
                            if (char.ToLower(keyChar) == 'v' && (args.EventKey.State & KeyShortcuts.ControlModifier) != 0)
                            {
                                Clipboard clip = Clipboard.Get(Atom.Intern("CLIPBOARD", false));
                                SetAutoFilter(autoFilterValue + clip.WaitForText(), true);
                            }
                            else
                            {
                                SetAutoFilter(autoFilterValue + keyChar, true);
                            }
                        }
                        else if (args.GdkKey == Gdk.Key.BackSpace)
                        {
                            SetAutoFilter(autoFilterValue.Substring(0, Math.Max(0, autoFilterValue.Length - 1)), true);
                        }
                    }

                    break;
                }

                return(ret);
            } finally {
                eventLock = false;
            }
        }