Ejemplo n.º 1
0
        protected override void OnKeyDown(DrawingArea canvas, KeyPressEventArgs args)
        {
            Gdk.ModifierType modifier = args.Event.State;

            // If we are dragging the text, we
            // aren't going to handle key presses
            if (tracking)
            {
                return;
            }

            // Ignore anything with Alt pressed
            if ((modifier & Gdk.ModifierType.Mod1Mask) != 0)
            {
                return;
            }

            // Assume that we are going to handle the key
            bool keyHandled = true;

            if (is_editing)
            {
                switch (args.Event.Key)
                {
                case Gdk.Key.BackSpace:
                    engine.PerformBackspace();
                    break;

                case Gdk.Key.Delete:
                    engine.PerformDelete();
                    break;

                case Gdk.Key.KP_Enter:
                case Gdk.Key.Return:
                    engine.PerformEnter();
                    break;

                case Gdk.Key.Left:
                    engine.PerformLeft((modifier & Gdk.ModifierType.ControlMask) != 0);
                    break;

                case Gdk.Key.Right:
                    engine.PerformRight((modifier & Gdk.ModifierType.ControlMask) != 0);
                    break;

                case Gdk.Key.Up:
                    engine.PerformUp();
                    break;

                case Gdk.Key.Down:
                    engine.PerformDown();
                    break;

                case Gdk.Key.Home:
                    engine.PerformHome((modifier & Gdk.ModifierType.ControlMask) != 0);
                    break;

                case Gdk.Key.End:
                    engine.PerformEnd((modifier & Gdk.ModifierType.ControlMask) != 0);
                    break;

                case Gdk.Key.Next:
                case Gdk.Key.Prior:
                    break;

                case Gdk.Key.Escape:
                    StopEditing();
                    break;

                default:
                    // Try to handle it as a character
                    uint ch = Gdk.Keyval.ToUnicode(args.Event.KeyValue);

                    if (ch != 0)
                    {
                        engine.InsertCharIntoString(ch);
                        RedrawText(true, true);
                    }
                    else
                    {
                        // We didn't handle the key
                        keyHandled = false;
                    }

                    break;
                }

                // If we processed a key, update the display
                if (keyHandled)
                {
                    RedrawText(true, true);
                }
            }

            args.RetVal = keyHandled;
        }
Ejemplo n.º 2
0
        protected override void OnKeyDown(DrawingArea canvas, KeyPressEventArgs args)
        {
            Gdk.ModifierType modifier = args.Event.State;

            // If we are dragging the text, we
            // aren't going to handle key presses
            if (tracking)
            {
                return;
            }

            // Ignore anything with Alt pressed
            if ((modifier & Gdk.ModifierType.Mod1Mask) != 0)
            {
                return;
            }

            // Assume that we are going to handle the key
            bool keyHandled = true;

            if (is_editing)
            {
                switch (args.Event.Key)
                {
                case Gdk.Key.BackSpace:
                    engine.PerformBackspace();
                    break;

                case Gdk.Key.Delete:
                    engine.PerformDelete();
                    break;

                case Gdk.Key.KP_Enter:
                case Gdk.Key.Return:
                    engine.PerformEnter();
                    break;

                case Gdk.Key.Left:
                    engine.PerformLeft((modifier & Gdk.ModifierType.ControlMask) != 0, (modifier & Gdk.ModifierType.ShiftMask) != 0);
                    break;

                case Gdk.Key.Right:
                    engine.PerformRight((modifier & Gdk.ModifierType.ControlMask) != 0, (modifier & Gdk.ModifierType.ShiftMask) != 0);
                    break;

                case Gdk.Key.Up:
                    engine.PerformUp((modifier & Gdk.ModifierType.ShiftMask) != 0);
                    break;

                case Gdk.Key.Down:
                    engine.PerformDown((modifier & Gdk.ModifierType.ShiftMask) != 0);
                    break;

                case Gdk.Key.Home:
                    engine.PerformHome((modifier & Gdk.ModifierType.ControlMask) != 0, (modifier & Gdk.ModifierType.ShiftMask) != 0);
                    break;

                case Gdk.Key.End:
                    engine.PerformEnd((modifier & Gdk.ModifierType.ControlMask) != 0, (modifier & Gdk.ModifierType.ShiftMask) != 0);
                    break;

                case Gdk.Key.Next:
                case Gdk.Key.Prior:
                    break;

                case Gdk.Key.Escape:
                    StopEditing();
                    break;

                case Gdk.Key.Insert:
                    if ((modifier & Gdk.ModifierType.ShiftMask) != 0)
                    {
                        Gtk.Clipboard cb = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
                        engine.PerformPaste(cb);
                    }
                    else if ((modifier & Gdk.ModifierType.ControlMask) != 0)
                    {
                        Gtk.Clipboard cb = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
                        engine.PerformCopy(cb);
                    }
                    break;

                default:
                    // Ignore command shortcut
                    if ((modifier & Gdk.ModifierType.ControlMask) != 0)
                    {
                        // Handle undo while editing - if there is nothing on the history stack but
                        // the user has typed some text, we need to handle the shortcut ourselves.
                        if (args.Event.Key == Gdk.Key.z)
                        {
                            StopEditing();

                            if (PintaCore.Workspace.ActiveDocument.History.CanUndo)
                            {
                                PintaCore.Workspace.ActiveDocument.History.Undo();
                            }
                        }
                        return;
                    }

                    keyHandled = TryHandleChar(args.Event);
                    break;
                }

                // If we processed a key, update the display
                if (keyHandled)
                {
                    RedrawText(true, true);
                }
            }
            else
            {
                // If we're not editing, allow the key press to be handled elsewhere (e.g. for selecting another tool).
                keyHandled = false;
            }

            args.RetVal = keyHandled;
        }